summaryrefslogtreecommitdiff
path: root/ast_to_hir.cpp
diff options
context:
space:
mode:
authorIan Romanick <ian.d.romanick@intel.com>2010-04-23 13:24:08 -0700
committerIan Romanick <ian.d.romanick@intel.com>2010-04-28 18:22:54 -0700
commitab89927a91a0ea6ffdb56e5e75044472f7277f4a (patch)
treea7fe68f6ea019d0507c82d2f052480d911d5f3f1 /ast_to_hir.cpp
parent82baaf428308e83ad28ca0914c13af59e8a28374 (diff)
Reject conflicting struct declarations, generate struct constructor
Diffstat (limited to 'ast_to_hir.cpp')
-rw-r--r--ast_to_hir.cpp15
1 files changed, 14 insertions, 1 deletions
diff --git a/ast_to_hir.cpp b/ast_to_hir.cpp
index 704f274..a32805b 100644
--- a/ast_to_hir.cpp
+++ b/ast_to_hir.cpp
@@ -2346,7 +2346,20 @@ ast_struct_specifier::hir(exec_list *instructions,
glsl_type *t = new glsl_type(fields, decl_count, name);
- state->symbols->add_type(name, t);
+ YYLTYPE loc = this->get_location();
+ if (!state->symbols->add_type(name, t)) {
+ _mesa_glsl_error(& loc, state, "struct `%s' previously defined", name);
+ } else {
+ /* This logic is a bit tricky. It is an error to declare a structure at
+ * global scope if there is also a function with the same name.
+ */
+ if ((state->current_function == NULL)
+ && (state->symbols->get_function(name) != NULL)) {
+ _mesa_glsl_error(& loc, state, "name `%s' previously defined", name);
+ } else {
+ t->generate_constructor(state->symbols);
+ }
+ }
/* Structure type definitions do not have r-values.
*/