Skip to content

Commit 84fbd02

Browse files
authored
Merge pull request #22825 from slavapestov/remove-old-type-reconstruction
Remove TypeReconstruction.cpp
2 parents 1a949ea + 6972c41 commit 84fbd02

24 files changed

+539
-2984
lines changed

include/swift/AST/ASTDemangler.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,19 @@
3030

3131
namespace swift {
3232

33+
class TypeDecl;
34+
3335
namespace Demangle {
3436

3537
Type getTypeForMangling(ASTContext &ctx,
3638
llvm::StringRef mangling);
3739

40+
TypeDecl *getTypeDeclForMangling(ASTContext &ctx,
41+
llvm::StringRef mangling);
42+
43+
TypeDecl *getTypeDeclForUSR(ASTContext &ctx,
44+
llvm::StringRef usr);
45+
3846
/// An implementation of MetadataReader's BuilderType concept that
3947
/// just finds and builds things in the AST.
4048
class ASTBuilder {
@@ -58,6 +66,8 @@ class ASTBuilder {
5866

5967
Type createBuiltinType(StringRef builtinName, StringRef mangledName);
6068

69+
TypeDecl *createTypeDecl(NodePointer node);
70+
6171
GenericTypeDecl *createTypeDecl(StringRef mangledName, bool &typeAlias);
6272

6373
GenericTypeDecl *createTypeDecl(NodePointer node,

include/swift/IDE/Utils.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,6 @@ void getLocationInfoForClangNode(ClangNode ClangNode,
130130

131131
Optional<std::pair<unsigned, unsigned>> parseLineCol(StringRef LineCol);
132132

133-
Decl *getDeclFromUSR(ASTContext &context, StringRef USR, std::string &error);
134-
Decl *getDeclFromMangledSymbolName(ASTContext &context, StringRef mangledName,
135-
std::string &error);
136-
137133
class XMLEscapingPrinter : public StreamPrinter {
138134
public:
139135
XMLEscapingPrinter(raw_ostream &OS) : StreamPrinter(OS){};

lib/AST/ASTDemangler.cpp

Lines changed: 48 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

@@ -45,6 +46,53 @@ Type swift::Demangle::getTypeForMangling(ASTContext &ctx,
4546
return swift::Demangle::decodeMangledType(builder, node);
4647
}
4748

49+
TypeDecl *swift::Demangle::getTypeDeclForMangling(ASTContext &ctx,
50+
StringRef mangling) {
51+
Demangle::Context Dem;
52+
auto node = Dem.demangleSymbolAsNode(mangling);
53+
if (!node)
54+
return nullptr;
55+
56+
ASTBuilder builder(ctx);
57+
return builder.createTypeDecl(node);
58+
}
59+
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+
71+
TypeDecl *ASTBuilder::createTypeDecl(NodePointer node) {
72+
if (node->getKind() == Node::Kind::Global)
73+
return createTypeDecl(node->getChild(0));
74+
75+
// Special case: associated types are not DeclContexts.
76+
if (node->getKind() == Node::Kind::AssociatedTypeRef) {
77+
if (node->getNumChildren() != 2)
78+
return nullptr;
79+
80+
auto *DC = findDeclContext(node->getChild(0));
81+
auto *proto = dyn_cast_or_null<ProtocolDecl>(DC);
82+
if (proto == nullptr)
83+
return nullptr;
84+
85+
auto name = Ctx.getIdentifier(node->getChild(1)->getText());
86+
auto results = proto->lookupDirect(name);
87+
if (results.size() != 1)
88+
return nullptr;
89+
90+
return dyn_cast<AssociatedTypeDecl>(results[0]);
91+
}
92+
93+
auto *DC = findDeclContext(node);
94+
return dyn_cast_or_null<GenericTypeDecl>(DC);
95+
}
4896

4997
Type
5098
ASTBuilder::createBuiltinType(StringRef builtinName,

lib/IDE/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ add_swift_host_library(swiftIDE STATIC
77
Formatting.cpp
88
Refactoring.cpp
99
ModuleInterfacePrinting.cpp
10-
TypeReconstruction.cpp
1110
REPLCodeCompletion.cpp
1211
SwiftSourceDocInfo.cpp
1312
SyntaxModel.cpp

0 commit comments

Comments
 (0)