From dc9f9d8e66ac3ec934a82d25da7b76902f775802 Mon Sep 17 00:00:00 2001 From: Paul Berry Date: Thu, 2 Aug 2012 06:45:30 -0700 Subject: [PATCH] glsl: Compute version_string on the fly. Fixes a bug where version_string would be left uninitialized if no GLSL "#version" directive was used. Reviewed-by: Kenneth Graunke Acked-by: Carl Worth --- src/glsl/ast_to_hir.cpp | 6 +++--- src/glsl/glsl_parser.yy | 13 +++++-------- src/glsl/glsl_parser_extras.h | 11 ++++++++++- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/glsl/ast_to_hir.cpp b/src/glsl/ast_to_hir.cpp index 75b551b..adada30 100644 --- a/src/glsl/ast_to_hir.cpp +++ b/src/glsl/ast_to_hir.cpp @@ -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. */ } diff --git a/src/glsl/glsl_parser.yy b/src/glsl/glsl_parser.yy index 03e05ff..e68a601 100644 --- a/src/glsl/glsl_parser.yy +++ b/src/glsl/glsl_parser.yy @@ -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; } diff --git a/src/glsl/glsl_parser_extras.h b/src/glsl/glsl_parser_extras.h index 5bad5a9..26fdee1 100644 --- a/src/glsl/glsl_parser_extras.h +++ b/src/glsl/glsl_parser_extras.h @@ -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; /** -- 2.7.4