From: Wolfgang (Blub) Bumiller Date: Fri, 16 Nov 2012 19:46:52 +0000 (+0100) Subject: ftepp_macro_call/ftepp_skipallwhite X-Git-Tag: 0.1.9~404^2~43 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=5f287fc47652957ec0f6990ba29bbcc959658109;p=xonotic%2Fgmqcc.git ftepp_macro_call/ftepp_skipallwhite --- diff --git a/ftepp.c b/ftepp.c index 04e41bb..cd42217 100644 --- a/ftepp.c +++ b/ftepp.c @@ -175,6 +175,21 @@ static bool ftepp_skipspace(ftepp_t *ftepp) return true; } +/* this one skips EOLs as well */ +static bool ftepp_skipallwhite(ftepp_t *ftepp) +{ + if (ftepp->token != TOKEN_WHITE && ftepp->token != TOKEN_EOL) + return true; + do { + ftepp_next(ftepp); + } while (ftepp->token == TOKEN_WHITE || ftepp->token == TOKEN_EOL); + if (ftepp->token >= TOKEN_EOF) { + ftepp_error(ftepp, "unexpected end of preprocessor directive"); + return false; + } + return true; +} + /** * The huge macro parsing code... */ @@ -263,6 +278,19 @@ static bool ftepp_define(ftepp_t *ftepp) return true; } +static bool ftepp_macro_call(ftepp_t *ftepp, ppmacro *macro) +{ + ftepp_next(ftepp); + if (!ftepp_skipallwhite(ftepp)) + return false; + return true; +} + +/** + * When a macro is used we have to handle parameters as well + * as special-concatenation via ## or stringification via # + */ + /** * #if - the FTEQCC way: * defined(FOO) => true if FOO was #defined regardless of parameters or contents @@ -595,7 +623,8 @@ static void ftepp_out(ftepp_t *ftepp, const char *str, bool ignore_cond) static bool ftepp_preprocess(ftepp_t *ftepp) { - bool newline = true; + ppmacro *macro; + bool newline = true; ftepp->lex->flags.preprocessing = true; ftepp->lex->flags.mergelines = false; @@ -611,6 +640,18 @@ static bool ftepp_preprocess(ftepp_t *ftepp) newline = false; switch (ftepp->token) { + case TOKEN_KEYWORD: + case TOKEN_IDENT: + case TOKEN_TYPENAME: + macro = ftepp_macro_find(ftepp, ftepp_tokval(ftepp)); + if (!macro) { + ftepp_out(ftepp, ftepp_tokval(ftepp), false); + ftepp_next(ftepp); + break; + } + if (!ftepp_macro_call(ftepp, macro)) + ftepp->token = TOKEN_ERROR; + break; case '#': if (!ftepp->newline) { ftepp_out(ftepp, ftepp_tokval(ftepp), false);