Skip to content

Commit 8e77ea7

Browse files
authored
Merge pull request #8598 from eeckstein/demangling-extensions
Demangler: fix de- and re-mangling of constrained extensions
2 parents 3bf1f0d + 3ee9c88 commit 8e77ea7

File tree

5 files changed

+25
-2
lines changed

5 files changed

+25
-2
lines changed

include/swift/Demangling/Demangler.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,8 @@ class Demangler : public NodeFactory {
455455

456456
NodePointer demangleObjCTypeName();
457457

458+
void dump();
459+
458460
public:
459461
Demangler() {}
460462

lib/Demangling/Demangler.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -905,6 +905,10 @@ NodePointer Demangler::demangleBoundGenericArgs(NodePointer Nominal,
905905
BoundParent = createWithChildren(Node::Kind::Extension,
906906
Context->getFirstChild(),
907907
BoundParent);
908+
if (Context->getNumChildren() == 3) {
909+
// Add the generic signature of the extension context.
910+
addChild(BoundParent, Context->getChild(2));
911+
}
908912
} else {
909913
BoundParent = demangleBoundGenericArgs(Context, TypeLists, TypeListIdx);
910914
}

lib/Demangling/NodeDumper.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===--- NodeDumper.cpp - Swift Demangling Node Dumper --------------------===//
1+
//===--- NodeDumper.cpp - Swift Demangling Debug Dump Functions -----------===//
22
//
33
// This source file is part of the Swift.org open source project
44
//
@@ -11,6 +11,7 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
#include "swift/Demangling/Demangle.h"
14+
#include "swift/Demangling/Demangler.h"
1415
#include <cstdio>
1516

1617
using namespace swift;
@@ -58,3 +59,14 @@ void swift::Demangle::Node::dump() {
5859
std::string TreeStr = getNodeTreeAsString(this);
5960
fputs(TreeStr.c_str(), stderr);
6061
}
62+
63+
void Demangler::dump() {
64+
for (unsigned Idx = 0; Idx < NodeStack.size(); ++Idx) {
65+
fprintf(stderr, "NodeStack[%u] at position %zd:\n", Idx, NodeStack[Idx].Pos);
66+
NodeStack[Idx].Node->dump();
67+
fprintf(stderr, "\n");
68+
}
69+
fprintf(stderr, "Position = %zd:\n%.*s\n%*s\n", Pos,
70+
(int)Text.size(), Text.data(), (int)Pos + 1, "^");
71+
}
72+

lib/Demangling/Remangler.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1784,6 +1784,10 @@ NodePointer Demangle::getUnspecialized(Node *node, NodeFactory &Factory) {
17841784
NodePointer result = Factory.createNode(Node::Kind::Extension);
17851785
result->addChild(node->getFirstChild(), Factory);
17861786
result->addChild(getUnspecialized(parent, Factory), Factory);
1787+
if (node->getNumChildren() == 3) {
1788+
// Add the generic signature of the extension.
1789+
result->addChild(node->getChild(2), Factory);
1790+
}
17871791
return result;
17881792
}
17891793
default:

test/Demangle/Inputs/manglings.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,4 +248,5 @@ _SocketJoinOrLeaveMulticast ---> _SocketJoinOrLeaveMulticast
248248
_T0s10DictionaryV3t17E6Index2V1loiSbAEyxq__G_AGtFZ ---> static (extension in t17):Swift.Dictionary.Index2.< infix ((extension in t17):[A : B].Index2, (extension in t17):[A : B].Index2) -> Swift.Bool
249249
_T08mangling14varargsVsArrayySaySiG3arrd_SS1ntF ---> mangling.varargsVsArray (arr : Swift.Int..., n : Swift.String) -> ()
250250
_T08mangling14varargsVsArrayySaySiG3arrd_tF ---> mangling.varargsVsArray (arr : Swift.Int...) -> ()
251-
251+
_T0s13_UnicodeViewsVss22RandomAccessCollectionRzs0A8EncodingR_11SubSequence_5IndexQZAFRtzsAcERpzAE_AEQZAIRSs15UnsignedInteger8Iterator_7ElementRPzAE_AlMQZANRS13EncodedScalar_AlMQY_AORSr0_lE13CharacterViewVyxq__G ---> (extension in Swift):Swift._UnicodeViews<A, B><A, B where A: Swift.RandomAccessCollection, B: Swift.UnicodeEncoding, A.Index == A.SubSequence.Index, A.SubSequence: Swift.RandomAccessCollection, A.SubSequence == A.SubSequence.SubSequence, A.Iterator.Element: Swift.UnsignedInteger, A.Iterator.Element == A.SubSequence.Iterator.Element, A.SubSequence.Iterator.Element == B.EncodedScalar.Iterator.Element>.CharacterView
252+

0 commit comments

Comments
 (0)