From 654eceb33b73a0c81f1d6fa15d14ba60aa973d35 Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Wed, 2 Jan 2013 17:23:49 +0100 Subject: [PATCH 1/2] Allow unary minus in ftepp_if_value --- ftepp.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/ftepp.c b/ftepp.c index 426bfc1..ecc36d8 100644 --- a/ftepp.c +++ b/ftepp.c @@ -788,6 +788,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; @@ -799,6 +800,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: @@ -855,6 +864,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: @@ -878,8 +888,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); From 6c076f99f642766814d14ce408bc234c8bad7427 Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Wed, 2 Jan 2013 17:38:24 +0100 Subject: [PATCH 2/2] lex->flags.preprocessing causes the lexer to parse the unary number if it is one --- lexer.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lexer.c b/lexer.c index 5e0414b..64cdb3d 100644 --- a/lexer.c +++ b/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);