Skip to content

Commit c682411

Browse files
committed
Make direct children of a class publicly available
Previously it was only possible to retrieve all children of a class (i.e. those that inherit directly and those that inherit by transitivity) given its ID. The new function retrieves only those children that inherit directly from the given class.
1 parent 6566d10 commit c682411

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

src/goto-programs/class_hierarchy.cpp

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,24 +88,39 @@ void class_hierarchy_grapht::populate(const symbol_tablet &symbol_table)
8888
}
8989
}
9090

91+
/// Get all the classes that directly (i.e. in one step) inherit from class c.
92+
/// \param c: The class to consider
93+
/// \return A list containing ids of all direct children of c.
94+
class_hierarchyt::idst
95+
class_hierarchyt::get_direct_children(const irep_idt &c) const
96+
{
97+
idst dest;
98+
class_mapt::const_iterator it = class_map.find(c);
99+
if(it == class_map.end())
100+
return dest;
101+
const entryt &entry = it->second;
102+
for(const auto &child : entry.children)
103+
dest.push_back(child);
104+
return dest;
105+
}
106+
107+
/// Get all the classes that inherit (directly or indirectly) from class c.
108+
/// \param c: The class to consider
109+
/// \param [out] dest: A list containing ids of all classes that eventually
110+
/// inherit from c.
91111
void class_hierarchyt::get_children_trans_rec(
92112
const irep_idt &c,
93113
idst &dest) const
94114
{
95-
class_mapt::const_iterator it=class_map.find(c);
96-
if(it==class_map.end())
97-
return;
98-
const entryt &entry=it->second;
99-
100-
for(const auto &child : entry.children)
115+
const idst &next_children = get_direct_children(c);
116+
for(const auto child : next_children)
101117
dest.push_back(child);
102-
103118
// recursive calls
104-
for(const auto &child : entry.children)
119+
for(const auto &child : next_children)
105120
get_children_trans_rec(child, dest);
106121
}
107122

108-
/// Get all the classes that inherit (directly or indirectly) from class c. The
123+
/// Get all the classes that class c inherits from (directly or indirectly). The
109124
/// first element(s) will be the immediate parents of c, though after this
110125
/// the order is all the parents of the first immediate parent
111126
/// \param c: The class to consider

src/goto-programs/class_hierarchy.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ class class_hierarchyt
5151

5252
void operator()(const symbol_tablet &);
5353

54+
idst get_direct_children(const irep_idt &c) const;
55+
5456
// transitively gets all children
5557
idst get_children_trans(const irep_idt &id) const
5658
{

0 commit comments

Comments
 (0)