Skip to content

Commit 3461eca

Browse files
committed
parsert is not a messaget
Use a messaget member "log" for output. The member is public for now to facilitate a step-by-step transition towards not constructing messaget objects without a configured message handler, which is deprecated.
1 parent e202911 commit 3461eca

File tree

11 files changed

+94
-30
lines changed

11 files changed

+94
-30
lines changed

jbmc/src/java_bytecode/java_bytecode_parser.cpp

Lines changed: 72 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,10 @@ class java_bytecode_parsert final : public parsert
6868
{
6969
if(index==0 || index>=constant_pool.size())
7070
{
71-
error() << "invalid constant pool index (" << index << ")" << eom;
72-
error() << "constant pool size: " << constant_pool.size() << eom;
71+
log.error() << "invalid constant pool index (" << index << ")"
72+
<< messaget::eom;
73+
log.error() << "constant pool size: " << constant_pool.size()
74+
<< messaget::eom;
7375
throw 0;
7476
}
7577

@@ -119,7 +121,7 @@ class java_bytecode_parsert final : public parsert
119121
{
120122
if(!*in)
121123
{
122-
error() << "unexpected end of bytecode file" << eom;
124+
log.error() << "unexpected end of bytecode file" << messaget::eom;
123125
throw 0;
124126
}
125127
in->get();
@@ -137,7 +139,7 @@ class java_bytecode_parsert final : public parsert
137139
{
138140
if(!*in)
139141
{
140-
error() << "unexpected end of bytecode file" << eom;
142+
log.error() << "unexpected end of bytecode file" << messaget::eom;
141143
throw 0;
142144
}
143145
result <<= 8u;
@@ -386,19 +388,19 @@ bool java_bytecode_parsert::parse()
386388

387389
catch(const char *message)
388390
{
389-
error() << message << eom;
391+
log.error() << message << messaget::eom;
390392
return true;
391393
}
392394

393395
catch(const std::string &message)
394396
{
395-
error() << message << eom;
397+
log.error() << message << messaget::eom;
396398
return true;
397399
}
398400

399401
catch(...)
400402
{
401-
error() << "parsing error" << eom;
403+
log.error() << "parsing error" << messaget::eom;
402404
return true;
403405
}
404406

@@ -437,13 +439,13 @@ void java_bytecode_parsert::rClassFile()
437439

438440
if(magic!=0xCAFEBABE)
439441
{
440-
error() << "wrong magic" << eom;
442+
log.error() << "wrong magic" << messaget::eom;
441443
throw 0;
442444
}
443445

444446
if(major_version<44)
445447
{
446-
error() << "unexpected major version" << eom;
448+
log.error() << "unexpected major version" << messaget::eom;
447449
throw 0;
448450
}
449451

@@ -643,7 +645,7 @@ void java_bytecode_parsert::rconstant_pool()
643645
const u2 constant_pool_count = read<u2>();
644646
if(constant_pool_count==0)
645647
{
646-
error() << "invalid constant_pool_count" << eom;
648+
log.error() << "invalid constant_pool_count" << messaget::eom;
647649
throw 0;
648650
}
649651

@@ -685,7 +687,7 @@ void java_bytecode_parsert::rconstant_pool()
685687
// Eight-byte constants take up two entries in the constant_pool table.
686688
if(it==constant_pool.end())
687689
{
688-
error() << "invalid double entry" << eom;
690+
log.error() << "invalid double entry" << messaget::eom;
689691
throw 0;
690692
}
691693
it++;
@@ -709,8 +711,8 @@ void java_bytecode_parsert::rconstant_pool()
709711
break;
710712

711713
default:
712-
error() << "unknown constant pool entry (" << it->tag << ")"
713-
<< eom;
714+
log.error() << "unknown constant pool entry (" << it->tag << ")"
715+
<< messaget::eom;
714716
throw 0;
715717
}
716718
}
@@ -1142,7 +1144,7 @@ void java_bytecode_parsert::rbytecode(std::vector<instructiont> &instructions)
11421144

11431145
if(address!=code_length)
11441146
{
1145-
error() << "bytecode length mismatch" << eom;
1147+
log.error() << "bytecode length mismatch" << messaget::eom;
11461148
throw 0;
11471149
}
11481150
}
@@ -1811,7 +1813,7 @@ optionalt<java_bytecode_parse_treet> java_bytecode_parse(
18111813
{
18121814
java_bytecode_parsert java_bytecode_parser(skip_instructions);
18131815
java_bytecode_parser.in=&istream;
1814-
java_bytecode_parser.set_message_handler(message_handler);
1816+
java_bytecode_parser.log.set_message_handler(message_handler);
18151817

18161818
bool parser_result=java_bytecode_parser.parse();
18171819

@@ -1980,9 +1982,15 @@ void java_bytecode_parsert::read_bootstrapmethods_entry()
19801982

19811983
method_handle_infot method_handle{entry};
19821984

1985+
<<<<<<< HEAD
19831986
const u2 num_bootstrap_arguments = read<u2>();
19841987
debug() << "INFO: parse BootstrapMethod handle " << num_bootstrap_arguments
19851988
<< " #args" << eom;
1989+
=======
1990+
u2 num_bootstrap_arguments = read_u2();
1991+
log.debug() << "INFO: parse BootstrapMethod handle "
1992+
<< num_bootstrap_arguments << " #args" << messaget::eom;
1993+
>>>>>>> parsert is not a messaget
19861994

19871995
// read u2 values of entry into vector
19881996
std::vector<u2> u2_values(num_bootstrap_arguments);
@@ -2021,10 +2029,16 @@ void java_bytecode_parsert::read_bootstrapmethods_entry()
20212029
// understand
20222030
if(num_bootstrap_arguments < 3)
20232031
{
2032+
<<<<<<< HEAD
20242033
store_unknown_method_handle(bootstrap_method_index);
20252034
debug()
2035+
=======
2036+
store_unknown_method_handle(
2037+
parsed_class, bootstrap_method_index, std::move(u2_values));
2038+
log.debug()
2039+
>>>>>>> parsert is not a messaget
20262040
<< "format of BootstrapMethods entry not recognized: too few arguments"
2027-
<< eom;
2041+
<< messaget::eom;
20282042
continue;
20292043
}
20302044

@@ -2045,10 +2059,18 @@ void java_bytecode_parsert::read_bootstrapmethods_entry()
20452059

20462060
if(!recognized)
20472061
{
2062+
<<<<<<< HEAD
20482063
debug() << "format of BootstrapMethods entry not recognized: extra "
20492064
"arguments of wrong type"
20502065
<< eom;
20512066
store_unknown_method_handle(bootstrap_method_index);
2067+
=======
2068+
log.debug() << "format of BootstrapMethods entry not recognized: extra "
2069+
"arguments of wrong type"
2070+
<< messaget::eom;
2071+
store_unknown_method_handle(
2072+
parsed_class, bootstrap_method_index, std::move(u2_values));
2073+
>>>>>>> parsert is not a messaget
20522074
continue;
20532075
}
20542076

@@ -2062,30 +2084,48 @@ void java_bytecode_parsert::read_bootstrapmethods_entry()
20622084
method_handle_argument.tag != CONSTANT_MethodHandle ||
20632085
method_type_argument.tag != CONSTANT_MethodType)
20642086
{
2087+
<<<<<<< HEAD
20652088
debug() << "format of BootstrapMethods entry not recognized: arguments "
20662089
"wrong type"
20672090
<< eom;
20682091
store_unknown_method_handle(bootstrap_method_index);
2092+
=======
2093+
log.debug()
2094+
<< "format of BootstrapMethods entry not recognized: arguments "
2095+
"wrong type"
2096+
<< messaget::eom;
2097+
store_unknown_method_handle(
2098+
parsed_class, bootstrap_method_index, std::move(u2_values));
2099+
>>>>>>> parsert is not a messaget
20692100
continue;
20702101
}
20712102

2072-
debug() << "INFO: parse lambda handle" << eom;
2103+
log.debug() << "INFO: parse lambda handle" << messaget::eom;
20732104
optionalt<lambda_method_handlet> lambda_method_handle =
20742105
parse_method_handle(method_handle_infot{method_handle_argument});
20752106

20762107
if(!lambda_method_handle.has_value())
20772108
{
2109+
<<<<<<< HEAD
20782110
debug() << "format of BootstrapMethods entry not recognized: method "
20792111
"handle not recognised"
20802112
<< eom;
20812113
store_unknown_method_handle(bootstrap_method_index);
2114+
=======
2115+
log.debug() << "format of BootstrapMethods entry not recognized: method "
2116+
"handle not recognised"
2117+
<< messaget::eom;
2118+
store_unknown_method_handle(
2119+
parsed_class, bootstrap_method_index, std::move(u2_values));
2120+
>>>>>>> parsert is not a messaget
20822121
continue;
20832122
}
20842123

20852124
// If parse_method_handle can't parse the lambda method, it should return {}
20862125
POSTCONDITION(
20872126
lambda_method_handle->handle_type != method_handle_typet::UNKNOWN_HANDLE);
20882127

2128+
<<<<<<< HEAD
20892129
debug() << "lambda function reference "
20902130
<< id2string(lambda_method_handle->get_method_descriptor()
20912131
.base_method_name())
@@ -2095,6 +2135,21 @@ void java_bytecode_parsert::read_bootstrapmethods_entry()
20952135
<< "\n method type is "
20962136
<< id2string(pool_entry(method_type_argument.ref1).s) << eom;
20972137
parse_tree.parsed_class.add_method_handle(
2138+
=======
2139+
lambda_method_handle->interface_type =
2140+
pool_entry(interface_type_argument.ref1).s;
2141+
lambda_method_handle->method_type = pool_entry(method_type_argument.ref1).s;
2142+
lambda_method_handle->u2_values = std::move(u2_values);
2143+
log.debug() << "lambda function reference "
2144+
<< id2string(lambda_method_handle->lambda_method_name)
2145+
<< " in class \"" << parsed_class.name << "\""
2146+
<< "\n interface type is "
2147+
<< id2string(pool_entry(interface_type_argument.ref1).s)
2148+
<< "\n method type is "
2149+
<< id2string(pool_entry(method_type_argument.ref1).s)
2150+
<< messaget::eom;
2151+
parsed_class.add_method_handle(
2152+
>>>>>>> parsert is not a messaget
20982153
bootstrap_method_index, *lambda_method_handle);
20992154
}
21002155
}

src/ansi-c/ansi_c_language.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ bool ansi_c_languaget::parse(
8080
ansi_c_parser.clear();
8181
ansi_c_parser.set_file(ID_built_in);
8282
ansi_c_parser.in=&codestr;
83-
ansi_c_parser.set_message_handler(message_handler);
83+
ansi_c_parser.log.set_message_handler(message_handler);
8484
ansi_c_parser.for_has_scope=config.ansi_c.for_has_scope;
8585
ansi_c_parser.ts_18661_3_Floatn_types=config.ansi_c.ts_18661_3_Floatn_types;
8686
ansi_c_parser.cpp98=false; // it's not C++
@@ -199,7 +199,7 @@ bool ansi_c_languaget::to_expr(
199199
ansi_c_parser.clear();
200200
ansi_c_parser.set_file(irep_idt());
201201
ansi_c_parser.in=&i_preprocessed;
202-
ansi_c_parser.set_message_handler(message_handler);
202+
ansi_c_parser.log.set_message_handler(message_handler);
203203
ansi_c_parser.mode=config.ansi_c.mode;
204204
ansi_c_parser.ts_18661_3_Floatn_types=config.ansi_c.ts_18661_3_Floatn_types;
205205
ansi_c_scanner_init();

src/ansi-c/builtin_factory.cpp

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ bool cpp_languaget::parse(
113113
cpp_parser.clear();
114114
cpp_parser.set_file(path);
115115
cpp_parser.in=&i_preprocessed;
116-
cpp_parser.set_message_handler(message_handler);
116+
cpp_parser.log.set_message_handler(message_handler);
117117
cpp_parser.mode=config.ansi_c.mode;
118118

119119
bool result=cpp_parser.parse();
@@ -260,7 +260,7 @@ bool cpp_languaget::to_expr(
260260
cpp_parser.clear();
261261
cpp_parser.set_file(irep_idt());
262262
cpp_parser.in=&i_preprocessed;
263-
cpp_parser.set_message_handler(message_handler);
263+
cpp_parser.log.set_message_handler(message_handler);
264264

265265
bool result=cpp_parser.parse();
266266

src/cpp/cpp_parser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ bool cpp_parsert::parse()
2828
ansi_c_parser.in=in;
2929
ansi_c_parser.mode=mode;
3030
ansi_c_parser.set_file(get_file());
31-
ansi_c_parser.set_message_handler(get_message_handler());
31+
ansi_c_parser.log.set_message_handler(log.get_message_handler());
3232

3333
return cpp_parse();
3434
}

src/cpp/parse.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -511,8 +511,8 @@ bool Parser::SyntaxError()
511511

512512
message+="'";
513513

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

518518
return ++number_of_errors < max_errors;

src/jsil/jsil_language.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ bool jsil_languaget::parse(
6565
jsil_parser.clear();
6666
jsil_parser.set_file(path);
6767
jsil_parser.in=&instream;
68-
jsil_parser.set_message_handler(message_handler);
68+
jsil_parser.log.set_message_handler(message_handler);
6969

7070
jsil_scanner_init();
7171
bool result=jsil_parser.parse();
@@ -141,7 +141,7 @@ bool jsil_languaget::to_expr(
141141
jsil_parser.clear();
142142
jsil_parser.set_file(irep_idt());
143143
jsil_parser.in=&instream;
144-
jsil_parser.set_message_handler(message_handler);
144+
jsil_parser.log.set_message_handler(message_handler);
145145
jsil_scanner_init();
146146

147147
bool result=jsil_parser.parse();

src/json/json_parser.cpp

Lines changed: 1 addition & 1 deletion
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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ void parsert::parse_error(
3535
if(!before.empty())
3636
tmp += " before '" + before + "'";
3737

38+
<<<<<<< HEAD
3839
#if 0
3940
source_locationt tmp_source_location=source_location;
4041
tmp_source_location.set_column(column-before.size());
@@ -43,4 +44,8 @@ void parsert::parse_error(
4344
error().source_location=source_location;
4445
error() << tmp << eom;
4546
#endif
47+
=======
48+
log.error().source_location = source_location;
49+
log.error() << tmp << messaget::eom;
50+
>>>>>>> parsert is not a messaget
4651
}

src/util/parser.h

Lines changed: 5 additions & 1 deletion
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;

0 commit comments

Comments
 (0)