Skip to content

Commit c1e83a0

Browse files
authored
Merge pull request #5621 from tautschnig/messaget-parser
parsert is not a messaget
2 parents c2813b7 + c06c96b commit c1e83a0

File tree

11 files changed

+60
-52
lines changed

11 files changed

+60
-52
lines changed

jbmc/src/java_bytecode/java_bytecode_parser.cpp

+41-37
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,10 @@ class java_bytecode_parsert final : public parsert
6666
{
6767
if(index==0 || index>=constant_pool.size())
6868
{
69-
error() << "invalid constant pool index (" << index << ")" << eom;
70-
error() << "constant pool size: " << constant_pool.size() << eom;
69+
log.error() << "invalid constant pool index (" << index << ")"
70+
<< messaget::eom;
71+
log.error() << "constant pool size: " << constant_pool.size()
72+
<< messaget::eom;
7173
throw 0;
7274
}
7375

@@ -117,7 +119,7 @@ class java_bytecode_parsert final : public parsert
117119
{
118120
if(!*in)
119121
{
120-
error() << "unexpected end of bytecode file" << eom;
122+
log.error() << "unexpected end of bytecode file" << messaget::eom;
121123
throw 0;
122124
}
123125
in->get();
@@ -135,7 +137,7 @@ class java_bytecode_parsert final : public parsert
135137
{
136138
if(!*in)
137139
{
138-
error() << "unexpected end of bytecode file" << eom;
140+
log.error() << "unexpected end of bytecode file" << messaget::eom;
139141
throw 0;
140142
}
141143
result <<= 8u;
@@ -384,19 +386,19 @@ bool java_bytecode_parsert::parse()
384386

385387
catch(const char *message)
386388
{
387-
error() << message << eom;
389+
log.error() << message << messaget::eom;
388390
return true;
389391
}
390392

391393
catch(const std::string &message)
392394
{
393-
error() << message << eom;
395+
log.error() << message << messaget::eom;
394396
return true;
395397
}
396398

397399
catch(...)
398400
{
399-
error() << "parsing error" << eom;
401+
log.error() << "parsing error" << messaget::eom;
400402
return true;
401403
}
402404

@@ -435,13 +437,13 @@ void java_bytecode_parsert::rClassFile()
435437

436438
if(magic!=0xCAFEBABE)
437439
{
438-
error() << "wrong magic" << eom;
440+
log.error() << "wrong magic" << messaget::eom;
439441
throw 0;
440442
}
441443

442444
if(major_version<44)
443445
{
444-
error() << "unexpected major version" << eom;
446+
log.error() << "unexpected major version" << messaget::eom;
445447
throw 0;
446448
}
447449

@@ -641,7 +643,7 @@ void java_bytecode_parsert::rconstant_pool()
641643
const u2 constant_pool_count = read<u2>();
642644
if(constant_pool_count==0)
643645
{
644-
error() << "invalid constant_pool_count" << eom;
646+
log.error() << "invalid constant_pool_count" << messaget::eom;
645647
throw 0;
646648
}
647649

@@ -683,7 +685,7 @@ void java_bytecode_parsert::rconstant_pool()
683685
// Eight-byte constants take up two entries in the constant_pool table.
684686
if(it==constant_pool.end())
685687
{
686-
error() << "invalid double entry" << eom;
688+
log.error() << "invalid double entry" << messaget::eom;
687689
throw 0;
688690
}
689691
it++;
@@ -707,8 +709,8 @@ void java_bytecode_parsert::rconstant_pool()
707709
break;
708710

709711
default:
710-
error() << "unknown constant pool entry (" << it->tag << ")"
711-
<< eom;
712+
log.error() << "unknown constant pool entry (" << it->tag << ")"
713+
<< messaget::eom;
712714
throw 0;
713715
}
714716
}
@@ -1140,7 +1142,7 @@ void java_bytecode_parsert::rbytecode(std::vector<instructiont> &instructions)
11401142

11411143
if(address!=code_length)
11421144
{
1143-
error() << "bytecode length mismatch" << eom;
1145+
log.error() << "bytecode length mismatch" << messaget::eom;
11441146
throw 0;
11451147
}
11461148
}
@@ -1809,7 +1811,7 @@ optionalt<java_bytecode_parse_treet> java_bytecode_parse(
18091811
{
18101812
java_bytecode_parsert java_bytecode_parser(skip_instructions);
18111813
java_bytecode_parser.in=&istream;
1812-
java_bytecode_parser.set_message_handler(message_handler);
1814+
java_bytecode_parser.log.set_message_handler(message_handler);
18131815

18141816
bool parser_result=java_bytecode_parser.parse();
18151817

@@ -1979,8 +1981,8 @@ void java_bytecode_parsert::read_bootstrapmethods_entry()
19791981
method_handle_infot method_handle{entry};
19801982

19811983
const u2 num_bootstrap_arguments = read<u2>();
1982-
debug() << "INFO: parse BootstrapMethod handle " << num_bootstrap_arguments
1983-
<< " #args" << eom;
1984+
log.debug() << "INFO: parse BootstrapMethod handle "
1985+
<< num_bootstrap_arguments << " #args" << messaget::eom;
19841986

19851987
// read u2 values of entry into vector
19861988
std::vector<u2> u2_values(num_bootstrap_arguments);
@@ -2020,9 +2022,9 @@ void java_bytecode_parsert::read_bootstrapmethods_entry()
20202022
if(num_bootstrap_arguments < 3)
20212023
{
20222024
store_unknown_method_handle(bootstrap_method_index);
2023-
debug()
2025+
log.debug()
20242026
<< "format of BootstrapMethods entry not recognized: too few arguments"
2025-
<< eom;
2027+
<< messaget::eom;
20262028
continue;
20272029
}
20282030

@@ -2043,9 +2045,9 @@ void java_bytecode_parsert::read_bootstrapmethods_entry()
20432045

20442046
if(!recognized)
20452047
{
2046-
debug() << "format of BootstrapMethods entry not recognized: extra "
2047-
"arguments of wrong type"
2048-
<< eom;
2048+
log.debug() << "format of BootstrapMethods entry not recognized: extra "
2049+
"arguments of wrong type"
2050+
<< messaget::eom;
20492051
store_unknown_method_handle(bootstrap_method_index);
20502052
continue;
20512053
}
@@ -2060,22 +2062,23 @@ void java_bytecode_parsert::read_bootstrapmethods_entry()
20602062
method_handle_argument.tag != CONSTANT_MethodHandle ||
20612063
method_type_argument.tag != CONSTANT_MethodType)
20622064
{
2063-
debug() << "format of BootstrapMethods entry not recognized: arguments "
2064-
"wrong type"
2065-
<< eom;
2065+
log.debug()
2066+
<< "format of BootstrapMethods entry not recognized: arguments "
2067+
"wrong type"
2068+
<< messaget::eom;
20662069
store_unknown_method_handle(bootstrap_method_index);
20672070
continue;
20682071
}
20692072

2070-
debug() << "INFO: parse lambda handle" << eom;
2073+
log.debug() << "INFO: parse lambda handle" << messaget::eom;
20712074
optionalt<lambda_method_handlet> lambda_method_handle =
20722075
parse_method_handle(method_handle_infot{method_handle_argument});
20732076

20742077
if(!lambda_method_handle.has_value())
20752078
{
2076-
debug() << "format of BootstrapMethods entry not recognized: method "
2077-
"handle not recognised"
2078-
<< eom;
2079+
log.debug() << "format of BootstrapMethods entry not recognized: method "
2080+
"handle not recognised"
2081+
<< messaget::eom;
20792082
store_unknown_method_handle(bootstrap_method_index);
20802083
continue;
20812084
}
@@ -2084,14 +2087,15 @@ void java_bytecode_parsert::read_bootstrapmethods_entry()
20842087
POSTCONDITION(
20852088
lambda_method_handle->handle_type != method_handle_typet::UNKNOWN_HANDLE);
20862089

2087-
debug() << "lambda function reference "
2088-
<< id2string(lambda_method_handle->get_method_descriptor()
2089-
.base_method_name())
2090-
<< " in class \"" << parse_tree.parsed_class.name << "\""
2091-
<< "\n interface type is "
2092-
<< id2string(pool_entry(interface_type_argument.ref1).s)
2093-
<< "\n method type is "
2094-
<< id2string(pool_entry(method_type_argument.ref1).s) << eom;
2090+
log.debug()
2091+
<< "lambda function reference "
2092+
<< id2string(
2093+
lambda_method_handle->get_method_descriptor().base_method_name())
2094+
<< " in class \"" << parse_tree.parsed_class.name << "\""
2095+
<< "\n interface type is "
2096+
<< id2string(pool_entry(interface_type_argument.ref1).s)
2097+
<< "\n method type is "
2098+
<< id2string(pool_entry(method_type_argument.ref1).s) << messaget::eom;
20952099
parse_tree.parsed_class.add_method_handle(
20962100
bootstrap_method_index, *lambda_method_handle);
20972101
}

src/ansi-c/ansi_c_language.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ bool ansi_c_languaget::parse(
7272
ansi_c_parser.clear();
7373
ansi_c_parser.set_file(ID_built_in);
7474
ansi_c_parser.in=&codestr;
75-
ansi_c_parser.set_message_handler(get_message_handler());
75+
ansi_c_parser.log.set_message_handler(get_message_handler());
7676
ansi_c_parser.for_has_scope=config.ansi_c.for_has_scope;
7777
ansi_c_parser.ts_18661_3_Floatn_types=config.ansi_c.ts_18661_3_Floatn_types;
7878
ansi_c_parser.cpp98=false; // it's not C++
@@ -198,7 +198,7 @@ bool ansi_c_languaget::to_expr(
198198
ansi_c_parser.clear();
199199
ansi_c_parser.set_file(irep_idt());
200200
ansi_c_parser.in=&i_preprocessed;
201-
ansi_c_parser.set_message_handler(get_message_handler());
201+
ansi_c_parser.log.set_message_handler(get_message_handler());
202202
ansi_c_parser.mode=config.ansi_c.mode;
203203
ansi_c_parser.ts_18661_3_Floatn_types=config.ansi_c.ts_18661_3_Floatn_types;
204204
ansi_c_scanner_init();

src/ansi-c/builtin_factory.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ static bool convert(
5050
ansi_c_parser.clear();
5151
ansi_c_parser.set_file(ID_built_in);
5252
ansi_c_parser.in=&in;
53-
ansi_c_parser.set_message_handler(message_handler);
53+
ansi_c_parser.log.set_message_handler(message_handler);
5454
ansi_c_parser.for_has_scope=config.ansi_c.for_has_scope;
5555
ansi_c_parser.cpp98=false; // it's not C++
5656
ansi_c_parser.cpp11=false; // it's not C++

src/cpp/cpp_language.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ bool cpp_languaget::parse(
104104
cpp_parser.clear();
105105
cpp_parser.set_file(path);
106106
cpp_parser.in=&i_preprocessed;
107-
cpp_parser.set_message_handler(get_message_handler());
107+
cpp_parser.log.set_message_handler(get_message_handler());
108108
cpp_parser.mode=config.ansi_c.mode;
109109

110110
bool result=cpp_parser.parse();
@@ -244,7 +244,7 @@ bool cpp_languaget::to_expr(
244244
cpp_parser.clear();
245245
cpp_parser.set_file(irep_idt());
246246
cpp_parser.in=&i_preprocessed;
247-
cpp_parser.set_message_handler(get_message_handler());
247+
cpp_parser.log.set_message_handler(get_message_handler());
248248

249249
bool result=cpp_parser.parse();
250250

src/cpp/cpp_parser.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ bool cpp_parsert::parse()
2929
ansi_c_parser.in=in;
3030
ansi_c_parser.mode=mode;
3131
ansi_c_parser.set_file(get_file());
32-
ansi_c_parser.set_message_handler(get_message_handler());
32+
ansi_c_parser.log.set_message_handler(log.get_message_handler());
3333

3434
return cpp_parse();
3535
}

src/cpp/parse.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -512,8 +512,8 @@ bool Parser::SyntaxError()
512512

513513
message+="'";
514514

515-
parser.error().source_location=source_location;
516-
parser.error() << message << messaget::eom;
515+
parser.log.error().source_location = source_location;
516+
parser.log.error() << message << messaget::eom;
517517
}
518518

519519
return ++number_of_errors < max_errors;

src/jsil/jsil_language.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ bool jsil_languaget::parse(
6161
jsil_parser.clear();
6262
jsil_parser.set_file(path);
6363
jsil_parser.in=&instream;
64-
jsil_parser.set_message_handler(get_message_handler());
64+
jsil_parser.log.set_message_handler(get_message_handler());
6565

6666
jsil_scanner_init();
6767
bool result=jsil_parser.parse();
@@ -136,7 +136,7 @@ bool jsil_languaget::to_expr(
136136
jsil_parser.clear();
137137
jsil_parser.set_file(irep_idt());
138138
jsil_parser.in=&instream;
139-
jsil_parser.set_message_handler(get_message_handler());
139+
jsil_parser.log.set_message_handler(get_message_handler());
140140
jsil_scanner_init();
141141

142142
bool result=jsil_parser.parse();

src/json/json_parser.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ bool parse_json(
2222
json_parser.clear();
2323
json_parser.set_file(filename);
2424
json_parser.in=&in;
25-
json_parser.set_message_handler(message_handler);
25+
json_parser.log.set_message_handler(message_handler);
2626

2727
bool result=json_parser.parse();
2828

src/util/parser.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ void parsert::parse_error(
4040
tmp_source_location.set_column(column-before.size());
4141
print(1, tmp, -1, tmp_source_location);
4242
#else
43-
error().source_location=source_location;
44-
error() << tmp << eom;
43+
log.error().source_location = source_location;
44+
log.error() << tmp << messaget::eom;
4545
#endif
4646
}

src/util/parser.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Author: Daniel Kroening, [email protected]
2020
#include "message.h"
2121
#include "file_util.h"
2222

23-
class parsert:public messaget
23+
class parsert
2424
{
2525
public:
2626
std::istream *in;
@@ -131,6 +131,10 @@ class parsert:public messaget
131131
column+=token_width;
132132
}
133133

134+
// should be protected or even just be a reference to a message handler, but
135+
// for now enables a step-by-step transition
136+
messaget log;
137+
134138
protected:
135139
source_locationt source_location;
136140
unsigned line_no, previous_line_no;

src/xmllang/xml_parser.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ bool parse_xml(
2222
xml_parser.clear();
2323
xml_parser.set_file(filename);
2424
xml_parser.in=&in;
25-
xml_parser.set_message_handler(message_handler);
25+
xml_parser.log.set_message_handler(message_handler);
2626

2727
bool result=yyxmlparse()!=0;
2828

0 commit comments

Comments
 (0)