Skip to content

Commit f90ed9e

Browse files
authored
Merge pull request diffblue#2515 from NathanJPhillips/feature/ignored-methods
Add ability to mark methods as ignored (not loaded)
2 parents 0c20014 + 4a12a29 commit f90ed9e

File tree

4 files changed

+53
-44
lines changed

4 files changed

+53
-44
lines changed

jbmc/src/java_bytecode/java_bytecode_convert_class.cpp

+13-8
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,15 @@ class java_bytecode_convert_classt:public messaget
118118
// see definition below for more info
119119
static void add_array_types(symbol_tablet &symbol_table);
120120

121-
static bool is_overlay_method(const methodt &method);
121+
static bool is_overlay_method(const methodt &method)
122+
{
123+
return method.has_annotation(ID_overlay_method);
124+
}
125+
126+
static bool is_ignored_method(const methodt &method)
127+
{
128+
return method.has_annotation(ID_ignored_method);
129+
}
122130

123131
bool check_field_exists(
124132
const fieldt &field,
@@ -455,6 +463,8 @@ void java_bytecode_convert_classt::convert(
455463
{
456464
for(const methodt &method : overlay_class.get().methods)
457465
{
466+
if(is_ignored_method(method))
467+
continue;
458468
const irep_idt method_identifier =
459469
qualified_classname + "." + id2string(method.name)
460470
+ ":" + method.descriptor;
@@ -496,6 +506,8 @@ void java_bytecode_convert_classt::convert(
496506
}
497507
for(const methodt &method : c.methods)
498508
{
509+
if(is_ignored_method(method))
510+
continue;
499511
const irep_idt method_identifier=
500512
qualified_classname + "." + id2string(method.name)
501513
+ ":" + method.descriptor;
@@ -877,13 +889,6 @@ void java_bytecode_convert_classt::add_array_types(symbol_tablet &symbol_table)
877889
}
878890
}
879891

880-
bool java_bytecode_convert_classt::is_overlay_method(const methodt &method)
881-
{
882-
return java_bytecode_parse_treet::find_annotation(
883-
method.annotations, ID_overlay_method)
884-
.has_value();
885-
}
886-
887892
bool java_bytecode_convert_class(
888893
const java_class_loadert::parse_tree_with_overlayst &parse_trees,
889894
symbol_tablet &symbol_table,

jbmc/src/java_bytecode/java_bytecode_parse_tree.h

+5
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ class java_bytecode_parse_treet
8484
is_private(false), is_static(false), is_final(false)
8585
{
8686
}
87+
88+
bool has_annotation(const irep_idt &annotation_id) const
89+
{
90+
return find_annotation(annotations, annotation_id).has_value();
91+
}
8792
};
8893

8994
class methodt:public membert

jbmc/src/java_bytecode/java_class_loader.cpp

+34-36
Original file line numberDiff line numberDiff line change
@@ -168,50 +168,48 @@ java_class_loadert::get_parse_tree(
168168
}
169169
}
170170

171-
if(!parse_trees.empty())
171+
auto parse_tree_it = parse_trees.begin();
172+
// If the first class implementation is an overlay emit a warning and
173+
// skip over it until we find a non-overlay class
174+
while(parse_tree_it != parse_trees.end())
172175
{
173-
auto parse_tree_it = parse_trees.begin();
174-
// If the first class implementation is an overlay emit a warning and
175-
// skip over it until we find a non-overlay class
176-
while(parse_tree_it != parse_trees.end())
177-
{
178-
// Skip parse trees that failed to load - though these shouldn't exist yet
179-
if(parse_tree_it->loading_successful)
180-
{
181-
if(!is_overlay_class(parse_tree_it->parsed_class))
182-
{
183-
// Keep the non-overlay class
184-
++parse_tree_it;
185-
break;
186-
}
187-
warning()
188-
<< "Skipping class " << class_name
189-
<< " marked with OverlayClassImplementation but found before"
190-
" original definition"
191-
<< eom;
192-
}
193-
auto unloaded_or_overlay_out_of_order_it = parse_tree_it;
194-
++parse_tree_it;
195-
parse_trees.erase(unloaded_or_overlay_out_of_order_it);
196-
}
197-
// Collect overlay classes
198-
while(parse_tree_it != parse_trees.end())
176+
// Skip parse trees that failed to load - though these shouldn't exist yet
177+
if(parse_tree_it->loading_successful)
199178
{
200-
// Remove non-initial classes that aren't overlays
201179
if(!is_overlay_class(parse_tree_it->parsed_class))
202180
{
203-
warning()
204-
<< "Skipping duplicate definition of class " << class_name
205-
<< " not marked with OverlayClassImplementation" << eom;
206-
auto duplicate_non_overlay_it = parse_tree_it;
181+
// Keep the non-overlay class
207182
++parse_tree_it;
208-
parse_trees.erase(duplicate_non_overlay_it);
183+
break;
209184
}
210-
else
211-
++parse_tree_it;
185+
warning()
186+
<< "Skipping class " << class_name
187+
<< " marked with OverlayClassImplementation but found before"
188+
" original definition"
189+
<< eom;
212190
}
213-
return parse_trees;
191+
auto unloaded_or_overlay_out_of_order_it = parse_tree_it;
192+
++parse_tree_it;
193+
parse_trees.erase(unloaded_or_overlay_out_of_order_it);
214194
}
195+
// Collect overlay classes
196+
while(parse_tree_it != parse_trees.end())
197+
{
198+
// Remove non-initial classes that aren't overlays
199+
if(!is_overlay_class(parse_tree_it->parsed_class))
200+
{
201+
warning()
202+
<< "Skipping duplicate definition of class " << class_name
203+
<< " not marked with OverlayClassImplementation" << eom;
204+
auto duplicate_non_overlay_it = parse_tree_it;
205+
++parse_tree_it;
206+
parse_trees.erase(duplicate_non_overlay_it);
207+
}
208+
else
209+
++parse_tree_it;
210+
}
211+
if(!parse_trees.empty())
212+
return parse_trees;
215213

216214
// Not found or failed to load
217215
warning() << "failed to load class `" << class_name << '\'' << eom;

src/util/irep_ids.def

+1
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,7 @@ IREP_ID_TWO(overflow_shl, overflow-shl)
664664
IREP_ID_TWO(C_no_initialization_required, #no_initialization_required)
665665
IREP_ID_TWO(overlay_class, java::com.diffblue.OverlayClassImplementation)
666666
IREP_ID_TWO(overlay_method, java::com.diffblue.OverlayMethodImplementation)
667+
IREP_ID_TWO(ignored_method, java::com.diffblue.IgnoredMethodImplementation)
667668
IREP_ID_ONE(is_annotation)
668669
IREP_ID_TWO(C_annotations, #annotations)
669670
IREP_ID_ONE(final)

0 commit comments

Comments
 (0)