summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKenneth Graunke <kenneth@whitecape.org>2010-04-28 11:49:12 -0700
committerIan Romanick <ian.d.romanick@intel.com>2010-04-28 15:34:52 -0700
commitabd40b15210c17b2a3ba8fcffc868fda203efa01 (patch)
treed5f78a55ee20488e0102a7ce1a6d2ac94d5d9fc3
parent0e385196f65d0f8dc3238e7eedb6f2d6c0a79a5d (diff)
Factor out qualifier checking code for later reuse.
-rw-r--r--ast_to_hir.cpp28
-rw-r--r--ir.cpp26
-rw-r--r--ir.h7
3 files changed, 40 insertions, 21 deletions
diff --git a/ast_to_hir.cpp b/ast_to_hir.cpp
index 7b4a855f57..0e7ab1ab3a 100644
--- a/ast_to_hir.cpp
+++ b/ast_to_hir.cpp
@@ -1952,27 +1952,13 @@ ast_function::hir(exec_list *instructions,
* definition.
*/
if (parameter_lists_match(& hir_parameters, & sig->parameters)) {
- exec_list_iterator iter_a = hir_parameters.iterator();
- exec_list_iterator iter_b = sig->parameters.iterator();
-
- /* check that the qualifiers match. */
- while (iter_a.has_next()) {
- ir_variable *a = (ir_variable *)iter_a.get();
- ir_variable *b = (ir_variable *)iter_b.get();
-
- if (a->read_only != b->read_only ||
- a->interpolation != b->interpolation ||
- a->centroid != b->centroid) {
- YYLTYPE loc = this->get_location();
-
- _mesa_glsl_error(& loc, state,
- "function `%s' parameter `%s' qualifiers "
- "don't match prototype",
- name, a->name);
- }
-
- iter_a.next();
- iter_b.next();
+ const char *mismatch = sig->qualifiers_match(&hir_parameters);
+ if (mismatch != NULL) {
+ YYLTYPE loc = this->get_location();
+
+ _mesa_glsl_error(&loc, state, "function `%s' parameter `%s' "
+ "qualifiers don't match prototype",
+ name, mismatch);
}
if (sig->return_type != return_type) {
diff --git a/ir.cpp b/ir.cpp
index b4b2ca4d91..8912c00e82 100644
--- a/ir.cpp
+++ b/ir.cpp
@@ -338,6 +338,32 @@ ir_function_signature::ir_function_signature(const glsl_type *return_type)
}
+const char *
+ir_function_signature::qualifiers_match(exec_list *params)
+{
+ exec_list_iterator iter_a = parameters.iterator();
+ exec_list_iterator iter_b = params->iterator();
+
+ /* check that the qualifiers match. */
+ while (iter_a.has_next()) {
+ ir_variable *a = (ir_variable *)iter_a.get();
+ ir_variable *b = (ir_variable *)iter_b.get();
+
+ if (a->read_only != b->read_only ||
+ a->interpolation != b->interpolation ||
+ a->centroid != b->centroid) {
+
+ /* parameter a's qualifiers don't match */
+ return a->name;
+ }
+
+ iter_a.next();
+ iter_b.next();
+ }
+ return NULL;
+}
+
+
ir_function::ir_function(const char *name)
: name(name)
{
diff --git a/ir.h b/ir.h
index 892455e1de..b9ab25b645 100644
--- a/ir.h
+++ b/ir.h
@@ -207,6 +207,13 @@ public:
const char *function_name() const;
/**
+ * Check whether the qualifiers match between this signature's parameters
+ * and the supplied parameter list. If not, returns the name of the first
+ * parameter with mismatched qualifiers (for use in error messages).
+ */
+ const char *qualifiers_match(exec_list *params);
+
+ /**
* Function return type.
*
* \note This discards the optional precision qualifier.