CBMC
class_hierarchy.h
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: Class Hierarchy
4 
5 Author: Daniel Kroening
6 
7 Date: April 2016
8 
9 \*******************************************************************/
10 
13 
14 #ifndef CPROVER_GOTO_PROGRAMS_CLASS_HIERARCHY_H
15 #define CPROVER_GOTO_PROGRAMS_CLASS_HIERARCHY_H
16 
17 #include <iosfwd>
18 #include <map>
19 #include <unordered_map>
20 
21 #include <util/graph.h>
22 #include <util/irep.h>
23 
24 #define OPT_SHOW_CLASS_HIERARCHY \
25  "(show-class-hierarchy)"
26 
27 #define HELP_SHOW_CLASS_HIERARCHY \
28  " {y--show-class-hierarchy} \t show the class hierarchy\n"
29 
30 class symbol_table_baset;
31 class json_stream_arrayt;
33 
41 {
42 public:
43  typedef std::vector<irep_idt> idst;
44 
45  class entryt
46  {
47  public:
50  };
51 
52  typedef std::map<irep_idt, entryt> class_mapt;
54 
55  void operator()(const symbol_table_baset &);
56 
57  class_hierarchyt() = default;
58  explicit class_hierarchyt(const symbol_table_baset &symbol_table)
59  {
60  (*this)(symbol_table);
61  }
64 
65  // transitively gets all children
66  idst get_children_trans(const irep_idt &id) const
67  {
68  idst result;
69  get_children_trans_rec(id, result);
70  return result;
71  }
72 
73  // transitively gets all parents
74  idst get_parents_trans(const irep_idt &id) const
75  {
76  idst result;
77  get_parents_trans_rec(id, result);
78  return result;
79  }
80 
81  void output(std::ostream &, bool children_only) const;
82  void output_dot(std::ostream &) const;
83  void output(json_stream_arrayt &, bool children_only) const;
84 
85 protected:
86  void get_children_trans_rec(const irep_idt &, idst &) const;
87  void get_parents_trans_rec(const irep_idt &, idst &) const;
88 };
89 
91 class class_hierarchy_graph_nodet : public graph_nodet<empty_edget>
92 {
93 public:
96 };
97 
100 class class_hierarchy_grapht : public grapht<class_hierarchy_graph_nodet>
101 {
102 public:
103  typedef std::vector<irep_idt> idst;
104 
106  typedef std::unordered_map<irep_idt, node_indext> nodes_by_namet;
107 
108  void populate(const symbol_table_baset &);
109 
113  {
114  return nodes_by_name;
115  }
116 
117  idst get_direct_children(const irep_idt &c) const;
118 
119  idst get_children_trans(const irep_idt &c) const;
120 
121  idst get_parents_trans(const irep_idt &c) const;
122 
123 private:
126 
127  idst ids_from_indices(const std::vector<node_indext> &nodes) const;
128 
129  idst get_other_reachable_ids(const irep_idt &c, bool forwards) const;
130 };
131 
137  const class_hierarchyt &hierarchy,
138  ui_message_handlert &message_handler,
139  bool children_only = false);
140 
141 #endif // CPROVER_GOTO_PROGRAMS_CLASS_HIERARCHY_H
void show_class_hierarchy(const class_hierarchyt &hierarchy, ui_message_handlert &message_handler, bool children_only=false)
Output the class hierarchy.
Class hierarchy graph node: simply contains a class identifier.
irep_idt class_identifier
Class ID for this node.
Class hierarchy, represented using grapht and therefore suitable for use with generic graph algorithm...
std::unordered_map< irep_idt, node_indext > nodes_by_namet
Maps class identifiers onto node indices.
const nodes_by_namet & get_nodes_by_class_identifier() const
Get map from class identifier to node index.
void populate(const symbol_table_baset &)
Populate the class hierarchy graph, such that there is a node for every struct type in the symbol tab...
nodes_by_namet nodes_by_name
Maps class identifiers onto node indices.
idst get_children_trans(const irep_idt &c) const
Get all the classes that inherit (directly or indirectly) from class c.
std::vector< irep_idt > idst
idst get_direct_children(const irep_idt &c) const
Get all the classes that directly (i.e.
idst get_other_reachable_ids(const irep_idt &c, bool forwards) const
Helper function for get_children_trans and get_parents_trans
idst get_parents_trans(const irep_idt &c) const
Get all the classes that class c inherits from (directly or indirectly).
idst ids_from_indices(const std::vector< node_indext > &nodes) const
Helper function that converts a vector of node_indext to a vector of ids that are stored in the corre...
Non-graph-based representation of the class hierarchy.
idst get_parents_trans(const irep_idt &id) const
void output_dot(std::ostream &) const
Output class hierarchy in Graphviz DOT format.
void get_parents_trans_rec(const irep_idt &, idst &) const
Get all the classes that class c inherits from (directly or indirectly).
class_hierarchyt & operator=(const class_hierarchyt &)=delete
class_mapt class_map
class_hierarchyt(const symbol_table_baset &symbol_table)
std::map< irep_idt, entryt > class_mapt
void operator()(const symbol_table_baset &)
Looks for all the struct types in the symbol table and construct a map from class names to a data str...
class_hierarchyt()=default
void get_children_trans_rec(const irep_idt &, idst &) const
idst get_children_trans(const irep_idt &id) const
void output(std::ostream &, bool children_only) const
Output the class hierarchy in plain text.
class_hierarchyt(const class_hierarchyt &)=delete
std::vector< irep_idt > idst
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition: dstring.h:38
This class represents a node in a directed graph.
Definition: graph.h:35
A generic directed graph with a parametric node type.
Definition: graph.h:167
Provides methods for streaming JSON arrays.
Definition: json_stream.h:93
The symbol table base class interface.
A Template Class for Graphs.