Skip to content

Commit f8fb071

Browse files
committed
ASTScope: Remove ASTScopeImpl::getDeclContext()
1 parent 49e371c commit f8fb071

File tree

4 files changed

+7
-84
lines changed

4 files changed

+7
-84
lines changed

include/swift/AST/ASTScope.h

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,6 @@ class ASTScopeImpl {
280280
public:
281281
virtual NullablePtr<ClosureExpr> getClosureIfClosureScope() const;
282282
virtual ASTContext &getASTContext() const;
283-
virtual NullablePtr<DeclContext> getDeclContext() const;
284283
virtual NullablePtr<Decl> getDeclIfAny() const { return nullptr; };
285284
virtual NullablePtr<Stmt> getStmtIfAny() const { return nullptr; };
286285
virtual NullablePtr<Expr> getExprIfAny() const { return nullptr; };
@@ -486,8 +485,6 @@ class ASTSourceFileScope final : public ASTScopeImpl {
486485
void printSpecifics(llvm::raw_ostream &out) const override;
487486

488487
public:
489-
NullablePtr<DeclContext> getDeclContext() const override;
490-
491488
void buildFullyExpandedTree();
492489
void
493490
buildEnoughOfTreeForTopLevelExpressionsButDontRequestGenericsOrExtendedNominals();
@@ -497,6 +494,8 @@ class ASTSourceFileScope final : public ASTScopeImpl {
497494
const SourceFile *getSourceFile() const override;
498495
NullablePtr<const void> addressForPrinting() const override { return SF; }
499496

497+
ASTContext &getASTContext() const override;
498+
500499
protected:
501500
ASTScopeImpl *expandSpecifically(ScopeCreator &scopeCreator) override;
502501

@@ -682,7 +681,6 @@ class GenericTypeOrExtensionScope : public ASTScopeImpl {
682681
// Returns the where clause scope, or the parent if none
683682
virtual ASTScopeImpl *createTrailingWhereClauseScope(ASTScopeImpl *parent,
684683
ScopeCreator &);
685-
NullablePtr<DeclContext> getDeclContext() const override;
686684
virtual NullablePtr<NominalTypeDecl> getCorrespondingNominalTypeDecl() const {
687685
return nullptr;
688686
}
@@ -827,7 +825,6 @@ class GenericParamScope final : public ASTScopeImpl {
827825

828826
/// Actually holder is always a GenericContext, need to test if
829827
/// ProtocolDecl or SubscriptDecl but will refactor later.
830-
NullablePtr<DeclContext> getDeclContext() const override;
831828
NullablePtr<const void> getReferrent() const override;
832829
std::string getClassName() const override;
833830
SourceRange
@@ -868,8 +865,6 @@ class AbstractFunctionDeclScope final : public ASTScopeImpl {
868865
void printSpecifics(llvm::raw_ostream &out) const override;
869866

870867
public:
871-
virtual NullablePtr<DeclContext> getDeclContext() const override;
872-
873868
virtual NullablePtr<Decl> getDeclIfAny() const override { return decl; }
874869
Decl *getDecl() const { return decl; }
875870

@@ -904,7 +899,6 @@ class ParameterListScope final : public ASTScopeImpl {
904899
std::string getClassName() const override;
905900
SourceRange
906901
getSourceRangeOfThisASTNode(bool omitAssertions = false) const override;
907-
virtual NullablePtr<DeclContext> getDeclContext() const override;
908902

909903
NullablePtr<const void> addressForPrinting() const override { return params; }
910904
};
@@ -927,9 +921,6 @@ class FunctionBodyScope : public ASTScopeImpl {
927921
public:
928922
SourceRange
929923
getSourceRangeOfThisASTNode(bool omitAssertions = false) const override;
930-
virtual NullablePtr<DeclContext> getDeclContext() const override {
931-
return decl;
932-
}
933924
virtual NullablePtr<Decl> getDeclIfAny() const override { return decl; }
934925
Decl *getDecl() const { return decl; }
935926

@@ -957,7 +948,6 @@ class DefaultArgumentInitializerScope final : public ASTScopeImpl {
957948
std::string getClassName() const override;
958949
SourceRange
959950
getSourceRangeOfThisASTNode(bool omitAssertions = false) const override;
960-
virtual NullablePtr<DeclContext> getDeclContext() const override;
961951
virtual NullablePtr<Decl> getDeclIfAny() const override { return decl; }
962952
Decl *getDecl() const { return decl; }
963953
};
@@ -1000,7 +990,6 @@ class AttachedPropertyWrapperScope final : public ASTScopeImpl {
1000990
SourceRange
1001991
getSourceRangeOfThisASTNode(bool omitAssertions = false) const override;
1002992
NullablePtr<const void> addressForPrinting() const override { return decl; }
1003-
virtual NullablePtr<DeclContext> getDeclContext() const override;
1004993

1005994
NullablePtr<DeclAttribute> getDeclAttributeIfAny() const override {
1006995
return attr;
@@ -1099,7 +1088,6 @@ class PatternEntryInitializerScope final : public AbstractPatternEntryScope {
10991088
std::string getClassName() const override;
11001089
SourceRange
11011090
getSourceRangeOfThisASTNode(bool omitAssertions = false) const override;
1102-
virtual NullablePtr<DeclContext> getDeclContext() const override;
11031091

11041092
protected:
11051093
bool lookupLocalsOrMembers(DeclConsumer) const override;
@@ -1187,7 +1175,6 @@ class CaptureListScope final : public ASTScopeImpl {
11871175
std::string getClassName() const override;
11881176
SourceRange
11891177
getSourceRangeOfThisASTNode(bool omitAssertions = false) const override;
1190-
NullablePtr<DeclContext> getDeclContext() const override;
11911178
NullablePtr<Expr> getExprIfAny() const override { return expr; }
11921179
Expr *getExpr() const { return expr; }
11931180
NullablePtr<const void> getReferrent() const override;
@@ -1210,9 +1197,6 @@ class ClosureParametersScope final : public ASTScopeImpl {
12101197
NullablePtr<ClosureExpr> getClosureIfClosureScope() const override {
12111198
return closureExpr;
12121199
}
1213-
NullablePtr<DeclContext> getDeclContext() const override {
1214-
return closureExpr;
1215-
}
12161200
NullablePtr<Expr> getExprIfAny() const override { return closureExpr; }
12171201
Expr *getExpr() const { return closureExpr; }
12181202
NullablePtr<const void> getReferrent() const override;
@@ -1245,9 +1229,6 @@ class TopLevelCodeScope final : public ASTScopeImpl {
12451229
std::string getClassName() const override;
12461230
SourceRange
12471231
getSourceRangeOfThisASTNode(bool omitAssertions = false) const override;
1248-
virtual NullablePtr<DeclContext> getDeclContext() const override {
1249-
return decl;
1250-
}
12511232
virtual NullablePtr<Decl> getDeclIfAny() const override { return decl; }
12521233
Decl *getDecl() const { return decl; }
12531234
NullablePtr<const void> getReferrent() const override;
@@ -1334,9 +1315,6 @@ class SubscriptDeclScope final : public ASTScopeImpl {
13341315
void printSpecifics(llvm::raw_ostream &out) const override;
13351316

13361317
public:
1337-
virtual NullablePtr<DeclContext> getDeclContext() const override {
1338-
return decl;
1339-
}
13401318
virtual NullablePtr<Decl> getDeclIfAny() const override { return decl; }
13411319
Decl *getDecl() const { return decl; }
13421320
NullablePtr<const void> getReferrent() const override;
@@ -1356,7 +1334,6 @@ class EnumElementScope : public ASTScopeImpl {
13561334

13571335
std::string getClassName() const override;
13581336
ASTScopeImpl *expandSpecifically(ScopeCreator &) override;
1359-
NullablePtr<DeclContext> getDeclContext() const override { return decl; }
13601337
NullablePtr<Decl> getDeclIfAny() const override { return decl; }
13611338
Decl *getDecl() const { return decl; }
13621339

@@ -1698,7 +1675,6 @@ class BraceStmtScope final : public AbstractStmtScope {
16981675
std::string getClassName() const override;
16991676
SourceRange
17001677
getSourceRangeOfThisASTNode(bool omitAssertions = false) const override;
1701-
virtual NullablePtr<DeclContext> getDeclContext() const override;
17021678

17031679
NullablePtr<ClosureExpr> parentClosureIfAny() const; // public??
17041680
Stmt *getStmt() const override { return stmt; }

lib/AST/ASTScope.cpp

Lines changed: 4 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -116,62 +116,9 @@ LabeledConditionalStmt *GuardStmtScope::getLabeledConditionalStmt() const {
116116
ASTContext &ASTScopeImpl::getASTContext() const {
117117
if (auto d = getDeclIfAny())
118118
return d.get()->getASTContext();
119-
if (auto dc = getDeclContext())
120-
return dc.get()->getASTContext();
121119
return getParent().get()->getASTContext();
122120
}
123121

124-
#pragma mark getDeclContext
125-
126-
NullablePtr<DeclContext> ASTScopeImpl::getDeclContext() const {
127-
return nullptr;
128-
}
129-
130-
NullablePtr<DeclContext> ASTSourceFileScope::getDeclContext() const {
131-
return NullablePtr<DeclContext>(SF);
132-
}
133-
134-
NullablePtr<DeclContext> GenericTypeOrExtensionScope::getDeclContext() const {
135-
return getGenericContext();
136-
}
137-
138-
NullablePtr<DeclContext> GenericParamScope::getDeclContext() const {
139-
return dyn_cast<DeclContext>(holder);
140-
}
141-
142-
NullablePtr<DeclContext> PatternEntryInitializerScope::getDeclContext() const {
143-
return getPatternEntry().getInitContext();
144-
}
145-
146-
NullablePtr<DeclContext> BraceStmtScope::getDeclContext() const {
147-
return getParent().get()->getDeclContext();
148-
}
149-
150-
NullablePtr<DeclContext>
151-
DefaultArgumentInitializerScope::getDeclContext() const {
152-
auto *dc = decl->getDefaultArgumentInitContext();
153-
ASTScopeAssert(dc, "If scope exists, this must exist");
154-
return dc;
155-
}
156-
157-
// When asked for a loc in an intializer in a capture list, the asked-for
158-
// context is the closure.
159-
NullablePtr<DeclContext> CaptureListScope::getDeclContext() const {
160-
return expr->getClosureBody();
161-
}
162-
163-
NullablePtr<DeclContext> AttachedPropertyWrapperScope::getDeclContext() const {
164-
return decl->getParentPatternBinding()->getInitContext(0);
165-
}
166-
167-
NullablePtr<DeclContext> AbstractFunctionDeclScope::getDeclContext() const {
168-
return decl;
169-
}
170-
171-
NullablePtr<DeclContext> ParameterListScope::getDeclContext() const {
172-
return matchingContext;
173-
}
174-
175122
#pragma mark getClassName
176123

177124
std::string GenericTypeOrExtensionScope::getClassName() const {
@@ -224,6 +171,10 @@ const SourceFile *ASTScopeImpl::getSourceFile() const {
224171

225172
const SourceFile *ASTSourceFileScope::getSourceFile() const { return SF; }
226173

174+
ASTContext &ASTSourceFileScope::getASTContext() const {
175+
return SF->getASTContext();
176+
}
177+
227178
SourceRange ExtensionScope::getBraces() const { return decl->getBraces(); }
228179

229180
SourceRange NominalTypeScope::getBraces() const { return decl->getBraces(); }

lib/AST/ASTScopeLookup.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ bool GenericTypeOrExtensionWhereOrBodyPortion::lookupMembersOf(
248248
auto nt = scope->getCorrespondingNominalTypeDecl().getPtrOrNull();
249249
if (!nt)
250250
return false;
251-
return consumer.lookInMembers(scope->getDeclContext().get(), nt);
251+
return consumer.lookInMembers(scope->getGenericContext(), nt);
252252
}
253253

254254
bool GenericTypeOrExtensionWherePortion::lookupMembersOf(

lib/AST/ASTScopePrinting.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,6 @@ void ASTScopeImpl::dumpOneScopeMapLocation(
5656
auto *locScope = findInnermostEnclosingScope(loc, &llvm::errs());
5757
locScope->print(llvm::errs(), 0, false, false);
5858

59-
// Dump the AST context, too.
60-
if (auto *dc = locScope->getDeclContext().getPtrOrNull())
61-
dc->printContext(llvm::errs());
62-
6359
namelookup::ASTScopeDeclGatherer gatherer;
6460
// Print the local bindings introduced by this scope.
6561
locScope->lookupLocalsOrMembers(gatherer);

0 commit comments

Comments
 (0)