@@ -1423,13 +1423,38 @@ class MetadataReader {
1423
1423
return name;
1424
1424
}
1425
1425
1426
+ // / Read and demangle the name of an anonymous context.
1427
+ Demangle::NodePointer demangleAnonymousContextName (
1428
+ ContextDescriptorRef contextRef,
1429
+ Demangler &dem) {
1430
+ auto anonymousBuffer = cast<TargetAnonymousContextDescriptor<Runtime>>(
1431
+ contextRef.getLocalBuffer ());
1432
+
1433
+ if (!anonymousBuffer->hasMangledName ())
1434
+ return nullptr ;
1435
+
1436
+ // Read the mangled name.
1437
+ auto mangledContextName = anonymousBuffer->getMangledContextName ();
1438
+ auto mangledNameAddress = resolveRelativeField (contextRef,
1439
+ mangledContextName->name );
1440
+
1441
+ std::string mangledName;
1442
+ if (!Reader->readString (RemoteAddress (mangledNameAddress), mangledName))
1443
+ return nullptr ;
1444
+
1445
+ return dem.demangleSymbol (mangledName);
1446
+ }
1447
+
1426
1448
// / If we have a context whose parent context is an anonymous context
1427
1449
// / that provides the local/private name for the current context,
1428
1450
// / produce a mangled node describing the name of \c context.
1429
1451
Demangle::NodePointer
1430
1452
adoptAnonymousContextName (ContextDescriptorRef contextRef,
1431
1453
Optional<ContextDescriptorRef> &parentContextRef,
1432
- Demangler &dem) {
1454
+ Demangler &dem,
1455
+ Demangle::NodePointer &outerNode) {
1456
+ outerNode = nullptr ;
1457
+
1433
1458
if (!parentContextRef || !*parentContextRef)
1434
1459
return nullptr ;
1435
1460
@@ -1444,21 +1469,7 @@ class MetadataReader {
1444
1469
if (!anonymousParent)
1445
1470
return nullptr ;
1446
1471
1447
- // Only perform this transformation when we have a mangled name describing
1448
- // the context.
1449
- if (!anonymousParent->hasMangledName ())
1450
- return nullptr ;
1451
-
1452
- // Read the mangled name.
1453
- auto mangledContextName = anonymousParent->getMangledContextName ();
1454
- auto mangledNameAddress = resolveRelativeField (*parentContextRef,
1455
- mangledContextName->name );
1456
-
1457
- std::string mangledName;
1458
- if (!Reader->readString (RemoteAddress (mangledNameAddress), mangledName))
1459
- return nullptr ;
1460
-
1461
- auto mangledNode = dem.demangleSymbol (mangledName);
1472
+ auto mangledNode = demangleAnonymousContextName (*parentContextRef, dem);
1462
1473
if (!mangledNode)
1463
1474
return nullptr ;
1464
1475
@@ -1469,9 +1480,9 @@ class MetadataReader {
1469
1480
return nullptr ;
1470
1481
1471
1482
// Dig out the name of the entity.
1472
- // FIXME: LocalDeclName
1473
1483
NodePointer nameChild = mangledNode->getChild (1 );
1474
- if (nameChild->getKind () != Node::Kind::PrivateDeclName ||
1484
+ if ((nameChild->getKind () != Node::Kind::PrivateDeclName &&
1485
+ nameChild->getKind () != Node::Kind::LocalDeclName) ||
1475
1486
nameChild->getNumChildren () < 2 )
1476
1487
return nullptr ;
1477
1488
@@ -1497,6 +1508,9 @@ class MetadataReader {
1497
1508
// context entirely.
1498
1509
parentContextRef = readParentContextDescriptor (*parentContextRef);
1499
1510
1511
+ // The outer node is the first child.
1512
+ outerNode = mangledNode->getChild (0 );
1513
+
1500
1514
// Return the name.
1501
1515
return nameChild;
1502
1516
}
@@ -1509,8 +1523,9 @@ class MetadataReader {
1509
1523
1510
1524
// If the parent is an anonymous context that provides a complete
1511
1525
// name for this node, note that.
1526
+ NodePointer demangledParentNode = nullptr ;
1512
1527
auto nameNode = adoptAnonymousContextName (
1513
- descriptor, parentDescriptorResult, dem);
1528
+ descriptor, parentDescriptorResult, dem, demangledParentNode );
1514
1529
1515
1530
// If there was a problem reading the parent descriptor, we're done.
1516
1531
if (!parentDescriptorResult) return nullptr ;
@@ -1520,10 +1535,18 @@ class MetadataReader {
1520
1535
if (auto parentDescriptor = *parentDescriptorResult) {
1521
1536
parentDemangling =
1522
1537
buildContextDescriptorMangling (parentDescriptor, dem);
1523
- if (!parentDemangling)
1538
+ if (!parentDemangling && !demangledParentNode )
1524
1539
return nullptr ;
1525
1540
}
1526
1541
1542
+ // If we have a better parent node produced from an enclosing nominal
1543
+ // context, use that.
1544
+ if (demangledParentNode &&
1545
+ (!parentDemangling ||
1546
+ parentDemangling->getKind () == Node::Kind::AnonymousContext)) {
1547
+ parentDemangling = demangledParentNode;
1548
+ }
1549
+
1527
1550
Demangle::Node::Kind nodeKind;
1528
1551
Optional<TypeImportInfo<std::string>> importInfo;
1529
1552
0 commit comments