diff --git a/src/statement-list/parser.y b/src/statement-list/parser.y index 70b2ccce9696..e7dcfb6d1e90 100644 --- a/src/statement-list/parser.y +++ b/src/statement-list/parser.y @@ -12,7 +12,7 @@ #ifdef STATEMENT_LIST_DEBUG #define YYDEBUG 1 #endif -#define PARSER statement_list_parser +#define PARSER (*statement_list_parser) #include "statement_list_parser.h" #include "converters/convert_string_value.h" @@ -26,6 +26,20 @@ int yystatement_listlex(); extern char *yystatement_listtext; +static statement_list_parsert *statement_list_parser; +int yystatement_listparse(void); +int yystatement_listparse(statement_list_parsert &_statement_list_parser) +{ + statement_list_parser = &_statement_list_parser; + return yystatement_listparse(); +} + +int yystatement_listerror(const std::string &error) +{ + statement_list_parser->parse_error(error, yystatement_listtext); + return 0; +} + #define YYSTYPE unsigned #define YYSTYPE_IS_TRIVIAL 1 diff --git a/src/statement-list/scanner.l b/src/statement-list/scanner.l index a06e11cf1f68..e5b28692b75e 100644 --- a/src/statement-list/scanner.l +++ b/src/statement-list/scanner.l @@ -41,7 +41,7 @@ static int isatty(int) { return 0; } #endif // Value inside of statement_list_parser.h. -#define PARSER statement_list_parser +#define PARSER (*statement_list_parser) // Sets the type of yystatement_listlval so that it can be used as the stack // index. @@ -62,11 +62,13 @@ static int isatty(int) { return 0; } #ifdef STATEMENT_LIST_DEBUG extern int yystatement_listdebug; #endif -void statement_list_scanner_init() +static statement_list_parsert *statement_list_parser; +void statement_list_scanner_init(statement_list_parsert &_statement_list_parser) { #ifdef STATEMENT_LIST_DEBUG yystatement_listdebug=1; #endif + statement_list_parser = &_statement_list_parser; YY_FLUSH_BUFFER; BEGIN(0); } diff --git a/src/statement-list/statement_list_language.cpp b/src/statement-list/statement_list_language.cpp index bd5e28d185c6..d1cc36b7b5bb 100644 --- a/src/statement-list/statement_list_language.cpp +++ b/src/statement-list/statement_list_language.cpp @@ -60,12 +60,11 @@ bool statement_list_languaget::parse( const std::string &path, message_handlert &message_handler) { - statement_list_parser.clear(); + statement_list_parsert statement_list_parser{message_handler}; parse_path = path; statement_list_parser.set_line_no(0); statement_list_parser.set_file(path); statement_list_parser.in = &instream; - statement_list_scanner_init(); bool result = statement_list_parser.parse(); // store result diff --git a/src/statement-list/statement_list_parser.cpp b/src/statement-list/statement_list_parser.cpp index a5f10b1ff1e6..6c5653cd6c63 100644 --- a/src/statement-list/statement_list_parser.cpp +++ b/src/statement-list/statement_list_parser.cpp @@ -21,10 +21,6 @@ Author: Matthias Weiss, matthias.weiss@diffblue.com #include #include -statement_list_parsert statement_list_parser; - -extern char *yystatement_listtext; - /// Searches for the name of the TIA module inside of its root /// expression. /// \param root: Expression that includes the element's name as a @@ -337,13 +333,8 @@ void statement_list_parsert::add_function(const exprt &function) bool statement_list_parsert::parse() { - return yystatement_listparse() != 0; -} - -int yystatement_listerror(const std::string &error) -{ - statement_list_parser.parse_error(error, yystatement_listtext); - return 0; + statement_list_scanner_init(*this); + return yystatement_listparse(*this) != 0; } void statement_list_parsert::clear() diff --git a/src/statement-list/statement_list_parser.h b/src/statement-list/statement_list_parser.h index 468e35ce05b8..2031e132d82b 100644 --- a/src/statement-list/statement_list_parser.h +++ b/src/statement-list/statement_list_parser.h @@ -16,9 +16,10 @@ Author: Matthias Weiss, matthias.weiss@diffblue.com #include "statement_list_parse_tree.h" +class statement_list_parsert; /// Defined in statement_list_y.tab.cpp. Main function for the parse process /// generated by bison, performs all necessary steps to fill the parse tree. -int yystatement_listparse(); +int yystatement_listparse(statement_list_parsert &); /// Responsible for starting the parse process and to translate the result into /// a statement_list_parse_treet. This parser works by using the expression @@ -34,6 +35,12 @@ int yystatement_listparse(); class statement_list_parsert : public parsert { public: + /// Constructor + explicit statement_list_parsert(message_handlert &message_handler) + : parsert(message_handler) + { + } + /// Starts the parsing process and saves the result inside of this instance's /// parse tree. /// \return False if successful. @@ -71,9 +78,6 @@ class statement_list_parsert : public parsert statement_list_parse_treet parse_tree; }; -/// Instance of the parser, used by other modules. -extern statement_list_parsert statement_list_parser; - /// Forwards any errors that are encountered during the parse process. This /// function gets called by the generated files of flex and bison. /// \param error: Error message. @@ -82,6 +86,6 @@ int yystatement_listerror(const std::string &error); /// Defined in scanner.l. This function initialises the scanner by setting /// debug flags (if present) and its initial state. -void statement_list_scanner_init(); +void statement_list_scanner_init(statement_list_parsert &); #endif // CPROVER_STATEMENT_LIST_STATEMENT_LIST_PARSER_H