]> git.tdb.fi Git - libs/gl.git/blobdiff - source/glsl/resolve.cpp
Resolve function calls where argument types need to be converted
[libs/gl.git] / source / glsl / resolve.cpp
index 176b13c5f1f55ad13e1613be145676150ef93db5..3f959a7d03bad94db6fe4f7138b00f0fbb546bf7 100644 (file)
@@ -1102,6 +1102,29 @@ bool FunctionResolver::apply(Stage &s)
        return r_any_resolved;
 }
 
+bool FunctionResolver::can_convert_arguments(const FunctionCall &call, const FunctionDeclaration &decl)
+{
+       if(decl.parameters.size()!=call.arguments.size())
+               return false;
+
+       for(unsigned j=0; j<call.arguments.size(); ++j)
+       {
+               const TypeDeclaration *arg_type = call.arguments[j]->type;
+               const TypeDeclaration *param_type = decl.parameters[j]->type_declaration;
+               if(arg_type==param_type)
+                       continue;
+
+               const BasicTypeDeclaration *arg_basic = dynamic_cast<const BasicTypeDeclaration *>(arg_type);
+               const BasicTypeDeclaration *param_basic = dynamic_cast<const BasicTypeDeclaration *>(param_type);
+               if(arg_basic && param_basic && can_convert(*arg_basic, *param_basic))
+                       continue;
+
+               return false;
+       }
+
+       return true;
+}
+
 void FunctionResolver::visit(FunctionCall &call)
 {
        FunctionDeclaration *declaration = 0;
@@ -1123,6 +1146,21 @@ void FunctionResolver::visit(FunctionCall &call)
                {
                        map<string, FunctionDeclaration *>::iterator i = stage->functions.find(format("%s(%s)", call.name, arg_types));
                        declaration = (i!=stage->functions.end() ? i->second : 0);
+
+                       if(!declaration)
+                       {
+                               for(i=stage->functions.lower_bound(call.name+"("); (i!=stage->functions.end() && i->second->name==call.name); ++i)
+                                       if(can_convert_arguments(call, *i->second))
+                                       {
+                                               if(declaration)
+                                               {
+                                                       declaration = 0;
+                                                       break;
+                                               }
+                                               else
+                                                       declaration = i->second;
+                                       }
+                       }
                }
        }