1212
1313#include " PrintClangValueType.h"
1414#include " ClangSyntaxPrinter.h"
15+ #include " DeclAndTypePrinter.h"
1516#include " OutputLanguageMode.h"
1617#include " PrimitiveTypeMapping.h"
1718#include " SwiftToClangInteropContext.h"
@@ -81,14 +82,16 @@ printCValueTypeStorageStruct(raw_ostream &os, const NominalTypeDecl *typeDecl,
8182 os << " };\n\n " ;
8283}
8384
84- void ClangValueTypePrinter::forwardDeclType (raw_ostream &os,
85- const NominalTypeDecl *typeDecl) {
85+ void ClangValueTypePrinter::forwardDeclType (
86+ raw_ostream &os, const NominalTypeDecl *typeDecl,
87+ DeclAndTypePrinter &declAndTypePrinter) {
8688 if (typeDecl->isGeneric ()) {
8789 auto genericSignature =
8890 typeDecl->getGenericSignature ().getCanonicalSignature ();
8991 ClangSyntaxPrinter (os).printGenericSignature (genericSignature);
9092 }
9193 os << " class" ;
94+ declAndTypePrinter.printAvailability (os, typeDecl);
9295 ClangSyntaxPrinter (os).printSymbolUSRAttribute (typeDecl);
9396 os << ' ' ;
9497 ClangSyntaxPrinter (os).printBaseName (typeDecl);
@@ -173,8 +176,8 @@ static void addCppExtensionsToStdlibType(const NominalTypeDecl *typeDecl,
173176}
174177
175178void ClangValueTypePrinter::printValueTypeDecl (
176- const NominalTypeDecl *typeDecl,
177- llvm::function_ref< void ( void )> bodyPrinter ) {
179+ const NominalTypeDecl *typeDecl, llvm::function_ref< void ( void )> bodyPrinter,
180+ DeclAndTypePrinter &declAndTypePrinter ) {
178181 // FIXME: Add support for generic structs.
179182 llvm::Optional<IRABIDetailsProvider::SizeAndAlignment> typeSizeAlign;
180183 Optional<CanGenericSignature> genericSignature;
@@ -221,7 +224,9 @@ void ClangValueTypePrinter::printValueTypeDecl(
221224 printer.printNamespace (cxx_synthesis::getCxxImplNamespaceName (),
222225 [&](raw_ostream &os) {
223226 printGenericSignature (os);
224- os << " class " ;
227+ os << " class" ;
228+ declAndTypePrinter.printAvailability (os, typeDecl);
229+ os << ' ' ;
225230 printCxxImplClassName (os, typeDecl);
226231 os << " ;\n\n " ;
227232
@@ -263,6 +268,7 @@ void ClangValueTypePrinter::printValueTypeDecl(
263268 // Print out the C++ class itself.
264269 printGenericSignature (os);
265270 os << " class" ;
271+ declAndTypePrinter.printAvailability (os, typeDecl);
266272 ClangSyntaxPrinter (os).printSymbolUSRAttribute (typeDecl);
267273 os << ' ' ;
268274 ClangSyntaxPrinter (os).printBaseName (typeDecl);
@@ -408,7 +414,9 @@ void ClangValueTypePrinter::printValueTypeDecl(
408414 printer.printNamespace (
409415 cxx_synthesis::getCxxImplNamespaceName (), [&](raw_ostream &os) {
410416 printGenericSignature (os);
411- os << " class " ;
417+ os << " class" ;
418+ declAndTypePrinter.printAvailability (os, typeDecl);
419+ os << ' ' ;
412420 printCxxImplClassName (os, typeDecl);
413421 os << " {\n " ;
414422 os << " public:\n " ;
@@ -461,7 +469,7 @@ void ClangValueTypePrinter::printValueTypeDecl(
461469
462470 printTypeGenericTraits (os, typeDecl, typeMetadataFuncName,
463471 typeMetadataFuncGenericParams,
464- typeDecl->getModuleContext ());
472+ typeDecl->getModuleContext (), declAndTypePrinter );
465473}
466474
467475void ClangValueTypePrinter::printParameterCxxToCUseScaffold (
@@ -512,8 +520,8 @@ void ClangValueTypePrinter::printValueTypeReturnScaffold(
512520}
513521
514522void ClangValueTypePrinter::printClangTypeSwiftGenericTraits (
515- raw_ostream &os, const TypeDecl *typeDecl,
516- const ModuleDecl *moduleContext ) {
523+ raw_ostream &os, const TypeDecl *typeDecl, const ModuleDecl *moduleContext,
524+ DeclAndTypePrinter &declAndTypePrinter ) {
517525 assert (typeDecl->hasClangNode ());
518526 // Do not reference unspecialized templates.
519527 if (isa<clang::ClassTemplateDecl>(typeDecl->getClangDecl ()))
@@ -522,7 +530,8 @@ void ClangValueTypePrinter::printClangTypeSwiftGenericTraits(
522530 typeDecl->getDeclaredInterfaceType ()->getCanonicalType ());
523531 std::string typeMetadataFuncName = typeMetadataFunc.mangleAsString ();
524532 printTypeGenericTraits (os, typeDecl, typeMetadataFuncName,
525- /* typeMetadataFuncRequirements=*/ {}, moduleContext);
533+ /* typeMetadataFuncRequirements=*/ {}, moduleContext,
534+ declAndTypePrinter);
526535}
527536
528537void ClangValueTypePrinter::printTypePrecedingGenericTraits (
@@ -553,7 +562,7 @@ void ClangValueTypePrinter::printTypePrecedingGenericTraits(
553562void ClangValueTypePrinter::printTypeGenericTraits (
554563 raw_ostream &os, const TypeDecl *typeDecl, StringRef typeMetadataFuncName,
555564 ArrayRef<GenericRequirement> typeMetadataFuncRequirements,
556- const ModuleDecl *moduleContext) {
565+ const ModuleDecl *moduleContext, DeclAndTypePrinter &declAndTypePrinter ) {
557566 auto *NTD = dyn_cast<NominalTypeDecl>(typeDecl);
558567 ClangSyntaxPrinter printer (os);
559568 // FIXME: avoid popping out of the module's namespace here.
@@ -580,7 +589,9 @@ void ClangValueTypePrinter::printTypeGenericTraits(
580589 }
581590 if (!NTD || printer.printNominalTypeOutsideMemberDeclTemplateSpecifiers (NTD))
582591 os << " template<>\n " ;
583- os << " struct TypeMetadataTrait<" ;
592+ os << " struct" ;
593+ declAndTypePrinter.printAvailability (os, typeDecl);
594+ os << " TypeMetadataTrait<" ;
584595 if (typeDecl->hasClangNode ()) {
585596 printer.printClangTypeReference (typeDecl->getClangDecl ());
586597 } else {
@@ -635,7 +646,9 @@ void ClangValueTypePrinter::printTypeGenericTraits(
635646 if (!typeDecl->hasClangNode () && typeMetadataFuncRequirements.empty ()) {
636647 assert (NTD);
637648 os << " template<>\n " ;
638- os << " struct implClassFor<" ;
649+ os << " struct" ;
650+ declAndTypePrinter.printAvailability (os, typeDecl);
651+ os << " implClassFor<" ;
639652 printer.printBaseName (typeDecl->getModuleContext ());
640653 os << " ::" ;
641654 printer.printBaseName (typeDecl);
0 commit comments