X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fglsl%2Fvalidate.cpp;h=6e90698c97b500c5dd2edcaebd7e3f8c70e90026;hb=3a1fe833ea04df75449706f1d773f6e65521a392;hp=f8ecc5eeefd34aaad243accf7034d9cee8513ca0;hpb=a1ba04add302e7712d127b46d8d11386987a0aea;p=libs%2Fgl.git diff --git a/source/glsl/validate.cpp b/source/glsl/validate.cpp index f8ecc5ee..6e90698c 100644 --- a/source/glsl/validate.cpp +++ b/source/glsl/validate.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include "validate.h" using namespace std; @@ -173,6 +174,17 @@ void DeclarationValidator::visit(InterfaceBlock &iface) void DeclarationValidator::visit(FunctionDeclaration &func) { + string key = func.name+func.signature; + map::const_iterator i = overloaded_functions.find(key); + if(i==overloaded_functions.end()) + overloaded_functions.insert(make_pair(key, &func)); + else if(func.return_type_declaration && i->second->return_type_declaration!=func.return_type_declaration) + { + error(func, format("Conflicting return type '%s' for function '%s'", func.return_type_declaration->name, func.name)); + if(i->second->return_type_declaration) + add_info(*i->second, format("Previously declared as returning '%s'", i->second->return_type_declaration->name)); + } + if(Statement *previous = find_definition(func.name)) { if(!dynamic_cast(previous)) @@ -225,6 +237,32 @@ void ReferenceValidator::visit(InterfaceBlockReference &iface) error(iface, format("Use of unlinked input block '%s'", iface.name)); } +void ReferenceValidator::visit(FunctionCall &call) +{ + if(!call.declaration && !call.constructor) + { + map::iterator i = stage->functions.lower_bound(call.name); + if(i!=stage->functions.end() && i->second->name==call.name) + { + bool valid_types = true; + string signature; + for(NodeArray::const_iterator j=call.arguments.begin(); (valid_types && j!=call.arguments.end()); ++j) + { + if((*j)->type) + append(signature, ", ", (*j)->type->name); + else + valid_types = false; + } + + if(valid_types) + error(call, format("No matching overload found for call to '%s(%s)'", call.name, signature)); + } + else + error(call, format("Call to undeclared function '%s'", call.name)); + } + TraversingVisitor::visit(call); +} + void ReferenceValidator::visit(VariableDeclaration &var) { if(!var.type_declaration) @@ -327,6 +365,20 @@ void ExpressionValidator::visit(Assignment &assign) TraversingVisitor::visit(assign); } +void ExpressionValidator::visit(TernaryExpression &ternary) +{ + if(ternary.condition->type) + { + BasicTypeDeclaration *basic_cond = dynamic_cast(ternary.condition->type); + if(!basic_cond || basic_cond->kind!=BasicTypeDeclaration::BOOL) + error(ternary, "Ternary operator condition is not a boolean"); + else if(!ternary.type && ternary.true_expr->type && ternary.false_expr->type) + error(ternary, format("Ternary operator has incompatible types '%s' and '%s'", + ternary.true_expr->type->name, ternary.false_expr->type->name)); + } + TraversingVisitor::visit(ternary); +} + void ExpressionValidator::visit(VariableDeclaration &var) { if(var.init_expression && var.init_expression->type && var.type_declaration && var.init_expression->type!=var.type_declaration)