LLVM  9.0.0svn
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_SUPPORT_MICROSOFTDEMANGLENODES_H
14 #define LLVM_SUPPORT_MICROSOFTDEMANGLENODES_H
15 
18 #include <array>
19 
20 namespace llvm {
21 namespace itanium_demangle {
22 class OutputStream;
23 }
24 }
25 
26 using llvm::itanium_demangle::OutputStream;
27 using llvm::itanium_demangle::StringView;
28 
29 namespace llvm {
30 namespace ms_demangle {
31 
32 // Storage classes
33 enum 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 
44 enum class StorageClass : uint8_t {
45  None,
49  Global,
51 };
52 
53 enum class PointerAffinity { None, Pointer, Reference, RValueReference };
54 enum class FunctionRefQualifier { None, Reference, RValueReference };
55 
56 // Calling conventions
57 enum class CallingConv : uint8_t {
58  None,
59  Cdecl,
60  Pascal,
61  Thiscall,
62  Stdcall,
63  Fastcall,
64  Clrcall,
65  Eabi,
66  Vectorcall,
67  Regcall,
68 };
69 
70 enum class ReferenceKind : uint8_t { None, LValueRef, RValueRef };
71 
76 };
77 
78 // Types
79 enum class PrimitiveKind {
80  Void,
81  Bool,
82  Char,
83  Schar,
84  Uchar,
85  Char16,
86  Char32,
87  Short,
88  Ushort,
89  Int,
90  Uint,
91  Long,
92  Ulong,
93  Int64,
94  Uint64,
95  Wchar,
96  Float,
97  Double,
98  Ldouble,
99  Nullptr,
100 };
101 
102 enum class CharKind {
103  Char,
104  Char16,
105  Char32,
106  Wchar,
107 };
108 
109 enum class IntrinsicFunctionKind : uint8_t {
110  None,
111  New, // ?2 # operator new
112  Delete, // ?3 # operator delete
113  Assign, // ?4 # operator=
114  RightShift, // ?5 # operator>>
115  LeftShift, // ?6 # operator<<
116  LogicalNot, // ?7 # operator!
117  Equals, // ?8 # operator==
118  NotEquals, // ?9 # operator!=
119  ArraySubscript, // ?A # operator[]
120  Pointer, // ?C # operator->
121  Dereference, // ?D # operator*
122  Increment, // ?E # operator++
123  Decrement, // ?F # operator--
124  Minus, // ?G # operator-
125  Plus, // ?H # operator+
126  BitwiseAnd, // ?I # operator&
127  MemberPointer, // ?J # operator->*
128  Divide, // ?K # operator/
129  Modulus, // ?L # operator%
130  LessThan, // ?M operator<
131  LessThanEqual, // ?N operator<=
132  GreaterThan, // ?O operator>
133  GreaterThanEqual, // ?P operator>=
134  Comma, // ?Q operator,
135  Parens, // ?R operator()
136  BitwiseNot, // ?S operator~
137  BitwiseXor, // ?T operator^
138  BitwiseOr, // ?U operator|
139  LogicalAnd, // ?V operator&&
140  LogicalOr, // ?W operator||
141  TimesEqual, // ?X operator*=
142  PlusEqual, // ?Y operator+=
143  MinusEqual, // ?Z operator-=
144  DivEqual, // ?_0 operator/=
145  ModEqual, // ?_1 operator%=
146  RshEqual, // ?_2 operator>>=
147  LshEqual, // ?_3 operator<<=
148  BitwiseAndEqual, // ?_4 operator&=
149  BitwiseOrEqual, // ?_5 operator|=
150  BitwiseXorEqual, // ?_6 operator^=
151  VbaseDtor, // ?_D # vbase destructor
152  VecDelDtor, // ?_E # vector deleting destructor
153  DefaultCtorClosure, // ?_F # default constructor closure
154  ScalarDelDtor, // ?_G # scalar deleting destructor
155  VecCtorIter, // ?_H # vector constructor iterator
156  VecDtorIter, // ?_I # vector destructor iterator
157  VecVbaseCtorIter, // ?_J # vector vbase constructor iterator
158  VdispMap, // ?_K # virtual displacement map
159  EHVecCtorIter, // ?_L # eh vector constructor iterator
160  EHVecDtorIter, // ?_M # eh vector destructor iterator
161  EHVecVbaseCtorIter, // ?_N # eh vector vbase constructor iterator
162  CopyCtorClosure, // ?_O # copy constructor closure
163  LocalVftableCtorClosure, // ?_T # local vftable constructor closure
164  ArrayNew, // ?_U operator new[]
165  ArrayDelete, // ?_V operator delete[]
166  ManVectorCtorIter, // ?__A managed vector ctor iterator
167  ManVectorDtorIter, // ?__B managed vector dtor iterator
168  EHVectorCopyCtorIter, // ?__C EH vector copy ctor iterator
169  EHVectorVbaseCopyCtorIter, // ?__D EH vector vbase copy ctor iterator
170  VectorCopyCtorIter, // ?__G vector copy constructor iterator
171  VectorVbaseCopyCtorIter, // ?__H vector vbase copy constructor iterator
172  ManVectorVbaseCopyCtorIter, // ?__I managed vector vbase copy constructor
173  CoAwait, // ?__L co_await
174  Spaceship, // operator<=>
176 };
177 
179  None,
180  Vftable,
181  Vbtable,
182  Typeof,
183  VcallThunk,
186  UdtReturning,
187  Unknown,
195  LocalVftable,
197 };
198 
199 // Function classes
200 enum FuncClass : uint16_t {
201  FC_None = 0,
202  FC_Public = 1 << 0,
203  FC_Protected = 1 << 1,
204  FC_Private = 1 << 2,
205  FC_Global = 1 << 3,
206  FC_Static = 1 << 4,
207  FC_Virtual = 1 << 5,
208  FC_Far = 1 << 6,
209  FC_ExternC = 1 << 7,
214 };
215 
216 enum class TagKind { Class, Struct, Union, Enum };
217 
218 enum class NodeKind {
219  Unknown,
220  Md5Symbol,
223  Identifier,
233  PointerType,
234  TagType,
235  ArrayType,
236  Custom,
238  NodeArray,
248 };
249 
250 struct Node {
251  explicit Node(NodeKind K) : Kind(K) {}
252  virtual ~Node() = default;
253 
254  NodeKind kind() const { return Kind; }
255 
256  virtual void output(OutputStream &OS, OutputFlags Flags) const = 0;
257 
258  std::string toString(OutputFlags Flags = OF_Default) const;
259 
260 private:
261  NodeKind Kind;
262 };
263 
264 struct TypeNode;
265 struct PrimitiveTypeNode;
266 struct FunctionSignatureNode;
267 struct IdentifierNode;
268 struct NamedIdentifierNode;
274 struct ThunkSignatureNode;
275 struct PointerTypeNode;
276 struct ArrayTypeNode;
277 struct CustomNode;
278 struct TagTypeNode;
279 struct IntrinsicTypeNode;
280 struct NodeArrayNode;
281 struct QualifiedNameNode;
284 struct IntegerLiteralNode;
287 struct SymbolNode;
288 struct FunctionSymbolNode;
289 struct VariableSymbolNode;
291 
292 struct TypeNode : public Node {
293  explicit TypeNode(NodeKind K) : Node(K) {}
294 
295  virtual void outputPre(OutputStream &OS, OutputFlags Flags) const = 0;
296  virtual void outputPost(OutputStream &OS, OutputFlags Flags) const = 0;
297 
298  void output(OutputStream &OS, OutputFlags Flags) const override {
299  outputPre(OS, Flags);
300  outputPost(OS, Flags);
301  }
302 
303  void outputQuals(bool SpaceBefore, bool SpaceAfter) const;
304 
306 };
307 
308 struct PrimitiveTypeNode : public TypeNode {
310  : TypeNode(NodeKind::PrimitiveType), PrimKind(K) {}
311 
312  void outputPre(OutputStream &OS, OutputFlags Flags) const;
313  void outputPost(OutputStream &OS, OutputFlags Flags) const {}
314 
316 };
317 
321 
322  void outputPre(OutputStream &OS, OutputFlags Flags) const override;
323  void outputPost(OutputStream &OS, OutputFlags Flags) const override;
324 
325  // Valid if this FunctionTypeNode is the Pointee of a PointerType or
326  // MemberPointerType.
328 
329  // The function's calling convention.
330  CallingConv CallConvention = CallingConv::None;
331 
332  // Function flags (gloabl, public, etc)
333  FuncClass FunctionClass = FC_Global;
334 
336 
337  // The return type of the function.
338  TypeNode *ReturnType = nullptr;
339 
340  // True if this is a C-style ... varargs function.
341  bool IsVariadic = false;
342 
343  // Function parameters
344  NodeArrayNode *Params = nullptr;
345 
346  // True if the function type is noexcept
347  bool IsNoexcept = false;
348 };
349 
350 struct IdentifierNode : public Node {
351  explicit IdentifierNode(NodeKind K) : Node(K) {}
352 
353  NodeArrayNode *TemplateParams = nullptr;
354 
355 protected:
356  void outputTemplateParameters(OutputStream &OS, OutputFlags Flags) const;
357 };
358 
361 
362  void output(OutputStream &OS, OutputFlags Flags) const override;
363 
364  uint64_t OffsetInVTable = 0;
365 };
366 
370 
371  void output(OutputStream &OS, OutputFlags Flags) const override;
372 
373  VariableSymbolNode *Variable = nullptr;
375  bool IsDestructor = false;
376 };
377 
380 
381  void output(OutputStream &OS, OutputFlags Flags) const override;
382 
384 };
385 
389  Operator(Operator) {}
390 
391  void output(OutputStream &OS, OutputFlags Flags) const override;
392 
394 };
395 
399 
400  void output(OutputStream &OS, OutputFlags Flags) const override;
401 
403 };
404 
408 
409  void output(OutputStream &OS, OutputFlags Flags) const override;
410 
411  uint32_t ScopeIndex = 0;
412 };
413 
417 
418  void output(OutputStream &OS, OutputFlags Flags) const override;
419 
420  // The type that this operator converts too.
421  TypeNode *TargetType = nullptr;
422 };
423 
426  explicit StructorIdentifierNode(bool IsDestructor)
428  IsDestructor(IsDestructor) {}
429 
430  void output(OutputStream &OS, OutputFlags Flags) const override;
431 
432  // The name of the class that this is a structor of.
433  IdentifierNode *Class = nullptr;
434  bool IsDestructor = false;
435 };
436 
439 
440  void outputPre(OutputStream &OS, OutputFlags Flags) const override;
441  void outputPost(OutputStream &OS, OutputFlags Flags) const override;
442 
443  struct ThisAdjustor {
444  uint32_t StaticOffset = 0;
445  int32_t VBPtrOffset = 0;
446  int32_t VBOffsetOffset = 0;
447  int32_t VtordispOffset = 0;
448  };
449 
451 };
452 
453 struct PointerTypeNode : public TypeNode {
455  void outputPre(OutputStream &OS, OutputFlags Flags) const override;
456  void outputPost(OutputStream &OS, OutputFlags Flags) const override;
457 
458  // Is this a pointer, reference, or rvalue-reference?
460 
461  // If this is a member pointer, this is the class that the member is in.
462  QualifiedNameNode *ClassParent = nullptr;
463 
464  // Represents a type X in "a pointer to X", "a reference to X", or
465  // "rvalue-reference to X"
466  TypeNode *Pointee = nullptr;
467 };
468 
469 struct TagTypeNode : public TypeNode {
470  explicit TagTypeNode(TagKind Tag) : TypeNode(NodeKind::TagType), Tag(Tag) {}
471 
472  void outputPre(OutputStream &OS, OutputFlags Flags) const;
473  void outputPost(OutputStream &OS, OutputFlags Flags) const;
474 
477 };
478 
479 struct ArrayTypeNode : public TypeNode {
481 
482  void outputPre(OutputStream &OS, OutputFlags Flags) const;
483  void outputPost(OutputStream &OS, OutputFlags Flags) const;
484 
485  void outputDimensionsImpl(OutputStream &OS, OutputFlags Flags) const;
486  void outputOneDimension(OutputStream &OS, OutputFlags Flags, Node *N) const;
487 
488  // A list of array dimensions. e.g. [3,4,5] in `int Foo[3][4][5]`
489  NodeArrayNode *Dimensions = nullptr;
490 
491  // The type of array element.
492  TypeNode *ElementType = nullptr;
493 };
494 
495 struct IntrinsicNode : public TypeNode {
497  void output(OutputStream &OS, OutputFlags Flags) const override {}
498 };
499 
500 struct CustomTypeNode : public TypeNode {
502 
503  void outputPre(OutputStream &OS, OutputFlags Flags) const override;
504  void outputPost(OutputStream &OS, OutputFlags Flags) const override;
505 
507 };
508 
509 struct NodeArrayNode : public Node {
511 
512  void output(OutputStream &OS, OutputFlags Flags) const override;
513 
514  void output(OutputStream &OS, OutputFlags Flags, StringView Separator) const;
515 
516  Node **Nodes = 0;
517  size_t Count = 0;
518 };
519 
520 struct QualifiedNameNode : public Node {
522 
523  void output(OutputStream &OS, OutputFlags Flags) const override;
524 
525  NodeArrayNode *Components = nullptr;
526 
528  Node *LastComponent = Components->Nodes[Components->Count - 1];
529  return static_cast<IdentifierNode *>(LastComponent);
530  }
531 };
532 
536 
537  void output(OutputStream &OS, OutputFlags Flags) const override;
538 
539  SymbolNode *Symbol = nullptr;
540 
541  int ThunkOffsetCount = 0;
542  std::array<int64_t, 3> ThunkOffsets;
544  bool IsMemberPointer = false;
545 };
546 
547 struct IntegerLiteralNode : public Node {
549  IntegerLiteralNode(uint64_t Value, bool IsNegative)
550  : Node(NodeKind::IntegerLiteral), Value(Value), IsNegative(IsNegative) {}
551 
552  void output(OutputStream &OS, OutputFlags Flags) const override;
553 
554  uint64_t Value = 0;
555  bool IsNegative = false;
556 };
557 
561 
562  void output(OutputStream &OS, OutputFlags Flags) const override;
563 
564  uint32_t NVOffset = 0;
565  int32_t VBPtrOffset = 0;
566  uint32_t VBTableOffset = 0;
567  uint32_t Flags = 0;
568 };
569 
570 struct SymbolNode : public Node {
571  explicit SymbolNode(NodeKind K) : Node(K) {}
572  void output(OutputStream &OS, OutputFlags Flags) const override;
574 };
575 
578  : SymbolNode(NodeKind::SpecialTableSymbol) {}
579 
580  void output(OutputStream &OS, OutputFlags Flags) const override;
581  QualifiedNameNode *TargetName = nullptr;
583 };
584 
588 
589  void output(OutputStream &OS, OutputFlags Flags) const override;
590 
591  bool IsVisible = false;
592 };
593 
596 
597  void output(OutputStream &OS, OutputFlags Flags) const override;
598 
600  bool IsTruncated = false;
601  CharKind Char = CharKind::Char;
602 };
603 
606 
607  void output(OutputStream &OS, OutputFlags Flags) const override;
608 
610  TypeNode *Type = nullptr;
611 };
612 
615 
616  void output(OutputStream &OS, OutputFlags Flags) const override;
617 
618  FunctionSignatureNode *Signature = nullptr;
619 };
620 
621 } // namespace ms_demangle
622 } // namespace llvm
623 
624 #endif
IntrinsicFunctionIdentifierNode(IntrinsicFunctionKind Operator)
const NoneType None
Definition: None.h:23
This class represents lattice values for constants.
Definition: AllocatorList.h:23
void output(OutputStream &OS, OutputFlags Flags) const override
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
void output(OutputStream &OS, OutputFlags Flags) const override
void outputPost(OutputStream &OS, OutputFlags Flags) const
IntegerLiteralNode(uint64_t Value, bool IsNegative)
std::string toString(Error E)
Write all error messages (if any) in E to a string.
Definition: Error.h:966
Class to represent array types.
Definition: DerivedTypes.h:400
Class to represent pointers.
Definition: DerivedTypes.h:498
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:45
Determine the kind of a node from its type.
This is a utility class that provides an abstraction for the common functionality between Instruction...
Definition: Operator.h:30
CHAIN = SC CHAIN, Imm128 - System call.
Qualifiers
#define N
const unsigned Kind
LLVM Value Representation.
Definition: Value.h:72