Skip to content

Stop unneccessary copies of class_hierarchyt #2971

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class java_bytecode_convert_methodt:public messaget
bool method_has_this;
std::map<irep_idt, bool> class_has_clinit_method;
std::map<irep_idt, bool> any_superclass_has_clinit_method;
class_hierarchyt class_hierarchy;
const class_hierarchyt &class_hierarchy;

enum instruction_sizet
{
Expand Down
4 changes: 4 additions & 0 deletions src/goto-programs/class_hierarchy.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ class class_hierarchyt

void operator()(const symbol_tablet &);

class_hierarchyt() = default;
class_hierarchyt(const class_hierarchyt &) = delete;
class_hierarchyt &operator=(const class_hierarchyt &) = delete;

// transitively gets all children
idst get_children_trans(const irep_idt &id) const
{
Expand Down
40 changes: 17 additions & 23 deletions src/goto-programs/resolve_inherited_component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,14 @@

#include "resolve_inherited_component.h"

/// See the operator() method comment.
/// \param symbol_table: The symbol table to resolve the component against
resolve_inherited_componentt::resolve_inherited_componentt(
const symbol_tablet &symbol_table):
symbol_table(symbol_table)
{
class_hierarchy(symbol_table);
}

/// See the operator() method comment
/// \param symbol_table: The symbol table to resolve the component against
/// \param class_hierarchy: A prebuilt class_hierachy based on the symbol_table
///
resolve_inherited_componentt::resolve_inherited_componentt(
const symbol_tablet &symbol_table, const class_hierarchyt &class_hierarchy):
class_hierarchy(class_hierarchy),
symbol_table(symbol_table)
const symbol_tablet &symbol_table,
const class_hierarchyt &clas_hierarchy)
: class_hierarchy(clas_hierarchy), symbol_table(symbol_table)
{
// We require the class_hierarchy to be already populated if we are being
// supplied it.
Expand Down Expand Up @@ -67,18 +58,21 @@ resolve_inherited_componentt::inherited_componentt
return inherited_componentt(current_class, component_name);
}

const class_hierarchyt::idst &parents=
class_hierarchy.class_map[current_class].parents;

if(include_interfaces)
{
classes_to_visit.insert(
classes_to_visit.end(), parents.begin(), parents.end());
}
else
const auto current_class_id = class_hierarchy.class_map.find(current_class);
if(current_class_id != class_hierarchy.class_map.end())
{
if(!parents.empty())
classes_to_visit.push_back(parents.front());
const class_hierarchyt::idst &parents = current_class_id->second.parents;

if(include_interfaces)
{
classes_to_visit.insert(
classes_to_visit.end(), parents.begin(), parents.end());
}
else
{
if(!parents.empty())
classes_to_visit.push_back(parents.front());
}
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/goto-programs/resolve_inherited_component.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
class resolve_inherited_componentt
{
public:
explicit resolve_inherited_componentt(const symbol_tablet &symbol_table);
resolve_inherited_componentt(
const symbol_tablet &symbol_table, const class_hierarchyt &class_hierarchy);

Expand Down Expand Up @@ -70,7 +69,7 @@ class resolve_inherited_componentt
const irep_idt &component_name,
const irep_idt &user_class_name);

class_hierarchyt class_hierarchy;
const class_hierarchyt &class_hierarchy;
const symbol_tablet &symbol_table;
};

Expand Down