From 5a6b9a27fdb2ac66aaadd90b15b1889fea8f08d0 Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Thu, 20 May 2010 14:29:43 -0700 Subject: [PATCH] Avoid printing a space at the beginning of lines in the output. This fixes more differences compared to "gcc -E" so removes several cases of erroneously failing test cases. The implementation isn't very elegant, but it is functional. --- glcpp-lex.l | 5 +++++ glcpp-parse.y | 18 +++++++++++------- glcpp.h | 1 + 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/glcpp-lex.l b/glcpp-lex.l index 8e3ab661e6f..13e4d6f0ef1 100644 --- a/glcpp-lex.l +++ b/glcpp-lex.l @@ -173,7 +173,12 @@ TOKEN [^[:space:](),]+ } \n { + /* XXX: Printing here (rather than in a parser production) + * *and* frobbing a bit of the parser state here are both ugly + * things. But all my attempts to avoid this by returning a + * NEWLINE token here have led to even more ugly things. */ printf ("\n"); + yyextra->just_printed_separator = 1; } {HSPACE}+ diff --git a/glcpp-parse.y b/glcpp-parse.y index c6d64176b2d..93713a3f0ca 100644 --- a/glcpp-parse.y +++ b/glcpp-parse.y @@ -114,7 +114,7 @@ glcpp_parser_lex (glcpp_parser_t *parser); %lex-param {glcpp_parser_t *parser} %token DEFINE FUNC_MACRO IDENTIFIER IDENTIFIER_FINALIZED OBJ_MACRO NEWLINE SEPARATOR SPACE TOKEN UNDEF -%type input punctuator +%type punctuator %type content FUNC_MACRO IDENTIFIER IDENTIFIER_FINALIZED OBJ_MACRO %type argument_list %type macro parameter_list @@ -144,7 +144,7 @@ glcpp_parser_lex (glcpp_parser_t *parser); * character between any two. */ input: /* empty */ { - $$ = SEPARATOR; + parser->just_printed_separator = 1; } | input content { int is_token; @@ -157,16 +157,18 @@ input: (c >= '0' && c <= '9') || (c == '_')); - if ($1 == TOKEN && is_not_separator) + if (! parser->just_printed_separator && is_not_separator) + { printf (" "); + } printf ("%s", $2); + if (is_not_separator) - $$ = TOKEN; + parser->just_printed_separator = 0; else - $$ = SEPARATOR; - } else { - $$ = $1; + parser->just_printed_separator = 1; } + if ($2) talloc_free ($2); } @@ -561,6 +563,8 @@ glcpp_parser_create (void) hash_table_string_compare); parser->expansions = NULL; + parser->just_printed_separator = 1; + return parser; } diff --git a/glcpp.h b/glcpp.h index 5432a318173..c25e29c6883 100644 --- a/glcpp.h +++ b/glcpp.h @@ -101,6 +101,7 @@ struct glcpp_parser { yyscan_t scanner; struct hash_table *defines; expansion_node_t *expansions; + int just_printed_separator; }; void -- 2.30.2