Coverage Report

Created: 2021-08-24 07:12

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/AST/TextNodeDumper.cpp
Line
Count
Source (jump to first uncovered line)
1
//===--- TextNodeDumper.cpp - Printing of AST nodes -----------------------===//
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 implements AST dumping of components of individual AST nodes.
10
//
11
//===----------------------------------------------------------------------===//
12
13
#include "clang/AST/TextNodeDumper.h"
14
#include "clang/AST/APValue.h"
15
#include "clang/AST/DeclFriend.h"
16
#include "clang/AST/DeclOpenMP.h"
17
#include "clang/AST/DeclTemplate.h"
18
#include "clang/AST/LocInfoType.h"
19
#include "clang/AST/Type.h"
20
#include "clang/Basic/Module.h"
21
#include "clang/Basic/SourceManager.h"
22
#include "clang/Basic/Specifiers.h"
23
#include "clang/Basic/TypeTraits.h"
24
#include "llvm/ADT/StringExtras.h"
25
26
#include <algorithm>
27
#include <utility>
28
29
using namespace clang;
30
31
1.90k
static void dumpPreviousDeclImpl(raw_ostream &OS, ...) {}
32
33
template <typename T>
34
2.00k
static void dumpPreviousDeclImpl(raw_ostream &OS, const Mergeable<T> *D) {
35
2.00k
  const T *First = D->getFirstDecl();
36
2.00k
  if (First != D)
37
0
    OS << " first " << First;
38
2.00k
}
Unexecuted instantiation: TextNodeDumper.cpp:void dumpPreviousDeclImpl<clang::LifetimeExtendedTemporaryDecl>(llvm::raw_ostream&, clang::Mergeable<clang::LifetimeExtendedTemporaryDecl> const*)
TextNodeDumper.cpp:void dumpPreviousDeclImpl<clang::UsingDecl>(llvm::raw_ostream&, clang::Mergeable<clang::UsingDecl> const*)
Line
Count
Source
34
27
static void dumpPreviousDeclImpl(raw_ostream &OS, const Mergeable<T> *D) {
35
27
  const T *First = D->getFirstDecl();
36
27
  if (First != D)
37
0
    OS << " first " << First;
38
27
}
TextNodeDumper.cpp:void dumpPreviousDeclImpl<clang::UsingEnumDecl>(llvm::raw_ostream&, clang::Mergeable<clang::UsingEnumDecl> const*)
Line
Count
Source
34
10
static void dumpPreviousDeclImpl(raw_ostream &OS, const Mergeable<T> *D) {
35
10
  const T *First = D->getFirstDecl();
36
10
  if (First != D)
37
0
    OS << " first " << First;
38
10
}
TextNodeDumper.cpp:void dumpPreviousDeclImpl<clang::ConceptDecl>(llvm::raw_ostream&, clang::Mergeable<clang::ConceptDecl> const*)
Line
Count
Source
34
4
static void dumpPreviousDeclImpl(raw_ostream &OS, const Mergeable<T> *D) {
35
4
  const T *First = D->getFirstDecl();
36
4
  if (First != D)
37
0
    OS << " first " << First;
38
4
}
TextNodeDumper.cpp:void dumpPreviousDeclImpl<clang::UnresolvedUsingTypenameDecl>(llvm::raw_ostream&, clang::Mergeable<clang::UnresolvedUsingTypenameDecl> const*)
Line
Count
Source
34
1
static void dumpPreviousDeclImpl(raw_ostream &OS, const Mergeable<T> *D) {
35
1
  const T *First = D->getFirstDecl();
36
1
  if (First != D)
37
0
    OS << " first " << First;
38
1
}
Unexecuted instantiation: TextNodeDumper.cpp:void dumpPreviousDeclImpl<clang::UsingPackDecl>(llvm::raw_ostream&, clang::Mergeable<clang::UsingPackDecl> const*)
TextNodeDumper.cpp:void dumpPreviousDeclImpl<clang::FieldDecl>(llvm::raw_ostream&, clang::Mergeable<clang::FieldDecl> const*)
Line
Count
Source
34
1.83k
static void dumpPreviousDeclImpl(raw_ostream &OS, const Mergeable<T> *D) {
35
1.83k
  const T *First = D->getFirstDecl();
36
1.83k
  if (First != D)
37
0
    OS << " first " << First;
38
1.83k
}
TextNodeDumper.cpp:void dumpPreviousDeclImpl<clang::EnumConstantDecl>(llvm::raw_ostream&, clang::Mergeable<clang::EnumConstantDecl> const*)
Line
Count
Source
34
73
static void dumpPreviousDeclImpl(raw_ostream &OS, const Mergeable<T> *D) {
35
73
  const T *First = D->getFirstDecl();
36
73
  if (First != D)
37
0
    OS << " first " << First;
38
73
}
TextNodeDumper.cpp:void dumpPreviousDeclImpl<clang::IndirectFieldDecl>(llvm::raw_ostream&, clang::Mergeable<clang::IndirectFieldDecl> const*)
Line
Count
Source
34
52
static void dumpPreviousDeclImpl(raw_ostream &OS, const Mergeable<T> *D) {
35
52
  const T *First = D->getFirstDecl();
36
52
  if (First != D)
37
0
    OS << " first " << First;
38
52
}
Unexecuted instantiation: TextNodeDumper.cpp:void dumpPreviousDeclImpl<clang::MSGuidDecl>(llvm::raw_ostream&, clang::Mergeable<clang::MSGuidDecl> const*)
Unexecuted instantiation: TextNodeDumper.cpp:void dumpPreviousDeclImpl<clang::TemplateParamObjectDecl>(llvm::raw_ostream&, clang::Mergeable<clang::TemplateParamObjectDecl> const*)
TextNodeDumper.cpp:void dumpPreviousDeclImpl<clang::UnresolvedUsingValueDecl>(llvm::raw_ostream&, clang::Mergeable<clang::UnresolvedUsingValueDecl> const*)
Line
Count
Source
34
1
static void dumpPreviousDeclImpl(raw_ostream &OS, const Mergeable<T> *D) {
35
1
  const T *First = D->getFirstDecl();
36
1
  if (First != D)
37
0
    OS << " first " << First;
38
1
}
39
40
template <typename T>
41
19.0k
static void dumpPreviousDeclImpl(raw_ostream &OS, const Redeclarable<T> *D) {
42
19.0k
  const T *Prev = D->getPreviousDecl();
43
19.0k
  if (Prev)
44
350
    OS << " prev " << Prev;
45
19.0k
}
TextNodeDumper.cpp:void dumpPreviousDeclImpl<clang::NamespaceDecl>(llvm::raw_ostream&, clang::Redeclarable<clang::NamespaceDecl> const*)
Line
Count
Source
41
153
static void dumpPreviousDeclImpl(raw_ostream &OS, const Redeclarable<T> *D) {
42
153
  const T *Prev = D->getPreviousDecl();
43
153
  if (Prev)
44
4
    OS << " prev " << Prev;
45
153
}
TextNodeDumper.cpp:void dumpPreviousDeclImpl<clang::NamespaceAliasDecl>(llvm::raw_ostream&, clang::Redeclarable<clang::NamespaceAliasDecl> const*)
Line
Count
Source
41
4
static void dumpPreviousDeclImpl(raw_ostream &OS, const Redeclarable<T> *D) {
42
4
  const T *Prev = D->getPreviousDecl();
43
4
  if (Prev)
44
0
    OS << " prev " << Prev;
45
4
}
TextNodeDumper.cpp:void dumpPreviousDeclImpl<clang::ObjCInterfaceDecl>(llvm::raw_ostream&, clang::Redeclarable<clang::ObjCInterfaceDecl> const*)
Line
Count
Source
41
103
static void dumpPreviousDeclImpl(raw_ostream &OS, const Redeclarable<T> *D) {
42
103
  const T *Prev = D->getPreviousDecl();
43
103
  if (Prev)
44
1
    OS << " prev " << Prev;
45
103
}
TextNodeDumper.cpp:void dumpPreviousDeclImpl<clang::ObjCProtocolDecl>(llvm::raw_ostream&, clang::Redeclarable<clang::ObjCProtocolDecl> const*)
Line
Count
Source
41
20
static void dumpPreviousDeclImpl(raw_ostream &OS, const Redeclarable<T> *D) {
42
20
  const T *Prev = D->getPreviousDecl();
43
20
  if (Prev)
44
0
    OS << " prev " << Prev;
45
20
}
TextNodeDumper.cpp:void dumpPreviousDeclImpl<clang::RedeclarableTemplateDecl>(llvm::raw_ostream&, clang::Redeclarable<clang::RedeclarableTemplateDecl> const*)
Line
Count
Source
41
484
static void dumpPreviousDeclImpl(raw_ostream &OS, const Redeclarable<T> *D) {
42
484
  const T *Prev = D->getPreviousDecl();
43
484
  if (Prev)
44
26
    OS << " prev " << Prev;
45
484
}
TextNodeDumper.cpp:void dumpPreviousDeclImpl<clang::TagDecl>(llvm::raw_ostream&, clang::Redeclarable<clang::TagDecl> const*)
Line
Count
Source
41
2.82k
static void dumpPreviousDeclImpl(raw_ostream &OS, const Redeclarable<T> *D) {
42
2.82k
  const T *Prev = D->getPreviousDecl();
43
2.82k
  if (Prev)
44
148
    OS << " prev " << Prev;
45
2.82k
}
TextNodeDumper.cpp:void dumpPreviousDeclImpl<clang::TypedefNameDecl>(llvm::raw_ostream&, clang::Redeclarable<clang::TypedefNameDecl> const*)
Line
Count
Source
41
2.80k
static void dumpPreviousDeclImpl(raw_ostream &OS, const Redeclarable<T> *D) {
42
2.80k
  const T *Prev = D->getPreviousDecl();
43
2.80k
  if (Prev)
44
5
    OS << " prev " << Prev;
45
2.80k
}
TextNodeDumper.cpp:void dumpPreviousDeclImpl<clang::UsingShadowDecl>(llvm::raw_ostream&, clang::Redeclarable<clang::UsingShadowDecl> const*)
Line
Count
Source
41
60
static void dumpPreviousDeclImpl(raw_ostream &OS, const Redeclarable<T> *D) {
42
60
  const T *Prev = D->getPreviousDecl();
43
60
  if (Prev)
44
0
    OS << " prev " << Prev;
45
60
}
TextNodeDumper.cpp:void dumpPreviousDeclImpl<clang::FunctionDecl>(llvm::raw_ostream&, clang::Redeclarable<clang::FunctionDecl> const*)
Line
Count
Source
41
4.14k
static void dumpPreviousDeclImpl(raw_ostream &OS, const Redeclarable<T> *D) {
42
4.14k
  const T *Prev = D->getPreviousDecl();
43
4.14k
  if (Prev)
44
152
    OS << " prev " << Prev;
45
4.14k
}
TextNodeDumper.cpp:void dumpPreviousDeclImpl<clang::VarDecl>(llvm::raw_ostream&, clang::Redeclarable<clang::VarDecl> const*)
Line
Count
Source
41
8.04k
static void dumpPreviousDeclImpl(raw_ostream &OS, const Redeclarable<T> *D) {
42
8.04k
  const T *Prev = D->getPreviousDecl();
43
8.04k
  if (Prev)
44
14
    OS << " prev " << Prev;
45
8.04k
}
TextNodeDumper.cpp:void dumpPreviousDeclImpl<clang::TranslationUnitDecl>(llvm::raw_ostream&, clang::Redeclarable<clang::TranslationUnitDecl> const*)
Line
Count
Source
41
424
static void dumpPreviousDeclImpl(raw_ostream &OS, const Redeclarable<T> *D) {
42
424
  const T *Prev = D->getPreviousDecl();
43
424
  if (Prev)
44
0
    OS << " prev " << Prev;
45
424
}
46
47
/// Dump the previous declaration in the redeclaration chain for a declaration,
48
/// if any.
49
22.9k
static void dumpPreviousDecl(raw_ostream &OS, const Decl *D) {
50
22.9k
  switch (D->getKind()) {
51
0
#define DECL(DERIVED, BASE)                                                    \
52
22.9k
  case Decl::DERIVED:                                                          \
53
22.9k
    return dumpPreviousDeclImpl(OS, cast<DERIVED##Decl>(D));
54
0
#define ABSTRACT_DECL(DECL)
55
22.9k
#include 
"clang/AST/DeclNodes.inc"0
56
22.9k
  }
57
0
  llvm_unreachable("Decl that isn't part of DeclNodes.inc!");
58
0
}
59
60
TextNodeDumper::TextNodeDumper(raw_ostream &OS, const ASTContext &Context,
61
                               bool ShowColors)
62
    : TextTreeStructure(OS, ShowColors), OS(OS), ShowColors(ShowColors),
63
      Context(&Context), SM(&Context.getSourceManager()),
64
      PrintPolicy(Context.getPrintingPolicy()),
65
1.51k
      Traits(&Context.getCommentCommandTraits()) {}
66
67
TextNodeDumper::TextNodeDumper(raw_ostream &OS, bool ShowColors)
68
93
    : TextTreeStructure(OS, ShowColors), OS(OS), ShowColors(ShowColors) {}
69
70
void TextNodeDumper::Visit(const comments::Comment *C,
71
593
                           const comments::FullComment *FC) {
72
593
  if (!C) {
73
0
    ColorScope Color(OS, ShowColors, NullColor);
74
0
    OS << "<<<NULL>>>";
75
0
    return;
76
0
  }
77
78
593
  {
79
593
    ColorScope Color(OS, ShowColors, CommentColor);
80
593
    OS << C->getCommentKindName();
81
593
  }
82
593
  dumpPointer(C);
83
593
  dumpSourceRange(C->getSourceRange());
84
85
593
  ConstCommentVisitor<TextNodeDumper, void,
86
593
                      const comments::FullComment *>::visit(C, FC);
87
593
}
88
89
1.98k
void TextNodeDumper::Visit(const Attr *A) {
90
1.98k
  {
91
1.98k
    ColorScope Color(OS, ShowColors, AttrColor);
92
93
1.98k
    switch (A->getKind()) {
94
0
#define ATTR(X)                                                                \
95
1.98k
  case attr::X:                                                                \
96
1.98k
    OS << #X;                                                                  \
97
1.98k
    break;
98
1.98k
#include 
"clang/Basic/AttrList.inc"0
99
1.98k
    }
100
1.98k
    OS << "Attr";
101
1.98k
  }
102
0
  dumpPointer(A);
103
1.98k
  dumpSourceRange(A->getRange());
104
1.98k
  if (A->isInherited())
105
99
    OS << " Inherited";
106
1.98k
  if (A->isImplicit())
107
1.41k
    OS << " Implicit";
108
109
1.98k
  ConstAttrVisitor<TextNodeDumper>::Visit(A);
110
1.98k
}
111
112
void TextNodeDumper::Visit(const TemplateArgument &TA, SourceRange R,
113
582
                           const Decl *From, StringRef Label) {
114
582
  OS << "TemplateArgument";
115
582
  if (R.isValid())
116
26
    dumpSourceRange(R);
117
118
582
  if (From)
119
6
    dumpDeclRef(From, Label);
120
121
582
  ConstTemplateArgumentVisitor<TextNodeDumper>::Visit(TA);
122
582
}
123
124
28.9k
void TextNodeDumper::Visit(const Stmt *Node) {
125
28.9k
  if (!Node) {
126
874
    ColorScope Color(OS, ShowColors, NullColor);
127
874
    OS << "<<<NULL>>>";
128
874
    return;
129
874
  }
130
28.0k
  {
131
28.0k
    ColorScope Color(OS, ShowColors, StmtColor);
132
28.0k
    OS << Node->getStmtClassName();
133
28.0k
  }
134
28.0k
  dumpPointer(Node);
135
28.0k
  dumpSourceRange(Node->getSourceRange());
136
137
28.0k
  if (const auto *E = dyn_cast<Expr>(Node)) {
138
20.9k
    dumpType(E->getType());
139
140
20.9k
    if (E->containsErrors()) {
141
158
      ColorScope Color(OS, ShowColors, ErrorsColor);
142
158
      OS << " contains-errors";
143
158
    }
144
145
20.9k
    {
146
20.9k
      ColorScope Color(OS, ShowColors, ValueKindColor);
147
20.9k
      switch (E->getValueKind()) {
148
14.2k
      case VK_PRValue:
149
14.2k
        break;
150
6.45k
      case VK_LValue:
151
6.45k
        OS << " lvalue";
152
6.45k
        break;
153
218
      case VK_XValue:
154
218
        OS << " xvalue";
155
218
        break;
156
20.9k
      }
157
20.9k
    }
158
159
20.9k
    {
160
20.9k
      ColorScope Color(OS, ShowColors, ObjectKindColor);
161
20.9k
      switch (E->getObjectKind()) {
162
20.9k
      case OK_Ordinary:
163
20.9k
        break;
164
0
      case OK_BitField:
165
0
        OS << " bitfield";
166
0
        break;
167
2
      case OK_ObjCProperty:
168
2
        OS << " objcproperty";
169
2
        break;
170
0
      case OK_ObjCSubscript:
171
0
        OS << " objcsubscript";
172
0
        break;
173
8
      case OK_VectorComponent:
174
8
        OS << " vectorcomponent";
175
8
        break;
176
0
      case OK_MatrixComponent:
177
0
        OS << " matrixcomponent";
178
0
        break;
179
20.9k
      }
180
20.9k
    }
181
20.9k
  }
182
183
28.0k
  ConstStmtVisitor<TextNodeDumper>::Visit(Node);
184
28.0k
}
185
186
4.52k
void TextNodeDumper::Visit(const Type *T) {
187
4.52k
  if (!T) {
188
0
    ColorScope Color(OS, ShowColors, NullColor);
189
0
    OS << "<<<NULL>>>";
190
0
    return;
191
0
  }
192
4.52k
  if (isa<LocInfoType>(T)) {
193
0
    {
194
0
      ColorScope Color(OS, ShowColors, TypeColor);
195
0
      OS << "LocInfo Type";
196
0
    }
197
0
    dumpPointer(T);
198
0
    return;
199
0
  }
200
201
4.52k
  {
202
4.52k
    ColorScope Color(OS, ShowColors, TypeColor);
203
4.52k
    OS << T->getTypeClassName() << "Type";
204
4.52k
  }
205
4.52k
  dumpPointer(T);
206
4.52k
  OS << " ";
207
4.52k
  dumpBareType(QualType(T, 0), false);
208
209
4.52k
  QualType SingleStepDesugar =
210
4.52k
      T->getLocallyUnqualifiedSingleStepDesugaredType();
211
4.52k
  if (SingleStepDesugar != QualType(T, 0))
212
172
    OS << " sugar";
213
214
4.52k
  if (T->containsErrors()) {
215
1
    ColorScope Color(OS, ShowColors, ErrorsColor);
216
1
    OS << " contains-errors";
217
1
  }
218
219
4.52k
  if (T->isDependentType())
220
206
    OS << " dependent";
221
4.31k
  else if (T->isInstantiationDependentType())
222
0
    OS << " instantiation_dependent";
223
224
4.52k
  if (T->isVariablyModifiedType())
225
0
    OS << " variably_modified";
226
4.52k
  if (T->containsUnexpandedParameterPack())
227
18
    OS << " contains_unexpanded_pack";
228
4.52k
  if (T->isFromAST())
229
137
    OS << " imported";
230
231
4.52k
  TypeVisitor<TextNodeDumper>::Visit(T);
232
4.52k
}
233
234
24
void TextNodeDumper::Visit(QualType T) {
235
24
  OS << "QualType";
236
24
  dumpPointer(T.getAsOpaquePtr());
237
24
  OS << " ";
238
24
  dumpBareType(T, false);
239
24
  OS << " " << T.split().Quals.getAsString();
240
24
}
241
242
22.9k
void TextNodeDumper::Visit(const Decl *D) {
243
22.9k
  if (!D) {
244
3
    ColorScope Color(OS, ShowColors, NullColor);
245
3
    OS << "<<<NULL>>>";
246
3
    return;
247
3
  }
248
249
22.9k
  {
250
22.9k
    ColorScope Color(OS, ShowColors, DeclKindNameColor);
251
22.9k
    OS << D->getDeclKindName() << "Decl";
252
22.9k
  }
253
22.9k
  dumpPointer(D);
254
22.9k
  if (D->getLexicalDeclContext() != D->getDeclContext())
255
76
    OS << " parent " << cast<Decl>(D->getDeclContext());
256
22.9k
  dumpPreviousDecl(OS, D);
257
22.9k
  dumpSourceRange(D->getSourceRange());
258
22.9k
  OS << ' ';
259
22.9k
  dumpLocation(D->getLocation());
260
22.9k
  if (D->isFromASTFile())
261
2.92k
    OS << " imported";
262
22.9k
  if (Module *M = D->getOwningModule())
263
175
    OS << " in " << M->getFullModuleName();
264
22.9k
  if (auto *ND = dyn_cast<NamedDecl>(D))
265
21.6k
    for (Module *M : D->getASTContext().getModulesWithMergedDefinition(
266
21.6k
             const_cast<NamedDecl *>(ND)))
267
3
      AddChild([=] { OS << "also in " << M->getFullModuleName(); });
268
22.9k
  if (const NamedDecl *ND = dyn_cast<NamedDecl>(D))
269
21.6k
    if (!ND->isUnconditionallyVisible())
270
66
      OS << " hidden";
271
22.9k
  if (D->isImplicit())
272
8.82k
    OS << " implicit";
273
274
22.9k
  if (D->isUsed())
275
3.85k
    OS << " used";
276
19.1k
  else if (D->isThisDeclarationReferenced())
277
1.37k
    OS << " referenced";
278
279
22.9k
  if (D->isInvalidDecl())
280
46
    OS << " invalid";
281
22.9k
  if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
282
4.14k
    if (FD->isConstexprSpecified())
283
704
      OS << " constexpr";
284
4.14k
    if (FD->isConsteval())
285
0
      OS << " consteval";
286
4.14k
  }
287
288
22.9k
  if (!isa<FunctionDecl>(*D)) {
289
18.8k
    const auto *MD = dyn_cast<ObjCMethodDecl>(D);
290
18.8k
    if (!MD || 
!MD->isThisDeclarationADefinition()177
) {
291
18.7k
      const auto *DC = dyn_cast<DeclContext>(D);
292
18.7k
      if (DC && 
DC->hasExternalLexicalStorage()4.47k
) {
293
659
        ColorScope Color(OS, ShowColors, UndeserializedColor);
294
659
        OS << " <undeserialized declarations>";
295
659
      }
296
18.7k
    }
297
18.8k
  }
298
299
22.9k
  ConstDeclVisitor<TextNodeDumper>::Visit(D);
300
22.9k
}
301
302
142
void TextNodeDumper::Visit(const CXXCtorInitializer *Init) {
303
142
  OS << "CXXCtorInitializer";
304
142
  if (Init->isAnyMemberInitializer()) {
305
109
    OS << ' ';
306
109
    dumpBareDeclRef(Init->getAnyMember());
307
109
  } else 
if (33
Init->isBaseInitializer()33
) {
308
30
    dumpType(QualType(Init->getBaseClass(), 0));
309
30
  } else 
if (3
Init->isDelegatingInitializer()3
) {
310
3
    dumpType(Init->getTypeSourceInfo()->getType());
311
3
  } else {
312
0
    llvm_unreachable("Unknown initializer type");
313
0
  }
314
142
}
315
316
8
void TextNodeDumper::Visit(const BlockDecl::Capture &C) {
317
8
  OS << "capture";
318
8
  if (C.isByRef())
319
0
    OS << " byref";
320
8
  if (C.isNested())
321
0
    OS << " nested";
322
8
  if (C.getVariable()) {
323
8
    OS << ' ';
324
8
    dumpBareDeclRef(C.getVariable());
325
8
  }
326
8
}
327
328
290
void TextNodeDumper::Visit(const OMPClause *C) {
329
290
  if (!C) {
330
0
    ColorScope Color(OS, ShowColors, NullColor);
331
0
    OS << "<<<NULL>>> OMPClause";
332
0
    return;
333
0
  }
334
290
  {
335
290
    ColorScope Color(OS, ShowColors, AttrColor);
336
290
    StringRef ClauseName(llvm::omp::getOpenMPClauseName(C->getClauseKind()));
337
290
    OS << "OMP" << ClauseName.substr(/*Start=*/0, /*N=*/1).upper()
338
290
       << ClauseName.drop_front() << "Clause";
339
290
  }
340
290
  dumpPointer(C);
341
290
  dumpSourceRange(SourceRange(C->getBeginLoc(), C->getEndLoc()));
342
290
  if (C->isImplicit())
343
66
    OS << " <implicit>";
344
290
}
345
346
26
void TextNodeDumper::Visit(const GenericSelectionExpr::ConstAssociation &A) {
347
26
  const TypeSourceInfo *TSI = A.getTypeSourceInfo();
348
26
  if (TSI) {
349
20
    OS << "case ";
350
20
    dumpType(TSI->getType());
351
20
  } else {
352
6
    OS << "default";
353
6
  }
354
355
26
  if (A.isSelected())
356
14
    OS << " selected";
357
26
}
358
359
8
void TextNodeDumper::Visit(const concepts::Requirement *R) {
360
8
  if (!R) {
361
0
    ColorScope Color(OS, ShowColors, NullColor);
362
0
    OS << "<<<NULL>>> Requirement";
363
0
    return;
364
0
  }
365
366
8
  {
367
8
    ColorScope Color(OS, ShowColors, StmtColor);
368
8
    switch (R->getKind()) {
369
2
    case concepts::Requirement::RK_Type:
370
2
      OS << "TypeRequirement";
371
2
      break;
372
2
    case concepts::Requirement::RK_Simple:
373
2
      OS << "SimpleRequirement";
374
2
      break;
375
2
    case concepts::Requirement::RK_Compound:
376
2
      OS << "CompoundRequirement";
377
2
      break;
378
2
    case concepts::Requirement::RK_Nested:
379
2
      OS << "NestedRequirement";
380
2
      break;
381
8
    }
382
8
  }
383
384
8
  dumpPointer(R);
385
386
8
  if (auto *ER = dyn_cast<concepts::ExprRequirement>(R)) {
387
4
    if (ER->hasNoexceptRequirement())
388
2
      OS << " noexcept";
389
4
  }
390
391
8
  if (R->isDependent())
392
6
    OS << " dependent";
393
2
  else
394
2
    OS << (R->isSatisfied() ? " satisfied" : 
" unsatisfied"0
);
395
8
  if (R->containsUnexpandedParameterPack())
396
0
    OS << " contains_unexpanded_pack";
397
8
}
398
399
60
static double GetApproxValue(const llvm::APFloat &F) {
400
60
  llvm::APFloat V = F;
401
60
  bool ignored;
402
60
  V.convert(llvm::APFloat::IEEEdouble(), llvm::APFloat::rmNearestTiesToEven,
403
60
            &ignored);
404
60
  return V.convertToDouble();
405
60
}
406
407
/// True if the \p APValue \p Value can be folded onto the current line.
408
386
static bool isSimpleAPValue(const APValue &Value) {
409
386
  switch (Value.getKind()) {
410
2
  case APValue::None:
411
2
  case APValue::Indeterminate:
412
222
  case APValue::Int:
413
260
  case APValue::Float:
414
260
  case APValue::FixedPoint:
415
268
  case APValue::ComplexInt:
416
276
  case APValue::ComplexFloat:
417
276
  case APValue::LValue:
418
276
  case APValue::MemberPointer:
419
276
  case APValue::AddrLabelDiff:
420
276
    return true;
421
4
  case APValue::Vector:
422
22
  case APValue::Array:
423
62
  case APValue::Struct:
424
62
    return false;
425
48
  case APValue::Union:
426
48
    return isSimpleAPValue(Value.getUnionValue());
427
386
  }
428
0
  llvm_unreachable("unexpected APValue kind!");
429
0
}
430
431
/// Dump the children of the \p APValue \p Value.
432
///
433
/// \param[in] Value          The \p APValue to visit
434
/// \param[in] Ty             The \p QualType passed to \p Visit
435
///
436
/// \param[in] IdxToChildFun  A function mapping an \p APValue and an index
437
///                           to one of the child of the \p APValue
438
///
439
/// \param[in] NumChildren    \p IdxToChildFun will be called on \p Value with
440
///                           the indices in the range \p [0,NumChildren(
441
///
442
/// \param[in] LabelSingular  The label to use on a line with a single child
443
/// \param[in] LabelPlurial   The label to use on a line with multiple children
444
void TextNodeDumper::dumpAPValueChildren(
445
    const APValue &Value, QualType Ty,
446
    const APValue &(*IdxToChildFun)(const APValue &, unsigned),
447
128
    unsigned NumChildren, StringRef LabelSingular, StringRef LabelPlurial) {
448
  // To save some vertical space we print up to MaxChildrenPerLine APValues
449
  // considered to be simple (by isSimpleAPValue) on a single line.
450
128
  constexpr unsigned MaxChildrenPerLine = 4;
451
128
  unsigned I = 0;
452
258
  while (I < NumChildren) {
453
130
    unsigned J = I;
454
342
    while (J < NumChildren) {
455
282
      if (isSimpleAPValue(IdxToChildFun(Value, J)) &&
456
282
          
(J - I < MaxChildrenPerLine)230
) {
457
212
        ++J;
458
212
        continue;
459
212
      }
460
70
      break;
461
282
    }
462
463
130
    J = std::max(I + 1, J);
464
465
    // Print [I,J) on a single line.
466
130
    AddChild(J - I > 1 ? 
LabelPlurial58
:
LabelSingular72
, [=]() {
467
386
      for (unsigned X = I; X < J; 
++X256
) {
468
256
        Visit(IdxToChildFun(Value, X), Ty);
469
256
        if (X + 1 != J)
470
126
          OS << ", ";
471
256
      }
472
130
    });
473
130
    I = J;
474
130
  }
475
128
}
476
477
695
void TextNodeDumper::Visit(const APValue &Value, QualType Ty) {
478
695
  ColorScope Color(OS, ShowColors, ValueKindColor);
479
695
  switch (Value.getKind()) {
480
2
  case APValue::None:
481
2
    OS << "None";
482
2
    return;
483
0
  case APValue::Indeterminate:
484
0
    OS << "Indeterminate";
485
0
    return;
486
485
  case APValue::Int:
487
485
    OS << "Int ";
488
485
    {
489
485
      ColorScope Color(OS, ShowColors, ValueColor);
490
485
      OS << Value.getInt();
491
485
    }
492
485
    return;
493
32
  case APValue::Float:
494
32
    OS << "Float ";
495
32
    {
496
32
      ColorScope Color(OS, ShowColors, ValueColor);
497
32
      OS << GetApproxValue(Value.getFloat());
498
32
    }
499
32
    return;
500
0
  case APValue::FixedPoint:
501
0
    OS << "FixedPoint ";
502
0
    {
503
0
      ColorScope Color(OS, ShowColors, ValueColor);
504
0
      OS << Value.getFixedPoint();
505
0
    }
506
0
    return;
507
16
  case APValue::Vector: {
508
16
    unsigned VectorLength = Value.getVectorLength();
509
16
    OS << "Vector length=" << VectorLength;
510
511
16
    dumpAPValueChildren(
512
16
        Value, Ty,
513
182
        [](const APValue &Value, unsigned Index) -> const APValue & {
514
182
          return Value.getVectorElt(Index);
515
182
        },
516
16
        VectorLength, "element", "elements");
517
16
    return;
518
0
  }
519
14
  case APValue::ComplexInt:
520
14
    OS << "ComplexInt ";
521
14
    {
522
14
      ColorScope Color(OS, ShowColors, ValueColor);
523
14
      OS << Value.getComplexIntReal() << " + " << Value.getComplexIntImag()
524
14
         << 'i';
525
14
    }
526
14
    return;
527
14
  case APValue::ComplexFloat:
528
14
    OS << "ComplexFloat ";
529
14
    {
530
14
      ColorScope Color(OS, ShowColors, ValueColor);
531
14
      OS << GetApproxValue(Value.getComplexFloatReal()) << " + "
532
14
         << GetApproxValue(Value.getComplexFloatImag()) << 'i';
533
14
    }
534
14
    return;
535
2
  case APValue::LValue:
536
2
    (void)Context;
537
2
    OS << "LValue <todo>";
538
2
    return;
539
32
  case APValue::Array: {
540
32
    unsigned ArraySize = Value.getArraySize();
541
32
    unsigned NumInitializedElements = Value.getArrayInitializedElts();
542
32
    OS << "Array size=" << ArraySize;
543
544
32
    dumpAPValueChildren(
545
32
        Value, Ty,
546
180
        [](const APValue &Value, unsigned Index) -> const APValue & {
547
180
          return Value.getArrayInitializedElt(Index);
548
180
        },
549
32
        NumInitializedElements, "element", "elements");
550
551
32
    if (Value.hasArrayFiller()) {
552
12
      AddChild("filler", [=] {
553
12
        {
554
12
          ColorScope Color(OS, ShowColors, ValueColor);
555
12
          OS << ArraySize - NumInitializedElements << " x ";
556
12
        }
557
12
        Visit(Value.getArrayFiller(), Ty);
558
12
      });
559
12
    }
560
561
32
    return;
562
0
  }
563
40
  case APValue::Struct: {
564
40
    OS << "Struct";
565
566
40
    dumpAPValueChildren(
567
40
        Value, Ty,
568
40
        [](const APValue &Value, unsigned Index) -> const APValue & {
569
12
          return Value.getStructBase(Index);
570
12
        },
571
40
        Value.getStructNumBases(), "base", "bases");
572
573
40
    dumpAPValueChildren(
574
40
        Value, Ty,
575
164
        [](const APValue &Value, unsigned Index) -> const APValue & {
576
164
          return Value.getStructField(Index);
577
164
        },
578
40
        Value.getStructNumFields(), "field", "fields");
579
580
40
    return;
581
0
  }
582
56
  case APValue::Union: {
583
56
    OS << "Union";
584
56
    {
585
56
      ColorScope Color(OS, ShowColors, ValueColor);
586
56
      if (const FieldDecl *FD = Value.getUnionField())
587
54
        OS << " ." << *cast<NamedDecl>(FD);
588
56
    }
589
    // If the union value is considered to be simple, fold it into the
590
    // current line to save some vertical space.
591
56
    const APValue &UnionValue = Value.getUnionValue();
592
56
    if (isSimpleAPValue(UnionValue)) {
593
46
      OS << ' ';
594
46
      Visit(UnionValue, Ty);
595
46
    } else {
596
10
      AddChild([=] { Visit(UnionValue, Ty); });
597
10
    }
598
599
56
    return;
600
0
  }
601
2
  case APValue::MemberPointer:
602
2
    OS << "MemberPointer <todo>";
603
2
    return;
604
0
  case APValue::AddrLabelDiff:
605
0
    OS << "AddrLabelDiff <todo>";
606
0
    return;
607
695
  }
608
0
  llvm_unreachable("Unknown APValue kind!");
609
0
}
610
611
66.7k
void TextNodeDumper::dumpPointer(const void *Ptr) {
612
66.7k
  ColorScope Color(OS, ShowColors, AddressColor);
613
66.7k
  OS << ' ' << Ptr;
614
66.7k
}
615
616
101k
void TextNodeDumper::dumpLocation(SourceLocation Loc) {
617
101k
  if (!SM)
618
0
    return;
619
620
101k
  ColorScope Color(OS, ShowColors, LocationColor);
621
101k
  SourceLocation SpellingLoc = SM->getSpellingLoc(Loc);
622
623
  // The general format we print out is filename:line:col, but we drop pieces
624
  // that haven't changed since the last loc printed.
625
101k
  PresumedLoc PLoc = SM->getPresumedLoc(SpellingLoc);
626
627
101k
  if (PLoc.isInvalid()) {
628
11.4k
    OS << "<invalid sloc>";
629
11.4k
    return;
630
11.4k
  }
631
632
90.2k
  if (strcmp(PLoc.getFilename(), LastLocFilename) != 0) {
633
1.53k
    OS << PLoc.getFilename() << ':' << PLoc.getLine() << ':'
634
1.53k
       << PLoc.getColumn();
635
1.53k
    LastLocFilename = PLoc.getFilename();
636
1.53k
    LastLocLine = PLoc.getLine();
637
88.6k
  } else if (PLoc.getLine() != LastLocLine) {
638
21.9k
    OS << "line" << ':' << PLoc.getLine() << ':' << PLoc.getColumn();
639
21.9k
    LastLocLine = PLoc.getLine();
640
66.7k
  } else {
641
66.7k
    OS << "col" << ':' << PLoc.getColumn();
642
66.7k
  }
643
90.2k
}
644
645
53.9k
void TextNodeDumper::dumpSourceRange(SourceRange R) {
646
  // Can't translate locations if a SourceManager isn't available.
647
53.9k
  if (!SM)
648
436
    return;
649
650
53.4k
  OS << " <";
651
53.4k
  dumpLocation(R.getBegin());
652
53.4k
  if (R.getBegin() != R.getEnd()) {
653
25.2k
    OS << ", ";
654
25.2k
    dumpLocation(R.getEnd());
655
25.2k
  }
656
53.4k
  OS << ">";
657
658
  // <t2.c:123:421[blah], t2.c:412:321>
659
53.4k
}
660
661
50.3k
void TextNodeDumper::dumpBareType(QualType T, bool Desugar) {
662
50.3k
  ColorScope Color(OS, ShowColors, TypeColor);
663
664
50.3k
  SplitQualType T_split = T.split();
665
50.3k
  OS << "'" << QualType::getAsString(T_split, PrintPolicy) << "'";
666
667
50.3k
  if (Desugar && 
!T.isNull()45.8k
) {
668
    // If the type is sugared, also dump a (shallow) desugared type.
669
45.8k
    SplitQualType D_split = T.getSplitDesugaredType();
670
45.8k
    if (T_split != D_split)
671
2.48k
      OS << ":'" << QualType::getAsString(D_split, PrintPolicy) << "'";
672
45.8k
  }
673
50.3k
}
674
675
45.7k
void TextNodeDumper::dumpType(QualType T) {
676
45.7k
  OS << ' ';
677
45.7k
  dumpBareType(T);
678
45.7k
}
679
680
7.92k
void TextNodeDumper::dumpBareDeclRef(const Decl *D) {
681
7.92k
  if (!D) {
682
28
    ColorScope Color(OS, ShowColors, NullColor);
683
28
    OS << "<<<NULL>>>";
684
28
    return;
685
28
  }
686
687
7.89k
  {
688
7.89k
    ColorScope Color(OS, ShowColors, DeclKindNameColor);
689
7.89k
    OS << D->getDeclKindName();
690
7.89k
  }
691
7.89k
  dumpPointer(D);
692
693
7.89k
  if (const NamedDecl *ND = dyn_cast<NamedDecl>(D)) {
694
7.88k
    ColorScope Color(OS, ShowColors, DeclNameColor);
695
7.88k
    OS << " '" << ND->getDeclName() << '\'';
696
7.88k
  }
697
698
7.89k
  if (const ValueDecl *VD = dyn_cast<ValueDecl>(D))
699
6.41k
    dumpType(VD->getType());
700
7.89k
}
701
702
21.5k
void TextNodeDumper::dumpName(const NamedDecl *ND) {
703
21.5k
  if (ND->getDeclName()) {
704
19.1k
    ColorScope Color(OS, ShowColors, DeclNameColor);
705
19.1k
    OS << ' ' << ND->getDeclName();
706
19.1k
  }
707
21.5k
}
708
709
185
void TextNodeDumper::dumpAccessSpecifier(AccessSpecifier AS) {
710
185
  const auto AccessSpelling = getAccessSpelling(AS);
711
185
  if (AccessSpelling.empty())
712
0
    return;
713
185
  OS << AccessSpelling;
714
185
}
715
716
void TextNodeDumper::dumpCleanupObject(
717
13
    const ExprWithCleanups::CleanupObject &C) {
718
13
  if (auto *BD = C.dyn_cast<BlockDecl *>())
719
10
    dumpDeclRef(BD, "cleanup");
720
3
  else if (auto *CLE = C.dyn_cast<CompoundLiteralExpr *>())
721
3
    AddChild([=] {
722
3
      OS << "cleanup ";
723
3
      {
724
3
        ColorScope Color(OS, ShowColors, StmtColor);
725
3
        OS << CLE->getStmtClassName();
726
3
      }
727
3
      dumpPointer(CLE);
728
3
    });
729
0
  else
730
0
    llvm_unreachable("unexpected cleanup type");
731
13
}
732
733
1.56k
void TextNodeDumper::dumpDeclRef(const Decl *D, StringRef Label) {
734
1.56k
  if (!D)
735
230
    return;
736
737
1.33k
  AddChild([=] {
738
1.33k
    if (!Label.empty())
739
57
      OS << Label << ' ';
740
1.33k
    dumpBareDeclRef(D);
741
1.33k
  });
742
1.33k
}
743
744
34
const char *TextNodeDumper::getCommandName(unsigned CommandID) {
745
34
  if (Traits)
746
8
    return Traits->getCommandInfo(CommandID)->Name;
747
26
  const comments::CommandInfo *Info =
748
26
      comments::CommandTraits::getBuiltinCommandInfo(CommandID);
749
26
  if (Info)
750
25
    return Info->Name;
751
1
  return "<not a builtin command>";
752
26
}
753
754
88
void TextNodeDumper::printFPOptions(FPOptionsOverride FPO) {
755
88
#define OPTION(NAME, TYPE, WIDTH, PREVIOUS)                                    \
756
968
  if (FPO.has##NAME##Override())                                               \
757
968
    
OS << " " #NAME "=" << FPO.get##NAME##Override()88
;
758
88
#include "clang/Basic/FPOptions.def"
759
88
}
760
761
void TextNodeDumper::visitTextComment(const comments::TextComment *C,
762
184
                                      const comments::FullComment *) {
763
184
  OS << " Text=\"" << C->getText() << "\"";
764
184
}
765
766
void TextNodeDumper::visitInlineCommandComment(
767
9
    const comments::InlineCommandComment *C, const comments::FullComment *) {
768
9
  OS << " Name=\"" << getCommandName(C->getCommandID()) << "\"";
769
9
  switch (C->getRenderKind()) {
770
1
  case comments::InlineCommandComment::RenderNormal:
771
1
    OS << " RenderNormal";
772
1
    break;
773
0
  case comments::InlineCommandComment::RenderBold:
774
0
    OS << " RenderBold";
775
0
    break;
776
6
  case comments::InlineCommandComment::RenderMonospaced:
777
6
    OS << " RenderMonospaced";
778
6
    break;
779
0
  case comments::InlineCommandComment::RenderEmphasized:
780
0
    OS << " RenderEmphasized";
781
0
    break;
782
2
  case comments::InlineCommandComment::RenderAnchor:
783
2
    OS << " RenderAnchor";
784
2
    break;
785
9
  }
786
787
15
  
for (unsigned i = 0, e = C->getNumArgs(); 9
i != e;
++i6
)
788
6
    OS << " Arg[" << i << "]=\"" << C->getArgText(i) << "\"";
789
9
}
790
791
void TextNodeDumper::visitHTMLStartTagComment(
792
18
    const comments::HTMLStartTagComment *C, const comments::FullComment *) {
793
18
  OS << " Name=\"" << C->getTagName() << "\"";
794
18
  if (C->getNumAttrs() != 0) {
795
6
    OS << " Attrs: ";
796
12
    for (unsigned i = 0, e = C->getNumAttrs(); i != e; 
++i6
) {
797
6
      const comments::HTMLStartTagComment::Attribute &Attr = C->getAttr(i);
798
6
      OS << " \"" << Attr.Name << "=\"" << Attr.Value << "\"";
799
6
    }
800
6
  }
801
18
  if (C->isSelfClosing())
802
5
    OS << " SelfClosing";
803
18
}
804
805
void TextNodeDumper::visitHTMLEndTagComment(
806
7
    const comments::HTMLEndTagComment *C, const comments::FullComment *) {
807
7
  OS << " Name=\"" << C->getTagName() << "\"";
808
7
}
809
810
void TextNodeDumper::visitBlockCommandComment(
811
11
    const comments::BlockCommandComment *C, const comments::FullComment *) {
812
11
  OS << " Name=\"" << getCommandName(C->getCommandID()) << "\"";
813
11
  for (unsigned i = 0, e = C->getNumArgs(); i != e; 
++i0
)
814
0
    OS << " Arg[" << i << "]=\"" << C->getArgText(i) << "\"";
815
11
}
816
817
void TextNodeDumper::visitParamCommandComment(
818
31
    const comments::ParamCommandComment *C, const comments::FullComment *FC) {
819
31
  OS << " "
820
31
     << comments::ParamCommandComment::getDirectionAsString(C->getDirection());
821
822
31
  if (C->isDirectionExplicit())
823
18
    OS << " explicitly";
824
13
  else
825
13
    OS << " implicitly";
826
827
31
  if (C->hasParamName()) {
828
30
    if (C->isParamIndexValid())
829
8
      OS << " Param=\"" << C->getParamName(FC) << "\"";
830
22
    else
831
22
      OS << " Param=\"" << C->getParamNameAsWritten() << "\"";
832
30
  }
833
834
31
  if (C->isParamIndexValid() && 
!C->isVarArgParam()8
)
835
4
    OS << " ParamIndex=" << C->getParamIndex();
836
31
}
837
838
void TextNodeDumper::visitTParamCommandComment(
839
9
    const comments::TParamCommandComment *C, const comments::FullComment *FC) {
840
9
  if (C->hasParamName()) {
841
8
    if (C->isPositionValid())
842
2
      OS << " Param=\"" << C->getParamName(FC) << "\"";
843
6
    else
844
6
      OS << " Param=\"" << C->getParamNameAsWritten() << "\"";
845
8
  }
846
847
9
  if (C->isPositionValid()) {
848
2
    OS << " Position=<";
849
4
    for (unsigned i = 0, e = C->getDepth(); i != e; 
++i2
) {
850
2
      OS << C->getIndex(i);
851
2
      if (i != e - 1)
852
0
        OS << ", ";
853
2
    }
854
2
    OS << ">";
855
2
  }
856
9
}
857
858
void TextNodeDumper::visitVerbatimBlockComment(
859
14
    const comments::VerbatimBlockComment *C, const comments::FullComment *) {
860
14
  OS << " Name=\"" << getCommandName(C->getCommandID())
861
14
     << "\""
862
14
        " CloseName=\""
863
14
     << C->getCloseName() << "\"";
864
14
}
865
866
void TextNodeDumper::visitVerbatimBlockLineComment(
867
    const comments::VerbatimBlockLineComment *C,
868
18
    const comments::FullComment *) {
869
18
  OS << " Text=\"" << C->getText() << "\"";
870
18
}
871
872
void TextNodeDumper::visitVerbatimLineComment(
873
4
    const comments::VerbatimLineComment *C, const comments::FullComment *) {
874
4
  OS << " Text=\"" << C->getText() << "\"";
875
4
}
876
877
0
void TextNodeDumper::VisitNullTemplateArgument(const TemplateArgument &) {
878
0
  OS << " null";
879
0
}
880
881
410
void TextNodeDumper::VisitTypeTemplateArgument(const TemplateArgument &TA) {
882
410
  OS << " type";
883
410
  dumpType(TA.getAsType());
884
410
}
885
886
void TextNodeDumper::VisitDeclarationTemplateArgument(
887
5
    const TemplateArgument &TA) {
888
5
  OS << " decl";
889
5
  dumpDeclRef(TA.getAsDecl());
890
5
}
891
892
2
void TextNodeDumper::VisitNullPtrTemplateArgument(const TemplateArgument &) {
893
2
  OS << " nullptr";
894
2
}
895
896
86
void TextNodeDumper::VisitIntegralTemplateArgument(const TemplateArgument &TA) {
897
86
  OS << " integral " << TA.getAsIntegral();
898
86
}
899
900
14
void TextNodeDumper::VisitTemplateTemplateArgument(const TemplateArgument &TA) {
901
14
  OS << " template ";
902
14
  TA.getAsTemplate().dump(OS);
903
14
}
904
905
void TextNodeDumper::VisitTemplateExpansionTemplateArgument(
906
0
    const TemplateArgument &TA) {
907
0
  OS << " template expansion ";
908
0
  TA.getAsTemplateOrTemplatePattern().dump(OS);
909
0
}
910
911
41
void TextNodeDumper::VisitExpressionTemplateArgument(const TemplateArgument &) {
912
41
  OS << " expr";
913
41
}
914
915
24
void TextNodeDumper::VisitPackTemplateArgument(const TemplateArgument &) {
916
24
  OS << " pack";
917
24
}
918
919
4.49k
static void dumpBasePath(raw_ostream &OS, const CastExpr *Node) {
920
4.49k
  if (Node->path_empty())
921
4.43k
    return;
922
923
58
  OS << " (";
924
58
  bool First = true;
925
58
  for (CastExpr::path_const_iterator I = Node->path_begin(),
926
58
                                     E = Node->path_end();
927
116
       I != E; 
++I58
) {
928
58
    const CXXBaseSpecifier *Base = *I;
929
58
    if (!First)
930
0
      OS << " -> ";
931
932
58
    const auto *RD =
933
58
        cast<CXXRecordDecl>(Base->getType()->castAs<RecordType>()->getDecl());
934
935
58
    if (Base->isVirtual())
936
0
      OS << "virtual ";
937
58
    OS << RD->getName();
938
58
    First = false;
939
58
  }
940
941
58
  OS << ')';
942
58
}
943
944
38
void TextNodeDumper::VisitIfStmt(const IfStmt *Node) {
945
38
  if (Node->hasInitStorage())
946
3
    OS << " has_init";
947
38
  if (Node->hasVarStorage())
948
1
    OS << " has_var";
949
38
  if (Node->hasElseStorage())
950
20
    OS << " has_else";
951
38
}
952
953
21
void TextNodeDumper::VisitSwitchStmt(const SwitchStmt *Node) {
954
21
  if (Node->hasInitStorage())
955
3
    OS << " has_init";
956
21
  if (Node->hasVarStorage())
957
0
    OS << " has_var";
958
21
}
959
960
14
void TextNodeDumper::VisitWhileStmt(const WhileStmt *Node) {
961
14
  if (Node->hasVarStorage())
962
1
    OS << " has_var";
963
14
}
964
965
20
void TextNodeDumper::VisitLabelStmt(const LabelStmt *Node) {
966
20
  OS << " '" << Node->getName() << "'";
967
20
  if (Node->isSideEntry())
968
0
    OS << " side_entry";
969
20
}
970
971
9
void TextNodeDumper::VisitGotoStmt(const GotoStmt *Node) {
972
9
  OS << " '" << Node->getLabel()->getName() << "'";
973
9
  dumpPointer(Node->getLabel());
974
9
}
975
976
36
void TextNodeDumper::VisitCaseStmt(const CaseStmt *Node) {
977
36
  if (Node->caseStmtIsGNURange())
978
7
    OS << " gnu_range";
979
36
}
980
981
308
void TextNodeDumper::VisitConstantExpr(const ConstantExpr *Node) {
982
308
  if (Node->hasAPValueResult())
983
284
    AddChild("value",
984
284
             [=] { Visit(Node->getAPValueResult(), Node->getType()); });
985
308
}
986
987
912
void TextNodeDumper::VisitCallExpr(const CallExpr *Node) {
988
912
  if (Node->usesADL())
989
8
    OS << " adl";
990
912
  if (Node->hasStoredFPFeatures())
991
8
    printFPOptions(Node->getFPFeatures());
992
912
}
993
994
41
void TextNodeDumper::VisitCXXOperatorCallExpr(const CXXOperatorCallExpr *Node) {
995
41
  const char *OperatorSpelling = clang::getOperatorSpelling(Node->getOperator());
996
41
  if (OperatorSpelling)
997
41
    OS << " '" << OperatorSpelling << "'";
998
999
41
  VisitCallExpr(Node);
1000
41
}
1001
1002
4.43k
void TextNodeDumper::VisitCastExpr(const CastExpr *Node) {
1003
4.43k
  OS << " <";
1004
4.43k
  {
1005
4.43k
    ColorScope Color(OS, ShowColors, CastColor);
1006
4.43k
    OS << Node->getCastKindName();
1007
4.43k
  }
1008
4.43k
  dumpBasePath(OS, Node);
1009
4.43k
  OS << ">";
1010
4.43k
  if (Node->hasStoredFPFeatures())
1011
60
    printFPOptions(Node->getFPFeatures());
1012
4.43k
}
1013
1014
4.19k
void TextNodeDumper::VisitImplicitCastExpr(const ImplicitCastExpr *Node) {
1015
4.19k
  VisitCastExpr(Node);
1016
4.19k
  if (Node->isPartOfExplicitCast())
1017
127
    OS << " part_of_explicit_cast";
1018
4.19k
}
1019
1020
5.90k
void TextNodeDumper::VisitDeclRefExpr(const DeclRefExpr *Node) {
1021
5.90k
  OS << " ";
1022
5.90k
  dumpBareDeclRef(Node->getDecl());
1023
5.90k
  if (Node->getDecl() != Node->getFoundDecl()) {
1024
98
    OS << " (";
1025
98
    dumpBareDeclRef(Node->getFoundDecl());
1026
98
    OS << ")";
1027
98
  }
1028
5.90k
  switch (Node->isNonOdrUse()) {
1029
5.75k
  case NOUR_None: break;
1030
103
  case NOUR_Unevaluated: OS << " non_odr_use_unevaluated"; break;
1031
48
  case NOUR_Constant: OS << " non_odr_use_constant"; break;
1032
0
  case NOUR_Discarded: OS << " non_odr_use_discarded"; break;
1033
5.90k
  }
1034
5.90k
}
1035
1036
void TextNodeDumper::VisitUnresolvedLookupExpr(
1037
64
    const UnresolvedLookupExpr *Node) {
1038
64
  OS << " (";
1039
64
  if (!Node->requiresADL())
1040
9
    OS << "no ";
1041
64
  OS << "ADL) = '" << Node->getName() << '\'';
1042
1043
64
  UnresolvedLookupExpr::decls_iterator I = Node->decls_begin(),
1044
64
                                       E = Node->decls_end();
1045
64
  if (I == E)
1046
29
    OS << " empty";
1047
107
  for (; I != E; 
++I43
)
1048
43
    dumpPointer(*I);
1049
64
}
1050
1051
0
void TextNodeDumper::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *Node) {
1052
0
  {
1053
0
    ColorScope Color(OS, ShowColors, DeclKindNameColor);
1054
0
    OS << " " << Node->getDecl()->getDeclKindName() << "Decl";
1055
0
  }
1056
0
  OS << "='" << *Node->getDecl() << "'";
1057
0
  dumpPointer(Node->getDecl());
1058
0
  if (Node->isFreeIvar())
1059
0
    OS << " isFreeIvar";
1060
0
}
1061
1062
void TextNodeDumper::VisitSYCLUniqueStableNameExpr(
1063
0
    const SYCLUniqueStableNameExpr *Node) {
1064
0
  dumpType(Node->getTypeSourceInfo()->getType());
1065
0
}
1066
1067
18
void TextNodeDumper::VisitPredefinedExpr(const PredefinedExpr *Node) {
1068
18
  OS << " " << PredefinedExpr::getIdentKindName(Node->getIdentKind());
1069
18
}
1070
1071
14
void TextNodeDumper::VisitCharacterLiteral(const CharacterLiteral *Node) {
1072
14
  ColorScope Color(OS, ShowColors, ValueColor);
1073
14
  OS << " " << Node->getValue();
1074
14
}
1075
1076
3.24k
void TextNodeDumper::VisitIntegerLiteral(const IntegerLiteral *Node) {
1077
3.24k
  bool isSigned = Node->getType()->isSignedIntegerType();
1078
3.24k
  ColorScope Color(OS, ShowColors, ValueColor);
1079
3.24k
  OS << " " << toString(Node->getValue(), 10, isSigned);
1080
3.24k
}
1081
1082
114
void TextNodeDumper::VisitFixedPointLiteral(const FixedPointLiteral *Node) {
1083
114
  ColorScope Color(OS, ShowColors, ValueColor);
1084
114
  OS << " " << Node->getValueAsString(/*Radix=*/10);
1085
114
}
1086
1087
176
void TextNodeDumper::VisitFloatingLiteral(const FloatingLiteral *Node) {
1088
176
  ColorScope Color(OS, ShowColors, ValueColor);
1089
176
  OS << " " << Node->getValueAsApproximateDouble();
1090
176
}
1091
1092
119
void TextNodeDumper::VisitStringLiteral(const StringLiteral *Str) {
1093
119
  ColorScope Color(OS, ShowColors, ValueColor);
1094
119
  OS << " ";
1095
119
  Str->outputString(OS);
1096
119
}
1097
1098
259
void TextNodeDumper::VisitInitListExpr(const InitListExpr *ILE) {
1099
259
  if (auto *Field = ILE->getInitializedFieldInUnion()) {
1100
54
    OS << " field ";
1101
54
    dumpBareDeclRef(Field);
1102
54
  }
1103
259
}
1104
1105
14
void TextNodeDumper::VisitGenericSelectionExpr(const GenericSelectionExpr *E) {
1106
14
  if (E->isResultDependent())
1107
0
    OS << " result_dependent";
1108
14
}
1109
1110
996
void TextNodeDumper::VisitUnaryOperator(const UnaryOperator *Node) {
1111
996
  OS << " " << (Node->isPostfix() ? 
"postfix"718
:
"prefix"278
) << " '"
1112
996
     << UnaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
1113
996
  if (!Node->canOverflow())
1114
179
    OS << " cannot overflow";
1115
996
  if (Node->hasStoredFPFeatures())
1116
0
    printFPOptions(Node->getStoredFPFeatures());
1117
996
}
1118
1119
void TextNodeDumper::VisitUnaryExprOrTypeTraitExpr(
1120
60
    const UnaryExprOrTypeTraitExpr *Node) {
1121
60
  OS << " " << getTraitSpelling(Node->getKind());
1122
1123
60
  if (Node->isArgumentType())
1124
47
    dumpType(Node->getArgumentType());
1125
60
}
1126
1127
333
void TextNodeDumper::VisitMemberExpr(const MemberExpr *Node) {
1128
333
  OS << " " << (Node->isArrow() ? 
"->"108
:
"."225
) << *Node->getMemberDecl();
1129
333
  dumpPointer(Node->getMemberDecl());
1130
333
  switch (Node->isNonOdrUse()) {
1131
319
  case NOUR_None: break;
1132
4
  case NOUR_Unevaluated: OS << " non_odr_use_unevaluated"; break;
1133
10
  case NOUR_Constant: OS << " non_odr_use_constant"; break;
1134
0
  case NOUR_Discarded: OS << " non_odr_use_discarded"; break;
1135
333
  }
1136
333
}
1137
1138
void TextNodeDumper::VisitExtVectorElementExpr(
1139
8
    const ExtVectorElementExpr *Node) {
1140
8
  OS << " " << Node->getAccessor().getNameStart();
1141
8
}
1142
1143
1.48k
void TextNodeDumper::VisitBinaryOperator(const BinaryOperator *Node) {
1144
1.48k
  OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
1145
1.48k
  if (Node->hasStoredFPFeatures())
1146
16
    printFPOptions(Node->getStoredFPFeatures());
1147
1.48k
}
1148
1149
void TextNodeDumper::VisitCompoundAssignOperator(
1150
57
    const CompoundAssignOperator *Node) {
1151
57
  OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode())
1152
57
     << "' ComputeLHSTy=";
1153
57
  dumpBareType(Node->getComputationLHSType());
1154
57
  OS << " ComputeResultTy=";
1155
57
  dumpBareType(Node->getComputationResultType());
1156
57
  if (Node->hasStoredFPFeatures())
1157
0
    printFPOptions(Node->getStoredFPFeatures());
1158
57
}
1159
1160
9
void TextNodeDumper::VisitAddrLabelExpr(const AddrLabelExpr *Node) {
1161
9
  OS << " " << Node->getLabel()->getName();
1162
9
  dumpPointer(Node->getLabel());
1163
9
}
1164
1165
52
void TextNodeDumper::VisitCXXNamedCastExpr(const CXXNamedCastExpr *Node) {
1166
52
  OS << " " << Node->getCastName() << "<"
1167
52
     << Node->getTypeAsWritten().getAsString() << ">"
1168
52
     << " <" << Node->getCastKindName();
1169
52
  dumpBasePath(OS, Node);
1170
52
  OS << ">";
1171
52
}
1172
1173
48
void TextNodeDumper::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *Node) {
1174
48
  OS << " " << (Node->getValue() ? 
"true"31
:
"false"17
);
1175
48
}
1176
1177
111
void TextNodeDumper::VisitCXXThisExpr(const CXXThisExpr *Node) {
1178
111
  if (Node->isImplicit())
1179
70
    OS << " implicit";
1180
111
  OS << " this";
1181
111
}
1182
1183
void TextNodeDumper::VisitCXXFunctionalCastExpr(
1184
31
    const CXXFunctionalCastExpr *Node) {
1185
31
  OS << " functional cast to " << Node->getTypeAsWritten().getAsString() << " <"
1186
31
     << Node->getCastKindName() << ">";
1187
31
  if (Node->hasStoredFPFeatures())
1188
2
    printFPOptions(Node->getFPFeatures());
1189
31
}
1190
1191
29
void TextNodeDumper::VisitCXXStaticCastExpr(const CXXStaticCastExpr *Node) {
1192
29
  VisitCXXNamedCastExpr(Node);
1193
29
  if (Node->hasStoredFPFeatures())
1194
2
    printFPOptions(Node->getFPFeatures());
1195
29
}
1196
1197
void TextNodeDumper::VisitCXXUnresolvedConstructExpr(
1198
24
    const CXXUnresolvedConstructExpr *Node) {
1199
24
  dumpType(Node->getTypeAsWritten());
1200
24
  if (Node->isListInitialization())
1201
3
    OS << " list";
1202
24
}
1203
1204
400
void TextNodeDumper::VisitCXXConstructExpr(const CXXConstructExpr *Node) {
1205
400
  CXXConstructorDecl *Ctor = Node->getConstructor();
1206
400
  dumpType(Ctor->getType());
1207
400
  if (Node->isElidable())
1208
100
    OS << " elidable";
1209
400
  if (Node->isListInitialization())
1210
10
    OS << " list";
1211
400
  if (Node->isStdInitListInitialization())
1212
1
    OS << " std::initializer_list";
1213
400
  if (Node->requiresZeroInitialization())
1214
27
    OS << " zeroing";
1215
400
}
1216
1217
void TextNodeDumper::VisitCXXBindTemporaryExpr(
1218
39
    const CXXBindTemporaryExpr *Node) {
1219
39
  OS << " (CXXTemporary";
1220
39
  dumpPointer(Node);
1221
39
  OS << ")";
1222
39
}
1223
1224
49
void TextNodeDumper::VisitCXXNewExpr(const CXXNewExpr *Node) {
1225
49
  if (Node->isGlobalNew())
1226
4
    OS << " global";
1227
49
  if (Node->isArray())
1228
16
    OS << " array";
1229
49
  if (Node->getOperatorNew()) {
1230
46
    OS << ' ';
1231
46
    dumpBareDeclRef(Node->getOperatorNew());
1232
46
  }
1233
  // We could dump the deallocation function used in case of error, but it's
1234
  // usually not that interesting.
1235
49
}
1236
1237
43
void TextNodeDumper::VisitCXXDeleteExpr(const CXXDeleteExpr *Node) {
1238
43
  if (Node->isGlobalDelete())
1239
4
    OS << " global";
1240
43
  if (Node->isArrayForm())
1241
13
    OS << " array";
1242
43
  if (Node->getOperatorDelete()) {
1243
41
    OS << ' ';
1244
41
    dumpBareDeclRef(Node->getOperatorDelete());
1245
41
  }
1246
43
}
1247
1248
22
void TextNodeDumper::VisitTypeTraitExpr(const TypeTraitExpr *Node) {
1249
22
  OS << " " << getTraitSpelling(Node->getTrait());
1250
22
}
1251
1252
2
void TextNodeDumper::VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr *Node) {
1253
2
  OS << " " << getTraitSpelling(Node->getTrait());
1254
2
}
1255
1256
2
void TextNodeDumper::VisitExpressionTraitExpr(const ExpressionTraitExpr *Node) {
1257
2
  OS << " " << getTraitSpelling(Node->getTrait());
1258
2
}
1259
1260
void TextNodeDumper::VisitMaterializeTemporaryExpr(
1261
193
    const MaterializeTemporaryExpr *Node) {
1262
193
  if (const ValueDecl *VD = Node->getExtendingDecl()) {
1263
8
    OS << " extended by ";
1264
8
    dumpBareDeclRef(VD);
1265
8
  }
1266
193
}
1267
1268
168
void TextNodeDumper::VisitExprWithCleanups(const ExprWithCleanups *Node) {
1269
181
  for (unsigned i = 0, e = Node->getNumObjects(); i != e; 
++i13
)
1270
13
    dumpCleanupObject(Node->getObject(i));
1271
168
}
1272
1273
12
void TextNodeDumper::VisitSizeOfPackExpr(const SizeOfPackExpr *Node) {
1274
12
  dumpPointer(Node->getPack());
1275
12
  dumpName(Node->getPack());
1276
12
}
1277
1278
void TextNodeDumper::VisitCXXDependentScopeMemberExpr(
1279
28
    const CXXDependentScopeMemberExpr *Node) {
1280
28
  OS << " " << (Node->isArrow() ? 
"->"10
:
"."18
) << Node->getMember();
1281
28
}
1282
1283
5
void TextNodeDumper::VisitObjCMessageExpr(const ObjCMessageExpr *Node) {
1284
5
  OS << " selector=";
1285
5
  Node->getSelector().print(OS);
1286
5
  switch (Node->getReceiverKind()) {
1287
1
  case ObjCMessageExpr::Instance:
1288
1
    break;
1289
1290
0
  case ObjCMessageExpr::Class:
1291
0
    OS << " class=";
1292
0
    dumpBareType(Node->getClassReceiver());
1293
0
    break;
1294
1295
3
  case ObjCMessageExpr::SuperInstance:
1296
3
    OS << " super (instance)";
1297
3
    break;
1298
1299
1
  case ObjCMessageExpr::SuperClass:
1300
1
    OS << " super (class)";
1301
1
    break;
1302
5
  }
1303
5
}
1304
1305
2
void TextNodeDumper::VisitObjCBoxedExpr(const ObjCBoxedExpr *Node) {
1306
2
  if (auto *BoxingMethod = Node->getBoxingMethod()) {
1307
0
    OS << " selector=";
1308
0
    BoxingMethod->getSelector().print(OS);
1309
0
  }
1310
2
}
1311
1312
9
void TextNodeDumper::VisitObjCAtCatchStmt(const ObjCAtCatchStmt *Node) {
1313
9
  if (!Node->getCatchParamDecl())
1314
2
    OS << " catch all";
1315
9
}
1316
1317
0
void TextNodeDumper::VisitObjCEncodeExpr(const ObjCEncodeExpr *Node) {
1318
0
  dumpType(Node->getEncodedType());
1319
0
}
1320
1321
0
void TextNodeDumper::VisitObjCSelectorExpr(const ObjCSelectorExpr *Node) {
1322
0
  OS << " ";
1323
0
  Node->getSelector().print(OS);
1324
0
}
1325
1326
0
void TextNodeDumper::VisitObjCProtocolExpr(const ObjCProtocolExpr *Node) {
1327
0
  OS << ' ' << *Node->getProtocol();
1328
0
}
1329
1330
2
void TextNodeDumper::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *Node) {
1331
2
  if (Node->isImplicitProperty()) {
1332
0
    OS << " Kind=MethodRef Getter=\"";
1333
0
    if (Node->getImplicitPropertyGetter())
1334
0
      Node->getImplicitPropertyGetter()->getSelector().print(OS);
1335
0
    else
1336
0
      OS << "(null)";
1337
1338
0
    OS << "\" Setter=\"";
1339
0
    if (ObjCMethodDecl *Setter = Node->getImplicitPropertySetter())
1340
0
      Setter->getSelector().print(OS);
1341
0
    else
1342
0
      OS << "(null)";
1343
0
    OS << "\"";
1344
2
  } else {
1345
2
    OS << " Kind=PropertyRef Property=\"" << *Node->getExplicitProperty()
1346
2
       << '"';
1347
2
  }
1348
1349
2
  if (Node->isSuperReceiver())
1350
2
    OS << " super";
1351
1352
2
  OS << " Messaging=";
1353
2
  if (Node->isMessagingGetter() && Node->isMessagingSetter())
1354
0
    OS << "Getter&Setter";
1355
2
  else if (Node->isMessagingGetter())
1356
2
    OS << "Getter";
1357
0
  else if (Node->isMessagingSetter())
1358
0
    OS << "Setter";
1359
2
}
1360
1361
void TextNodeDumper::VisitObjCSubscriptRefExpr(
1362
0
    const ObjCSubscriptRefExpr *Node) {
1363
0
  if (Node->isArraySubscriptRefExpr())
1364
0
    OS << " Kind=ArraySubscript GetterForArray=\"";
1365
0
  else
1366
0
    OS << " Kind=DictionarySubscript GetterForDictionary=\"";
1367
0
  if (Node->getAtIndexMethodDecl())
1368
0
    Node->getAtIndexMethodDecl()->getSelector().print(OS);
1369
0
  else
1370
0
    OS << "(null)";
1371
1372
0
  if (Node->isArraySubscriptRefExpr())
1373
0
    OS << "\" SetterForArray=\"";
1374
0
  else
1375
0
    OS << "\" SetterForDictionary=\"";
1376
0
  if (Node->setAtIndexMethodDecl())
1377
0
    Node->setAtIndexMethodDecl()->getSelector().print(OS);
1378
0
  else
1379
0
    OS << "(null)";
1380
0
}
1381
1382
7
void TextNodeDumper::VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *Node) {
1383
7
  OS << " " << (Node->getValue() ? "__objc_yes" : 
"__objc_no"0
);
1384
7
}
1385
1386
0
void TextNodeDumper::VisitOMPIteratorExpr(const OMPIteratorExpr *Node) {
1387
0
  OS << " ";
1388
0
  for (unsigned I = 0, E = Node->numOfIterators(); I < E; ++I) {
1389
0
    Visit(Node->getIteratorDecl(I));
1390
0
    OS << " = ";
1391
0
    const OMPIteratorExpr::IteratorRange Range = Node->getIteratorRange(I);
1392
0
    OS << " begin ";
1393
0
    Visit(Range.Begin);
1394
0
    OS << " end ";
1395
0
    Visit(Range.End);
1396
0
    if (Range.Step) {
1397
0
      OS << " step ";
1398
0
      Visit(Range.Step);
1399
0
    }
1400
0
  }
1401
0
}
1402
1403
void TextNodeDumper::VisitConceptSpecializationExpr(
1404
20
    const ConceptSpecializationExpr *Node) {
1405
20
  OS << " ";
1406
20
  dumpBareDeclRef(Node->getFoundDecl());
1407
20
}
1408
1409
void TextNodeDumper::VisitRequiresExpr(
1410
2
    const RequiresExpr *Node) {
1411
2
  if (!Node->isValueDependent())
1412
0
    OS << (Node->isSatisfied() ? " satisfied" : " unsatisfied");
1413
2
}
1414
1415
1
void TextNodeDumper::VisitRValueReferenceType(const ReferenceType *T) {
1416
1
  if (T->isSpelledAsLValue())
1417
0
    OS << " written as lvalue reference";
1418
1
}
1419
1420
338
void TextNodeDumper::VisitArrayType(const ArrayType *T) {
1421
338
  switch (T->getSizeModifier()) {
1422
338
  case ArrayType::Normal:
1423
338
    break;
1424
0
  case ArrayType::Static:
1425
0
    OS << " static";
1426
0
    break;
1427
0
  case ArrayType::Star:
1428
0
    OS << " *";
1429
0
    break;
1430
338
  }
1431
338
  OS << " " << T->getIndexTypeQualifiers().getAsString();
1432
338
}
1433
1434
334
void TextNodeDumper::VisitConstantArrayType(const ConstantArrayType *T) {
1435
334
  OS << " " << T->getSize();
1436
334
  VisitArrayType(T);
1437
334
}
1438
1439
0
void TextNodeDumper::VisitVariableArrayType(const VariableArrayType *T) {
1440
0
  OS << " ";
1441
0
  dumpSourceRange(T->getBracketsRange());
1442
0
  VisitArrayType(T);
1443
0
}
1444
1445
void TextNodeDumper::VisitDependentSizedArrayType(
1446
4
    const DependentSizedArrayType *T) {
1447
4
  VisitArrayType(T);
1448
4
  OS << " ";
1449
4
  dumpSourceRange(T->getBracketsRange());
1450
4
}
1451
1452
void TextNodeDumper::VisitDependentSizedExtVectorType(
1453
0
    const DependentSizedExtVectorType *T) {
1454
0
  OS << " ";
1455
0
  dumpLocation(T->getAttributeLoc());
1456
0
}
1457
1458
6
void TextNodeDumper::VisitVectorType(const VectorType *T) {
1459
6
  switch (T->getVectorKind()) {
1460
5
  case VectorType::GenericVector:
1461
5
    break;
1462
1
  case VectorType::AltiVecVector:
1463
1
    OS << " altivec";
1464
1
    break;
1465
0
  case VectorType::AltiVecPixel:
1466
0
    OS << " altivec pixel";
1467
0
    break;
1468
0
  case VectorType::AltiVecBool:
1469
0
    OS << " altivec bool";
1470
0
    break;
1471
0
  case VectorType::NeonVector:
1472
0
    OS << " neon";
1473
0
    break;
1474
0
  case VectorType::NeonPolyVector:
1475
0
    OS << " neon poly";
1476
0
    break;
1477
0
  case VectorType::SveFixedLengthDataVector:
1478
0
    OS << " fixed-length sve data vector";
1479
0
    break;
1480
0
  case VectorType::SveFixedLengthPredicateVector:
1481
0
    OS << " fixed-length sve predicate vector";
1482
0
    break;
1483
6
  }
1484
6
  OS << " " << T->getNumElements();
1485
6
}
1486
1487
25
void TextNodeDumper::VisitFunctionType(const FunctionType *T) {
1488
25
  auto EI = T->getExtInfo();
1489
25
  if (EI.getNoReturn())
1490
0
    OS << " noreturn";
1491
25
  if (EI.getProducesResult())
1492
0
    OS << " produces_result";
1493
25
  if (EI.getHasRegParm())
1494
0
    OS << " regparm " << EI.getRegParm();
1495
25
  OS << " " << FunctionType::getNameForCallConv(EI.getCC());
1496
25
}
1497
1498
25
void TextNodeDumper::VisitFunctionProtoType(const FunctionProtoType *T) {
1499
25
  auto EPI = T->getExtProtoInfo();
1500
25
  if (EPI.HasTrailingReturn)
1501
10
    OS << " trailing_return";
1502
25
  if (T->isConst())
1503
0
    OS << " const";
1504
25
  if (T->isVolatile())
1505
0
    OS << " volatile";
1506
25
  if (T->isRestrict())
1507
0
    OS << " restrict";
1508
25
  if (T->getExtProtoInfo().Variadic)
1509
0
    OS << " variadic";
1510
25
  switch (EPI.RefQualifier) {
1511
25
  case RQ_None:
1512
25
    break;
1513
0
  case RQ_LValue:
1514
0
    OS << " &";
1515
0
    break;
1516
0
  case RQ_RValue:
1517
0
    OS << " &&";
1518
0
    break;
1519
25
  }
1520
  // FIXME: Exception specification.
1521
  // FIXME: Consumed parameters.
1522
25
  VisitFunctionType(T);
1523
25
}
1524
1525
0
void TextNodeDumper::VisitUnresolvedUsingType(const UnresolvedUsingType *T) {
1526
0
  dumpDeclRef(T->getDecl());
1527
0
}
1528
1529
30
void TextNodeDumper::VisitTypedefType(const TypedefType *T) {
1530
30
  dumpDeclRef(T->getDecl());
1531
30
}
1532
1533
0
void TextNodeDumper::VisitUnaryTransformType(const UnaryTransformType *T) {
1534
0
  switch (T->getUTTKind()) {
1535
0
  case UnaryTransformType::EnumUnderlyingType:
1536
0
    OS << " underlying_type";
1537
0
    break;
1538
0
  }
1539
0
}
1540
1541
842
void TextNodeDumper::VisitTagType(const TagType *T) {
1542
842
  dumpDeclRef(T->getDecl());
1543
842
}
1544
1545
105
void TextNodeDumper::VisitTemplateTypeParmType(const TemplateTypeParmType *T) {
1546
105
  OS << " depth " << T->getDepth() << " index " << T->getIndex();
1547
105
  if (T->isParameterPack())
1548
10
    OS << " pack";
1549
105
  dumpDeclRef(T->getDecl());
1550
105
}
1551
1552
1
void TextNodeDumper::VisitAutoType(const AutoType *T) {
1553
1
  if (T->isDecltypeAuto())
1554
0
    OS << " decltype(auto)";
1555
1
  if (!T->isDeduced())
1556
0
    OS << " undeduced";
1557
1
  if (T->isConstrained()) {
1558
0
    dumpDeclRef(T->getTypeConstraintConcept());
1559
0
    for (const auto &Arg : T->getTypeConstraintArguments())
1560
0
      VisitTemplateArgument(Arg);
1561
0
  }
1562
1
}
1563
1564
void TextNodeDumper::VisitTemplateSpecializationType(
1565
63
    const TemplateSpecializationType *T) {
1566
63
  if (T->isTypeAlias())
1567
6
    OS << " alias";
1568
63
  OS << " ";
1569
63
  T->getTemplateName().dump(OS);
1570
63
}
1571
1572
void TextNodeDumper::VisitInjectedClassNameType(
1573
15
    const InjectedClassNameType *T) {
1574
15
  dumpDeclRef(T->getDecl());
1575
15
}
1576
1577
5
void TextNodeDumper::VisitObjCInterfaceType(const ObjCInterfaceType *T) {
1578
5
  dumpDeclRef(T->getDecl());
1579
5
}
1580
1581
6
void TextNodeDumper::VisitPackExpansionType(const PackExpansionType *T) {
1582
6
  if (auto N = T->getNumExpansions())
1583
2
    OS << " expansions " << *N;
1584
6
}
1585
1586
4
void TextNodeDumper::VisitLabelDecl(const LabelDecl *D) { dumpName(D); }
1587
1588
2.71k
void TextNodeDumper::VisitTypedefDecl(const TypedefDecl *D) {
1589
2.71k
  dumpName(D);
1590
2.71k
  dumpType(D->getUnderlyingType());
1591
2.71k
  if (D->isModulePrivate())
1592
1
    OS << " __module_private__";
1593
2.71k
}
1594
1595
72
void TextNodeDumper::VisitEnumDecl(const EnumDecl *D) {
1596
72
  if (D->isScoped()) {
1597
9
    if (D->isScopedUsingClassTag())
1598
9
      OS << " class";
1599
0
    else
1600
0
      OS << " struct";
1601
9
  }
1602
72
  dumpName(D);
1603
72
  if (D->isModulePrivate())
1604
1
    OS << " __module_private__";
1605
72
  if (D->isFixed())
1606
11
    dumpType(D->getIntegerType());
1607
72
}
1608
1609
2.74k
void TextNodeDumper::VisitRecordDecl(const RecordDecl *D) {
1610
2.74k
  OS << ' ' << D->getKindName();
1611
2.74k
  dumpName(D);
1612
2.74k
  if (D->isModulePrivate())
1613
1
    OS << " __module_private__";
1614
2.74k
  if (D->isCompleteDefinition())
1615
1.65k
    OS << " definition";
1616
2.74k
}
1617
1618
73
void TextNodeDumper::VisitEnumConstantDecl(const EnumConstantDecl *D) {
1619
73
  dumpName(D);
1620
73
  dumpType(D->getType());
1621
73
}
1622
1623
52
void TextNodeDumper::VisitIndirectFieldDecl(const IndirectFieldDecl *D) {
1624
52
  dumpName(D);
1625
52
  dumpType(D->getType());
1626
1627
52
  for (const auto *Child : D->chain())
1628
104
    dumpDeclRef(Child);
1629
52
}
1630
1631
4.14k
void TextNodeDumper::VisitFunctionDecl(const FunctionDecl *D) {
1632
4.14k
  dumpName(D);
1633
4.14k
  dumpType(D->getType());
1634
1635
4.14k
  StorageClass SC = D->getStorageClass();
1636
4.14k
  if (SC != SC_None)
1637
260
    OS << ' ' << VarDecl::getStorageClassSpecifierString(SC);
1638
4.14k
  if (D->isInlineSpecified())
1639
1.40k
    OS << " inline";
1640
4.14k
  if (D->isVirtualAsWritten())
1641
47
    OS << " virtual";
1642
4.14k
  if (D->isModulePrivate())
1643
0
    OS << " __module_private__";
1644
1645
4.14k
  if (D->isPure())
1646
6
    OS << " pure";
1647
4.14k
  if (D->isDefaulted()) {
1648
1.05k
    OS << " default";
1649
1.05k
    if (D->isDeleted())
1650
87
      OS << "_delete";
1651
1.05k
  }
1652
4.14k
  if (D->isDeletedAsWritten())
1653
20
    OS << " delete";
1654
4.14k
  if (D->isTrivial())
1655
853
    OS << " trivial";
1656
1657
4.14k
  if (const auto *FPT = D->getType()->getAs<FunctionProtoType>()) {
1658
3.93k
    FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo();
1659
3.93k
    switch (EPI.ExceptionSpec.Type) {
1660
3.20k
    default:
1661
3.20k
      break;
1662
3.20k
    case EST_Unevaluated:
1663
730
      OS << " noexcept-unevaluated " << EPI.ExceptionSpec.SourceDecl;
1664
730
      break;
1665
0
    case EST_Uninstantiated:
1666
0
      OS << " noexcept-uninstantiated " << EPI.ExceptionSpec.SourceTemplate;
1667
0
      break;
1668
3.93k
    }
1669
3.93k
  }
1670
1671
4.14k
  if (const auto *MD = dyn_cast<CXXMethodDecl>(D)) {
1672
2.07k
    if (MD->size_overridden_methods() != 0) {
1673
14
      auto dumpOverride = [=](const CXXMethodDecl *D) {
1674
14
        SplitQualType T_split = D->getType().split();
1675
14
        OS << D << " " << D->getParent()->getName() << "::" << D->getDeclName()
1676
14
           << " '" << QualType::getAsString(T_split, PrintPolicy) << "'";
1677
14
      };
1678
1679
13
      AddChild([=] {
1680
13
        auto Overrides = MD->overridden_methods();
1681
13
        OS << "Overrides: [ ";
1682
13
        dumpOverride(*Overrides.begin());
1683
13
        for (const auto *Override :
1684
13
             llvm::make_range(Overrides.begin() + 1, Overrides.end())) {
1685
1
          OS << ", ";
1686
1
          dumpOverride(Override);
1687
1
        }
1688
13
        OS << " ]";
1689
13
      });
1690
13
    }
1691
2.07k
  }
1692
1693
  // Since NumParams comes from the FunctionProtoType of the FunctionDecl and
1694
  // the Params are set later, it is possible for a dump during debugging to
1695
  // encounter a FunctionDecl that has been created but hasn't been assigned
1696
  // ParmVarDecls yet.
1697
4.14k
  if (!D->param_empty() && 
!D->param_begin()1.91k
)
1698
0
    OS << " <<<NULL params x " << D->getNumParams() << ">>>";
1699
4.14k
}
1700
1701
void TextNodeDumper::VisitLifetimeExtendedTemporaryDecl(
1702
0
    const LifetimeExtendedTemporaryDecl *D) {
1703
0
  OS << " extended by ";
1704
0
  dumpBareDeclRef(D->getExtendingDecl());
1705
0
  OS << " mangling ";
1706
0
  {
1707
0
    ColorScope Color(OS, ShowColors, ValueColor);
1708
0
    OS << D->getManglingNumber();
1709
0
  }
1710
0
}
1711
1712
1.78k
void TextNodeDumper::VisitFieldDecl(const FieldDecl *D) {
1713
1.78k
  dumpName(D);
1714
1.78k
  dumpType(D->getType());
1715
1.78k
  if (D->isMutable())
1716
2
    OS << " mutable";
1717
1.78k
  if (D->isModulePrivate())
1718
1
    OS << " __module_private__";
1719
1.78k
}
1720
1721
7.94k
void TextNodeDumper::VisitVarDecl(const VarDecl *D) {
1722
7.94k
  dumpName(D);
1723
7.94k
  dumpType(D->getType());
1724
7.94k
  StorageClass SC = D->getStorageClass();
1725
7.94k
  if (SC != SC_None)
1726
110
    OS << ' ' << VarDecl::getStorageClassSpecifierString(SC);
1727
7.94k
  switch (D->getTLSKind()) {
1728
7.93k
  case VarDecl::TLS_None:
1729
7.93k
    break;
1730
10
  case VarDecl::TLS_Static:
1731
10
    OS << " tls";
1732
10
    break;
1733
7
  case VarDecl::TLS_Dynamic:
1734
7
    OS << " tls_dynamic";
1735
7
    break;
1736
7.94k
  }
1737
7.94k
  if (D->isModulePrivate())
1738
1
    OS << " __module_private__";
1739
7.94k
  if (D->isNRVOVariable())
1740
20
    OS << " nrvo";
1741
7.94k
  if (D->isInline())
1742
1
    OS << " inline";
1743
7.94k
  if (D->isConstexpr())
1744
90
    OS << " constexpr";
1745
7.94k
  if (D->hasInit()) {
1746
2.41k
    switch (D->getInitStyle()) {
1747
2.28k
    case VarDecl::CInit:
1748
2.28k
      OS << " cinit";
1749
2.28k
      break;
1750
88
    case VarDecl::CallInit:
1751
88
      OS << " callinit";
1752
88
      break;
1753
40
    case VarDecl::ListInit:
1754
40
      OS << " listinit";
1755
40
      break;
1756
2.41k
    }
1757
2.41k
  }
1758
7.94k
  if (D->needsDestruction(D->getASTContext()))
1759
44
    OS << " destroyed";
1760
7.94k
  if (D->isParameterPack())
1761
19
    OS << " pack";
1762
1763
7.94k
  if (D->hasInit()) {
1764
2.41k
    const Expr *E = D->getInit();
1765
    // Only dump the value of constexpr VarDecls for now.
1766
2.41k
    if (E && !E->isValueDependent() && 
D->isConstexpr()2.32k
) {
1767
87
      const APValue *Value = D->evaluateValue();
1768
87
      if (Value)
1769
87
        AddChild("value", [=] { Visit(*Value, E->getType()); });
1770
87
    }
1771
2.41k
  }
1772
7.94k
}
1773
1774
0
void TextNodeDumper::VisitBindingDecl(const BindingDecl *D) {
1775
0
  dumpName(D);
1776
0
  dumpType(D->getType());
1777
0
}
1778
1779
676
void TextNodeDumper::VisitCapturedDecl(const CapturedDecl *D) {
1780
676
  if (D->isNothrow())
1781
585
    OS << " nothrow";
1782
676
}
1783
1784
4
void TextNodeDumper::VisitImportDecl(const ImportDecl *D) {
1785
4
  OS << ' ' << D->getImportedModule()->getFullModuleName();
1786
1787
4
  for (Decl *InitD :
1788
4
       D->getASTContext().getModuleInitializers(D->getImportedModule()))
1789
0
    dumpDeclRef(InitD, "initializer");
1790
4
}
1791
1792
0
void TextNodeDumper::VisitPragmaCommentDecl(const PragmaCommentDecl *D) {
1793
0
  OS << ' ';
1794
0
  switch (D->getCommentKind()) {
1795
0
  case PCK_Unknown:
1796
0
    llvm_unreachable("unexpected pragma comment kind");
1797
0
  case PCK_Compiler:
1798
0
    OS << "compiler";
1799
0
    break;
1800
0
  case PCK_ExeStr:
1801
0
    OS << "exestr";
1802
0
    break;
1803
0
  case PCK_Lib:
1804
0
    OS << "lib";
1805
0
    break;
1806
0
  case PCK_Linker:
1807
0
    OS << "linker";
1808
0
    break;
1809
0
  case PCK_User:
1810
0
    OS << "user";
1811
0
    break;
1812
0
  }
1813
0
  StringRef Arg = D->getArg();
1814
0
  if (!Arg.empty())
1815
0
    OS << " \"" << Arg << "\"";
1816
0
}
1817
1818
void TextNodeDumper::VisitPragmaDetectMismatchDecl(
1819
0
    const PragmaDetectMismatchDecl *D) {
1820
0
  OS << " \"" << D->getName() << "\" \"" << D->getValue() << "\"";
1821
0
}
1822
1823
void TextNodeDumper::VisitOMPExecutableDirective(
1824
321
    const OMPExecutableDirective *D) {
1825
321
  if (D->isStandaloneDirective())
1826
66
    OS << " openmp_standalone_directive";
1827
321
}
1828
1829
void TextNodeDumper::VisitOMPDeclareReductionDecl(
1830
6
    const OMPDeclareReductionDecl *D) {
1831
6
  dumpName(D);
1832
6
  dumpType(D->getType());
1833
6
  OS << " combiner";
1834
6
  dumpPointer(D->getCombiner());
1835
6
  if (const auto *Initializer = D->getInitializer()) {
1836
2
    OS << " initializer";
1837
2
    dumpPointer(Initializer);
1838
2
    switch (D->getInitializerKind()) {
1839
0
    case OMPDeclareReductionDecl::DirectInit:
1840
0
      OS << " omp_priv = ";
1841
0
      break;
1842
2
    case OMPDeclareReductionDecl::CopyInit:
1843
2
      OS << " omp_priv ()";
1844
2
      break;
1845
0
    case OMPDeclareReductionDecl::CallInit:
1846
0
      break;
1847
2
    }
1848
2
  }
1849
6
}
1850
1851
0
void TextNodeDumper::VisitOMPRequiresDecl(const OMPRequiresDecl *D) {
1852
0
  for (const auto *C : D->clauselists()) {
1853
0
    AddChild([=] {
1854
0
      if (!C) {
1855
0
        ColorScope Color(OS, ShowColors, NullColor);
1856
0
        OS << "<<<NULL>>> OMPClause";
1857
0
        return;
1858
0
      }
1859
0
      {
1860
0
        ColorScope Color(OS, ShowColors, AttrColor);
1861
0
        StringRef ClauseName(
1862
0
            llvm::omp::getOpenMPClauseName(C->getClauseKind()));
1863
0
        OS << "OMP" << ClauseName.substr(/*Start=*/0, /*N=*/1).upper()
1864
0
           << ClauseName.drop_front() << "Clause";
1865
0
      }
1866
0
      dumpPointer(C);
1867
0
      dumpSourceRange(SourceRange(C->getBeginLoc(), C->getEndLoc()));
1868
0
    });
1869
0
  }
1870
0
}
1871
1872
96
void TextNodeDumper::VisitOMPCapturedExprDecl(const OMPCapturedExprDecl *D) {
1873
96
  dumpName(D);
1874
96
  dumpType(D->getType());
1875
96
}
1876
1877
153
void TextNodeDumper::VisitNamespaceDecl(const NamespaceDecl *D) {
1878
153
  dumpName(D);
1879
153
  if (D->isInline())
1880
3
    OS << " inline";
1881
153
  if (!D->isOriginalNamespace())
1882
4
    dumpDeclRef(D->getOriginalNamespace(), "original");
1883
153
}
1884
1885
23
void TextNodeDumper::VisitUsingDirectiveDecl(const UsingDirectiveDecl *D) {
1886
23
  OS << ' ';
1887
23
  dumpBareDeclRef(D->getNominatedNamespace());
1888
23
}
1889
1890
4
void TextNodeDumper::VisitNamespaceAliasDecl(const NamespaceAliasDecl *D) {
1891
4
  dumpName(D);
1892
4
  dumpDeclRef(D->getAliasedNamespace());
1893
4
}
1894
1895
79
void TextNodeDumper::VisitTypeAliasDecl(const TypeAliasDecl *D) {
1896
79
  dumpName(D);
1897
79
  dumpType(D->getUnderlyingType());
1898
79
}
1899
1900
void TextNodeDumper::VisitTypeAliasTemplateDecl(
1901
7
    const TypeAliasTemplateDecl *D) {
1902
7
  dumpName(D);
1903
7
}
1904
1905
2.33k
void TextNodeDumper::VisitCXXRecordDecl(const CXXRecordDecl *D) {
1906
2.33k
  VisitRecordDecl(D);
1907
2.33k
  if (!D->isCompleteDefinition())
1908
1.07k
    return;
1909
1910
1.25k
  AddChild([=] {
1911
1.25k
    {
1912
1.25k
      ColorScope Color(OS, ShowColors, DeclKindNameColor);
1913
1.25k
      OS << "DefinitionData";
1914
1.25k
    }
1915
1.25k
#define FLAG(fn, name)                                                         \
1916
84.1k
  
if (3.67k
D->fn()) \
1917
37.9k
    OS << " " #name;
1918
1.25k
    FLAG(isParsingBaseSpecifiers, parsing_base_specifiers);
1919
1920
1.25k
    FLAG(isGenericLambda, generic);
1921
1.25k
    FLAG(isLambda, lambda);
1922
1923
1.25k
    FLAG(isAnonymousStructOrUnion, is_anonymous);
1924
1.25k
    FLAG(canPassInRegisters, pass_in_registers);
1925
1.25k
    FLAG(isEmpty, empty);
1926
1.25k
    FLAG(isAggregate, aggregate);
1927
1.25k
    FLAG(isStandardLayout, standard_layout);
1928
1.25k
    FLAG(isTriviallyCopyable, trivially_copyable);
1929
1.25k
    FLAG(isPOD, pod);
1930
1.25k
    FLAG(isTrivial, trivial);
1931
1.25k
    FLAG(isPolymorphic, polymorphic);
1932
1.25k
    FLAG(isAbstract, abstract);
1933
1.25k
    FLAG(isLiteral, literal);
1934
1935
1.25k
    FLAG(hasUserDeclaredConstructor, has_user_declared_ctor);
1936
1.25k
    FLAG(hasConstexprNonCopyMoveConstructor, has_constexpr_non_copy_move_ctor);
1937
1.25k
    FLAG(hasMutableFields, has_mutable_fields);
1938
1.25k
    FLAG(hasVariantMembers, has_variant_members);
1939
1.25k
    FLAG(allowConstDefaultInit, can_const_default_init);
1940
1941
1.25k
    AddChild([=] {
1942
1.25k
      {
1943
1.25k
        ColorScope Color(OS, ShowColors, DeclKindNameColor);
1944
1.25k
        OS << "DefaultConstructor";
1945
1.25k
      }
1946
1.25k
      FLAG(hasDefaultConstructor, exists);
1947
1.25k
      FLAG(hasTrivialDefaultConstructor, trivial);
1948
1.25k
      FLAG(hasNonTrivialDefaultConstructor, non_trivial);
1949
1.25k
      FLAG(hasUserProvidedDefaultConstructor, user_provided);
1950
1.25k
      FLAG(hasConstexprDefaultConstructor, constexpr);
1951
1.25k
      FLAG(needsImplicitDefaultConstructor, needs_implicit);
1952
1.25k
      FLAG(defaultedDefaultConstructorIsConstexpr, defaulted_is_constexpr);
1953
1.25k
    });
1954
1955
1.25k
    AddChild([=] {
1956
1.25k
      {
1957
1.25k
        ColorScope Color(OS, ShowColors, DeclKindNameColor);
1958
1.25k
        OS << "CopyConstructor";
1959
1.25k
      }
1960
1.25k
      FLAG(hasSimpleCopyConstructor, simple);
1961
1.25k
      FLAG(hasTrivialCopyConstructor, trivial);
1962
1.25k
      FLAG(hasNonTrivialCopyConstructor, non_trivial);
1963
1.25k
      FLAG(hasUserDeclaredCopyConstructor, user_declared);
1964
1.25k
      FLAG(hasCopyConstructorWithConstParam, has_const_param);
1965
1.25k
      FLAG(needsImplicitCopyConstructor, needs_implicit);
1966
1.25k
      FLAG(needsOverloadResolutionForCopyConstructor,
1967
1.25k
           needs_overload_resolution);
1968
1.25k
      if (!D->needsOverloadResolutionForCopyConstructor())
1969
1.21k
        FLAG(defaultedCopyConstructorIsDeleted, defaulted_is_deleted);
1970
1.25k
      FLAG(implicitCopyConstructorHasConstParam, implicit_has_const_param);
1971
1.25k
    });
1972
1973
1.25k
    AddChild([=] {
1974
1.25k
      {
1975
1.25k
        ColorScope Color(OS, ShowColors, DeclKindNameColor);
1976
1.25k
        OS << "MoveConstructor";
1977
1.25k
      }
1978
1.25k
      FLAG(hasMoveConstructor, exists);
1979
1.25k
      FLAG(hasSimpleMoveConstructor, simple);
1980
1.25k
      FLAG(hasTrivialMoveConstructor, trivial);
1981
1.25k
      FLAG(hasNonTrivialMoveConstructor, non_trivial);
1982
1.25k
      FLAG(hasUserDeclaredMoveConstructor, user_declared);
1983
1.25k
      FLAG(needsImplicitMoveConstructor, needs_implicit);
1984
1.25k
      FLAG(needsOverloadResolutionForMoveConstructor,
1985
1.25k
           needs_overload_resolution);
1986
1.25k
      if (!D->needsOverloadResolutionForMoveConstructor())
1987
1.22k
        FLAG(defaultedMoveConstructorIsDeleted, defaulted_is_deleted);
1988
1.25k
    });
1989
1990
1.25k
    AddChild([=] {
1991
1.25k
      {
1992
1.25k
        ColorScope Color(OS, ShowColors, DeclKindNameColor);
1993
1.25k
        OS << "CopyAssignment";
1994
1.25k
      }
1995
1.25k
      FLAG(hasSimpleCopyAssignment, simple);
1996
1.25k
      FLAG(hasTrivialCopyAssignment, trivial);
1997
1.25k
      FLAG(hasNonTrivialCopyAssignment, non_trivial);
1998
1.25k
      FLAG(hasCopyAssignmentWithConstParam, has_const_param);
1999
1.25k
      FLAG(hasUserDeclaredCopyAssignment, user_declared);
2000
1.25k
      FLAG(needsImplicitCopyAssignment, needs_implicit);
2001
1.25k
      FLAG(needsOverloadResolutionForCopyAssignment, needs_overload_resolution);
2002
1.25k
      FLAG(implicitCopyAssignmentHasConstParam, implicit_has_const_param);
2003
1.25k
    });
2004
2005
1.25k
    AddChild([=] {
2006
1.25k
      {
2007
1.25k
        ColorScope Color(OS, ShowColors, DeclKindNameColor);
2008
1.25k
        OS << "MoveAssignment";
2009
1.25k
      }
2010
1.25k
      FLAG(hasMoveAssignment, exists);
2011
1.25k
      FLAG(hasSimpleMoveAssignment, simple);
2012
1.25k
      FLAG(hasTrivialMoveAssignment, trivial);
2013
1.25k
      FLAG(hasNonTrivialMoveAssignment, non_trivial);
2014
1.25k
      FLAG(hasUserDeclaredMoveAssignment, user_declared);
2015
1.25k
      FLAG(needsImplicitMoveAssignment, needs_implicit);
2016
1.25k
      FLAG(needsOverloadResolutionForMoveAssignment, needs_overload_resolution);
2017
1.25k
    });
2018
2019
1.25k
    AddChild([=] {
2020
1.25k
      {
2021
1.25k
        ColorScope Color(OS, ShowColors, DeclKindNameColor);
2022
1.25k
        OS << "Destructor";
2023
1.25k
      }
2024
1.25k
      FLAG(hasSimpleDestructor, simple);
2025
1.25k
      FLAG(hasIrrelevantDestructor, irrelevant);
2026
1.25k
      FLAG(hasTrivialDestructor, trivial);
2027
1.25k
      FLAG(hasNonTrivialDestructor, non_trivial);
2028
1.25k
      FLAG(hasUserDeclaredDestructor, user_declared);
2029
1.25k
      FLAG(hasConstexprDestructor, constexpr);
2030
1.25k
      FLAG(needsImplicitDestructor, needs_implicit);
2031
1.25k
      FLAG(needsOverloadResolutionForDestructor, needs_overload_resolution);
2032
1.25k
      if (!D->needsOverloadResolutionForDestructor())
2033
1.23k
        FLAG(defaultedDestructorIsDeleted, defaulted_is_deleted);
2034
1.25k
    });
2035
1.25k
  });
2036
2037
1.25k
  for (const auto &I : D->bases()) {
2038
104
    AddChild([=] {
2039
104
      if (I.isVirtual())
2040
31
        OS << "virtual ";
2041
104
      dumpAccessSpecifier(I.getAccessSpecifier());
2042
104
      dumpType(I.getType());
2043
104
      if (I.isPackExpansion())
2044
3
        OS << "...";
2045
104
    });
2046
104
  }
2047
1.25k
}
2048
2049
280
void TextNodeDumper::VisitFunctionTemplateDecl(const FunctionTemplateDecl *D) {
2050
280
  dumpName(D);
2051
280
}
2052
2053
192
void TextNodeDumper::VisitClassTemplateDecl(const ClassTemplateDecl *D) {
2054
192
  dumpName(D);
2055
192
}
2056
2057
5
void TextNodeDumper::VisitVarTemplateDecl(const VarTemplateDecl *D) {
2058
5
  dumpName(D);
2059
5
}
2060
2061
4
void TextNodeDumper::VisitBuiltinTemplateDecl(const BuiltinTemplateDecl *D) {
2062
4
  dumpName(D);
2063
4
}
2064
2065
505
void TextNodeDumper::VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D) {
2066
505
  if (const auto *TC = D->getTypeConstraint()) {
2067
12
    OS << " ";
2068
12
    dumpBareDeclRef(TC->getNamedConcept());
2069
12
    if (TC->getNamedConcept() != TC->getFoundDecl()) {
2070
4
      OS << " (";
2071
4
      dumpBareDeclRef(TC->getFoundDecl());
2072
4
      OS << ")";
2073
4
    }
2074
493
  } else if (D->wasDeclaredWithTypename())
2075
364
    OS << " typename";
2076
129
  else
2077
129
    OS << " class";
2078
505
  OS << " depth " << D->getDepth() << " index " << D->getIndex();
2079
505
  if (D->isParameterPack())
2080
48
    OS << " ...";
2081
505
  dumpName(D);
2082
505
}
2083
2084
void TextNodeDumper::VisitNonTypeTemplateParmDecl(
2085
146
    const NonTypeTemplateParmDecl *D) {
2086
146
  dumpType(D->getType());
2087
146
  OS << " depth " << D->getDepth() << " index " << D->getIndex();
2088
146
  if (D->isParameterPack())
2089
14
    OS << " ...";
2090
146
  dumpName(D);
2091
146
}
2092
2093
void TextNodeDumper::VisitTemplateTemplateParmDecl(
2094
15
    const TemplateTemplateParmDecl *D) {
2095
15
  OS << " depth " << D->getDepth() << " index " << D->getIndex();
2096
15
  if (D->isParameterPack())
2097
5
    OS << " ...";
2098
15
  dumpName(D);
2099
15
}
2100
2101
27
void TextNodeDumper::VisitUsingDecl(const UsingDecl *D) {
2102
27
  OS << ' ';
2103
27
  if (D->getQualifier())
2104
27
    D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
2105
27
  OS << D->getDeclName();
2106
27
}
2107
2108
10
void TextNodeDumper::VisitUsingEnumDecl(const UsingEnumDecl *D) {
2109
10
  OS << ' ';
2110
10
  dumpBareDeclRef(D->getEnumDecl());
2111
10
}
2112
2113
void TextNodeDumper::VisitUnresolvedUsingTypenameDecl(
2114
1
    const UnresolvedUsingTypenameDecl *D) {
2115
1
  OS << ' ';
2116
1
  if (D->getQualifier())
2117
1
    D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
2118
1
  OS << D->getDeclName();
2119
1
}
2120
2121
void TextNodeDumper::VisitUnresolvedUsingValueDecl(
2122
1
    const UnresolvedUsingValueDecl *D) {
2123
1
  OS << ' ';
2124
1
  if (D->getQualifier())
2125
1
    D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
2126
1
  OS << D->getDeclName();
2127
1
  dumpType(D->getType());
2128
1
}
2129
2130
48
void TextNodeDumper::VisitUsingShadowDecl(const UsingShadowDecl *D) {
2131
48
  OS << ' ';
2132
48
  dumpBareDeclRef(D->getTargetDecl());
2133
48
}
2134
2135
void TextNodeDumper::VisitConstructorUsingShadowDecl(
2136
12
    const ConstructorUsingShadowDecl *D) {
2137
12
  if (D->constructsVirtualBase())
2138
0
    OS << " virtual";
2139
2140
12
  AddChild([=] {
2141
12
    OS << "target ";
2142
12
    dumpBareDeclRef(D->getTargetDecl());
2143
12
  });
2144
2145
12
  AddChild([=] {
2146
12
    OS << "nominated ";
2147
12
    dumpBareDeclRef(D->getNominatedBaseClass());
2148
12
    OS << ' ';
2149
12
    dumpBareDeclRef(D->getNominatedBaseClassShadowDecl());
2150
12
  });
2151
2152
12
  AddChild([=] {
2153
12
    OS << "constructed ";
2154
12
    dumpBareDeclRef(D->getConstructedBaseClass());
2155
12
    OS << ' ';
2156
12
    dumpBareDeclRef(D->getConstructedBaseClassShadowDecl());
2157
12
  });
2158
12
}
2159
2160
64
void TextNodeDumper::VisitLinkageSpecDecl(const LinkageSpecDecl *D) {
2161
64
  switch (D->getLanguage()) {
2162
63
  case LinkageSpecDecl::lang_c:
2163
63
    OS << " C";
2164
63
    break;
2165
1
  case LinkageSpecDecl::lang_cxx:
2166
1
    OS << " C++";
2167
1
    break;
2168
64
  }
2169
64
}
2170
2171
81
void TextNodeDumper::VisitAccessSpecDecl(const AccessSpecDecl *D) {
2172
81
  OS << ' ';
2173
81
  dumpAccessSpecifier(D->getAccess());
2174
81
}
2175
2176
10
void TextNodeDumper::VisitFriendDecl(const FriendDecl *D) {
2177
10
  if (TypeSourceInfo *T = D->getFriendType())
2178
4
    dumpType(T->getType());
2179
10
}
2180
2181
51
void TextNodeDumper::VisitObjCIvarDecl(const ObjCIvarDecl *D) {
2182
51
  dumpName(D);
2183
51
  dumpType(D->getType());
2184
51
  if (D->getSynthesize())
2185
11
    OS << " synthesize";
2186
2187
51
  switch (D->getAccessControl()) {
2188
0
  case ObjCIvarDecl::None:
2189
0
    OS << " none";
2190
0
    break;
2191
22
  case ObjCIvarDecl::Private:
2192
22
    OS << " private";
2193
22
    break;
2194
21
  case ObjCIvarDecl::Protected:
2195
21
    OS << " protected";
2196
21
    break;
2197
6
  case ObjCIvarDecl::Public:
2198
6
    OS << " public";
2199
6
    break;
2200
2
  case ObjCIvarDecl::Package:
2201
2
    OS << " package";
2202
2
    break;
2203
51
  }
2204
51
}
2205
2206
177
void TextNodeDumper::VisitObjCMethodDecl(const ObjCMethodDecl *D) {
2207
177
  if (D->isInstanceMethod())
2208
153
    OS << " -";
2209
24
  else
2210
24
    OS << " +";
2211
177
  dumpName(D);
2212
177
  dumpType(D->getReturnType());
2213
2214
177
  if (D->isVariadic())
2215
5
    OS << " variadic";
2216
177
}
2217
2218
4
void TextNodeDumper::VisitObjCTypeParamDecl(const ObjCTypeParamDecl *D) {
2219
4
  dumpName(D);
2220
4
  switch (D->getVariance()) {
2221
4
  case ObjCTypeParamVariance::Invariant:
2222
4
    break;
2223
2224
0
  case ObjCTypeParamVariance::Covariant:
2225
0
    OS << " covariant";
2226
0
    break;
2227
2228
0
  case ObjCTypeParamVariance::Contravariant:
2229
0
    OS << " contravariant";
2230
0
    break;
2231
4
  }
2232
2233
4
  if (D->hasExplicitBound())
2234
1
    OS << " bounded";
2235
4
  dumpType(D->getUnderlyingType());
2236
4
}
2237
2238
19
void TextNodeDumper::VisitObjCCategoryDecl(const ObjCCategoryDecl *D) {
2239
19
  dumpName(D);
2240
19
  dumpDeclRef(D->getClassInterface());
2241
19
  dumpDeclRef(D->getImplementation());
2242
19
  for (const auto *P : D->protocols())
2243
2
    dumpDeclRef(P);
2244
19
}
2245
2246
4
void TextNodeDumper::VisitObjCCategoryImplDecl(const ObjCCategoryImplDecl *D) {
2247
4
  dumpName(D);
2248
4
  dumpDeclRef(D->getClassInterface());
2249
4
  dumpDeclRef(D->getCategoryDecl());
2250
4
}
2251
2252
20
void TextNodeDumper::VisitObjCProtocolDecl(const ObjCProtocolDecl *D) {
2253
20
  dumpName(D);
2254
2255
20
  for (const auto *Child : D->protocols())
2256
0
    dumpDeclRef(Child);
2257
20
}
2258
2259
103
void TextNodeDumper::VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D) {
2260
103
  dumpName(D);
2261
103
  dumpDeclRef(D->getSuperClass(), "super");
2262
2263
103
  dumpDeclRef(D->getImplementation());
2264
103
  for (const auto *Child : D->protocols())
2265
5
    dumpDeclRef(Child);
2266
103
}
2267
2268
void TextNodeDumper::VisitObjCImplementationDecl(
2269
24
    const ObjCImplementationDecl *D) {
2270
24
  dumpName(D);
2271
24
  dumpDeclRef(D->getSuperClass(), "super");
2272
24
  dumpDeclRef(D->getClassInterface());
2273
24
}
2274
2275
void TextNodeDumper::VisitObjCCompatibleAliasDecl(
2276
3
    const ObjCCompatibleAliasDecl *D) {
2277
3
  dumpName(D);
2278
3
  dumpDeclRef(D->getClassInterface());
2279
3
}
2280
2281
45
void TextNodeDumper::VisitObjCPropertyDecl(const ObjCPropertyDecl *D) {
2282
45
  dumpName(D);
2283
45
  dumpType(D->getType());
2284
2285
45
  if (D->getPropertyImplementation() == ObjCPropertyDecl::Required)
2286
0
    OS << " required";
2287
45
  else if (D->getPropertyImplementation() == ObjCPropertyDecl::Optional)
2288
0
    OS << " optional";
2289
2290
45
  ObjCPropertyAttribute::Kind Attrs = D->getPropertyAttributes();
2291
45
  if (Attrs != ObjCPropertyAttribute::kind_noattr) {
2292
45
    if (Attrs & ObjCPropertyAttribute::kind_readonly)
2293
16
      OS << " readonly";
2294
45
    if (Attrs & ObjCPropertyAttribute::kind_assign)
2295
27
      OS << " assign";
2296
45
    if (Attrs & ObjCPropertyAttribute::kind_readwrite)
2297
29
      OS << " readwrite";
2298
45
    if (Attrs & ObjCPropertyAttribute::kind_retain)
2299
1
      OS << " retain";
2300
45
    if (Attrs & ObjCPropertyAttribute::kind_copy)
2301
1
      OS << " copy";
2302
45
    if (Attrs & ObjCPropertyAttribute::kind_nonatomic)
2303
5
      OS << " nonatomic";
2304
45
    if (Attrs & ObjCPropertyAttribute::kind_atomic)
2305
31
      OS << " atomic";
2306
45
    if (Attrs & ObjCPropertyAttribute::kind_weak)
2307
0
      OS << " weak";
2308
45
    if (Attrs & ObjCPropertyAttribute::kind_strong)
2309
0
      OS << " strong";
2310
45
    if (Attrs & ObjCPropertyAttribute::kind_unsafe_unretained)
2311
26
      OS << " unsafe_unretained";
2312
45
    if (Attrs & ObjCPropertyAttribute::kind_class)
2313
1
      OS << " class";
2314
45
    if (Attrs & ObjCPropertyAttribute::kind_direct)
2315
0
      OS << " direct";
2316
45
    if (Attrs & ObjCPropertyAttribute::kind_getter)
2317
12
      dumpDeclRef(D->getGetterMethodDecl(), "getter");
2318
45
    if (Attrs & ObjCPropertyAttribute::kind_setter)
2319
12
      dumpDeclRef(D->getSetterMethodDecl(), "setter");
2320
45
  }
2321
45
}
2322
2323
20
void TextNodeDumper::VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D) {
2324
20
  dumpName(D->getPropertyDecl());
2325
20
  if (D->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize)
2326
19
    OS << " synthesize";
2327
1
  else
2328
1
    OS << " dynamic";
2329
20
  dumpDeclRef(D->getPropertyDecl());
2330
20
  dumpDeclRef(D->getPropertyIvarDecl());
2331
20
}
2332
2333
19
void TextNodeDumper::VisitBlockDecl(const BlockDecl *D) {
2334
19
  if (D->isVariadic())
2335
2
    OS << " variadic";
2336
2337
19
  if (D->capturesCXXThis())
2338
2
    OS << " captures_this";
2339
19
}
2340
2341
4
void TextNodeDumper::VisitConceptDecl(const ConceptDecl *D) {
2342
4
  dumpName(D);
2343
4
}