Skip to content

Commit 2909c22

Browse files
committed
swift-module-digester: keep track of super class names in the module dump
1 parent 721182d commit 2909c22

File tree

6 files changed

+22
-1
lines changed

6 files changed

+22
-1
lines changed

include/swift/IDE/DigesterEnums.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ KEY(declAttributes)
109109
KEY(declKind)
110110
KEY(ownership)
111111
KEY(superclassUsr)
112+
KEY(superclassName)
112113
KEY(hasDefaultArg)
113114
KEY(conformingProtocols)
114115
KEY(enumRawTypeName)

test/api-digester/Outputs/cake-abi.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@
198198
"location": "",
199199
"moduleName": "cake",
200200
"superclassUsr": "s:4cake2C0C",
201+
"superclassName": "C0",
201202
"children": [
202203
{
203204
"kind": "Function",

test/api-digester/Outputs/cake.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@
205205
"location": "",
206206
"moduleName": "cake",
207207
"superclassUsr": "s:4cake2C0C",
208+
"superclassName": "C0",
208209
"children": [
209210
{
210211
"kind": "Function",

test/api-digester/Outputs/clang-module-dump.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"location": "",
1313
"moduleName": "Foo",
1414
"superclassUsr": "c:objc(cs)NSObject",
15+
"superclassName": "NSObject",
1516
"conformingProtocols": [
1617
"ObjcProt",
1718
"NSObjectProtocol"

tools/swift-api-digester/ModuleAnalyzerNodes.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ struct swift::ide::api::SDKNodeInitInfo {
4848
std::vector<TypeAttrKind> TypeAttrs;
4949
std::vector<StringRef> ConformingProtocols;
5050
StringRef SuperclassUsr;
51+
StringRef SuperclassName;
5152
StringRef EnumRawTypeName;
5253
bool hasDefaultArgument = false;
5354
StringRef GenericSig;
@@ -100,6 +101,7 @@ SDKNodeTypeAlias::SDKNodeTypeAlias(SDKNodeInitInfo Info):
100101

101102
SDKNodeDeclType::SDKNodeDeclType(SDKNodeInitInfo Info):
102103
SDKNodeDecl(Info, SDKNodeKind::DeclType), SuperclassUsr(Info.SuperclassUsr),
104+
SuperclassName(Info.SuperclassName),
103105
ConformingProtocols(Info.ConformingProtocols),
104106
EnumRawTypeName(Info.EnumRawTypeName) {}
105107

@@ -568,6 +570,9 @@ SDKNode* SDKNode::constructSDKNode(SDKContext &Ctx,
568570
case KeyKind::KK_superclassUsr:
569571
Info.SuperclassUsr = GetScalarString(Pair.getValue());
570572
break;
573+
case KeyKind::KK_superclassName:
574+
Info.SuperclassName = GetScalarString(Pair.getValue());
575+
break;
571576
case KeyKind::KK_genericSig:
572577
Info.GenericSig = GetScalarString(Pair.getValue());
573578
break;
@@ -756,6 +761,9 @@ bool SDKNode::operator==(const SDKNode &Other) const {
756761
if (!hasSameContents(Left->getAllProtocols(), Right->getAllProtocols())) {
757762
return false;
758763
}
764+
if (Left->getSuperClassName() != Right->getSuperClassName()) {
765+
return false;
766+
}
759767
}
760768
LLVM_FALLTHROUGH;
761769
}
@@ -1059,8 +1067,10 @@ SDKNodeInitInfo::SDKNodeInitInfo(SDKContext &Ctx, ValueDecl *VD)
10591067

10601068
// Calculate usr for its super class.
10611069
if (auto *CD = dyn_cast_or_null<ClassDecl>(VD)) {
1062-
if (auto *Super = CD->getSuperclassDecl())
1070+
if (auto *Super = CD->getSuperclassDecl()) {
10631071
SuperclassUsr = calculateUsr(Ctx, Super);
1072+
SuperclassName = Super->getName().str();
1073+
}
10641074
}
10651075

10661076
// Capture all attributes.
@@ -1508,6 +1518,11 @@ struct ObjectTraits<SDKNode *> {
15081518
out.mapRequired(getKeyContent(Ctx, KeyKind::KK_superclassUsr).data(),
15091519
Super);
15101520
}
1521+
auto SuperName = TD->getSuperClassName();
1522+
if (!SuperName.empty()) {
1523+
out.mapRequired(getKeyContent(Ctx, KeyKind::KK_superclassName).data(),
1524+
SuperName);
1525+
}
15111526
auto Pros = TD->getAllProtocols();
15121527
if (!Pros.empty()) {
15131528
out.mapRequired(getKeyContent(Ctx,

tools/swift-api-digester/ModuleAnalyzerNodes.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,12 +407,14 @@ class SDKNodeVectorViewer::ViewerIterator :
407407

408408
class SDKNodeDeclType : public SDKNodeDecl {
409409
StringRef SuperclassUsr;
410+
StringRef SuperclassName;
410411
std::vector<StringRef> ConformingProtocols;
411412
StringRef EnumRawTypeName;
412413
public:
413414
SDKNodeDeclType(SDKNodeInitInfo Info);
414415
static bool classof(const SDKNode *N);
415416
StringRef getSuperClassUsr() const { return SuperclassUsr; }
417+
StringRef getSuperClassName() const { return SuperclassName; }
416418
ArrayRef<StringRef> getAllProtocols() const { return ConformingProtocols; }
417419

418420
#define NOMINAL_TYPE_DECL(ID, PARENT) \

0 commit comments

Comments
 (0)