@@ -56,7 +56,7 @@ auto pad(int padding)
56
56
};
57
57
}
58
58
59
- auto multi_return_type_name (declaration_node const & n)
59
+ auto multi_return_type_name (declaration_node const & n)
60
60
-> std::string
61
61
{
62
62
// When generating a multi-return struct, also enable multi-return
@@ -1326,7 +1326,7 @@ class cppfront
1326
1326
printer.print_extra (
1327
1327
" \n // Generated by cppfront "
1328
1328
#include " version.info"
1329
- " build "
1329
+ " build "
1330
1330
#include " build.info"
1331
1331
);
1332
1332
}
@@ -4083,7 +4083,7 @@ class cppfront
4083
4083
printer.print_extra ( " {" );
4084
4084
for (auto & param : n.parameters ->parameters ) {
4085
4085
printer.print_extra ( " \n " );
4086
- printer.print_extra ( print_to_string (*param) );
4086
+ printer.print_extra ( print_to_string (*param, false , false , true ) );
4087
4087
}
4088
4088
}
4089
4089
@@ -4170,7 +4170,8 @@ class cppfront
4170
4170
auto emit (
4171
4171
parameter_declaration_node const & n,
4172
4172
bool is_returns = false ,
4173
- bool is_template_parameter = false
4173
+ bool is_template_parameter = false ,
4174
+ bool is_statement = false
4174
4175
)
4175
4176
-> void
4176
4177
{ STACKINSTR
@@ -4492,8 +4493,16 @@ class cppfront
4492
4493
)
4493
4494
{
4494
4495
auto guard = stack_element (current_declarations, &*n.declaration );
4495
- printer.print_cpp2 ( " = " , n.declaration ->initializer ->position () );
4496
- emit (*n.declaration ->initializer );
4496
+ if (is_statement) {
4497
+ printer.print_cpp2 ( " {" , n.declaration ->initializer ->position () );
4498
+ }
4499
+ else {
4500
+ printer.print_cpp2 ( " = " , n.declaration ->initializer ->position () );
4501
+ }
4502
+ emit (*n.declaration ->initializer , !is_statement);
4503
+ if (is_statement) {
4504
+ printer.print_cpp2 ( " };" , n.declaration ->initializer ->position () );
4505
+ }
4497
4506
}
4498
4507
}
4499
4508
@@ -4679,7 +4688,7 @@ class cppfront
4679
4688
);
4680
4689
}
4681
4690
else {
4682
- emit (*n.parameters , false , false , generating_postfix_inc_dec);
4691
+ emit (*n.parameters , false , false , generating_postfix_inc_dec);
4683
4692
}
4684
4693
4685
4694
// For an anonymous function, the emitted lambda is 'constexpr' or 'mutable'
@@ -5511,6 +5520,22 @@ class cppfront
5511
5520
type = print_to_string (*a->type_id );
5512
5521
}
5513
5522
5523
+ auto print_initializer_to_string = [&](expression_node const & n) -> std::string {
5524
+ // If this expression is just a single expression-list, we can
5525
+ // take over direct control of emitting it without needing to
5526
+ // go through the whole grammar, and surround it with braces
5527
+ if (n.is_expression_list ()) {
5528
+ return " { "
5529
+ + print_to_string (*n.get_expression_list (), false )
5530
+ + " }" ;
5531
+ }
5532
+ // Otherwise, just emit the general expression as usual
5533
+ else {
5534
+ return " = "
5535
+ + print_to_string (n);
5536
+ }
5537
+ };
5538
+
5514
5539
// (*) If this is at type scope, Cpp1 requires an out-of-line declaration dance
5515
5540
// for some cases to work - see https://stackoverflow.com/questions/11928089/
5516
5541
if (n.parent_is_type ())
@@ -5542,8 +5567,7 @@ class cppfront
5542
5567
+ " "
5543
5568
+ type_qualification_if_any_for (n)
5544
5569
+ print_to_string (*n.identifier )
5545
- + " = "
5546
- + print_to_string ( *std::get<alias_node::an_object>(a->initializer ) )
5570
+ + print_initializer_to_string ( *std::get<alias_node::an_object>(a->initializer ) )
5547
5571
+ " ;\n " ,
5548
5572
n.position ()
5549
5573
);
@@ -5564,8 +5588,7 @@ class cppfront
5564
5588
type + " "
5565
5589
+ intro + " "
5566
5590
+ print_to_string (*n.identifier )
5567
- + " = "
5568
- + print_to_string ( *std::get<alias_node::an_object>(a->initializer ) )
5591
+ + print_initializer_to_string ( *std::get<alias_node::an_object>(a->initializer ) )
5569
5592
+ " ;\n " ,
5570
5593
n.position ()
5571
5594
);
0 commit comments