2
2
//
3
3
// This source file is part of the Swift.org open source project
4
4
//
5
- // Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
5
+ // Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors
6
6
// Licensed under Apache License v2.0 with Runtime Library Exception
7
7
//
8
8
// See https://swift.org/LICENSE.txt for license information
@@ -35,6 +35,11 @@ namespace Demangle {
35
35
36
36
enum class SymbolicReferenceKind : uint8_t ;
37
37
38
+ // / A simple default implementation that assigns letters to type parameters in
39
+ // / alphabetic order.
40
+ std::string genericParameterName (uint64_t depth, uint64_t index);
41
+
42
+ // / Display style options for the demangler.
38
43
struct DemangleOptions {
39
44
bool SynthesizeSugarOnTypes = false ;
40
45
bool DisplayDebuggerGeneratedModule = true ;
@@ -52,6 +57,8 @@ struct DemangleOptions {
52
57
bool ShortenArchetype = false ;
53
58
bool ShowPrivateDiscriminators = true ;
54
59
bool ShowFunctionArgumentTypes = true ;
60
+ std::function<std::string(uint64_t , uint64_t )> GenericParameterName =
61
+ genericParameterName;
55
62
56
63
DemangleOptions () {}
57
64
@@ -142,32 +149,38 @@ class Node {
142
149
friend class NodeFactory ;
143
150
144
151
private:
145
- Kind NodeKind;
146
152
147
- enum class PayloadKind : uint8_t {
148
- None, Text, Index
153
+ struct NodeVector {
154
+ NodePointer *Nodes;
155
+ uint32_t Number = 0 ;
156
+ uint32_t Capacity = 0 ;
149
157
};
150
- PayloadKind NodePayloadKind;
151
158
152
159
union {
153
- llvm::StringRef TextPayload;
154
- IndexType IndexPayload;
160
+ llvm::StringRef Text;
161
+ IndexType Index;
162
+ NodePointer InlineChildren[2 ];
163
+ NodeVector Children;
155
164
};
156
165
157
- NodePointer *Children = nullptr ;
158
- size_t NumChildren = 0 ;
159
- size_t ReservedChildren = 0 ;
166
+
167
+ Kind NodeKind;
168
+
169
+ enum class PayloadKind : uint8_t {
170
+ None, Text, Index, OneChild, TwoChildren, ManyChildren
171
+ };
172
+ PayloadKind NodePayloadKind;
160
173
161
174
Node (Kind k)
162
175
: NodeKind(k), NodePayloadKind(PayloadKind::None) {
163
176
}
164
177
Node (Kind k, llvm::StringRef t)
165
178
: NodeKind(k), NodePayloadKind(PayloadKind::Text) {
166
- TextPayload = t;
179
+ Text = t;
167
180
}
168
181
Node (Kind k, IndexType index)
169
182
: NodeKind(k), NodePayloadKind(PayloadKind::Index) {
170
- IndexPayload = index;
183
+ Index = index;
171
184
}
172
185
Node (const Node &) = delete ;
173
186
Node &operator =(const Node &) = delete ;
@@ -178,37 +191,33 @@ class Node {
178
191
bool hasText () const { return NodePayloadKind == PayloadKind::Text; }
179
192
llvm::StringRef getText () const {
180
193
assert (hasText ());
181
- return TextPayload ;
194
+ return Text ;
182
195
}
183
196
184
197
bool hasIndex () const { return NodePayloadKind == PayloadKind::Index; }
185
198
uint64_t getIndex () const {
186
199
assert (hasIndex ());
187
- return IndexPayload ;
200
+ return Index ;
188
201
}
189
202
190
- using iterator = NodePointer *;
191
- using const_iterator = const NodePointer *;
192
- using size_type = size_t ;
203
+ using iterator = const NodePointer *;
204
+
205
+ size_t getNumChildren () const ;
193
206
194
- bool hasChildren () const { return NumChildren != 0 ; }
195
- size_t getNumChildren () const { return NumChildren; }
196
- iterator begin () { return Children; }
197
- iterator end () { return Children + NumChildren; }
198
- const_iterator begin () const { return Children; }
199
- const_iterator end () const { return Children + NumChildren; }
207
+ bool hasChildren () const { return getNumChildren () != 0 ; }
208
+
209
+ iterator begin () const ;
210
+
211
+ iterator end () const ;
200
212
201
213
NodePointer getFirstChild () const {
202
- assert (NumChildren >= 1 );
203
- return Children[0 ];
214
+ return getChild (0 );
204
215
}
205
216
NodePointer getChild (size_t index) const {
206
- assert (NumChildren > index);
207
- return Children [index];
217
+ assert (getNumChildren () > index);
218
+ return begin () [index];
208
219
}
209
220
210
- // inline void addChild(NodePointer Child, Context &Ctx);
211
-
212
221
// Only to be used by the demangler parsers.
213
222
void addChild (NodePointer Child, NodeFactory &Factory);
214
223
// Only to be used by the demangler parsers.
@@ -344,17 +353,19 @@ class Context {
344
353
// / prefix: _T, _T0, $S, _$S.
345
354
// /
346
355
// / \returns The demangled string.
347
- std::string demangleSymbolAsString (llvm::StringRef MangledName,
348
- const DemangleOptions &Options = DemangleOptions());
356
+ std::string demangleSymbolAsString (
357
+ llvm::StringRef MangledName,
358
+ const DemangleOptions &Options = DemangleOptions());
349
359
350
360
// / Demangle the given type and return the readable name.
351
361
// /
352
362
// / \param MangledName The mangled type string, which does _not_ start with
353
363
// / a mangling prefix.
354
364
// /
355
365
// / \returns The demangled string.
356
- std::string demangleTypeAsString (llvm::StringRef MangledName,
357
- const DemangleOptions &Options = DemangleOptions());
366
+ std::string
367
+ demangleTypeAsString (llvm::StringRef MangledName,
368
+ const DemangleOptions &Options = DemangleOptions());
358
369
359
370
// / Returns true if the mangledName refers to a thunk function.
360
371
// /
@@ -473,7 +484,7 @@ void mangleIdentifier(const char *data, size_t length,
473
484
// / Remangle a demangled parse tree.
474
485
// /
475
486
// / This should always round-trip perfectly with demangleSymbolAsNode.
476
- std::string mangleNode (const NodePointer & root);
487
+ std::string mangleNode (NodePointer root);
477
488
478
489
using SymbolicResolver =
479
490
llvm::function_ref<Demangle::NodePointer (SymbolicReferenceKind,
@@ -483,13 +494,13 @@ using SymbolicResolver =
483
494
// / symbolic references.
484
495
// /
485
496
// / This should always round-trip perfectly with demangleSymbolAsNode.
486
- std::string mangleNode (const NodePointer & root, SymbolicResolver resolver);
497
+ std::string mangleNode (NodePointer root, SymbolicResolver resolver);
487
498
488
499
// / Remangle in the old mangling scheme.
489
500
// /
490
501
// / This is only used for objc-runtime names and should be removed as soon as
491
502
// / we switch to the new mangling for those names as well.
492
- std::string mangleNodeOld (const NodePointer & root);
503
+ std::string mangleNodeOld (NodePointer root);
493
504
494
505
// / Transform the node structure to a string.
495
506
// /
@@ -569,7 +580,6 @@ bool nodeConsumesGenericArgs(Node *node);
569
580
bool isSpecialized (Node *node);
570
581
571
582
NodePointer getUnspecialized (Node *node, NodeFactory &Factory);
572
- std::string archetypeName (Node::IndexType index, Node::IndexType depth);
573
583
574
584
// / Form a StringRef around the mangled name starting at base, if the name may
575
585
// / contain symbolic references.
0 commit comments