@@ -60,11 +60,28 @@ class TypeDecl;
6060class VisibleDeclConsumer ;
6161enum class SelectorSplitKind ;
6262
63+ // / This interface is implemented by LLDB to serve as a fallback when Clang
64+ // / modules can't be imported from source in the debugger.
65+ // /
66+ // / During compile time, ClangImporter-imported Clang modules are compiled with
67+ // / -gmodules, which emits a DWARF rendition of all types defined in the module
68+ // / into the .pcm file. On Darwin, these types can be collected by
69+ // / dsymutil. This delegate allows DWARFImporter to ask LLDB to look up a Clang
70+ // / type by name, synthesize a Clang AST from it. DWARFImporter then hands this
71+ // / Clang AST to ClangImporter to import the type into Swift.
72+ class DWARFImporterDelegate {
73+ public:
74+ virtual ~DWARFImporterDelegate () {}
75+ // / Perform a qualified lookup of a Clang type with this name.
76+ // / \param kind Only return results with this type kind.
77+ virtual void lookupValue (StringRef name, llvm::Optional<ClangTypeKind> kind,
78+ SmallVectorImpl<clang::Decl *> &results) {}
79+ };
80+
6381// / Class that imports Clang modules into Swift, mapping directly
6482// / from Clang ASTs over to Swift ASTs.
6583class ClangImporter final : public ClangModuleLoader {
6684 friend class ClangModuleUnit ;
67- friend class DWARFImporter ;
6885
6986public:
7087 class Implementation ;
@@ -73,8 +90,11 @@ class ClangImporter final : public ClangModuleLoader {
7390 Implementation &Impl;
7491
7592 ClangImporter (ASTContext &ctx, const ClangImporterOptions &clangImporterOpts,
76- DependencyTracker *tracker);
93+ DependencyTracker *tracker,
94+ std::unique_ptr<DWARFImporterDelegate> dwarfImporterDelegate);
7795
96+ ModuleDecl *loadModuleClang (SourceLoc importLoc,
97+ ArrayRef<std::pair<Identifier, SourceLoc>> path);
7898public:
7999 // / Create a new Clang importer that can import a suitable Clang
80100 // / module into the given ASTContext.
@@ -89,13 +109,15 @@ class ClangImporter final : public ClangModuleLoader {
89109 // /
90110 // / \param tracker The object tracking files this compilation depends on.
91111 // /
112+ // / \param dwarfImporterDelegate A helper object that can synthesize
113+ // / Clang Decls from debug info. Used by LLDB.
114+ // /
92115 // / \returns a new Clang module importer, or null (with a diagnostic) if
93116 // / an error occurred.
94117 static std::unique_ptr<ClangImporter>
95- create (ASTContext &ctx,
96- const ClangImporterOptions &importerOpts,
97- std::string swiftPCHHash = " " ,
98- DependencyTracker *tracker = nullptr );
118+ create (ASTContext &ctx, const ClangImporterOptions &importerOpts,
119+ std::string swiftPCHHash = " " , DependencyTracker *tracker = nullptr ,
120+ std::unique_ptr<DWARFImporterDelegate> dwarfImporterDelegate = {});
99121
100122 ClangImporter (const ClangImporter &) = delete ;
101123 ClangImporter (ClangImporter &&) = delete ;
@@ -150,15 +172,15 @@ class ClangImporter final : public ClangModuleLoader {
150172 // / Look for declarations associated with the given name.
151173 // /
152174 // / \param name The name we're searching for.
153- void lookupValue (DeclName name, VisibleDeclConsumer &consumer) override ;
175+ void lookupValue (DeclName name, VisibleDeclConsumer &consumer);
154176
155177 // / Look up a type declaration by its Clang name.
156178 // /
157179 // / Note that this method does no filtering. If it finds the type in a loaded
158180 // / module, it returns it. This is intended for use in reflection / debugging
159181 // / contexts where access is not a problem.
160182 void lookupTypeDecl (StringRef clangName, ClangTypeKind kind,
161- llvm::function_ref<void (TypeDecl *)> receiver) override ;
183+ llvm::function_ref<void (TypeDecl *)> receiver);
162184
163185 // / Look up type a declaration synthesized by the Clang importer itself, using
164186 // / a "related entity kind" to determine which type it should be. For example,
@@ -171,7 +193,7 @@ class ClangImporter final : public ClangModuleLoader {
171193 void
172194 lookupRelatedEntity (StringRef clangName, ClangTypeKind kind,
173195 StringRef relatedEntityKind,
174- llvm::function_ref<void (TypeDecl *)> receiver) override ;
196+ llvm::function_ref<void (TypeDecl *)> receiver);
175197
176198 // / Look for textually included declarations from the bridging header.
177199 // /
0 commit comments