@@ -39,6 +39,18 @@ static void unreachable(const char *Message) {
39
39
std::abort ();
40
40
}
41
41
42
+ static StringRef getTextForSubstitution (Node *node, std::string &tmp) {
43
+ switch (node->getKind ()) {
44
+ case Node::Kind::InfixOperator:
45
+ case Node::Kind::PrefixOperator:
46
+ case Node::Kind::PostfixOperator:
47
+ tmp = Mangle::translateOperator (node->getText ());
48
+ return tmp;
49
+ default :
50
+ return node->getText ();
51
+ }
52
+ }
53
+
42
54
namespace {
43
55
44
56
class SubstitutionEntry {
@@ -66,8 +78,11 @@ class SubstitutionEntry {
66
78
return false ;
67
79
if (lhs.treatAsIdentifier != rhs.treatAsIdentifier )
68
80
return false ;
69
- if (lhs.treatAsIdentifier )
70
- return lhs.TheNode ->getText () == rhs.TheNode ->getText ();
81
+ if (lhs.treatAsIdentifier ) {
82
+ std::string tmp1, tmp2;
83
+ return (getTextForSubstitution (lhs.TheNode , tmp1) ==
84
+ getTextForSubstitution (rhs.TheNode , tmp2));
85
+ }
71
86
return lhs.deepEquals (lhs.TheNode , rhs.TheNode );
72
87
}
73
88
@@ -84,7 +99,8 @@ class SubstitutionEntry {
84
99
void deepHash (Node *node) {
85
100
if (treatAsIdentifier) {
86
101
combineHash ((size_t ) Node::Kind::Identifier);
87
- combineHash (node->getText ());
102
+ std::string tmp;
103
+ combineHash (getTextForSubstitution (node, tmp));
88
104
return ;
89
105
}
90
106
combineHash ((size_t ) node->getKind ());
@@ -279,7 +295,8 @@ class Remangler {
279
295
280
296
void mangleAnyNominalType (Node *node);
281
297
void mangleAnyGenericType (Node *node, StringRef TypeOp);
282
- void mangleGenericArgs (Node *node, char &Separator);
298
+ void mangleGenericArgs (Node *node, char &Separator,
299
+ bool fullSubstitutionMap=false );
283
300
void mangleAnyConstructor (Node *node, char kindOp);
284
301
void mangleAbstractStorage (Node *node, StringRef accessorCode);
285
302
void mangleAnyProtocolConformance (Node *node);
@@ -473,29 +490,49 @@ void Remangler::mangleAnyNominalType(Node *node) {
473
490
}
474
491
}
475
492
476
- void Remangler::mangleGenericArgs (Node *node, char &Separator) {
493
+ void Remangler::mangleGenericArgs (Node *node, char &Separator,
494
+ bool fullSubstitutionMap) {
477
495
switch (node->getKind ()) {
478
496
case Node::Kind::Structure:
479
497
case Node::Kind::Enum:
480
498
case Node::Kind::Class:
481
499
case Node::Kind::TypeAlias:
500
+ if (node->getKind () == Node::Kind::TypeAlias)
501
+ fullSubstitutionMap = true ;
502
+
503
+ mangleGenericArgs (node->getChild (0 ), Separator,
504
+ fullSubstitutionMap);
505
+ Buffer << Separator;
506
+ Separator = ' _' ;
507
+ break ;
508
+
482
509
case Node::Kind::Function:
483
510
case Node::Kind::Getter:
484
511
case Node::Kind::Setter:
485
512
case Node::Kind::WillSet:
486
513
case Node::Kind::DidSet:
514
+ case Node::Kind::ReadAccessor:
515
+ case Node::Kind::ModifyAccessor:
516
+ case Node::Kind::UnsafeAddressor:
517
+ case Node::Kind::UnsafeMutableAddressor:
518
+ case Node::Kind::Allocator:
487
519
case Node::Kind::Constructor:
488
520
case Node::Kind::Destructor:
489
- mangleGenericArgs (node->getChild (0 ), Separator);
490
- Buffer << Separator;
491
- Separator = ' _' ;
492
- break ;
493
-
494
521
case Node::Kind::Variable:
495
522
case Node::Kind::Subscript:
496
523
case Node::Kind::ExplicitClosure:
497
524
case Node::Kind::ImplicitClosure:
498
- mangleGenericArgs (node->getChild (0 ), Separator);
525
+ case Node::Kind::DefaultArgumentInitializer:
526
+ case Node::Kind::Initializer:
527
+ if (!fullSubstitutionMap)
528
+ break ;
529
+
530
+ mangleGenericArgs (node->getChild (0 ), Separator,
531
+ fullSubstitutionMap);
532
+ if (Demangle::nodeConsumesGenericArgs (node)) {
533
+ Buffer << Separator;
534
+ Separator = ' _' ;
535
+ }
499
536
break ;
500
537
501
538
case Node::Kind::BoundGenericOtherNominalType:
@@ -504,31 +541,39 @@ void Remangler::mangleGenericArgs(Node *node, char &Separator) {
504
541
case Node::Kind::BoundGenericClass:
505
542
case Node::Kind::BoundGenericProtocol:
506
543
case Node::Kind::BoundGenericTypeAlias: {
544
+ if (node->getKind () == Node::Kind::BoundGenericTypeAlias)
545
+ fullSubstitutionMap = true ;
546
+
507
547
NodePointer unboundType = node->getChild (0 );
508
548
assert (unboundType->getKind () == Node::Kind::Type);
509
549
NodePointer nominalType = unboundType->getChild (0 );
510
550
NodePointer parentOrModule = nominalType->getChild (0 );
511
- mangleGenericArgs (parentOrModule, Separator);
551
+ mangleGenericArgs (parentOrModule, Separator,
552
+ fullSubstitutionMap);
512
553
Buffer << Separator;
513
554
Separator = ' _' ;
514
555
mangleChildNodes (node->getChild (1 ));
515
556
break ;
516
557
}
517
558
518
559
case Node::Kind::BoundGenericFunction: {
560
+ fullSubstitutionMap = true ;
561
+
519
562
NodePointer unboundFunction = node->getChild (0 );
520
563
assert (unboundFunction->getKind () == Node::Kind::Function ||
521
564
unboundFunction->getKind () == Node::Kind::Constructor);
522
565
NodePointer parentOrModule = unboundFunction->getChild (0 );
523
- mangleGenericArgs (parentOrModule, Separator);
566
+ mangleGenericArgs (parentOrModule, Separator,
567
+ fullSubstitutionMap);
524
568
Buffer << Separator;
525
569
Separator = ' _' ;
526
570
mangleChildNodes (node->getChild (1 ));
527
571
break ;
528
572
}
529
573
530
574
case Node::Kind::Extension:
531
- mangleGenericArgs (node->getChild (1 ), Separator);
575
+ mangleGenericArgs (node->getChild (1 ), Separator,
576
+ fullSubstitutionMap);
532
577
break ;
533
578
534
579
default :
@@ -578,17 +623,22 @@ void Remangler::mangleAssociatedTypeDescriptor(Node *node) {
578
623
}
579
624
580
625
void Remangler::mangleAssociatedConformanceDescriptor (Node *node) {
581
- mangleChildNodes (node);
626
+ mangle (node->getChild (0 ));
627
+ mangle (node->getChild (1 ));
628
+ manglePureProtocol (node->getChild (2 ));
582
629
Buffer << " Tn" ;
583
630
}
584
631
585
632
void Remangler::mangleDefaultAssociatedConformanceAccessor (Node *node) {
586
- mangleChildNodes (node);
633
+ mangle (node->getChild (0 ));
634
+ mangle (node->getChild (1 ));
635
+ manglePureProtocol (node->getChild (2 ));
587
636
Buffer << " TN" ;
588
637
}
589
638
590
639
void Remangler::mangleBaseConformanceDescriptor (Node *node) {
591
- mangleChildNodes (node);
640
+ mangle (node->getChild (0 ));
641
+ manglePureProtocol (node->getChild (1 ));
592
642
Buffer << " Tb" ;
593
643
}
594
644
@@ -1795,7 +1845,7 @@ void Remangler::mangleProtocolWitness(Node *node) {
1795
1845
}
1796
1846
1797
1847
void Remangler::mangleProtocolSelfConformanceWitnessTable (Node *node) {
1798
- mangleSingleChildNode (node);
1848
+ manglePureProtocol (node-> getChild ( 0 ) );
1799
1849
Buffer << " WS" ;
1800
1850
}
1801
1851
@@ -2295,16 +2345,23 @@ bool Demangle::isSpecialized(Node *node) {
2295
2345
case Node::Kind::OtherNominalType:
2296
2346
case Node::Kind::Protocol:
2297
2347
case Node::Kind::Function:
2348
+ case Node::Kind::Allocator:
2298
2349
case Node::Kind::Constructor:
2299
2350
case Node::Kind::Destructor:
2300
2351
case Node::Kind::Variable:
2301
2352
case Node::Kind::Subscript:
2302
2353
case Node::Kind::ExplicitClosure:
2303
2354
case Node::Kind::ImplicitClosure:
2355
+ case Node::Kind::Initializer:
2356
+ case Node::Kind::DefaultArgumentInitializer:
2304
2357
case Node::Kind::Getter:
2305
2358
case Node::Kind::Setter:
2306
2359
case Node::Kind::WillSet:
2307
2360
case Node::Kind::DidSet:
2361
+ case Node::Kind::ReadAccessor:
2362
+ case Node::Kind::ModifyAccessor:
2363
+ case Node::Kind::UnsafeAddressor:
2364
+ case Node::Kind::UnsafeMutableAddressor:
2308
2365
return isSpecialized (node->getChild (0 ));
2309
2366
2310
2367
case Node::Kind::Extension:
@@ -2323,12 +2380,19 @@ NodePointer Demangle::getUnspecialized(Node *node, NodeFactory &Factory) {
2323
2380
case Node::Kind::Setter:
2324
2381
case Node::Kind::WillSet:
2325
2382
case Node::Kind::DidSet:
2383
+ case Node::Kind::ReadAccessor:
2384
+ case Node::Kind::ModifyAccessor:
2385
+ case Node::Kind::UnsafeAddressor:
2386
+ case Node::Kind::UnsafeMutableAddressor:
2387
+ case Node::Kind::Allocator:
2326
2388
case Node::Kind::Constructor:
2327
2389
case Node::Kind::Destructor:
2328
2390
case Node::Kind::Variable:
2329
2391
case Node::Kind::Subscript:
2330
2392
case Node::Kind::ExplicitClosure:
2331
2393
case Node::Kind::ImplicitClosure:
2394
+ case Node::Kind::Initializer:
2395
+ case Node::Kind::DefaultArgumentInitializer:
2332
2396
NumToCopy = node->getNumChildren ();
2333
2397
LLVM_FALLTHROUGH;
2334
2398
case Node::Kind::Structure:
0 commit comments