LLVM  10.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 #include <cstdint>
20 #include <string>
21 
22 namespace llvm {
23 namespace itanium_demangle {
24 class OutputStream;
25 }
26 }
27 
28 using llvm::itanium_demangle::OutputStream;
29 using llvm::itanium_demangle::StringView;
30 
31 namespace llvm {
32 namespace ms_demangle {
33 
34 // Storage classes
35 enum Qualifiers : uint8_t {
36  Q_None = 0,
37  Q_Const = 1 << 0,
38  Q_Volatile = 1 << 1,
39  Q_Far = 1 << 2,
40  Q_Huge = 1 << 3,
41  Q_Unaligned = 1 << 4,
42  Q_Restrict = 1 << 5,
43  Q_Pointer64 = 1 << 6
44 };
45 
46 enum class StorageClass : uint8_t {
47  None,
51  Global,
53 };
54 
55 enum class PointerAffinity { None, Pointer, Reference, RValueReference };
56 enum class FunctionRefQualifier { None, Reference, RValueReference };
57 
58 // Calling conventions
59 enum class CallingConv : uint8_t {
60  None,
61  Cdecl,
62  Pascal,
63  Thiscall,
64  Stdcall,
65  Fastcall,
66  Clrcall,
67  Eabi,
68  Vectorcall,
69  Regcall,
70 };
71 
72 enum class ReferenceKind : uint8_t { None, LValueRef, RValueRef };
73 
78 };
79 
80 // Types
81 enum class PrimitiveKind {
82  Void,
83  Bool,
84  Char,
85  Schar,
86  Uchar,
87  Char8,
88  Char16,
89  Char32,
90  Short,
91  Ushort,
92  Int,
93  Uint,
94  Long,
95  Ulong,
96  Int64,
97  Uint64,
98  Wchar,
99  Float,
100  Double,
101  Ldouble,
102  Nullptr,
103 };
104 
105 enum class CharKind {
106  Char,
107  Char16,
108  Char32,
109  Wchar,
110 };
111 
112 enum class IntrinsicFunctionKind : uint8_t {
113  None,
114  New, // ?2 # operator new
115  Delete, // ?3 # operator delete
116  Assign, // ?4 # operator=
117  RightShift, // ?5 # operator>>
118  LeftShift, // ?6 # operator<<
119  LogicalNot, // ?7 # operator!
120  Equals, // ?8 # operator==
121  NotEquals, // ?9 # operator!=
122  ArraySubscript, // ?A # operator[]
123  Pointer, // ?C # operator->
124  Dereference, // ?D # operator*
125  Increment, // ?E # operator++
126  Decrement, // ?F # operator--
127  Minus, // ?G # operator-
128  Plus, // ?H # operator+
129  BitwiseAnd, // ?I # operator&
130  MemberPointer, // ?J # operator->*
131  Divide, // ?K # operator/
132  Modulus, // ?L # operator%
133  LessThan, // ?M operator<
134  LessThanEqual, // ?N operator<=
135  GreaterThan, // ?O operator>
136  GreaterThanEqual, // ?P operator>=
137  Comma, // ?Q operator,
138  Parens, // ?R operator()
139  BitwiseNot, // ?S operator~
140  BitwiseXor, // ?T operator^
141  BitwiseOr, // ?U operator|
142  LogicalAnd, // ?V operator&&
143  LogicalOr, // ?W operator||
144  TimesEqual, // ?X operator*=
145  PlusEqual, // ?Y operator+=
146  MinusEqual, // ?Z operator-=
147  DivEqual, // ?_0 operator/=
148  ModEqual, // ?_1 operator%=
149  RshEqual, // ?_2 operator>>=
150  LshEqual, // ?_3 operator<<=
151  BitwiseAndEqual, // ?_4 operator&=
152  BitwiseOrEqual, // ?_5 operator|=
153  BitwiseXorEqual, // ?_6 operator^=
154  VbaseDtor, // ?_D # vbase destructor
155  VecDelDtor, // ?_E # vector deleting destructor
156  DefaultCtorClosure, // ?_F # default constructor closure
157  ScalarDelDtor, // ?_G # scalar deleting destructor
158  VecCtorIter, // ?_H # vector constructor iterator
159  VecDtorIter, // ?_I # vector destructor iterator
160  VecVbaseCtorIter, // ?_J # vector vbase constructor iterator
161  VdispMap, // ?_K # virtual displacement map
162  EHVecCtorIter, // ?_L # eh vector constructor iterator
163  EHVecDtorIter, // ?_M # eh vector destructor iterator
164  EHVecVbaseCtorIter, // ?_N # eh vector vbase constructor iterator
165  CopyCtorClosure, // ?_O # copy constructor closure
166  LocalVftableCtorClosure, // ?_T # local vftable constructor closure
167  ArrayNew, // ?_U operator new[]
168  ArrayDelete, // ?_V operator delete[]
169  ManVectorCtorIter, // ?__A managed vector ctor iterator
170  ManVectorDtorIter, // ?__B managed vector dtor iterator
171  EHVectorCopyCtorIter, // ?__C EH vector copy ctor iterator
172  EHVectorVbaseCopyCtorIter, // ?__D EH vector vbase copy ctor iterator
173  VectorCopyCtorIter, // ?__G vector copy constructor iterator
174  VectorVbaseCopyCtorIter, // ?__H vector vbase copy constructor iterator
175  ManVectorVbaseCopyCtorIter, // ?__I managed vector vbase copy constructor
176  CoAwait, // ?__L operator co_await
177  Spaceship, // ?__M operator<=>
179 };
180 
182  None,
183  Vftable,
184  Vbtable,
185  Typeof,
186  VcallThunk,
189  UdtReturning,
190  Unknown,
198  LocalVftable,
200 };
201 
202 // Function classes
203 enum FuncClass : uint16_t {
204  FC_None = 0,
205  FC_Public = 1 << 0,
206  FC_Protected = 1 << 1,
207  FC_Private = 1 << 2,
208  FC_Global = 1 << 3,
209  FC_Static = 1 << 4,
210  FC_Virtual = 1 << 5,
211  FC_Far = 1 << 6,
212  FC_ExternC = 1 << 7,
217 };
218 
219 enum class TagKind { Class, Struct, Union, Enum };
220 
221 enum class NodeKind {
222  Unknown,
223  Md5Symbol,
226  Identifier,
236  PointerType,
237  TagType,
238  ArrayType,
239  Custom,
241  NodeArray,
251 };
252 
253 struct Node {
254  explicit Node(NodeKind K) : Kind(K) {}
255  virtual ~Node() = default;
256 
257  NodeKind kind() const { return Kind; }
258 
259  virtual void output(OutputStream &OS, OutputFlags Flags) const = 0;
260 
261  std::string toString(OutputFlags Flags = OF_Default) const;
262 
263 private:
264  NodeKind Kind;
265 };
266 
267 struct TypeNode;
268 struct PrimitiveTypeNode;
269 struct FunctionSignatureNode;
270 struct IdentifierNode;
271 struct NamedIdentifierNode;
277 struct ThunkSignatureNode;
278 struct PointerTypeNode;
279 struct ArrayTypeNode;
280 struct CustomNode;
281 struct TagTypeNode;
282 struct IntrinsicTypeNode;
283 struct NodeArrayNode;
284 struct QualifiedNameNode;
287 struct IntegerLiteralNode;
290 struct SymbolNode;
291 struct FunctionSymbolNode;
292 struct VariableSymbolNode;
294 
295 struct TypeNode : public Node {
296  explicit TypeNode(NodeKind K) : Node(K) {}
297 
298  virtual void outputPre(OutputStream &OS, OutputFlags Flags) const = 0;
299  virtual void outputPost(OutputStream &OS, OutputFlags Flags) const = 0;
300 
301  void output(OutputStream &OS, OutputFlags Flags) const override {
302  outputPre(OS, Flags);
303  outputPost(OS, Flags);
304  }
305 
306  void outputQuals(bool SpaceBefore, bool SpaceAfter) const;
307 
309 };
310 
311 struct PrimitiveTypeNode : public TypeNode {
313  : TypeNode(NodeKind::PrimitiveType), PrimKind(K) {}
314 
315  void outputPre(OutputStream &OS, OutputFlags Flags) const;
316  void outputPost(OutputStream &OS, OutputFlags Flags) const {}
317 
319 };
320 
324 
325  void outputPre(OutputStream &OS, OutputFlags Flags) const override;
326  void outputPost(OutputStream &OS, 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.
333  CallingConv CallConvention = CallingConv::None;
334 
335  // Function flags (gloabl, public, etc)
336  FuncClass FunctionClass = FC_Global;
337 
339 
340  // The return type of the function.
341  TypeNode *ReturnType = nullptr;
342 
343  // True if this is a C-style ... varargs function.
344  bool IsVariadic = false;
345 
346  // Function parameters
347  NodeArrayNode *Params = nullptr;
348 
349  // True if the function type is noexcept.
350  bool IsNoexcept = false;
351 };
352 
353 struct IdentifierNode : public Node {
354  explicit IdentifierNode(NodeKind K) : Node(K) {}
355 
356  NodeArrayNode *TemplateParams = nullptr;
357 
358 protected:
359  void outputTemplateParameters(OutputStream &OS, OutputFlags Flags) const;
360 };
361 
364 
365  void output(OutputStream &OS, OutputFlags Flags) const override;
366 
367  uint64_t OffsetInVTable = 0;
368 };
369 
373 
374  void output(OutputStream &OS, OutputFlags Flags) const override;
375 
376  VariableSymbolNode *Variable = nullptr;
378  bool IsDestructor = false;
379 };
380 
383 
384  void output(OutputStream &OS, OutputFlags Flags) const override;
385 
387 };
388 
392  Operator(Operator) {}
393 
394  void output(OutputStream &OS, OutputFlags Flags) const override;
395 
397 };
398 
402 
403  void output(OutputStream &OS, OutputFlags Flags) const override;
404 
406 };
407 
411 
412  void output(OutputStream &OS, OutputFlags Flags) const override;
413 
414  bool IsThread = false;
415  uint32_t ScopeIndex = 0;
416 };
417 
421 
422  void output(OutputStream &OS, OutputFlags Flags) const override;
423 
424  // The type that this operator converts too.
425  TypeNode *TargetType = nullptr;
426 };
427 
430  explicit StructorIdentifierNode(bool IsDestructor)
432  IsDestructor(IsDestructor) {}
433 
434  void output(OutputStream &OS, OutputFlags Flags) const override;
435 
436  // The name of the class that this is a structor of.
437  IdentifierNode *Class = nullptr;
438  bool IsDestructor = false;
439 };
440 
443 
444  void outputPre(OutputStream &OS, OutputFlags Flags) const override;
445  void outputPost(OutputStream &OS, OutputFlags Flags) const override;
446 
447  struct ThisAdjustor {
448  uint32_t StaticOffset = 0;
449  int32_t VBPtrOffset = 0;
450  int32_t VBOffsetOffset = 0;
451  int32_t VtordispOffset = 0;
452  };
453 
455 };
456 
457 struct PointerTypeNode : public TypeNode {
459  void outputPre(OutputStream &OS, OutputFlags Flags) const override;
460  void outputPost(OutputStream &OS, 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.
466  QualifiedNameNode *ClassParent = nullptr;
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 
473 struct TagTypeNode : public TypeNode {
474  explicit TagTypeNode(TagKind Tag) : TypeNode(NodeKind::TagType), Tag(Tag) {}
475 
476  void outputPre(OutputStream &OS, OutputFlags Flags) const;
477  void outputPost(OutputStream &OS, OutputFlags Flags) const;
478 
481 };
482 
483 struct ArrayTypeNode : public TypeNode {
485 
486  void outputPre(OutputStream &OS, OutputFlags Flags) const;
487  void outputPost(OutputStream &OS, OutputFlags Flags) const;
488 
489  void outputDimensionsImpl(OutputStream &OS, OutputFlags Flags) const;
490  void outputOneDimension(OutputStream &OS, OutputFlags Flags, Node *N) const;
491 
492  // A list of array dimensions. e.g. [3,4,5] in `int Foo[3][4][5]`
493  NodeArrayNode *Dimensions = nullptr;
494 
495  // The type of array element.
496  TypeNode *ElementType = nullptr;
497 };
498 
499 struct IntrinsicNode : public TypeNode {
501  void output(OutputStream &OS, OutputFlags Flags) const override {}
502 };
503 
504 struct CustomTypeNode : public TypeNode {
506 
507  void outputPre(OutputStream &OS, OutputFlags Flags) const override;
508  void outputPost(OutputStream &OS, OutputFlags Flags) const override;
509 
511 };
512 
513 struct NodeArrayNode : public Node {
515 
516  void output(OutputStream &OS, OutputFlags Flags) const override;
517 
518  void output(OutputStream &OS, OutputFlags Flags, StringView Separator) const;
519 
520  Node **Nodes = nullptr;
521  size_t Count = 0;
522 };
523 
524 struct QualifiedNameNode : public Node {
526 
527  void output(OutputStream &OS, OutputFlags Flags) const override;
528 
529  NodeArrayNode *Components = nullptr;
530 
532  Node *LastComponent = Components->Nodes[Components->Count - 1];
533  return static_cast<IdentifierNode *>(LastComponent);
534  }
535 };
536 
540 
541  void output(OutputStream &OS, OutputFlags Flags) const override;
542 
543  SymbolNode *Symbol = nullptr;
544 
545  int ThunkOffsetCount = 0;
546  std::array<int64_t, 3> ThunkOffsets;
548  bool IsMemberPointer = false;
549 };
550 
551 struct IntegerLiteralNode : public Node {
553  IntegerLiteralNode(uint64_t Value, bool IsNegative)
554  : Node(NodeKind::IntegerLiteral), Value(Value), IsNegative(IsNegative) {}
555 
556  void output(OutputStream &OS, OutputFlags Flags) const override;
557 
558  uint64_t Value = 0;
559  bool IsNegative = false;
560 };
561 
565 
566  void output(OutputStream &OS, OutputFlags Flags) const override;
567 
568  uint32_t NVOffset = 0;
569  int32_t VBPtrOffset = 0;
570  uint32_t VBTableOffset = 0;
571  uint32_t Flags = 0;
572 };
573 
574 struct SymbolNode : public Node {
575  explicit SymbolNode(NodeKind K) : Node(K) {}
576  void output(OutputStream &OS, OutputFlags Flags) const override;
578 };
579 
582  : SymbolNode(NodeKind::SpecialTableSymbol) {}
583 
584  void output(OutputStream &OS, OutputFlags Flags) const override;
585  QualifiedNameNode *TargetName = nullptr;
587 };
588 
592 
593  void output(OutputStream &OS, OutputFlags Flags) const override;
594 
595  bool IsVisible = false;
596 };
597 
600 
601  void output(OutputStream &OS, OutputFlags Flags) const override;
602 
604  bool IsTruncated = false;
605  CharKind Char = CharKind::Char;
606 };
607 
610 
611  void output(OutputStream &OS, OutputFlags Flags) const override;
612 
614  TypeNode *Type = nullptr;
615 };
616 
619 
620  void output(OutputStream &OS, OutputFlags Flags) const override;
621 
622  FunctionSignatureNode *Signature = nullptr;
623 };
624 
625 } // namespace ms_demangle
626 } // namespace llvm
627 
628 #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:403
Class to represent pointers.
Definition: DerivedTypes.h:544
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
LLVM Value Representation.
Definition: Value.h:73