Skip to content

Commit 97b2b2b

Browse files
committed
SMV: avoid some expression copies
References are changed to rvalue references to avoid some copying when populating the parse tree.
1 parent 82c9305 commit 97b2b2b

File tree

2 files changed

+64
-58
lines changed

2 files changed

+64
-58
lines changed

src/smvlang/parser.y

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -486,17 +486,15 @@ assignments: assignment
486486

487487
assignment : assignment_head '(' assignment_var ')' BECOMES_Token formula ';'
488488
{
489-
binary($$, $3, ID_equal, $6);
490-
491489
if(stack_expr($1).id()==ID_smv_next)
492490
{
493-
exprt &op=to_binary_expr(stack_expr($$)).op0();
491+
exprt &op=stack_expr($3);
494492
unary_exprt tmp(ID_smv_next, std::move(op));
495493
tmp.swap(op);
496-
PARSER.module->add_assign_next(to_equal_expr(stack_expr($$)));
494+
PARSER.module->add_assign_next(std::move(stack_expr($3)), std::move(stack_expr($6)));
497495
}
498496
else
499-
PARSER.module->add_assign_init(to_equal_expr(stack_expr($$)));
497+
PARSER.module->add_assign_init(std::move(stack_expr($3)), std::move(stack_expr($6)));
500498
}
501499
| assignment_var BECOMES_Token formula ';'
502500
{
@@ -528,8 +526,7 @@ assignment : assignment_head '(' assignment_var ')' BECOMES_Token formula ';'
528526
DATA_INVARIANT(false, "unexpected variable class");
529527
}
530528

531-
binary($$, $1, ID_equal, $3);
532-
PARSER.module->add_assign_current(to_equal_expr(stack_expr($$)));
529+
PARSER.module->add_assign_current(std::move(stack_expr($1)), std::move(stack_expr($3)));
533530
}
534531
;
535532

@@ -575,8 +572,7 @@ define : assignment_var BECOMES_Token formula ';'
575572
DATA_INVARIANT(false, "unexpected variable class");
576573
}
577574

578-
binary($$, $1, ID_equal, $3);
579-
PARSER.module->add_define(to_equal_expr(stack_expr($$)));
575+
PARSER.module->add_define(std::move(stack_expr($1)), std::move(stack_expr($3)));
580576
}
581577
;
582578

src/smvlang/smv_parse_tree.h

Lines changed: 59 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -118,100 +118,110 @@ class smv_parse_treet
118118
typedef std::list<itemt> item_listt;
119119
item_listt items;
120120

121-
void add_item(
122-
itemt::item_typet item_type,
123-
const exprt &expr,
124-
const source_locationt &location)
121+
void
122+
add_item(itemt::item_typet item_type, exprt expr, source_locationt location)
125123
{
126-
items.push_back(itemt());
124+
items.push_back(itemt{});
127125
items.back().item_type=item_type;
128-
items.back().expr=expr;
129-
items.back().location=location;
126+
items.back().expr = std::move(expr);
127+
items.back().location = std::move(location);
130128
}
131129

132-
void add_assign_current(const equal_exprt &expr)
130+
void add_assign_current(exprt lhs, exprt rhs)
133131
{
134-
add_item(itemt::ASSIGN_CURRENT, expr, source_locationt::nil());
132+
add_item(
133+
itemt::ASSIGN_CURRENT,
134+
binary_exprt{std::move(lhs), ID_equal, std::move(rhs)},
135+
source_locationt::nil());
135136
}
136137

137-
void add_assign_init(const equal_exprt &expr)
138+
void add_assign_init(exprt lhs, exprt rhs)
138139
{
139-
add_item(itemt::ASSIGN_INIT, expr, source_locationt::nil());
140+
add_item(
141+
itemt::ASSIGN_INIT,
142+
binary_exprt{std::move(lhs), ID_equal, std::move(rhs)},
143+
source_locationt::nil());
140144
}
141145

142-
void add_assign_next(const equal_exprt &expr)
146+
void add_assign_next(exprt lhs, exprt rhs)
143147
{
144-
add_item(itemt::ASSIGN_NEXT, expr, source_locationt::nil());
148+
add_item(
149+
itemt::ASSIGN_NEXT,
150+
binary_exprt{std::move(lhs), ID_equal, std::move(rhs)},
151+
source_locationt::nil());
145152
}
146153

147-
void add_invar(const exprt &expr)
154+
void add_invar(exprt expr)
148155
{
149-
add_item(itemt::INVAR, expr, source_locationt::nil());
156+
add_item(itemt::INVAR, std::move(expr), source_locationt::nil());
150157
}
151158

152-
void add_ctlspec(const exprt &expr)
159+
void add_ctlspec(exprt expr)
153160
{
154-
add_item(itemt::CTLSPEC, expr, source_locationt::nil());
161+
add_item(itemt::CTLSPEC, std::move(expr), source_locationt::nil());
155162
}
156163

157-
void add_ltlspec(const exprt &expr)
164+
void add_ltlspec(exprt expr)
158165
{
159-
add_item(itemt::LTLSPEC, expr, source_locationt::nil());
166+
add_item(itemt::LTLSPEC, std::move(expr), source_locationt::nil());
160167
}
161168

162-
void add_define(const equal_exprt &expr)
169+
void add_define(exprt lhs, exprt rhs)
163170
{
164-
add_item(itemt::DEFINE, expr, source_locationt::nil());
171+
add_item(
172+
itemt::DEFINE,
173+
binary_exprt{std::move(lhs), ID_equal, std::move(rhs)},
174+
source_locationt::nil());
165175
}
166-
167-
void add_fairness(const exprt &expr)
176+
177+
void add_fairness(exprt expr)
168178
{
169-
add_item(itemt::FAIRNESS, expr, source_locationt::nil());
179+
add_item(itemt::FAIRNESS, std::move(expr), source_locationt::nil());
170180
}
171-
172-
void add_init(const exprt &expr)
181+
182+
void add_init(exprt expr)
173183
{
174-
add_item(itemt::INIT, expr, source_locationt::nil());
184+
add_item(itemt::INIT, std::move(expr), source_locationt::nil());
175185
}
176-
177-
void add_trans(const exprt &expr)
186+
187+
void add_trans(exprt expr)
178188
{
179-
add_item(itemt::TRANS, expr, source_locationt::nil());
189+
add_item(itemt::TRANS, std::move(expr), source_locationt::nil());
180190
}
181-
182-
void add_invar(const exprt &expr, const source_locationt &location)
191+
192+
void add_invar(exprt expr, source_locationt location)
183193
{
184-
add_item(itemt::INVAR, expr, location);
194+
add_item(itemt::INVAR, std::move(expr), location);
185195
}
186196

187-
void add_ctlspec(const exprt &expr, const source_locationt &location)
197+
void add_ctlspec(exprt expr, source_locationt location)
188198
{
189-
add_item(itemt::CTLSPEC, expr, location);
199+
add_item(itemt::CTLSPEC, std::move(expr), std::move(location));
190200
}
191201

192-
void add_ltlspec(const exprt &expr, const source_locationt &location)
202+
void add_ltlspec(exprt expr, source_locationt location)
193203
{
194-
add_item(itemt::LTLSPEC, expr, location);
204+
add_item(itemt::LTLSPEC, std::move(expr), location);
195205
}
196-
197-
void add_define(const exprt &expr, const source_locationt &location)
206+
207+
void add_define(exprt expr, source_locationt location)
198208
{
199-
add_item(itemt::DEFINE, expr, location);
209+
add_item(itemt::DEFINE, std::move(expr), std::move(location));
200210
}
201-
202-
void add_fairness(const exprt &expr, const source_locationt &location)
211+
212+
void add_fairness(exprt expr, source_locationt location)
203213
{
204-
add_item(itemt::FAIRNESS, expr, location);
214+
add_item(itemt::FAIRNESS, std::move(expr), std::move(location));
205215
}
206-
207-
void add_init(const exprt &expr, const source_locationt &location)
216+
217+
void add_init(exprt expr, source_locationt location)
208218
{
209-
add_item(itemt::INIT, expr, location);
219+
add_item(itemt::INIT, std::move(expr), std::move(location));
210220
}
211-
212-
void add_trans(const exprt &expr, const source_locationt &location)
221+
222+
void add_trans(exprt expr, source_locationt location)
213223
{
214-
add_item(itemt::TRANS, expr, location);
224+
add_item(itemt::TRANS, std::move(expr), std::move(location));
215225
}
216226

217227
mc_varst vars;

0 commit comments

Comments
 (0)