Skip to content

Commit 90a5ac2

Browse files
Merge pull request #26674 from adrian-prantl/astdemangler
Make ASTDemamgler.cpp independent from ClangImporter.
2 parents ebaba2b + eb740be commit 90a5ac2

File tree

3 files changed

+32
-5
lines changed

3 files changed

+32
-5
lines changed

include/swift/AST/ClangModuleLoader.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,33 @@ class ClangModuleLoader : public ModuleLoader {
7171
virtual bool
7272
isInOverlayModuleForImportedModule(const DeclContext *overlayDC,
7373
const DeclContext *importedDC) = 0;
74+
75+
/// Look for declarations associated with the given name.
76+
///
77+
/// \param name The name we're searching for.
78+
virtual void lookupValue(DeclName name, VisibleDeclConsumer &consumer) = 0;
79+
80+
/// Look up a type declaration by its Clang name.
81+
///
82+
/// Note that this method does no filtering. If it finds the type in a loaded
83+
/// module, it returns it. This is intended for use in reflection / debugging
84+
/// contexts where access is not a problem.
85+
virtual void
86+
lookupTypeDecl(StringRef clangName, ClangTypeKind kind,
87+
llvm::function_ref<void(TypeDecl *)> receiver) = 0;
88+
89+
/// Look up type a declaration synthesized by the Clang importer itself, using
90+
/// a "related entity kind" to determine which type it should be. For example,
91+
/// this can be used to find the synthesized error struct for an
92+
/// NS_ERROR_ENUM.
93+
///
94+
/// Note that this method does no filtering. If it finds the type in a loaded
95+
/// module, it returns it. This is intended for use in reflection / debugging
96+
/// contexts where access is not a problem.
97+
virtual void
98+
lookupRelatedEntity(StringRef clangName, ClangTypeKind kind,
99+
StringRef relatedEntityKind,
100+
llvm::function_ref<void(TypeDecl *)> receiver) = 0;
74101
};
75102

76103
} // namespace swift

include/swift/ClangImporter/ClangImporter.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,15 +172,15 @@ class ClangImporter final : public ClangModuleLoader {
172172
/// Look for declarations associated with the given name.
173173
///
174174
/// \param name The name we're searching for.
175-
void lookupValue(DeclName name, VisibleDeclConsumer &consumer);
175+
void lookupValue(DeclName name, VisibleDeclConsumer &consumer) override;
176176

177177
/// Look up a type declaration by its Clang name.
178178
///
179179
/// Note that this method does no filtering. If it finds the type in a loaded
180180
/// module, it returns it. This is intended for use in reflection / debugging
181181
/// contexts where access is not a problem.
182182
void lookupTypeDecl(StringRef clangName, ClangTypeKind kind,
183-
llvm::function_ref<void(TypeDecl *)> receiver);
183+
llvm::function_ref<void(TypeDecl *)> receiver) override;
184184

185185
/// Look up type a declaration synthesized by the Clang importer itself, using
186186
/// a "related entity kind" to determine which type it should be. For example,
@@ -193,7 +193,7 @@ class ClangImporter final : public ClangModuleLoader {
193193
void
194194
lookupRelatedEntity(StringRef clangName, ClangTypeKind kind,
195195
StringRef relatedEntityKind,
196-
llvm::function_ref<void(TypeDecl *)> receiver);
196+
llvm::function_ref<void(TypeDecl *)> receiver) override;
197197

198198
/// Look for textually included declarations from the bridging header.
199199
///

lib/AST/ASTDemangler.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@
2222
#include "swift/AST/ASTDemangler.h"
2323

2424
#include "swift/AST/ASTContext.h"
25+
#include "swift/AST/ClangModuleLoader.h"
2526
#include "swift/AST/Decl.h"
2627
#include "swift/AST/GenericSignature.h"
2728
#include "swift/AST/GenericSignatureBuilder.h"
2829
#include "swift/AST/Module.h"
2930
#include "swift/AST/NameLookup.h"
3031
#include "swift/AST/Type.h"
3132
#include "swift/AST/Types.h"
32-
#include "swift/ClangImporter/ClangImporter.h"
3333
#include "swift/Demangling/Demangler.h"
3434
#include "swift/Demangling/ManglingMacros.h"
3535
#include "llvm/ADT/StringSwitch.h"
@@ -1069,7 +1069,7 @@ GenericTypeDecl *ASTBuilder::findForeignTypeDecl(StringRef name,
10691069
ForeignModuleKind foreignKind,
10701070
Demangle::Node::Kind kind) {
10711071
// Check to see if we have an importer loaded.
1072-
auto importer = static_cast<ClangImporter *>(Ctx.getClangModuleLoader());
1072+
auto importer = Ctx.getClangModuleLoader();
10731073
if (!importer)
10741074
return nullptr;
10751075

0 commit comments

Comments
 (0)