@@ -15,14 +15,6 @@ enum class KeyKind {
15
15
#include " swift/IDE/DigesterEnums.def"
16
16
};
17
17
18
- // / The additional information we need to create a type node.
19
- struct TypeInitInfo {
20
- bool IsImplicitlyUnwrappedOptional = false ;
21
- // / When this type node represents a function parameter, this boolean value
22
- // / indicates whether the parameter has default argument.
23
- bool hasDefaultArgument = false ;
24
- };
25
-
26
18
static StringRef getAttrName (DeclAttrKind Kind) {
27
19
switch (Kind) {
28
20
#define DECL_ATTR (NAME, CLASS, ...) \
@@ -57,13 +49,14 @@ struct swift::ide::api::SDKNodeInitInfo {
57
49
std::vector<StringRef> ConformingProtocols;
58
50
StringRef SuperclassUsr;
59
51
StringRef EnumRawTypeName;
60
- TypeInitInfo TypeInfo ;
52
+ bool hasDefaultArgument = false ;
61
53
StringRef GenericSig;
62
54
bool HasSetter = false ;
63
55
64
56
SDKNodeInitInfo (SDKContext &Ctx) : Ctx(Ctx) {}
65
57
SDKNodeInitInfo (SDKContext &Ctx, ValueDecl *VD);
66
- SDKNodeInitInfo (SDKContext &Ctx, Type Ty, TypeInitInfo Info = TypeInitInfo());
58
+ SDKNodeInitInfo (SDKContext &Ctx, Type Ty, bool IsImplicitlyUnwrappedOptional,
59
+ bool hasDefaultArgument);
67
60
SDKNode* createSDKNode (SDKNodeKind Kind);
68
61
};
69
62
@@ -94,7 +87,7 @@ SDKNodeDecl::SDKNodeDecl(SDKNodeInitInfo Info, SDKNodeKind Kind)
94
87
95
88
SDKNodeType::SDKNodeType (SDKNodeInitInfo Info, SDKNodeKind Kind):
96
89
SDKNode(Info, Kind), TypeAttributes(Info.TypeAttrs),
97
- HasDefaultArg(Info.TypeInfo. hasDefaultArgument) {}
90
+ HasDefaultArg(Info.hasDefaultArgument) {}
98
91
99
92
SDKNodeTypeNominal::SDKNodeTypeNominal (SDKNodeInitInfo Info):
100
93
SDKNodeType(Info, SDKNodeKind::TypeNominal), USR(Info.USR) {}
@@ -585,7 +578,7 @@ SDKNode* SDKNode::constructSDKNode(SDKContext &Ctx,
585
578
Info.IsMutating = true ;
586
579
break ;
587
580
case KeyKind::KK_hasDefaultArg:
588
- Info.TypeInfo . hasDefaultArgument = true ;
581
+ Info.hasDefaultArgument = true ;
589
582
break ;
590
583
case KeyKind::KK_static:
591
584
Info.IsStatic = true ;
@@ -1036,10 +1029,11 @@ static Optional<unsigned> getFixedBinaryOrder(ValueDecl *VD) {
1036
1029
}
1037
1030
1038
1031
SDKNodeInitInfo::SDKNodeInitInfo (SDKContext &Ctx, Type Ty,
1039
- TypeInitInfo TypeInfo) :
1040
- Ctx(Ctx), Name(getTypeName(Ctx, Ty, TypeInfo.IsImplicitlyUnwrappedOptional)),
1041
- PrintedName(getPrintedName(Ctx, Ty, TypeInfo.IsImplicitlyUnwrappedOptional)),
1042
- TypeInfo(TypeInfo) {
1032
+ bool IsImplicitlyUnwrappedOptional = false ,
1033
+ bool hasDefaultArgument = false ) :
1034
+ Ctx(Ctx), Name(getTypeName(Ctx, Ty, IsImplicitlyUnwrappedOptional)),
1035
+ PrintedName(getPrintedName(Ctx, Ty, IsImplicitlyUnwrappedOptional)),
1036
+ hasDefaultArgument(hasDefaultArgument) {
1043
1037
if (isFunctionTypeNoEscape (Ty))
1044
1038
TypeAttrs.push_back (TypeAttrKind::TAK_noescape);
1045
1039
// If this is a nominal type, get its Usr.
@@ -1109,64 +1103,62 @@ case SDKNodeKind::X: \
1109
1103
1110
1104
// Recursively construct a node that represents a type, for instance,
1111
1105
// representing the return value type of a function decl.
1112
- static SDKNode *constructTypeNode (SDKContext &Ctx, Type T,
1113
- TypeInitInfo InitInfo = TypeInitInfo()) {
1106
+ SDKNode *swift::ide::api::
1107
+ SwiftDeclCollector::constructTypeNode (Type T,
1108
+ bool IsImplicitlyUnwrappedOptional,
1109
+ bool hasDefaultArgument) {
1114
1110
if (Ctx.checkingABI ()) {
1115
1111
T = T->getCanonicalType ();
1116
1112
}
1117
- SDKNode* Root = SDKNodeInitInfo (Ctx, T, InitInfo)
1118
- .createSDKNode (SDKNodeKind::TypeNominal);
1113
+ SDKNode* Root = SDKNodeInitInfo (Ctx, T, IsImplicitlyUnwrappedOptional,
1114
+ hasDefaultArgument) .createSDKNode (SDKNodeKind::TypeNominal);
1119
1115
1120
1116
if (auto NAT = dyn_cast<NameAliasType>(T.getPointer ())) {
1121
1117
SDKNode* Root = SDKNodeInitInfo (Ctx, T).createSDKNode (SDKNodeKind::TypeAlias);
1122
- Root->addChild (constructTypeNode (Ctx, NAT->getCanonicalType ()));
1118
+ Root->addChild (constructTypeNode (NAT->getCanonicalType ()));
1123
1119
return Root;
1124
1120
}
1125
1121
1126
1122
if (auto Fun = T->getAs <AnyFunctionType>()) {
1127
1123
SDKNode* Root = SDKNodeInitInfo (Ctx, T).createSDKNode (SDKNodeKind::TypeFunc);
1128
1124
1129
1125
// Still, return type first
1130
- Root->addChild (constructTypeNode (Ctx, Fun->getResult ()));
1131
- Root->addChild (constructTypeNode (Ctx, Fun->getInput ()));
1126
+ Root->addChild (constructTypeNode (Fun->getResult ()));
1127
+ Root->addChild (constructTypeNode (Fun->getInput ()));
1132
1128
return Root;
1133
1129
}
1134
1130
1135
1131
// Keep paren type as a stand-alone level.
1136
1132
if (auto *PT = dyn_cast<ParenType>(T.getPointer ())) {
1137
- Root->addChild (constructTypeNode (Ctx, PT->getSinglyDesugaredType ()));
1133
+ Root->addChild (constructTypeNode (PT->getSinglyDesugaredType ()));
1138
1134
return Root;
1139
1135
}
1140
1136
1141
1137
// Handle the case where Type has sub-types.
1142
1138
if (auto BGT = T->getAs <BoundGenericType>()) {
1143
1139
for (auto Arg : BGT->getGenericArgs ()) {
1144
- Root->addChild (constructTypeNode (Ctx, Arg));
1140
+ Root->addChild (constructTypeNode (Arg));
1145
1141
}
1146
1142
} else if (auto Tup = T->getAs <TupleType>()) {
1147
1143
for (auto Elt : Tup->getElementTypes ())
1148
- Root->addChild (constructTypeNode (Ctx, Elt));
1144
+ Root->addChild (constructTypeNode (Elt));
1149
1145
} else if (auto MTT = T->getAs <AnyMetatypeType>()) {
1150
- Root->addChild (constructTypeNode (Ctx, MTT->getInstanceType ()));
1146
+ Root->addChild (constructTypeNode (MTT->getInstanceType ()));
1151
1147
} else if (auto ATT = T->getAs <ArchetypeType>()) {
1152
1148
for (auto Pro : ATT->getConformsTo ()) {
1153
- Root->addChild (constructTypeNode (Ctx, Pro->getDeclaredType ()));
1149
+ Root->addChild (constructTypeNode (Pro->getDeclaredType ()));
1154
1150
}
1155
1151
}
1156
1152
return Root;
1157
1153
}
1158
1154
1159
- static std::vector<SDKNode*>
1160
- createParameterNodes (SDKContext &Ctx, ParameterList *PL) {
1155
+ std::vector<SDKNode*> swift::ide::api::
1156
+ SwiftDeclCollector:: createParameterNodes (ParameterList *PL) {
1161
1157
std::vector<SDKNode*> Result;
1162
1158
for (auto param: *PL) {
1163
- TypeInitInfo TypeInfo;
1164
- TypeInfo.IsImplicitlyUnwrappedOptional = param->getAttrs ().
1165
- hasAttribute<ImplicitlyUnwrappedOptionalAttr>();
1166
- TypeInfo.hasDefaultArgument = param->getDefaultArgumentKind () !=
1167
- DefaultArgumentKind::None;
1168
- Result.push_back (constructTypeNode (Ctx, param->getInterfaceType (),
1169
- TypeInfo));
1159
+ Result.push_back (constructTypeNode (param->getInterfaceType (),
1160
+ param->getAttrs ().hasAttribute <ImplicitlyUnwrappedOptionalAttr>(),
1161
+ param->getDefaultArgumentKind () != DefaultArgumentKind::None));
1170
1162
}
1171
1163
return Result;
1172
1164
}
@@ -1175,27 +1167,28 @@ createParameterNodes(SDKContext &Ctx, ParameterList *PL) {
1175
1167
// is guaranteed to be the return value type of this function.
1176
1168
// We sometimes skip the first parameter because it can be metatype of dynamic
1177
1169
// this if the function is a member function.
1178
- static SDKNode *constructFunctionNode (SDKContext &Ctx, FuncDecl* FD,
1179
- SDKNodeKind Kind) {
1170
+ SDKNode *swift::ide::api::
1171
+ SwiftDeclCollector::constructFunctionNode (FuncDecl* FD,
1172
+ SDKNodeKind Kind) {
1180
1173
auto Func = SDKNodeInitInfo (Ctx, FD).createSDKNode (Kind);
1181
- TypeInitInfo TypeInfo;
1182
- TypeInfo.IsImplicitlyUnwrappedOptional = FD->getAttrs ().
1183
- hasAttribute<ImplicitlyUnwrappedOptionalAttr>();
1184
- Func->addChild (constructTypeNode (Ctx, FD->getResultInterfaceType (), TypeInfo));
1185
- for (auto *Node : createParameterNodes (Ctx, FD->getParameters ()))
1174
+ Func->addChild (constructTypeNode (FD->getResultInterfaceType (),
1175
+ FD->getAttrs ().hasAttribute <ImplicitlyUnwrappedOptionalAttr>()));
1176
+ for (auto *Node : createParameterNodes (FD->getParameters ()))
1186
1177
Func->addChild (Node);
1187
1178
return Func;
1188
1179
}
1189
1180
1190
- static SDKNode* constructInitNode (SDKContext &Ctx, ConstructorDecl *CD) {
1181
+ SDKNode* swift::ide::api::
1182
+ SwiftDeclCollector::constructInitNode (ConstructorDecl *CD) {
1191
1183
auto Func = SDKNodeInitInfo (Ctx, CD).createSDKNode (SDKNodeKind::DeclConstructor);
1192
- Func->addChild (constructTypeNode (Ctx, CD->getResultInterfaceType ()));
1193
- for (auto *Node : createParameterNodes (Ctx, CD->getParameters ()))
1184
+ Func->addChild (constructTypeNode (CD->getResultInterfaceType ()));
1185
+ for (auto *Node : createParameterNodes (CD->getParameters ()))
1194
1186
Func->addChild (Node);
1195
1187
return Func;
1196
1188
}
1197
1189
1198
- static bool shouldIgnore (Decl *D, const Decl* Parent, SDKContext &Ctx) {
1190
+ bool swift::ide::api::
1191
+ SwiftDeclCollector::shouldIgnore (Decl *D, const Decl* Parent) {
1199
1192
if (D->isPrivateStdlibDecl (false ))
1200
1193
return true ;
1201
1194
if (AvailableAttr::isUnavailable (D))
@@ -1242,17 +1235,13 @@ static bool shouldIgnore(Decl *D, const Decl* Parent, SDKContext &Ctx) {
1242
1235
return false ;
1243
1236
}
1244
1237
1245
- static void addMembersToRoot (SDKContext &Ctx, SDKNode *Root,
1246
- IterableDeclContext *Context,
1247
- std::set<ExtensionDecl*> &HandledExts);
1248
-
1249
- static SDKNode *constructTypeDeclNode (SDKContext &Ctx, NominalTypeDecl *NTD,
1250
- std::set<ExtensionDecl*> &HandledExts) {
1238
+ SDKNode *swift::ide::api::
1239
+ SwiftDeclCollector::constructTypeDeclNode (NominalTypeDecl *NTD) {
1251
1240
auto TypeNode = SDKNodeInitInfo (Ctx, NTD).createSDKNode (SDKNodeKind::DeclType);
1252
- addMembersToRoot (Ctx, TypeNode, NTD, HandledExts );
1241
+ addMembersToRoot (TypeNode, NTD);
1253
1242
for (auto Ext : NTD->getExtensions ()) {
1254
- HandledExts .insert (Ext);
1255
- addMembersToRoot (Ctx, TypeNode, Ext, HandledExts );
1243
+ HandledExtensions .insert (Ext);
1244
+ addMembersToRoot (TypeNode, Ext);
1256
1245
}
1257
1246
return TypeNode;
1258
1247
}
@@ -1262,83 +1251,82 @@ static SDKNode *constructTypeDeclNode(SDKContext &Ctx, NominalTypeDecl *NTD,
1262
1251
// / extended types. If the extended types are from a different module, we have to
1263
1252
// / synthesize this type node to include those extension members, since these
1264
1253
// / extension members are legit members of the module.
1265
- static SDKNode *constructExternalExtensionNode (SDKContext &Ctx, SDKNode *Root,
1266
- NominalTypeDecl *NTD,
1267
- ArrayRef<ExtensionDecl*> AllExts,
1268
- std::set<ExtensionDecl*> &HandledExts) {
1254
+ SDKNode *swift::ide::api::
1255
+ SwiftDeclCollector::constructExternalExtensionNode (NominalTypeDecl *NTD,
1256
+ ArrayRef<ExtensionDecl*> AllExts) {
1269
1257
auto *TypeNode = SDKNodeInitInfo (Ctx, NTD).createSDKNode (SDKNodeKind::DeclType);
1270
1258
1271
1259
// The members of the extensions are the only members of this synthesized type.
1272
1260
for (auto *Ext: AllExts) {
1273
- HandledExts .insert (Ext);
1274
- addMembersToRoot (Ctx, TypeNode, Ext, HandledExts );
1261
+ HandledExtensions .insert (Ext);
1262
+ addMembersToRoot (TypeNode, Ext);
1275
1263
}
1276
1264
return TypeNode;
1277
1265
}
1278
1266
1279
- static SDKNode *constructVarNode (SDKContext &Ctx, ValueDecl *VD) {
1267
+ SDKNode *swift::ide::api::
1268
+ SwiftDeclCollector::constructVarNode (ValueDecl *VD) {
1280
1269
auto Var = SDKNodeInitInfo (Ctx, VD).createSDKNode (SDKNodeKind::DeclVar);
1281
- TypeInitInfo TypeInfo;
1282
- TypeInfo.IsImplicitlyUnwrappedOptional = VD->getAttrs ().
1283
- hasAttribute<ImplicitlyUnwrappedOptionalAttr>();
1284
- Var->addChild (constructTypeNode (Ctx, VD->getInterfaceType (), TypeInfo));
1270
+ Var->addChild (constructTypeNode (VD->getInterfaceType (),
1271
+ VD->getAttrs ().hasAttribute <ImplicitlyUnwrappedOptionalAttr>()));
1285
1272
if (auto VAD = dyn_cast<AbstractStorageDecl>(VD)) {
1286
1273
if (auto Getter = VAD->getGetter ())
1287
- Var->addChild (constructFunctionNode (Ctx, Getter, SDKNodeKind::DeclGetter));
1274
+ Var->addChild (constructFunctionNode (Getter, SDKNodeKind::DeclGetter));
1288
1275
if (auto Setter = VAD->getSetter ()) {
1289
1276
if (Setter->getFormalAccess () > AccessLevel::Internal)
1290
- Var->addChild (constructFunctionNode (Ctx, Setter, SDKNodeKind::DeclSetter));
1277
+ Var->addChild (constructFunctionNode (Setter, SDKNodeKind::DeclSetter));
1291
1278
}
1292
1279
}
1293
1280
return Var;
1294
1281
}
1295
1282
1296
- static SDKNode *constructTypeAliasNode (SDKContext &Ctx,TypeAliasDecl *TAD) {
1283
+ SDKNode *swift::ide::api::
1284
+ SwiftDeclCollector::constructTypeAliasNode (TypeAliasDecl *TAD) {
1297
1285
auto Alias = SDKNodeInitInfo (Ctx, TAD).createSDKNode (SDKNodeKind::DeclTypeAlias);
1298
- Alias->addChild (constructTypeNode (Ctx, TAD->getUnderlyingTypeLoc ().getType ()));
1286
+ Alias->addChild (constructTypeNode (TAD->getUnderlyingTypeLoc ().getType ()));
1299
1287
return Alias;
1300
1288
}
1301
1289
1302
- static SDKNode *constructAssociatedTypeNode (SDKContext &Ctx,
1303
- AssociatedTypeDecl *ATD) {
1290
+ SDKNode *swift::ide::api::
1291
+ SwiftDeclCollector::constructAssociatedTypeNode ( AssociatedTypeDecl *ATD) {
1304
1292
auto Asso = SDKNodeInitInfo (Ctx, ATD).
1305
1293
createSDKNode (SDKNodeKind::DeclAssociatedType);
1306
1294
if (auto DT = ATD->getDefaultDefinitionType ()) {
1307
- Asso->addChild (constructTypeNode (Ctx, DT));
1295
+ Asso->addChild (constructTypeNode (DT));
1308
1296
}
1309
1297
return Asso;
1310
1298
}
1311
1299
1312
- static SDKNode *constructSubscriptDeclNode (SDKContext &Ctx, SubscriptDecl *SD) {
1300
+ SDKNode *swift::ide::api::
1301
+ SwiftDeclCollector::constructSubscriptDeclNode (SubscriptDecl *SD) {
1313
1302
auto Subs = SDKNodeInitInfo (Ctx, SD).createSDKNode (SDKNodeKind::DeclSubscript);
1314
- Subs->addChild (constructTypeNode (Ctx, SD->getElementInterfaceType ()));
1315
- for (auto *Node: createParameterNodes (Ctx, SD->getIndices ()))
1303
+ Subs->addChild (constructTypeNode (SD->getElementInterfaceType ()));
1304
+ for (auto *Node: createParameterNodes (SD->getIndices ()))
1316
1305
Subs->addChild (Node);
1317
1306
return Subs;
1318
1307
}
1319
1308
1320
- static void addMembersToRoot (SDKContext &Ctx, SDKNode *Root,
1321
- IterableDeclContext *Context,
1322
- std::set<ExtensionDecl*> &HandledExts) {
1309
+ void swift::ide::api::
1310
+ SwiftDeclCollector::addMembersToRoot (SDKNode *Root, IterableDeclContext *Context) {
1323
1311
for (auto *Member : Context->getMembers ()) {
1324
- if (shouldIgnore (Member, Context->getDecl (), Ctx ))
1312
+ if (shouldIgnore (Member, Context->getDecl ()))
1325
1313
continue ;
1326
1314
if (auto Func = dyn_cast<FuncDecl>(Member)) {
1327
- Root->addChild (constructFunctionNode (Ctx, Func, SDKNodeKind::DeclFunction));
1315
+ Root->addChild (constructFunctionNode (Func, SDKNodeKind::DeclFunction));
1328
1316
} else if (auto CD = dyn_cast<ConstructorDecl>(Member)) {
1329
- Root->addChild (constructInitNode (Ctx, CD));
1317
+ Root->addChild (constructInitNode (CD));
1330
1318
} else if (auto VD = dyn_cast<VarDecl>(Member)) {
1331
- Root->addChild (constructVarNode (Ctx, VD));
1319
+ Root->addChild (constructVarNode (VD));
1332
1320
} else if (auto TAD = dyn_cast<TypeAliasDecl>(Member)) {
1333
- Root->addChild (constructTypeAliasNode (Ctx, TAD));
1321
+ Root->addChild (constructTypeAliasNode (TAD));
1334
1322
} else if (auto EED = dyn_cast<EnumElementDecl>(Member)) {
1335
- Root->addChild (constructVarNode (Ctx, EED));
1323
+ Root->addChild (constructVarNode (EED));
1336
1324
} else if (auto NTD = dyn_cast<NominalTypeDecl>(Member)) {
1337
- Root->addChild (constructTypeDeclNode (Ctx, NTD, HandledExts ));
1325
+ Root->addChild (constructTypeDeclNode (NTD));
1338
1326
} else if (auto ATD = dyn_cast<AssociatedTypeDecl>(Member)) {
1339
- Root->addChild (constructAssociatedTypeNode (Ctx, ATD));
1327
+ Root->addChild (constructAssociatedTypeNode (ATD));
1340
1328
} else if (auto SD = dyn_cast<SubscriptDecl>(Member)) {
1341
- Root->addChild (constructSubscriptDeclNode (Ctx, SD));
1329
+ Root->addChild (constructSubscriptDeclNode (SD));
1342
1330
} else if (isa<PatternBindingDecl>(Member)) {
1343
1331
// All containing variables should have been handled.
1344
1332
} else if (isa<DestructorDecl>(Member)) {
@@ -1360,7 +1348,7 @@ void SwiftDeclCollector::lookupVisibleDecls(ArrayRef<ModuleDecl *> Modules) {
1360
1348
llvm::SmallVector<Decl*, 512 > Decls;
1361
1349
M->getDisplayDecls (Decls);
1362
1350
for (auto D : Decls) {
1363
- if (shouldIgnore (D, nullptr , Ctx ))
1351
+ if (shouldIgnore (D, nullptr ))
1364
1352
continue ;
1365
1353
if (KnownDecls.count (D))
1366
1354
continue ;
@@ -1393,22 +1381,21 @@ void SwiftDeclCollector::lookupVisibleDecls(ArrayRef<ModuleDecl *> Modules) {
1393
1381
}
1394
1382
}
1395
1383
for (auto Pair: ExtensionMap) {
1396
- RootNode->addChild (constructExternalExtensionNode (Ctx, RootNode,
1397
- Pair.first , Pair.second , HandledExtensions));
1384
+ RootNode->addChild (constructExternalExtensionNode (Pair.first , Pair.second ));
1398
1385
}
1399
1386
}
1400
1387
1401
1388
void SwiftDeclCollector::processDecl (ValueDecl *VD) {
1402
1389
if (auto FD = dyn_cast<FuncDecl>(VD)) {
1403
- RootNode->addChild (constructFunctionNode (Ctx, FD, SDKNodeKind::DeclFunction));
1390
+ RootNode->addChild (constructFunctionNode (FD, SDKNodeKind::DeclFunction));
1404
1391
} else if (auto NTD = dyn_cast<NominalTypeDecl>(VD)) {
1405
- RootNode->addChild (constructTypeDeclNode (Ctx, NTD, HandledExtensions ));
1392
+ RootNode->addChild (constructTypeDeclNode (NTD));
1406
1393
}
1407
1394
if (auto VAD = dyn_cast<VarDecl>(VD)) {
1408
- RootNode->addChild (constructVarNode (Ctx, VAD));
1395
+ RootNode->addChild (constructVarNode (VAD));
1409
1396
}
1410
1397
if (auto TAD = dyn_cast<TypeAliasDecl>(VD)) {
1411
- RootNode->addChild (constructTypeAliasNode (Ctx, TAD));
1398
+ RootNode->addChild (constructTypeAliasNode (TAD));
1412
1399
}
1413
1400
}
1414
1401
0 commit comments