diff options
author | Carl Worth <cworth@cworth.org> | 2010-05-19 10:01:29 -0700 |
---|---|---|
committer | Carl Worth <cworth@cworth.org> | 2010-05-19 10:01:29 -0700 |
commit | 8f38aff9b5dd42ef963532fe5fc618e8bafa218a (patch) | |
tree | 54e5169fc3edd846609f1e6af8d71c2d4d5c4204 | |
parent | 5d2114254592e03b6d554c5e2eea4ea442c3fa05 (diff) |
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.)
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | glcpp-parse.y | 13 | ||||
-rw-r--r-- | glcpp.h | 6 |
3 files changed, 15 insertions, 6 deletions
@@ -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 647532f209..6ef1cae0ec 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); +} @@ -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 */ |