Add a wrapper function around the lexer.

We rename the generated lexer from yylex to glcpp_lex. Then we
implement our own yylex function in glcpp-parse.y that calls
glcpp_lex. This doesn't change the behavior at all yet, but gives us a
place where we can do implement alternate lexing in the future.

(We want this because instead of re-lexing from strings for macro
expansion, we want to lex from pre-parsed token lists. We need this so
that when we terminate recursion due to an already active macro
expansion, we can ensure that that symbol never gets expanded again
later.)
This commit is contained in:
Carl Worth 2010-05-19 10:01:29 -07:00
parent 5d21142545
commit 8f38aff9b5
3 changed files with 15 additions and 6 deletions

View file

@ -13,7 +13,7 @@ glcpp: glcpp.o glcpp-lex.o glcpp-parse.o hash_table.o xtalloc.o
bison --debug --defines=$*.h --output=$*.c $^
%.c: %.l
flex --outfile=$@ $<
flex --prefix=glcpp_ --outfile=$@ $<
glcpp-lex.c: glcpp-parse.h

View file

@ -82,6 +82,9 @@ _argument_list_length (argument_list_t *list);
string_list_t *
_argument_list_member_at (argument_list_t *list, int index);
static int
yylex (yyscan_t scanner);
%}
%union {
@ -405,7 +408,7 @@ glcpp_parser_create (void)
parser = xtalloc (NULL, glcpp_parser_t);
yylex_init_extra (parser, &parser->scanner);
glcpp_lex_init_extra (parser, &parser->scanner);
parser->defines = hash_table_ctor (32, hash_table_string_hash,
hash_table_string_compare);
parser->expansions = NULL;
@ -426,7 +429,7 @@ glcpp_parser_parse (glcpp_parser_t *parser)
void
glcpp_parser_destroy (glcpp_parser_t *parser)
{
yylex_destroy (parser->scanner);
glcpp_lex_destroy (parser->scanner);
hash_table_dtor (parser->defines);
talloc_free (parser);
}
@ -642,3 +645,9 @@ _expand_function_macro (glcpp_parser_t *parser,
glcpp_parser_push_expansion_macro (parser, macro, arguments);
}
static int
yylex (yyscan_t scanner)
{
return glcpp_lex (scanner);
}

View file

@ -128,13 +128,13 @@ glcpp_parser_pop_expansion (glcpp_parser_t *parser);
/* Generated by glcpp-lex.l to glcpp-lex.c */
int
yylex_init_extra (glcpp_parser_t *parser, yyscan_t* scanner);
glcpp_lex_init_extra (glcpp_parser_t *parser, yyscan_t* scanner);
int
yylex (yyscan_t scanner);
glcpp_lex (yyscan_t scanner);
int
yylex_destroy (yyscan_t scanner);
glcpp_lex_destroy (yyscan_t scanner);
/* Generated by glcpp-parse.y to glcpp-parse.c */