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/DeclOpenMP.h"
22 #include "clang/AST/DeclVisitor.h"
23 #include "clang/AST/LocInfoType.h"
24 #include "clang/AST/StmtVisitor.h"
25 #include "clang/AST/TypeVisitor.h"
26 #include "clang/Basic/Builtins.h"
27 #include "clang/Basic/Module.h"
28 #include "clang/Basic/SourceManager.h"
29 #include "llvm/Support/raw_ostream.h"
30 using namespace clang;
31 using namespace clang::comments;
33 //===----------------------------------------------------------------------===//
35 //===----------------------------------------------------------------------===//
38 // Colors used for various parts of the AST dump
39 // Do not use bold yellow for any text. It is hard to read on white screens.
41 struct TerminalColor {
42 raw_ostream::Colors Color;
48 // Bold Green - DeclKindNameColor, UndeserializedColor
49 // Yellow - AddressColor, LocationColor
50 // Blue - CommentColor, NullColor, IndentColor
51 // Bold Blue - AttrColor
52 // Bold Magenta - StmtColor
53 // Cyan - ValueKindColor, ObjectKindColor
54 // Bold Cyan - ValueColor, DeclNameColor
56 // Decl kind names (VarDecl, FunctionDecl, etc)
57 static const TerminalColor DeclKindNameColor = { raw_ostream::GREEN, true };
58 // Attr names (CleanupAttr, GuardedByAttr, etc)
59 static const TerminalColor AttrColor = { raw_ostream::BLUE, true };
60 // Statement names (DeclStmt, ImplicitCastExpr, etc)
61 static const TerminalColor StmtColor = { raw_ostream::MAGENTA, true };
62 // Comment names (FullComment, ParagraphComment, TextComment, etc)
63 static const TerminalColor CommentColor = { raw_ostream::BLUE, false };
65 // Type names (int, float, etc, plus user defined types)
66 static const TerminalColor TypeColor = { raw_ostream::GREEN, false };
69 static const TerminalColor AddressColor = { raw_ostream::YELLOW, false };
71 static const TerminalColor LocationColor = { raw_ostream::YELLOW, false };
74 static const TerminalColor ValueKindColor = { raw_ostream::CYAN, false };
75 // bitfield/objcproperty/objcsubscript/vectorcomponent
76 static const TerminalColor ObjectKindColor = { raw_ostream::CYAN, false };
79 static const TerminalColor NullColor = { raw_ostream::BLUE, false };
81 // Undeserialized entities
82 static const TerminalColor UndeserializedColor = { raw_ostream::GREEN, true };
84 // CastKind from CastExpr's
85 static const TerminalColor CastColor = { raw_ostream::RED, false };
87 // Value of the statement
88 static const TerminalColor ValueColor = { raw_ostream::CYAN, true };
90 static const TerminalColor DeclNameColor = { raw_ostream::CYAN, true };
92 // Indents ( `, -. | )
93 static const TerminalColor IndentColor = { raw_ostream::BLUE, false };
96 : public ConstDeclVisitor<ASTDumper>, public ConstStmtVisitor<ASTDumper>,
97 public ConstCommentVisitor<ASTDumper>, public TypeVisitor<ASTDumper> {
99 const CommandTraits *Traits;
100 const SourceManager *SM;
102 /// Pending[i] is an action to dump an entity at level i.
103 llvm::SmallVector<std::function<void(bool isLastChild)>, 32> Pending;
105 /// Indicates whether we should trigger deserialization of nodes that had
106 /// not already been loaded.
107 bool Deserialize = false;
109 /// Indicates whether we're at the top level.
110 bool TopLevel = true;
112 /// Indicates if we're handling the first child after entering a new depth.
113 bool FirstChild = true;
115 /// Prefix for currently-being-dumped entity.
118 /// Keep track of the last location we print out so that we can
119 /// print out deltas from then on out.
120 const char *LastLocFilename = "";
121 unsigned LastLocLine = ~0U;
123 /// The \c FullComment parent of the comment being dumped.
124 const FullComment *FC = nullptr;
128 /// Dump a child of the current node.
129 template<typename Fn> void dumpChild(Fn doDumpChild) {
130 // If we're at the top level, there's nothing interesting to do; just
135 while (!Pending.empty()) {
136 Pending.back()(true);
145 const FullComment *OrigFC = FC;
146 auto dumpWithIndent = [this, doDumpChild, OrigFC](bool isLastChild) {
147 // Print out the appropriate tree structure and work out the prefix for
148 // children of this node. For instance:
152 // | `-C Prefix = "| "
154 // |-E Prefix = " | "
158 // Note that the first level gets no prefix.
161 ColorScope Color(*this, IndentColor);
162 OS << Prefix << (isLastChild ? '`' : '|') << '-';
163 this->Prefix.push_back(isLastChild ? ' ' : '|');
164 this->Prefix.push_back(' ');
168 unsigned Depth = Pending.size();
173 // If any children are left, they're the last at their nesting level.
174 // Dump those ones out now.
175 while (Depth < Pending.size()) {
176 Pending.back()(true);
177 this->Pending.pop_back();
180 // Restore the old prefix.
181 this->Prefix.resize(Prefix.size() - 2);
185 Pending.push_back(std::move(dumpWithIndent));
187 Pending.back()(false);
188 Pending.back() = std::move(dumpWithIndent);
196 ColorScope(ASTDumper &Dumper, TerminalColor Color)
198 if (Dumper.ShowColors)
199 Dumper.OS.changeColor(Color.Color, Color.Bold);
202 if (Dumper.ShowColors)
203 Dumper.OS.resetColor();
208 ASTDumper(raw_ostream &OS, const CommandTraits *Traits,
209 const SourceManager *SM)
210 : OS(OS), Traits(Traits), SM(SM),
211 ShowColors(SM && SM->getDiagnostics().getShowColors()) { }
213 ASTDumper(raw_ostream &OS, const CommandTraits *Traits,
214 const SourceManager *SM, bool ShowColors)
215 : OS(OS), Traits(Traits), SM(SM), ShowColors(ShowColors) {}
217 void setDeserialize(bool D) { Deserialize = D; }
219 void dumpDecl(const Decl *D);
220 void dumpStmt(const Stmt *S);
221 void dumpFullComment(const FullComment *C);
224 void dumpPointer(const void *Ptr);
225 void dumpSourceRange(SourceRange R);
226 void dumpLocation(SourceLocation Loc);
227 void dumpBareType(QualType T, bool Desugar = true);
228 void dumpType(QualType T);
229 void dumpTypeAsChild(QualType T);
230 void dumpTypeAsChild(const Type *T);
231 void dumpBareDeclRef(const Decl *Node);
232 void dumpDeclRef(const Decl *Node, const char *Label = nullptr);
233 void dumpName(const NamedDecl *D);
234 bool hasNodes(const DeclContext *DC);
235 void dumpDeclContext(const DeclContext *DC);
236 void dumpLookups(const DeclContext *DC, bool DumpDecls);
237 void dumpAttr(const Attr *A);
240 void dumpAccessSpecifier(AccessSpecifier AS);
241 void dumpCXXCtorInitializer(const CXXCtorInitializer *Init);
242 void dumpTemplateParameters(const TemplateParameterList *TPL);
243 void dumpTemplateArgumentListInfo(const TemplateArgumentListInfo &TALI);
244 void dumpTemplateArgumentLoc(const TemplateArgumentLoc &A);
245 void dumpTemplateArgumentList(const TemplateArgumentList &TAL);
246 void dumpTemplateArgument(const TemplateArgument &A,
247 SourceRange R = SourceRange());
249 // Objective-C utilities.
250 void dumpObjCTypeParamList(const ObjCTypeParamList *typeParams);
253 void VisitComplexType(const ComplexType *T) {
254 dumpTypeAsChild(T->getElementType());
256 void VisitPointerType(const PointerType *T) {
257 dumpTypeAsChild(T->getPointeeType());
259 void VisitBlockPointerType(const BlockPointerType *T) {
260 dumpTypeAsChild(T->getPointeeType());
262 void VisitReferenceType(const ReferenceType *T) {
263 dumpTypeAsChild(T->getPointeeType());
265 void VisitRValueReferenceType(const ReferenceType *T) {
266 if (T->isSpelledAsLValue())
267 OS << " written as lvalue reference";
268 VisitReferenceType(T);
270 void VisitMemberPointerType(const MemberPointerType *T) {
271 dumpTypeAsChild(T->getClass());
272 dumpTypeAsChild(T->getPointeeType());
274 void VisitArrayType(const ArrayType *T) {
275 switch (T->getSizeModifier()) {
276 case ArrayType::Normal: break;
277 case ArrayType::Static: OS << " static"; break;
278 case ArrayType::Star: OS << " *"; break;
280 OS << " " << T->getIndexTypeQualifiers().getAsString();
281 dumpTypeAsChild(T->getElementType());
283 void VisitConstantArrayType(const ConstantArrayType *T) {
284 OS << " " << T->getSize();
287 void VisitVariableArrayType(const VariableArrayType *T) {
289 dumpSourceRange(T->getBracketsRange());
291 dumpStmt(T->getSizeExpr());
293 void VisitDependentSizedArrayType(const DependentSizedArrayType *T) {
296 dumpSourceRange(T->getBracketsRange());
297 dumpStmt(T->getSizeExpr());
299 void VisitDependentSizedExtVectorType(
300 const DependentSizedExtVectorType *T) {
302 dumpLocation(T->getAttributeLoc());
303 dumpTypeAsChild(T->getElementType());
304 dumpStmt(T->getSizeExpr());
306 void VisitVectorType(const VectorType *T) {
307 switch (T->getVectorKind()) {
308 case VectorType::GenericVector: break;
309 case VectorType::AltiVecVector: OS << " altivec"; break;
310 case VectorType::AltiVecPixel: OS << " altivec pixel"; break;
311 case VectorType::AltiVecBool: OS << " altivec bool"; break;
312 case VectorType::NeonVector: OS << " neon"; break;
313 case VectorType::NeonPolyVector: OS << " neon poly"; break;
315 OS << " " << T->getNumElements();
316 dumpTypeAsChild(T->getElementType());
318 void VisitFunctionType(const FunctionType *T) {
319 auto EI = T->getExtInfo();
320 if (EI.getNoReturn()) OS << " noreturn";
321 if (EI.getProducesResult()) OS << " produces_result";
322 if (EI.getHasRegParm()) OS << " regparm " << EI.getRegParm();
323 OS << " " << FunctionType::getNameForCallConv(EI.getCC());
324 dumpTypeAsChild(T->getReturnType());
326 void VisitFunctionProtoType(const FunctionProtoType *T) {
327 auto EPI = T->getExtProtoInfo();
328 if (EPI.HasTrailingReturn) OS << " trailing_return";
329 if (T->isConst()) OS << " const";
330 if (T->isVolatile()) OS << " volatile";
331 if (T->isRestrict()) OS << " restrict";
332 switch (EPI.RefQualifier) {
334 case RQ_LValue: OS << " &"; break;
335 case RQ_RValue: OS << " &&"; break;
337 // FIXME: Exception specification.
338 // FIXME: Consumed parameters.
339 VisitFunctionType(T);
340 for (QualType PT : T->getParamTypes())
343 dumpChild([=] { OS << "..."; });
345 void VisitUnresolvedUsingType(const UnresolvedUsingType *T) {
346 dumpDeclRef(T->getDecl());
348 void VisitTypedefType(const TypedefType *T) {
349 dumpDeclRef(T->getDecl());
351 void VisitTypeOfExprType(const TypeOfExprType *T) {
352 dumpStmt(T->getUnderlyingExpr());
354 void VisitDecltypeType(const DecltypeType *T) {
355 dumpStmt(T->getUnderlyingExpr());
357 void VisitUnaryTransformType(const UnaryTransformType *T) {
358 switch (T->getUTTKind()) {
359 case UnaryTransformType::EnumUnderlyingType:
360 OS << " underlying_type";
363 dumpTypeAsChild(T->getBaseType());
365 void VisitTagType(const TagType *T) {
366 dumpDeclRef(T->getDecl());
368 void VisitAttributedType(const AttributedType *T) {
370 dumpTypeAsChild(T->getModifiedType());
372 void VisitTemplateTypeParmType(const TemplateTypeParmType *T) {
373 OS << " depth " << T->getDepth() << " index " << T->getIndex();
374 if (T->isParameterPack()) OS << " pack";
375 dumpDeclRef(T->getDecl());
377 void VisitSubstTemplateTypeParmType(const SubstTemplateTypeParmType *T) {
378 dumpTypeAsChild(T->getReplacedParameter());
380 void VisitSubstTemplateTypeParmPackType(
381 const SubstTemplateTypeParmPackType *T) {
382 dumpTypeAsChild(T->getReplacedParameter());
383 dumpTemplateArgument(T->getArgumentPack());
385 void VisitAutoType(const AutoType *T) {
386 if (T->isDecltypeAuto()) OS << " decltype(auto)";
390 void VisitTemplateSpecializationType(const TemplateSpecializationType *T) {
391 if (T->isTypeAlias()) OS << " alias";
392 OS << " "; T->getTemplateName().dump(OS);
394 dumpTemplateArgument(Arg);
395 if (T->isTypeAlias())
396 dumpTypeAsChild(T->getAliasedType());
398 void VisitInjectedClassNameType(const InjectedClassNameType *T) {
399 dumpDeclRef(T->getDecl());
401 void VisitObjCInterfaceType(const ObjCInterfaceType *T) {
402 dumpDeclRef(T->getDecl());
404 void VisitObjCObjectPointerType(const ObjCObjectPointerType *T) {
405 dumpTypeAsChild(T->getPointeeType());
407 void VisitAtomicType(const AtomicType *T) {
408 dumpTypeAsChild(T->getValueType());
410 void VisitPipeType(const PipeType *T) {
411 dumpTypeAsChild(T->getElementType());
413 void VisitAdjustedType(const AdjustedType *T) {
414 dumpTypeAsChild(T->getOriginalType());
416 void VisitPackExpansionType(const PackExpansionType *T) {
417 if (auto N = T->getNumExpansions()) OS << " expansions " << *N;
419 dumpTypeAsChild(T->getPattern());
421 // FIXME: ElaboratedType, DependentNameType,
422 // DependentTemplateSpecializationType, ObjCObjectType
425 void VisitLabelDecl(const LabelDecl *D);
426 void VisitTypedefDecl(const TypedefDecl *D);
427 void VisitEnumDecl(const EnumDecl *D);
428 void VisitRecordDecl(const RecordDecl *D);
429 void VisitEnumConstantDecl(const EnumConstantDecl *D);
430 void VisitIndirectFieldDecl(const IndirectFieldDecl *D);
431 void VisitFunctionDecl(const FunctionDecl *D);
432 void VisitFieldDecl(const FieldDecl *D);
433 void VisitVarDecl(const VarDecl *D);
434 void VisitDecompositionDecl(const DecompositionDecl *D);
435 void VisitBindingDecl(const BindingDecl *D);
436 void VisitFileScopeAsmDecl(const FileScopeAsmDecl *D);
437 void VisitImportDecl(const ImportDecl *D);
438 void VisitPragmaCommentDecl(const PragmaCommentDecl *D);
439 void VisitPragmaDetectMismatchDecl(const PragmaDetectMismatchDecl *D);
440 void VisitCapturedDecl(const CapturedDecl *D);
443 void VisitOMPThreadPrivateDecl(const OMPThreadPrivateDecl *D);
444 void VisitOMPDeclareReductionDecl(const OMPDeclareReductionDecl *D);
445 void VisitOMPCapturedExprDecl(const OMPCapturedExprDecl *D);
448 void VisitNamespaceDecl(const NamespaceDecl *D);
449 void VisitUsingDirectiveDecl(const UsingDirectiveDecl *D);
450 void VisitNamespaceAliasDecl(const NamespaceAliasDecl *D);
451 void VisitTypeAliasDecl(const TypeAliasDecl *D);
452 void VisitTypeAliasTemplateDecl(const TypeAliasTemplateDecl *D);
453 void VisitCXXRecordDecl(const CXXRecordDecl *D);
454 void VisitStaticAssertDecl(const StaticAssertDecl *D);
455 template<typename SpecializationDecl>
456 void VisitTemplateDeclSpecialization(const SpecializationDecl *D,
457 bool DumpExplicitInst,
459 template<typename TemplateDecl>
460 void VisitTemplateDecl(const TemplateDecl *D, bool DumpExplicitInst);
461 void VisitFunctionTemplateDecl(const FunctionTemplateDecl *D);
462 void VisitClassTemplateDecl(const ClassTemplateDecl *D);
463 void VisitClassTemplateSpecializationDecl(
464 const ClassTemplateSpecializationDecl *D);
465 void VisitClassTemplatePartialSpecializationDecl(
466 const ClassTemplatePartialSpecializationDecl *D);
467 void VisitClassScopeFunctionSpecializationDecl(
468 const ClassScopeFunctionSpecializationDecl *D);
469 void VisitBuiltinTemplateDecl(const BuiltinTemplateDecl *D);
470 void VisitVarTemplateDecl(const VarTemplateDecl *D);
471 void VisitVarTemplateSpecializationDecl(
472 const VarTemplateSpecializationDecl *D);
473 void VisitVarTemplatePartialSpecializationDecl(
474 const VarTemplatePartialSpecializationDecl *D);
475 void VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D);
476 void VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D);
477 void VisitTemplateTemplateParmDecl(const TemplateTemplateParmDecl *D);
478 void VisitUsingDecl(const UsingDecl *D);
479 void VisitUnresolvedUsingTypenameDecl(const UnresolvedUsingTypenameDecl *D);
480 void VisitUnresolvedUsingValueDecl(const UnresolvedUsingValueDecl *D);
481 void VisitUsingShadowDecl(const UsingShadowDecl *D);
482 void VisitConstructorUsingShadowDecl(const ConstructorUsingShadowDecl *D);
483 void VisitLinkageSpecDecl(const LinkageSpecDecl *D);
484 void VisitAccessSpecDecl(const AccessSpecDecl *D);
485 void VisitFriendDecl(const FriendDecl *D);
488 void VisitObjCIvarDecl(const ObjCIvarDecl *D);
489 void VisitObjCMethodDecl(const ObjCMethodDecl *D);
490 void VisitObjCTypeParamDecl(const ObjCTypeParamDecl *D);
491 void VisitObjCCategoryDecl(const ObjCCategoryDecl *D);
492 void VisitObjCCategoryImplDecl(const ObjCCategoryImplDecl *D);
493 void VisitObjCProtocolDecl(const ObjCProtocolDecl *D);
494 void VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D);
495 void VisitObjCImplementationDecl(const ObjCImplementationDecl *D);
496 void VisitObjCCompatibleAliasDecl(const ObjCCompatibleAliasDecl *D);
497 void VisitObjCPropertyDecl(const ObjCPropertyDecl *D);
498 void VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D);
499 void VisitBlockDecl(const BlockDecl *D);
502 void VisitStmt(const Stmt *Node);
503 void VisitDeclStmt(const DeclStmt *Node);
504 void VisitAttributedStmt(const AttributedStmt *Node);
505 void VisitLabelStmt(const LabelStmt *Node);
506 void VisitGotoStmt(const GotoStmt *Node);
507 void VisitCXXCatchStmt(const CXXCatchStmt *Node);
508 void VisitCapturedStmt(const CapturedStmt *Node);
511 void VisitOMPExecutableDirective(const OMPExecutableDirective *Node);
514 void VisitExpr(const Expr *Node);
515 void VisitCastExpr(const CastExpr *Node);
516 void VisitDeclRefExpr(const DeclRefExpr *Node);
517 void VisitPredefinedExpr(const PredefinedExpr *Node);
518 void VisitCharacterLiteral(const CharacterLiteral *Node);
519 void VisitIntegerLiteral(const IntegerLiteral *Node);
520 void VisitFloatingLiteral(const FloatingLiteral *Node);
521 void VisitStringLiteral(const StringLiteral *Str);
522 void VisitInitListExpr(const InitListExpr *ILE);
523 void VisitArrayInitLoopExpr(const ArrayInitLoopExpr *ILE);
524 void VisitArrayInitIndexExpr(const ArrayInitIndexExpr *ILE);
525 void VisitUnaryOperator(const UnaryOperator *Node);
526 void VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *Node);
527 void VisitMemberExpr(const MemberExpr *Node);
528 void VisitExtVectorElementExpr(const ExtVectorElementExpr *Node);
529 void VisitBinaryOperator(const BinaryOperator *Node);
530 void VisitCompoundAssignOperator(const CompoundAssignOperator *Node);
531 void VisitAddrLabelExpr(const AddrLabelExpr *Node);
532 void VisitBlockExpr(const BlockExpr *Node);
533 void VisitOpaqueValueExpr(const OpaqueValueExpr *Node);
536 void VisitCXXNamedCastExpr(const CXXNamedCastExpr *Node);
537 void VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *Node);
538 void VisitCXXThisExpr(const CXXThisExpr *Node);
539 void VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *Node);
540 void VisitCXXConstructExpr(const CXXConstructExpr *Node);
541 void VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *Node);
542 void VisitCXXNewExpr(const CXXNewExpr *Node);
543 void VisitCXXDeleteExpr(const CXXDeleteExpr *Node);
544 void VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *Node);
545 void VisitExprWithCleanups(const ExprWithCleanups *Node);
546 void VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *Node);
547 void dumpCXXTemporary(const CXXTemporary *Temporary);
548 void VisitLambdaExpr(const LambdaExpr *Node) {
550 dumpDecl(Node->getLambdaClass());
552 void VisitSizeOfPackExpr(const SizeOfPackExpr *Node);
554 VisitCXXDependentScopeMemberExpr(const CXXDependentScopeMemberExpr *Node);
557 void VisitObjCAtCatchStmt(const ObjCAtCatchStmt *Node);
558 void VisitObjCEncodeExpr(const ObjCEncodeExpr *Node);
559 void VisitObjCMessageExpr(const ObjCMessageExpr *Node);
560 void VisitObjCBoxedExpr(const ObjCBoxedExpr *Node);
561 void VisitObjCSelectorExpr(const ObjCSelectorExpr *Node);
562 void VisitObjCProtocolExpr(const ObjCProtocolExpr *Node);
563 void VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *Node);
564 void VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *Node);
565 void VisitObjCIvarRefExpr(const ObjCIvarRefExpr *Node);
566 void VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *Node);
569 const char *getCommandName(unsigned CommandID);
570 void dumpComment(const Comment *C);
573 void visitTextComment(const TextComment *C);
574 void visitInlineCommandComment(const InlineCommandComment *C);
575 void visitHTMLStartTagComment(const HTMLStartTagComment *C);
576 void visitHTMLEndTagComment(const HTMLEndTagComment *C);
579 void visitBlockCommandComment(const BlockCommandComment *C);
580 void visitParamCommandComment(const ParamCommandComment *C);
581 void visitTParamCommandComment(const TParamCommandComment *C);
582 void visitVerbatimBlockComment(const VerbatimBlockComment *C);
583 void visitVerbatimBlockLineComment(const VerbatimBlockLineComment *C);
584 void visitVerbatimLineComment(const VerbatimLineComment *C);
588 //===----------------------------------------------------------------------===//
590 //===----------------------------------------------------------------------===//
592 void ASTDumper::dumpPointer(const void *Ptr) {
593 ColorScope Color(*this, AddressColor);
597 void ASTDumper::dumpLocation(SourceLocation Loc) {
601 ColorScope Color(*this, LocationColor);
602 SourceLocation SpellingLoc = SM->getSpellingLoc(Loc);
604 // The general format we print out is filename:line:col, but we drop pieces
605 // that haven't changed since the last loc printed.
606 PresumedLoc PLoc = SM->getPresumedLoc(SpellingLoc);
608 if (PLoc.isInvalid()) {
609 OS << "<invalid sloc>";
613 if (strcmp(PLoc.getFilename(), LastLocFilename) != 0) {
614 OS << PLoc.getFilename() << ':' << PLoc.getLine()
615 << ':' << PLoc.getColumn();
616 LastLocFilename = PLoc.getFilename();
617 LastLocLine = PLoc.getLine();
618 } else if (PLoc.getLine() != LastLocLine) {
619 OS << "line" << ':' << PLoc.getLine()
620 << ':' << PLoc.getColumn();
621 LastLocLine = PLoc.getLine();
623 OS << "col" << ':' << PLoc.getColumn();
627 void ASTDumper::dumpSourceRange(SourceRange R) {
628 // Can't translate locations if a SourceManager isn't available.
633 dumpLocation(R.getBegin());
634 if (R.getBegin() != R.getEnd()) {
636 dumpLocation(R.getEnd());
640 // <t2.c:123:421[blah], t2.c:412:321>
644 void ASTDumper::dumpBareType(QualType T, bool Desugar) {
645 ColorScope Color(*this, TypeColor);
647 SplitQualType T_split = T.split();
648 OS << "'" << QualType::getAsString(T_split) << "'";
650 if (Desugar && !T.isNull()) {
651 // If the type is sugared, also dump a (shallow) desugared type.
652 SplitQualType D_split = T.getSplitDesugaredType();
653 if (T_split != D_split)
654 OS << ":'" << QualType::getAsString(D_split) << "'";
658 void ASTDumper::dumpType(QualType T) {
663 void ASTDumper::dumpTypeAsChild(QualType T) {
664 SplitQualType SQT = T.split();
665 if (!SQT.Quals.hasQualifiers())
666 return dumpTypeAsChild(SQT.Ty);
670 dumpPointer(T.getAsOpaquePtr());
672 dumpBareType(T, false);
673 OS << " " << T.split().Quals.getAsString();
674 dumpTypeAsChild(T.split().Ty);
678 void ASTDumper::dumpTypeAsChild(const Type *T) {
681 ColorScope Color(*this, NullColor);
685 if (const LocInfoType *LIT = llvm::dyn_cast<LocInfoType>(T)) {
687 ColorScope Color(*this, TypeColor);
688 OS << "LocInfo Type";
691 dumpTypeAsChild(LIT->getTypeSourceInfo()->getType());
696 ColorScope Color(*this, TypeColor);
697 OS << T->getTypeClassName() << "Type";
701 dumpBareType(QualType(T, 0), false);
703 QualType SingleStepDesugar =
704 T->getLocallyUnqualifiedSingleStepDesugaredType();
705 if (SingleStepDesugar != QualType(T, 0))
707 if (T->isDependentType())
709 else if (T->isInstantiationDependentType())
710 OS << " instantiation_dependent";
711 if (T->isVariablyModifiedType())
712 OS << " variably_modified";
713 if (T->containsUnexpandedParameterPack())
714 OS << " contains_unexpanded_pack";
718 TypeVisitor<ASTDumper>::Visit(T);
720 if (SingleStepDesugar != QualType(T, 0))
721 dumpTypeAsChild(SingleStepDesugar);
725 void ASTDumper::dumpBareDeclRef(const Decl *D) {
727 ColorScope Color(*this, NullColor);
733 ColorScope Color(*this, DeclKindNameColor);
734 OS << D->getDeclKindName();
738 if (const NamedDecl *ND = dyn_cast<NamedDecl>(D)) {
739 ColorScope Color(*this, DeclNameColor);
740 OS << " '" << ND->getDeclName() << '\'';
743 if (const ValueDecl *VD = dyn_cast<ValueDecl>(D))
744 dumpType(VD->getType());
747 void ASTDumper::dumpDeclRef(const Decl *D, const char *Label) {
758 void ASTDumper::dumpName(const NamedDecl *ND) {
759 if (ND->getDeclName()) {
760 ColorScope Color(*this, DeclNameColor);
761 OS << ' ' << ND->getNameAsString();
765 bool ASTDumper::hasNodes(const DeclContext *DC) {
769 return DC->hasExternalLexicalStorage() ||
770 (Deserialize ? DC->decls_begin() != DC->decls_end()
771 : DC->noload_decls_begin() != DC->noload_decls_end());
774 void ASTDumper::dumpDeclContext(const DeclContext *DC) {
778 for (auto *D : (Deserialize ? DC->decls() : DC->noload_decls()))
781 if (DC->hasExternalLexicalStorage()) {
783 ColorScope Color(*this, UndeserializedColor);
784 OS << "<undeserialized declarations>";
789 void ASTDumper::dumpLookups(const DeclContext *DC, bool DumpDecls) {
791 OS << "StoredDeclsMap ";
792 dumpBareDeclRef(cast<Decl>(DC));
794 const DeclContext *Primary = DC->getPrimaryContext();
797 dumpPointer(cast<Decl>(Primary));
800 bool HasUndeserializedLookups = Primary->hasExternalVisibleStorage();
802 for (auto I = Deserialize ? Primary->lookups_begin()
803 : Primary->noload_lookups_begin(),
804 E = Deserialize ? Primary->lookups_end()
805 : Primary->noload_lookups_end();
807 DeclarationName Name = I.getLookupName();
808 DeclContextLookupResult R = *I;
811 OS << "DeclarationName ";
813 ColorScope Color(*this, DeclNameColor);
814 OS << '\'' << Name << '\'';
817 for (DeclContextLookupResult::iterator RI = R.begin(), RE = R.end();
820 dumpBareDeclRef(*RI);
822 if ((*RI)->isHidden())
825 // If requested, dump the redecl chain for this lookup.
827 // Dump earliest decl first.
828 std::function<void(Decl *)> DumpWithPrev = [&](Decl *D) {
829 if (Decl *Prev = D->getPreviousDecl())
840 if (HasUndeserializedLookups) {
842 ColorScope Color(*this, UndeserializedColor);
843 OS << "<undeserialized lookups>";
849 void ASTDumper::dumpAttr(const Attr *A) {
852 ColorScope Color(*this, AttrColor);
854 switch (A->getKind()) {
855 #define ATTR(X) case attr::X: OS << #X; break;
856 #include "clang/Basic/AttrList.inc"
861 dumpSourceRange(A->getRange());
862 if (A->isInherited())
866 #include "clang/AST/AttrDump.inc"
870 static void dumpPreviousDeclImpl(raw_ostream &OS, ...) {}
873 static void dumpPreviousDeclImpl(raw_ostream &OS, const Mergeable<T> *D) {
874 const T *First = D->getFirstDecl();
876 OS << " first " << First;
880 static void dumpPreviousDeclImpl(raw_ostream &OS, const Redeclarable<T> *D) {
881 const T *Prev = D->getPreviousDecl();
883 OS << " prev " << Prev;
886 /// Dump the previous declaration in the redeclaration chain for a declaration,
888 static void dumpPreviousDecl(raw_ostream &OS, const Decl *D) {
889 switch (D->getKind()) {
890 #define DECL(DERIVED, BASE) \
891 case Decl::DERIVED: \
892 return dumpPreviousDeclImpl(OS, cast<DERIVED##Decl>(D));
893 #define ABSTRACT_DECL(DECL)
894 #include "clang/AST/DeclNodes.inc"
896 llvm_unreachable("Decl that isn't part of DeclNodes.inc!");
899 //===----------------------------------------------------------------------===//
901 //===----------------------------------------------------------------------===//
903 void ASTDumper::dumpAccessSpecifier(AccessSpecifier AS) {
919 void ASTDumper::dumpCXXCtorInitializer(const CXXCtorInitializer *Init) {
921 OS << "CXXCtorInitializer";
922 if (Init->isAnyMemberInitializer()) {
924 dumpBareDeclRef(Init->getAnyMember());
925 } else if (Init->isBaseInitializer()) {
926 dumpType(QualType(Init->getBaseClass(), 0));
927 } else if (Init->isDelegatingInitializer()) {
928 dumpType(Init->getTypeSourceInfo()->getType());
930 llvm_unreachable("Unknown initializer type");
932 dumpStmt(Init->getInit());
936 void ASTDumper::dumpTemplateParameters(const TemplateParameterList *TPL) {
940 for (TemplateParameterList::const_iterator I = TPL->begin(), E = TPL->end();
945 void ASTDumper::dumpTemplateArgumentListInfo(
946 const TemplateArgumentListInfo &TALI) {
947 for (unsigned i = 0, e = TALI.size(); i < e; ++i)
948 dumpTemplateArgumentLoc(TALI[i]);
951 void ASTDumper::dumpTemplateArgumentLoc(const TemplateArgumentLoc &A) {
952 dumpTemplateArgument(A.getArgument(), A.getSourceRange());
955 void ASTDumper::dumpTemplateArgumentList(const TemplateArgumentList &TAL) {
956 for (unsigned i = 0, e = TAL.size(); i < e; ++i)
957 dumpTemplateArgument(TAL[i]);
960 void ASTDumper::dumpTemplateArgument(const TemplateArgument &A, SourceRange R) {
962 OS << "TemplateArgument";
966 switch (A.getKind()) {
967 case TemplateArgument::Null:
970 case TemplateArgument::Type:
972 dumpType(A.getAsType());
974 case TemplateArgument::Declaration:
976 dumpDeclRef(A.getAsDecl());
978 case TemplateArgument::NullPtr:
981 case TemplateArgument::Integral:
982 OS << " integral " << A.getAsIntegral();
984 case TemplateArgument::Template:
986 A.getAsTemplate().dump(OS);
988 case TemplateArgument::TemplateExpansion:
989 OS << " template expansion";
990 A.getAsTemplateOrTemplatePattern().dump(OS);
992 case TemplateArgument::Expression:
994 dumpStmt(A.getAsExpr());
996 case TemplateArgument::Pack:
998 for (TemplateArgument::pack_iterator I = A.pack_begin(), E = A.pack_end();
1000 dumpTemplateArgument(*I);
1006 //===----------------------------------------------------------------------===//
1007 // Objective-C Utilities
1008 //===----------------------------------------------------------------------===//
1009 void ASTDumper::dumpObjCTypeParamList(const ObjCTypeParamList *typeParams) {
1013 for (auto typeParam : *typeParams) {
1014 dumpDecl(typeParam);
1018 //===----------------------------------------------------------------------===//
1019 // Decl dumping methods.
1020 //===----------------------------------------------------------------------===//
1022 void ASTDumper::dumpDecl(const Decl *D) {
1025 ColorScope Color(*this, NullColor);
1031 ColorScope Color(*this, DeclKindNameColor);
1032 OS << D->getDeclKindName() << "Decl";
1035 if (D->getLexicalDeclContext() != D->getDeclContext())
1036 OS << " parent " << cast<Decl>(D->getDeclContext());
1037 dumpPreviousDecl(OS, D);
1038 dumpSourceRange(D->getSourceRange());
1040 dumpLocation(D->getLocation());
1041 if (D->isFromASTFile())
1043 if (Module *M = D->getOwningModule())
1044 OS << " in " << M->getFullModuleName();
1045 if (auto *ND = dyn_cast<NamedDecl>(D))
1046 for (Module *M : D->getASTContext().getModulesWithMergedDefinition(
1047 const_cast<NamedDecl *>(ND)))
1048 dumpChild([=] { OS << "also in " << M->getFullModuleName(); });
1049 if (const NamedDecl *ND = dyn_cast<NamedDecl>(D))
1052 if (D->isImplicit())
1056 else if (D->isThisDeclarationReferenced())
1057 OS << " referenced";
1058 if (D->isInvalidDecl())
1060 if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
1061 if (FD->isConstexpr())
1065 ConstDeclVisitor<ASTDumper>::Visit(D);
1067 for (Decl::attr_iterator I = D->attr_begin(), E = D->attr_end(); I != E;
1071 if (const FullComment *Comment =
1072 D->getASTContext().getLocalCommentForDeclUncached(D))
1073 dumpFullComment(Comment);
1075 // Decls within functions are visited by the body.
1076 if (!isa<FunctionDecl>(*D) && !isa<ObjCMethodDecl>(*D) &&
1077 hasNodes(dyn_cast<DeclContext>(D)))
1078 dumpDeclContext(cast<DeclContext>(D));
1082 void ASTDumper::VisitLabelDecl(const LabelDecl *D) {
1086 void ASTDumper::VisitTypedefDecl(const TypedefDecl *D) {
1088 dumpType(D->getUnderlyingType());
1089 if (D->isModulePrivate())
1090 OS << " __module_private__";
1091 dumpTypeAsChild(D->getUnderlyingType());
1094 void ASTDumper::VisitEnumDecl(const EnumDecl *D) {
1095 if (D->isScoped()) {
1096 if (D->isScopedUsingClassTag())
1102 if (D->isModulePrivate())
1103 OS << " __module_private__";
1105 dumpType(D->getIntegerType());
1108 void ASTDumper::VisitRecordDecl(const RecordDecl *D) {
1109 OS << ' ' << D->getKindName();
1111 if (D->isModulePrivate())
1112 OS << " __module_private__";
1113 if (D->isCompleteDefinition())
1114 OS << " definition";
1117 void ASTDumper::VisitEnumConstantDecl(const EnumConstantDecl *D) {
1119 dumpType(D->getType());
1120 if (const Expr *Init = D->getInitExpr())
1124 void ASTDumper::VisitIndirectFieldDecl(const IndirectFieldDecl *D) {
1126 dumpType(D->getType());
1128 for (auto *Child : D->chain())
1132 void ASTDumper::VisitFunctionDecl(const FunctionDecl *D) {
1134 dumpType(D->getType());
1136 StorageClass SC = D->getStorageClass();
1138 OS << ' ' << VarDecl::getStorageClassSpecifierString(SC);
1139 if (D->isInlineSpecified())
1141 if (D->isVirtualAsWritten())
1143 if (D->isModulePrivate())
1144 OS << " __module_private__";
1148 if (D->isDefaulted()) {
1153 if (D->isDeletedAsWritten())
1158 if (const FunctionProtoType *FPT = D->getType()->getAs<FunctionProtoType>()) {
1159 FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo();
1160 switch (EPI.ExceptionSpec.Type) {
1162 case EST_Unevaluated:
1163 OS << " noexcept-unevaluated " << EPI.ExceptionSpec.SourceDecl;
1165 case EST_Uninstantiated:
1166 OS << " noexcept-uninstantiated " << EPI.ExceptionSpec.SourceTemplate;
1171 if (const FunctionTemplateSpecializationInfo *FTSI =
1172 D->getTemplateSpecializationInfo())
1173 dumpTemplateArgumentList(*FTSI->TemplateArguments);
1175 if (!D->param_begin() && D->getNumParams())
1176 dumpChild([=] { OS << "<<NULL params x " << D->getNumParams() << ">>"; });
1178 for (const ParmVarDecl *Parameter : D->parameters())
1179 dumpDecl(Parameter);
1181 if (const CXXConstructorDecl *C = dyn_cast<CXXConstructorDecl>(D))
1182 for (CXXConstructorDecl::init_const_iterator I = C->init_begin(),
1185 dumpCXXCtorInitializer(*I);
1187 if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(D))
1188 if (MD->size_overridden_methods() != 0) {
1190 [=](const CXXMethodDecl *D) {
1191 SplitQualType T_split = D->getType().split();
1192 OS << D << " " << D->getParent()->getName() << "::";
1193 if (isa<CXXDestructorDecl>(D))
1194 OS << "~" << D->getParent()->getName();
1197 OS << " '" << QualType::getAsString(T_split) << "'";
1201 auto FirstOverrideItr = MD->begin_overridden_methods();
1202 OS << "Overrides: [ ";
1203 dumpOverride(*FirstOverrideItr);
1204 for (const auto *Override :
1205 llvm::make_range(FirstOverrideItr + 1,
1206 MD->end_overridden_methods()))
1207 dumpOverride(Override);
1212 if (D->doesThisDeclarationHaveABody())
1213 dumpStmt(D->getBody());
1216 void ASTDumper::VisitFieldDecl(const FieldDecl *D) {
1218 dumpType(D->getType());
1221 if (D->isModulePrivate())
1222 OS << " __module_private__";
1224 if (D->isBitField())
1225 dumpStmt(D->getBitWidth());
1226 if (Expr *Init = D->getInClassInitializer())
1230 void ASTDumper::VisitVarDecl(const VarDecl *D) {
1232 dumpType(D->getType());
1233 StorageClass SC = D->getStorageClass();
1235 OS << ' ' << VarDecl::getStorageClassSpecifierString(SC);
1236 switch (D->getTLSKind()) {
1237 case VarDecl::TLS_None: break;
1238 case VarDecl::TLS_Static: OS << " tls"; break;
1239 case VarDecl::TLS_Dynamic: OS << " tls_dynamic"; break;
1241 if (D->isModulePrivate())
1242 OS << " __module_private__";
1243 if (D->isNRVOVariable())
1247 if (D->isConstexpr())
1250 switch (D->getInitStyle()) {
1251 case VarDecl::CInit: OS << " cinit"; break;
1252 case VarDecl::CallInit: OS << " callinit"; break;
1253 case VarDecl::ListInit: OS << " listinit"; break;
1255 dumpStmt(D->getInit());
1259 void ASTDumper::VisitDecompositionDecl(const DecompositionDecl *D) {
1261 for (auto *B : D->bindings())
1265 void ASTDumper::VisitBindingDecl(const BindingDecl *D) {
1267 dumpType(D->getType());
1268 if (auto *E = D->getBinding())
1272 void ASTDumper::VisitFileScopeAsmDecl(const FileScopeAsmDecl *D) {
1273 dumpStmt(D->getAsmString());
1276 void ASTDumper::VisitImportDecl(const ImportDecl *D) {
1277 OS << ' ' << D->getImportedModule()->getFullModuleName();
1280 void ASTDumper::VisitPragmaCommentDecl(const PragmaCommentDecl *D) {
1282 switch (D->getCommentKind()) {
1283 case PCK_Unknown: llvm_unreachable("unexpected pragma comment kind");
1284 case PCK_Compiler: OS << "compiler"; break;
1285 case PCK_ExeStr: OS << "exestr"; break;
1286 case PCK_Lib: OS << "lib"; break;
1287 case PCK_Linker: OS << "linker"; break;
1288 case PCK_User: OS << "user"; break;
1290 StringRef Arg = D->getArg();
1292 OS << " \"" << Arg << "\"";
1295 void ASTDumper::VisitPragmaDetectMismatchDecl(
1296 const PragmaDetectMismatchDecl *D) {
1297 OS << " \"" << D->getName() << "\" \"" << D->getValue() << "\"";
1300 void ASTDumper::VisitCapturedDecl(const CapturedDecl *D) {
1301 dumpStmt(D->getBody());
1304 //===----------------------------------------------------------------------===//
1305 // OpenMP Declarations
1306 //===----------------------------------------------------------------------===//
1308 void ASTDumper::VisitOMPThreadPrivateDecl(const OMPThreadPrivateDecl *D) {
1309 for (auto *E : D->varlists())
1313 void ASTDumper::VisitOMPDeclareReductionDecl(const OMPDeclareReductionDecl *D) {
1315 dumpType(D->getType());
1317 dumpStmt(D->getCombiner());
1318 if (auto *Initializer = D->getInitializer()) {
1319 OS << " initializer";
1320 dumpStmt(Initializer);
1324 void ASTDumper::VisitOMPCapturedExprDecl(const OMPCapturedExprDecl *D) {
1326 dumpType(D->getType());
1327 dumpStmt(D->getInit());
1330 //===----------------------------------------------------------------------===//
1332 //===----------------------------------------------------------------------===//
1334 void ASTDumper::VisitNamespaceDecl(const NamespaceDecl *D) {
1338 if (!D->isOriginalNamespace())
1339 dumpDeclRef(D->getOriginalNamespace(), "original");
1342 void ASTDumper::VisitUsingDirectiveDecl(const UsingDirectiveDecl *D) {
1344 dumpBareDeclRef(D->getNominatedNamespace());
1347 void ASTDumper::VisitNamespaceAliasDecl(const NamespaceAliasDecl *D) {
1349 dumpDeclRef(D->getAliasedNamespace());
1352 void ASTDumper::VisitTypeAliasDecl(const TypeAliasDecl *D) {
1354 dumpType(D->getUnderlyingType());
1355 dumpTypeAsChild(D->getUnderlyingType());
1358 void ASTDumper::VisitTypeAliasTemplateDecl(const TypeAliasTemplateDecl *D) {
1360 dumpTemplateParameters(D->getTemplateParameters());
1361 dumpDecl(D->getTemplatedDecl());
1364 void ASTDumper::VisitCXXRecordDecl(const CXXRecordDecl *D) {
1366 if (!D->isCompleteDefinition())
1369 for (const auto &I : D->bases()) {
1373 dumpAccessSpecifier(I.getAccessSpecifier());
1374 dumpType(I.getType());
1375 if (I.isPackExpansion())
1381 void ASTDumper::VisitStaticAssertDecl(const StaticAssertDecl *D) {
1382 dumpStmt(D->getAssertExpr());
1383 dumpStmt(D->getMessage());
1386 template<typename SpecializationDecl>
1387 void ASTDumper::VisitTemplateDeclSpecialization(const SpecializationDecl *D,
1388 bool DumpExplicitInst,
1390 bool DumpedAny = false;
1391 for (auto *RedeclWithBadType : D->redecls()) {
1392 // FIXME: The redecls() range sometimes has elements of a less-specific
1393 // type. (In particular, ClassTemplateSpecializationDecl::redecls() gives
1394 // us TagDecls, and should give CXXRecordDecls).
1395 auto *Redecl = dyn_cast<SpecializationDecl>(RedeclWithBadType);
1397 // Found the injected-class-name for a class template. This will be dumped
1398 // as part of its surrounding class so we don't need to dump it here.
1399 assert(isa<CXXRecordDecl>(RedeclWithBadType) &&
1400 "expected an injected-class-name");
1404 switch (Redecl->getTemplateSpecializationKind()) {
1405 case TSK_ExplicitInstantiationDeclaration:
1406 case TSK_ExplicitInstantiationDefinition:
1407 if (!DumpExplicitInst)
1410 case TSK_Undeclared:
1411 case TSK_ImplicitInstantiation:
1413 dumpDeclRef(Redecl);
1418 case TSK_ExplicitSpecialization:
1423 // Ensure we dump at least one decl for each specialization.
1428 template<typename TemplateDecl>
1429 void ASTDumper::VisitTemplateDecl(const TemplateDecl *D,
1430 bool DumpExplicitInst) {
1432 dumpTemplateParameters(D->getTemplateParameters());
1434 dumpDecl(D->getTemplatedDecl());
1436 for (auto *Child : D->specializations())
1437 VisitTemplateDeclSpecialization(Child, DumpExplicitInst,
1438 !D->isCanonicalDecl());
1441 void ASTDumper::VisitFunctionTemplateDecl(const FunctionTemplateDecl *D) {
1442 // FIXME: We don't add a declaration of a function template specialization
1443 // to its context when it's explicitly instantiated, so dump explicit
1444 // instantiations when we dump the template itself.
1445 VisitTemplateDecl(D, true);
1448 void ASTDumper::VisitClassTemplateDecl(const ClassTemplateDecl *D) {
1449 VisitTemplateDecl(D, false);
1452 void ASTDumper::VisitClassTemplateSpecializationDecl(
1453 const ClassTemplateSpecializationDecl *D) {
1454 VisitCXXRecordDecl(D);
1455 dumpTemplateArgumentList(D->getTemplateArgs());
1458 void ASTDumper::VisitClassTemplatePartialSpecializationDecl(
1459 const ClassTemplatePartialSpecializationDecl *D) {
1460 VisitClassTemplateSpecializationDecl(D);
1461 dumpTemplateParameters(D->getTemplateParameters());
1464 void ASTDumper::VisitClassScopeFunctionSpecializationDecl(
1465 const ClassScopeFunctionSpecializationDecl *D) {
1466 dumpDeclRef(D->getSpecialization());
1467 if (D->hasExplicitTemplateArgs())
1468 dumpTemplateArgumentListInfo(D->templateArgs());
1471 void ASTDumper::VisitVarTemplateDecl(const VarTemplateDecl *D) {
1472 VisitTemplateDecl(D, false);
1475 void ASTDumper::VisitBuiltinTemplateDecl(const BuiltinTemplateDecl *D) {
1477 dumpTemplateParameters(D->getTemplateParameters());
1480 void ASTDumper::VisitVarTemplateSpecializationDecl(
1481 const VarTemplateSpecializationDecl *D) {
1482 dumpTemplateArgumentList(D->getTemplateArgs());
1486 void ASTDumper::VisitVarTemplatePartialSpecializationDecl(
1487 const VarTemplatePartialSpecializationDecl *D) {
1488 dumpTemplateParameters(D->getTemplateParameters());
1489 VisitVarTemplateSpecializationDecl(D);
1492 void ASTDumper::VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D) {
1493 if (D->wasDeclaredWithTypename())
1497 OS << " depth " << D->getDepth() << " index " << D->getIndex();
1498 if (D->isParameterPack())
1501 if (D->hasDefaultArgument())
1502 dumpTemplateArgument(D->getDefaultArgument());
1505 void ASTDumper::VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D) {
1506 dumpType(D->getType());
1507 OS << " depth " << D->getDepth() << " index " << D->getIndex();
1508 if (D->isParameterPack())
1511 if (D->hasDefaultArgument())
1512 dumpTemplateArgument(D->getDefaultArgument());
1515 void ASTDumper::VisitTemplateTemplateParmDecl(
1516 const TemplateTemplateParmDecl *D) {
1517 OS << " depth " << D->getDepth() << " index " << D->getIndex();
1518 if (D->isParameterPack())
1521 dumpTemplateParameters(D->getTemplateParameters());
1522 if (D->hasDefaultArgument())
1523 dumpTemplateArgumentLoc(D->getDefaultArgument());
1526 void ASTDumper::VisitUsingDecl(const UsingDecl *D) {
1528 if (D->getQualifier())
1529 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
1530 OS << D->getNameAsString();
1533 void ASTDumper::VisitUnresolvedUsingTypenameDecl(
1534 const UnresolvedUsingTypenameDecl *D) {
1536 if (D->getQualifier())
1537 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
1538 OS << D->getNameAsString();
1541 void ASTDumper::VisitUnresolvedUsingValueDecl(const UnresolvedUsingValueDecl *D) {
1543 if (D->getQualifier())
1544 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
1545 OS << D->getNameAsString();
1546 dumpType(D->getType());
1549 void ASTDumper::VisitUsingShadowDecl(const UsingShadowDecl *D) {
1551 dumpBareDeclRef(D->getTargetDecl());
1552 if (auto *TD = dyn_cast<TypeDecl>(D->getUnderlyingDecl()))
1553 dumpTypeAsChild(TD->getTypeForDecl());
1556 void ASTDumper::VisitConstructorUsingShadowDecl(
1557 const ConstructorUsingShadowDecl *D) {
1558 if (D->constructsVirtualBase())
1563 dumpBareDeclRef(D->getTargetDecl());
1568 dumpBareDeclRef(D->getNominatedBaseClass());
1570 dumpBareDeclRef(D->getNominatedBaseClassShadowDecl());
1574 OS << "constructed ";
1575 dumpBareDeclRef(D->getConstructedBaseClass());
1577 dumpBareDeclRef(D->getConstructedBaseClassShadowDecl());
1581 void ASTDumper::VisitLinkageSpecDecl(const LinkageSpecDecl *D) {
1582 switch (D->getLanguage()) {
1583 case LinkageSpecDecl::lang_c: OS << " C"; break;
1584 case LinkageSpecDecl::lang_cxx: OS << " C++"; break;
1588 void ASTDumper::VisitAccessSpecDecl(const AccessSpecDecl *D) {
1590 dumpAccessSpecifier(D->getAccess());
1593 void ASTDumper::VisitFriendDecl(const FriendDecl *D) {
1594 if (TypeSourceInfo *T = D->getFriendType())
1595 dumpType(T->getType());
1597 dumpDecl(D->getFriendDecl());
1600 //===----------------------------------------------------------------------===//
1601 // Obj-C Declarations
1602 //===----------------------------------------------------------------------===//
1604 void ASTDumper::VisitObjCIvarDecl(const ObjCIvarDecl *D) {
1606 dumpType(D->getType());
1607 if (D->getSynthesize())
1608 OS << " synthesize";
1610 switch (D->getAccessControl()) {
1611 case ObjCIvarDecl::None:
1614 case ObjCIvarDecl::Private:
1617 case ObjCIvarDecl::Protected:
1620 case ObjCIvarDecl::Public:
1623 case ObjCIvarDecl::Package:
1629 void ASTDumper::VisitObjCMethodDecl(const ObjCMethodDecl *D) {
1630 if (D->isInstanceMethod())
1635 dumpType(D->getReturnType());
1637 if (D->isThisDeclarationADefinition()) {
1640 for (const ParmVarDecl *Parameter : D->parameters())
1641 dumpDecl(Parameter);
1644 if (D->isVariadic())
1645 dumpChild([=] { OS << "..."; });
1648 dumpStmt(D->getBody());
1651 void ASTDumper::VisitObjCTypeParamDecl(const ObjCTypeParamDecl *D) {
1653 switch (D->getVariance()) {
1654 case ObjCTypeParamVariance::Invariant:
1657 case ObjCTypeParamVariance::Covariant:
1661 case ObjCTypeParamVariance::Contravariant:
1662 OS << " contravariant";
1666 if (D->hasExplicitBound())
1668 dumpType(D->getUnderlyingType());
1671 void ASTDumper::VisitObjCCategoryDecl(const ObjCCategoryDecl *D) {
1673 dumpDeclRef(D->getClassInterface());
1674 dumpObjCTypeParamList(D->getTypeParamList());
1675 dumpDeclRef(D->getImplementation());
1676 for (ObjCCategoryDecl::protocol_iterator I = D->protocol_begin(),
1677 E = D->protocol_end();
1682 void ASTDumper::VisitObjCCategoryImplDecl(const ObjCCategoryImplDecl *D) {
1684 dumpDeclRef(D->getClassInterface());
1685 dumpDeclRef(D->getCategoryDecl());
1688 void ASTDumper::VisitObjCProtocolDecl(const ObjCProtocolDecl *D) {
1691 for (auto *Child : D->protocols())
1695 void ASTDumper::VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D) {
1697 dumpObjCTypeParamList(D->getTypeParamListAsWritten());
1698 dumpDeclRef(D->getSuperClass(), "super");
1700 dumpDeclRef(D->getImplementation());
1701 for (auto *Child : D->protocols())
1705 void ASTDumper::VisitObjCImplementationDecl(const ObjCImplementationDecl *D) {
1707 dumpDeclRef(D->getSuperClass(), "super");
1708 dumpDeclRef(D->getClassInterface());
1709 for (ObjCImplementationDecl::init_const_iterator I = D->init_begin(),
1712 dumpCXXCtorInitializer(*I);
1715 void ASTDumper::VisitObjCCompatibleAliasDecl(const ObjCCompatibleAliasDecl *D) {
1717 dumpDeclRef(D->getClassInterface());
1720 void ASTDumper::VisitObjCPropertyDecl(const ObjCPropertyDecl *D) {
1722 dumpType(D->getType());
1724 if (D->getPropertyImplementation() == ObjCPropertyDecl::Required)
1726 else if (D->getPropertyImplementation() == ObjCPropertyDecl::Optional)
1729 ObjCPropertyDecl::PropertyAttributeKind Attrs = D->getPropertyAttributes();
1730 if (Attrs != ObjCPropertyDecl::OBJC_PR_noattr) {
1731 if (Attrs & ObjCPropertyDecl::OBJC_PR_readonly)
1733 if (Attrs & ObjCPropertyDecl::OBJC_PR_assign)
1735 if (Attrs & ObjCPropertyDecl::OBJC_PR_readwrite)
1737 if (Attrs & ObjCPropertyDecl::OBJC_PR_retain)
1739 if (Attrs & ObjCPropertyDecl::OBJC_PR_copy)
1741 if (Attrs & ObjCPropertyDecl::OBJC_PR_nonatomic)
1743 if (Attrs & ObjCPropertyDecl::OBJC_PR_atomic)
1745 if (Attrs & ObjCPropertyDecl::OBJC_PR_weak)
1747 if (Attrs & ObjCPropertyDecl::OBJC_PR_strong)
1749 if (Attrs & ObjCPropertyDecl::OBJC_PR_unsafe_unretained)
1750 OS << " unsafe_unretained";
1751 if (Attrs & ObjCPropertyDecl::OBJC_PR_class)
1753 if (Attrs & ObjCPropertyDecl::OBJC_PR_getter)
1754 dumpDeclRef(D->getGetterMethodDecl(), "getter");
1755 if (Attrs & ObjCPropertyDecl::OBJC_PR_setter)
1756 dumpDeclRef(D->getSetterMethodDecl(), "setter");
1760 void ASTDumper::VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D) {
1761 dumpName(D->getPropertyDecl());
1762 if (D->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize)
1763 OS << " synthesize";
1766 dumpDeclRef(D->getPropertyDecl());
1767 dumpDeclRef(D->getPropertyIvarDecl());
1770 void ASTDumper::VisitBlockDecl(const BlockDecl *D) {
1771 for (auto I : D->parameters())
1774 if (D->isVariadic())
1775 dumpChild([=]{ OS << "..."; });
1777 if (D->capturesCXXThis())
1778 dumpChild([=]{ OS << "capture this"; });
1780 for (const auto &I : D->captures()) {
1787 if (I.getVariable()) {
1789 dumpBareDeclRef(I.getVariable());
1791 if (I.hasCopyExpr())
1792 dumpStmt(I.getCopyExpr());
1795 dumpStmt(D->getBody());
1798 //===----------------------------------------------------------------------===//
1799 // Stmt dumping methods.
1800 //===----------------------------------------------------------------------===//
1802 void ASTDumper::dumpStmt(const Stmt *S) {
1805 ColorScope Color(*this, NullColor);
1810 if (const DeclStmt *DS = dyn_cast<DeclStmt>(S)) {
1815 ConstStmtVisitor<ASTDumper>::Visit(S);
1817 for (const Stmt *SubStmt : S->children())
1822 void ASTDumper::VisitStmt(const Stmt *Node) {
1824 ColorScope Color(*this, StmtColor);
1825 OS << Node->getStmtClassName();
1828 dumpSourceRange(Node->getSourceRange());
1831 void ASTDumper::VisitDeclStmt(const DeclStmt *Node) {
1833 for (DeclStmt::const_decl_iterator I = Node->decl_begin(),
1834 E = Node->decl_end();
1839 void ASTDumper::VisitAttributedStmt(const AttributedStmt *Node) {
1841 for (ArrayRef<const Attr *>::iterator I = Node->getAttrs().begin(),
1842 E = Node->getAttrs().end();
1847 void ASTDumper::VisitLabelStmt(const LabelStmt *Node) {
1849 OS << " '" << Node->getName() << "'";
1852 void ASTDumper::VisitGotoStmt(const GotoStmt *Node) {
1854 OS << " '" << Node->getLabel()->getName() << "'";
1855 dumpPointer(Node->getLabel());
1858 void ASTDumper::VisitCXXCatchStmt(const CXXCatchStmt *Node) {
1860 dumpDecl(Node->getExceptionDecl());
1863 void ASTDumper::VisitCapturedStmt(const CapturedStmt *Node) {
1865 dumpDecl(Node->getCapturedDecl());
1868 //===----------------------------------------------------------------------===//
1869 // OpenMP dumping methods.
1870 //===----------------------------------------------------------------------===//
1872 void ASTDumper::VisitOMPExecutableDirective(
1873 const OMPExecutableDirective *Node) {
1875 for (auto *C : Node->clauses()) {
1878 ColorScope Color(*this, NullColor);
1879 OS << "<<<NULL>>> OMPClause";
1883 ColorScope Color(*this, AttrColor);
1884 StringRef ClauseName(getOpenMPClauseName(C->getClauseKind()));
1885 OS << "OMP" << ClauseName.substr(/*Start=*/0, /*N=*/1).upper()
1886 << ClauseName.drop_front() << "Clause";
1889 dumpSourceRange(SourceRange(C->getLocStart(), C->getLocEnd()));
1890 if (C->isImplicit())
1891 OS << " <implicit>";
1892 for (auto *S : C->children())
1898 //===----------------------------------------------------------------------===//
1899 // Expr dumping methods.
1900 //===----------------------------------------------------------------------===//
1902 void ASTDumper::VisitExpr(const Expr *Node) {
1904 dumpType(Node->getType());
1907 ColorScope Color(*this, ValueKindColor);
1908 switch (Node->getValueKind()) {
1921 ColorScope Color(*this, ObjectKindColor);
1922 switch (Node->getObjectKind()) {
1928 case OK_ObjCProperty:
1929 OS << " objcproperty";
1931 case OK_ObjCSubscript:
1932 OS << " objcsubscript";
1934 case OK_VectorComponent:
1935 OS << " vectorcomponent";
1941 static void dumpBasePath(raw_ostream &OS, const CastExpr *Node) {
1942 if (Node->path_empty())
1947 for (CastExpr::path_const_iterator I = Node->path_begin(),
1948 E = Node->path_end();
1950 const CXXBaseSpecifier *Base = *I;
1954 const CXXRecordDecl *RD =
1955 cast<CXXRecordDecl>(Base->getType()->getAs<RecordType>()->getDecl());
1957 if (Base->isVirtual())
1959 OS << RD->getName();
1966 void ASTDumper::VisitCastExpr(const CastExpr *Node) {
1970 ColorScope Color(*this, CastColor);
1971 OS << Node->getCastKindName();
1973 dumpBasePath(OS, Node);
1977 void ASTDumper::VisitDeclRefExpr(const DeclRefExpr *Node) {
1981 dumpBareDeclRef(Node->getDecl());
1982 if (Node->getDecl() != Node->getFoundDecl()) {
1984 dumpBareDeclRef(Node->getFoundDecl());
1989 void ASTDumper::VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *Node) {
1992 if (!Node->requiresADL())
1994 OS << "ADL) = '" << Node->getName() << '\'';
1996 UnresolvedLookupExpr::decls_iterator
1997 I = Node->decls_begin(), E = Node->decls_end();
2004 void ASTDumper::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *Node) {
2008 ColorScope Color(*this, DeclKindNameColor);
2009 OS << " " << Node->getDecl()->getDeclKindName() << "Decl";
2011 OS << "='" << *Node->getDecl() << "'";
2012 dumpPointer(Node->getDecl());
2013 if (Node->isFreeIvar())
2014 OS << " isFreeIvar";
2017 void ASTDumper::VisitPredefinedExpr(const PredefinedExpr *Node) {
2019 OS << " " << PredefinedExpr::getIdentTypeName(Node->getIdentType());
2022 void ASTDumper::VisitCharacterLiteral(const CharacterLiteral *Node) {
2024 ColorScope Color(*this, ValueColor);
2025 OS << " " << Node->getValue();
2028 void ASTDumper::VisitIntegerLiteral(const IntegerLiteral *Node) {
2031 bool isSigned = Node->getType()->isSignedIntegerType();
2032 ColorScope Color(*this, ValueColor);
2033 OS << " " << Node->getValue().toString(10, isSigned);
2036 void ASTDumper::VisitFloatingLiteral(const FloatingLiteral *Node) {
2038 ColorScope Color(*this, ValueColor);
2039 OS << " " << Node->getValueAsApproximateDouble();
2042 void ASTDumper::VisitStringLiteral(const StringLiteral *Str) {
2044 ColorScope Color(*this, ValueColor);
2046 Str->outputString(OS);
2049 void ASTDumper::VisitInitListExpr(const InitListExpr *ILE) {
2051 if (auto *Filler = ILE->getArrayFiller()) {
2053 OS << "array filler";
2057 if (auto *Field = ILE->getInitializedFieldInUnion()) {
2059 dumpBareDeclRef(Field);
2063 void ASTDumper::VisitArrayInitLoopExpr(const ArrayInitLoopExpr *E) {
2067 void ASTDumper::VisitArrayInitIndexExpr(const ArrayInitIndexExpr *E) {
2071 void ASTDumper::VisitUnaryOperator(const UnaryOperator *Node) {
2073 OS << " " << (Node->isPostfix() ? "postfix" : "prefix")
2074 << " '" << UnaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
2077 void ASTDumper::VisitUnaryExprOrTypeTraitExpr(
2078 const UnaryExprOrTypeTraitExpr *Node) {
2080 switch(Node->getKind()) {
2090 case UETT_OpenMPRequiredSimdAlign:
2091 OS << " __builtin_omp_required_simd_align";
2094 if (Node->isArgumentType())
2095 dumpType(Node->getArgumentType());
2098 void ASTDumper::VisitMemberExpr(const MemberExpr *Node) {
2100 OS << " " << (Node->isArrow() ? "->" : ".") << *Node->getMemberDecl();
2101 dumpPointer(Node->getMemberDecl());
2104 void ASTDumper::VisitExtVectorElementExpr(const ExtVectorElementExpr *Node) {
2106 OS << " " << Node->getAccessor().getNameStart();
2109 void ASTDumper::VisitBinaryOperator(const BinaryOperator *Node) {
2111 OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
2114 void ASTDumper::VisitCompoundAssignOperator(
2115 const CompoundAssignOperator *Node) {
2117 OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode())
2118 << "' ComputeLHSTy=";
2119 dumpBareType(Node->getComputationLHSType());
2120 OS << " ComputeResultTy=";
2121 dumpBareType(Node->getComputationResultType());
2124 void ASTDumper::VisitBlockExpr(const BlockExpr *Node) {
2126 dumpDecl(Node->getBlockDecl());
2129 void ASTDumper::VisitOpaqueValueExpr(const OpaqueValueExpr *Node) {
2132 if (Expr *Source = Node->getSourceExpr())
2138 void ASTDumper::VisitAddrLabelExpr(const AddrLabelExpr *Node) {
2140 OS << " " << Node->getLabel()->getName();
2141 dumpPointer(Node->getLabel());
2144 //===----------------------------------------------------------------------===//
2146 //===----------------------------------------------------------------------===//
2148 void ASTDumper::VisitCXXNamedCastExpr(const CXXNamedCastExpr *Node) {
2150 OS << " " << Node->getCastName()
2151 << "<" << Node->getTypeAsWritten().getAsString() << ">"
2152 << " <" << Node->getCastKindName();
2153 dumpBasePath(OS, Node);
2157 void ASTDumper::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *Node) {
2159 OS << " " << (Node->getValue() ? "true" : "false");
2162 void ASTDumper::VisitCXXThisExpr(const CXXThisExpr *Node) {
2167 void ASTDumper::VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *Node) {
2169 OS << " functional cast to " << Node->getTypeAsWritten().getAsString()
2170 << " <" << Node->getCastKindName() << ">";
2173 void ASTDumper::VisitCXXConstructExpr(const CXXConstructExpr *Node) {
2175 CXXConstructorDecl *Ctor = Node->getConstructor();
2176 dumpType(Ctor->getType());
2177 if (Node->isElidable())
2179 if (Node->requiresZeroInitialization())
2183 void ASTDumper::VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *Node) {
2186 dumpCXXTemporary(Node->getTemporary());
2189 void ASTDumper::VisitCXXNewExpr(const CXXNewExpr *Node) {
2191 if (Node->isGlobalNew())
2193 if (Node->isArray())
2195 if (Node->getOperatorNew()) {
2197 dumpBareDeclRef(Node->getOperatorNew());
2199 // We could dump the deallocation function used in case of error, but it's
2200 // usually not that interesting.
2203 void ASTDumper::VisitCXXDeleteExpr(const CXXDeleteExpr *Node) {
2205 if (Node->isGlobalDelete())
2207 if (Node->isArrayForm())
2209 if (Node->getOperatorDelete()) {
2211 dumpBareDeclRef(Node->getOperatorDelete());
2216 ASTDumper::VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *Node) {
2218 if (const ValueDecl *VD = Node->getExtendingDecl()) {
2219 OS << " extended by ";
2220 dumpBareDeclRef(VD);
2224 void ASTDumper::VisitExprWithCleanups(const ExprWithCleanups *Node) {
2226 for (unsigned i = 0, e = Node->getNumObjects(); i != e; ++i)
2227 dumpDeclRef(Node->getObject(i), "cleanup");
2230 void ASTDumper::dumpCXXTemporary(const CXXTemporary *Temporary) {
2231 OS << "(CXXTemporary";
2232 dumpPointer(Temporary);
2236 void ASTDumper::VisitSizeOfPackExpr(const SizeOfPackExpr *Node) {
2238 dumpPointer(Node->getPack());
2239 dumpName(Node->getPack());
2240 if (Node->isPartiallySubstituted())
2241 for (const auto &A : Node->getPartialArguments())
2242 dumpTemplateArgument(A);
2245 void ASTDumper::VisitCXXDependentScopeMemberExpr(
2246 const CXXDependentScopeMemberExpr *Node) {
2248 OS << " " << (Node->isArrow() ? "->" : ".") << Node->getMember();
2251 //===----------------------------------------------------------------------===//
2252 // Obj-C Expressions
2253 //===----------------------------------------------------------------------===//
2255 void ASTDumper::VisitObjCMessageExpr(const ObjCMessageExpr *Node) {
2258 Node->getSelector().print(OS);
2259 switch (Node->getReceiverKind()) {
2260 case ObjCMessageExpr::Instance:
2263 case ObjCMessageExpr::Class:
2265 dumpBareType(Node->getClassReceiver());
2268 case ObjCMessageExpr::SuperInstance:
2269 OS << " super (instance)";
2272 case ObjCMessageExpr::SuperClass:
2273 OS << " super (class)";
2278 void ASTDumper::VisitObjCBoxedExpr(const ObjCBoxedExpr *Node) {
2280 if (auto *BoxingMethod = Node->getBoxingMethod()) {
2282 BoxingMethod->getSelector().print(OS);
2286 void ASTDumper::VisitObjCAtCatchStmt(const ObjCAtCatchStmt *Node) {
2288 if (const VarDecl *CatchParam = Node->getCatchParamDecl())
2289 dumpDecl(CatchParam);
2294 void ASTDumper::VisitObjCEncodeExpr(const ObjCEncodeExpr *Node) {
2296 dumpType(Node->getEncodedType());
2299 void ASTDumper::VisitObjCSelectorExpr(const ObjCSelectorExpr *Node) {
2303 Node->getSelector().print(OS);
2306 void ASTDumper::VisitObjCProtocolExpr(const ObjCProtocolExpr *Node) {
2309 OS << ' ' << *Node->getProtocol();
2312 void ASTDumper::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *Node) {
2314 if (Node->isImplicitProperty()) {
2315 OS << " Kind=MethodRef Getter=\"";
2316 if (Node->getImplicitPropertyGetter())
2317 Node->getImplicitPropertyGetter()->getSelector().print(OS);
2321 OS << "\" Setter=\"";
2322 if (ObjCMethodDecl *Setter = Node->getImplicitPropertySetter())
2323 Setter->getSelector().print(OS);
2328 OS << " Kind=PropertyRef Property=\"" << *Node->getExplicitProperty() <<'"';
2331 if (Node->isSuperReceiver())
2334 OS << " Messaging=";
2335 if (Node->isMessagingGetter() && Node->isMessagingSetter())
2336 OS << "Getter&Setter";
2337 else if (Node->isMessagingGetter())
2339 else if (Node->isMessagingSetter())
2343 void ASTDumper::VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *Node) {
2345 if (Node->isArraySubscriptRefExpr())
2346 OS << " Kind=ArraySubscript GetterForArray=\"";
2348 OS << " Kind=DictionarySubscript GetterForDictionary=\"";
2349 if (Node->getAtIndexMethodDecl())
2350 Node->getAtIndexMethodDecl()->getSelector().print(OS);
2354 if (Node->isArraySubscriptRefExpr())
2355 OS << "\" SetterForArray=\"";
2357 OS << "\" SetterForDictionary=\"";
2358 if (Node->setAtIndexMethodDecl())
2359 Node->setAtIndexMethodDecl()->getSelector().print(OS);
2364 void ASTDumper::VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *Node) {
2366 OS << " " << (Node->getValue() ? "__objc_yes" : "__objc_no");
2369 //===----------------------------------------------------------------------===//
2371 //===----------------------------------------------------------------------===//
2373 const char *ASTDumper::getCommandName(unsigned CommandID) {
2375 return Traits->getCommandInfo(CommandID)->Name;
2376 const CommandInfo *Info = CommandTraits::getBuiltinCommandInfo(CommandID);
2379 return "<not a builtin command>";
2382 void ASTDumper::dumpFullComment(const FullComment *C) {
2391 void ASTDumper::dumpComment(const Comment *C) {
2394 ColorScope Color(*this, NullColor);
2400 ColorScope Color(*this, CommentColor);
2401 OS << C->getCommentKindName();
2404 dumpSourceRange(C->getSourceRange());
2405 ConstCommentVisitor<ASTDumper>::visit(C);
2406 for (Comment::child_iterator I = C->child_begin(), E = C->child_end();
2412 void ASTDumper::visitTextComment(const TextComment *C) {
2413 OS << " Text=\"" << C->getText() << "\"";
2416 void ASTDumper::visitInlineCommandComment(const InlineCommandComment *C) {
2417 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\"";
2418 switch (C->getRenderKind()) {
2419 case InlineCommandComment::RenderNormal:
2420 OS << " RenderNormal";
2422 case InlineCommandComment::RenderBold:
2423 OS << " RenderBold";
2425 case InlineCommandComment::RenderMonospaced:
2426 OS << " RenderMonospaced";
2428 case InlineCommandComment::RenderEmphasized:
2429 OS << " RenderEmphasized";
2433 for (unsigned i = 0, e = C->getNumArgs(); i != e; ++i)
2434 OS << " Arg[" << i << "]=\"" << C->getArgText(i) << "\"";
2437 void ASTDumper::visitHTMLStartTagComment(const HTMLStartTagComment *C) {
2438 OS << " Name=\"" << C->getTagName() << "\"";
2439 if (C->getNumAttrs() != 0) {
2441 for (unsigned i = 0, e = C->getNumAttrs(); i != e; ++i) {
2442 const HTMLStartTagComment::Attribute &Attr = C->getAttr(i);
2443 OS << " \"" << Attr.Name << "=\"" << Attr.Value << "\"";
2446 if (C->isSelfClosing())
2447 OS << " SelfClosing";
2450 void ASTDumper::visitHTMLEndTagComment(const HTMLEndTagComment *C) {
2451 OS << " Name=\"" << C->getTagName() << "\"";
2454 void ASTDumper::visitBlockCommandComment(const BlockCommandComment *C) {
2455 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\"";
2456 for (unsigned i = 0, e = C->getNumArgs(); i != e; ++i)
2457 OS << " Arg[" << i << "]=\"" << C->getArgText(i) << "\"";
2460 void ASTDumper::visitParamCommandComment(const ParamCommandComment *C) {
2461 OS << " " << ParamCommandComment::getDirectionAsString(C->getDirection());
2463 if (C->isDirectionExplicit())
2464 OS << " explicitly";
2466 OS << " implicitly";
2468 if (C->hasParamName()) {
2469 if (C->isParamIndexValid())
2470 OS << " Param=\"" << C->getParamName(FC) << "\"";
2472 OS << " Param=\"" << C->getParamNameAsWritten() << "\"";
2475 if (C->isParamIndexValid() && !C->isVarArgParam())
2476 OS << " ParamIndex=" << C->getParamIndex();
2479 void ASTDumper::visitTParamCommandComment(const TParamCommandComment *C) {
2480 if (C->hasParamName()) {
2481 if (C->isPositionValid())
2482 OS << " Param=\"" << C->getParamName(FC) << "\"";
2484 OS << " Param=\"" << C->getParamNameAsWritten() << "\"";
2487 if (C->isPositionValid()) {
2488 OS << " Position=<";
2489 for (unsigned i = 0, e = C->getDepth(); i != e; ++i) {
2490 OS << C->getIndex(i);
2498 void ASTDumper::visitVerbatimBlockComment(const VerbatimBlockComment *C) {
2499 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\""
2500 " CloseName=\"" << C->getCloseName() << "\"";
2503 void ASTDumper::visitVerbatimBlockLineComment(
2504 const VerbatimBlockLineComment *C) {
2505 OS << " Text=\"" << C->getText() << "\"";
2508 void ASTDumper::visitVerbatimLineComment(const VerbatimLineComment *C) {
2509 OS << " Text=\"" << C->getText() << "\"";
2512 //===----------------------------------------------------------------------===//
2513 // Type method implementations
2514 //===----------------------------------------------------------------------===//
2516 void QualType::dump(const char *msg) const {
2518 llvm::errs() << msg << ": ";
2522 LLVM_DUMP_METHOD void QualType::dump() const { dump(llvm::errs()); }
2524 LLVM_DUMP_METHOD void QualType::dump(llvm::raw_ostream &OS) const {
2525 ASTDumper Dumper(OS, nullptr, nullptr);
2526 Dumper.dumpTypeAsChild(*this);
2529 LLVM_DUMP_METHOD void Type::dump() const { dump(llvm::errs()); }
2531 LLVM_DUMP_METHOD void Type::dump(llvm::raw_ostream &OS) const {
2532 QualType(this, 0).dump(OS);
2535 //===----------------------------------------------------------------------===//
2536 // Decl method implementations
2537 //===----------------------------------------------------------------------===//
2539 LLVM_DUMP_METHOD void Decl::dump() const { dump(llvm::errs()); }
2541 LLVM_DUMP_METHOD void Decl::dump(raw_ostream &OS, bool Deserialize) const {
2542 ASTDumper P(OS, &getASTContext().getCommentCommandTraits(),
2543 &getASTContext().getSourceManager());
2544 P.setDeserialize(Deserialize);
2548 LLVM_DUMP_METHOD void Decl::dumpColor() const {
2549 ASTDumper P(llvm::errs(), &getASTContext().getCommentCommandTraits(),
2550 &getASTContext().getSourceManager(), /*ShowColors*/true);
2554 LLVM_DUMP_METHOD void DeclContext::dumpLookups() const {
2555 dumpLookups(llvm::errs());
2558 LLVM_DUMP_METHOD void DeclContext::dumpLookups(raw_ostream &OS,
2560 bool Deserialize) const {
2561 const DeclContext *DC = this;
2562 while (!DC->isTranslationUnit())
2563 DC = DC->getParent();
2564 ASTContext &Ctx = cast<TranslationUnitDecl>(DC)->getASTContext();
2565 ASTDumper P(OS, &Ctx.getCommentCommandTraits(), &Ctx.getSourceManager());
2566 P.setDeserialize(Deserialize);
2567 P.dumpLookups(this, DumpDecls);
2570 //===----------------------------------------------------------------------===//
2571 // Stmt method implementations
2572 //===----------------------------------------------------------------------===//
2574 LLVM_DUMP_METHOD void Stmt::dump(SourceManager &SM) const {
2575 dump(llvm::errs(), SM);
2578 LLVM_DUMP_METHOD void Stmt::dump(raw_ostream &OS, SourceManager &SM) const {
2579 ASTDumper P(OS, nullptr, &SM);
2583 LLVM_DUMP_METHOD void Stmt::dump(raw_ostream &OS) const {
2584 ASTDumper P(OS, nullptr, nullptr);
2588 LLVM_DUMP_METHOD void Stmt::dump() const {
2589 ASTDumper P(llvm::errs(), nullptr, nullptr);
2593 LLVM_DUMP_METHOD void Stmt::dumpColor() const {
2594 ASTDumper P(llvm::errs(), nullptr, nullptr, /*ShowColors*/true);
2598 //===----------------------------------------------------------------------===//
2599 // Comment method implementations
2600 //===----------------------------------------------------------------------===//
2602 LLVM_DUMP_METHOD void Comment::dump() const {
2603 dump(llvm::errs(), nullptr, nullptr);
2606 LLVM_DUMP_METHOD void Comment::dump(const ASTContext &Context) const {
2607 dump(llvm::errs(), &Context.getCommentCommandTraits(),
2608 &Context.getSourceManager());
2611 void Comment::dump(raw_ostream &OS, const CommandTraits *Traits,
2612 const SourceManager *SM) const {
2613 const FullComment *FC = dyn_cast<FullComment>(this);
2614 ASTDumper D(OS, Traits, SM);
2615 D.dumpFullComment(FC);
2618 LLVM_DUMP_METHOD void Comment::dumpColor() const {
2619 const FullComment *FC = dyn_cast<FullComment>(this);
2620 ASTDumper D(llvm::errs(), nullptr, nullptr, /*ShowColors*/true);
2621 D.dumpFullComment(FC);