From: Ian Romanick Date: Wed, 31 Mar 2010 23:28:51 +0000 (-0700) Subject: Refactor parts of match_function_by_name into process_parameters and process_call X-Git-Tag: 062012170305~10660^2~625^2~482 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=68515ee6c2a41cf5c0476b3309fcb050ef37b0d2;p=profile%2Fivi%2Fmesa.git Refactor parts of match_function_by_name into process_parameters and process_call These will be used in the functions that implement calls to array constructors. --- diff --git a/ast_function.cpp b/ast_function.cpp index 74ae5d8..340873a 100644 --- a/ast_function.cpp +++ b/ast_function.cpp @@ -27,23 +27,14 @@ #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); }