glsl: Fix symbol replacement handling in preprocessor.
authorMichal Krol <michal@vmware.com>
Wed, 10 Jun 2009 10:15:13 +0000 (12:15 +0200)
committerMichal Krol <michal@vmware.com>
Wed, 10 Jun 2009 10:15:13 +0000 (12:15 +0200)
src/mesa/shader/slang/slang_preprocess.c

index f9390f75047d47890ffbbb31f807df79ad598ced..15cd1ece7da800a42dc1e4535a537057a74e01d7 100644 (file)
@@ -1012,8 +1012,6 @@ preprocess_source (slang_string *output, const char *source,
          case TOKEN_DEFINE:
             {
                pp_symbol *symbol = NULL;
-               slang_string replacement;
-               expand_state es;
 
                /* Parse macro name. */
                id = (const char *) (&prod[i]);
@@ -1055,21 +1053,25 @@ preprocess_source (slang_string *output, const char *source,
                id = (const char *) (&prod[i]);
                idlen = _mesa_strlen (id);
                if (state.cond.top->effective) {
+                  slang_string replacement;
+                  expand_state es;
+
                   pp_annotate (output, ") %s", id);
-               }
-               slang_string_init(&replacement);
-               slang_string_pushs(&replacement, id, idlen);
-               i += idlen + 1;
 
-               /* Expand macro replacement. */
-               es.output = &symbol->replacement;
-               es.input = slang_string_cstr(&replacement);
-               es.state = &state;
-               if (!expand(&es, &state.symbols)) {
+                  slang_string_init(&replacement);
+                  slang_string_pushs(&replacement, id, idlen);
+
+                  /* Expand macro replacement. */
+                  es.output = &symbol->replacement;
+                  es.input = slang_string_cstr(&replacement);
+                  es.state = &state;
+                  if (!expand(&es, &state.symbols)) {
+                     slang_string_free(&replacement);
+                     goto error;
+                  }
                   slang_string_free(&replacement);
-                  goto error;
                }
-               slang_string_free(&replacement);
+               i += idlen + 1;
             }
             break;