@@ -15,6 +15,7 @@ Date: April 2016
15
15
16
16
#include < ostream>
17
17
18
+ #include < util/json_stream.h>
18
19
#include < util/std_types.h>
19
20
#include < util/symbol_table.h>
20
21
@@ -30,6 +31,9 @@ void class_hierarchyt::operator()(const symbol_tablet &symbol_table)
30
31
{
31
32
const struct_typet &struct_type = to_struct_type (symbol_pair.second .type );
32
33
34
+ class_map[symbol_pair.first ].is_abstract =
35
+ struct_type.get_bool (ID_abstract);
36
+
33
37
const irept::subt &bases=
34
38
struct_type.find (ID_bases).get_sub ();
35
39
@@ -123,17 +127,23 @@ void class_hierarchyt::get_parents_trans_rec(
123
127
get_parents_trans_rec (child, dest);
124
128
}
125
129
126
- void class_hierarchyt::output (std::ostream &out) const
130
+ // / Output the class hierarchy in plain text
131
+ // / \param out: the output stream
132
+ // / \param children_only: print the children only and do not print the parents
133
+ void class_hierarchyt::output (std::ostream &out, bool children_only) const
127
134
{
128
135
for (const auto &c : class_map)
129
136
{
130
- for (const auto &pa : c.second .parents )
131
- out << " Parent of " << c.first << " : "
132
- << pa << ' \n ' ;
133
-
137
+ out << c.first << (c.second .is_abstract ? " (abstract)" : " " ) << " :\n " ;
138
+ if (!children_only)
139
+ {
140
+ out << " parents:\n " ;
141
+ for (const auto &pa : c.second .parents )
142
+ out << " " << pa << ' \n ' ;
143
+ }
144
+ out << " children:\n " ;
134
145
for (const auto &ch : c.second .children )
135
- out << " Child of " << c.first << " : "
136
- << ch << ' \n ' ;
146
+ out << " " << ch << ' \n ' ;
137
147
}
138
148
}
139
149
@@ -156,3 +166,50 @@ void class_hierarchyt::output_dot(std::ostream &ostr) const
156
166
}
157
167
ostr << " }\n " ;
158
168
}
169
+
170
+ // / Output the class hierarchy in JSON format
171
+ // / \param json_stream: the output JSON stream array
172
+ // / \param children_only: print the children only and do not print the parents
173
+ void class_hierarchyt::output (
174
+ json_stream_arrayt &json_stream,
175
+ bool children_only) const
176
+ {
177
+ for (const auto &c : class_map)
178
+ {
179
+ json_stream_objectt &json_class = json_stream.push_back_stream_object ();
180
+ json_class[" name" ] = json_stringt (c.first );
181
+ json_class[" isAbstract" ] = jsont::json_boolean (c.second .is_abstract );
182
+ if (!children_only)
183
+ {
184
+ json_stream_arrayt &json_parents =
185
+ json_class.push_back_stream_array (" parents" );
186
+ for (const auto &pa : c.second .parents )
187
+ json_parents.push_back (json_stringt (pa));
188
+ }
189
+ json_stream_arrayt &json_children =
190
+ json_class.push_back_stream_array (" children" );
191
+ for (const auto &ch : c.second .children )
192
+ json_children.push_back (json_stringt (ch));
193
+ }
194
+ }
195
+
196
+ void show_class_hierarchy (
197
+ const class_hierarchyt &hierarchy,
198
+ message_handlert &message_handler,
199
+ ui_message_handlert::uit ui,
200
+ bool children_only)
201
+ {
202
+ messaget msg (message_handler);
203
+ switch (ui)
204
+ {
205
+ case ui_message_handlert::uit::PLAIN:
206
+ hierarchy.output (msg.result (), children_only);
207
+ msg.result () << messaget::eom;
208
+ break ;
209
+ case ui_message_handlert::uit::JSON_UI:
210
+ hierarchy.output (msg.result ().json_stream (), children_only);
211
+ break ;
212
+ case ui_message_handlert::uit::XML_UI:
213
+ UNIMPLEMENTED;
214
+ }
215
+ }
0 commit comments