[Mesa-dev] [PATCH 05/10] glsl: Refactor parser rule of layout_qualifier_id

Chad Versace chad.versace at intel.com
Sat Oct 23 11:22:25 PDT 2010


In file glsl_parser.ypp, within the production rule of layout_qualifier_id,
factor out the logic for extension ARB_fragment_coord_conventions into its own
function.

Rationale: A future commit will add to this production rule extra logic for
extension AMD_conservative_depth. If the logic for both extensions were
contained within the production rule, this would result in an ugly
proliferation of boolean flags and if/else trees.
---
 src/glsl/glsl_parser.ypp |   64 ++++++++++++++++++++++++++++++++++++---------
 1 files changed, 51 insertions(+), 13 deletions(-)

diff --git a/src/glsl/glsl_parser.ypp b/src/glsl/glsl_parser.ypp
index 3813d7a..97f7b32 100644
--- a/src/glsl/glsl_parser.ypp
+++ b/src/glsl/glsl_parser.ypp
@@ -32,6 +32,24 @@
 
 #define YYLEX_PARAM state->scanner
 
+/**
+ * \brief Helper function for prodution rule of 'layout_qualifier_id'.
+ *
+ * If extension 'ARB_fragment_coord_conventions' is enabled and \c token1 is
+ * a layout qualifer added by that extension, then process the token and
+ * return true. Else, return false.
+ *
+ * This function should be used only within the production rule of
+ * 'layout_qualifier_id'.
+ */
+static bool
+layout_qualifier_id__ARB_fragment_coord_conventions_enable(
+   _mesa_glsl_parse_state *state,
+   ast_type_qualifier *lhs,
+   YYLTYPE *lhs_location,
+   const char *token1,
+   YYLTYPE *token1_location);
+
 %}
 
 %pure-parser
@@ -1006,15 +1024,8 @@ layout_qualifier_id:
 
 	   memset(& $$, 0, sizeof($$));
 
-	   if (state->ARB_fragment_coord_conventions_enable) {
-	      if (strcmp($1, "origin_upper_left") == 0) {
-		 got_one = true;
-		 $$.flags.q.origin_upper_left = 1;
-	      } else if (strcmp($1, "pixel_center_integer") == 0) {
-		 got_one = true;
-		 $$.flags.q.pixel_center_integer = 1;
-	      }
-	   }
+           got_one = layout_qualifier_id__ARB_fragment_coord_conventions_enable(
+              state, & $$, & @$, $1, & @1);
 
 	   /* If the identifier didn't match any known layout identifiers,
 	    * emit an error.
@@ -1023,10 +1034,6 @@ layout_qualifier_id:
 	      _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
 			       "`%s'\n", $1);
 	      YYERROR;
-	   } else if (state->ARB_fragment_coord_conventions_warn) {
-	      _mesa_glsl_warning(& @1, state,
-				 "GL_ARB_fragment_coord_conventions layout "
-				 "identifier `%s' used\n", $1);
 	   }
 	}
 	| IDENTIFIER '=' INTCONSTANT
@@ -1629,3 +1636,34 @@ function_definition:
 	   $$->body = $2;
 	}
 	;
+%%
+
+static bool
+layout_qualifier_id__ARB_fragment_coord_conventions_enable(
+   _mesa_glsl_parse_state *state,
+   ast_type_qualifier *lhs,
+   YYLTYPE *lhs_location,
+   const char *token1,
+   YYLTYPE *token1_location)
+{
+   // found: Indicates if a layout qualifier has been found.
+   bool found = false;
+
+   if (!state->ARB_fragment_coord_conventions_enable)
+      return false;
+
+   if (strcmp(token1, "origin_upper_left") == 0) {
+      found = true;
+      lhs->flags.q.origin_upper_left = 1;
+   } else if (strcmp(token1, "pixel_center_integer") == 0) {
+      found = true;
+      lhs->flags.q.pixel_center_integer = 1;
+   }
+
+   if (found && state->ARB_fragment_coord_conventions_warn) {
+      _mesa_glsl_warning(token1_location, state, "GL_ARB_fragment_coord_conventions "
+         "layout identifier `%s' used\n", token1);
+   }
+
+   return found;
+}
-- 
1.7.1



More information about the mesa-dev mailing list