39
39
#include " swift/Parse/Lexer.h"
40
40
#include " swift/Parse/Parser.h"
41
41
42
+ #include " SwiftToClangInteropContext.h"
42
43
#include " clang/AST/ASTContext.h"
43
44
#include " clang/AST/Attr.h"
44
45
#include " clang/AST/Decl.h"
45
46
#include " clang/AST/DeclObjC.h"
46
47
#include " clang/Basic/CharInfo.h"
47
48
#include " clang/Basic/SourceManager.h"
48
- #include " SwiftToClangInteropContext .h"
49
+ #include " llvm/Support/raw_ostream .h"
49
50
50
51
using namespace swift ;
51
52
using namespace swift ::objc_translation;
@@ -561,8 +562,8 @@ class DeclAndTypePrinter::Implementation
561
562
outOfLineOS << " return swift::" ;
562
563
outOfLineOS << cxx_synthesis::getCxxImplNamespaceName ();
563
564
outOfLineOS << " ::implClassFor<" ;
564
- outOfLineSyntaxPrinter. printNominalTypeReference (
565
- objectTypeDecl ,
565
+ owningPrinter. printTypeName (
566
+ outOfLineOS, paramType ,
566
567
elementDecl->getParentEnum ()->getModuleContext ());
567
568
outOfLineOS << " >::type" ;
568
569
if (!isOptional && isa<ClassDecl>(objectTypeDecl)) {
@@ -574,8 +575,8 @@ class DeclAndTypePrinter::Implementation
574
575
outOfLineOS << " swift::"
575
576
<< cxx_synthesis::getCxxImplNamespaceName ();
576
577
outOfLineOS << " ::implClassFor<" ;
577
- outOfLineSyntaxPrinter. printNominalTypeReference (
578
- objectTypeDecl ,
578
+ owningPrinter. printTypeName (
579
+ outOfLineOS, paramType ,
579
580
elementDecl->getParentEnum ()->getModuleContext ());
580
581
outOfLineOS << " >::type" ;
581
582
outOfLineOS << " ::initializeWithTake(result, "
@@ -729,31 +730,36 @@ class DeclAndTypePrinter::Implementation
729
730
objectTypeDecl =
730
731
paramType->getNominalOrBoundGenericNominal ();
731
732
outOfLineOS << " alignas(" ;
732
- outOfLineSyntaxPrinter.printNominalTypeReference (
733
- objectTypeDecl, ED->getModuleContext ());
733
+ owningPrinter.printTypeName (
734
+ outOfLineOS, paramType,
735
+ elementDecl->getParentEnum ()->getModuleContext ());
734
736
outOfLineOS << " ) unsigned char buffer[sizeof(" ;
735
- outOfLineSyntaxPrinter.printNominalTypeReference (
736
- objectTypeDecl, ED->getModuleContext ());
737
+ owningPrinter.printTypeName (
738
+ outOfLineOS, paramType,
739
+ elementDecl->getParentEnum ()->getModuleContext ());
737
740
outOfLineOS << " )];\n " ;
738
741
outOfLineOS << " auto *valCopy = new(buffer) " ;
739
- outOfLineSyntaxPrinter.printNominalTypeReference (
740
- objectTypeDecl, ED->getModuleContext ());
742
+ owningPrinter.printTypeName (
743
+ outOfLineOS, paramType,
744
+ elementDecl->getParentEnum ()->getModuleContext ());
741
745
outOfLineOS << " (val);\n " ;
742
746
outOfLineOS << " " ;
743
747
outOfLineOS << cxx_synthesis::getCxxSwiftNamespaceName ()
744
748
<< " ::" ;
745
749
outOfLineOS << cxx_synthesis::getCxxImplNamespaceName ();
746
750
outOfLineOS << " ::implClassFor<" ;
747
- outOfLineSyntaxPrinter.printNominalTypeReference (
748
- objectTypeDecl, ED->getModuleContext ());
751
+ owningPrinter.printTypeName (
752
+ outOfLineOS, paramType,
753
+ elementDecl->getParentEnum ()->getModuleContext ());
749
754
outOfLineOS << " >::type::initializeWithTake(result._"
750
755
" getOpaquePointer(), " ;
751
756
outOfLineOS << cxx_synthesis::getCxxSwiftNamespaceName ()
752
757
<< " ::" ;
753
758
outOfLineOS << cxx_synthesis::getCxxImplNamespaceName ();
754
759
outOfLineOS << " ::implClassFor<" ;
755
- outOfLineSyntaxPrinter.printNominalTypeReference (
756
- objectTypeDecl, ED->getModuleContext ());
760
+ owningPrinter.printTypeName (
761
+ outOfLineOS, paramType,
762
+ elementDecl->getParentEnum ()->getModuleContext ());
757
763
outOfLineOS << " >::type::getOpaquePointer(*valCopy)" ;
758
764
outOfLineOS << " );\n " ;
759
765
}
@@ -2958,6 +2964,15 @@ void DeclAndTypePrinter::print(Type ty) {
2958
2964
getImpl ().print (ty, /* overridingOptionality*/ std::nullopt);
2959
2965
}
2960
2966
2967
+ void DeclAndTypePrinter::printTypeName (raw_ostream &os, Type ty,
2968
+ const ModuleDecl *moduleContext) {
2969
+ std::string dummy;
2970
+ llvm::raw_string_ostream dummyOS (dummy);
2971
+ DeclAndTypeClangFunctionPrinter printer (os, dummyOS, typeMapping,
2972
+ interopContext, *this );
2973
+ printer.printTypeName (ty, moduleContext);
2974
+ }
2975
+
2961
2976
void DeclAndTypePrinter::printAvailability (raw_ostream &os, const Decl *D) {
2962
2977
getImpl ().printAvailability (os, D);
2963
2978
}
0 commit comments