CBMC
destructor_tree.h
Go to the documentation of this file.
1 /*******************************************************************\
2 
3  Module: Destructor Tree
4 
5  Author: John Dumbell, john.dumbell@diffblue.com
6 
7 \*******************************************************************/
8 
9 #ifndef CPROVER_GOTO_PROGRAMS_DESTRUCTOR_TREE_H
10 #define CPROVER_GOTO_PROGRAMS_DESTRUCTOR_TREE_H
11 
12 #include <util/graph.h>
13 #include <util/std_code.h>
14 
15 typedef std::size_t node_indext;
16 
21 {
22 public:
24  : common_ancestor(node),
27  {
28  }
30  node_indext node,
31  std::size_t left_pre_size,
32  std::size_t right_pre_size)
33  : common_ancestor(node),
34  left_depth_below_common_ancestor(left_pre_size),
35  right_depth_below_common_ancestor(right_pre_size)
36  {
37  }
41 };
42 
46 {
47 public:
49  : destructor(code), node_id(id)
50  {
51  }
52 
55 };
56 
89 {
90 public:
92  {
93  // We add a default node to the graph to act as a root for path traversal.
94  this->destruction_graph.add_node();
95  }
96 
99  void add(const codet &destructor);
100 
103 
112  const std::vector<destructor_and_idt> get_destructors(
113  optionalt<node_indext> end_index = {},
114  optionalt<node_indext> starting_index = {});
115 
120  node_indext left_index,
121  node_indext right_index);
122 
127 
130  void set_current_node(node_indext val);
131 
134 
136  void descend_tree();
137 
138 private:
139  class destructor_nodet : public graph_nodet<empty_edget>
140  {
141  public:
142  destructor_nodet() = default;
143 
144  explicit destructor_nodet(codet destructor)
145  : destructor_value(std::move(destructor))
146  {
147  }
149  };
150 
153 };
154 
155 #endif // CPROVER_GOTO_PROGRAMS_DESTRUCTOR_TREE_H
destructor_treet::destructor_nodet::destructor_nodet
destructor_nodet()=default
destructor_treet::destructor_nodet::destructor_value
optionalt< codet > destructor_value
Definition: destructor_tree.h:148
ancestry_resultt::left_depth_below_common_ancestor
std::size_t left_depth_below_common_ancestor
Definition: destructor_tree.h:39
destructor_and_idt::node_id
node_indext node_id
Definition: destructor_tree.h:54
destructor_and_idt::destructor
const codet destructor
Definition: destructor_tree.h:53
destructor_treet::descend_tree
void descend_tree()
Walks the current node down to its child.
Definition: destructor_tree.cpp:88
destructor_treet::destructor_treet
destructor_treet()
Definition: destructor_tree.h:91
grapht
A generic directed graph with a parametric node type.
Definition: graph.h:166
destructor_treet::get_destructor
optionalt< codet > & get_destructor(node_indext index)
Fetches the destructor value for the passed-in node index.
Definition: destructor_tree.cpp:19
node_indext
std::size_t node_indext
Definition: destructor_tree.h:15
ancestry_resultt::ancestry_resultt
ancestry_resultt(node_indext node, std::size_t left_pre_size, std::size_t right_pre_size)
Definition: destructor_tree.h:29
destructor_treet::add
void add(const codet &destructor)
Adds a destructor to the current stack, attaching itself to the current node.
Definition: destructor_tree.cpp:11
ancestry_resultt::right_depth_below_common_ancestor
std::size_t right_depth_below_common_ancestor
Definition: destructor_tree.h:40
ancestry_resultt::common_ancestor
node_indext common_ancestor
Definition: destructor_tree.h:38
destructor_treet::current_node
node_indext current_node
Definition: destructor_tree.h:152
std_code.h
optionalt
nonstd::optional< T > optionalt
Definition: optional.h:35
destructor_treet::destruction_graph
grapht< destructor_nodet > destruction_graph
Definition: destructor_tree.h:151
destructor_treet::destructor_nodet
Definition: destructor_tree.h:139
destructor_treet::set_current_node
void set_current_node(optionalt< node_indext > val)
Sets the current node.
Definition: destructor_tree.cpp:77
destructor_treet::destructor_nodet::destructor_nodet
destructor_nodet(codet destructor)
Definition: destructor_tree.h:144
graph.h
graph_nodet
This class represents a node in a directed graph.
Definition: graph.h:34
destructor_and_idt::destructor_and_idt
destructor_and_idt(const codet &code, node_indext id)
Definition: destructor_tree.h:48
ancestry_resultt::ancestry_resultt
ancestry_resultt(node_indext node)
Definition: destructor_tree.h:23
destructor_treet::get_current_node
node_indext get_current_node() const
Gets the node that the next addition will be added to as a child.
Definition: destructor_tree.cpp:97
destructor_treet::get_nearest_common_ancestor_info
const ancestry_resultt get_nearest_common_ancestor_info(node_indext left_index, node_indext right_index)
Finds the nearest common ancestor of two nodes and then returns it.
Definition: destructor_tree.cpp:25
destructor_treet::get_destructors
const std::vector< destructor_and_idt > get_destructors(optionalt< node_indext > end_index={}, optionalt< node_indext > starting_index={})
Builds a vector of destructors that start from starting_index and ends at end_index.
Definition: destructor_tree.cpp:56
destructor_and_idt
Result of a tree query holding both destructor codet and the ID of the node that held it.
Definition: destructor_tree.h:45
ancestry_resultt
Result of an attempt to find ancestor information about two nodes.
Definition: destructor_tree.h:20
codet
Data structure for representing an arbitrary statement in a program.
Definition: std_code_base.h:28
destructor_treet
Tree to keep track of the destructors generated along each branch of a function.
Definition: destructor_tree.h:88