blob: c1a8eaf01f08383949ca711b7b9089517e73a4c0 [file] [log] [blame]
Alexander Kornienko18ec81b2012-12-13 13:59:55 +00001//===--- ASTDumper.cpp - Dumping implementation for ASTs ------------------===//
Chris Lattnercbe4f772007-08-08 22:51:59 +00002//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner5b12ab82007-12-29 19:59:25 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattnercbe4f772007-08-08 22:51:59 +00007//
8//===----------------------------------------------------------------------===//
9//
Alexander Kornienko18ec81b2012-12-13 13:59:55 +000010// This file implements the AST dump methods, which dump out the
Chris Lattnercbe4f772007-08-08 22:51:59 +000011// AST in a form that exposes type details and other fields.
12//
13//===----------------------------------------------------------------------===//
14
Chandler Carruth3a022472012-12-04 09:13:33 +000015#include "clang/AST/ASTContext.h"
Alexander Kornienko5bc364e2013-01-07 17:53:08 +000016#include "clang/AST/Attr.h"
Alexander Kornienkoebc17b52013-01-14 14:07:11 +000017#include "clang/AST/CommentVisitor.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000018#include "clang/AST/DeclCXX.h"
Richard Smith33937e72013-06-22 21:49:40 +000019#include "clang/AST/DeclLookups.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000020#include "clang/AST/DeclObjC.h"
Alexander Kornienko90ff6072012-12-20 02:09:13 +000021#include "clang/AST/DeclVisitor.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000022#include "clang/AST/StmtVisitor.h"
Alexander Kornienko90ff6072012-12-20 02:09:13 +000023#include "clang/Basic/Module.h"
Chris Lattner11e30d32007-08-30 06:17:34 +000024#include "clang/Basic/SourceManager.h"
Daniel Dunbar34a96c82009-12-03 09:13:13 +000025#include "llvm/Support/raw_ostream.h"
Chris Lattnercbe4f772007-08-08 22:51:59 +000026using namespace clang;
Alexander Kornienkoebc17b52013-01-14 14:07:11 +000027using namespace clang::comments;
Chris Lattnercbe4f772007-08-08 22:51:59 +000028
29//===----------------------------------------------------------------------===//
Alexander Kornienko18ec81b2012-12-13 13:59:55 +000030// ASTDumper Visitor
Chris Lattnercbe4f772007-08-08 22:51:59 +000031//===----------------------------------------------------------------------===//
32
33namespace {
Richard Trieud215b8d2013-01-26 01:31:20 +000034 // Colors used for various parts of the AST dump
Richard Trieu532018f2014-03-06 01:09:03 +000035 // Do not use bold yellow for any text. It is hard to read on white screens.
Richard Trieud215b8d2013-01-26 01:31:20 +000036
37 struct TerminalColor {
38 raw_ostream::Colors Color;
39 bool Bold;
40 };
41
Richard Trieu532018f2014-03-06 01:09:03 +000042 // Red - CastColor
43 // Green - TypeColor
44 // Bold Green - DeclKindNameColor, UndeserializedColor
45 // Yellow - AddressColor, LocationColor
46 // Blue - CommentColor, NullColor, IndentColor
47 // Bold Blue - AttrColor
48 // Bold Magenta - StmtColor
49 // Cyan - ValueKindColor, ObjectKindColor
50 // Bold Cyan - ValueColor, DeclNameColor
51
Richard Trieud215b8d2013-01-26 01:31:20 +000052 // Decl kind names (VarDecl, FunctionDecl, etc)
53 static const TerminalColor DeclKindNameColor = { raw_ostream::GREEN, true };
54 // Attr names (CleanupAttr, GuardedByAttr, etc)
55 static const TerminalColor AttrColor = { raw_ostream::BLUE, true };
56 // Statement names (DeclStmt, ImplicitCastExpr, etc)
57 static const TerminalColor StmtColor = { raw_ostream::MAGENTA, true };
58 // Comment names (FullComment, ParagraphComment, TextComment, etc)
Richard Trieu532018f2014-03-06 01:09:03 +000059 static const TerminalColor CommentColor = { raw_ostream::BLUE, false };
Richard Trieud215b8d2013-01-26 01:31:20 +000060
61 // Type names (int, float, etc, plus user defined types)
62 static const TerminalColor TypeColor = { raw_ostream::GREEN, false };
63
64 // Pointer address
65 static const TerminalColor AddressColor = { raw_ostream::YELLOW, false };
66 // Source locations
67 static const TerminalColor LocationColor = { raw_ostream::YELLOW, false };
68
69 // lvalue/xvalue
70 static const TerminalColor ValueKindColor = { raw_ostream::CYAN, false };
71 // bitfield/objcproperty/objcsubscript/vectorcomponent
72 static const TerminalColor ObjectKindColor = { raw_ostream::CYAN, false };
73
74 // Null statements
75 static const TerminalColor NullColor = { raw_ostream::BLUE, false };
76
Richard Smith1d209d02013-05-23 01:49:11 +000077 // Undeserialized entities
78 static const TerminalColor UndeserializedColor = { raw_ostream::GREEN, true };
79
Richard Trieud215b8d2013-01-26 01:31:20 +000080 // CastKind from CastExpr's
81 static const TerminalColor CastColor = { raw_ostream::RED, false };
82
83 // Value of the statement
84 static const TerminalColor ValueColor = { raw_ostream::CYAN, true };
85 // Decl names
86 static const TerminalColor DeclNameColor = { raw_ostream::CYAN, true };
87
Richard Trieude5cc7d2013-01-31 01:44:26 +000088 // Indents ( `, -. | )
89 static const TerminalColor IndentColor = { raw_ostream::BLUE, false };
90
Alexander Kornienko90ff6072012-12-20 02:09:13 +000091 class ASTDumper
Alexander Kornienko540bacb2013-02-01 12:35:51 +000092 : public ConstDeclVisitor<ASTDumper>, public ConstStmtVisitor<ASTDumper>,
Alexander Kornienkoebc17b52013-01-14 14:07:11 +000093 public ConstCommentVisitor<ASTDumper> {
Chris Lattner0e62c1c2011-07-23 10:55:15 +000094 raw_ostream &OS;
Alexander Kornienkoebc17b52013-01-14 14:07:11 +000095 const CommandTraits *Traits;
96 const SourceManager *SM;
Manuel Klimek874030e2012-11-07 00:33:12 +000097 bool IsFirstLine;
Mike Stump11289f42009-09-09 15:08:12 +000098
Richard Trieude5cc7d2013-01-31 01:44:26 +000099 // Indicates whether more child are expected at the current tree depth
100 enum IndentType { IT_Child, IT_LastChild };
101
102 /// Indents[i] indicates if another child exists at level i.
103 /// Used by Indent() to print the tree structure.
104 llvm::SmallVector<IndentType, 32> Indents;
105
106 /// Indicates that more children will be needed at this indent level.
107 /// If true, prevents lastChild() from marking the node as the last child.
108 /// This is used when there are multiple collections of children to be
109 /// dumped as well as during conditional node dumping.
110 bool MoreChildren;
111
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000112 /// Keep track of the last location we print out so that we can
113 /// print out deltas from then on out.
Chris Lattner11e30d32007-08-30 06:17:34 +0000114 const char *LastLocFilename;
115 unsigned LastLocLine;
Douglas Gregor7de59662009-05-29 20:38:28 +0000116
Alexander Kornienkoebc17b52013-01-14 14:07:11 +0000117 /// The \c FullComment parent of the comment being dumped.
118 const FullComment *FC;
119
Richard Trieud215b8d2013-01-26 01:31:20 +0000120 bool ShowColors;
121
Manuel Klimek874030e2012-11-07 00:33:12 +0000122 class IndentScope {
Alexander Kornienko18ec81b2012-12-13 13:59:55 +0000123 ASTDumper &Dumper;
Richard Trieude5cc7d2013-01-31 01:44:26 +0000124 // Preserve the Dumper's MoreChildren value from the previous IndentScope
125 bool MoreChildren;
Manuel Klimek874030e2012-11-07 00:33:12 +0000126 public:
Alexander Kornienko18ec81b2012-12-13 13:59:55 +0000127 IndentScope(ASTDumper &Dumper) : Dumper(Dumper) {
Richard Trieude5cc7d2013-01-31 01:44:26 +0000128 MoreChildren = Dumper.hasMoreChildren();
129 Dumper.setMoreChildren(false);
Manuel Klimek874030e2012-11-07 00:33:12 +0000130 Dumper.indent();
131 }
132 ~IndentScope() {
Richard Trieude5cc7d2013-01-31 01:44:26 +0000133 Dumper.setMoreChildren(MoreChildren);
Manuel Klimek874030e2012-11-07 00:33:12 +0000134 Dumper.unindent();
135 }
136 };
137
Richard Trieud215b8d2013-01-26 01:31:20 +0000138 class ColorScope {
139 ASTDumper &Dumper;
140 public:
141 ColorScope(ASTDumper &Dumper, TerminalColor Color)
142 : Dumper(Dumper) {
143 if (Dumper.ShowColors)
144 Dumper.OS.changeColor(Color.Color, Color.Bold);
145 }
146 ~ColorScope() {
147 if (Dumper.ShowColors)
148 Dumper.OS.resetColor();
149 }
150 };
151
Chris Lattnercbe4f772007-08-08 22:51:59 +0000152 public:
Alexander Kornienkoebc17b52013-01-14 14:07:11 +0000153 ASTDumper(raw_ostream &OS, const CommandTraits *Traits,
154 const SourceManager *SM)
Richard Smith56d12152013-01-31 02:04:38 +0000155 : OS(OS), Traits(Traits), SM(SM), IsFirstLine(true), MoreChildren(false),
156 LastLocFilename(""), LastLocLine(~0U), FC(0),
Richard Trieud215b8d2013-01-26 01:31:20 +0000157 ShowColors(SM && SM->getDiagnostics().getShowColors()) { }
158
159 ASTDumper(raw_ostream &OS, const CommandTraits *Traits,
160 const SourceManager *SM, bool ShowColors)
Richard Smith56d12152013-01-31 02:04:38 +0000161 : OS(OS), Traits(Traits), SM(SM), IsFirstLine(true), MoreChildren(false),
162 LastLocFilename(""), LastLocLine(~0U),
Richard Trieude5cc7d2013-01-31 01:44:26 +0000163 ShowColors(ShowColors) { }
Mike Stump11289f42009-09-09 15:08:12 +0000164
Alexander Kornienko18ec81b2012-12-13 13:59:55 +0000165 ~ASTDumper() {
Manuel Klimek874030e2012-11-07 00:33:12 +0000166 OS << "\n";
167 }
168
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000169 void dumpDecl(const Decl *D);
170 void dumpStmt(const Stmt *S);
Alexander Kornienkoebc17b52013-01-14 14:07:11 +0000171 void dumpFullComment(const FullComment *C);
Mike Stump11289f42009-09-09 15:08:12 +0000172
Richard Trieude5cc7d2013-01-31 01:44:26 +0000173 // Formatting
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000174 void indent();
175 void unindent();
Richard Trieude5cc7d2013-01-31 01:44:26 +0000176 void lastChild();
177 bool hasMoreChildren();
178 void setMoreChildren(bool Value);
179
180 // Utilities
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000181 void dumpPointer(const void *Ptr);
182 void dumpSourceRange(SourceRange R);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000183 void dumpLocation(SourceLocation Loc);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000184 void dumpBareType(QualType T);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000185 void dumpType(QualType T);
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000186 void dumpBareDeclRef(const Decl *Node);
Alexander Kornienko9bdeb112012-12-20 12:23:54 +0000187 void dumpDeclRef(const Decl *Node, const char *Label = 0);
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000188 void dumpName(const NamedDecl *D);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000189 bool hasNodes(const DeclContext *DC);
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000190 void dumpDeclContext(const DeclContext *DC);
Richard Smith33937e72013-06-22 21:49:40 +0000191 void dumpLookups(const DeclContext *DC);
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000192 void dumpAttr(const Attr *A);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000193
194 // C++ Utilities
195 void dumpAccessSpecifier(AccessSpecifier AS);
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000196 void dumpCXXCtorInitializer(const CXXCtorInitializer *Init);
197 void dumpTemplateParameters(const TemplateParameterList *TPL);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000198 void dumpTemplateArgumentListInfo(const TemplateArgumentListInfo &TALI);
199 void dumpTemplateArgumentLoc(const TemplateArgumentLoc &A);
200 void dumpTemplateArgumentList(const TemplateArgumentList &TAL);
201 void dumpTemplateArgument(const TemplateArgument &A,
202 SourceRange R = SourceRange());
203
204 // Decls
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000205 void VisitLabelDecl(const LabelDecl *D);
206 void VisitTypedefDecl(const TypedefDecl *D);
207 void VisitEnumDecl(const EnumDecl *D);
208 void VisitRecordDecl(const RecordDecl *D);
209 void VisitEnumConstantDecl(const EnumConstantDecl *D);
210 void VisitIndirectFieldDecl(const IndirectFieldDecl *D);
211 void VisitFunctionDecl(const FunctionDecl *D);
212 void VisitFieldDecl(const FieldDecl *D);
213 void VisitVarDecl(const VarDecl *D);
214 void VisitFileScopeAsmDecl(const FileScopeAsmDecl *D);
215 void VisitImportDecl(const ImportDecl *D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000216
217 // C++ Decls
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000218 void VisitNamespaceDecl(const NamespaceDecl *D);
219 void VisitUsingDirectiveDecl(const UsingDirectiveDecl *D);
220 void VisitNamespaceAliasDecl(const NamespaceAliasDecl *D);
221 void VisitTypeAliasDecl(const TypeAliasDecl *D);
222 void VisitTypeAliasTemplateDecl(const TypeAliasTemplateDecl *D);
223 void VisitCXXRecordDecl(const CXXRecordDecl *D);
224 void VisitStaticAssertDecl(const StaticAssertDecl *D);
225 void VisitFunctionTemplateDecl(const FunctionTemplateDecl *D);
226 void VisitClassTemplateDecl(const ClassTemplateDecl *D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000227 void VisitClassTemplateSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000228 const ClassTemplateSpecializationDecl *D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000229 void VisitClassTemplatePartialSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000230 const ClassTemplatePartialSpecializationDecl *D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000231 void VisitClassScopeFunctionSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000232 const ClassScopeFunctionSpecializationDecl *D);
Richard Smithd25789a2013-09-18 01:36:02 +0000233 void VisitVarTemplateDecl(const VarTemplateDecl *D);
234 void VisitVarTemplateSpecializationDecl(
235 const VarTemplateSpecializationDecl *D);
236 void VisitVarTemplatePartialSpecializationDecl(
237 const VarTemplatePartialSpecializationDecl *D);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000238 void VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D);
239 void VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D);
240 void VisitTemplateTemplateParmDecl(const TemplateTemplateParmDecl *D);
241 void VisitUsingDecl(const UsingDecl *D);
242 void VisitUnresolvedUsingTypenameDecl(const UnresolvedUsingTypenameDecl *D);
243 void VisitUnresolvedUsingValueDecl(const UnresolvedUsingValueDecl *D);
244 void VisitUsingShadowDecl(const UsingShadowDecl *D);
245 void VisitLinkageSpecDecl(const LinkageSpecDecl *D);
246 void VisitAccessSpecDecl(const AccessSpecDecl *D);
247 void VisitFriendDecl(const FriendDecl *D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000248
249 // ObjC Decls
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000250 void VisitObjCIvarDecl(const ObjCIvarDecl *D);
251 void VisitObjCMethodDecl(const ObjCMethodDecl *D);
252 void VisitObjCCategoryDecl(const ObjCCategoryDecl *D);
253 void VisitObjCCategoryImplDecl(const ObjCCategoryImplDecl *D);
254 void VisitObjCProtocolDecl(const ObjCProtocolDecl *D);
255 void VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D);
256 void VisitObjCImplementationDecl(const ObjCImplementationDecl *D);
257 void VisitObjCCompatibleAliasDecl(const ObjCCompatibleAliasDecl *D);
258 void VisitObjCPropertyDecl(const ObjCPropertyDecl *D);
259 void VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D);
260 void VisitBlockDecl(const BlockDecl *D);
Mike Stump11289f42009-09-09 15:08:12 +0000261
Chris Lattner84ca3762007-08-30 01:00:35 +0000262 // Stmts.
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000263 void VisitStmt(const Stmt *Node);
264 void VisitDeclStmt(const DeclStmt *Node);
265 void VisitAttributedStmt(const AttributedStmt *Node);
266 void VisitLabelStmt(const LabelStmt *Node);
267 void VisitGotoStmt(const GotoStmt *Node);
Pavel Labath1ef83422013-09-04 14:35:00 +0000268 void VisitCXXCatchStmt(const CXXCatchStmt *Node);
Mike Stump11289f42009-09-09 15:08:12 +0000269
Chris Lattner84ca3762007-08-30 01:00:35 +0000270 // Exprs
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000271 void VisitExpr(const Expr *Node);
272 void VisitCastExpr(const CastExpr *Node);
273 void VisitDeclRefExpr(const DeclRefExpr *Node);
274 void VisitPredefinedExpr(const PredefinedExpr *Node);
275 void VisitCharacterLiteral(const CharacterLiteral *Node);
276 void VisitIntegerLiteral(const IntegerLiteral *Node);
277 void VisitFloatingLiteral(const FloatingLiteral *Node);
278 void VisitStringLiteral(const StringLiteral *Str);
279 void VisitUnaryOperator(const UnaryOperator *Node);
280 void VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *Node);
281 void VisitMemberExpr(const MemberExpr *Node);
282 void VisitExtVectorElementExpr(const ExtVectorElementExpr *Node);
283 void VisitBinaryOperator(const BinaryOperator *Node);
284 void VisitCompoundAssignOperator(const CompoundAssignOperator *Node);
285 void VisitAddrLabelExpr(const AddrLabelExpr *Node);
286 void VisitBlockExpr(const BlockExpr *Node);
287 void VisitOpaqueValueExpr(const OpaqueValueExpr *Node);
Chris Lattner84ca3762007-08-30 01:00:35 +0000288
289 // C++
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000290 void VisitCXXNamedCastExpr(const CXXNamedCastExpr *Node);
291 void VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *Node);
292 void VisitCXXThisExpr(const CXXThisExpr *Node);
293 void VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *Node);
294 void VisitCXXConstructExpr(const CXXConstructExpr *Node);
295 void VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *Node);
Richard Smithe6c01442013-06-05 00:46:14 +0000296 void VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000297 void VisitExprWithCleanups(const ExprWithCleanups *Node);
298 void VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *Node);
299 void dumpCXXTemporary(const CXXTemporary *Temporary);
Faisal Vali2b391ab2013-09-26 19:54:12 +0000300 void VisitLambdaExpr(const LambdaExpr *Node) {
301 VisitExpr(Node);
302 dumpDecl(Node->getLambdaClass());
303 }
Mike Stump11289f42009-09-09 15:08:12 +0000304
Chris Lattner84ca3762007-08-30 01:00:35 +0000305 // ObjC
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000306 void VisitObjCAtCatchStmt(const ObjCAtCatchStmt *Node);
307 void VisitObjCEncodeExpr(const ObjCEncodeExpr *Node);
308 void VisitObjCMessageExpr(const ObjCMessageExpr *Node);
309 void VisitObjCBoxedExpr(const ObjCBoxedExpr *Node);
310 void VisitObjCSelectorExpr(const ObjCSelectorExpr *Node);
311 void VisitObjCProtocolExpr(const ObjCProtocolExpr *Node);
312 void VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *Node);
313 void VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *Node);
314 void VisitObjCIvarRefExpr(const ObjCIvarRefExpr *Node);
315 void VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *Node);
Alexander Kornienkoebc17b52013-01-14 14:07:11 +0000316
317 // Comments.
318 const char *getCommandName(unsigned CommandID);
319 void dumpComment(const Comment *C);
320
321 // Inline comments.
322 void visitTextComment(const TextComment *C);
323 void visitInlineCommandComment(const InlineCommandComment *C);
324 void visitHTMLStartTagComment(const HTMLStartTagComment *C);
325 void visitHTMLEndTagComment(const HTMLEndTagComment *C);
326
327 // Block comments.
328 void visitBlockCommandComment(const BlockCommandComment *C);
329 void visitParamCommandComment(const ParamCommandComment *C);
330 void visitTParamCommandComment(const TParamCommandComment *C);
331 void visitVerbatimBlockComment(const VerbatimBlockComment *C);
332 void visitVerbatimBlockLineComment(const VerbatimBlockLineComment *C);
333 void visitVerbatimLineComment(const VerbatimLineComment *C);
Chris Lattnercbe4f772007-08-08 22:51:59 +0000334 };
335}
336
337//===----------------------------------------------------------------------===//
Chris Lattner11e30d32007-08-30 06:17:34 +0000338// Utilities
339//===----------------------------------------------------------------------===//
340
Richard Trieude5cc7d2013-01-31 01:44:26 +0000341// Print out the appropriate tree structure using the Indents vector.
342// Example of tree and the Indents vector at each level.
343// A { }
344// |-B { IT_Child }
345// | `-C { IT_Child, IT_LastChild }
346// `-D { IT_LastChild }
347// |-E { IT_LastChild, IT_Child }
348// `-F { IT_LastChild, IT_LastChild }
349// Type non-last element, last element
350// IT_Child "| " "|-"
351// IT_LastChild " " "`-"
Alexander Kornienko18ec81b2012-12-13 13:59:55 +0000352void ASTDumper::indent() {
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000353 if (IsFirstLine)
354 IsFirstLine = false;
355 else
356 OS << "\n";
Richard Trieude5cc7d2013-01-31 01:44:26 +0000357
358 ColorScope Color(*this, IndentColor);
Craig Topper2341c0d2013-07-04 03:08:24 +0000359 for (SmallVectorImpl<IndentType>::const_iterator I = Indents.begin(),
360 E = Indents.end();
Richard Trieude5cc7d2013-01-31 01:44:26 +0000361 I != E; ++I) {
362 switch (*I) {
Richard Smith56d12152013-01-31 02:04:38 +0000363 case IT_Child:
364 if (I == E - 1)
365 OS << "|-";
366 else
367 OS << "| ";
368 continue;
369 case IT_LastChild:
370 if (I == E - 1)
371 OS << "`-";
372 else
373 OS << " ";
374 continue;
Richard Trieude5cc7d2013-01-31 01:44:26 +0000375 }
Richard Smith56d12152013-01-31 02:04:38 +0000376 llvm_unreachable("Invalid IndentType");
Richard Trieude5cc7d2013-01-31 01:44:26 +0000377 }
378 Indents.push_back(IT_Child);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000379}
380
Alexander Kornienko18ec81b2012-12-13 13:59:55 +0000381void ASTDumper::unindent() {
Richard Trieude5cc7d2013-01-31 01:44:26 +0000382 Indents.pop_back();
383}
384
385// Call before each potential last child node is to be dumped. If MoreChildren
386// is false, then this is the last child, otherwise treat as a regular node.
387void ASTDumper::lastChild() {
388 if (!hasMoreChildren())
389 Indents.back() = IT_LastChild;
390}
391
392// MoreChildren should be set before calling another function that may print
393// additional nodes to prevent conflicting final child nodes.
394bool ASTDumper::hasMoreChildren() {
395 return MoreChildren;
396}
397
398void ASTDumper::setMoreChildren(bool Value) {
399 MoreChildren = Value;
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000400}
401
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000402void ASTDumper::dumpPointer(const void *Ptr) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000403 ColorScope Color(*this, AddressColor);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000404 OS << ' ' << Ptr;
405}
406
Alexander Kornienko18ec81b2012-12-13 13:59:55 +0000407void ASTDumper::dumpLocation(SourceLocation Loc) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000408 ColorScope Color(*this, LocationColor);
Chris Lattner53e384f2009-01-16 07:00:02 +0000409 SourceLocation SpellingLoc = SM->getSpellingLoc(Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000410
Chris Lattner11e30d32007-08-30 06:17:34 +0000411 // The general format we print out is filename:line:col, but we drop pieces
412 // that haven't changed since the last loc printed.
Chris Lattnerf1ca7d32009-01-27 07:57:44 +0000413 PresumedLoc PLoc = SM->getPresumedLoc(SpellingLoc);
414
Douglas Gregor453b0122010-11-12 07:15:47 +0000415 if (PLoc.isInvalid()) {
416 OS << "<invalid sloc>";
417 return;
418 }
419
Chris Lattnerf1ca7d32009-01-27 07:57:44 +0000420 if (strcmp(PLoc.getFilename(), LastLocFilename) != 0) {
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000421 OS << PLoc.getFilename() << ':' << PLoc.getLine()
422 << ':' << PLoc.getColumn();
Chris Lattnerf1ca7d32009-01-27 07:57:44 +0000423 LastLocFilename = PLoc.getFilename();
424 LastLocLine = PLoc.getLine();
425 } else if (PLoc.getLine() != LastLocLine) {
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000426 OS << "line" << ':' << PLoc.getLine()
427 << ':' << PLoc.getColumn();
Chris Lattnerf1ca7d32009-01-27 07:57:44 +0000428 LastLocLine = PLoc.getLine();
Chris Lattner11e30d32007-08-30 06:17:34 +0000429 } else {
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000430 OS << "col" << ':' << PLoc.getColumn();
Chris Lattner11e30d32007-08-30 06:17:34 +0000431 }
432}
433
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000434void ASTDumper::dumpSourceRange(SourceRange R) {
Chris Lattner11e30d32007-08-30 06:17:34 +0000435 // Can't translate locations if a SourceManager isn't available.
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000436 if (!SM)
437 return;
Mike Stump11289f42009-09-09 15:08:12 +0000438
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000439 OS << " <";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000440 dumpLocation(R.getBegin());
Chris Lattnera7c19fe2007-10-16 22:36:42 +0000441 if (R.getBegin() != R.getEnd()) {
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000442 OS << ", ";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000443 dumpLocation(R.getEnd());
Chris Lattner11e30d32007-08-30 06:17:34 +0000444 }
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000445 OS << ">";
Mike Stump11289f42009-09-09 15:08:12 +0000446
Chris Lattner11e30d32007-08-30 06:17:34 +0000447 // <t2.c:123:421[blah], t2.c:412:321>
448
449}
450
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000451void ASTDumper::dumpBareType(QualType T) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000452 ColorScope Color(*this, TypeColor);
453
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000454 SplitQualType T_split = T.split();
455 OS << "'" << QualType::getAsString(T_split) << "'";
456
457 if (!T.isNull()) {
458 // If the type is sugared, also dump a (shallow) desugared type.
459 SplitQualType D_split = T.getSplitDesugaredType();
460 if (T_split != D_split)
461 OS << ":'" << QualType::getAsString(D_split) << "'";
462 }
463}
464
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000465void ASTDumper::dumpType(QualType T) {
466 OS << ' ';
467 dumpBareType(T);
468}
469
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000470void ASTDumper::dumpBareDeclRef(const Decl *D) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000471 {
472 ColorScope Color(*this, DeclKindNameColor);
473 OS << D->getDeclKindName();
474 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000475 dumpPointer(D);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000476
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000477 if (const NamedDecl *ND = dyn_cast<NamedDecl>(D)) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000478 ColorScope Color(*this, DeclNameColor);
David Blaikied4da8722013-05-14 21:04:00 +0000479 OS << " '" << ND->getDeclName() << '\'';
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000480 }
481
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000482 if (const ValueDecl *VD = dyn_cast<ValueDecl>(D))
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000483 dumpType(VD->getType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000484}
485
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000486void ASTDumper::dumpDeclRef(const Decl *D, const char *Label) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000487 if (!D)
488 return;
489
490 IndentScope Indent(*this);
491 if (Label)
492 OS << Label << ' ';
493 dumpBareDeclRef(D);
494}
495
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000496void ASTDumper::dumpName(const NamedDecl *ND) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000497 if (ND->getDeclName()) {
498 ColorScope Color(*this, DeclNameColor);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000499 OS << ' ' << ND->getNameAsString();
Richard Trieud215b8d2013-01-26 01:31:20 +0000500 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000501}
502
Richard Trieude5cc7d2013-01-31 01:44:26 +0000503bool ASTDumper::hasNodes(const DeclContext *DC) {
504 if (!DC)
505 return false;
506
Richard Smith1d209d02013-05-23 01:49:11 +0000507 return DC->hasExternalLexicalStorage() ||
508 DC->noload_decls_begin() != DC->noload_decls_end();
Richard Trieude5cc7d2013-01-31 01:44:26 +0000509}
510
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000511void ASTDumper::dumpDeclContext(const DeclContext *DC) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000512 if (!DC)
513 return;
Richard Smith1d209d02013-05-23 01:49:11 +0000514 bool HasUndeserializedDecls = DC->hasExternalLexicalStorage();
Richard Smith77c5bb52013-10-18 01:34:56 +0000515 for (DeclContext::decl_iterator I = DC->noload_decls_begin(),
516 E = DC->noload_decls_end();
Richard Trieude5cc7d2013-01-31 01:44:26 +0000517 I != E; ++I) {
518 DeclContext::decl_iterator Next = I;
519 ++Next;
Richard Smith1d209d02013-05-23 01:49:11 +0000520 if (Next == E && !HasUndeserializedDecls)
Richard Trieude5cc7d2013-01-31 01:44:26 +0000521 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000522 dumpDecl(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000523 }
Richard Smith1d209d02013-05-23 01:49:11 +0000524 if (HasUndeserializedDecls) {
525 lastChild();
526 IndentScope Indent(*this);
527 ColorScope Color(*this, UndeserializedColor);
528 OS << "<undeserialized declarations>";
529 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000530}
531
Richard Smith33937e72013-06-22 21:49:40 +0000532void ASTDumper::dumpLookups(const DeclContext *DC) {
533 IndentScope Indent(*this);
534
535 OS << "StoredDeclsMap ";
536 dumpBareDeclRef(cast<Decl>(DC));
537
538 const DeclContext *Primary = DC->getPrimaryContext();
539 if (Primary != DC) {
540 OS << " primary";
541 dumpPointer(cast<Decl>(Primary));
542 }
543
544 bool HasUndeserializedLookups = Primary->hasExternalVisibleStorage();
545
546 DeclContext::all_lookups_iterator I = Primary->noload_lookups_begin(),
547 E = Primary->noload_lookups_end();
548 while (I != E) {
549 DeclarationName Name = I.getLookupName();
550 DeclContextLookupResult R = *I++;
551 if (I == E && !HasUndeserializedLookups)
552 lastChild();
553
554 IndentScope Indent(*this);
555 OS << "DeclarationName ";
556 {
557 ColorScope Color(*this, DeclNameColor);
558 OS << '\'' << Name << '\'';
559 }
560
561 for (DeclContextLookupResult::iterator RI = R.begin(), RE = R.end();
562 RI != RE; ++RI) {
563 if (RI + 1 == RE)
564 lastChild();
565 dumpDeclRef(*RI);
Richard Smith15fc7df2013-10-22 23:50:38 +0000566 if ((*RI)->isHidden())
567 OS << " hidden";
Richard Smith33937e72013-06-22 21:49:40 +0000568 }
569 }
570
571 if (HasUndeserializedLookups) {
572 lastChild();
573 IndentScope Indent(*this);
574 ColorScope Color(*this, UndeserializedColor);
575 OS << "<undeserialized lookups>";
576 }
577}
578
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000579void ASTDumper::dumpAttr(const Attr *A) {
580 IndentScope Indent(*this);
Richard Trieud215b8d2013-01-26 01:31:20 +0000581 {
582 ColorScope Color(*this, AttrColor);
Aaron Ballman36a53502014-01-16 13:03:14 +0000583
Richard Trieud215b8d2013-01-26 01:31:20 +0000584 switch (A->getKind()) {
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000585#define ATTR(X) case attr::X: OS << #X; break;
586#include "clang/Basic/AttrList.inc"
Richard Trieud215b8d2013-01-26 01:31:20 +0000587 default: llvm_unreachable("unexpected attribute kind");
588 }
589 OS << "Attr";
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000590 }
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000591 dumpPointer(A);
592 dumpSourceRange(A->getRange());
593#include "clang/AST/AttrDump.inc"
Aaron Ballman36a53502014-01-16 13:03:14 +0000594 if (A->isImplicit())
595 OS << " Implicit";
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000596}
597
Richard Smith71bec062013-10-15 21:58:30 +0000598static void dumpPreviousDeclImpl(raw_ostream &OS, ...) {}
599
600template<typename T>
601static void dumpPreviousDeclImpl(raw_ostream &OS, const Mergeable<T> *D) {
Rafael Espindola8db352d2013-10-17 15:37:26 +0000602 const T *First = D->getFirstDecl();
Richard Smith71bec062013-10-15 21:58:30 +0000603 if (First != D)
604 OS << " first " << First;
Richard Smithf5f43542013-02-07 01:35:44 +0000605}
606
607template<typename T>
Richard Smith71bec062013-10-15 21:58:30 +0000608static void dumpPreviousDeclImpl(raw_ostream &OS, const Redeclarable<T> *D) {
609 const T *Prev = D->getPreviousDecl();
610 if (Prev)
611 OS << " prev " << Prev;
Richard Smithf5f43542013-02-07 01:35:44 +0000612}
613
Richard Smith71bec062013-10-15 21:58:30 +0000614/// Dump the previous declaration in the redeclaration chain for a declaration,
615/// if any.
616static void dumpPreviousDecl(raw_ostream &OS, const Decl *D) {
Richard Smithf5f43542013-02-07 01:35:44 +0000617 switch (D->getKind()) {
618#define DECL(DERIVED, BASE) \
619 case Decl::DERIVED: \
Richard Smith71bec062013-10-15 21:58:30 +0000620 return dumpPreviousDeclImpl(OS, cast<DERIVED##Decl>(D));
Richard Smithf5f43542013-02-07 01:35:44 +0000621#define ABSTRACT_DECL(DECL)
622#include "clang/AST/DeclNodes.inc"
623 }
624 llvm_unreachable("Decl that isn't part of DeclNodes.inc!");
625}
626
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000627//===----------------------------------------------------------------------===//
628// C++ Utilities
629//===----------------------------------------------------------------------===//
630
631void ASTDumper::dumpAccessSpecifier(AccessSpecifier AS) {
632 switch (AS) {
633 case AS_none:
634 break;
635 case AS_public:
636 OS << "public";
637 break;
638 case AS_protected:
639 OS << "protected";
640 break;
641 case AS_private:
642 OS << "private";
643 break;
644 }
645}
646
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000647void ASTDumper::dumpCXXCtorInitializer(const CXXCtorInitializer *Init) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000648 IndentScope Indent(*this);
649 OS << "CXXCtorInitializer";
650 if (Init->isAnyMemberInitializer()) {
651 OS << ' ';
652 dumpBareDeclRef(Init->getAnyMember());
653 } else {
654 dumpType(QualType(Init->getBaseClass(), 0));
655 }
656 dumpStmt(Init->getInit());
657}
658
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000659void ASTDumper::dumpTemplateParameters(const TemplateParameterList *TPL) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000660 if (!TPL)
661 return;
662
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000663 for (TemplateParameterList::const_iterator I = TPL->begin(), E = TPL->end();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000664 I != E; ++I)
665 dumpDecl(*I);
666}
667
668void ASTDumper::dumpTemplateArgumentListInfo(
669 const TemplateArgumentListInfo &TALI) {
Richard Trieude5cc7d2013-01-31 01:44:26 +0000670 for (unsigned i = 0, e = TALI.size(); i < e; ++i) {
671 if (i + 1 == e)
672 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000673 dumpTemplateArgumentLoc(TALI[i]);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000674 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000675}
676
677void ASTDumper::dumpTemplateArgumentLoc(const TemplateArgumentLoc &A) {
678 dumpTemplateArgument(A.getArgument(), A.getSourceRange());
679}
680
681void ASTDumper::dumpTemplateArgumentList(const TemplateArgumentList &TAL) {
682 for (unsigned i = 0, e = TAL.size(); i < e; ++i)
683 dumpTemplateArgument(TAL[i]);
684}
685
686void ASTDumper::dumpTemplateArgument(const TemplateArgument &A, SourceRange R) {
687 IndentScope Indent(*this);
688 OS << "TemplateArgument";
689 if (R.isValid())
690 dumpSourceRange(R);
691
692 switch (A.getKind()) {
693 case TemplateArgument::Null:
694 OS << " null";
695 break;
696 case TemplateArgument::Type:
697 OS << " type";
Richard Trieude5cc7d2013-01-31 01:44:26 +0000698 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000699 dumpType(A.getAsType());
700 break;
701 case TemplateArgument::Declaration:
702 OS << " decl";
Richard Trieude5cc7d2013-01-31 01:44:26 +0000703 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000704 dumpDeclRef(A.getAsDecl());
705 break;
706 case TemplateArgument::NullPtr:
707 OS << " nullptr";
708 break;
709 case TemplateArgument::Integral:
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000710 OS << " integral " << A.getAsIntegral();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000711 break;
712 case TemplateArgument::Template:
713 OS << " template ";
714 A.getAsTemplate().dump(OS);
715 break;
716 case TemplateArgument::TemplateExpansion:
717 OS << " template expansion";
718 A.getAsTemplateOrTemplatePattern().dump(OS);
719 break;
720 case TemplateArgument::Expression:
721 OS << " expr";
Richard Trieude5cc7d2013-01-31 01:44:26 +0000722 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000723 dumpStmt(A.getAsExpr());
724 break;
725 case TemplateArgument::Pack:
726 OS << " pack";
727 for (TemplateArgument::pack_iterator I = A.pack_begin(), E = A.pack_end();
Richard Trieude5cc7d2013-01-31 01:44:26 +0000728 I != E; ++I) {
729 if (I + 1 == E)
730 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000731 dumpTemplateArgument(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000732 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000733 break;
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000734 }
735}
736
Chris Lattner11e30d32007-08-30 06:17:34 +0000737//===----------------------------------------------------------------------===//
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000738// Decl dumping methods.
Chris Lattnercbe4f772007-08-08 22:51:59 +0000739//===----------------------------------------------------------------------===//
740
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000741void ASTDumper::dumpDecl(const Decl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000742 IndentScope Indent(*this);
Mike Stump11289f42009-09-09 15:08:12 +0000743
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000744 if (!D) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000745 ColorScope Color(*this, NullColor);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000746 OS << "<<<NULL>>>";
747 return;
Chris Lattnercbe4f772007-08-08 22:51:59 +0000748 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000749
Richard Trieud215b8d2013-01-26 01:31:20 +0000750 {
751 ColorScope Color(*this, DeclKindNameColor);
752 OS << D->getDeclKindName() << "Decl";
753 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000754 dumpPointer(D);
Richard Smithf5f43542013-02-07 01:35:44 +0000755 if (D->getLexicalDeclContext() != D->getDeclContext())
756 OS << " parent " << cast<Decl>(D->getDeclContext());
Richard Smith71bec062013-10-15 21:58:30 +0000757 dumpPreviousDecl(OS, D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000758 dumpSourceRange(D->getSourceRange());
Richard Smith15fc7df2013-10-22 23:50:38 +0000759 if (Module *M = D->getOwningModule())
760 OS << " in " << M->getFullModuleName();
761 if (const NamedDecl *ND = dyn_cast<NamedDecl>(D))
762 if (ND->isHidden())
763 OS << " hidden";
Richard Trieude5cc7d2013-01-31 01:44:26 +0000764
Aaron Ballman7dce1a82014-03-07 13:13:38 +0000765 bool HasAttrs = D->attr_begin() != D->attr_end();
Richard Smithb39b9d52013-05-21 05:24:00 +0000766 const FullComment *Comment =
767 D->getASTContext().getLocalCommentForDeclUncached(D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000768 // Decls within functions are visited by the body
Richard Trieude5cc7d2013-01-31 01:44:26 +0000769 bool HasDeclContext = !isa<FunctionDecl>(*D) && !isa<ObjCMethodDecl>(*D) &&
770 hasNodes(dyn_cast<DeclContext>(D));
771
Richard Smithb39b9d52013-05-21 05:24:00 +0000772 setMoreChildren(HasAttrs || Comment || HasDeclContext);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000773 ConstDeclVisitor<ASTDumper>::Visit(D);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000774
Richard Smithb39b9d52013-05-21 05:24:00 +0000775 setMoreChildren(Comment || HasDeclContext);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000776 for (Decl::attr_iterator I = D->attr_begin(), E = D->attr_end();
777 I != E; ++I) {
778 if (I + 1 == E)
779 lastChild();
780 dumpAttr(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000781 }
782
783 setMoreChildren(HasDeclContext);
784 lastChild();
Richard Smithb39b9d52013-05-21 05:24:00 +0000785 dumpFullComment(Comment);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000786
Nick Lewyckya382db02013-08-27 03:15:56 +0000787 if (D->isInvalidDecl())
788 OS << " invalid";
789
Richard Trieude5cc7d2013-01-31 01:44:26 +0000790 setMoreChildren(false);
791 if (HasDeclContext)
Richard Smithf5f43542013-02-07 01:35:44 +0000792 dumpDeclContext(cast<DeclContext>(D));
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000793}
794
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000795void ASTDumper::VisitLabelDecl(const LabelDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000796 dumpName(D);
797}
798
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000799void ASTDumper::VisitTypedefDecl(const TypedefDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000800 dumpName(D);
801 dumpType(D->getUnderlyingType());
802 if (D->isModulePrivate())
803 OS << " __module_private__";
804}
805
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000806void ASTDumper::VisitEnumDecl(const EnumDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000807 if (D->isScoped()) {
808 if (D->isScopedUsingClassTag())
809 OS << " class";
810 else
811 OS << " struct";
812 }
813 dumpName(D);
814 if (D->isModulePrivate())
815 OS << " __module_private__";
816 if (D->isFixed())
817 dumpType(D->getIntegerType());
818}
819
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000820void ASTDumper::VisitRecordDecl(const RecordDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000821 OS << ' ' << D->getKindName();
822 dumpName(D);
823 if (D->isModulePrivate())
824 OS << " __module_private__";
Richard Smith99bc1b92013-08-30 05:32:29 +0000825 if (D->isCompleteDefinition())
826 OS << " definition";
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000827}
828
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000829void ASTDumper::VisitEnumConstantDecl(const EnumConstantDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000830 dumpName(D);
831 dumpType(D->getType());
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000832 if (const Expr *Init = D->getInitExpr()) {
Richard Trieude5cc7d2013-01-31 01:44:26 +0000833 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000834 dumpStmt(Init);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000835 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000836}
837
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000838void ASTDumper::VisitIndirectFieldDecl(const IndirectFieldDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000839 dumpName(D);
840 dumpType(D->getType());
841 for (IndirectFieldDecl::chain_iterator I = D->chain_begin(),
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000842 E = D->chain_end();
843 I != E; ++I) {
Richard Trieude5cc7d2013-01-31 01:44:26 +0000844 if (I + 1 == E)
845 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000846 dumpDeclRef(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000847 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000848}
849
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000850void ASTDumper::VisitFunctionDecl(const FunctionDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000851 dumpName(D);
852 dumpType(D->getType());
853
Rafael Espindola6ae7e502013-04-03 19:27:57 +0000854 StorageClass SC = D->getStorageClass();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000855 if (SC != SC_None)
856 OS << ' ' << VarDecl::getStorageClassSpecifierString(SC);
857 if (D->isInlineSpecified())
858 OS << " inline";
859 if (D->isVirtualAsWritten())
860 OS << " virtual";
861 if (D->isModulePrivate())
862 OS << " __module_private__";
863
864 if (D->isPure())
865 OS << " pure";
866 else if (D->isDeletedAsWritten())
867 OS << " delete";
868
Richard Smithadaa0152013-05-17 02:09:46 +0000869 if (const FunctionProtoType *FPT = D->getType()->getAs<FunctionProtoType>()) {
870 FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo();
871 switch (EPI.ExceptionSpecType) {
872 default: break;
873 case EST_Unevaluated:
874 OS << " noexcept-unevaluated " << EPI.ExceptionSpecDecl;
875 break;
876 case EST_Uninstantiated:
877 OS << " noexcept-uninstantiated " << EPI.ExceptionSpecTemplate;
878 break;
879 }
880 }
881
Richard Trieude5cc7d2013-01-31 01:44:26 +0000882 bool OldMoreChildren = hasMoreChildren();
883 const FunctionTemplateSpecializationInfo *FTSI =
884 D->getTemplateSpecializationInfo();
885 bool HasTemplateSpecialization = FTSI;
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000886
Richard Trieude5cc7d2013-01-31 01:44:26 +0000887 bool HasNamedDecls = D->getDeclsInPrototypeScope().begin() !=
888 D->getDeclsInPrototypeScope().end();
889
890 bool HasFunctionDecls = D->param_begin() != D->param_end();
891
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000892 const CXXConstructorDecl *C = dyn_cast<CXXConstructorDecl>(D);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000893 bool HasCtorInitializers = C && C->init_begin() != C->init_end();
894
895 bool HasDeclarationBody = D->doesThisDeclarationHaveABody();
896
897 setMoreChildren(OldMoreChildren || HasNamedDecls || HasFunctionDecls ||
898 HasCtorInitializers || HasDeclarationBody);
899 if (HasTemplateSpecialization) {
900 lastChild();
901 dumpTemplateArgumentList(*FTSI->TemplateArguments);
902 }
903
904 setMoreChildren(OldMoreChildren || HasFunctionDecls ||
905 HasCtorInitializers || HasDeclarationBody);
Dmitri Gribenkof8579502013-01-12 19:30:44 +0000906 for (ArrayRef<NamedDecl *>::iterator
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000907 I = D->getDeclsInPrototypeScope().begin(),
Richard Trieude5cc7d2013-01-31 01:44:26 +0000908 E = D->getDeclsInPrototypeScope().end(); I != E; ++I) {
909 if (I + 1 == E)
910 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000911 dumpDecl(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000912 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000913
Richard Trieude5cc7d2013-01-31 01:44:26 +0000914 setMoreChildren(OldMoreChildren || HasCtorInitializers || HasDeclarationBody);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000915 for (FunctionDecl::param_const_iterator I = D->param_begin(),
916 E = D->param_end();
Richard Trieude5cc7d2013-01-31 01:44:26 +0000917 I != E; ++I) {
918 if (I + 1 == E)
919 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000920 dumpDecl(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000921 }
922
923 setMoreChildren(OldMoreChildren || HasDeclarationBody);
924 if (HasCtorInitializers)
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000925 for (CXXConstructorDecl::init_const_iterator I = C->init_begin(),
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000926 E = C->init_end();
927 I != E; ++I) {
Richard Trieude5cc7d2013-01-31 01:44:26 +0000928 if (I + 1 == E)
929 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000930 dumpCXXCtorInitializer(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000931 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000932
Richard Trieude5cc7d2013-01-31 01:44:26 +0000933 setMoreChildren(OldMoreChildren);
934 if (HasDeclarationBody) {
935 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000936 dumpStmt(D->getBody());
Richard Trieude5cc7d2013-01-31 01:44:26 +0000937 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000938}
939
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000940void ASTDumper::VisitFieldDecl(const FieldDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000941 dumpName(D);
942 dumpType(D->getType());
943 if (D->isMutable())
944 OS << " mutable";
945 if (D->isModulePrivate())
946 OS << " __module_private__";
Richard Trieude5cc7d2013-01-31 01:44:26 +0000947
948 bool OldMoreChildren = hasMoreChildren();
949 bool IsBitField = D->isBitField();
950 Expr *Init = D->getInClassInitializer();
951 bool HasInit = Init;
952
953 setMoreChildren(OldMoreChildren || HasInit);
954 if (IsBitField) {
955 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000956 dumpStmt(D->getBitWidth());
Richard Trieude5cc7d2013-01-31 01:44:26 +0000957 }
958 setMoreChildren(OldMoreChildren);
959 if (HasInit) {
960 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000961 dumpStmt(Init);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000962 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000963}
964
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000965void ASTDumper::VisitVarDecl(const VarDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000966 dumpName(D);
967 dumpType(D->getType());
Rafael Espindola6ae7e502013-04-03 19:27:57 +0000968 StorageClass SC = D->getStorageClass();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000969 if (SC != SC_None)
970 OS << ' ' << VarDecl::getStorageClassSpecifierString(SC);
Richard Smithfd3834f2013-04-13 02:43:54 +0000971 switch (D->getTLSKind()) {
972 case VarDecl::TLS_None: break;
973 case VarDecl::TLS_Static: OS << " tls"; break;
974 case VarDecl::TLS_Dynamic: OS << " tls_dynamic"; break;
975 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000976 if (D->isModulePrivate())
977 OS << " __module_private__";
978 if (D->isNRVOVariable())
979 OS << " nrvo";
Richard Trieude5cc7d2013-01-31 01:44:26 +0000980 if (D->hasInit()) {
981 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000982 dumpStmt(D->getInit());
Richard Trieude5cc7d2013-01-31 01:44:26 +0000983 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000984}
985
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000986void ASTDumper::VisitFileScopeAsmDecl(const FileScopeAsmDecl *D) {
Richard Trieude5cc7d2013-01-31 01:44:26 +0000987 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000988 dumpStmt(D->getAsmString());
989}
990
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000991void ASTDumper::VisitImportDecl(const ImportDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000992 OS << ' ' << D->getImportedModule()->getFullModuleName();
993}
994
995//===----------------------------------------------------------------------===//
996// C++ Declarations
997//===----------------------------------------------------------------------===//
998
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000999void ASTDumper::VisitNamespaceDecl(const NamespaceDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001000 dumpName(D);
1001 if (D->isInline())
1002 OS << " inline";
1003 if (!D->isOriginalNamespace())
1004 dumpDeclRef(D->getOriginalNamespace(), "original");
1005}
1006
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001007void ASTDumper::VisitUsingDirectiveDecl(const UsingDirectiveDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001008 OS << ' ';
1009 dumpBareDeclRef(D->getNominatedNamespace());
1010}
1011
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001012void ASTDumper::VisitNamespaceAliasDecl(const NamespaceAliasDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001013 dumpName(D);
1014 dumpDeclRef(D->getAliasedNamespace());
1015}
1016
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001017void ASTDumper::VisitTypeAliasDecl(const TypeAliasDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001018 dumpName(D);
1019 dumpType(D->getUnderlyingType());
1020}
1021
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001022void ASTDumper::VisitTypeAliasTemplateDecl(const TypeAliasTemplateDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001023 dumpName(D);
1024 dumpTemplateParameters(D->getTemplateParameters());
1025 dumpDecl(D->getTemplatedDecl());
1026}
1027
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001028void ASTDumper::VisitCXXRecordDecl(const CXXRecordDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001029 VisitRecordDecl(D);
1030 if (!D->isCompleteDefinition())
1031 return;
1032
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001033 for (CXXRecordDecl::base_class_const_iterator I = D->bases_begin(),
1034 E = D->bases_end();
1035 I != E; ++I) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001036 IndentScope Indent(*this);
1037 if (I->isVirtual())
1038 OS << "virtual ";
1039 dumpAccessSpecifier(I->getAccessSpecifier());
1040 dumpType(I->getType());
1041 if (I->isPackExpansion())
1042 OS << "...";
1043 }
1044}
1045
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001046void ASTDumper::VisitStaticAssertDecl(const StaticAssertDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001047 dumpStmt(D->getAssertExpr());
Richard Trieude5cc7d2013-01-31 01:44:26 +00001048 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001049 dumpStmt(D->getMessage());
1050}
1051
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001052void ASTDumper::VisitFunctionTemplateDecl(const FunctionTemplateDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001053 dumpName(D);
1054 dumpTemplateParameters(D->getTemplateParameters());
1055 dumpDecl(D->getTemplatedDecl());
Dmitri Gribenko81f25752013-02-14 13:20:36 +00001056 for (FunctionTemplateDecl::spec_iterator I = D->spec_begin(),
1057 E = D->spec_end();
1058 I != E; ++I) {
Richard Trieude5cc7d2013-01-31 01:44:26 +00001059 FunctionTemplateDecl::spec_iterator Next = I;
1060 ++Next;
1061 if (Next == E)
1062 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001063 switch (I->getTemplateSpecializationKind()) {
1064 case TSK_Undeclared:
1065 case TSK_ImplicitInstantiation:
1066 case TSK_ExplicitInstantiationDeclaration:
1067 case TSK_ExplicitInstantiationDefinition:
Dmitri Gribenkoefc6dfb2013-02-21 22:01:10 +00001068 if (D == D->getCanonicalDecl())
1069 dumpDecl(*I);
1070 else
1071 dumpDeclRef(*I);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001072 break;
1073 case TSK_ExplicitSpecialization:
1074 dumpDeclRef(*I);
1075 break;
1076 }
1077 }
1078}
1079
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001080void ASTDumper::VisitClassTemplateDecl(const ClassTemplateDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001081 dumpName(D);
1082 dumpTemplateParameters(D->getTemplateParameters());
Richard Trieude5cc7d2013-01-31 01:44:26 +00001083
Dmitri Gribenko81f25752013-02-14 13:20:36 +00001084 ClassTemplateDecl::spec_iterator I = D->spec_begin();
1085 ClassTemplateDecl::spec_iterator E = D->spec_end();
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001086 if (I == E)
Richard Trieude5cc7d2013-01-31 01:44:26 +00001087 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001088 dumpDecl(D->getTemplatedDecl());
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001089 for (; I != E; ++I) {
Richard Trieude5cc7d2013-01-31 01:44:26 +00001090 ClassTemplateDecl::spec_iterator Next = I;
1091 ++Next;
1092 if (Next == E)
1093 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001094 switch (I->getTemplateSpecializationKind()) {
1095 case TSK_Undeclared:
1096 case TSK_ImplicitInstantiation:
Dmitri Gribenkoefc6dfb2013-02-21 22:01:10 +00001097 if (D == D->getCanonicalDecl())
1098 dumpDecl(*I);
1099 else
1100 dumpDeclRef(*I);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001101 break;
1102 case TSK_ExplicitSpecialization:
1103 case TSK_ExplicitInstantiationDeclaration:
1104 case TSK_ExplicitInstantiationDefinition:
1105 dumpDeclRef(*I);
1106 break;
1107 }
1108 }
1109}
1110
1111void ASTDumper::VisitClassTemplateSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001112 const ClassTemplateSpecializationDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001113 VisitCXXRecordDecl(D);
1114 dumpTemplateArgumentList(D->getTemplateArgs());
1115}
1116
1117void ASTDumper::VisitClassTemplatePartialSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001118 const ClassTemplatePartialSpecializationDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001119 VisitClassTemplateSpecializationDecl(D);
1120 dumpTemplateParameters(D->getTemplateParameters());
1121}
1122
1123void ASTDumper::VisitClassScopeFunctionSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001124 const ClassScopeFunctionSpecializationDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001125 dumpDeclRef(D->getSpecialization());
1126 if (D->hasExplicitTemplateArgs())
1127 dumpTemplateArgumentListInfo(D->templateArgs());
1128}
1129
Richard Smithd25789a2013-09-18 01:36:02 +00001130void ASTDumper::VisitVarTemplateDecl(const VarTemplateDecl *D) {
1131 dumpName(D);
1132 dumpTemplateParameters(D->getTemplateParameters());
1133
1134 VarTemplateDecl::spec_iterator I = D->spec_begin();
1135 VarTemplateDecl::spec_iterator E = D->spec_end();
1136 if (I == E)
1137 lastChild();
1138 dumpDecl(D->getTemplatedDecl());
1139 for (; I != E; ++I) {
1140 VarTemplateDecl::spec_iterator Next = I;
1141 ++Next;
1142 if (Next == E)
1143 lastChild();
1144 switch (I->getTemplateSpecializationKind()) {
1145 case TSK_Undeclared:
1146 case TSK_ImplicitInstantiation:
1147 if (D == D->getCanonicalDecl())
1148 dumpDecl(*I);
1149 else
1150 dumpDeclRef(*I);
1151 break;
1152 case TSK_ExplicitSpecialization:
1153 case TSK_ExplicitInstantiationDeclaration:
1154 case TSK_ExplicitInstantiationDefinition:
1155 dumpDeclRef(*I);
1156 break;
1157 }
1158 }
1159}
1160
1161void ASTDumper::VisitVarTemplateSpecializationDecl(
1162 const VarTemplateSpecializationDecl *D) {
1163 dumpTemplateArgumentList(D->getTemplateArgs());
1164 VisitVarDecl(D);
1165}
1166
1167void ASTDumper::VisitVarTemplatePartialSpecializationDecl(
1168 const VarTemplatePartialSpecializationDecl *D) {
1169 dumpTemplateParameters(D->getTemplateParameters());
1170 VisitVarTemplateSpecializationDecl(D);
1171}
1172
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001173void ASTDumper::VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001174 if (D->wasDeclaredWithTypename())
1175 OS << " typename";
1176 else
1177 OS << " class";
1178 if (D->isParameterPack())
1179 OS << " ...";
1180 dumpName(D);
1181 if (D->hasDefaultArgument())
1182 dumpType(D->getDefaultArgument());
1183}
1184
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001185void ASTDumper::VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001186 dumpType(D->getType());
1187 if (D->isParameterPack())
1188 OS << " ...";
1189 dumpName(D);
1190 if (D->hasDefaultArgument())
1191 dumpStmt(D->getDefaultArgument());
1192}
1193
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001194void ASTDumper::VisitTemplateTemplateParmDecl(
1195 const TemplateTemplateParmDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001196 if (D->isParameterPack())
1197 OS << " ...";
1198 dumpName(D);
1199 dumpTemplateParameters(D->getTemplateParameters());
1200 if (D->hasDefaultArgument())
1201 dumpTemplateArgumentLoc(D->getDefaultArgument());
1202}
1203
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001204void ASTDumper::VisitUsingDecl(const UsingDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001205 OS << ' ';
1206 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
1207 OS << D->getNameAsString();
1208}
1209
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001210void ASTDumper::VisitUnresolvedUsingTypenameDecl(
1211 const UnresolvedUsingTypenameDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001212 OS << ' ';
1213 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
1214 OS << D->getNameAsString();
1215}
1216
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001217void ASTDumper::VisitUnresolvedUsingValueDecl(const UnresolvedUsingValueDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001218 OS << ' ';
1219 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
1220 OS << D->getNameAsString();
1221 dumpType(D->getType());
1222}
1223
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001224void ASTDumper::VisitUsingShadowDecl(const UsingShadowDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001225 OS << ' ';
1226 dumpBareDeclRef(D->getTargetDecl());
1227}
1228
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001229void ASTDumper::VisitLinkageSpecDecl(const LinkageSpecDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001230 switch (D->getLanguage()) {
1231 case LinkageSpecDecl::lang_c: OS << " C"; break;
1232 case LinkageSpecDecl::lang_cxx: OS << " C++"; break;
1233 }
1234}
1235
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001236void ASTDumper::VisitAccessSpecDecl(const AccessSpecDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001237 OS << ' ';
1238 dumpAccessSpecifier(D->getAccess());
1239}
1240
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001241void ASTDumper::VisitFriendDecl(const FriendDecl *D) {
Richard Smithf5f43542013-02-07 01:35:44 +00001242 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001243 if (TypeSourceInfo *T = D->getFriendType())
1244 dumpType(T->getType());
1245 else
1246 dumpDecl(D->getFriendDecl());
1247}
1248
1249//===----------------------------------------------------------------------===//
1250// Obj-C Declarations
1251//===----------------------------------------------------------------------===//
1252
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001253void ASTDumper::VisitObjCIvarDecl(const ObjCIvarDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001254 dumpName(D);
1255 dumpType(D->getType());
1256 if (D->getSynthesize())
1257 OS << " synthesize";
1258
1259 switch (D->getAccessControl()) {
1260 case ObjCIvarDecl::None:
1261 OS << " none";
1262 break;
1263 case ObjCIvarDecl::Private:
1264 OS << " private";
1265 break;
1266 case ObjCIvarDecl::Protected:
1267 OS << " protected";
1268 break;
1269 case ObjCIvarDecl::Public:
1270 OS << " public";
1271 break;
1272 case ObjCIvarDecl::Package:
1273 OS << " package";
1274 break;
1275 }
1276}
1277
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001278void ASTDumper::VisitObjCMethodDecl(const ObjCMethodDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001279 if (D->isInstanceMethod())
1280 OS << " -";
1281 else
1282 OS << " +";
1283 dumpName(D);
Alp Toker314cc812014-01-25 16:55:45 +00001284 dumpType(D->getReturnType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001285
Richard Trieude5cc7d2013-01-31 01:44:26 +00001286 bool OldMoreChildren = hasMoreChildren();
1287 bool IsVariadic = D->isVariadic();
1288 bool HasBody = D->hasBody();
1289
1290 setMoreChildren(OldMoreChildren || IsVariadic || HasBody);
1291 if (D->isThisDeclarationADefinition()) {
1292 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001293 dumpDeclContext(D);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001294 } else {
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001295 for (ObjCMethodDecl::param_const_iterator I = D->param_begin(),
1296 E = D->param_end();
1297 I != E; ++I) {
Richard Trieude5cc7d2013-01-31 01:44:26 +00001298 if (I + 1 == E)
1299 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001300 dumpDecl(*I);
1301 }
1302 }
1303
Richard Trieude5cc7d2013-01-31 01:44:26 +00001304 setMoreChildren(OldMoreChildren || HasBody);
1305 if (IsVariadic) {
1306 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001307 IndentScope Indent(*this);
1308 OS << "...";
1309 }
1310
Richard Trieude5cc7d2013-01-31 01:44:26 +00001311 setMoreChildren(OldMoreChildren);
1312 if (HasBody) {
1313 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001314 dumpStmt(D->getBody());
Richard Trieude5cc7d2013-01-31 01:44:26 +00001315 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001316}
1317
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001318void ASTDumper::VisitObjCCategoryDecl(const ObjCCategoryDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001319 dumpName(D);
1320 dumpDeclRef(D->getClassInterface());
Richard Trieude5cc7d2013-01-31 01:44:26 +00001321 if (D->protocol_begin() == D->protocol_end())
1322 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001323 dumpDeclRef(D->getImplementation());
1324 for (ObjCCategoryDecl::protocol_iterator I = D->protocol_begin(),
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001325 E = D->protocol_end();
1326 I != E; ++I) {
Richard Trieude5cc7d2013-01-31 01:44:26 +00001327 if (I + 1 == E)
1328 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001329 dumpDeclRef(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001330 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001331}
1332
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001333void ASTDumper::VisitObjCCategoryImplDecl(const ObjCCategoryImplDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001334 dumpName(D);
1335 dumpDeclRef(D->getClassInterface());
Richard Trieude5cc7d2013-01-31 01:44:26 +00001336 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001337 dumpDeclRef(D->getCategoryDecl());
1338}
1339
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001340void ASTDumper::VisitObjCProtocolDecl(const ObjCProtocolDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001341 dumpName(D);
1342 for (ObjCProtocolDecl::protocol_iterator I = D->protocol_begin(),
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001343 E = D->protocol_end();
1344 I != E; ++I) {
Richard Trieude5cc7d2013-01-31 01:44:26 +00001345 if (I + 1 == E)
1346 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001347 dumpDeclRef(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001348 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001349}
1350
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001351void ASTDumper::VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001352 dumpName(D);
1353 dumpDeclRef(D->getSuperClass(), "super");
Richard Trieude5cc7d2013-01-31 01:44:26 +00001354 if (D->protocol_begin() == D->protocol_end())
1355 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001356 dumpDeclRef(D->getImplementation());
1357 for (ObjCInterfaceDecl::protocol_iterator I = D->protocol_begin(),
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001358 E = D->protocol_end();
1359 I != E; ++I) {
Richard Trieude5cc7d2013-01-31 01:44:26 +00001360 if (I + 1 == E)
1361 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001362 dumpDeclRef(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001363 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001364}
1365
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001366void ASTDumper::VisitObjCImplementationDecl(const ObjCImplementationDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001367 dumpName(D);
1368 dumpDeclRef(D->getSuperClass(), "super");
Richard Trieude5cc7d2013-01-31 01:44:26 +00001369 if (D->init_begin() == D->init_end())
1370 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001371 dumpDeclRef(D->getClassInterface());
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001372 for (ObjCImplementationDecl::init_const_iterator I = D->init_begin(),
1373 E = D->init_end();
1374 I != E; ++I) {
Richard Trieude5cc7d2013-01-31 01:44:26 +00001375 if (I + 1 == E)
1376 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001377 dumpCXXCtorInitializer(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001378 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001379}
1380
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001381void ASTDumper::VisitObjCCompatibleAliasDecl(const ObjCCompatibleAliasDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001382 dumpName(D);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001383 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001384 dumpDeclRef(D->getClassInterface());
1385}
1386
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001387void ASTDumper::VisitObjCPropertyDecl(const ObjCPropertyDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001388 dumpName(D);
1389 dumpType(D->getType());
1390
1391 if (D->getPropertyImplementation() == ObjCPropertyDecl::Required)
1392 OS << " required";
1393 else if (D->getPropertyImplementation() == ObjCPropertyDecl::Optional)
1394 OS << " optional";
1395
1396 ObjCPropertyDecl::PropertyAttributeKind Attrs = D->getPropertyAttributes();
1397 if (Attrs != ObjCPropertyDecl::OBJC_PR_noattr) {
1398 if (Attrs & ObjCPropertyDecl::OBJC_PR_readonly)
1399 OS << " readonly";
1400 if (Attrs & ObjCPropertyDecl::OBJC_PR_assign)
1401 OS << " assign";
1402 if (Attrs & ObjCPropertyDecl::OBJC_PR_readwrite)
1403 OS << " readwrite";
1404 if (Attrs & ObjCPropertyDecl::OBJC_PR_retain)
1405 OS << " retain";
1406 if (Attrs & ObjCPropertyDecl::OBJC_PR_copy)
1407 OS << " copy";
1408 if (Attrs & ObjCPropertyDecl::OBJC_PR_nonatomic)
1409 OS << " nonatomic";
1410 if (Attrs & ObjCPropertyDecl::OBJC_PR_atomic)
1411 OS << " atomic";
1412 if (Attrs & ObjCPropertyDecl::OBJC_PR_weak)
1413 OS << " weak";
1414 if (Attrs & ObjCPropertyDecl::OBJC_PR_strong)
1415 OS << " strong";
1416 if (Attrs & ObjCPropertyDecl::OBJC_PR_unsafe_unretained)
1417 OS << " unsafe_unretained";
Richard Trieude5cc7d2013-01-31 01:44:26 +00001418 if (Attrs & ObjCPropertyDecl::OBJC_PR_getter) {
1419 if (!(Attrs & ObjCPropertyDecl::OBJC_PR_setter))
1420 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001421 dumpDeclRef(D->getGetterMethodDecl(), "getter");
Richard Trieude5cc7d2013-01-31 01:44:26 +00001422 }
1423 if (Attrs & ObjCPropertyDecl::OBJC_PR_setter) {
1424 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001425 dumpDeclRef(D->getSetterMethodDecl(), "setter");
Richard Trieude5cc7d2013-01-31 01:44:26 +00001426 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001427 }
1428}
1429
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001430void ASTDumper::VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001431 dumpName(D->getPropertyDecl());
1432 if (D->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize)
1433 OS << " synthesize";
1434 else
1435 OS << " dynamic";
1436 dumpDeclRef(D->getPropertyDecl());
Richard Trieude5cc7d2013-01-31 01:44:26 +00001437 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001438 dumpDeclRef(D->getPropertyIvarDecl());
1439}
1440
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001441void ASTDumper::VisitBlockDecl(const BlockDecl *D) {
Aaron Ballmanb2b8b1d2014-03-07 16:09:59 +00001442 for (auto I : D->params())
1443 dumpDecl(I);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001444
1445 if (D->isVariadic()) {
1446 IndentScope Indent(*this);
1447 OS << "...";
1448 }
1449
1450 if (D->capturesCXXThis()) {
1451 IndentScope Indent(*this);
1452 OS << "capture this";
1453 }
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001454 for (BlockDecl::capture_iterator I = D->capture_begin(), E = D->capture_end();
1455 I != E; ++I) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001456 IndentScope Indent(*this);
1457 OS << "capture";
1458 if (I->isByRef())
1459 OS << " byref";
1460 if (I->isNested())
1461 OS << " nested";
1462 if (I->getVariable()) {
1463 OS << ' ';
1464 dumpBareDeclRef(I->getVariable());
1465 }
1466 if (I->hasCopyExpr())
1467 dumpStmt(I->getCopyExpr());
1468 }
Richard Trieude5cc7d2013-01-31 01:44:26 +00001469 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001470 dumpStmt(D->getBody());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001471}
1472
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001473//===----------------------------------------------------------------------===//
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001474// Stmt dumping methods.
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001475//===----------------------------------------------------------------------===//
1476
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001477void ASTDumper::dumpStmt(const Stmt *S) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001478 IndentScope Indent(*this);
1479
1480 if (!S) {
Richard Trieud215b8d2013-01-26 01:31:20 +00001481 ColorScope Color(*this, NullColor);
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001482 OS << "<<<NULL>>>";
1483 return;
1484 }
1485
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001486 if (const DeclStmt *DS = dyn_cast<DeclStmt>(S)) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001487 VisitDeclStmt(DS);
1488 return;
1489 }
1490
David Blaikie7d170102013-05-15 07:37:26 +00001491 setMoreChildren(!S->children().empty());
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001492 ConstStmtVisitor<ASTDumper>::Visit(S);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001493 setMoreChildren(false);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001494 for (Stmt::const_child_range CI = S->children(); CI; ++CI) {
1495 Stmt::const_child_range Next = CI;
Richard Trieude5cc7d2013-01-31 01:44:26 +00001496 ++Next;
1497 if (!Next)
1498 lastChild();
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001499 dumpStmt(*CI);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001500 }
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001501}
1502
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001503void ASTDumper::VisitStmt(const Stmt *Node) {
Richard Trieud215b8d2013-01-26 01:31:20 +00001504 {
1505 ColorScope Color(*this, StmtColor);
1506 OS << Node->getStmtClassName();
1507 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001508 dumpPointer(Node);
1509 dumpSourceRange(Node->getSourceRange());
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001510}
1511
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001512void ASTDumper::VisitDeclStmt(const DeclStmt *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001513 VisitStmt(Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001514 for (DeclStmt::const_decl_iterator I = Node->decl_begin(),
1515 E = Node->decl_end();
Richard Trieude5cc7d2013-01-31 01:44:26 +00001516 I != E; ++I) {
1517 if (I + 1 == E)
1518 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001519 dumpDecl(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001520 }
Ted Kremenek433a4922007-12-12 06:59:42 +00001521}
1522
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001523void ASTDumper::VisitAttributedStmt(const AttributedStmt *Node) {
Alexander Kornienko5bc364e2013-01-07 17:53:08 +00001524 VisitStmt(Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001525 for (ArrayRef<const Attr *>::iterator I = Node->getAttrs().begin(),
1526 E = Node->getAttrs().end();
1527 I != E; ++I) {
Richard Trieude5cc7d2013-01-31 01:44:26 +00001528 if (I + 1 == E)
1529 lastChild();
Alexander Kornienko5bc364e2013-01-07 17:53:08 +00001530 dumpAttr(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001531 }
Alexander Kornienko5bc364e2013-01-07 17:53:08 +00001532}
1533
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001534void ASTDumper::VisitLabelStmt(const LabelStmt *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001535 VisitStmt(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001536 OS << " '" << Node->getName() << "'";
Chris Lattnercbe4f772007-08-08 22:51:59 +00001537}
1538
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001539void ASTDumper::VisitGotoStmt(const GotoStmt *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001540 VisitStmt(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001541 OS << " '" << Node->getLabel()->getName() << "'";
1542 dumpPointer(Node->getLabel());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001543}
1544
Pavel Labath1ef83422013-09-04 14:35:00 +00001545void ASTDumper::VisitCXXCatchStmt(const CXXCatchStmt *Node) {
1546 VisitStmt(Node);
1547 dumpDecl(Node->getExceptionDecl());
1548}
1549
Chris Lattnercbe4f772007-08-08 22:51:59 +00001550//===----------------------------------------------------------------------===//
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001551// Expr dumping methods.
Chris Lattnercbe4f772007-08-08 22:51:59 +00001552//===----------------------------------------------------------------------===//
1553
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001554void ASTDumper::VisitExpr(const Expr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001555 VisitStmt(Node);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001556 dumpType(Node->getType());
1557
Richard Trieud215b8d2013-01-26 01:31:20 +00001558 {
1559 ColorScope Color(*this, ValueKindColor);
1560 switch (Node->getValueKind()) {
1561 case VK_RValue:
1562 break;
1563 case VK_LValue:
1564 OS << " lvalue";
1565 break;
1566 case VK_XValue:
1567 OS << " xvalue";
1568 break;
1569 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001570 }
1571
Richard Trieud215b8d2013-01-26 01:31:20 +00001572 {
1573 ColorScope Color(*this, ObjectKindColor);
1574 switch (Node->getObjectKind()) {
1575 case OK_Ordinary:
1576 break;
1577 case OK_BitField:
1578 OS << " bitfield";
1579 break;
1580 case OK_ObjCProperty:
1581 OS << " objcproperty";
1582 break;
1583 case OK_ObjCSubscript:
1584 OS << " objcsubscript";
1585 break;
1586 case OK_VectorComponent:
1587 OS << " vectorcomponent";
1588 break;
1589 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001590 }
Chris Lattnercbe4f772007-08-08 22:51:59 +00001591}
1592
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001593static void dumpBasePath(raw_ostream &OS, const CastExpr *Node) {
John McCallcf142162010-08-07 06:22:56 +00001594 if (Node->path_empty())
Anders Carlssona70cff62010-04-24 19:06:50 +00001595 return;
1596
1597 OS << " (";
1598 bool First = true;
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001599 for (CastExpr::path_const_iterator I = Node->path_begin(),
1600 E = Node->path_end();
1601 I != E; ++I) {
Anders Carlssona70cff62010-04-24 19:06:50 +00001602 const CXXBaseSpecifier *Base = *I;
1603 if (!First)
1604 OS << " -> ";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001605
Anders Carlssona70cff62010-04-24 19:06:50 +00001606 const CXXRecordDecl *RD =
1607 cast<CXXRecordDecl>(Base->getType()->getAs<RecordType>()->getDecl());
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001608
Anders Carlssona70cff62010-04-24 19:06:50 +00001609 if (Base->isVirtual())
1610 OS << "virtual ";
1611 OS << RD->getName();
1612 First = false;
1613 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001614
Anders Carlssona70cff62010-04-24 19:06:50 +00001615 OS << ')';
1616}
1617
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001618void ASTDumper::VisitCastExpr(const CastExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001619 VisitExpr(Node);
Richard Trieud215b8d2013-01-26 01:31:20 +00001620 OS << " <";
1621 {
1622 ColorScope Color(*this, CastColor);
1623 OS << Node->getCastKindName();
1624 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001625 dumpBasePath(OS, Node);
Anders Carlssona70cff62010-04-24 19:06:50 +00001626 OS << ">";
Anders Carlssond7923c62009-08-22 23:33:40 +00001627}
1628
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001629void ASTDumper::VisitDeclRefExpr(const DeclRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001630 VisitExpr(Node);
Ted Kremenek5f64ca82007-09-10 17:32:55 +00001631
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001632 OS << " ";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001633 dumpBareDeclRef(Node->getDecl());
Chandler Carruth8d26bb02011-05-01 23:48:14 +00001634 if (Node->getDecl() != Node->getFoundDecl()) {
1635 OS << " (";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001636 dumpBareDeclRef(Node->getFoundDecl());
Chandler Carruth8d26bb02011-05-01 23:48:14 +00001637 OS << ")";
1638 }
John McCall351762c2011-02-07 10:33:21 +00001639}
1640
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001641void ASTDumper::VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001642 VisitExpr(Node);
John McCall76d09942009-12-11 21:50:11 +00001643 OS << " (";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001644 if (!Node->requiresADL())
1645 OS << "no ";
Benjamin Kramerb11416d2010-04-17 09:33:03 +00001646 OS << "ADL) = '" << Node->getName() << '\'';
John McCall76d09942009-12-11 21:50:11 +00001647
1648 UnresolvedLookupExpr::decls_iterator
1649 I = Node->decls_begin(), E = Node->decls_end();
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001650 if (I == E)
1651 OS << " empty";
John McCall76d09942009-12-11 21:50:11 +00001652 for (; I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001653 dumpPointer(*I);
John McCall76d09942009-12-11 21:50:11 +00001654}
1655
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001656void ASTDumper::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001657 VisitExpr(Node);
Steve Naroff5d5efca2008-03-12 13:19:12 +00001658
Richard Trieud215b8d2013-01-26 01:31:20 +00001659 {
1660 ColorScope Color(*this, DeclKindNameColor);
1661 OS << " " << Node->getDecl()->getDeclKindName() << "Decl";
1662 }
1663 OS << "='" << *Node->getDecl() << "'";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001664 dumpPointer(Node->getDecl());
Steve Naroffb3424a92008-05-23 22:01:24 +00001665 if (Node->isFreeIvar())
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001666 OS << " isFreeIvar";
Steve Naroff5d5efca2008-03-12 13:19:12 +00001667}
1668
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001669void ASTDumper::VisitPredefinedExpr(const PredefinedExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001670 VisitExpr(Node);
Chris Lattnercbe4f772007-08-08 22:51:59 +00001671 switch (Node->getIdentType()) {
David Blaikie83d382b2011-09-23 05:06:16 +00001672 default: llvm_unreachable("unknown case");
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001673 case PredefinedExpr::Func: OS << " __func__"; break;
1674 case PredefinedExpr::Function: OS << " __FUNCTION__"; break;
David Majnemerbed356a2013-11-06 23:31:56 +00001675 case PredefinedExpr::FuncDName: OS << " __FUNCDNAME__"; break;
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001676 case PredefinedExpr::LFunction: OS << " L__FUNCTION__"; break;
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001677 case PredefinedExpr::PrettyFunction: OS << " __PRETTY_FUNCTION__";break;
Chris Lattnercbe4f772007-08-08 22:51:59 +00001678 }
1679}
1680
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001681void ASTDumper::VisitCharacterLiteral(const CharacterLiteral *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001682 VisitExpr(Node);
Richard Trieud215b8d2013-01-26 01:31:20 +00001683 ColorScope Color(*this, ValueColor);
Richard Trieu364ee422011-11-03 23:56:23 +00001684 OS << " " << Node->getValue();
Chris Lattnercbe4f772007-08-08 22:51:59 +00001685}
1686
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001687void ASTDumper::VisitIntegerLiteral(const IntegerLiteral *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001688 VisitExpr(Node);
Chris Lattnercbe4f772007-08-08 22:51:59 +00001689
1690 bool isSigned = Node->getType()->isSignedIntegerType();
Richard Trieud215b8d2013-01-26 01:31:20 +00001691 ColorScope Color(*this, ValueColor);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001692 OS << " " << Node->getValue().toString(10, isSigned);
Chris Lattnercbe4f772007-08-08 22:51:59 +00001693}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001694
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001695void ASTDumper::VisitFloatingLiteral(const FloatingLiteral *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001696 VisitExpr(Node);
Richard Trieud215b8d2013-01-26 01:31:20 +00001697 ColorScope Color(*this, ValueColor);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001698 OS << " " << Node->getValueAsApproximateDouble();
Chris Lattnercbe4f772007-08-08 22:51:59 +00001699}
Chris Lattner1c20a172007-08-26 03:42:43 +00001700
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001701void ASTDumper::VisitStringLiteral(const StringLiteral *Str) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001702 VisitExpr(Str);
Richard Trieud215b8d2013-01-26 01:31:20 +00001703 ColorScope Color(*this, ValueColor);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001704 OS << " ";
Richard Trieudc355912012-06-13 20:25:24 +00001705 Str->outputString(OS);
Chris Lattnercbe4f772007-08-08 22:51:59 +00001706}
Chris Lattner84ca3762007-08-30 01:00:35 +00001707
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001708void ASTDumper::VisitUnaryOperator(const UnaryOperator *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001709 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001710 OS << " " << (Node->isPostfix() ? "postfix" : "prefix")
1711 << " '" << UnaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
Chris Lattnercbe4f772007-08-08 22:51:59 +00001712}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001713
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001714void ASTDumper::VisitUnaryExprOrTypeTraitExpr(
1715 const UnaryExprOrTypeTraitExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001716 VisitExpr(Node);
Peter Collingbournee190dee2011-03-11 19:24:49 +00001717 switch(Node->getKind()) {
1718 case UETT_SizeOf:
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001719 OS << " sizeof";
Peter Collingbournee190dee2011-03-11 19:24:49 +00001720 break;
1721 case UETT_AlignOf:
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001722 OS << " alignof";
Peter Collingbournee190dee2011-03-11 19:24:49 +00001723 break;
1724 case UETT_VecStep:
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001725 OS << " vec_step";
Peter Collingbournee190dee2011-03-11 19:24:49 +00001726 break;
1727 }
Sebastian Redl6f282892008-11-11 17:56:53 +00001728 if (Node->isArgumentType())
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001729 dumpType(Node->getArgumentType());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001730}
Chris Lattnerdb3b3ff2007-08-09 17:35:30 +00001731
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001732void ASTDumper::VisitMemberExpr(const MemberExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001733 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001734 OS << " " << (Node->isArrow() ? "->" : ".") << *Node->getMemberDecl();
1735 dumpPointer(Node->getMemberDecl());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001736}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001737
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001738void ASTDumper::VisitExtVectorElementExpr(const ExtVectorElementExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001739 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001740 OS << " " << Node->getAccessor().getNameStart();
Chris Lattnercbe4f772007-08-08 22:51:59 +00001741}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001742
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001743void ASTDumper::VisitBinaryOperator(const BinaryOperator *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001744 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001745 OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
Chris Lattner86928112007-08-25 02:00:02 +00001746}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001747
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001748void ASTDumper::VisitCompoundAssignOperator(
1749 const CompoundAssignOperator *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001750 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001751 OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode())
1752 << "' ComputeLHSTy=";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001753 dumpBareType(Node->getComputationLHSType());
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001754 OS << " ComputeResultTy=";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001755 dumpBareType(Node->getComputationResultType());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001756}
Chris Lattnercbe4f772007-08-08 22:51:59 +00001757
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001758void ASTDumper::VisitBlockExpr(const BlockExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001759 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001760 dumpDecl(Node->getBlockDecl());
John McCall351762c2011-02-07 10:33:21 +00001761}
1762
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001763void ASTDumper::VisitOpaqueValueExpr(const OpaqueValueExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001764 VisitExpr(Node);
John McCallfe96e0b2011-11-06 09:01:30 +00001765
Richard Trieude5cc7d2013-01-31 01:44:26 +00001766 if (Expr *Source = Node->getSourceExpr()) {
1767 lastChild();
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001768 dumpStmt(Source);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001769 }
John McCallfe96e0b2011-11-06 09:01:30 +00001770}
1771
Chris Lattnercbe4f772007-08-08 22:51:59 +00001772// GNU extensions.
1773
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001774void ASTDumper::VisitAddrLabelExpr(const AddrLabelExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001775 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001776 OS << " " << Node->getLabel()->getName();
1777 dumpPointer(Node->getLabel());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001778}
1779
Chris Lattner8f184b12007-08-09 18:03:18 +00001780//===----------------------------------------------------------------------===//
1781// C++ Expressions
1782//===----------------------------------------------------------------------===//
Chris Lattnercbe4f772007-08-08 22:51:59 +00001783
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001784void ASTDumper::VisitCXXNamedCastExpr(const CXXNamedCastExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001785 VisitExpr(Node);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001786 OS << " " << Node->getCastName()
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001787 << "<" << Node->getTypeAsWritten().getAsString() << ">"
Anders Carlssona70cff62010-04-24 19:06:50 +00001788 << " <" << Node->getCastKindName();
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001789 dumpBasePath(OS, Node);
Anders Carlssona70cff62010-04-24 19:06:50 +00001790 OS << ">";
Chris Lattnercbe4f772007-08-08 22:51:59 +00001791}
1792
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001793void ASTDumper::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001794 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001795 OS << " " << (Node->getValue() ? "true" : "false");
Chris Lattnercbe4f772007-08-08 22:51:59 +00001796}
1797
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001798void ASTDumper::VisitCXXThisExpr(const CXXThisExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001799 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001800 OS << " this";
Douglas Gregor8ea1f532008-11-04 14:56:14 +00001801}
1802
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001803void ASTDumper::VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001804 VisitExpr(Node);
Eli Friedman29538892011-09-02 17:38:59 +00001805 OS << " functional cast to " << Node->getTypeAsWritten().getAsString()
1806 << " <" << Node->getCastKindName() << ">";
Douglas Gregore200adc2008-10-27 19:41:14 +00001807}
1808
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001809void ASTDumper::VisitCXXConstructExpr(const CXXConstructExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001810 VisitExpr(Node);
John McCalleba90cd2010-02-02 19:03:45 +00001811 CXXConstructorDecl *Ctor = Node->getConstructor();
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001812 dumpType(Ctor->getType());
Anders Carlsson073846832009-08-12 00:21:52 +00001813 if (Node->isElidable())
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001814 OS << " elidable";
John McCall85370042010-08-07 06:38:55 +00001815 if (Node->requiresZeroInitialization())
1816 OS << " zeroing";
Anders Carlsson073846832009-08-12 00:21:52 +00001817}
1818
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001819void ASTDumper::VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001820 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001821 OS << " ";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001822 dumpCXXTemporary(Node->getTemporary());
Anders Carlsson073846832009-08-12 00:21:52 +00001823}
1824
Richard Smithe6c01442013-06-05 00:46:14 +00001825void
1826ASTDumper::VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *Node) {
1827 VisitExpr(Node);
1828 if (const ValueDecl *VD = Node->getExtendingDecl()) {
1829 OS << " extended by ";
1830 dumpBareDeclRef(VD);
1831 }
1832}
1833
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001834void ASTDumper::VisitExprWithCleanups(const ExprWithCleanups *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001835 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001836 for (unsigned i = 0, e = Node->getNumObjects(); i != e; ++i)
1837 dumpDeclRef(Node->getObject(i), "cleanup");
Anders Carlsson073846832009-08-12 00:21:52 +00001838}
1839
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001840void ASTDumper::dumpCXXTemporary(const CXXTemporary *Temporary) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001841 OS << "(CXXTemporary";
1842 dumpPointer(Temporary);
1843 OS << ")";
Anders Carlsson073846832009-08-12 00:21:52 +00001844}
1845
Anders Carlsson76f4a902007-08-21 17:43:55 +00001846//===----------------------------------------------------------------------===//
1847// Obj-C Expressions
1848//===----------------------------------------------------------------------===//
1849
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001850void ASTDumper::VisitObjCMessageExpr(const ObjCMessageExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001851 VisitExpr(Node);
Aaron Ballmanb190f972014-01-03 17:59:55 +00001852 OS << " selector=";
1853 Node->getSelector().print(OS);
Douglas Gregor9a129192010-04-21 00:45:42 +00001854 switch (Node->getReceiverKind()) {
1855 case ObjCMessageExpr::Instance:
1856 break;
1857
1858 case ObjCMessageExpr::Class:
1859 OS << " class=";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001860 dumpBareType(Node->getClassReceiver());
Douglas Gregor9a129192010-04-21 00:45:42 +00001861 break;
1862
1863 case ObjCMessageExpr::SuperInstance:
1864 OS << " super (instance)";
1865 break;
1866
1867 case ObjCMessageExpr::SuperClass:
1868 OS << " super (class)";
1869 break;
1870 }
Ted Kremenek36748da2008-02-29 22:04:05 +00001871}
1872
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001873void ASTDumper::VisitObjCBoxedExpr(const ObjCBoxedExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001874 VisitExpr(Node);
Aaron Ballmanb190f972014-01-03 17:59:55 +00001875 OS << " selector=";
1876 Node->getBoxingMethod()->getSelector().print(OS);
Argyrios Kyrtzidis9dd40892012-05-10 20:02:31 +00001877}
1878
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001879void ASTDumper::VisitObjCAtCatchStmt(const ObjCAtCatchStmt *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001880 VisitStmt(Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001881 if (const VarDecl *CatchParam = Node->getCatchParamDecl())
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001882 dumpDecl(CatchParam);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001883 else
Douglas Gregor96c79492010-04-23 22:50:49 +00001884 OS << " catch all";
Douglas Gregor96c79492010-04-23 22:50:49 +00001885}
1886
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001887void ASTDumper::VisitObjCEncodeExpr(const ObjCEncodeExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001888 VisitExpr(Node);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001889 dumpType(Node->getEncodedType());
Anders Carlssonc5a81eb2007-08-22 15:14:15 +00001890}
1891
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001892void ASTDumper::VisitObjCSelectorExpr(const ObjCSelectorExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001893 VisitExpr(Node);
Mike Stump11289f42009-09-09 15:08:12 +00001894
Aaron Ballmanb190f972014-01-03 17:59:55 +00001895 OS << " ";
1896 Node->getSelector().print(OS);
Fariborz Jahanian4bef4622007-10-16 20:40:23 +00001897}
1898
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001899void ASTDumper::VisitObjCProtocolExpr(const ObjCProtocolExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001900 VisitExpr(Node);
Mike Stump11289f42009-09-09 15:08:12 +00001901
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001902 OS << ' ' << *Node->getProtocol();
Fariborz Jahaniana32aaef2007-10-17 16:58:11 +00001903}
Daniel Dunbar4b8c6db2008-08-30 05:35:15 +00001904
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001905void ASTDumper::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001906 VisitExpr(Node);
John McCallb7bd14f2010-12-02 01:19:52 +00001907 if (Node->isImplicitProperty()) {
Fariborz Jahanian0f0b3022010-12-22 19:46:35 +00001908 OS << " Kind=MethodRef Getter=\"";
1909 if (Node->getImplicitPropertyGetter())
Aaron Ballmanb190f972014-01-03 17:59:55 +00001910 Node->getImplicitPropertyGetter()->getSelector().print(OS);
Fariborz Jahanian0f0b3022010-12-22 19:46:35 +00001911 else
1912 OS << "(null)";
1913
1914 OS << "\" Setter=\"";
John McCallb7bd14f2010-12-02 01:19:52 +00001915 if (ObjCMethodDecl *Setter = Node->getImplicitPropertySetter())
Aaron Ballmanb190f972014-01-03 17:59:55 +00001916 Setter->getSelector().print(OS);
John McCallb7bd14f2010-12-02 01:19:52 +00001917 else
1918 OS << "(null)";
1919 OS << "\"";
1920 } else {
Benjamin Kramerb89514a2011-10-14 18:45:37 +00001921 OS << " Kind=PropertyRef Property=\"" << *Node->getExplicitProperty() <<'"';
John McCallb7bd14f2010-12-02 01:19:52 +00001922 }
Fariborz Jahanian8a1810f2008-11-22 18:39:36 +00001923
Fariborz Jahanian681c0752010-10-14 16:04:05 +00001924 if (Node->isSuperReceiver())
1925 OS << " super";
Argyrios Kyrtzidisab468b02012-03-30 00:19:18 +00001926
1927 OS << " Messaging=";
1928 if (Node->isMessagingGetter() && Node->isMessagingSetter())
1929 OS << "Getter&Setter";
1930 else if (Node->isMessagingGetter())
1931 OS << "Getter";
1932 else if (Node->isMessagingSetter())
1933 OS << "Setter";
Douglas Gregor8ea1f532008-11-04 14:56:14 +00001934}
1935
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001936void ASTDumper::VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001937 VisitExpr(Node);
Ted Kremeneke65b0862012-03-06 20:05:56 +00001938 if (Node->isArraySubscriptRefExpr())
1939 OS << " Kind=ArraySubscript GetterForArray=\"";
1940 else
1941 OS << " Kind=DictionarySubscript GetterForDictionary=\"";
1942 if (Node->getAtIndexMethodDecl())
Aaron Ballmanb190f972014-01-03 17:59:55 +00001943 Node->getAtIndexMethodDecl()->getSelector().print(OS);
Ted Kremeneke65b0862012-03-06 20:05:56 +00001944 else
1945 OS << "(null)";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001946
Ted Kremeneke65b0862012-03-06 20:05:56 +00001947 if (Node->isArraySubscriptRefExpr())
1948 OS << "\" SetterForArray=\"";
1949 else
1950 OS << "\" SetterForDictionary=\"";
1951 if (Node->setAtIndexMethodDecl())
Aaron Ballmanb190f972014-01-03 17:59:55 +00001952 Node->setAtIndexMethodDecl()->getSelector().print(OS);
Ted Kremeneke65b0862012-03-06 20:05:56 +00001953 else
1954 OS << "(null)";
1955}
1956
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001957void ASTDumper::VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001958 VisitExpr(Node);
Ted Kremeneke65b0862012-03-06 20:05:56 +00001959 OS << " " << (Node->getValue() ? "__objc_yes" : "__objc_no");
1960}
1961
Chris Lattnercbe4f772007-08-08 22:51:59 +00001962//===----------------------------------------------------------------------===//
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00001963// Comments
1964//===----------------------------------------------------------------------===//
1965
1966const char *ASTDumper::getCommandName(unsigned CommandID) {
1967 if (Traits)
1968 return Traits->getCommandInfo(CommandID)->Name;
1969 const CommandInfo *Info = CommandTraits::getBuiltinCommandInfo(CommandID);
1970 if (Info)
1971 return Info->Name;
1972 return "<not a builtin command>";
1973}
1974
1975void ASTDumper::dumpFullComment(const FullComment *C) {
1976 if (!C)
1977 return;
1978
1979 FC = C;
1980 dumpComment(C);
1981 FC = 0;
1982}
1983
1984void ASTDumper::dumpComment(const Comment *C) {
1985 IndentScope Indent(*this);
1986
1987 if (!C) {
Richard Trieud215b8d2013-01-26 01:31:20 +00001988 ColorScope Color(*this, NullColor);
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00001989 OS << "<<<NULL>>>";
1990 return;
1991 }
1992
Richard Trieud215b8d2013-01-26 01:31:20 +00001993 {
1994 ColorScope Color(*this, CommentColor);
1995 OS << C->getCommentKindName();
1996 }
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00001997 dumpPointer(C);
1998 dumpSourceRange(C->getSourceRange());
1999 ConstCommentVisitor<ASTDumper>::visit(C);
2000 for (Comment::child_iterator I = C->child_begin(), E = C->child_end();
Richard Trieude5cc7d2013-01-31 01:44:26 +00002001 I != E; ++I) {
2002 if (I + 1 == E)
2003 lastChild();
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002004 dumpComment(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +00002005 }
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002006}
2007
2008void ASTDumper::visitTextComment(const TextComment *C) {
2009 OS << " Text=\"" << C->getText() << "\"";
2010}
2011
2012void ASTDumper::visitInlineCommandComment(const InlineCommandComment *C) {
2013 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\"";
2014 switch (C->getRenderKind()) {
2015 case InlineCommandComment::RenderNormal:
2016 OS << " RenderNormal";
2017 break;
2018 case InlineCommandComment::RenderBold:
2019 OS << " RenderBold";
2020 break;
2021 case InlineCommandComment::RenderMonospaced:
2022 OS << " RenderMonospaced";
2023 break;
2024 case InlineCommandComment::RenderEmphasized:
2025 OS << " RenderEmphasized";
2026 break;
2027 }
2028
2029 for (unsigned i = 0, e = C->getNumArgs(); i != e; ++i)
2030 OS << " Arg[" << i << "]=\"" << C->getArgText(i) << "\"";
2031}
2032
2033void ASTDumper::visitHTMLStartTagComment(const HTMLStartTagComment *C) {
2034 OS << " Name=\"" << C->getTagName() << "\"";
2035 if (C->getNumAttrs() != 0) {
2036 OS << " Attrs: ";
2037 for (unsigned i = 0, e = C->getNumAttrs(); i != e; ++i) {
2038 const HTMLStartTagComment::Attribute &Attr = C->getAttr(i);
2039 OS << " \"" << Attr.Name << "=\"" << Attr.Value << "\"";
2040 }
2041 }
2042 if (C->isSelfClosing())
2043 OS << " SelfClosing";
2044}
2045
2046void ASTDumper::visitHTMLEndTagComment(const HTMLEndTagComment *C) {
2047 OS << " Name=\"" << C->getTagName() << "\"";
2048}
2049
2050void ASTDumper::visitBlockCommandComment(const BlockCommandComment *C) {
2051 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\"";
2052 for (unsigned i = 0, e = C->getNumArgs(); i != e; ++i)
2053 OS << " Arg[" << i << "]=\"" << C->getArgText(i) << "\"";
2054}
2055
2056void ASTDumper::visitParamCommandComment(const ParamCommandComment *C) {
2057 OS << " " << ParamCommandComment::getDirectionAsString(C->getDirection());
2058
2059 if (C->isDirectionExplicit())
2060 OS << " explicitly";
2061 else
2062 OS << " implicitly";
2063
2064 if (C->hasParamName()) {
2065 if (C->isParamIndexValid())
2066 OS << " Param=\"" << C->getParamName(FC) << "\"";
2067 else
2068 OS << " Param=\"" << C->getParamNameAsWritten() << "\"";
2069 }
2070
2071 if (C->isParamIndexValid())
2072 OS << " ParamIndex=" << C->getParamIndex();
2073}
2074
2075void ASTDumper::visitTParamCommandComment(const TParamCommandComment *C) {
2076 if (C->hasParamName()) {
2077 if (C->isPositionValid())
2078 OS << " Param=\"" << C->getParamName(FC) << "\"";
2079 else
2080 OS << " Param=\"" << C->getParamNameAsWritten() << "\"";
2081 }
2082
2083 if (C->isPositionValid()) {
2084 OS << " Position=<";
2085 for (unsigned i = 0, e = C->getDepth(); i != e; ++i) {
2086 OS << C->getIndex(i);
2087 if (i != e - 1)
2088 OS << ", ";
2089 }
2090 OS << ">";
2091 }
2092}
2093
2094void ASTDumper::visitVerbatimBlockComment(const VerbatimBlockComment *C) {
2095 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\""
2096 " CloseName=\"" << C->getCloseName() << "\"";
2097}
2098
2099void ASTDumper::visitVerbatimBlockLineComment(
2100 const VerbatimBlockLineComment *C) {
2101 OS << " Text=\"" << C->getText() << "\"";
2102}
2103
2104void ASTDumper::visitVerbatimLineComment(const VerbatimLineComment *C) {
2105 OS << " Text=\"" << C->getText() << "\"";
2106}
2107
2108//===----------------------------------------------------------------------===//
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002109// Decl method implementations
2110//===----------------------------------------------------------------------===//
2111
Alp Tokeref6b0072014-01-04 13:47:14 +00002112LLVM_DUMP_METHOD void Decl::dump() const { dump(llvm::errs()); }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002113
Alp Tokeref6b0072014-01-04 13:47:14 +00002114LLVM_DUMP_METHOD void Decl::dump(raw_ostream &OS) const {
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002115 ASTDumper P(OS, &getASTContext().getCommentCommandTraits(),
2116 &getASTContext().getSourceManager());
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002117 P.dumpDecl(this);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002118}
2119
Alp Tokeref6b0072014-01-04 13:47:14 +00002120LLVM_DUMP_METHOD void Decl::dumpColor() const {
Richard Trieud215b8d2013-01-26 01:31:20 +00002121 ASTDumper P(llvm::errs(), &getASTContext().getCommentCommandTraits(),
2122 &getASTContext().getSourceManager(), /*ShowColors*/true);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002123 P.dumpDecl(this);
Richard Trieud215b8d2013-01-26 01:31:20 +00002124}
Richard Smith33937e72013-06-22 21:49:40 +00002125
Alp Tokeref6b0072014-01-04 13:47:14 +00002126LLVM_DUMP_METHOD void DeclContext::dumpLookups() const {
Richard Smith6ea05822013-06-24 01:45:33 +00002127 dumpLookups(llvm::errs());
2128}
2129
Alp Tokeref6b0072014-01-04 13:47:14 +00002130LLVM_DUMP_METHOD void DeclContext::dumpLookups(raw_ostream &OS) const {
Richard Smith33937e72013-06-22 21:49:40 +00002131 const DeclContext *DC = this;
2132 while (!DC->isTranslationUnit())
2133 DC = DC->getParent();
2134 ASTContext &Ctx = cast<TranslationUnitDecl>(DC)->getASTContext();
Richard Smith6ea05822013-06-24 01:45:33 +00002135 ASTDumper P(OS, &Ctx.getCommentCommandTraits(), &Ctx.getSourceManager());
Richard Smith33937e72013-06-22 21:49:40 +00002136 P.dumpLookups(this);
2137}
2138
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002139//===----------------------------------------------------------------------===//
Chris Lattnercbe4f772007-08-08 22:51:59 +00002140// Stmt method implementations
2141//===----------------------------------------------------------------------===//
2142
Alp Tokeref6b0072014-01-04 13:47:14 +00002143LLVM_DUMP_METHOD void Stmt::dump(SourceManager &SM) const {
Argyrios Kyrtzidisc049f752010-08-09 10:54:31 +00002144 dump(llvm::errs(), SM);
2145}
2146
Alp Tokeref6b0072014-01-04 13:47:14 +00002147LLVM_DUMP_METHOD void Stmt::dump(raw_ostream &OS, SourceManager &SM) const {
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002148 ASTDumper P(OS, 0, &SM);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002149 P.dumpStmt(this);
Chris Lattner779d5d92007-08-30 00:40:08 +00002150}
2151
Alp Tokeref6b0072014-01-04 13:47:14 +00002152LLVM_DUMP_METHOD void Stmt::dump() const {
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002153 ASTDumper P(llvm::errs(), 0, 0);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002154 P.dumpStmt(this);
Chris Lattnercbe4f772007-08-08 22:51:59 +00002155}
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002156
Alp Tokeref6b0072014-01-04 13:47:14 +00002157LLVM_DUMP_METHOD void Stmt::dumpColor() const {
Richard Trieud215b8d2013-01-26 01:31:20 +00002158 ASTDumper P(llvm::errs(), 0, 0, /*ShowColors*/true);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002159 P.dumpStmt(this);
Richard Trieud215b8d2013-01-26 01:31:20 +00002160}
2161
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002162//===----------------------------------------------------------------------===//
2163// Comment method implementations
2164//===----------------------------------------------------------------------===//
2165
Alp Tokeref6b0072014-01-04 13:47:14 +00002166LLVM_DUMP_METHOD void Comment::dump() const { dump(llvm::errs(), 0, 0); }
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002167
Alp Tokeref6b0072014-01-04 13:47:14 +00002168LLVM_DUMP_METHOD void Comment::dump(const ASTContext &Context) const {
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002169 dump(llvm::errs(), &Context.getCommentCommandTraits(),
2170 &Context.getSourceManager());
2171}
2172
Alexander Kornienko00911f12013-01-15 12:20:21 +00002173void Comment::dump(raw_ostream &OS, const CommandTraits *Traits,
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002174 const SourceManager *SM) const {
2175 const FullComment *FC = dyn_cast<FullComment>(this);
2176 ASTDumper D(OS, Traits, SM);
2177 D.dumpFullComment(FC);
2178}
Richard Trieud215b8d2013-01-26 01:31:20 +00002179
Alp Tokeref6b0072014-01-04 13:47:14 +00002180LLVM_DUMP_METHOD void Comment::dumpColor() const {
Richard Trieud215b8d2013-01-26 01:31:20 +00002181 const FullComment *FC = dyn_cast<FullComment>(this);
2182 ASTDumper D(llvm::errs(), 0, 0, /*ShowColors*/true);
2183 D.dumpFullComment(FC);
2184}