LLVM 20.0.0git
MicrosoftDemangleNodes.h
Go to the documentation of this file.
1//===- MicrosoftDemangleNodes.h ---------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines the AST nodes used in the MSVC demangler.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_DEMANGLE_MICROSOFTDEMANGLENODES_H
14#define LLVM_DEMANGLE_MICROSOFTDEMANGLENODES_H
15
16#include <array>
17#include <cstdint>
18#include <string>
19#include <string_view>
20
21namespace llvm {
22namespace itanium_demangle {
23class OutputBuffer;
24}
25}
26
27using llvm::itanium_demangle::OutputBuffer;
28
29namespace llvm {
30namespace ms_demangle {
31
32// Storage classes
33enum Qualifiers : uint8_t {
34 Q_None = 0,
35 Q_Const = 1 << 0,
36 Q_Volatile = 1 << 1,
37 Q_Far = 1 << 2,
38 Q_Huge = 1 << 3,
39 Q_Unaligned = 1 << 4,
40 Q_Restrict = 1 << 5,
41 Q_Pointer64 = 1 << 6
42};
43
44enum class StorageClass : uint8_t {
45 None,
49 Global,
51};
52
55
56// Calling conventions
57enum class CallingConv : uint8_t {
58 None,
59 Cdecl,
60 Pascal,
62 Stdcall,
64 Clrcall,
65 Eabi,
67 Regcall,
68 Swift, // Clang-only
69 SwiftAsync, // Clang-only
70};
71
72enum class ReferenceKind : uint8_t { None, LValueRef, RValueRef };
73
82};
83
84// Types
85enum class PrimitiveKind {
86 Void,
87 Bool,
88 Char,
89 Schar,
90 Uchar,
91 Char8,
92 Char16,
93 Char32,
94 Short,
95 Ushort,
96 Int,
97 Uint,
98 Long,
99 Ulong,
100 Int64,
101 Uint64,
102 Wchar,
103 Float,
104 Double,
105 Ldouble,
106 Nullptr,
107};
108
109enum class CharKind {
110 Char,
111 Char16,
112 Char32,
113 Wchar,
114};
115
116enum class IntrinsicFunctionKind : uint8_t {
117 None,
118 New, // ?2 # operator new
119 Delete, // ?3 # operator delete
120 Assign, // ?4 # operator=
121 RightShift, // ?5 # operator>>
122 LeftShift, // ?6 # operator<<
123 LogicalNot, // ?7 # operator!
124 Equals, // ?8 # operator==
125 NotEquals, // ?9 # operator!=
126 ArraySubscript, // ?A # operator[]
127 Pointer, // ?C # operator->
128 Dereference, // ?D # operator*
129 Increment, // ?E # operator++
130 Decrement, // ?F # operator--
131 Minus, // ?G # operator-
132 Plus, // ?H # operator+
133 BitwiseAnd, // ?I # operator&
134 MemberPointer, // ?J # operator->*
135 Divide, // ?K # operator/
136 Modulus, // ?L # operator%
137 LessThan, // ?M operator<
138 LessThanEqual, // ?N operator<=
139 GreaterThan, // ?O operator>
140 GreaterThanEqual, // ?P operator>=
141 Comma, // ?Q operator,
142 Parens, // ?R operator()
143 BitwiseNot, // ?S operator~
144 BitwiseXor, // ?T operator^
145 BitwiseOr, // ?U operator|
146 LogicalAnd, // ?V operator&&
147 LogicalOr, // ?W operator||
148 TimesEqual, // ?X operator*=
149 PlusEqual, // ?Y operator+=
150 MinusEqual, // ?Z operator-=
151 DivEqual, // ?_0 operator/=
152 ModEqual, // ?_1 operator%=
153 RshEqual, // ?_2 operator>>=
154 LshEqual, // ?_3 operator<<=
155 BitwiseAndEqual, // ?_4 operator&=
156 BitwiseOrEqual, // ?_5 operator|=
157 BitwiseXorEqual, // ?_6 operator^=
158 VbaseDtor, // ?_D # vbase destructor
159 VecDelDtor, // ?_E # vector deleting destructor
160 DefaultCtorClosure, // ?_F # default constructor closure
161 ScalarDelDtor, // ?_G # scalar deleting destructor
162 VecCtorIter, // ?_H # vector constructor iterator
163 VecDtorIter, // ?_I # vector destructor iterator
164 VecVbaseCtorIter, // ?_J # vector vbase constructor iterator
165 VdispMap, // ?_K # virtual displacement map
166 EHVecCtorIter, // ?_L # eh vector constructor iterator
167 EHVecDtorIter, // ?_M # eh vector destructor iterator
168 EHVecVbaseCtorIter, // ?_N # eh vector vbase constructor iterator
169 CopyCtorClosure, // ?_O # copy constructor closure
170 LocalVftableCtorClosure, // ?_T # local vftable constructor closure
171 ArrayNew, // ?_U operator new[]
172 ArrayDelete, // ?_V operator delete[]
173 ManVectorCtorIter, // ?__A managed vector ctor iterator
174 ManVectorDtorIter, // ?__B managed vector dtor iterator
175 EHVectorCopyCtorIter, // ?__C EH vector copy ctor iterator
176 EHVectorVbaseCopyCtorIter, // ?__D EH vector vbase copy ctor iterator
177 VectorCopyCtorIter, // ?__G vector copy constructor iterator
178 VectorVbaseCopyCtorIter, // ?__H vector vbase copy constructor iterator
179 ManVectorVbaseCopyCtorIter, // ?__I managed vector vbase copy constructor
180 CoAwait, // ?__L operator co_await
181 Spaceship, // ?__M operator<=>
183};
184
186 None,
187 Vftable,
188 Vbtable,
189 Typeof,
194 Unknown,
204};
205
206// Function classes
209 FC_Public = 1 << 0,
210 FC_Protected = 1 << 1,
211 FC_Private = 1 << 2,
212 FC_Global = 1 << 3,
213 FC_Static = 1 << 4,
214 FC_Virtual = 1 << 5,
215 FC_Far = 1 << 6,
216 FC_ExternC = 1 << 7,
221};
222
223enum class TagKind { Class, Struct, Union, Enum };
224
225enum class NodeKind {
226 Unknown,
227 Md5Symbol,
241 TagType,
242 ArrayType,
243 Custom,
245 NodeArray,
255};
256
257struct Node {
258 explicit Node(NodeKind K) : Kind(K) {}
259 virtual ~Node() = default;
260
261 NodeKind kind() const { return Kind; }
262
263 virtual void output(OutputBuffer &OB, OutputFlags Flags) const = 0;
264
265 std::string toString(OutputFlags Flags = OF_Default) const;
266
267private:
268 NodeKind Kind;
269};
270
271struct TypeNode;
272struct PrimitiveTypeNode;
274struct IdentifierNode;
281struct ThunkSignatureNode;
282struct PointerTypeNode;
283struct ArrayTypeNode;
284struct TagTypeNode;
285struct NodeArrayNode;
286struct QualifiedNameNode;
289struct IntegerLiteralNode;
292struct SymbolNode;
293struct FunctionSymbolNode;
294struct VariableSymbolNode;
296
297struct TypeNode : public Node {
298 explicit TypeNode(NodeKind K) : Node(K) {}
299
300 virtual void outputPre(OutputBuffer &OB, OutputFlags Flags) const = 0;
301 virtual void outputPost(OutputBuffer &OB, OutputFlags Flags) const = 0;
302
303 void output(OutputBuffer &OB, OutputFlags Flags) const override {
304 outputPre(OB, Flags);
305 outputPost(OB, Flags);
306 }
307
309};
310
314
315 void outputPre(OutputBuffer &OB, OutputFlags Flags) const override;
316 void outputPost(OutputBuffer &OB, OutputFlags Flags) const override {}
317
319};
320
324
325 void outputPre(OutputBuffer &OB, OutputFlags Flags) const override;
326 void outputPost(OutputBuffer &OB, OutputFlags Flags) const override;
327
328 // Valid if this FunctionTypeNode is the Pointee of a PointerType or
329 // MemberPointerType.
331
332 // The function's calling convention.
334
335 // Function flags (global, public, etc)
337
339
340 // The return type of the function.
342
343 // True if this is a C-style ... varargs function.
344 bool IsVariadic = false;
345
346 // Function parameters
348
349 // True if the function type is noexcept.
350 bool IsNoexcept = false;
351};
352
353struct IdentifierNode : public Node {
354 explicit IdentifierNode(NodeKind K) : Node(K) {}
355
357
358protected:
360};
361
364
365 void output(OutputBuffer &OB, OutputFlags Flags) const override;
366
368};
369
373
374 void output(OutputBuffer &OB, OutputFlags Flags) const override;
375
378 bool IsDestructor = false;
379};
380
383
384 void output(OutputBuffer &OB, OutputFlags Flags) const override;
385
386 std::string_view Name;
387};
388
393
394 void output(OutputBuffer &OB, OutputFlags Flags) const override;
395
397};
398
402
403 void output(OutputBuffer &OB, OutputFlags Flags) const override;
404
405 std::string_view Name;
406};
407
411
412 void output(OutputBuffer &OB, OutputFlags Flags) const override;
413
414 bool IsThread = false;
416};
417
421
422 void output(OutputBuffer &OB, OutputFlags Flags) const override;
423
424 // The type that this operator converts too.
426};
427
433
434 void output(OutputBuffer &OB, OutputFlags Flags) const override;
435
436 // The name of the class that this is a structor of.
438 bool IsDestructor = false;
439};
440
443
444 void outputPre(OutputBuffer &OB, OutputFlags Flags) const override;
445 void outputPost(OutputBuffer &OB, OutputFlags Flags) const override;
446
449 int32_t VBPtrOffset = 0;
450 int32_t VBOffsetOffset = 0;
451 int32_t VtordispOffset = 0;
452 };
453
455};
456
457struct PointerTypeNode : public TypeNode {
459 void outputPre(OutputBuffer &OB, OutputFlags Flags) const override;
460 void outputPost(OutputBuffer &OB, OutputFlags Flags) const override;
461
462 // Is this a pointer, reference, or rvalue-reference?
464
465 // If this is a member pointer, this is the class that the member is in.
467
468 // Represents a type X in "a pointer to X", "a reference to X", or
469 // "rvalue-reference to X"
470 TypeNode *Pointee = nullptr;
471};
472
473struct TagTypeNode : public TypeNode {
475
476 void outputPre(OutputBuffer &OB, OutputFlags Flags) const override;
477 void outputPost(OutputBuffer &OB, OutputFlags Flags) const override;
478
481};
482
483struct ArrayTypeNode : public TypeNode {
485
486 void outputPre(OutputBuffer &OB, OutputFlags Flags) const override;
487 void outputPost(OutputBuffer &OB, OutputFlags Flags) const override;
488
489 void outputDimensionsImpl(OutputBuffer &OB, OutputFlags Flags) const;
490 void outputOneDimension(OutputBuffer &OB, OutputFlags Flags, Node *N) const;
491
492 // A list of array dimensions. e.g. [3,4,5] in `int Foo[3][4][5]`
494
495 // The type of array element.
497};
498
499struct IntrinsicNode : public TypeNode {
501 void output(OutputBuffer &OB, OutputFlags Flags) const override {}
502};
503
504struct CustomTypeNode : public TypeNode {
506
507 void outputPre(OutputBuffer &OB, OutputFlags Flags) const override;
508 void outputPost(OutputBuffer &OB, OutputFlags Flags) const override;
509
511};
512
513struct NodeArrayNode : public Node {
515
516 void output(OutputBuffer &OB, OutputFlags Flags) const override;
517
518 void output(OutputBuffer &OB, OutputFlags Flags,
519 std::string_view Separator) const;
520
521 Node **Nodes = nullptr;
522 size_t Count = 0;
523};
524
525struct QualifiedNameNode : public Node {
527
528 void output(OutputBuffer &OB, OutputFlags Flags) const override;
529
531
533 Node *LastComponent = Components->Nodes[Components->Count - 1];
534 return static_cast<IdentifierNode *>(LastComponent);
535 }
536};
537
541
542 void output(OutputBuffer &OB, OutputFlags Flags) const override;
543
544 SymbolNode *Symbol = nullptr;
545
547 std::array<int64_t, 3> ThunkOffsets;
549 bool IsMemberPointer = false;
550};
551
552struct IntegerLiteralNode : public Node {
556
557 void output(OutputBuffer &OB, OutputFlags Flags) const override;
558
560 bool IsNegative = false;
561};
562
566
567 void output(OutputBuffer &OB, OutputFlags Flags) const override;
568
570 int32_t VBPtrOffset = 0;
573};
574
575struct SymbolNode : public Node {
576 explicit SymbolNode(NodeKind K) : Node(K) {}
577 void output(OutputBuffer &OB, OutputFlags Flags) const override;
579};
580
584
585 void output(OutputBuffer &OB, OutputFlags Flags) const override;
588};
589
593
594 void output(OutputBuffer &OB, OutputFlags Flags) const override;
595
596 bool IsVisible = false;
597};
598
601
602 void output(OutputBuffer &OB, OutputFlags Flags) const override;
603
604 std::string_view DecodedString;
605 bool IsTruncated = false;
607};
608
611
612 void output(OutputBuffer &OB, OutputFlags Flags) const override;
613
615 TypeNode *Type = nullptr;
616};
617
620
621 void output(OutputBuffer &OB, OutputFlags Flags) const override;
622
624};
625
626} // namespace ms_demangle
627} // namespace llvm
628
629#endif
Class to represent array types.
Definition: DerivedTypes.h:371
This is a utility class that provides an abstraction for the common functionality between Instruction...
Definition: Operator.h:32
Class to represent pointers.
Definition: DerivedTypes.h:646
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
LLVM Value Representation.
Definition: Value.h:74
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
#define N
Determine the kind of a node from its type.
void outputPost(OutputBuffer &OB, OutputFlags Flags) const override
void outputOneDimension(OutputBuffer &OB, OutputFlags Flags, Node *N) const
void outputPre(OutputBuffer &OB, OutputFlags Flags) const override
void outputDimensionsImpl(OutputBuffer &OB, OutputFlags Flags) const
void output(OutputBuffer &OB, OutputFlags Flags) const override
void outputPost(OutputBuffer &OB, OutputFlags Flags) const override
void outputPre(OutputBuffer &OB, OutputFlags Flags) const override
void output(OutputBuffer &OB, OutputFlags Flags) const override
void output(OutputBuffer &OB, OutputFlags Flags) const override
void outputPre(OutputBuffer &OB, OutputFlags Flags) const override
void outputPost(OutputBuffer &OB, OutputFlags Flags) const override
void output(OutputBuffer &OB, OutputFlags Flags) const override
void outputTemplateParameters(OutputBuffer &OB, OutputFlags Flags) const
IntegerLiteralNode(uint64_t Value, bool IsNegative)
void output(OutputBuffer &OB, OutputFlags Flags) const override
IntrinsicFunctionIdentifierNode(IntrinsicFunctionKind Operator)
void output(OutputBuffer &OB, OutputFlags Flags) const override
void output(OutputBuffer &OB, OutputFlags Flags) const override
void output(OutputBuffer &OB, OutputFlags Flags) const override
void output(OutputBuffer &OB, OutputFlags Flags) const override
void output(OutputBuffer &OB, OutputFlags Flags) const override
void output(OutputBuffer &OB, OutputFlags Flags) const override
void output(OutputBuffer &OB, OutputFlags Flags) const override
virtual void output(OutputBuffer &OB, OutputFlags Flags) const =0
virtual ~Node()=default
std::string toString(OutputFlags Flags=OF_Default) const
void outputPost(OutputBuffer &OB, OutputFlags Flags) const override
void outputPre(OutputBuffer &OB, OutputFlags Flags) const override
void outputPre(OutputBuffer &OB, OutputFlags Flags) const override
void outputPost(OutputBuffer &OB, OutputFlags Flags) const override
void output(OutputBuffer &OB, OutputFlags Flags) const override
void output(OutputBuffer &OB, OutputFlags Flags) const override
void output(OutputBuffer &OB, OutputFlags Flags) const override
void output(OutputBuffer &OB, OutputFlags Flags) const override
void output(OutputBuffer &OB, OutputFlags Flags) const override
void outputPost(OutputBuffer &OB, OutputFlags Flags) const override
void outputPre(OutputBuffer &OB, OutputFlags Flags) const override
void output(OutputBuffer &OB, OutputFlags Flags) const override
void outputPost(OutputBuffer &OB, OutputFlags Flags) const override
void outputPre(OutputBuffer &OB, OutputFlags Flags) const override
void output(OutputBuffer &OB, OutputFlags Flags) const override
virtual void outputPre(OutputBuffer &OB, OutputFlags Flags) const =0
virtual void outputPost(OutputBuffer &OB, OutputFlags Flags) const =0
void output(OutputBuffer &OB, OutputFlags Flags) const override
void output(OutputBuffer &OB, OutputFlags Flags) const override