From 99dc9be48bee7fdde460659569ad2fef5b7cdd87 Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Thu, 7 Jul 2011 18:33:44 -0400 Subject: [PATCH] Use the reentrant scanner API. --- src/parse-decl.c | 12 +++++++++--- src/parse.y | 11 +++++++---- src/scan.l | 4 ++-- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/parse-decl.c b/src/parse-decl.c index 059f5f7..c088471 100644 --- a/src/parse-decl.c +++ b/src/parse-decl.c @@ -373,12 +373,18 @@ static bool forall_declarators(struct cdecl *decl, struct cdecl *cdecl_parse_decl(const char *declstr) { YY_BUFFER_STATE state; + yyscan_t scanner; struct cdecl *decl; int rc; - state = yy_scan_string(declstr); - rc = yyparse(&decl); - yy_delete_buffer(state); + rc = yylex_init(&scanner); + if (rc != 0) + return NULL; + + state = yy_scan_string(declstr, scanner); + rc = yyparse(scanner, &decl); + yy_delete_buffer(state, scanner); + yylex_destroy(scanner); if (rc != 0) return NULL; diff --git a/src/parse.y b/src/parse.y index 63d5fa9..2b02a5e 100644 --- a/src/parse.y +++ b/src/parse.y @@ -18,7 +18,9 @@ */ } +%parse-param {yyscan_t scanner} %parse-param {struct cdecl **out} +%lex-param {yyscan_t scanner} %define api.pure %error-verbose %locations @@ -31,7 +33,7 @@ #include "cdecl.h" #define FAIL(msg) do { \ - yyerror(&yylloc, NULL, msg); \ + yyerror(&yylloc, NULL, NULL, msg); \ YYERROR; \ } while (0) @@ -52,8 +54,8 @@ } %code provides { -void yyerror(YYLTYPE *, struct cdecl **, const char *); -int yyparse(struct cdecl **out); +void yyerror(YYLTYPE *, struct cdecl **, void *, const char *); +int yyparse(void *scanner, struct cdecl **out); } %union { @@ -381,7 +383,8 @@ direct_declarator: { } %% -void yyerror(YYLTYPE *loc, struct cdecl **out, const char *err) +void +yyerror(YYLTYPE *loc, struct cdecl **out, yyscan_t scanner, const char *err) { if (strstr(err, "T_LEX_ERROR")) return; diff --git a/src/scan.l b/src/scan.l index f0bf30a..06647de 100644 --- a/src/scan.l +++ b/src/scan.l @@ -20,11 +20,11 @@ #include "parse.h" } -%option noyywrap bison-locations +%option noyywrap bison-locations reentrant %{ #define lex_error(msg) do { \ - yyerror(yylloc, NULL, (msg)); \ + yyerror(yylloc, NULL, NULL, (msg)); \ return T_LEX_ERROR; \ } while(0) %} -- 2.43.2