@@ -951,6 +951,15 @@ static void VisitNodeDestructor(
951
951
}
952
952
}
953
953
954
+ static Demangle::NodePointer DropGenericSignature (
955
+ Demangle::NodePointer cur_node) {
956
+ if (cur_node->getKind () != Demangle::Node::Kind::DependentGenericType)
957
+ return nullptr ;
958
+ if (cur_node->getChild (0 ) == nullptr )
959
+ return nullptr ;
960
+ return cur_node->getFirstChild ();
961
+ }
962
+
954
963
static void VisitNodeDeclContext (
955
964
ASTContext *ast,
956
965
Demangle::NodePointer cur_node, VisitNodeResult &result) {
@@ -979,14 +988,10 @@ static void VisitNodeDeclContext(
979
988
if (generics->getChild (0 ) == nullptr )
980
989
break ;
981
990
generics = generics->getFirstChild ();
982
- if (generics->getKind () != Demangle::Node::Kind::DependentGenericType)
991
+ generics = DropGenericSignature (generics);
992
+ if (generics == nullptr )
983
993
break ;
984
- if (generics->getChild (0 ) == nullptr )
985
- break ;
986
- generics = generics->getFirstChild ();
987
- // if (generics->getKind() !=
988
- // Demangle::Node::Kind::ArchetypeList)
989
- // break;
994
+
990
995
AbstractFunctionDecl *func_decl = nullptr ;
991
996
for (Decl *decl : found_decls._decls ) {
992
997
func_decl = dyn_cast<AbstractFunctionDecl>(decl);
@@ -1254,6 +1259,28 @@ static void VisitNodeFunction(
1254
1259
}
1255
1260
}
1256
1261
1262
+ do {
1263
+ if (cur_node->getKind () == Demangle::Node::Kind::Subscript) {
1264
+ FindNamedDecls (ast, DeclBaseName::createSubscript (),
1265
+ decl_scope_result);
1266
+ if (decl_scope_result._decls .empty ()) {
1267
+ result._error = stringWithFormat (
1268
+ " subscript identifier could not be found by name lookup" );
1269
+ break ;
1270
+ }
1271
+ std::copy (decl_scope_result._decls .begin (),
1272
+ decl_scope_result._decls .end (),
1273
+ back_inserter (identifier_result._decls ));
1274
+ std::copy (decl_scope_result._types .begin (),
1275
+ decl_scope_result._types .end (),
1276
+ back_inserter (identifier_result._types ));
1277
+ identifier_result._module = decl_scope_result._module ;
1278
+ if (decl_scope_result._decls .size () == 1 )
1279
+ found_univocous = true ;
1280
+ break ;
1281
+ }
1282
+ } while (0 );
1283
+
1257
1284
// if (node_kind == Demangle::Node::Kind::Allocator)
1258
1285
// {
1259
1286
// // For allocators we don't have an identifier for
@@ -1416,6 +1443,8 @@ static void VisitNodeSetterGetter(
1416
1443
Demangle::NodePointer cur_node, VisitNodeResult &result) {
1417
1444
VisitNodeResult decl_ctx_result;
1418
1445
std::string identifier;
1446
+ std::vector<StringRef> labels;
1447
+
1419
1448
VisitNodeResult type_result;
1420
1449
1421
1450
assert (cur_node->getNumChildren () == 1 &&
@@ -1440,9 +1469,23 @@ static void VisitNodeSetterGetter(
1440
1469
case Demangle::Node::Kind::Identifier:
1441
1470
identifier.assign ((*pos)->getText ());
1442
1471
break ;
1443
- case Demangle::Node::Kind::Type:
1444
- VisitNode (ast, *pos, type_result);
1472
+ case Demangle::Node::Kind::Type: {
1473
+ auto type = (*pos)->getFirstChild ();
1474
+ if (DropGenericSignature (type))
1475
+ type = type->getChild (1 );
1476
+ VisitNode (ast, type, type_result);
1477
+ break ;
1478
+ }
1479
+ case Demangle::Node::Kind::LabelList: {
1480
+ for (const auto &label : **pos) {
1481
+ if (label->getKind () == Demangle::Node::Kind::FirstElementMarker)
1482
+ labels.push_back (StringRef ());
1483
+ else {
1484
+ labels.push_back (label->getText ());
1485
+ }
1486
+ }
1445
1487
break ;
1488
+ }
1446
1489
default :
1447
1490
result._error =
1448
1491
stringWithFormat (" %s encountered in generic type children" ,
@@ -1451,6 +1494,11 @@ static void VisitNodeSetterGetter(
1451
1494
}
1452
1495
}
1453
1496
1497
+ if (!type_result.HasSingleType ()) {
1498
+ result._error = " bad type" ;
1499
+ return ;
1500
+ }
1501
+
1454
1502
if (referenced_node->getKind () == Demangle::Node::Kind::Subscript) {
1455
1503
// Since there can be many subscripts for the same nominal type, we need to
1456
1504
// find the one matching the specified type.
@@ -1467,9 +1515,6 @@ static void VisitNodeSetterGetter(
1467
1515
const AnyFunctionType *type_func =
1468
1516
type_result._types .front ()->getAs <AnyFunctionType>();
1469
1517
1470
- Type type_result_type = type_func->getResult ();
1471
- Type type_input_type = type_func->getInput ();
1472
-
1473
1518
FuncDecl *identifier_func = nullptr ;
1474
1519
1475
1520
for (size_t i = 0 ; i < num_decls; i++) {
@@ -1494,24 +1539,24 @@ static void VisitNodeSetterGetter(
1494
1539
break ;
1495
1540
}
1496
1541
1497
- if (identifier_func && identifier_func->getInterfaceType ()) {
1498
- const AnyFunctionType *identifier_func_type =
1499
- identifier_func->getInterfaceType ()->getAs <AnyFunctionType>();
1500
- if (identifier_func_type) {
1542
+ if (identifier_func &&
1543
+ subscript_decl->getGetter () &&
1544
+ subscript_decl->getGetter ()->getInterfaceType ()) {
1545
+ auto subscript_type =
1546
+ subscript_decl->getGetter ()->getInterfaceType ()->getAs <AnyFunctionType>();
1547
+
1548
+ if (subscript_type) {
1501
1549
// Swift function types are formally functions that take the class
1502
1550
// and return the method,
1503
1551
// we have to strip off the first level of function call to compare
1504
1552
// against the type
1505
1553
// from the demangled name.
1506
- const AnyFunctionType *identifier_uncurried_result =
1507
- identifier_func_type->getResult ()->getAs <AnyFunctionType>();
1508
- if (identifier_uncurried_result) {
1509
- Type identifier_result_type =
1510
- identifier_uncurried_result->getResult ();
1511
- Type identifier_input_type =
1512
- identifier_uncurried_result->getInput ();
1513
- if (identifier_result_type->isEqual (type_result_type) &&
1514
- identifier_input_type->isEqual (type_input_type)) {
1554
+ auto subscript_uncurried_result =
1555
+ subscript_type->getResult ()->getAs <AnyFunctionType>();
1556
+ if (subscript_uncurried_result) {
1557
+ if (CompareFunctionTypes (type_func,
1558
+ subscript_uncurried_result,
1559
+ labels)) {
1515
1560
break ;
1516
1561
}
1517
1562
}
@@ -2061,6 +2106,25 @@ VisitNodeWeak(ASTContext *ast,
2061
2106
}
2062
2107
}
2063
2108
2109
+ static void
2110
+ VisitNodeGenericParam (ASTContext *ast,
2111
+ Demangle::NodePointer cur_node,
2112
+ VisitNodeResult &result) {
2113
+ if (cur_node->getNumChildren () == 2 ) {
2114
+ auto first = cur_node->getChild (0 );
2115
+ auto second = cur_node->getChild (1 );
2116
+ if (first->getKind () == Demangle::Node::Kind::Index &&
2117
+ second->getKind () == Demangle::Node::Kind::Index) {
2118
+ result._types .push_back (
2119
+ GenericTypeParamType::get (first->getIndex (),
2120
+ second->getIndex (), *ast));
2121
+ return ;
2122
+ }
2123
+ }
2124
+
2125
+ result._error = " bad generic param type" ;
2126
+ }
2127
+
2064
2128
static void VisitFirstChildNode (
2065
2129
ASTContext *ast,
2066
2130
Demangle::NodePointer cur_node, VisitNodeResult &result) {
@@ -2159,7 +2223,8 @@ static void VisitNode(
2159
2223
2160
2224
case Demangle::Node::Kind::Function:
2161
2225
case Demangle::Node::Kind::Allocator:
2162
- case Demangle::Node::Kind::Variable: // Out of order on purpose
2226
+ case Demangle::Node::Kind::Variable:
2227
+ case Demangle::Node::Kind::Subscript: // Out of order on purpose
2163
2228
VisitNodeFunction (ast, node, result);
2164
2229
break ;
2165
2230
@@ -2229,6 +2294,10 @@ static void VisitNode(
2229
2294
VisitNodeWeak (ast, node, result);
2230
2295
break ;
2231
2296
2297
+ case Demangle::Node::Kind::DependentGenericParamType:
2298
+ VisitNodeGenericParam (ast, node, result);
2299
+ break ;
2300
+
2232
2301
case Demangle::Node::Kind::LocalDeclName:
2233
2302
case Demangle::Node::Kind::Identifier:
2234
2303
case Demangle::Node::Kind::PrivateDeclName:
0 commit comments