Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h
Line
Count
Source (jump to first uncovered line)
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
16
#include "llvm/Demangle/DemangleConfig.h"
17
#include "llvm/Demangle/StringView.h"
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,
48
  PrivateStatic,
49
  ProtectedStatic,
50
  PublicStatic,
51
  Global,
52
  FunctionLocalStatic,
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
74
enum OutputFlags {
75
  OF_Default = 0,
76
  OF_NoCallingConvention = 1,
77
  OF_NoTagSpecifier = 2,
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<=>
178
  MaxIntrinsic
179
};
180
181
enum class SpecialIntrinsicKind {
182
  None,
183
  Vftable,
184
  Vbtable,
185
  Typeof,
186
  VcallThunk,
187
  LocalStaticGuard,
188
  StringLiteralSymbol,
189
  UdtReturning,
190
  Unknown,
191
  DynamicInitializer,
192
  DynamicAtexitDestructor,
193
  RttiTypeDescriptor,
194
  RttiBaseClassDescriptor,
195
  RttiBaseClassArray,
196
  RttiClassHierarchyDescriptor,
197
  RttiCompleteObjLocator,
198
  LocalVftable,
199
  LocalStaticThreadGuard,
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,
213
  FC_NoParameterList = 1 << 8,
214
  FC_VirtualThisAdjust = 1 << 9,
215
  FC_VirtualThisAdjustEx = 1 << 10,
216
  FC_StaticThisAdjust = 1 << 11,
217
};
218
219
enum class TagKind { Class, Struct, Union, Enum };
220
221
enum class NodeKind {
222
  Unknown,
223
  Md5Symbol,
224
  PrimitiveType,
225
  FunctionSignature,
226
  Identifier,
227
  NamedIdentifier,
228
  VcallThunkIdentifier,
229
  LocalStaticGuardIdentifier,
230
  IntrinsicFunctionIdentifier,
231
  ConversionOperatorIdentifier,
232
  DynamicStructorIdentifier,
233
  StructorIdentifier,
234
  LiteralOperatorIdentifier,
235
  ThunkSignature,
236
  PointerType,
237
  TagType,
238
  ArrayType,
239
  Custom,
240
  IntrinsicType,
241
  NodeArray,
242
  QualifiedName,
243
  TemplateParameterReference,
244
  EncodedStringLiteral,
245
  IntegerLiteral,
246
  RttiBaseClassDescriptor,
247
  LocalStaticGuardVariable,
248
  FunctionSymbol,
249
  VariableSymbol,
250
  SpecialTableSymbol
251
};
252
253
struct Node {
254
12.2k
  explicit Node(NodeKind K) : Kind(K) {}
255
0
  virtual ~Node() = default;
256
257
5.85k
  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;
272
struct VcallThunkIdentifierNode;
273
struct IntrinsicFunctionIdentifierNode;
274
struct LiteralOperatorIdentifierNode;
275
struct ConversionOperatorIdentifierNode;
276
struct StructorIdentifierNode;
277
struct ThunkSignatureNode;
278
struct PointerTypeNode;
279
struct ArrayTypeNode;
280
struct CustomNode;
281
struct TagTypeNode;
282
struct IntrinsicTypeNode;
283
struct NodeArrayNode;
284
struct QualifiedNameNode;
285
struct TemplateParameterReferenceNode;
286
struct EncodedStringLiteralNode;
287
struct IntegerLiteralNode;
288
struct RttiBaseClassDescriptorNode;
289
struct LocalStaticGuardVariableNode;
290
struct SymbolNode;
291
struct FunctionSymbolNode;
292
struct VariableSymbolNode;
293
struct SpecialTableSymbolNode;
294
295
struct TypeNode : public Node {
296
2.96k
  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
1.17k
  void output(OutputStream &OS, OutputFlags Flags) const override {
302
1.17k
    outputPre(OS, Flags);
303
1.17k
    outputPost(OS, Flags);
304
1.17k
  }
305
306
  void outputQuals(bool SpaceBefore, bool SpaceAfter) const;
307
308
  Qualifiers Quals = Q_None;
309
};
310
311
struct PrimitiveTypeNode : public TypeNode {
312
  explicit PrimitiveTypeNode(PrimitiveKind K)
313
1.19k
      : TypeNode(NodeKind::PrimitiveType), PrimKind(K) {}
314
315
  void outputPre(OutputStream &OS, OutputFlags Flags) const;
316
1.40k
  void outputPost(OutputStream &OS, OutputFlags Flags) const {}
317
318
  PrimitiveKind PrimKind;
319
};
320
321
struct FunctionSignatureNode : public TypeNode {
322
14
  explicit FunctionSignatureNode(NodeKind K) : TypeNode(K) {}
323
821
  FunctionSignatureNode() : TypeNode(NodeKind::FunctionSignature) {}
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.
330
  PointerAffinity Affinity = PointerAffinity::None;
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
338
  FunctionRefQualifier RefQualifier = FunctionRefQualifier::None;
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
4.30k
  explicit IdentifierNode(NodeKind K) : Node(K) {}
355
356
  NodeArrayNode *TemplateParams = nullptr;
357
358
protected:
359
  void outputTemplateParameters(OutputStream &OS, OutputFlags Flags) const;
360
};
361
362
struct VcallThunkIdentifierNode : public IdentifierNode {
363
9
  VcallThunkIdentifierNode() : IdentifierNode(NodeKind::VcallThunkIdentifier) {}
364
365
  void output(OutputStream &OS, OutputFlags Flags) const override;
366
367
  uint64_t OffsetInVTable = 0;
368
};
369
370
struct DynamicStructorIdentifierNode : public IdentifierNode {
371
  DynamicStructorIdentifierNode()
372
9
      : IdentifierNode(NodeKind::DynamicStructorIdentifier) {}
373
374
  void output(OutputStream &OS, OutputFlags Flags) const override;
375
376
  VariableSymbolNode *Variable = nullptr;
377
  QualifiedNameNode *Name = nullptr;
378
  bool IsDestructor = false;
379
};
380
381
struct NamedIdentifierNode : public IdentifierNode {
382
4.03k
  NamedIdentifierNode() : IdentifierNode(NodeKind::NamedIdentifier) {}
383
384
  void output(OutputStream &OS, OutputFlags Flags) const override;
385
386
  StringView Name;
387
};
388
389
struct IntrinsicFunctionIdentifierNode : public IdentifierNode {
390
  explicit IntrinsicFunctionIdentifierNode(IntrinsicFunctionKind Operator)
391
      : IdentifierNode(NodeKind::IntrinsicFunctionIdentifier),
392
139
        Operator(Operator) {}
393
394
  void output(OutputStream &OS, OutputFlags Flags) const override;
395
396
  IntrinsicFunctionKind Operator;
397
};
398
399
struct LiteralOperatorIdentifierNode : public IdentifierNode {
400
  LiteralOperatorIdentifierNode()
401
2
      : IdentifierNode(NodeKind::LiteralOperatorIdentifier) {}
402
403
  void output(OutputStream &OS, OutputFlags Flags) const override;
404
405
  StringView Name;
406
};
407
408
struct LocalStaticGuardIdentifierNode : public IdentifierNode {
409
  LocalStaticGuardIdentifierNode()
410
3
      : IdentifierNode(NodeKind::LocalStaticGuardIdentifier) {}
411
412
  void output(OutputStream &OS, OutputFlags Flags) const override;
413
414
  bool IsThread = false;
415
  uint32_t ScopeIndex = 0;
416
};
417
418
struct ConversionOperatorIdentifierNode : public IdentifierNode {
419
  ConversionOperatorIdentifierNode()
420
22
      : IdentifierNode(NodeKind::ConversionOperatorIdentifier) {}
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
428
struct StructorIdentifierNode : public IdentifierNode {
429
77
  StructorIdentifierNode() : IdentifierNode(NodeKind::StructorIdentifier) {}
430
  explicit StructorIdentifierNode(bool IsDestructor)
431
      : IdentifierNode(NodeKind::StructorIdentifier),
432
0
        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
441
struct ThunkSignatureNode : public FunctionSignatureNode {
442
14
  ThunkSignatureNode() : FunctionSignatureNode(NodeKind::ThunkSignature) {}
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
454
  ThisAdjustor ThisAdjust;
455
};
456
457
struct PointerTypeNode : public TypeNode {
458
483
  PointerTypeNode() : TypeNode(NodeKind::PointerType) {}
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?
463
  PointerAffinity Affinity = PointerAffinity::None;
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
401
  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
479
  QualifiedNameNode *QualifiedName = nullptr;
480
  TagKind Tag;
481
};
482
483
struct ArrayTypeNode : public TypeNode {
484
40
  ArrayTypeNode() : TypeNode(NodeKind::ArrayType) {}
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 {
500
0
  IntrinsicNode() : TypeNode(NodeKind::IntrinsicType) {}
501
0
  void output(OutputStream &OS, OutputFlags Flags) const override {}
502
};
503
504
struct CustomTypeNode : public TypeNode {
505
11
  CustomTypeNode() : TypeNode(NodeKind::Custom) {}
506
507
  void outputPre(OutputStream &OS, OutputFlags Flags) const override;
508
  void outputPost(OutputStream &OS, OutputFlags Flags) const override;
509
510
  IdentifierNode *Identifier;
511
};
512
513
struct NodeArrayNode : public Node {
514
2.16k
  NodeArrayNode() : Node(NodeKind::NodeArray) {}
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 {
525
1.38k
  QualifiedNameNode() : Node(NodeKind::QualifiedName) {}
526
527
  void output(OutputStream &OS, OutputFlags Flags) const override;
528
529
  NodeArrayNode *Components = nullptr;
530
531
1.62k
  IdentifierNode *getUnqualifiedIdentifier() {
532
1.62k
    Node *LastComponent = Components->Nodes[Components->Count - 1];
533
1.62k
    return static_cast<IdentifierNode *>(LastComponent);
534
1.62k
  }
535
};
536
537
struct TemplateParameterReferenceNode : public Node {
538
  TemplateParameterReferenceNode()
539
39
      : Node(NodeKind::TemplateParameterReference) {}
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;
547
  PointerAffinity Affinity = PointerAffinity::None;
548
  bool IsMemberPointer = false;
549
};
550
551
struct IntegerLiteralNode : public Node {
552
0
  IntegerLiteralNode() : Node(NodeKind::IntegerLiteral) {}
553
  IntegerLiteralNode(uint64_t Value, bool IsNegative)
554
111
      : 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
562
struct RttiBaseClassDescriptorNode : public IdentifierNode {
563
  RttiBaseClassDescriptorNode()
564
2
      : IdentifierNode(NodeKind::RttiBaseClassDescriptor) {}
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
1.31k
  explicit SymbolNode(NodeKind K) : Node(K) {}
576
  void output(OutputStream &OS, OutputFlags Flags) const override;
577
  QualifiedNameNode *Name = nullptr;
578
};
579
580
struct SpecialTableSymbolNode : public SymbolNode {
581
  explicit SpecialTableSymbolNode()
582
9
      : SymbolNode(NodeKind::SpecialTableSymbol) {}
583
584
  void output(OutputStream &OS, OutputFlags Flags) const override;
585
  QualifiedNameNode *TargetName = nullptr;
586
  Qualifiers Quals;
587
};
588
589
struct LocalStaticGuardVariableNode : public SymbolNode {
590
  LocalStaticGuardVariableNode()
591
3
      : SymbolNode(NodeKind::LocalStaticGuardVariable) {}
592
593
  void output(OutputStream &OS, OutputFlags Flags) const override;
594
595
  bool IsVisible = false;
596
};
597
598
struct EncodedStringLiteralNode : public SymbolNode {
599
392
  EncodedStringLiteralNode() : SymbolNode(NodeKind::EncodedStringLiteral) {}
600
601
  void output(OutputStream &OS, OutputFlags Flags) const override;
602
603
  StringView DecodedString;
604
  bool IsTruncated = false;
605
  CharKind Char = CharKind::Char;
606
};
607
608
struct VariableSymbolNode : public SymbolNode {
609
194
  VariableSymbolNode() : SymbolNode(NodeKind::VariableSymbol) {}
610
611
  void output(OutputStream &OS, OutputFlags Flags) const override;
612
613
  StorageClass SC = StorageClass::None;
614
  TypeNode *Type = nullptr;
615
};
616
617
struct FunctionSymbolNode : public SymbolNode {
618
717
  FunctionSymbolNode() : SymbolNode(NodeKind::FunctionSymbol) {}
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