mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
AST: Accessors no longer appear as members of their parent DeclContext
Accessors logically belong to their storage and can be synthesized on the fly, so removing them from the members list eliminates one source of mutability (but doesn't eliminate it; there are also witnesses for derived conformances, and implicit constructors). Since a few ASTWalker implementations break in non-trivial ways when the traversal is changed to visit accessors as children of the storage rather than peers, I hacked up the ASTWalker to optionally preserve the old traversal order for now. This is ugly and needs to be cleaned up, but I want to avoid breaking _too_ much with this commit.
This commit is contained in:
@@ -2844,7 +2844,10 @@ class Serializer::DeclSerializer : public DeclVisitor<DeclSerializer> {
|
||||
unsigned getNumberOfRequiredVTableEntries(
|
||||
const AbstractStorageDecl *storage) const {
|
||||
unsigned count = 0;
|
||||
// FIXME: Implement once accessors are no longer part of their parent.
|
||||
for (auto *accessor : storage->getAllAccessors()) {
|
||||
if (accessor->needsNewVTableEntry())
|
||||
count++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
@@ -4762,33 +4765,27 @@ static void collectInterestingNestedDeclarations(
|
||||
|
||||
for (const Decl *member : members) {
|
||||
// If there is a corresponding Objective-C method, record it.
|
||||
auto recordObjCMethod = [&] {
|
||||
auto recordObjCMethod = [&](const AbstractFunctionDecl *func) {
|
||||
if (isLocal)
|
||||
return;
|
||||
|
||||
if (auto func = dyn_cast<AbstractFunctionDecl>(member)) {
|
||||
if (auto owningClass = func->getDeclContext()->getSelfClassDecl()) {
|
||||
if (func->isObjC()) {
|
||||
if (auto owningClass = func->getDeclContext()->getSelfClassDecl()) {
|
||||
Mangle::ASTMangler mangler;
|
||||
std::string ownerName = mangler.mangleNominalType(owningClass);
|
||||
assert(!ownerName.empty() && "Mangled type came back empty!");
|
||||
Mangle::ASTMangler mangler;
|
||||
std::string ownerName = mangler.mangleNominalType(owningClass);
|
||||
assert(!ownerName.empty() && "Mangled type came back empty!");
|
||||
|
||||
objcMethods[func->getObjCSelector()].push_back(
|
||||
std::make_tuple(ownerName,
|
||||
func->isObjCInstanceMethod(),
|
||||
S.addDeclRef(func)));
|
||||
}
|
||||
objcMethods[func->getObjCSelector()].push_back(
|
||||
std::make_tuple(ownerName,
|
||||
func->isObjCInstanceMethod(),
|
||||
S.addDeclRef(func)));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if (auto memberValue = dyn_cast<ValueDecl>(member)) {
|
||||
if (!memberValue->hasName()) {
|
||||
recordObjCMethod();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (memberValue->isOperator()) {
|
||||
if (memberValue->hasName() &&
|
||||
memberValue->isOperator()) {
|
||||
// Add operator methods.
|
||||
// Note that we don't have to add operators that are already in the
|
||||
// top-level list.
|
||||
@@ -4799,6 +4796,17 @@ static void collectInterestingNestedDeclarations(
|
||||
}
|
||||
}
|
||||
|
||||
// Record Objective-C methods.
|
||||
if (auto *func = dyn_cast<AbstractFunctionDecl>(member))
|
||||
recordObjCMethod(func);
|
||||
|
||||
// Handle accessors.
|
||||
if (auto storage = dyn_cast<AbstractStorageDecl>(member)) {
|
||||
for (auto *accessor : storage->getAllAccessors()) {
|
||||
recordObjCMethod(accessor);
|
||||
}
|
||||
}
|
||||
|
||||
if (auto nestedType = dyn_cast<TypeDecl>(member)) {
|
||||
if (nestedType->getEffectiveAccess() > swift::AccessLevel::FilePrivate) {
|
||||
if (!nominalParent) {
|
||||
@@ -4820,9 +4828,6 @@ static void collectInterestingNestedDeclarations(
|
||||
objcMethods, nestedTypeDecls,
|
||||
isLocal);
|
||||
}
|
||||
|
||||
// Record Objective-C methods.
|
||||
recordObjCMethod();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user