Browse Source

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.
tags/mesa-7.9-rc1
Carl Worth 15 years ago
parent
commit
5a6b9a27fd
3 changed files with 17 additions and 7 deletions
  1. 5
    0
      glcpp-lex.l
  2. 11
    7
      glcpp-parse.y
  3. 1
    0
      glcpp.h

+ 5
- 0
glcpp-lex.l View File

@@ -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}+

+ 11
- 7
glcpp-parse.y View File

@@ -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 <ival> input punctuator
%type <ival> punctuator
%type <str> content FUNC_MACRO IDENTIFIER IDENTIFIER_FINALIZED OBJ_MACRO
%type <argument_list> argument_list
%type <string_list> 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;
}


+ 1
- 0
glcpp.h View File

@@ -101,6 +101,7 @@ struct glcpp_parser {
yyscan_t scanner;
struct hash_table *defines;
expansion_node_t *expansions;
int just_printed_separator;
};

void

Loading…
Cancel
Save