Skip to content

Commit abcdc6c

Browse files
committed
[ASTScope] Rename and generalize AttachedPropertyWrapperScope to CustomAttributeScope
so that it can represent the scope for any custom attribute and its arguments. This commit is NFC, but CustomAttributeScope is now applicable to attached macros.
1 parent bcb01ce commit abcdc6c

File tree

4 files changed

+15
-19
lines changed

4 files changed

+15
-19
lines changed

include/swift/AST/ASTScope.h

+10-14
Original file line numberDiff line numberDiff line change
@@ -840,24 +840,20 @@ class DefaultArgumentInitializerScope final : public ASTScopeImpl {
840840
bool ignoreInDebugInfo() const override { return true; }
841841
};
842842

843-
/// Consider:
844-
/// @_propertyWrapper
845-
/// struct WrapperWithInitialValue {
846-
/// }
847-
/// struct HasWrapper {
848-
/// @WrapperWithInitialValue var y = 17
849-
/// }
850-
/// Lookup has to be able to find the use of WrapperWithInitialValue, that's
851-
/// what this scope is for. Because the source positions are screwy.
852-
853-
class AttachedPropertyWrapperScope final : public ASTScopeImpl {
843+
/// The scope for custom attributes and their arguments, such as for
844+
/// attached property wrappers and for attached macros.
845+
///
846+
/// Source locations for the attribute name and its arguments are in the
847+
/// custom attribute, so lookup is invoked from within the attribute
848+
/// itself.
849+
class CustomAttributeScope final : public ASTScopeImpl {
854850
public:
855851
CustomAttr *attr;
856-
VarDecl *decl;
852+
ValueDecl *decl;
857853

858-
AttachedPropertyWrapperScope(CustomAttr *attr, VarDecl *decl)
854+
CustomAttributeScope(CustomAttr *attr, ValueDecl *decl)
859855
: attr(attr), decl(decl) {}
860-
virtual ~AttachedPropertyWrapperScope() {}
856+
virtual ~CustomAttributeScope() {}
861857

862858
protected:
863859
ASTScopeImpl *expandSpecifically(ScopeCreator &) override;

lib/AST/ASTScope.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ DEFINE_GET_CLASS_NAME(AbstractFunctionDeclScope)
138138
DEFINE_GET_CLASS_NAME(ParameterListScope)
139139
DEFINE_GET_CLASS_NAME(FunctionBodyScope)
140140
DEFINE_GET_CLASS_NAME(DefaultArgumentInitializerScope)
141-
DEFINE_GET_CLASS_NAME(AttachedPropertyWrapperScope)
141+
DEFINE_GET_CLASS_NAME(CustomAttributeScope)
142142
DEFINE_GET_CLASS_NAME(PatternEntryDeclScope)
143143
DEFINE_GET_CLASS_NAME(PatternEntryInitializerScope)
144144
DEFINE_GET_CLASS_NAME(ConditionalClausePatternUseScope)

lib/AST/ASTScopeCreation.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ void ScopeCreator::addChildrenForKnownAttributes(ValueDecl *decl,
602602
}
603603
} else if (auto *customAttr = dyn_cast<CustomAttr>(attr)) {
604604
if (auto *vd = dyn_cast<VarDecl>(decl)) {
605-
constructExpandAndInsert<AttachedPropertyWrapperScope>(
605+
constructExpandAndInsert<CustomAttributeScope>(
606606
parent, customAttr, vd);
607607
}
608608
}
@@ -716,7 +716,7 @@ CREATES_NEW_INSERTION_POINT(ConditionalClausePatternUseScope)
716716

717717
NO_NEW_INSERTION_POINT(FunctionBodyScope)
718718
NO_NEW_INSERTION_POINT(AbstractFunctionDeclScope)
719-
NO_NEW_INSERTION_POINT(AttachedPropertyWrapperScope)
719+
NO_NEW_INSERTION_POINT(CustomAttributeScope)
720720
NO_NEW_INSERTION_POINT(EnumElementScope)
721721
NO_NEW_INSERTION_POINT(GuardStmtBodyScope)
722722
NO_NEW_INSERTION_POINT(ParameterListScope)
@@ -1177,7 +1177,7 @@ void DefaultArgumentInitializerScope::
11771177
scopeCreator.addToScopeTree(initExpr, this);
11781178
}
11791179

1180-
void AttachedPropertyWrapperScope::
1180+
void CustomAttributeScope::
11811181
expandAScopeThatDoesNotCreateANewInsertionPoint(
11821182
ScopeCreator &scopeCreator) {
11831183
if (auto *args = attr->getArgs()) {

lib/AST/ASTScopeSourceRange.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ SourceRange ClosureParametersScope::getSourceRangeOfThisASTNode(
360360
return explicitClosureExpr->getSourceRange();
361361
}
362362

363-
SourceRange AttachedPropertyWrapperScope::getSourceRangeOfThisASTNode(
363+
SourceRange CustomAttributeScope::getSourceRangeOfThisASTNode(
364364
const bool omitAssertions) const {
365365
return attr->getRange();
366366
}

0 commit comments

Comments
 (0)