From: Carl Worth Date: Thu, 13 May 2010 17:46:29 +0000 (-0700) Subject: Make the lexer return SPACE tokens unconditionally. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=48b94da0994b44e41324a2419117dcd81facce8b;p=mesa.git Make the lexer return SPACE tokens unconditionally. It seems strange to always be returning SPACE tokens, but since we were already needing to return a SPACE token in some cases, this actually simplifies our lexer. This also allows us to fix two whitespace-handling differences compared to "gcc -E" so that now the recent modification to the test suite passes once again. --- diff --git a/glcpp-lex.l b/glcpp-lex.l index 3c9dda46d47..21b9e3530aa 100644 --- a/glcpp-lex.l +++ b/glcpp-lex.l @@ -32,9 +32,6 @@ %option reentrant noyywrap %option extra-type="glcpp_parser_t *" -%x ST_DEFINE -%x ST_DEFVAL - SPACE [[:space:]] NONSPACE [^[:space:]] NEWLINE [\n] @@ -55,31 +52,9 @@ TOKEN [^[:space:](),]+ * "#define foo()" from "#define foo ()". */ {HASH}define{HSPACE}* { - BEGIN ST_DEFINE; return DEFINE; } -{IDENTIFIER} { - BEGIN ST_DEFVAL; - yylval.str = xtalloc_strdup (yyextra, yytext); - return IDENTIFIER; -} - -\n { - BEGIN INITIAL; - return NEWLINE; -} - -{HSPACE}+ { - BEGIN INITIAL; - return SPACE; -} - -"(" { - BEGIN INITIAL; - return '('; -} - {IDENTIFIER} { yylval.str = xtalloc_strdup (yyextra, yytext); switch (glcpp_parser_macro_type (yyextra, yylval.str)) @@ -109,6 +84,8 @@ TOKEN [^[:space:](),]+ return NEWLINE; } -{SPACE}+ +{HSPACE}+ { + return SPACE; +} %% diff --git a/glcpp-parse.y b/glcpp-parse.y index dc352de55b6..7d1c3ab927f 100644 --- a/glcpp-parse.y +++ b/glcpp-parse.y @@ -109,6 +109,7 @@ content: | '(' { printf ("("); } | ')' { printf (")"); } | ',' { printf (","); } +| SPACE { printf (" "); } ; macro: @@ -157,8 +158,12 @@ directive: | DEFINE IDENTIFIER SPACE replacement_list { _define_object_macro (parser, $2, $4); } -| DEFINE IDENTIFIER '(' parameter_list ')' replacement_list { - _define_function_macro (parser, $2, $4, $6); +| DEFINE IDENTIFIER '(' parameter_list ')' { + list_t *list = _list_create (parser); + _define_function_macro (parser, $2, $4, list); + } +| DEFINE IDENTIFIER '(' parameter_list ')' SPACE replacement_list { + _define_function_macro (parser, $2, $4, $7); } | UNDEF FUNC_MACRO { list_t *replacement = hash_table_find (parser->defines, $2); @@ -185,8 +190,10 @@ directive: ; replacement_list: - /* empty */ { + word_or_symbol { $$ = _list_create (parser); + _list_append_item ($$, $1); + talloc_free ($1); } | replacement_list word_or_symbol { _list_append_item ($1, $2); @@ -216,6 +223,7 @@ word_or_symbol: | '(' { $$ = xtalloc_strdup (parser, "("); } | ')' { $$ = xtalloc_strdup (parser, ")"); } | ',' { $$ = xtalloc_strdup (parser, ","); } +| SPACE { $$ = xtalloc_strdup (parser, " "); } ; word: @@ -323,29 +331,24 @@ glcpp_parser_macro_type (glcpp_parser_t *parser, const char *identifier) static void _print_expanded_macro_recursive (glcpp_parser_t *parser, const char *token, - const char *orig, - int *first) + const char *orig) { macro_t *macro; node_t *node; macro = hash_table_find (parser->defines, token); if (macro == NULL) { - printf ("%s%s", *first ? "" : " ", token); - *first = 0; + printf ("%s", token); } else { list_t *replacement_list = macro->replacement_list; for (node = replacement_list->head ; node ; node = node->next) { token = node->str; - if (strcmp (token, orig) == 0) { - printf ("%s%s", *first ? "" : " ", token); - *first = 0; - } else { + if (strcmp (token, orig) == 0) + printf ("%s", token); + else _print_expanded_macro_recursive (parser, - token, orig, - first); - } + token, orig); } } } @@ -386,13 +389,12 @@ _define_function_macro (glcpp_parser_t *parser, void _print_expanded_object_macro (glcpp_parser_t *parser, const char *identifier) { - int first = 1; macro_t *macro; macro = hash_table_find (parser->defines, identifier); assert (! macro->is_function); - _print_expanded_macro_recursive (parser, identifier, identifier, &first); + _print_expanded_macro_recursive (parser, identifier, identifier); } void @@ -400,7 +402,6 @@ _print_expanded_function_macro (glcpp_parser_t *parser, const char *identifier, list_t *arguments) { - int first = 1; macro_t *macro; macro = hash_table_find (parser->defines, identifier); @@ -408,5 +409,5 @@ _print_expanded_function_macro (glcpp_parser_t *parser, /* XXX: Need to use argument list here in the expansion. */ - _print_expanded_macro_recursive (parser, identifier, identifier, &first); + _print_expanded_macro_recursive (parser, identifier, identifier); }