[Mesa-dev] [PATCH 13/26] glsl/parser: Extract version directive processing into a function.

Ian Romanick idr at freedesktop.org
Fri Nov 30 10:07:28 PST 2012


From: Paul Berry <stereotype441 at gmail.com>

Version directive handling is going to have to be used within two
parser rules, one for desktop-style version directives (e.g. "#version
130") and one for the new ES-style version directive (e.g. "#version
300 es"), so this patch moves it to a function that can be called from
both rules.

No functional change.

Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>
---
 src/glsl/glsl_parser.yy         | 43 +---------------------------------
 src/glsl/glsl_parser_extras.cpp | 52 +++++++++++++++++++++++++++++++++++++++++
 src/glsl/glsl_parser_extras.h   |  2 ++
 3 files changed, 55 insertions(+), 42 deletions(-)

diff --git a/src/glsl/glsl_parser.yy b/src/glsl/glsl_parser.yy
index 6cc1a51..b15e1d1 100644
--- a/src/glsl/glsl_parser.yy
+++ b/src/glsl/glsl_parser.yy
@@ -261,48 +261,7 @@ version_statement:
 	/* blank - no #version specified: defaults are already set */
 	| VERSION_TOK INTCONSTANT EOL
 	{
-	   bool supported = false;
-
-	   switch ($2) {
-	   case 100:
-	      state->es_shader = true;
-	      supported = state->ctx->API == API_OPENGLES2 ||
-		          state->ctx->Extensions.ARB_ES2_compatibility;
-	      break;
-	   case 110:
-	   case 120:
-	      /* FINISHME: Once the OpenGL 3.0 'forward compatible' context or
-	       * the OpenGL 3.2 Core context is supported, this logic will need
-	       * change.  Older versions of GLSL are no longer supported
-	       * outside the compatibility contexts of 3.x.
-	       */
-	   case 130:
-	   case 140:
-	   case 150:
-	   case 330:
-	   case 400:
-	   case 410:
-	   case 420:
-	      supported = _mesa_is_desktop_gl(state->ctx) &&
-			  ((unsigned) $2) <= state->ctx->Const.GLSLVersion;
-	      break;
-	   default:
-	      supported = false;
-	      break;
-	   }
-
-	   state->language_version = $2;
-
-	   if (!supported) {
-	      _mesa_glsl_error(& @2, state, "%s is not supported. "
-			       "Supported versions are: %s\n",
-			       state->get_version_string(),
-			       state->supported_version_string);
-	   }
-
-	   if (state->language_version >= 140) {
-	      state->ARB_uniform_buffer_object_enable = true;
-	   }
+           state->process_version_directive(&@2, $2);
 	}
 	;
 
diff --git a/src/glsl/glsl_parser_extras.cpp b/src/glsl/glsl_parser_extras.cpp
index 14589b0..cc33a07 100644
--- a/src/glsl/glsl_parser_extras.cpp
+++ b/src/glsl/glsl_parser_extras.cpp
@@ -174,6 +174,58 @@ _mesa_glsl_parse_state::check_version(unsigned required_glsl_version,
    return false;
 }
 
+/**
+ * Process a GLSL #version directive.
+ *
+ * \param version is the integer that follows the #version token.
+ */
+void
+_mesa_glsl_parse_state::process_version_directive(YYLTYPE *locp, int version)
+{
+   bool supported = false;
+
+   switch (version) {
+   case 100:
+      this->es_shader = true;
+      supported = this->ctx->API == API_OPENGLES2 ||
+         this->ctx->Extensions.ARB_ES2_compatibility;
+      break;
+   case 110:
+   case 120:
+      /* FINISHME: Once the OpenGL 3.0 'forward compatible' context or
+       * the OpenGL 3.2 Core context is supported, this logic will need
+       * change.  Older versions of GLSL are no longer supported
+       * outside the compatibility contexts of 3.x.
+       */
+   case 130:
+   case 140:
+   case 150:
+   case 330:
+   case 400:
+   case 410:
+   case 420:
+      supported = _mesa_is_desktop_gl(this->ctx) &&
+         ((unsigned) version) <= this->ctx->Const.GLSLVersion;
+      break;
+   default:
+      supported = false;
+      break;
+   }
+
+   this->language_version = version;
+
+   if (!supported) {
+      _mesa_glsl_error(locp, this, "%s is not supported. "
+                       "Supported versions are: %s\n",
+                       this->get_version_string(),
+                       this->supported_version_string);
+   }
+
+   if (this->language_version >= 140) {
+      this->ARB_uniform_buffer_object_enable = true;
+   }
+}
+
 const char *
 _mesa_glsl_shader_target_name(enum _mesa_glsl_parser_targets target)
 {
diff --git a/src/glsl/glsl_parser_extras.h b/src/glsl/glsl_parser_extras.h
index 20ed7b8..5ee7bc1 100644
--- a/src/glsl/glsl_parser_extras.h
+++ b/src/glsl/glsl_parser_extras.h
@@ -136,6 +136,8 @@ struct _mesa_glsl_parse_state {
       return check_version(130, 300, locp, "bit-wise operations are forbidden");
    }
 
+   void process_version_directive(YYLTYPE *locp, int version);
+
    struct gl_context *const ctx;
    void *scanner;
    exec_list translation_unit;
-- 
1.7.11.7



More information about the mesa-dev mailing list