Skip to content

Commit dbbbbe5

Browse files
committed
[PrintAsObjC] DeclAndTypePrinter::Impl doesn't need the module
It can get it from the owning DeclAndTypePrinter, and most of the time it's only using it to get the ASTContext anyway. No functionality change.
1 parent d68eae6 commit dbbbbe5

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed

lib/PrintAsObjC/DeclAndTypePrinter.cpp

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -99,18 +99,20 @@ class DeclAndTypePrinter::Implementation
9999
friend ASTVisitor;
100100
friend TypeVisitor;
101101

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.
105104
raw_ostream &os;
106105
DeclAndTypePrinter &owningPrinter;
107106

108107
SmallVector<const FunctionType *, 4> openFunctionTypes;
109108

109+
ASTContext &getASTContext() const {
110+
return owningPrinter.M.getASTContext();
111+
}
112+
110113
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) {}
114116

115117
void print(const Decl *D) {
116118
PrettyStackTraceDecl trace("printing", D);
@@ -479,7 +481,7 @@ class DeclAndTypePrinter::Implementation
479481

480482
auto result = methodTy->getResult();
481483
if (result->isUninhabited())
482-
return M.getASTContext().TheEmptyTupleType;
484+
return getASTContext().TheEmptyTupleType;
483485
return result;
484486
}
485487

@@ -678,7 +680,7 @@ class DeclAndTypePrinter::Implementation
678680
// because it's a diagnostic inflicted on /clients/, but it's close
679681
// enough. It really is invalid to call +new when -init is unavailable.
680682
StringRef annotationName = "SWIFT_UNAVAILABLE_MSG";
681-
if (!M.getASTContext().isSwiftVersionAtLeast(5))
683+
if (!getASTContext().isSwiftVersionAtLeast(5))
682684
annotationName = "SWIFT_DEPRECATED_MSG";
683685
os << "+ (nonnull instancetype)new " << annotationName
684686
<< "(\"-init is unavailable\");\n";
@@ -984,7 +986,7 @@ class DeclAndTypePrinter::Implementation
984986
}
985987

986988
void printSwift3ObjCDeprecatedInference(ValueDecl *VD) {
987-
const LangOptions &langOpts = M.getASTContext().LangOpts;
989+
const LangOptions &langOpts = getASTContext().LangOpts;
988990
if (!langOpts.EnableSwift3ObjCInference ||
989991
langOpts.WarnSwift3ObjCInference == Swift3ObjCInferenceWarnings::None) {
990992
return;
@@ -1029,7 +1031,7 @@ class DeclAndTypePrinter::Implementation
10291031
ty = unwrapped;
10301032

10311033
auto genericTy = ty->getAs<BoundGenericStructType>();
1032-
if (!genericTy || genericTy->getDecl() != M.getASTContext().getArrayDecl())
1034+
if (!genericTy || genericTy->getDecl() != getASTContext().getArrayDecl())
10331035
return false;
10341036

10351037
assert(genericTy->getGenericArgs().size() == 1);
@@ -1055,7 +1057,7 @@ class DeclAndTypePrinter::Implementation
10551057
return false;
10561058

10571059
if (owningPrinter.ID_CFTypeRef.empty())
1058-
owningPrinter.ID_CFTypeRef = M.getASTContext().getIdentifier("CFTypeRef");
1060+
owningPrinter.ID_CFTypeRef = getASTContext().getIdentifier("CFTypeRef");
10591061
return TAD->getName() == owningPrinter.ID_CFTypeRef;
10601062
}
10611063

@@ -1095,7 +1097,7 @@ class DeclAndTypePrinter::Implementation
10951097
if (VD->isStatic())
10961098
os << ", class";
10971099

1098-
ASTContext &ctx = M.getASTContext();
1100+
ASTContext &ctx = getASTContext();
10991101
bool isSettable = VD->isSettable(nullptr);
11001102
if (isSettable && !ctx.isAccessControlDisabled()) {
11011103
isSettable =
@@ -1339,7 +1341,7 @@ class DeclAndTypePrinter::Implementation
13391341

13401342
// Determine whether this nominal type is _ObjectiveCBridgeable.
13411343
SmallVector<ProtocolConformance *, 2> conformances;
1342-
if (!nominal->lookupConformance(&M, proto, conformances))
1344+
if (!nominal->lookupConformance(&owningPrinter.M, proto, conformances))
13431345
return nullptr;
13441346

13451347
// Dig out the Objective-C type.
@@ -1448,7 +1450,7 @@ class DeclAndTypePrinter::Implementation
14481450
const NameAndOptional *getKnownTypeInfo(const TypeDecl *typeDecl) {
14491451
auto &specialNames = owningPrinter.specialNames;
14501452
if (specialNames.empty()) {
1451-
ASTContext &ctx = M.getASTContext();
1453+
ASTContext &ctx = getASTContext();
14521454
#define MAP(SWIFT_NAME, CLANG_REPR, NEEDS_NULLABILITY) \
14531455
specialNames[{ctx.StdlibModuleName, ctx.getIdentifier(#SWIFT_NAME)}] = \
14541456
{ CLANG_REPR, NEEDS_NULLABILITY}
@@ -1561,7 +1563,7 @@ class DeclAndTypePrinter::Implementation
15611563
}
15621564

15631565
bool isClangPointerType(const clang::TypeDecl *clangTypeDecl) const {
1564-
ASTContext &ctx = M.getASTContext();
1566+
ASTContext &ctx = getASTContext();
15651567
auto &clangASTContext = ctx.getClangModuleLoader()->getClangASTContext();
15661568
clang::QualType clangTy = clangASTContext.getTypeDeclType(clangTypeDecl);
15671569
return clangTy->isPointerType() || clangTy->isBlockPointerType() ||
@@ -1619,7 +1621,7 @@ class DeclAndTypePrinter::Implementation
16191621
if (clangDecl->getTypedefNameForAnonDecl())
16201622
return;
16211623

1622-
ASTContext &ctx = M.getASTContext();
1624+
ASTContext &ctx = getASTContext();
16231625
auto importer = static_cast<ClangImporter *>(ctx.getClangModuleLoader());
16241626
if (importer->hasTypedef(clangDecl))
16251627
return;
@@ -1652,7 +1654,7 @@ class DeclAndTypePrinter::Implementation
16521654
///
16531655
/// This will print the type as bridged to Objective-C.
16541656
void printCollectionElement(Type ty) {
1655-
ASTContext &ctx = M.getASTContext();
1657+
ASTContext &ctx = getASTContext();
16561658

16571659
auto isSwiftNewtype = [](const StructDecl *SD) -> bool {
16581660
if (!SD)
@@ -1672,7 +1674,7 @@ class DeclAndTypePrinter::Implementation
16721674
SD != ctx.getDictionaryDecl() &&
16731675
SD != ctx.getSetDecl() &&
16741676
!isSwiftNewtype(SD)) {
1675-
ty = ctx.getBridgedToObjC(&M, ty);
1677+
ty = ctx.getBridgedToObjC(&owningPrinter.M, ty);
16761678
}
16771679

16781680
assert(ty && "unknown bridged type");
@@ -1688,7 +1690,7 @@ class DeclAndTypePrinter::Implementation
16881690
if (!SD->getModuleContext()->isStdlibModule())
16891691
return false;
16901692

1691-
ASTContext &ctx = M.getASTContext();
1693+
ASTContext &ctx = getASTContext();
16921694

16931695
if (SD == ctx.getUnmanagedDecl()) {
16941696
auto args = BGT->getGenericArgs();
@@ -2010,7 +2012,7 @@ class DeclAndTypePrinter::Implementation
20102012
void print(Type ty, Optional<OptionalTypeKind> optionalKind,
20112013
Identifier name = Identifier(),
20122014
IsFunctionParam_t isFuncParam = IsNotFunctionParam) {
2013-
PrettyStackTraceType trace(M.getASTContext(), "printing", ty);
2015+
PrettyStackTraceType trace(getASTContext(), "printing", ty);
20142016

20152017
if (isFuncParam)
20162018
if (auto fnTy = ty->lookThroughAllOptionalTypes()
@@ -2030,7 +2032,7 @@ class DeclAndTypePrinter::Implementation
20302032
};
20312033

20322034
auto DeclAndTypePrinter::getImpl() -> Implementation {
2033-
return Implementation(M, os, *this);
2035+
return Implementation(os, *this);
20342036
}
20352037

20362038
bool DeclAndTypePrinter::shouldInclude(const ValueDecl *VD) {

0 commit comments

Comments
 (0)