]> git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
Lexer should keep newlines in merged lines, so will the preprocessor, but therefore...
authorWolfgang (Blub) Bumiller <blub@speed.at>
Fri, 16 Nov 2012 22:13:53 +0000 (23:13 +0100)
committerWolfgang (Blub) Bumiller <blub@speed.at>
Fri, 16 Nov 2012 22:13:53 +0000 (23:13 +0100)
ftepp.c
lexer.c

diff --git a/ftepp.c b/ftepp.c
index 1a2ff21f6aa69881ea148e90000ddcaefc631481..59ec54504402efdfdbf70c737405e5d4f73f07bd 100644 (file)
--- a/ftepp.c
+++ b/ftepp.c
@@ -114,10 +114,13 @@ static pptoken *pptoken_make(ftepp_t *ftepp)
 {
     pptoken *token = (pptoken*)mem_a(sizeof(pptoken));
     token->token = ftepp->token;
+#if 0
     if (token->token == TOKEN_WHITE)
         token->value = util_strdup(" ");
     else
+#else
         token->value = util_strdup(ftepp_tokval(ftepp));
+#endif
     memcpy(&token->constval, &ftepp->lex->tok.constval, sizeof(token->constval));
     return token;
 }
@@ -312,7 +315,7 @@ static bool ftepp_define(ftepp_t *ftepp)
         case TOKEN_TYPENAME:
         case TOKEN_KEYWORD:
             macro = ftepp_macro_find(ftepp, ftepp_tokval(ftepp));
-            if (macro) {
+            if (macro && ftepp->output_on) {
                 if (ftepp_warn(ftepp, WARN_PREPROCESSOR, "redefining `%s`", ftepp_tokval(ftepp)))
                     return false;
                 ftepp_macro_delete(ftepp, ftepp_tokval(ftepp));
@@ -338,7 +341,11 @@ static bool ftepp_define(ftepp_t *ftepp)
     if (!ftepp_define_body(ftepp, macro))
         return false;
 
-    vec_push(ftepp->macros, macro);
+    if (ftepp->output_on)
+        vec_push(ftepp->macros, macro);
+    else {
+        ppmacro_delete(macro);
+    }
     return true;
 }
 
@@ -767,15 +774,17 @@ static bool ftepp_undef(ftepp_t *ftepp)
     if (!ftepp_skipspace(ftepp))
         return false;
 
-    switch (ftepp->token) {
-        case TOKEN_IDENT:
-        case TOKEN_TYPENAME:
-        case TOKEN_KEYWORD:
-            ftepp_macro_delete(ftepp, ftepp_tokval(ftepp));
-            break;
-        default:
-            ftepp_error(ftepp, "expected macro name");
-            return false;
+    if (ftepp->output_on) {
+        switch (ftepp->token) {
+            case TOKEN_IDENT:
+            case TOKEN_TYPENAME:
+            case TOKEN_KEYWORD:
+                ftepp_macro_delete(ftepp, ftepp_tokval(ftepp));
+                break;
+            default:
+                ftepp_error(ftepp, "expected macro name");
+                return false;
+        }
     }
 
     (void)ftepp_next(ftepp);
diff --git a/lexer.c b/lexer.c
index 8558404f1dfbc17a7ffd80855cb0c052835f2beb..de09bfa2f4b85848dfba2bb0b28b444b809fe8c9 100644 (file)
--- a/lexer.c
+++ b/lexer.c
@@ -412,13 +412,17 @@ static int lex_skipwhite(lex_file *lex)
 
                 if (lex->flags.preprocessing) {
                     haswhite = true;
+                    /*
                     lex_tokench(lex, '/');
                     lex_tokench(lex, '/');
+                    */
+                    lex_tokench(lex, ' ');
+                    lex_tokench(lex, ' ');
                 }
 
                 while (ch != EOF && ch != '\n') {
                     if (lex->flags.preprocessing)
-                        lex_tokench(lex, ch);
+                        lex_tokench(lex, ' '); /* ch); */
                     ch = lex_getch(lex);
                 }
                 if (lex->flags.preprocessing) {
@@ -433,8 +437,12 @@ static int lex_skipwhite(lex_file *lex)
                 /* multiline comment */
                 if (lex->flags.preprocessing) {
                     haswhite = true;
+                    /*
                     lex_tokench(lex, '/');
                     lex_tokench(lex, '*');
+                    */
+                    lex_tokench(lex, ' ');
+                    lex_tokench(lex, ' ');
                 }
 
                 while (ch != EOF)
@@ -444,14 +452,18 @@ static int lex_skipwhite(lex_file *lex)
                         ch = lex_getch(lex);
                         if (ch == '/') {
                             if (lex->flags.preprocessing) {
+                                /*
                                 lex_tokench(lex, '*');
                                 lex_tokench(lex, '/');
+                                */
+                                lex_tokench(lex, ' ');
+                                lex_tokench(lex, ' ');
                             }
                             break;
                         }
                     }
                     if (lex->flags.preprocessing) {
-                        lex_tokench(lex, ch);
+                        lex_tokench(lex, ' '); /* ch); */
                     }
                 }
                 ch = ' '; /* cause TRUE in the isspace check */
@@ -686,6 +698,7 @@ int lex_do(lex_file *lex)
             break;
         }
         /* we reached a linemerge */
+        lex_tokench(lex, '\n');
         continue;
     }