@@ -88,6 +88,62 @@ void class_hierarchy_grapht::populate(const symbol_tablet &symbol_table)
88
88
}
89
89
}
90
90
91
+ // / Helper function that converts a vector of node_indext to a vector of ids
92
+ // / that are stored in the corresponding nodes in the graph.
93
+ class_hierarchy_grapht::idst class_hierarchy_grapht::ids_from_indices (
94
+ const std::vector<node_indext> &nodes) const
95
+ {
96
+ idst result;
97
+ std::transform (
98
+ nodes.begin (),
99
+ nodes.end (),
100
+ std::back_inserter (result),
101
+ [&](const node_indext &node_index) {
102
+ return (*this )[node_index].class_identifier ;
103
+ });
104
+ return result;
105
+ }
106
+
107
+ // / Get all the classes that directly (i.e. in one step) inherit from class c.
108
+ // / \param c: The class to consider
109
+ // / \return A list containing ids of all direct children of c.
110
+ class_hierarchy_grapht::idst
111
+ class_hierarchy_grapht::get_direct_children (const irep_idt &c) const
112
+ {
113
+ const node_indext &node_index = nodes_by_name.at (c);
114
+ const auto &child_indices = get_successors (node_index);
115
+ return ids_from_indices (child_indices);
116
+ }
117
+
118
+ // / Helper function for `get_children_trans` and `get_parents_trans`
119
+ class_hierarchy_grapht::idst class_hierarchy_grapht::get_reachable_ids (
120
+ const irep_idt &c,
121
+ bool forwards) const
122
+ {
123
+ idst direct_child_ids;
124
+ const node_indext &node_index = nodes_by_name.at (c);
125
+ const auto &reachable_indices = get_reachable (node_index, forwards);
126
+ return ids_from_indices (reachable_indices);
127
+ }
128
+
129
+ // / Get all the classes that inherit (directly or indirectly) from class c.
130
+ // / \param c: The class to consider
131
+ // / \return A list containing ids of all classes that eventually inherit from c.
132
+ class_hierarchy_grapht::idst
133
+ class_hierarchy_grapht::get_children_trans (const irep_idt &c) const
134
+ {
135
+ return get_reachable_ids (c, true );
136
+ }
137
+
138
+ // / Get all the classes that class c inherits from (directly or indirectly).
139
+ // / \param c: The class to consider
140
+ // / \return A list of class ids that c eventually inherits from.
141
+ class_hierarchy_grapht::idst
142
+ class_hierarchy_grapht::get_parents_trans (const irep_idt &c) const
143
+ {
144
+ return get_reachable_ids (c, false );
145
+ }
146
+
91
147
void class_hierarchyt::get_children_trans_rec (
92
148
const irep_idt &c,
93
149
idst &dest) const
@@ -105,7 +161,7 @@ void class_hierarchyt::get_children_trans_rec(
105
161
get_children_trans_rec (child, dest);
106
162
}
107
163
108
- // / Get all the classes that inherit (directly or indirectly) from class c . The
164
+ // / Get all the classes that class c inherits from (directly or indirectly). The
109
165
// / first element(s) will be the immediate parents of c, though after this
110
166
// / the order is all the parents of the first immediate parent
111
167
// / \param c: The class to consider
0 commit comments