glsl: force creation of new scope for for-loop body
authorBrian Paul <brianp@vmware.com>
Sat, 10 Jan 2009 18:40:20 +0000 (11:40 -0700)
committerBrian Paul <brianp@vmware.com>
Sat, 10 Jan 2009 18:40:20 +0000 (11:40 -0700)
Fixes regression in progs/demos/convolution.c due to loop unrolling.
This also allows the following to be compiled correctly:
for (int i = 0; i < n; i++) {
   int i;
   ...
}
This fix is a bit of a hack, however.  The better fix would be to change
the slang_shader.syn grammar.  Will revisit that...

src/mesa/shader/slang/slang_compile.c

index ec27fc69dffd043aaedb48e5f3faafffa1d1e03d..add8594ff954d04b626c84534804afb27813e6a4 100644 (file)
@@ -1138,8 +1138,26 @@ parse_statement(slang_parse_ctx * C, slang_output_ctx * O,
             RETURN0;
          if (!parse_child_operation(C, &o, oper, GL_FALSE))
             RETURN0;
+#if 0
          if (!parse_child_operation(C, &o, oper, GL_TRUE))
             RETURN0;
+#else
+         /* force creation of new scope for loop body */
+         {
+            slang_operation *ch;
+            slang_output_ctx oo = o;
+
+            /* grow child array */
+            ch = slang_operation_grow(&oper->num_children, &oper->children);
+            ch->type = SLANG_OPER_BLOCK_NEW_SCOPE;
+
+            ch->locals->outer_scope = o.vars;
+            oo.vars = ch->locals;
+
+            if (!parse_child_operation(C, &oo, ch, GL_TRUE))
+               RETURN0;
+         }
+#endif
       }
       break;
    case OP_PRECISION: