Skip to content

Commit 0e60775

Browse files
committed
NFC, refactor importer::requiresCPlusPlus into reusable function
1 parent d4aa18a commit 0e60775

File tree

4 files changed

+24
-34
lines changed

4 files changed

+24
-34
lines changed

include/swift/ClangImporter/ClangImporter.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,13 @@ getModuleCachePathFromClang(const clang::CompilerInstance &Instance);
572572
/// Whether the given parameter name identifies a completion handler.
573573
bool isCompletionHandlerParamName(StringRef paramName);
574574

575+
namespace importer {
576+
577+
/// Returns true if the given module has a 'cplusplus' requirement.
578+
bool requiresCPlusPlus(const clang::Module *module);
579+
580+
} // namespace importer
581+
575582
} // end namespace swift
576583

577584
#endif

lib/ClangImporter/ClangImporter.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6569,3 +6569,19 @@ void ClangImporter::enableSymbolicImportFeature(bool isEnabled) {
65696569
Impl.importSymbolicCXXDecls = isEnabled;
65706570
Impl.nameImporter->enableSymbolicImportFeature(isEnabled);
65716571
}
6572+
6573+
bool importer::requiresCPlusPlus(const clang::Module *module) {
6574+
// The libc++ modulemap doesn't currently declare the requirement.
6575+
if (module->getTopLevelModuleName() == "std")
6576+
return true;
6577+
6578+
// Modulemaps often declare the requirement for the top-level module only.
6579+
if (auto parent = module->Parent) {
6580+
if (requiresCPlusPlus(parent))
6581+
return true;
6582+
}
6583+
6584+
return llvm::any_of(module->Requirements, [](clang::Module::Requirement req) {
6585+
return req.first == "cplusplus";
6586+
});
6587+
}

lib/ClangImporter/ImporterImpl.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1927,22 +1927,6 @@ inline Optional<const clang::EnumDecl *> findAnonymousEnumForTypedef(
19271927
return None;
19281928
}
19291929

1930-
inline bool requiresCPlusPlus(const clang::Module *module) {
1931-
// The libc++ modulemap doesn't currently declare the requirement.
1932-
if (module->getTopLevelModuleName() == "std")
1933-
return true;
1934-
1935-
// Modulemaps often declare the requirement for the top-level module only.
1936-
if (auto parent = module->Parent) {
1937-
if (requiresCPlusPlus(parent))
1938-
return true;
1939-
}
1940-
1941-
return llvm::any_of(module->Requirements, [](clang::Module::Requirement req) {
1942-
return req.first == "cplusplus";
1943-
});
1944-
}
1945-
19461930
inline std::string getPrivateOperatorName(const std::string &OperatorToken) {
19471931
#define OVERLOADED_OPERATOR(Name, Spelling, Token, Unary, Binary, MemberOnly) \
19481932
if (OperatorToken == Spelling) { \

lib/Index/IndexRecord.cpp

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -396,23 +396,6 @@ emitDataForSwiftSerializedModule(ModuleDecl *module,
396396
const PathRemapper &pathRemapper,
397397
SourceFile *initialFile);
398398

399-
// FIXME (Alex): Share code with importer.
400-
inline bool requiresCPlusPlus(const clang::Module *module) {
401-
// The libc++ modulemap doesn't currently declare the requirement.
402-
if (module->getTopLevelModuleName() == "std")
403-
return true;
404-
405-
// Modulemaps often declare the requirement for the top-level module only.
406-
if (auto parent = module->Parent) {
407-
if (requiresCPlusPlus(parent))
408-
return true;
409-
}
410-
411-
return llvm::any_of(module->Requirements, [](clang::Module::Requirement req) {
412-
return req.first == "cplusplus";
413-
});
414-
}
415-
416399
static void
417400
appendSymbolicInterfaceToIndexStorePath(SmallVectorImpl<char> &resultingPath) {
418401
llvm::sys::path::append(resultingPath, "interfaces");
@@ -490,7 +473,7 @@ static void emitSymbolicInterfaceForClangModule(
490473
return;
491474
// Skip system modules without an explicit 'cplusplus' requirement.
492475
bool isSystem = clangModUnit->isSystemModule();
493-
if (isSystem && !requiresCPlusPlus(clangModule))
476+
if (isSystem && !importer::requiresCPlusPlus(clangModule))
494477
return;
495478

496479
// Make sure the `interfaces` directory is created.

0 commit comments

Comments
 (0)