From: Wolfgang (Blub) Bumiller Date: Fri, 16 Nov 2012 22:13:53 +0000 (+0100) Subject: Lexer should keep newlines in merged lines, so will the preprocessor, but therefore... X-Git-Tag: 0.1.9~404^2~29 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=515cafe8bd17a64f38c6bba73d234e79a215b775;p=xonotic%2Fgmqcc.git Lexer should keep newlines in merged lines, so will the preprocessor, but therefore the lexer will replace comments with actual spaces so we don't get borken output... also don't error about redifining a macro when inside a non-outputting #if branch --- diff --git a/ftepp.c b/ftepp.c index 1a2ff21..59ec545 100644 --- 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 8558404..de09bfa 100644 --- 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; }