31
31
#include " swift/Basic/Assertions.h"
32
32
#include " swift/Basic/SourceManager.h"
33
33
#include " swift/ClangImporter/ClangImporter.h"
34
+ #include " swift/SIL/SILInstruction.h"
34
35
#include " swift/Strings.h"
35
36
36
37
#include " clang/AST/Decl.h"
@@ -218,7 +219,10 @@ class ModuleWriter {
218
219
return state.first == EmissionState::Defined;
219
220
}
220
221
221
- bool require (const TypeDecl *D) {
222
+ bool require (const TypeDecl *D) { return requireTypes (D, declsToWrite); }
223
+
224
+ template <typename T>
225
+ bool requireTypes (const TypeDecl *D, T &types) {
222
226
if (addImport (D)) {
223
227
seenTypes[D] = { EmissionState::Defined, true };
224
228
return true ;
@@ -229,7 +233,7 @@ class ModuleWriter {
229
233
case EmissionState::NotYetDefined:
230
234
case EmissionState::DefinitionRequested:
231
235
state.first = EmissionState::DefinitionRequested;
232
- declsToWrite .push_back (D);
236
+ types .push_back (D);
233
237
return false ;
234
238
case EmissionState::Defined:
235
239
return true ;
@@ -364,23 +368,31 @@ class ModuleWriter {
364
368
}
365
369
366
370
bool hadAnyDelayedMembers = false ;
367
- SmallVector<ValueDecl *, 4 > nestedTypes;
371
+ SmallVector<const ValueDecl *, 4 > nestedTypes;
368
372
for (auto member : members) {
369
373
PrettyStackTraceDecl loopEntry (" printing for member" , member);
370
374
auto VD = dyn_cast<ValueDecl>(member);
371
375
if (!VD || !printer.shouldInclude (VD))
372
376
continue ;
373
377
374
378
// Catch nested types and emit their definitions /after/ this class.
375
- if (isa<TypeDecl>(VD)) {
376
- // Don't emit nested types that are just implicitly @objc.
377
- // You should have to opt into this, since they are even less
378
- // namespaced than usual.
379
- if (std::any_of (VD->getAttrs ().begin (), VD->getAttrs ().end (),
380
- [](const DeclAttribute *attr) {
381
- return isa<ObjCAttr>(attr) && !attr->isImplicit ();
382
- })) {
383
- nestedTypes.push_back (VD);
379
+ if (const auto *TD = dyn_cast<TypeDecl>(VD)) {
380
+ if (outputLangMode == OutputLanguageMode::Cxx) {
381
+ if (!isa<TypeAliasDecl>(TD) && !isStringNestedType (VD, " UTF8View" ) &&
382
+ !isStringNestedType (VD, " Index" )) {
383
+ forwardDeclareType (TD);
384
+ requireTypes (TD, nestedTypes);
385
+ }
386
+ } else {
387
+ // Don't emit nested types that are just implicitly @objc.
388
+ // You should have to opt into this, since they are even less
389
+ // namespaced than usual.
390
+ if (std::any_of (VD->getAttrs ().begin (), VD->getAttrs ().end (),
391
+ [](const DeclAttribute *attr) {
392
+ return isa<ObjCAttr>(attr) && !attr->isImplicit ();
393
+ })) {
394
+ nestedTypes.push_back (VD);
395
+ }
384
396
}
385
397
continue ;
386
398
}
@@ -1060,11 +1072,14 @@ EmittedClangHeaderDependencyInfo swift::printModuleContentsAsCxx(
1060
1072
os << " }\n " ;
1061
1073
}
1062
1074
1075
+ os << " #pragma clang diagnostic push\n " ;
1076
+ os << " #pragma clang diagnostic ignored \" -Wreserved-identifier\"\n " ;
1063
1077
// Construct a C++ namespace for the module.
1064
1078
ClangSyntaxPrinter (os).printNamespace (
1065
1079
[&](raw_ostream &os) { ClangSyntaxPrinter (os).printBaseName (&M); },
1066
1080
[&](raw_ostream &os) { os << moduleOS.str (); },
1067
1081
ClangSyntaxPrinter::NamespaceTrivia::AttributeSwiftPrivate, &M);
1082
+ os << " #pragma clang diagnostic pop\n " ;
1068
1083
1069
1084
if (M.isStdlibModule ()) {
1070
1085
os << " #pragma clang diagnostic pop\n " ;
0 commit comments