[Mesa-dev] [PATCH 02/26] glsl: Simplify symbol table version checking.

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


From: Paul Berry <stereotype441 at gmail.com>

Previously, we stored the GLSL language version in the
glsl_symbol_table struct.  But this was unnecessary--all
glsl_symbol_table needs to know is whether functions and variables
have separate namespaces (they do in GLSL 1.10 only).

Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>
---
 src/glsl/ast_function.cpp                    | 3 ++-
 src/glsl/ast_to_hir.cpp                      | 2 +-
 src/glsl/builtins/tools/generate_builtins.py | 2 +-
 src/glsl/glsl_symbol_table.cpp               | 6 +++---
 src/glsl/glsl_symbol_table.h                 | 3 ++-
 5 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/src/glsl/ast_function.cpp b/src/glsl/ast_function.cpp
index ea3282c..c0e05ad 100644
--- a/src/glsl/ast_function.cpp
+++ b/src/glsl/ast_function.cpp
@@ -324,7 +324,8 @@ match_function_by_name(const char *name,
       goto done; /* no match */
 
    /* Is the function hidden by a variable (impossible in 1.10)? */
-   if (state->language_version != 110 && state->symbols->get_variable(name))
+   if (!state->symbols->separate_function_namespace
+       && state->symbols->get_variable(name))
       goto done; /* no match */
 
    if (f != NULL) {
diff --git a/src/glsl/ast_to_hir.cpp b/src/glsl/ast_to_hir.cpp
index d450aa1..75b551b 100644
--- a/src/glsl/ast_to_hir.cpp
+++ b/src/glsl/ast_to_hir.cpp
@@ -66,7 +66,7 @@ _mesa_ast_to_hir(exec_list *instructions, struct _mesa_glsl_parse_state *state)
 {
    _mesa_glsl_initialize_variables(instructions, state);
 
-   state->symbols->language_version = state->language_version;
+   state->symbols->separate_function_namespace = state->language_version == 110;
 
    state->current_function = NULL;
 
diff --git a/src/glsl/builtins/tools/generate_builtins.py b/src/glsl/builtins/tools/generate_builtins.py
index d7c393e..cd6229e 100755
--- a/src/glsl/builtins/tools/generate_builtins.py
+++ b/src/glsl/builtins/tools/generate_builtins.py
@@ -183,7 +183,7 @@ read_builtins(GLenum target, const char *protos, const char **functions, unsigne
       new(sh) _mesa_glsl_parse_state(&fakeCtx, target, sh);
 
    st->language_version = 140;
-   st->symbols->language_version = 140;
+   st->symbols->separate_function_namespace = false;
    st->ARB_texture_rectangle_enable = true;
    st->EXT_texture_array_enable = true;
    st->OES_EGL_image_external_enable = true;
diff --git a/src/glsl/glsl_symbol_table.cpp b/src/glsl/glsl_symbol_table.cpp
index bcb65d3..f934ea8 100644
--- a/src/glsl/glsl_symbol_table.cpp
+++ b/src/glsl/glsl_symbol_table.cpp
@@ -52,7 +52,7 @@ public:
 
 glsl_symbol_table::glsl_symbol_table()
 {
-   this->language_version = 120;
+   this->separate_function_namespace = false;
    this->table = _mesa_symbol_table_ctor();
    this->mem_ctx = ralloc_context(NULL);
 }
@@ -80,7 +80,7 @@ bool glsl_symbol_table::name_declared_this_scope(const char *name)
 
 bool glsl_symbol_table::add_variable(ir_variable *v)
 {
-   if (this->language_version == 110) {
+   if (this->separate_function_namespace) {
       /* In 1.10, functions and variables have separate namespaces. */
       symbol_table_entry *existing = get_entry(v->name);
       if (name_declared_this_scope(v->name)) {
@@ -120,7 +120,7 @@ bool glsl_symbol_table::add_type(const char *name, const glsl_type *t)
 
 bool glsl_symbol_table::add_function(ir_function *f)
 {
-   if (this->language_version == 110 && name_declared_this_scope(f->name)) {
+   if (this->separate_function_namespace && name_declared_this_scope(f->name)) {
       /* In 1.10, functions and variables have separate namespaces. */
       symbol_table_entry *existing = get_entry(f->name);
       if ((existing->f == NULL) && (existing->t == NULL)) {
diff --git a/src/glsl/glsl_symbol_table.h b/src/glsl/glsl_symbol_table.h
index 637bc03..9f56027 100644
--- a/src/glsl/glsl_symbol_table.h
+++ b/src/glsl/glsl_symbol_table.h
@@ -77,7 +77,8 @@ public:
    glsl_symbol_table();
    ~glsl_symbol_table();
 
-   unsigned int language_version;
+   /* In 1.10, functions and variables have separate namespaces. */
+   bool separate_function_namespace;
 
    void push_scope();
    void pop_scope();
-- 
1.7.11.7



More information about the mesa-dev mailing list