recursively call the preprocessor on expanded macros

This commit is contained in:
Wolfgang (Blub) Bumiller 2012-11-16 22:31:51 +01:00
parent 05a26333fc
commit 57ac55ad01

22
ftepp.c
View file

@ -325,6 +325,7 @@ static void macroparam_clean(macroparam *self)
vec_free(self->tokens); vec_free(self->tokens);
} }
/* need to leave the last token up */
static bool ftepp_macro_call_params(ftepp_t *ftepp, macroparam **out_params) static bool ftepp_macro_call_params(ftepp_t *ftepp, macroparam **out_params)
{ {
macroparam *params = NULL; macroparam *params = NULL;
@ -367,10 +368,12 @@ static bool ftepp_macro_call_params(ftepp_t *ftepp, macroparam **out_params)
goto on_error; goto on_error;
} }
} }
/* need to leave that up
if (ftepp_next(ftepp) >= TOKEN_EOF) { if (ftepp_next(ftepp) >= TOKEN_EOF) {
ftepp_error(ftepp, "unexpected EOF in macro call"); ftepp_error(ftepp, "unexpected EOF in macro call");
goto on_error; goto on_error;
} }
*/
*out_params = params; *out_params = params;
return true; return true;
@ -395,13 +398,16 @@ static bool macro_params_find(ppmacro *macro, const char *name, size_t *idx)
return false; return false;
} }
static bool ftepp_preprocess(ftepp_t *ftepp);
static bool ftepp_macro_expand(ftepp_t *ftepp, ppmacro *macro, macroparam *params) static bool ftepp_macro_expand(ftepp_t *ftepp, ppmacro *macro, macroparam *params)
{ {
char *old_string = ftepp->output; char *old_string = ftepp->output;
bool old_string_flag = ftepp->output_string; bool old_string_flag = ftepp->output_string;
lex_file *old_lexer = ftepp->lex;
bool retval = true; bool retval = true;
size_t o, pi, pv; size_t o, pi, pv;
lex_file *inlex;
/* really ... */ /* really ... */
if (!vec_size(macro->output)) if (!vec_size(macro->output))
@ -437,10 +443,23 @@ static bool ftepp_macro_expand(ftepp_t *ftepp, ppmacro *macro, macroparam *param
} }
} }
vec_push(ftepp->output, 0); vec_push(ftepp->output, 0);
printf("_________________\n%s\n=================\n", ftepp->output); /* Now run the preprocessor recursively on this string buffer */
inlex = lex_open_string(ftepp->output, vec_size(ftepp->output)-1, ftepp->lex->name);
if (!inlex) {
ftepp_error(ftepp, "internal error: failed to instantiate lexer");
retval = false;
goto cleanup; goto cleanup;
}
ftepp->output = old_string;
ftepp->output_string = old_string_flag;
ftepp->lex = inlex;
if (!ftepp_preprocess(ftepp)) {
retval = false;
goto cleanup;
}
cleanup: cleanup:
ftepp->lex = old_lexer;
ftepp->output = old_string; ftepp->output = old_string;
ftepp->output_string = old_string_flag; ftepp->output_string = old_string_flag;
return retval; return retval;
@ -483,6 +502,7 @@ static bool ftepp_macro_call(ftepp_t *ftepp, ppmacro *macro)
if (!ftepp_macro_expand(ftepp, macro, params)) if (!ftepp_macro_expand(ftepp, macro, params))
retval = false; retval = false;
ftepp_next(ftepp);
cleanup: cleanup:
for (o = 0; o < vec_size(params); ++o) for (o = 0; o < vec_size(params); ++o)