]> git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
Merge remote-tracking branch 'origin/pp-unary-numbers'
authorWolfgang Bumiller <blub@speed.at>
Thu, 3 Jan 2013 13:58:02 +0000 (14:58 +0100)
committerWolfgang Bumiller <blub@speed.at>
Thu, 3 Jan 2013 13:58:02 +0000 (14:58 +0100)
ftepp.c
lexer.c

diff --git a/ftepp.c b/ftepp.c
index ea686612cfd08156d65fe7326a29a205516779e6..838d0de38d37f9198fbe3fa2e795340e83c09394 100644 (file)
--- a/ftepp.c
+++ b/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);
diff --git a/lexer.c b/lexer.c
index 5e0414b5b9f075868ed9cf45852977e7240b6ed1..64cdb3d3cff06b7212c7caf4cc44472ebe700d1e 100644 (file)
--- 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);