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/Builtins.h"
25 #include "clang/Basic/Module.h"
26 #include "clang/Basic/SourceManager.h"
27 #include "clang/Sema/LocInfoType.h"
28 #include "llvm/Support/raw_ostream.h"
29 using namespace clang;
30 using namespace clang::comments;
32 //===----------------------------------------------------------------------===//
34 //===----------------------------------------------------------------------===//
37 // Colors used for various parts of the AST dump
38 // Do not use bold yellow for any text. It is hard to read on white screens.
40 struct TerminalColor {
41 raw_ostream::Colors Color;
47 // Bold Green - DeclKindNameColor, UndeserializedColor
48 // Yellow - AddressColor, LocationColor
49 // Blue - CommentColor, NullColor, IndentColor
50 // Bold Blue - AttrColor
51 // Bold Magenta - StmtColor
52 // Cyan - ValueKindColor, ObjectKindColor
53 // Bold Cyan - ValueColor, DeclNameColor
55 // Decl kind names (VarDecl, FunctionDecl, etc)
56 static const TerminalColor DeclKindNameColor = { raw_ostream::GREEN, true };
57 // Attr names (CleanupAttr, GuardedByAttr, etc)
58 static const TerminalColor AttrColor = { raw_ostream::BLUE, true };
59 // Statement names (DeclStmt, ImplicitCastExpr, etc)
60 static const TerminalColor StmtColor = { raw_ostream::MAGENTA, true };
61 // Comment names (FullComment, ParagraphComment, TextComment, etc)
62 static const TerminalColor CommentColor = { raw_ostream::BLUE, false };
64 // Type names (int, float, etc, plus user defined types)
65 static const TerminalColor TypeColor = { raw_ostream::GREEN, false };
68 static const TerminalColor AddressColor = { raw_ostream::YELLOW, false };
70 static const TerminalColor LocationColor = { raw_ostream::YELLOW, false };
73 static const TerminalColor ValueKindColor = { raw_ostream::CYAN, false };
74 // bitfield/objcproperty/objcsubscript/vectorcomponent
75 static const TerminalColor ObjectKindColor = { raw_ostream::CYAN, false };
78 static const TerminalColor NullColor = { raw_ostream::BLUE, false };
80 // Undeserialized entities
81 static const TerminalColor UndeserializedColor = { raw_ostream::GREEN, true };
83 // CastKind from CastExpr's
84 static const TerminalColor CastColor = { raw_ostream::RED, false };
86 // Value of the statement
87 static const TerminalColor ValueColor = { raw_ostream::CYAN, true };
89 static const TerminalColor DeclNameColor = { raw_ostream::CYAN, true };
91 // Indents ( `, -. | )
92 static const TerminalColor IndentColor = { raw_ostream::BLUE, false };
95 : public ConstDeclVisitor<ASTDumper>, public ConstStmtVisitor<ASTDumper>,
96 public ConstCommentVisitor<ASTDumper>, public TypeVisitor<ASTDumper> {
98 const CommandTraits *Traits;
99 const SourceManager *SM;
101 /// Pending[i] is an action to dump an entity at level i.
102 llvm::SmallVector<std::function<void(bool isLastChild)>, 32> Pending;
104 /// Indicates whether we're at the top level.
107 /// Indicates if we're handling the first child after entering a new depth.
110 /// Prefix for currently-being-dumped entity.
113 /// Keep track of the last location we print out so that we can
114 /// print out deltas from then on out.
115 const char *LastLocFilename;
116 unsigned LastLocLine;
118 /// The \c FullComment parent of the comment being dumped.
119 const FullComment *FC;
123 /// Dump a child of the current node.
124 template<typename Fn> void dumpChild(Fn doDumpChild) {
125 // If we're at the top level, there's nothing interesting to do; just
130 while (!Pending.empty()) {
131 Pending.back()(true);
140 const FullComment *OrigFC = FC;
141 auto dumpWithIndent = [this, doDumpChild, OrigFC](bool isLastChild) {
142 // Print out the appropriate tree structure and work out the prefix for
143 // children of this node. For instance:
147 // | `-C Prefix = "| "
149 // |-E Prefix = " | "
153 // Note that the first level gets no prefix.
156 ColorScope Color(*this, IndentColor);
157 OS << Prefix << (isLastChild ? '`' : '|') << '-';
158 this->Prefix.push_back(isLastChild ? ' ' : '|');
159 this->Prefix.push_back(' ');
163 unsigned Depth = Pending.size();
168 // If any children are left, they're the last at their nesting level.
169 // Dump those ones out now.
170 while (Depth < Pending.size()) {
171 Pending.back()(true);
172 this->Pending.pop_back();
175 // Restore the old prefix.
176 this->Prefix.resize(Prefix.size() - 2);
180 Pending.push_back(std::move(dumpWithIndent));
182 Pending.back()(false);
183 Pending.back() = std::move(dumpWithIndent);
191 ColorScope(ASTDumper &Dumper, TerminalColor Color)
193 if (Dumper.ShowColors)
194 Dumper.OS.changeColor(Color.Color, Color.Bold);
197 if (Dumper.ShowColors)
198 Dumper.OS.resetColor();
203 ASTDumper(raw_ostream &OS, const CommandTraits *Traits,
204 const SourceManager *SM)
205 : OS(OS), Traits(Traits), SM(SM), TopLevel(true), FirstChild(true),
206 LastLocFilename(""), LastLocLine(~0U), FC(nullptr),
207 ShowColors(SM && SM->getDiagnostics().getShowColors()) { }
209 ASTDumper(raw_ostream &OS, const CommandTraits *Traits,
210 const SourceManager *SM, bool ShowColors)
211 : OS(OS), Traits(Traits), SM(SM), TopLevel(true), FirstChild(true),
212 LastLocFilename(""), LastLocLine(~0U),
213 ShowColors(ShowColors) { }
215 void dumpDecl(const Decl *D);
216 void dumpStmt(const Stmt *S);
217 void dumpFullComment(const FullComment *C);
220 void dumpPointer(const void *Ptr);
221 void dumpSourceRange(SourceRange R);
222 void dumpLocation(SourceLocation Loc);
223 void dumpBareType(QualType T, bool Desugar = true);
224 void dumpType(QualType T);
225 void dumpTypeAsChild(QualType T);
226 void dumpTypeAsChild(const Type *T);
227 void dumpBareDeclRef(const Decl *Node);
228 void dumpDeclRef(const Decl *Node, const char *Label = nullptr);
229 void dumpName(const NamedDecl *D);
230 bool hasNodes(const DeclContext *DC);
231 void dumpDeclContext(const DeclContext *DC);
232 void dumpLookups(const DeclContext *DC, bool DumpDecls);
233 void dumpAttr(const Attr *A);
236 void dumpAccessSpecifier(AccessSpecifier AS);
237 void dumpCXXCtorInitializer(const CXXCtorInitializer *Init);
238 void dumpTemplateParameters(const TemplateParameterList *TPL);
239 void dumpTemplateArgumentListInfo(const TemplateArgumentListInfo &TALI);
240 void dumpTemplateArgumentLoc(const TemplateArgumentLoc &A);
241 void dumpTemplateArgumentList(const TemplateArgumentList &TAL);
242 void dumpTemplateArgument(const TemplateArgument &A,
243 SourceRange R = SourceRange());
245 // Objective-C utilities.
246 void dumpObjCTypeParamList(const ObjCTypeParamList *typeParams);
249 void VisitComplexType(const ComplexType *T) {
250 dumpTypeAsChild(T->getElementType());
252 void VisitPointerType(const PointerType *T) {
253 dumpTypeAsChild(T->getPointeeType());
255 void VisitBlockPointerType(const BlockPointerType *T) {
256 dumpTypeAsChild(T->getPointeeType());
258 void VisitReferenceType(const ReferenceType *T) {
259 dumpTypeAsChild(T->getPointeeType());
261 void VisitRValueReferenceType(const ReferenceType *T) {
262 if (T->isSpelledAsLValue())
263 OS << " written as lvalue reference";
264 VisitReferenceType(T);
266 void VisitMemberPointerType(const MemberPointerType *T) {
267 dumpTypeAsChild(T->getClass());
268 dumpTypeAsChild(T->getPointeeType());
270 void VisitArrayType(const ArrayType *T) {
271 switch (T->getSizeModifier()) {
272 case ArrayType::Normal: break;
273 case ArrayType::Static: OS << " static"; break;
274 case ArrayType::Star: OS << " *"; break;
276 OS << " " << T->getIndexTypeQualifiers().getAsString();
277 dumpTypeAsChild(T->getElementType());
279 void VisitConstantArrayType(const ConstantArrayType *T) {
280 OS << " " << T->getSize();
283 void VisitVariableArrayType(const VariableArrayType *T) {
285 dumpSourceRange(T->getBracketsRange());
287 dumpStmt(T->getSizeExpr());
289 void VisitDependentSizedArrayType(const DependentSizedArrayType *T) {
292 dumpSourceRange(T->getBracketsRange());
293 dumpStmt(T->getSizeExpr());
295 void VisitDependentSizedExtVectorType(
296 const DependentSizedExtVectorType *T) {
298 dumpLocation(T->getAttributeLoc());
299 dumpTypeAsChild(T->getElementType());
300 dumpStmt(T->getSizeExpr());
302 void VisitVectorType(const VectorType *T) {
303 switch (T->getVectorKind()) {
304 case VectorType::GenericVector: break;
305 case VectorType::AltiVecVector: OS << " altivec"; break;
306 case VectorType::AltiVecPixel: OS << " altivec pixel"; break;
307 case VectorType::AltiVecBool: OS << " altivec bool"; break;
308 case VectorType::NeonVector: OS << " neon"; break;
309 case VectorType::NeonPolyVector: OS << " neon poly"; break;
311 OS << " " << T->getNumElements();
312 dumpTypeAsChild(T->getElementType());
314 void VisitFunctionType(const FunctionType *T) {
315 auto EI = T->getExtInfo();
316 if (EI.getNoReturn()) OS << " noreturn";
317 if (EI.getProducesResult()) OS << " produces_result";
318 if (EI.getHasRegParm()) OS << " regparm " << EI.getRegParm();
319 OS << " " << FunctionType::getNameForCallConv(EI.getCC());
320 dumpTypeAsChild(T->getReturnType());
322 void VisitFunctionProtoType(const FunctionProtoType *T) {
323 auto EPI = T->getExtProtoInfo();
324 if (EPI.HasTrailingReturn) OS << " trailing_return";
325 if (T->isConst()) OS << " const";
326 if (T->isVolatile()) OS << " volatile";
327 if (T->isRestrict()) OS << " restrict";
328 switch (EPI.RefQualifier) {
330 case RQ_LValue: OS << " &"; break;
331 case RQ_RValue: OS << " &&"; break;
333 // FIXME: Exception specification.
334 // FIXME: Consumed parameters.
335 VisitFunctionType(T);
336 for (QualType PT : T->getParamTypes())
339 dumpChild([=] { OS << "..."; });
341 void VisitUnresolvedUsingType(const UnresolvedUsingType *T) {
342 dumpDeclRef(T->getDecl());
344 void VisitTypedefType(const TypedefType *T) {
345 dumpDeclRef(T->getDecl());
347 void VisitTypeOfExprType(const TypeOfExprType *T) {
348 dumpStmt(T->getUnderlyingExpr());
350 void VisitDecltypeType(const DecltypeType *T) {
351 dumpStmt(T->getUnderlyingExpr());
353 void VisitUnaryTransformType(const UnaryTransformType *T) {
354 switch (T->getUTTKind()) {
355 case UnaryTransformType::EnumUnderlyingType:
356 OS << " underlying_type";
359 dumpTypeAsChild(T->getBaseType());
361 void VisitTagType(const TagType *T) {
362 dumpDeclRef(T->getDecl());
364 void VisitAttributedType(const AttributedType *T) {
366 dumpTypeAsChild(T->getModifiedType());
368 void VisitTemplateTypeParmType(const TemplateTypeParmType *T) {
369 OS << " depth " << T->getDepth() << " index " << T->getIndex();
370 if (T->isParameterPack()) OS << " pack";
371 dumpDeclRef(T->getDecl());
373 void VisitSubstTemplateTypeParmType(const SubstTemplateTypeParmType *T) {
374 dumpTypeAsChild(T->getReplacedParameter());
376 void VisitSubstTemplateTypeParmPackType(
377 const SubstTemplateTypeParmPackType *T) {
378 dumpTypeAsChild(T->getReplacedParameter());
379 dumpTemplateArgument(T->getArgumentPack());
381 void VisitAutoType(const AutoType *T) {
382 if (T->isDecltypeAuto()) OS << " decltype(auto)";
386 void VisitTemplateSpecializationType(const TemplateSpecializationType *T) {
387 if (T->isTypeAlias()) OS << " alias";
388 OS << " "; T->getTemplateName().dump(OS);
390 dumpTemplateArgument(Arg);
391 if (T->isTypeAlias())
392 dumpTypeAsChild(T->getAliasedType());
394 void VisitInjectedClassNameType(const InjectedClassNameType *T) {
395 dumpDeclRef(T->getDecl());
397 void VisitObjCInterfaceType(const ObjCInterfaceType *T) {
398 dumpDeclRef(T->getDecl());
400 void VisitObjCObjectPointerType(const ObjCObjectPointerType *T) {
401 dumpTypeAsChild(T->getPointeeType());
403 void VisitAtomicType(const AtomicType *T) {
404 dumpTypeAsChild(T->getValueType());
406 void VisitAdjustedType(const AdjustedType *T) {
407 dumpTypeAsChild(T->getOriginalType());
409 void VisitPackExpansionType(const PackExpansionType *T) {
410 if (auto N = T->getNumExpansions()) OS << " expansions " << *N;
412 dumpTypeAsChild(T->getPattern());
414 // FIXME: ElaboratedType, DependentNameType,
415 // DependentTemplateSpecializationType, ObjCObjectType
418 void VisitLabelDecl(const LabelDecl *D);
419 void VisitTypedefDecl(const TypedefDecl *D);
420 void VisitEnumDecl(const EnumDecl *D);
421 void VisitRecordDecl(const RecordDecl *D);
422 void VisitEnumConstantDecl(const EnumConstantDecl *D);
423 void VisitIndirectFieldDecl(const IndirectFieldDecl *D);
424 void VisitFunctionDecl(const FunctionDecl *D);
425 void VisitFieldDecl(const FieldDecl *D);
426 void VisitVarDecl(const VarDecl *D);
427 void VisitFileScopeAsmDecl(const FileScopeAsmDecl *D);
428 void VisitImportDecl(const ImportDecl *D);
431 void VisitNamespaceDecl(const NamespaceDecl *D);
432 void VisitUsingDirectiveDecl(const UsingDirectiveDecl *D);
433 void VisitNamespaceAliasDecl(const NamespaceAliasDecl *D);
434 void VisitTypeAliasDecl(const TypeAliasDecl *D);
435 void VisitTypeAliasTemplateDecl(const TypeAliasTemplateDecl *D);
436 void VisitCXXRecordDecl(const CXXRecordDecl *D);
437 void VisitStaticAssertDecl(const StaticAssertDecl *D);
438 template<typename SpecializationDecl>
439 void VisitTemplateDeclSpecialization(const SpecializationDecl *D,
440 bool DumpExplicitInst,
442 template<typename TemplateDecl>
443 void VisitTemplateDecl(const TemplateDecl *D, bool DumpExplicitInst);
444 void VisitFunctionTemplateDecl(const FunctionTemplateDecl *D);
445 void VisitClassTemplateDecl(const ClassTemplateDecl *D);
446 void VisitClassTemplateSpecializationDecl(
447 const ClassTemplateSpecializationDecl *D);
448 void VisitClassTemplatePartialSpecializationDecl(
449 const ClassTemplatePartialSpecializationDecl *D);
450 void VisitClassScopeFunctionSpecializationDecl(
451 const ClassScopeFunctionSpecializationDecl *D);
452 void VisitBuiltinTemplateDecl(const BuiltinTemplateDecl *D);
453 void VisitVarTemplateDecl(const VarTemplateDecl *D);
454 void VisitVarTemplateSpecializationDecl(
455 const VarTemplateSpecializationDecl *D);
456 void VisitVarTemplatePartialSpecializationDecl(
457 const VarTemplatePartialSpecializationDecl *D);
458 void VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D);
459 void VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D);
460 void VisitTemplateTemplateParmDecl(const TemplateTemplateParmDecl *D);
461 void VisitUsingDecl(const UsingDecl *D);
462 void VisitUnresolvedUsingTypenameDecl(const UnresolvedUsingTypenameDecl *D);
463 void VisitUnresolvedUsingValueDecl(const UnresolvedUsingValueDecl *D);
464 void VisitUsingShadowDecl(const UsingShadowDecl *D);
465 void VisitLinkageSpecDecl(const LinkageSpecDecl *D);
466 void VisitAccessSpecDecl(const AccessSpecDecl *D);
467 void VisitFriendDecl(const FriendDecl *D);
470 void VisitObjCIvarDecl(const ObjCIvarDecl *D);
471 void VisitObjCMethodDecl(const ObjCMethodDecl *D);
472 void VisitObjCTypeParamDecl(const ObjCTypeParamDecl *D);
473 void VisitObjCCategoryDecl(const ObjCCategoryDecl *D);
474 void VisitObjCCategoryImplDecl(const ObjCCategoryImplDecl *D);
475 void VisitObjCProtocolDecl(const ObjCProtocolDecl *D);
476 void VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D);
477 void VisitObjCImplementationDecl(const ObjCImplementationDecl *D);
478 void VisitObjCCompatibleAliasDecl(const ObjCCompatibleAliasDecl *D);
479 void VisitObjCPropertyDecl(const ObjCPropertyDecl *D);
480 void VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D);
481 void VisitBlockDecl(const BlockDecl *D);
484 void VisitStmt(const Stmt *Node);
485 void VisitDeclStmt(const DeclStmt *Node);
486 void VisitAttributedStmt(const AttributedStmt *Node);
487 void VisitLabelStmt(const LabelStmt *Node);
488 void VisitGotoStmt(const GotoStmt *Node);
489 void VisitCXXCatchStmt(const CXXCatchStmt *Node);
492 void VisitExpr(const Expr *Node);
493 void VisitCastExpr(const CastExpr *Node);
494 void VisitDeclRefExpr(const DeclRefExpr *Node);
495 void VisitPredefinedExpr(const PredefinedExpr *Node);
496 void VisitCharacterLiteral(const CharacterLiteral *Node);
497 void VisitIntegerLiteral(const IntegerLiteral *Node);
498 void VisitFloatingLiteral(const FloatingLiteral *Node);
499 void VisitStringLiteral(const StringLiteral *Str);
500 void VisitInitListExpr(const InitListExpr *ILE);
501 void VisitUnaryOperator(const UnaryOperator *Node);
502 void VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *Node);
503 void VisitMemberExpr(const MemberExpr *Node);
504 void VisitExtVectorElementExpr(const ExtVectorElementExpr *Node);
505 void VisitBinaryOperator(const BinaryOperator *Node);
506 void VisitCompoundAssignOperator(const CompoundAssignOperator *Node);
507 void VisitAddrLabelExpr(const AddrLabelExpr *Node);
508 void VisitBlockExpr(const BlockExpr *Node);
509 void VisitOpaqueValueExpr(const OpaqueValueExpr *Node);
512 void VisitCXXNamedCastExpr(const CXXNamedCastExpr *Node);
513 void VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *Node);
514 void VisitCXXThisExpr(const CXXThisExpr *Node);
515 void VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *Node);
516 void VisitCXXConstructExpr(const CXXConstructExpr *Node);
517 void VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *Node);
518 void VisitCXXNewExpr(const CXXNewExpr *Node);
519 void VisitCXXDeleteExpr(const CXXDeleteExpr *Node);
520 void VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *Node);
521 void VisitExprWithCleanups(const ExprWithCleanups *Node);
522 void VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *Node);
523 void dumpCXXTemporary(const CXXTemporary *Temporary);
524 void VisitLambdaExpr(const LambdaExpr *Node) {
526 dumpDecl(Node->getLambdaClass());
528 void VisitSizeOfPackExpr(const SizeOfPackExpr *Node);
531 void VisitObjCAtCatchStmt(const ObjCAtCatchStmt *Node);
532 void VisitObjCEncodeExpr(const ObjCEncodeExpr *Node);
533 void VisitObjCMessageExpr(const ObjCMessageExpr *Node);
534 void VisitObjCBoxedExpr(const ObjCBoxedExpr *Node);
535 void VisitObjCSelectorExpr(const ObjCSelectorExpr *Node);
536 void VisitObjCProtocolExpr(const ObjCProtocolExpr *Node);
537 void VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *Node);
538 void VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *Node);
539 void VisitObjCIvarRefExpr(const ObjCIvarRefExpr *Node);
540 void VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *Node);
543 const char *getCommandName(unsigned CommandID);
544 void dumpComment(const Comment *C);
547 void visitTextComment(const TextComment *C);
548 void visitInlineCommandComment(const InlineCommandComment *C);
549 void visitHTMLStartTagComment(const HTMLStartTagComment *C);
550 void visitHTMLEndTagComment(const HTMLEndTagComment *C);
553 void visitBlockCommandComment(const BlockCommandComment *C);
554 void visitParamCommandComment(const ParamCommandComment *C);
555 void visitTParamCommandComment(const TParamCommandComment *C);
556 void visitVerbatimBlockComment(const VerbatimBlockComment *C);
557 void visitVerbatimBlockLineComment(const VerbatimBlockLineComment *C);
558 void visitVerbatimLineComment(const VerbatimLineComment *C);
562 //===----------------------------------------------------------------------===//
564 //===----------------------------------------------------------------------===//
566 void ASTDumper::dumpPointer(const void *Ptr) {
567 ColorScope Color(*this, AddressColor);
571 void ASTDumper::dumpLocation(SourceLocation Loc) {
575 ColorScope Color(*this, LocationColor);
576 SourceLocation SpellingLoc = SM->getSpellingLoc(Loc);
578 // The general format we print out is filename:line:col, but we drop pieces
579 // that haven't changed since the last loc printed.
580 PresumedLoc PLoc = SM->getPresumedLoc(SpellingLoc);
582 if (PLoc.isInvalid()) {
583 OS << "<invalid sloc>";
587 if (strcmp(PLoc.getFilename(), LastLocFilename) != 0) {
588 OS << PLoc.getFilename() << ':' << PLoc.getLine()
589 << ':' << PLoc.getColumn();
590 LastLocFilename = PLoc.getFilename();
591 LastLocLine = PLoc.getLine();
592 } else if (PLoc.getLine() != LastLocLine) {
593 OS << "line" << ':' << PLoc.getLine()
594 << ':' << PLoc.getColumn();
595 LastLocLine = PLoc.getLine();
597 OS << "col" << ':' << PLoc.getColumn();
601 void ASTDumper::dumpSourceRange(SourceRange R) {
602 // Can't translate locations if a SourceManager isn't available.
607 dumpLocation(R.getBegin());
608 if (R.getBegin() != R.getEnd()) {
610 dumpLocation(R.getEnd());
614 // <t2.c:123:421[blah], t2.c:412:321>
618 void ASTDumper::dumpBareType(QualType T, bool Desugar) {
619 ColorScope Color(*this, TypeColor);
621 SplitQualType T_split = T.split();
622 OS << "'" << QualType::getAsString(T_split) << "'";
624 if (Desugar && !T.isNull()) {
625 // If the type is sugared, also dump a (shallow) desugared type.
626 SplitQualType D_split = T.getSplitDesugaredType();
627 if (T_split != D_split)
628 OS << ":'" << QualType::getAsString(D_split) << "'";
632 void ASTDumper::dumpType(QualType T) {
637 void ASTDumper::dumpTypeAsChild(QualType T) {
638 SplitQualType SQT = T.split();
639 if (!SQT.Quals.hasQualifiers())
640 return dumpTypeAsChild(SQT.Ty);
644 dumpPointer(T.getAsOpaquePtr());
646 dumpBareType(T, false);
647 OS << " " << T.split().Quals.getAsString();
648 dumpTypeAsChild(T.split().Ty);
652 void ASTDumper::dumpTypeAsChild(const Type *T) {
655 ColorScope Color(*this, NullColor);
659 if (const LocInfoType *LIT = llvm::dyn_cast<LocInfoType>(T)) {
661 ColorScope Color(*this, TypeColor);
662 OS << "LocInfo Type";
665 dumpTypeAsChild(LIT->getTypeSourceInfo()->getType());
670 ColorScope Color(*this, TypeColor);
671 OS << T->getTypeClassName() << "Type";
675 dumpBareType(QualType(T, 0), false);
677 QualType SingleStepDesugar =
678 T->getLocallyUnqualifiedSingleStepDesugaredType();
679 if (SingleStepDesugar != QualType(T, 0))
681 if (T->isDependentType())
683 else if (T->isInstantiationDependentType())
684 OS << " instantiation_dependent";
685 if (T->isVariablyModifiedType())
686 OS << " variably_modified";
687 if (T->containsUnexpandedParameterPack())
688 OS << " contains_unexpanded_pack";
692 TypeVisitor<ASTDumper>::Visit(T);
694 if (SingleStepDesugar != QualType(T, 0))
695 dumpTypeAsChild(SingleStepDesugar);
699 void ASTDumper::dumpBareDeclRef(const Decl *D) {
701 ColorScope Color(*this, DeclKindNameColor);
702 OS << D->getDeclKindName();
706 if (const NamedDecl *ND = dyn_cast<NamedDecl>(D)) {
707 ColorScope Color(*this, DeclNameColor);
708 OS << " '" << ND->getDeclName() << '\'';
711 if (const ValueDecl *VD = dyn_cast<ValueDecl>(D))
712 dumpType(VD->getType());
715 void ASTDumper::dumpDeclRef(const Decl *D, const char *Label) {
726 void ASTDumper::dumpName(const NamedDecl *ND) {
727 if (ND->getDeclName()) {
728 ColorScope Color(*this, DeclNameColor);
729 OS << ' ' << ND->getNameAsString();
733 bool ASTDumper::hasNodes(const DeclContext *DC) {
737 return DC->hasExternalLexicalStorage() ||
738 DC->noload_decls_begin() != DC->noload_decls_end();
741 void ASTDumper::dumpDeclContext(const DeclContext *DC) {
745 for (auto *D : DC->noload_decls())
748 if (DC->hasExternalLexicalStorage()) {
750 ColorScope Color(*this, UndeserializedColor);
751 OS << "<undeserialized declarations>";
756 void ASTDumper::dumpLookups(const DeclContext *DC, bool DumpDecls) {
758 OS << "StoredDeclsMap ";
759 dumpBareDeclRef(cast<Decl>(DC));
761 const DeclContext *Primary = DC->getPrimaryContext();
764 dumpPointer(cast<Decl>(Primary));
767 bool HasUndeserializedLookups = Primary->hasExternalVisibleStorage();
769 DeclContext::all_lookups_iterator I = Primary->noload_lookups_begin(),
770 E = Primary->noload_lookups_end();
772 DeclarationName Name = I.getLookupName();
773 DeclContextLookupResult R = *I++;
776 OS << "DeclarationName ";
778 ColorScope Color(*this, DeclNameColor);
779 OS << '\'' << Name << '\'';
782 for (DeclContextLookupResult::iterator RI = R.begin(), RE = R.end();
785 dumpBareDeclRef(*RI);
787 if ((*RI)->isHidden())
790 // If requested, dump the redecl chain for this lookup.
792 // Dump earliest decl first.
793 std::function<void(Decl *)> DumpWithPrev = [&](Decl *D) {
794 if (Decl *Prev = D->getPreviousDecl())
805 if (HasUndeserializedLookups) {
807 ColorScope Color(*this, UndeserializedColor);
808 OS << "<undeserialized lookups>";
814 void ASTDumper::dumpAttr(const Attr *A) {
817 ColorScope Color(*this, AttrColor);
819 switch (A->getKind()) {
820 #define ATTR(X) case attr::X: OS << #X; break;
821 #include "clang/Basic/AttrList.inc"
823 llvm_unreachable("unexpected attribute kind");
828 dumpSourceRange(A->getRange());
829 if (A->isInherited())
833 #include "clang/AST/AttrDump.inc"
837 static void dumpPreviousDeclImpl(raw_ostream &OS, ...) {}
840 static void dumpPreviousDeclImpl(raw_ostream &OS, const Mergeable<T> *D) {
841 const T *First = D->getFirstDecl();
843 OS << " first " << First;
847 static void dumpPreviousDeclImpl(raw_ostream &OS, const Redeclarable<T> *D) {
848 const T *Prev = D->getPreviousDecl();
850 OS << " prev " << Prev;
853 /// Dump the previous declaration in the redeclaration chain for a declaration,
855 static void dumpPreviousDecl(raw_ostream &OS, const Decl *D) {
856 switch (D->getKind()) {
857 #define DECL(DERIVED, BASE) \
858 case Decl::DERIVED: \
859 return dumpPreviousDeclImpl(OS, cast<DERIVED##Decl>(D));
860 #define ABSTRACT_DECL(DECL)
861 #include "clang/AST/DeclNodes.inc"
863 llvm_unreachable("Decl that isn't part of DeclNodes.inc!");
866 //===----------------------------------------------------------------------===//
868 //===----------------------------------------------------------------------===//
870 void ASTDumper::dumpAccessSpecifier(AccessSpecifier AS) {
886 void ASTDumper::dumpCXXCtorInitializer(const CXXCtorInitializer *Init) {
888 OS << "CXXCtorInitializer";
889 if (Init->isAnyMemberInitializer()) {
891 dumpBareDeclRef(Init->getAnyMember());
892 } else if (Init->isBaseInitializer()) {
893 dumpType(QualType(Init->getBaseClass(), 0));
894 } else if (Init->isDelegatingInitializer()) {
895 dumpType(Init->getTypeSourceInfo()->getType());
897 llvm_unreachable("Unknown initializer type");
899 dumpStmt(Init->getInit());
903 void ASTDumper::dumpTemplateParameters(const TemplateParameterList *TPL) {
907 for (TemplateParameterList::const_iterator I = TPL->begin(), E = TPL->end();
912 void ASTDumper::dumpTemplateArgumentListInfo(
913 const TemplateArgumentListInfo &TALI) {
914 for (unsigned i = 0, e = TALI.size(); i < e; ++i)
915 dumpTemplateArgumentLoc(TALI[i]);
918 void ASTDumper::dumpTemplateArgumentLoc(const TemplateArgumentLoc &A) {
919 dumpTemplateArgument(A.getArgument(), A.getSourceRange());
922 void ASTDumper::dumpTemplateArgumentList(const TemplateArgumentList &TAL) {
923 for (unsigned i = 0, e = TAL.size(); i < e; ++i)
924 dumpTemplateArgument(TAL[i]);
927 void ASTDumper::dumpTemplateArgument(const TemplateArgument &A, SourceRange R) {
929 OS << "TemplateArgument";
933 switch (A.getKind()) {
934 case TemplateArgument::Null:
937 case TemplateArgument::Type:
939 dumpType(A.getAsType());
941 case TemplateArgument::Declaration:
943 dumpDeclRef(A.getAsDecl());
945 case TemplateArgument::NullPtr:
948 case TemplateArgument::Integral:
949 OS << " integral " << A.getAsIntegral();
951 case TemplateArgument::Template:
953 A.getAsTemplate().dump(OS);
955 case TemplateArgument::TemplateExpansion:
956 OS << " template expansion";
957 A.getAsTemplateOrTemplatePattern().dump(OS);
959 case TemplateArgument::Expression:
961 dumpStmt(A.getAsExpr());
963 case TemplateArgument::Pack:
965 for (TemplateArgument::pack_iterator I = A.pack_begin(), E = A.pack_end();
967 dumpTemplateArgument(*I);
973 //===----------------------------------------------------------------------===//
974 // Objective-C Utilities
975 //===----------------------------------------------------------------------===//
976 void ASTDumper::dumpObjCTypeParamList(const ObjCTypeParamList *typeParams) {
980 for (auto typeParam : *typeParams) {
985 //===----------------------------------------------------------------------===//
986 // Decl dumping methods.
987 //===----------------------------------------------------------------------===//
989 void ASTDumper::dumpDecl(const Decl *D) {
992 ColorScope Color(*this, NullColor);
998 ColorScope Color(*this, DeclKindNameColor);
999 OS << D->getDeclKindName() << "Decl";
1002 if (D->getLexicalDeclContext() != D->getDeclContext())
1003 OS << " parent " << cast<Decl>(D->getDeclContext());
1004 dumpPreviousDecl(OS, D);
1005 dumpSourceRange(D->getSourceRange());
1007 dumpLocation(D->getLocation());
1008 if (Module *M = D->getImportedOwningModule())
1009 OS << " in " << M->getFullModuleName();
1010 else if (Module *M = D->getLocalOwningModule())
1011 OS << " in (local) " << M->getFullModuleName();
1012 if (auto *ND = dyn_cast<NamedDecl>(D))
1013 for (Module *M : D->getASTContext().getModulesWithMergedDefinition(
1014 const_cast<NamedDecl *>(ND)))
1015 dumpChild([=] { OS << "also in " << M->getFullModuleName(); });
1016 if (const NamedDecl *ND = dyn_cast<NamedDecl>(D))
1019 if (D->isImplicit())
1023 else if (D->isThisDeclarationReferenced())
1024 OS << " referenced";
1025 if (D->isInvalidDecl())
1027 if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
1028 if (FD->isConstexpr())
1032 ConstDeclVisitor<ASTDumper>::Visit(D);
1034 for (Decl::attr_iterator I = D->attr_begin(), E = D->attr_end(); I != E;
1038 if (const FullComment *Comment =
1039 D->getASTContext().getLocalCommentForDeclUncached(D))
1040 dumpFullComment(Comment);
1042 // Decls within functions are visited by the body.
1043 if (!isa<FunctionDecl>(*D) && !isa<ObjCMethodDecl>(*D) &&
1044 hasNodes(dyn_cast<DeclContext>(D)))
1045 dumpDeclContext(cast<DeclContext>(D));
1049 void ASTDumper::VisitLabelDecl(const LabelDecl *D) {
1053 void ASTDumper::VisitTypedefDecl(const TypedefDecl *D) {
1055 dumpType(D->getUnderlyingType());
1056 if (D->isModulePrivate())
1057 OS << " __module_private__";
1060 void ASTDumper::VisitEnumDecl(const EnumDecl *D) {
1061 if (D->isScoped()) {
1062 if (D->isScopedUsingClassTag())
1068 if (D->isModulePrivate())
1069 OS << " __module_private__";
1071 dumpType(D->getIntegerType());
1074 void ASTDumper::VisitRecordDecl(const RecordDecl *D) {
1075 OS << ' ' << D->getKindName();
1077 if (D->isModulePrivate())
1078 OS << " __module_private__";
1079 if (D->isCompleteDefinition())
1080 OS << " definition";
1083 void ASTDumper::VisitEnumConstantDecl(const EnumConstantDecl *D) {
1085 dumpType(D->getType());
1086 if (const Expr *Init = D->getInitExpr())
1090 void ASTDumper::VisitIndirectFieldDecl(const IndirectFieldDecl *D) {
1092 dumpType(D->getType());
1094 for (auto *Child : D->chain())
1098 void ASTDumper::VisitFunctionDecl(const FunctionDecl *D) {
1100 dumpType(D->getType());
1102 StorageClass SC = D->getStorageClass();
1104 OS << ' ' << VarDecl::getStorageClassSpecifierString(SC);
1105 if (D->isInlineSpecified())
1107 if (D->isVirtualAsWritten())
1109 if (D->isModulePrivate())
1110 OS << " __module_private__";
1114 else if (D->isDeletedAsWritten())
1117 if (const FunctionProtoType *FPT = D->getType()->getAs<FunctionProtoType>()) {
1118 FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo();
1119 switch (EPI.ExceptionSpec.Type) {
1121 case EST_Unevaluated:
1122 OS << " noexcept-unevaluated " << EPI.ExceptionSpec.SourceDecl;
1124 case EST_Uninstantiated:
1125 OS << " noexcept-uninstantiated " << EPI.ExceptionSpec.SourceTemplate;
1130 if (const FunctionTemplateSpecializationInfo *FTSI =
1131 D->getTemplateSpecializationInfo())
1132 dumpTemplateArgumentList(*FTSI->TemplateArguments);
1134 for (ArrayRef<NamedDecl *>::iterator
1135 I = D->getDeclsInPrototypeScope().begin(),
1136 E = D->getDeclsInPrototypeScope().end(); I != E; ++I)
1139 if (!D->param_begin() && D->getNumParams())
1140 dumpChild([=] { OS << "<<NULL params x " << D->getNumParams() << ">>"; });
1142 for (FunctionDecl::param_const_iterator I = D->param_begin(),
1147 if (const CXXConstructorDecl *C = dyn_cast<CXXConstructorDecl>(D))
1148 for (CXXConstructorDecl::init_const_iterator I = C->init_begin(),
1151 dumpCXXCtorInitializer(*I);
1153 if (D->doesThisDeclarationHaveABody())
1154 dumpStmt(D->getBody());
1157 void ASTDumper::VisitFieldDecl(const FieldDecl *D) {
1159 dumpType(D->getType());
1162 if (D->isModulePrivate())
1163 OS << " __module_private__";
1165 if (D->isBitField())
1166 dumpStmt(D->getBitWidth());
1167 if (Expr *Init = D->getInClassInitializer())
1171 void ASTDumper::VisitVarDecl(const VarDecl *D) {
1173 dumpType(D->getType());
1174 StorageClass SC = D->getStorageClass();
1176 OS << ' ' << VarDecl::getStorageClassSpecifierString(SC);
1177 switch (D->getTLSKind()) {
1178 case VarDecl::TLS_None: break;
1179 case VarDecl::TLS_Static: OS << " tls"; break;
1180 case VarDecl::TLS_Dynamic: OS << " tls_dynamic"; break;
1182 if (D->isModulePrivate())
1183 OS << " __module_private__";
1184 if (D->isNRVOVariable())
1187 switch (D->getInitStyle()) {
1188 case VarDecl::CInit: OS << " cinit"; break;
1189 case VarDecl::CallInit: OS << " callinit"; break;
1190 case VarDecl::ListInit: OS << " listinit"; break;
1192 dumpStmt(D->getInit());
1196 void ASTDumper::VisitFileScopeAsmDecl(const FileScopeAsmDecl *D) {
1197 dumpStmt(D->getAsmString());
1200 void ASTDumper::VisitImportDecl(const ImportDecl *D) {
1201 OS << ' ' << D->getImportedModule()->getFullModuleName();
1204 //===----------------------------------------------------------------------===//
1206 //===----------------------------------------------------------------------===//
1208 void ASTDumper::VisitNamespaceDecl(const NamespaceDecl *D) {
1212 if (!D->isOriginalNamespace())
1213 dumpDeclRef(D->getOriginalNamespace(), "original");
1216 void ASTDumper::VisitUsingDirectiveDecl(const UsingDirectiveDecl *D) {
1218 dumpBareDeclRef(D->getNominatedNamespace());
1221 void ASTDumper::VisitNamespaceAliasDecl(const NamespaceAliasDecl *D) {
1223 dumpDeclRef(D->getAliasedNamespace());
1226 void ASTDumper::VisitTypeAliasDecl(const TypeAliasDecl *D) {
1228 dumpType(D->getUnderlyingType());
1231 void ASTDumper::VisitTypeAliasTemplateDecl(const TypeAliasTemplateDecl *D) {
1233 dumpTemplateParameters(D->getTemplateParameters());
1234 dumpDecl(D->getTemplatedDecl());
1237 void ASTDumper::VisitCXXRecordDecl(const CXXRecordDecl *D) {
1239 if (!D->isCompleteDefinition())
1242 for (const auto &I : D->bases()) {
1246 dumpAccessSpecifier(I.getAccessSpecifier());
1247 dumpType(I.getType());
1248 if (I.isPackExpansion())
1254 void ASTDumper::VisitStaticAssertDecl(const StaticAssertDecl *D) {
1255 dumpStmt(D->getAssertExpr());
1256 dumpStmt(D->getMessage());
1259 template<typename SpecializationDecl>
1260 void ASTDumper::VisitTemplateDeclSpecialization(const SpecializationDecl *D,
1261 bool DumpExplicitInst,
1263 bool DumpedAny = false;
1264 for (auto *RedeclWithBadType : D->redecls()) {
1265 // FIXME: The redecls() range sometimes has elements of a less-specific
1266 // type. (In particular, ClassTemplateSpecializationDecl::redecls() gives
1267 // us TagDecls, and should give CXXRecordDecls).
1268 auto *Redecl = dyn_cast<SpecializationDecl>(RedeclWithBadType);
1270 // Found the injected-class-name for a class template. This will be dumped
1271 // as part of its surrounding class so we don't need to dump it here.
1272 assert(isa<CXXRecordDecl>(RedeclWithBadType) &&
1273 "expected an injected-class-name");
1277 switch (Redecl->getTemplateSpecializationKind()) {
1278 case TSK_ExplicitInstantiationDeclaration:
1279 case TSK_ExplicitInstantiationDefinition:
1280 if (!DumpExplicitInst)
1283 case TSK_Undeclared:
1284 case TSK_ImplicitInstantiation:
1286 dumpDeclRef(Redecl);
1291 case TSK_ExplicitSpecialization:
1296 // Ensure we dump at least one decl for each specialization.
1301 template<typename TemplateDecl>
1302 void ASTDumper::VisitTemplateDecl(const TemplateDecl *D,
1303 bool DumpExplicitInst) {
1305 dumpTemplateParameters(D->getTemplateParameters());
1307 dumpDecl(D->getTemplatedDecl());
1309 for (auto *Child : D->specializations())
1310 VisitTemplateDeclSpecialization(Child, DumpExplicitInst,
1311 !D->isCanonicalDecl());
1314 void ASTDumper::VisitFunctionTemplateDecl(const FunctionTemplateDecl *D) {
1315 // FIXME: We don't add a declaration of a function template specialization
1316 // to its context when it's explicitly instantiated, so dump explicit
1317 // instantiations when we dump the template itself.
1318 VisitTemplateDecl(D, true);
1321 void ASTDumper::VisitClassTemplateDecl(const ClassTemplateDecl *D) {
1322 VisitTemplateDecl(D, false);
1325 void ASTDumper::VisitClassTemplateSpecializationDecl(
1326 const ClassTemplateSpecializationDecl *D) {
1327 VisitCXXRecordDecl(D);
1328 dumpTemplateArgumentList(D->getTemplateArgs());
1331 void ASTDumper::VisitClassTemplatePartialSpecializationDecl(
1332 const ClassTemplatePartialSpecializationDecl *D) {
1333 VisitClassTemplateSpecializationDecl(D);
1334 dumpTemplateParameters(D->getTemplateParameters());
1337 void ASTDumper::VisitClassScopeFunctionSpecializationDecl(
1338 const ClassScopeFunctionSpecializationDecl *D) {
1339 dumpDeclRef(D->getSpecialization());
1340 if (D->hasExplicitTemplateArgs())
1341 dumpTemplateArgumentListInfo(D->templateArgs());
1344 void ASTDumper::VisitVarTemplateDecl(const VarTemplateDecl *D) {
1345 VisitTemplateDecl(D, false);
1348 void ASTDumper::VisitBuiltinTemplateDecl(const BuiltinTemplateDecl *D) {
1350 dumpTemplateParameters(D->getTemplateParameters());
1353 void ASTDumper::VisitVarTemplateSpecializationDecl(
1354 const VarTemplateSpecializationDecl *D) {
1355 dumpTemplateArgumentList(D->getTemplateArgs());
1359 void ASTDumper::VisitVarTemplatePartialSpecializationDecl(
1360 const VarTemplatePartialSpecializationDecl *D) {
1361 dumpTemplateParameters(D->getTemplateParameters());
1362 VisitVarTemplateSpecializationDecl(D);
1365 void ASTDumper::VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D) {
1366 if (D->wasDeclaredWithTypename())
1370 if (D->isParameterPack())
1373 if (D->hasDefaultArgument())
1374 dumpTemplateArgument(D->getDefaultArgument());
1377 void ASTDumper::VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D) {
1378 dumpType(D->getType());
1379 if (D->isParameterPack())
1382 if (D->hasDefaultArgument())
1383 dumpTemplateArgument(D->getDefaultArgument());
1386 void ASTDumper::VisitTemplateTemplateParmDecl(
1387 const TemplateTemplateParmDecl *D) {
1388 if (D->isParameterPack())
1391 dumpTemplateParameters(D->getTemplateParameters());
1392 if (D->hasDefaultArgument())
1393 dumpTemplateArgumentLoc(D->getDefaultArgument());
1396 void ASTDumper::VisitUsingDecl(const UsingDecl *D) {
1398 if (D->getQualifier())
1399 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
1400 OS << D->getNameAsString();
1403 void ASTDumper::VisitUnresolvedUsingTypenameDecl(
1404 const UnresolvedUsingTypenameDecl *D) {
1406 if (D->getQualifier())
1407 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
1408 OS << D->getNameAsString();
1411 void ASTDumper::VisitUnresolvedUsingValueDecl(const UnresolvedUsingValueDecl *D) {
1413 if (D->getQualifier())
1414 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
1415 OS << D->getNameAsString();
1416 dumpType(D->getType());
1419 void ASTDumper::VisitUsingShadowDecl(const UsingShadowDecl *D) {
1421 dumpBareDeclRef(D->getTargetDecl());
1424 void ASTDumper::VisitLinkageSpecDecl(const LinkageSpecDecl *D) {
1425 switch (D->getLanguage()) {
1426 case LinkageSpecDecl::lang_c: OS << " C"; break;
1427 case LinkageSpecDecl::lang_cxx: OS << " C++"; break;
1431 void ASTDumper::VisitAccessSpecDecl(const AccessSpecDecl *D) {
1433 dumpAccessSpecifier(D->getAccess());
1436 void ASTDumper::VisitFriendDecl(const FriendDecl *D) {
1437 if (TypeSourceInfo *T = D->getFriendType())
1438 dumpType(T->getType());
1440 dumpDecl(D->getFriendDecl());
1443 //===----------------------------------------------------------------------===//
1444 // Obj-C Declarations
1445 //===----------------------------------------------------------------------===//
1447 void ASTDumper::VisitObjCIvarDecl(const ObjCIvarDecl *D) {
1449 dumpType(D->getType());
1450 if (D->getSynthesize())
1451 OS << " synthesize";
1453 switch (D->getAccessControl()) {
1454 case ObjCIvarDecl::None:
1457 case ObjCIvarDecl::Private:
1460 case ObjCIvarDecl::Protected:
1463 case ObjCIvarDecl::Public:
1466 case ObjCIvarDecl::Package:
1472 void ASTDumper::VisitObjCMethodDecl(const ObjCMethodDecl *D) {
1473 if (D->isInstanceMethod())
1478 dumpType(D->getReturnType());
1480 if (D->isThisDeclarationADefinition()) {
1483 for (ObjCMethodDecl::param_const_iterator I = D->param_begin(),
1489 if (D->isVariadic())
1490 dumpChild([=] { OS << "..."; });
1493 dumpStmt(D->getBody());
1496 void ASTDumper::VisitObjCTypeParamDecl(const ObjCTypeParamDecl *D) {
1498 switch (D->getVariance()) {
1499 case ObjCTypeParamVariance::Invariant:
1502 case ObjCTypeParamVariance::Covariant:
1506 case ObjCTypeParamVariance::Contravariant:
1507 OS << " contravariant";
1511 if (D->hasExplicitBound())
1513 dumpType(D->getUnderlyingType());
1516 void ASTDumper::VisitObjCCategoryDecl(const ObjCCategoryDecl *D) {
1518 dumpDeclRef(D->getClassInterface());
1519 dumpObjCTypeParamList(D->getTypeParamList());
1520 dumpDeclRef(D->getImplementation());
1521 for (ObjCCategoryDecl::protocol_iterator I = D->protocol_begin(),
1522 E = D->protocol_end();
1527 void ASTDumper::VisitObjCCategoryImplDecl(const ObjCCategoryImplDecl *D) {
1529 dumpDeclRef(D->getClassInterface());
1530 dumpDeclRef(D->getCategoryDecl());
1533 void ASTDumper::VisitObjCProtocolDecl(const ObjCProtocolDecl *D) {
1536 for (auto *Child : D->protocols())
1540 void ASTDumper::VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D) {
1542 dumpObjCTypeParamList(D->getTypeParamListAsWritten());
1543 dumpDeclRef(D->getSuperClass(), "super");
1545 dumpDeclRef(D->getImplementation());
1546 for (auto *Child : D->protocols())
1550 void ASTDumper::VisitObjCImplementationDecl(const ObjCImplementationDecl *D) {
1552 dumpDeclRef(D->getSuperClass(), "super");
1553 dumpDeclRef(D->getClassInterface());
1554 for (ObjCImplementationDecl::init_const_iterator I = D->init_begin(),
1557 dumpCXXCtorInitializer(*I);
1560 void ASTDumper::VisitObjCCompatibleAliasDecl(const ObjCCompatibleAliasDecl *D) {
1562 dumpDeclRef(D->getClassInterface());
1565 void ASTDumper::VisitObjCPropertyDecl(const ObjCPropertyDecl *D) {
1567 dumpType(D->getType());
1569 if (D->getPropertyImplementation() == ObjCPropertyDecl::Required)
1571 else if (D->getPropertyImplementation() == ObjCPropertyDecl::Optional)
1574 ObjCPropertyDecl::PropertyAttributeKind Attrs = D->getPropertyAttributes();
1575 if (Attrs != ObjCPropertyDecl::OBJC_PR_noattr) {
1576 if (Attrs & ObjCPropertyDecl::OBJC_PR_readonly)
1578 if (Attrs & ObjCPropertyDecl::OBJC_PR_assign)
1580 if (Attrs & ObjCPropertyDecl::OBJC_PR_readwrite)
1582 if (Attrs & ObjCPropertyDecl::OBJC_PR_retain)
1584 if (Attrs & ObjCPropertyDecl::OBJC_PR_copy)
1586 if (Attrs & ObjCPropertyDecl::OBJC_PR_nonatomic)
1588 if (Attrs & ObjCPropertyDecl::OBJC_PR_atomic)
1590 if (Attrs & ObjCPropertyDecl::OBJC_PR_weak)
1592 if (Attrs & ObjCPropertyDecl::OBJC_PR_strong)
1594 if (Attrs & ObjCPropertyDecl::OBJC_PR_unsafe_unretained)
1595 OS << " unsafe_unretained";
1596 if (Attrs & ObjCPropertyDecl::OBJC_PR_getter)
1597 dumpDeclRef(D->getGetterMethodDecl(), "getter");
1598 if (Attrs & ObjCPropertyDecl::OBJC_PR_setter)
1599 dumpDeclRef(D->getSetterMethodDecl(), "setter");
1603 void ASTDumper::VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D) {
1604 dumpName(D->getPropertyDecl());
1605 if (D->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize)
1606 OS << " synthesize";
1609 dumpDeclRef(D->getPropertyDecl());
1610 dumpDeclRef(D->getPropertyIvarDecl());
1613 void ASTDumper::VisitBlockDecl(const BlockDecl *D) {
1614 for (auto I : D->params())
1617 if (D->isVariadic())
1618 dumpChild([=]{ OS << "..."; });
1620 if (D->capturesCXXThis())
1621 dumpChild([=]{ OS << "capture this"; });
1623 for (const auto &I : D->captures()) {
1630 if (I.getVariable()) {
1632 dumpBareDeclRef(I.getVariable());
1634 if (I.hasCopyExpr())
1635 dumpStmt(I.getCopyExpr());
1638 dumpStmt(D->getBody());
1641 //===----------------------------------------------------------------------===//
1642 // Stmt dumping methods.
1643 //===----------------------------------------------------------------------===//
1645 void ASTDumper::dumpStmt(const Stmt *S) {
1648 ColorScope Color(*this, NullColor);
1653 if (const DeclStmt *DS = dyn_cast<DeclStmt>(S)) {
1658 ConstStmtVisitor<ASTDumper>::Visit(S);
1660 for (const Stmt *SubStmt : S->children())
1665 void ASTDumper::VisitStmt(const Stmt *Node) {
1667 ColorScope Color(*this, StmtColor);
1668 OS << Node->getStmtClassName();
1671 dumpSourceRange(Node->getSourceRange());
1674 void ASTDumper::VisitDeclStmt(const DeclStmt *Node) {
1676 for (DeclStmt::const_decl_iterator I = Node->decl_begin(),
1677 E = Node->decl_end();
1682 void ASTDumper::VisitAttributedStmt(const AttributedStmt *Node) {
1684 for (ArrayRef<const Attr *>::iterator I = Node->getAttrs().begin(),
1685 E = Node->getAttrs().end();
1690 void ASTDumper::VisitLabelStmt(const LabelStmt *Node) {
1692 OS << " '" << Node->getName() << "'";
1695 void ASTDumper::VisitGotoStmt(const GotoStmt *Node) {
1697 OS << " '" << Node->getLabel()->getName() << "'";
1698 dumpPointer(Node->getLabel());
1701 void ASTDumper::VisitCXXCatchStmt(const CXXCatchStmt *Node) {
1703 dumpDecl(Node->getExceptionDecl());
1706 //===----------------------------------------------------------------------===//
1707 // Expr dumping methods.
1708 //===----------------------------------------------------------------------===//
1710 void ASTDumper::VisitExpr(const Expr *Node) {
1712 dumpType(Node->getType());
1715 ColorScope Color(*this, ValueKindColor);
1716 switch (Node->getValueKind()) {
1729 ColorScope Color(*this, ObjectKindColor);
1730 switch (Node->getObjectKind()) {
1736 case OK_ObjCProperty:
1737 OS << " objcproperty";
1739 case OK_ObjCSubscript:
1740 OS << " objcsubscript";
1742 case OK_VectorComponent:
1743 OS << " vectorcomponent";
1749 static void dumpBasePath(raw_ostream &OS, const CastExpr *Node) {
1750 if (Node->path_empty())
1755 for (CastExpr::path_const_iterator I = Node->path_begin(),
1756 E = Node->path_end();
1758 const CXXBaseSpecifier *Base = *I;
1762 const CXXRecordDecl *RD =
1763 cast<CXXRecordDecl>(Base->getType()->getAs<RecordType>()->getDecl());
1765 if (Base->isVirtual())
1767 OS << RD->getName();
1774 void ASTDumper::VisitCastExpr(const CastExpr *Node) {
1778 ColorScope Color(*this, CastColor);
1779 OS << Node->getCastKindName();
1781 dumpBasePath(OS, Node);
1785 void ASTDumper::VisitDeclRefExpr(const DeclRefExpr *Node) {
1789 dumpBareDeclRef(Node->getDecl());
1790 if (Node->getDecl() != Node->getFoundDecl()) {
1792 dumpBareDeclRef(Node->getFoundDecl());
1797 void ASTDumper::VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *Node) {
1800 if (!Node->requiresADL())
1802 OS << "ADL) = '" << Node->getName() << '\'';
1804 UnresolvedLookupExpr::decls_iterator
1805 I = Node->decls_begin(), E = Node->decls_end();
1812 void ASTDumper::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *Node) {
1816 ColorScope Color(*this, DeclKindNameColor);
1817 OS << " " << Node->getDecl()->getDeclKindName() << "Decl";
1819 OS << "='" << *Node->getDecl() << "'";
1820 dumpPointer(Node->getDecl());
1821 if (Node->isFreeIvar())
1822 OS << " isFreeIvar";
1825 void ASTDumper::VisitPredefinedExpr(const PredefinedExpr *Node) {
1827 OS << " " << PredefinedExpr::getIdentTypeName(Node->getIdentType());
1830 void ASTDumper::VisitCharacterLiteral(const CharacterLiteral *Node) {
1832 ColorScope Color(*this, ValueColor);
1833 OS << " " << Node->getValue();
1836 void ASTDumper::VisitIntegerLiteral(const IntegerLiteral *Node) {
1839 bool isSigned = Node->getType()->isSignedIntegerType();
1840 ColorScope Color(*this, ValueColor);
1841 OS << " " << Node->getValue().toString(10, isSigned);
1844 void ASTDumper::VisitFloatingLiteral(const FloatingLiteral *Node) {
1846 ColorScope Color(*this, ValueColor);
1847 OS << " " << Node->getValueAsApproximateDouble();
1850 void ASTDumper::VisitStringLiteral(const StringLiteral *Str) {
1852 ColorScope Color(*this, ValueColor);
1854 Str->outputString(OS);
1857 void ASTDumper::VisitInitListExpr(const InitListExpr *ILE) {
1859 if (auto *Filler = ILE->getArrayFiller()) {
1861 OS << "array filler";
1865 if (auto *Field = ILE->getInitializedFieldInUnion()) {
1867 dumpBareDeclRef(Field);
1871 void ASTDumper::VisitUnaryOperator(const UnaryOperator *Node) {
1873 OS << " " << (Node->isPostfix() ? "postfix" : "prefix")
1874 << " '" << UnaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
1877 void ASTDumper::VisitUnaryExprOrTypeTraitExpr(
1878 const UnaryExprOrTypeTraitExpr *Node) {
1880 switch(Node->getKind()) {
1890 case UETT_OpenMPRequiredSimdAlign:
1891 OS << " __builtin_omp_required_simd_align";
1894 if (Node->isArgumentType())
1895 dumpType(Node->getArgumentType());
1898 void ASTDumper::VisitMemberExpr(const MemberExpr *Node) {
1900 OS << " " << (Node->isArrow() ? "->" : ".") << *Node->getMemberDecl();
1901 dumpPointer(Node->getMemberDecl());
1904 void ASTDumper::VisitExtVectorElementExpr(const ExtVectorElementExpr *Node) {
1906 OS << " " << Node->getAccessor().getNameStart();
1909 void ASTDumper::VisitBinaryOperator(const BinaryOperator *Node) {
1911 OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
1914 void ASTDumper::VisitCompoundAssignOperator(
1915 const CompoundAssignOperator *Node) {
1917 OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode())
1918 << "' ComputeLHSTy=";
1919 dumpBareType(Node->getComputationLHSType());
1920 OS << " ComputeResultTy=";
1921 dumpBareType(Node->getComputationResultType());
1924 void ASTDumper::VisitBlockExpr(const BlockExpr *Node) {
1926 dumpDecl(Node->getBlockDecl());
1929 void ASTDumper::VisitOpaqueValueExpr(const OpaqueValueExpr *Node) {
1932 if (Expr *Source = Node->getSourceExpr())
1938 void ASTDumper::VisitAddrLabelExpr(const AddrLabelExpr *Node) {
1940 OS << " " << Node->getLabel()->getName();
1941 dumpPointer(Node->getLabel());
1944 //===----------------------------------------------------------------------===//
1946 //===----------------------------------------------------------------------===//
1948 void ASTDumper::VisitCXXNamedCastExpr(const CXXNamedCastExpr *Node) {
1950 OS << " " << Node->getCastName()
1951 << "<" << Node->getTypeAsWritten().getAsString() << ">"
1952 << " <" << Node->getCastKindName();
1953 dumpBasePath(OS, Node);
1957 void ASTDumper::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *Node) {
1959 OS << " " << (Node->getValue() ? "true" : "false");
1962 void ASTDumper::VisitCXXThisExpr(const CXXThisExpr *Node) {
1967 void ASTDumper::VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *Node) {
1969 OS << " functional cast to " << Node->getTypeAsWritten().getAsString()
1970 << " <" << Node->getCastKindName() << ">";
1973 void ASTDumper::VisitCXXConstructExpr(const CXXConstructExpr *Node) {
1975 CXXConstructorDecl *Ctor = Node->getConstructor();
1976 dumpType(Ctor->getType());
1977 if (Node->isElidable())
1979 if (Node->requiresZeroInitialization())
1983 void ASTDumper::VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *Node) {
1986 dumpCXXTemporary(Node->getTemporary());
1989 void ASTDumper::VisitCXXNewExpr(const CXXNewExpr *Node) {
1991 if (Node->isGlobalNew())
1993 if (Node->isArray())
1995 if (Node->getOperatorNew()) {
1997 dumpBareDeclRef(Node->getOperatorNew());
1999 // We could dump the deallocation function used in case of error, but it's
2000 // usually not that interesting.
2003 void ASTDumper::VisitCXXDeleteExpr(const CXXDeleteExpr *Node) {
2005 if (Node->isGlobalDelete())
2007 if (Node->isArrayForm())
2009 if (Node->getOperatorDelete()) {
2011 dumpBareDeclRef(Node->getOperatorDelete());
2016 ASTDumper::VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *Node) {
2018 if (const ValueDecl *VD = Node->getExtendingDecl()) {
2019 OS << " extended by ";
2020 dumpBareDeclRef(VD);
2024 void ASTDumper::VisitExprWithCleanups(const ExprWithCleanups *Node) {
2026 for (unsigned i = 0, e = Node->getNumObjects(); i != e; ++i)
2027 dumpDeclRef(Node->getObject(i), "cleanup");
2030 void ASTDumper::dumpCXXTemporary(const CXXTemporary *Temporary) {
2031 OS << "(CXXTemporary";
2032 dumpPointer(Temporary);
2036 void ASTDumper::VisitSizeOfPackExpr(const SizeOfPackExpr *Node) {
2038 dumpPointer(Node->getPack());
2039 dumpName(Node->getPack());
2040 if (Node->isPartiallySubstituted())
2041 for (const auto &A : Node->getPartialArguments())
2042 dumpTemplateArgument(A);
2046 //===----------------------------------------------------------------------===//
2047 // Obj-C Expressions
2048 //===----------------------------------------------------------------------===//
2050 void ASTDumper::VisitObjCMessageExpr(const ObjCMessageExpr *Node) {
2053 Node->getSelector().print(OS);
2054 switch (Node->getReceiverKind()) {
2055 case ObjCMessageExpr::Instance:
2058 case ObjCMessageExpr::Class:
2060 dumpBareType(Node->getClassReceiver());
2063 case ObjCMessageExpr::SuperInstance:
2064 OS << " super (instance)";
2067 case ObjCMessageExpr::SuperClass:
2068 OS << " super (class)";
2073 void ASTDumper::VisitObjCBoxedExpr(const ObjCBoxedExpr *Node) {
2076 Node->getBoxingMethod()->getSelector().print(OS);
2079 void ASTDumper::VisitObjCAtCatchStmt(const ObjCAtCatchStmt *Node) {
2081 if (const VarDecl *CatchParam = Node->getCatchParamDecl())
2082 dumpDecl(CatchParam);
2087 void ASTDumper::VisitObjCEncodeExpr(const ObjCEncodeExpr *Node) {
2089 dumpType(Node->getEncodedType());
2092 void ASTDumper::VisitObjCSelectorExpr(const ObjCSelectorExpr *Node) {
2096 Node->getSelector().print(OS);
2099 void ASTDumper::VisitObjCProtocolExpr(const ObjCProtocolExpr *Node) {
2102 OS << ' ' << *Node->getProtocol();
2105 void ASTDumper::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *Node) {
2107 if (Node->isImplicitProperty()) {
2108 OS << " Kind=MethodRef Getter=\"";
2109 if (Node->getImplicitPropertyGetter())
2110 Node->getImplicitPropertyGetter()->getSelector().print(OS);
2114 OS << "\" Setter=\"";
2115 if (ObjCMethodDecl *Setter = Node->getImplicitPropertySetter())
2116 Setter->getSelector().print(OS);
2121 OS << " Kind=PropertyRef Property=\"" << *Node->getExplicitProperty() <<'"';
2124 if (Node->isSuperReceiver())
2127 OS << " Messaging=";
2128 if (Node->isMessagingGetter() && Node->isMessagingSetter())
2129 OS << "Getter&Setter";
2130 else if (Node->isMessagingGetter())
2132 else if (Node->isMessagingSetter())
2136 void ASTDumper::VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *Node) {
2138 if (Node->isArraySubscriptRefExpr())
2139 OS << " Kind=ArraySubscript GetterForArray=\"";
2141 OS << " Kind=DictionarySubscript GetterForDictionary=\"";
2142 if (Node->getAtIndexMethodDecl())
2143 Node->getAtIndexMethodDecl()->getSelector().print(OS);
2147 if (Node->isArraySubscriptRefExpr())
2148 OS << "\" SetterForArray=\"";
2150 OS << "\" SetterForDictionary=\"";
2151 if (Node->setAtIndexMethodDecl())
2152 Node->setAtIndexMethodDecl()->getSelector().print(OS);
2157 void ASTDumper::VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *Node) {
2159 OS << " " << (Node->getValue() ? "__objc_yes" : "__objc_no");
2162 //===----------------------------------------------------------------------===//
2164 //===----------------------------------------------------------------------===//
2166 const char *ASTDumper::getCommandName(unsigned CommandID) {
2168 return Traits->getCommandInfo(CommandID)->Name;
2169 const CommandInfo *Info = CommandTraits::getBuiltinCommandInfo(CommandID);
2172 return "<not a builtin command>";
2175 void ASTDumper::dumpFullComment(const FullComment *C) {
2184 void ASTDumper::dumpComment(const Comment *C) {
2187 ColorScope Color(*this, NullColor);
2193 ColorScope Color(*this, CommentColor);
2194 OS << C->getCommentKindName();
2197 dumpSourceRange(C->getSourceRange());
2198 ConstCommentVisitor<ASTDumper>::visit(C);
2199 for (Comment::child_iterator I = C->child_begin(), E = C->child_end();
2205 void ASTDumper::visitTextComment(const TextComment *C) {
2206 OS << " Text=\"" << C->getText() << "\"";
2209 void ASTDumper::visitInlineCommandComment(const InlineCommandComment *C) {
2210 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\"";
2211 switch (C->getRenderKind()) {
2212 case InlineCommandComment::RenderNormal:
2213 OS << " RenderNormal";
2215 case InlineCommandComment::RenderBold:
2216 OS << " RenderBold";
2218 case InlineCommandComment::RenderMonospaced:
2219 OS << " RenderMonospaced";
2221 case InlineCommandComment::RenderEmphasized:
2222 OS << " RenderEmphasized";
2226 for (unsigned i = 0, e = C->getNumArgs(); i != e; ++i)
2227 OS << " Arg[" << i << "]=\"" << C->getArgText(i) << "\"";
2230 void ASTDumper::visitHTMLStartTagComment(const HTMLStartTagComment *C) {
2231 OS << " Name=\"" << C->getTagName() << "\"";
2232 if (C->getNumAttrs() != 0) {
2234 for (unsigned i = 0, e = C->getNumAttrs(); i != e; ++i) {
2235 const HTMLStartTagComment::Attribute &Attr = C->getAttr(i);
2236 OS << " \"" << Attr.Name << "=\"" << Attr.Value << "\"";
2239 if (C->isSelfClosing())
2240 OS << " SelfClosing";
2243 void ASTDumper::visitHTMLEndTagComment(const HTMLEndTagComment *C) {
2244 OS << " Name=\"" << C->getTagName() << "\"";
2247 void ASTDumper::visitBlockCommandComment(const BlockCommandComment *C) {
2248 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\"";
2249 for (unsigned i = 0, e = C->getNumArgs(); i != e; ++i)
2250 OS << " Arg[" << i << "]=\"" << C->getArgText(i) << "\"";
2253 void ASTDumper::visitParamCommandComment(const ParamCommandComment *C) {
2254 OS << " " << ParamCommandComment::getDirectionAsString(C->getDirection());
2256 if (C->isDirectionExplicit())
2257 OS << " explicitly";
2259 OS << " implicitly";
2261 if (C->hasParamName()) {
2262 if (C->isParamIndexValid())
2263 OS << " Param=\"" << C->getParamName(FC) << "\"";
2265 OS << " Param=\"" << C->getParamNameAsWritten() << "\"";
2268 if (C->isParamIndexValid() && !C->isVarArgParam())
2269 OS << " ParamIndex=" << C->getParamIndex();
2272 void ASTDumper::visitTParamCommandComment(const TParamCommandComment *C) {
2273 if (C->hasParamName()) {
2274 if (C->isPositionValid())
2275 OS << " Param=\"" << C->getParamName(FC) << "\"";
2277 OS << " Param=\"" << C->getParamNameAsWritten() << "\"";
2280 if (C->isPositionValid()) {
2281 OS << " Position=<";
2282 for (unsigned i = 0, e = C->getDepth(); i != e; ++i) {
2283 OS << C->getIndex(i);
2291 void ASTDumper::visitVerbatimBlockComment(const VerbatimBlockComment *C) {
2292 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\""
2293 " CloseName=\"" << C->getCloseName() << "\"";
2296 void ASTDumper::visitVerbatimBlockLineComment(
2297 const VerbatimBlockLineComment *C) {
2298 OS << " Text=\"" << C->getText() << "\"";
2301 void ASTDumper::visitVerbatimLineComment(const VerbatimLineComment *C) {
2302 OS << " Text=\"" << C->getText() << "\"";
2305 //===----------------------------------------------------------------------===//
2306 // Type method implementations
2307 //===----------------------------------------------------------------------===//
2309 void QualType::dump(const char *msg) const {
2311 llvm::errs() << msg << ": ";
2315 LLVM_DUMP_METHOD void QualType::dump() const {
2316 ASTDumper Dumper(llvm::errs(), nullptr, nullptr);
2317 Dumper.dumpTypeAsChild(*this);
2320 LLVM_DUMP_METHOD void Type::dump() const { QualType(this, 0).dump(); }
2322 //===----------------------------------------------------------------------===//
2323 // Decl method implementations
2324 //===----------------------------------------------------------------------===//
2326 LLVM_DUMP_METHOD void Decl::dump() const { dump(llvm::errs()); }
2328 LLVM_DUMP_METHOD void Decl::dump(raw_ostream &OS) const {
2329 ASTDumper P(OS, &getASTContext().getCommentCommandTraits(),
2330 &getASTContext().getSourceManager());
2334 LLVM_DUMP_METHOD void Decl::dumpColor() const {
2335 ASTDumper P(llvm::errs(), &getASTContext().getCommentCommandTraits(),
2336 &getASTContext().getSourceManager(), /*ShowColors*/true);
2340 LLVM_DUMP_METHOD void DeclContext::dumpLookups() const {
2341 dumpLookups(llvm::errs());
2344 LLVM_DUMP_METHOD void DeclContext::dumpLookups(raw_ostream &OS,
2345 bool DumpDecls) const {
2346 const DeclContext *DC = this;
2347 while (!DC->isTranslationUnit())
2348 DC = DC->getParent();
2349 ASTContext &Ctx = cast<TranslationUnitDecl>(DC)->getASTContext();
2350 ASTDumper P(OS, &Ctx.getCommentCommandTraits(), &Ctx.getSourceManager());
2351 P.dumpLookups(this, DumpDecls);
2354 //===----------------------------------------------------------------------===//
2355 // Stmt method implementations
2356 //===----------------------------------------------------------------------===//
2358 LLVM_DUMP_METHOD void Stmt::dump(SourceManager &SM) const {
2359 dump(llvm::errs(), SM);
2362 LLVM_DUMP_METHOD void Stmt::dump(raw_ostream &OS, SourceManager &SM) const {
2363 ASTDumper P(OS, nullptr, &SM);
2367 LLVM_DUMP_METHOD void Stmt::dump(raw_ostream &OS) const {
2368 ASTDumper P(OS, nullptr, nullptr);
2372 LLVM_DUMP_METHOD void Stmt::dump() const {
2373 ASTDumper P(llvm::errs(), nullptr, nullptr);
2377 LLVM_DUMP_METHOD void Stmt::dumpColor() const {
2378 ASTDumper P(llvm::errs(), nullptr, nullptr, /*ShowColors*/true);
2382 //===----------------------------------------------------------------------===//
2383 // Comment method implementations
2384 //===----------------------------------------------------------------------===//
2386 LLVM_DUMP_METHOD void Comment::dump() const {
2387 dump(llvm::errs(), nullptr, nullptr);
2390 LLVM_DUMP_METHOD void Comment::dump(const ASTContext &Context) const {
2391 dump(llvm::errs(), &Context.getCommentCommandTraits(),
2392 &Context.getSourceManager());
2395 void Comment::dump(raw_ostream &OS, const CommandTraits *Traits,
2396 const SourceManager *SM) const {
2397 const FullComment *FC = dyn_cast<FullComment>(this);
2398 ASTDumper D(OS, Traits, SM);
2399 D.dumpFullComment(FC);
2402 LLVM_DUMP_METHOD void Comment::dumpColor() const {
2403 const FullComment *FC = dyn_cast<FullComment>(this);
2404 ASTDumper D(llvm::errs(), nullptr, nullptr, /*ShowColors*/true);
2405 D.dumpFullComment(FC);