r300: move some more function to generic
[mesa.git] / src / mesa / shader / slang / slang_compile_operation.c
index 4d2fd5b6667f75a413753bd4a3b35a81ed515094..53cf6faff9796a7b009bfe5591a2cd1913024f2d 100644 (file)
@@ -28,7 +28,7 @@
  * \author Michal Krol
  */
 
-#include "imports.h"
+#include "main/imports.h"
 #include "slang_compile.h"
 #include "slang_mem.h"
 
@@ -80,10 +80,23 @@ slang_replace_scope(slang_operation *oper,
                     slang_variable_scope *newScope)
 {
    GLuint i;
+
    if (oper->locals != newScope &&
        oper->locals->outer_scope == oldScope) {
+      /* found.  replace old w/ new */
       oper->locals->outer_scope = newScope;
    }
+
+   if (oper->type == SLANG_OPER_VARIABLE_DECL) {
+      /* search/replace in the initializer */
+      slang_variable *var;
+      var = _slang_locate_variable(oper->locals, oper->a_id, GL_TRUE);
+      if (var && var->initializer) {
+         slang_replace_scope(var->initializer, oldScope, newScope);
+      }
+   }
+
+   /* search/replace in children */
    for (i = 0; i < oper->num_children; i++) {
       slang_replace_scope(&oper->children[i], oldScope, newScope);
    }
@@ -148,7 +161,9 @@ slang_operation_copy(slang_operation * x, const slang_operation * y)
    /* If this operation declares a new scope, we need to make sure
     * all children point to it, not the original operation's scope!
     */
-   if (x->type == SLANG_OPER_BLOCK_NEW_SCOPE) {
+   if (x->type == SLANG_OPER_BLOCK_NEW_SCOPE ||
+       x->type == SLANG_OPER_WHILE ||
+       x->type == SLANG_OPER_FOR) {
       slang_replace_scope(x, y->locals, x->locals);
    }