mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
swift-module-digester: include SubscriptDecl in the Json dump.
We model SubscriptDecl as an abstract function decl with a flag indicating whether setter is defined.
This commit is contained in:
@@ -58,6 +58,7 @@ struct swift::ide::api::SDKNodeInitInfo {
|
||||
StringRef EnumRawTypeName;
|
||||
TypeInitInfo TypeInfo;
|
||||
StringRef GenericSig;
|
||||
bool HasSetter = false;
|
||||
|
||||
SDKNodeInitInfo(SDKContext &Ctx) : Ctx(Ctx) {}
|
||||
SDKNodeInitInfo(SDKContext &Ctx, ValueDecl *VD);
|
||||
@@ -133,6 +134,10 @@ SDKNodeDeclSetter::SDKNodeDeclSetter(SDKNodeInitInfo Info):
|
||||
SDKNodeDeclAssociatedType::SDKNodeDeclAssociatedType(SDKNodeInitInfo Info):
|
||||
SDKNodeDecl(Info, SDKNodeKind::DeclAssociatedType) {};
|
||||
|
||||
SDKNodeDeclSubscript::SDKNodeDeclSubscript(SDKNodeInitInfo Info):
|
||||
SDKNodeDeclAbstractFunc(Info, SDKNodeKind::DeclSubscript),
|
||||
HasSetter(Info.HasSetter) {}
|
||||
|
||||
StringRef SDKNodeDecl::getHeaderName() const {
|
||||
if (Location.empty())
|
||||
return StringRef();
|
||||
@@ -352,6 +357,7 @@ bool SDKNodeDecl::classof(const SDKNode *N) {
|
||||
case SDKNodeKind::DeclType:
|
||||
case SDKNodeKind::DeclVar:
|
||||
case SDKNodeKind::DeclAssociatedType:
|
||||
case SDKNodeKind::DeclSubscript:
|
||||
return true;
|
||||
case SDKNodeKind::Root:
|
||||
case SDKNodeKind::TypeNominal:
|
||||
@@ -439,6 +445,7 @@ bool SDKNodeDeclAbstractFunc::classof(const SDKNode *N) {
|
||||
case SDKNodeKind::DeclSetter:
|
||||
case SDKNodeKind::DeclGetter:
|
||||
case SDKNodeKind::DeclConstructor:
|
||||
case SDKNodeKind::DeclSubscript:
|
||||
return true;
|
||||
|
||||
default:
|
||||
@@ -571,6 +578,9 @@ SDKNode* SDKNode::constructSDKNode(SDKContext &Ctx,
|
||||
case KeyKind::KK_implicit:
|
||||
Info.IsImplicit = true;
|
||||
break;
|
||||
case KeyKind::KK_hasSetter:
|
||||
Info.HasSetter = true;
|
||||
break;
|
||||
case KeyKind::KK_ownership:
|
||||
Info.ReferenceOwnership =
|
||||
swift::ReferenceOwnership(getAsInt(Pair.getValue()));
|
||||
@@ -736,6 +746,7 @@ bool SDKNode::operator==(const SDKNode &Other) const {
|
||||
LLVM_FALLTHROUGH;
|
||||
}
|
||||
case SDKNodeKind::DeclAssociatedType:
|
||||
case SDKNodeKind::DeclSubscript:
|
||||
case SDKNodeKind::DeclTypeAlias: {
|
||||
auto Left = this->getAs<SDKNodeDecl>();
|
||||
auto Right = (&Other)->getAs<SDKNodeDecl>();
|
||||
@@ -868,9 +879,8 @@ static StringRef getEscapedName(DeclBaseName name) {
|
||||
|
||||
static StringRef getPrintedName(SDKContext &Ctx, ValueDecl *VD) {
|
||||
llvm::SmallString<32> Result;
|
||||
if (auto FD = dyn_cast<AbstractFunctionDecl>(VD)) {
|
||||
auto DM = FD->getFullName();
|
||||
|
||||
DeclName DM = VD->getFullName();
|
||||
if (isa<AbstractFunctionDecl>(VD) || isa<SubscriptDecl>(VD)) {
|
||||
if (DM.getBaseName().empty()) {
|
||||
Result.append("_");
|
||||
} else {
|
||||
@@ -885,7 +895,6 @@ static StringRef getPrintedName(SDKContext &Ctx, ValueDecl *VD) {
|
||||
Result.append(")");
|
||||
return Ctx.buffer(Result.str());
|
||||
}
|
||||
auto DM = VD->getFullName();
|
||||
Result.append(getEscapedName(DM.getBaseName()));
|
||||
return Ctx.buffer(Result.str());
|
||||
}
|
||||
@@ -1052,6 +1061,11 @@ SDKNodeInitInfo::SDKNodeInitInfo(SDKContext &Ctx, ValueDecl *VD)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Record whether a subscript has getter/setter.
|
||||
if (auto *SD = dyn_cast<SubscriptDecl>(VD)) {
|
||||
HasSetter = SD->getSetter();
|
||||
}
|
||||
}
|
||||
|
||||
SDKNode *SDKNodeInitInfo::createSDKNode(SDKNodeKind Kind) {
|
||||
@@ -1265,6 +1279,14 @@ static SDKNode *constructAssociatedTypeNode(SDKContext &Ctx,
|
||||
return Asso;
|
||||
}
|
||||
|
||||
static SDKNode *constructSubscriptDeclNode(SDKContext &Ctx, SubscriptDecl *SD) {
|
||||
auto Subs = SDKNodeInitInfo(Ctx, SD).createSDKNode(SDKNodeKind::DeclSubscript);
|
||||
Subs->addChild(constructTypeNode(Ctx, SD->getElementInterfaceType()));
|
||||
for (auto *Node: createParameterNodes(Ctx, SD->getIndices()))
|
||||
Subs->addChild(Node);
|
||||
return Subs;
|
||||
}
|
||||
|
||||
static void addMembersToRoot(SDKContext &Ctx, SDKNode *Root,
|
||||
IterableDeclContext *Context,
|
||||
std::set<ExtensionDecl*> &HandledExts) {
|
||||
@@ -1285,6 +1307,14 @@ static void addMembersToRoot(SDKContext &Ctx, SDKNode *Root,
|
||||
Root->addChild(constructTypeDeclNode(Ctx, NTD, HandledExts));
|
||||
} else if (auto ATD = dyn_cast<AssociatedTypeDecl>(Member)) {
|
||||
Root->addChild(constructAssociatedTypeNode(Ctx, ATD));
|
||||
} else if (auto SD = dyn_cast<SubscriptDecl>(Member)) {
|
||||
Root->addChild(constructSubscriptDeclNode(Ctx, SD));
|
||||
} else if (isa<PatternBindingDecl>(Member)) {
|
||||
// All containing variables should have been handled.
|
||||
} else if (isa<DestructorDecl>(Member)) {
|
||||
// deinit has no impact.
|
||||
} else {
|
||||
llvm_unreachable("unhandled member decl kind.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1444,6 +1474,12 @@ struct ObjectTraits<SDKNode *> {
|
||||
out.mapRequired(getKeyContent(Ctx, KeyKind::KK_selfIndex).data(),
|
||||
Index);
|
||||
}
|
||||
if (auto S = dyn_cast<SDKNodeDeclSubscript>(value)) {
|
||||
if (bool hasSetter = S->hasSetter()) {
|
||||
out.mapRequired(getKeyContent(Ctx, KeyKind::KK_hasSetter).data(),
|
||||
hasSetter);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (auto *TD = dyn_cast<SDKNodeDeclType>(value)) {
|
||||
auto Super = TD->getSuperClassUsr();
|
||||
|
||||
Reference in New Issue
Block a user