Skip to content

Commit 3f57114

Browse files
committed
Rename "destructor tree" classes to "scope tree"
This data structure is going to be used for declarations as well as destructors. So it needs to be renamed to match the expanded use case.
1 parent b8276a5 commit 3f57114

6 files changed

+59
-60
lines changed

src/goto-programs/destructor_tree.cpp

+17-17
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
/*******************************************************************\
22
3-
Module: Destructor Tree
3+
Module: Scope Tree
44
55
Author: John Dumbell, [email protected]
66
77
\*******************************************************************/
88

99
#include "destructor_tree.h"
1010

11-
void destructor_treet::add(
11+
void scope_treet::add(
1212
const codet &destructor,
1313
std::optional<goto_programt::targett> declaration)
1414
{
1515
auto previous_node = get_current_node();
16-
auto new_node = destruction_graph.add_node(destructor);
17-
destruction_graph.add_edge(previous_node, new_node);
16+
auto new_node = scope_graph.add_node(destructor);
17+
scope_graph.add_edge(previous_node, new_node);
1818
current_node = new_node;
1919
}
2020

21-
optionalt<codet> &destructor_treet::get_destructor(node_indext index)
21+
optionalt<codet> &scope_treet::get_destructor(node_indext index)
2222
{
23-
PRECONDITION(index < destruction_graph.size());
24-
return destruction_graph[index].destructor_value;
23+
PRECONDITION(index < scope_graph.size());
24+
return scope_graph[index].destructor_value;
2525
}
2626

27-
const ancestry_resultt destructor_treet::get_nearest_common_ancestor_info(
27+
const ancestry_resultt scope_treet::get_nearest_common_ancestor_info(
2828
node_indext left_index,
2929
node_indext right_index)
3030
{
@@ -33,7 +33,7 @@ const ancestry_resultt destructor_treet::get_nearest_common_ancestor_info(
3333
{
3434
if(right_index > left_index)
3535
{
36-
auto edge_map = destruction_graph[right_index].in;
36+
auto edge_map = scope_graph[right_index].in;
3737
INVARIANT(
3838
!edge_map.empty(),
3939
"Node at index " + std::to_string(right_index) +
@@ -42,7 +42,7 @@ const ancestry_resultt destructor_treet::get_nearest_common_ancestor_info(
4242
}
4343
else
4444
{
45-
auto edge_map = destruction_graph[left_index].in;
45+
auto edge_map = scope_graph[left_index].in;
4646
INVARIANT(
4747
!edge_map.empty(),
4848
"Node at index " + std::to_string(left_index) +
@@ -55,7 +55,7 @@ const ancestry_resultt destructor_treet::get_nearest_common_ancestor_info(
5555
return {right_index, left_unique_count, right_unique_count};
5656
}
5757

58-
const std::vector<destructor_and_idt> destructor_treet::get_destructors(
58+
const std::vector<destructor_and_idt> scope_treet::get_destructors(
5959
optionalt<node_indext> end_index,
6060
optionalt<node_indext> starting_index)
6161
{
@@ -65,7 +65,7 @@ const std::vector<destructor_and_idt> destructor_treet::get_destructors(
6565
std::vector<destructor_and_idt> codes;
6666
while(next_id > end_id)
6767
{
68-
auto node = destruction_graph[next_id];
68+
auto node = scope_graph[next_id];
6969
auto &destructor = node.destructor_value;
7070
if(destructor)
7171
codes.emplace_back(destructor_and_idt(*destructor, next_id));
@@ -76,27 +76,27 @@ const std::vector<destructor_and_idt> destructor_treet::get_destructors(
7676
return codes;
7777
}
7878

79-
void destructor_treet::set_current_node(optionalt<node_indext> val)
79+
void scope_treet::set_current_node(optionalt<node_indext> val)
8080
{
8181
if(val)
8282
set_current_node(*val);
8383
}
8484

85-
void destructor_treet::set_current_node(node_indext val)
85+
void scope_treet::set_current_node(node_indext val)
8686
{
8787
current_node = val;
8888
}
8989

90-
void destructor_treet::descend_tree()
90+
void scope_treet::descend_tree()
9191
{
9292
node_indext current_node = get_current_node();
9393
if(current_node != 0)
9494
{
95-
set_current_node(destruction_graph[current_node].in.begin()->first);
95+
set_current_node(scope_graph[current_node].in.begin()->first);
9696
}
9797
}
9898

99-
node_indext destructor_treet::get_current_node() const
99+
node_indext scope_treet::get_current_node() const
100100
{
101101
return current_node;
102102
}

src/goto-programs/destructor_tree.h

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*******************************************************************\
22
3-
Module: Destructor Tree
3+
Module: Scope Tree
44
55
Author: John Dumbell, [email protected]
66
@@ -87,13 +87,13 @@ class destructor_and_idt
8787
/// required to get there from 'c' was 2 and 'e' was 1, which also tells
8888
/// you if a certain branch is a prefix or not. In this case neither are a
8989
/// prefix of the other.
90-
class destructor_treet
90+
class scope_treet
9191
{
9292
public:
93-
destructor_treet()
93+
scope_treet()
9494
{
9595
// We add a default node to the graph to act as a root for path traversal.
96-
this->destruction_graph.add_node();
96+
this->scope_graph.add_node();
9797
}
9898

9999
/// Adds a destructor/declaration pair to the current stack, attaching it to
@@ -142,19 +142,19 @@ class destructor_treet
142142
void descend_tree();
143143

144144
private:
145-
class destructor_nodet : public graph_nodet<empty_edget>
145+
class scope_nodet : public graph_nodet<empty_edget>
146146
{
147147
public:
148-
destructor_nodet() = default;
148+
scope_nodet() = default;
149149

150-
explicit destructor_nodet(codet destructor)
150+
explicit scope_nodet(codet destructor)
151151
: destructor_value(std::move(destructor))
152152
{
153153
}
154154
optionalt<codet> destructor_value;
155155
};
156156

157-
grapht<destructor_nodet> destruction_graph;
157+
grapht<scope_nodet> scope_graph;
158158
node_indext current_node = 0;
159159
};
160160

src/goto-programs/goto_clean_expr.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ symbol_exprt goto_convertt::make_compound_literal(
5353
if(!new_symbol.is_static_lifetime)
5454
{
5555
code_deadt code_dead(result);
56-
targets.destructor_stack.add(std::move(code_dead), {});
56+
targets.scope_stack.add(std::move(code_dead), {});
5757
}
5858

5959
return result;

src/goto-programs/goto_convert.cpp

+8-9
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ void goto_convertt::finish_gotos(goto_programt &dest, const irep_idt &mode)
148148
// Compare the currently-live variables on the path of the GOTO and label.
149149
// We want to work out what variables should die during the jump.
150150
ancestry_resultt intersection_result =
151-
targets.destructor_stack.get_nearest_common_ancestor_info(
151+
targets.scope_stack.get_nearest_common_ancestor_info(
152152
goto_target, label_target);
153153

154154
// If our goto had no variables of note, just skip
@@ -339,7 +339,7 @@ void goto_convertt::convert_label(
339339
dest.destructive_append(tmp);
340340

341341
targets.labels.insert(
342-
{label, {target, targets.destructor_stack.get_current_node()}});
342+
{label, {target, targets.scope_stack.get_current_node()}});
343343
target->labels.push_front(label);
344344
}
345345
}
@@ -545,8 +545,7 @@ void goto_convertt::convert_block(
545545
const source_locationt &end_location=code.end_location();
546546

547547
// this saves the index of the destructor stack
548-
node_indext old_stack_top =
549-
targets.destructor_stack.get_current_node();
548+
node_indext old_stack_top = targets.scope_stack.get_current_node();
550549

551550
// now convert block
552551
for(const auto &b_code : code.statements())
@@ -564,7 +563,7 @@ void goto_convertt::convert_block(
564563
unwind_destructor_stack(end_location, dest, mode, old_stack_top);
565564

566565
// Set the current node of our destructor stack back to before the block.
567-
targets.destructor_stack.set_current_node(old_stack_top);
566+
targets.scope_stack.set_current_node(old_stack_top);
568567
}
569568

570569
void goto_convertt::convert_expression(
@@ -653,7 +652,7 @@ void goto_convertt::convert_frontend_decl(
653652

654653
{
655654
code_deadt code_dead(symbol_expr);
656-
targets.destructor_stack.add(code_dead, {});
655+
targets.scope_stack.add(code_dead, {});
657656
}
658657

659658
// do destructor
@@ -665,7 +664,7 @@ void goto_convertt::convert_frontend_decl(
665664
address_of_exprt this_expr(symbol_expr, pointer_type(symbol.type));
666665
destructor.arguments().push_back(this_expr);
667666

668-
targets.destructor_stack.add(destructor, {});
667+
targets.scope_stack.add(destructor, {});
669668
}
670669
}
671670

@@ -1367,7 +1366,7 @@ void goto_convertt::convert_goto(const code_gotot &code, goto_programt &dest)
13671366
dest.add(goto_programt::make_incomplete_goto(code, code.source_location()));
13681367

13691368
// remember it to do the target later
1370-
targets.gotos.emplace_back(t, targets.destructor_stack.get_current_node());
1369+
targets.gotos.emplace_back(t, targets.scope_stack.get_current_node());
13711370
}
13721371

13731372
void goto_convertt::convert_gcc_computed_goto(
@@ -1391,7 +1390,7 @@ void goto_convertt::convert_start_thread(
13911390

13921391
// remember it to do target later
13931392
targets.gotos.emplace_back(
1394-
start_thread, targets.destructor_stack.get_current_node());
1393+
start_thread, targets.scope_stack.get_current_node());
13951394
}
13961395

13971396
void goto_convertt::convert_end_thread(

src/goto-programs/goto_convert_class.h

+8-8
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ class goto_convertt:public messaget
395395
labelst labels;
396396
gotost gotos;
397397
computed_gotost computed_gotos;
398-
destructor_treet destructor_stack;
398+
scope_treet scope_stack;
399399

400400
casest cases;
401401
cases_mapt cases_map;
@@ -425,14 +425,14 @@ class goto_convertt:public messaget
425425
{
426426
break_set=true;
427427
break_target=_break_target;
428-
break_stack_node=destructor_stack.get_current_node();
428+
break_stack_node = scope_stack.get_current_node();
429429
}
430430

431431
void set_continue(goto_programt::targett _continue_target)
432432
{
433433
continue_set=true;
434434
continue_target=_continue_target;
435-
continue_stack_node=destructor_stack.get_current_node();
435+
continue_stack_node = scope_stack.get_current_node();
436436
}
437437

438438
void set_default(goto_programt::targett _default_target)
@@ -451,14 +451,14 @@ class goto_convertt:public messaget
451451
{
452452
throw_set=true;
453453
throw_target=_throw_target;
454-
throw_stack_node=destructor_stack.get_current_node();
454+
throw_stack_node = scope_stack.get_current_node();
455455
}
456456

457457
void set_leave(goto_programt::targett _leave_target)
458458
{
459459
leave_set=true;
460460
leave_target=_leave_target;
461-
leave_stack_node=destructor_stack.get_current_node();
461+
leave_stack_node = scope_stack.get_current_node();
462462
}
463463
} targets;
464464

@@ -497,7 +497,7 @@ class goto_convertt:public messaget
497497
default_set=targets.default_set;
498498
break_target=targets.break_target;
499499
default_target=targets.default_target;
500-
break_stack_node=targets.destructor_stack.get_current_node();
500+
break_stack_node = targets.scope_stack.get_current_node();
501501
cases=targets.cases;
502502
cases_map=targets.cases_map;
503503
}
@@ -529,7 +529,7 @@ class goto_convertt:public messaget
529529
{
530530
throw_set=targets.throw_set;
531531
throw_target=targets.throw_target;
532-
throw_stack_node=targets.destructor_stack.get_current_node();
532+
throw_stack_node = targets.scope_stack.get_current_node();
533533
}
534534

535535
void restore(targetst &targets)
@@ -551,7 +551,7 @@ class goto_convertt:public messaget
551551
{
552552
leave_set=targets.leave_set;
553553
leave_target=targets.leave_target;
554-
leave_stack_node=targets.destructor_stack.get_current_node();
554+
leave_stack_node = targets.scope_stack.get_current_node();
555555
}
556556

557557
void restore(targetst &targets)

0 commit comments

Comments
 (0)