@@ -99,18 +99,20 @@ class DeclAndTypePrinter::Implementation
99
99
friend ASTVisitor;
100
100
friend TypeVisitor;
101
101
102
- // These first two members are accessible through 'owningPrinter',
103
- // but it makes the code simpler to have them here too.
104
- ModuleDecl &M;
102
+ // The output stream is accessible through 'owningPrinter',
103
+ // but it makes the code simpler to have it here too.
105
104
raw_ostream &os;
106
105
DeclAndTypePrinter &owningPrinter;
107
106
108
107
SmallVector<const FunctionType *, 4 > openFunctionTypes;
109
108
109
+ ASTContext &getASTContext () const {
110
+ return owningPrinter.M .getASTContext ();
111
+ }
112
+
110
113
public:
111
- explicit Implementation (ModuleDecl &mod, raw_ostream &out,
112
- DeclAndTypePrinter &owner)
113
- : M(mod), os(out), owningPrinter(owner) {}
114
+ explicit Implementation (raw_ostream &out, DeclAndTypePrinter &owner)
115
+ : os(out), owningPrinter(owner) {}
114
116
115
117
void print (const Decl *D) {
116
118
PrettyStackTraceDecl trace (" printing" , D);
@@ -479,7 +481,7 @@ class DeclAndTypePrinter::Implementation
479
481
480
482
auto result = methodTy->getResult ();
481
483
if (result->isUninhabited ())
482
- return M. getASTContext ().TheEmptyTupleType ;
484
+ return getASTContext ().TheEmptyTupleType ;
483
485
return result;
484
486
}
485
487
@@ -678,7 +680,7 @@ class DeclAndTypePrinter::Implementation
678
680
// because it's a diagnostic inflicted on /clients/, but it's close
679
681
// enough. It really is invalid to call +new when -init is unavailable.
680
682
StringRef annotationName = " SWIFT_UNAVAILABLE_MSG" ;
681
- if (!M. getASTContext ().isSwiftVersionAtLeast (5 ))
683
+ if (!getASTContext ().isSwiftVersionAtLeast (5 ))
682
684
annotationName = " SWIFT_DEPRECATED_MSG" ;
683
685
os << " + (nonnull instancetype)new " << annotationName
684
686
<< " (\" -init is unavailable\" );\n " ;
@@ -984,7 +986,7 @@ class DeclAndTypePrinter::Implementation
984
986
}
985
987
986
988
void printSwift3ObjCDeprecatedInference (ValueDecl *VD) {
987
- const LangOptions &langOpts = M. getASTContext ().LangOpts ;
989
+ const LangOptions &langOpts = getASTContext ().LangOpts ;
988
990
if (!langOpts.EnableSwift3ObjCInference ||
989
991
langOpts.WarnSwift3ObjCInference == Swift3ObjCInferenceWarnings::None) {
990
992
return ;
@@ -1029,7 +1031,7 @@ class DeclAndTypePrinter::Implementation
1029
1031
ty = unwrapped;
1030
1032
1031
1033
auto genericTy = ty->getAs <BoundGenericStructType>();
1032
- if (!genericTy || genericTy->getDecl () != M. getASTContext ().getArrayDecl ())
1034
+ if (!genericTy || genericTy->getDecl () != getASTContext ().getArrayDecl ())
1033
1035
return false ;
1034
1036
1035
1037
assert (genericTy->getGenericArgs ().size () == 1 );
@@ -1055,7 +1057,7 @@ class DeclAndTypePrinter::Implementation
1055
1057
return false ;
1056
1058
1057
1059
if (owningPrinter.ID_CFTypeRef .empty ())
1058
- owningPrinter.ID_CFTypeRef = M. getASTContext ().getIdentifier (" CFTypeRef" );
1060
+ owningPrinter.ID_CFTypeRef = getASTContext ().getIdentifier (" CFTypeRef" );
1059
1061
return TAD->getName () == owningPrinter.ID_CFTypeRef ;
1060
1062
}
1061
1063
@@ -1095,7 +1097,7 @@ class DeclAndTypePrinter::Implementation
1095
1097
if (VD->isStatic ())
1096
1098
os << " , class" ;
1097
1099
1098
- ASTContext &ctx = M. getASTContext ();
1100
+ ASTContext &ctx = getASTContext ();
1099
1101
bool isSettable = VD->isSettable (nullptr );
1100
1102
if (isSettable && !ctx.isAccessControlDisabled ()) {
1101
1103
isSettable =
@@ -1339,7 +1341,7 @@ class DeclAndTypePrinter::Implementation
1339
1341
1340
1342
// Determine whether this nominal type is _ObjectiveCBridgeable.
1341
1343
SmallVector<ProtocolConformance *, 2 > conformances;
1342
- if (!nominal->lookupConformance (&M, proto, conformances))
1344
+ if (!nominal->lookupConformance (&owningPrinter. M , proto, conformances))
1343
1345
return nullptr ;
1344
1346
1345
1347
// Dig out the Objective-C type.
@@ -1448,7 +1450,7 @@ class DeclAndTypePrinter::Implementation
1448
1450
const NameAndOptional *getKnownTypeInfo (const TypeDecl *typeDecl) {
1449
1451
auto &specialNames = owningPrinter.specialNames ;
1450
1452
if (specialNames.empty ()) {
1451
- ASTContext &ctx = M. getASTContext ();
1453
+ ASTContext &ctx = getASTContext ();
1452
1454
#define MAP (SWIFT_NAME, CLANG_REPR, NEEDS_NULLABILITY ) \
1453
1455
specialNames[{ctx.StdlibModuleName , ctx.getIdentifier (#SWIFT_NAME)}] = \
1454
1456
{ CLANG_REPR, NEEDS_NULLABILITY}
@@ -1561,7 +1563,7 @@ class DeclAndTypePrinter::Implementation
1561
1563
}
1562
1564
1563
1565
bool isClangPointerType (const clang::TypeDecl *clangTypeDecl) const {
1564
- ASTContext &ctx = M. getASTContext ();
1566
+ ASTContext &ctx = getASTContext ();
1565
1567
auto &clangASTContext = ctx.getClangModuleLoader ()->getClangASTContext ();
1566
1568
clang::QualType clangTy = clangASTContext.getTypeDeclType (clangTypeDecl);
1567
1569
return clangTy->isPointerType () || clangTy->isBlockPointerType () ||
@@ -1619,7 +1621,7 @@ class DeclAndTypePrinter::Implementation
1619
1621
if (clangDecl->getTypedefNameForAnonDecl ())
1620
1622
return ;
1621
1623
1622
- ASTContext &ctx = M. getASTContext ();
1624
+ ASTContext &ctx = getASTContext ();
1623
1625
auto importer = static_cast <ClangImporter *>(ctx.getClangModuleLoader ());
1624
1626
if (importer->hasTypedef (clangDecl))
1625
1627
return ;
@@ -1652,7 +1654,7 @@ class DeclAndTypePrinter::Implementation
1652
1654
// /
1653
1655
// / This will print the type as bridged to Objective-C.
1654
1656
void printCollectionElement (Type ty) {
1655
- ASTContext &ctx = M. getASTContext ();
1657
+ ASTContext &ctx = getASTContext ();
1656
1658
1657
1659
auto isSwiftNewtype = [](const StructDecl *SD) -> bool {
1658
1660
if (!SD)
@@ -1672,7 +1674,7 @@ class DeclAndTypePrinter::Implementation
1672
1674
SD != ctx.getDictionaryDecl () &&
1673
1675
SD != ctx.getSetDecl () &&
1674
1676
!isSwiftNewtype (SD)) {
1675
- ty = ctx.getBridgedToObjC (&M, ty);
1677
+ ty = ctx.getBridgedToObjC (&owningPrinter. M , ty);
1676
1678
}
1677
1679
1678
1680
assert (ty && " unknown bridged type" );
@@ -1688,7 +1690,7 @@ class DeclAndTypePrinter::Implementation
1688
1690
if (!SD->getModuleContext ()->isStdlibModule ())
1689
1691
return false ;
1690
1692
1691
- ASTContext &ctx = M. getASTContext ();
1693
+ ASTContext &ctx = getASTContext ();
1692
1694
1693
1695
if (SD == ctx.getUnmanagedDecl ()) {
1694
1696
auto args = BGT->getGenericArgs ();
@@ -2010,7 +2012,7 @@ class DeclAndTypePrinter::Implementation
2010
2012
void print (Type ty, Optional<OptionalTypeKind> optionalKind,
2011
2013
Identifier name = Identifier(),
2012
2014
IsFunctionParam_t isFuncParam = IsNotFunctionParam) {
2013
- PrettyStackTraceType trace (M. getASTContext (), " printing" , ty);
2015
+ PrettyStackTraceType trace (getASTContext (), " printing" , ty);
2014
2016
2015
2017
if (isFuncParam)
2016
2018
if (auto fnTy = ty->lookThroughAllOptionalTypes ()
@@ -2030,7 +2032,7 @@ class DeclAndTypePrinter::Implementation
2030
2032
};
2031
2033
2032
2034
auto DeclAndTypePrinter::getImpl () -> Implementation {
2033
- return Implementation (M, os, *this );
2035
+ return Implementation (os, *this );
2034
2036
}
2035
2037
2036
2038
bool DeclAndTypePrinter::shouldInclude (const ValueDecl *VD) {
0 commit comments