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/DeclObjC.h"
20 #include "clang/AST/DeclVisitor.h"
21 #include "clang/AST/StmtVisitor.h"
22 #include "clang/Basic/Module.h"
23 #include "clang/Basic/SourceManager.h"
24 #include "llvm/Support/raw_ostream.h"
25 using namespace clang;
26 using namespace clang::comments;
28 //===----------------------------------------------------------------------===//
30 //===----------------------------------------------------------------------===//
33 // Colors used for various parts of the AST dump
35 struct TerminalColor {
36 raw_ostream::Colors Color;
40 // Decl kind names (VarDecl, FunctionDecl, etc)
41 static const TerminalColor DeclKindNameColor = { raw_ostream::GREEN, true };
42 // Attr names (CleanupAttr, GuardedByAttr, etc)
43 static const TerminalColor AttrColor = { raw_ostream::BLUE, true };
44 // Statement names (DeclStmt, ImplicitCastExpr, etc)
45 static const TerminalColor StmtColor = { raw_ostream::MAGENTA, true };
46 // Comment names (FullComment, ParagraphComment, TextComment, etc)
47 static const TerminalColor CommentColor = { raw_ostream::YELLOW, true };
49 // Type names (int, float, etc, plus user defined types)
50 static const TerminalColor TypeColor = { raw_ostream::GREEN, false };
53 static const TerminalColor AddressColor = { raw_ostream::YELLOW, false };
55 static const TerminalColor LocationColor = { raw_ostream::YELLOW, false };
58 static const TerminalColor ValueKindColor = { raw_ostream::CYAN, false };
59 // bitfield/objcproperty/objcsubscript/vectorcomponent
60 static const TerminalColor ObjectKindColor = { raw_ostream::CYAN, false };
63 static const TerminalColor NullColor = { raw_ostream::BLUE, false };
65 // CastKind from CastExpr's
66 static const TerminalColor CastColor = { raw_ostream::RED, false };
68 // Value of the statement
69 static const TerminalColor ValueColor = { raw_ostream::CYAN, true };
71 static const TerminalColor DeclNameColor = { raw_ostream::CYAN, true };
73 // Indents ( `, -. | )
74 static const TerminalColor IndentColor = { raw_ostream::BLUE, false };
77 : public ConstDeclVisitor<ASTDumper>, public ConstStmtVisitor<ASTDumper>,
78 public ConstCommentVisitor<ASTDumper> {
80 const CommandTraits *Traits;
81 const SourceManager *SM;
84 // Indicates whether more child are expected at the current tree depth
85 enum IndentType { IT_Child, IT_LastChild };
87 /// Indents[i] indicates if another child exists at level i.
88 /// Used by Indent() to print the tree structure.
89 llvm::SmallVector<IndentType, 32> Indents;
91 /// Indicates that more children will be needed at this indent level.
92 /// If true, prevents lastChild() from marking the node as the last child.
93 /// This is used when there are multiple collections of children to be
94 /// dumped as well as during conditional node dumping.
97 /// Keep track of the last location we print out so that we can
98 /// print out deltas from then on out.
99 const char *LastLocFilename;
100 unsigned LastLocLine;
102 /// The \c FullComment parent of the comment being dumped.
103 const FullComment *FC;
109 // Preserve the Dumper's MoreChildren value from the previous IndentScope
112 IndentScope(ASTDumper &Dumper) : Dumper(Dumper) {
113 MoreChildren = Dumper.hasMoreChildren();
114 Dumper.setMoreChildren(false);
118 Dumper.setMoreChildren(MoreChildren);
126 ColorScope(ASTDumper &Dumper, TerminalColor Color)
128 if (Dumper.ShowColors)
129 Dumper.OS.changeColor(Color.Color, Color.Bold);
132 if (Dumper.ShowColors)
133 Dumper.OS.resetColor();
138 ASTDumper(raw_ostream &OS, const CommandTraits *Traits,
139 const SourceManager *SM)
140 : OS(OS), Traits(Traits), SM(SM), IsFirstLine(true), MoreChildren(false),
141 LastLocFilename(""), LastLocLine(~0U), FC(0),
142 ShowColors(SM && SM->getDiagnostics().getShowColors()) { }
144 ASTDumper(raw_ostream &OS, const CommandTraits *Traits,
145 const SourceManager *SM, bool ShowColors)
146 : OS(OS), Traits(Traits), SM(SM), IsFirstLine(true), MoreChildren(false),
147 LastLocFilename(""), LastLocLine(~0U),
148 ShowColors(ShowColors) { }
154 void dumpDecl(const Decl *D);
155 void dumpStmt(const Stmt *S);
156 void dumpFullComment(const FullComment *C);
162 bool hasMoreChildren();
163 void setMoreChildren(bool Value);
166 void dumpPointer(const void *Ptr);
167 void dumpSourceRange(SourceRange R);
168 void dumpLocation(SourceLocation Loc);
169 void dumpBareType(QualType T);
170 void dumpType(QualType T);
171 void dumpBareDeclRef(const Decl *Node);
172 void dumpDeclRef(const Decl *Node, const char *Label = 0);
173 void dumpName(const NamedDecl *D);
174 bool hasNodes(const DeclContext *DC);
175 void dumpDeclContext(const DeclContext *DC);
176 void dumpAttr(const Attr *A);
179 void dumpAccessSpecifier(AccessSpecifier AS);
180 void dumpCXXCtorInitializer(const CXXCtorInitializer *Init);
181 void dumpTemplateParameters(const TemplateParameterList *TPL);
182 void dumpTemplateArgumentListInfo(const TemplateArgumentListInfo &TALI);
183 void dumpTemplateArgumentLoc(const TemplateArgumentLoc &A);
184 void dumpTemplateArgumentList(const TemplateArgumentList &TAL);
185 void dumpTemplateArgument(const TemplateArgument &A,
186 SourceRange R = SourceRange());
189 void VisitLabelDecl(const LabelDecl *D);
190 void VisitTypedefDecl(const TypedefDecl *D);
191 void VisitEnumDecl(const EnumDecl *D);
192 void VisitRecordDecl(const RecordDecl *D);
193 void VisitEnumConstantDecl(const EnumConstantDecl *D);
194 void VisitIndirectFieldDecl(const IndirectFieldDecl *D);
195 void VisitFunctionDecl(const FunctionDecl *D);
196 void VisitFieldDecl(const FieldDecl *D);
197 void VisitVarDecl(const VarDecl *D);
198 void VisitFileScopeAsmDecl(const FileScopeAsmDecl *D);
199 void VisitImportDecl(const ImportDecl *D);
202 void VisitNamespaceDecl(const NamespaceDecl *D);
203 void VisitUsingDirectiveDecl(const UsingDirectiveDecl *D);
204 void VisitNamespaceAliasDecl(const NamespaceAliasDecl *D);
205 void VisitTypeAliasDecl(const TypeAliasDecl *D);
206 void VisitTypeAliasTemplateDecl(const TypeAliasTemplateDecl *D);
207 void VisitCXXRecordDecl(const CXXRecordDecl *D);
208 void VisitStaticAssertDecl(const StaticAssertDecl *D);
209 void VisitFunctionTemplateDecl(const FunctionTemplateDecl *D);
210 void VisitClassTemplateDecl(const ClassTemplateDecl *D);
211 void VisitClassTemplateSpecializationDecl(
212 const ClassTemplateSpecializationDecl *D);
213 void VisitClassTemplatePartialSpecializationDecl(
214 const ClassTemplatePartialSpecializationDecl *D);
215 void VisitClassScopeFunctionSpecializationDecl(
216 const ClassScopeFunctionSpecializationDecl *D);
217 void VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D);
218 void VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D);
219 void VisitTemplateTemplateParmDecl(const TemplateTemplateParmDecl *D);
220 void VisitUsingDecl(const UsingDecl *D);
221 void VisitUnresolvedUsingTypenameDecl(const UnresolvedUsingTypenameDecl *D);
222 void VisitUnresolvedUsingValueDecl(const UnresolvedUsingValueDecl *D);
223 void VisitUsingShadowDecl(const UsingShadowDecl *D);
224 void VisitLinkageSpecDecl(const LinkageSpecDecl *D);
225 void VisitAccessSpecDecl(const AccessSpecDecl *D);
226 void VisitFriendDecl(const FriendDecl *D);
229 void VisitObjCIvarDecl(const ObjCIvarDecl *D);
230 void VisitObjCMethodDecl(const ObjCMethodDecl *D);
231 void VisitObjCCategoryDecl(const ObjCCategoryDecl *D);
232 void VisitObjCCategoryImplDecl(const ObjCCategoryImplDecl *D);
233 void VisitObjCProtocolDecl(const ObjCProtocolDecl *D);
234 void VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D);
235 void VisitObjCImplementationDecl(const ObjCImplementationDecl *D);
236 void VisitObjCCompatibleAliasDecl(const ObjCCompatibleAliasDecl *D);
237 void VisitObjCPropertyDecl(const ObjCPropertyDecl *D);
238 void VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D);
239 void VisitBlockDecl(const BlockDecl *D);
242 void VisitStmt(const Stmt *Node);
243 void VisitDeclStmt(const DeclStmt *Node);
244 void VisitAttributedStmt(const AttributedStmt *Node);
245 void VisitLabelStmt(const LabelStmt *Node);
246 void VisitGotoStmt(const GotoStmt *Node);
249 void VisitExpr(const Expr *Node);
250 void VisitCastExpr(const CastExpr *Node);
251 void VisitDeclRefExpr(const DeclRefExpr *Node);
252 void VisitPredefinedExpr(const PredefinedExpr *Node);
253 void VisitCharacterLiteral(const CharacterLiteral *Node);
254 void VisitIntegerLiteral(const IntegerLiteral *Node);
255 void VisitFloatingLiteral(const FloatingLiteral *Node);
256 void VisitStringLiteral(const StringLiteral *Str);
257 void VisitUnaryOperator(const UnaryOperator *Node);
258 void VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *Node);
259 void VisitMemberExpr(const MemberExpr *Node);
260 void VisitExtVectorElementExpr(const ExtVectorElementExpr *Node);
261 void VisitBinaryOperator(const BinaryOperator *Node);
262 void VisitCompoundAssignOperator(const CompoundAssignOperator *Node);
263 void VisitAddrLabelExpr(const AddrLabelExpr *Node);
264 void VisitBlockExpr(const BlockExpr *Node);
265 void VisitOpaqueValueExpr(const OpaqueValueExpr *Node);
268 void VisitCXXNamedCastExpr(const CXXNamedCastExpr *Node);
269 void VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *Node);
270 void VisitCXXThisExpr(const CXXThisExpr *Node);
271 void VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *Node);
272 void VisitCXXConstructExpr(const CXXConstructExpr *Node);
273 void VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *Node);
274 void VisitExprWithCleanups(const ExprWithCleanups *Node);
275 void VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *Node);
276 void dumpCXXTemporary(const CXXTemporary *Temporary);
279 void VisitObjCAtCatchStmt(const ObjCAtCatchStmt *Node);
280 void VisitObjCEncodeExpr(const ObjCEncodeExpr *Node);
281 void VisitObjCMessageExpr(const ObjCMessageExpr *Node);
282 void VisitObjCBoxedExpr(const ObjCBoxedExpr *Node);
283 void VisitObjCSelectorExpr(const ObjCSelectorExpr *Node);
284 void VisitObjCProtocolExpr(const ObjCProtocolExpr *Node);
285 void VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *Node);
286 void VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *Node);
287 void VisitObjCIvarRefExpr(const ObjCIvarRefExpr *Node);
288 void VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *Node);
291 const char *getCommandName(unsigned CommandID);
292 void dumpComment(const Comment *C);
295 void visitTextComment(const TextComment *C);
296 void visitInlineCommandComment(const InlineCommandComment *C);
297 void visitHTMLStartTagComment(const HTMLStartTagComment *C);
298 void visitHTMLEndTagComment(const HTMLEndTagComment *C);
301 void visitBlockCommandComment(const BlockCommandComment *C);
302 void visitParamCommandComment(const ParamCommandComment *C);
303 void visitTParamCommandComment(const TParamCommandComment *C);
304 void visitVerbatimBlockComment(const VerbatimBlockComment *C);
305 void visitVerbatimBlockLineComment(const VerbatimBlockLineComment *C);
306 void visitVerbatimLineComment(const VerbatimLineComment *C);
310 //===----------------------------------------------------------------------===//
312 //===----------------------------------------------------------------------===//
314 // Print out the appropriate tree structure using the Indents vector.
315 // Example of tree and the Indents vector at each level.
318 // | `-C { IT_Child, IT_LastChild }
319 // `-D { IT_LastChild }
320 // |-E { IT_LastChild, IT_Child }
321 // `-F { IT_LastChild, IT_LastChild }
322 // Type non-last element, last element
323 // IT_Child "| " "|-"
324 // IT_LastChild " " "`-"
325 void ASTDumper::indent() {
331 ColorScope Color(*this, IndentColor);
332 for (llvm::SmallVector<IndentType, 32>::const_iterator I = Indents.begin(),
349 llvm_unreachable("Invalid IndentType");
351 Indents.push_back(IT_Child);
354 void ASTDumper::unindent() {
358 // Call before each potential last child node is to be dumped. If MoreChildren
359 // is false, then this is the last child, otherwise treat as a regular node.
360 void ASTDumper::lastChild() {
361 if (!hasMoreChildren())
362 Indents.back() = IT_LastChild;
365 // MoreChildren should be set before calling another function that may print
366 // additional nodes to prevent conflicting final child nodes.
367 bool ASTDumper::hasMoreChildren() {
371 void ASTDumper::setMoreChildren(bool Value) {
372 MoreChildren = Value;
375 void ASTDumper::dumpPointer(const void *Ptr) {
376 ColorScope Color(*this, AddressColor);
380 void ASTDumper::dumpLocation(SourceLocation Loc) {
381 ColorScope Color(*this, LocationColor);
382 SourceLocation SpellingLoc = SM->getSpellingLoc(Loc);
384 // The general format we print out is filename:line:col, but we drop pieces
385 // that haven't changed since the last loc printed.
386 PresumedLoc PLoc = SM->getPresumedLoc(SpellingLoc);
388 if (PLoc.isInvalid()) {
389 OS << "<invalid sloc>";
393 if (strcmp(PLoc.getFilename(), LastLocFilename) != 0) {
394 OS << PLoc.getFilename() << ':' << PLoc.getLine()
395 << ':' << PLoc.getColumn();
396 LastLocFilename = PLoc.getFilename();
397 LastLocLine = PLoc.getLine();
398 } else if (PLoc.getLine() != LastLocLine) {
399 OS << "line" << ':' << PLoc.getLine()
400 << ':' << PLoc.getColumn();
401 LastLocLine = PLoc.getLine();
403 OS << "col" << ':' << PLoc.getColumn();
407 void ASTDumper::dumpSourceRange(SourceRange R) {
408 // Can't translate locations if a SourceManager isn't available.
413 dumpLocation(R.getBegin());
414 if (R.getBegin() != R.getEnd()) {
416 dumpLocation(R.getEnd());
420 // <t2.c:123:421[blah], t2.c:412:321>
424 void ASTDumper::dumpBareType(QualType T) {
425 ColorScope Color(*this, TypeColor);
427 SplitQualType T_split = T.split();
428 OS << "'" << QualType::getAsString(T_split) << "'";
431 // If the type is sugared, also dump a (shallow) desugared type.
432 SplitQualType D_split = T.getSplitDesugaredType();
433 if (T_split != D_split)
434 OS << ":'" << QualType::getAsString(D_split) << "'";
438 void ASTDumper::dumpType(QualType T) {
443 void ASTDumper::dumpBareDeclRef(const Decl *D) {
445 ColorScope Color(*this, DeclKindNameColor);
446 OS << D->getDeclKindName();
450 if (const NamedDecl *ND = dyn_cast<NamedDecl>(D)) {
451 ColorScope Color(*this, DeclNameColor);
453 ND->getDeclName().printName(OS);
457 if (const ValueDecl *VD = dyn_cast<ValueDecl>(D))
458 dumpType(VD->getType());
461 void ASTDumper::dumpDeclRef(const Decl *D, const char *Label) {
465 IndentScope Indent(*this);
471 void ASTDumper::dumpName(const NamedDecl *ND) {
472 if (ND->getDeclName()) {
473 ColorScope Color(*this, DeclNameColor);
474 OS << ' ' << ND->getNameAsString();
478 bool ASTDumper::hasNodes(const DeclContext *DC) {
482 return DC->decls_begin() != DC->decls_end();
485 void ASTDumper::dumpDeclContext(const DeclContext *DC) {
488 for (DeclContext::decl_iterator I = DC->decls_begin(), E = DC->decls_end();
490 DeclContext::decl_iterator Next = I;
498 void ASTDumper::dumpAttr(const Attr *A) {
499 IndentScope Indent(*this);
501 ColorScope Color(*this, AttrColor);
502 switch (A->getKind()) {
503 #define ATTR(X) case attr::X: OS << #X; break;
504 #include "clang/Basic/AttrList.inc"
505 default: llvm_unreachable("unexpected attribute kind");
510 dumpSourceRange(A->getRange());
511 #include "clang/AST/AttrDump.inc"
514 static Decl *getPreviousDeclImpl(...) {
519 static const Decl *getPreviousDeclImpl(const Redeclarable<T> *D) {
520 return D->getPreviousDecl();
523 /// Get the previous declaration in the redeclaration chain for a declaration.
524 static const Decl *getPreviousDecl(const Decl *D) {
525 switch (D->getKind()) {
526 #define DECL(DERIVED, BASE) \
527 case Decl::DERIVED: \
528 return getPreviousDeclImpl(cast<DERIVED##Decl>(D));
529 #define ABSTRACT_DECL(DECL)
530 #include "clang/AST/DeclNodes.inc"
532 llvm_unreachable("Decl that isn't part of DeclNodes.inc!");
535 //===----------------------------------------------------------------------===//
537 //===----------------------------------------------------------------------===//
539 void ASTDumper::dumpAccessSpecifier(AccessSpecifier AS) {
555 void ASTDumper::dumpCXXCtorInitializer(const CXXCtorInitializer *Init) {
556 IndentScope Indent(*this);
557 OS << "CXXCtorInitializer";
558 if (Init->isAnyMemberInitializer()) {
560 dumpBareDeclRef(Init->getAnyMember());
562 dumpType(QualType(Init->getBaseClass(), 0));
564 dumpStmt(Init->getInit());
567 void ASTDumper::dumpTemplateParameters(const TemplateParameterList *TPL) {
571 for (TemplateParameterList::const_iterator I = TPL->begin(), E = TPL->end();
576 void ASTDumper::dumpTemplateArgumentListInfo(
577 const TemplateArgumentListInfo &TALI) {
578 for (unsigned i = 0, e = TALI.size(); i < e; ++i) {
581 dumpTemplateArgumentLoc(TALI[i]);
585 void ASTDumper::dumpTemplateArgumentLoc(const TemplateArgumentLoc &A) {
586 dumpTemplateArgument(A.getArgument(), A.getSourceRange());
589 void ASTDumper::dumpTemplateArgumentList(const TemplateArgumentList &TAL) {
590 for (unsigned i = 0, e = TAL.size(); i < e; ++i)
591 dumpTemplateArgument(TAL[i]);
594 void ASTDumper::dumpTemplateArgument(const TemplateArgument &A, SourceRange R) {
595 IndentScope Indent(*this);
596 OS << "TemplateArgument";
600 switch (A.getKind()) {
601 case TemplateArgument::Null:
604 case TemplateArgument::Type:
607 dumpType(A.getAsType());
609 case TemplateArgument::Declaration:
612 dumpDeclRef(A.getAsDecl());
614 case TemplateArgument::NullPtr:
617 case TemplateArgument::Integral:
618 OS << " integral " << A.getAsIntegral();
620 case TemplateArgument::Template:
622 A.getAsTemplate().dump(OS);
624 case TemplateArgument::TemplateExpansion:
625 OS << " template expansion";
626 A.getAsTemplateOrTemplatePattern().dump(OS);
628 case TemplateArgument::Expression:
631 dumpStmt(A.getAsExpr());
633 case TemplateArgument::Pack:
635 for (TemplateArgument::pack_iterator I = A.pack_begin(), E = A.pack_end();
639 dumpTemplateArgument(*I);
645 //===----------------------------------------------------------------------===//
646 // Decl dumping methods.
647 //===----------------------------------------------------------------------===//
649 void ASTDumper::dumpDecl(const Decl *D) {
650 IndentScope Indent(*this);
653 ColorScope Color(*this, NullColor);
659 ColorScope Color(*this, DeclKindNameColor);
660 OS << D->getDeclKindName() << "Decl";
663 if (D->getLexicalDeclContext() != D->getDeclContext())
664 OS << " parent " << cast<Decl>(D->getDeclContext());
665 if (const Decl *Prev = getPreviousDecl(D))
666 OS << " prev " << Prev;
667 dumpSourceRange(D->getSourceRange());
669 bool HasAttrs = D->attr_begin() != D->attr_end();
670 bool HasComment = D->getASTContext().getCommentForDecl(D, 0);
671 // Decls within functions are visited by the body
672 bool HasDeclContext = !isa<FunctionDecl>(*D) && !isa<ObjCMethodDecl>(*D) &&
673 hasNodes(dyn_cast<DeclContext>(D));
675 setMoreChildren(HasAttrs || HasComment || HasDeclContext);
676 ConstDeclVisitor<ASTDumper>::Visit(D);
678 setMoreChildren(HasComment || HasDeclContext);
679 for (Decl::attr_iterator I = D->attr_begin(), E = D->attr_end();
686 setMoreChildren(HasDeclContext);
688 dumpFullComment(D->getASTContext().getCommentForDecl(D, 0));
690 setMoreChildren(false);
692 dumpDeclContext(cast<DeclContext>(D));
695 void ASTDumper::VisitLabelDecl(const LabelDecl *D) {
699 void ASTDumper::VisitTypedefDecl(const TypedefDecl *D) {
701 dumpType(D->getUnderlyingType());
702 if (D->isModulePrivate())
703 OS << " __module_private__";
706 void ASTDumper::VisitEnumDecl(const EnumDecl *D) {
708 if (D->isScopedUsingClassTag())
714 if (D->isModulePrivate())
715 OS << " __module_private__";
717 dumpType(D->getIntegerType());
720 void ASTDumper::VisitRecordDecl(const RecordDecl *D) {
721 OS << ' ' << D->getKindName();
723 if (D->isModulePrivate())
724 OS << " __module_private__";
727 void ASTDumper::VisitEnumConstantDecl(const EnumConstantDecl *D) {
729 dumpType(D->getType());
730 if (const Expr *Init = D->getInitExpr()) {
736 void ASTDumper::VisitIndirectFieldDecl(const IndirectFieldDecl *D) {
738 dumpType(D->getType());
739 for (IndirectFieldDecl::chain_iterator I = D->chain_begin(),
748 void ASTDumper::VisitFunctionDecl(const FunctionDecl *D) {
750 dumpType(D->getType());
752 StorageClass SC = D->getStorageClass();
754 OS << ' ' << VarDecl::getStorageClassSpecifierString(SC);
755 if (D->isInlineSpecified())
757 if (D->isVirtualAsWritten())
759 if (D->isModulePrivate())
760 OS << " __module_private__";
764 else if (D->isDeletedAsWritten())
767 bool OldMoreChildren = hasMoreChildren();
768 const FunctionTemplateSpecializationInfo *FTSI =
769 D->getTemplateSpecializationInfo();
770 bool HasTemplateSpecialization = FTSI;
772 bool HasNamedDecls = D->getDeclsInPrototypeScope().begin() !=
773 D->getDeclsInPrototypeScope().end();
775 bool HasFunctionDecls = D->param_begin() != D->param_end();
777 const CXXConstructorDecl *C = dyn_cast<CXXConstructorDecl>(D);
778 bool HasCtorInitializers = C && C->init_begin() != C->init_end();
780 bool HasDeclarationBody = D->doesThisDeclarationHaveABody();
782 setMoreChildren(OldMoreChildren || HasNamedDecls || HasFunctionDecls ||
783 HasCtorInitializers || HasDeclarationBody);
784 if (HasTemplateSpecialization) {
786 dumpTemplateArgumentList(*FTSI->TemplateArguments);
789 setMoreChildren(OldMoreChildren || HasFunctionDecls ||
790 HasCtorInitializers || HasDeclarationBody);
791 for (ArrayRef<NamedDecl *>::iterator
792 I = D->getDeclsInPrototypeScope().begin(),
793 E = D->getDeclsInPrototypeScope().end(); I != E; ++I) {
799 setMoreChildren(OldMoreChildren || HasCtorInitializers || HasDeclarationBody);
800 for (FunctionDecl::param_const_iterator I = D->param_begin(),
808 setMoreChildren(OldMoreChildren || HasDeclarationBody);
809 if (HasCtorInitializers)
810 for (CXXConstructorDecl::init_const_iterator I = C->init_begin(),
815 dumpCXXCtorInitializer(*I);
818 setMoreChildren(OldMoreChildren);
819 if (HasDeclarationBody) {
821 dumpStmt(D->getBody());
825 void ASTDumper::VisitFieldDecl(const FieldDecl *D) {
827 dumpType(D->getType());
830 if (D->isModulePrivate())
831 OS << " __module_private__";
833 bool OldMoreChildren = hasMoreChildren();
834 bool IsBitField = D->isBitField();
835 Expr *Init = D->getInClassInitializer();
838 setMoreChildren(OldMoreChildren || HasInit);
841 dumpStmt(D->getBitWidth());
843 setMoreChildren(OldMoreChildren);
850 void ASTDumper::VisitVarDecl(const VarDecl *D) {
852 dumpType(D->getType());
853 StorageClass SC = D->getStorageClass();
855 OS << ' ' << VarDecl::getStorageClassSpecifierString(SC);
856 switch (D->getTLSKind()) {
857 case VarDecl::TLS_None: break;
858 case VarDecl::TLS_Static: OS << " tls"; break;
859 case VarDecl::TLS_Dynamic: OS << " tls_dynamic"; break;
861 if (D->isModulePrivate())
862 OS << " __module_private__";
863 if (D->isNRVOVariable())
867 dumpStmt(D->getInit());
871 void ASTDumper::VisitFileScopeAsmDecl(const FileScopeAsmDecl *D) {
873 dumpStmt(D->getAsmString());
876 void ASTDumper::VisitImportDecl(const ImportDecl *D) {
877 OS << ' ' << D->getImportedModule()->getFullModuleName();
880 //===----------------------------------------------------------------------===//
882 //===----------------------------------------------------------------------===//
884 void ASTDumper::VisitNamespaceDecl(const NamespaceDecl *D) {
888 if (!D->isOriginalNamespace())
889 dumpDeclRef(D->getOriginalNamespace(), "original");
892 void ASTDumper::VisitUsingDirectiveDecl(const UsingDirectiveDecl *D) {
894 dumpBareDeclRef(D->getNominatedNamespace());
897 void ASTDumper::VisitNamespaceAliasDecl(const NamespaceAliasDecl *D) {
899 dumpDeclRef(D->getAliasedNamespace());
902 void ASTDumper::VisitTypeAliasDecl(const TypeAliasDecl *D) {
904 dumpType(D->getUnderlyingType());
907 void ASTDumper::VisitTypeAliasTemplateDecl(const TypeAliasTemplateDecl *D) {
909 dumpTemplateParameters(D->getTemplateParameters());
910 dumpDecl(D->getTemplatedDecl());
913 void ASTDumper::VisitCXXRecordDecl(const CXXRecordDecl *D) {
915 if (!D->isCompleteDefinition())
918 for (CXXRecordDecl::base_class_const_iterator I = D->bases_begin(),
921 IndentScope Indent(*this);
924 dumpAccessSpecifier(I->getAccessSpecifier());
925 dumpType(I->getType());
926 if (I->isPackExpansion())
931 void ASTDumper::VisitStaticAssertDecl(const StaticAssertDecl *D) {
932 dumpStmt(D->getAssertExpr());
934 dumpStmt(D->getMessage());
937 void ASTDumper::VisitFunctionTemplateDecl(const FunctionTemplateDecl *D) {
939 dumpTemplateParameters(D->getTemplateParameters());
940 dumpDecl(D->getTemplatedDecl());
941 for (FunctionTemplateDecl::spec_iterator I = D->spec_begin(),
944 FunctionTemplateDecl::spec_iterator Next = I;
948 switch (I->getTemplateSpecializationKind()) {
950 case TSK_ImplicitInstantiation:
951 case TSK_ExplicitInstantiationDeclaration:
952 case TSK_ExplicitInstantiationDefinition:
953 if (D == D->getCanonicalDecl())
958 case TSK_ExplicitSpecialization:
965 void ASTDumper::VisitClassTemplateDecl(const ClassTemplateDecl *D) {
967 dumpTemplateParameters(D->getTemplateParameters());
969 ClassTemplateDecl::spec_iterator I = D->spec_begin();
970 ClassTemplateDecl::spec_iterator E = D->spec_end();
973 dumpDecl(D->getTemplatedDecl());
974 for (; I != E; ++I) {
975 ClassTemplateDecl::spec_iterator Next = I;
979 switch (I->getTemplateSpecializationKind()) {
981 case TSK_ImplicitInstantiation:
982 if (D == D->getCanonicalDecl())
987 case TSK_ExplicitSpecialization:
988 case TSK_ExplicitInstantiationDeclaration:
989 case TSK_ExplicitInstantiationDefinition:
996 void ASTDumper::VisitClassTemplateSpecializationDecl(
997 const ClassTemplateSpecializationDecl *D) {
998 VisitCXXRecordDecl(D);
999 dumpTemplateArgumentList(D->getTemplateArgs());
1002 void ASTDumper::VisitClassTemplatePartialSpecializationDecl(
1003 const ClassTemplatePartialSpecializationDecl *D) {
1004 VisitClassTemplateSpecializationDecl(D);
1005 dumpTemplateParameters(D->getTemplateParameters());
1008 void ASTDumper::VisitClassScopeFunctionSpecializationDecl(
1009 const ClassScopeFunctionSpecializationDecl *D) {
1010 dumpDeclRef(D->getSpecialization());
1011 if (D->hasExplicitTemplateArgs())
1012 dumpTemplateArgumentListInfo(D->templateArgs());
1015 void ASTDumper::VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D) {
1016 if (D->wasDeclaredWithTypename())
1020 if (D->isParameterPack())
1023 if (D->hasDefaultArgument())
1024 dumpType(D->getDefaultArgument());
1027 void ASTDumper::VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D) {
1028 dumpType(D->getType());
1029 if (D->isParameterPack())
1032 if (D->hasDefaultArgument())
1033 dumpStmt(D->getDefaultArgument());
1036 void ASTDumper::VisitTemplateTemplateParmDecl(
1037 const TemplateTemplateParmDecl *D) {
1038 if (D->isParameterPack())
1041 dumpTemplateParameters(D->getTemplateParameters());
1042 if (D->hasDefaultArgument())
1043 dumpTemplateArgumentLoc(D->getDefaultArgument());
1046 void ASTDumper::VisitUsingDecl(const UsingDecl *D) {
1048 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
1049 OS << D->getNameAsString();
1052 void ASTDumper::VisitUnresolvedUsingTypenameDecl(
1053 const UnresolvedUsingTypenameDecl *D) {
1055 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
1056 OS << D->getNameAsString();
1059 void ASTDumper::VisitUnresolvedUsingValueDecl(const UnresolvedUsingValueDecl *D) {
1061 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
1062 OS << D->getNameAsString();
1063 dumpType(D->getType());
1066 void ASTDumper::VisitUsingShadowDecl(const UsingShadowDecl *D) {
1068 dumpBareDeclRef(D->getTargetDecl());
1071 void ASTDumper::VisitLinkageSpecDecl(const LinkageSpecDecl *D) {
1072 switch (D->getLanguage()) {
1073 case LinkageSpecDecl::lang_c: OS << " C"; break;
1074 case LinkageSpecDecl::lang_cxx: OS << " C++"; break;
1078 void ASTDumper::VisitAccessSpecDecl(const AccessSpecDecl *D) {
1080 dumpAccessSpecifier(D->getAccess());
1083 void ASTDumper::VisitFriendDecl(const FriendDecl *D) {
1085 if (TypeSourceInfo *T = D->getFriendType())
1086 dumpType(T->getType());
1088 dumpDecl(D->getFriendDecl());
1091 //===----------------------------------------------------------------------===//
1092 // Obj-C Declarations
1093 //===----------------------------------------------------------------------===//
1095 void ASTDumper::VisitObjCIvarDecl(const ObjCIvarDecl *D) {
1097 dumpType(D->getType());
1098 if (D->getSynthesize())
1099 OS << " synthesize";
1101 switch (D->getAccessControl()) {
1102 case ObjCIvarDecl::None:
1105 case ObjCIvarDecl::Private:
1108 case ObjCIvarDecl::Protected:
1111 case ObjCIvarDecl::Public:
1114 case ObjCIvarDecl::Package:
1120 void ASTDumper::VisitObjCMethodDecl(const ObjCMethodDecl *D) {
1121 if (D->isInstanceMethod())
1126 dumpType(D->getResultType());
1128 bool OldMoreChildren = hasMoreChildren();
1129 bool IsVariadic = D->isVariadic();
1130 bool HasBody = D->hasBody();
1132 setMoreChildren(OldMoreChildren || IsVariadic || HasBody);
1133 if (D->isThisDeclarationADefinition()) {
1137 for (ObjCMethodDecl::param_const_iterator I = D->param_begin(),
1146 setMoreChildren(OldMoreChildren || HasBody);
1149 IndentScope Indent(*this);
1153 setMoreChildren(OldMoreChildren);
1156 dumpStmt(D->getBody());
1160 void ASTDumper::VisitObjCCategoryDecl(const ObjCCategoryDecl *D) {
1162 dumpDeclRef(D->getClassInterface());
1163 if (D->protocol_begin() == D->protocol_end())
1165 dumpDeclRef(D->getImplementation());
1166 for (ObjCCategoryDecl::protocol_iterator I = D->protocol_begin(),
1167 E = D->protocol_end();
1175 void ASTDumper::VisitObjCCategoryImplDecl(const ObjCCategoryImplDecl *D) {
1177 dumpDeclRef(D->getClassInterface());
1179 dumpDeclRef(D->getCategoryDecl());
1182 void ASTDumper::VisitObjCProtocolDecl(const ObjCProtocolDecl *D) {
1184 for (ObjCProtocolDecl::protocol_iterator I = D->protocol_begin(),
1185 E = D->protocol_end();
1193 void ASTDumper::VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D) {
1195 dumpDeclRef(D->getSuperClass(), "super");
1196 if (D->protocol_begin() == D->protocol_end())
1198 dumpDeclRef(D->getImplementation());
1199 for (ObjCInterfaceDecl::protocol_iterator I = D->protocol_begin(),
1200 E = D->protocol_end();
1208 void ASTDumper::VisitObjCImplementationDecl(const ObjCImplementationDecl *D) {
1210 dumpDeclRef(D->getSuperClass(), "super");
1211 if (D->init_begin() == D->init_end())
1213 dumpDeclRef(D->getClassInterface());
1214 for (ObjCImplementationDecl::init_const_iterator I = D->init_begin(),
1219 dumpCXXCtorInitializer(*I);
1223 void ASTDumper::VisitObjCCompatibleAliasDecl(const ObjCCompatibleAliasDecl *D) {
1226 dumpDeclRef(D->getClassInterface());
1229 void ASTDumper::VisitObjCPropertyDecl(const ObjCPropertyDecl *D) {
1231 dumpType(D->getType());
1233 if (D->getPropertyImplementation() == ObjCPropertyDecl::Required)
1235 else if (D->getPropertyImplementation() == ObjCPropertyDecl::Optional)
1238 ObjCPropertyDecl::PropertyAttributeKind Attrs = D->getPropertyAttributes();
1239 if (Attrs != ObjCPropertyDecl::OBJC_PR_noattr) {
1240 if (Attrs & ObjCPropertyDecl::OBJC_PR_readonly)
1242 if (Attrs & ObjCPropertyDecl::OBJC_PR_assign)
1244 if (Attrs & ObjCPropertyDecl::OBJC_PR_readwrite)
1246 if (Attrs & ObjCPropertyDecl::OBJC_PR_retain)
1248 if (Attrs & ObjCPropertyDecl::OBJC_PR_copy)
1250 if (Attrs & ObjCPropertyDecl::OBJC_PR_nonatomic)
1252 if (Attrs & ObjCPropertyDecl::OBJC_PR_atomic)
1254 if (Attrs & ObjCPropertyDecl::OBJC_PR_weak)
1256 if (Attrs & ObjCPropertyDecl::OBJC_PR_strong)
1258 if (Attrs & ObjCPropertyDecl::OBJC_PR_unsafe_unretained)
1259 OS << " unsafe_unretained";
1260 if (Attrs & ObjCPropertyDecl::OBJC_PR_getter) {
1261 if (!(Attrs & ObjCPropertyDecl::OBJC_PR_setter))
1263 dumpDeclRef(D->getGetterMethodDecl(), "getter");
1265 if (Attrs & ObjCPropertyDecl::OBJC_PR_setter) {
1267 dumpDeclRef(D->getSetterMethodDecl(), "setter");
1272 void ASTDumper::VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D) {
1273 dumpName(D->getPropertyDecl());
1274 if (D->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize)
1275 OS << " synthesize";
1278 dumpDeclRef(D->getPropertyDecl());
1280 dumpDeclRef(D->getPropertyIvarDecl());
1283 void ASTDumper::VisitBlockDecl(const BlockDecl *D) {
1284 for (BlockDecl::param_const_iterator I = D->param_begin(), E = D->param_end();
1288 if (D->isVariadic()) {
1289 IndentScope Indent(*this);
1293 if (D->capturesCXXThis()) {
1294 IndentScope Indent(*this);
1295 OS << "capture this";
1297 for (BlockDecl::capture_iterator I = D->capture_begin(), E = D->capture_end();
1299 IndentScope Indent(*this);
1305 if (I->getVariable()) {
1307 dumpBareDeclRef(I->getVariable());
1309 if (I->hasCopyExpr())
1310 dumpStmt(I->getCopyExpr());
1313 dumpStmt(D->getBody());
1316 //===----------------------------------------------------------------------===//
1317 // Stmt dumping methods.
1318 //===----------------------------------------------------------------------===//
1320 void ASTDumper::dumpStmt(const Stmt *S) {
1321 IndentScope Indent(*this);
1324 ColorScope Color(*this, NullColor);
1329 if (const DeclStmt *DS = dyn_cast<DeclStmt>(S)) {
1334 setMoreChildren(S->children());
1335 ConstStmtVisitor<ASTDumper>::Visit(S);
1336 setMoreChildren(false);
1337 for (Stmt::const_child_range CI = S->children(); CI; ++CI) {
1338 Stmt::const_child_range Next = CI;
1346 void ASTDumper::VisitStmt(const Stmt *Node) {
1348 ColorScope Color(*this, StmtColor);
1349 OS << Node->getStmtClassName();
1352 dumpSourceRange(Node->getSourceRange());
1355 void ASTDumper::VisitDeclStmt(const DeclStmt *Node) {
1357 for (DeclStmt::const_decl_iterator I = Node->decl_begin(),
1358 E = Node->decl_end();
1366 void ASTDumper::VisitAttributedStmt(const AttributedStmt *Node) {
1368 for (ArrayRef<const Attr *>::iterator I = Node->getAttrs().begin(),
1369 E = Node->getAttrs().end();
1377 void ASTDumper::VisitLabelStmt(const LabelStmt *Node) {
1379 OS << " '" << Node->getName() << "'";
1382 void ASTDumper::VisitGotoStmt(const GotoStmt *Node) {
1384 OS << " '" << Node->getLabel()->getName() << "'";
1385 dumpPointer(Node->getLabel());
1388 //===----------------------------------------------------------------------===//
1389 // Expr dumping methods.
1390 //===----------------------------------------------------------------------===//
1392 void ASTDumper::VisitExpr(const Expr *Node) {
1394 dumpType(Node->getType());
1397 ColorScope Color(*this, ValueKindColor);
1398 switch (Node->getValueKind()) {
1411 ColorScope Color(*this, ObjectKindColor);
1412 switch (Node->getObjectKind()) {
1418 case OK_ObjCProperty:
1419 OS << " objcproperty";
1421 case OK_ObjCSubscript:
1422 OS << " objcsubscript";
1424 case OK_VectorComponent:
1425 OS << " vectorcomponent";
1431 static void dumpBasePath(raw_ostream &OS, const CastExpr *Node) {
1432 if (Node->path_empty())
1437 for (CastExpr::path_const_iterator I = Node->path_begin(),
1438 E = Node->path_end();
1440 const CXXBaseSpecifier *Base = *I;
1444 const CXXRecordDecl *RD =
1445 cast<CXXRecordDecl>(Base->getType()->getAs<RecordType>()->getDecl());
1447 if (Base->isVirtual())
1449 OS << RD->getName();
1456 void ASTDumper::VisitCastExpr(const CastExpr *Node) {
1460 ColorScope Color(*this, CastColor);
1461 OS << Node->getCastKindName();
1463 dumpBasePath(OS, Node);
1467 void ASTDumper::VisitDeclRefExpr(const DeclRefExpr *Node) {
1471 dumpBareDeclRef(Node->getDecl());
1472 if (Node->getDecl() != Node->getFoundDecl()) {
1474 dumpBareDeclRef(Node->getFoundDecl());
1479 void ASTDumper::VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *Node) {
1482 if (!Node->requiresADL())
1484 OS << "ADL) = '" << Node->getName() << '\'';
1486 UnresolvedLookupExpr::decls_iterator
1487 I = Node->decls_begin(), E = Node->decls_end();
1494 void ASTDumper::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *Node) {
1498 ColorScope Color(*this, DeclKindNameColor);
1499 OS << " " << Node->getDecl()->getDeclKindName() << "Decl";
1501 OS << "='" << *Node->getDecl() << "'";
1502 dumpPointer(Node->getDecl());
1503 if (Node->isFreeIvar())
1504 OS << " isFreeIvar";
1507 void ASTDumper::VisitPredefinedExpr(const PredefinedExpr *Node) {
1509 switch (Node->getIdentType()) {
1510 default: llvm_unreachable("unknown case");
1511 case PredefinedExpr::Func: OS << " __func__"; break;
1512 case PredefinedExpr::Function: OS << " __FUNCTION__"; break;
1513 case PredefinedExpr::LFunction: OS << " L__FUNCTION__"; break;
1514 case PredefinedExpr::PrettyFunction: OS << " __PRETTY_FUNCTION__";break;
1518 void ASTDumper::VisitCharacterLiteral(const CharacterLiteral *Node) {
1520 ColorScope Color(*this, ValueColor);
1521 OS << " " << Node->getValue();
1524 void ASTDumper::VisitIntegerLiteral(const IntegerLiteral *Node) {
1527 bool isSigned = Node->getType()->isSignedIntegerType();
1528 ColorScope Color(*this, ValueColor);
1529 OS << " " << Node->getValue().toString(10, isSigned);
1532 void ASTDumper::VisitFloatingLiteral(const FloatingLiteral *Node) {
1534 ColorScope Color(*this, ValueColor);
1535 OS << " " << Node->getValueAsApproximateDouble();
1538 void ASTDumper::VisitStringLiteral(const StringLiteral *Str) {
1540 ColorScope Color(*this, ValueColor);
1542 Str->outputString(OS);
1545 void ASTDumper::VisitUnaryOperator(const UnaryOperator *Node) {
1547 OS << " " << (Node->isPostfix() ? "postfix" : "prefix")
1548 << " '" << UnaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
1551 void ASTDumper::VisitUnaryExprOrTypeTraitExpr(
1552 const UnaryExprOrTypeTraitExpr *Node) {
1554 switch(Node->getKind()) {
1565 if (Node->isArgumentType())
1566 dumpType(Node->getArgumentType());
1569 void ASTDumper::VisitMemberExpr(const MemberExpr *Node) {
1571 OS << " " << (Node->isArrow() ? "->" : ".") << *Node->getMemberDecl();
1572 dumpPointer(Node->getMemberDecl());
1575 void ASTDumper::VisitExtVectorElementExpr(const ExtVectorElementExpr *Node) {
1577 OS << " " << Node->getAccessor().getNameStart();
1580 void ASTDumper::VisitBinaryOperator(const BinaryOperator *Node) {
1582 OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
1585 void ASTDumper::VisitCompoundAssignOperator(
1586 const CompoundAssignOperator *Node) {
1588 OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode())
1589 << "' ComputeLHSTy=";
1590 dumpBareType(Node->getComputationLHSType());
1591 OS << " ComputeResultTy=";
1592 dumpBareType(Node->getComputationResultType());
1595 void ASTDumper::VisitBlockExpr(const BlockExpr *Node) {
1597 dumpDecl(Node->getBlockDecl());
1600 void ASTDumper::VisitOpaqueValueExpr(const OpaqueValueExpr *Node) {
1603 if (Expr *Source = Node->getSourceExpr()) {
1611 void ASTDumper::VisitAddrLabelExpr(const AddrLabelExpr *Node) {
1613 OS << " " << Node->getLabel()->getName();
1614 dumpPointer(Node->getLabel());
1617 //===----------------------------------------------------------------------===//
1619 //===----------------------------------------------------------------------===//
1621 void ASTDumper::VisitCXXNamedCastExpr(const CXXNamedCastExpr *Node) {
1623 OS << " " << Node->getCastName()
1624 << "<" << Node->getTypeAsWritten().getAsString() << ">"
1625 << " <" << Node->getCastKindName();
1626 dumpBasePath(OS, Node);
1630 void ASTDumper::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *Node) {
1632 OS << " " << (Node->getValue() ? "true" : "false");
1635 void ASTDumper::VisitCXXThisExpr(const CXXThisExpr *Node) {
1640 void ASTDumper::VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *Node) {
1642 OS << " functional cast to " << Node->getTypeAsWritten().getAsString()
1643 << " <" << Node->getCastKindName() << ">";
1646 void ASTDumper::VisitCXXConstructExpr(const CXXConstructExpr *Node) {
1648 CXXConstructorDecl *Ctor = Node->getConstructor();
1649 dumpType(Ctor->getType());
1650 if (Node->isElidable())
1652 if (Node->requiresZeroInitialization())
1656 void ASTDumper::VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *Node) {
1659 dumpCXXTemporary(Node->getTemporary());
1662 void ASTDumper::VisitExprWithCleanups(const ExprWithCleanups *Node) {
1664 for (unsigned i = 0, e = Node->getNumObjects(); i != e; ++i)
1665 dumpDeclRef(Node->getObject(i), "cleanup");
1668 void ASTDumper::dumpCXXTemporary(const CXXTemporary *Temporary) {
1669 OS << "(CXXTemporary";
1670 dumpPointer(Temporary);
1674 //===----------------------------------------------------------------------===//
1675 // Obj-C Expressions
1676 //===----------------------------------------------------------------------===//
1678 void ASTDumper::VisitObjCMessageExpr(const ObjCMessageExpr *Node) {
1680 OS << " selector=" << Node->getSelector().getAsString();
1681 switch (Node->getReceiverKind()) {
1682 case ObjCMessageExpr::Instance:
1685 case ObjCMessageExpr::Class:
1687 dumpBareType(Node->getClassReceiver());
1690 case ObjCMessageExpr::SuperInstance:
1691 OS << " super (instance)";
1694 case ObjCMessageExpr::SuperClass:
1695 OS << " super (class)";
1700 void ASTDumper::VisitObjCBoxedExpr(const ObjCBoxedExpr *Node) {
1702 OS << " selector=" << Node->getBoxingMethod()->getSelector().getAsString();
1705 void ASTDumper::VisitObjCAtCatchStmt(const ObjCAtCatchStmt *Node) {
1707 if (const VarDecl *CatchParam = Node->getCatchParamDecl())
1708 dumpDecl(CatchParam);
1713 void ASTDumper::VisitObjCEncodeExpr(const ObjCEncodeExpr *Node) {
1715 dumpType(Node->getEncodedType());
1718 void ASTDumper::VisitObjCSelectorExpr(const ObjCSelectorExpr *Node) {
1721 OS << " " << Node->getSelector().getAsString();
1724 void ASTDumper::VisitObjCProtocolExpr(const ObjCProtocolExpr *Node) {
1727 OS << ' ' << *Node->getProtocol();
1730 void ASTDumper::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *Node) {
1732 if (Node->isImplicitProperty()) {
1733 OS << " Kind=MethodRef Getter=\"";
1734 if (Node->getImplicitPropertyGetter())
1735 OS << Node->getImplicitPropertyGetter()->getSelector().getAsString();
1739 OS << "\" Setter=\"";
1740 if (ObjCMethodDecl *Setter = Node->getImplicitPropertySetter())
1741 OS << Setter->getSelector().getAsString();
1746 OS << " Kind=PropertyRef Property=\"" << *Node->getExplicitProperty() <<'"';
1749 if (Node->isSuperReceiver())
1752 OS << " Messaging=";
1753 if (Node->isMessagingGetter() && Node->isMessagingSetter())
1754 OS << "Getter&Setter";
1755 else if (Node->isMessagingGetter())
1757 else if (Node->isMessagingSetter())
1761 void ASTDumper::VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *Node) {
1763 if (Node->isArraySubscriptRefExpr())
1764 OS << " Kind=ArraySubscript GetterForArray=\"";
1766 OS << " Kind=DictionarySubscript GetterForDictionary=\"";
1767 if (Node->getAtIndexMethodDecl())
1768 OS << Node->getAtIndexMethodDecl()->getSelector().getAsString();
1772 if (Node->isArraySubscriptRefExpr())
1773 OS << "\" SetterForArray=\"";
1775 OS << "\" SetterForDictionary=\"";
1776 if (Node->setAtIndexMethodDecl())
1777 OS << Node->setAtIndexMethodDecl()->getSelector().getAsString();
1782 void ASTDumper::VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *Node) {
1784 OS << " " << (Node->getValue() ? "__objc_yes" : "__objc_no");
1787 //===----------------------------------------------------------------------===//
1789 //===----------------------------------------------------------------------===//
1791 const char *ASTDumper::getCommandName(unsigned CommandID) {
1793 return Traits->getCommandInfo(CommandID)->Name;
1794 const CommandInfo *Info = CommandTraits::getBuiltinCommandInfo(CommandID);
1797 return "<not a builtin command>";
1800 void ASTDumper::dumpFullComment(const FullComment *C) {
1809 void ASTDumper::dumpComment(const Comment *C) {
1810 IndentScope Indent(*this);
1813 ColorScope Color(*this, NullColor);
1819 ColorScope Color(*this, CommentColor);
1820 OS << C->getCommentKindName();
1823 dumpSourceRange(C->getSourceRange());
1824 ConstCommentVisitor<ASTDumper>::visit(C);
1825 for (Comment::child_iterator I = C->child_begin(), E = C->child_end();
1833 void ASTDumper::visitTextComment(const TextComment *C) {
1834 OS << " Text=\"" << C->getText() << "\"";
1837 void ASTDumper::visitInlineCommandComment(const InlineCommandComment *C) {
1838 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\"";
1839 switch (C->getRenderKind()) {
1840 case InlineCommandComment::RenderNormal:
1841 OS << " RenderNormal";
1843 case InlineCommandComment::RenderBold:
1844 OS << " RenderBold";
1846 case InlineCommandComment::RenderMonospaced:
1847 OS << " RenderMonospaced";
1849 case InlineCommandComment::RenderEmphasized:
1850 OS << " RenderEmphasized";
1854 for (unsigned i = 0, e = C->getNumArgs(); i != e; ++i)
1855 OS << " Arg[" << i << "]=\"" << C->getArgText(i) << "\"";
1858 void ASTDumper::visitHTMLStartTagComment(const HTMLStartTagComment *C) {
1859 OS << " Name=\"" << C->getTagName() << "\"";
1860 if (C->getNumAttrs() != 0) {
1862 for (unsigned i = 0, e = C->getNumAttrs(); i != e; ++i) {
1863 const HTMLStartTagComment::Attribute &Attr = C->getAttr(i);
1864 OS << " \"" << Attr.Name << "=\"" << Attr.Value << "\"";
1867 if (C->isSelfClosing())
1868 OS << " SelfClosing";
1871 void ASTDumper::visitHTMLEndTagComment(const HTMLEndTagComment *C) {
1872 OS << " Name=\"" << C->getTagName() << "\"";
1875 void ASTDumper::visitBlockCommandComment(const BlockCommandComment *C) {
1876 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\"";
1877 for (unsigned i = 0, e = C->getNumArgs(); i != e; ++i)
1878 OS << " Arg[" << i << "]=\"" << C->getArgText(i) << "\"";
1881 void ASTDumper::visitParamCommandComment(const ParamCommandComment *C) {
1882 OS << " " << ParamCommandComment::getDirectionAsString(C->getDirection());
1884 if (C->isDirectionExplicit())
1885 OS << " explicitly";
1887 OS << " implicitly";
1889 if (C->hasParamName()) {
1890 if (C->isParamIndexValid())
1891 OS << " Param=\"" << C->getParamName(FC) << "\"";
1893 OS << " Param=\"" << C->getParamNameAsWritten() << "\"";
1896 if (C->isParamIndexValid())
1897 OS << " ParamIndex=" << C->getParamIndex();
1900 void ASTDumper::visitTParamCommandComment(const TParamCommandComment *C) {
1901 if (C->hasParamName()) {
1902 if (C->isPositionValid())
1903 OS << " Param=\"" << C->getParamName(FC) << "\"";
1905 OS << " Param=\"" << C->getParamNameAsWritten() << "\"";
1908 if (C->isPositionValid()) {
1909 OS << " Position=<";
1910 for (unsigned i = 0, e = C->getDepth(); i != e; ++i) {
1911 OS << C->getIndex(i);
1919 void ASTDumper::visitVerbatimBlockComment(const VerbatimBlockComment *C) {
1920 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\""
1921 " CloseName=\"" << C->getCloseName() << "\"";
1924 void ASTDumper::visitVerbatimBlockLineComment(
1925 const VerbatimBlockLineComment *C) {
1926 OS << " Text=\"" << C->getText() << "\"";
1929 void ASTDumper::visitVerbatimLineComment(const VerbatimLineComment *C) {
1930 OS << " Text=\"" << C->getText() << "\"";
1933 //===----------------------------------------------------------------------===//
1934 // Decl method implementations
1935 //===----------------------------------------------------------------------===//
1937 void Decl::dump() const {
1941 void Decl::dump(raw_ostream &OS) const {
1942 ASTDumper P(OS, &getASTContext().getCommentCommandTraits(),
1943 &getASTContext().getSourceManager());
1947 void Decl::dumpColor() const {
1948 ASTDumper P(llvm::errs(), &getASTContext().getCommentCommandTraits(),
1949 &getASTContext().getSourceManager(), /*ShowColors*/true);
1952 //===----------------------------------------------------------------------===//
1953 // Stmt method implementations
1954 //===----------------------------------------------------------------------===//
1956 void Stmt::dump(SourceManager &SM) const {
1957 dump(llvm::errs(), SM);
1960 void Stmt::dump(raw_ostream &OS, SourceManager &SM) const {
1961 ASTDumper P(OS, 0, &SM);
1965 void Stmt::dump() const {
1966 ASTDumper P(llvm::errs(), 0, 0);
1970 void Stmt::dumpColor() const {
1971 ASTDumper P(llvm::errs(), 0, 0, /*ShowColors*/true);
1975 //===----------------------------------------------------------------------===//
1976 // Comment method implementations
1977 //===----------------------------------------------------------------------===//
1979 void Comment::dump() const {
1980 dump(llvm::errs(), 0, 0);
1983 void Comment::dump(const ASTContext &Context) const {
1984 dump(llvm::errs(), &Context.getCommentCommandTraits(),
1985 &Context.getSourceManager());
1988 void Comment::dump(raw_ostream &OS, const CommandTraits *Traits,
1989 const SourceManager *SM) const {
1990 const FullComment *FC = dyn_cast<FullComment>(this);
1991 ASTDumper D(OS, Traits, SM);
1992 D.dumpFullComment(FC);
1995 void Comment::dumpColor() const {
1996 const FullComment *FC = dyn_cast<FullComment>(this);
1997 ASTDumper D(llvm::errs(), 0, 0, /*ShowColors*/true);
1998 D.dumpFullComment(FC);