cmake: Inline the add_llvm_symbol_exports.py script
[llvm-project.git] / clang / lib / AST / TextNodeDumper.cpp
blob574cb6c4ca40157e7e7941bcf68fd09baafaf280
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.
11 //===----------------------------------------------------------------------===//
13 #include "clang/AST/TextNodeDumper.h"
14 #include "clang/AST/APValue.h"
15 #include "clang/AST/DeclFriend.h"
16 #include "clang/AST/DeclOpenMP.h"
17 #include "clang/AST/DeclTemplate.h"
18 #include "clang/AST/LocInfoType.h"
19 #include "clang/AST/Type.h"
20 #include "clang/Basic/Module.h"
21 #include "clang/Basic/SourceManager.h"
22 #include "clang/Basic/Specifiers.h"
23 #include "clang/Basic/TypeTraits.h"
24 #include "llvm/ADT/StringExtras.h"
26 #include <algorithm>
27 #include <utility>
29 using namespace clang;
31 static void dumpPreviousDeclImpl(raw_ostream &OS, ...) {}
33 template <typename T>
34 static void dumpPreviousDeclImpl(raw_ostream &OS, const Mergeable<T> *D) {
35 const T *First = D->getFirstDecl();
36 if (First != D)
37 OS << " first " << First;
40 template <typename T>
41 static void dumpPreviousDeclImpl(raw_ostream &OS, const Redeclarable<T> *D) {
42 const T *Prev = D->getPreviousDecl();
43 if (Prev)
44 OS << " prev " << Prev;
47 /// Dump the previous declaration in the redeclaration chain for a declaration,
48 /// if any.
49 static void dumpPreviousDecl(raw_ostream &OS, const Decl *D) {
50 switch (D->getKind()) {
51 #define DECL(DERIVED, BASE) \
52 case Decl::DERIVED: \
53 return dumpPreviousDeclImpl(OS, cast<DERIVED##Decl>(D));
54 #define ABSTRACT_DECL(DECL)
55 #include "clang/AST/DeclNodes.inc"
57 llvm_unreachable("Decl that isn't part of DeclNodes.inc!");
60 TextNodeDumper::TextNodeDumper(raw_ostream &OS, const ASTContext &Context,
61 bool ShowColors)
62 : TextTreeStructure(OS, ShowColors), OS(OS), ShowColors(ShowColors),
63 Context(&Context), SM(&Context.getSourceManager()),
64 PrintPolicy(Context.getPrintingPolicy()),
65 Traits(&Context.getCommentCommandTraits()) {}
67 TextNodeDumper::TextNodeDumper(raw_ostream &OS, bool ShowColors)
68 : TextTreeStructure(OS, ShowColors), OS(OS), ShowColors(ShowColors) {}
70 void TextNodeDumper::Visit(const comments::Comment *C,
71 const comments::FullComment *FC) {
72 if (!C) {
73 ColorScope Color(OS, ShowColors, NullColor);
74 OS << "<<<NULL>>>";
75 return;
79 ColorScope Color(OS, ShowColors, CommentColor);
80 OS << C->getCommentKindName();
82 dumpPointer(C);
83 dumpSourceRange(C->getSourceRange());
85 ConstCommentVisitor<TextNodeDumper, void,
86 const comments::FullComment *>::visit(C, FC);
89 void TextNodeDumper::Visit(const Attr *A) {
91 ColorScope Color(OS, ShowColors, AttrColor);
93 switch (A->getKind()) {
94 #define ATTR(X) \
95 case attr::X: \
96 OS << #X; \
97 break;
98 #include "clang/Basic/AttrList.inc"
100 OS << "Attr";
102 dumpPointer(A);
103 dumpSourceRange(A->getRange());
104 if (A->isInherited())
105 OS << " Inherited";
106 if (A->isImplicit())
107 OS << " Implicit";
109 ConstAttrVisitor<TextNodeDumper>::Visit(A);
112 void TextNodeDumper::Visit(const TemplateArgument &TA, SourceRange R,
113 const Decl *From, StringRef Label) {
114 OS << "TemplateArgument";
115 if (R.isValid())
116 dumpSourceRange(R);
118 if (From)
119 dumpDeclRef(From, Label);
121 ConstTemplateArgumentVisitor<TextNodeDumper>::Visit(TA);
124 void TextNodeDumper::Visit(const Stmt *Node) {
125 if (!Node) {
126 ColorScope Color(OS, ShowColors, NullColor);
127 OS << "<<<NULL>>>";
128 return;
131 ColorScope Color(OS, ShowColors, StmtColor);
132 OS << Node->getStmtClassName();
134 dumpPointer(Node);
135 dumpSourceRange(Node->getSourceRange());
137 if (const auto *E = dyn_cast<Expr>(Node)) {
138 dumpType(E->getType());
140 if (E->containsErrors()) {
141 ColorScope Color(OS, ShowColors, ErrorsColor);
142 OS << " contains-errors";
146 ColorScope Color(OS, ShowColors, ValueKindColor);
147 switch (E->getValueKind()) {
148 case VK_PRValue:
149 break;
150 case VK_LValue:
151 OS << " lvalue";
152 break;
153 case VK_XValue:
154 OS << " xvalue";
155 break;
160 ColorScope Color(OS, ShowColors, ObjectKindColor);
161 switch (E->getObjectKind()) {
162 case OK_Ordinary:
163 break;
164 case OK_BitField:
165 OS << " bitfield";
166 break;
167 case OK_ObjCProperty:
168 OS << " objcproperty";
169 break;
170 case OK_ObjCSubscript:
171 OS << " objcsubscript";
172 break;
173 case OK_VectorComponent:
174 OS << " vectorcomponent";
175 break;
176 case OK_MatrixComponent:
177 OS << " matrixcomponent";
178 break;
183 ConstStmtVisitor<TextNodeDumper>::Visit(Node);
186 void TextNodeDumper::Visit(const Type *T) {
187 if (!T) {
188 ColorScope Color(OS, ShowColors, NullColor);
189 OS << "<<<NULL>>>";
190 return;
192 if (isa<LocInfoType>(T)) {
194 ColorScope Color(OS, ShowColors, TypeColor);
195 OS << "LocInfo Type";
197 dumpPointer(T);
198 return;
202 ColorScope Color(OS, ShowColors, TypeColor);
203 OS << T->getTypeClassName() << "Type";
205 dumpPointer(T);
206 OS << " ";
207 dumpBareType(QualType(T, 0), false);
209 QualType SingleStepDesugar =
210 T->getLocallyUnqualifiedSingleStepDesugaredType();
211 if (SingleStepDesugar != QualType(T, 0))
212 OS << " sugar";
214 if (T->containsErrors()) {
215 ColorScope Color(OS, ShowColors, ErrorsColor);
216 OS << " contains-errors";
219 if (T->isDependentType())
220 OS << " dependent";
221 else if (T->isInstantiationDependentType())
222 OS << " instantiation_dependent";
224 if (T->isVariablyModifiedType())
225 OS << " variably_modified";
226 if (T->containsUnexpandedParameterPack())
227 OS << " contains_unexpanded_pack";
228 if (T->isFromAST())
229 OS << " imported";
231 TypeVisitor<TextNodeDumper>::Visit(T);
234 void TextNodeDumper::Visit(QualType T) {
235 OS << "QualType";
236 dumpPointer(T.getAsOpaquePtr());
237 OS << " ";
238 dumpBareType(T, false);
239 OS << " " << T.split().Quals.getAsString();
242 void TextNodeDumper::Visit(const Decl *D) {
243 if (!D) {
244 ColorScope Color(OS, ShowColors, NullColor);
245 OS << "<<<NULL>>>";
246 return;
250 ColorScope Color(OS, ShowColors, DeclKindNameColor);
251 OS << D->getDeclKindName() << "Decl";
253 dumpPointer(D);
254 if (D->getLexicalDeclContext() != D->getDeclContext())
255 OS << " parent " << cast<Decl>(D->getDeclContext());
256 dumpPreviousDecl(OS, D);
257 dumpSourceRange(D->getSourceRange());
258 OS << ' ';
259 dumpLocation(D->getLocation());
260 if (D->isFromASTFile())
261 OS << " imported";
262 if (Module *M = D->getOwningModule())
263 OS << " in " << M->getFullModuleName();
264 if (auto *ND = dyn_cast<NamedDecl>(D))
265 for (Module *M : D->getASTContext().getModulesWithMergedDefinition(
266 const_cast<NamedDecl *>(ND)))
267 AddChild([=] { OS << "also in " << M->getFullModuleName(); });
268 if (const NamedDecl *ND = dyn_cast<NamedDecl>(D))
269 if (!ND->isUnconditionallyVisible())
270 OS << " hidden";
271 if (D->isImplicit())
272 OS << " implicit";
274 if (D->isUsed())
275 OS << " used";
276 else if (D->isThisDeclarationReferenced())
277 OS << " referenced";
279 if (D->isInvalidDecl())
280 OS << " invalid";
281 if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
282 if (FD->isConstexprSpecified())
283 OS << " constexpr";
284 if (FD->isConsteval())
285 OS << " consteval";
286 if (FD->isMultiVersion())
287 OS << " multiversion";
290 if (!isa<FunctionDecl>(*D)) {
291 const auto *MD = dyn_cast<ObjCMethodDecl>(D);
292 if (!MD || !MD->isThisDeclarationADefinition()) {
293 const auto *DC = dyn_cast<DeclContext>(D);
294 if (DC && DC->hasExternalLexicalStorage()) {
295 ColorScope Color(OS, ShowColors, UndeserializedColor);
296 OS << " <undeserialized declarations>";
301 ConstDeclVisitor<TextNodeDumper>::Visit(D);
304 void TextNodeDumper::Visit(const CXXCtorInitializer *Init) {
305 OS << "CXXCtorInitializer";
306 if (Init->isAnyMemberInitializer()) {
307 OS << ' ';
308 dumpBareDeclRef(Init->getAnyMember());
309 } else if (Init->isBaseInitializer()) {
310 dumpType(QualType(Init->getBaseClass(), 0));
311 } else if (Init->isDelegatingInitializer()) {
312 dumpType(Init->getTypeSourceInfo()->getType());
313 } else {
314 llvm_unreachable("Unknown initializer type");
318 void TextNodeDumper::Visit(const BlockDecl::Capture &C) {
319 OS << "capture";
320 if (C.isByRef())
321 OS << " byref";
322 if (C.isNested())
323 OS << " nested";
324 if (C.getVariable()) {
325 OS << ' ';
326 dumpBareDeclRef(C.getVariable());
330 void TextNodeDumper::Visit(const OMPClause *C) {
331 if (!C) {
332 ColorScope Color(OS, ShowColors, NullColor);
333 OS << "<<<NULL>>> OMPClause";
334 return;
337 ColorScope Color(OS, ShowColors, AttrColor);
338 StringRef ClauseName(llvm::omp::getOpenMPClauseName(C->getClauseKind()));
339 OS << "OMP" << ClauseName.substr(/*Start=*/0, /*N=*/1).upper()
340 << ClauseName.drop_front() << "Clause";
342 dumpPointer(C);
343 dumpSourceRange(SourceRange(C->getBeginLoc(), C->getEndLoc()));
344 if (C->isImplicit())
345 OS << " <implicit>";
348 void TextNodeDumper::Visit(const GenericSelectionExpr::ConstAssociation &A) {
349 const TypeSourceInfo *TSI = A.getTypeSourceInfo();
350 if (TSI) {
351 OS << "case ";
352 dumpType(TSI->getType());
353 } else {
354 OS << "default";
357 if (A.isSelected())
358 OS << " selected";
361 void TextNodeDumper::Visit(const concepts::Requirement *R) {
362 if (!R) {
363 ColorScope Color(OS, ShowColors, NullColor);
364 OS << "<<<NULL>>> Requirement";
365 return;
369 ColorScope Color(OS, ShowColors, StmtColor);
370 switch (R->getKind()) {
371 case concepts::Requirement::RK_Type:
372 OS << "TypeRequirement";
373 break;
374 case concepts::Requirement::RK_Simple:
375 OS << "SimpleRequirement";
376 break;
377 case concepts::Requirement::RK_Compound:
378 OS << "CompoundRequirement";
379 break;
380 case concepts::Requirement::RK_Nested:
381 OS << "NestedRequirement";
382 break;
386 dumpPointer(R);
388 if (auto *ER = dyn_cast<concepts::ExprRequirement>(R)) {
389 if (ER->hasNoexceptRequirement())
390 OS << " noexcept";
393 if (R->isDependent())
394 OS << " dependent";
395 else
396 OS << (R->isSatisfied() ? " satisfied" : " unsatisfied");
397 if (R->containsUnexpandedParameterPack())
398 OS << " contains_unexpanded_pack";
401 static double GetApproxValue(const llvm::APFloat &F) {
402 llvm::APFloat V = F;
403 bool ignored;
404 V.convert(llvm::APFloat::IEEEdouble(), llvm::APFloat::rmNearestTiesToEven,
405 &ignored);
406 return V.convertToDouble();
409 /// True if the \p APValue \p Value can be folded onto the current line.
410 static bool isSimpleAPValue(const APValue &Value) {
411 switch (Value.getKind()) {
412 case APValue::None:
413 case APValue::Indeterminate:
414 case APValue::Int:
415 case APValue::Float:
416 case APValue::FixedPoint:
417 case APValue::ComplexInt:
418 case APValue::ComplexFloat:
419 case APValue::LValue:
420 case APValue::MemberPointer:
421 case APValue::AddrLabelDiff:
422 return true;
423 case APValue::Vector:
424 case APValue::Array:
425 case APValue::Struct:
426 return false;
427 case APValue::Union:
428 return isSimpleAPValue(Value.getUnionValue());
430 llvm_unreachable("unexpected APValue kind!");
433 /// Dump the children of the \p APValue \p Value.
435 /// \param[in] Value The \p APValue to visit
436 /// \param[in] Ty The \p QualType passed to \p Visit
438 /// \param[in] IdxToChildFun A function mapping an \p APValue and an index
439 /// to one of the child of the \p APValue
441 /// \param[in] NumChildren \p IdxToChildFun will be called on \p Value with
442 /// the indices in the range \p [0,NumChildren(
444 /// \param[in] LabelSingular The label to use on a line with a single child
445 /// \param[in] LabelPlurial The label to use on a line with multiple children
446 void TextNodeDumper::dumpAPValueChildren(
447 const APValue &Value, QualType Ty,
448 const APValue &(*IdxToChildFun)(const APValue &, unsigned),
449 unsigned NumChildren, StringRef LabelSingular, StringRef LabelPlurial) {
450 // To save some vertical space we print up to MaxChildrenPerLine APValues
451 // considered to be simple (by isSimpleAPValue) on a single line.
452 constexpr unsigned MaxChildrenPerLine = 4;
453 unsigned I = 0;
454 while (I < NumChildren) {
455 unsigned J = I;
456 while (J < NumChildren) {
457 if (isSimpleAPValue(IdxToChildFun(Value, J)) &&
458 (J - I < MaxChildrenPerLine)) {
459 ++J;
460 continue;
462 break;
465 J = std::max(I + 1, J);
467 // Print [I,J) on a single line.
468 AddChild(J - I > 1 ? LabelPlurial : LabelSingular, [=]() {
469 for (unsigned X = I; X < J; ++X) {
470 Visit(IdxToChildFun(Value, X), Ty);
471 if (X + 1 != J)
472 OS << ", ";
475 I = J;
479 void TextNodeDumper::Visit(const APValue &Value, QualType Ty) {
480 ColorScope Color(OS, ShowColors, ValueKindColor);
481 switch (Value.getKind()) {
482 case APValue::None:
483 OS << "None";
484 return;
485 case APValue::Indeterminate:
486 OS << "Indeterminate";
487 return;
488 case APValue::Int:
489 OS << "Int ";
491 ColorScope Color(OS, ShowColors, ValueColor);
492 OS << Value.getInt();
494 return;
495 case APValue::Float:
496 OS << "Float ";
498 ColorScope Color(OS, ShowColors, ValueColor);
499 OS << GetApproxValue(Value.getFloat());
501 return;
502 case APValue::FixedPoint:
503 OS << "FixedPoint ";
505 ColorScope Color(OS, ShowColors, ValueColor);
506 OS << Value.getFixedPoint();
508 return;
509 case APValue::Vector: {
510 unsigned VectorLength = Value.getVectorLength();
511 OS << "Vector length=" << VectorLength;
513 dumpAPValueChildren(
514 Value, Ty,
515 [](const APValue &Value, unsigned Index) -> const APValue & {
516 return Value.getVectorElt(Index);
518 VectorLength, "element", "elements");
519 return;
521 case APValue::ComplexInt:
522 OS << "ComplexInt ";
524 ColorScope Color(OS, ShowColors, ValueColor);
525 OS << Value.getComplexIntReal() << " + " << Value.getComplexIntImag()
526 << 'i';
528 return;
529 case APValue::ComplexFloat:
530 OS << "ComplexFloat ";
532 ColorScope Color(OS, ShowColors, ValueColor);
533 OS << GetApproxValue(Value.getComplexFloatReal()) << " + "
534 << GetApproxValue(Value.getComplexFloatImag()) << 'i';
536 return;
537 case APValue::LValue:
538 (void)Context;
539 OS << "LValue <todo>";
540 return;
541 case APValue::Array: {
542 unsigned ArraySize = Value.getArraySize();
543 unsigned NumInitializedElements = Value.getArrayInitializedElts();
544 OS << "Array size=" << ArraySize;
546 dumpAPValueChildren(
547 Value, Ty,
548 [](const APValue &Value, unsigned Index) -> const APValue & {
549 return Value.getArrayInitializedElt(Index);
551 NumInitializedElements, "element", "elements");
553 if (Value.hasArrayFiller()) {
554 AddChild("filler", [=] {
556 ColorScope Color(OS, ShowColors, ValueColor);
557 OS << ArraySize - NumInitializedElements << " x ";
559 Visit(Value.getArrayFiller(), Ty);
563 return;
565 case APValue::Struct: {
566 OS << "Struct";
568 dumpAPValueChildren(
569 Value, Ty,
570 [](const APValue &Value, unsigned Index) -> const APValue & {
571 return Value.getStructBase(Index);
573 Value.getStructNumBases(), "base", "bases");
575 dumpAPValueChildren(
576 Value, Ty,
577 [](const APValue &Value, unsigned Index) -> const APValue & {
578 return Value.getStructField(Index);
580 Value.getStructNumFields(), "field", "fields");
582 return;
584 case APValue::Union: {
585 OS << "Union";
587 ColorScope Color(OS, ShowColors, ValueColor);
588 if (const FieldDecl *FD = Value.getUnionField())
589 OS << " ." << *cast<NamedDecl>(FD);
591 // If the union value is considered to be simple, fold it into the
592 // current line to save some vertical space.
593 const APValue &UnionValue = Value.getUnionValue();
594 if (isSimpleAPValue(UnionValue)) {
595 OS << ' ';
596 Visit(UnionValue, Ty);
597 } else {
598 AddChild([=] { Visit(UnionValue, Ty); });
601 return;
603 case APValue::MemberPointer:
604 OS << "MemberPointer <todo>";
605 return;
606 case APValue::AddrLabelDiff:
607 OS << "AddrLabelDiff <todo>";
608 return;
610 llvm_unreachable("Unknown APValue kind!");
613 void TextNodeDumper::dumpPointer(const void *Ptr) {
614 ColorScope Color(OS, ShowColors, AddressColor);
615 OS << ' ' << Ptr;
618 void TextNodeDumper::dumpLocation(SourceLocation Loc) {
619 if (!SM)
620 return;
622 ColorScope Color(OS, ShowColors, LocationColor);
623 SourceLocation SpellingLoc = SM->getSpellingLoc(Loc);
625 // The general format we print out is filename:line:col, but we drop pieces
626 // that haven't changed since the last loc printed.
627 PresumedLoc PLoc = SM->getPresumedLoc(SpellingLoc);
629 if (PLoc.isInvalid()) {
630 OS << "<invalid sloc>";
631 return;
634 if (strcmp(PLoc.getFilename(), LastLocFilename) != 0) {
635 OS << PLoc.getFilename() << ':' << PLoc.getLine() << ':'
636 << PLoc.getColumn();
637 LastLocFilename = PLoc.getFilename();
638 LastLocLine = PLoc.getLine();
639 } else if (PLoc.getLine() != LastLocLine) {
640 OS << "line" << ':' << PLoc.getLine() << ':' << PLoc.getColumn();
641 LastLocLine = PLoc.getLine();
642 } else {
643 OS << "col" << ':' << PLoc.getColumn();
647 void TextNodeDumper::dumpSourceRange(SourceRange R) {
648 // Can't translate locations if a SourceManager isn't available.
649 if (!SM)
650 return;
652 OS << " <";
653 dumpLocation(R.getBegin());
654 if (R.getBegin() != R.getEnd()) {
655 OS << ", ";
656 dumpLocation(R.getEnd());
658 OS << ">";
660 // <t2.c:123:421[blah], t2.c:412:321>
663 void TextNodeDumper::dumpBareType(QualType T, bool Desugar) {
664 ColorScope Color(OS, ShowColors, TypeColor);
666 SplitQualType T_split = T.split();
667 OS << "'" << QualType::getAsString(T_split, PrintPolicy) << "'";
669 if (Desugar && !T.isNull()) {
670 // If the type is sugared, also dump a (shallow) desugared type.
671 SplitQualType D_split = T.getSplitDesugaredType();
672 if (T_split != D_split)
673 OS << ":'" << QualType::getAsString(D_split, PrintPolicy) << "'";
677 void TextNodeDumper::dumpType(QualType T) {
678 OS << ' ';
679 dumpBareType(T);
682 void TextNodeDumper::dumpBareDeclRef(const Decl *D) {
683 if (!D) {
684 ColorScope Color(OS, ShowColors, NullColor);
685 OS << "<<<NULL>>>";
686 return;
690 ColorScope Color(OS, ShowColors, DeclKindNameColor);
691 OS << D->getDeclKindName();
693 dumpPointer(D);
695 if (const NamedDecl *ND = dyn_cast<NamedDecl>(D)) {
696 ColorScope Color(OS, ShowColors, DeclNameColor);
697 OS << " '" << ND->getDeclName() << '\'';
700 if (const ValueDecl *VD = dyn_cast<ValueDecl>(D))
701 dumpType(VD->getType());
704 void TextNodeDumper::dumpName(const NamedDecl *ND) {
705 if (ND->getDeclName()) {
706 ColorScope Color(OS, ShowColors, DeclNameColor);
707 OS << ' ' << ND->getDeclName();
711 void TextNodeDumper::dumpAccessSpecifier(AccessSpecifier AS) {
712 const auto AccessSpelling = getAccessSpelling(AS);
713 if (AccessSpelling.empty())
714 return;
715 OS << AccessSpelling;
718 void TextNodeDumper::dumpCleanupObject(
719 const ExprWithCleanups::CleanupObject &C) {
720 if (auto *BD = C.dyn_cast<BlockDecl *>())
721 dumpDeclRef(BD, "cleanup");
722 else if (auto *CLE = C.dyn_cast<CompoundLiteralExpr *>())
723 AddChild([=] {
724 OS << "cleanup ";
726 ColorScope Color(OS, ShowColors, StmtColor);
727 OS << CLE->getStmtClassName();
729 dumpPointer(CLE);
731 else
732 llvm_unreachable("unexpected cleanup type");
735 void TextNodeDumper::dumpDeclRef(const Decl *D, StringRef Label) {
736 if (!D)
737 return;
739 AddChild([=] {
740 if (!Label.empty())
741 OS << Label << ' ';
742 dumpBareDeclRef(D);
746 const char *TextNodeDumper::getCommandName(unsigned CommandID) {
747 if (Traits)
748 return Traits->getCommandInfo(CommandID)->Name;
749 const comments::CommandInfo *Info =
750 comments::CommandTraits::getBuiltinCommandInfo(CommandID);
751 if (Info)
752 return Info->Name;
753 return "<not a builtin command>";
756 void TextNodeDumper::printFPOptions(FPOptionsOverride FPO) {
757 #define OPTION(NAME, TYPE, WIDTH, PREVIOUS) \
758 if (FPO.has##NAME##Override()) \
759 OS << " " #NAME "=" << FPO.get##NAME##Override();
760 #include "clang/Basic/FPOptions.def"
763 void TextNodeDumper::visitTextComment(const comments::TextComment *C,
764 const comments::FullComment *) {
765 OS << " Text=\"" << C->getText() << "\"";
768 void TextNodeDumper::visitInlineCommandComment(
769 const comments::InlineCommandComment *C, const comments::FullComment *) {
770 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\"";
771 switch (C->getRenderKind()) {
772 case comments::InlineCommandComment::RenderNormal:
773 OS << " RenderNormal";
774 break;
775 case comments::InlineCommandComment::RenderBold:
776 OS << " RenderBold";
777 break;
778 case comments::InlineCommandComment::RenderMonospaced:
779 OS << " RenderMonospaced";
780 break;
781 case comments::InlineCommandComment::RenderEmphasized:
782 OS << " RenderEmphasized";
783 break;
784 case comments::InlineCommandComment::RenderAnchor:
785 OS << " RenderAnchor";
786 break;
789 for (unsigned i = 0, e = C->getNumArgs(); i != e; ++i)
790 OS << " Arg[" << i << "]=\"" << C->getArgText(i) << "\"";
793 void TextNodeDumper::visitHTMLStartTagComment(
794 const comments::HTMLStartTagComment *C, const comments::FullComment *) {
795 OS << " Name=\"" << C->getTagName() << "\"";
796 if (C->getNumAttrs() != 0) {
797 OS << " Attrs: ";
798 for (unsigned i = 0, e = C->getNumAttrs(); i != e; ++i) {
799 const comments::HTMLStartTagComment::Attribute &Attr = C->getAttr(i);
800 OS << " \"" << Attr.Name << "=\"" << Attr.Value << "\"";
803 if (C->isSelfClosing())
804 OS << " SelfClosing";
807 void TextNodeDumper::visitHTMLEndTagComment(
808 const comments::HTMLEndTagComment *C, const comments::FullComment *) {
809 OS << " Name=\"" << C->getTagName() << "\"";
812 void TextNodeDumper::visitBlockCommandComment(
813 const comments::BlockCommandComment *C, const comments::FullComment *) {
814 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\"";
815 for (unsigned i = 0, e = C->getNumArgs(); i != e; ++i)
816 OS << " Arg[" << i << "]=\"" << C->getArgText(i) << "\"";
819 void TextNodeDumper::visitParamCommandComment(
820 const comments::ParamCommandComment *C, const comments::FullComment *FC) {
821 OS << " "
822 << comments::ParamCommandComment::getDirectionAsString(C->getDirection());
824 if (C->isDirectionExplicit())
825 OS << " explicitly";
826 else
827 OS << " implicitly";
829 if (C->hasParamName()) {
830 if (C->isParamIndexValid())
831 OS << " Param=\"" << C->getParamName(FC) << "\"";
832 else
833 OS << " Param=\"" << C->getParamNameAsWritten() << "\"";
836 if (C->isParamIndexValid() && !C->isVarArgParam())
837 OS << " ParamIndex=" << C->getParamIndex();
840 void TextNodeDumper::visitTParamCommandComment(
841 const comments::TParamCommandComment *C, const comments::FullComment *FC) {
842 if (C->hasParamName()) {
843 if (C->isPositionValid())
844 OS << " Param=\"" << C->getParamName(FC) << "\"";
845 else
846 OS << " Param=\"" << C->getParamNameAsWritten() << "\"";
849 if (C->isPositionValid()) {
850 OS << " Position=<";
851 for (unsigned i = 0, e = C->getDepth(); i != e; ++i) {
852 OS << C->getIndex(i);
853 if (i != e - 1)
854 OS << ", ";
856 OS << ">";
860 void TextNodeDumper::visitVerbatimBlockComment(
861 const comments::VerbatimBlockComment *C, const comments::FullComment *) {
862 OS << " Name=\"" << getCommandName(C->getCommandID())
863 << "\""
864 " CloseName=\""
865 << C->getCloseName() << "\"";
868 void TextNodeDumper::visitVerbatimBlockLineComment(
869 const comments::VerbatimBlockLineComment *C,
870 const comments::FullComment *) {
871 OS << " Text=\"" << C->getText() << "\"";
874 void TextNodeDumper::visitVerbatimLineComment(
875 const comments::VerbatimLineComment *C, const comments::FullComment *) {
876 OS << " Text=\"" << C->getText() << "\"";
879 void TextNodeDumper::VisitNullTemplateArgument(const TemplateArgument &) {
880 OS << " null";
883 void TextNodeDumper::VisitTypeTemplateArgument(const TemplateArgument &TA) {
884 OS << " type";
885 dumpType(TA.getAsType());
888 void TextNodeDumper::VisitDeclarationTemplateArgument(
889 const TemplateArgument &TA) {
890 OS << " decl";
891 dumpDeclRef(TA.getAsDecl());
894 void TextNodeDumper::VisitNullPtrTemplateArgument(const TemplateArgument &) {
895 OS << " nullptr";
898 void TextNodeDumper::VisitIntegralTemplateArgument(const TemplateArgument &TA) {
899 OS << " integral " << TA.getAsIntegral();
902 void TextNodeDumper::VisitTemplateTemplateArgument(const TemplateArgument &TA) {
903 if (TA.getAsTemplate().getKind() == TemplateName::UsingTemplate)
904 OS << " using";
905 OS << " template ";
906 TA.getAsTemplate().dump(OS);
909 void TextNodeDumper::VisitTemplateExpansionTemplateArgument(
910 const TemplateArgument &TA) {
911 if (TA.getAsTemplateOrTemplatePattern().getKind() ==
912 TemplateName::UsingTemplate)
913 OS << " using";
914 OS << " template expansion ";
915 TA.getAsTemplateOrTemplatePattern().dump(OS);
918 void TextNodeDumper::VisitExpressionTemplateArgument(const TemplateArgument &) {
919 OS << " expr";
922 void TextNodeDumper::VisitPackTemplateArgument(const TemplateArgument &) {
923 OS << " pack";
926 static void dumpBasePath(raw_ostream &OS, const CastExpr *Node) {
927 if (Node->path_empty())
928 return;
930 OS << " (";
931 bool First = true;
932 for (CastExpr::path_const_iterator I = Node->path_begin(),
933 E = Node->path_end();
934 I != E; ++I) {
935 const CXXBaseSpecifier *Base = *I;
936 if (!First)
937 OS << " -> ";
939 const auto *RD =
940 cast<CXXRecordDecl>(Base->getType()->castAs<RecordType>()->getDecl());
942 if (Base->isVirtual())
943 OS << "virtual ";
944 OS << RD->getName();
945 First = false;
948 OS << ')';
951 void TextNodeDumper::VisitIfStmt(const IfStmt *Node) {
952 if (Node->hasInitStorage())
953 OS << " has_init";
954 if (Node->hasVarStorage())
955 OS << " has_var";
956 if (Node->hasElseStorage())
957 OS << " has_else";
958 if (Node->isConstexpr())
959 OS << " constexpr";
960 if (Node->isConsteval()) {
961 OS << " ";
962 if (Node->isNegatedConsteval())
963 OS << "!";
964 OS << "consteval";
968 void TextNodeDumper::VisitSwitchStmt(const SwitchStmt *Node) {
969 if (Node->hasInitStorage())
970 OS << " has_init";
971 if (Node->hasVarStorage())
972 OS << " has_var";
975 void TextNodeDumper::VisitWhileStmt(const WhileStmt *Node) {
976 if (Node->hasVarStorage())
977 OS << " has_var";
980 void TextNodeDumper::VisitLabelStmt(const LabelStmt *Node) {
981 OS << " '" << Node->getName() << "'";
982 if (Node->isSideEntry())
983 OS << " side_entry";
986 void TextNodeDumper::VisitGotoStmt(const GotoStmt *Node) {
987 OS << " '" << Node->getLabel()->getName() << "'";
988 dumpPointer(Node->getLabel());
991 void TextNodeDumper::VisitCaseStmt(const CaseStmt *Node) {
992 if (Node->caseStmtIsGNURange())
993 OS << " gnu_range";
996 void TextNodeDumper::VisitConstantExpr(const ConstantExpr *Node) {
997 if (Node->hasAPValueResult())
998 AddChild("value",
999 [=] { Visit(Node->getAPValueResult(), Node->getType()); });
1002 void TextNodeDumper::VisitCallExpr(const CallExpr *Node) {
1003 if (Node->usesADL())
1004 OS << " adl";
1005 if (Node->hasStoredFPFeatures())
1006 printFPOptions(Node->getFPFeatures());
1009 void TextNodeDumper::VisitCXXOperatorCallExpr(const CXXOperatorCallExpr *Node) {
1010 const char *OperatorSpelling = clang::getOperatorSpelling(Node->getOperator());
1011 if (OperatorSpelling)
1012 OS << " '" << OperatorSpelling << "'";
1014 VisitCallExpr(Node);
1017 void TextNodeDumper::VisitCastExpr(const CastExpr *Node) {
1018 OS << " <";
1020 ColorScope Color(OS, ShowColors, CastColor);
1021 OS << Node->getCastKindName();
1023 dumpBasePath(OS, Node);
1024 OS << ">";
1025 if (Node->hasStoredFPFeatures())
1026 printFPOptions(Node->getFPFeatures());
1029 void TextNodeDumper::VisitImplicitCastExpr(const ImplicitCastExpr *Node) {
1030 VisitCastExpr(Node);
1031 if (Node->isPartOfExplicitCast())
1032 OS << " part_of_explicit_cast";
1035 void TextNodeDumper::VisitDeclRefExpr(const DeclRefExpr *Node) {
1036 OS << " ";
1037 dumpBareDeclRef(Node->getDecl());
1038 if (Node->getDecl() != Node->getFoundDecl()) {
1039 OS << " (";
1040 dumpBareDeclRef(Node->getFoundDecl());
1041 OS << ")";
1043 switch (Node->isNonOdrUse()) {
1044 case NOUR_None: break;
1045 case NOUR_Unevaluated: OS << " non_odr_use_unevaluated"; break;
1046 case NOUR_Constant: OS << " non_odr_use_constant"; break;
1047 case NOUR_Discarded: OS << " non_odr_use_discarded"; break;
1051 void TextNodeDumper::VisitUnresolvedLookupExpr(
1052 const UnresolvedLookupExpr *Node) {
1053 OS << " (";
1054 if (!Node->requiresADL())
1055 OS << "no ";
1056 OS << "ADL) = '" << Node->getName() << '\'';
1058 UnresolvedLookupExpr::decls_iterator I = Node->decls_begin(),
1059 E = Node->decls_end();
1060 if (I == E)
1061 OS << " empty";
1062 for (; I != E; ++I)
1063 dumpPointer(*I);
1066 void TextNodeDumper::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *Node) {
1068 ColorScope Color(OS, ShowColors, DeclKindNameColor);
1069 OS << " " << Node->getDecl()->getDeclKindName() << "Decl";
1071 OS << "='" << *Node->getDecl() << "'";
1072 dumpPointer(Node->getDecl());
1073 if (Node->isFreeIvar())
1074 OS << " isFreeIvar";
1077 void TextNodeDumper::VisitSYCLUniqueStableNameExpr(
1078 const SYCLUniqueStableNameExpr *Node) {
1079 dumpType(Node->getTypeSourceInfo()->getType());
1082 void TextNodeDumper::VisitPredefinedExpr(const PredefinedExpr *Node) {
1083 OS << " " << PredefinedExpr::getIdentKindName(Node->getIdentKind());
1086 void TextNodeDumper::VisitCharacterLiteral(const CharacterLiteral *Node) {
1087 ColorScope Color(OS, ShowColors, ValueColor);
1088 OS << " " << Node->getValue();
1091 void TextNodeDumper::VisitIntegerLiteral(const IntegerLiteral *Node) {
1092 bool isSigned = Node->getType()->isSignedIntegerType();
1093 ColorScope Color(OS, ShowColors, ValueColor);
1094 OS << " " << toString(Node->getValue(), 10, isSigned);
1097 void TextNodeDumper::VisitFixedPointLiteral(const FixedPointLiteral *Node) {
1098 ColorScope Color(OS, ShowColors, ValueColor);
1099 OS << " " << Node->getValueAsString(/*Radix=*/10);
1102 void TextNodeDumper::VisitFloatingLiteral(const FloatingLiteral *Node) {
1103 ColorScope Color(OS, ShowColors, ValueColor);
1104 OS << " " << Node->getValueAsApproximateDouble();
1107 void TextNodeDumper::VisitStringLiteral(const StringLiteral *Str) {
1108 ColorScope Color(OS, ShowColors, ValueColor);
1109 OS << " ";
1110 Str->outputString(OS);
1113 void TextNodeDumper::VisitInitListExpr(const InitListExpr *ILE) {
1114 if (auto *Field = ILE->getInitializedFieldInUnion()) {
1115 OS << " field ";
1116 dumpBareDeclRef(Field);
1120 void TextNodeDumper::VisitGenericSelectionExpr(const GenericSelectionExpr *E) {
1121 if (E->isResultDependent())
1122 OS << " result_dependent";
1125 void TextNodeDumper::VisitUnaryOperator(const UnaryOperator *Node) {
1126 OS << " " << (Node->isPostfix() ? "postfix" : "prefix") << " '"
1127 << UnaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
1128 if (!Node->canOverflow())
1129 OS << " cannot overflow";
1130 if (Node->hasStoredFPFeatures())
1131 printFPOptions(Node->getStoredFPFeatures());
1134 void TextNodeDumper::VisitUnaryExprOrTypeTraitExpr(
1135 const UnaryExprOrTypeTraitExpr *Node) {
1136 OS << " " << getTraitSpelling(Node->getKind());
1138 if (Node->isArgumentType())
1139 dumpType(Node->getArgumentType());
1142 void TextNodeDumper::VisitMemberExpr(const MemberExpr *Node) {
1143 OS << " " << (Node->isArrow() ? "->" : ".") << *Node->getMemberDecl();
1144 dumpPointer(Node->getMemberDecl());
1145 switch (Node->isNonOdrUse()) {
1146 case NOUR_None: break;
1147 case NOUR_Unevaluated: OS << " non_odr_use_unevaluated"; break;
1148 case NOUR_Constant: OS << " non_odr_use_constant"; break;
1149 case NOUR_Discarded: OS << " non_odr_use_discarded"; break;
1153 void TextNodeDumper::VisitExtVectorElementExpr(
1154 const ExtVectorElementExpr *Node) {
1155 OS << " " << Node->getAccessor().getNameStart();
1158 void TextNodeDumper::VisitBinaryOperator(const BinaryOperator *Node) {
1159 OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
1160 if (Node->hasStoredFPFeatures())
1161 printFPOptions(Node->getStoredFPFeatures());
1164 void TextNodeDumper::VisitCompoundAssignOperator(
1165 const CompoundAssignOperator *Node) {
1166 OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode())
1167 << "' ComputeLHSTy=";
1168 dumpBareType(Node->getComputationLHSType());
1169 OS << " ComputeResultTy=";
1170 dumpBareType(Node->getComputationResultType());
1171 if (Node->hasStoredFPFeatures())
1172 printFPOptions(Node->getStoredFPFeatures());
1175 void TextNodeDumper::VisitAddrLabelExpr(const AddrLabelExpr *Node) {
1176 OS << " " << Node->getLabel()->getName();
1177 dumpPointer(Node->getLabel());
1180 void TextNodeDumper::VisitCXXNamedCastExpr(const CXXNamedCastExpr *Node) {
1181 OS << " " << Node->getCastName() << "<"
1182 << Node->getTypeAsWritten().getAsString() << ">"
1183 << " <" << Node->getCastKindName();
1184 dumpBasePath(OS, Node);
1185 OS << ">";
1188 void TextNodeDumper::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *Node) {
1189 OS << " " << (Node->getValue() ? "true" : "false");
1192 void TextNodeDumper::VisitCXXThisExpr(const CXXThisExpr *Node) {
1193 if (Node->isImplicit())
1194 OS << " implicit";
1195 OS << " this";
1198 void TextNodeDumper::VisitCXXFunctionalCastExpr(
1199 const CXXFunctionalCastExpr *Node) {
1200 OS << " functional cast to " << Node->getTypeAsWritten().getAsString() << " <"
1201 << Node->getCastKindName() << ">";
1202 if (Node->hasStoredFPFeatures())
1203 printFPOptions(Node->getFPFeatures());
1206 void TextNodeDumper::VisitCXXStaticCastExpr(const CXXStaticCastExpr *Node) {
1207 VisitCXXNamedCastExpr(Node);
1208 if (Node->hasStoredFPFeatures())
1209 printFPOptions(Node->getFPFeatures());
1212 void TextNodeDumper::VisitCXXUnresolvedConstructExpr(
1213 const CXXUnresolvedConstructExpr *Node) {
1214 dumpType(Node->getTypeAsWritten());
1215 if (Node->isListInitialization())
1216 OS << " list";
1219 void TextNodeDumper::VisitCXXConstructExpr(const CXXConstructExpr *Node) {
1220 CXXConstructorDecl *Ctor = Node->getConstructor();
1221 dumpType(Ctor->getType());
1222 if (Node->isElidable())
1223 OS << " elidable";
1224 if (Node->isListInitialization())
1225 OS << " list";
1226 if (Node->isStdInitListInitialization())
1227 OS << " std::initializer_list";
1228 if (Node->requiresZeroInitialization())
1229 OS << " zeroing";
1232 void TextNodeDumper::VisitCXXBindTemporaryExpr(
1233 const CXXBindTemporaryExpr *Node) {
1234 OS << " (CXXTemporary";
1235 dumpPointer(Node);
1236 OS << ")";
1239 void TextNodeDumper::VisitCXXNewExpr(const CXXNewExpr *Node) {
1240 if (Node->isGlobalNew())
1241 OS << " global";
1242 if (Node->isArray())
1243 OS << " array";
1244 if (Node->getOperatorNew()) {
1245 OS << ' ';
1246 dumpBareDeclRef(Node->getOperatorNew());
1248 // We could dump the deallocation function used in case of error, but it's
1249 // usually not that interesting.
1252 void TextNodeDumper::VisitCXXDeleteExpr(const CXXDeleteExpr *Node) {
1253 if (Node->isGlobalDelete())
1254 OS << " global";
1255 if (Node->isArrayForm())
1256 OS << " array";
1257 if (Node->getOperatorDelete()) {
1258 OS << ' ';
1259 dumpBareDeclRef(Node->getOperatorDelete());
1263 void TextNodeDumper::VisitTypeTraitExpr(const TypeTraitExpr *Node) {
1264 OS << " " << getTraitSpelling(Node->getTrait());
1267 void TextNodeDumper::VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr *Node) {
1268 OS << " " << getTraitSpelling(Node->getTrait());
1271 void TextNodeDumper::VisitExpressionTraitExpr(const ExpressionTraitExpr *Node) {
1272 OS << " " << getTraitSpelling(Node->getTrait());
1275 void TextNodeDumper::VisitMaterializeTemporaryExpr(
1276 const MaterializeTemporaryExpr *Node) {
1277 if (const ValueDecl *VD = Node->getExtendingDecl()) {
1278 OS << " extended by ";
1279 dumpBareDeclRef(VD);
1283 void TextNodeDumper::VisitExprWithCleanups(const ExprWithCleanups *Node) {
1284 for (unsigned i = 0, e = Node->getNumObjects(); i != e; ++i)
1285 dumpCleanupObject(Node->getObject(i));
1288 void TextNodeDumper::VisitSizeOfPackExpr(const SizeOfPackExpr *Node) {
1289 dumpPointer(Node->getPack());
1290 dumpName(Node->getPack());
1293 void TextNodeDumper::VisitCXXDependentScopeMemberExpr(
1294 const CXXDependentScopeMemberExpr *Node) {
1295 OS << " " << (Node->isArrow() ? "->" : ".") << Node->getMember();
1298 void TextNodeDumper::VisitObjCMessageExpr(const ObjCMessageExpr *Node) {
1299 OS << " selector=";
1300 Node->getSelector().print(OS);
1301 switch (Node->getReceiverKind()) {
1302 case ObjCMessageExpr::Instance:
1303 break;
1305 case ObjCMessageExpr::Class:
1306 OS << " class=";
1307 dumpBareType(Node->getClassReceiver());
1308 break;
1310 case ObjCMessageExpr::SuperInstance:
1311 OS << " super (instance)";
1312 break;
1314 case ObjCMessageExpr::SuperClass:
1315 OS << " super (class)";
1316 break;
1320 void TextNodeDumper::VisitObjCBoxedExpr(const ObjCBoxedExpr *Node) {
1321 if (auto *BoxingMethod = Node->getBoxingMethod()) {
1322 OS << " selector=";
1323 BoxingMethod->getSelector().print(OS);
1327 void TextNodeDumper::VisitObjCAtCatchStmt(const ObjCAtCatchStmt *Node) {
1328 if (!Node->getCatchParamDecl())
1329 OS << " catch all";
1332 void TextNodeDumper::VisitObjCEncodeExpr(const ObjCEncodeExpr *Node) {
1333 dumpType(Node->getEncodedType());
1336 void TextNodeDumper::VisitObjCSelectorExpr(const ObjCSelectorExpr *Node) {
1337 OS << " ";
1338 Node->getSelector().print(OS);
1341 void TextNodeDumper::VisitObjCProtocolExpr(const ObjCProtocolExpr *Node) {
1342 OS << ' ' << *Node->getProtocol();
1345 void TextNodeDumper::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *Node) {
1346 if (Node->isImplicitProperty()) {
1347 OS << " Kind=MethodRef Getter=\"";
1348 if (Node->getImplicitPropertyGetter())
1349 Node->getImplicitPropertyGetter()->getSelector().print(OS);
1350 else
1351 OS << "(null)";
1353 OS << "\" Setter=\"";
1354 if (ObjCMethodDecl *Setter = Node->getImplicitPropertySetter())
1355 Setter->getSelector().print(OS);
1356 else
1357 OS << "(null)";
1358 OS << "\"";
1359 } else {
1360 OS << " Kind=PropertyRef Property=\"" << *Node->getExplicitProperty()
1361 << '"';
1364 if (Node->isSuperReceiver())
1365 OS << " super";
1367 OS << " Messaging=";
1368 if (Node->isMessagingGetter() && Node->isMessagingSetter())
1369 OS << "Getter&Setter";
1370 else if (Node->isMessagingGetter())
1371 OS << "Getter";
1372 else if (Node->isMessagingSetter())
1373 OS << "Setter";
1376 void TextNodeDumper::VisitObjCSubscriptRefExpr(
1377 const ObjCSubscriptRefExpr *Node) {
1378 if (Node->isArraySubscriptRefExpr())
1379 OS << " Kind=ArraySubscript GetterForArray=\"";
1380 else
1381 OS << " Kind=DictionarySubscript GetterForDictionary=\"";
1382 if (Node->getAtIndexMethodDecl())
1383 Node->getAtIndexMethodDecl()->getSelector().print(OS);
1384 else
1385 OS << "(null)";
1387 if (Node->isArraySubscriptRefExpr())
1388 OS << "\" SetterForArray=\"";
1389 else
1390 OS << "\" SetterForDictionary=\"";
1391 if (Node->setAtIndexMethodDecl())
1392 Node->setAtIndexMethodDecl()->getSelector().print(OS);
1393 else
1394 OS << "(null)";
1397 void TextNodeDumper::VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *Node) {
1398 OS << " " << (Node->getValue() ? "__objc_yes" : "__objc_no");
1401 void TextNodeDumper::VisitOMPIteratorExpr(const OMPIteratorExpr *Node) {
1402 OS << " ";
1403 for (unsigned I = 0, E = Node->numOfIterators(); I < E; ++I) {
1404 Visit(Node->getIteratorDecl(I));
1405 OS << " = ";
1406 const OMPIteratorExpr::IteratorRange Range = Node->getIteratorRange(I);
1407 OS << " begin ";
1408 Visit(Range.Begin);
1409 OS << " end ";
1410 Visit(Range.End);
1411 if (Range.Step) {
1412 OS << " step ";
1413 Visit(Range.Step);
1418 void TextNodeDumper::VisitConceptSpecializationExpr(
1419 const ConceptSpecializationExpr *Node) {
1420 OS << " ";
1421 dumpBareDeclRef(Node->getFoundDecl());
1424 void TextNodeDumper::VisitRequiresExpr(
1425 const RequiresExpr *Node) {
1426 if (!Node->isValueDependent())
1427 OS << (Node->isSatisfied() ? " satisfied" : " unsatisfied");
1430 void TextNodeDumper::VisitRValueReferenceType(const ReferenceType *T) {
1431 if (T->isSpelledAsLValue())
1432 OS << " written as lvalue reference";
1435 void TextNodeDumper::VisitArrayType(const ArrayType *T) {
1436 switch (T->getSizeModifier()) {
1437 case ArrayType::Normal:
1438 break;
1439 case ArrayType::Static:
1440 OS << " static";
1441 break;
1442 case ArrayType::Star:
1443 OS << " *";
1444 break;
1446 OS << " " << T->getIndexTypeQualifiers().getAsString();
1449 void TextNodeDumper::VisitConstantArrayType(const ConstantArrayType *T) {
1450 OS << " " << T->getSize();
1451 VisitArrayType(T);
1454 void TextNodeDumper::VisitVariableArrayType(const VariableArrayType *T) {
1455 OS << " ";
1456 dumpSourceRange(T->getBracketsRange());
1457 VisitArrayType(T);
1460 void TextNodeDumper::VisitDependentSizedArrayType(
1461 const DependentSizedArrayType *T) {
1462 VisitArrayType(T);
1463 OS << " ";
1464 dumpSourceRange(T->getBracketsRange());
1467 void TextNodeDumper::VisitDependentSizedExtVectorType(
1468 const DependentSizedExtVectorType *T) {
1469 OS << " ";
1470 dumpLocation(T->getAttributeLoc());
1473 void TextNodeDumper::VisitVectorType(const VectorType *T) {
1474 switch (T->getVectorKind()) {
1475 case VectorType::GenericVector:
1476 break;
1477 case VectorType::AltiVecVector:
1478 OS << " altivec";
1479 break;
1480 case VectorType::AltiVecPixel:
1481 OS << " altivec pixel";
1482 break;
1483 case VectorType::AltiVecBool:
1484 OS << " altivec bool";
1485 break;
1486 case VectorType::NeonVector:
1487 OS << " neon";
1488 break;
1489 case VectorType::NeonPolyVector:
1490 OS << " neon poly";
1491 break;
1492 case VectorType::SveFixedLengthDataVector:
1493 OS << " fixed-length sve data vector";
1494 break;
1495 case VectorType::SveFixedLengthPredicateVector:
1496 OS << " fixed-length sve predicate vector";
1497 break;
1499 OS << " " << T->getNumElements();
1502 void TextNodeDumper::VisitFunctionType(const FunctionType *T) {
1503 auto EI = T->getExtInfo();
1504 if (EI.getNoReturn())
1505 OS << " noreturn";
1506 if (EI.getProducesResult())
1507 OS << " produces_result";
1508 if (EI.getHasRegParm())
1509 OS << " regparm " << EI.getRegParm();
1510 OS << " " << FunctionType::getNameForCallConv(EI.getCC());
1513 void TextNodeDumper::VisitFunctionProtoType(const FunctionProtoType *T) {
1514 auto EPI = T->getExtProtoInfo();
1515 if (EPI.HasTrailingReturn)
1516 OS << " trailing_return";
1517 if (T->isConst())
1518 OS << " const";
1519 if (T->isVolatile())
1520 OS << " volatile";
1521 if (T->isRestrict())
1522 OS << " restrict";
1523 if (T->getExtProtoInfo().Variadic)
1524 OS << " variadic";
1525 switch (EPI.RefQualifier) {
1526 case RQ_None:
1527 break;
1528 case RQ_LValue:
1529 OS << " &";
1530 break;
1531 case RQ_RValue:
1532 OS << " &&";
1533 break;
1535 // FIXME: Exception specification.
1536 // FIXME: Consumed parameters.
1537 VisitFunctionType(T);
1540 void TextNodeDumper::VisitUnresolvedUsingType(const UnresolvedUsingType *T) {
1541 dumpDeclRef(T->getDecl());
1544 void TextNodeDumper::VisitUsingType(const UsingType *T) {
1545 dumpDeclRef(T->getFoundDecl());
1546 if (!T->typeMatchesDecl())
1547 OS << " divergent";
1550 void TextNodeDumper::VisitTypedefType(const TypedefType *T) {
1551 dumpDeclRef(T->getDecl());
1552 if (!T->typeMatchesDecl())
1553 OS << " divergent";
1556 void TextNodeDumper::VisitUnaryTransformType(const UnaryTransformType *T) {
1557 switch (T->getUTTKind()) {
1558 #define TRANSFORM_TYPE_TRAIT_DEF(Enum, Trait) \
1559 case UnaryTransformType::Enum: \
1560 OS << " " #Trait; \
1561 break;
1562 #include "clang/Basic/TransformTypeTraits.def"
1566 void TextNodeDumper::VisitTagType(const TagType *T) {
1567 dumpDeclRef(T->getDecl());
1570 void TextNodeDumper::VisitTemplateTypeParmType(const TemplateTypeParmType *T) {
1571 OS << " depth " << T->getDepth() << " index " << T->getIndex();
1572 if (T->isParameterPack())
1573 OS << " pack";
1574 dumpDeclRef(T->getDecl());
1577 void TextNodeDumper::VisitSubstTemplateTypeParmType(
1578 const SubstTemplateTypeParmType *T) {
1579 dumpDeclRef(T->getAssociatedDecl());
1580 VisitTemplateTypeParmDecl(T->getReplacedParameter());
1581 if (auto PackIndex = T->getPackIndex())
1582 OS << " pack_index " << *PackIndex;
1585 void TextNodeDumper::VisitSubstTemplateTypeParmPackType(
1586 const SubstTemplateTypeParmPackType *T) {
1587 dumpDeclRef(T->getAssociatedDecl());
1588 VisitTemplateTypeParmDecl(T->getReplacedParameter());
1591 void TextNodeDumper::VisitAutoType(const AutoType *T) {
1592 if (T->isDecltypeAuto())
1593 OS << " decltype(auto)";
1594 if (!T->isDeduced())
1595 OS << " undeduced";
1596 if (T->isConstrained()) {
1597 dumpDeclRef(T->getTypeConstraintConcept());
1598 for (const auto &Arg : T->getTypeConstraintArguments())
1599 VisitTemplateArgument(Arg);
1603 void TextNodeDumper::VisitDeducedTemplateSpecializationType(
1604 const DeducedTemplateSpecializationType *T) {
1605 if (T->getTemplateName().getKind() == TemplateName::UsingTemplate)
1606 OS << " using";
1609 void TextNodeDumper::VisitTemplateSpecializationType(
1610 const TemplateSpecializationType *T) {
1611 if (T->isTypeAlias())
1612 OS << " alias";
1613 if (T->getTemplateName().getKind() == TemplateName::UsingTemplate)
1614 OS << " using";
1615 OS << " ";
1616 T->getTemplateName().dump(OS);
1619 void TextNodeDumper::VisitInjectedClassNameType(
1620 const InjectedClassNameType *T) {
1621 dumpDeclRef(T->getDecl());
1624 void TextNodeDumper::VisitObjCInterfaceType(const ObjCInterfaceType *T) {
1625 dumpDeclRef(T->getDecl());
1628 void TextNodeDumper::VisitPackExpansionType(const PackExpansionType *T) {
1629 if (auto N = T->getNumExpansions())
1630 OS << " expansions " << *N;
1633 void TextNodeDumper::VisitLabelDecl(const LabelDecl *D) { dumpName(D); }
1635 void TextNodeDumper::VisitTypedefDecl(const TypedefDecl *D) {
1636 dumpName(D);
1637 dumpType(D->getUnderlyingType());
1638 if (D->isModulePrivate())
1639 OS << " __module_private__";
1642 void TextNodeDumper::VisitEnumDecl(const EnumDecl *D) {
1643 if (D->isScoped()) {
1644 if (D->isScopedUsingClassTag())
1645 OS << " class";
1646 else
1647 OS << " struct";
1649 dumpName(D);
1650 if (D->isModulePrivate())
1651 OS << " __module_private__";
1652 if (D->isFixed())
1653 dumpType(D->getIntegerType());
1656 void TextNodeDumper::VisitRecordDecl(const RecordDecl *D) {
1657 OS << ' ' << D->getKindName();
1658 dumpName(D);
1659 if (D->isModulePrivate())
1660 OS << " __module_private__";
1661 if (D->isCompleteDefinition())
1662 OS << " definition";
1665 void TextNodeDumper::VisitEnumConstantDecl(const EnumConstantDecl *D) {
1666 dumpName(D);
1667 dumpType(D->getType());
1670 void TextNodeDumper::VisitIndirectFieldDecl(const IndirectFieldDecl *D) {
1671 dumpName(D);
1672 dumpType(D->getType());
1674 for (const auto *Child : D->chain())
1675 dumpDeclRef(Child);
1678 void TextNodeDumper::VisitFunctionDecl(const FunctionDecl *D) {
1679 dumpName(D);
1680 dumpType(D->getType());
1682 StorageClass SC = D->getStorageClass();
1683 if (SC != SC_None)
1684 OS << ' ' << VarDecl::getStorageClassSpecifierString(SC);
1685 if (D->isInlineSpecified())
1686 OS << " inline";
1687 if (D->isVirtualAsWritten())
1688 OS << " virtual";
1689 if (D->isModulePrivate())
1690 OS << " __module_private__";
1692 if (D->isPure())
1693 OS << " pure";
1694 if (D->isDefaulted()) {
1695 OS << " default";
1696 if (D->isDeleted())
1697 OS << "_delete";
1699 if (D->isDeletedAsWritten())
1700 OS << " delete";
1701 if (D->isTrivial())
1702 OS << " trivial";
1704 if (D->isIneligibleOrNotSelected())
1705 OS << (isa<CXXDestructorDecl>(D) ? " not_selected" : " ineligible");
1707 if (const auto *FPT = D->getType()->getAs<FunctionProtoType>()) {
1708 FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo();
1709 switch (EPI.ExceptionSpec.Type) {
1710 default:
1711 break;
1712 case EST_Unevaluated:
1713 OS << " noexcept-unevaluated " << EPI.ExceptionSpec.SourceDecl;
1714 break;
1715 case EST_Uninstantiated:
1716 OS << " noexcept-uninstantiated " << EPI.ExceptionSpec.SourceTemplate;
1717 break;
1721 if (const auto *MD = dyn_cast<CXXMethodDecl>(D)) {
1722 if (MD->size_overridden_methods() != 0) {
1723 auto dumpOverride = [=](const CXXMethodDecl *D) {
1724 SplitQualType T_split = D->getType().split();
1725 OS << D << " " << D->getParent()->getName() << "::" << D->getDeclName()
1726 << " '" << QualType::getAsString(T_split, PrintPolicy) << "'";
1729 AddChild([=] {
1730 auto Overrides = MD->overridden_methods();
1731 OS << "Overrides: [ ";
1732 dumpOverride(*Overrides.begin());
1733 for (const auto *Override :
1734 llvm::make_range(Overrides.begin() + 1, Overrides.end())) {
1735 OS << ", ";
1736 dumpOverride(Override);
1738 OS << " ]";
1743 if (!D->isInlineSpecified() && D->isInlined()) {
1744 OS << " implicit-inline";
1746 // Since NumParams comes from the FunctionProtoType of the FunctionDecl and
1747 // the Params are set later, it is possible for a dump during debugging to
1748 // encounter a FunctionDecl that has been created but hasn't been assigned
1749 // ParmVarDecls yet.
1750 if (!D->param_empty() && !D->param_begin())
1751 OS << " <<<NULL params x " << D->getNumParams() << ">>>";
1754 void TextNodeDumper::VisitLifetimeExtendedTemporaryDecl(
1755 const LifetimeExtendedTemporaryDecl *D) {
1756 OS << " extended by ";
1757 dumpBareDeclRef(D->getExtendingDecl());
1758 OS << " mangling ";
1760 ColorScope Color(OS, ShowColors, ValueColor);
1761 OS << D->getManglingNumber();
1765 void TextNodeDumper::VisitFieldDecl(const FieldDecl *D) {
1766 dumpName(D);
1767 dumpType(D->getType());
1768 if (D->isMutable())
1769 OS << " mutable";
1770 if (D->isModulePrivate())
1771 OS << " __module_private__";
1774 void TextNodeDumper::VisitVarDecl(const VarDecl *D) {
1775 dumpName(D);
1776 dumpType(D->getType());
1777 StorageClass SC = D->getStorageClass();
1778 if (SC != SC_None)
1779 OS << ' ' << VarDecl::getStorageClassSpecifierString(SC);
1780 switch (D->getTLSKind()) {
1781 case VarDecl::TLS_None:
1782 break;
1783 case VarDecl::TLS_Static:
1784 OS << " tls";
1785 break;
1786 case VarDecl::TLS_Dynamic:
1787 OS << " tls_dynamic";
1788 break;
1790 if (D->isModulePrivate())
1791 OS << " __module_private__";
1792 if (D->isNRVOVariable())
1793 OS << " nrvo";
1794 if (D->isInline())
1795 OS << " inline";
1796 if (D->isConstexpr())
1797 OS << " constexpr";
1798 if (D->hasInit()) {
1799 switch (D->getInitStyle()) {
1800 case VarDecl::CInit:
1801 OS << " cinit";
1802 break;
1803 case VarDecl::CallInit:
1804 OS << " callinit";
1805 break;
1806 case VarDecl::ListInit:
1807 OS << " listinit";
1808 break;
1811 if (D->needsDestruction(D->getASTContext()))
1812 OS << " destroyed";
1813 if (D->isParameterPack())
1814 OS << " pack";
1816 if (D->hasInit()) {
1817 const Expr *E = D->getInit();
1818 // Only dump the value of constexpr VarDecls for now.
1819 if (E && !E->isValueDependent() && D->isConstexpr()) {
1820 const APValue *Value = D->evaluateValue();
1821 if (Value)
1822 AddChild("value", [=] { Visit(*Value, E->getType()); });
1827 void TextNodeDumper::VisitBindingDecl(const BindingDecl *D) {
1828 dumpName(D);
1829 dumpType(D->getType());
1832 void TextNodeDumper::VisitCapturedDecl(const CapturedDecl *D) {
1833 if (D->isNothrow())
1834 OS << " nothrow";
1837 void TextNodeDumper::VisitImportDecl(const ImportDecl *D) {
1838 OS << ' ' << D->getImportedModule()->getFullModuleName();
1840 for (Decl *InitD :
1841 D->getASTContext().getModuleInitializers(D->getImportedModule()))
1842 dumpDeclRef(InitD, "initializer");
1845 void TextNodeDumper::VisitPragmaCommentDecl(const PragmaCommentDecl *D) {
1846 OS << ' ';
1847 switch (D->getCommentKind()) {
1848 case PCK_Unknown:
1849 llvm_unreachable("unexpected pragma comment kind");
1850 case PCK_Compiler:
1851 OS << "compiler";
1852 break;
1853 case PCK_ExeStr:
1854 OS << "exestr";
1855 break;
1856 case PCK_Lib:
1857 OS << "lib";
1858 break;
1859 case PCK_Linker:
1860 OS << "linker";
1861 break;
1862 case PCK_User:
1863 OS << "user";
1864 break;
1866 StringRef Arg = D->getArg();
1867 if (!Arg.empty())
1868 OS << " \"" << Arg << "\"";
1871 void TextNodeDumper::VisitPragmaDetectMismatchDecl(
1872 const PragmaDetectMismatchDecl *D) {
1873 OS << " \"" << D->getName() << "\" \"" << D->getValue() << "\"";
1876 void TextNodeDumper::VisitOMPExecutableDirective(
1877 const OMPExecutableDirective *D) {
1878 if (D->isStandaloneDirective())
1879 OS << " openmp_standalone_directive";
1882 void TextNodeDumper::VisitOMPDeclareReductionDecl(
1883 const OMPDeclareReductionDecl *D) {
1884 dumpName(D);
1885 dumpType(D->getType());
1886 OS << " combiner";
1887 dumpPointer(D->getCombiner());
1888 if (const auto *Initializer = D->getInitializer()) {
1889 OS << " initializer";
1890 dumpPointer(Initializer);
1891 switch (D->getInitializerKind()) {
1892 case OMPDeclareReductionDecl::DirectInit:
1893 OS << " omp_priv = ";
1894 break;
1895 case OMPDeclareReductionDecl::CopyInit:
1896 OS << " omp_priv ()";
1897 break;
1898 case OMPDeclareReductionDecl::CallInit:
1899 break;
1904 void TextNodeDumper::VisitOMPRequiresDecl(const OMPRequiresDecl *D) {
1905 for (const auto *C : D->clauselists()) {
1906 AddChild([=] {
1907 if (!C) {
1908 ColorScope Color(OS, ShowColors, NullColor);
1909 OS << "<<<NULL>>> OMPClause";
1910 return;
1913 ColorScope Color(OS, ShowColors, AttrColor);
1914 StringRef ClauseName(
1915 llvm::omp::getOpenMPClauseName(C->getClauseKind()));
1916 OS << "OMP" << ClauseName.substr(/*Start=*/0, /*N=*/1).upper()
1917 << ClauseName.drop_front() << "Clause";
1919 dumpPointer(C);
1920 dumpSourceRange(SourceRange(C->getBeginLoc(), C->getEndLoc()));
1925 void TextNodeDumper::VisitOMPCapturedExprDecl(const OMPCapturedExprDecl *D) {
1926 dumpName(D);
1927 dumpType(D->getType());
1930 void TextNodeDumper::VisitNamespaceDecl(const NamespaceDecl *D) {
1931 dumpName(D);
1932 if (D->isInline())
1933 OS << " inline";
1934 if (!D->isOriginalNamespace())
1935 dumpDeclRef(D->getOriginalNamespace(), "original");
1938 void TextNodeDumper::VisitUsingDirectiveDecl(const UsingDirectiveDecl *D) {
1939 OS << ' ';
1940 dumpBareDeclRef(D->getNominatedNamespace());
1943 void TextNodeDumper::VisitNamespaceAliasDecl(const NamespaceAliasDecl *D) {
1944 dumpName(D);
1945 dumpDeclRef(D->getAliasedNamespace());
1948 void TextNodeDumper::VisitTypeAliasDecl(const TypeAliasDecl *D) {
1949 dumpName(D);
1950 dumpType(D->getUnderlyingType());
1953 void TextNodeDumper::VisitTypeAliasTemplateDecl(
1954 const TypeAliasTemplateDecl *D) {
1955 dumpName(D);
1958 void TextNodeDumper::VisitCXXRecordDecl(const CXXRecordDecl *D) {
1959 VisitRecordDecl(D);
1960 if (!D->isCompleteDefinition())
1961 return;
1963 AddChild([=] {
1965 ColorScope Color(OS, ShowColors, DeclKindNameColor);
1966 OS << "DefinitionData";
1968 #define FLAG(fn, name) \
1969 if (D->fn()) \
1970 OS << " " #name;
1971 FLAG(isParsingBaseSpecifiers, parsing_base_specifiers);
1973 FLAG(isGenericLambda, generic);
1974 FLAG(isLambda, lambda);
1976 FLAG(isAnonymousStructOrUnion, is_anonymous);
1977 FLAG(canPassInRegisters, pass_in_registers);
1978 FLAG(isEmpty, empty);
1979 FLAG(isAggregate, aggregate);
1980 FLAG(isStandardLayout, standard_layout);
1981 FLAG(isTriviallyCopyable, trivially_copyable);
1982 FLAG(isPOD, pod);
1983 FLAG(isTrivial, trivial);
1984 FLAG(isPolymorphic, polymorphic);
1985 FLAG(isAbstract, abstract);
1986 FLAG(isLiteral, literal);
1988 FLAG(hasUserDeclaredConstructor, has_user_declared_ctor);
1989 FLAG(hasConstexprNonCopyMoveConstructor, has_constexpr_non_copy_move_ctor);
1990 FLAG(hasMutableFields, has_mutable_fields);
1991 FLAG(hasVariantMembers, has_variant_members);
1992 FLAG(allowConstDefaultInit, can_const_default_init);
1994 AddChild([=] {
1996 ColorScope Color(OS, ShowColors, DeclKindNameColor);
1997 OS << "DefaultConstructor";
1999 FLAG(hasDefaultConstructor, exists);
2000 FLAG(hasTrivialDefaultConstructor, trivial);
2001 FLAG(hasNonTrivialDefaultConstructor, non_trivial);
2002 FLAG(hasUserProvidedDefaultConstructor, user_provided);
2003 FLAG(hasConstexprDefaultConstructor, constexpr);
2004 FLAG(needsImplicitDefaultConstructor, needs_implicit);
2005 FLAG(defaultedDefaultConstructorIsConstexpr, defaulted_is_constexpr);
2008 AddChild([=] {
2010 ColorScope Color(OS, ShowColors, DeclKindNameColor);
2011 OS << "CopyConstructor";
2013 FLAG(hasSimpleCopyConstructor, simple);
2014 FLAG(hasTrivialCopyConstructor, trivial);
2015 FLAG(hasNonTrivialCopyConstructor, non_trivial);
2016 FLAG(hasUserDeclaredCopyConstructor, user_declared);
2017 FLAG(hasCopyConstructorWithConstParam, has_const_param);
2018 FLAG(needsImplicitCopyConstructor, needs_implicit);
2019 FLAG(needsOverloadResolutionForCopyConstructor,
2020 needs_overload_resolution);
2021 if (!D->needsOverloadResolutionForCopyConstructor())
2022 FLAG(defaultedCopyConstructorIsDeleted, defaulted_is_deleted);
2023 FLAG(implicitCopyConstructorHasConstParam, implicit_has_const_param);
2026 AddChild([=] {
2028 ColorScope Color(OS, ShowColors, DeclKindNameColor);
2029 OS << "MoveConstructor";
2031 FLAG(hasMoveConstructor, exists);
2032 FLAG(hasSimpleMoveConstructor, simple);
2033 FLAG(hasTrivialMoveConstructor, trivial);
2034 FLAG(hasNonTrivialMoveConstructor, non_trivial);
2035 FLAG(hasUserDeclaredMoveConstructor, user_declared);
2036 FLAG(needsImplicitMoveConstructor, needs_implicit);
2037 FLAG(needsOverloadResolutionForMoveConstructor,
2038 needs_overload_resolution);
2039 if (!D->needsOverloadResolutionForMoveConstructor())
2040 FLAG(defaultedMoveConstructorIsDeleted, defaulted_is_deleted);
2043 AddChild([=] {
2045 ColorScope Color(OS, ShowColors, DeclKindNameColor);
2046 OS << "CopyAssignment";
2048 FLAG(hasSimpleCopyAssignment, simple);
2049 FLAG(hasTrivialCopyAssignment, trivial);
2050 FLAG(hasNonTrivialCopyAssignment, non_trivial);
2051 FLAG(hasCopyAssignmentWithConstParam, has_const_param);
2052 FLAG(hasUserDeclaredCopyAssignment, user_declared);
2053 FLAG(needsImplicitCopyAssignment, needs_implicit);
2054 FLAG(needsOverloadResolutionForCopyAssignment, needs_overload_resolution);
2055 FLAG(implicitCopyAssignmentHasConstParam, implicit_has_const_param);
2058 AddChild([=] {
2060 ColorScope Color(OS, ShowColors, DeclKindNameColor);
2061 OS << "MoveAssignment";
2063 FLAG(hasMoveAssignment, exists);
2064 FLAG(hasSimpleMoveAssignment, simple);
2065 FLAG(hasTrivialMoveAssignment, trivial);
2066 FLAG(hasNonTrivialMoveAssignment, non_trivial);
2067 FLAG(hasUserDeclaredMoveAssignment, user_declared);
2068 FLAG(needsImplicitMoveAssignment, needs_implicit);
2069 FLAG(needsOverloadResolutionForMoveAssignment, needs_overload_resolution);
2072 AddChild([=] {
2074 ColorScope Color(OS, ShowColors, DeclKindNameColor);
2075 OS << "Destructor";
2077 FLAG(hasSimpleDestructor, simple);
2078 FLAG(hasIrrelevantDestructor, irrelevant);
2079 FLAG(hasTrivialDestructor, trivial);
2080 FLAG(hasNonTrivialDestructor, non_trivial);
2081 FLAG(hasUserDeclaredDestructor, user_declared);
2082 FLAG(hasConstexprDestructor, constexpr);
2083 FLAG(needsImplicitDestructor, needs_implicit);
2084 FLAG(needsOverloadResolutionForDestructor, needs_overload_resolution);
2085 if (!D->needsOverloadResolutionForDestructor())
2086 FLAG(defaultedDestructorIsDeleted, defaulted_is_deleted);
2090 for (const auto &I : D->bases()) {
2091 AddChild([=] {
2092 if (I.isVirtual())
2093 OS << "virtual ";
2094 dumpAccessSpecifier(I.getAccessSpecifier());
2095 dumpType(I.getType());
2096 if (I.isPackExpansion())
2097 OS << "...";
2102 void TextNodeDumper::VisitFunctionTemplateDecl(const FunctionTemplateDecl *D) {
2103 dumpName(D);
2106 void TextNodeDumper::VisitClassTemplateDecl(const ClassTemplateDecl *D) {
2107 dumpName(D);
2110 void TextNodeDumper::VisitVarTemplateDecl(const VarTemplateDecl *D) {
2111 dumpName(D);
2114 void TextNodeDumper::VisitBuiltinTemplateDecl(const BuiltinTemplateDecl *D) {
2115 dumpName(D);
2118 void TextNodeDumper::VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D) {
2119 if (const auto *TC = D->getTypeConstraint()) {
2120 OS << " ";
2121 dumpBareDeclRef(TC->getNamedConcept());
2122 if (TC->getNamedConcept() != TC->getFoundDecl()) {
2123 OS << " (";
2124 dumpBareDeclRef(TC->getFoundDecl());
2125 OS << ")";
2127 } else if (D->wasDeclaredWithTypename())
2128 OS << " typename";
2129 else
2130 OS << " class";
2131 OS << " depth " << D->getDepth() << " index " << D->getIndex();
2132 if (D->isParameterPack())
2133 OS << " ...";
2134 dumpName(D);
2137 void TextNodeDumper::VisitNonTypeTemplateParmDecl(
2138 const NonTypeTemplateParmDecl *D) {
2139 dumpType(D->getType());
2140 OS << " depth " << D->getDepth() << " index " << D->getIndex();
2141 if (D->isParameterPack())
2142 OS << " ...";
2143 dumpName(D);
2146 void TextNodeDumper::VisitTemplateTemplateParmDecl(
2147 const TemplateTemplateParmDecl *D) {
2148 OS << " depth " << D->getDepth() << " index " << D->getIndex();
2149 if (D->isParameterPack())
2150 OS << " ...";
2151 dumpName(D);
2154 void TextNodeDumper::VisitUsingDecl(const UsingDecl *D) {
2155 OS << ' ';
2156 if (D->getQualifier())
2157 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
2158 OS << D->getDeclName();
2161 void TextNodeDumper::VisitUsingEnumDecl(const UsingEnumDecl *D) {
2162 OS << ' ';
2163 dumpBareDeclRef(D->getEnumDecl());
2166 void TextNodeDumper::VisitUnresolvedUsingTypenameDecl(
2167 const UnresolvedUsingTypenameDecl *D) {
2168 OS << ' ';
2169 if (D->getQualifier())
2170 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
2171 OS << D->getDeclName();
2174 void TextNodeDumper::VisitUnresolvedUsingValueDecl(
2175 const UnresolvedUsingValueDecl *D) {
2176 OS << ' ';
2177 if (D->getQualifier())
2178 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
2179 OS << D->getDeclName();
2180 dumpType(D->getType());
2183 void TextNodeDumper::VisitUsingShadowDecl(const UsingShadowDecl *D) {
2184 OS << ' ';
2185 dumpBareDeclRef(D->getTargetDecl());
2188 void TextNodeDumper::VisitConstructorUsingShadowDecl(
2189 const ConstructorUsingShadowDecl *D) {
2190 if (D->constructsVirtualBase())
2191 OS << " virtual";
2193 AddChild([=] {
2194 OS << "target ";
2195 dumpBareDeclRef(D->getTargetDecl());
2198 AddChild([=] {
2199 OS << "nominated ";
2200 dumpBareDeclRef(D->getNominatedBaseClass());
2201 OS << ' ';
2202 dumpBareDeclRef(D->getNominatedBaseClassShadowDecl());
2205 AddChild([=] {
2206 OS << "constructed ";
2207 dumpBareDeclRef(D->getConstructedBaseClass());
2208 OS << ' ';
2209 dumpBareDeclRef(D->getConstructedBaseClassShadowDecl());
2213 void TextNodeDumper::VisitLinkageSpecDecl(const LinkageSpecDecl *D) {
2214 switch (D->getLanguage()) {
2215 case LinkageSpecDecl::lang_c:
2216 OS << " C";
2217 break;
2218 case LinkageSpecDecl::lang_cxx:
2219 OS << " C++";
2220 break;
2224 void TextNodeDumper::VisitAccessSpecDecl(const AccessSpecDecl *D) {
2225 OS << ' ';
2226 dumpAccessSpecifier(D->getAccess());
2229 void TextNodeDumper::VisitFriendDecl(const FriendDecl *D) {
2230 if (TypeSourceInfo *T = D->getFriendType())
2231 dumpType(T->getType());
2234 void TextNodeDumper::VisitObjCIvarDecl(const ObjCIvarDecl *D) {
2235 dumpName(D);
2236 dumpType(D->getType());
2237 if (D->getSynthesize())
2238 OS << " synthesize";
2240 switch (D->getAccessControl()) {
2241 case ObjCIvarDecl::None:
2242 OS << " none";
2243 break;
2244 case ObjCIvarDecl::Private:
2245 OS << " private";
2246 break;
2247 case ObjCIvarDecl::Protected:
2248 OS << " protected";
2249 break;
2250 case ObjCIvarDecl::Public:
2251 OS << " public";
2252 break;
2253 case ObjCIvarDecl::Package:
2254 OS << " package";
2255 break;
2259 void TextNodeDumper::VisitObjCMethodDecl(const ObjCMethodDecl *D) {
2260 if (D->isInstanceMethod())
2261 OS << " -";
2262 else
2263 OS << " +";
2264 dumpName(D);
2265 dumpType(D->getReturnType());
2267 if (D->isVariadic())
2268 OS << " variadic";
2271 void TextNodeDumper::VisitObjCTypeParamDecl(const ObjCTypeParamDecl *D) {
2272 dumpName(D);
2273 switch (D->getVariance()) {
2274 case ObjCTypeParamVariance::Invariant:
2275 break;
2277 case ObjCTypeParamVariance::Covariant:
2278 OS << " covariant";
2279 break;
2281 case ObjCTypeParamVariance::Contravariant:
2282 OS << " contravariant";
2283 break;
2286 if (D->hasExplicitBound())
2287 OS << " bounded";
2288 dumpType(D->getUnderlyingType());
2291 void TextNodeDumper::VisitObjCCategoryDecl(const ObjCCategoryDecl *D) {
2292 dumpName(D);
2293 dumpDeclRef(D->getClassInterface());
2294 dumpDeclRef(D->getImplementation());
2295 for (const auto *P : D->protocols())
2296 dumpDeclRef(P);
2299 void TextNodeDumper::VisitObjCCategoryImplDecl(const ObjCCategoryImplDecl *D) {
2300 dumpName(D);
2301 dumpDeclRef(D->getClassInterface());
2302 dumpDeclRef(D->getCategoryDecl());
2305 void TextNodeDumper::VisitObjCProtocolDecl(const ObjCProtocolDecl *D) {
2306 dumpName(D);
2308 for (const auto *Child : D->protocols())
2309 dumpDeclRef(Child);
2312 void TextNodeDumper::VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D) {
2313 dumpName(D);
2314 dumpDeclRef(D->getSuperClass(), "super");
2316 dumpDeclRef(D->getImplementation());
2317 for (const auto *Child : D->protocols())
2318 dumpDeclRef(Child);
2321 void TextNodeDumper::VisitObjCImplementationDecl(
2322 const ObjCImplementationDecl *D) {
2323 dumpName(D);
2324 dumpDeclRef(D->getSuperClass(), "super");
2325 dumpDeclRef(D->getClassInterface());
2328 void TextNodeDumper::VisitObjCCompatibleAliasDecl(
2329 const ObjCCompatibleAliasDecl *D) {
2330 dumpName(D);
2331 dumpDeclRef(D->getClassInterface());
2334 void TextNodeDumper::VisitObjCPropertyDecl(const ObjCPropertyDecl *D) {
2335 dumpName(D);
2336 dumpType(D->getType());
2338 if (D->getPropertyImplementation() == ObjCPropertyDecl::Required)
2339 OS << " required";
2340 else if (D->getPropertyImplementation() == ObjCPropertyDecl::Optional)
2341 OS << " optional";
2343 ObjCPropertyAttribute::Kind Attrs = D->getPropertyAttributes();
2344 if (Attrs != ObjCPropertyAttribute::kind_noattr) {
2345 if (Attrs & ObjCPropertyAttribute::kind_readonly)
2346 OS << " readonly";
2347 if (Attrs & ObjCPropertyAttribute::kind_assign)
2348 OS << " assign";
2349 if (Attrs & ObjCPropertyAttribute::kind_readwrite)
2350 OS << " readwrite";
2351 if (Attrs & ObjCPropertyAttribute::kind_retain)
2352 OS << " retain";
2353 if (Attrs & ObjCPropertyAttribute::kind_copy)
2354 OS << " copy";
2355 if (Attrs & ObjCPropertyAttribute::kind_nonatomic)
2356 OS << " nonatomic";
2357 if (Attrs & ObjCPropertyAttribute::kind_atomic)
2358 OS << " atomic";
2359 if (Attrs & ObjCPropertyAttribute::kind_weak)
2360 OS << " weak";
2361 if (Attrs & ObjCPropertyAttribute::kind_strong)
2362 OS << " strong";
2363 if (Attrs & ObjCPropertyAttribute::kind_unsafe_unretained)
2364 OS << " unsafe_unretained";
2365 if (Attrs & ObjCPropertyAttribute::kind_class)
2366 OS << " class";
2367 if (Attrs & ObjCPropertyAttribute::kind_direct)
2368 OS << " direct";
2369 if (Attrs & ObjCPropertyAttribute::kind_getter)
2370 dumpDeclRef(D->getGetterMethodDecl(), "getter");
2371 if (Attrs & ObjCPropertyAttribute::kind_setter)
2372 dumpDeclRef(D->getSetterMethodDecl(), "setter");
2376 void TextNodeDumper::VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D) {
2377 dumpName(D->getPropertyDecl());
2378 if (D->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize)
2379 OS << " synthesize";
2380 else
2381 OS << " dynamic";
2382 dumpDeclRef(D->getPropertyDecl());
2383 dumpDeclRef(D->getPropertyIvarDecl());
2386 void TextNodeDumper::VisitBlockDecl(const BlockDecl *D) {
2387 if (D->isVariadic())
2388 OS << " variadic";
2390 if (D->capturesCXXThis())
2391 OS << " captures_this";
2394 void TextNodeDumper::VisitConceptDecl(const ConceptDecl *D) {
2395 dumpName(D);
2398 void TextNodeDumper::VisitCompoundStmt(const CompoundStmt *S) {
2399 VisitStmt(S);
2400 if (S->hasStoredFPFeatures())
2401 printFPOptions(S->getStoredFPFeatures());
2404 void TextNodeDumper::VisitHLSLBufferDecl(const HLSLBufferDecl *D) {
2405 if (D->isCBuffer())
2406 OS << " cbuffer";
2407 else
2408 OS << " tbuffer";
2409 dumpName(D);