Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/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/DeclFriend.h"
15
#include "clang/AST/DeclOpenMP.h"
16
#include "clang/AST/DeclTemplate.h"
17
#include "clang/AST/LocInfoType.h"
18
19
using namespace clang;
20
21
1.39k
static void dumpPreviousDeclImpl(raw_ostream &OS, ...) {}
22
23
template <typename T>
24
1.06k
static void dumpPreviousDeclImpl(raw_ostream &OS, const Mergeable<T> *D) {
25
1.06k
  const T *First = D->getFirstDecl();
26
1.06k
  if (First != D)
27
0
    OS << " first " << First;
28
1.06k
}
Unexecuted instantiation: TextNodeDumper.cpp:void dumpPreviousDeclImpl<clang::ConceptDecl>(llvm::raw_ostream&, clang::Mergeable<clang::ConceptDecl> const*)
TextNodeDumper.cpp:void dumpPreviousDeclImpl<clang::UnresolvedUsingTypenameDecl>(llvm::raw_ostream&, clang::Mergeable<clang::UnresolvedUsingTypenameDecl> const*)
Line
Count
Source
24
1
static void dumpPreviousDeclImpl(raw_ostream &OS, const Mergeable<T> *D) {
25
1
  const T *First = D->getFirstDecl();
26
1
  if (First != D)
27
0
    OS << " first " << First;
28
1
}
TextNodeDumper.cpp:void dumpPreviousDeclImpl<clang::UsingDecl>(llvm::raw_ostream&, clang::Mergeable<clang::UsingDecl> const*)
Line
Count
Source
24
18
static void dumpPreviousDeclImpl(raw_ostream &OS, const Mergeable<T> *D) {
25
18
  const T *First = D->getFirstDecl();
26
18
  if (First != D)
27
0
    OS << " first " << First;
28
18
}
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
24
955
static void dumpPreviousDeclImpl(raw_ostream &OS, const Mergeable<T> *D) {
25
955
  const T *First = D->getFirstDecl();
26
955
  if (First != D)
27
0
    OS << " first " << First;
28
955
}
TextNodeDumper.cpp:void dumpPreviousDeclImpl<clang::EnumConstantDecl>(llvm::raw_ostream&, clang::Mergeable<clang::EnumConstantDecl> const*)
Line
Count
Source
24
63
static void dumpPreviousDeclImpl(raw_ostream &OS, const Mergeable<T> *D) {
25
63
  const T *First = D->getFirstDecl();
26
63
  if (First != D)
27
0
    OS << " first " << First;
28
63
}
TextNodeDumper.cpp:void dumpPreviousDeclImpl<clang::IndirectFieldDecl>(llvm::raw_ostream&, clang::Mergeable<clang::IndirectFieldDecl> const*)
Line
Count
Source
24
27
static void dumpPreviousDeclImpl(raw_ostream &OS, const Mergeable<T> *D) {
25
27
  const T *First = D->getFirstDecl();
26
27
  if (First != D)
27
0
    OS << " first " << First;
28
27
}
TextNodeDumper.cpp:void dumpPreviousDeclImpl<clang::UnresolvedUsingValueDecl>(llvm::raw_ostream&, clang::Mergeable<clang::UnresolvedUsingValueDecl> const*)
Line
Count
Source
24
1
static void dumpPreviousDeclImpl(raw_ostream &OS, const Mergeable<T> *D) {
25
1
  const T *First = D->getFirstDecl();
26
1
  if (First != D)
27
0
    OS << " first " << First;
28
1
}
29
30
template <typename T>
31
10.8k
static void dumpPreviousDeclImpl(raw_ostream &OS, const Redeclarable<T> *D) {
32
10.8k
  const T *Prev = D->getPreviousDecl();
33
10.8k
  if (Prev)
34
191
    OS << " prev " << Prev;
35
10.8k
}
TextNodeDumper.cpp:void dumpPreviousDeclImpl<clang::NamespaceDecl>(llvm::raw_ostream&, clang::Redeclarable<clang::NamespaceDecl> const*)
Line
Count
Source
31
93
static void dumpPreviousDeclImpl(raw_ostream &OS, const Redeclarable<T> *D) {
32
93
  const T *Prev = D->getPreviousDecl();
33
93
  if (Prev)
34
3
    OS << " prev " << Prev;
35
93
}
TextNodeDumper.cpp:void dumpPreviousDeclImpl<clang::NamespaceAliasDecl>(llvm::raw_ostream&, clang::Redeclarable<clang::NamespaceAliasDecl> const*)
Line
Count
Source
31
4
static void dumpPreviousDeclImpl(raw_ostream &OS, const Redeclarable<T> *D) {
32
4
  const T *Prev = D->getPreviousDecl();
33
4
  if (Prev)
34
0
    OS << " prev " << Prev;
35
4
}
TextNodeDumper.cpp:void dumpPreviousDeclImpl<clang::ObjCInterfaceDecl>(llvm::raw_ostream&, clang::Redeclarable<clang::ObjCInterfaceDecl> const*)
Line
Count
Source
31
62
static void dumpPreviousDeclImpl(raw_ostream &OS, const Redeclarable<T> *D) {
32
62
  const T *Prev = D->getPreviousDecl();
33
62
  if (Prev)
34
1
    OS << " prev " << Prev;
35
62
}
TextNodeDumper.cpp:void dumpPreviousDeclImpl<clang::ObjCProtocolDecl>(llvm::raw_ostream&, clang::Redeclarable<clang::ObjCProtocolDecl> const*)
Line
Count
Source
31
17
static void dumpPreviousDeclImpl(raw_ostream &OS, const Redeclarable<T> *D) {
32
17
  const T *Prev = D->getPreviousDecl();
33
17
  if (Prev)
34
0
    OS << " prev " << Prev;
35
17
}
TextNodeDumper.cpp:void dumpPreviousDeclImpl<clang::RedeclarableTemplateDecl>(llvm::raw_ostream&, clang::Redeclarable<clang::RedeclarableTemplateDecl> const*)
Line
Count
Source
31
224
static void dumpPreviousDeclImpl(raw_ostream &OS, const Redeclarable<T> *D) {
32
224
  const T *Prev = D->getPreviousDecl();
33
224
  if (Prev)
34
10
    OS << " prev " << Prev;
35
224
}
TextNodeDumper.cpp:void dumpPreviousDeclImpl<clang::TagDecl>(llvm::raw_ostream&, clang::Redeclarable<clang::TagDecl> const*)
Line
Count
Source
31
1.60k
static void dumpPreviousDeclImpl(raw_ostream &OS, const Redeclarable<T> *D) {
32
1.60k
  const T *Prev = D->getPreviousDecl();
33
1.60k
  if (Prev)
34
83
    OS << " prev " << Prev;
35
1.60k
}
TextNodeDumper.cpp:void dumpPreviousDeclImpl<clang::TypedefNameDecl>(llvm::raw_ostream&, clang::Redeclarable<clang::TypedefNameDecl> const*)
Line
Count
Source
31
1.01k
static void dumpPreviousDeclImpl(raw_ostream &OS, const Redeclarable<T> *D) {
32
1.01k
  const T *Prev = D->getPreviousDecl();
33
1.01k
  if (Prev)
34
2
    OS << " prev " << Prev;
35
1.01k
}
TextNodeDumper.cpp:void dumpPreviousDeclImpl<clang::UsingShadowDecl>(llvm::raw_ostream&, clang::Redeclarable<clang::UsingShadowDecl> const*)
Line
Count
Source
31
24
static void dumpPreviousDeclImpl(raw_ostream &OS, const Redeclarable<T> *D) {
32
24
  const T *Prev = D->getPreviousDecl();
33
24
  if (Prev)
34
0
    OS << " prev " << Prev;
35
24
}
TextNodeDumper.cpp:void dumpPreviousDeclImpl<clang::FunctionDecl>(llvm::raw_ostream&, clang::Redeclarable<clang::FunctionDecl> const*)
Line
Count
Source
31
1.97k
static void dumpPreviousDeclImpl(raw_ostream &OS, const Redeclarable<T> *D) {
32
1.97k
  const T *Prev = D->getPreviousDecl();
33
1.97k
  if (Prev)
34
79
    OS << " prev " << Prev;
35
1.97k
}
TextNodeDumper.cpp:void dumpPreviousDeclImpl<clang::VarDecl>(llvm::raw_ostream&, clang::Redeclarable<clang::VarDecl> const*)
Line
Count
Source
31
5.85k
static void dumpPreviousDeclImpl(raw_ostream &OS, const Redeclarable<T> *D) {
32
5.85k
  const T *Prev = D->getPreviousDecl();
33
5.85k
  if (Prev)
34
13
    OS << " prev " << Prev;
35
5.85k
}
36
37
/// Dump the previous declaration in the redeclaration chain for a declaration,
38
/// if any.
39
13.3k
static void dumpPreviousDecl(raw_ostream &OS, const Decl *D) {
40
13.3k
  switch (D->getKind()) {
41
13.3k
#define DECL(DERIVED, BASE)                                                    \
42
13.3k
  case Decl::DERIVED:                                                          \
43
13.3k
    return dumpPreviousDeclImpl(OS, cast<DERIVED##Decl>(D));
44
13.3k
#define ABSTRACT_DECL(DECL)
45
13.3k
#include 
"clang/AST/DeclNodes.inc"54
46
13.3k
  }
47
13.3k
  
llvm_unreachable0
("Decl that isn't part of DeclNodes.inc!");
48
13.3k
}
49
50
TextNodeDumper::TextNodeDumper(raw_ostream &OS, bool ShowColors,
51
                               const SourceManager *SM,
52
                               const PrintingPolicy &PrintPolicy,
53
                               const comments::CommandTraits *Traits)
54
    : TextTreeStructure(OS, ShowColors), OS(OS), ShowColors(ShowColors), SM(SM),
55
954
      PrintPolicy(PrintPolicy), Traits(Traits) {}
56
57
void TextNodeDumper::Visit(const comments::Comment *C,
58
513
                           const comments::FullComment *FC) {
59
513
  if (!C) {
60
0
    ColorScope Color(OS, ShowColors, NullColor);
61
0
    OS << "<<<NULL>>>";
62
0
    return;
63
0
  }
64
513
65
513
  {
66
513
    ColorScope Color(OS, ShowColors, CommentColor);
67
513
    OS << C->getCommentKindName();
68
513
  }
69
513
  dumpPointer(C);
70
513
  dumpSourceRange(C->getSourceRange());
71
513
72
513
  ConstCommentVisitor<TextNodeDumper, void,
73
513
                      const comments::FullComment *>::visit(C, FC);
74
513
}
75
76
1.04k
void TextNodeDumper::Visit(const Attr *A) {
77
1.04k
  {
78
1.04k
    ColorScope Color(OS, ShowColors, AttrColor);
79
1.04k
80
1.04k
    switch (A->getKind()) {
81
1.04k
#define ATTR(X)                                                                \
82
1.04k
  case attr::X:                                                                \
83
1.04k
    OS << #X;                                                                  \
84
1.04k
    break;
85
1.04k
#include 
"clang/Basic/AttrList.inc"0
86
1.04k
    }
87
1.04k
    OS << "Attr";
88
1.04k
  }
89
1.04k
  dumpPointer(A);
90
1.04k
  dumpSourceRange(A->getRange());
91
1.04k
  if (A->isInherited())
92
10
    OS << " Inherited";
93
1.04k
  if (A->isImplicit())
94
780
    OS << " Implicit";
95
1.04k
96
1.04k
  ConstAttrVisitor<TextNodeDumper>::Visit(A);
97
1.04k
}
98
99
void TextNodeDumper::Visit(const TemplateArgument &TA, SourceRange R,
100
206
                           const Decl *From, StringRef Label) {
101
206
  OS << "TemplateArgument";
102
206
  if (R.isValid())
103
4
    dumpSourceRange(R);
104
206
105
206
  if (From)
106
3
    dumpDeclRef(From, Label);
107
206
108
206
  ConstTemplateArgumentVisitor<TextNodeDumper>::Visit(TA);
109
206
}
110
111
18.2k
void TextNodeDumper::Visit(const Stmt *Node) {
112
18.2k
  if (!Node) {
113
754
    ColorScope Color(OS, ShowColors, NullColor);
114
754
    OS << "<<<NULL>>>";
115
754
    return;
116
754
  }
117
17.5k
  {
118
17.5k
    ColorScope Color(OS, ShowColors, StmtColor);
119
17.5k
    OS << Node->getStmtClassName();
120
17.5k
  }
121
17.5k
  dumpPointer(Node);
122
17.5k
  dumpSourceRange(Node->getSourceRange());
123
17.5k
124
17.5k
  if (Node->isOMPStructuredBlock())
125
423
    OS << " openmp_structured_block";
126
17.5k
127
17.5k
  if (const auto *E = dyn_cast<Expr>(Node)) {
128
13.1k
    dumpType(E->getType());
129
13.1k
130
13.1k
    {
131
13.1k
      ColorScope Color(OS, ShowColors, ValueKindColor);
132
13.1k
      switch (E->getValueKind()) {
133
13.1k
      case VK_RValue:
134
8.63k
        break;
135
13.1k
      case VK_LValue:
136
4.37k
        OS << " lvalue";
137
4.37k
        break;
138
13.1k
      case VK_XValue:
139
104
        OS << " xvalue";
140
104
        break;
141
13.1k
      }
142
13.1k
    }
143
13.1k
144
13.1k
    {
145
13.1k
      ColorScope Color(OS, ShowColors, ObjectKindColor);
146
13.1k
      switch (E->getObjectKind()) {
147
13.1k
      case OK_Ordinary:
148
13.1k
        break;
149
13.1k
      case OK_BitField:
150
0
        OS << " bitfield";
151
0
        break;
152
13.1k
      case OK_ObjCProperty:
153
2
        OS << " objcproperty";
154
2
        break;
155
13.1k
      case OK_ObjCSubscript:
156
0
        OS << " objcsubscript";
157
0
        break;
158
13.1k
      case OK_VectorComponent:
159
8
        OS << " vectorcomponent";
160
8
        break;
161
17.5k
      }
162
17.5k
    }
163
17.5k
  }
164
17.5k
165
17.5k
  ConstStmtVisitor<TextNodeDumper>::Visit(Node);
166
17.5k
}
167
168
1.48k
void TextNodeDumper::Visit(const Type *T) {
169
1.48k
  if (!T) {
170
0
    ColorScope Color(OS, ShowColors, NullColor);
171
0
    OS << "<<<NULL>>>";
172
0
    return;
173
0
  }
174
1.48k
  if (isa<LocInfoType>(T)) {
175
0
    {
176
0
      ColorScope Color(OS, ShowColors, TypeColor);
177
0
      OS << "LocInfo Type";
178
0
    }
179
0
    dumpPointer(T);
180
0
    return;
181
0
  }
182
1.48k
183
1.48k
  {
184
1.48k
    ColorScope Color(OS, ShowColors, TypeColor);
185
1.48k
    OS << T->getTypeClassName() << "Type";
186
1.48k
  }
187
1.48k
  dumpPointer(T);
188
1.48k
  OS << " ";
189
1.48k
  dumpBareType(QualType(T, 0), false);
190
1.48k
191
1.48k
  QualType SingleStepDesugar =
192
1.48k
      T->getLocallyUnqualifiedSingleStepDesugaredType();
193
1.48k
  if (SingleStepDesugar != QualType(T, 0))
194
49
    OS << " sugar";
195
1.48k
196
1.48k
  if (T->isDependentType())
197
18
    OS << " dependent";
198
1.46k
  else if (T->isInstantiationDependentType())
199
0
    OS << " instantiation_dependent";
200
1.48k
201
1.48k
  if (T->isVariablyModifiedType())
202
0
    OS << " variably_modified";
203
1.48k
  if (T->containsUnexpandedParameterPack())
204
0
    OS << " contains_unexpanded_pack";
205
1.48k
  if (T->isFromAST())
206
27
    OS << " imported";
207
1.48k
208
1.48k
  TypeVisitor<TextNodeDumper>::Visit(T);
209
1.48k
}
210
211
5
void TextNodeDumper::Visit(QualType T) {
212
5
  OS << "QualType";
213
5
  dumpPointer(T.getAsOpaquePtr());
214
5
  OS << " ";
215
5
  dumpBareType(T, false);
216
5
  OS << " " << T.split().Quals.getAsString();
217
5
}
218
219
13.3k
void TextNodeDumper::Visit(const Decl *D) {
220
13.3k
  if (!D) {
221
2
    ColorScope Color(OS, ShowColors, NullColor);
222
2
    OS << "<<<NULL>>>";
223
2
    return;
224
2
  }
225
13.3k
226
13.3k
  Context = &D->getASTContext();
227
13.3k
  {
228
13.3k
    ColorScope Color(OS, ShowColors, DeclKindNameColor);
229
13.3k
    OS << D->getDeclKindName() << "Decl";
230
13.3k
  }
231
13.3k
  dumpPointer(D);
232
13.3k
  if (D->getLexicalDeclContext() != D->getDeclContext())
233
60
    OS << " parent " << cast<Decl>(D->getDeclContext());
234
13.3k
  dumpPreviousDecl(OS, D);
235
13.3k
  dumpSourceRange(D->getSourceRange());
236
13.3k
  OS << ' ';
237
13.3k
  dumpLocation(D->getLocation());
238
13.3k
  if (D->isFromASTFile())
239
101
    OS << " imported";
240
13.3k
  if (Module *M = D->getOwningModule())
241
74
    OS << " in " << M->getFullModuleName();
242
13.3k
  if (auto *ND = dyn_cast<NamedDecl>(D))
243
12.4k
    for (Module *M : D->getASTContext().getModulesWithMergedDefinition(
244
12.4k
             const_cast<NamedDecl *>(ND)))
245
0
      AddChild([=] { OS << "also in " << M->getFullModuleName(); });
246
13.3k
  if (const NamedDecl *ND = dyn_cast<NamedDecl>(D))
247
12.4k
    if (ND->isHidden())
248
51
      OS << " hidden";
249
13.3k
  if (D->isImplicit())
250
5.45k
    OS << " implicit";
251
13.3k
252
13.3k
  if (D->isUsed())
253
2.78k
    OS << " used";
254
10.5k
  else if (D->isThisDeclarationReferenced())
255
659
    OS << " referenced";
256
13.3k
257
13.3k
  if (D->isInvalidDecl())
258
10
    OS << " invalid";
259
13.3k
  if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
260
1.97k
    if (FD->isConstexprSpecified())
261
341
      OS << " constexpr";
262
1.97k
    if (FD->isConsteval())
263
0
      OS << " consteval";
264
1.97k
  }
265
13.3k
266
13.3k
  if (!isa<FunctionDecl>(*D)) {
267
11.3k
    const auto *MD = dyn_cast<ObjCMethodDecl>(D);
268
11.3k
    if (!MD || 
!MD->isThisDeclarationADefinition()97
) {
269
11.3k
      const auto *DC = dyn_cast<DeclContext>(D);
270
11.3k
      if (DC && 
DC->hasExternalLexicalStorage()2.70k
) {
271
42
        ColorScope Color(OS, ShowColors, UndeserializedColor);
272
42
        OS << " <undeserialized declarations>";
273
42
      }
274
11.3k
    }
275
11.3k
  }
276
13.3k
277
13.3k
  ConstDeclVisitor<TextNodeDumper>::Visit(D);
278
13.3k
}
279
280
86
void TextNodeDumper::Visit(const CXXCtorInitializer *Init) {
281
86
  OS << "CXXCtorInitializer";
282
86
  if (Init->isAnyMemberInitializer()) {
283
63
    OS << ' ';
284
63
    dumpBareDeclRef(Init->getAnyMember());
285
63
  } else 
if (23
Init->isBaseInitializer()23
) {
286
22
    dumpType(QualType(Init->getBaseClass(), 0));
287
22
  } else 
if (1
Init->isDelegatingInitializer()1
) {
288
1
    dumpType(Init->getTypeSourceInfo()->getType());
289
1
  } else {
290
0
    llvm_unreachable("Unknown initializer type");
291
0
  }
292
86
}
293
294
5
void TextNodeDumper::Visit(const BlockDecl::Capture &C) {
295
5
  OS << "capture";
296
5
  if (C.isByRef())
297
0
    OS << " byref";
298
5
  if (C.isNested())
299
0
    OS << " nested";
300
5
  if (C.getVariable()) {
301
5
    OS << ' ';
302
5
    dumpBareDeclRef(C.getVariable());
303
5
  }
304
5
}
305
306
158
void TextNodeDumper::Visit(const OMPClause *C) {
307
158
  if (!C) {
308
0
    ColorScope Color(OS, ShowColors, NullColor);
309
0
    OS << "<<<NULL>>> OMPClause";
310
0
    return;
311
0
  }
312
158
  {
313
158
    ColorScope Color(OS, ShowColors, AttrColor);
314
158
    StringRef ClauseName(getOpenMPClauseName(C->getClauseKind()));
315
158
    OS << "OMP" << ClauseName.substr(/*Start=*/0, /*N=*/1).upper()
316
158
       << ClauseName.drop_front() << "Clause";
317
158
  }
318
158
  dumpPointer(C);
319
158
  dumpSourceRange(SourceRange(C->getBeginLoc(), C->getEndLoc()));
320
158
  if (C->isImplicit())
321
65
    OS << " <implicit>";
322
158
}
323
324
9
void TextNodeDumper::Visit(const GenericSelectionExpr::ConstAssociation &A) {
325
9
  const TypeSourceInfo *TSI = A.getTypeSourceInfo();
326
9
  if (TSI) {
327
6
    OS << "case ";
328
6
    dumpType(TSI->getType());
329
6
  } else {
330
3
    OS << "default";
331
3
  }
332
9
333
9
  if (A.isSelected())
334
5
    OS << " selected";
335
9
}
336
337
39.1k
void TextNodeDumper::dumpPointer(const void *Ptr) {
338
39.1k
  ColorScope Color(OS, ShowColors, AddressColor);
339
39.1k
  OS << ' ' << Ptr;
340
39.1k
}
341
342
60.9k
void TextNodeDumper::dumpLocation(SourceLocation Loc) {
343
60.9k
  if (!SM)
344
0
    return;
345
60.9k
346
60.9k
  ColorScope Color(OS, ShowColors, LocationColor);
347
60.9k
  SourceLocation SpellingLoc = SM->getSpellingLoc(Loc);
348
60.9k
349
60.9k
  // The general format we print out is filename:line:col, but we drop pieces
350
60.9k
  // that haven't changed since the last loc printed.
351
60.9k
  PresumedLoc PLoc = SM->getPresumedLoc(SpellingLoc);
352
60.9k
353
60.9k
  if (PLoc.isInvalid()) {
354
4.91k
    OS << "<invalid sloc>";
355
4.91k
    return;
356
4.91k
  }
357
56.0k
358
56.0k
  if (strcmp(PLoc.getFilename(), LastLocFilename) != 0) {
359
975
    OS << PLoc.getFilename() << ':' << PLoc.getLine() << ':'
360
975
       << PLoc.getColumn();
361
975
    LastLocFilename = PLoc.getFilename();
362
975
    LastLocLine = PLoc.getLine();
363
55.0k
  } else if (PLoc.getLine() != LastLocLine) {
364
13.3k
    OS << "line" << ':' << PLoc.getLine() << ':' << PLoc.getColumn();
365
13.3k
    LastLocLine = PLoc.getLine();
366
41.7k
  } else {
367
41.7k
    OS << "col" << ':' << PLoc.getColumn();
368
41.7k
  }
369
56.0k
}
370
371
32.5k
void TextNodeDumper::dumpSourceRange(SourceRange R) {
372
32.5k
  // Can't translate locations if a SourceManager isn't available.
373
32.5k
  if (!SM)
374
17
    return;
375
32.5k
376
32.5k
  OS << " <";
377
32.5k
  dumpLocation(R.getBegin());
378
32.5k
  if (R.getBegin() != R.getEnd()) {
379
15.0k
    OS << ", ";
380
15.0k
    dumpLocation(R.getEnd());
381
15.0k
  }
382
32.5k
  OS << ">";
383
32.5k
384
32.5k
  // <t2.c:123:421[blah], t2.c:412:321>
385
32.5k
}
386
387
29.5k
void TextNodeDumper::dumpBareType(QualType T, bool Desugar) {
388
29.5k
  ColorScope Color(OS, ShowColors, TypeColor);
389
29.5k
390
29.5k
  SplitQualType T_split = T.split();
391
29.5k
  OS << "'" << QualType::getAsString(T_split, PrintPolicy) << "'";
392
29.5k
393
29.5k
  if (Desugar && 
!T.isNull()28.0k
) {
394
28.0k
    // If the type is sugared, also dump a (shallow) desugared type.
395
28.0k
    SplitQualType D_split = T.getSplitDesugaredType();
396
28.0k
    if (T_split != D_split)
397
1.00k
      OS << ":'" << QualType::getAsString(D_split, PrintPolicy) << "'";
398
28.0k
  }
399
29.5k
}
400
401
28.0k
void TextNodeDumper::dumpType(QualType T) {
402
28.0k
  OS << ' ';
403
28.0k
  dumpBareType(T);
404
28.0k
}
405
406
4.98k
void TextNodeDumper::dumpBareDeclRef(const Decl *D) {
407
4.98k
  if (!D) {
408
24
    ColorScope Color(OS, ShowColors, NullColor);
409
24
    OS << "<<<NULL>>>";
410
24
    return;
411
24
  }
412
4.96k
413
4.96k
  {
414
4.96k
    ColorScope Color(OS, ShowColors, DeclKindNameColor);
415
4.96k
    OS << D->getDeclKindName();
416
4.96k
  }
417
4.96k
  dumpPointer(D);
418
4.96k
419
4.96k
  if (const NamedDecl *ND = dyn_cast<NamedDecl>(D)) {
420
4.95k
    ColorScope Color(OS, ShowColors, DeclNameColor);
421
4.95k
    OS << " '" << ND->getDeclName() << '\'';
422
4.95k
  }
423
4.96k
424
4.96k
  if (const ValueDecl *VD = dyn_cast<ValueDecl>(D))
425
4.27k
    dumpType(VD->getType());
426
4.96k
}
427
428
12.3k
void TextNodeDumper::dumpName(const NamedDecl *ND) {
429
12.3k
  if (ND->getDeclName()) {
430
10.8k
    ColorScope Color(OS, ShowColors, DeclNameColor);
431
10.8k
    OS << ' ' << ND->getNameAsString();
432
10.8k
  }
433
12.3k
}
434
435
132
void TextNodeDumper::dumpAccessSpecifier(AccessSpecifier AS) {
436
132
  switch (AS) {
437
132
  case AS_none:
438
0
    break;
439
132
  case AS_public:
440
110
    OS << "public";
441
110
    break;
442
132
  case AS_protected:
443
6
    OS << "protected";
444
6
    break;
445
132
  case AS_private:
446
16
    OS << "private";
447
16
    break;
448
132
  }
449
132
}
450
451
673
void TextNodeDumper::dumpDeclRef(const Decl *D, StringRef Label) {
452
673
  if (!D)
453
127
    return;
454
546
455
546
  AddChild([=] {
456
546
    if (!Label.empty())
457
27
      OS << Label << ' ';
458
546
    dumpBareDeclRef(D);
459
546
  });
460
546
}
461
462
29
const char *TextNodeDumper::getCommandName(unsigned CommandID) {
463
29
  if (Traits)
464
29
    return Traits->getCommandInfo(CommandID)->Name;
465
0
  const comments::CommandInfo *Info =
466
0
      comments::CommandTraits::getBuiltinCommandInfo(CommandID);
467
0
  if (Info)
468
0
    return Info->Name;
469
0
  return "<not a builtin command>";
470
0
}
471
472
void TextNodeDumper::visitTextComment(const comments::TextComment *C,
473
157
                                      const comments::FullComment *) {
474
157
  OS << " Text=\"" << C->getText() << "\"";
475
157
}
476
477
void TextNodeDumper::visitInlineCommandComment(
478
6
    const comments::InlineCommandComment *C, const comments::FullComment *) {
479
6
  OS << " Name=\"" << getCommandName(C->getCommandID()) << "\"";
480
6
  switch (C->getRenderKind()) {
481
6
  case comments::InlineCommandComment::RenderNormal:
482
1
    OS << " RenderNormal";
483
1
    break;
484
6
  case comments::InlineCommandComment::RenderBold:
485
0
    OS << " RenderBold";
486
0
    break;
487
6
  case comments::InlineCommandComment::RenderMonospaced:
488
5
    OS << " RenderMonospaced";
489
5
    break;
490
6
  case comments::InlineCommandComment::RenderEmphasized:
491
0
    OS << " RenderEmphasized";
492
0
    break;
493
6
  }
494
6
495
9
  
for (unsigned i = 0, e = C->getNumArgs(); 6
i != e;
++i3
)
496
3
    OS << " Arg[" << i << "]=\"" << C->getArgText(i) << "\"";
497
6
}
498
499
void TextNodeDumper::visitHTMLStartTagComment(
500
16
    const comments::HTMLStartTagComment *C, const comments::FullComment *) {
501
16
  OS << " Name=\"" << C->getTagName() << "\"";
502
16
  if (C->getNumAttrs() != 0) {
503
6
    OS << " Attrs: ";
504
12
    for (unsigned i = 0, e = C->getNumAttrs(); i != e; 
++i6
) {
505
6
      const comments::HTMLStartTagComment::Attribute &Attr = C->getAttr(i);
506
6
      OS << " \"" << Attr.Name << "=\"" << Attr.Value << "\"";
507
6
    }
508
6
  }
509
16
  if (C->isSelfClosing())
510
4
    OS << " SelfClosing";
511
16
}
512
513
void TextNodeDumper::visitHTMLEndTagComment(
514
6
    const comments::HTMLEndTagComment *C, const comments::FullComment *) {
515
6
  OS << " Name=\"" << C->getTagName() << "\"";
516
6
}
517
518
void TextNodeDumper::visitBlockCommandComment(
519
10
    const comments::BlockCommandComment *C, const comments::FullComment *) {
520
10
  OS << " Name=\"" << getCommandName(C->getCommandID()) << "\"";
521
10
  for (unsigned i = 0, e = C->getNumArgs(); i != e; 
++i0
)
522
0
    OS << " Arg[" << i << "]=\"" << C->getArgText(i) << "\"";
523
10
}
524
525
void TextNodeDumper::visitParamCommandComment(
526
27
    const comments::ParamCommandComment *C, const comments::FullComment *FC) {
527
27
  OS << " "
528
27
     << comments::ParamCommandComment::getDirectionAsString(C->getDirection());
529
27
530
27
  if (C->isDirectionExplicit())
531
17
    OS << " explicitly";
532
10
  else
533
10
    OS << " implicitly";
534
27
535
27
  if (C->hasParamName()) {
536
26
    if (C->isParamIndexValid())
537
4
      OS << " Param=\"" << C->getParamName(FC) << "\"";
538
22
    else
539
22
      OS << " Param=\"" << C->getParamNameAsWritten() << "\"";
540
26
  }
541
27
542
27
  if (C->isParamIndexValid() && 
!C->isVarArgParam()4
)
543
2
    OS << " ParamIndex=" << C->getParamIndex();
544
27
}
545
546
void TextNodeDumper::visitTParamCommandComment(
547
7
    const comments::TParamCommandComment *C, const comments::FullComment *FC) {
548
7
  if (C->hasParamName()) {
549
6
    if (C->isPositionValid())
550
1
      OS << " Param=\"" << C->getParamName(FC) << "\"";
551
5
    else
552
5
      OS << " Param=\"" << C->getParamNameAsWritten() << "\"";
553
6
  }
554
7
555
7
  if (C->isPositionValid()) {
556
1
    OS << " Position=<";
557
2
    for (unsigned i = 0, e = C->getDepth(); i != e; 
++i1
) {
558
1
      OS << C->getIndex(i);
559
1
      if (i != e - 1)
560
0
        OS << ", ";
561
1
    }
562
1
    OS << ">";
563
1
  }
564
7
}
565
566
void TextNodeDumper::visitVerbatimBlockComment(
567
13
    const comments::VerbatimBlockComment *C, const comments::FullComment *) {
568
13
  OS << " Name=\"" << getCommandName(C->getCommandID())
569
13
     << "\""
570
13
        " CloseName=\""
571
13
     << C->getCloseName() << "\"";
572
13
}
573
574
void TextNodeDumper::visitVerbatimBlockLineComment(
575
    const comments::VerbatimBlockLineComment *C,
576
17
    const comments::FullComment *) {
577
17
  OS << " Text=\"" << C->getText() << "\"";
578
17
}
579
580
void TextNodeDumper::visitVerbatimLineComment(
581
4
    const comments::VerbatimLineComment *C, const comments::FullComment *) {
582
4
  OS << " Text=\"" << C->getText() << "\"";
583
4
}
584
585
0
void TextNodeDumper::VisitNullTemplateArgument(const TemplateArgument &) {
586
0
  OS << " null";
587
0
}
588
589
140
void TextNodeDumper::VisitTypeTemplateArgument(const TemplateArgument &TA) {
590
140
  OS << " type";
591
140
  dumpType(TA.getAsType());
592
140
}
593
594
void TextNodeDumper::VisitDeclarationTemplateArgument(
595
1
    const TemplateArgument &TA) {
596
1
  OS << " decl";
597
1
  dumpDeclRef(TA.getAsDecl());
598
1
}
599
600
1
void TextNodeDumper::VisitNullPtrTemplateArgument(const TemplateArgument &) {
601
1
  OS << " nullptr";
602
1
}
603
604
39
void TextNodeDumper::VisitIntegralTemplateArgument(const TemplateArgument &TA) {
605
39
  OS << " integral " << TA.getAsIntegral();
606
39
}
607
608
6
void TextNodeDumper::VisitTemplateTemplateArgument(const TemplateArgument &TA) {
609
6
  OS << " template ";
610
6
  TA.getAsTemplate().dump(OS);
611
6
}
612
613
void TextNodeDumper::VisitTemplateExpansionTemplateArgument(
614
0
    const TemplateArgument &TA) {
615
0
  OS << " template expansion ";
616
0
  TA.getAsTemplateOrTemplatePattern().dump(OS);
617
0
}
618
619
11
void TextNodeDumper::VisitExpressionTemplateArgument(const TemplateArgument &) {
620
11
  OS << " expr";
621
11
}
622
623
8
void TextNodeDumper::VisitPackTemplateArgument(const TemplateArgument &) {
624
8
  OS << " pack";
625
8
}
626
627
2.78k
static void dumpBasePath(raw_ostream &OS, const CastExpr *Node) {
628
2.78k
  if (Node->path_empty())
629
2.74k
    return;
630
40
631
40
  OS << " (";
632
40
  bool First = true;
633
40
  for (CastExpr::path_const_iterator I = Node->path_begin(),
634
40
                                     E = Node->path_end();
635
80
       I != E; 
++I40
) {
636
40
    const CXXBaseSpecifier *Base = *I;
637
40
    if (!First)
638
0
      OS << " -> ";
639
40
640
40
    const CXXRecordDecl *RD =
641
40
        cast<CXXRecordDecl>(Base->getType()->getAs<RecordType>()->getDecl());
642
40
643
40
    if (Base->isVirtual())
644
0
      OS << "virtual ";
645
40
    OS << RD->getName();
646
40
    First = false;
647
40
  }
648
40
649
40
  OS << ')';
650
40
}
651
652
23
void TextNodeDumper::VisitIfStmt(const IfStmt *Node) {
653
23
  if (Node->hasInitStorage())
654
2
    OS << " has_init";
655
23
  if (Node->hasVarStorage())
656
1
    OS << " has_var";
657
23
  if (Node->hasElseStorage())
658
14
    OS << " has_else";
659
23
}
660
661
14
void TextNodeDumper::VisitSwitchStmt(const SwitchStmt *Node) {
662
14
  if (Node->hasInitStorage())
663
2
    OS << " has_init";
664
14
  if (Node->hasVarStorage())
665
0
    OS << " has_var";
666
14
}
667
668
9
void TextNodeDumper::VisitWhileStmt(const WhileStmt *Node) {
669
9
  if (Node->hasVarStorage())
670
1
    OS << " has_var";
671
9
}
672
673
15
void TextNodeDumper::VisitLabelStmt(const LabelStmt *Node) {
674
15
  OS << " '" << Node->getName() << "'";
675
15
}
676
677
8
void TextNodeDumper::VisitGotoStmt(const GotoStmt *Node) {
678
8
  OS << " '" << Node->getLabel()->getName() << "'";
679
8
  dumpPointer(Node->getLabel());
680
8
}
681
682
23
void TextNodeDumper::VisitCaseStmt(const CaseStmt *Node) {
683
23
  if (Node->caseStmtIsGNURange())
684
6
    OS << " gnu_range";
685
23
}
686
687
197
void TextNodeDumper::VisitConstantExpr(const ConstantExpr *Node) {
688
197
  if (Node->getResultAPValueKind() != APValue::None) {
689
47
    ColorScope Color(OS, ShowColors, ValueColor);
690
47
    OS << " ";
691
47
    Node->getAPValueResult().printPretty(OS, *Context, Node->getType());
692
47
  }
693
197
}
694
695
218
void TextNodeDumper::VisitCallExpr(const CallExpr *Node) {
696
218
  if (Node->usesADL())
697
5
    OS << " adl";
698
218
}
699
700
2.75k
void TextNodeDumper::VisitCastExpr(const CastExpr *Node) {
701
2.75k
  OS << " <";
702
2.75k
  {
703
2.75k
    ColorScope Color(OS, ShowColors, CastColor);
704
2.75k
    OS << Node->getCastKindName();
705
2.75k
  }
706
2.75k
  dumpBasePath(OS, Node);
707
2.75k
  OS << ">";
708
2.75k
}
709
710
2.60k
void TextNodeDumper::VisitImplicitCastExpr(const ImplicitCastExpr *Node) {
711
2.60k
  VisitCastExpr(Node);
712
2.60k
  if (Node->isPartOfExplicitCast())
713
56
    OS << " part_of_explicit_cast";
714
2.60k
}
715
716
3.98k
void TextNodeDumper::VisitDeclRefExpr(const DeclRefExpr *Node) {
717
3.98k
  OS << " ";
718
3.98k
  dumpBareDeclRef(Node->getDecl());
719
3.98k
  if (Node->getDecl() != Node->getFoundDecl()) {
720
42
    OS << " (";
721
42
    dumpBareDeclRef(Node->getFoundDecl());
722
42
    OS << ")";
723
42
  }
724
3.98k
  switch (Node->isNonOdrUse()) {
725
3.98k
  
case NOUR_None: break3.94k
;
726
3.98k
  
case NOUR_Unevaluated: OS << " non_odr_use_unevaluated"; break24
;
727
3.98k
  
case NOUR_Constant: OS << " non_odr_use_constant"; break20
;
728
3.98k
  
case NOUR_Discarded: OS << " non_odr_use_discarded"; break0
;
729
3.98k
  }
730
3.98k
}
731
732
void TextNodeDumper::VisitUnresolvedLookupExpr(
733
13
    const UnresolvedLookupExpr *Node) {
734
13
  OS << " (";
735
13
  if (!Node->requiresADL())
736
9
    OS << "no ";
737
13
  OS << "ADL) = '" << Node->getName() << '\'';
738
13
739
13
  UnresolvedLookupExpr::decls_iterator I = Node->decls_begin(),
740
13
                                       E = Node->decls_end();
741
13
  if (I == E)
742
0
    OS << " empty";
743
27
  for (; I != E; 
++I14
)
744
14
    dumpPointer(*I);
745
13
}
746
747
0
void TextNodeDumper::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *Node) {
748
0
  {
749
0
    ColorScope Color(OS, ShowColors, DeclKindNameColor);
750
0
    OS << " " << Node->getDecl()->getDeclKindName() << "Decl";
751
0
  }
752
0
  OS << "='" << *Node->getDecl() << "'";
753
0
  dumpPointer(Node->getDecl());
754
0
  if (Node->isFreeIvar())
755
0
    OS << " isFreeIvar";
756
0
}
757
758
18
void TextNodeDumper::VisitPredefinedExpr(const PredefinedExpr *Node) {
759
18
  OS << " " << PredefinedExpr::getIdentKindName(Node->getIdentKind());
760
18
}
761
762
12
void TextNodeDumper::VisitCharacterLiteral(const CharacterLiteral *Node) {
763
12
  ColorScope Color(OS, ShowColors, ValueColor);
764
12
  OS << " " << Node->getValue();
765
12
}
766
767
2.23k
void TextNodeDumper::VisitIntegerLiteral(const IntegerLiteral *Node) {
768
2.23k
  bool isSigned = Node->getType()->isSignedIntegerType();
769
2.23k
  ColorScope Color(OS, ShowColors, ValueColor);
770
2.23k
  OS << " " << Node->getValue().toString(10, isSigned);
771
2.23k
}
772
773
53
void TextNodeDumper::VisitFixedPointLiteral(const FixedPointLiteral *Node) {
774
53
  ColorScope Color(OS, ShowColors, ValueColor);
775
53
  OS << " " << Node->getValueAsString(/*Radix=*/10);
776
53
}
777
778
91
void TextNodeDumper::VisitFloatingLiteral(const FloatingLiteral *Node) {
779
91
  ColorScope Color(OS, ShowColors, ValueColor);
780
91
  OS << " " << Node->getValueAsApproximateDouble();
781
91
}
782
783
66
void TextNodeDumper::VisitStringLiteral(const StringLiteral *Str) {
784
66
  ColorScope Color(OS, ShowColors, ValueColor);
785
66
  OS << " ";
786
66
  Str->outputString(OS);
787
66
}
788
789
96
void TextNodeDumper::VisitInitListExpr(const InitListExpr *ILE) {
790
96
  if (auto *Field = ILE->getInitializedFieldInUnion()) {
791
2
    OS << " field ";
792
2
    dumpBareDeclRef(Field);
793
2
  }
794
96
}
795
796
5
void TextNodeDumper::VisitGenericSelectionExpr(const GenericSelectionExpr *E) {
797
5
  if (E->isResultDependent())
798
0
    OS << " result_dependent";
799
5
}
800
801
849
void TextNodeDumper::VisitUnaryOperator(const UnaryOperator *Node) {
802
849
  OS << " " << (Node->isPostfix() ? 
"postfix"702
:
"prefix"147
) << " '"
803
849
     << UnaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
804
849
  if (!Node->canOverflow())
805
85
    OS << " cannot overflow";
806
849
}
807
808
void TextNodeDumper::VisitUnaryExprOrTypeTraitExpr(
809
26
    const UnaryExprOrTypeTraitExpr *Node) {
810
26
  switch (Node->getKind()) {
811
26
  case UETT_SizeOf:
812
21
    OS << " sizeof";
813
21
    break;
814
26
  case UETT_AlignOf:
815
5
    OS << " alignof";
816
5
    break;
817
26
  case UETT_VecStep:
818
0
    OS << " vec_step";
819
0
    break;
820
26
  case UETT_OpenMPRequiredSimdAlign:
821
0
    OS << " __builtin_omp_required_simd_align";
822
0
    break;
823
26
  case UETT_PreferredAlignOf:
824
0
    OS << " __alignof";
825
0
    break;
826
26
  }
827
26
  if (Node->isArgumentType())
828
18
    dumpType(Node->getArgumentType());
829
26
}
830
831
132
void TextNodeDumper::VisitMemberExpr(const MemberExpr *Node) {
832
132
  OS << " " << (Node->isArrow() ? 
"->"67
:
"."65
) << *Node->getMemberDecl();
833
132
  dumpPointer(Node->getMemberDecl());
834
132
  switch (Node->isNonOdrUse()) {
835
132
  
case NOUR_None: break118
;
836
132
  
case NOUR_Unevaluated: OS << " non_odr_use_unevaluated"; break4
;
837
132
  
case NOUR_Constant: OS << " non_odr_use_constant"; break10
;
838
132
  
case NOUR_Discarded: OS << " non_odr_use_discarded"; break0
;
839
132
  }
840
132
}
841
842
void TextNodeDumper::VisitExtVectorElementExpr(
843
8
    const ExtVectorElementExpr *Node) {
844
8
  OS << " " << Node->getAccessor().getNameStart();
845
8
}
846
847
1.13k
void TextNodeDumper::VisitBinaryOperator(const BinaryOperator *Node) {
848
1.13k
  OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
849
1.13k
}
850
851
void TextNodeDumper::VisitCompoundAssignOperator(
852
19
    const CompoundAssignOperator *Node) {
853
19
  OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode())
854
19
     << "' ComputeLHSTy=";
855
19
  dumpBareType(Node->getComputationLHSType());
856
19
  OS << " ComputeResultTy=";
857
19
  dumpBareType(Node->getComputationResultType());
858
19
}
859
860
8
void TextNodeDumper::VisitAddrLabelExpr(const AddrLabelExpr *Node) {
861
8
  OS << " " << Node->getLabel()->getName();
862
8
  dumpPointer(Node->getLabel());
863
8
}
864
865
26
void TextNodeDumper::VisitCXXNamedCastExpr(const CXXNamedCastExpr *Node) {
866
26
  OS << " " << Node->getCastName() << "<"
867
26
     << Node->getTypeAsWritten().getAsString() << ">"
868
26
     << " <" << Node->getCastKindName();
869
26
  dumpBasePath(OS, Node);
870
26
  OS << ">";
871
26
}
872
873
29
void TextNodeDumper::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *Node) {
874
29
  OS << " " << (Node->getValue() ? 
"true"21
:
"false"8
);
875
29
}
876
877
62
void TextNodeDumper::VisitCXXThisExpr(const CXXThisExpr *Node) {
878
62
  if (Node->isImplicit())
879
40
    OS << " implicit";
880
62
  OS << " this";
881
62
}
882
883
void TextNodeDumper::VisitCXXFunctionalCastExpr(
884
19
    const CXXFunctionalCastExpr *Node) {
885
19
  OS << " functional cast to " << Node->getTypeAsWritten().getAsString() << " <"
886
19
     << Node->getCastKindName() << ">";
887
19
}
888
889
void TextNodeDumper::VisitCXXUnresolvedConstructExpr(
890
18
    const CXXUnresolvedConstructExpr *Node) {
891
18
  dumpType(Node->getTypeAsWritten());
892
18
  if (Node->isListInitialization())
893
2
    OS << " list";
894
18
}
895
896
259
void TextNodeDumper::VisitCXXConstructExpr(const CXXConstructExpr *Node) {
897
259
  CXXConstructorDecl *Ctor = Node->getConstructor();
898
259
  dumpType(Ctor->getType());
899
259
  if (Node->isElidable())
900
59
    OS << " elidable";
901
259
  if (Node->isListInitialization())
902
6
    OS << " list";
903
259
  if (Node->isStdInitListInitialization())
904
1
    OS << " std::initializer_list";
905
259
  if (Node->requiresZeroInitialization())
906
25
    OS << " zeroing";
907
259
}
908
909
void TextNodeDumper::VisitCXXBindTemporaryExpr(
910
14
    const CXXBindTemporaryExpr *Node) {
911
14
  OS << " (CXXTemporary";
912
14
  dumpPointer(Node);
913
14
  OS << ")";
914
14
}
915
916
38
void TextNodeDumper::VisitCXXNewExpr(const CXXNewExpr *Node) {
917
38
  if (Node->isGlobalNew())
918
2
    OS << " global";
919
38
  if (Node->isArray())
920
13
    OS << " array";
921
38
  if (Node->getOperatorNew()) {
922
36
    OS << ' ';
923
36
    dumpBareDeclRef(Node->getOperatorNew());
924
36
  }
925
38
  // We could dump the deallocation function used in case of error, but it's
926
38
  // usually not that interesting.
927
38
}
928
929
37
void TextNodeDumper::VisitCXXDeleteExpr(const CXXDeleteExpr *Node) {
930
37
  if (Node->isGlobalDelete())
931
2
    OS << " global";
932
37
  if (Node->isArrayForm())
933
11
    OS << " array";
934
37
  if (Node->getOperatorDelete()) {
935
36
    OS << ' ';
936
36
    dumpBareDeclRef(Node->getOperatorDelete());
937
36
  }
938
37
}
939
940
void TextNodeDumper::VisitMaterializeTemporaryExpr(
941
93
    const MaterializeTemporaryExpr *Node) {
942
93
  if (const ValueDecl *VD = Node->getExtendingDecl()) {
943
5
    OS << " extended by ";
944
5
    dumpBareDeclRef(VD);
945
5
  }
946
93
}
947
948
85
void TextNodeDumper::VisitExprWithCleanups(const ExprWithCleanups *Node) {
949
91
  for (unsigned i = 0, e = Node->getNumObjects(); i != e; 
++i6
)
950
6
    dumpDeclRef(Node->getObject(i), "cleanup");
951
85
}
952
953
5
void TextNodeDumper::VisitSizeOfPackExpr(const SizeOfPackExpr *Node) {
954
5
  dumpPointer(Node->getPack());
955
5
  dumpName(Node->getPack());
956
5
}
957
958
void TextNodeDumper::VisitCXXDependentScopeMemberExpr(
959
19
    const CXXDependentScopeMemberExpr *Node) {
960
19
  OS << " " << (Node->isArrow() ? 
"->"9
:
"."10
) << Node->getMember();
961
19
}
962
963
4
void TextNodeDumper::VisitObjCMessageExpr(const ObjCMessageExpr *Node) {
964
4
  OS << " selector=";
965
4
  Node->getSelector().print(OS);
966
4
  switch (Node->getReceiverKind()) {
967
4
  case ObjCMessageExpr::Instance:
968
0
    break;
969
4
970
4
  case ObjCMessageExpr::Class:
971
0
    OS << " class=";
972
0
    dumpBareType(Node->getClassReceiver());
973
0
    break;
974
4
975
4
  case ObjCMessageExpr::SuperInstance:
976
3
    OS << " super (instance)";
977
3
    break;
978
4
979
4
  case ObjCMessageExpr::SuperClass:
980
1
    OS << " super (class)";
981
1
    break;
982
4
  }
983
4
}
984
985
1
void TextNodeDumper::VisitObjCBoxedExpr(const ObjCBoxedExpr *Node) {
986
1
  if (auto *BoxingMethod = Node->getBoxingMethod()) {
987
0
    OS << " selector=";
988
0
    BoxingMethod->getSelector().print(OS);
989
0
  }
990
1
}
991
992
7
void TextNodeDumper::VisitObjCAtCatchStmt(const ObjCAtCatchStmt *Node) {
993
7
  if (!Node->getCatchParamDecl())
994
1
    OS << " catch all";
995
7
}
996
997
0
void TextNodeDumper::VisitObjCEncodeExpr(const ObjCEncodeExpr *Node) {
998
0
  dumpType(Node->getEncodedType());
999
0
}
1000
1001
0
void TextNodeDumper::VisitObjCSelectorExpr(const ObjCSelectorExpr *Node) {
1002
0
  OS << " ";
1003
0
  Node->getSelector().print(OS);
1004
0
}
1005
1006
0
void TextNodeDumper::VisitObjCProtocolExpr(const ObjCProtocolExpr *Node) {
1007
0
  OS << ' ' << *Node->getProtocol();
1008
0
}
1009
1010
2
void TextNodeDumper::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *Node) {
1011
2
  if (Node->isImplicitProperty()) {
1012
0
    OS << " Kind=MethodRef Getter=\"";
1013
0
    if (Node->getImplicitPropertyGetter())
1014
0
      Node->getImplicitPropertyGetter()->getSelector().print(OS);
1015
0
    else
1016
0
      OS << "(null)";
1017
0
1018
0
    OS << "\" Setter=\"";
1019
0
    if (ObjCMethodDecl *Setter = Node->getImplicitPropertySetter())
1020
0
      Setter->getSelector().print(OS);
1021
0
    else
1022
0
      OS << "(null)";
1023
0
    OS << "\"";
1024
2
  } else {
1025
2
    OS << " Kind=PropertyRef Property=\"" << *Node->getExplicitProperty()
1026
2
       << '"';
1027
2
  }
1028
2
1029
2
  if (Node->isSuperReceiver())
1030
2
    OS << " super";
1031
2
1032
2
  OS << " Messaging=";
1033
2
  if (Node->isMessagingGetter() && Node->isMessagingSetter())
1034
0
    OS << "Getter&Setter";
1035
2
  else if (Node->isMessagingGetter())
1036
2
    OS << "Getter";
1037
0
  else if (Node->isMessagingSetter())
1038
0
    OS << "Setter";
1039
2
}
1040
1041
void TextNodeDumper::VisitObjCSubscriptRefExpr(
1042
0
    const ObjCSubscriptRefExpr *Node) {
1043
0
  if (Node->isArraySubscriptRefExpr())
1044
0
    OS << " Kind=ArraySubscript GetterForArray=\"";
1045
0
  else
1046
0
    OS << " Kind=DictionarySubscript GetterForDictionary=\"";
1047
0
  if (Node->getAtIndexMethodDecl())
1048
0
    Node->getAtIndexMethodDecl()->getSelector().print(OS);
1049
0
  else
1050
0
    OS << "(null)";
1051
0
1052
0
  if (Node->isArraySubscriptRefExpr())
1053
0
    OS << "\" SetterForArray=\"";
1054
0
  else
1055
0
    OS << "\" SetterForDictionary=\"";
1056
0
  if (Node->setAtIndexMethodDecl())
1057
0
    Node->setAtIndexMethodDecl()->getSelector().print(OS);
1058
0
  else
1059
0
    OS << "(null)";
1060
0
}
1061
1062
7
void TextNodeDumper::VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *Node) {
1063
7
  OS << " " << (Node->getValue() ? "__objc_yes" : 
"__objc_no"0
);
1064
7
}
1065
1066
0
void TextNodeDumper::VisitRValueReferenceType(const ReferenceType *T) {
1067
0
  if (T->isSpelledAsLValue())
1068
0
    OS << " written as lvalue reference";
1069
0
}
1070
1071
147
void TextNodeDumper::VisitArrayType(const ArrayType *T) {
1072
147
  switch (T->getSizeModifier()) {
1073
147
  case ArrayType::Normal:
1074
147
    break;
1075
147
  case ArrayType::Static:
1076
0
    OS << " static";
1077
0
    break;
1078
147
  case ArrayType::Star:
1079
0
    OS << " *";
1080
0
    break;
1081
147
  }
1082
147
  OS << " " << T->getIndexTypeQualifiers().getAsString();
1083
147
}
1084
1085
146
void TextNodeDumper::VisitConstantArrayType(const ConstantArrayType *T) {
1086
146
  OS << " " << T->getSize();
1087
146
  VisitArrayType(T);
1088
146
}
1089
1090
0
void TextNodeDumper::VisitVariableArrayType(const VariableArrayType *T) {
1091
0
  OS << " ";
1092
0
  dumpSourceRange(T->getBracketsRange());
1093
0
  VisitArrayType(T);
1094
0
}
1095
1096
void TextNodeDumper::VisitDependentSizedArrayType(
1097
1
    const DependentSizedArrayType *T) {
1098
1
  VisitArrayType(T);
1099
1
  OS << " ";
1100
1
  dumpSourceRange(T->getBracketsRange());
1101
1
}
1102
1103
void TextNodeDumper::VisitDependentSizedExtVectorType(
1104
0
    const DependentSizedExtVectorType *T) {
1105
0
  OS << " ";
1106
0
  dumpLocation(T->getAttributeLoc());
1107
0
}
1108
1109
5
void TextNodeDumper::VisitVectorType(const VectorType *T) {
1110
5
  switch (T->getVectorKind()) {
1111
5
  case VectorType::GenericVector:
1112
5
    break;
1113
5
  case VectorType::AltiVecVector:
1114
0
    OS << " altivec";
1115
0
    break;
1116
5
  case VectorType::AltiVecPixel:
1117
0
    OS << " altivec pixel";
1118
0
    break;
1119
5
  case VectorType::AltiVecBool:
1120
0
    OS << " altivec bool";
1121
0
    break;
1122
5
  case VectorType::NeonVector:
1123
0
    OS << " neon";
1124
0
    break;
1125
5
  case VectorType::NeonPolyVector:
1126
0
    OS << " neon poly";
1127
0
    break;
1128
5
  }
1129
5
  OS << " " << T->getNumElements();
1130
5
}
1131
1132
0
void TextNodeDumper::VisitFunctionType(const FunctionType *T) {
1133
0
  auto EI = T->getExtInfo();
1134
0
  if (EI.getNoReturn())
1135
0
    OS << " noreturn";
1136
0
  if (EI.getProducesResult())
1137
0
    OS << " produces_result";
1138
0
  if (EI.getHasRegParm())
1139
0
    OS << " regparm " << EI.getRegParm();
1140
0
  OS << " " << FunctionType::getNameForCallConv(EI.getCC());
1141
0
}
1142
1143
0
void TextNodeDumper::VisitFunctionProtoType(const FunctionProtoType *T) {
1144
0
  auto EPI = T->getExtProtoInfo();
1145
0
  if (EPI.HasTrailingReturn)
1146
0
    OS << " trailing_return";
1147
0
  if (T->isConst())
1148
0
    OS << " const";
1149
0
  if (T->isVolatile())
1150
0
    OS << " volatile";
1151
0
  if (T->isRestrict())
1152
0
    OS << " restrict";
1153
0
  if (T->getExtProtoInfo().Variadic)
1154
0
    OS << " variadic";
1155
0
  switch (EPI.RefQualifier) {
1156
0
  case RQ_None:
1157
0
    break;
1158
0
  case RQ_LValue:
1159
0
    OS << " &";
1160
0
    break;
1161
0
  case RQ_RValue:
1162
0
    OS << " &&";
1163
0
    break;
1164
0
  }
1165
0
  // FIXME: Exception specification.
1166
0
  // FIXME: Consumed parameters.
1167
0
  VisitFunctionType(T);
1168
0
}
1169
1170
0
void TextNodeDumper::VisitUnresolvedUsingType(const UnresolvedUsingType *T) {
1171
0
  dumpDeclRef(T->getDecl());
1172
0
}
1173
1174
4
void TextNodeDumper::VisitTypedefType(const TypedefType *T) {
1175
4
  dumpDeclRef(T->getDecl());
1176
4
}
1177
1178
void TextNodeDumper::VisitUnaryTransformType(const UnaryTransformType *T) {
1179
  switch (T->getUTTKind()) {
1180
  case UnaryTransformType::EnumUnderlyingType:
1181
    OS << " underlying_type";
1182
    break;
1183
  }
1184
}
1185
1186
337
void TextNodeDumper::VisitTagType(const TagType *T) {
1187
337
  dumpDeclRef(T->getDecl());
1188
337
}
1189
1190
8
void TextNodeDumper::VisitTemplateTypeParmType(const TemplateTypeParmType *T) {
1191
8
  OS << " depth " << T->getDepth() << " index " << T->getIndex();
1192
8
  if (T->isParameterPack())
1193
0
    OS << " pack";
1194
8
  dumpDeclRef(T->getDecl());
1195
8
}
1196
1197
0
void TextNodeDumper::VisitAutoType(const AutoType *T) {
1198
0
  if (T->isDecltypeAuto())
1199
0
    OS << " decltype(auto)";
1200
0
  if (!T->isDeduced())
1201
0
    OS << " undeduced";
1202
0
}
1203
1204
void TextNodeDumper::VisitTemplateSpecializationType(
1205
17
    const TemplateSpecializationType *T) {
1206
17
  if (T->isTypeAlias())
1207
0
    OS << " alias";
1208
17
  OS << " ";
1209
17
  T->getTemplateName().dump(OS);
1210
17
}
1211
1212
void TextNodeDumper::VisitInjectedClassNameType(
1213
0
    const InjectedClassNameType *T) {
1214
0
  dumpDeclRef(T->getDecl());
1215
0
}
1216
1217
0
void TextNodeDumper::VisitObjCInterfaceType(const ObjCInterfaceType *T) {
1218
0
  dumpDeclRef(T->getDecl());
1219
0
}
1220
1221
0
void TextNodeDumper::VisitPackExpansionType(const PackExpansionType *T) {
1222
0
  if (auto N = T->getNumExpansions())
1223
0
    OS << " expansions " << *N;
1224
0
}
1225
1226
3
void TextNodeDumper::VisitLabelDecl(const LabelDecl *D) { dumpName(D); }
1227
1228
984
void TextNodeDumper::VisitTypedefDecl(const TypedefDecl *D) {
1229
984
  dumpName(D);
1230
984
  dumpType(D->getUnderlyingType());
1231
984
  if (D->isModulePrivate())
1232
1
    OS << " __module_private__";
1233
984
}
1234
1235
50
void TextNodeDumper::VisitEnumDecl(const EnumDecl *D) {
1236
50
  if (D->isScoped()) {
1237
7
    if (D->isScopedUsingClassTag())
1238
7
      OS << " class";
1239
0
    else
1240
0
      OS << " struct";
1241
7
  }
1242
50
  dumpName(D);
1243
50
  if (D->isModulePrivate())
1244
1
    OS << " __module_private__";
1245
50
  if (D->isFixed())
1246
9
    dumpType(D->getIntegerType());
1247
50
}
1248
1249
1.55k
void TextNodeDumper::VisitRecordDecl(const RecordDecl *D) {
1250
1.55k
  OS << ' ' << D->getKindName();
1251
1.55k
  dumpName(D);
1252
1.55k
  if (D->isModulePrivate())
1253
1
    OS << " __module_private__";
1254
1.55k
  if (D->isCompleteDefinition())
1255
947
    OS << " definition";
1256
1.55k
}
1257
1258
63
void TextNodeDumper::VisitEnumConstantDecl(const EnumConstantDecl *D) {
1259
63
  dumpName(D);
1260
63
  dumpType(D->getType());
1261
63
}
1262
1263
27
void TextNodeDumper::VisitIndirectFieldDecl(const IndirectFieldDecl *D) {
1264
27
  dumpName(D);
1265
27
  dumpType(D->getType());
1266
27
1267
27
  for (const auto *Child : D->chain())
1268
54
    dumpDeclRef(Child);
1269
27
}
1270
1271
1.97k
void TextNodeDumper::VisitFunctionDecl(const FunctionDecl *D) {
1272
1.97k
  dumpName(D);
1273
1.97k
  dumpType(D->getType());
1274
1.97k
1275
1.97k
  StorageClass SC = D->getStorageClass();
1276
1.97k
  if (SC != SC_None)
1277
65
    OS << ' ' << VarDecl::getStorageClassSpecifierString(SC);
1278
1.97k
  if (D->isInlineSpecified())
1279
665
    OS << " inline";
1280
1.97k
  if (D->isVirtualAsWritten())
1281
37
    OS << " virtual";
1282
1.97k
  if (D->isModulePrivate())
1283
0
    OS << " __module_private__";
1284
1.97k
1285
1.97k
  if (D->isPure())
1286
4
    OS << " pure";
1287
1.97k
  if (D->isDefaulted()) {
1288
542
    OS << " default";
1289
542
    if (D->isDeleted())
1290
39
      OS << "_delete";
1291
542
  }
1292
1.97k
  if (D->isDeletedAsWritten())
1293
10
    OS << " delete";
1294
1.97k
  if (D->isTrivial())
1295
461
    OS << " trivial";
1296
1.97k
1297
1.97k
  if (const auto *FPT = D->getType()->getAs<FunctionProtoType>()) {
1298
1.84k
    FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo();
1299
1.84k
    switch (EPI.ExceptionSpec.Type) {
1300
1.84k
    default:
1301
1.41k
      break;
1302
1.84k
    case EST_Unevaluated:
1303
432
      OS << " noexcept-unevaluated " << EPI.ExceptionSpec.SourceDecl;
1304
432
      break;
1305
1.84k
    case EST_Uninstantiated:
1306
0
      OS << " noexcept-uninstantiated " << EPI.ExceptionSpec.SourceTemplate;
1307
0
      break;
1308
1.97k
    }
1309
1.97k
  }
1310
1.97k
1311
1.97k
  if (const auto *MD = dyn_cast<CXXMethodDecl>(D)) {
1312
1.03k
    if (MD->size_overridden_methods() != 0) {
1313
11
      auto dumpOverride = [=](const CXXMethodDecl *D) {
1314
11
        SplitQualType T_split = D->getType().split();
1315
11
        OS << D << " " << D->getParent()->getName()
1316
11
           << "::" << D->getNameAsString() << " '"
1317
11
           << QualType::getAsString(T_split, PrintPolicy) << "'";
1318
11
      };
1319
10
1320
10
      AddChild([=] {
1321
10
        auto Overrides = MD->overridden_methods();
1322
10
        OS << "Overrides: [ ";
1323
10
        dumpOverride(*Overrides.begin());
1324
10
        for (const auto *Override :
1325
10
             llvm::make_range(Overrides.begin() + 1, Overrides.end())) {
1326
1
          OS << ", ";
1327
1
          dumpOverride(Override);
1328
1
        }
1329
10
        OS << " ]";
1330
10
      });
1331
10
    }
1332
1.03k
  }
1333
1.97k
1334
1.97k
  // Since NumParams comes from the FunctionProtoType of the FunctionDecl and
1335
1.97k
  // the Params are set later, it is possible for a dump during debugging to
1336
1.97k
  // encounter a FunctionDecl that has been created but hasn't been assigned
1337
1.97k
  // ParmVarDecls yet.
1338
1.97k
  if (!D->param_empty() && 
!D->param_begin()967
)
1339
0
    OS << " <<<NULL params x " << D->getNumParams() << ">>>";
1340
1.97k
}
1341
1342
923
void TextNodeDumper::VisitFieldDecl(const FieldDecl *D) {
1343
923
  dumpName(D);
1344
923
  dumpType(D->getType());
1345
923
  if (D->isMutable())
1346
2
    OS << " mutable";
1347
923
  if (D->isModulePrivate())
1348
1
    OS << " __module_private__";
1349
923
}
1350
1351
5.75k
void TextNodeDumper::VisitVarDecl(const VarDecl *D) {
1352
5.75k
  dumpName(D);
1353
5.75k
  dumpType(D->getType());
1354
5.75k
  StorageClass SC = D->getStorageClass();
1355
5.75k
  if (SC != SC_None)
1356
43
    OS << ' ' << VarDecl::getStorageClassSpecifierString(SC);
1357
5.75k
  switch (D->getTLSKind()) {
1358
5.75k
  case VarDecl::TLS_None:
1359
5.74k
    break;
1360
5.75k
  case VarDecl::TLS_Static:
1361
9
    OS << " tls";
1362
9
    break;
1363
5.75k
  case VarDecl::TLS_Dynamic:
1364
3
    OS << " tls_dynamic";
1365
3
    break;
1366
5.75k
  }
1367
5.75k
  if (D->isModulePrivate())
1368
1
    OS << " __module_private__";
1369
5.75k
  if (D->isNRVOVariable())
1370
4
    OS << " nrvo";
1371
5.75k
  if (D->isInline())
1372
1
    OS << " inline";
1373
5.75k
  if (D->isConstexpr())
1374
2
    OS << " constexpr";
1375
5.75k
  if (D->hasInit()) {
1376
1.87k
    switch (D->getInitStyle()) {
1377
1.87k
    case VarDecl::CInit:
1378
1.83k
      OS << " cinit";
1379
1.83k
      break;
1380
1.87k
    case VarDecl::CallInit:
1381
38
      OS << " callinit";
1382
38
      break;
1383
1.87k
    case VarDecl::ListInit:
1384
4
      OS << " listinit";
1385
4
      break;
1386
5.75k
    }
1387
5.75k
  }
1388
5.75k
  if (D->isParameterPack())
1389
9
    OS << " pack";
1390
5.75k
}
1391
1392
0
void TextNodeDumper::VisitBindingDecl(const BindingDecl *D) {
1393
0
  dumpName(D);
1394
0
  dumpType(D->getType());
1395
0
}
1396
1397
631
void TextNodeDumper::VisitCapturedDecl(const CapturedDecl *D) {
1398
631
  if (D->isNothrow())
1399
585
    OS << " nothrow";
1400
631
}
1401
1402
0
void TextNodeDumper::VisitImportDecl(const ImportDecl *D) {
1403
0
  OS << ' ' << D->getImportedModule()->getFullModuleName();
1404
0
1405
0
  for (Decl *InitD :
1406
0
       D->getASTContext().getModuleInitializers(D->getImportedModule()))
1407
0
    dumpDeclRef(InitD, "initializer");
1408
0
}
1409
1410
0
void TextNodeDumper::VisitPragmaCommentDecl(const PragmaCommentDecl *D) {
1411
0
  OS << ' ';
1412
0
  switch (D->getCommentKind()) {
1413
0
  case PCK_Unknown:
1414
0
    llvm_unreachable("unexpected pragma comment kind");
1415
0
  case PCK_Compiler:
1416
0
    OS << "compiler";
1417
0
    break;
1418
0
  case PCK_ExeStr:
1419
0
    OS << "exestr";
1420
0
    break;
1421
0
  case PCK_Lib:
1422
0
    OS << "lib";
1423
0
    break;
1424
0
  case PCK_Linker:
1425
0
    OS << "linker";
1426
0
    break;
1427
0
  case PCK_User:
1428
0
    OS << "user";
1429
0
    break;
1430
0
  }
1431
0
  StringRef Arg = D->getArg();
1432
0
  if (!Arg.empty())
1433
0
    OS << " \"" << Arg << "\"";
1434
0
}
1435
1436
void TextNodeDumper::VisitPragmaDetectMismatchDecl(
1437
0
    const PragmaDetectMismatchDecl *D) {
1438
0
  OS << " \"" << D->getName() << "\" \"" << D->getValue() << "\"";
1439
0
}
1440
1441
void TextNodeDumper::VisitOMPExecutableDirective(
1442
187
    const OMPExecutableDirective *D) {
1443
187
  if (D->isStandaloneDirective())
1444
10
    OS << " openmp_standalone_directive";
1445
187
}
1446
1447
void TextNodeDumper::VisitOMPDeclareReductionDecl(
1448
6
    const OMPDeclareReductionDecl *D) {
1449
6
  dumpName(D);
1450
6
  dumpType(D->getType());
1451
6
  OS << " combiner";
1452
6
  dumpPointer(D->getCombiner());
1453
6
  if (const auto *Initializer = D->getInitializer()) {
1454
2
    OS << " initializer";
1455
2
    dumpPointer(Initializer);
1456
2
    switch (D->getInitializerKind()) {
1457
2
    case OMPDeclareReductionDecl::DirectInit:
1458
0
      OS << " omp_priv = ";
1459
0
      break;
1460
2
    case OMPDeclareReductionDecl::CopyInit:
1461
0
      OS << " omp_priv ()";
1462
0
      break;
1463
2
    case OMPDeclareReductionDecl::CallInit:
1464
2
      break;
1465
2
    }
1466
2
  }
1467
6
}
1468
1469
0
void TextNodeDumper::VisitOMPRequiresDecl(const OMPRequiresDecl *D) {
1470
0
  for (const auto *C : D->clauselists()) {
1471
0
    AddChild([=] {
1472
0
      if (!C) {
1473
0
        ColorScope Color(OS, ShowColors, NullColor);
1474
0
        OS << "<<<NULL>>> OMPClause";
1475
0
        return;
1476
0
      }
1477
0
      {
1478
0
        ColorScope Color(OS, ShowColors, AttrColor);
1479
0
        StringRef ClauseName(getOpenMPClauseName(C->getClauseKind()));
1480
0
        OS << "OMP" << ClauseName.substr(/*Start=*/0, /*N=*/1).upper()
1481
0
           << ClauseName.drop_front() << "Clause";
1482
0
      }
1483
0
      dumpPointer(C);
1484
0
      dumpSourceRange(SourceRange(C->getBeginLoc(), C->getEndLoc()));
1485
0
    });
1486
0
  }
1487
0
}
1488
1489
96
void TextNodeDumper::VisitOMPCapturedExprDecl(const OMPCapturedExprDecl *D) {
1490
96
  dumpName(D);
1491
96
  dumpType(D->getType());
1492
96
}
1493
1494
93
void TextNodeDumper::VisitNamespaceDecl(const NamespaceDecl *D) {
1495
93
  dumpName(D);
1496
93
  if (D->isInline())
1497
2
    OS << " inline";
1498
93
  if (!D->isOriginalNamespace())
1499
3
    dumpDeclRef(D->getOriginalNamespace(), "original");
1500
93
}
1501
1502
15
void TextNodeDumper::VisitUsingDirectiveDecl(const UsingDirectiveDecl *D) {
1503
15
  OS << ' ';
1504
15
  dumpBareDeclRef(D->getNominatedNamespace());
1505
15
}
1506
1507
4
void TextNodeDumper::VisitNamespaceAliasDecl(const NamespaceAliasDecl *D) {
1508
4
  dumpName(D);
1509
4
  dumpDeclRef(D->getAliasedNamespace());
1510
4
}
1511
1512
30
void TextNodeDumper::VisitTypeAliasDecl(const TypeAliasDecl *D) {
1513
30
  dumpName(D);
1514
30
  dumpType(D->getUnderlyingType());
1515
30
}
1516
1517
void TextNodeDumper::VisitTypeAliasTemplateDecl(
1518
1
    const TypeAliasTemplateDecl *D) {
1519
1
  dumpName(D);
1520
1
}
1521
1522
1.19k
void TextNodeDumper::VisitCXXRecordDecl(const CXXRecordDecl *D) {
1523
1.19k
  VisitRecordDecl(D);
1524
1.19k
  if (!D->isCompleteDefinition())
1525
592
    return;
1526
598
1527
598
  AddChild([=] {
1528
598
    {
1529
598
      ColorScope Color(OS, ShowColors, DeclKindNameColor);
1530
598
      OS << "DefinitionData";
1531
598
    }
1532
598
#define FLAG(fn, name)                                                         \
1533
38.2k
  
if (1.72k
D->fn()) \
1534
17.3k
    OS << " " #name;
1535
598
    FLAG(isParsingBaseSpecifiers, parsing_base_specifiers);
1536
598
1537
598
    FLAG(isGenericLambda, generic);
1538
598
    FLAG(isLambda, lambda);
1539
598
1540
598
    FLAG(canPassInRegisters, pass_in_registers);
1541
598
    FLAG(isEmpty, empty);
1542
598
    FLAG(isAggregate, aggregate);
1543
598
    FLAG(isStandardLayout, standard_layout);
1544
598
    FLAG(isTriviallyCopyable, trivially_copyable);
1545
598
    FLAG(isPOD, pod);
1546
598
    FLAG(isTrivial, trivial);
1547
598
    FLAG(isPolymorphic, polymorphic);
1548
598
    FLAG(isAbstract, abstract);
1549
598
    FLAG(isLiteral, literal);
1550
598
1551
598
    FLAG(hasUserDeclaredConstructor, has_user_declared_ctor);
1552
598
    FLAG(hasConstexprNonCopyMoveConstructor, has_constexpr_non_copy_move_ctor);
1553
598
    FLAG(hasMutableFields, has_mutable_fields);
1554
598
    FLAG(hasVariantMembers, has_variant_members);
1555
598
    FLAG(allowConstDefaultInit, can_const_default_init);
1556
598
1557
598
    AddChild([=] {
1558
598
      {
1559
598
        ColorScope Color(OS, ShowColors, DeclKindNameColor);
1560
598
        OS << "DefaultConstructor";
1561
598
      }
1562
598
      FLAG(hasDefaultConstructor, exists);
1563
598
      FLAG(hasTrivialDefaultConstructor, trivial);
1564
598
      FLAG(hasNonTrivialDefaultConstructor, non_trivial);
1565
598
      FLAG(hasUserProvidedDefaultConstructor, user_provided);
1566
598
      FLAG(hasConstexprDefaultConstructor, constexpr);
1567
598
      FLAG(needsImplicitDefaultConstructor, needs_implicit);
1568
598
      FLAG(defaultedDefaultConstructorIsConstexpr, defaulted_is_constexpr);
1569
598
    });
1570
598
1571
598
    AddChild([=] {
1572
598
      {
1573
598
        ColorScope Color(OS, ShowColors, DeclKindNameColor);
1574
598
        OS << "CopyConstructor";
1575
598
      }
1576
598
      FLAG(hasSimpleCopyConstructor, simple);
1577
598
      FLAG(hasTrivialCopyConstructor, trivial);
1578
598
      FLAG(hasNonTrivialCopyConstructor, non_trivial);
1579
598
      FLAG(hasUserDeclaredCopyConstructor, user_declared);
1580
598
      FLAG(hasCopyConstructorWithConstParam, has_const_param);
1581
598
      FLAG(needsImplicitCopyConstructor, needs_implicit);
1582
598
      FLAG(needsOverloadResolutionForCopyConstructor,
1583
598
           needs_overload_resolution);
1584
598
      if (!D->needsOverloadResolutionForCopyConstructor())
1585
598
        
FLAG568
(defaultedCopyConstructorIsDeleted, defaulted_is_deleted);
1586
598
      FLAG(implicitCopyConstructorHasConstParam, implicit_has_const_param);
1587
598
    });
1588
598
1589
598
    AddChild([=] {
1590
598
      {
1591
598
        ColorScope Color(OS, ShowColors, DeclKindNameColor);
1592
598
        OS << "MoveConstructor";
1593
598
      }
1594
598
      FLAG(hasMoveConstructor, exists);
1595
598
      FLAG(hasSimpleMoveConstructor, simple);
1596
598
      FLAG(hasTrivialMoveConstructor, trivial);
1597
598
      FLAG(hasNonTrivialMoveConstructor, non_trivial);
1598
598
      FLAG(hasUserDeclaredMoveConstructor, user_declared);
1599
598
      FLAG(needsImplicitMoveConstructor, needs_implicit);
1600
598
      FLAG(needsOverloadResolutionForMoveConstructor,
1601
598
           needs_overload_resolution);
1602
598
      if (!D->needsOverloadResolutionForMoveConstructor())
1603
598
        
FLAG579
(defaultedMoveConstructorIsDeleted, defaulted_is_deleted);
1604
598
    });
1605
598
1606
598
    AddChild([=] {
1607
598
      {
1608
598
        ColorScope Color(OS, ShowColors, DeclKindNameColor);
1609
598
        OS << "CopyAssignment";
1610
598
      }
1611
598
      FLAG(hasTrivialCopyAssignment, trivial);
1612
598
      FLAG(hasNonTrivialCopyAssignment, non_trivial);
1613
598
      FLAG(hasCopyAssignmentWithConstParam, has_const_param);
1614
598
      FLAG(hasUserDeclaredCopyAssignment, user_declared);
1615
598
      FLAG(needsImplicitCopyAssignment, needs_implicit);
1616
598
      FLAG(needsOverloadResolutionForCopyAssignment, needs_overload_resolution);
1617
598
      FLAG(implicitCopyAssignmentHasConstParam, implicit_has_const_param);
1618
598
    });
1619
598
1620
598
    AddChild([=] {
1621
598
      {
1622
598
        ColorScope Color(OS, ShowColors, DeclKindNameColor);
1623
598
        OS << "MoveAssignment";
1624
598
      }
1625
598
      FLAG(hasMoveAssignment, exists);
1626
598
      FLAG(hasSimpleMoveAssignment, simple);
1627
598
      FLAG(hasTrivialMoveAssignment, trivial);
1628
598
      FLAG(hasNonTrivialMoveAssignment, non_trivial);
1629
598
      FLAG(hasUserDeclaredMoveAssignment, user_declared);
1630
598
      FLAG(needsImplicitMoveAssignment, needs_implicit);
1631
598
      FLAG(needsOverloadResolutionForMoveAssignment, needs_overload_resolution);
1632
598
    });
1633
598
1634
598
    AddChild([=] {
1635
598
      {
1636
598
        ColorScope Color(OS, ShowColors, DeclKindNameColor);
1637
598
        OS << "Destructor";
1638
598
      }
1639
598
      FLAG(hasSimpleDestructor, simple);
1640
598
      FLAG(hasIrrelevantDestructor, irrelevant);
1641
598
      FLAG(hasTrivialDestructor, trivial);
1642
598
      FLAG(hasNonTrivialDestructor, non_trivial);
1643
598
      FLAG(hasUserDeclaredDestructor, user_declared);
1644
598
      FLAG(needsImplicitDestructor, needs_implicit);
1645
598
      FLAG(needsOverloadResolutionForDestructor, needs_overload_resolution);
1646
598
      if (!D->needsOverloadResolutionForDestructor())
1647
598
        
FLAG582
(defaultedDestructorIsDeleted, defaulted_is_deleted);
1648
598
    });
1649
598
  });
1650
598
1651
598
  for (const auto &I : D->bases()) {
1652
78
    AddChild([=] {
1653
78
      if (I.isVirtual())
1654
23
        OS << "virtual ";
1655
78
      dumpAccessSpecifier(I.getAccessSpecifier());
1656
78
      dumpType(I.getType());
1657
78
      if (I.isPackExpansion())
1658
2
        OS << "...";
1659
78
    });
1660
78
  }
1661
598
}
1662
1663
105
void TextNodeDumper::VisitFunctionTemplateDecl(const FunctionTemplateDecl *D) {
1664
105
  dumpName(D);
1665
105
}
1666
1667
114
void TextNodeDumper::VisitClassTemplateDecl(const ClassTemplateDecl *D) {
1668
114
  dumpName(D);
1669
114
}
1670
1671
4
void TextNodeDumper::VisitVarTemplateDecl(const VarTemplateDecl *D) {
1672
4
  dumpName(D);
1673
4
}
1674
1675
0
void TextNodeDumper::VisitBuiltinTemplateDecl(const BuiltinTemplateDecl *D) {
1676
0
  dumpName(D);
1677
0
}
1678
1679
225
void TextNodeDumper::VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D) {
1680
225
  if (D->wasDeclaredWithTypename())
1681
186
    OS << " typename";
1682
39
  else
1683
39
    OS << " class";
1684
225
  OS << " depth " << D->getDepth() << " index " << D->getIndex();
1685
225
  if (D->isParameterPack())
1686
19
    OS << " ...";
1687
225
  dumpName(D);
1688
225
}
1689
1690
void TextNodeDumper::VisitNonTypeTemplateParmDecl(
1691
49
    const NonTypeTemplateParmDecl *D) {
1692
49
  dumpType(D->getType());
1693
49
  OS << " depth " << D->getDepth() << " index " << D->getIndex();
1694
49
  if (D->isParameterPack())
1695
5
    OS << " ...";
1696
49
  dumpName(D);
1697
49
}
1698
1699
void TextNodeDumper::VisitTemplateTemplateParmDecl(
1700
11
    const TemplateTemplateParmDecl *D) {
1701
11
  OS << " depth " << D->getDepth() << " index " << D->getIndex();
1702
11
  if (D->isParameterPack())
1703
5
    OS << " ...";
1704
11
  dumpName(D);
1705
11
}
1706
1707
18
void TextNodeDumper::VisitUsingDecl(const UsingDecl *D) {
1708
18
  OS << ' ';
1709
18
  if (D->getQualifier())
1710
18
    D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
1711
18
  OS << D->getNameAsString();
1712
18
}
1713
1714
void TextNodeDumper::VisitUnresolvedUsingTypenameDecl(
1715
1
    const UnresolvedUsingTypenameDecl *D) {
1716
1
  OS << ' ';
1717
1
  if (D->getQualifier())
1718
1
    D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
1719
1
  OS << D->getNameAsString();
1720
1
}
1721
1722
void TextNodeDumper::VisitUnresolvedUsingValueDecl(
1723
1
    const UnresolvedUsingValueDecl *D) {
1724
1
  OS << ' ';
1725
1
  if (D->getQualifier())
1726
1
    D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
1727
1
  OS << D->getNameAsString();
1728
1
  dumpType(D->getType());
1729
1
}
1730
1731
12
void TextNodeDumper::VisitUsingShadowDecl(const UsingShadowDecl *D) {
1732
12
  OS << ' ';
1733
12
  dumpBareDeclRef(D->getTargetDecl());
1734
12
}
1735
1736
void TextNodeDumper::VisitConstructorUsingShadowDecl(
1737
12
    const ConstructorUsingShadowDecl *D) {
1738
12
  if (D->constructsVirtualBase())
1739
0
    OS << " virtual";
1740
12
1741
12
  AddChild([=] {
1742
12
    OS << "target ";
1743
12
    dumpBareDeclRef(D->getTargetDecl());
1744
12
  });
1745
12
1746
12
  AddChild([=] {
1747
12
    OS << "nominated ";
1748
12
    dumpBareDeclRef(D->getNominatedBaseClass());
1749
12
    OS << ' ';
1750
12
    dumpBareDeclRef(D->getNominatedBaseClassShadowDecl());
1751
12
  });
1752
12
1753
12
  AddChild([=] {
1754
12
    OS << "constructed ";
1755
12
    dumpBareDeclRef(D->getConstructedBaseClass());
1756
12
    OS << ' ';
1757
12
    dumpBareDeclRef(D->getConstructedBaseClassShadowDecl());
1758
12
  });
1759
12
}
1760
1761
13
void TextNodeDumper::VisitLinkageSpecDecl(const LinkageSpecDecl *D) {
1762
13
  switch (D->getLanguage()) {
1763
13
  case LinkageSpecDecl::lang_c:
1764
12
    OS << " C";
1765
12
    break;
1766
13
  case LinkageSpecDecl::lang_cxx:
1767
1
    OS << " C++";
1768
1
    break;
1769
13
  }
1770
13
}
1771
1772
54
void TextNodeDumper::VisitAccessSpecDecl(const AccessSpecDecl *D) {
1773
54
  OS << ' ';
1774
54
  dumpAccessSpecifier(D->getAccess());
1775
54
}
1776
1777
10
void TextNodeDumper::VisitFriendDecl(const FriendDecl *D) {
1778
10
  if (TypeSourceInfo *T = D->getFriendType())
1779
4
    dumpType(T->getType());
1780
10
}
1781
1782
32
void TextNodeDumper::VisitObjCIvarDecl(const ObjCIvarDecl *D) {
1783
32
  dumpName(D);
1784
32
  dumpType(D->getType());
1785
32
  if (D->getSynthesize())
1786
7
    OS << " synthesize";
1787
32
1788
32
  switch (D->getAccessControl()) {
1789
32
  case ObjCIvarDecl::None:
1790
0
    OS << " none";
1791
0
    break;
1792
32
  case ObjCIvarDecl::Private:
1793
13
    OS << " private";
1794
13
    break;
1795
32
  case ObjCIvarDecl::Protected:
1796
17
    OS << " protected";
1797
17
    break;
1798
32
  case ObjCIvarDecl::Public:
1799
1
    OS << " public";
1800
1
    break;
1801
32
  case ObjCIvarDecl::Package:
1802
1
    OS << " package";
1803
1
    break;
1804
32
  }
1805
32
}
1806
1807
97
void TextNodeDumper::VisitObjCMethodDecl(const ObjCMethodDecl *D) {
1808
97
  if (D->isInstanceMethod())
1809
75
    OS << " -";
1810
22
  else
1811
22
    OS << " +";
1812
97
  dumpName(D);
1813
97
  dumpType(D->getReturnType());
1814
97
1815
97
  if (D->isVariadic())
1816
3
    OS << " variadic";
1817
97
}
1818
1819
3
void TextNodeDumper::VisitObjCTypeParamDecl(const ObjCTypeParamDecl *D) {
1820
3
  dumpName(D);
1821
3
  switch (D->getVariance()) {
1822
3
  case ObjCTypeParamVariance::Invariant:
1823
3
    break;
1824
3
1825
3
  case ObjCTypeParamVariance::Covariant:
1826
0
    OS << " covariant";
1827
0
    break;
1828
3
1829
3
  case ObjCTypeParamVariance::Contravariant:
1830
0
    OS << " contravariant";
1831
0
    break;
1832
3
  }
1833
3
1834
3
  if (D->hasExplicitBound())
1835
1
    OS << " bounded";
1836
3
  dumpType(D->getUnderlyingType());
1837
3
}
1838
1839
16
void TextNodeDumper::VisitObjCCategoryDecl(const ObjCCategoryDecl *D) {
1840
16
  dumpName(D);
1841
16
  dumpDeclRef(D->getClassInterface());
1842
16
  dumpDeclRef(D->getImplementation());
1843
16
  for (const auto *P : D->protocols())
1844
1
    dumpDeclRef(P);
1845
16
}
1846
1847
3
void TextNodeDumper::VisitObjCCategoryImplDecl(const ObjCCategoryImplDecl *D) {
1848
3
  dumpName(D);
1849
3
  dumpDeclRef(D->getClassInterface());
1850
3
  dumpDeclRef(D->getCategoryDecl());
1851
3
}
1852
1853
17
void TextNodeDumper::VisitObjCProtocolDecl(const ObjCProtocolDecl *D) {
1854
17
  dumpName(D);
1855
17
1856
17
  for (const auto *Child : D->protocols())
1857
0
    dumpDeclRef(Child);
1858
17
}
1859
1860
62
void TextNodeDumper::VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D) {
1861
62
  dumpName(D);
1862
62
  dumpDeclRef(D->getSuperClass(), "super");
1863
62
1864
62
  dumpDeclRef(D->getImplementation());
1865
62
  for (const auto *Child : D->protocols())
1866
3
    dumpDeclRef(Child);
1867
62
}
1868
1869
void TextNodeDumper::VisitObjCImplementationDecl(
1870
15
    const ObjCImplementationDecl *D) {
1871
15
  dumpName(D);
1872
15
  dumpDeclRef(D->getSuperClass(), "super");
1873
15
  dumpDeclRef(D->getClassInterface());
1874
15
}
1875
1876
void TextNodeDumper::VisitObjCCompatibleAliasDecl(
1877
2
    const ObjCCompatibleAliasDecl *D) {
1878
2
  dumpName(D);
1879
2
  dumpDeclRef(D->getClassInterface());
1880
2
}
1881
1882
26
void TextNodeDumper::VisitObjCPropertyDecl(const ObjCPropertyDecl *D) {
1883
26
  dumpName(D);
1884
26
  dumpType(D->getType());
1885
26
1886
26
  if (D->getPropertyImplementation() == ObjCPropertyDecl::Required)
1887
0
    OS << " required";
1888
26
  else if (D->getPropertyImplementation() == ObjCPropertyDecl::Optional)
1889
0
    OS << " optional";
1890
26
1891
26
  ObjCPropertyDecl::PropertyAttributeKind Attrs = D->getPropertyAttributes();
1892
26
  if (Attrs != ObjCPropertyDecl::OBJC_PR_noattr) {
1893
26
    if (Attrs & ObjCPropertyDecl::OBJC_PR_readonly)
1894
5
      OS << " readonly";
1895
26
    if (Attrs & ObjCPropertyDecl::OBJC_PR_assign)
1896
19
      OS << " assign";
1897
26
    if (Attrs & ObjCPropertyDecl::OBJC_PR_readwrite)
1898
21
      OS << " readwrite";
1899
26
    if (Attrs & ObjCPropertyDecl::OBJC_PR_retain)
1900
1
      OS << " retain";
1901
26
    if (Attrs & ObjCPropertyDecl::OBJC_PR_copy)
1902
1
      OS << " copy";
1903
26
    if (Attrs & ObjCPropertyDecl::OBJC_PR_nonatomic)
1904
3
      OS << " nonatomic";
1905
26
    if (Attrs & ObjCPropertyDecl::OBJC_PR_atomic)
1906
23
      OS << " atomic";
1907
26
    if (Attrs & ObjCPropertyDecl::OBJC_PR_weak)
1908
0
      OS << " weak";
1909
26
    if (Attrs & ObjCPropertyDecl::OBJC_PR_strong)
1910
0
      OS << " strong";
1911
26
    if (Attrs & ObjCPropertyDecl::OBJC_PR_unsafe_unretained)
1912
19
      OS << " unsafe_unretained";
1913
26
    if (Attrs & ObjCPropertyDecl::OBJC_PR_class)
1914
0
      OS << " class";
1915
26
    if (Attrs & ObjCPropertyDecl::OBJC_PR_getter)
1916
2
      dumpDeclRef(D->getGetterMethodDecl(), "getter");
1917
26
    if (Attrs & ObjCPropertyDecl::OBJC_PR_setter)
1918
2
      dumpDeclRef(D->getSetterMethodDecl(), "setter");
1919
26
  }
1920
26
}
1921
1922
13
void TextNodeDumper::VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D) {
1923
13
  dumpName(D->getPropertyDecl());
1924
13
  if (D->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize)
1925
12
    OS << " synthesize";
1926
1
  else
1927
1
    OS << " dynamic";
1928
13
  dumpDeclRef(D->getPropertyDecl());
1929
13
  dumpDeclRef(D->getPropertyIvarDecl());
1930
13
}
1931
1932
15
void TextNodeDumper::VisitBlockDecl(const BlockDecl *D) {
1933
15
  if (D->isVariadic())
1934
1
    OS << " variadic";
1935
15
1936
15
  if (D->capturesCXXThis())
1937
1
    OS << " captures_this";
1938
15
}
1939
1940
0
void TextNodeDumper::VisitConceptDecl(const ConceptDecl *D) {
1941
0
  dumpName(D);
1942
0
}