Skip to content

Commit 2f4c6ad

Browse files
Add and unify --show-class-hierarchy command line option
1 parent a018e2f commit 2f4c6ad

19 files changed

+101
-10
lines changed
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
public abstract class HierarchyTest {
2+
// These fields exist only so the classloader will load all test classes:
3+
HierarchyTestGrandchild field1;
4+
HierarchyTestChild2 field2;
5+
6+
abstract void foo();
7+
}
8+
9+
class HierarchyTestChild1 extends HierarchyTest {
10+
void foo() {}
11+
}
12+
13+
class HierarchyTestChild2 extends HierarchyTest {
14+
void foo() {}
15+
}
16+
17+
class HierarchyTestGrandchild extends HierarchyTestChild1
18+
implements HierarchyTestInterface1, HierarchyTestInterface2 {}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
interface HierarchyTestInterface1 {}
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
interface HierarchyTestInterface2 {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CORE symex-driven-lazy-loading-expected-failure
2+
HierarchyTest.class
3+
--show-class-hierarchy --json-ui
4+
activate-multi-line-match
5+
EXIT=0
6+
SIGNAL=0
7+
\{\n *"isAbstract": true,\n *"name": "java::HierarchyTest",\n *"parents": \[\n *"java::java.lang.Object"\n *\],\n *"children": \[\n *"java::HierarchyTestChild(1|2)",\n *"java::HierarchyTestChild(1|2)"\n *\]\n *\},\n *\{\n *"isAbstract": false,\n *"name": "java::HierarchyTestGrandchild",\n *"parents": \[\n *"java::HierarchyTestChild1",\n *"java::HierarchyTestInterface1",\n *"java::HierarchyTestInterface2"\n *\],\n *"children": \[\n *\]\n *\},\n *\{\n *"isAbstract": false,\n *"name": "java::HierarchyTestChild2",\n *"parents": \[\n *"java::HierarchyTest"\n *\],\n *"children": \[\n *\]\n *\},\n *\{\n *"isAbstract": false,\n *"name": "java::HierarchyTestChild1",\n *"parents": \[\n *"java::HierarchyTest"\n *\],\n *"children": \[\n *"java::HierarchyTestGrandchild"\n *\]\n *\},\n *\{\n *"isAbstract": true,\n *"name": "java::HierarchyTestInterface1",\n *"parents": \[\n *"java::java.lang.Object"\n *\],\n *"children": \[\n *"java::HierarchyTestGrandchild"\n *\]\n *\},\n *\{\n *"isAbstract": true,\n *"name": "java::HierarchyTestInterface2",\n *"parents": \[\n *"java::java.lang.Object"\n *\],\n *"children": \[\n *"java::HierarchyTestGrandchild"\n *\]\n *\},
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CORE symex-driven-lazy-loading-expected-failure
2+
HierarchyTest.class
3+
--show-class-hierarchy
4+
activate-multi-line-match
5+
EXIT=0
6+
SIGNAL=0
7+
java::HierarchyTest \(abstract\):\n *parents:\n *java::java\.lang\.Object\n *children:\n *java::HierarchyTestChild(1|2)\n *java::HierarchyTestChild(1|2)\njava::HierarchyTestGrandchild:\n *parents:\n *java::HierarchyTestChild1\n *java::HierarchyTestInterface1\n *java::HierarchyTestInterface2\n *children:\njava::HierarchyTestChild2:\n *parents:\n *java::HierarchyTest\n *children:\njava::HierarchyTestChild1:\n *parents:\n *java::HierarchyTest\n *children:\n *java::HierarchyTestGrandchild\njava::HierarchyTestInterface1 \(abstract\):\n *parents:\n *java::java\.lang\.Object\n *children:\n *java::HierarchyTestGrandchild\njava::HierarchyTestInterface2 \(abstract\):\n *parents:\n *java::java\.lang\.Object\n *children:\n *java::HierarchyTestGrandchild

jbmc/src/jbmc/jbmc_parse_options.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,16 @@ int jbmc_parse_optionst::get_goto_program(
645645
*this, options, get_message_handler());
646646
lazy_goto_model.initialize(cmdline);
647647

648+
// Show the class hierarchy
649+
if(cmdline.isset("show-class-hierarchy"))
650+
{
651+
class_hierarchyt hierarchy;
652+
hierarchy(lazy_goto_model.symbol_table);
653+
show_class_hierarchy(
654+
hierarchy, get_message_handler(), ui_message_handler.get_ui());
655+
return CPROVER_EXIT_SUCCESS;
656+
}
657+
648658
// Add failed symbols for any symbol created prior to loading any
649659
// particular function:
650660
add_failed_symbols(lazy_goto_model.symbol_table);
@@ -1079,6 +1089,7 @@ void jbmc_parse_optionst::help()
10791089
" --show-symbol-table show loaded symbol table\n"
10801090
HELP_SHOW_GOTO_FUNCTIONS
10811091
" --drop-unused-functions drop functions trivially unreachable from main function\n" // NOLINT(*)
1092+
HELP_SHOW_CLASS_HIERARCHY
10821093
"\n"
10831094
"Program instrumentation options:\n"
10841095
HELP_GOTO_CHECK

jbmc/src/jbmc/jbmc_parse_options.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@ Author: Daniel Kroening, [email protected]
2222

2323
#include <cbmc/bmc.h>
2424

25+
#include <goto-instrument/cover.h>
26+
#include <goto-programs/class_hierarchy.h>
2527
#include <goto-programs/goto_trace.h>
2628
#include <goto-programs/lazy_goto_model.h>
2729
#include <goto-programs/show_properties.h>
28-
#include <goto-instrument/cover.h>
2930

3031
#include <goto-symex/path_storage.h>
3132

@@ -60,6 +61,7 @@ class optionst;
6061
"(string-max-input-length):" \
6162
"(16)(32)(64)(LP64)(ILP64)(LLP64)(ILP32)(LP32)" \
6263
OPT_SHOW_GOTO_FUNCTIONS \
64+
OPT_SHOW_CLASS_HIERARCHY \
6365
"(show-loops)" \
6466
"(show-symbol-table)(show-parse-tree)" \
6567
OPT_SHOW_PROPERTIES \
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
CORE
22
main.c
3-
--class-hierarchy --dot
3+
--show-class-hierarchy --dot
44
digraph class_hierarchy
55
^EXIT=0$
66
^SIGNAL=0$
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
CORE
22
main.c
3-
--class-hierarchy
3+
--show-class-hierarchy
44
^EXIT=0$
55
^SIGNAL=0$

src/goto-instrument/goto_instrument_parse_options.cpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -652,16 +652,17 @@ int goto_instrument_parse_optionst::doit()
652652
return 0;
653653
}
654654

655-
if(cmdline.isset("class-hierarchy"))
655+
if(cmdline.isset("show-class-hierarchy"))
656656
{
657657
class_hierarchyt hierarchy;
658658
hierarchy(goto_model.symbol_table);
659659
if(cmdline.isset("dot"))
660660
hierarchy.output_dot(std::cout);
661661
else
662-
hierarchy.output(std::cout, false);
662+
show_class_hierarchy(
663+
hierarchy, get_message_handler(), ui_message_handler.get_ui());
663664

664-
return 0;
665+
return CPROVER_EXIT_SUCCESS;
665666
}
666667

667668
if(cmdline.isset("dot"))
@@ -1472,7 +1473,7 @@ void goto_instrument_parse_optionst::help()
14721473
" --call-graph show graph of function calls\n"
14731474
// NOLINTNEXTLINE(whitespace/line_length)
14741475
" --reachable-call-graph show graph of function calls potentially reachable from main function\n"
1475-
" --class-hierarchy show class hierarchy\n"
1476+
HELP_SHOW_CLASS_HIERARCHY
14761477
// NOLINTNEXTLINE(whitespace/line_length)
14771478
" --show-threaded show instructions that may be executed by more than one thread\n"
14781479
"\n"

src/goto-instrument/goto_instrument_parse_options.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@ Author: Daniel Kroening, [email protected]
1616
#include <util/parse_options.h>
1717
#include <util/timestamper.h>
1818

19+
#include <goto-programs/class_hierarchy.h>
1920
#include <goto-programs/goto_functions.h>
20-
#include <goto-programs/show_goto_functions.h>
21-
#include <goto-programs/show_properties.h>
2221
#include <goto-programs/remove_calls_no_body.h>
2322
#include <goto-programs/remove_const_function_pointers.h>
23+
#include <goto-programs/show_goto_functions.h>
24+
#include <goto-programs/show_properties.h>
2425

2526
#include <analyses/goto_check.h>
2627

@@ -50,7 +51,7 @@ Author: Daniel Kroening, [email protected]
5051
"(max-var):(max-po-trans):(ignore-arrays)" \
5152
"(cfg-kill)(no-dependencies)(force-loop-duplication)" \
5253
"(call-graph)(reachable-call-graph)" \
53-
"(class-hierarchy)" \
54+
OPT_SHOW_CLASS_HIERARCHY \
5455
"(no-po-rendering)(render-cluster-file)(render-cluster-function)" \
5556
"(nondet-volatile)(isr):" \
5657
"(stack-depth):(nondet-static)" \

src/goto-programs/class_hierarchy.cpp

+21
Original file line numberDiff line numberDiff line change
@@ -192,3 +192,24 @@ void class_hierarchyt::output(
192192
json_children.push_back(json_stringt(ch));
193193
}
194194
}
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+
}

src/goto-programs/class_hierarchy.h

+21
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,19 @@ Date: April 2016
2020

2121
#include <util/graph.h>
2222
#include <util/irep.h>
23+
#include <util/ui_message.h>
24+
25+
// clang-format off
26+
#define OPT_SHOW_CLASS_HIERARCHY \
27+
"(show-class-hierarchy)"
28+
29+
#define HELP_SHOW_CLASS_HIERARCHY \
30+
" --show-class-hierarchy show the class hierarchy\n"
31+
// clang-format on
2332

2433
class symbol_tablet;
2534
class json_stream_arrayt;
35+
class message_handlert;
2636

2737
class class_hierarchyt
2838
{
@@ -96,4 +106,15 @@ class class_hierarchy_grapht : public grapht<class_hierarchy_graph_nodet>
96106
nodes_by_namet nodes_by_name;
97107
};
98108

109+
/// Output the class hierarchy
110+
/// \param hierarchy: the class hierarchy to be printed
111+
/// \param message_handler: the message handler
112+
/// \param ui: the UI format
113+
/// \param children_only: print the children only and do not print the parents
114+
void show_class_hierarchy(
115+
const class_hierarchyt &hierarchy,
116+
message_handlert &message_handler,
117+
ui_message_handlert::uit ui,
118+
bool children_only = false);
119+
99120
#endif // CPROVER_GOTO_PROGRAMS_CLASS_HIERARCHY_H

0 commit comments

Comments
 (0)