@@ -1504,108 +1504,16 @@ static int doPrintAST(const CompilerInvocation &InitInvok,
1504
1504
return EXIT_SUCCESS;
1505
1505
}
1506
1506
1507
- // If we were given a mangled name, do a very simple form of LLDB's logic to
1508
- // look up a type based on that name.
1509
- Demangle::Context DCtx;
1510
- Demangle::NodePointer node = DCtx.demangleSymbolAsNode (MangledNameToFind);
1511
- using NodeKind = Demangle::Node::Kind;
1512
-
1513
- if (!node) {
1514
- llvm::errs () << " Unable to demangle name.\n " ;
1515
- return EXIT_FAILURE;
1516
- }
1517
- node = node->getFirstChild ();
1518
-
1519
- // FIXME: Look up things other than types.
1520
- if (node->getKind () != NodeKind::TypeMangling) {
1521
- llvm::errs () << " Name does not refer to a type.\n " ;
1522
- return EXIT_FAILURE;
1523
- }
1524
- node = node->getFirstChild ();
1525
- assert (node->getKind () == NodeKind::Type);
1526
- node = node->getFirstChild ();
1527
-
1528
- switch (node->getKind ()) {
1529
- case NodeKind::Class:
1530
- case NodeKind::Enum:
1531
- case NodeKind::Protocol:
1532
- case NodeKind::Structure:
1533
- case NodeKind::TypeAlias:
1534
- break ;
1535
- default :
1536
- llvm::errs () << " Name does not refer to a nominal type or typealias.\n " ;
1537
- return EXIT_FAILURE;
1538
- }
1539
-
1540
- ASTContext &ctx = CI.getASTContext ();
1541
-
1542
- SmallVector<std::pair<DeclName, Identifier>, 4 > identifiers;
1543
- do {
1544
- auto nameNode = node->getChild (1 );
1545
- switch (nameNode->getKind ()) {
1546
- case NodeKind::Identifier:
1547
- identifiers.push_back ({ ctx.getIdentifier (nameNode->getText ()),
1548
- Identifier () });
1549
- break ;
1550
- case NodeKind::PrivateDeclName:
1551
- identifiers.push_back ({
1552
- ctx.getIdentifier (nameNode->getChild (1 )->getText ()),
1553
- ctx.getIdentifier (nameNode->getChild (0 )->getText ())
1554
- });
1555
- break ;
1556
- default :
1557
- llvm::errs () << " Unsupported name kind.\n " ;
1558
- return EXIT_FAILURE;
1559
- }
1560
-
1561
- node = node->getChild (0 );
1562
-
1563
- switch (node->getKind ()) {
1564
- case NodeKind::Module:
1565
- // Will break out of loop below.
1566
- break ;
1567
- case NodeKind::Class:
1568
- case NodeKind::Enum:
1569
- case NodeKind::Protocol:
1570
- case NodeKind::Structure:
1571
- break ;
1572
- default :
1573
- llvm::errs () << " Name does not refer to a nominal type.\n " ;
1574
- return EXIT_FAILURE;
1575
- }
1576
- } while (node->getKind () != NodeKind::Module);
1577
-
1578
- ModuleDecl *M = getModuleByFullName (ctx, node->getText ());
1579
- SmallVector<ValueDecl *, 4 > results;
1580
- M->lookupMember (results, M, identifiers.back ().first ,
1581
- identifiers.back ().second );
1582
-
1583
- if (results.empty ()) {
1584
- llvm::errs () << " No matching declarations found for "
1585
- << MangledNameToFind << " .\n " ;
1507
+ // If we were given a mangled name, only print that declaration.
1508
+ std::string error;
1509
+ const Decl *D = ide::getDeclFromMangledSymbolName (CI.getASTContext (),
1510
+ MangledNameToFind, error);
1511
+ if (!D) {
1512
+ llvm::errs () << " Unable to find decl for symbol: " << error << " \n " ;
1586
1513
return EXIT_FAILURE;
1587
1514
}
1588
1515
1589
- // Progressively perform lookup into matching containers.
1590
- for (auto member : reversed (llvm::makeArrayRef (identifiers).drop_back ())) {
1591
- decltype (results) prevResults;
1592
- std::swap (results, prevResults);
1593
-
1594
- for (auto container : prevResults) {
1595
- M->lookupMember (results, cast<NominalTypeDecl>(container),
1596
- member.first , member.second );
1597
- }
1598
-
1599
- if (results.empty ()) {
1600
- llvm::errs () << " No matching declarations found for "
1601
- << MangledNameToFind << " .\n " ;
1602
- return EXIT_FAILURE;
1603
- }
1604
- }
1605
-
1606
- for (auto *VD : results)
1607
- VD->print (llvm::outs (), Options);
1608
-
1516
+ D->print (llvm::outs (), Options);
1609
1517
return EXIT_SUCCESS;
1610
1518
}
1611
1519
0 commit comments