Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jsil_parsert: construct with message handler #8136

Merged
merged 2 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions src/jsil/jsil_language.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,11 @@ bool jsil_languaget::parse(
parse_path=path;

// parsing
jsil_parsert jsil_parser{message_handler};
jsil_parser.clear();
jsil_parser.set_file(path);
jsil_parser.in=&instream;
jsil_parser.log.set_message_handler(message_handler);

jsil_scanner_init();
bool result=jsil_parser.parse();

// save result
Expand Down Expand Up @@ -137,12 +136,10 @@ bool jsil_languaget::to_expr(
std::istringstream instream(code);

// parsing

jsil_parsert jsil_parser{message_handler};
jsil_parser.clear();
jsil_parser.set_file(irep_idt());
jsil_parser.in=&instream;
jsil_parser.log.set_message_handler(message_handler);
jsil_scanner_init();

bool result=jsil_parser.parse();

Expand Down
10 changes: 0 additions & 10 deletions src/jsil/jsil_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,3 @@ Author: Michael Tautschnig, [email protected]
/// Jsil Language

#include "jsil_parser.h"

jsil_parsert jsil_parser;

extern char *yyjsiltext;

int yyjsilerror(const std::string &error)
{
jsil_parser.parse_error(error, yyjsiltext);
return 0;
}
17 changes: 10 additions & 7 deletions src/jsil/jsil_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,24 @@ Author: Michael Tautschnig, [email protected]

#include "jsil_parse_tree.h"

int yyjsilparse();
class jsil_parsert;
int yyjsilparse(jsil_parsert &);
void jsil_scanner_init(jsil_parsert &);

class jsil_parsert:public parsert
{
public:
explicit jsil_parsert(message_handlert &message_handler)
: parsert(message_handler)
{
}

jsil_parse_treet parse_tree;

virtual bool parse() override
{
return yyjsilparse()!=0;
jsil_scanner_init(*this);
return yyjsilparse(*this) != 0;
}

virtual void clear() override
Expand All @@ -41,9 +49,4 @@ class jsil_parsert:public parsert
std::string string_literal;
};

extern jsil_parsert jsil_parser;

int yyjsilerror(const std::string &error);
void jsil_scanner_init();

#endif // CPROVER_JSIL_JSIL_PARSER_H
16 changes: 15 additions & 1 deletion src/jsil/parser.y
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
%{

// #define YYDEBUG 1
#define PARSER jsil_parser
#define PARSER (*jsil_parser)

#include "jsil_parser.h"

int yyjsillex();
extern char *yyjsiltext;

static jsil_parsert *jsil_parser;
int yyjsilparse(void);
int yyjsilparse(jsil_parsert &_jsil_parser)
{
jsil_parser = &_jsil_parser;
return yyjsilparse();
}

int yyjsilerror(const std::string &error)
{
jsil_parser->parse_error(error, yyjsiltext);
return 0;
}

#define YYSTYPE unsigned
#define YYSTYPE_IS_TRIVIAL 1

Expand Down
20 changes: 11 additions & 9 deletions src/jsil/scanner.l
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,23 @@
#include <ansi-c/literals/convert_float_literal.h>
#include <ansi-c/literals/convert_string_literal.h>

#define PARSER jsil_parser
#define PARSER (*jsil_parser)
#define YYSTYPE unsigned

#include "jsil_parser.h"
#include "jsil_y.tab.h"
// extern int yyjsildebug;

static jsil_parsert *jsil_parser;
void jsil_scanner_init(jsil_parsert &_jsil_parser)
{
jsil_parser = &_jsil_parser;
YY_FLUSH_BUFFER;
BEGIN(0);
}

int yyjsilerror(const std::string &error);

#define loc() \
{ newstack(yyjsillval); PARSER.set_source_location(parser_stack(yyjsillval)); }

Expand Down Expand Up @@ -71,14 +81,6 @@ string_lit ["]{s_char}*["]
%x STRING_LITERAL_COMMENT
%x STATEMENTS

%{
void jsil_scanner_init()
{
// yyjsildebug=1;
YY_FLUSH_BUFFER;
BEGIN(0);
}
%}
/* %option debug */

%%
Expand Down
7 changes: 7 additions & 0 deletions src/util/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Author: Daniel Kroening, [email protected]
#ifndef CPROVER_UTIL_PARSER_H
#define CPROVER_UTIL_PARSER_H

#include "deprecate.h"
#include "expr.h"
#include "message.h"

Expand Down Expand Up @@ -39,7 +40,13 @@ class parsert
last_line.clear();
}

DEPRECATED(SINCE(2023, 12, 20, "use parsert(message_handler) instead"))
parsert():in(nullptr) { clear(); }
explicit parsert(message_handlert &message_handler)
: in(nullptr), log(message_handler)
{
clear();
}
virtual ~parsert() { }

// The following are for the benefit of the scanner
Expand Down