@@ -39,7 +39,9 @@ struct swift::ide::api::SDKNodeInitInfo {
39
39
std::vector<TypeAttrKind> TypeAttrs;
40
40
41
41
SDKNodeInitInfo (SDKContext &Ctx) : Ctx(Ctx) {}
42
+ SDKNodeInitInfo (SDKContext &Ctx, Decl *D);
42
43
SDKNodeInitInfo (SDKContext &Ctx, ValueDecl *VD);
44
+ SDKNodeInitInfo (SDKContext &Ctx, OperatorDecl *D);
43
45
SDKNodeInitInfo (SDKContext &Ctx, Type Ty, bool IsImplicitlyUnwrappedOptional,
44
46
bool hasDefaultArgument);
45
47
SDKNode* createSDKNode (SDKNodeKind Kind);
@@ -55,6 +57,15 @@ SDKContext::SDKContext(CheckerOptions Opts): Diags(SourceMgr), Opts(Opts) {
55
57
#undef ADD
56
58
}
57
59
60
+ void SDKNodeRoot::registerDescendant (SDKNode *D) {
61
+ // Operator doesn't have usr
62
+ if (isa<SDKNodeDeclOperator>(D))
63
+ return ;
64
+ if (auto DD = dyn_cast<SDKNodeDecl>(D)) {
65
+ assert (!DD->getUsr ().empty ());
66
+ DescendantDeclTable[DD->getUsr ()].insert (DD);
67
+ }
68
+ }
58
69
59
70
SDKNode::SDKNode (SDKNodeInitInfo Info, SDKNodeKind Kind): Ctx(Info.Ctx),
60
71
Name(Info.Name), PrintedName(Info.PrintedName), TheKind(unsigned (Kind)) {}
@@ -86,12 +97,15 @@ SDKNodeTypeFunc::SDKNodeTypeFunc(SDKNodeInitInfo Info):
86
97
SDKNodeTypeAlias::SDKNodeTypeAlias (SDKNodeInitInfo Info):
87
98
SDKNodeType(Info, SDKNodeKind::TypeAlias) {}
88
99
89
- SDKNodeDeclType::SDKNodeDeclType (SDKNodeInitInfo Info):
100
+ SDKNodeDeclType::SDKNodeDeclType (SDKNodeInitInfo Info):
90
101
SDKNodeDecl(Info, SDKNodeKind::DeclType), SuperclassUsr(Info.SuperclassUsr),
91
102
SuperclassNames(Info.SuperclassNames),
92
103
ConformingProtocols(Info.ConformingProtocols),
93
104
EnumRawTypeName(Info.EnumRawTypeName) {}
94
105
106
+ SDKNodeDeclOperator::SDKNodeDeclOperator (SDKNodeInitInfo Info):
107
+ SDKNodeDecl(Info, SDKNodeKind::DeclOperator) {}
108
+
95
109
SDKNodeDeclTypeAlias::SDKNodeDeclTypeAlias (SDKNodeInitInfo Info):
96
110
SDKNodeDecl(Info, SDKNodeKind::DeclTypeAlias) {}
97
111
@@ -306,6 +320,7 @@ StringRef SDKNodeType::getTypeRoleDescription() const {
306
320
case SDKNodeKind::TypeFunc:
307
321
case SDKNodeKind::TypeAlias:
308
322
case SDKNodeKind::DeclType:
323
+ case SDKNodeKind::DeclOperator:
309
324
llvm_unreachable (" Type Parent is wrong" );
310
325
case SDKNodeKind::DeclFunction:
311
326
case SDKNodeKind::DeclConstructor:
@@ -719,6 +734,7 @@ bool static isSDKNodeEqual(SDKContext &Ctx, const SDKNode &L, const SDKNode &R)
719
734
}
720
735
LLVM_FALLTHROUGH;
721
736
}
737
+ case SDKNodeKind::DeclOperator:
722
738
case SDKNodeKind::DeclTypeAlias: {
723
739
auto Left = L.getAs <SDKNodeDecl>();
724
740
auto Right = R.getAs <SDKNodeDecl>();
@@ -820,14 +836,14 @@ static StringRef calculateUsr(SDKContext &Ctx, ValueDecl *VD) {
820
836
return StringRef ();
821
837
}
822
838
823
- static StringRef calculateLocation (SDKContext &SDKCtx, ValueDecl *VD ) {
839
+ static StringRef calculateLocation (SDKContext &SDKCtx, Decl *D ) {
824
840
if (SDKCtx.getOpts ().AvoidLocation )
825
841
return StringRef ();
826
- auto &Ctx = VD ->getASTContext ();
842
+ auto &Ctx = D ->getASTContext ();
827
843
auto &Importer = static_cast <ClangImporter &>(*Ctx.getClangModuleLoader ());
828
844
829
845
clang::SourceManager &SM = Importer.getClangPreprocessor ().getSourceManager ();
830
- if (ClangNode CN = VD ->getClangNode ()) {
846
+ if (ClangNode CN = D ->getClangNode ()) {
831
847
clang::SourceLocation Loc = CN.getLocation ();
832
848
Loc = SM.getFileLoc (Loc);
833
849
if (Loc.isValid ())
@@ -926,10 +942,10 @@ Requirement getCanonicalRequirement(Requirement &Req) {
926
942
}
927
943
}
928
944
929
- static StringRef printGenericSignature (SDKContext &Ctx, ValueDecl *VD ) {
945
+ static StringRef printGenericSignature (SDKContext &Ctx, Decl *D ) {
930
946
llvm::SmallString<32 > Result;
931
947
llvm::raw_svector_ostream OS (Result);
932
- if (auto *PD = dyn_cast<ProtocolDecl>(VD )) {
948
+ if (auto *PD = dyn_cast<ProtocolDecl>(D )) {
933
949
if (PD->getRequirementSignature ().empty ())
934
950
return StringRef ();
935
951
OS << " <" ;
@@ -949,7 +965,7 @@ static StringRef printGenericSignature(SDKContext &Ctx, ValueDecl *VD) {
949
965
return Ctx.buffer (OS.str ());
950
966
}
951
967
952
- if (auto *GC = VD ->getAsGenericContext ()) {
968
+ if (auto *GC = D ->getAsGenericContext ()) {
953
969
if (auto *Sig = GC->getGenericSignature ()) {
954
970
if (Ctx.checkingABI ())
955
971
Sig->getCanonicalSignature ()->print (OS);
@@ -1008,23 +1024,40 @@ SDKNodeInitInfo::SDKNodeInitInfo(SDKContext &Ctx, Type Ty,
1008
1024
}
1009
1025
}
1010
1026
1027
+ SDKNodeInitInfo::SDKNodeInitInfo (SDKContext &Ctx, Decl *D):
1028
+ Ctx(Ctx), DKind(D->getKind ()),
1029
+ Location(calculateLocation(Ctx, D)),
1030
+ ModuleName(D->getModuleContext ()->getName().str()),
1031
+ GenericSig(printGenericSignature(Ctx, D)),
1032
+ IsImplicit(D->isImplicit ()),
1033
+ IsDeprecated(D->getAttrs ().getDeprecated(D->getASTContext ())) {
1034
+ // Capture all attributes.
1035
+ auto AllAttrs = D->getAttrs ();
1036
+ std::transform (AllAttrs.begin (), AllAttrs.end (), std::back_inserter (DeclAttrs),
1037
+ [](DeclAttribute *attr) { return attr->getKind (); });
1038
+ }
1039
+
1040
+ SDKNodeInitInfo::SDKNodeInitInfo (SDKContext &Ctx, OperatorDecl *OD):
1041
+ SDKNodeInitInfo(Ctx, cast<Decl>(OD)) {
1042
+ Name = OD->getName ().str ();
1043
+ PrintedName = OD->getName ().str ();
1044
+ }
1045
+
1011
1046
SDKNodeInitInfo::SDKNodeInitInfo (SDKContext &Ctx, ValueDecl *VD)
1012
- : Ctx(Ctx), DKind(VD->getKind ()),
1013
- Name(VD->hasName () ? getEscapedName(VD->getBaseName ()) : Ctx.buffer(" _" )),
1014
- PrintedName(getPrintedName(Ctx, VD)),
1015
- Usr(calculateUsr(Ctx, VD)), Location(calculateLocation(Ctx, VD)),
1016
- ModuleName(VD->getModuleContext ()->getName().str()),
1017
- GenericSig(printGenericSignature(Ctx, VD)),
1018
- IsImplicit(VD->isImplicit ()),
1019
- IsThrowing(isFuncThrowing(VD)), IsMutating(isFuncMutating(VD)),
1020
- IsStatic(VD->isStatic ()),
1021
- IsDeprecated(VD->getAttrs ().getDeprecated(VD->getASTContext ())),
1022
- IsOverriding(VD->getOverriddenDecl ()),
1023
- IsProtocolReq(isa<ProtocolDecl>(VD->getDeclContext ()) && VD->isProtocolRequirement()),
1024
- IsOpen(VD->getFormalAccess () == AccessLevel::Open),
1025
- IsInternal(VD->getFormalAccess () < AccessLevel::Public),
1026
- SelfIndex(getSelfIndex(VD)), FixedBinaryOrder(getFixedBinaryOrder(VD)),
1027
- ReferenceOwnership(getReferenceOwnership(VD)) {
1047
+ : SDKNodeInitInfo(Ctx, cast<Decl>(VD)) {
1048
+ Name = VD->hasName () ? getEscapedName (VD->getBaseName ()) : Ctx.buffer (" _" );
1049
+ PrintedName = getPrintedName (Ctx, VD);
1050
+ Usr = calculateUsr (Ctx, VD);
1051
+ IsThrowing = isFuncThrowing (VD);
1052
+ IsMutating = isFuncMutating (VD);
1053
+ IsStatic = VD->isStatic ();
1054
+ IsOverriding = VD->getOverriddenDecl ();
1055
+ IsProtocolReq = isa<ProtocolDecl>(VD->getDeclContext ()) && VD->isProtocolRequirement ();
1056
+ IsOpen = VD->getFormalAccess () == AccessLevel::Open;
1057
+ IsInternal = VD->getFormalAccess () < AccessLevel::Public;
1058
+ SelfIndex = getSelfIndex (VD);
1059
+ FixedBinaryOrder = getFixedBinaryOrder (VD);
1060
+ ReferenceOwnership = getReferenceOwnership (VD);
1028
1061
1029
1062
// Calculate usr for its super class.
1030
1063
if (auto *CD = dyn_cast_or_null<ClassDecl>(VD)) {
@@ -1036,11 +1069,6 @@ SDKNodeInitInfo::SDKNodeInitInfo(SDKContext &Ctx, ValueDecl *VD)
1036
1069
}
1037
1070
}
1038
1071
1039
- // Capture all attributes.
1040
- auto AllAttrs = VD->getAttrs ();
1041
- std::transform (AllAttrs.begin (), AllAttrs.end (), std::back_inserter (DeclAttrs),
1042
- [](DeclAttribute *attr) { return attr->getKind (); });
1043
-
1044
1072
// Get all protocol names this type decl conforms to.
1045
1073
if (auto *NTD = dyn_cast<NominalTypeDecl>(VD)) {
1046
1074
for (auto *P: NTD->getAllProtocols ()) {
@@ -1178,8 +1206,6 @@ SwiftDeclCollector::shouldIgnore(Decl *D, const Decl* Parent) {
1178
1206
return true ;
1179
1207
if (isa<ConstructorDecl>(D))
1180
1208
return false ;
1181
- if (isa<OperatorDecl>(D))
1182
- return true ;
1183
1209
if (auto VD = dyn_cast<ValueDecl>(D)) {
1184
1210
if (VD->getBaseName ().empty ())
1185
1211
return true ;
@@ -1340,6 +1366,8 @@ void SwiftDeclCollector::lookupVisibleDecls(ArrayRef<ModuleDecl *> Modules) {
1340
1366
KnownDecls.insert (D);
1341
1367
if (auto VD = dyn_cast<ValueDecl>(D))
1342
1368
foundDecl (VD, DeclVisibilityKind::DynamicLookup);
1369
+ else
1370
+ processDecl (D);
1343
1371
}
1344
1372
}
1345
1373
@@ -1353,7 +1381,7 @@ void SwiftDeclCollector::lookupVisibleDecls(ArrayRef<ModuleDecl *> Modules) {
1353
1381
});
1354
1382
1355
1383
for (auto *VD : ClangMacros)
1356
- processDecl (VD);
1384
+ processValueDecl (VD);
1357
1385
1358
1386
// Collect extensions to types from other modules and synthesize type nodes
1359
1387
// for them.
@@ -1370,7 +1398,18 @@ void SwiftDeclCollector::lookupVisibleDecls(ArrayRef<ModuleDecl *> Modules) {
1370
1398
}
1371
1399
}
1372
1400
1373
- void SwiftDeclCollector::processDecl (ValueDecl *VD) {
1401
+ SDKNode *SwiftDeclCollector::constructOperatorDeclNode (OperatorDecl *OD) {
1402
+ return SDKNodeInitInfo (Ctx, OD).createSDKNode (SDKNodeKind::DeclOperator);
1403
+ }
1404
+
1405
+ void SwiftDeclCollector::processDecl (Decl *D) {
1406
+ assert (!isa<ValueDecl>(D));
1407
+ if (auto *OD = dyn_cast<OperatorDecl>(D)) {
1408
+ RootNode->addChild (constructOperatorDeclNode (OD));
1409
+ }
1410
+ }
1411
+
1412
+ void SwiftDeclCollector::processValueDecl (ValueDecl *VD) {
1374
1413
if (auto FD = dyn_cast<FuncDecl>(VD)) {
1375
1414
RootNode->addChild (constructFunctionNode (FD, SDKNodeKind::DeclFunction));
1376
1415
} else if (auto NTD = dyn_cast<NominalTypeDecl>(VD)) {
@@ -1391,7 +1430,7 @@ void SwiftDeclCollector::foundDecl(ValueDecl *VD, DeclVisibilityKind Reason) {
1391
1430
return ;
1392
1431
}
1393
1432
1394
- processDecl (VD);
1433
+ processValueDecl (VD);
1395
1434
}
1396
1435
1397
1436
void SDKNode::output (json::Output &out, KeyKind Key, bool Value) {
0 commit comments