Skip to content

Commit 9362bc8

Browse files
committed
Turn several helper methods on TypeChecker into static functions.
None of them actually depend on TypeChecker; they were just using it as a fast way to get an ASTContext.
1 parent 86fb3fa commit 9362bc8

File tree

2 files changed

+20
-39
lines changed

2 files changed

+20
-39
lines changed

lib/Sema/TypeCheckAvailability.cpp

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1404,10 +1404,7 @@ const AvailableAttr *TypeChecker::getDeprecated(const Decl *D) {
14041404
static bool
14051405
someEnclosingDeclMatches(SourceRange ReferenceRange,
14061406
const DeclContext *ReferenceDC,
1407-
TypeChecker &TC,
14081407
llvm::function_ref<bool(const Decl *)> Pred) {
1409-
ASTContext &Ctx = TC.Context;
1410-
14111408
// Climb the DeclContext hierarchy to see if any of the containing
14121409
// declarations matches the predicate.
14131410
const DeclContext *DC = ReferenceDC;
@@ -1446,6 +1443,7 @@ someEnclosingDeclMatches(SourceRange ReferenceRange,
14461443
if (ReferenceRange.isInvalid())
14471444
return false;
14481445

1446+
ASTContext &Ctx = ReferenceDC->getASTContext();
14491447
const Decl *DeclToSearch =
14501448
findContainingDeclaration(ReferenceRange, ReferenceDC, Ctx.SourceMgr);
14511449

@@ -1474,28 +1472,32 @@ someEnclosingDeclMatches(SourceRange ReferenceRange,
14741472
return false;
14751473
}
14761474

1477-
bool TypeChecker::isInsideImplicitFunction(SourceRange ReferenceRange,
1478-
const DeclContext *DC) {
1475+
/// Returns true if the reference or any of its parents is an
1476+
/// implicit function.
1477+
static bool isInsideImplicitFunction(SourceRange ReferenceRange,
1478+
const DeclContext *DC) {
14791479
auto IsInsideImplicitFunc = [](const Decl *D) {
14801480
auto *AFD = dyn_cast<AbstractFunctionDecl>(D);
14811481
return AFD && AFD->isImplicit();
14821482
};
14831483

1484-
return someEnclosingDeclMatches(ReferenceRange, DC, *this,
1485-
IsInsideImplicitFunc);
1484+
return someEnclosingDeclMatches(ReferenceRange, DC, IsInsideImplicitFunc);
14861485
}
14871486

1488-
bool TypeChecker::isInsideUnavailableDeclaration(
1489-
SourceRange ReferenceRange, const DeclContext *ReferenceDC) {
1487+
/// Returns true if the reference or any of its parents is an
1488+
/// unavailable (or obsoleted) declaration.
1489+
static bool isInsideUnavailableDeclaration(SourceRange ReferenceRange,
1490+
const DeclContext *ReferenceDC) {
14901491
auto IsUnavailable = [](const Decl *D) {
14911492
return D->getAttrs().getUnavailable(D->getASTContext());
14921493
};
14931494

1494-
return someEnclosingDeclMatches(ReferenceRange, ReferenceDC, *this,
1495-
IsUnavailable);
1495+
return someEnclosingDeclMatches(ReferenceRange, ReferenceDC, IsUnavailable);
14961496
}
14971497

1498-
bool TypeChecker::isInsideCompatibleUnavailableDeclaration(
1498+
/// Returns true if the reference or any of its parents is an
1499+
/// unconditional unavailable declaration for the same platform.
1500+
static bool isInsideCompatibleUnavailableDeclaration(
14991501
SourceRange ReferenceRange, const DeclContext *ReferenceDC,
15001502
const AvailableAttr *attr) {
15011503
if (!attr->isUnconditionallyUnavailable()) {
@@ -1512,18 +1514,18 @@ bool TypeChecker::isInsideCompatibleUnavailableDeclaration(
15121514
return EnclosingUnavailable && EnclosingUnavailable->Platform == platform;
15131515
};
15141516

1515-
return someEnclosingDeclMatches(ReferenceRange, ReferenceDC, *this,
1516-
IsUnavailable);
1517+
return someEnclosingDeclMatches(ReferenceRange, ReferenceDC, IsUnavailable);
15171518
}
15181519

1519-
bool TypeChecker::isInsideDeprecatedDeclaration(SourceRange ReferenceRange,
1520-
const DeclContext *ReferenceDC){
1520+
/// Returns true if the reference is lexically contained in a declaration
1521+
/// that is deprecated on all deployment targets.
1522+
static bool isInsideDeprecatedDeclaration(SourceRange ReferenceRange,
1523+
const DeclContext *ReferenceDC){
15211524
auto IsDeprecated = [](const Decl *D) {
15221525
return D->getAttrs().getDeprecated(D->getASTContext());
15231526
};
15241527

1525-
return someEnclosingDeclMatches(ReferenceRange, ReferenceDC, *this,
1526-
IsDeprecated);
1528+
return someEnclosingDeclMatches(ReferenceRange, ReferenceDC, IsDeprecated);
15271529
}
15281530

15291531
static void fixItAvailableAttrRename(TypeChecker &TC,

lib/Sema/TypeChecker.h

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2404,27 +2404,6 @@ class TypeChecker final : public LazyResolver {
24042404
const DeclContext *ReferenceDC, const UnavailabilityReason &Reason,
24052405
bool ForInout);
24062406

2407-
/// Returns true if the reference or any of its parents is an
2408-
/// implicit function.
2409-
bool isInsideImplicitFunction(SourceRange ReferenceRange,
2410-
const DeclContext *DC);
2411-
2412-
/// Returns true if the reference or any of its parents is an
2413-
/// unavailable (or obsoleted) declaration.
2414-
bool isInsideUnavailableDeclaration(SourceRange ReferenceRange,
2415-
const DeclContext *DC);
2416-
2417-
/// Returns true if the reference or any of its parents is an
2418-
/// unconditional unavailable declaration for the same platform.
2419-
bool isInsideCompatibleUnavailableDeclaration(SourceRange ReferenceRange,
2420-
const DeclContext *DC,
2421-
const AvailableAttr *attr);
2422-
2423-
/// Returns true if the reference is lexically contained in a declaration
2424-
/// that is deprecated on all deployment targets.
2425-
bool isInsideDeprecatedDeclaration(SourceRange ReferenceRange,
2426-
const DeclContext *DC);
2427-
24282407
/// Returns the availability attribute indicating deprecation if the
24292408
/// declaration is deprecated or null otherwise.
24302409
static const AvailableAttr *getDeprecated(const Decl *D);

0 commit comments

Comments
 (0)