X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fglsl%2Fvalidate.cpp;h=fcccb526e0dc3bc62831e3c949f8bb767b929591;hb=01c59fefa142fe7812db32e703bbe52a0c14a2bb;hp=676dd9e808792867458d8c59d03a62d47ceb8e88;hpb=50ab5ca2babc8d9592903da6072a13b381ed6656;p=libs%2Fgl.git diff --git a/source/glsl/validate.cpp b/source/glsl/validate.cpp index 676dd9e8..fcccb526 100644 --- a/source/glsl/validate.cpp +++ b/source/glsl/validate.cpp @@ -1,3 +1,4 @@ +#include #include #include #include "validate.h" @@ -155,11 +156,16 @@ void DeclarationValidator::visit(InterfaceBlock &iface) void DeclarationValidator::visit(FunctionDeclaration &func) { if(Statement *previous = find_definition(func.name)) - if(!dynamic_cast(previous)) + { + FunctionDeclaration *prev_func = dynamic_cast(previous); + if(prev_func && prev_func->definition==&func) + declarations[current_block][func.name] = &func; + else multiple_definition(format("'%s'", func.name), func, *previous); + } + else + record_definition(func.name, func); - if(func.definition==&func) - check_definition(func.name, func); TraversingVisitor::visit(func); } @@ -231,18 +237,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); }