1 //===--- ASTDumper.cpp - Dumping implementation for ASTs ------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the AST dump methods, which dump out the
11 // AST in a form that exposes type details and other fields.
13 //===----------------------------------------------------------------------===//
15 #include "clang/AST/ASTContext.h"
16 #include "clang/AST/Attr.h"
17 #include "clang/AST/CommentVisitor.h"
18 #include "clang/AST/DeclCXX.h"
19 #include "clang/AST/DeclLookups.h"
20 #include "clang/AST/DeclObjC.h"
21 #include "clang/AST/DeclVisitor.h"
22 #include "clang/AST/StmtVisitor.h"
23 #include "clang/AST/TypeVisitor.h"
24 #include "clang/Basic/Module.h"
25 #include "clang/Basic/SourceManager.h"
26 #include "llvm/Support/raw_ostream.h"
27 using namespace clang;
28 using namespace clang::comments;
30 //===----------------------------------------------------------------------===//
32 //===----------------------------------------------------------------------===//
35 // Colors used for various parts of the AST dump
36 // Do not use bold yellow for any text. It is hard to read on white screens.
38 struct TerminalColor {
39 raw_ostream::Colors Color;
45 // Bold Green - DeclKindNameColor, UndeserializedColor
46 // Yellow - AddressColor, LocationColor
47 // Blue - CommentColor, NullColor, IndentColor
48 // Bold Blue - AttrColor
49 // Bold Magenta - StmtColor
50 // Cyan - ValueKindColor, ObjectKindColor
51 // Bold Cyan - ValueColor, DeclNameColor
53 // Decl kind names (VarDecl, FunctionDecl, etc)
54 static const TerminalColor DeclKindNameColor = { raw_ostream::GREEN, true };
55 // Attr names (CleanupAttr, GuardedByAttr, etc)
56 static const TerminalColor AttrColor = { raw_ostream::BLUE, true };
57 // Statement names (DeclStmt, ImplicitCastExpr, etc)
58 static const TerminalColor StmtColor = { raw_ostream::MAGENTA, true };
59 // Comment names (FullComment, ParagraphComment, TextComment, etc)
60 static const TerminalColor CommentColor = { raw_ostream::BLUE, false };
62 // Type names (int, float, etc, plus user defined types)
63 static const TerminalColor TypeColor = { raw_ostream::GREEN, false };
66 static const TerminalColor AddressColor = { raw_ostream::YELLOW, false };
68 static const TerminalColor LocationColor = { raw_ostream::YELLOW, false };
71 static const TerminalColor ValueKindColor = { raw_ostream::CYAN, false };
72 // bitfield/objcproperty/objcsubscript/vectorcomponent
73 static const TerminalColor ObjectKindColor = { raw_ostream::CYAN, false };
76 static const TerminalColor NullColor = { raw_ostream::BLUE, false };
78 // Undeserialized entities
79 static const TerminalColor UndeserializedColor = { raw_ostream::GREEN, true };
81 // CastKind from CastExpr's
82 static const TerminalColor CastColor = { raw_ostream::RED, false };
84 // Value of the statement
85 static const TerminalColor ValueColor = { raw_ostream::CYAN, true };
87 static const TerminalColor DeclNameColor = { raw_ostream::CYAN, true };
89 // Indents ( `, -. | )
90 static const TerminalColor IndentColor = { raw_ostream::BLUE, false };
93 : public ConstDeclVisitor<ASTDumper>, public ConstStmtVisitor<ASTDumper>,
94 public ConstCommentVisitor<ASTDumper>, public TypeVisitor<ASTDumper> {
96 const CommandTraits *Traits;
97 const SourceManager *SM;
99 /// Pending[i] is an action to dump an entity at level i.
100 llvm::SmallVector<std::function<void(bool isLastChild)>, 32> Pending;
102 /// Indicates whether we're at the top level.
105 /// Indicates if we're handling the first child after entering a new depth.
108 /// Prefix for currently-being-dumped entity.
111 /// Keep track of the last location we print out so that we can
112 /// print out deltas from then on out.
113 const char *LastLocFilename;
114 unsigned LastLocLine;
116 /// The \c FullComment parent of the comment being dumped.
117 const FullComment *FC;
121 /// Dump a child of the current node.
122 template<typename Fn> void dumpChild(Fn doDumpChild) {
123 // If we're at the top level, there's nothing interesting to do; just
128 while (!Pending.empty()) {
129 Pending.back()(true);
138 const FullComment *OrigFC = FC;
139 auto dumpWithIndent = [this, doDumpChild, OrigFC](bool isLastChild) {
140 // Print out the appropriate tree structure and work out the prefix for
141 // children of this node. For instance:
145 // | `-C Prefix = "| "
147 // |-E Prefix = " | "
151 // Note that the first level gets no prefix.
154 ColorScope Color(*this, IndentColor);
155 OS << Prefix << (isLastChild ? '`' : '|') << '-';
156 this->Prefix.push_back(isLastChild ? ' ' : '|');
157 this->Prefix.push_back(' ');
161 unsigned Depth = Pending.size();
166 // If any children are left, they're the last at their nesting level.
167 // Dump those ones out now.
168 while (Depth < Pending.size()) {
169 Pending.back()(true);
170 this->Pending.pop_back();
173 // Restore the old prefix.
174 this->Prefix.resize(Prefix.size() - 2);
178 Pending.push_back(std::move(dumpWithIndent));
180 Pending.back()(false);
181 Pending.back() = std::move(dumpWithIndent);
189 ColorScope(ASTDumper &Dumper, TerminalColor Color)
191 if (Dumper.ShowColors)
192 Dumper.OS.changeColor(Color.Color, Color.Bold);
195 if (Dumper.ShowColors)
196 Dumper.OS.resetColor();
201 ASTDumper(raw_ostream &OS, const CommandTraits *Traits,
202 const SourceManager *SM)
203 : OS(OS), Traits(Traits), SM(SM), TopLevel(true), FirstChild(true),
204 LastLocFilename(""), LastLocLine(~0U), FC(nullptr),
205 ShowColors(SM && SM->getDiagnostics().getShowColors()) { }
207 ASTDumper(raw_ostream &OS, const CommandTraits *Traits,
208 const SourceManager *SM, bool ShowColors)
209 : OS(OS), Traits(Traits), SM(SM), TopLevel(true), FirstChild(true),
210 LastLocFilename(""), LastLocLine(~0U),
211 ShowColors(ShowColors) { }
213 void dumpDecl(const Decl *D);
214 void dumpStmt(const Stmt *S);
215 void dumpFullComment(const FullComment *C);
218 void dumpPointer(const void *Ptr);
219 void dumpSourceRange(SourceRange R);
220 void dumpLocation(SourceLocation Loc);
221 void dumpBareType(QualType T, bool Desugar = true);
222 void dumpType(QualType T);
223 void dumpTypeAsChild(QualType T);
224 void dumpTypeAsChild(const Type *T);
225 void dumpBareDeclRef(const Decl *Node);
226 void dumpDeclRef(const Decl *Node, const char *Label = nullptr);
227 void dumpName(const NamedDecl *D);
228 bool hasNodes(const DeclContext *DC);
229 void dumpDeclContext(const DeclContext *DC);
230 void dumpLookups(const DeclContext *DC, bool DumpDecls);
231 void dumpAttr(const Attr *A);
234 void dumpAccessSpecifier(AccessSpecifier AS);
235 void dumpCXXCtorInitializer(const CXXCtorInitializer *Init);
236 void dumpTemplateParameters(const TemplateParameterList *TPL);
237 void dumpTemplateArgumentListInfo(const TemplateArgumentListInfo &TALI);
238 void dumpTemplateArgumentLoc(const TemplateArgumentLoc &A);
239 void dumpTemplateArgumentList(const TemplateArgumentList &TAL);
240 void dumpTemplateArgument(const TemplateArgument &A,
241 SourceRange R = SourceRange());
243 // Objective-C utilities.
244 void dumpObjCTypeParamList(const ObjCTypeParamList *typeParams);
247 void VisitComplexType(const ComplexType *T) {
248 dumpTypeAsChild(T->getElementType());
250 void VisitPointerType(const PointerType *T) {
251 dumpTypeAsChild(T->getPointeeType());
253 void VisitBlockPointerType(const BlockPointerType *T) {
254 dumpTypeAsChild(T->getPointeeType());
256 void VisitReferenceType(const ReferenceType *T) {
257 dumpTypeAsChild(T->getPointeeType());
259 void VisitRValueReferenceType(const ReferenceType *T) {
260 if (T->isSpelledAsLValue())
261 OS << " written as lvalue reference";
262 VisitReferenceType(T);
264 void VisitMemberPointerType(const MemberPointerType *T) {
265 dumpTypeAsChild(T->getClass());
266 dumpTypeAsChild(T->getPointeeType());
268 void VisitArrayType(const ArrayType *T) {
269 switch (T->getSizeModifier()) {
270 case ArrayType::Normal: break;
271 case ArrayType::Static: OS << " static"; break;
272 case ArrayType::Star: OS << " *"; break;
274 OS << " " << T->getIndexTypeQualifiers().getAsString();
275 dumpTypeAsChild(T->getElementType());
277 void VisitConstantArrayType(const ConstantArrayType *T) {
278 OS << " " << T->getSize();
281 void VisitVariableArrayType(const VariableArrayType *T) {
283 dumpSourceRange(T->getBracketsRange());
285 dumpStmt(T->getSizeExpr());
287 void VisitDependentSizedArrayType(const DependentSizedArrayType *T) {
290 dumpSourceRange(T->getBracketsRange());
291 dumpStmt(T->getSizeExpr());
293 void VisitDependentSizedExtVectorType(
294 const DependentSizedExtVectorType *T) {
296 dumpLocation(T->getAttributeLoc());
297 dumpTypeAsChild(T->getElementType());
298 dumpStmt(T->getSizeExpr());
300 void VisitVectorType(const VectorType *T) {
301 switch (T->getVectorKind()) {
302 case VectorType::GenericVector: break;
303 case VectorType::AltiVecVector: OS << " altivec"; break;
304 case VectorType::AltiVecPixel: OS << " altivec pixel"; break;
305 case VectorType::AltiVecBool: OS << " altivec bool"; break;
306 case VectorType::NeonVector: OS << " neon"; break;
307 case VectorType::NeonPolyVector: OS << " neon poly"; break;
309 OS << " " << T->getNumElements();
310 dumpTypeAsChild(T->getElementType());
312 void VisitFunctionType(const FunctionType *T) {
313 auto EI = T->getExtInfo();
314 if (EI.getNoReturn()) OS << " noreturn";
315 if (EI.getProducesResult()) OS << " produces_result";
316 if (EI.getHasRegParm()) OS << " regparm " << EI.getRegParm();
317 OS << " " << FunctionType::getNameForCallConv(EI.getCC());
318 dumpTypeAsChild(T->getReturnType());
320 void VisitFunctionProtoType(const FunctionProtoType *T) {
321 auto EPI = T->getExtProtoInfo();
322 if (EPI.HasTrailingReturn) OS << " trailing_return";
323 if (T->isConst()) OS << " const";
324 if (T->isVolatile()) OS << " volatile";
325 if (T->isRestrict()) OS << " restrict";
326 switch (EPI.RefQualifier) {
328 case RQ_LValue: OS << " &"; break;
329 case RQ_RValue: OS << " &&"; break;
331 // FIXME: Exception specification.
332 // FIXME: Consumed parameters.
333 VisitFunctionType(T);
334 for (QualType PT : T->getParamTypes())
337 dumpChild([=] { OS << "..."; });
339 void VisitUnresolvedUsingType(const UnresolvedUsingType *T) {
340 dumpDeclRef(T->getDecl());
342 void VisitTypedefType(const TypedefType *T) {
343 dumpDeclRef(T->getDecl());
345 void VisitTypeOfExprType(const TypeOfExprType *T) {
346 dumpStmt(T->getUnderlyingExpr());
348 void VisitDecltypeType(const DecltypeType *T) {
349 dumpStmt(T->getUnderlyingExpr());
351 void VisitUnaryTransformType(const UnaryTransformType *T) {
352 switch (T->getUTTKind()) {
353 case UnaryTransformType::EnumUnderlyingType:
354 OS << " underlying_type";
357 dumpTypeAsChild(T->getBaseType());
359 void VisitTagType(const TagType *T) {
360 dumpDeclRef(T->getDecl());
362 void VisitAttributedType(const AttributedType *T) {
364 dumpTypeAsChild(T->getModifiedType());
366 void VisitTemplateTypeParmType(const TemplateTypeParmType *T) {
367 OS << " depth " << T->getDepth() << " index " << T->getIndex();
368 if (T->isParameterPack()) OS << " pack";
369 dumpDeclRef(T->getDecl());
371 void VisitSubstTemplateTypeParmType(const SubstTemplateTypeParmType *T) {
372 dumpTypeAsChild(T->getReplacedParameter());
374 void VisitSubstTemplateTypeParmPackType(
375 const SubstTemplateTypeParmPackType *T) {
376 dumpTypeAsChild(T->getReplacedParameter());
377 dumpTemplateArgument(T->getArgumentPack());
379 void VisitAutoType(const AutoType *T) {
380 if (T->isDecltypeAuto()) OS << " decltype(auto)";
384 void VisitTemplateSpecializationType(const TemplateSpecializationType *T) {
385 if (T->isTypeAlias()) OS << " alias";
386 OS << " "; T->getTemplateName().dump(OS);
388 dumpTemplateArgument(Arg);
389 if (T->isTypeAlias())
390 dumpTypeAsChild(T->getAliasedType());
392 void VisitInjectedClassNameType(const InjectedClassNameType *T) {
393 dumpDeclRef(T->getDecl());
395 void VisitObjCInterfaceType(const ObjCInterfaceType *T) {
396 dumpDeclRef(T->getDecl());
398 void VisitObjCObjectPointerType(const ObjCObjectPointerType *T) {
399 dumpTypeAsChild(T->getPointeeType());
401 void VisitAtomicType(const AtomicType *T) {
402 dumpTypeAsChild(T->getValueType());
404 void VisitAdjustedType(const AdjustedType *T) {
405 dumpTypeAsChild(T->getOriginalType());
407 void VisitPackExpansionType(const PackExpansionType *T) {
408 if (auto N = T->getNumExpansions()) OS << " expansions " << *N;
410 dumpTypeAsChild(T->getPattern());
412 // FIXME: ElaboratedType, DependentNameType,
413 // DependentTemplateSpecializationType, ObjCObjectType
416 void VisitLabelDecl(const LabelDecl *D);
417 void VisitTypedefDecl(const TypedefDecl *D);
418 void VisitEnumDecl(const EnumDecl *D);
419 void VisitRecordDecl(const RecordDecl *D);
420 void VisitEnumConstantDecl(const EnumConstantDecl *D);
421 void VisitIndirectFieldDecl(const IndirectFieldDecl *D);
422 void VisitFunctionDecl(const FunctionDecl *D);
423 void VisitFieldDecl(const FieldDecl *D);
424 void VisitVarDecl(const VarDecl *D);
425 void VisitFileScopeAsmDecl(const FileScopeAsmDecl *D);
426 void VisitImportDecl(const ImportDecl *D);
429 void VisitNamespaceDecl(const NamespaceDecl *D);
430 void VisitUsingDirectiveDecl(const UsingDirectiveDecl *D);
431 void VisitNamespaceAliasDecl(const NamespaceAliasDecl *D);
432 void VisitTypeAliasDecl(const TypeAliasDecl *D);
433 void VisitTypeAliasTemplateDecl(const TypeAliasTemplateDecl *D);
434 void VisitCXXRecordDecl(const CXXRecordDecl *D);
435 void VisitStaticAssertDecl(const StaticAssertDecl *D);
436 template<typename SpecializationDecl>
437 void VisitTemplateDeclSpecialization(const SpecializationDecl *D,
438 bool DumpExplicitInst,
440 template<typename TemplateDecl>
441 void VisitTemplateDecl(const TemplateDecl *D, bool DumpExplicitInst);
442 void VisitFunctionTemplateDecl(const FunctionTemplateDecl *D);
443 void VisitClassTemplateDecl(const ClassTemplateDecl *D);
444 void VisitClassTemplateSpecializationDecl(
445 const ClassTemplateSpecializationDecl *D);
446 void VisitClassTemplatePartialSpecializationDecl(
447 const ClassTemplatePartialSpecializationDecl *D);
448 void VisitClassScopeFunctionSpecializationDecl(
449 const ClassScopeFunctionSpecializationDecl *D);
450 void VisitVarTemplateDecl(const VarTemplateDecl *D);
451 void VisitVarTemplateSpecializationDecl(
452 const VarTemplateSpecializationDecl *D);
453 void VisitVarTemplatePartialSpecializationDecl(
454 const VarTemplatePartialSpecializationDecl *D);
455 void VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D);
456 void VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D);
457 void VisitTemplateTemplateParmDecl(const TemplateTemplateParmDecl *D);
458 void VisitUsingDecl(const UsingDecl *D);
459 void VisitUnresolvedUsingTypenameDecl(const UnresolvedUsingTypenameDecl *D);
460 void VisitUnresolvedUsingValueDecl(const UnresolvedUsingValueDecl *D);
461 void VisitUsingShadowDecl(const UsingShadowDecl *D);
462 void VisitLinkageSpecDecl(const LinkageSpecDecl *D);
463 void VisitAccessSpecDecl(const AccessSpecDecl *D);
464 void VisitFriendDecl(const FriendDecl *D);
467 void VisitObjCIvarDecl(const ObjCIvarDecl *D);
468 void VisitObjCMethodDecl(const ObjCMethodDecl *D);
469 void VisitObjCTypeParamDecl(const ObjCTypeParamDecl *D);
470 void VisitObjCCategoryDecl(const ObjCCategoryDecl *D);
471 void VisitObjCCategoryImplDecl(const ObjCCategoryImplDecl *D);
472 void VisitObjCProtocolDecl(const ObjCProtocolDecl *D);
473 void VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D);
474 void VisitObjCImplementationDecl(const ObjCImplementationDecl *D);
475 void VisitObjCCompatibleAliasDecl(const ObjCCompatibleAliasDecl *D);
476 void VisitObjCPropertyDecl(const ObjCPropertyDecl *D);
477 void VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D);
478 void VisitBlockDecl(const BlockDecl *D);
481 void VisitStmt(const Stmt *Node);
482 void VisitDeclStmt(const DeclStmt *Node);
483 void VisitAttributedStmt(const AttributedStmt *Node);
484 void VisitLabelStmt(const LabelStmt *Node);
485 void VisitGotoStmt(const GotoStmt *Node);
486 void VisitCXXCatchStmt(const CXXCatchStmt *Node);
489 void VisitExpr(const Expr *Node);
490 void VisitCastExpr(const CastExpr *Node);
491 void VisitDeclRefExpr(const DeclRefExpr *Node);
492 void VisitPredefinedExpr(const PredefinedExpr *Node);
493 void VisitCharacterLiteral(const CharacterLiteral *Node);
494 void VisitIntegerLiteral(const IntegerLiteral *Node);
495 void VisitFloatingLiteral(const FloatingLiteral *Node);
496 void VisitStringLiteral(const StringLiteral *Str);
497 void VisitInitListExpr(const InitListExpr *ILE);
498 void VisitUnaryOperator(const UnaryOperator *Node);
499 void VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *Node);
500 void VisitMemberExpr(const MemberExpr *Node);
501 void VisitExtVectorElementExpr(const ExtVectorElementExpr *Node);
502 void VisitBinaryOperator(const BinaryOperator *Node);
503 void VisitCompoundAssignOperator(const CompoundAssignOperator *Node);
504 void VisitAddrLabelExpr(const AddrLabelExpr *Node);
505 void VisitBlockExpr(const BlockExpr *Node);
506 void VisitOpaqueValueExpr(const OpaqueValueExpr *Node);
509 void VisitCXXNamedCastExpr(const CXXNamedCastExpr *Node);
510 void VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *Node);
511 void VisitCXXThisExpr(const CXXThisExpr *Node);
512 void VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *Node);
513 void VisitCXXConstructExpr(const CXXConstructExpr *Node);
514 void VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *Node);
515 void VisitCXXNewExpr(const CXXNewExpr *Node);
516 void VisitCXXDeleteExpr(const CXXDeleteExpr *Node);
517 void VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *Node);
518 void VisitExprWithCleanups(const ExprWithCleanups *Node);
519 void VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *Node);
520 void dumpCXXTemporary(const CXXTemporary *Temporary);
521 void VisitLambdaExpr(const LambdaExpr *Node) {
523 dumpDecl(Node->getLambdaClass());
525 void VisitSizeOfPackExpr(const SizeOfPackExpr *Node);
528 void VisitObjCAtCatchStmt(const ObjCAtCatchStmt *Node);
529 void VisitObjCEncodeExpr(const ObjCEncodeExpr *Node);
530 void VisitObjCMessageExpr(const ObjCMessageExpr *Node);
531 void VisitObjCBoxedExpr(const ObjCBoxedExpr *Node);
532 void VisitObjCSelectorExpr(const ObjCSelectorExpr *Node);
533 void VisitObjCProtocolExpr(const ObjCProtocolExpr *Node);
534 void VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *Node);
535 void VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *Node);
536 void VisitObjCIvarRefExpr(const ObjCIvarRefExpr *Node);
537 void VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *Node);
540 const char *getCommandName(unsigned CommandID);
541 void dumpComment(const Comment *C);
544 void visitTextComment(const TextComment *C);
545 void visitInlineCommandComment(const InlineCommandComment *C);
546 void visitHTMLStartTagComment(const HTMLStartTagComment *C);
547 void visitHTMLEndTagComment(const HTMLEndTagComment *C);
550 void visitBlockCommandComment(const BlockCommandComment *C);
551 void visitParamCommandComment(const ParamCommandComment *C);
552 void visitTParamCommandComment(const TParamCommandComment *C);
553 void visitVerbatimBlockComment(const VerbatimBlockComment *C);
554 void visitVerbatimBlockLineComment(const VerbatimBlockLineComment *C);
555 void visitVerbatimLineComment(const VerbatimLineComment *C);
559 //===----------------------------------------------------------------------===//
561 //===----------------------------------------------------------------------===//
563 void ASTDumper::dumpPointer(const void *Ptr) {
564 ColorScope Color(*this, AddressColor);
568 void ASTDumper::dumpLocation(SourceLocation Loc) {
572 ColorScope Color(*this, LocationColor);
573 SourceLocation SpellingLoc = SM->getSpellingLoc(Loc);
575 // The general format we print out is filename:line:col, but we drop pieces
576 // that haven't changed since the last loc printed.
577 PresumedLoc PLoc = SM->getPresumedLoc(SpellingLoc);
579 if (PLoc.isInvalid()) {
580 OS << "<invalid sloc>";
584 if (strcmp(PLoc.getFilename(), LastLocFilename) != 0) {
585 OS << PLoc.getFilename() << ':' << PLoc.getLine()
586 << ':' << PLoc.getColumn();
587 LastLocFilename = PLoc.getFilename();
588 LastLocLine = PLoc.getLine();
589 } else if (PLoc.getLine() != LastLocLine) {
590 OS << "line" << ':' << PLoc.getLine()
591 << ':' << PLoc.getColumn();
592 LastLocLine = PLoc.getLine();
594 OS << "col" << ':' << PLoc.getColumn();
598 void ASTDumper::dumpSourceRange(SourceRange R) {
599 // Can't translate locations if a SourceManager isn't available.
604 dumpLocation(R.getBegin());
605 if (R.getBegin() != R.getEnd()) {
607 dumpLocation(R.getEnd());
611 // <t2.c:123:421[blah], t2.c:412:321>
615 void ASTDumper::dumpBareType(QualType T, bool Desugar) {
616 ColorScope Color(*this, TypeColor);
618 SplitQualType T_split = T.split();
619 OS << "'" << QualType::getAsString(T_split) << "'";
621 if (Desugar && !T.isNull()) {
622 // If the type is sugared, also dump a (shallow) desugared type.
623 SplitQualType D_split = T.getSplitDesugaredType();
624 if (T_split != D_split)
625 OS << ":'" << QualType::getAsString(D_split) << "'";
629 void ASTDumper::dumpType(QualType T) {
634 void ASTDumper::dumpTypeAsChild(QualType T) {
635 SplitQualType SQT = T.split();
636 if (!SQT.Quals.hasQualifiers())
637 return dumpTypeAsChild(SQT.Ty);
641 dumpPointer(T.getAsOpaquePtr());
643 dumpBareType(T, false);
644 OS << " " << T.split().Quals.getAsString();
645 dumpTypeAsChild(T.split().Ty);
649 void ASTDumper::dumpTypeAsChild(const Type *T) {
652 ColorScope Color(*this, NullColor);
658 ColorScope Color(*this, TypeColor);
659 OS << T->getTypeClassName() << "Type";
663 dumpBareType(QualType(T, 0), false);
665 QualType SingleStepDesugar =
666 T->getLocallyUnqualifiedSingleStepDesugaredType();
667 if (SingleStepDesugar != QualType(T, 0))
669 if (T->isDependentType())
671 else if (T->isInstantiationDependentType())
672 OS << " instantiation_dependent";
673 if (T->isVariablyModifiedType())
674 OS << " variably_modified";
675 if (T->containsUnexpandedParameterPack())
676 OS << " contains_unexpanded_pack";
680 TypeVisitor<ASTDumper>::Visit(T);
682 if (SingleStepDesugar != QualType(T, 0))
683 dumpTypeAsChild(SingleStepDesugar);
687 void ASTDumper::dumpBareDeclRef(const Decl *D) {
689 ColorScope Color(*this, DeclKindNameColor);
690 OS << D->getDeclKindName();
694 if (const NamedDecl *ND = dyn_cast<NamedDecl>(D)) {
695 ColorScope Color(*this, DeclNameColor);
696 OS << " '" << ND->getDeclName() << '\'';
699 if (const ValueDecl *VD = dyn_cast<ValueDecl>(D))
700 dumpType(VD->getType());
703 void ASTDumper::dumpDeclRef(const Decl *D, const char *Label) {
714 void ASTDumper::dumpName(const NamedDecl *ND) {
715 if (ND->getDeclName()) {
716 ColorScope Color(*this, DeclNameColor);
717 OS << ' ' << ND->getNameAsString();
721 bool ASTDumper::hasNodes(const DeclContext *DC) {
725 return DC->hasExternalLexicalStorage() ||
726 DC->noload_decls_begin() != DC->noload_decls_end();
729 void ASTDumper::dumpDeclContext(const DeclContext *DC) {
733 for (auto *D : DC->noload_decls())
736 if (DC->hasExternalLexicalStorage()) {
738 ColorScope Color(*this, UndeserializedColor);
739 OS << "<undeserialized declarations>";
744 void ASTDumper::dumpLookups(const DeclContext *DC, bool DumpDecls) {
746 OS << "StoredDeclsMap ";
747 dumpBareDeclRef(cast<Decl>(DC));
749 const DeclContext *Primary = DC->getPrimaryContext();
752 dumpPointer(cast<Decl>(Primary));
755 bool HasUndeserializedLookups = Primary->hasExternalVisibleStorage();
757 DeclContext::all_lookups_iterator I = Primary->noload_lookups_begin(),
758 E = Primary->noload_lookups_end();
760 DeclarationName Name = I.getLookupName();
761 DeclContextLookupResult R = *I++;
764 OS << "DeclarationName ";
766 ColorScope Color(*this, DeclNameColor);
767 OS << '\'' << Name << '\'';
770 for (DeclContextLookupResult::iterator RI = R.begin(), RE = R.end();
773 dumpBareDeclRef(*RI);
775 if ((*RI)->isHidden())
778 // If requested, dump the redecl chain for this lookup.
780 // Dump earliest decl first.
781 std::function<void(Decl *)> DumpWithPrev = [&](Decl *D) {
782 if (Decl *Prev = D->getPreviousDecl())
793 if (HasUndeserializedLookups) {
795 ColorScope Color(*this, UndeserializedColor);
796 OS << "<undeserialized lookups>";
802 void ASTDumper::dumpAttr(const Attr *A) {
805 ColorScope Color(*this, AttrColor);
807 switch (A->getKind()) {
808 #define ATTR(X) case attr::X: OS << #X; break;
809 #include "clang/Basic/AttrList.inc"
811 llvm_unreachable("unexpected attribute kind");
816 dumpSourceRange(A->getRange());
817 if (A->isInherited())
821 #include "clang/AST/AttrDump.inc"
825 static void dumpPreviousDeclImpl(raw_ostream &OS, ...) {}
828 static void dumpPreviousDeclImpl(raw_ostream &OS, const Mergeable<T> *D) {
829 const T *First = D->getFirstDecl();
831 OS << " first " << First;
835 static void dumpPreviousDeclImpl(raw_ostream &OS, const Redeclarable<T> *D) {
836 const T *Prev = D->getPreviousDecl();
838 OS << " prev " << Prev;
841 /// Dump the previous declaration in the redeclaration chain for a declaration,
843 static void dumpPreviousDecl(raw_ostream &OS, const Decl *D) {
844 switch (D->getKind()) {
845 #define DECL(DERIVED, BASE) \
846 case Decl::DERIVED: \
847 return dumpPreviousDeclImpl(OS, cast<DERIVED##Decl>(D));
848 #define ABSTRACT_DECL(DECL)
849 #include "clang/AST/DeclNodes.inc"
851 llvm_unreachable("Decl that isn't part of DeclNodes.inc!");
854 //===----------------------------------------------------------------------===//
856 //===----------------------------------------------------------------------===//
858 void ASTDumper::dumpAccessSpecifier(AccessSpecifier AS) {
874 void ASTDumper::dumpCXXCtorInitializer(const CXXCtorInitializer *Init) {
876 OS << "CXXCtorInitializer";
877 if (Init->isAnyMemberInitializer()) {
879 dumpBareDeclRef(Init->getAnyMember());
880 } else if (Init->isBaseInitializer()) {
881 dumpType(QualType(Init->getBaseClass(), 0));
882 } else if (Init->isDelegatingInitializer()) {
883 dumpType(Init->getTypeSourceInfo()->getType());
885 llvm_unreachable("Unknown initializer type");
887 dumpStmt(Init->getInit());
891 void ASTDumper::dumpTemplateParameters(const TemplateParameterList *TPL) {
895 for (TemplateParameterList::const_iterator I = TPL->begin(), E = TPL->end();
900 void ASTDumper::dumpTemplateArgumentListInfo(
901 const TemplateArgumentListInfo &TALI) {
902 for (unsigned i = 0, e = TALI.size(); i < e; ++i)
903 dumpTemplateArgumentLoc(TALI[i]);
906 void ASTDumper::dumpTemplateArgumentLoc(const TemplateArgumentLoc &A) {
907 dumpTemplateArgument(A.getArgument(), A.getSourceRange());
910 void ASTDumper::dumpTemplateArgumentList(const TemplateArgumentList &TAL) {
911 for (unsigned i = 0, e = TAL.size(); i < e; ++i)
912 dumpTemplateArgument(TAL[i]);
915 void ASTDumper::dumpTemplateArgument(const TemplateArgument &A, SourceRange R) {
917 OS << "TemplateArgument";
921 switch (A.getKind()) {
922 case TemplateArgument::Null:
925 case TemplateArgument::Type:
927 dumpType(A.getAsType());
929 case TemplateArgument::Declaration:
931 dumpDeclRef(A.getAsDecl());
933 case TemplateArgument::NullPtr:
936 case TemplateArgument::Integral:
937 OS << " integral " << A.getAsIntegral();
939 case TemplateArgument::Template:
941 A.getAsTemplate().dump(OS);
943 case TemplateArgument::TemplateExpansion:
944 OS << " template expansion";
945 A.getAsTemplateOrTemplatePattern().dump(OS);
947 case TemplateArgument::Expression:
949 dumpStmt(A.getAsExpr());
951 case TemplateArgument::Pack:
953 for (TemplateArgument::pack_iterator I = A.pack_begin(), E = A.pack_end();
955 dumpTemplateArgument(*I);
961 //===----------------------------------------------------------------------===//
962 // Objective-C Utilities
963 //===----------------------------------------------------------------------===//
964 void ASTDumper::dumpObjCTypeParamList(const ObjCTypeParamList *typeParams) {
968 for (auto typeParam : *typeParams) {
973 //===----------------------------------------------------------------------===//
974 // Decl dumping methods.
975 //===----------------------------------------------------------------------===//
977 void ASTDumper::dumpDecl(const Decl *D) {
980 ColorScope Color(*this, NullColor);
986 ColorScope Color(*this, DeclKindNameColor);
987 OS << D->getDeclKindName() << "Decl";
990 if (D->getLexicalDeclContext() != D->getDeclContext())
991 OS << " parent " << cast<Decl>(D->getDeclContext());
992 dumpPreviousDecl(OS, D);
993 dumpSourceRange(D->getSourceRange());
995 dumpLocation(D->getLocation());
996 if (Module *M = D->getImportedOwningModule())
997 OS << " in " << M->getFullModuleName();
998 else if (Module *M = D->getLocalOwningModule())
999 OS << " in (local) " << M->getFullModuleName();
1000 if (auto *ND = dyn_cast<NamedDecl>(D))
1001 for (Module *M : D->getASTContext().getModulesWithMergedDefinition(
1002 const_cast<NamedDecl *>(ND)))
1003 dumpChild([=] { OS << "also in " << M->getFullModuleName(); });
1004 if (const NamedDecl *ND = dyn_cast<NamedDecl>(D))
1007 if (D->isImplicit())
1011 else if (D->isThisDeclarationReferenced())
1012 OS << " referenced";
1013 if (D->isInvalidDecl())
1015 if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
1016 if (FD->isConstexpr())
1020 ConstDeclVisitor<ASTDumper>::Visit(D);
1022 for (Decl::attr_iterator I = D->attr_begin(), E = D->attr_end(); I != E;
1026 if (const FullComment *Comment =
1027 D->getASTContext().getLocalCommentForDeclUncached(D))
1028 dumpFullComment(Comment);
1030 // Decls within functions are visited by the body.
1031 if (!isa<FunctionDecl>(*D) && !isa<ObjCMethodDecl>(*D) &&
1032 hasNodes(dyn_cast<DeclContext>(D)))
1033 dumpDeclContext(cast<DeclContext>(D));
1037 void ASTDumper::VisitLabelDecl(const LabelDecl *D) {
1041 void ASTDumper::VisitTypedefDecl(const TypedefDecl *D) {
1043 dumpType(D->getUnderlyingType());
1044 if (D->isModulePrivate())
1045 OS << " __module_private__";
1048 void ASTDumper::VisitEnumDecl(const EnumDecl *D) {
1049 if (D->isScoped()) {
1050 if (D->isScopedUsingClassTag())
1056 if (D->isModulePrivate())
1057 OS << " __module_private__";
1059 dumpType(D->getIntegerType());
1062 void ASTDumper::VisitRecordDecl(const RecordDecl *D) {
1063 OS << ' ' << D->getKindName();
1065 if (D->isModulePrivate())
1066 OS << " __module_private__";
1067 if (D->isCompleteDefinition())
1068 OS << " definition";
1071 void ASTDumper::VisitEnumConstantDecl(const EnumConstantDecl *D) {
1073 dumpType(D->getType());
1074 if (const Expr *Init = D->getInitExpr())
1078 void ASTDumper::VisitIndirectFieldDecl(const IndirectFieldDecl *D) {
1080 dumpType(D->getType());
1082 for (auto *Child : D->chain())
1086 void ASTDumper::VisitFunctionDecl(const FunctionDecl *D) {
1088 dumpType(D->getType());
1090 StorageClass SC = D->getStorageClass();
1092 OS << ' ' << VarDecl::getStorageClassSpecifierString(SC);
1093 if (D->isInlineSpecified())
1095 if (D->isVirtualAsWritten())
1097 if (D->isModulePrivate())
1098 OS << " __module_private__";
1102 else if (D->isDeletedAsWritten())
1105 if (const FunctionProtoType *FPT = D->getType()->getAs<FunctionProtoType>()) {
1106 FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo();
1107 switch (EPI.ExceptionSpec.Type) {
1109 case EST_Unevaluated:
1110 OS << " noexcept-unevaluated " << EPI.ExceptionSpec.SourceDecl;
1112 case EST_Uninstantiated:
1113 OS << " noexcept-uninstantiated " << EPI.ExceptionSpec.SourceTemplate;
1118 if (const FunctionTemplateSpecializationInfo *FTSI =
1119 D->getTemplateSpecializationInfo())
1120 dumpTemplateArgumentList(*FTSI->TemplateArguments);
1122 for (ArrayRef<NamedDecl *>::iterator
1123 I = D->getDeclsInPrototypeScope().begin(),
1124 E = D->getDeclsInPrototypeScope().end(); I != E; ++I)
1127 if (!D->param_begin() && D->getNumParams())
1128 dumpChild([=] { OS << "<<NULL params x " << D->getNumParams() << ">>"; });
1130 for (FunctionDecl::param_const_iterator I = D->param_begin(),
1135 if (const CXXConstructorDecl *C = dyn_cast<CXXConstructorDecl>(D))
1136 for (CXXConstructorDecl::init_const_iterator I = C->init_begin(),
1139 dumpCXXCtorInitializer(*I);
1141 if (D->doesThisDeclarationHaveABody())
1142 dumpStmt(D->getBody());
1145 void ASTDumper::VisitFieldDecl(const FieldDecl *D) {
1147 dumpType(D->getType());
1150 if (D->isModulePrivate())
1151 OS << " __module_private__";
1153 if (D->isBitField())
1154 dumpStmt(D->getBitWidth());
1155 if (Expr *Init = D->getInClassInitializer())
1159 void ASTDumper::VisitVarDecl(const VarDecl *D) {
1161 dumpType(D->getType());
1162 StorageClass SC = D->getStorageClass();
1164 OS << ' ' << VarDecl::getStorageClassSpecifierString(SC);
1165 switch (D->getTLSKind()) {
1166 case VarDecl::TLS_None: break;
1167 case VarDecl::TLS_Static: OS << " tls"; break;
1168 case VarDecl::TLS_Dynamic: OS << " tls_dynamic"; break;
1170 if (D->isModulePrivate())
1171 OS << " __module_private__";
1172 if (D->isNRVOVariable())
1175 switch (D->getInitStyle()) {
1176 case VarDecl::CInit: OS << " cinit"; break;
1177 case VarDecl::CallInit: OS << " callinit"; break;
1178 case VarDecl::ListInit: OS << " listinit"; break;
1180 dumpStmt(D->getInit());
1184 void ASTDumper::VisitFileScopeAsmDecl(const FileScopeAsmDecl *D) {
1185 dumpStmt(D->getAsmString());
1188 void ASTDumper::VisitImportDecl(const ImportDecl *D) {
1189 OS << ' ' << D->getImportedModule()->getFullModuleName();
1192 //===----------------------------------------------------------------------===//
1194 //===----------------------------------------------------------------------===//
1196 void ASTDumper::VisitNamespaceDecl(const NamespaceDecl *D) {
1200 if (!D->isOriginalNamespace())
1201 dumpDeclRef(D->getOriginalNamespace(), "original");
1204 void ASTDumper::VisitUsingDirectiveDecl(const UsingDirectiveDecl *D) {
1206 dumpBareDeclRef(D->getNominatedNamespace());
1209 void ASTDumper::VisitNamespaceAliasDecl(const NamespaceAliasDecl *D) {
1211 dumpDeclRef(D->getAliasedNamespace());
1214 void ASTDumper::VisitTypeAliasDecl(const TypeAliasDecl *D) {
1216 dumpType(D->getUnderlyingType());
1219 void ASTDumper::VisitTypeAliasTemplateDecl(const TypeAliasTemplateDecl *D) {
1221 dumpTemplateParameters(D->getTemplateParameters());
1222 dumpDecl(D->getTemplatedDecl());
1225 void ASTDumper::VisitCXXRecordDecl(const CXXRecordDecl *D) {
1227 if (!D->isCompleteDefinition())
1230 for (const auto &I : D->bases()) {
1234 dumpAccessSpecifier(I.getAccessSpecifier());
1235 dumpType(I.getType());
1236 if (I.isPackExpansion())
1242 void ASTDumper::VisitStaticAssertDecl(const StaticAssertDecl *D) {
1243 dumpStmt(D->getAssertExpr());
1244 dumpStmt(D->getMessage());
1247 template<typename SpecializationDecl>
1248 void ASTDumper::VisitTemplateDeclSpecialization(const SpecializationDecl *D,
1249 bool DumpExplicitInst,
1251 bool DumpedAny = false;
1252 for (auto *RedeclWithBadType : D->redecls()) {
1253 // FIXME: The redecls() range sometimes has elements of a less-specific
1254 // type. (In particular, ClassTemplateSpecializationDecl::redecls() gives
1255 // us TagDecls, and should give CXXRecordDecls).
1256 auto *Redecl = dyn_cast<SpecializationDecl>(RedeclWithBadType);
1258 // Found the injected-class-name for a class template. This will be dumped
1259 // as part of its surrounding class so we don't need to dump it here.
1260 assert(isa<CXXRecordDecl>(RedeclWithBadType) &&
1261 "expected an injected-class-name");
1265 switch (Redecl->getTemplateSpecializationKind()) {
1266 case TSK_ExplicitInstantiationDeclaration:
1267 case TSK_ExplicitInstantiationDefinition:
1268 if (!DumpExplicitInst)
1271 case TSK_Undeclared:
1272 case TSK_ImplicitInstantiation:
1274 dumpDeclRef(Redecl);
1279 case TSK_ExplicitSpecialization:
1284 // Ensure we dump at least one decl for each specialization.
1289 template<typename TemplateDecl>
1290 void ASTDumper::VisitTemplateDecl(const TemplateDecl *D,
1291 bool DumpExplicitInst) {
1293 dumpTemplateParameters(D->getTemplateParameters());
1295 dumpDecl(D->getTemplatedDecl());
1297 for (auto *Child : D->specializations())
1298 VisitTemplateDeclSpecialization(Child, DumpExplicitInst,
1299 !D->isCanonicalDecl());
1302 void ASTDumper::VisitFunctionTemplateDecl(const FunctionTemplateDecl *D) {
1303 // FIXME: We don't add a declaration of a function template specialization
1304 // to its context when it's explicitly instantiated, so dump explicit
1305 // instantiations when we dump the template itself.
1306 VisitTemplateDecl(D, true);
1309 void ASTDumper::VisitClassTemplateDecl(const ClassTemplateDecl *D) {
1310 VisitTemplateDecl(D, false);
1313 void ASTDumper::VisitClassTemplateSpecializationDecl(
1314 const ClassTemplateSpecializationDecl *D) {
1315 VisitCXXRecordDecl(D);
1316 dumpTemplateArgumentList(D->getTemplateArgs());
1319 void ASTDumper::VisitClassTemplatePartialSpecializationDecl(
1320 const ClassTemplatePartialSpecializationDecl *D) {
1321 VisitClassTemplateSpecializationDecl(D);
1322 dumpTemplateParameters(D->getTemplateParameters());
1325 void ASTDumper::VisitClassScopeFunctionSpecializationDecl(
1326 const ClassScopeFunctionSpecializationDecl *D) {
1327 dumpDeclRef(D->getSpecialization());
1328 if (D->hasExplicitTemplateArgs())
1329 dumpTemplateArgumentListInfo(D->templateArgs());
1332 void ASTDumper::VisitVarTemplateDecl(const VarTemplateDecl *D) {
1333 VisitTemplateDecl(D, false);
1336 void ASTDumper::VisitVarTemplateSpecializationDecl(
1337 const VarTemplateSpecializationDecl *D) {
1338 dumpTemplateArgumentList(D->getTemplateArgs());
1342 void ASTDumper::VisitVarTemplatePartialSpecializationDecl(
1343 const VarTemplatePartialSpecializationDecl *D) {
1344 dumpTemplateParameters(D->getTemplateParameters());
1345 VisitVarTemplateSpecializationDecl(D);
1348 void ASTDumper::VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D) {
1349 if (D->wasDeclaredWithTypename())
1353 if (D->isParameterPack())
1356 if (D->hasDefaultArgument())
1357 dumpTemplateArgument(D->getDefaultArgument());
1360 void ASTDumper::VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D) {
1361 dumpType(D->getType());
1362 if (D->isParameterPack())
1365 if (D->hasDefaultArgument())
1366 dumpTemplateArgument(D->getDefaultArgument());
1369 void ASTDumper::VisitTemplateTemplateParmDecl(
1370 const TemplateTemplateParmDecl *D) {
1371 if (D->isParameterPack())
1374 dumpTemplateParameters(D->getTemplateParameters());
1375 if (D->hasDefaultArgument())
1376 dumpTemplateArgumentLoc(D->getDefaultArgument());
1379 void ASTDumper::VisitUsingDecl(const UsingDecl *D) {
1381 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
1382 OS << D->getNameAsString();
1385 void ASTDumper::VisitUnresolvedUsingTypenameDecl(
1386 const UnresolvedUsingTypenameDecl *D) {
1388 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
1389 OS << D->getNameAsString();
1392 void ASTDumper::VisitUnresolvedUsingValueDecl(const UnresolvedUsingValueDecl *D) {
1394 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
1395 OS << D->getNameAsString();
1396 dumpType(D->getType());
1399 void ASTDumper::VisitUsingShadowDecl(const UsingShadowDecl *D) {
1401 dumpBareDeclRef(D->getTargetDecl());
1404 void ASTDumper::VisitLinkageSpecDecl(const LinkageSpecDecl *D) {
1405 switch (D->getLanguage()) {
1406 case LinkageSpecDecl::lang_c: OS << " C"; break;
1407 case LinkageSpecDecl::lang_cxx: OS << " C++"; break;
1411 void ASTDumper::VisitAccessSpecDecl(const AccessSpecDecl *D) {
1413 dumpAccessSpecifier(D->getAccess());
1416 void ASTDumper::VisitFriendDecl(const FriendDecl *D) {
1417 if (TypeSourceInfo *T = D->getFriendType())
1418 dumpType(T->getType());
1420 dumpDecl(D->getFriendDecl());
1423 //===----------------------------------------------------------------------===//
1424 // Obj-C Declarations
1425 //===----------------------------------------------------------------------===//
1427 void ASTDumper::VisitObjCIvarDecl(const ObjCIvarDecl *D) {
1429 dumpType(D->getType());
1430 if (D->getSynthesize())
1431 OS << " synthesize";
1433 switch (D->getAccessControl()) {
1434 case ObjCIvarDecl::None:
1437 case ObjCIvarDecl::Private:
1440 case ObjCIvarDecl::Protected:
1443 case ObjCIvarDecl::Public:
1446 case ObjCIvarDecl::Package:
1452 void ASTDumper::VisitObjCMethodDecl(const ObjCMethodDecl *D) {
1453 if (D->isInstanceMethod())
1458 dumpType(D->getReturnType());
1460 if (D->isThisDeclarationADefinition()) {
1463 for (ObjCMethodDecl::param_const_iterator I = D->param_begin(),
1469 if (D->isVariadic())
1470 dumpChild([=] { OS << "..."; });
1473 dumpStmt(D->getBody());
1476 void ASTDumper::VisitObjCTypeParamDecl(const ObjCTypeParamDecl *D) {
1478 switch (D->getVariance()) {
1479 case ObjCTypeParamVariance::Invariant:
1482 case ObjCTypeParamVariance::Covariant:
1486 case ObjCTypeParamVariance::Contravariant:
1487 OS << " contravariant";
1491 if (D->hasExplicitBound())
1493 dumpType(D->getUnderlyingType());
1496 void ASTDumper::VisitObjCCategoryDecl(const ObjCCategoryDecl *D) {
1498 dumpDeclRef(D->getClassInterface());
1499 dumpObjCTypeParamList(D->getTypeParamList());
1500 dumpDeclRef(D->getImplementation());
1501 for (ObjCCategoryDecl::protocol_iterator I = D->protocol_begin(),
1502 E = D->protocol_end();
1507 void ASTDumper::VisitObjCCategoryImplDecl(const ObjCCategoryImplDecl *D) {
1509 dumpDeclRef(D->getClassInterface());
1510 dumpDeclRef(D->getCategoryDecl());
1513 void ASTDumper::VisitObjCProtocolDecl(const ObjCProtocolDecl *D) {
1516 for (auto *Child : D->protocols())
1520 void ASTDumper::VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D) {
1522 dumpObjCTypeParamList(D->getTypeParamListAsWritten());
1523 dumpDeclRef(D->getSuperClass(), "super");
1525 dumpDeclRef(D->getImplementation());
1526 for (auto *Child : D->protocols())
1530 void ASTDumper::VisitObjCImplementationDecl(const ObjCImplementationDecl *D) {
1532 dumpDeclRef(D->getSuperClass(), "super");
1533 dumpDeclRef(D->getClassInterface());
1534 for (ObjCImplementationDecl::init_const_iterator I = D->init_begin(),
1537 dumpCXXCtorInitializer(*I);
1540 void ASTDumper::VisitObjCCompatibleAliasDecl(const ObjCCompatibleAliasDecl *D) {
1542 dumpDeclRef(D->getClassInterface());
1545 void ASTDumper::VisitObjCPropertyDecl(const ObjCPropertyDecl *D) {
1547 dumpType(D->getType());
1549 if (D->getPropertyImplementation() == ObjCPropertyDecl::Required)
1551 else if (D->getPropertyImplementation() == ObjCPropertyDecl::Optional)
1554 ObjCPropertyDecl::PropertyAttributeKind Attrs = D->getPropertyAttributes();
1555 if (Attrs != ObjCPropertyDecl::OBJC_PR_noattr) {
1556 if (Attrs & ObjCPropertyDecl::OBJC_PR_readonly)
1558 if (Attrs & ObjCPropertyDecl::OBJC_PR_assign)
1560 if (Attrs & ObjCPropertyDecl::OBJC_PR_readwrite)
1562 if (Attrs & ObjCPropertyDecl::OBJC_PR_retain)
1564 if (Attrs & ObjCPropertyDecl::OBJC_PR_copy)
1566 if (Attrs & ObjCPropertyDecl::OBJC_PR_nonatomic)
1568 if (Attrs & ObjCPropertyDecl::OBJC_PR_atomic)
1570 if (Attrs & ObjCPropertyDecl::OBJC_PR_weak)
1572 if (Attrs & ObjCPropertyDecl::OBJC_PR_strong)
1574 if (Attrs & ObjCPropertyDecl::OBJC_PR_unsafe_unretained)
1575 OS << " unsafe_unretained";
1576 if (Attrs & ObjCPropertyDecl::OBJC_PR_getter)
1577 dumpDeclRef(D->getGetterMethodDecl(), "getter");
1578 if (Attrs & ObjCPropertyDecl::OBJC_PR_setter)
1579 dumpDeclRef(D->getSetterMethodDecl(), "setter");
1583 void ASTDumper::VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D) {
1584 dumpName(D->getPropertyDecl());
1585 if (D->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize)
1586 OS << " synthesize";
1589 dumpDeclRef(D->getPropertyDecl());
1590 dumpDeclRef(D->getPropertyIvarDecl());
1593 void ASTDumper::VisitBlockDecl(const BlockDecl *D) {
1594 for (auto I : D->params())
1597 if (D->isVariadic())
1598 dumpChild([=]{ OS << "..."; });
1600 if (D->capturesCXXThis())
1601 dumpChild([=]{ OS << "capture this"; });
1603 for (const auto &I : D->captures()) {
1610 if (I.getVariable()) {
1612 dumpBareDeclRef(I.getVariable());
1614 if (I.hasCopyExpr())
1615 dumpStmt(I.getCopyExpr());
1618 dumpStmt(D->getBody());
1621 //===----------------------------------------------------------------------===//
1622 // Stmt dumping methods.
1623 //===----------------------------------------------------------------------===//
1625 void ASTDumper::dumpStmt(const Stmt *S) {
1628 ColorScope Color(*this, NullColor);
1633 if (const DeclStmt *DS = dyn_cast<DeclStmt>(S)) {
1638 ConstStmtVisitor<ASTDumper>::Visit(S);
1640 for (const Stmt *SubStmt : S->children())
1645 void ASTDumper::VisitStmt(const Stmt *Node) {
1647 ColorScope Color(*this, StmtColor);
1648 OS << Node->getStmtClassName();
1651 dumpSourceRange(Node->getSourceRange());
1654 void ASTDumper::VisitDeclStmt(const DeclStmt *Node) {
1656 for (DeclStmt::const_decl_iterator I = Node->decl_begin(),
1657 E = Node->decl_end();
1662 void ASTDumper::VisitAttributedStmt(const AttributedStmt *Node) {
1664 for (ArrayRef<const Attr *>::iterator I = Node->getAttrs().begin(),
1665 E = Node->getAttrs().end();
1670 void ASTDumper::VisitLabelStmt(const LabelStmt *Node) {
1672 OS << " '" << Node->getName() << "'";
1675 void ASTDumper::VisitGotoStmt(const GotoStmt *Node) {
1677 OS << " '" << Node->getLabel()->getName() << "'";
1678 dumpPointer(Node->getLabel());
1681 void ASTDumper::VisitCXXCatchStmt(const CXXCatchStmt *Node) {
1683 dumpDecl(Node->getExceptionDecl());
1686 //===----------------------------------------------------------------------===//
1687 // Expr dumping methods.
1688 //===----------------------------------------------------------------------===//
1690 void ASTDumper::VisitExpr(const Expr *Node) {
1692 dumpType(Node->getType());
1695 ColorScope Color(*this, ValueKindColor);
1696 switch (Node->getValueKind()) {
1709 ColorScope Color(*this, ObjectKindColor);
1710 switch (Node->getObjectKind()) {
1716 case OK_ObjCProperty:
1717 OS << " objcproperty";
1719 case OK_ObjCSubscript:
1720 OS << " objcsubscript";
1722 case OK_VectorComponent:
1723 OS << " vectorcomponent";
1729 static void dumpBasePath(raw_ostream &OS, const CastExpr *Node) {
1730 if (Node->path_empty())
1735 for (CastExpr::path_const_iterator I = Node->path_begin(),
1736 E = Node->path_end();
1738 const CXXBaseSpecifier *Base = *I;
1742 const CXXRecordDecl *RD =
1743 cast<CXXRecordDecl>(Base->getType()->getAs<RecordType>()->getDecl());
1745 if (Base->isVirtual())
1747 OS << RD->getName();
1754 void ASTDumper::VisitCastExpr(const CastExpr *Node) {
1758 ColorScope Color(*this, CastColor);
1759 OS << Node->getCastKindName();
1761 dumpBasePath(OS, Node);
1765 void ASTDumper::VisitDeclRefExpr(const DeclRefExpr *Node) {
1769 dumpBareDeclRef(Node->getDecl());
1770 if (Node->getDecl() != Node->getFoundDecl()) {
1772 dumpBareDeclRef(Node->getFoundDecl());
1777 void ASTDumper::VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *Node) {
1780 if (!Node->requiresADL())
1782 OS << "ADL) = '" << Node->getName() << '\'';
1784 UnresolvedLookupExpr::decls_iterator
1785 I = Node->decls_begin(), E = Node->decls_end();
1792 void ASTDumper::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *Node) {
1796 ColorScope Color(*this, DeclKindNameColor);
1797 OS << " " << Node->getDecl()->getDeclKindName() << "Decl";
1799 OS << "='" << *Node->getDecl() << "'";
1800 dumpPointer(Node->getDecl());
1801 if (Node->isFreeIvar())
1802 OS << " isFreeIvar";
1805 void ASTDumper::VisitPredefinedExpr(const PredefinedExpr *Node) {
1807 OS << " " << PredefinedExpr::getIdentTypeName(Node->getIdentType());
1810 void ASTDumper::VisitCharacterLiteral(const CharacterLiteral *Node) {
1812 ColorScope Color(*this, ValueColor);
1813 OS << " " << Node->getValue();
1816 void ASTDumper::VisitIntegerLiteral(const IntegerLiteral *Node) {
1819 bool isSigned = Node->getType()->isSignedIntegerType();
1820 ColorScope Color(*this, ValueColor);
1821 OS << " " << Node->getValue().toString(10, isSigned);
1824 void ASTDumper::VisitFloatingLiteral(const FloatingLiteral *Node) {
1826 ColorScope Color(*this, ValueColor);
1827 OS << " " << Node->getValueAsApproximateDouble();
1830 void ASTDumper::VisitStringLiteral(const StringLiteral *Str) {
1832 ColorScope Color(*this, ValueColor);
1834 Str->outputString(OS);
1837 void ASTDumper::VisitInitListExpr(const InitListExpr *ILE) {
1839 if (auto *Filler = ILE->getArrayFiller()) {
1841 OS << "array filler";
1845 if (auto *Field = ILE->getInitializedFieldInUnion()) {
1847 dumpBareDeclRef(Field);
1851 void ASTDumper::VisitUnaryOperator(const UnaryOperator *Node) {
1853 OS << " " << (Node->isPostfix() ? "postfix" : "prefix")
1854 << " '" << UnaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
1857 void ASTDumper::VisitUnaryExprOrTypeTraitExpr(
1858 const UnaryExprOrTypeTraitExpr *Node) {
1860 switch(Node->getKind()) {
1870 case UETT_OpenMPRequiredSimdAlign:
1871 OS << " __builtin_omp_required_simd_align";
1874 if (Node->isArgumentType())
1875 dumpType(Node->getArgumentType());
1878 void ASTDumper::VisitMemberExpr(const MemberExpr *Node) {
1880 OS << " " << (Node->isArrow() ? "->" : ".") << *Node->getMemberDecl();
1881 dumpPointer(Node->getMemberDecl());
1884 void ASTDumper::VisitExtVectorElementExpr(const ExtVectorElementExpr *Node) {
1886 OS << " " << Node->getAccessor().getNameStart();
1889 void ASTDumper::VisitBinaryOperator(const BinaryOperator *Node) {
1891 OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
1894 void ASTDumper::VisitCompoundAssignOperator(
1895 const CompoundAssignOperator *Node) {
1897 OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode())
1898 << "' ComputeLHSTy=";
1899 dumpBareType(Node->getComputationLHSType());
1900 OS << " ComputeResultTy=";
1901 dumpBareType(Node->getComputationResultType());
1904 void ASTDumper::VisitBlockExpr(const BlockExpr *Node) {
1906 dumpDecl(Node->getBlockDecl());
1909 void ASTDumper::VisitOpaqueValueExpr(const OpaqueValueExpr *Node) {
1912 if (Expr *Source = Node->getSourceExpr())
1918 void ASTDumper::VisitAddrLabelExpr(const AddrLabelExpr *Node) {
1920 OS << " " << Node->getLabel()->getName();
1921 dumpPointer(Node->getLabel());
1924 //===----------------------------------------------------------------------===//
1926 //===----------------------------------------------------------------------===//
1928 void ASTDumper::VisitCXXNamedCastExpr(const CXXNamedCastExpr *Node) {
1930 OS << " " << Node->getCastName()
1931 << "<" << Node->getTypeAsWritten().getAsString() << ">"
1932 << " <" << Node->getCastKindName();
1933 dumpBasePath(OS, Node);
1937 void ASTDumper::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *Node) {
1939 OS << " " << (Node->getValue() ? "true" : "false");
1942 void ASTDumper::VisitCXXThisExpr(const CXXThisExpr *Node) {
1947 void ASTDumper::VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *Node) {
1949 OS << " functional cast to " << Node->getTypeAsWritten().getAsString()
1950 << " <" << Node->getCastKindName() << ">";
1953 void ASTDumper::VisitCXXConstructExpr(const CXXConstructExpr *Node) {
1955 CXXConstructorDecl *Ctor = Node->getConstructor();
1956 dumpType(Ctor->getType());
1957 if (Node->isElidable())
1959 if (Node->requiresZeroInitialization())
1963 void ASTDumper::VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *Node) {
1966 dumpCXXTemporary(Node->getTemporary());
1969 void ASTDumper::VisitCXXNewExpr(const CXXNewExpr *Node) {
1971 if (Node->isGlobalNew())
1973 if (Node->isArray())
1975 if (Node->getOperatorNew()) {
1977 dumpBareDeclRef(Node->getOperatorNew());
1979 // We could dump the deallocation function used in case of error, but it's
1980 // usually not that interesting.
1983 void ASTDumper::VisitCXXDeleteExpr(const CXXDeleteExpr *Node) {
1985 if (Node->isGlobalDelete())
1987 if (Node->isArrayForm())
1989 if (Node->getOperatorDelete()) {
1991 dumpBareDeclRef(Node->getOperatorDelete());
1996 ASTDumper::VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *Node) {
1998 if (const ValueDecl *VD = Node->getExtendingDecl()) {
1999 OS << " extended by ";
2000 dumpBareDeclRef(VD);
2004 void ASTDumper::VisitExprWithCleanups(const ExprWithCleanups *Node) {
2006 for (unsigned i = 0, e = Node->getNumObjects(); i != e; ++i)
2007 dumpDeclRef(Node->getObject(i), "cleanup");
2010 void ASTDumper::dumpCXXTemporary(const CXXTemporary *Temporary) {
2011 OS << "(CXXTemporary";
2012 dumpPointer(Temporary);
2016 void ASTDumper::VisitSizeOfPackExpr(const SizeOfPackExpr *Node) {
2018 dumpPointer(Node->getPack());
2019 dumpName(Node->getPack());
2023 //===----------------------------------------------------------------------===//
2024 // Obj-C Expressions
2025 //===----------------------------------------------------------------------===//
2027 void ASTDumper::VisitObjCMessageExpr(const ObjCMessageExpr *Node) {
2030 Node->getSelector().print(OS);
2031 switch (Node->getReceiverKind()) {
2032 case ObjCMessageExpr::Instance:
2035 case ObjCMessageExpr::Class:
2037 dumpBareType(Node->getClassReceiver());
2040 case ObjCMessageExpr::SuperInstance:
2041 OS << " super (instance)";
2044 case ObjCMessageExpr::SuperClass:
2045 OS << " super (class)";
2050 void ASTDumper::VisitObjCBoxedExpr(const ObjCBoxedExpr *Node) {
2053 Node->getBoxingMethod()->getSelector().print(OS);
2056 void ASTDumper::VisitObjCAtCatchStmt(const ObjCAtCatchStmt *Node) {
2058 if (const VarDecl *CatchParam = Node->getCatchParamDecl())
2059 dumpDecl(CatchParam);
2064 void ASTDumper::VisitObjCEncodeExpr(const ObjCEncodeExpr *Node) {
2066 dumpType(Node->getEncodedType());
2069 void ASTDumper::VisitObjCSelectorExpr(const ObjCSelectorExpr *Node) {
2073 Node->getSelector().print(OS);
2076 void ASTDumper::VisitObjCProtocolExpr(const ObjCProtocolExpr *Node) {
2079 OS << ' ' << *Node->getProtocol();
2082 void ASTDumper::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *Node) {
2084 if (Node->isImplicitProperty()) {
2085 OS << " Kind=MethodRef Getter=\"";
2086 if (Node->getImplicitPropertyGetter())
2087 Node->getImplicitPropertyGetter()->getSelector().print(OS);
2091 OS << "\" Setter=\"";
2092 if (ObjCMethodDecl *Setter = Node->getImplicitPropertySetter())
2093 Setter->getSelector().print(OS);
2098 OS << " Kind=PropertyRef Property=\"" << *Node->getExplicitProperty() <<'"';
2101 if (Node->isSuperReceiver())
2104 OS << " Messaging=";
2105 if (Node->isMessagingGetter() && Node->isMessagingSetter())
2106 OS << "Getter&Setter";
2107 else if (Node->isMessagingGetter())
2109 else if (Node->isMessagingSetter())
2113 void ASTDumper::VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *Node) {
2115 if (Node->isArraySubscriptRefExpr())
2116 OS << " Kind=ArraySubscript GetterForArray=\"";
2118 OS << " Kind=DictionarySubscript GetterForDictionary=\"";
2119 if (Node->getAtIndexMethodDecl())
2120 Node->getAtIndexMethodDecl()->getSelector().print(OS);
2124 if (Node->isArraySubscriptRefExpr())
2125 OS << "\" SetterForArray=\"";
2127 OS << "\" SetterForDictionary=\"";
2128 if (Node->setAtIndexMethodDecl())
2129 Node->setAtIndexMethodDecl()->getSelector().print(OS);
2134 void ASTDumper::VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *Node) {
2136 OS << " " << (Node->getValue() ? "__objc_yes" : "__objc_no");
2139 //===----------------------------------------------------------------------===//
2141 //===----------------------------------------------------------------------===//
2143 const char *ASTDumper::getCommandName(unsigned CommandID) {
2145 return Traits->getCommandInfo(CommandID)->Name;
2146 const CommandInfo *Info = CommandTraits::getBuiltinCommandInfo(CommandID);
2149 return "<not a builtin command>";
2152 void ASTDumper::dumpFullComment(const FullComment *C) {
2161 void ASTDumper::dumpComment(const Comment *C) {
2164 ColorScope Color(*this, NullColor);
2170 ColorScope Color(*this, CommentColor);
2171 OS << C->getCommentKindName();
2174 dumpSourceRange(C->getSourceRange());
2175 ConstCommentVisitor<ASTDumper>::visit(C);
2176 for (Comment::child_iterator I = C->child_begin(), E = C->child_end();
2182 void ASTDumper::visitTextComment(const TextComment *C) {
2183 OS << " Text=\"" << C->getText() << "\"";
2186 void ASTDumper::visitInlineCommandComment(const InlineCommandComment *C) {
2187 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\"";
2188 switch (C->getRenderKind()) {
2189 case InlineCommandComment::RenderNormal:
2190 OS << " RenderNormal";
2192 case InlineCommandComment::RenderBold:
2193 OS << " RenderBold";
2195 case InlineCommandComment::RenderMonospaced:
2196 OS << " RenderMonospaced";
2198 case InlineCommandComment::RenderEmphasized:
2199 OS << " RenderEmphasized";
2203 for (unsigned i = 0, e = C->getNumArgs(); i != e; ++i)
2204 OS << " Arg[" << i << "]=\"" << C->getArgText(i) << "\"";
2207 void ASTDumper::visitHTMLStartTagComment(const HTMLStartTagComment *C) {
2208 OS << " Name=\"" << C->getTagName() << "\"";
2209 if (C->getNumAttrs() != 0) {
2211 for (unsigned i = 0, e = C->getNumAttrs(); i != e; ++i) {
2212 const HTMLStartTagComment::Attribute &Attr = C->getAttr(i);
2213 OS << " \"" << Attr.Name << "=\"" << Attr.Value << "\"";
2216 if (C->isSelfClosing())
2217 OS << " SelfClosing";
2220 void ASTDumper::visitHTMLEndTagComment(const HTMLEndTagComment *C) {
2221 OS << " Name=\"" << C->getTagName() << "\"";
2224 void ASTDumper::visitBlockCommandComment(const BlockCommandComment *C) {
2225 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\"";
2226 for (unsigned i = 0, e = C->getNumArgs(); i != e; ++i)
2227 OS << " Arg[" << i << "]=\"" << C->getArgText(i) << "\"";
2230 void ASTDumper::visitParamCommandComment(const ParamCommandComment *C) {
2231 OS << " " << ParamCommandComment::getDirectionAsString(C->getDirection());
2233 if (C->isDirectionExplicit())
2234 OS << " explicitly";
2236 OS << " implicitly";
2238 if (C->hasParamName()) {
2239 if (C->isParamIndexValid())
2240 OS << " Param=\"" << C->getParamName(FC) << "\"";
2242 OS << " Param=\"" << C->getParamNameAsWritten() << "\"";
2245 if (C->isParamIndexValid() && !C->isVarArgParam())
2246 OS << " ParamIndex=" << C->getParamIndex();
2249 void ASTDumper::visitTParamCommandComment(const TParamCommandComment *C) {
2250 if (C->hasParamName()) {
2251 if (C->isPositionValid())
2252 OS << " Param=\"" << C->getParamName(FC) << "\"";
2254 OS << " Param=\"" << C->getParamNameAsWritten() << "\"";
2257 if (C->isPositionValid()) {
2258 OS << " Position=<";
2259 for (unsigned i = 0, e = C->getDepth(); i != e; ++i) {
2260 OS << C->getIndex(i);
2268 void ASTDumper::visitVerbatimBlockComment(const VerbatimBlockComment *C) {
2269 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\""
2270 " CloseName=\"" << C->getCloseName() << "\"";
2273 void ASTDumper::visitVerbatimBlockLineComment(
2274 const VerbatimBlockLineComment *C) {
2275 OS << " Text=\"" << C->getText() << "\"";
2278 void ASTDumper::visitVerbatimLineComment(const VerbatimLineComment *C) {
2279 OS << " Text=\"" << C->getText() << "\"";
2282 //===----------------------------------------------------------------------===//
2283 // Type method implementations
2284 //===----------------------------------------------------------------------===//
2286 void QualType::dump(const char *msg) const {
2288 llvm::errs() << msg << ": ";
2292 LLVM_DUMP_METHOD void QualType::dump() const {
2293 ASTDumper Dumper(llvm::errs(), nullptr, nullptr);
2294 Dumper.dumpTypeAsChild(*this);
2297 LLVM_DUMP_METHOD void Type::dump() const { QualType(this, 0).dump(); }
2299 //===----------------------------------------------------------------------===//
2300 // Decl method implementations
2301 //===----------------------------------------------------------------------===//
2303 LLVM_DUMP_METHOD void Decl::dump() const { dump(llvm::errs()); }
2305 LLVM_DUMP_METHOD void Decl::dump(raw_ostream &OS) const {
2306 ASTDumper P(OS, &getASTContext().getCommentCommandTraits(),
2307 &getASTContext().getSourceManager());
2311 LLVM_DUMP_METHOD void Decl::dumpColor() const {
2312 ASTDumper P(llvm::errs(), &getASTContext().getCommentCommandTraits(),
2313 &getASTContext().getSourceManager(), /*ShowColors*/true);
2317 LLVM_DUMP_METHOD void DeclContext::dumpLookups() const {
2318 dumpLookups(llvm::errs());
2321 LLVM_DUMP_METHOD void DeclContext::dumpLookups(raw_ostream &OS,
2322 bool DumpDecls) const {
2323 const DeclContext *DC = this;
2324 while (!DC->isTranslationUnit())
2325 DC = DC->getParent();
2326 ASTContext &Ctx = cast<TranslationUnitDecl>(DC)->getASTContext();
2327 ASTDumper P(OS, &Ctx.getCommentCommandTraits(), &Ctx.getSourceManager());
2328 P.dumpLookups(this, DumpDecls);
2331 //===----------------------------------------------------------------------===//
2332 // Stmt method implementations
2333 //===----------------------------------------------------------------------===//
2335 LLVM_DUMP_METHOD void Stmt::dump(SourceManager &SM) const {
2336 dump(llvm::errs(), SM);
2339 LLVM_DUMP_METHOD void Stmt::dump(raw_ostream &OS, SourceManager &SM) const {
2340 ASTDumper P(OS, nullptr, &SM);
2344 LLVM_DUMP_METHOD void Stmt::dump(raw_ostream &OS) const {
2345 ASTDumper P(OS, nullptr, nullptr);
2349 LLVM_DUMP_METHOD void Stmt::dump() const {
2350 ASTDumper P(llvm::errs(), nullptr, nullptr);
2354 LLVM_DUMP_METHOD void Stmt::dumpColor() const {
2355 ASTDumper P(llvm::errs(), nullptr, nullptr, /*ShowColors*/true);
2359 //===----------------------------------------------------------------------===//
2360 // Comment method implementations
2361 //===----------------------------------------------------------------------===//
2363 LLVM_DUMP_METHOD void Comment::dump() const {
2364 dump(llvm::errs(), nullptr, nullptr);
2367 LLVM_DUMP_METHOD void Comment::dump(const ASTContext &Context) const {
2368 dump(llvm::errs(), &Context.getCommentCommandTraits(),
2369 &Context.getSourceManager());
2372 void Comment::dump(raw_ostream &OS, const CommandTraits *Traits,
2373 const SourceManager *SM) const {
2374 const FullComment *FC = dyn_cast<FullComment>(this);
2375 ASTDumper D(OS, Traits, SM);
2376 D.dumpFullComment(FC);
2379 LLVM_DUMP_METHOD void Comment::dumpColor() const {
2380 const FullComment *FC = dyn_cast<FullComment>(this);
2381 ASTDumper D(llvm::errs(), nullptr, nullptr, /*ShowColors*/true);
2382 D.dumpFullComment(FC);