[NFC] AST-level support for static subscripts

* Moves the IsStatic flag from VarDecl to AbstractStorageDecl.
* Adds a StaticSubscriptKind to SubscriptDecl.
* Updates serialization for these changes.
* Updates SubscriptDecl constructor call sites for these changes.
This commit is contained in:
Brent Royal-Gordon
2019-03-16 16:13:45 -07:00
committed by Brent Royal-Gordon
parent 94f770672a
commit 972eda2316
7 changed files with 76 additions and 49 deletions

View File

@@ -2019,12 +2019,9 @@ bool ValueDecl::isInstanceMember() const {
return false;
case DeclKind::Subscript:
// Subscripts are always instance members.
return true;
case DeclKind::Var:
// Non-static variables are instance members.
return !cast<VarDecl>(this)->isStatic();
// Non-static variables and subscripts are instance members.
return !cast<AbstractStorageDecl>(this)->isStatic();
case DeclKind::Module:
// Modules are never instance members.
@@ -5098,12 +5095,16 @@ bool VarDecl::isAnonClosureParam() const {
return nameStr[0] == '$';
}
StaticSpellingKind VarDecl::getCorrectStaticSpelling() const {
StaticSpellingKind AbstractStorageDecl::getCorrectStaticSpelling() const {
if (!isStatic())
return StaticSpellingKind::None;
if (auto *PBD = getParentPatternBinding()) {
if (PBD->getStaticSpelling() != StaticSpellingKind::None)
return PBD->getStaticSpelling();
if (auto *VD = dyn_cast<VarDecl>(this)) {
if (auto *PBD = VD->getParentPatternBinding()) {
if (PBD->getStaticSpelling() != StaticSpellingKind::None)
return PBD->getStaticSpelling();
}
} else if (auto *SD = dyn_cast<SubscriptDecl>(this)) {
return SD->getStaticSpelling();
}
return getCorrectStaticSpellingForDecl(this);