Skip to content

Commit

Permalink
statement_list_parsert: construct with message handler
Browse files Browse the repository at this point in the history
This both avoids an object of static lifetime as well as it fixes the
(transitive) use of the deprecated messaget() constructor.
  • Loading branch information
tautschnig committed Dec 20, 2023
1 parent 856c641 commit 647ea51
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 21 deletions.
16 changes: 15 additions & 1 deletion src/statement-list/parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)

Check warning on line 37 in src/statement-list/parser.y

View check run for this annotation

Codecov / codecov/patch

src/statement-list/parser.y#L37

Added line #L37 was not covered by tests
{
statement_list_parser->parse_error(error, yystatement_listtext);
return 0;

Check warning on line 40 in src/statement-list/parser.y

View check run for this annotation

Codecov / codecov/patch

src/statement-list/parser.y#L39-L40

Added lines #L39 - L40 were not covered by tests
}

#define YYSTYPE unsigned
#define YYSTYPE_IS_TRIVIAL 1

Expand Down
6 changes: 4 additions & 2 deletions src/statement-list/scanner.l
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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);
}
Expand Down
3 changes: 1 addition & 2 deletions src/statement-list/statement_list_language.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 2 additions & 11 deletions src/statement-list/statement_list_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ Author: Matthias Weiss, [email protected]
#include <iostream>
#include <iterator>

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
Expand Down Expand Up @@ -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()
Expand Down
14 changes: 9 additions & 5 deletions src/statement-list/statement_list_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ Author: Matthias Weiss, [email protected]

#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
Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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

0 comments on commit 647ea51

Please sign in to comment.