From 8f38aff9b5dd42ef963532fe5fc618e8bafa218a Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Wed, 19 May 2010 10:01:29 -0700 Subject: [PATCH] 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.) --- Makefile | 2 +- glcpp-parse.y | 13 +++++++++++-- glcpp.h | 6 +++--- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 3fa863c49b9..88116128f85 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/glcpp-parse.y b/glcpp-parse.y index 647532f209d..6ef1cae0eca 100644 --- a/glcpp-parse.y +++ b/glcpp-parse.y @@ -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); +} diff --git a/glcpp.h b/glcpp.h index 81f7d14c5ba..6aabf6f1823 100644 --- a/glcpp.h +++ b/glcpp.h @@ -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 */ -- 2.30.2