Skip to content

Commit c5ba99a

Browse files
committed
WIP: message handler
1 parent b0a0a9b commit c5ba99a

File tree

76 files changed

+929
-238
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+929
-238
lines changed

jbmc/src/java_bytecode/java_bytecode_parser.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ Author: Daniel Kroening, [email protected]
2929
class java_bytecode_parsert final : public parsert
3030
{
3131
public:
32-
explicit java_bytecode_parsert(bool skip_instructions)
33-
: skip_instructions(skip_instructions)
32+
java_bytecode_parsert(bool skip_instructions, message_handlert &message_handler)
33+
: parsert(message_handler), skip_instructions(skip_instructions)
3434
{
3535
}
3636

@@ -1811,9 +1811,8 @@ optionalt<java_bytecode_parse_treet> java_bytecode_parse(
18111811
message_handlert &message_handler,
18121812
bool skip_instructions)
18131813
{
1814-
java_bytecode_parsert java_bytecode_parser(skip_instructions);
1814+
java_bytecode_parsert java_bytecode_parser(skip_instructions, message_handler);
18151815
java_bytecode_parser.in=&istream;
1816-
java_bytecode_parser.log.set_message_handler(message_handler);
18171816

18181817
bool parser_result=java_bytecode_parser.parse();
18191818

jbmc/unit/solvers/strings/string_constraint_instantiation/instantiate_not_contains.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ decision_proceduret::resultt check_sat(const exprt &expr, const namespacet &ns)
168168
info.ns = &ns;
169169
info.prop = &sat_check;
170170
info.output_xml = false;
171-
bv_refinementt solver(info);
171+
bv_refinementt solver(info, null_message_handler);
172172
solver << expr;
173173
return solver();
174174
}

src/ansi-c/ansi_c_language.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,26 +77,22 @@ bool ansi_c_languaget::parse(
7777
ansi_c_internal_additions(code);
7878
std::istringstream codestr(code);
7979

80-
ansi_c_parser.clear();
80+
ansi_c_parsert ansi_c_parser(message_handler);
8181
ansi_c_parser.set_file(ID_built_in);
8282
ansi_c_parser.in=&codestr;
83-
ansi_c_parser.log.set_message_handler(message_handler);
8483
ansi_c_parser.for_has_scope=config.ansi_c.for_has_scope;
8584
ansi_c_parser.ts_18661_3_Floatn_types=config.ansi_c.ts_18661_3_Floatn_types;
8685
ansi_c_parser.cpp98=false; // it's not C++
8786
ansi_c_parser.cpp11=false; // it's not C++
8887
ansi_c_parser.mode=config.ansi_c.mode;
8988

90-
ansi_c_scanner_init();
91-
9289
bool result=ansi_c_parser.parse();
9390

9491
if(!result)
9592
{
9693
ansi_c_parser.set_line_no(0);
9794
ansi_c_parser.set_file(path);
9895
ansi_c_parser.in=&i_preprocessed;
99-
ansi_c_scanner_init();
10096
result=ansi_c_parser.parse();
10197
}
10298

@@ -196,13 +192,12 @@ bool ansi_c_languaget::to_expr(
196192

197193
// parsing
198194

199-
ansi_c_parser.clear();
195+
ansi_c_parsert ansi_c_parser(get_message_handler());
200196
ansi_c_parser.set_file(irep_idt());
201197
ansi_c_parser.in=&i_preprocessed;
202198
ansi_c_parser.log.set_message_handler(message_handler);
203199
ansi_c_parser.mode=config.ansi_c.mode;
204200
ansi_c_parser.ts_18661_3_Floatn_types=config.ansi_c.ts_18661_3_Floatn_types;
205-
ansi_c_scanner_init();
206201

207202
bool result=ansi_c_parser.parse();
208203

src/ansi-c/ansi_c_parser.cpp

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,37 @@ Author: Daniel Kroening, [email protected]
1010

1111
#include "c_storage_spec.h"
1212

13-
ansi_c_parsert ansi_c_parser;
13+
void ansi_c_parser_init(ansi_c_parsert *ansi_c_parser);
14+
void ansi_c_scanner_init(ansi_c_parsert *ansi_c_parser);
15+
int yyansi_cparse();
16+
17+
bool ansi_c_parsert::parse()
18+
{
19+
clear();
20+
ansi_c_scanner_init(this);
21+
ansi_c_parser_init(this);
22+
return yyansi_cparse()!=0;
23+
}
24+
25+
void ansi_c_parsert::clear()
26+
{
27+
parsert::clear();
28+
parse_tree.clear();
29+
30+
// scanner state
31+
tag_following=false;
32+
asm_block_following=false;
33+
parenthesis_counter=0;
34+
string_literal.clear();
35+
pragma_pack.clear();
36+
37+
// set up global scope
38+
scopes.clear();
39+
scopes.push_back(scopet());
40+
41+
ansi_c_scanner_init(nullptr);
42+
ansi_c_parser_init(nullptr);
43+
}
1444

1545
ansi_c_id_classt ansi_c_parsert::lookup(
1646
const irep_idt &base_name,
@@ -73,14 +103,6 @@ void ansi_c_parsert::add_tag_with_body(irept &tag)
73103
}
74104
}
75105

76-
extern char *yyansi_ctext;
77-
78-
int yyansi_cerror(const std::string &error)
79-
{
80-
ansi_c_parser.parse_error(error, yyansi_ctext);
81-
return 0;
82-
}
83-
84106
void ansi_c_parsert::add_declarator(
85107
exprt &declaration,
86108
irept &declarator)

src/ansi-c/ansi_c_parser.h

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,12 @@ Author: Daniel Kroening, [email protected]
2222
#include "ansi_c_parse_tree.h"
2323
#include "ansi_c_scope.h"
2424

25-
int yyansi_cparse();
26-
2725
class ansi_c_parsert:public parsert
2826
{
2927
public:
3028
ansi_c_parse_treet parse_tree;
3129

30+
<<<<<<< HEAD
3231
ansi_c_parsert()
3332
: tag_following(false),
3433
asm_block_following(false),
@@ -38,14 +37,25 @@ class ansi_c_parsert:public parsert
3837
cpp11(false),
3938
for_has_scope(false),
4039
ts_18661_3_Floatn_types(false)
40+
=======
41+
explicit ansi_c_parsert(message_handlert &message_handler):
42+
parsert(message_handler),
43+
tag_following(false),
44+
asm_block_following(false),
45+
parenthesis_counter(0),
46+
mode(modet::NONE),
47+
cpp98(false),
48+
cpp11(false),
49+
for_has_scope(false),
50+
ts_18661_3_Floatn_types(false),
51+
Float128_type(false)
52+
>>>>>>> WIP: message handler
4153
{
4254
}
4355

44-
virtual bool parse() override
45-
{
46-
return yyansi_cparse()!=0;
47-
}
56+
bool parse() override;
4857

58+
<<<<<<< HEAD
4959
virtual void clear() override
5060
{
5161
parsert::clear();
@@ -63,6 +73,9 @@ class ansi_c_parsert:public parsert
6373
scopes.clear();
6474
scopes.push_back(scopet());
6575
}
76+
=======
77+
void clear() override;
78+
>>>>>>> WIP: message handler
6679

6780
// internal state of the scanner
6881
bool tag_following;
@@ -158,9 +171,4 @@ class ansi_c_parsert:public parsert
158171
}
159172
};
160173

161-
extern ansi_c_parsert ansi_c_parser;
162-
163-
int yyansi_cerror(const std::string &error);
164-
void ansi_c_scanner_init();
165-
166174
#endif // CPROVER_ANSI_C_ANSI_C_PARSER_H

src/ansi-c/builtin_factory.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ static bool convert(
4747
{
4848
std::istringstream in(s.str());
4949

50-
ansi_c_parser.clear();
50+
ansi_c_parsert ansi_c_parser(message_handler);
5151
ansi_c_parser.set_file(ID_built_in);
5252
ansi_c_parser.in=&in;
5353
ansi_c_parser.log.set_message_handler(message_handler);
@@ -56,8 +56,6 @@ static bool convert(
5656
ansi_c_parser.cpp11=false; // it's not C++
5757
ansi_c_parser.mode=config.ansi_c.mode;
5858

59-
ansi_c_scanner_init();
60-
6159
if(ansi_c_parser.parse())
6260
return true;
6361

src/ansi-c/parser.y

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,19 @@
1313
#ifdef ANSI_C_DEBUG
1414
#define YYDEBUG 1
1515
#endif
16-
#define PARSER ansi_c_parser
16+
#define PARSER (*ansi_c_parser)
1717

1818
#include "ansi_c_parser.h"
1919

2020
int yyansi_clex();
21-
extern char *yyansi_ctext;
21+
int yyansi_cerror(const std::string &error);
22+
23+
static ansi_c_parsert *ansi_c_parser;
24+
25+
void ansi_c_parser_init(ansi_c_parsert *_ansi_c_parser)
26+
{
27+
ansi_c_parser = _ansi_c_parser;
28+
}
2229

2330
#include "parser_static.inc"
2431

src/ansi-c/scanner.l

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ static int isatty(int) { return 0; }
4040
#include "literals/convert_string_literal.h"
4141
#include "literals/unescape_string.h"
4242

43-
#define PARSER ansi_c_parser
43+
#define PARSER (*ansi_c_parser)
4444
#define YYSTYPE unsigned
4545
#undef ECHO
4646
#define ECHO
@@ -54,6 +54,10 @@ extern int yyansi_cdebug;
5454
#define loc() \
5555
{ newstack(yyansi_clval); PARSER.set_source_location(parser_stack(yyansi_clval)); }
5656

57+
static ansi_c_parsert *ansi_c_parser;
58+
59+
int yyansi_cerror(const std::string &error);
60+
5761
int make_identifier()
5862
{
5963
loc();
@@ -263,8 +267,9 @@ named_check ["]({arith_check}|{enum_check}|{memory_check}|{overflow_check})[
263267
%x OTHER_PRAGMA
264268

265269
%{
266-
void ansi_c_scanner_init()
270+
void ansi_c_scanner_init(ansi_c_parsert *_ansi_c_parser)
267271
{
272+
ansi_c_parser = _ansi_c_parser;
268273
#ifdef ANSI_C_DEBUG
269274
yyansi_cdebug=1;
270275
#endif
@@ -275,7 +280,8 @@ void ansi_c_scanner_init()
275280

276281
%%
277282

278-
<INITIAL>.|\n { BEGIN(GRAMMAR);
283+
<INITIAL>.|\n { PRECONDITION(ansi_c_parser);
284+
BEGIN(GRAMMAR);
279285
yyless(0); /* start again with this character */
280286
}
281287

@@ -1780,3 +1786,10 @@ __decltype { if(PARSER.cpp98 &&
17801786
%%
17811787

17821788
int yywrap() { return 1; }
1789+
1790+
int yyansi_cerror(const std::string &error)
1791+
{
1792+
PRECONDITION(ansi_c_parser);
1793+
ansi_c_parser->parse_error(error, yyansi_ctext);
1794+
return 0;
1795+
}

src/assembler/assembler_parser.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,25 @@ Author: Daniel Kroening, [email protected]
88

99
#include "assembler_parser.h"
1010

11+
<<<<<<< HEAD
1112
assembler_parsert assembler_parser;
1213

1314
extern char *yyassemblertext;
15+
=======
16+
int yyassemblerlex();
17+
void assembler_scanner_init(assembler_parsert *assembler_parser);
1418

15-
int yyassemblererror(const std::string &error)
19+
bool assembler_parsert::parse()
1620
{
17-
assembler_parser.parse_error(error, yyassemblertext);
18-
return 0;
21+
assembler_scanner_init(this);
22+
yyassemblerlex();
23+
return false;
24+
}
25+
>>>>>>> WIP: message handler
26+
27+
void assembler_parsert::clear()
28+
{
29+
parsert::clear();
30+
instructions.clear();
31+
assembler_scanner_init(nullptr);
1932
}

src/assembler/assembler_parser.h

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,15 @@ Author: Daniel Kroening, [email protected]
1111
#define CPROVER_ASSEMBLER_ASSEMBLER_PARSER_H
1212

1313
#include <util/parser.h>
14+
<<<<<<< HEAD
1415

1516
#include <list>
1617

1718
int yyassemblerlex();
1819
int yyassemblererror(const std::string &error);
1920
void assembler_scanner_init();
21+
=======
22+
>>>>>>> WIP: message handler
2023

2124
class assembler_parsert:public parsert
2225
{
@@ -37,24 +40,14 @@ class assembler_parsert:public parsert
3740
instructions.push_back(instructiont());
3841
}
3942

40-
assembler_parsert()
43+
explicit assembler_parsert(message_handlert &message_handler)
44+
: parsert(message_handler)
4145
{
4246
}
4347

44-
virtual bool parse()
45-
{
46-
yyassemblerlex();
47-
return false;
48-
}
48+
bool parse() override;
4949

50-
virtual void clear()
51-
{
52-
parsert::clear();
53-
instructions.clear();
54-
// assembler_scanner_init();
55-
}
50+
void clear() override;
5651
};
5752

58-
extern assembler_parsert assembler_parser;
59-
6053
#endif // CPROVER_ASSEMBLER_ASSEMBLER_PARSER_H

0 commit comments

Comments
 (0)