]> git.tdb.fi Git - libs/gl.git/blobdiff - source/glsl/resolve.cpp
Refactor function call argument type resolving logic a bit
[libs/gl.git] / source / glsl / resolve.cpp
index 3aeab30bd703711d28909cea07b15adc4fc1318d..82c0a367dfd2e70f89d04e9b9335cb4df23c2ded 100644 (file)
@@ -179,7 +179,7 @@ void VariableResolver::visit(RefPtr<Expression> &expr)
        r_replacement_expr = 0;
 }
 
-void VariableResolver::check_assignment_target(Statement *declaration)
+void VariableResolver::check_assignment_target(VariableDeclaration *declaration)
 {
        if(record_target)
        {
@@ -1084,7 +1084,27 @@ void ExpressionResolver::visit(FunctionCall &call)
        TraversingVisitor::visit(call);
 
        if(call.declaration)
+       {
+               for(unsigned i=0; i<call.arguments.size(); ++i)
+               {
+                       TypeDeclaration *arg_type = call.arguments[i]->type;
+                       TypeDeclaration *param_type = call.declaration->parameters[i]->type_declaration;
+                       if(arg_type==param_type)
+                               continue;
+                       else if(!arg_type || !param_type)
+                               return;
+
+                       BasicTypeDeclaration *arg_basic = dynamic_cast<BasicTypeDeclaration *>(arg_type);
+                       BasicTypeDeclaration *param_basic = dynamic_cast<BasicTypeDeclaration *>(param_type);
+                       if(arg_basic && param_basic)
+                       {
+                               Compatibility compat = get_compatibility(*param_basic, *arg_basic);
+                               if(compat==RIGHT_CONVERTIBLE)
+                                       convert_to(call.arguments[i], *param_basic);
+                       }
+               }
                resolve(call, call.declaration->return_type_declaration, false);
+       }
        else if(call.constructor)
                visit_constructor(call);
 }