@@ -4383,78 +4383,80 @@ class cppfront
4383
4383
auto object = objects.begin ();
4384
4384
auto statement = statements.begin ();
4385
4385
auto separator = std::string{" : " };
4386
- while (
4387
- object != objects.end ()
4388
- && statement != statements.end ()
4389
- )
4390
- {
4391
- assert (*statement);
4392
4386
4387
+ while (object != objects.end ())
4388
+ {
4393
4389
auto object_name = canonize_object_name (*object);
4394
4390
4395
4391
auto is_object_before_base =
4396
4392
n.get_decl_if_type_scope_object_name_before_a_base_type (*(*object)->name ());
4397
4393
4398
- // If this is an assignment statement, get the lhs and rhs
4399
- auto lhs = std::string{};
4400
- auto rhs = std::string{};
4401
- {
4402
- auto exprs = (*statement)->get_lhs_rhs_if_simple_assignment ();
4403
- if (exprs.lhs ) {
4404
- if (auto tok = exprs.lhs ->get_first_token_ignoring_this ()) {
4405
- lhs = *tok;
4406
- }
4407
- else {
4408
- lhs = print_to_string ( *exprs.lhs );
4409
- }
4410
- }
4411
- if (exprs.rhs ) {
4412
- rhs = print_to_string ( *exprs.rhs );
4413
- }
4414
- }
4415
-
4416
- // If this is an initialization of an 'out' parameter, stash it
4417
- if (n.has_out_parameter_named (lhs)){
4418
- out_inits.push_back ( print_to_string (**statement, false ) );
4419
- (*statement)->emitted = true ;
4420
- ++statement;
4421
- continue ;
4422
- }
4423
-
4424
- // Now we're ready to check whether this is an assignment to *object
4425
-
4426
4394
auto found_explicit_init = false ;
4427
4395
auto found_default_init = false ;
4396
+ auto stmt_pos = source_position{};
4428
4397
4429
- auto stmt_pos = (*statement)->position ();
4430
4398
auto initializer = std::string{};
4431
4399
4432
- if (!lhs.empty ())
4400
+ // If we're at an assignment statement, get the lhs and rhs
4401
+ if (statement != statements.end ())
4433
4402
{
4434
- // First, see if it's an assignment 'name = something'
4435
- found_explicit_init = object_name == lhs ;
4403
+ assert (*statement);
4404
+ stmt_pos = (*statement)-> position () ;
4436
4405
4437
- // Otherwise, see if it's 'this.name = something'
4438
- if (!found_explicit_init)
4406
+ auto lhs = std::string{};
4407
+ auto rhs = std::string{};
4439
4408
{
4440
- // If it's of the form 'this.name', check 'name'
4441
- if (
4442
- starts_with ( lhs, " (*this)." )
4443
- && object_name == lhs.substr (8 )
4444
- )
4445
- {
4446
- found_explicit_init = true ;
4409
+ auto exprs = (*statement)->get_lhs_rhs_if_simple_assignment ();
4410
+ if (exprs.lhs ) {
4411
+ if (auto tok = exprs.lhs ->get_first_token_ignoring_this ()) {
4412
+ lhs = *tok;
4413
+ }
4414
+ else {
4415
+ lhs = print_to_string ( *exprs.lhs );
4416
+ }
4417
+ }
4418
+ if (exprs.rhs ) {
4419
+ rhs = print_to_string ( *exprs.rhs );
4447
4420
}
4448
4421
}
4449
4422
4450
- if (found_explicit_init)
4451
- {
4452
- initializer = rhs;
4453
-
4454
- // We've used this statement, so note it
4455
- // and move 'statement' forward
4423
+ // If this is an initialization of an 'out' parameter, stash it
4424
+ if (n.has_out_parameter_named (lhs)){
4425
+ out_inits.push_back ( print_to_string (**statement, false ) );
4456
4426
(*statement)->emitted = true ;
4457
4427
++statement;
4428
+ continue ;
4429
+ }
4430
+
4431
+ // Now we're ready to check whether this is an assignment to *object
4432
+
4433
+ if (!lhs.empty ())
4434
+ {
4435
+ // First, see if it's an assignment 'name = something'
4436
+ found_explicit_init = object_name == lhs;
4437
+
4438
+ // Otherwise, see if it's 'this.name = something'
4439
+ if (!found_explicit_init)
4440
+ {
4441
+ // If it's of the form 'this.name', check 'name'
4442
+ if (
4443
+ starts_with ( lhs, " (*this)." )
4444
+ && object_name == lhs.substr (8 )
4445
+ )
4446
+ {
4447
+ found_explicit_init = true ;
4448
+ }
4449
+ }
4450
+
4451
+ if (found_explicit_init)
4452
+ {
4453
+ initializer = rhs;
4454
+
4455
+ // We've used this statement, so note it
4456
+ // and move 'statement' forward
4457
+ (*statement)->emitted = true ;
4458
+ ++statement;
4459
+ }
4458
4460
}
4459
4461
}
4460
4462
@@ -4600,45 +4602,45 @@ class cppfront
4600
4602
++object;
4601
4603
}
4602
4604
4603
- // Each remaining object is required to have a default initializer,
4604
- // since it had no explicit initialization statement
4605
- for (
4606
- ;
4607
- object != objects.end ();
4608
- ++object
4609
- )
4610
- {
4611
- auto object_name = canonize_object_name (*object);
4612
-
4613
- if ((*object)->initializer )
4614
- {
4615
- // Good. Entering here avoids emitting the error on the 'else'
4616
-
4617
- auto initializer = print_to_string ( *(*object)->initializer , false );
4618
- if (initializer.empty ()) {
4619
- initializer = " {}" ;
4620
- }
4621
-
4622
- // Need to actually emit the initializer in an assignment operator
4623
- if (is_assignment)
4624
- {
4625
- current_functions.back ().prolog .statements .push_back (
4626
- object_name +
4627
- " = " +
4628
- initializer +
4629
- " ;"
4630
- );
4631
- }
4632
- }
4633
- else
4634
- {
4635
- errors.emplace_back (
4636
- n.position (),
4637
- object_name + " was not initialized in the operator= body and has no default initializer - " + error_msg
4638
- );
4639
- return ;
4640
- }
4641
- }
4605
+ // // Each remaining object is required to have a default initializer,
4606
+ // // since it had no explicit initialization statement
4607
+ // for (
4608
+ // ;
4609
+ // object != objects.end();
4610
+ // ++object
4611
+ // )
4612
+ // {
4613
+ // auto object_name = canonize_object_name(*object);
4614
+
4615
+ // if ((*object)->initializer)
4616
+ // {
4617
+ // // Good. Entering here avoids emitting the error on the 'else'
4618
+
4619
+ // auto initializer = print_to_string( *(*object)->initializer, false );
4620
+ // if (initializer.empty()) {
4621
+ // initializer = "{}";
4622
+ // }
4623
+
4624
+ // // Need to actually emit the initializer in an assignment operator
4625
+ // if (is_assignment)
4626
+ // {
4627
+ // current_functions.back().prolog.statements.push_back(
4628
+ // object_name +
4629
+ // " = " +
4630
+ // initializer +
4631
+ // ";"
4632
+ // );
4633
+ // }
4634
+ // }
4635
+ // else
4636
+ // {
4637
+ // errors.emplace_back(
4638
+ // n.position(),
4639
+ // object_name + " was not initialized in the operator= body and has no default initializer - " + error_msg
4640
+ // );
4641
+ // return;
4642
+ // }
4643
+ // }
4642
4644
4643
4645
// Now no data members should be left over
4644
4646
if (object != objects.end ())
0 commit comments