Skip to content

Commit 24c0ccc

Browse files
tautschnigDaniel Kroening
authored and
Daniel Kroening
committed
Replaces uses of reserve; add_to_operands by a single add_to_operands
This reduces the lines of code and simplifies maintenance.
1 parent 4a96ec9 commit 24c0ccc

File tree

2 files changed

+8
-18
lines changed

2 files changed

+8
-18
lines changed

src/ansi-c/parser.y

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2323,27 +2323,21 @@ selection_statement:
23232323
{
23242324
$$=$1;
23252325
statement($$, ID_ifthenelse);
2326-
stack($$).operands().reserve(3);
2327-
mto($$, $3);
2328-
mto($$, $5);
2329-
stack($$).copy_to_operands(nil_exprt());
2326+
stack($$).add_to_operands(
2327+
std::move(stack($3)), std::move(stack($5)), nil_exprt());
23302328
}
23312329
| TOK_IF '(' comma_expression ')' statement TOK_ELSE statement
23322330
{
23332331
$$=$1;
23342332
statement($$, ID_ifthenelse);
2335-
stack($$).operands().reserve(3);
2336-
mto($$, $3);
2337-
mto($$, $5);
2338-
mto($$, $7);
2333+
stack($$).add_to_operands(
2334+
std::move(stack($3)), std::move(stack($5)), std::move(stack($7)));
23392335
}
23402336
| TOK_SWITCH '(' comma_expression ')' statement
23412337
{
23422338
$$=$1;
23432339
statement($$, ID_switch);
2344-
stack($$).operands().reserve(2);
2345-
mto($$, $3);
2346-
mto($$, $5);
2340+
stack($$).add_to_operands(std::move(stack($3)), std::move(stack($5)));
23472341
}
23482342
;
23492343

@@ -2358,9 +2352,7 @@ iteration_statement:
23582352
{
23592353
$$=$1;
23602354
statement($$, ID_while);
2361-
stack($$).operands().reserve(2);
2362-
mto($$, $3);
2363-
mto($$, $6);
2355+
stack($$).add_to_operands(std::move(stack($3)), std::move(stack($6)));
23642356

23652357
if(stack($5).is_not_nil())
23662358
stack($$).add(ID_C_spec_loop_invariant).swap(stack($5));
@@ -2370,9 +2362,7 @@ iteration_statement:
23702362
{
23712363
$$=$1;
23722364
statement($$, ID_dowhile);
2373-
stack($$).operands().reserve(2);
2374-
mto($$, $5);
2375-
mto($$, $2);
2365+
stack($$).add_to_operands(std::move(stack($5)), std::move(stack($2)));
23762366

23772367
if(stack($7).is_not_nil())
23782368
stack($$).add(ID_C_spec_loop_invariant).swap(stack($7));

src/ansi-c/parser_static.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#define mts(x, y) (to_type_with_subtypes(stack_type(x)).move_to_subtypes(stack_type(y)))
1414
#define binary(x, y, l, id, z) { init(x, id); \
1515
stack(x).add_source_location()=stack(l).source_location(); \
16-
stack(x).reserve_operands(2); mto(x, y); mto(x, z); }
16+
stack(x).add_to_operands(std::move(stack(y)), std::move(stack(z))); }
1717

1818
/*******************************************************************\
1919

0 commit comments

Comments
 (0)