Skip to content

Commit f7def54

Browse files
committed
Merge pull request #1279 from dduan/rename_decl_context_methods
[AST] rename some DeclContext isXXX methods to getAsXXX
2 parents 63e367e + efe2307 commit f7def54

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+163
-158
lines changed

include/swift/AST/DeclContext.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -240,27 +240,27 @@ class alignas(1 << DeclContextAlignInBits) DeclContext {
240240

241241
/// If this DeclContext is a nominal type declaration or an
242242
/// extension thereof, return the nominal type declaration.
243-
NominalTypeDecl *isNominalTypeOrNominalTypeExtensionContext() const;
243+
NominalTypeDecl *getAsNominalTypeOrNominalTypeExtensionContext() const;
244244

245245
/// If this DeclContext is a class, or an extension on a class, return the
246246
/// ClassDecl, otherwise return null.
247-
ClassDecl *isClassOrClassExtensionContext() const;
247+
ClassDecl *getAsClassOrClassExtensionContext() const;
248248

249249
/// If this DeclContext is an enum, or an extension on an enum, return the
250250
/// EnumDecl, otherwise return null.
251-
EnumDecl *isEnumOrEnumExtensionContext() const;
251+
EnumDecl *getAsEnumOrEnumExtensionContext() const;
252252

253253
/// If this DeclContext is a protocol, or an extension on a
254254
/// protocol, return the ProtocolDecl, otherwise return null.
255-
ProtocolDecl *isProtocolOrProtocolExtensionContext() const;
255+
ProtocolDecl *getAsProtocolOrProtocolExtensionContext() const;
256256

257257
/// If this DeclContext is a protocol extension, return the extended protocol.
258-
ProtocolDecl *isProtocolExtensionContext() const;
258+
ProtocolDecl *getAsProtocolExtensionContext() const;
259259

260260
/// \brief Retrieve the generic parameter 'Self' from a protocol or
261261
/// protocol extension.
262262
///
263-
/// Only valid if \c isProtocolOrProtocolExtensionContext().
263+
/// Only valid if \c getAsProtocolOrProtocolExtensionContext().
264264
GenericTypeParamDecl *getProtocolSelf() const;
265265

266266
/// getDeclaredTypeOfContext - For a type context, retrieves the declared

include/swift/SIL/SILInstruction.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2949,7 +2949,7 @@ class WitnessMethodInst : public MethodInst {
29492949
CanType getLookupType() const { return LookupType; }
29502950
ProtocolDecl *getLookupProtocol() const {
29512951
return getMember().getDecl()->getDeclContext()
2952-
->isProtocolOrProtocolExtensionContext();
2952+
->getAsProtocolOrProtocolExtensionContext();
29532953
}
29542954
ProtocolConformanceRef getConformance() const { return Conformance; }
29552955

lib/AST/ASTContext.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1952,7 +1952,8 @@ bool ASTContext::diagnoseUnintendedObjCMethodOverrides(SourceFile &sf) {
19521952
continue;
19531953
}
19541954

1955-
auto classDecl = method->getDeclContext()->isClassOrClassExtensionContext();
1955+
auto classDecl =
1956+
method->getDeclContext()->getAsClassOrClassExtensionContext();
19561957
if (!classDecl)
19571958
continue; // error-recovery path, only
19581959

@@ -2238,7 +2239,8 @@ bool ASTContext::diagnoseObjCUnsatisfiedOptReqConflicts(SourceFile &sf) {
22382239
bool anyDiagnosed = false;
22392240
for (const auto &unsatisfied : localReqs) {
22402241
// Check whether there is a conflict here.
2241-
ClassDecl *classDecl = unsatisfied.first->isClassOrClassExtensionContext();
2242+
ClassDecl *classDecl =
2243+
unsatisfied.first->getAsClassOrClassExtensionContext();
22422244
auto req = unsatisfied.second;
22432245
auto selector = req->getObjCSelector();
22442246
bool isInstanceMethod = req->isInstanceMember();

lib/AST/ASTPrinter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1219,7 +1219,7 @@ void PrintAST::printNominalDeclName(NominalTypeDecl *decl) {
12191219
// For a protocol extension, print only the where clause; the
12201220
// generic parameter list is implicit. For other nominal types,
12211221
// print the generic parameters.
1222-
if (decl->isProtocolOrProtocolExtensionContext())
1222+
if (decl->getAsProtocolOrProtocolExtensionContext())
12231223
printWhereClause(gp->getRequirements());
12241224
else
12251225
printGenericParams(gp);

lib/AST/ASTVerifier.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1742,7 +1742,7 @@ struct ASTNodeBase {};
17421742
} else {
17431743
auto ext = cast<ExtensionDecl>(decl);
17441744
conformingDC = ext;
1745-
nominal = ext->isNominalTypeOrNominalTypeExtensionContext();
1745+
nominal = ext->getAsNominalTypeOrNominalTypeExtensionContext();
17461746
}
17471747

17481748
auto proto = conformance->getProtocol();

lib/AST/ArchetypeBuilder.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1068,7 +1068,8 @@ bool ArchetypeBuilder::addAbstractTypeParamRequirements(
10681068
// Mark all associatedtypes in this protocol as recursive (and error-type)
10691069
// to avoid later crashes dealing with this invalid protocol in other
10701070
// contexts.
1071-
auto containingProto = assocType->getDeclContext()->isProtocolOrProtocolExtensionContext();
1071+
auto containingProto =
1072+
assocType->getDeclContext()->getAsProtocolOrProtocolExtensionContext();
10721073
for (auto member : containingProto->getMembers())
10731074
if (auto assocType = dyn_cast<AssociatedTypeDecl>(member))
10741075
assocType->setIsRecursive();

lib/AST/ConformanceLookupTable.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,7 @@ ProtocolConformance *ConformanceLookupTable::getConformance(
789789
return nullptr;
790790

791791
NominalTypeDecl *conformingNominal
792-
= conformingDC->isNominalTypeOrNominalTypeExtensionContext();
792+
= conformingDC->getAsNominalTypeOrNominalTypeExtensionContext();
793793

794794
// Form the conformance.
795795
Type type = entry->getDeclContext()->getDeclaredTypeInContext();
@@ -843,7 +843,7 @@ void ConformanceLookupTable::registerProtocolConformance(
843843
ProtocolConformance *conformance) {
844844
auto protocol = conformance->getProtocol();
845845
auto dc = conformance->getDeclContext();
846-
auto nominal = dc->isNominalTypeOrNominalTypeExtensionContext();
846+
auto nominal = dc->getAsNominalTypeOrNominalTypeExtensionContext();
847847

848848
// If there is an entry to update, do so.
849849
auto &dcConformances = AllConformances[dc];

lib/AST/Decl.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,7 +1220,8 @@ bool AbstractStorageDecl::hasFixedLayout() const {
12201220
return true;
12211221

12221222
// If we're in a nominal type, just query the type.
1223-
auto nominal = getDeclContext()->isNominalTypeOrNominalTypeExtensionContext();
1223+
auto nominal =
1224+
getDeclContext()->getAsNominalTypeOrNominalTypeExtensionContext();
12241225
if (nominal)
12251226
return nominal->hasFixedLayout();
12261227

@@ -1521,7 +1522,7 @@ OverloadSignature ValueDecl::getOverloadSignature() const {
15211522

15221523
signature.Name = getFullName();
15231524
signature.InProtocolExtension
1524-
= getDeclContext()->isProtocolExtensionContext();
1525+
= getDeclContext()->getAsProtocolExtensionContext();
15251526

15261527
// Functions, initializers, and de-initializers include their
15271528
// interface types in their signatures as well as whether they are
@@ -1633,7 +1634,7 @@ ArrayRef<ValueDecl *>
16331634
ValueDecl::getSatisfiedProtocolRequirements(bool Sorted) const {
16341635
// Dig out the nominal type.
16351636
NominalTypeDecl *NTD =
1636-
getDeclContext()->isNominalTypeOrNominalTypeExtensionContext();
1637+
getDeclContext()->getAsNominalTypeOrNominalTypeExtensionContext();
16371638
if (!NTD || isa<ProtocolDecl>(NTD))
16381639
return {};
16391640

@@ -1893,7 +1894,8 @@ Type NominalTypeDecl::computeInterfaceType() const {
18931894

18941895
// Figure out the interface type of the parent.
18951896
Type parentType;
1896-
if (auto parent = getDeclContext()->isNominalTypeOrNominalTypeExtensionContext())
1897+
if (auto parent =
1898+
getDeclContext()->getAsNominalTypeOrNominalTypeExtensionContext())
18971899
parentType = parent->getDeclaredInterfaceType();
18981900

18991901
Type type;
@@ -2024,7 +2026,7 @@ SourceRange GenericTypeParamDecl::getSourceRange() const {
20242026
bool GenericTypeParamDecl::isProtocolSelf() const {
20252027
if (!isImplicit()) return false;
20262028
auto dc = getDeclContext();
2027-
if (!dc->isProtocolOrProtocolExtensionContext()) return false;
2029+
if (!dc->getAsProtocolOrProtocolExtensionContext()) return false;
20282030
return dc->getProtocolSelf() == this;
20292031
}
20302032

@@ -3302,7 +3304,7 @@ static Type getSelfTypeForContext(DeclContext *dc) {
33023304
// For a protocol or extension thereof, the type is 'Self'.
33033305
// FIXME: Weird that we're producing an archetype for protocol Self,
33043306
// but the declared type of the context in non-protocol cases.
3305-
if (dc->isProtocolOrProtocolExtensionContext()) {
3307+
if (dc->getAsProtocolOrProtocolExtensionContext()) {
33063308
// In the parser, generic parameters won't be wired up yet, just give up on
33073309
// producing a type.
33083310
if (dc->getGenericParamsOfContext() == nullptr)
@@ -3971,7 +3973,7 @@ bool FuncDecl::isUnaryOperator() const {
39713973
return false;
39723974

39733975
unsigned opArgIndex
3974-
= getDeclContext()->isProtocolOrProtocolExtensionContext() ? 1 : 0;
3976+
= getDeclContext()->getAsProtocolOrProtocolExtensionContext() ? 1 : 0;
39753977

39763978
auto *params = getParameterList(opArgIndex);
39773979
return params->size() == 1 && !params->get(0)->isVariadic();
@@ -3982,7 +3984,7 @@ bool FuncDecl::isBinaryOperator() const {
39823984
return false;
39833985

39843986
unsigned opArgIndex
3985-
= getDeclContext()->isProtocolOrProtocolExtensionContext() ? 1 : 0;
3987+
= getDeclContext()->getAsProtocolOrProtocolExtensionContext() ? 1 : 0;
39863988

39873989
auto *params = getParameterList(opArgIndex);
39883990
return params->size() == 2 && !params->get(1)->isVariadic();
@@ -4084,7 +4086,7 @@ DynamicSelfType *FuncDecl::getDynamicSelfInterface() const {
40844086
}
40854087

40864088
bool FuncDecl::hasArchetypeSelf() const {
4087-
if (!getDeclContext()->isProtocolExtensionContext())
4089+
if (!getDeclContext()->getAsProtocolExtensionContext())
40884090
return false;
40894091

40904092
auto selfTy = getDeclContext()->getProtocolSelf()->getArchetype();

lib/AST/DeclContext.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ ASTContext &DeclContext::getASTContext() const {
3939
}
4040

4141
NominalTypeDecl *
42-
DeclContext::isNominalTypeOrNominalTypeExtensionContext() const {
42+
DeclContext::getAsNominalTypeOrNominalTypeExtensionContext() const {
4343
switch (getContextKind()) {
4444
case DeclContextKind::Module:
4545
case DeclContextKind::FileUnit:
@@ -73,31 +73,31 @@ DeclContext::isNominalTypeOrNominalTypeExtensionContext() const {
7373
}
7474
}
7575

76-
ClassDecl *DeclContext::isClassOrClassExtensionContext() const {
76+
ClassDecl *DeclContext::getAsClassOrClassExtensionContext() const {
7777
return dyn_cast_or_null<ClassDecl>(
78-
isNominalTypeOrNominalTypeExtensionContext());
78+
getAsNominalTypeOrNominalTypeExtensionContext());
7979
}
8080

81-
EnumDecl *DeclContext::isEnumOrEnumExtensionContext() const {
81+
EnumDecl *DeclContext::getAsEnumOrEnumExtensionContext() const {
8282
return dyn_cast_or_null<EnumDecl>(
83-
isNominalTypeOrNominalTypeExtensionContext());
83+
getAsNominalTypeOrNominalTypeExtensionContext());
8484
}
8585

86-
ProtocolDecl *DeclContext::isProtocolOrProtocolExtensionContext() const {
86+
ProtocolDecl *DeclContext::getAsProtocolOrProtocolExtensionContext() const {
8787
return dyn_cast_or_null<ProtocolDecl>(
88-
isNominalTypeOrNominalTypeExtensionContext());
88+
getAsNominalTypeOrNominalTypeExtensionContext());
8989
}
9090

91-
ProtocolDecl *DeclContext::isProtocolExtensionContext() const {
91+
ProtocolDecl *DeclContext::getAsProtocolExtensionContext() const {
9292
if (getContextKind() != DeclContextKind::ExtensionDecl)
9393
return nullptr;
9494

9595
return dyn_cast_or_null<ProtocolDecl>(
96-
isNominalTypeOrNominalTypeExtensionContext());
96+
getAsNominalTypeOrNominalTypeExtensionContext());
9797
}
9898

9999
GenericTypeParamDecl *DeclContext::getProtocolSelf() const {
100-
assert(isProtocolOrProtocolExtensionContext() && "not a protocol");
100+
assert(getAsProtocolOrProtocolExtensionContext() && "not a protocol");
101101
return getGenericParamsOfContext()->getParams().front();
102102
}
103103

@@ -176,7 +176,7 @@ Type DeclContext::getDeclaredTypeInContext() const {
176176

177177
Type DeclContext::getDeclaredInterfaceType() const {
178178
// FIXME: Need a sugar-preserving getExtendedInterfaceType for extensions
179-
if (auto nominal = isNominalTypeOrNominalTypeExtensionContext())
179+
if (auto nominal = getAsNominalTypeOrNominalTypeExtensionContext())
180180
return nominal->getDeclaredInterfaceType();
181181
return Type();
182182
}

lib/AST/LookupVisibleDecls.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ static void doGlobalExtensionLookup(Type BaseType,
175175
// Look in each extension of this type.
176176
for (auto extension : nominal->getExtensions()) {
177177
bool validatedExtension = false;
178-
if (TypeResolver && extension->isProtocolExtensionContext()) {
178+
if (TypeResolver && extension->getAsProtocolExtensionContext()) {
179179
if (!TypeResolver->isProtocolExtensionUsable(
180180
const_cast<DeclContext *>(CurrDC), BaseType, extension)) {
181181
continue;
@@ -754,7 +754,7 @@ void swift::lookupVisibleDecls(VisibleDeclConsumer &Consumer,
754754
BaseDecl = AFD->getImplicitSelfDecl();
755755
DC = DC->getParent();
756756

757-
if (DC->isProtocolExtensionContext())
757+
if (DC->getAsProtocolExtensionContext())
758758
ExtendedType = DC->getProtocolSelf()->getArchetype();
759759

760760
if (auto *FD = dyn_cast<FuncDecl>(AFD))

lib/AST/Module.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,7 @@ DeclContext *BoundGenericType::getGenericParamContext(
666666
if (!gpContext)
667667
return getDecl();
668668

669-
assert(gpContext->isNominalTypeOrNominalTypeExtensionContext() == getDecl() &&
669+
assert(gpContext->getAsNominalTypeOrNominalTypeExtensionContext() == getDecl() &&
670670
"not a valid context");
671671
return gpContext;
672672
}

lib/AST/NameLookup.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,11 @@ bool swift::removeShadowedDecls(SmallVectorImpl<ValueDecl*> &decls,
225225
// If one declaration is in a protocol or extension thereof and the
226226
// other is not, prefer the one that is not.
227227
if ((bool)firstDecl->getDeclContext()
228-
->isProtocolOrProtocolExtensionContext()
228+
->getAsProtocolOrProtocolExtensionContext()
229229
!= (bool)secondDecl->getDeclContext()
230-
->isProtocolOrProtocolExtensionContext()) {
230+
->getAsProtocolOrProtocolExtensionContext()) {
231231
if (firstDecl->getDeclContext()
232-
->isProtocolOrProtocolExtensionContext()) {
232+
->getAsProtocolOrProtocolExtensionContext()) {
233233
shadowed.insert(firstDecl);
234234
break;
235235
} else {
@@ -433,7 +433,7 @@ UnqualifiedLookup::UnqualifiedLookup(DeclName Name, DeclContext *DC,
433433
isCascadingUse = AFD->isCascadingContextForLookup(false);
434434

435435
if (AFD->getExtensionType()) {
436-
if (AFD->getDeclContext()->isProtocolOrProtocolExtensionContext()) {
436+
if (AFD->getDeclContext()->getAsProtocolOrProtocolExtensionContext()) {
437437
ExtendedType = AFD->getDeclContext()->getProtocolSelf()
438438
->getArchetype();
439439

@@ -479,13 +479,13 @@ UnqualifiedLookup::UnqualifiedLookup(DeclName Name, DeclContext *DC,
479479
if (!isCascadingUse.hasValue())
480480
isCascadingUse = ACE->isCascadingContextForLookup(false);
481481
} else if (ExtensionDecl *ED = dyn_cast<ExtensionDecl>(DC)) {
482-
if (ED->isProtocolOrProtocolExtensionContext()) {
482+
if (ED->getAsProtocolOrProtocolExtensionContext()) {
483483
ExtendedType = ED->getProtocolSelf()->getArchetype();
484484
} else {
485485
ExtendedType = ED->getExtendedType();
486486
}
487487

488-
BaseDecl = ED->isNominalTypeOrNominalTypeExtensionContext();
488+
BaseDecl = ED->getAsNominalTypeOrNominalTypeExtensionContext();
489489
MetaBaseDecl = BaseDecl;
490490
if (!isCascadingUse.hasValue())
491491
isCascadingUse = ED->isCascadingContextForLookup(false);

lib/AST/ProtocolConformance.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ ArrayRef<ValueDecl *>
635635
NominalTypeDecl::getSatisfiedProtocolRequirementsForMember(
636636
const ValueDecl *member,
637637
bool sorted) const {
638-
assert(member->getDeclContext()->isNominalTypeOrNominalTypeExtensionContext()
638+
assert(member->getDeclContext()->getAsNominalTypeOrNominalTypeExtensionContext()
639639
== this);
640640
assert(!isa<ProtocolDecl>(this));
641641
prepareConformanceTable();
@@ -654,7 +654,7 @@ DeclContext::getLocalProtocols(
654654
SmallVector<ProtocolDecl *, 2> result;
655655

656656
// Dig out the nominal type.
657-
NominalTypeDecl *nominal = isNominalTypeOrNominalTypeExtensionContext();
657+
NominalTypeDecl *nominal = getAsNominalTypeOrNominalTypeExtensionContext();
658658
if (!nominal)
659659
return result;
660660

@@ -687,7 +687,7 @@ DeclContext::getLocalConformances(
687687
SmallVector<ProtocolConformance *, 2> result;
688688

689689
// Dig out the nominal type.
690-
NominalTypeDecl *nominal = isNominalTypeOrNominalTypeExtensionContext();
690+
NominalTypeDecl *nominal = getAsNominalTypeOrNominalTypeExtensionContext();
691691
if (!nominal)
692692
return result;
693693

lib/AST/Type.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2411,7 +2411,7 @@ TypeSubstitutionMap TypeBase::getMemberSubstitutions(const DeclContext *dc) {
24112411

24122412
// If the member is part of a protocol or extension thereof, we need
24132413
// to substitute in the type of Self.
2414-
if (dc->isProtocolOrProtocolExtensionContext()) {
2414+
if (dc->getAsProtocolOrProtocolExtensionContext()) {
24152415
// We only substitute into archetypes for now for protocols.
24162416
// FIXME: This seems like an odd restriction. Whatever is depending on
24172417
// this, shouldn't.
@@ -2431,7 +2431,7 @@ TypeSubstitutionMap TypeBase::getMemberSubstitutions(const DeclContext *dc) {
24312431
LazyResolver *resolver = dc->getASTContext().getLazyResolver();
24322432

24332433
// Find the superclass type with the context matching that of the member.
2434-
auto ownerNominal = dc->isNominalTypeOrNominalTypeExtensionContext();
2434+
auto ownerNominal = dc->getAsNominalTypeOrNominalTypeExtensionContext();
24352435
while (!baseTy->is<ErrorType>() &&
24362436
baseTy->getAnyNominal() &&
24372437
baseTy->getAnyNominal() != ownerNominal) {

0 commit comments

Comments
 (0)