Refactor parts of match_function_by_name into process_parameters and process_call
authorIan Romanick <ian.d.romanick@intel.com>
Wed, 31 Mar 2010 23:28:51 +0000 (16:28 -0700)
committerIan Romanick <ian.d.romanick@intel.com>
Wed, 31 Mar 2010 23:28:51 +0000 (16:28 -0700)
These will be used in the functions that implement calls to array constructors.

ast_function.cpp

index 74ae5d8962bf13db4c3d92bc89ab086e52ba28d0..340873ae4181984c83dc83cea25455dcffc82a13 100644 (file)
 #include "glsl_types.h"
 #include "ir.h"
 
-static ir_rvalue *
-match_function_by_name(exec_list *instructions, const char *name,
-                      YYLTYPE *loc, simple_node *parameters,
-                      struct _mesa_glsl_parse_state *state)
+static unsigned
+process_parameters(exec_list *instructions, exec_list *actual_parameters,
+                  simple_node *parameters,
+                  struct _mesa_glsl_parse_state *state)
 {
-   ir_function *f = state->symbols->get_function(name);
-
-   if (f == NULL) {
-      _mesa_glsl_error(loc, state, "function `%s' undeclared", name);
-      return ir_call::get_error_instruction();
-   }
-
-   /* Once we've determined that the function being called might exist,
-    * process the parameters.
-    */
-   exec_list actual_parameters;
    simple_node *const first = parameters;
+   unsigned count = 0;
+
    if (first != NULL) {
       simple_node *ptr = first;
       do {
@@ -51,20 +42,31 @@ match_function_by_name(exec_list *instructions, const char *name,
            ((ast_node *) ptr)->hir(instructions, state);
         ptr = ptr->next;
 
-        actual_parameters.push_tail(result);
+        actual_parameters->push_tail(result);
+        count++;
       } while (ptr != first);
    }
 
-   /* After processing the function's actual parameters, try to find an
-    * overload of the function that matches.
-    */
+   return count;
+}
+
+
+static ir_rvalue *
+process_call(exec_list *instructions, ir_function *f,
+            YYLTYPE *loc, exec_list *actual_parameters,
+            struct _mesa_glsl_parse_state *state)
+{
    const ir_function_signature *sig =
-      f->matching_signature(& actual_parameters);
+      f->matching_signature(actual_parameters);
+
+   /* The instructions param will be used when the FINISHMEs below are done */
+   (void) instructions;
+
    if (sig != NULL) {
       /* FINISHME: The list of actual parameters needs to be modified to
        * FINISHME: include any necessary conversions.
        */
-      return new ir_call(sig, actual_parameters);
+      return new ir_call(sig, actual_parameters);
    } else {
       /* FINISHME: Log a better error message here.  G++ will show the types
        * FINISHME: of the actual parameters and the set of candidate
@@ -72,9 +74,34 @@ match_function_by_name(exec_list *instructions, const char *name,
        * FINISHME: multiple functions match.
        */
       _mesa_glsl_error(loc, state, "no matching function for call to `%s'",
-                      name);
+                      f->name);
+      return ir_call::get_error_instruction();
+   }
+}
+
+
+static ir_rvalue *
+match_function_by_name(exec_list *instructions, const char *name,
+                      YYLTYPE *loc, simple_node *parameters,
+                      struct _mesa_glsl_parse_state *state)
+{
+   ir_function *f = state->symbols->get_function(name);
+
+   if (f == NULL) {
+      _mesa_glsl_error(loc, state, "function `%s' undeclared", name);
       return ir_call::get_error_instruction();
    }
+
+   /* Once we've determined that the function being called might exist,
+    * process the parameters.
+    */
+   exec_list actual_parameters;
+   process_parameters(instructions, &actual_parameters, parameters, state);
+
+   /* After processing the function's actual parameters, try to find an
+    * overload of the function that matches.
+    */
+   return process_call(instructions, f, loc, &actual_parameters, state);
 }