mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[interop][SwiftToCxx] guard inline emitted Stdlib module
This commit is contained in:
@@ -773,6 +773,9 @@ EmittedClangHeaderDependencyInfo swift::printModuleContentsAsCxx(
|
|||||||
|
|
||||||
// FIXME: refactor.
|
// FIXME: refactor.
|
||||||
if (!prologueOS.str().empty()) {
|
if (!prologueOS.str().empty()) {
|
||||||
|
// FIXME: This is a workaround for prologue being emitted outside of
|
||||||
|
// __cplusplus.
|
||||||
|
if (!M.isStdlibModule())
|
||||||
os << "#endif\n";
|
os << "#endif\n";
|
||||||
os << "#ifdef __cplusplus\n";
|
os << "#ifdef __cplusplus\n";
|
||||||
os << "namespace ";
|
os << "namespace ";
|
||||||
@@ -784,6 +787,7 @@ EmittedClangHeaderDependencyInfo swift::printModuleContentsAsCxx(
|
|||||||
|
|
||||||
os << prologueOS.str();
|
os << prologueOS.str();
|
||||||
|
|
||||||
|
if (!M.isStdlibModule())
|
||||||
os << "\n#ifdef __cplusplus\n";
|
os << "\n#ifdef __cplusplus\n";
|
||||||
os << "}\n";
|
os << "}\n";
|
||||||
os << "}\n";
|
os << "}\n";
|
||||||
|
|||||||
@@ -528,7 +528,12 @@ bool swift::printAsClangHeader(raw_ostream &os, ModuleDecl *M,
|
|||||||
if (defaultDependencyBehavior && deps.dependsOnStandardLibrary) {
|
if (defaultDependencyBehavior && deps.dependsOnStandardLibrary) {
|
||||||
assert(!M->isStdlibModule());
|
assert(!M->isStdlibModule());
|
||||||
SwiftToClangInteropContext interopContext(*M->getASTContext().getStdlibModule(), irGenOpts);
|
SwiftToClangInteropContext interopContext(*M->getASTContext().getStdlibModule(), irGenOpts);
|
||||||
|
auto macroGuard =
|
||||||
|
computeMacroGuard(M->getASTContext().getStdlibModule());
|
||||||
|
os << "#ifndef " << macroGuard << "\n";
|
||||||
|
os << "#define " << macroGuard << "\n";
|
||||||
printModuleContentsAsCxx(os, *M->getASTContext().getStdlibModule(), interopContext, /*requiresExposedAttribute=*/true);
|
printModuleContentsAsCxx(os, *M->getASTContext().getStdlibModule(), interopContext, /*requiresExposedAttribute=*/true);
|
||||||
|
os << "#endif // " << macroGuard << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
os << moduleContents.str();
|
os << moduleContents.str();
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
2
|
3
|
||||||
|
|||||||
@@ -1,9 +1,14 @@
|
|||||||
// RUN: %empty-directory(%t)
|
// RUN: %empty-directory(%t)
|
||||||
|
|
||||||
// RUN: %target-swift-frontend -typecheck %s -typecheck -module-name UseOptional -enable-experimental-cxx-interop -emit-clang-header-path %t/stdlib.h
|
// RUN: %target-swift-frontend -typecheck %s -typecheck -module-name UseOptional -enable-experimental-cxx-interop -emit-clang-header-path %t/stdlib.h
|
||||||
|
// RUN: %target-swift-frontend -typecheck %s -typecheck -module-name UseOptional2 -enable-experimental-cxx-interop -emit-clang-header-path %t/stdlib2.h
|
||||||
|
|
||||||
// RUN: %FileCheck %s < %t/stdlib.h
|
// RUN: %FileCheck %s < %t/stdlib.h
|
||||||
|
|
||||||
|
// RUN: cat %t/stdlib.h %t/stdlib2.h > %t/two_includes.h
|
||||||
|
|
||||||
|
// RUN: %check-generic-interop-cxx-header-in-clang(%t/two_includes.h -Wno-unused-private-field -Wno-unused-function -Wno-shadow -Wno-documentation)
|
||||||
|
|
||||||
@_expose(Cxx)
|
@_expose(Cxx)
|
||||||
public func test() -> String {
|
public func test() -> String {
|
||||||
return ""
|
return ""
|
||||||
|
|||||||
Reference in New Issue
Block a user