mirror of
https://github.com/DarkPlacesEngine/gmqcc.git
synced 2025-01-18 14:21:36 +00:00
ftepp_macro_call/ftepp_skipallwhite
This commit is contained in:
parent
0bd0a430d6
commit
5f287fc476
1 changed files with 42 additions and 1 deletions
43
ftepp.c
43
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);
|
||||
|
|
Loading…
Reference in a new issue