@@ -75,7 +75,7 @@ struct DemangleOptions {
75
75
};
76
76
77
77
class Node ;
78
- typedef std::shared_ptr< Node> NodePointer;
78
+ typedef Node * NodePointer;
79
79
80
80
enum class FunctionSigSpecializationParamKind : unsigned {
81
81
// Option Flags use bits 0-5. This give us 6 bits implying 64 entries to
@@ -123,11 +123,10 @@ enum class Directness {
123
123
Direct, Indirect
124
124
};
125
125
126
- struct NodeFactory ;
126
+ class NodeFactory ;
127
127
class Context ;
128
128
129
-
130
- class Node : public std ::enable_shared_from_this<Node> {
129
+ class Node {
131
130
public:
132
131
enum class Kind : uint16_t {
133
132
#define NODE (ID ) ID,
@@ -136,6 +135,8 @@ class Node : public std::enable_shared_from_this<Node> {
136
135
137
136
typedef uint64_t IndexType;
138
137
138
+ friend class NodeFactory ;
139
+
139
140
private:
140
141
Kind NodeKind;
141
142
@@ -145,20 +146,20 @@ class Node : public std::enable_shared_from_this<Node> {
145
146
PayloadKind NodePayloadKind;
146
147
147
148
union {
148
- std::string TextPayload;
149
+ llvm::StringRef TextPayload;
149
150
IndexType IndexPayload;
150
151
};
151
152
152
- // FIXME: use allocator.
153
- typedef std::vector<NodePointer> NodeVector ;
154
- NodeVector Children ;
153
+ NodePointer *Children = nullptr ;
154
+ size_t NumChildren = 0 ;
155
+ size_t ReservedChildren = 0 ;
155
156
156
157
Node (Kind k)
157
158
: NodeKind(k), NodePayloadKind(PayloadKind::None) {
158
159
}
159
- Node (Kind k, std::string && t)
160
+ Node (Kind k, llvm::StringRef t)
160
161
: NodeKind(k), NodePayloadKind(PayloadKind::Text) {
161
- new (& TextPayload) std::string ( std::move (t)) ;
162
+ TextPayload = t ;
162
163
}
163
164
Node (Kind k, IndexType index)
164
165
: NodeKind(k), NodePayloadKind(PayloadKind::Index) {
@@ -167,15 +168,11 @@ class Node : public std::enable_shared_from_this<Node> {
167
168
Node (const Node &) = delete ;
168
169
Node &operator =(const Node &) = delete ;
169
170
170
- friend struct NodeFactory ;
171
-
172
171
public:
173
- ~Node ();
174
-
175
172
Kind getKind () const { return NodeKind; }
176
173
177
174
bool hasText () const { return NodePayloadKind == PayloadKind::Text; }
178
- const std::string & getText () const {
175
+ llvm::StringRef getText () const {
179
176
assert (hasText ());
180
177
return TextPayload;
181
178
}
@@ -186,37 +183,29 @@ class Node : public std::enable_shared_from_this<Node> {
186
183
return IndexPayload;
187
184
}
188
185
189
- typedef NodeVector::iterator iterator;
190
- typedef NodeVector::const_iterator const_iterator;
191
- typedef NodeVector::size_type size_type;
192
-
193
- bool hasChildren () const { return !Children.empty (); }
194
- size_t getNumChildren () const { return Children.size (); }
195
- iterator begin () { return Children.begin (); }
196
- iterator end () { return Children.end (); }
197
- const_iterator begin () const { return Children.begin (); }
198
- const_iterator end () const { return Children.end (); }
199
-
200
- NodePointer getFirstChild () const { return Children.front (); }
201
- NodePointer getChild (size_t index) const { return Children[index]; }
202
-
203
- // / Deprecated - use addChild(NodePointer Child, Context &Ctx) instead.
204
- NodePointer addChild (NodePointer child) {
205
- assert (child && " adding null child!" );
206
- Children.push_back (child);
207
- return child;
186
+ typedef NodePointer *iterator;
187
+ typedef const NodePointer *const_iterator;
188
+ typedef size_t size_type;
189
+
190
+ bool hasChildren () const { return NumChildren != 0 ; }
191
+ size_t getNumChildren () const { return NumChildren; }
192
+ iterator begin () { return Children; }
193
+ iterator end () { return Children + NumChildren; }
194
+ const_iterator begin () const { return Children; }
195
+ const_iterator end () const { return Children + NumChildren; }
196
+
197
+ NodePointer getFirstChild () const {
198
+ assert (NumChildren >= 1 );
199
+ return Children[0 ];
208
200
}
209
-
210
- // / Deprecated - use addChild(NodePointer Child, Context &Ctx) instead.
211
- void addChildren (NodePointer child1, NodePointer child2) {
212
- addChild (std::move (child1));
213
- addChild (std::move (child2));
201
+ NodePointer getChild (size_t index) const {
202
+ assert (NumChildren > index);
203
+ return Children[index];
214
204
}
215
205
216
- // / Add a new node as a child of this one.
217
206
void addChild (NodePointer Child, Context &Ctx);
218
207
219
- // / Add a new node as a child of this one .
208
+ // Only to be used by the demangler parsers .
220
209
void addChild (NodePointer Child, NodeFactory &Factory);
221
210
};
222
211
@@ -245,6 +234,8 @@ class Demangler;
245
234
// / allocations.
246
235
// /
247
236
class Context {
237
+ Demangler *D;
238
+
248
239
friend class Node ;
249
240
250
241
public:
@@ -360,33 +351,6 @@ demangleSymbolAsString(llvm::StringRef MangledName,
360
351
MangledName.size (), Options);
361
352
}
362
353
363
- // / Deprecated - use Context::demangleTypeAsNode instead.
364
- NodePointer
365
- demangleTypeAsNode (const char *mangledName, size_t mangledNameLength,
366
- const DemangleOptions &options = DemangleOptions());
367
-
368
- // / Deprecated - use Context::demangleTypeAsNode instead.
369
- inline NodePointer
370
- demangleTypeAsNode (const std::string &mangledName,
371
- const DemangleOptions &options = DemangleOptions()) {
372
- return demangleTypeAsNode (mangledName.data (), mangledName.size (), options);
373
- }
374
-
375
- // / Deprecated - use Context::isThunkSymbol instead.
376
- bool isThunkSymbol (const char *mangledName, size_t mangledNameLength);
377
-
378
- // / Deprecated - use Context::demangleSymbolAsNode instead.
379
- NodePointer
380
- demangleSymbolAsNode (const char *mangledName, size_t mangledNameLength,
381
- const DemangleOptions &options = DemangleOptions());
382
-
383
- // / Deprecated - use Context::demangleSymbolAsNode instead.
384
- inline NodePointer
385
- demangleSymbolAsNode (const std::string &mangledName,
386
- const DemangleOptions &options = DemangleOptions()) {
387
- return demangleSymbolAsNode (mangledName.data (), mangledName.size (), options);
388
- }
389
-
390
354
// / Standalong utility function to demangle the given type as string.
391
355
// /
392
356
// / If performance is an issue when demangling multiple symbols,
@@ -465,26 +429,6 @@ inline std::string mangleNode(const NodePointer &root, bool NewMangling) {
465
429
std::string nodeToString (NodePointer Root,
466
430
const DemangleOptions &Options = DemangleOptions());
467
431
468
- // / Deprecated - use Context::createNode instead.
469
- struct NodeFactory {
470
- static NodePointer create (Node::Kind K) {
471
- return NodePointer (new Node (K));
472
- }
473
- static NodePointer create (Node::Kind K, Node::IndexType Index) {
474
- return NodePointer (new Node (K, Index));
475
- }
476
- static NodePointer create (Node::Kind K, llvm::StringRef Text) {
477
- return NodePointer (new Node (K, Text));
478
- }
479
- static NodePointer create (Node::Kind K, std::string &&Text) {
480
- return NodePointer (new Node (K, std::move (Text)));
481
- }
482
- template <size_t N>
483
- static NodePointer create (Node::Kind K, const char (&Text)[N]) {
484
- return NodePointer (new Node (K, llvm::StringRef (Text)));
485
- }
486
- };
487
-
488
432
// / A class for printing to a std::string.
489
433
class DemanglerPrinter {
490
434
public:
@@ -532,7 +476,7 @@ class DemanglerPrinter {
532
476
533
477
bool mangleStandardSubstitution (Node *node, DemanglerPrinter &Out);
534
478
bool isSpecialized (Node *node);
535
- NodePointer getUnspecialized (Node *node);
479
+ NodePointer getUnspecialized (Node *node, NodeFactory &Factory );
536
480
537
481
// / Is a character considered a digit by the demangling grammar?
538
482
// /
0 commit comments