2929#include " swift/AST/SwiftNameTranslation.h"
3030#include " swift/AST/TypeDeclFinder.h"
3131#include " swift/Basic/Assertions.h"
32+ #include " swift/Basic/Feature.h"
3233#include " swift/Basic/SourceManager.h"
3334#include " swift/ClangImporter/ClangImporter.h"
3435#include " swift/SIL/SILInstruction.h"
@@ -1183,13 +1184,14 @@ EmittedClangHeaderDependencyInfo swift::printModuleContentsAsCxx(
11831184 std::string modulePrologueBuf;
11841185 llvm::raw_string_ostream prologueOS{modulePrologueBuf};
11851186 EmittedClangHeaderDependencyInfo info;
1187+ auto &context = M.getASTContext ();
11861188
11871189 // Define the `SWIFT_SYMBOL` macro.
11881190 os << " #ifdef SWIFT_SYMBOL\n " ;
11891191 os << " #undef SWIFT_SYMBOL\n " ;
11901192 os << " #endif\n " ;
11911193 os << " #define SWIFT_SYMBOL(usrValue) SWIFT_SYMBOL_MODULE_USR(\" " ;
1192- ClangSyntaxPrinter (M. getASTContext () , os).printBaseName (&M);
1194+ ClangSyntaxPrinter (context , os).printBaseName (&M);
11931195 os << " \" , usrValue)\n " ;
11941196
11951197 // FIXME: Use getRequiredAccess once @expose is supported.
@@ -1204,17 +1206,19 @@ EmittedClangHeaderDependencyInfo swift::printModuleContentsAsCxx(
12041206 os << " #include <string>\n " ;
12051207 os << " #endif\n " ;
12061208 os << " #include <new>\n " ;
1209+ if (context.LangOpts .hasFeature (Feature::Embedded))
1210+ os << " #define __EmbeddedSwift__\n " ;
12071211 // Embed an overlay for the standard library.
1208- ClangSyntaxPrinter (M. getASTContext () , moduleOS). printIncludeForShimHeader (
1209- " _SwiftStdlibCxxOverlay.h" );
1212+ ClangSyntaxPrinter (context , moduleOS)
1213+ . printIncludeForShimHeader ( " _SwiftStdlibCxxOverlay.h" );
12101214 // Ignore typos in Swift stdlib doc comments.
12111215 os << " #pragma clang diagnostic push\n " ;
12121216 os << " #pragma clang diagnostic ignored \" -Wdocumentation\"\n " ;
12131217 }
12141218
12151219 os << " #ifndef SWIFT_PRINTED_CORE\n " ;
12161220 os << " #define SWIFT_PRINTED_CORE\n " ;
1217- printSwiftToClangCoreScaffold (interopContext, M. getASTContext () ,
1221+ printSwiftToClangCoreScaffold (interopContext, context ,
12181222 writer.getTypeMapping (), os);
12191223 os << " #endif\n " ;
12201224
@@ -1226,9 +1230,9 @@ EmittedClangHeaderDependencyInfo swift::printModuleContentsAsCxx(
12261230 os << " #endif\n " ;
12271231 os << " #ifdef __cplusplus\n " ;
12281232 os << " namespace " ;
1229- ClangSyntaxPrinter (M. getASTContext () , os).printBaseName (&M);
1233+ ClangSyntaxPrinter (context , os).printBaseName (&M);
12301234 os << " SWIFT_PRIVATE_ATTR" ;
1231- ClangSyntaxPrinter (M. getASTContext () , os).printSymbolUSRAttribute (&M);
1235+ ClangSyntaxPrinter (context , os).printSymbolUSRAttribute (&M);
12321236 os << " {\n " ;
12331237 os << " namespace " << cxx_synthesis::getCxxImplNamespaceName () << " {\n " ;
12341238 os << " extern \" C\" {\n " ;
@@ -1246,10 +1250,13 @@ EmittedClangHeaderDependencyInfo swift::printModuleContentsAsCxx(
12461250 os << " #pragma clang diagnostic push\n " ;
12471251 os << " #pragma clang diagnostic ignored \" -Wreserved-identifier\"\n " ;
12481252 // Construct a C++ namespace for the module.
1249- ClangSyntaxPrinter (M.getASTContext (), os).printNamespace (
1250- [&](raw_ostream &os) { ClangSyntaxPrinter (M.getASTContext (), os).printBaseName (&M); },
1251- [&](raw_ostream &os) { os << moduleOS.str (); },
1252- ClangSyntaxPrinter::NamespaceTrivia::AttributeSwiftPrivate, &M);
1253+ ClangSyntaxPrinter (context, os)
1254+ .printNamespace (
1255+ [&](raw_ostream &os) {
1256+ ClangSyntaxPrinter (context, os).printBaseName (&M);
1257+ },
1258+ [&](raw_ostream &os) { os << moduleOS.str (); },
1259+ ClangSyntaxPrinter::NamespaceTrivia::AttributeSwiftPrivate, &M);
12531260 os << " #pragma clang diagnostic pop\n " ;
12541261
12551262 if (M.isStdlibModule ()) {
0 commit comments