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

source code of clang/lib/AST/TextNodeDumper.cpp