mirror of
https://github.com/DarkPlacesEngine/gmqcc.git
synced 2025-03-22 10:41:43 +00:00
Merge remote-tracking branch 'origin/pp-unary-numbers'
This commit is contained in:
commit
9edae7fa0a
2 changed files with 25 additions and 0 deletions
14
ftepp.c
14
ftepp.c
|
@ -822,6 +822,7 @@ static bool ftepp_if_value(ftepp_t *ftepp, bool *out, double *value_out)
|
|||
{
|
||||
ppmacro *macro;
|
||||
bool wasnot = false;
|
||||
bool wasneg = false;
|
||||
|
||||
if (!ftepp_skipspace(ftepp))
|
||||
return false;
|
||||
|
@ -833,6 +834,14 @@ static bool ftepp_if_value(ftepp_t *ftepp, bool *out, double *value_out)
|
|||
return false;
|
||||
}
|
||||
|
||||
if (ftepp->token == TOKEN_OPERATOR && !strcmp(ftepp_tokval(ftepp), "-"))
|
||||
{
|
||||
wasneg = true;
|
||||
ftepp_next(ftepp);
|
||||
if (!ftepp_skipspace(ftepp))
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (ftepp->token) {
|
||||
case TOKEN_IDENT:
|
||||
case TOKEN_TYPENAME:
|
||||
|
@ -889,6 +898,7 @@ static bool ftepp_if_value(ftepp_t *ftepp, bool *out, double *value_out)
|
|||
}
|
||||
break;
|
||||
case TOKEN_STRINGCONST:
|
||||
*value_out = 0;
|
||||
*out = false;
|
||||
break;
|
||||
case TOKEN_INTCONST:
|
||||
|
@ -912,8 +922,12 @@ static bool ftepp_if_value(ftepp_t *ftepp, bool *out, double *value_out)
|
|||
|
||||
default:
|
||||
ftepp_error(ftepp, "junk in #if: `%s` ...", ftepp_tokval(ftepp));
|
||||
if (opts.debug)
|
||||
ftepp_error(ftepp, "internal: token %i\n", ftepp->token);
|
||||
return false;
|
||||
}
|
||||
if (wasneg)
|
||||
*value_out = -*value_out;
|
||||
if (wasnot) {
|
||||
*out = !*out;
|
||||
*value_out = (*out ? 1 : 0);
|
||||
|
|
11
lexer.c
11
lexer.c
|
@ -1299,6 +1299,17 @@ int lex_do(lex_file *lex)
|
|||
lex_tokench(lex, nextch);
|
||||
lex_tokench(lex, thirdch);
|
||||
}
|
||||
}
|
||||
else if (lex->flags.preprocessing &&
|
||||
ch == '-' && isdigit(nextch))
|
||||
{
|
||||
lex->tok.ttype = lex_finish_digit(lex, nextch);
|
||||
if (lex->tok.ttype == TOKEN_INTCONST)
|
||||
lex->tok.constval.i = -lex->tok.constval.i;
|
||||
else
|
||||
lex->tok.constval.f = -lex->tok.constval.f;
|
||||
lex_endtoken(lex);
|
||||
return lex->tok.ttype;
|
||||
} else
|
||||
lex_ungetch(lex, nextch);
|
||||
|
||||
|
|
Loading…
Reference in a new issue