Skip to content

Commit 4e55714

Browse files
committed
ASTDemangler: Introduce new getTypeDeclForUSR()
1 parent d0d5fbd commit 4e55714

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

include/swift/AST/ASTDemangler.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ Type getTypeForMangling(ASTContext &ctx,
4040
TypeDecl *getTypeDeclForMangling(ASTContext &ctx,
4141
llvm::StringRef mangling);
4242

43+
TypeDecl *getTypeDeclForUSR(ASTContext &ctx,
44+
llvm::StringRef usr);
45+
4346
/// An implementation of MetadataReader's BuilderType concept that
4447
/// just finds and builds things in the AST.
4548
class ASTBuilder {

lib/AST/ASTDemangler.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "swift/AST/Types.h"
3232
#include "swift/ClangImporter/ClangImporter.h"
3333
#include "swift/Demangling/Demangler.h"
34+
#include "swift/Demangling/ManglingMacros.h"
3435

3536
using namespace swift;
3637

@@ -56,6 +57,17 @@ TypeDecl *swift::Demangle::getTypeDeclForMangling(ASTContext &ctx,
5657
return builder.createTypeDecl(node);
5758
}
5859

60+
TypeDecl *swift::Demangle::getTypeDeclForUSR(ASTContext &ctx,
61+
StringRef usr) {
62+
if (!usr.startswith("s:"))
63+
return nullptr;
64+
65+
std::string mangling(usr);
66+
mangling.replace(0, 2, MANGLING_PREFIX_STR);
67+
68+
return getTypeDeclForMangling(ctx, mangling);
69+
}
70+
5971
TypeDecl *ASTBuilder::createTypeDecl(NodePointer node) {
6072
if (node->getKind() == Node::Kind::Global)
6173
return createTypeDecl(node->getChild(0));

0 commit comments

Comments
 (0)