Skip to content

Commit 0713688

Browse files
committed
Extend declaration in scope tree into a stateful struct
So that we can track what changes have been made to each declaration.
1 parent 05ed8d9 commit 0713688

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

Diff for: src/goto-programs/scope_tree.cpp

+8-6
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ void scope_treet::add(
1313
std::optional<goto_programt::targett> declaration)
1414
{
1515
auto previous_node = get_current_node();
16-
auto new_node = scope_graph.add_node(destructor, declaration);
16+
using declaration_optt = std::optional<declaration_statet>;
17+
auto declaration_opt =
18+
declaration ? declaration_optt{{*declaration}} : declaration_optt{};
19+
auto new_node = scope_graph.add_node(destructor, std::move(declaration_opt));
1720
scope_graph.add_edge(previous_node, new_node);
1821
current_node = new_node;
1922
}
@@ -24,11 +27,11 @@ optionalt<codet> &scope_treet::get_destructor(node_indext index)
2427
return scope_graph[index].destructor_value;
2528
}
2629

27-
optionalt<goto_programt::targett> &
30+
optionalt<scope_treet::declaration_statet> &
2831
scope_treet::get_declaration(node_indext index)
2932
{
3033
PRECONDITION(index < scope_graph.size());
31-
return scope_graph[index].declaration_value;
34+
return scope_graph[index].declaration;
3235
}
3336

3437
const ancestry_resultt scope_treet::get_nearest_common_ancestor_info(
@@ -110,8 +113,7 @@ node_indext scope_treet::get_current_node() const
110113

111114
scope_treet::scope_nodet::scope_nodet(
112115
codet destructor,
113-
std::optional<goto_programt::targett> declaration)
114-
: destructor_value(std::move(destructor)),
115-
declaration_value(std::move(declaration))
116+
std::optional<declaration_statet> declaration)
117+
: destructor_value(std::move(destructor)), declaration(std::move(declaration))
116118
{
117119
}

Diff for: src/goto-programs/scope_tree.h

+11-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
#include <goto-programs/goto_program.h>
1616

17+
#include <unordered_set>
18+
1719
typedef std::size_t node_indext;
1820

1921
/// Result of an attempt to find ancestor information about two nodes. Holds
@@ -90,6 +92,12 @@ class destructor_and_idt
9092
class scope_treet
9193
{
9294
public:
95+
struct declaration_statet
96+
{
97+
goto_programt::targett instruction;
98+
std::unordered_set<irep_idt, irep_id_hash> if_conditions_added;
99+
};
100+
93101
scope_treet()
94102
{
95103
// We add a default node to the graph to act as a root for path traversal.
@@ -108,7 +116,7 @@ class scope_treet
108116
optionalt<codet> &get_destructor(node_indext index);
109117

110118
/// Fetches the declaration value for the passed-in node index.
111-
optionalt<goto_programt::targett> &get_declaration(node_indext index);
119+
optionalt<declaration_statet> &get_declaration(node_indext index);
112120

113121
/// Builds a vector of destructors that start from starting_index and ends
114122
/// at end_index.
@@ -152,10 +160,10 @@ class scope_treet
152160

153161
explicit scope_nodet(
154162
codet destructor,
155-
std::optional<goto_programt::targett> declaration);
163+
std::optional<declaration_statet> declaration);
156164

157165
optionalt<codet> destructor_value;
158-
optionalt<goto_programt::targett> declaration_value;
166+
optionalt<declaration_statet> declaration;
159167
};
160168

161169
grapht<scope_nodet> scope_graph;

0 commit comments

Comments
 (0)