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,7 +773,10 @@ EmittedClangHeaderDependencyInfo swift::printModuleContentsAsCxx(
|
||||
|
||||
// FIXME: refactor.
|
||||
if (!prologueOS.str().empty()) {
|
||||
os << "#endif\n";
|
||||
// FIXME: This is a workaround for prologue being emitted outside of
|
||||
// __cplusplus.
|
||||
if (!M.isStdlibModule())
|
||||
os << "#endif\n";
|
||||
os << "#ifdef __cplusplus\n";
|
||||
os << "namespace ";
|
||||
M.ValueDecl::getName().print(os);
|
||||
@@ -784,7 +787,8 @@ EmittedClangHeaderDependencyInfo swift::printModuleContentsAsCxx(
|
||||
|
||||
os << prologueOS.str();
|
||||
|
||||
os << "\n#ifdef __cplusplus\n";
|
||||
if (!M.isStdlibModule())
|
||||
os << "\n#ifdef __cplusplus\n";
|
||||
os << "}\n";
|
||||
os << "}\n";
|
||||
os << "}\n";
|
||||
|
||||
@@ -528,7 +528,12 @@ bool swift::printAsClangHeader(raw_ostream &os, ModuleDecl *M,
|
||||
if (defaultDependencyBehavior && deps.dependsOnStandardLibrary) {
|
||||
assert(!M->isStdlibModule());
|
||||
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);
|
||||
os << "#endif // " << macroGuard << "\n";
|
||||
}
|
||||
|
||||
os << moduleContents.str();
|
||||
|
||||
@@ -1 +1 @@
|
||||
2
|
||||
3
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
// 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 UseOptional2 -enable-experimental-cxx-interop -emit-clang-header-path %t/stdlib2.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)
|
||||
public func test() -> String {
|
||||
return ""
|
||||
|
||||
Reference in New Issue
Block a user