29
29
#include " swift/AST/SwiftNameTranslation.h"
30
30
#include " swift/AST/TypeDeclFinder.h"
31
31
#include " swift/Basic/Assertions.h"
32
+ #include " swift/Basic/Feature.h"
32
33
#include " swift/Basic/SourceManager.h"
33
34
#include " swift/ClangImporter/ClangImporter.h"
34
35
#include " swift/SIL/SILInstruction.h"
@@ -1183,13 +1184,14 @@ EmittedClangHeaderDependencyInfo swift::printModuleContentsAsCxx(
1183
1184
std::string modulePrologueBuf;
1184
1185
llvm::raw_string_ostream prologueOS{modulePrologueBuf};
1185
1186
EmittedClangHeaderDependencyInfo info;
1187
+ auto &context = M.getASTContext ();
1186
1188
1187
1189
// Define the `SWIFT_SYMBOL` macro.
1188
1190
os << " #ifdef SWIFT_SYMBOL\n " ;
1189
1191
os << " #undef SWIFT_SYMBOL\n " ;
1190
1192
os << " #endif\n " ;
1191
1193
os << " #define SWIFT_SYMBOL(usrValue) SWIFT_SYMBOL_MODULE_USR(\" " ;
1192
- ClangSyntaxPrinter (M. getASTContext () , os).printBaseName (&M);
1194
+ ClangSyntaxPrinter (context , os).printBaseName (&M);
1193
1195
os << " \" , usrValue)\n " ;
1194
1196
1195
1197
// FIXME: Use getRequiredAccess once @expose is supported.
@@ -1204,17 +1206,19 @@ EmittedClangHeaderDependencyInfo swift::printModuleContentsAsCxx(
1204
1206
os << " #include <string>\n " ;
1205
1207
os << " #endif\n " ;
1206
1208
os << " #include <new>\n " ;
1209
+ if (context.LangOpts .hasFeature (Feature::Embedded))
1210
+ os << " #define __EmbeddedSwift__\n " ;
1207
1211
// Embed an overlay for the standard library.
1208
- ClangSyntaxPrinter (M. getASTContext () , moduleOS). printIncludeForShimHeader (
1209
- " _SwiftStdlibCxxOverlay.h" );
1212
+ ClangSyntaxPrinter (context , moduleOS)
1213
+ . printIncludeForShimHeader ( " _SwiftStdlibCxxOverlay.h" );
1210
1214
// Ignore typos in Swift stdlib doc comments.
1211
1215
os << " #pragma clang diagnostic push\n " ;
1212
1216
os << " #pragma clang diagnostic ignored \" -Wdocumentation\"\n " ;
1213
1217
}
1214
1218
1215
1219
os << " #ifndef SWIFT_PRINTED_CORE\n " ;
1216
1220
os << " #define SWIFT_PRINTED_CORE\n " ;
1217
- printSwiftToClangCoreScaffold (interopContext, M. getASTContext () ,
1221
+ printSwiftToClangCoreScaffold (interopContext, context ,
1218
1222
writer.getTypeMapping (), os);
1219
1223
os << " #endif\n " ;
1220
1224
@@ -1226,9 +1230,9 @@ EmittedClangHeaderDependencyInfo swift::printModuleContentsAsCxx(
1226
1230
os << " #endif\n " ;
1227
1231
os << " #ifdef __cplusplus\n " ;
1228
1232
os << " namespace " ;
1229
- ClangSyntaxPrinter (M. getASTContext () , os).printBaseName (&M);
1233
+ ClangSyntaxPrinter (context , os).printBaseName (&M);
1230
1234
os << " SWIFT_PRIVATE_ATTR" ;
1231
- ClangSyntaxPrinter (M. getASTContext () , os).printSymbolUSRAttribute (&M);
1235
+ ClangSyntaxPrinter (context , os).printSymbolUSRAttribute (&M);
1232
1236
os << " {\n " ;
1233
1237
os << " namespace " << cxx_synthesis::getCxxImplNamespaceName () << " {\n " ;
1234
1238
os << " extern \" C\" {\n " ;
@@ -1246,10 +1250,13 @@ EmittedClangHeaderDependencyInfo swift::printModuleContentsAsCxx(
1246
1250
os << " #pragma clang diagnostic push\n " ;
1247
1251
os << " #pragma clang diagnostic ignored \" -Wreserved-identifier\"\n " ;
1248
1252
// 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);
1253
1260
os << " #pragma clang diagnostic pop\n " ;
1254
1261
1255
1262
if (M.isStdlibModule ()) {
0 commit comments