LLVM  8.0.0svn
MicrosoftDemangleNodes.h
Go to the documentation of this file.
1 #ifndef LLVM_SUPPORT_MICROSOFTDEMANGLENODES_H
2 #define LLVM_SUPPORT_MICROSOFTDEMANGLENODES_H
3 
6 #include <array>
7 
8 class OutputStream;
9 
10 namespace llvm {
11 namespace ms_demangle {
12 
13 // Storage classes
14 enum Qualifiers : uint8_t {
15  Q_None = 0,
16  Q_Const = 1 << 0,
17  Q_Volatile = 1 << 1,
18  Q_Far = 1 << 2,
19  Q_Huge = 1 << 3,
20  Q_Unaligned = 1 << 4,
21  Q_Restrict = 1 << 5,
22  Q_Pointer64 = 1 << 6
23 };
24 
25 enum class StorageClass : uint8_t {
26  None,
30  Global,
32 };
33 
35 enum class FunctionRefQualifier { None, Reference, RValueReference };
36 
37 // Calling conventions
38 enum class CallingConv : uint8_t {
39  None,
40  Cdecl,
41  Pascal,
42  Thiscall,
43  Stdcall,
44  Fastcall,
45  Clrcall,
46  Eabi,
47  Vectorcall,
48  Regcall,
49 };
50 
51 enum class ReferenceKind : uint8_t { None, LValueRef, RValueRef };
52 
56 };
57 
58 // Types
59 enum class PrimitiveKind {
60  Void,
61  Bool,
62  Char,
63  Schar,
64  Uchar,
65  Char16,
66  Char32,
67  Short,
68  Ushort,
69  Int,
70  Uint,
71  Long,
72  Ulong,
73  Int64,
74  Uint64,
75  Wchar,
76  Float,
77  Double,
78  Ldouble,
79  Nullptr,
80 };
81 
82 enum class CharKind {
83  Char,
84  Char16,
85  Char32,
86  Wchar,
87 };
88 
89 enum class IntrinsicFunctionKind : uint8_t {
90  None,
91  New, // ?2 # operator new
92  Delete, // ?3 # operator delete
93  Assign, // ?4 # operator=
94  RightShift, // ?5 # operator>>
95  LeftShift, // ?6 # operator<<
96  LogicalNot, // ?7 # operator!
97  Equals, // ?8 # operator==
98  NotEquals, // ?9 # operator!=
99  ArraySubscript, // ?A # operator[]
100  Pointer, // ?C # operator->
101  Dereference, // ?D # operator*
102  Increment, // ?E # operator++
103  Decrement, // ?F # operator--
104  Minus, // ?G # operator-
105  Plus, // ?H # operator+
106  BitwiseAnd, // ?I # operator&
107  MemberPointer, // ?J # operator->*
108  Divide, // ?K # operator/
109  Modulus, // ?L # operator%
110  LessThan, // ?M operator<
111  LessThanEqual, // ?N operator<=
112  GreaterThan, // ?O operator>
113  GreaterThanEqual, // ?P operator>=
114  Comma, // ?Q operator,
115  Parens, // ?R operator()
116  BitwiseNot, // ?S operator~
117  BitwiseXor, // ?T operator^
118  BitwiseOr, // ?U operator|
119  LogicalAnd, // ?V operator&&
120  LogicalOr, // ?W operator||
121  TimesEqual, // ?X operator*=
122  PlusEqual, // ?Y operator+=
123  MinusEqual, // ?Z operator-=
124  DivEqual, // ?_0 operator/=
125  ModEqual, // ?_1 operator%=
126  RshEqual, // ?_2 operator>>=
127  LshEqual, // ?_3 operator<<=
128  BitwiseAndEqual, // ?_4 operator&=
129  BitwiseOrEqual, // ?_5 operator|=
130  BitwiseXorEqual, // ?_6 operator^=
131  VbaseDtor, // ?_D # vbase destructor
132  VecDelDtor, // ?_E # vector deleting destructor
133  DefaultCtorClosure, // ?_F # default constructor closure
134  ScalarDelDtor, // ?_G # scalar deleting destructor
135  VecCtorIter, // ?_H # vector constructor iterator
136  VecDtorIter, // ?_I # vector destructor iterator
137  VecVbaseCtorIter, // ?_J # vector vbase constructor iterator
138  VdispMap, // ?_K # virtual displacement map
139  EHVecCtorIter, // ?_L # eh vector constructor iterator
140  EHVecDtorIter, // ?_M # eh vector destructor iterator
141  EHVecVbaseCtorIter, // ?_N # eh vector vbase constructor iterator
142  CopyCtorClosure, // ?_O # copy constructor closure
143  LocalVftableCtorClosure, // ?_T # local vftable constructor closure
144  ArrayNew, // ?_U operator new[]
145  ArrayDelete, // ?_V operator delete[]
146  ManVectorCtorIter, // ?__A managed vector ctor iterator
147  ManVectorDtorIter, // ?__B managed vector dtor iterator
148  EHVectorCopyCtorIter, // ?__C EH vector copy ctor iterator
149  EHVectorVbaseCopyCtorIter, // ?__D EH vector vbase copy ctor iterator
150  VectorCopyCtorIter, // ?__G vector copy constructor iterator
151  VectorVbaseCopyCtorIter, // ?__H vector vbase copy constructor iterator
152  ManVectorVbaseCopyCtorIter, // ?__I managed vector vbase copy constructor
153  CoAwait, // ?__L co_await
154  Spaceship, // operator<=>
156 };
157 
159  None,
160  Vftable,
161  Vbtable,
162  Typeof,
163  VcallThunk,
166  UdtReturning,
167  Unknown,
175  LocalVftable,
177 };
178 
179 // Function classes
180 enum FuncClass : uint16_t {
181  FC_None = 0,
182  FC_Public = 1 << 0,
183  FC_Protected = 1 << 1,
184  FC_Private = 1 << 2,
185  FC_Global = 1 << 3,
186  FC_Static = 1 << 4,
187  FC_Virtual = 1 << 5,
188  FC_Far = 1 << 6,
189  FC_ExternC = 1 << 7,
194 };
195 
196 enum class TagKind { Class, Struct, Union, Enum };
197 
198 enum class NodeKind {
199  Unknown,
200  Md5Symbol,
203  Identifier,
213  PointerType,
214  TagType,
215  ArrayType,
216  Custom,
218  NodeArray,
228 };
229 
230 struct Node {
231  explicit Node(NodeKind K) : Kind(K) {}
232  virtual ~Node() = default;
233 
234  NodeKind kind() const { return Kind; }
235 
236  virtual void output(OutputStream &OS, OutputFlags Flags) const = 0;
237 
238 private:
239  NodeKind Kind;
240 };
241 
242 struct TypeNode;
243 struct PrimitiveTypeNode;
244 struct FunctionSignatureNode;
245 struct IdentifierNode;
246 struct NamedIdentifierNode;
252 struct ThunkSignatureNode;
253 struct PointerTypeNode;
254 struct ArrayTypeNode;
255 struct CustomNode;
256 struct TagTypeNode;
257 struct IntrinsicTypeNode;
258 struct NodeArrayNode;
259 struct QualifiedNameNode;
262 struct IntegerLiteralNode;
265 struct SymbolNode;
266 struct FunctionSymbolNode;
267 struct VariableSymbolNode;
269 
270 struct TypeNode : public Node {
271  explicit TypeNode(NodeKind K) : Node(K) {}
272 
273  virtual void outputPre(OutputStream &OS, OutputFlags Flags) const = 0;
274  virtual void outputPost(OutputStream &OS, OutputFlags Flags) const = 0;
275 
276  void output(OutputStream &OS, OutputFlags Flags) const override {
277  outputPre(OS, Flags);
278  outputPost(OS, Flags);
279  }
280 
281  void outputQuals(bool SpaceBefore, bool SpaceAfter) const;
282 
284 };
285 
286 struct PrimitiveTypeNode : public TypeNode {
288  : TypeNode(NodeKind::PrimitiveType), PrimKind(K) {}
289 
290  void outputPre(OutputStream &OS, OutputFlags Flags) const;
291  void outputPost(OutputStream &OS, OutputFlags Flags) const {}
292 
294 };
295 
299 
300  void outputPre(OutputStream &OS, OutputFlags Flags) const override;
301  void outputPost(OutputStream &OS, OutputFlags Flags) const override;
302 
303  // Valid if this FunctionTypeNode is the Pointee of a PointerType or
304  // MemberPointerType.
306 
307  // The function's calling convention.
308  CallingConv CallConvention = CallingConv::None;
309 
310  // Function flags (gloabl, public, etc)
311  FuncClass FunctionClass = FC_Global;
312 
314 
315  // The return type of the function.
316  TypeNode *ReturnType = nullptr;
317 
318  // True if this is a C-style ... varargs function.
319  bool IsVariadic = false;
320 
321  // Function parameters
322  NodeArrayNode *Params = nullptr;
323 };
324 
325 struct IdentifierNode : public Node {
326  explicit IdentifierNode(NodeKind K) : Node(K) {}
327 
328  NodeArrayNode *TemplateParams = nullptr;
329 
330 protected:
331  void outputTemplateParameters(OutputStream &OS, OutputFlags Flags) const;
332 };
333 
336 
337  void output(OutputStream &OS, OutputFlags Flags) const override;
338 
339  uint64_t OffsetInVTable = 0;
340 };
341 
345 
346  void output(OutputStream &OS, OutputFlags Flags) const override;
347 
348  VariableSymbolNode *Variable = nullptr;
350  bool IsDestructor = false;
351 };
352 
355 
356  void output(OutputStream &OS, OutputFlags Flags) const override;
357 
359 };
360 
364  Operator(Operator) {}
365 
366  void output(OutputStream &OS, OutputFlags Flags) const override;
367 
369 };
370 
374 
375  void output(OutputStream &OS, OutputFlags Flags) const override;
376 
378 };
379 
383 
384  void output(OutputStream &OS, OutputFlags Flags) const override;
385 
386  uint32_t ScopeIndex = 0;
387 };
388 
392 
393  void output(OutputStream &OS, OutputFlags Flags) const override;
394 
395  // The type that this operator converts too.
396  TypeNode *TargetType = nullptr;
397 };
398 
401  explicit StructorIdentifierNode(bool IsDestructor)
403  IsDestructor(IsDestructor) {}
404 
405  void output(OutputStream &OS, OutputFlags Flags) const override;
406 
407  // The name of the class that this is a structor of.
408  IdentifierNode *Class = nullptr;
409  bool IsDestructor = false;
410 };
411 
414 
415  void outputPre(OutputStream &OS, OutputFlags Flags) const override;
416  void outputPost(OutputStream &OS, OutputFlags Flags) const override;
417 
418  struct ThisAdjustor {
419  uint32_t StaticOffset = 0;
420  int32_t VBPtrOffset = 0;
421  int32_t VBOffsetOffset = 0;
422  int32_t VtordispOffset = 0;
423  };
424 
426 };
427 
428 struct PointerTypeNode : public TypeNode {
430  void outputPre(OutputStream &OS, OutputFlags Flags) const override;
431  void outputPost(OutputStream &OS, OutputFlags Flags) const override;
432 
433  // Is this a pointer, reference, or rvalue-reference?
435 
436  // If this is a member pointer, this is the class that the member is in.
437  QualifiedNameNode *ClassParent = nullptr;
438 
439  // Represents a type X in "a pointer to X", "a reference to X", or
440  // "rvalue-reference to X"
441  TypeNode *Pointee = nullptr;
442 };
443 
444 struct TagTypeNode : public TypeNode {
445  explicit TagTypeNode(TagKind Tag) : TypeNode(NodeKind::TagType), Tag(Tag) {}
446 
447  void outputPre(OutputStream &OS, OutputFlags Flags) const;
448  void outputPost(OutputStream &OS, OutputFlags Flags) const;
449 
452 };
453 
454 struct ArrayTypeNode : public TypeNode {
456 
457  void outputPre(OutputStream &OS, OutputFlags Flags) const;
458  void outputPost(OutputStream &OS, OutputFlags Flags) const;
459 
460  void outputDimensionsImpl(OutputStream &OS, OutputFlags Flags) const;
461  void outputOneDimension(OutputStream &OS, OutputFlags Flags, Node *N) const;
462 
463  // A list of array dimensions. e.g. [3,4,5] in `int Foo[3][4][5]`
464  NodeArrayNode *Dimensions = nullptr;
465 
466  // The type of array element.
467  TypeNode *ElementType = nullptr;
468 };
469 
470 struct IntrinsicNode : public TypeNode {
472  void output(OutputStream &OS, OutputFlags Flags) const override {}
473 };
474 
475 struct CustomTypeNode : public TypeNode {
477 
478  void outputPre(OutputStream &OS, OutputFlags Flags) const override;
479  void outputPost(OutputStream &OS, OutputFlags Flags) const override;
480 
482 };
483 
484 struct NodeArrayNode : public Node {
486 
487  void output(OutputStream &OS, OutputFlags Flags) const override;
488 
489  void output(OutputStream &OS, OutputFlags Flags, StringView Separator) const;
490 
491  Node **Nodes = 0;
492  size_t Count = 0;
493 };
494 
495 struct QualifiedNameNode : public Node {
497 
498  void output(OutputStream &OS, OutputFlags Flags) const override;
499 
500  NodeArrayNode *Components = nullptr;
501 
503  Node *LastComponent = Components->Nodes[Components->Count - 1];
504  return static_cast<IdentifierNode *>(LastComponent);
505  }
506 };
507 
511 
512  void output(OutputStream &OS, OutputFlags Flags) const override;
513 
514  SymbolNode *Symbol = nullptr;
515 
516  int ThunkOffsetCount = 0;
517  std::array<int64_t, 3> ThunkOffsets;
519  bool IsMemberPointer = false;
520 };
521 
522 struct IntegerLiteralNode : public Node {
524  IntegerLiteralNode(uint64_t Value, bool IsNegative)
525  : Node(NodeKind::IntegerLiteral), Value(Value), IsNegative(IsNegative) {}
526 
527  void output(OutputStream &OS, OutputFlags Flags) const override;
528 
529  uint64_t Value = 0;
530  bool IsNegative = false;
531 };
532 
536 
537  void output(OutputStream &OS, OutputFlags Flags) const override;
538 
539  uint32_t NVOffset = 0;
540  int32_t VBPtrOffset = 0;
541  uint32_t VBTableOffset = 0;
542  uint32_t Flags = 0;
543 };
544 
545 struct SymbolNode : public Node {
546  explicit SymbolNode(NodeKind K) : Node(K) {}
547  void output(OutputStream &OS, OutputFlags Flags) const override;
549 };
550 
553  : SymbolNode(NodeKind::SpecialTableSymbol) {}
554 
555  void output(OutputStream &OS, OutputFlags Flags) const override;
556  QualifiedNameNode *TargetName = nullptr;
558 };
559 
563 
564  void output(OutputStream &OS, OutputFlags Flags) const override;
565 
566  bool IsVisible = false;
567 };
568 
571 
572  void output(OutputStream &OS, OutputFlags Flags) const override;
573 
575  bool IsTruncated = false;
577 };
578 
581 
582  void output(OutputStream &OS, OutputFlags Flags) const override;
583 
585  TypeNode *Type = nullptr;
586 };
587 
590 
591  void output(OutputStream &OS, OutputFlags Flags) const override;
592 
593  FunctionSignatureNode *Signature = nullptr;
594 };
595 
596 } // namespace ms_demangle
597 } // namespace llvm
598 
599 #endif
IntrinsicFunctionIdentifierNode(IntrinsicFunctionKind Operator)
This class represents lattice values for constants.
Definition: AllocatorList.h:24
void output(OutputStream &OS, OutputFlags Flags) const override
void output(OutputStream &OS, OutputFlags Flags) const override
void outputPost(OutputStream &OS, OutputFlags Flags) const
IntegerLiteralNode(uint64_t Value, bool IsNegative)
amdgpu Simplify well known AMD library false Value Value const Twine & Name
Class to represent array types.
Definition: DerivedTypes.h:369
Class to represent pointers.
Definition: DerivedTypes.h:467
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
This is a utility class that provides an abstraction for the common functionality between Instruction...
Definition: Operator.h:31
CHAIN = SC CHAIN, Imm128 - System call.
#define N
const unsigned Kind
LLVM Value Representation.
Definition: Value.h:73