From e0e429fca3f1f67e5d18f0989fd2dcc0d23a6bb9 Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Wed, 16 Jun 2010 16:26:28 -0700 Subject: [PATCH] glcpp: Build a reentrant parser. --- glcpp/glcpp-lex.l | 14 +++++++------- glcpp/glcpp-parse.y | 12 +++++++----- glcpp/glcpp.h | 2 +- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/glcpp/glcpp-lex.l b/glcpp/glcpp-lex.l index 933d9f449a6..06bde3f1957 100644 --- a/glcpp/glcpp-lex.l +++ b/glcpp/glcpp-lex.l @@ -29,7 +29,7 @@ #include "glcpp-parse.h" %} -%option reentrant noyywrap +%option bison-bridge reentrant noyywrap %option extra-type="glcpp_parser_t *" %option prefix="glcpp_" @@ -66,7 +66,7 @@ NON_STARS_THEN_STARS [^*]*[*]+ /* glcpp doesn't handle #extension, #version, or #pragma directives. * Simply pass them through to the main compiler's lexer/parser. */ {HASH}(extension|version|pragma).*\n { - yylval.str = xtalloc_strdup (yyextra, yytext); + yylval->str = xtalloc_strdup (yyextra, yytext); return OTHER; } @@ -130,17 +130,17 @@ NON_STARS_THEN_STARS [^*]*[*]+ } {DECIMAL_INTEGER} { - yylval.str = xtalloc_strdup (yyextra, yytext); + yylval->str = xtalloc_strdup (yyextra, yytext); return INTEGER_STRING; } {OCTAL_INTEGER} { - yylval.str = xtalloc_strdup (yyextra, yytext); + yylval->str = xtalloc_strdup (yyextra, yytext); return INTEGER_STRING; } {HEXADECIMAL_INTEGER} { - yylval.str = xtalloc_strdup (yyextra, yytext); + yylval->str = xtalloc_strdup (yyextra, yytext); return INTEGER_STRING; } @@ -185,7 +185,7 @@ NON_STARS_THEN_STARS [^*]*[*]+ } {IDENTIFIER} { - yylval.str = xtalloc_strdup (yyextra, yytext); + yylval->str = xtalloc_strdup (yyextra, yytext); return IDENTIFIER; } @@ -194,7 +194,7 @@ NON_STARS_THEN_STARS [^*]*[*]+ } {OTHER}+ { - yylval.str = xtalloc_strdup (yyextra, yytext); + yylval->str = xtalloc_strdup (yyextra, yytext); return OTHER; } diff --git a/glcpp/glcpp-parse.y b/glcpp/glcpp-parse.y index fde9b92edec..8119de3aa5c 100644 --- a/glcpp/glcpp-parse.y +++ b/glcpp/glcpp-parse.y @@ -133,13 +133,15 @@ _glcpp_parser_skip_stack_pop (glcpp_parser_t *parser); #define yylex glcpp_parser_lex static int -glcpp_parser_lex (glcpp_parser_t *parser); +glcpp_parser_lex (YYSTYPE *yylval, glcpp_parser_t *parser); static void glcpp_parser_lex_from (glcpp_parser_t *parser, token_list_t *list); %} +%pure-parser + %parse-param {glcpp_parser_t *parser} %lex-param {glcpp_parser_t *parser} @@ -1449,13 +1451,13 @@ _define_function_macro (glcpp_parser_t *parser, } static int -glcpp_parser_lex (glcpp_parser_t *parser) +glcpp_parser_lex (YYSTYPE *yylval, glcpp_parser_t *parser) { token_node_t *node; int ret; if (parser->lex_from_list == NULL) { - ret = glcpp_lex (parser->scanner); + ret = glcpp_lex (yylval, parser->scanner); /* XXX: This ugly block of code exists for the sole * purpose of converting a NEWLINE token into a SPACE @@ -1501,7 +1503,7 @@ glcpp_parser_lex (glcpp_parser_t *parser) { macro_t *macro; macro = hash_table_find (parser->defines, - yylval.str); + yylval->str); if (macro && macro->is_function) { parser->newline_as_space = 1; parser->paren_count = 0; @@ -1519,7 +1521,7 @@ glcpp_parser_lex (glcpp_parser_t *parser) return NEWLINE; } - yylval = node->token->value; + *yylval = node->token->value; ret = node->token->type; parser->lex_from_node = node->next; diff --git a/glcpp/glcpp.h b/glcpp/glcpp.h index 0d43f0b69e1..3441ab86327 100644 --- a/glcpp/glcpp.h +++ b/glcpp/glcpp.h @@ -163,7 +163,7 @@ void glcpp_lex_set_source_string(glcpp_parser_t *parser, const char *shader); int -glcpp_lex (yyscan_t scanner); +glcpp_lex (YYSTYPE *lvalp, yyscan_t scanner); int glcpp_lex_destroy (yyscan_t scanner); -- 2.30.2