Skip to content

Commit 2082719

Browse files
Merge pull request #5118 from owen-mc-diffblue/remove-unneeded-class-hierarchy-from-resolve-inherited-componentt
Remove unneeded class hierarchy from resolve_inherited_componentt
2 parents da454ce + 0c9a5bc commit 2082719

8 files changed

+21
-28
lines changed

jbmc/src/java_bytecode/ci_lazy_methods.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ irep_idt ci_lazy_methodst::get_virtual_method_target(
547547
if(!instantiated_classes.count(classname))
548548
return irep_idt();
549549

550-
resolve_inherited_componentt call_resolver(symbol_table, class_hierarchy);
550+
resolve_inherited_componentt call_resolver{symbol_table};
551551
const auto resolved_call = call_resolver(classname, call_basename, false);
552552

553553
if(resolved_call)

jbmc/src/java_bytecode/java_bytecode_convert_method.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3209,8 +3209,8 @@ bool java_bytecode_convert_methodt::is_method_inherited(
32093209
const irep_idt &classname,
32103210
const irep_idt &methodid) const
32113211
{
3212-
const auto inherited_method = get_inherited_component(
3213-
classname, methodid, symbol_table, class_hierarchy, false);
3212+
const auto inherited_method =
3213+
get_inherited_component(classname, methodid, symbol_table, false);
32143214
return inherited_method.has_value();
32153215
}
32163216

@@ -3224,7 +3224,7 @@ irep_idt java_bytecode_convert_methodt::get_static_field(
32243224
const irep_idt &component_name) const
32253225
{
32263226
const auto inherited_method = get_inherited_component(
3227-
class_identifier, component_name, symbol_table, class_hierarchy, true);
3227+
class_identifier, component_name, symbol_table, true);
32283228

32293229
INVARIANT(
32303230
inherited_method.has_value(), "static field should be in symbol table");

jbmc/src/java_bytecode/java_bytecode_language.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -672,8 +672,8 @@ static void create_stub_global_symbols(
672672

673673
// The final 'true' parameter here includes interfaces, as they can
674674
// define static fields.
675-
const auto referred_component = get_inherited_component(
676-
class_id, component, symbol_table, class_hierarchy, true);
675+
const auto referred_component =
676+
get_inherited_component(class_id, component, symbol_table, true);
677677
if(!referred_component)
678678
{
679679
// Create a new stub global on an arbitrary incomplete ancestor of the

jbmc/src/java_bytecode/java_utils.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,6 @@ std::string pretty_print_java_type(const std::string &fqn_java_type)
371371
/// \param component_name: component basename to search for. If searching for
372372
/// A.b, this is "b".
373373
/// \param symbol_table: global symbol table.
374-
/// \param class_hierarchy: global class hierarchy.
375374
/// \param include_interfaces: if true, search for the given component in all
376375
/// ancestors including interfaces, rather than just parents.
377376
/// \return the concrete component referred to if any is found, or an invalid
@@ -381,11 +380,9 @@ get_inherited_component(
381380
const irep_idt &component_class_id,
382381
const irep_idt &component_name,
383382
const symbol_tablet &symbol_table,
384-
const class_hierarchyt &class_hierarchy,
385383
bool include_interfaces)
386384
{
387-
resolve_inherited_componentt component_resolver(
388-
symbol_table, class_hierarchy);
385+
resolve_inherited_componentt component_resolver{symbol_table};
389386
const auto resolved_component =
390387
component_resolver(component_class_id, component_name, include_interfaces);
391388

jbmc/src/java_bytecode/java_utils.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ get_inherited_component(
122122
const irep_idt &component_class_id,
123123
const irep_idt &component_name,
124124
const symbol_tablet &symbol_table,
125-
const class_hierarchyt &class_hierarchy,
126125
bool include_interfaces);
127126

128127
bool is_non_null_library_global(const irep_idt &);

src/goto-programs/remove_virtual_functions.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -589,8 +589,7 @@ void get_virtual_calleest::get_functions(
589589
const std::string function_name_string(id2string(function_name));
590590
INVARIANT(!class_id.empty(), "All virtual functions must have a class");
591591

592-
resolve_inherited_componentt get_virtual_call_target(
593-
symbol_table, class_hierarchy);
592+
resolve_inherited_componentt get_virtual_call_target{symbol_table};
594593
const function_call_resolvert resolve_function_call =
595594
[&get_virtual_call_target](
596595
const irep_idt &class_id, const irep_idt &function_name) {

src/goto-programs/resolve_inherited_component.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,10 @@ Author: Diffblue Ltd.
1212

1313
/// See the operator() method comment
1414
/// \param symbol_table: The symbol table to resolve the component against
15-
/// \param class_hierarchy: A prebuilt class_hierachy based on the symbol_table
16-
///
1715
resolve_inherited_componentt::resolve_inherited_componentt(
18-
const symbol_tablet &symbol_table,
19-
const class_hierarchyt &class_hierarchy)
20-
: class_hierarchy(class_hierarchy), symbol_table(symbol_table)
16+
const symbol_tablet &symbol_table)
17+
: symbol_table(symbol_table)
2118
{
22-
// We require the class_hierarchy to be already populated if we are being
23-
// supplied it.
24-
PRECONDITION(!class_hierarchy.class_map.empty());
2519
}
2620

2721
/// Given a class and a component, identify the concrete field or method it is
@@ -58,10 +52,16 @@ resolve_inherited_componentt::operator()(
5852
return inherited_componentt(current_class, component_name);
5953
}
6054

61-
const auto current_class_id = class_hierarchy.class_map.find(current_class);
62-
if(current_class_id != class_hierarchy.class_map.end())
55+
const auto current_class_symbol_it =
56+
symbol_table.symbols.find(current_class);
57+
58+
if(current_class_symbol_it != symbol_table.symbols.end())
6359
{
64-
const class_hierarchyt::idst &parents = current_class_id->second.parents;
60+
const auto parents =
61+
make_range(to_struct_type(current_class_symbol_it->second.type).bases())
62+
.map([](const struct_typet::baset &base) {
63+
return base.type().get_identifier();
64+
});
6565

6666
if(include_interfaces)
6767
{
@@ -71,7 +71,7 @@ resolve_inherited_componentt::operator()(
7171
else
7272
{
7373
if(!parents.empty())
74-
classes_to_visit.push_back(parents.front());
74+
classes_to_visit.push_back(*parents.begin());
7575
}
7676
}
7777
}

src/goto-programs/resolve_inherited_component.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ Author: Diffblue Ltd.
2121
class resolve_inherited_componentt
2222
{
2323
public:
24-
resolve_inherited_componentt(
25-
const symbol_tablet &symbol_table, const class_hierarchyt &class_hierarchy);
24+
explicit resolve_inherited_componentt(const symbol_tablet &symbol_table);
2625

2726
class inherited_componentt
2827
{
@@ -54,7 +53,6 @@ class resolve_inherited_componentt
5453
const irep_idt &class_name, const irep_idt &component_name);
5554

5655
private:
57-
const class_hierarchyt &class_hierarchy;
5856
const symbol_tablet &symbol_table;
5957
};
6058

0 commit comments

Comments
 (0)