@@ -302,7 +302,8 @@ struct SDKNodeInitInfo {
302
302
StringRef SuperclassUsr;
303
303
SDKNodeInitInfo (SDKContext &Ctx) : Ctx(Ctx) {}
304
304
SDKNodeInitInfo (SDKContext &Ctx, ValueDecl *VD);
305
- SDKNodeInitInfo (SDKContext &Ctx, Type Ty);
305
+ SDKNodeInitInfo (SDKContext &Ctx, Type Ty,
306
+ bool IsImplicitlyUnwrappedOptional =false );
306
307
SDKNode* createSDKNode (SDKNodeKind Kind);
307
308
};
308
309
@@ -1029,16 +1030,21 @@ class SDKNodeDumpVisitor : public SDKNodeVisitor {
1029
1030
SDKNodeDumpVisitor () {};
1030
1031
};
1031
1032
1032
- static StringRef getPrintedName (SDKContext &Ctx, Type Ty) {
1033
+ static StringRef getPrintedName (SDKContext &Ctx, Type Ty,
1034
+ bool IsImplicitlyUnwrappedOptional) {
1033
1035
std::string S;
1034
1036
llvm::raw_string_ostream OS (S);
1035
1037
PrintOptions PO;
1036
1038
PO.SkipAttributes = true ;
1039
+ if (IsImplicitlyUnwrappedOptional)
1040
+ PO.PrintOptionalAsImplicitlyUnwrapped = true ;
1041
+
1037
1042
Ty.print (OS, PO);
1038
1043
return Ctx.buffer (OS.str ());
1039
1044
}
1040
1045
1041
- static StringRef getTypeName (SDKContext &Ctx, Type Ty) {
1046
+ static StringRef getTypeName (SDKContext &Ctx, Type Ty,
1047
+ bool IsImplicitlyUnwrappedOptional) {
1042
1048
if (Ty->getKind () == TypeKind::Paren) {
1043
1049
return Ctx.buffer (" Paren" );
1044
1050
}
@@ -1049,6 +1055,10 @@ static StringRef getTypeName(SDKContext &Ctx, Type Ty) {
1049
1055
return NAT->getDecl ()->getNameStr ();
1050
1056
}
1051
1057
if (Ty->getAnyNominal ()) {
1058
+ if (IsImplicitlyUnwrappedOptional) {
1059
+ assert (Ty->getAnyOptionalObjectType ());
1060
+ return StringRef (" ImplicitlyUnwrappedOptional" );
1061
+ }
1052
1062
return Ty->getAnyNominal ()->getNameStr ();
1053
1063
}
1054
1064
#define TYPE (id, parent ) \
@@ -1159,8 +1169,10 @@ static Ownership getOwnership(ValueDecl *VD) {
1159
1169
return Ownership::Strong;
1160
1170
}
1161
1171
1162
- SDKNodeInitInfo::SDKNodeInitInfo (SDKContext &Ctx, Type Ty) :
1163
- Ctx (Ctx), Name(getTypeName(Ctx, Ty)), PrintedName(getPrintedName(Ctx, Ty)) {
1172
+ SDKNodeInitInfo::SDKNodeInitInfo (SDKContext &Ctx, Type Ty,
1173
+ bool IsImplicitlyUnwrappedOptional) :
1174
+ Ctx (Ctx), Name(getTypeName(Ctx, Ty, IsImplicitlyUnwrappedOptional)),
1175
+ PrintedName (getPrintedName(Ctx, Ty, IsImplicitlyUnwrappedOptional)) {
1164
1176
if (isFunctionTypeNoEscape (Ty))
1165
1177
TypeAttrs.push_back (TypeAttrKind::TAK_noescape);
1166
1178
}
@@ -1196,8 +1208,10 @@ case SDKNodeKind::X: \
1196
1208
1197
1209
// Recursively construct a node that represents a type, for instance,
1198
1210
// representing the return value type of a function decl.
1199
- static SDKNode *constructTypeNode (SDKContext &Ctx, Type T) {
1200
- SDKNode* Root = SDKNodeInitInfo (Ctx, T).createSDKNode (SDKNodeKind::TypeNominal);
1211
+ static SDKNode *constructTypeNode (SDKContext &Ctx, Type T,
1212
+ bool IsImplicitlyUnwrappedOptional =false ) {
1213
+ SDKNode* Root = SDKNodeInitInfo (Ctx, T, IsImplicitlyUnwrappedOptional)
1214
+ .createSDKNode (SDKNodeKind::TypeNominal);
1201
1215
1202
1216
if (auto NAT = dyn_cast<NameAliasType>(T.getPointer ())) {
1203
1217
SDKNode* Root = SDKNodeInitInfo (Ctx, T).createSDKNode (SDKNodeKind::TypeNameAlias);
@@ -1245,11 +1259,20 @@ static SDKNode *constructTypeNode(SDKContext &Ctx, Type T) {
1245
1259
static SDKNode *constructFunctionNode (SDKContext &Ctx, FuncDecl* FD,
1246
1260
SDKNodeKind Kind) {
1247
1261
auto Func = SDKNodeInitInfo (Ctx, FD).createSDKNode (Kind);
1248
- Func->addChild (constructTypeNode (Ctx, FD->getResultInterfaceType ()));
1262
+ bool resultIsImplicitlyUnwrappedOptional = false ;
1263
+ if (FD->getAttrs ().hasAttribute <ImplicitlyUnwrappedOptionalAttr>())
1264
+ resultIsImplicitlyUnwrappedOptional = true ;
1265
+ Func->addChild (constructTypeNode (Ctx, FD->getResultInterfaceType (),
1266
+ resultIsImplicitlyUnwrappedOptional));
1249
1267
for (auto *paramList : FD->getParameterLists ()) {
1250
1268
for (auto param : *paramList) {
1269
+ bool paramIsImplicitlyUnwrappedOptional = false ;
1270
+ if (param->getAttrs ().hasAttribute <ImplicitlyUnwrappedOptionalAttr>())
1271
+ paramIsImplicitlyUnwrappedOptional = true ;
1272
+
1251
1273
if (!param->isSelfParameter ())
1252
- Func->addChild (constructTypeNode (Ctx, param->getInterfaceType ()));
1274
+ Func->addChild (constructTypeNode (Ctx, param->getInterfaceType (),
1275
+ paramIsImplicitlyUnwrappedOptional));
1253
1276
}
1254
1277
}
1255
1278
return Func;
@@ -1321,7 +1344,11 @@ static SDKNode *constructTypeDeclNode(SDKContext &Ctx, NominalTypeDecl *NTD) {
1321
1344
1322
1345
static SDKNode *constructVarNode (SDKContext &Ctx, ValueDecl *VD) {
1323
1346
auto Var = SDKNodeInitInfo (Ctx, VD).createSDKNode (SDKNodeKind::Var);
1324
- Var->addChild (constructTypeNode (Ctx, VD->getInterfaceType ()));
1347
+ auto isImplicitlyUnwrappedOptional = false ;
1348
+ if (VD->getAttrs ().hasAttribute <ImplicitlyUnwrappedOptionalAttr>())
1349
+ isImplicitlyUnwrappedOptional = true ;
1350
+ Var->addChild (constructTypeNode (Ctx, VD->getInterfaceType (),
1351
+ isImplicitlyUnwrappedOptional));
1325
1352
if (auto VAD = dyn_cast<AbstractStorageDecl>(VD)) {
1326
1353
if (auto Getter = VAD->getGetter ())
1327
1354
Var->addChild (constructFunctionNode (Ctx, Getter, SDKNodeKind::Getter));
0 commit comments