glsl: Compute version_string on the fly.
authorPaul Berry <stereotype441@gmail.com>
Thu, 2 Aug 2012 13:45:30 +0000 (06:45 -0700)
committerIan Romanick <ian.d.romanick@intel.com>
Thu, 6 Dec 2012 20:13:21 +0000 (12:13 -0800)
Fixes a bug where version_string would be left uninitialized if no
GLSL "#version" directive was used.

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Acked-by: Carl Worth <cworth@cworth.org>
src/glsl/ast_to_hir.cpp
src/glsl/glsl_parser.yy
src/glsl/glsl_parser_extras.h

index 75b551b2db44641cd8a199f4f09a5382e5030413..adada30509eef6856159c9401d06677405c68140 100644 (file)
@@ -449,7 +449,7 @@ modulus_result_type(const struct glsl_type *type_a,
    if (state->language_version < 130) {
       _mesa_glsl_error(loc, state,
                        "operator '%%' is reserved in %s",
-                       state->version_string);
+                       state->get_version_string());
       return glsl_type::error_type;
    }
 
@@ -2618,13 +2618,13 @@ ast_declarator_list::hir(exec_list *instructions,
            _mesa_glsl_error(& loc, state,
                             "`out' qualifier in declaration of `%s' "
                             "only valid for function parameters in %s.",
-                            decl->identifier, state->version_string);
+                            decl->identifier, state->get_version_string());
         }
         if (this->type->qualifier.flags.q.in) {
            _mesa_glsl_error(& loc, state,
                             "`in' qualifier in declaration of `%s' "
                             "only valid for function parameters in %s.",
-                            decl->identifier, state->version_string);
+                            decl->identifier, state->get_version_string());
         }
         /* FINISHME: Test for other invalid qualifiers. */
       }
index 03e05ff1bf31559876f9d71e4b6b516a95b0c7ac..e68a601c89e5fd06c5a097dc4794bd1cc31258a1 100644 (file)
@@ -289,14 +289,11 @@ version_statement:
           }
 
           state->language_version = $2;
-          state->version_string =
-              glsl_compute_version_string(state, state->es_shader,
-                                          state->language_version);
 
           if (!supported) {
              _mesa_glsl_error(& @2, state, "%s is not supported. "
                               "Supported versions are: %s\n",
-                              state->version_string,
+                              state->get_version_string(),
                               state->supported_version_string);
           }
 
@@ -316,7 +313,7 @@ pragma_statement:
           if (state->language_version == 110) {
              _mesa_glsl_warning(& @1, state,
                                 "pragma `invariant(all)' not supported in %s",
-                                state->version_string);
+                                state->get_version_string());
           } else {
              state->all_invariant = true;
           }
@@ -1501,7 +1498,7 @@ precision_qualifier:
                                         "precision qualifier forbidden "
                                         "in %s (1.30 or later "
                                         "required)\n",
-                                        state->version_string);
+                                        state->get_version_string());
 
                     $$ = ast_precision_high;
                  }
@@ -1511,7 +1508,7 @@ precision_qualifier:
                                         "precision qualifier forbidden "
                                         "in %s (1.30 or later "
                                         "required)\n",
-                                        state->version_string);
+                                        state->get_version_string());
 
                     $$ = ast_precision_medium;
                  }
@@ -1521,7 +1518,7 @@ precision_qualifier:
                                         "precision qualifier forbidden "
                                         "in %s (1.30 or later "
                                         "required)\n",
-                                        state->version_string);
+                                        state->get_version_string());
 
                     $$ = ast_precision_low;
                  }
index 5bad5a94d3cffc782d213500fd827914c452b241..26fdee1c14d44a779ca3ffd2ff5155a62c1ca13c 100644 (file)
@@ -80,6 +80,16 @@ struct _mesa_glsl_parse_state {
       ralloc_free(mem);
    }
 
+   /**
+    * Generate a string representing the GLSL version currently being compiled
+    * (useful for error messages).
+    */
+   const char *get_version_string()
+   {
+      return glsl_compute_version_string(this, this->es_shader,
+                                         this->language_version);
+   }
+
    struct gl_context *const ctx;
    void *scanner;
    exec_list translation_unit;
@@ -91,7 +101,6 @@ struct _mesa_glsl_parse_state {
 
    bool es_shader;
    unsigned language_version;
-   const char *version_string;
    enum _mesa_glsl_parser_targets target;
 
    /**