Skip to content

Commit 6467d0e

Browse files
authored
Merge pull request #39429 from zoecarver/lazy-pt1-clang-module-loader
[nfc][cxx-interop] Add three utilities to the `ClangModuleLoader`.
2 parents 308c87f + d13f43c commit 6467d0e

File tree

3 files changed

+54
-3
lines changed

3 files changed

+54
-3
lines changed

include/swift/AST/ClangModuleLoader.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ namespace swift {
3333

3434
class Decl;
3535
class DeclContext;
36+
class EffectiveClangContext;
37+
class SwiftLookupTable;
3638
class VisibleDeclConsumer;
3739

3840
/// Represents the different namespaces for types in C.
@@ -177,6 +179,9 @@ class ClangModuleLoader : public ModuleLoader {
177179
StringRef relatedEntityKind,
178180
llvm::function_ref<void(TypeDecl *)> receiver) = 0;
179181

182+
/// Imports a clang decl directly, rather than looking up its name.
183+
virtual Decl *importDeclDirectly(const clang::NamedDecl *decl) = 0;
184+
180185
/// Instantiate and import class template using given arguments.
181186
///
182187
/// This method will find the clang::ClassTemplateSpecialization decl if
@@ -241,6 +246,21 @@ class ClangModuleLoader : public ModuleLoader {
241246

242247
virtual Type importFunctionReturnType(const clang::FunctionDecl *clangDecl,
243248
DeclContext *dc) = 0;
249+
250+
/// Find the lookup table that corresponds to the given Clang module.
251+
///
252+
/// \param clangModule The module, or null to indicate that we're talking
253+
/// about the directly-parsed headers.
254+
virtual SwiftLookupTable *
255+
findLookupTable(const clang::Module *clangModule) = 0;
256+
257+
virtual DeclName
258+
importName(const clang::NamedDecl *D,
259+
clang::DeclarationName givenName = clang::DeclarationName()) = 0;
260+
261+
/// Determine the effective Clang context for the given Swift nominal type.
262+
EffectiveClangContext virtual getEffectiveClangContext(
263+
const NominalTypeDecl *nominal) = 0;
244264
};
245265

246266
/// Describes a C++ template instantiation error.

include/swift/ClangImporter/ClangImporter.h

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,14 @@ class ClangModuleUnit;
6262
class ClangNode;
6363
class Decl;
6464
class DeclContext;
65+
class EffectiveClangContext;
6566
class EnumDecl;
6667
class ImportDecl;
6768
class IRGenOptions;
6869
class ModuleDecl;
6970
class NominalTypeDecl;
7071
class StructDecl;
72+
class SwiftLookupTable;
7173
class TypeDecl;
7274
class VisibleDeclConsumer;
7375
enum class SelectorSplitKind;
@@ -457,11 +459,12 @@ class ClangImporter final : public ClangModuleLoader {
457459
/// Given a Clang module, decide whether this module is imported already.
458460
static bool isModuleImported(const clang::Module *M);
459461

460-
DeclName importName(const clang::NamedDecl *D,
461-
clang::DeclarationName givenName);
462+
DeclName importName(
463+
const clang::NamedDecl *D,
464+
clang::DeclarationName givenName = clang::DeclarationName()) override;
462465

463466
Type importFunctionReturnType(const clang::FunctionDecl *clangDecl,
464-
DeclContext *dc) override;
467+
DeclContext *dc) override;
465468

466469
Optional<std::string>
467470
getOrCreatePCH(const ClangImporterOptions &ImporterOptions,
@@ -493,6 +496,19 @@ class ClangImporter final : public ClangModuleLoader {
493496
SubstitutionMap subst) override;
494497

495498
bool isCXXMethodMutating(const clang::CXXMethodDecl *method) override;
499+
500+
/// Find the lookup table that corresponds to the given Clang module.
501+
///
502+
/// \param clangModule The module, or null to indicate that we're talking
503+
/// about the directly-parsed headers.
504+
SwiftLookupTable *findLookupTable(const clang::Module *clangModule) override;
505+
506+
/// Determine the effective Clang context for the given Swift nominal type.
507+
EffectiveClangContext
508+
getEffectiveClangContext(const NominalTypeDecl *nominal) override;
509+
510+
/// Imports a clang decl directly, rather than looking up it's name.
511+
Decl *importDeclDirectly(const clang::NamedDecl *decl) override;
496512
};
497513

498514
ImportDecl *createImportDecl(ASTContext &Ctx, DeclContext *DC, ClangNode ClangN,

lib/ClangImporter/ClangImporter.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4346,3 +4346,18 @@ bool ClangImporter::isCXXMethodMutating(const clang::CXXMethodDecl *method) {
43464346
return isa<clang::CXXConstructorDecl>(method) || !method->isConst() ||
43474347
method->getParent()->hasMutableFields();
43484348
}
4349+
4350+
SwiftLookupTable *
4351+
ClangImporter::findLookupTable(const clang::Module *clangModule) {
4352+
return Impl.findLookupTable(clangModule);
4353+
}
4354+
4355+
/// Determine the effective Clang context for the given Swift nominal type.
4356+
EffectiveClangContext
4357+
ClangImporter::getEffectiveClangContext(const NominalTypeDecl *nominal) {
4358+
return Impl.getEffectiveClangContext(nominal);
4359+
}
4360+
4361+
Decl *ClangImporter::importDeclDirectly(const clang::NamedDecl *decl) {
4362+
return Impl.importDecl(decl, Impl.CurrentVersion);
4363+
}

0 commit comments

Comments
 (0)