Merge remote-tracking branch 'origin/pp-unary-numbers'

This commit is contained in:
Wolfgang Bumiller 2013-01-03 14:58:02 +01:00
commit 9edae7fa0a
2 changed files with 25 additions and 0 deletions

14
ftepp.c
View file

@ -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
View file

@ -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);