Skip to content

Commit 57da328

Browse files
Add JSON output for class hierarchy
1 parent 78cf3b9 commit 57da328

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

src/goto-programs/class_hierarchy.cpp

+27
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

@@ -162,3 +163,29 @@ void class_hierarchyt::output_dot(std::ostream &ostr) const
162163
}
163164
ostr << "}\n";
164165
}
166+
167+
/// Output the class hierarchy in JSON format
168+
/// \param json_stream: the output JSON stream array
169+
/// \param children_only: print the children only and do not print the parents
170+
void class_hierarchyt::output(
171+
json_stream_arrayt &json_stream,
172+
bool children_only) const
173+
{
174+
for(const auto &c : class_map)
175+
{
176+
json_stream_objectt &json_class = json_stream.push_back_stream_object();
177+
json_class["name"] = json_stringt(c.first);
178+
json_class["isAbstract"] = jsont::json_boolean(c.second.is_abstract);
179+
if(!children_only)
180+
{
181+
json_stream_arrayt &json_parents =
182+
json_class.push_back_stream_array("parents");
183+
for(const auto &pa : c.second.parents)
184+
json_parents.push_back(json_stringt(pa));
185+
}
186+
json_stream_arrayt &json_children =
187+
json_class.push_back_stream_array("children");
188+
for(const auto &ch : c.second.children)
189+
json_children.push_back(json_stringt(ch));
190+
}
191+
}

src/goto-programs/class_hierarchy.h

+2
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)