@@ -3499,49 +3499,37 @@ bool DWARFASTParserClang::CopyUniqueClassMethodTypes(
3499
3499
// in "dst_cu" and "dst_class_die"
3500
3500
class_type->GetFullCompilerType ();
3501
3501
3502
- DWARFDIE src_die;
3503
- DWARFDIE dst_die;
3502
+ auto gather = [](DWARFDIE die, UniqueCStringMap<DWARFDIE> &map,
3503
+ UniqueCStringMap<DWARFDIE> map_artificial) {
3504
+ if (die.Tag () != DW_TAG_subprogram)
3505
+ return ;
3506
+ // Make sure this is a declaration and not a concrete instance by looking
3507
+ // for DW_AT_declaration set to 1. Sometimes concrete function instances are
3508
+ // placed inside the class definitions and shouldn't be included in the list
3509
+ // of things are are tracking here.
3510
+ if (die.GetAttributeValueAsUnsigned (DW_AT_declaration, 0 ) != 1 )
3511
+ return ;
3512
+
3513
+ if (const char *name = die.GetMangledName ()) {
3514
+ ConstString const_name (name);
3515
+ if (die.GetAttributeValueAsUnsigned (DW_AT_artificial, 0 ))
3516
+ map_artificial.Append (const_name, die);
3517
+ else
3518
+ map.Append (const_name, die);
3519
+ }
3520
+ };
3521
+
3504
3522
UniqueCStringMap<DWARFDIE> src_name_to_die;
3505
3523
UniqueCStringMap<DWARFDIE> dst_name_to_die;
3506
3524
UniqueCStringMap<DWARFDIE> src_name_to_die_artificial;
3507
3525
UniqueCStringMap<DWARFDIE> dst_name_to_die_artificial;
3508
- for (src_die = src_class_die.GetFirstChild (); src_die.IsValid ();
3526
+ for (DWARFDIE src_die = src_class_die.GetFirstChild (); src_die.IsValid ();
3509
3527
src_die = src_die.GetSibling ()) {
3510
- if (src_die.Tag () == DW_TAG_subprogram) {
3511
- // Make sure this is a declaration and not a concrete instance by looking
3512
- // for DW_AT_declaration set to 1. Sometimes concrete function instances
3513
- // are placed inside the class definitions and shouldn't be included in
3514
- // the list of things are are tracking here.
3515
- if (src_die.GetAttributeValueAsUnsigned (DW_AT_declaration, 0 ) == 1 ) {
3516
- const char *src_name = src_die.GetMangledName ();
3517
- if (src_name) {
3518
- ConstString src_const_name (src_name);
3519
- if (src_die.GetAttributeValueAsUnsigned (DW_AT_artificial, 0 ))
3520
- src_name_to_die_artificial.Append (src_const_name, src_die);
3521
- else
3522
- src_name_to_die.Append (src_const_name, src_die);
3523
- }
3524
- }
3525
- }
3528
+ gather (src_die, src_name_to_die, src_name_to_die_artificial);
3526
3529
}
3527
- for (dst_die = dst_class_die.GetFirstChild (); dst_die.IsValid ();
3530
+ for (DWARFDIE dst_die = dst_class_die.GetFirstChild (); dst_die.IsValid ();
3528
3531
dst_die = dst_die.GetSibling ()) {
3529
- if (dst_die.Tag () == DW_TAG_subprogram) {
3530
- // Make sure this is a declaration and not a concrete instance by looking
3531
- // for DW_AT_declaration set to 1. Sometimes concrete function instances
3532
- // are placed inside the class definitions and shouldn't be included in
3533
- // the list of things are are tracking here.
3534
- if (dst_die.GetAttributeValueAsUnsigned (DW_AT_declaration, 0 ) == 1 ) {
3535
- const char *dst_name = dst_die.GetMangledName ();
3536
- if (dst_name) {
3537
- ConstString dst_const_name (dst_name);
3538
- if (dst_die.GetAttributeValueAsUnsigned (DW_AT_artificial, 0 ))
3539
- dst_name_to_die_artificial.Append (dst_const_name, dst_die);
3540
- else
3541
- dst_name_to_die.Append (dst_const_name, dst_die);
3542
- }
3543
- }
3544
- }
3532
+ gather (dst_die, dst_name_to_die, dst_name_to_die_artificial);
3545
3533
}
3546
3534
const uint32_t src_size = src_name_to_die.GetSize ();
3547
3535
const uint32_t dst_size = dst_name_to_die.GetSize ();
@@ -3556,8 +3544,8 @@ bool DWARFASTParserClang::CopyUniqueClassMethodTypes(
3556
3544
3557
3545
if (fast_path) {
3558
3546
for (idx = 0 ; idx < src_size; ++idx) {
3559
- src_die = src_name_to_die.GetValueAtIndexUnchecked (idx);
3560
- dst_die = dst_name_to_die.GetValueAtIndexUnchecked (idx);
3547
+ DWARFDIE src_die = src_name_to_die.GetValueAtIndexUnchecked (idx);
3548
+ DWARFDIE dst_die = dst_name_to_die.GetValueAtIndexUnchecked (idx);
3561
3549
3562
3550
if (src_die.Tag () != dst_die.Tag ())
3563
3551
fast_path = false ;
@@ -3575,28 +3563,29 @@ bool DWARFASTParserClang::CopyUniqueClassMethodTypes(
3575
3563
3576
3564
DWARFASTParserClang *src_dwarf_ast_parser =
3577
3565
static_cast <DWARFASTParserClang *>(
3578
- SymbolFileDWARF::GetDWARFParser (*src_die .GetCU ()));
3566
+ SymbolFileDWARF::GetDWARFParser (*src_class_die .GetCU ()));
3579
3567
DWARFASTParserClang *dst_dwarf_ast_parser =
3580
3568
static_cast <DWARFASTParserClang *>(
3581
- SymbolFileDWARF::GetDWARFParser (*dst_die.GetCU ()));
3569
+ SymbolFileDWARF::GetDWARFParser (*dst_class_die.GetCU ()));
3570
+ auto link = [&](DWARFDIE src, DWARFDIE dst) {
3571
+ SymbolFileDWARF::DIEToTypePtr &die_to_type =
3572
+ dst_class_die.GetDWARF ()->GetDIEToType ();
3573
+ clang::DeclContext *src_decl_ctx =
3574
+ src_dwarf_ast_parser->m_die_to_decl_ctx [src.GetDIE ()];
3575
+ if (src_decl_ctx)
3576
+ dst_dwarf_ast_parser->LinkDeclContextToDIE (src_decl_ctx, dst);
3577
+
3578
+ if (Type *src_child_type = die_to_type[src.GetDIE ()])
3579
+ die_to_type[dst.GetDIE ()] = src_child_type;
3580
+ };
3582
3581
3583
3582
// Now do the work of linking the DeclContexts and Types.
3584
3583
if (fast_path) {
3585
3584
// We can do this quickly. Just run across the tables index-for-index
3586
3585
// since we know each node has matching names and tags.
3587
3586
for (idx = 0 ; idx < src_size; ++idx) {
3588
- src_die = src_name_to_die.GetValueAtIndexUnchecked (idx);
3589
- dst_die = dst_name_to_die.GetValueAtIndexUnchecked (idx);
3590
-
3591
- clang::DeclContext *src_decl_ctx =
3592
- src_dwarf_ast_parser->m_die_to_decl_ctx [src_die.GetDIE ()];
3593
- if (src_decl_ctx)
3594
- dst_dwarf_ast_parser->LinkDeclContextToDIE (src_decl_ctx, dst_die);
3595
-
3596
- Type *src_child_type =
3597
- dst_die.GetDWARF ()->GetDIEToType ()[src_die.GetDIE ()];
3598
- if (src_child_type)
3599
- dst_die.GetDWARF ()->GetDIEToType ()[dst_die.GetDIE ()] = src_child_type;
3587
+ link (src_name_to_die.GetValueAtIndexUnchecked (idx),
3588
+ dst_name_to_die.GetValueAtIndexUnchecked (idx));
3600
3589
}
3601
3590
} else {
3602
3591
// We must do this slowly. For each member of the destination, look up a
@@ -3608,24 +3597,13 @@ bool DWARFASTParserClang::CopyUniqueClassMethodTypes(
3608
3597
3609
3598
for (idx = 0 ; idx < dst_size; ++idx) {
3610
3599
ConstString dst_name = dst_name_to_die.GetCStringAtIndex (idx);
3611
- dst_die = dst_name_to_die.GetValueAtIndexUnchecked (idx);
3612
- src_die = src_name_to_die.Find (dst_name, DWARFDIE ());
3613
-
3614
- if (src_die && (src_die.Tag () == dst_die.Tag ())) {
3615
- clang::DeclContext *src_decl_ctx =
3616
- src_dwarf_ast_parser->m_die_to_decl_ctx [src_die.GetDIE ()];
3617
- if (src_decl_ctx)
3618
- dst_dwarf_ast_parser->LinkDeclContextToDIE (src_decl_ctx, dst_die);
3619
-
3620
- Type *src_child_type =
3621
- dst_die.GetDWARF ()->GetDIEToType ()[src_die.GetDIE ()];
3622
- if (src_child_type) {
3623
- dst_die.GetDWARF ()->GetDIEToType ()[dst_die.GetDIE ()] =
3624
- src_child_type;
3625
- }
3626
- } else {
3600
+ DWARFDIE dst_die = dst_name_to_die.GetValueAtIndexUnchecked (idx);
3601
+ DWARFDIE src_die = src_name_to_die.Find (dst_name, DWARFDIE ());
3602
+
3603
+ if (src_die && (src_die.Tag () == dst_die.Tag ()))
3604
+ link (src_die, dst_die);
3605
+ else
3627
3606
failures.push_back (dst_die);
3628
- }
3629
3607
}
3630
3608
}
3631
3609
}
@@ -3639,29 +3617,21 @@ bool DWARFASTParserClang::CopyUniqueClassMethodTypes(
3639
3617
for (idx = 0 ; idx < src_size_artificial; ++idx) {
3640
3618
ConstString src_name_artificial =
3641
3619
src_name_to_die_artificial.GetCStringAtIndex (idx);
3642
- src_die = src_name_to_die_artificial.GetValueAtIndexUnchecked (idx);
3643
- dst_die =
3620
+ DWARFDIE src_die =
3621
+ src_name_to_die_artificial.GetValueAtIndexUnchecked (idx);
3622
+ DWARFDIE dst_die =
3644
3623
dst_name_to_die_artificial.Find (src_name_artificial, DWARFDIE ());
3645
3624
3646
- if (dst_die) {
3647
- // Both classes have the artificial types, link them
3648
- clang::DeclContext *src_decl_ctx =
3649
- src_dwarf_ast_parser->m_die_to_decl_ctx [src_die.GetDIE ()];
3650
- if (src_decl_ctx)
3651
- dst_dwarf_ast_parser->LinkDeclContextToDIE (src_decl_ctx, dst_die);
3652
-
3653
- Type *src_child_type =
3654
- dst_die.GetDWARF ()->GetDIEToType ()[src_die.GetDIE ()];
3655
- if (src_child_type)
3656
- dst_die.GetDWARF ()->GetDIEToType ()[dst_die.GetDIE ()] = src_child_type;
3657
- }
3625
+ // Both classes have the artificial types, link them
3626
+ if (dst_die)
3627
+ link (src_die, dst_die);
3658
3628
}
3659
3629
}
3660
3630
3661
3631
if (dst_size_artificial) {
3662
3632
for (idx = 0 ; idx < dst_size_artificial; ++idx) {
3663
- dst_die = dst_name_to_die_artificial. GetValueAtIndexUnchecked (idx);
3664
- failures. push_back (dst_die );
3633
+ failures. push_back (
3634
+ dst_name_to_die_artificial. GetValueAtIndexUnchecked (idx) );
3665
3635
}
3666
3636
}
3667
3637
0 commit comments