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:
+11
-2
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user