Skip to content

Commit a018e2f

Browse files
Add JSON output for class hierarchy
1 parent 68c45ed commit a018e2f

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

src/goto-programs/class_hierarchy.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Date: April 2016
1515

1616
#include <ostream>
1717

18+
#include <util/json_stream.h>
1819
#include <util/std_types.h>
1920
#include <util/symbol_table.h>
2021

@@ -165,3 +166,29 @@ void class_hierarchyt::output_dot(std::ostream &ostr) const
165166
}
166167
ostr << "}\n";
167168
}
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+
}

src/goto-programs/class_hierarchy.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Date: April 2016
2222
#include <util/irep.h>
2323

2424
class symbol_tablet;
25+
class json_stream_arrayt;
2526

2627
class class_hierarchyt
2728
{
@@ -58,6 +59,7 @@ class class_hierarchyt
5859

5960
void output(std::ostream &, bool children_only) const;
6061
void output_dot(std::ostream &) const;
62+
void output(json_stream_arrayt &, bool children_only) const;
6163

6264
protected:
6365
void get_children_trans_rec(const irep_idt &, idst &) const;

0 commit comments

Comments
 (0)