diff options
author | Michal Krol <[email protected]> | 2009-06-26 12:26:05 +0200 |
---|---|---|
committer | Michal Krol <[email protected]> | 2009-09-07 10:11:52 +0200 |
commit | a294715612d14d64e12026361ff7cc29321607d6 (patch) | |
tree | 34f6fdc5ad039a504b7f99eba340b3668225af32 /src/glsl/pp/sl_pp_macro.c | |
parent | 153b179862411e9de14d26bbcff16bc81f1edc91 (diff) |
glsl: Allow for preprocessor macro redefinition.
Diffstat (limited to 'src/glsl/pp/sl_pp_macro.c')
-rw-r--r-- | src/glsl/pp/sl_pp_macro.c | 45 |
1 files changed, 33 insertions, 12 deletions
diff --git a/src/glsl/pp/sl_pp_macro.c b/src/glsl/pp/sl_pp_macro.c index a8412f0651c..a82c30cb167 100644 --- a/src/glsl/pp/sl_pp_macro.c +++ b/src/glsl/pp/sl_pp_macro.c @@ -30,6 +30,15 @@ #include "sl_pp_process.h" +static void +_macro_init(struct sl_pp_macro *macro) +{ + macro->name = -1; + macro->num_args = -1; + macro->arg = NULL; + macro->body = NULL; +} + struct sl_pp_macro * sl_pp_macro_new(void) { @@ -37,33 +46,45 @@ sl_pp_macro_new(void) macro = calloc(1, sizeof(struct sl_pp_macro)); if (macro) { - macro->name = -1; - macro->num_args = -1; + _macro_init(macro); } return macro; } +static void +_macro_destroy(struct sl_pp_macro *macro) +{ + struct sl_pp_macro_formal_arg *arg = macro->arg; + + while (arg) { + struct sl_pp_macro_formal_arg *next_arg = arg->next; + + free(arg); + arg = next_arg; + } + + free(macro->body); +} + void sl_pp_macro_free(struct sl_pp_macro *macro) { while (macro) { struct sl_pp_macro *next_macro = macro->next; - struct sl_pp_macro_formal_arg *arg = macro->arg; - - while (arg) { - struct sl_pp_macro_formal_arg *next_arg = arg->next; - - free(arg); - arg = next_arg; - } - - free(macro->body); + _macro_destroy(macro); free(macro); macro = next_macro; } } +void +sl_pp_macro_reset(struct sl_pp_macro *macro) +{ + _macro_destroy(macro); + _macro_init(macro); +} + static void skip_whitespace(const struct sl_pp_token_info *input, unsigned int *pi) |