Skip to content

Commit 68c45ed

Browse files
Improve class hierarchy output
more readable output, adds info whether class is abstract removes the plain text unit test which is replaced by a JBMC regression test in a later commit
1 parent e5e0897 commit 68c45ed

File tree

4 files changed

+25
-23
lines changed

4 files changed

+25
-23
lines changed

jbmc/unit/java_bytecode/goto-programs/class_hierarchy_output.cpp

+6-14
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,15 @@
1717
void require_parent_child_relationship(
1818
const std::string &parent_raw,
1919
const std::string &child_raw,
20-
const std::string &output,
2120
const std::string &output_dot)
2221
{
2322
std::string parent = "java::" + parent_raw;
2423
std::string child = "java::" + child_raw;
2524

26-
std::stringstream
27-
plain_child_expectation, plain_parent_expectation, dot_expectation;
25+
std::stringstream dot_expectation;
2826

29-
plain_child_expectation << "Child of " << parent << ": " << child;
30-
plain_parent_expectation << "Parent of " << child << ": " << parent;
3127
dot_expectation << "\"" << child << "\" -> \"" << parent << "\"";
3228

33-
REQUIRE(output.find(plain_child_expectation.str()) != std::string::npos);
34-
REQUIRE(output.find(plain_parent_expectation.str()) != std::string::npos);
3529
REQUIRE(output_dot.find(dot_expectation.str()) != std::string::npos);
3630
}
3731

@@ -47,20 +41,18 @@ SCENARIO(
4741
std::stringstream output_dot_stream;
4842

4943
hierarchy(symbol_table);
50-
hierarchy.output(output_stream);
5144
hierarchy.output_dot(output_dot_stream);
5245

53-
std::string output = output_stream.str();
5446
std::string output_dot = output_dot_stream.str();
5547

5648
require_parent_child_relationship(
57-
"HierarchyTest", "HierarchyTestChild1", output, output_dot);
49+
"HierarchyTest", "HierarchyTestChild1", output_dot);
5850
require_parent_child_relationship(
59-
"HierarchyTest", "HierarchyTestChild2", output, output_dot);
51+
"HierarchyTest", "HierarchyTestChild2", output_dot);
6052
require_parent_child_relationship(
61-
"HierarchyTestChild1", "HierarchyTestGrandchild", output, output_dot);
53+
"HierarchyTestChild1", "HierarchyTestGrandchild", output_dot);
6254
require_parent_child_relationship(
63-
"HierarchyTestInterface1", "HierarchyTestGrandchild", output, output_dot);
55+
"HierarchyTestInterface1", "HierarchyTestGrandchild", output_dot);
6456
require_parent_child_relationship(
65-
"HierarchyTestInterface2", "HierarchyTestGrandchild", output, output_dot);
57+
"HierarchyTestInterface2", "HierarchyTestGrandchild", output_dot);
6658
}

src/goto-instrument/goto_instrument_parse_options.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,7 @@ int goto_instrument_parse_optionst::doit()
659659
if(cmdline.isset("dot"))
660660
hierarchy.output_dot(std::cout);
661661
else
662-
hierarchy.output(std::cout);
662+
hierarchy.output(std::cout, false);
663663

664664
return 0;
665665
}

src/goto-programs/class_hierarchy.cpp

+16-7
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ void class_hierarchyt::operator()(const symbol_tablet &symbol_table)
3030
{
3131
const struct_typet &struct_type = to_struct_type(symbol_pair.second.type);
3232

33+
class_map[symbol_pair.first].is_abstract =
34+
struct_type.get_bool(ID_abstract);
35+
3336
const irept::subt &bases=
3437
struct_type.find(ID_bases).get_sub();
3538

@@ -123,17 +126,23 @@ void class_hierarchyt::get_parents_trans_rec(
123126
get_parents_trans_rec(child, dest);
124127
}
125128

126-
void class_hierarchyt::output(std::ostream &out) const
129+
/// Output the class hierarchy in plain text
130+
/// \param out: the output stream
131+
/// \param children_only: print the children only and do not print the parents
132+
void class_hierarchyt::output(std::ostream &out, bool children_only) const
127133
{
128134
for(const auto &c : class_map)
129135
{
130-
for(const auto &pa : c.second.parents)
131-
out << "Parent of " << c.first << ": "
132-
<< pa << '\n';
133-
136+
out << c.first << (c.second.is_abstract ? " (abstract)" : "") << ":\n";
137+
if(!children_only)
138+
{
139+
out << " parents:\n";
140+
for(const auto &pa : c.second.parents)
141+
out << " " << pa << '\n';
142+
}
143+
out << " children:\n";
134144
for(const auto &ch : c.second.children)
135-
out << "Child of " << c.first << ": "
136-
<< ch << '\n';
145+
out << " " << ch << '\n';
137146
}
138147
}
139148

src/goto-programs/class_hierarchy.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class class_hierarchyt
3232
{
3333
public:
3434
idst parents, children;
35+
bool is_abstract;
3536
};
3637

3738
typedef std::map<irep_idt, entryt> class_mapt;
@@ -55,7 +56,7 @@ class class_hierarchyt
5556
return result;
5657
}
5758

58-
void output(std::ostream &) const;
59+
void output(std::ostream &, bool children_only) const;
5960
void output_dot(std::ostream &) const;
6061

6162
protected:

0 commit comments

Comments
 (0)