glsl: Expand nested preprocessor macros.
authorBrian Paul <brianp@vmware.com>
Tue, 9 Jun 2009 15:14:38 +0000 (09:14 -0600)
committerBrian Paul <brianp@vmware.com>
Tue, 9 Jun 2009 15:14:38 +0000 (09:14 -0600)
(cherry picked from master, commit ef8caec29ae73bb2bbeb48f0578d839ef29348cd)

src/mesa/shader/slang/slang_preprocess.c

index fd98fae360baf36789fdd52b27696ec0f053bd6a..0e95cdb525e341093fbc783780985b055b160bf9 100644 (file)
@@ -1012,6 +1012,8 @@ 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]);
@@ -1054,9 +1056,20 @@ preprocess_source (slang_string *output, const char *source,
                idlen = _mesa_strlen (id);
                if (state.cond.top->effective) {
                   pp_annotate (output, ") %s", id);
-                  slang_string_pushs (&symbol->replacement, id, idlen);
                }
+               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_free(&replacement);
+                  goto error;
+               }
+               slang_string_free(&replacement);
             }
             break;