]> git.tdb.fi Git - libs/gl.git/blobdiff - source/glsl/validate.cpp
Properly resolve arithmetic assignment operators
[libs/gl.git] / source / glsl / validate.cpp
index 676dd9e808792867458d8c59d03a62d47ceb8e88..2f02400ee675a5bc159362d9e85fec755a92c9d7 100644 (file)
@@ -1,3 +1,4 @@
+#include <cstring>
 #include <msp/core/raii.h>
 #include <msp/strings/format.h>
 #include "validate.h"
@@ -231,18 +232,30 @@ void ExpressionValidator::visit(BinaryExpression &binary)
 
 void ExpressionValidator::visit(Assignment &assign)
 {
-       if(assign.left->type && !assign.left->lvalue)
-               error(assign, "Target of assignment is not an lvalue");
-       if(assign.left->type && assign.right->type && assign.left->type!=assign.right->type)
-               error(assign, format("Assignment to variable of type '%s' from expression of type '%s'",
-                       assign.left->type->name, assign.right->type->name));
+       if(assign.left->type)
+       {
+               if(!assign.left->lvalue)
+                       error(assign, "Target of assignment is not an lvalue");
+               if(assign.right->type)
+               {
+                       if(assign.oper->token[0]!='=')
+                       {
+                               if(!assign.type)
+                                       error(assign, format("No matching operator '%s' found for '%s' and '%s'",
+                                               string(assign.oper->token, strlen(assign.oper->token)-1), assign.left->type->name, assign.right->type->name));
+                       }
+                       else if(assign.left->type!=assign.right->type)
+                               error(assign, format("Assignment to variable of type '%s' from expression of incompatible type '%s'",
+                                       assign.left->type->name, assign.right->type->name));
+               }
+       }
        TraversingVisitor::visit(assign);
 }
 
 void ExpressionValidator::visit(VariableDeclaration &var)
 {
        if(var.init_expression && var.init_expression->type && var.type_declaration && var.init_expression->type!=var.type_declaration)
-               error(var, format("Initializing a variable of type '%s' with an expression of type '%s'",
+               error(var, format("Initializing a variable of type '%s' with an expression of incompatible type '%s'",
                        var.type_declaration->name, var.init_expression->type->name));
        TraversingVisitor::visit(var);
 }