@@ -99,25 +99,18 @@ 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.
102
104
ModuleDecl &M;
103
105
raw_ostream &os;
104
- const DelayedMemberSet &delayedMembers;
105
- AccessLevel minRequiredAccess;
106
+ DeclAndTypePrinter &owningPrinter;
106
107
107
108
SmallVector<const FunctionType *, 4 > openFunctionTypes;
108
109
109
- using NameAndOptional = std::pair<StringRef, bool >;
110
- llvm::DenseMap<std::pair<Identifier, Identifier>, NameAndOptional>
111
- specialNames;
112
-
113
- // Cached for convenience.
114
- Identifier ID_CFTypeRef;
115
- Optional<Type> NSCopyingType;
116
-
117
110
public:
118
111
explicit Implementation (ModuleDecl &mod, raw_ostream &out,
119
- const DelayedMemberSet &delayed, AccessLevel access )
120
- : M(mod), os(out), delayedMembers(delayed), minRequiredAccess(access ) {}
112
+ DeclAndTypePrinter &owner )
113
+ : M(mod), os(out), owningPrinter(owner ) {}
121
114
122
115
void print (const Decl *D) {
123
116
PrettyStackTraceDecl trace (" printing" , D);
@@ -156,8 +149,7 @@ class DeclAndTypePrinter::Implementation
156
149
}
157
150
158
151
bool shouldInclude (const ValueDecl *VD) {
159
- return isVisibleToObjC (VD, minRequiredAccess) &&
160
- !VD->getAttrs ().hasAttribute <ImplementationOnlyAttr>();
152
+ return owningPrinter.shouldInclude (VD);
161
153
}
162
154
163
155
private:
@@ -195,7 +187,7 @@ class DeclAndTypePrinter::Implementation
195
187
continue ;
196
188
if (isa<AccessorDecl>(VD))
197
189
continue ;
198
- if (!AllowDelayed && delayedMembers.count (VD)) {
190
+ if (!AllowDelayed && owningPrinter. delayedMembers .count (VD)) {
199
191
os << " // '" << VD->getFullName () << " ' below\n " ;
200
192
continue ;
201
193
}
@@ -619,7 +611,7 @@ class DeclAndTypePrinter::Implementation
619
611
// Swift designated initializers are Objective-C designated initializers.
620
612
if (auto ctor = dyn_cast<ConstructorDecl>(AFD)) {
621
613
if (ctor->hasStubImplementation ()
622
- || ctor->getFormalAccess () < minRequiredAccess) {
614
+ || ctor->getFormalAccess () < owningPrinter. minRequiredAccess ) {
623
615
// This will only be reached if the overridden initializer has the
624
616
// required access
625
617
os << " SWIFT_UNAVAILABLE" ;
@@ -1062,9 +1054,9 @@ class DeclAndTypePrinter::Implementation
1062
1054
if (!TAD || !TAD->hasClangNode ())
1063
1055
return false ;
1064
1056
1065
- if (ID_CFTypeRef.empty ())
1066
- ID_CFTypeRef = M.getASTContext ().getIdentifier (" CFTypeRef" );
1067
- return TAD->getName () == ID_CFTypeRef;
1057
+ if (owningPrinter. ID_CFTypeRef .empty ())
1058
+ owningPrinter. ID_CFTypeRef = M.getASTContext ().getIdentifier (" CFTypeRef" );
1059
+ return TAD->getName () == owningPrinter. ID_CFTypeRef ;
1068
1060
}
1069
1061
1070
1062
// / Returns true if \p ty can be used with Objective-C reference-counting
@@ -1105,8 +1097,10 @@ class DeclAndTypePrinter::Implementation
1105
1097
1106
1098
ASTContext &ctx = M.getASTContext ();
1107
1099
bool isSettable = VD->isSettable (nullptr );
1108
- if (isSettable && !ctx.isAccessControlDisabled ())
1109
- isSettable = (VD->getSetterFormalAccess () >= minRequiredAccess);
1100
+ if (isSettable && !ctx.isAccessControlDisabled ()) {
1101
+ isSettable =
1102
+ (VD->getSetterFormalAccess () >= owningPrinter.minRequiredAccess );
1103
+ }
1110
1104
if (!isSettable)
1111
1105
os << " , readonly" ;
1112
1106
@@ -1393,19 +1387,19 @@ class DeclAndTypePrinter::Implementation
1393
1387
else if (swiftNominal == ctx.getDictionaryDecl () &&
1394
1388
isNSObjectOrAnyHashable (ctx, typeArgs[0 ])) {
1395
1389
if (ModuleDecl *M = ctx.getLoadedModule (ctx.Id_Foundation )) {
1396
- if (!NSCopyingType) {
1390
+ if (!owningPrinter. NSCopyingType ) {
1397
1391
SmallVector<ValueDecl *, 1 > decls;
1398
1392
M->lookupQualified (M, ctx.getIdentifier (" NSCopying" ),
1399
1393
NL_OnlyTypes, decls);
1400
1394
if (decls.size () == 1 && isa<ProtocolDecl>(decls[0 ])) {
1401
- NSCopyingType = cast<ProtocolDecl>(decls[0 ])
1395
+ owningPrinter. NSCopyingType = cast<ProtocolDecl>(decls[0 ])
1402
1396
->getDeclaredInterfaceType ();
1403
1397
} else {
1404
- NSCopyingType = Type ();
1398
+ owningPrinter. NSCopyingType = Type ();
1405
1399
}
1406
1400
}
1407
- if (*NSCopyingType) {
1408
- rewrittenArgsBuf[0 ] = *NSCopyingType;
1401
+ if (*owningPrinter. NSCopyingType ) {
1402
+ rewrittenArgsBuf[0 ] = *owningPrinter. NSCopyingType ;
1409
1403
rewrittenArgsBuf[1 ] = typeArgs[1 ];
1410
1404
typeArgs = rewrittenArgsBuf;
1411
1405
}
@@ -1452,6 +1446,7 @@ class DeclAndTypePrinter::Implementation
1452
1446
// /
1453
1447
// / Returns null if the name is not one of these known types.
1454
1448
const NameAndOptional *getKnownTypeInfo (const TypeDecl *typeDecl) {
1449
+ auto &specialNames = owningPrinter.specialNames ;
1455
1450
if (specialNames.empty ()) {
1456
1451
ASTContext &ctx = M.getASTContext ();
1457
1452
#define MAP (SWIFT_NAME, CLANG_REPR, NEEDS_NULLABILITY ) \
@@ -2035,11 +2030,12 @@ class DeclAndTypePrinter::Implementation
2035
2030
};
2036
2031
2037
2032
auto DeclAndTypePrinter::getImpl () -> Implementation {
2038
- return Implementation (M, os, delayedMembers, minRequiredAccess );
2033
+ return Implementation (M, os, * this );
2039
2034
}
2040
2035
2041
2036
bool DeclAndTypePrinter::shouldInclude (const ValueDecl *VD) {
2042
- return getImpl ().shouldInclude (VD);
2037
+ return isVisibleToObjC (VD, minRequiredAccess) &&
2038
+ !VD->getAttrs ().hasAttribute <ImplementationOnlyAttr>();
2043
2039
}
2044
2040
2045
2041
void DeclAndTypePrinter::print (const Decl *D) {
0 commit comments