]> git.tdb.fi Git - libs/gl.git/blobdiff - source/glsl/validate.cpp
Require GLSL functions to be declared before use
[libs/gl.git] / source / glsl / validate.cpp
index f8ecc5eeefd34aaad243accf7034d9cee8513ca0..1458d01eaaba8743d40e90bb9b030790dca3cad9 100644 (file)
@@ -173,6 +173,17 @@ void DeclarationValidator::visit(InterfaceBlock &iface)
 
 void DeclarationValidator::visit(FunctionDeclaration &func)
 {
+       string key = func.name+func.signature;
+       map<string, FunctionDeclaration *>::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<FunctionDeclaration *>(previous))
@@ -225,6 +236,13 @@ 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)
+               error(call, format("Call to undeclared function '%s'", call.name));
+       TraversingVisitor::visit(call);
+}
+
 void ReferenceValidator::visit(VariableDeclaration &var)
 {
        if(!var.type_declaration)