Skip to content

Commit 299307b

Browse files
authored
Merge pull request #5596 from tautschnig/messaget-java_bytecode_convert
java_bytecode_convert* aren't messaget
2 parents f0a22a7 + 66ffe18 commit 299307b

File tree

4 files changed

+100
-92
lines changed

4 files changed

+100
-92
lines changed

jbmc/src/java_bytecode/java_bytecode_convert_class.cpp

Lines changed: 66 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Author: Daniel Kroening, [email protected]
3131
#include <util/std_expr.h>
3232
#include <util/suffix.h>
3333

34-
class java_bytecode_convert_classt:public messaget
34+
class java_bytecode_convert_classt
3535
{
3636
public:
3737
java_bytecode_convert_classt(
@@ -41,7 +41,7 @@ class java_bytecode_convert_classt:public messaget
4141
method_bytecodet &method_bytecode,
4242
java_string_library_preprocesst &_string_preprocess,
4343
const std::unordered_set<std::string> &no_load_classes)
44-
: messaget(_message_handler),
44+
: log(_message_handler),
4545
symbol_table(_symbol_table),
4646
max_array_length(_max_array_length),
4747
method_bytecode(method_bytecode),
@@ -98,7 +98,7 @@ class java_bytecode_convert_classt:public messaget
9898
generate_class_stub(
9999
class_name,
100100
symbol_table,
101-
get_message_handler(),
101+
log.get_message_handler(),
102102
struct_union_typet::componentst{});
103103
}
104104

@@ -108,6 +108,7 @@ class java_bytecode_convert_classt:public messaget
108108
typedef java_bytecode_parse_treet::annotationt annotationt;
109109

110110
private:
111+
messaget log;
111112
symbol_tablet &symbol_table;
112113
const size_t max_array_length;
113114
method_bytecodet &method_bytecode;
@@ -274,7 +275,8 @@ void java_bytecode_convert_classt::convert(
274275
std::string qualified_classname="java::"+id2string(c.name);
275276
if(symbol_table.has_symbol(qualified_classname))
276277
{
277-
debug() << "Skip class " << c.name << " (already loaded)" << eom;
278+
log.debug() << "Skip class " << c.name << " (already loaded)"
279+
<< messaget::eom;
278280
return;
279281
}
280282

@@ -302,10 +304,10 @@ void java_bytecode_convert_classt::convert(
302304
}
303305
catch(const unsupported_java_class_signature_exceptiont &e)
304306
{
305-
debug() << "Class: " << c.name
306-
<< "\n could not parse signature: " << c.signature.value()
307-
<< "\n " << e.what() << "\n ignoring that the class is generic"
308-
<< eom;
307+
log.debug() << "Class: " << c.name
308+
<< "\n could not parse signature: " << c.signature.value()
309+
<< "\n " << e.what()
310+
<< "\n ignoring that the class is generic" << messaget::eom;
309311
}
310312
}
311313

@@ -325,9 +327,11 @@ void java_bytecode_convert_classt::convert(
325327
{
326328
if(max_array_length != 0 && c.enum_elements > max_array_length)
327329
{
328-
warning() << "Java Enum " << c.name << " won't work properly because max "
329-
<< "array length (" << max_array_length << ") is less than the "
330-
<< "enum size (" << c.enum_elements << ")" << eom;
330+
log.warning() << "Java Enum " << c.name
331+
<< " won't work properly because max "
332+
<< "array length (" << max_array_length
333+
<< ") is less than the "
334+
<< "enum size (" << c.enum_elements << ")" << messaget::eom;
331335
}
332336
class_type.set(
333337
ID_java_enum_static_unwind,
@@ -364,10 +368,12 @@ void java_bytecode_convert_classt::convert(
364368
}
365369
catch(const unsupported_java_class_signature_exceptiont &e)
366370
{
367-
debug() << "Superclass: " << c.super_class << " of class: " << c.name
368-
<< "\n could not parse signature: " << superclass_ref.value()
369-
<< "\n " << e.what()
370-
<< "\n ignoring that the superclass is generic" << eom;
371+
log.debug() << "Superclass: " << c.super_class
372+
<< " of class: " << c.name
373+
<< "\n could not parse signature: "
374+
<< superclass_ref.value() << "\n " << e.what()
375+
<< "\n ignoring that the superclass is generic"
376+
<< messaget::eom;
371377
class_type.add_base(base);
372378
}
373379
}
@@ -404,10 +410,11 @@ void java_bytecode_convert_classt::convert(
404410
}
405411
catch(const unsupported_java_class_signature_exceptiont &e)
406412
{
407-
debug() << "Interface: " << interface << " of class: " << c.name
408-
<< "\n could not parse signature: " << interface_ref.value()
409-
<< "\n " << e.what()
410-
<< "\n ignoring that the interface is generic" << eom;
413+
log.debug() << "Interface: " << interface << " of class: " << c.name
414+
<< "\n could not parse signature: " << interface_ref.value()
415+
<< "\n " << e.what()
416+
<< "\n ignoring that the interface is generic"
417+
<< messaget::eom;
411418
class_type.add_base(base);
412419
}
413420
}
@@ -455,10 +462,11 @@ void java_bytecode_convert_classt::convert(
455462
symbolt *class_symbol;
456463

457464
// add before we do members
458-
debug() << "Adding symbol: class '" << c.name << "'" << eom;
465+
log.debug() << "Adding symbol: class '" << c.name << "'" << messaget::eom;
459466
if(symbol_table.move(new_symbol, class_symbol))
460467
{
461-
error() << "failed to add class symbol " << new_symbol.name << eom;
468+
log.error() << "failed to add class symbol " << new_symbol.name
469+
<< messaget::eom;
462470
throw 0;
463471
}
464472

@@ -477,12 +485,11 @@ void java_bytecode_convert_classt::convert(
477485
std::string err =
478486
"Duplicate field definition for " + field_id + " in overlay class";
479487
// TODO: This could just be a warning if the types match
480-
error() << err << eom;
488+
log.error() << err << messaget::eom;
481489
throw err.c_str();
482490
}
483-
debug()
484-
<< "Adding symbol from overlay class: field '" << field.name << "'"
485-
<< eom;
491+
log.debug() << "Adding symbol from overlay class: field '" << field.name
492+
<< "'" << messaget::eom;
486493
convert(*class_symbol, field);
487494
POSTCONDITION(check_field_exists(field, field_id, fields));
488495
}
@@ -493,12 +500,12 @@ void java_bytecode_convert_classt::convert(
493500
if(check_field_exists(field, field_id, fields))
494501
{
495502
// TODO: This could be a warning if the types match
496-
error()
497-
<< "Field definition for " << field_id
498-
<< " already loaded from overlay class" << eom;
503+
log.error() << "Field definition for " << field_id
504+
<< " already loaded from overlay class" << messaget::eom;
499505
continue;
500506
}
501-
debug() << "Adding symbol: field '" << field.name << "'" << eom;
507+
log.debug() << "Adding symbol: field '" << field.name << "'"
508+
<< messaget::eom;
502509
convert(*class_symbol, field);
503510
POSTCONDITION(check_field_exists(field, field_id, fields));
504511
}
@@ -514,9 +521,8 @@ void java_bytecode_convert_classt::convert(
514521
+ ":" + method.descriptor;
515522
if(is_ignored_method(c.name, method))
516523
{
517-
debug()
518-
<< "Ignoring method: '" << method_identifier << "'"
519-
<< eom;
524+
log.debug() << "Ignoring method: '" << method_identifier << "'"
525+
<< messaget::eom;
520526
continue;
521527
}
522528
if(method_bytecode.contains_method(method_identifier))
@@ -530,26 +536,25 @@ void java_bytecode_convert_classt::convert(
530536
{
531537
// This method was defined in a previous class definition without
532538
// being marked as an overlay method
533-
warning()
539+
log.warning()
534540
<< "Method " << method_identifier
535541
<< " exists in an overlay class without being marked as an "
536-
"overlay and also exists in another overlay class that appears "
537-
"earlier in the classpath"
538-
<< eom;
542+
"overlay and also exists in another overlay class that appears "
543+
"earlier in the classpath"
544+
<< messaget::eom;
539545
}
540546
continue;
541547
}
542548
// Always run the lazy pre-stage, as it symbol-table
543549
// registers the function.
544-
debug()
545-
<< "Adding symbol from overlay class: method '" << method_identifier
546-
<< "'" << eom;
550+
log.debug() << "Adding symbol from overlay class: method '"
551+
<< method_identifier << "'" << messaget::eom;
547552
java_bytecode_convert_method_lazy(
548553
*class_symbol,
549554
method_identifier,
550555
method,
551556
symbol_table,
552-
get_message_handler());
557+
log.get_message_handler());
553558
method_bytecode.add(qualified_classname, method_identifier, method);
554559
if(is_overlay_method(method))
555560
overlay_methods.insert(method_identifier);
@@ -562,9 +567,8 @@ void java_bytecode_convert_classt::convert(
562567
+ ":" + method.descriptor;
563568
if(is_ignored_method(c.name, method))
564569
{
565-
debug()
566-
<< "Ignoring method: '" << method_identifier << "'"
567-
<< eom;
570+
log.debug() << "Ignoring method: '" << method_identifier << "'"
571+
<< messaget::eom;
568572
continue;
569573
}
570574
if(method_bytecode.contains_method(method_identifier))
@@ -577,39 +581,41 @@ void java_bytecode_convert_classt::convert(
577581
{
578582
// This method was defined in a previous class definition without
579583
// being marked as an overlay method
580-
warning()
584+
log.warning()
581585
<< "Method " << method_identifier
582586
<< " exists in an overlay class without being marked as an overlay "
583-
"and also exists in the underlying class"
584-
<< eom;
587+
"and also exists in the underlying class"
588+
<< messaget::eom;
585589
}
586590
continue;
587591
}
588592
// Always run the lazy pre-stage, as it symbol-table
589593
// registers the function.
590-
debug() << "Adding symbol: method '" << method_identifier << "'" << eom;
594+
log.debug() << "Adding symbol: method '" << method_identifier << "'"
595+
<< messaget::eom;
591596
java_bytecode_convert_method_lazy(
592597
*class_symbol,
593598
method_identifier,
594599
method,
595600
symbol_table,
596-
get_message_handler());
601+
log.get_message_handler());
597602
method_bytecode.add(qualified_classname, method_identifier, method);
598603
if(is_overlay_method(method))
599604
{
600-
warning()
605+
log.warning()
601606
<< "Method " << method_identifier
602-
<< " marked as an overlay where defined in the underlying class" << eom;
607+
<< " marked as an overlay where defined in the underlying class"
608+
<< messaget::eom;
603609
}
604610
}
605611
if(!overlay_methods.empty())
606612
{
607-
error()
613+
log.error()
608614
<< "Overlay methods defined in overlay classes did not exist in the "
609-
"underlying class:\n";
615+
"underlying class:\n";
610616
for(const irep_idt &method_id : overlay_methods)
611-
error() << " " << method_id << "\n";
612-
error() << eom;
617+
log.error() << " " << method_id << "\n";
618+
log.error() << messaget::eom;
613619
}
614620

615621
// is this a root class?
@@ -744,8 +750,8 @@ void java_bytecode_convert_classt::convert(
744750
const auto value = zero_initializer(field_type, class_symbol.location, ns);
745751
if(!value.has_value())
746752
{
747-
error().source_location = class_symbol.location;
748-
error() << "failed to zero-initialize " << f.name << eom;
753+
log.error().source_location = class_symbol.location;
754+
log.error() << "failed to zero-initialize " << f.name << messaget::eom;
749755
throw 0;
750756
}
751757
new_symbol.value = *value;
@@ -1025,12 +1031,14 @@ bool java_bytecode_convert_class(
10251031

10261032
catch(const char *e)
10271033
{
1028-
java_bytecode_convert_class.error() << e << messaget::eom;
1034+
messaget log{message_handler};
1035+
log.error() << e << messaget::eom;
10291036
}
10301037

10311038
catch(const std::string &e)
10321039
{
1033-
java_bytecode_convert_class.error() << e << messaget::eom;
1040+
messaget log{message_handler};
1041+
log.error() << e << messaget::eom;
10341042
}
10351043

10361044
return true;

jbmc/src/java_bytecode/java_bytecode_convert_method.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ exprt::operandst java_bytecode_convert_methodt::pop(std::size_t n)
134134
{
135135
if(stack.size()<n)
136136
{
137-
error() << "malformed bytecode (pop too high)" << eom;
137+
log.error() << "malformed bytecode (pop too high)" << messaget::eom;
138138
throw 0;
139139
}
140140

@@ -575,8 +575,8 @@ void java_bytecode_convert_methodt::convert(
575575
// the formal parameters
576576
slots_for_parameters = java_method_parameter_slots(method_type);
577577

578-
debug() << "Generating codet: class " << class_symbol.name << ", method "
579-
<< m.name << eom;
578+
log.debug() << "Generating codet: class " << class_symbol.name << ", method "
579+
<< m.name << messaget::eom;
580580

581581
// Add parameter symbols to the symbol table
582582
create_parameter_symbols(parameters, variables, symbol_table);
@@ -870,11 +870,11 @@ code_blockt &java_bytecode_convert_methodt::get_or_create_block_for_pcrange(
870870
{
871871
if(p<(*findstart) || p>=findlim_block_start_address)
872872
{
873-
debug() << "Generating codet: "
874-
<< "warning: refusing to create lexical block spanning "
875-
<< (*findstart) << "-" << findlim_block_start_address
876-
<< " due to incoming edge " << p << " -> "
877-
<< checkit->first << eom;
873+
log.debug() << "Generating codet: "
874+
<< "warning: refusing to create lexical block spanning "
875+
<< (*findstart) << "-" << findlim_block_start_address
876+
<< " due to incoming edge " << p << " -> " << checkit->first
877+
<< messaget::eom;
878878
return this_block;
879879
}
880880
}
@@ -893,10 +893,10 @@ code_blockt &java_bytecode_convert_methodt::get_or_create_block_for_pcrange(
893893
code_blockt &newblock=to_code_block(newlabel.code());
894894
auto nblocks=std::distance(findstart, findlim);
895895
assert(nblocks>=2);
896-
debug() << "Generating codet: combining "
897-
<< std::distance(findstart, findlim)
898-
<< " blocks for addresses " << (*findstart) << "-"
899-
<< findlim_block_start_address << eom;
896+
log.debug() << "Generating codet: combining "
897+
<< std::distance(findstart, findlim) << " blocks for addresses "
898+
<< (*findstart) << "-" << findlim_block_start_address
899+
<< messaget::eom;
900900

901901
// Make a new block containing every child of interest:
902902
auto &this_block_children = this_block.statements();
@@ -2312,7 +2312,7 @@ void java_bytecode_convert_methodt::convert_invoke(
23122312
method_type,
23132313
class_method_descriptor.class_id(),
23142314
symbol_table,
2315-
get_message_handler());
2315+
log.get_message_handler());
23162316
}
23172317

23182318
exprt function;
@@ -3075,8 +3075,8 @@ optionalt<exprt> java_bytecode_convert_methodt::convert_invoke_dynamic(
30753075
const auto value = zero_initializer(return_type, location, ns);
30763076
if(!value.has_value())
30773077
{
3078-
error().source_location = location;
3079-
error() << "failed to zero-initialize return type" << eom;
3078+
log.error().source_location = location;
3079+
log.error() << "failed to zero-initialize return type" << messaget::eom;
30803080
throw 0;
30813081
}
30823082
return value;

jbmc/src/java_bytecode/java_bytecode_convert_method_class.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Author: Daniel Kroening, [email protected]
2929
class symbol_tablet;
3030
class symbolt;
3131

32-
class java_bytecode_convert_methodt:public messaget
32+
class java_bytecode_convert_methodt
3333
{
3434
public:
3535
java_bytecode_convert_methodt(
@@ -42,7 +42,7 @@ class java_bytecode_convert_methodt:public messaget
4242
const class_hierarchyt &class_hierarchy,
4343
bool threading_support,
4444
bool assert_no_exceptions_thrown)
45-
: messaget(_message_handler),
45+
: log(_message_handler),
4646
symbol_table(symbol_table),
4747
ns(symbol_table),
4848
max_array_length(_max_array_length),
@@ -74,6 +74,7 @@ class java_bytecode_convert_methodt:public messaget
7474
typedef uint16_t method_offsett;
7575

7676
protected:
77+
messaget log;
7778
symbol_table_baset &symbol_table;
7879
namespacet ns;
7980
const size_t max_array_length;

0 commit comments

Comments
 (0)