summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Romanick <ian.d.romanick@intel.com>2010-03-29 12:59:02 -0700
committerIan Romanick <ian.d.romanick@intel.com>2010-03-29 12:59:02 -0700
commit17d86f4371da413176ba365ca26a58bac172d365 (patch)
tree1163a6e651e42e69d5b8c43b3859a3d165cbb9c5
parent521c2983b43570ece73d9377f812baa6bcaf94d3 (diff)
Add a variable to the symbol table after processing the initializer
-rw-r--r--ast_to_hir.cpp17
1 files changed, 13 insertions, 4 deletions
diff --git a/ast_to_hir.cpp b/ast_to_hir.cpp
index e16f79f6f2..7b1db0c481 100644
--- a/ast_to_hir.cpp
+++ b/ast_to_hir.cpp
@@ -981,10 +981,6 @@ ast_declarator_list::hir(exec_list *instructions,
continue;
}
- const bool added_variable =
- state->symbols->add_variable(decl->identifier, var);
- assert(added_variable);
-
instructions->push_tail(var);
if (decl->initializer != NULL) {
@@ -1028,6 +1024,19 @@ ast_declarator_list::hir(exec_list *instructions,
this->get_location());
}
}
+
+ /* Add the vairable to the symbol table after processing the initializer.
+ * This differs from most C-like languages, but it follows the GLSL
+ * specification. From page 28 (page 34 of the PDF) of the GLSL 1.50
+ * spec:
+ *
+ * "Within a declaration, the scope of a name starts immediately
+ * after the initializer if present or immediately after the name
+ * being declared if not."
+ */
+ const bool added_variable =
+ state->symbols->add_variable(decl->identifier, var);
+ assert(added_variable);
}
/* Variable declarations do not have r-values.