Skip to content

Commit f436b60

Browse files
authored
Merge pull request swiftlang#34076 from slavapestov/more-astscope-cleanups
More ASTScope cleanups
2 parents df2924e + f8fb071 commit f436b60

File tree

7 files changed

+18
-231
lines changed

7 files changed

+18
-231
lines changed

include/swift/AST/ASTScope.h

Lines changed: 3 additions & 29 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; };
@@ -354,7 +353,7 @@ class ASTScopeImpl {
354353

355354
/// Entry point into ASTScopeImpl-land for lookups
356355
static void
357-
unqualifiedLookup(SourceFile *, DeclNameRef, SourceLoc, DeclConsumer);
356+
unqualifiedLookup(SourceFile *, SourceLoc, DeclConsumer);
358357

359358
/// Entry point into ASTScopeImpl-land for labeled statement lookups.
360359
static llvm::SmallVector<LabeledStmt *, 4>
@@ -366,7 +365,6 @@ class ASTScopeImpl {
366365
#pragma mark - - lookup- starting point
367366
private:
368367
static const ASTScopeImpl *findStartingScopeForLookup(SourceFile *,
369-
const DeclNameRef name,
370368
const SourceLoc where);
371369

372370
protected:
@@ -487,8 +485,6 @@ class ASTSourceFileScope final : public ASTScopeImpl {
487485
void printSpecifics(llvm::raw_ostream &out) const override;
488486

489487
public:
490-
NullablePtr<DeclContext> getDeclContext() const override;
491-
492488
void buildFullyExpandedTree();
493489
void
494490
buildEnoughOfTreeForTopLevelExpressionsButDontRequestGenericsOrExtendedNominals();
@@ -497,7 +493,8 @@ class ASTSourceFileScope final : public ASTScopeImpl {
497493

498494
const SourceFile *getSourceFile() const override;
499495
NullablePtr<const void> addressForPrinting() const override { return SF; }
500-
bool crossCheckWithAST();
496+
497+
ASTContext &getASTContext() const override;
501498

502499
protected:
503500
ASTScopeImpl *expandSpecifically(ScopeCreator &scopeCreator) override;
@@ -684,7 +681,6 @@ class GenericTypeOrExtensionScope : public ASTScopeImpl {
684681
// Returns the where clause scope, or the parent if none
685682
virtual ASTScopeImpl *createTrailingWhereClauseScope(ASTScopeImpl *parent,
686683
ScopeCreator &);
687-
NullablePtr<DeclContext> getDeclContext() const override;
688684
virtual NullablePtr<NominalTypeDecl> getCorrespondingNominalTypeDecl() const {
689685
return nullptr;
690686
}
@@ -829,7 +825,6 @@ class GenericParamScope final : public ASTScopeImpl {
829825

830826
/// Actually holder is always a GenericContext, need to test if
831827
/// ProtocolDecl or SubscriptDecl but will refactor later.
832-
NullablePtr<DeclContext> getDeclContext() const override;
833828
NullablePtr<const void> getReferrent() const override;
834829
std::string getClassName() const override;
835830
SourceRange
@@ -870,8 +865,6 @@ class AbstractFunctionDeclScope final : public ASTScopeImpl {
870865
void printSpecifics(llvm::raw_ostream &out) const override;
871866

872867
public:
873-
virtual NullablePtr<DeclContext> getDeclContext() const override;
874-
875868
virtual NullablePtr<Decl> getDeclIfAny() const override { return decl; }
876869
Decl *getDecl() const { return decl; }
877870

@@ -906,7 +899,6 @@ class ParameterListScope final : public ASTScopeImpl {
906899
std::string getClassName() const override;
907900
SourceRange
908901
getSourceRangeOfThisASTNode(bool omitAssertions = false) const override;
909-
virtual NullablePtr<DeclContext> getDeclContext() const override;
910902

911903
NullablePtr<const void> addressForPrinting() const override { return params; }
912904
};
@@ -929,9 +921,6 @@ class FunctionBodyScope : public ASTScopeImpl {
929921
public:
930922
SourceRange
931923
getSourceRangeOfThisASTNode(bool omitAssertions = false) const override;
932-
virtual NullablePtr<DeclContext> getDeclContext() const override {
933-
return decl;
934-
}
935924
virtual NullablePtr<Decl> getDeclIfAny() const override { return decl; }
936925
Decl *getDecl() const { return decl; }
937926

@@ -959,7 +948,6 @@ class DefaultArgumentInitializerScope final : public ASTScopeImpl {
959948
std::string getClassName() const override;
960949
SourceRange
961950
getSourceRangeOfThisASTNode(bool omitAssertions = false) const override;
962-
virtual NullablePtr<DeclContext> getDeclContext() const override;
963951
virtual NullablePtr<Decl> getDeclIfAny() const override { return decl; }
964952
Decl *getDecl() const { return decl; }
965953
};
@@ -1002,7 +990,6 @@ class AttachedPropertyWrapperScope final : public ASTScopeImpl {
1002990
SourceRange
1003991
getSourceRangeOfThisASTNode(bool omitAssertions = false) const override;
1004992
NullablePtr<const void> addressForPrinting() const override { return decl; }
1005-
virtual NullablePtr<DeclContext> getDeclContext() const override;
1006993

1007994
NullablePtr<DeclAttribute> getDeclAttributeIfAny() const override {
1008995
return attr;
@@ -1101,7 +1088,6 @@ class PatternEntryInitializerScope final : public AbstractPatternEntryScope {
11011088
std::string getClassName() const override;
11021089
SourceRange
11031090
getSourceRangeOfThisASTNode(bool omitAssertions = false) const override;
1104-
virtual NullablePtr<DeclContext> getDeclContext() const override;
11051091

11061092
protected:
11071093
bool lookupLocalsOrMembers(DeclConsumer) const override;
@@ -1189,7 +1175,6 @@ class CaptureListScope final : public ASTScopeImpl {
11891175
std::string getClassName() const override;
11901176
SourceRange
11911177
getSourceRangeOfThisASTNode(bool omitAssertions = false) const override;
1192-
NullablePtr<DeclContext> getDeclContext() const override;
11931178
NullablePtr<Expr> getExprIfAny() const override { return expr; }
11941179
Expr *getExpr() const { return expr; }
11951180
NullablePtr<const void> getReferrent() const override;
@@ -1212,9 +1197,6 @@ class ClosureParametersScope final : public ASTScopeImpl {
12121197
NullablePtr<ClosureExpr> getClosureIfClosureScope() const override {
12131198
return closureExpr;
12141199
}
1215-
NullablePtr<DeclContext> getDeclContext() const override {
1216-
return closureExpr;
1217-
}
12181200
NullablePtr<Expr> getExprIfAny() const override { return closureExpr; }
12191201
Expr *getExpr() const { return closureExpr; }
12201202
NullablePtr<const void> getReferrent() const override;
@@ -1247,9 +1229,6 @@ class TopLevelCodeScope final : public ASTScopeImpl {
12471229
std::string getClassName() const override;
12481230
SourceRange
12491231
getSourceRangeOfThisASTNode(bool omitAssertions = false) const override;
1250-
virtual NullablePtr<DeclContext> getDeclContext() const override {
1251-
return decl;
1252-
}
12531232
virtual NullablePtr<Decl> getDeclIfAny() const override { return decl; }
12541233
Decl *getDecl() const { return decl; }
12551234
NullablePtr<const void> getReferrent() const override;
@@ -1336,9 +1315,6 @@ class SubscriptDeclScope final : public ASTScopeImpl {
13361315
void printSpecifics(llvm::raw_ostream &out) const override;
13371316

13381317
public:
1339-
virtual NullablePtr<DeclContext> getDeclContext() const override {
1340-
return decl;
1341-
}
13421318
virtual NullablePtr<Decl> getDeclIfAny() const override { return decl; }
13431319
Decl *getDecl() const { return decl; }
13441320
NullablePtr<const void> getReferrent() const override;
@@ -1358,7 +1334,6 @@ class EnumElementScope : public ASTScopeImpl {
13581334

13591335
std::string getClassName() const override;
13601336
ASTScopeImpl *expandSpecifically(ScopeCreator &) override;
1361-
NullablePtr<DeclContext> getDeclContext() const override { return decl; }
13621337
NullablePtr<Decl> getDeclIfAny() const override { return decl; }
13631338
Decl *getDecl() const { return decl; }
13641339

@@ -1700,7 +1675,6 @@ class BraceStmtScope final : public AbstractStmtScope {
17001675
std::string getClassName() const override;
17011676
SourceRange
17021677
getSourceRangeOfThisASTNode(bool omitAssertions = false) const override;
1703-
virtual NullablePtr<DeclContext> getDeclContext() const override;
17041678

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

include/swift/AST/NameLookup.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ class ASTScope {
681681
/// Flesh out the tree for dumping
682682
void buildFullyExpandedTree();
683683

684-
static void unqualifiedLookup(SourceFile *, DeclNameRef, SourceLoc,
684+
static void unqualifiedLookup(SourceFile *, SourceLoc,
685685
namelookup::AbstractASTScopeDeclConsumer &);
686686

687687
/// Entry point to record the visible statement labels from the given

lib/AST/ASTScope.cpp

Lines changed: 6 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ using namespace ast_scope;
3939
#pragma mark ASTScope
4040

4141
void ASTScope::unqualifiedLookup(
42-
SourceFile *SF, DeclNameRef name, SourceLoc loc,
42+
SourceFile *SF, SourceLoc loc,
4343
namelookup::AbstractASTScopeDeclConsumer &consumer) {
4444
if (auto *s = SF->getASTContext().Stats)
4545
++s->getFrontendCounters().NumASTScopeLookups;
46-
ASTScopeImpl::unqualifiedLookup(SF, name, loc, consumer);
46+
ASTScopeImpl::unqualifiedLookup(SF, loc, consumer);
4747
}
4848

4949
llvm::SmallVector<LabeledStmt *, 4> ASTScope::lookupLabeledStmts(
@@ -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(); }

0 commit comments

Comments
 (0)