Factor out qualifier checking code for later reuse.
authorKenneth Graunke <kenneth@whitecape.org>
Wed, 28 Apr 2010 18:49:12 +0000 (11:49 -0700)
committerIan Romanick <ian.d.romanick@intel.com>
Wed, 28 Apr 2010 22:34:52 +0000 (15:34 -0700)
ast_to_hir.cpp
ir.cpp
ir.h

index 7b4a855f57674d20852f0dc3e530322e0cd8e72d..0e7ab1ab3a302ad0ae1a43346be326ba0f73fad6 100644 (file)
@@ -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 b4b2ca4d91617a09b3912b0869a489421162452f..8912c00e8271d9bf5fc2677c5d3d4497127bac9c 100644 (file)
--- 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 892455e1dee29a74f25318cf2f2255529b83d28a..b9ab25b645323d99e0db4fdd0447b05e41d8bd06 100644 (file)
--- a/ir.h
+++ b/ir.h
@@ -206,6 +206,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.
     *