}
-static bool
-parameter_lists_match(exec_list *list_a, exec_list *list_b)
-{
- exec_list_iterator iter_a = list_a->iterator();
- exec_list_iterator iter_b = list_b->iterator();
-
- while (iter_a.has_next() && iter_b.has_next()) {
- ir_variable *a = (ir_variable *)iter_a.get();
- ir_variable *b = (ir_variable *)iter_b.get();
-
- /* If the types of the parameters do not match, the parameters lists
- * are different.
- */
- if (a->type != b->type)
- return false;
-
- iter_a.next();
- iter_b.next();
- }
-
- /* Unless both lists are exhausted, they differ in length and, by
- * definition, do not match.
- */
- if (iter_a.has_next() != iter_b.has_next())
- return false;
-
- return true;
-}
-
-
ir_rvalue *
ast_function::hir(exec_list *instructions,
struct _mesa_glsl_parse_state *state)
const char *const name = identifier;
f = state->symbols->get_function(name);
if (f != NULL) {
- foreach_iter(exec_list_iterator, iter, *f) {
- sig = (struct ir_function_signature *) iter.get();
-
- /* Compare the parameter list of the function being defined to the
- * existing function. If the parameter lists match, then the return
- * type must also match and the existing function must not have a
- * definition.
- */
- if (parameter_lists_match(& hir_parameters, & sig->parameters)) {
- const char *mismatch = sig->qualifiers_match(&hir_parameters);
- if (mismatch != NULL) {
- YYLTYPE loc = this->get_location();
+ ir_function_signature *sig = f->exact_matching_signature(&hir_parameters);
+ if (sig != NULL) {
+ const char *badvar = sig->qualifiers_match(&hir_parameters);
+ if (badvar != NULL) {
+ YYLTYPE loc = this->get_location();
- _mesa_glsl_error(&loc, state, "function `%s' parameter `%s' "
- "qualifiers don't match prototype",
- name, mismatch);
- }
+ _mesa_glsl_error(&loc, state, "function `%s' parameter `%s' "
+ "qualifiers don't match prototype", name, badvar);
+ }
- if (sig->return_type != return_type) {
- YYLTYPE loc = this->get_location();
+ if (sig->return_type != return_type) {
+ YYLTYPE loc = this->get_location();
- _mesa_glsl_error(& loc, state,
- "function `%s' return type doesn't match "
- "prototype",
- name);
- }
+ _mesa_glsl_error(&loc, state, "function `%s' return type doesn't "
+ "match prototype", name);
+ }
- if (is_definition && sig->is_defined) {
- YYLTYPE loc = this->get_location();
+ if (is_definition && sig->is_defined) {
+ YYLTYPE loc = this->get_location();
- _mesa_glsl_error(& loc, state, "function `%s' redefined", name);
- sig = NULL;
- break;
- }
+ _mesa_glsl_error(& loc, state, "function `%s' redefined", name);
+ sig = NULL;
}
-
- sig = NULL;
}
-
} else if (state->symbols->name_declared_this_scope(name)) {
/* This function name shadows a non-function use of the same name.
*/
return match;
}
+
+
+static bool
+parameter_lists_match_exact(exec_list *list_a, exec_list *list_b)
+{
+ exec_list_iterator iter_a = list_a->iterator();
+ exec_list_iterator iter_b = list_b->iterator();
+
+ while (iter_a.has_next() && iter_b.has_next()) {
+ ir_variable *a = (ir_variable *)iter_a.get();
+ ir_variable *b = (ir_variable *)iter_b.get();
+
+ /* If the types of the parameters do not match, the parameters lists
+ * are different.
+ */
+ if (a->type != b->type)
+ return false;
+
+ iter_a.next();
+ iter_b.next();
+ }
+
+ /* Unless both lists are exhausted, they differ in length and, by
+ * definition, do not match.
+ */
+ if (iter_a.has_next() != iter_b.has_next())
+ return false;
+
+ return true;
+}
+
+ir_function_signature *
+ir_function::exact_matching_signature(exec_list *actual_parameters)
+{
+ foreach_iter(exec_list_iterator, iter, signatures) {
+ ir_function_signature *const sig =
+ (ir_function_signature *) iter.get();
+
+ if (parameter_lists_match_exact(&sig->parameters, actual_parameters))
+ return sig;
+ }
+ return NULL;
+}