@@ -308,6 +308,14 @@ class ParentExtensionInfo {
308
308
ArrayRef<StringRef> getGenericRequirements () const { return Requirements; }
309
309
};
310
310
311
+ // / The additional information we need to create a type node.
312
+ struct TypeInitInfo {
313
+ bool IsImplicitlyUnwrappedOptional = false ;
314
+ // / When this type node represents a function parameter, this boolean value
315
+ // / indicates whether the parameter has default argument.
316
+ bool hasDefaultArgument = false ;
317
+ };
318
+
311
319
struct SDKNodeInitInfo {
312
320
SDKContext &Ctx;
313
321
StringRef Name;
@@ -325,11 +333,11 @@ struct SDKNodeInitInfo {
325
333
std::vector<TypeAttrKind> TypeAttrs;
326
334
StringRef SuperclassUsr;
327
335
ParentExtensionInfo *ExtInfo = nullptr ;
336
+ TypeInitInfo TypeInfo;
328
337
329
338
SDKNodeInitInfo (SDKContext &Ctx) : Ctx(Ctx) {}
330
339
SDKNodeInitInfo (SDKContext &Ctx, ValueDecl *VD);
331
- SDKNodeInitInfo (SDKContext &Ctx, Type Ty,
332
- bool IsImplicitlyUnwrappedOptional =false );
340
+ SDKNodeInitInfo (SDKContext &Ctx, Type Ty, TypeInitInfo Info = TypeInitInfo());
333
341
SDKNode* createSDKNode (SDKNodeKind Kind);
334
342
};
335
343
@@ -465,17 +473,23 @@ NodePtr UpdatedNodesMap::findUpdateCounterpart(const SDKNode *Node) const {
465
473
466
474
class SDKNodeType : public SDKNode {
467
475
std::vector<TypeAttrKind> TypeAttributes;
476
+ bool HasDefaultArg;
468
477
469
478
protected:
470
479
bool hasTypeAttribute (TypeAttrKind DAKind) const ;
471
480
SDKNodeType (SDKNodeInitInfo Info, SDKNodeKind Kind) : SDKNode(Info, Kind),
472
- TypeAttributes (Info.TypeAttrs) {}
481
+ TypeAttributes (Info.TypeAttrs),
482
+ HasDefaultArg(Info.TypeInfo.hasDefaultArgument) {}
473
483
474
484
public:
475
485
KnownTypeKind getTypeKind () const ;
476
486
void addTypeAttribute (TypeAttrKind AttrKind);
477
487
ArrayRef<TypeAttrKind> getTypeAttributes () const ;
478
488
SDKNodeDecl *getClosestParentDecl () const ;
489
+
490
+ // When the type node represents a function parameter, this function returns
491
+ // whether the parameter has a default value.
492
+ bool hasDefaultArgument () const { return HasDefaultArg; }
479
493
static bool classof (const SDKNode *N);
480
494
};
481
495
@@ -947,6 +961,9 @@ SDKNode* SDKNode::constructSDKNode(SDKContext &Ctx,
947
961
case KeyKind::KK_mutating:
948
962
Info.IsMutating = true ;
949
963
break ;
964
+ case KeyKind::KK_hasDefaultArg:
965
+ Info.TypeInfo .hasDefaultArgument = true ;
966
+ break ;
950
967
case KeyKind::KK_static:
951
968
Info.IsStatic = true ;
952
969
break ;
@@ -1219,9 +1236,10 @@ static Ownership getOwnership(ValueDecl *VD) {
1219
1236
}
1220
1237
1221
1238
SDKNodeInitInfo::SDKNodeInitInfo (SDKContext &Ctx, Type Ty,
1222
- bool IsImplicitlyUnwrappedOptional) :
1223
- Ctx (Ctx), Name(getTypeName(Ctx, Ty, IsImplicitlyUnwrappedOptional)),
1224
- PrintedName (getPrintedName(Ctx, Ty, IsImplicitlyUnwrappedOptional)) {
1239
+ TypeInitInfo TypeInfo) :
1240
+ Ctx (Ctx), Name(getTypeName(Ctx, Ty, TypeInfo.IsImplicitlyUnwrappedOptional)),
1241
+ PrintedName (getPrintedName(Ctx, Ty, TypeInfo.IsImplicitlyUnwrappedOptional)),
1242
+ TypeInfo (TypeInfo) {
1225
1243
if (isFunctionTypeNoEscape (Ty))
1226
1244
TypeAttrs.push_back (TypeAttrKind::TAK_noescape);
1227
1245
}
@@ -1270,8 +1288,8 @@ case SDKNodeKind::X: \
1270
1288
// Recursively construct a node that represents a type, for instance,
1271
1289
// representing the return value type of a function decl.
1272
1290
static SDKNode *constructTypeNode (SDKContext &Ctx, Type T,
1273
- bool IsImplicitlyUnwrappedOptional = false ) {
1274
- SDKNode* Root = SDKNodeInitInfo (Ctx, T, IsImplicitlyUnwrappedOptional )
1291
+ TypeInitInfo InitInfo = TypeInitInfo() ) {
1292
+ SDKNode* Root = SDKNodeInitInfo (Ctx, T, InitInfo )
1275
1293
.createSDKNode (SDKNodeKind::TypeNominal);
1276
1294
1277
1295
if (auto NAT = dyn_cast<NameAliasType>(T.getPointer ())) {
@@ -1313,42 +1331,46 @@ static SDKNode *constructTypeNode(SDKContext &Ctx, Type T,
1313
1331
return Root;
1314
1332
}
1315
1333
1334
+ static std::vector<SDKNode*>
1335
+ createParameterNodes (SDKContext &Ctx, ArrayRef<ParameterList*> AllParamLists) {
1336
+ std::vector<SDKNode*> Result;
1337
+ for (auto PL: AllParamLists) {
1338
+ for (auto param: *PL) {
1339
+ if (param->isSelfParameter ())
1340
+ continue ;
1341
+ TypeInitInfo TypeInfo;
1342
+ TypeInfo.IsImplicitlyUnwrappedOptional = param->getAttrs ().
1343
+ hasAttribute<ImplicitlyUnwrappedOptionalAttr>();
1344
+ TypeInfo.hasDefaultArgument = param->getDefaultArgumentKind () !=
1345
+ DefaultArgumentKind::None;
1346
+ Result.push_back (constructTypeNode (Ctx, param->getInterfaceType (),
1347
+ TypeInfo));
1348
+ }
1349
+ }
1350
+ return Result;
1351
+ }
1352
+
1316
1353
// Construct a node for a function decl. The first child of the function decl
1317
1354
// is guaranteed to be the return value type of this function.
1318
1355
// We sometimes skip the first parameter because it can be metatype of dynamic
1319
1356
// this if the function is a member function.
1320
1357
static SDKNode *constructFunctionNode (SDKContext &Ctx, FuncDecl* FD,
1321
1358
SDKNodeKind Kind) {
1322
1359
auto Func = SDKNodeInitInfo (Ctx, FD).createSDKNode (Kind);
1323
- bool resultIsImplicitlyUnwrappedOptional = false ;
1324
- if (FD->getAttrs ().hasAttribute <ImplicitlyUnwrappedOptionalAttr>())
1325
- resultIsImplicitlyUnwrappedOptional = true ;
1326
- Func->addChild (constructTypeNode (Ctx, FD->getResultInterfaceType (),
1327
- resultIsImplicitlyUnwrappedOptional));
1328
- for (auto *paramList : FD->getParameterLists ()) {
1329
- for (auto param : *paramList) {
1330
- bool paramIsImplicitlyUnwrappedOptional = false ;
1331
- if (param->getAttrs ().hasAttribute <ImplicitlyUnwrappedOptionalAttr>())
1332
- paramIsImplicitlyUnwrappedOptional = true ;
1333
-
1334
- if (!param->isSelfParameter ())
1335
- Func->addChild (constructTypeNode (Ctx, param->getInterfaceType (),
1336
- paramIsImplicitlyUnwrappedOptional));
1337
- }
1338
- }
1360
+ TypeInitInfo TypeInfo;
1361
+ TypeInfo.IsImplicitlyUnwrappedOptional = FD->getAttrs ().
1362
+ hasAttribute<ImplicitlyUnwrappedOptionalAttr>();
1363
+ Func->addChild (constructTypeNode (Ctx, FD->getResultInterfaceType (), TypeInfo));
1364
+ for (auto *Node : createParameterNodes (Ctx, FD->getParameterLists ()))
1365
+ Func->addChild (Node);
1339
1366
return Func;
1340
1367
}
1341
1368
1342
1369
static SDKNode* constructInitNode (SDKContext &Ctx, ConstructorDecl *CD) {
1343
1370
auto Func = SDKNodeInitInfo (Ctx, CD).createSDKNode (SDKNodeKind::Constructor);
1344
1371
Func->addChild (constructTypeNode (Ctx, CD->getResultInterfaceType ()));
1345
- for (auto *paramList : CD->getParameterLists ()) {
1346
- for (auto param : *paramList)
1347
- Func->addChild (constructTypeNode (Ctx, param->getInterfaceType ()));
1348
- }
1349
-
1350
- // Always remove the first parameter in init.
1351
- Func->removeChild (Func->getChildBegin () + 1 );
1372
+ for (auto *Node : createParameterNodes (Ctx, CD->getParameterLists ()))
1373
+ Func->addChild (Node);
1352
1374
return Func;
1353
1375
}
1354
1376
@@ -1405,11 +1427,10 @@ static SDKNode *constructTypeDeclNode(SDKContext &Ctx, NominalTypeDecl *NTD) {
1405
1427
1406
1428
static SDKNode *constructVarNode (SDKContext &Ctx, ValueDecl *VD) {
1407
1429
auto Var = SDKNodeInitInfo (Ctx, VD).createSDKNode (SDKNodeKind::Var);
1408
- auto isImplicitlyUnwrappedOptional = false ;
1409
- if (VD->getAttrs ().hasAttribute <ImplicitlyUnwrappedOptionalAttr>())
1410
- isImplicitlyUnwrappedOptional = true ;
1411
- Var->addChild (constructTypeNode (Ctx, VD->getInterfaceType (),
1412
- isImplicitlyUnwrappedOptional));
1430
+ TypeInitInfo TypeInfo;
1431
+ TypeInfo.IsImplicitlyUnwrappedOptional = VD->getAttrs ().
1432
+ hasAttribute<ImplicitlyUnwrappedOptionalAttr>();
1433
+ Var->addChild (constructTypeNode (Ctx, VD->getInterfaceType (), TypeInfo));
1413
1434
if (auto VAD = dyn_cast<AbstractStorageDecl>(VD)) {
1414
1435
if (auto Getter = VAD->getGetter ())
1415
1436
Var->addChild (constructFunctionNode (Ctx, Getter, SDKNodeKind::Getter));
@@ -1650,6 +1671,10 @@ namespace swift {
1650
1671
if (!Attributes.empty ())
1651
1672
out.mapRequired (getKeyContent (Ctx, KeyKind::KK_typeAttributes).data (),
1652
1673
Attributes);
1674
+ if (bool HasDefault = T->hasDefaultArgument ()) {
1675
+ out.mapRequired (getKeyContent (Ctx, KeyKind::KK_hasDefaultArg).data (),
1676
+ HasDefault);
1677
+ }
1653
1678
}
1654
1679
if (!value->isLeaf ()) {
1655
1680
ArrayRef<SDKNode *> Children = value->getChildren ();
0 commit comments