From: Ian Romanick Date: Fri, 19 Mar 2010 22:34:13 +0000 (-0700) Subject: Use separate namespaces for types, variables, and functions X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=38395c1aad82abdeecbd66bca8daaa6f431c920c;p=mesa.git Use separate namespaces for types, variables, and functions This will allow types and their constructors to be easily stored in the same symbol table. This does add a potential problem that a shader could declare a variable and a function with the same name. This appears to be forbidden by the GLSL spec. --- diff --git a/glsl_symbol_table.h b/glsl_symbol_table.h index 482507cf671..ad3ccf06efe 100644 --- a/glsl_symbol_table.h +++ b/glsl_symbol_table.h @@ -37,6 +37,13 @@ * type safe and some symbol table invariants. */ class glsl_symbol_table { +private: + enum glsl_symbol_name_space { + glsl_variable_name_space = 0, + glsl_type_name_space = 1, + glsl_function_name_space = 2 + }; + public: glsl_symbol_table() { @@ -68,17 +75,20 @@ public: /*@{*/ bool add_variable(const char *name, ir_variable *v) { - return _mesa_symbol_table_add_symbol(table, 0, name, v) == 0; + return _mesa_symbol_table_add_symbol(table, glsl_variable_name_space, + name, v) == 0; } bool add_type(const char *name, const glsl_type *t) { - return _mesa_symbol_table_add_symbol(table, 0, name, (void *) t) == 0; + return _mesa_symbol_table_add_symbol(table, glsl_type_name_space, + name, (void *) t) == 0; } bool add_function(const char *name, ir_function *f) { - return _mesa_symbol_table_add_symbol(table, 0, name, f) == 0; + return _mesa_symbol_table_add_symbol(table, glsl_function_name_space, + name, f) == 0; } /*@}*/ @@ -88,17 +98,20 @@ public: /*@{*/ ir_variable *get_variable(const char *name) { - return (ir_variable *) _mesa_symbol_table_find_symbol(table, 0, name); + return (ir_variable *) + _mesa_symbol_table_find_symbol(table, glsl_variable_name_space, name); } glsl_type *get_type(const char *name) { - return (glsl_type *) _mesa_symbol_table_find_symbol(table, 0, name); + return (glsl_type *) + _mesa_symbol_table_find_symbol(table, glsl_type_name_space, name); } ir_function *get_function(const char *name) { - return (ir_function *) _mesa_symbol_table_find_symbol(table, 0, name); + return (ir_function *) + _mesa_symbol_table_find_symbol(table, glsl_function_name_space, name); } /*@}*/