Skip to content

Commit 64749c1

Browse files
committed
refactor: emit like a returned expression list
1 parent 12fd401 commit 64749c1

7 files changed

+19
-20
lines changed

regression-tests/test-results/pure2-bugfix-for-assign-expression-list.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ auto main() -> int;
2020
auto main() -> int{
2121
using vec = std::vector<int>;
2222
vec v {0};
23-
v = {};
23+
v = { };
2424
cpp2::Default.expects(v==vec(), "");
25-
v = {1};
25+
v = { 1 };
2626
cpp2::Default.expects(v==vec(1), "");
27-
v = {2, 3};
27+
v = { 2, 3 };
2828
cpp2::Default.expects(std::move(v)==vec(2, 3), "");
2929
}
3030

regression-tests/test-results/pure2-types-smf-and-that-1-provide-everything.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ auto main() -> int{
143143
CPP2_UFCS(print, z, " cp-assign ", " <- ");
144144
CPP2_UFCS(print, y, "", "\n");
145145

146-
z = {std::move(y)};
146+
z = { std::move(y) };
147147
CPP2_UFCS(print, std::move(z), " mv-assign ", " <- ");
148148
CPP2_UFCS(print, std::move(y), "", "\n");
149149
}

regression-tests/test-results/pure2-types-smf-and-that-2-provide-mvconstruct-and-cpassign.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ auto main() -> int{
148148
CPP2_UFCS(print, z, " cp-assign ", " <- ");
149149
CPP2_UFCS(print, y, "", "\n");
150150

151-
z = {std::move(y)};
151+
z = { std::move(y) };
152152
CPP2_UFCS(print, std::move(z), " mv-assign ", " <- ");
153153
CPP2_UFCS(print, std::move(y), "", "\n");
154154
}

regression-tests/test-results/pure2-types-smf-and-that-3-provide-mvconstruct-and-mvassign.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ auto main() -> int{
147147
CPP2_UFCS(print, z, " cp-assign ", " <- ");
148148
CPP2_UFCS(print, y, "", "\n");
149149

150-
z = {std::move(y)};
150+
z = { std::move(y) };
151151
CPP2_UFCS(print, std::move(z), " mv-assign ", " <- ");
152152
CPP2_UFCS(print, std::move(y), "", "\n");
153153
}

regression-tests/test-results/pure2-types-smf-and-that-4-provide-cpassign-and-mvassign.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ auto main() -> int{
147147
CPP2_UFCS(print, z, " cp-assign ", " <- ");
148148
CPP2_UFCS(print, y, "", "\n");
149149

150-
z = {std::move(y)};
150+
z = { std::move(y) };
151151
CPP2_UFCS(print, std::move(z), " mv-assign ", " <- ");
152152
CPP2_UFCS(print, std::move(y), "", "\n");
153153
}

regression-tests/test-results/pure2-types-smf-and-that-5-provide-nothing-but-general-case.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ auto main() -> int{
153153
CPP2_UFCS(print, z, " cp-assign ", " <- ");
154154
CPP2_UFCS(print, y, "", "\n");
155155

156-
z = {std::move(y)};
156+
z = { std::move(y) };
157157
CPP2_UFCS(print, std::move(z), " mv-assign ", " <- ");
158158
CPP2_UFCS(print, std::move(y), "", "\n");
159159
}

source/cppfront.cpp

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,7 +1003,6 @@ class cppfront
10031003
bool violates_bounds_safety = false;
10041004
bool violates_initialization_safety = false;
10051005
bool suppress_move_from_last_use = false;
1006-
bool expression_list_is_braced_init = false;
10071006

10081007
declaration_node const* generating_assignment_from = {};
10091008
declaration_node const* generating_move_from = {};
@@ -3501,15 +3500,22 @@ class cppfront
35013500
printer.print_cpp2(" ", n.position());
35023501
emit(*x.op);
35033502
printer.print_cpp2(" ", n.position());
3503+
// When assigning a single expression-list, we can
3504+
// take over direct control of emitting it without needing to
3505+
// go through the whole grammar, and surround it with braces
35043506
if (
35053507
x.op->type() == lexeme::Assignment
35063508
&& x.expr->is_expression_list()
3507-
)
3509+
)
35083510
{
3509-
expression_list_is_braced_init = true;
3511+
printer.print_cpp2( "{ ", n.position() );
3512+
emit(*x.expr->get_expression_list(), false);
3513+
printer.print_cpp2( " }", n.position() );
3514+
}
3515+
// Otherwise, just emit the general expression as usual
3516+
else {
3517+
emit(*x.expr);
35103518
}
3511-
emit(*x.expr);
3512-
assert (expression_list_is_braced_init == false);
35133519
}
35143520
}
35153521
}
@@ -3540,13 +3546,9 @@ class cppfront
35403546
&& !n.inside_initializer
35413547
&& parens_ok
35423548
;
3543-
auto add_braces = std::exchange(expression_list_is_braced_init, false);
35443549
if (add_parens) {
35453550
printer.print_cpp2( *n.open_paren, n.position());
35463551
}
3547-
else if (add_braces) {
3548-
printer.print_cpp2( "{", n.position());
3549-
}
35503552

35513553
auto first = true;
35523554
for (auto const& x : n.expressions) {
@@ -3596,9 +3598,6 @@ class cppfront
35963598
if (add_parens) {
35973599
printer.print_cpp2( *n.close_paren, n.position());
35983600
}
3599-
else if (add_braces) {
3600-
printer.print_cpp2( "}", n.position());
3601-
}
36023601
// We want to consume only one of these
36033602
consumed_expression_list_parens();
36043603
}

0 commit comments

Comments
 (0)