Skip to content

Commit 573af22

Browse files
author
David Ungar
committed
---
yaml --- r: 313335 b: refs/heads/A-7-9-astscope-no-nesting c: 46aa705 h: refs/heads/master i: 313333: 9fbb180 313331: e7452ea 313327: 584eb7c
1 parent 8321e4c commit 573af22

File tree

5 files changed

+62
-19
lines changed

5 files changed

+62
-19
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1416,4 +1416,4 @@ refs/tags/swift-DEVELOPMENT-SNAPSHOT-2019-06-30-a: 507bcc31605fe02fdc5d1fadca1bd
14161416
refs/tags/swift-DEVELOPMENT-SNAPSHOT-2019-07-01-a: 503b7173a821a8c714628503dfe1d865d9fb6804
14171417
refs/tags/swift-DEVELOPMENT-SNAPSHOT-2019-07-02-a: 1c3a1b43d7a730aa133f36327138335ce5b27765
14181418
refs/tags/swift-DEVELOPMENT-SNAPSHOT-2019-07-03-a: 67fd73eeb45b2a74028c6799704b79b1de9b7c87
1419-
refs/heads/A-7-9-astscope-no-nesting: e5e7b8363789f662ad23f2d93717c32a6138fef0
1419+
refs/heads/A-7-9-astscope-no-nesting: 46aa705930831cfce24b14beee762242545ce885

branches/A-7-9-astscope-no-nesting/include/swift/AST/ASTScope.h

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -896,18 +896,19 @@ class AbstractFunctionDeclScope final : public ASTScopeImpl {
896896
resolveIsCascadingUseForThisScope(Optional<bool>) const override;
897897
};
898898

899-
/// The parameters for an abstract function (init/func/deinit).
900-
class AbstractFunctionParamsScope final : public ASTScopeImpl {
899+
/// The parameters for an abstract function (init/func/deinit)., subscript, and
900+
/// enum element
901+
class ParameterListScope final : public ASTScopeImpl {
901902
public:
902903
ParameterList *const params;
903904
/// For get functions in subscript declarations,
904905
/// a lookup into the subscript parameters must count as the get func context.
905906
const NullablePtr<DeclContext> matchingContext;
906907

907-
AbstractFunctionParamsScope(ParameterList *params,
908-
NullablePtr<DeclContext> matchingContext)
908+
ParameterListScope(ParameterList *params,
909+
NullablePtr<DeclContext> matchingContext)
909910
: params(params), matchingContext(matchingContext) {}
910-
virtual ~AbstractFunctionParamsScope() {}
911+
virtual ~ParameterListScope() {}
911912

912913
protected:
913914
ASTScopeImpl *expandSpecifically(ScopeCreator &scopeCreator) override;
@@ -1478,6 +1479,29 @@ class VarDeclScope final : public ASTScopeImpl {
14781479
bool isThisAnAbstractStorageDecl() const override { return true; }
14791480
};
14801481

1482+
class EnumElementScope : public ASTScopeImpl {
1483+
EnumElementDecl *const decl;
1484+
1485+
public:
1486+
EnumElementScope(EnumElementDecl *e) : decl(e) {}
1487+
1488+
SourceRange
1489+
getChildlessSourceRange(bool omitAssertions = false) const override;
1490+
1491+
std::string getClassName() const override;
1492+
ASTScopeImpl *expandSpecifically(ScopeCreator &) override;
1493+
NullablePtr<DeclContext> getDeclContext() const override { return decl; }
1494+
NullablePtr<Decl> getDeclIfAny() const override { return decl; }
1495+
Decl *getDecl() const { return decl; }
1496+
1497+
protected:
1498+
SourceRange
1499+
getSourceRangeOfEnclosedParams(bool omitAssertions) const override;
1500+
1501+
private:
1502+
void expandAScopeThatDoesNotCreateANewInsertionPoint(ScopeCreator &);
1503+
};
1504+
14811505
class AbstractStmtScope : public ASTScopeImpl {
14821506
public:
14831507
SourceRange

branches/A-7-9-astscope-no-nesting/lib/AST/ASTScope.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ NullablePtr<DeclContext> AbstractFunctionDeclScope::getDeclContext() const {
187187
return decl;
188188
}
189189

190-
NullablePtr<DeclContext> AbstractFunctionParamsScope::getDeclContext() const {
190+
NullablePtr<DeclContext> ParameterListScope::getDeclContext() const {
191191
return matchingContext;
192192
}
193193

@@ -203,7 +203,7 @@ std::string GenericTypeOrExtensionScope::getClassName() const {
203203
DEFINE_GET_CLASS_NAME(ASTSourceFileScope)
204204
DEFINE_GET_CLASS_NAME(GenericParamScope)
205205
DEFINE_GET_CLASS_NAME(AbstractFunctionDeclScope)
206-
DEFINE_GET_CLASS_NAME(AbstractFunctionParamsScope)
206+
DEFINE_GET_CLASS_NAME(ParameterListScope)
207207
DEFINE_GET_CLASS_NAME(MethodBodyScope)
208208
DEFINE_GET_CLASS_NAME(PureFunctionBodyScope)
209209
DEFINE_GET_CLASS_NAME(DefaultArgumentInitializerScope)
@@ -220,6 +220,7 @@ DEFINE_GET_CLASS_NAME(TopLevelCodeScope)
220220
DEFINE_GET_CLASS_NAME(SpecializeAttributeScope)
221221
DEFINE_GET_CLASS_NAME(SubscriptDeclScope)
222222
DEFINE_GET_CLASS_NAME(VarDeclScope)
223+
DEFINE_GET_CLASS_NAME(EnumElementScope)
223224
DEFINE_GET_CLASS_NAME(IfStmtScope)
224225
DEFINE_GET_CLASS_NAME(WhileStmtScope)
225226
DEFINE_GET_CLASS_NAME(GuardStmtScope)

branches/A-7-9-astscope-no-nesting/lib/AST/ASTScopeCreation.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -618,8 +618,7 @@ class ASTVisitorForScopeCreation
618618
NullablePtr<ASTScopeImpl> visitEnumElementDecl(EnumElementDecl *eed,
619619
ASTScopeImpl *p,
620620
ScopeCreator &scopeCreator) {
621-
if (auto *expr = eed->getRawValueExpr()) // might contain a closure
622-
visitExpr(expr, p, scopeCreator);
621+
scopeCreator.createSubtree<EnumElementScope>(p, eed);
623622
return p;
624623
}
625624

@@ -785,7 +784,7 @@ ASTScopeImpl *ASTScopeImpl::expandAndBeCurrent(ScopeCreator &scopeCreator) {
785784
#define NO_EXPANSION(Scope) \
786785
ASTScopeImpl *Scope::expandSpecifically(ScopeCreator &) { return this; }
787786

788-
CREATES_NEW_INSERTION_POINT(AbstractFunctionParamsScope)
787+
CREATES_NEW_INSERTION_POINT(ParameterListScope)
789788
CREATES_NEW_INSERTION_POINT(ConditionalClauseScope)
790789
CREATES_NEW_INSERTION_POINT(GuardStmtScope)
791790
CREATES_NEW_INSERTION_POINT(PatternEntryDeclScope)
@@ -797,6 +796,7 @@ CREATES_NEW_INSERTION_POINT(TopLevelCodeScope)
797796
NO_NEW_INSERTION_POINT(AbstractFunctionBodyScope)
798797
NO_NEW_INSERTION_POINT(AbstractFunctionDeclScope)
799798
NO_NEW_INSERTION_POINT(AttachedPropertyWrapperScope)
799+
NO_NEW_INSERTION_POINT(EnumElementScope)
800800

801801
NO_NEW_INSERTION_POINT(CaptureListScope)
802802
NO_NEW_INSERTION_POINT(CaseStmtScope)
@@ -824,8 +824,7 @@ NO_EXPANSION(LookupParentDiversionScope)
824824
#undef CREATES_NEW_INSERTION_POINT
825825
#undef NO_NEW_INSERTION_POINT
826826

827-
ASTScopeImpl *
828-
AbstractFunctionParamsScope::expandAScopeThatCreatesANewInsertionPoint(
827+
ASTScopeImpl *ParameterListScope::expandAScopeThatCreatesANewInsertionPoint(
829828
ScopeCreator &scopeCreator) {
830829
// Each initializer for a function parameter is its own, sibling, scope.
831830
// Unlike generic parameters or pattern initializers, it cannot refer to a
@@ -957,7 +956,7 @@ void AbstractFunctionDeclScope::expandAScopeThatDoesNotCreateANewInsertionPoint(
957956
leaf = scopeCreator.createGenericParamScopes(decl, decl->getGenericParams(),
958957
leaf);
959958
if (isLocalizable(*decl) && getParamsSourceLoc(decl).isValid()) {
960-
leaf = scopeCreator.createSubtree<AbstractFunctionParamsScope>(
959+
leaf = scopeCreator.createSubtree<ParameterListScope>(
961960
leaf, decl->getParameters(), nullptr);
962961
}
963962
}
@@ -972,6 +971,14 @@ void AbstractFunctionDeclScope::expandAScopeThatDoesNotCreateANewInsertionPoint(
972971
}
973972
}
974973

974+
void EnumElementScope::expandAScopeThatDoesNotCreateANewInsertionPoint(
975+
ScopeCreator &scopeCreator) {
976+
if (auto *pl = decl->getParameterList())
977+
scopeCreator.createSubtree<ParameterListScope>(this, pl, nullptr);
978+
if (auto *expr = decl->getRawValueExpr()) // might contain a closure
979+
ASTVisitorForScopeCreation().visitExpr(expr, this, scopeCreator);
980+
}
981+
975982
void AbstractFunctionBodyScope::expandAScopeThatDoesNotCreateANewInsertionPoint(
976983
ScopeCreator &scopeCreator) {
977984
expandBody(scopeCreator);
@@ -1071,7 +1078,7 @@ void SubscriptDeclScope::expandAScopeThatDoesNotCreateANewInsertionPoint(
10711078
auto *sub = decl;
10721079
auto *leaf =
10731080
scopeCreator.createGenericParamScopes(sub, sub->getGenericParams(), this);
1074-
auto *params = scopeCreator.createSubtree<AbstractFunctionParamsScope>(
1081+
auto *params = scopeCreator.createSubtree<ParameterListScope>(
10751082
leaf, sub->getIndices(), sub->getGetter());
10761083
scopeCreator.addChildrenForAllLocalizableAccessors(sub, params);
10771084
}
@@ -1248,7 +1255,7 @@ AbstractFunctionDeclScope::getEnclosingAbstractStorageDecl() const {
12481255
return getParent().get()->getEnclosingAbstractStorageDecl();
12491256
}
12501257
NullablePtr<AbstractStorageDecl>
1251-
AbstractFunctionParamsScope::getEnclosingAbstractStorageDecl() const {
1258+
ParameterListScope::getEnclosingAbstractStorageDecl() const {
12521259
return getParent().get()->getEnclosingAbstractStorageDecl();
12531260
}
12541261
NullablePtr<AbstractStorageDecl>

branches/A-7-9-astscope-no-nesting/lib/AST/ASTScopeSourceRange.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,11 @@ SubscriptDeclScope::getChildlessSourceRange(const bool omitAssertions) const {
182182
return decl->getSourceRange();
183183
}
184184

185+
SourceRange
186+
EnumElementScope::getChildlessSourceRange(const bool omitAssertions) const {
187+
return decl->getSourceRange();
188+
}
189+
185190
SourceRange
186191
WholeClosureScope::getChildlessSourceRange(const bool omitAssertions) const {
187192
return closureExpr->getSourceRange();
@@ -292,14 +297,14 @@ SourceRange AbstractFunctionDeclScope::getChildlessSourceRange(
292297
return decl->getBody()->getSourceRange();
293298
}
294299

295-
SourceRange AbstractFunctionParamsScope::getChildlessSourceRange(
296-
const bool omitAssertions) const {
300+
SourceRange
301+
ParameterListScope::getChildlessSourceRange(const bool omitAssertions) const {
297302
const auto rangeForGoodInput = getSourceRangeOfEnclosedParams(omitAssertions);
298303
return SourceRange(rangeForGoodInput.Start,
299304
fixupEndForBadInput(rangeForGoodInput));
300305
}
301306

302-
SourceLoc AbstractFunctionParamsScope::fixupEndForBadInput(
307+
SourceLoc ParameterListScope::fixupEndForBadInput(
303308
const SourceRange rangeForGoodInput) const {
304309
const auto s = rangeForGoodInput.Start;
305310
const auto e = rangeForGoodInput.End;
@@ -541,6 +546,12 @@ ASTScopeImpl::getSourceRangeOfEnclosedParams(const bool omitAssertions) const {
541546
return getParent().get()->getSourceRangeOfEnclosedParams(omitAssertions);
542547
}
543548

549+
SourceRange
550+
EnumElementScope::getSourceRangeOfEnclosedParams(bool omitAssertions) const {
551+
auto *pl = decl->getParameterList();
552+
return pl ? pl->getSourceRange() : SourceRange();
553+
}
554+
544555
SourceRange SubscriptDeclScope::getSourceRangeOfEnclosedParams(
545556
const bool omitAssertions) const {
546557
auto r = SourceRange(decl->getIndices()->getLParenLoc(), decl->getEndLoc());

0 commit comments

Comments
 (0)