Skip to content

Commit a7e55aa

Browse files
Add JSON output for class hierarchy
1 parent 2851625 commit a7e55aa

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/goto-programs/class_hierarchy.cpp

Lines changed: 20 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

@@ -158,3 +159,22 @@ void class_hierarchyt::output_dot(std::ostream &ostr) const
158159
}
159160
ostr << "}\n";
160161
}
162+
163+
void class_hierarchyt::output(json_stream_arrayt &json_stream, bool children_only) const
164+
{
165+
for(const auto &c : class_map)
166+
{
167+
json_stream_objectt &json_class = json_stream.push_back_stream_object();
168+
json_class["name"] = json_stringt(c.first);
169+
json_class["isAbstract"] = jsont::json_boolean(c.second.is_abstract);
170+
if(!children_only)
171+
{
172+
json_stream_arrayt &json_parents = json_class.push_back_stream_array("parents");
173+
for(const auto &pa : c.second.parents)
174+
json_parents.push_back(json_stringt(pa));
175+
}
176+
json_stream_arrayt &json_children = json_class.push_back_stream_array("children");
177+
for(const auto &ch : c.second.children)
178+
json_children.push_back(json_stringt(ch));
179+
}
180+
}

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)