blob: bdadbeddbafddbc69e631d35bf64ad4d5ccd2263 [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
35
36 struct TerminalColor {
37 raw_ostream::Colors Color;
38 bool Bold;
39 };
40
41 // Decl kind names (VarDecl, FunctionDecl, etc)
42 static const TerminalColor DeclKindNameColor = { raw_ostream::GREEN, true };
43 // Attr names (CleanupAttr, GuardedByAttr, etc)
44 static const TerminalColor AttrColor = { raw_ostream::BLUE, true };
45 // Statement names (DeclStmt, ImplicitCastExpr, etc)
46 static const TerminalColor StmtColor = { raw_ostream::MAGENTA, true };
47 // Comment names (FullComment, ParagraphComment, TextComment, etc)
48 static const TerminalColor CommentColor = { raw_ostream::YELLOW, true };
49
50 // Type names (int, float, etc, plus user defined types)
51 static const TerminalColor TypeColor = { raw_ostream::GREEN, false };
52
53 // Pointer address
54 static const TerminalColor AddressColor = { raw_ostream::YELLOW, false };
55 // Source locations
56 static const TerminalColor LocationColor = { raw_ostream::YELLOW, false };
57
58 // lvalue/xvalue
59 static const TerminalColor ValueKindColor = { raw_ostream::CYAN, false };
60 // bitfield/objcproperty/objcsubscript/vectorcomponent
61 static const TerminalColor ObjectKindColor = { raw_ostream::CYAN, false };
62
63 // Null statements
64 static const TerminalColor NullColor = { raw_ostream::BLUE, false };
65
Richard Smith1d209d02013-05-23 01:49:11 +000066 // Undeserialized entities
67 static const TerminalColor UndeserializedColor = { raw_ostream::GREEN, true };
68
Richard Trieud215b8d2013-01-26 01:31:20 +000069 // CastKind from CastExpr's
70 static const TerminalColor CastColor = { raw_ostream::RED, false };
71
72 // Value of the statement
73 static const TerminalColor ValueColor = { raw_ostream::CYAN, true };
74 // Decl names
75 static const TerminalColor DeclNameColor = { raw_ostream::CYAN, true };
76
Richard Trieude5cc7d2013-01-31 01:44:26 +000077 // Indents ( `, -. | )
78 static const TerminalColor IndentColor = { raw_ostream::BLUE, false };
79
Alexander Kornienko90ff6072012-12-20 02:09:13 +000080 class ASTDumper
Alexander Kornienko540bacb2013-02-01 12:35:51 +000081 : public ConstDeclVisitor<ASTDumper>, public ConstStmtVisitor<ASTDumper>,
Alexander Kornienkoebc17b52013-01-14 14:07:11 +000082 public ConstCommentVisitor<ASTDumper> {
Chris Lattner0e62c1c2011-07-23 10:55:15 +000083 raw_ostream &OS;
Alexander Kornienkoebc17b52013-01-14 14:07:11 +000084 const CommandTraits *Traits;
85 const SourceManager *SM;
Manuel Klimek874030e2012-11-07 00:33:12 +000086 bool IsFirstLine;
Mike Stump11289f42009-09-09 15:08:12 +000087
Richard Trieude5cc7d2013-01-31 01:44:26 +000088 // Indicates whether more child are expected at the current tree depth
89 enum IndentType { IT_Child, IT_LastChild };
90
91 /// Indents[i] indicates if another child exists at level i.
92 /// Used by Indent() to print the tree structure.
93 llvm::SmallVector<IndentType, 32> Indents;
94
95 /// Indicates that more children will be needed at this indent level.
96 /// If true, prevents lastChild() from marking the node as the last child.
97 /// This is used when there are multiple collections of children to be
98 /// dumped as well as during conditional node dumping.
99 bool MoreChildren;
100
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000101 /// Keep track of the last location we print out so that we can
102 /// print out deltas from then on out.
Chris Lattner11e30d32007-08-30 06:17:34 +0000103 const char *LastLocFilename;
104 unsigned LastLocLine;
Douglas Gregor7de59662009-05-29 20:38:28 +0000105
Alexander Kornienkoebc17b52013-01-14 14:07:11 +0000106 /// The \c FullComment parent of the comment being dumped.
107 const FullComment *FC;
108
Richard Trieud215b8d2013-01-26 01:31:20 +0000109 bool ShowColors;
110
Manuel Klimek874030e2012-11-07 00:33:12 +0000111 class IndentScope {
Alexander Kornienko18ec81b2012-12-13 13:59:55 +0000112 ASTDumper &Dumper;
Richard Trieude5cc7d2013-01-31 01:44:26 +0000113 // Preserve the Dumper's MoreChildren value from the previous IndentScope
114 bool MoreChildren;
Manuel Klimek874030e2012-11-07 00:33:12 +0000115 public:
Alexander Kornienko18ec81b2012-12-13 13:59:55 +0000116 IndentScope(ASTDumper &Dumper) : Dumper(Dumper) {
Richard Trieude5cc7d2013-01-31 01:44:26 +0000117 MoreChildren = Dumper.hasMoreChildren();
118 Dumper.setMoreChildren(false);
Manuel Klimek874030e2012-11-07 00:33:12 +0000119 Dumper.indent();
120 }
121 ~IndentScope() {
Richard Trieude5cc7d2013-01-31 01:44:26 +0000122 Dumper.setMoreChildren(MoreChildren);
Manuel Klimek874030e2012-11-07 00:33:12 +0000123 Dumper.unindent();
124 }
125 };
126
Richard Trieud215b8d2013-01-26 01:31:20 +0000127 class ColorScope {
128 ASTDumper &Dumper;
129 public:
130 ColorScope(ASTDumper &Dumper, TerminalColor Color)
131 : Dumper(Dumper) {
132 if (Dumper.ShowColors)
133 Dumper.OS.changeColor(Color.Color, Color.Bold);
134 }
135 ~ColorScope() {
136 if (Dumper.ShowColors)
137 Dumper.OS.resetColor();
138 }
139 };
140
Chris Lattnercbe4f772007-08-08 22:51:59 +0000141 public:
Alexander Kornienkoebc17b52013-01-14 14:07:11 +0000142 ASTDumper(raw_ostream &OS, const CommandTraits *Traits,
143 const SourceManager *SM)
Richard Smith56d12152013-01-31 02:04:38 +0000144 : OS(OS), Traits(Traits), SM(SM), IsFirstLine(true), MoreChildren(false),
145 LastLocFilename(""), LastLocLine(~0U), FC(0),
Richard Trieud215b8d2013-01-26 01:31:20 +0000146 ShowColors(SM && SM->getDiagnostics().getShowColors()) { }
147
148 ASTDumper(raw_ostream &OS, const CommandTraits *Traits,
149 const SourceManager *SM, bool ShowColors)
Richard Smith56d12152013-01-31 02:04:38 +0000150 : OS(OS), Traits(Traits), SM(SM), IsFirstLine(true), MoreChildren(false),
151 LastLocFilename(""), LastLocLine(~0U),
Richard Trieude5cc7d2013-01-31 01:44:26 +0000152 ShowColors(ShowColors) { }
Mike Stump11289f42009-09-09 15:08:12 +0000153
Alexander Kornienko18ec81b2012-12-13 13:59:55 +0000154 ~ASTDumper() {
Manuel Klimek874030e2012-11-07 00:33:12 +0000155 OS << "\n";
156 }
157
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000158 void dumpDecl(const Decl *D);
159 void dumpStmt(const Stmt *S);
Alexander Kornienkoebc17b52013-01-14 14:07:11 +0000160 void dumpFullComment(const FullComment *C);
Mike Stump11289f42009-09-09 15:08:12 +0000161
Richard Trieude5cc7d2013-01-31 01:44:26 +0000162 // Formatting
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000163 void indent();
164 void unindent();
Richard Trieude5cc7d2013-01-31 01:44:26 +0000165 void lastChild();
166 bool hasMoreChildren();
167 void setMoreChildren(bool Value);
168
169 // Utilities
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000170 void dumpPointer(const void *Ptr);
171 void dumpSourceRange(SourceRange R);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000172 void dumpLocation(SourceLocation Loc);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000173 void dumpBareType(QualType T);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000174 void dumpType(QualType T);
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000175 void dumpBareDeclRef(const Decl *Node);
Alexander Kornienko9bdeb112012-12-20 12:23:54 +0000176 void dumpDeclRef(const Decl *Node, const char *Label = 0);
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000177 void dumpName(const NamedDecl *D);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000178 bool hasNodes(const DeclContext *DC);
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000179 void dumpDeclContext(const DeclContext *DC);
Richard Smith33937e72013-06-22 21:49:40 +0000180 void dumpLookups(const DeclContext *DC);
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000181 void dumpAttr(const Attr *A);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000182
183 // C++ Utilities
184 void dumpAccessSpecifier(AccessSpecifier AS);
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000185 void dumpCXXCtorInitializer(const CXXCtorInitializer *Init);
186 void dumpTemplateParameters(const TemplateParameterList *TPL);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000187 void dumpTemplateArgumentListInfo(const TemplateArgumentListInfo &TALI);
188 void dumpTemplateArgumentLoc(const TemplateArgumentLoc &A);
189 void dumpTemplateArgumentList(const TemplateArgumentList &TAL);
190 void dumpTemplateArgument(const TemplateArgument &A,
191 SourceRange R = SourceRange());
192
193 // Decls
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000194 void VisitLabelDecl(const LabelDecl *D);
195 void VisitTypedefDecl(const TypedefDecl *D);
196 void VisitEnumDecl(const EnumDecl *D);
197 void VisitRecordDecl(const RecordDecl *D);
198 void VisitEnumConstantDecl(const EnumConstantDecl *D);
199 void VisitIndirectFieldDecl(const IndirectFieldDecl *D);
200 void VisitFunctionDecl(const FunctionDecl *D);
201 void VisitFieldDecl(const FieldDecl *D);
202 void VisitVarDecl(const VarDecl *D);
203 void VisitFileScopeAsmDecl(const FileScopeAsmDecl *D);
204 void VisitImportDecl(const ImportDecl *D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000205
206 // C++ Decls
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000207 void VisitNamespaceDecl(const NamespaceDecl *D);
208 void VisitUsingDirectiveDecl(const UsingDirectiveDecl *D);
209 void VisitNamespaceAliasDecl(const NamespaceAliasDecl *D);
210 void VisitTypeAliasDecl(const TypeAliasDecl *D);
211 void VisitTypeAliasTemplateDecl(const TypeAliasTemplateDecl *D);
212 void VisitCXXRecordDecl(const CXXRecordDecl *D);
213 void VisitStaticAssertDecl(const StaticAssertDecl *D);
214 void VisitFunctionTemplateDecl(const FunctionTemplateDecl *D);
215 void VisitClassTemplateDecl(const ClassTemplateDecl *D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000216 void VisitClassTemplateSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000217 const ClassTemplateSpecializationDecl *D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000218 void VisitClassTemplatePartialSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000219 const ClassTemplatePartialSpecializationDecl *D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000220 void VisitClassScopeFunctionSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000221 const ClassScopeFunctionSpecializationDecl *D);
Richard Smithd25789a2013-09-18 01:36:02 +0000222 void VisitVarTemplateDecl(const VarTemplateDecl *D);
223 void VisitVarTemplateSpecializationDecl(
224 const VarTemplateSpecializationDecl *D);
225 void VisitVarTemplatePartialSpecializationDecl(
226 const VarTemplatePartialSpecializationDecl *D);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000227 void VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D);
228 void VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D);
229 void VisitTemplateTemplateParmDecl(const TemplateTemplateParmDecl *D);
230 void VisitUsingDecl(const UsingDecl *D);
231 void VisitUnresolvedUsingTypenameDecl(const UnresolvedUsingTypenameDecl *D);
232 void VisitUnresolvedUsingValueDecl(const UnresolvedUsingValueDecl *D);
233 void VisitUsingShadowDecl(const UsingShadowDecl *D);
234 void VisitLinkageSpecDecl(const LinkageSpecDecl *D);
235 void VisitAccessSpecDecl(const AccessSpecDecl *D);
236 void VisitFriendDecl(const FriendDecl *D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000237
238 // ObjC Decls
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000239 void VisitObjCIvarDecl(const ObjCIvarDecl *D);
240 void VisitObjCMethodDecl(const ObjCMethodDecl *D);
241 void VisitObjCCategoryDecl(const ObjCCategoryDecl *D);
242 void VisitObjCCategoryImplDecl(const ObjCCategoryImplDecl *D);
243 void VisitObjCProtocolDecl(const ObjCProtocolDecl *D);
244 void VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D);
245 void VisitObjCImplementationDecl(const ObjCImplementationDecl *D);
246 void VisitObjCCompatibleAliasDecl(const ObjCCompatibleAliasDecl *D);
247 void VisitObjCPropertyDecl(const ObjCPropertyDecl *D);
248 void VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D);
249 void VisitBlockDecl(const BlockDecl *D);
Mike Stump11289f42009-09-09 15:08:12 +0000250
Chris Lattner84ca3762007-08-30 01:00:35 +0000251 // Stmts.
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000252 void VisitStmt(const Stmt *Node);
253 void VisitDeclStmt(const DeclStmt *Node);
254 void VisitAttributedStmt(const AttributedStmt *Node);
255 void VisitLabelStmt(const LabelStmt *Node);
256 void VisitGotoStmt(const GotoStmt *Node);
Pavel Labath1ef83422013-09-04 14:35:00 +0000257 void VisitCXXCatchStmt(const CXXCatchStmt *Node);
Mike Stump11289f42009-09-09 15:08:12 +0000258
Chris Lattner84ca3762007-08-30 01:00:35 +0000259 // Exprs
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000260 void VisitExpr(const Expr *Node);
261 void VisitCastExpr(const CastExpr *Node);
262 void VisitDeclRefExpr(const DeclRefExpr *Node);
263 void VisitPredefinedExpr(const PredefinedExpr *Node);
264 void VisitCharacterLiteral(const CharacterLiteral *Node);
265 void VisitIntegerLiteral(const IntegerLiteral *Node);
266 void VisitFloatingLiteral(const FloatingLiteral *Node);
267 void VisitStringLiteral(const StringLiteral *Str);
268 void VisitUnaryOperator(const UnaryOperator *Node);
269 void VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *Node);
270 void VisitMemberExpr(const MemberExpr *Node);
271 void VisitExtVectorElementExpr(const ExtVectorElementExpr *Node);
272 void VisitBinaryOperator(const BinaryOperator *Node);
273 void VisitCompoundAssignOperator(const CompoundAssignOperator *Node);
274 void VisitAddrLabelExpr(const AddrLabelExpr *Node);
275 void VisitBlockExpr(const BlockExpr *Node);
276 void VisitOpaqueValueExpr(const OpaqueValueExpr *Node);
Chris Lattner84ca3762007-08-30 01:00:35 +0000277
278 // C++
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000279 void VisitCXXNamedCastExpr(const CXXNamedCastExpr *Node);
280 void VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *Node);
281 void VisitCXXThisExpr(const CXXThisExpr *Node);
282 void VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *Node);
283 void VisitCXXConstructExpr(const CXXConstructExpr *Node);
284 void VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *Node);
Richard Smithe6c01442013-06-05 00:46:14 +0000285 void VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000286 void VisitExprWithCleanups(const ExprWithCleanups *Node);
287 void VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *Node);
288 void dumpCXXTemporary(const CXXTemporary *Temporary);
Faisal Vali2b391ab2013-09-26 19:54:12 +0000289 void VisitLambdaExpr(const LambdaExpr *Node) {
290 VisitExpr(Node);
291 dumpDecl(Node->getLambdaClass());
292 }
Mike Stump11289f42009-09-09 15:08:12 +0000293
Chris Lattner84ca3762007-08-30 01:00:35 +0000294 // ObjC
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000295 void VisitObjCAtCatchStmt(const ObjCAtCatchStmt *Node);
296 void VisitObjCEncodeExpr(const ObjCEncodeExpr *Node);
297 void VisitObjCMessageExpr(const ObjCMessageExpr *Node);
298 void VisitObjCBoxedExpr(const ObjCBoxedExpr *Node);
299 void VisitObjCSelectorExpr(const ObjCSelectorExpr *Node);
300 void VisitObjCProtocolExpr(const ObjCProtocolExpr *Node);
301 void VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *Node);
302 void VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *Node);
303 void VisitObjCIvarRefExpr(const ObjCIvarRefExpr *Node);
304 void VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *Node);
Alexander Kornienkoebc17b52013-01-14 14:07:11 +0000305
306 // Comments.
307 const char *getCommandName(unsigned CommandID);
308 void dumpComment(const Comment *C);
309
310 // Inline comments.
311 void visitTextComment(const TextComment *C);
312 void visitInlineCommandComment(const InlineCommandComment *C);
313 void visitHTMLStartTagComment(const HTMLStartTagComment *C);
314 void visitHTMLEndTagComment(const HTMLEndTagComment *C);
315
316 // Block comments.
317 void visitBlockCommandComment(const BlockCommandComment *C);
318 void visitParamCommandComment(const ParamCommandComment *C);
319 void visitTParamCommandComment(const TParamCommandComment *C);
320 void visitVerbatimBlockComment(const VerbatimBlockComment *C);
321 void visitVerbatimBlockLineComment(const VerbatimBlockLineComment *C);
322 void visitVerbatimLineComment(const VerbatimLineComment *C);
Chris Lattnercbe4f772007-08-08 22:51:59 +0000323 };
324}
325
326//===----------------------------------------------------------------------===//
Chris Lattner11e30d32007-08-30 06:17:34 +0000327// Utilities
328//===----------------------------------------------------------------------===//
329
Richard Trieude5cc7d2013-01-31 01:44:26 +0000330// Print out the appropriate tree structure using the Indents vector.
331// Example of tree and the Indents vector at each level.
332// A { }
333// |-B { IT_Child }
334// | `-C { IT_Child, IT_LastChild }
335// `-D { IT_LastChild }
336// |-E { IT_LastChild, IT_Child }
337// `-F { IT_LastChild, IT_LastChild }
338// Type non-last element, last element
339// IT_Child "| " "|-"
340// IT_LastChild " " "`-"
Alexander Kornienko18ec81b2012-12-13 13:59:55 +0000341void ASTDumper::indent() {
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000342 if (IsFirstLine)
343 IsFirstLine = false;
344 else
345 OS << "\n";
Richard Trieude5cc7d2013-01-31 01:44:26 +0000346
347 ColorScope Color(*this, IndentColor);
Craig Topper2341c0d2013-07-04 03:08:24 +0000348 for (SmallVectorImpl<IndentType>::const_iterator I = Indents.begin(),
349 E = Indents.end();
Richard Trieude5cc7d2013-01-31 01:44:26 +0000350 I != E; ++I) {
351 switch (*I) {
Richard Smith56d12152013-01-31 02:04:38 +0000352 case IT_Child:
353 if (I == E - 1)
354 OS << "|-";
355 else
356 OS << "| ";
357 continue;
358 case IT_LastChild:
359 if (I == E - 1)
360 OS << "`-";
361 else
362 OS << " ";
363 continue;
Richard Trieude5cc7d2013-01-31 01:44:26 +0000364 }
Richard Smith56d12152013-01-31 02:04:38 +0000365 llvm_unreachable("Invalid IndentType");
Richard Trieude5cc7d2013-01-31 01:44:26 +0000366 }
367 Indents.push_back(IT_Child);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000368}
369
Alexander Kornienko18ec81b2012-12-13 13:59:55 +0000370void ASTDumper::unindent() {
Richard Trieude5cc7d2013-01-31 01:44:26 +0000371 Indents.pop_back();
372}
373
374// Call before each potential last child node is to be dumped. If MoreChildren
375// is false, then this is the last child, otherwise treat as a regular node.
376void ASTDumper::lastChild() {
377 if (!hasMoreChildren())
378 Indents.back() = IT_LastChild;
379}
380
381// MoreChildren should be set before calling another function that may print
382// additional nodes to prevent conflicting final child nodes.
383bool ASTDumper::hasMoreChildren() {
384 return MoreChildren;
385}
386
387void ASTDumper::setMoreChildren(bool Value) {
388 MoreChildren = Value;
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000389}
390
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000391void ASTDumper::dumpPointer(const void *Ptr) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000392 ColorScope Color(*this, AddressColor);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000393 OS << ' ' << Ptr;
394}
395
Alexander Kornienko18ec81b2012-12-13 13:59:55 +0000396void ASTDumper::dumpLocation(SourceLocation Loc) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000397 ColorScope Color(*this, LocationColor);
Chris Lattner53e384f2009-01-16 07:00:02 +0000398 SourceLocation SpellingLoc = SM->getSpellingLoc(Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000399
Chris Lattner11e30d32007-08-30 06:17:34 +0000400 // The general format we print out is filename:line:col, but we drop pieces
401 // that haven't changed since the last loc printed.
Chris Lattnerf1ca7d32009-01-27 07:57:44 +0000402 PresumedLoc PLoc = SM->getPresumedLoc(SpellingLoc);
403
Douglas Gregor453b0122010-11-12 07:15:47 +0000404 if (PLoc.isInvalid()) {
405 OS << "<invalid sloc>";
406 return;
407 }
408
Chris Lattnerf1ca7d32009-01-27 07:57:44 +0000409 if (strcmp(PLoc.getFilename(), LastLocFilename) != 0) {
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000410 OS << PLoc.getFilename() << ':' << PLoc.getLine()
411 << ':' << PLoc.getColumn();
Chris Lattnerf1ca7d32009-01-27 07:57:44 +0000412 LastLocFilename = PLoc.getFilename();
413 LastLocLine = PLoc.getLine();
414 } else if (PLoc.getLine() != LastLocLine) {
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000415 OS << "line" << ':' << PLoc.getLine()
416 << ':' << PLoc.getColumn();
Chris Lattnerf1ca7d32009-01-27 07:57:44 +0000417 LastLocLine = PLoc.getLine();
Chris Lattner11e30d32007-08-30 06:17:34 +0000418 } else {
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000419 OS << "col" << ':' << PLoc.getColumn();
Chris Lattner11e30d32007-08-30 06:17:34 +0000420 }
421}
422
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000423void ASTDumper::dumpSourceRange(SourceRange R) {
Chris Lattner11e30d32007-08-30 06:17:34 +0000424 // Can't translate locations if a SourceManager isn't available.
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000425 if (!SM)
426 return;
Mike Stump11289f42009-09-09 15:08:12 +0000427
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000428 OS << " <";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000429 dumpLocation(R.getBegin());
Chris Lattnera7c19fe2007-10-16 22:36:42 +0000430 if (R.getBegin() != R.getEnd()) {
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000431 OS << ", ";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000432 dumpLocation(R.getEnd());
Chris Lattner11e30d32007-08-30 06:17:34 +0000433 }
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000434 OS << ">";
Mike Stump11289f42009-09-09 15:08:12 +0000435
Chris Lattner11e30d32007-08-30 06:17:34 +0000436 // <t2.c:123:421[blah], t2.c:412:321>
437
438}
439
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000440void ASTDumper::dumpBareType(QualType T) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000441 ColorScope Color(*this, TypeColor);
442
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000443 SplitQualType T_split = T.split();
444 OS << "'" << QualType::getAsString(T_split) << "'";
445
446 if (!T.isNull()) {
447 // If the type is sugared, also dump a (shallow) desugared type.
448 SplitQualType D_split = T.getSplitDesugaredType();
449 if (T_split != D_split)
450 OS << ":'" << QualType::getAsString(D_split) << "'";
451 }
452}
453
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000454void ASTDumper::dumpType(QualType T) {
455 OS << ' ';
456 dumpBareType(T);
457}
458
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000459void ASTDumper::dumpBareDeclRef(const Decl *D) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000460 {
461 ColorScope Color(*this, DeclKindNameColor);
462 OS << D->getDeclKindName();
463 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000464 dumpPointer(D);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000465
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000466 if (const NamedDecl *ND = dyn_cast<NamedDecl>(D)) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000467 ColorScope Color(*this, DeclNameColor);
David Blaikied4da8722013-05-14 21:04:00 +0000468 OS << " '" << ND->getDeclName() << '\'';
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000469 }
470
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000471 if (const ValueDecl *VD = dyn_cast<ValueDecl>(D))
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000472 dumpType(VD->getType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000473}
474
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000475void ASTDumper::dumpDeclRef(const Decl *D, const char *Label) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000476 if (!D)
477 return;
478
479 IndentScope Indent(*this);
480 if (Label)
481 OS << Label << ' ';
482 dumpBareDeclRef(D);
483}
484
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000485void ASTDumper::dumpName(const NamedDecl *ND) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000486 if (ND->getDeclName()) {
487 ColorScope Color(*this, DeclNameColor);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000488 OS << ' ' << ND->getNameAsString();
Richard Trieud215b8d2013-01-26 01:31:20 +0000489 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000490}
491
Richard Trieude5cc7d2013-01-31 01:44:26 +0000492bool ASTDumper::hasNodes(const DeclContext *DC) {
493 if (!DC)
494 return false;
495
Richard Smith1d209d02013-05-23 01:49:11 +0000496 return DC->hasExternalLexicalStorage() ||
497 DC->noload_decls_begin() != DC->noload_decls_end();
Richard Trieude5cc7d2013-01-31 01:44:26 +0000498}
499
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000500void ASTDumper::dumpDeclContext(const DeclContext *DC) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000501 if (!DC)
502 return;
Richard Smith1d209d02013-05-23 01:49:11 +0000503 bool HasUndeserializedDecls = DC->hasExternalLexicalStorage();
504 for (DeclContext::decl_iterator I = DC->noload_decls_begin(), E = DC->noload_decls_end();
Richard Trieude5cc7d2013-01-31 01:44:26 +0000505 I != E; ++I) {
506 DeclContext::decl_iterator Next = I;
507 ++Next;
Richard Smith1d209d02013-05-23 01:49:11 +0000508 if (Next == E && !HasUndeserializedDecls)
Richard Trieude5cc7d2013-01-31 01:44:26 +0000509 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000510 dumpDecl(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000511 }
Richard Smith1d209d02013-05-23 01:49:11 +0000512 if (HasUndeserializedDecls) {
513 lastChild();
514 IndentScope Indent(*this);
515 ColorScope Color(*this, UndeserializedColor);
516 OS << "<undeserialized declarations>";
517 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000518}
519
Richard Smith33937e72013-06-22 21:49:40 +0000520void ASTDumper::dumpLookups(const DeclContext *DC) {
521 IndentScope Indent(*this);
522
523 OS << "StoredDeclsMap ";
524 dumpBareDeclRef(cast<Decl>(DC));
525
526 const DeclContext *Primary = DC->getPrimaryContext();
527 if (Primary != DC) {
528 OS << " primary";
529 dumpPointer(cast<Decl>(Primary));
530 }
531
532 bool HasUndeserializedLookups = Primary->hasExternalVisibleStorage();
533
534 DeclContext::all_lookups_iterator I = Primary->noload_lookups_begin(),
535 E = Primary->noload_lookups_end();
536 while (I != E) {
537 DeclarationName Name = I.getLookupName();
538 DeclContextLookupResult R = *I++;
539 if (I == E && !HasUndeserializedLookups)
540 lastChild();
541
542 IndentScope Indent(*this);
543 OS << "DeclarationName ";
544 {
545 ColorScope Color(*this, DeclNameColor);
546 OS << '\'' << Name << '\'';
547 }
548
549 for (DeclContextLookupResult::iterator RI = R.begin(), RE = R.end();
550 RI != RE; ++RI) {
551 if (RI + 1 == RE)
552 lastChild();
553 dumpDeclRef(*RI);
554 }
555 }
556
557 if (HasUndeserializedLookups) {
558 lastChild();
559 IndentScope Indent(*this);
560 ColorScope Color(*this, UndeserializedColor);
561 OS << "<undeserialized lookups>";
562 }
563}
564
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000565void ASTDumper::dumpAttr(const Attr *A) {
566 IndentScope Indent(*this);
Richard Trieud215b8d2013-01-26 01:31:20 +0000567 {
568 ColorScope Color(*this, AttrColor);
569 switch (A->getKind()) {
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000570#define ATTR(X) case attr::X: OS << #X; break;
571#include "clang/Basic/AttrList.inc"
Richard Trieud215b8d2013-01-26 01:31:20 +0000572 default: llvm_unreachable("unexpected attribute kind");
573 }
574 OS << "Attr";
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000575 }
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000576 dumpPointer(A);
577 dumpSourceRange(A->getRange());
578#include "clang/AST/AttrDump.inc"
579}
580
Richard Smithf5f43542013-02-07 01:35:44 +0000581static Decl *getPreviousDeclImpl(...) {
582 return 0;
583}
584
585template<typename T>
586static const Decl *getPreviousDeclImpl(const Redeclarable<T> *D) {
587 return D->getPreviousDecl();
588}
589
590/// Get the previous declaration in the redeclaration chain for a declaration.
591static const Decl *getPreviousDecl(const Decl *D) {
592 switch (D->getKind()) {
593#define DECL(DERIVED, BASE) \
594 case Decl::DERIVED: \
595 return getPreviousDeclImpl(cast<DERIVED##Decl>(D));
596#define ABSTRACT_DECL(DECL)
597#include "clang/AST/DeclNodes.inc"
598 }
599 llvm_unreachable("Decl that isn't part of DeclNodes.inc!");
600}
601
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000602//===----------------------------------------------------------------------===//
603// C++ Utilities
604//===----------------------------------------------------------------------===//
605
606void ASTDumper::dumpAccessSpecifier(AccessSpecifier AS) {
607 switch (AS) {
608 case AS_none:
609 break;
610 case AS_public:
611 OS << "public";
612 break;
613 case AS_protected:
614 OS << "protected";
615 break;
616 case AS_private:
617 OS << "private";
618 break;
619 }
620}
621
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000622void ASTDumper::dumpCXXCtorInitializer(const CXXCtorInitializer *Init) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000623 IndentScope Indent(*this);
624 OS << "CXXCtorInitializer";
625 if (Init->isAnyMemberInitializer()) {
626 OS << ' ';
627 dumpBareDeclRef(Init->getAnyMember());
628 } else {
629 dumpType(QualType(Init->getBaseClass(), 0));
630 }
631 dumpStmt(Init->getInit());
632}
633
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000634void ASTDumper::dumpTemplateParameters(const TemplateParameterList *TPL) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000635 if (!TPL)
636 return;
637
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000638 for (TemplateParameterList::const_iterator I = TPL->begin(), E = TPL->end();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000639 I != E; ++I)
640 dumpDecl(*I);
641}
642
643void ASTDumper::dumpTemplateArgumentListInfo(
644 const TemplateArgumentListInfo &TALI) {
Richard Trieude5cc7d2013-01-31 01:44:26 +0000645 for (unsigned i = 0, e = TALI.size(); i < e; ++i) {
646 if (i + 1 == e)
647 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000648 dumpTemplateArgumentLoc(TALI[i]);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000649 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000650}
651
652void ASTDumper::dumpTemplateArgumentLoc(const TemplateArgumentLoc &A) {
653 dumpTemplateArgument(A.getArgument(), A.getSourceRange());
654}
655
656void ASTDumper::dumpTemplateArgumentList(const TemplateArgumentList &TAL) {
657 for (unsigned i = 0, e = TAL.size(); i < e; ++i)
658 dumpTemplateArgument(TAL[i]);
659}
660
661void ASTDumper::dumpTemplateArgument(const TemplateArgument &A, SourceRange R) {
662 IndentScope Indent(*this);
663 OS << "TemplateArgument";
664 if (R.isValid())
665 dumpSourceRange(R);
666
667 switch (A.getKind()) {
668 case TemplateArgument::Null:
669 OS << " null";
670 break;
671 case TemplateArgument::Type:
672 OS << " type";
Richard Trieude5cc7d2013-01-31 01:44:26 +0000673 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000674 dumpType(A.getAsType());
675 break;
676 case TemplateArgument::Declaration:
677 OS << " decl";
Richard Trieude5cc7d2013-01-31 01:44:26 +0000678 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000679 dumpDeclRef(A.getAsDecl());
680 break;
681 case TemplateArgument::NullPtr:
682 OS << " nullptr";
683 break;
684 case TemplateArgument::Integral:
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000685 OS << " integral " << A.getAsIntegral();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000686 break;
687 case TemplateArgument::Template:
688 OS << " template ";
689 A.getAsTemplate().dump(OS);
690 break;
691 case TemplateArgument::TemplateExpansion:
692 OS << " template expansion";
693 A.getAsTemplateOrTemplatePattern().dump(OS);
694 break;
695 case TemplateArgument::Expression:
696 OS << " expr";
Richard Trieude5cc7d2013-01-31 01:44:26 +0000697 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000698 dumpStmt(A.getAsExpr());
699 break;
700 case TemplateArgument::Pack:
701 OS << " pack";
702 for (TemplateArgument::pack_iterator I = A.pack_begin(), E = A.pack_end();
Richard Trieude5cc7d2013-01-31 01:44:26 +0000703 I != E; ++I) {
704 if (I + 1 == E)
705 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000706 dumpTemplateArgument(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000707 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000708 break;
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000709 }
710}
711
Chris Lattner11e30d32007-08-30 06:17:34 +0000712//===----------------------------------------------------------------------===//
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000713// Decl dumping methods.
Chris Lattnercbe4f772007-08-08 22:51:59 +0000714//===----------------------------------------------------------------------===//
715
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000716void ASTDumper::dumpDecl(const Decl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000717 IndentScope Indent(*this);
Mike Stump11289f42009-09-09 15:08:12 +0000718
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000719 if (!D) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000720 ColorScope Color(*this, NullColor);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000721 OS << "<<<NULL>>>";
722 return;
Chris Lattnercbe4f772007-08-08 22:51:59 +0000723 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000724
Richard Trieud215b8d2013-01-26 01:31:20 +0000725 {
726 ColorScope Color(*this, DeclKindNameColor);
727 OS << D->getDeclKindName() << "Decl";
728 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000729 dumpPointer(D);
Richard Smithf5f43542013-02-07 01:35:44 +0000730 if (D->getLexicalDeclContext() != D->getDeclContext())
731 OS << " parent " << cast<Decl>(D->getDeclContext());
732 if (const Decl *Prev = getPreviousDecl(D))
733 OS << " prev " << Prev;
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000734 dumpSourceRange(D->getSourceRange());
Richard Trieude5cc7d2013-01-31 01:44:26 +0000735
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000736 bool HasAttrs = D->attr_begin() != D->attr_end();
Richard Smithb39b9d52013-05-21 05:24:00 +0000737 const FullComment *Comment =
738 D->getASTContext().getLocalCommentForDeclUncached(D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000739 // Decls within functions are visited by the body
Richard Trieude5cc7d2013-01-31 01:44:26 +0000740 bool HasDeclContext = !isa<FunctionDecl>(*D) && !isa<ObjCMethodDecl>(*D) &&
741 hasNodes(dyn_cast<DeclContext>(D));
742
Richard Smithb39b9d52013-05-21 05:24:00 +0000743 setMoreChildren(HasAttrs || Comment || HasDeclContext);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000744 ConstDeclVisitor<ASTDumper>::Visit(D);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000745
Richard Smithb39b9d52013-05-21 05:24:00 +0000746 setMoreChildren(Comment || HasDeclContext);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000747 for (Decl::attr_iterator I = D->attr_begin(), E = D->attr_end();
748 I != E; ++I) {
749 if (I + 1 == E)
750 lastChild();
751 dumpAttr(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000752 }
753
754 setMoreChildren(HasDeclContext);
755 lastChild();
Richard Smithb39b9d52013-05-21 05:24:00 +0000756 dumpFullComment(Comment);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000757
Nick Lewyckya382db02013-08-27 03:15:56 +0000758 if (D->isInvalidDecl())
759 OS << " invalid";
760
Richard Trieude5cc7d2013-01-31 01:44:26 +0000761 setMoreChildren(false);
762 if (HasDeclContext)
Richard Smithf5f43542013-02-07 01:35:44 +0000763 dumpDeclContext(cast<DeclContext>(D));
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000764}
765
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000766void ASTDumper::VisitLabelDecl(const LabelDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000767 dumpName(D);
768}
769
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000770void ASTDumper::VisitTypedefDecl(const TypedefDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000771 dumpName(D);
772 dumpType(D->getUnderlyingType());
773 if (D->isModulePrivate())
774 OS << " __module_private__";
775}
776
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000777void ASTDumper::VisitEnumDecl(const EnumDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000778 if (D->isScoped()) {
779 if (D->isScopedUsingClassTag())
780 OS << " class";
781 else
782 OS << " struct";
783 }
784 dumpName(D);
785 if (D->isModulePrivate())
786 OS << " __module_private__";
787 if (D->isFixed())
788 dumpType(D->getIntegerType());
789}
790
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000791void ASTDumper::VisitRecordDecl(const RecordDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000792 OS << ' ' << D->getKindName();
793 dumpName(D);
794 if (D->isModulePrivate())
795 OS << " __module_private__";
Richard Smith99bc1b92013-08-30 05:32:29 +0000796 if (D->isCompleteDefinition())
797 OS << " definition";
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000798}
799
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000800void ASTDumper::VisitEnumConstantDecl(const EnumConstantDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000801 dumpName(D);
802 dumpType(D->getType());
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000803 if (const Expr *Init = D->getInitExpr()) {
Richard Trieude5cc7d2013-01-31 01:44:26 +0000804 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000805 dumpStmt(Init);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000806 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000807}
808
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000809void ASTDumper::VisitIndirectFieldDecl(const IndirectFieldDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000810 dumpName(D);
811 dumpType(D->getType());
812 for (IndirectFieldDecl::chain_iterator I = D->chain_begin(),
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000813 E = D->chain_end();
814 I != E; ++I) {
Richard Trieude5cc7d2013-01-31 01:44:26 +0000815 if (I + 1 == E)
816 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000817 dumpDeclRef(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000818 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000819}
820
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000821void ASTDumper::VisitFunctionDecl(const FunctionDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000822 dumpName(D);
823 dumpType(D->getType());
824
Rafael Espindola6ae7e502013-04-03 19:27:57 +0000825 StorageClass SC = D->getStorageClass();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000826 if (SC != SC_None)
827 OS << ' ' << VarDecl::getStorageClassSpecifierString(SC);
828 if (D->isInlineSpecified())
829 OS << " inline";
830 if (D->isVirtualAsWritten())
831 OS << " virtual";
832 if (D->isModulePrivate())
833 OS << " __module_private__";
834
835 if (D->isPure())
836 OS << " pure";
837 else if (D->isDeletedAsWritten())
838 OS << " delete";
839
Richard Smithadaa0152013-05-17 02:09:46 +0000840 if (const FunctionProtoType *FPT = D->getType()->getAs<FunctionProtoType>()) {
841 FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo();
842 switch (EPI.ExceptionSpecType) {
843 default: break;
844 case EST_Unevaluated:
845 OS << " noexcept-unevaluated " << EPI.ExceptionSpecDecl;
846 break;
847 case EST_Uninstantiated:
848 OS << " noexcept-uninstantiated " << EPI.ExceptionSpecTemplate;
849 break;
850 }
851 }
852
Richard Trieude5cc7d2013-01-31 01:44:26 +0000853 bool OldMoreChildren = hasMoreChildren();
854 const FunctionTemplateSpecializationInfo *FTSI =
855 D->getTemplateSpecializationInfo();
856 bool HasTemplateSpecialization = FTSI;
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000857
Richard Trieude5cc7d2013-01-31 01:44:26 +0000858 bool HasNamedDecls = D->getDeclsInPrototypeScope().begin() !=
859 D->getDeclsInPrototypeScope().end();
860
861 bool HasFunctionDecls = D->param_begin() != D->param_end();
862
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000863 const CXXConstructorDecl *C = dyn_cast<CXXConstructorDecl>(D);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000864 bool HasCtorInitializers = C && C->init_begin() != C->init_end();
865
866 bool HasDeclarationBody = D->doesThisDeclarationHaveABody();
867
868 setMoreChildren(OldMoreChildren || HasNamedDecls || HasFunctionDecls ||
869 HasCtorInitializers || HasDeclarationBody);
870 if (HasTemplateSpecialization) {
871 lastChild();
872 dumpTemplateArgumentList(*FTSI->TemplateArguments);
873 }
874
875 setMoreChildren(OldMoreChildren || HasFunctionDecls ||
876 HasCtorInitializers || HasDeclarationBody);
Dmitri Gribenkof8579502013-01-12 19:30:44 +0000877 for (ArrayRef<NamedDecl *>::iterator
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000878 I = D->getDeclsInPrototypeScope().begin(),
Richard Trieude5cc7d2013-01-31 01:44:26 +0000879 E = D->getDeclsInPrototypeScope().end(); I != E; ++I) {
880 if (I + 1 == E)
881 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000882 dumpDecl(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000883 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000884
Richard Trieude5cc7d2013-01-31 01:44:26 +0000885 setMoreChildren(OldMoreChildren || HasCtorInitializers || HasDeclarationBody);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000886 for (FunctionDecl::param_const_iterator I = D->param_begin(),
887 E = D->param_end();
Richard Trieude5cc7d2013-01-31 01:44:26 +0000888 I != E; ++I) {
889 if (I + 1 == E)
890 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000891 dumpDecl(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000892 }
893
894 setMoreChildren(OldMoreChildren || HasDeclarationBody);
895 if (HasCtorInitializers)
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000896 for (CXXConstructorDecl::init_const_iterator I = C->init_begin(),
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000897 E = C->init_end();
898 I != E; ++I) {
Richard Trieude5cc7d2013-01-31 01:44:26 +0000899 if (I + 1 == E)
900 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000901 dumpCXXCtorInitializer(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000902 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000903
Richard Trieude5cc7d2013-01-31 01:44:26 +0000904 setMoreChildren(OldMoreChildren);
905 if (HasDeclarationBody) {
906 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000907 dumpStmt(D->getBody());
Richard Trieude5cc7d2013-01-31 01:44:26 +0000908 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000909}
910
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000911void ASTDumper::VisitFieldDecl(const FieldDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000912 dumpName(D);
913 dumpType(D->getType());
914 if (D->isMutable())
915 OS << " mutable";
916 if (D->isModulePrivate())
917 OS << " __module_private__";
Richard Trieude5cc7d2013-01-31 01:44:26 +0000918
919 bool OldMoreChildren = hasMoreChildren();
920 bool IsBitField = D->isBitField();
921 Expr *Init = D->getInClassInitializer();
922 bool HasInit = Init;
923
924 setMoreChildren(OldMoreChildren || HasInit);
925 if (IsBitField) {
926 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000927 dumpStmt(D->getBitWidth());
Richard Trieude5cc7d2013-01-31 01:44:26 +0000928 }
929 setMoreChildren(OldMoreChildren);
930 if (HasInit) {
931 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000932 dumpStmt(Init);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000933 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000934}
935
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000936void ASTDumper::VisitVarDecl(const VarDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000937 dumpName(D);
938 dumpType(D->getType());
Rafael Espindola6ae7e502013-04-03 19:27:57 +0000939 StorageClass SC = D->getStorageClass();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000940 if (SC != SC_None)
941 OS << ' ' << VarDecl::getStorageClassSpecifierString(SC);
Richard Smithfd3834f2013-04-13 02:43:54 +0000942 switch (D->getTLSKind()) {
943 case VarDecl::TLS_None: break;
944 case VarDecl::TLS_Static: OS << " tls"; break;
945 case VarDecl::TLS_Dynamic: OS << " tls_dynamic"; break;
946 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000947 if (D->isModulePrivate())
948 OS << " __module_private__";
949 if (D->isNRVOVariable())
950 OS << " nrvo";
Richard Trieude5cc7d2013-01-31 01:44:26 +0000951 if (D->hasInit()) {
952 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000953 dumpStmt(D->getInit());
Richard Trieude5cc7d2013-01-31 01:44:26 +0000954 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000955}
956
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000957void ASTDumper::VisitFileScopeAsmDecl(const FileScopeAsmDecl *D) {
Richard Trieude5cc7d2013-01-31 01:44:26 +0000958 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000959 dumpStmt(D->getAsmString());
960}
961
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000962void ASTDumper::VisitImportDecl(const ImportDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000963 OS << ' ' << D->getImportedModule()->getFullModuleName();
964}
965
966//===----------------------------------------------------------------------===//
967// C++ Declarations
968//===----------------------------------------------------------------------===//
969
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000970void ASTDumper::VisitNamespaceDecl(const NamespaceDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000971 dumpName(D);
972 if (D->isInline())
973 OS << " inline";
974 if (!D->isOriginalNamespace())
975 dumpDeclRef(D->getOriginalNamespace(), "original");
976}
977
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000978void ASTDumper::VisitUsingDirectiveDecl(const UsingDirectiveDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000979 OS << ' ';
980 dumpBareDeclRef(D->getNominatedNamespace());
981}
982
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000983void ASTDumper::VisitNamespaceAliasDecl(const NamespaceAliasDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000984 dumpName(D);
985 dumpDeclRef(D->getAliasedNamespace());
986}
987
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000988void ASTDumper::VisitTypeAliasDecl(const TypeAliasDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000989 dumpName(D);
990 dumpType(D->getUnderlyingType());
991}
992
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000993void ASTDumper::VisitTypeAliasTemplateDecl(const TypeAliasTemplateDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000994 dumpName(D);
995 dumpTemplateParameters(D->getTemplateParameters());
996 dumpDecl(D->getTemplatedDecl());
997}
998
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000999void ASTDumper::VisitCXXRecordDecl(const CXXRecordDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001000 VisitRecordDecl(D);
1001 if (!D->isCompleteDefinition())
1002 return;
1003
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001004 for (CXXRecordDecl::base_class_const_iterator I = D->bases_begin(),
1005 E = D->bases_end();
1006 I != E; ++I) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001007 IndentScope Indent(*this);
1008 if (I->isVirtual())
1009 OS << "virtual ";
1010 dumpAccessSpecifier(I->getAccessSpecifier());
1011 dumpType(I->getType());
1012 if (I->isPackExpansion())
1013 OS << "...";
1014 }
1015}
1016
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001017void ASTDumper::VisitStaticAssertDecl(const StaticAssertDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001018 dumpStmt(D->getAssertExpr());
Richard Trieude5cc7d2013-01-31 01:44:26 +00001019 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001020 dumpStmt(D->getMessage());
1021}
1022
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001023void ASTDumper::VisitFunctionTemplateDecl(const FunctionTemplateDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001024 dumpName(D);
1025 dumpTemplateParameters(D->getTemplateParameters());
1026 dumpDecl(D->getTemplatedDecl());
Dmitri Gribenko81f25752013-02-14 13:20:36 +00001027 for (FunctionTemplateDecl::spec_iterator I = D->spec_begin(),
1028 E = D->spec_end();
1029 I != E; ++I) {
Richard Trieude5cc7d2013-01-31 01:44:26 +00001030 FunctionTemplateDecl::spec_iterator Next = I;
1031 ++Next;
1032 if (Next == E)
1033 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001034 switch (I->getTemplateSpecializationKind()) {
1035 case TSK_Undeclared:
1036 case TSK_ImplicitInstantiation:
1037 case TSK_ExplicitInstantiationDeclaration:
1038 case TSK_ExplicitInstantiationDefinition:
Dmitri Gribenkoefc6dfb2013-02-21 22:01:10 +00001039 if (D == D->getCanonicalDecl())
1040 dumpDecl(*I);
1041 else
1042 dumpDeclRef(*I);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001043 break;
1044 case TSK_ExplicitSpecialization:
1045 dumpDeclRef(*I);
1046 break;
1047 }
1048 }
1049}
1050
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001051void ASTDumper::VisitClassTemplateDecl(const ClassTemplateDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001052 dumpName(D);
1053 dumpTemplateParameters(D->getTemplateParameters());
Richard Trieude5cc7d2013-01-31 01:44:26 +00001054
Dmitri Gribenko81f25752013-02-14 13:20:36 +00001055 ClassTemplateDecl::spec_iterator I = D->spec_begin();
1056 ClassTemplateDecl::spec_iterator E = D->spec_end();
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001057 if (I == E)
Richard Trieude5cc7d2013-01-31 01:44:26 +00001058 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001059 dumpDecl(D->getTemplatedDecl());
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001060 for (; I != E; ++I) {
Richard Trieude5cc7d2013-01-31 01:44:26 +00001061 ClassTemplateDecl::spec_iterator Next = I;
1062 ++Next;
1063 if (Next == E)
1064 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001065 switch (I->getTemplateSpecializationKind()) {
1066 case TSK_Undeclared:
1067 case TSK_ImplicitInstantiation:
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 case TSK_ExplicitInstantiationDeclaration:
1075 case TSK_ExplicitInstantiationDefinition:
1076 dumpDeclRef(*I);
1077 break;
1078 }
1079 }
1080}
1081
1082void ASTDumper::VisitClassTemplateSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001083 const ClassTemplateSpecializationDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001084 VisitCXXRecordDecl(D);
1085 dumpTemplateArgumentList(D->getTemplateArgs());
1086}
1087
1088void ASTDumper::VisitClassTemplatePartialSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001089 const ClassTemplatePartialSpecializationDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001090 VisitClassTemplateSpecializationDecl(D);
1091 dumpTemplateParameters(D->getTemplateParameters());
1092}
1093
1094void ASTDumper::VisitClassScopeFunctionSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001095 const ClassScopeFunctionSpecializationDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001096 dumpDeclRef(D->getSpecialization());
1097 if (D->hasExplicitTemplateArgs())
1098 dumpTemplateArgumentListInfo(D->templateArgs());
1099}
1100
Richard Smithd25789a2013-09-18 01:36:02 +00001101void ASTDumper::VisitVarTemplateDecl(const VarTemplateDecl *D) {
1102 dumpName(D);
1103 dumpTemplateParameters(D->getTemplateParameters());
1104
1105 VarTemplateDecl::spec_iterator I = D->spec_begin();
1106 VarTemplateDecl::spec_iterator E = D->spec_end();
1107 if (I == E)
1108 lastChild();
1109 dumpDecl(D->getTemplatedDecl());
1110 for (; I != E; ++I) {
1111 VarTemplateDecl::spec_iterator Next = I;
1112 ++Next;
1113 if (Next == E)
1114 lastChild();
1115 switch (I->getTemplateSpecializationKind()) {
1116 case TSK_Undeclared:
1117 case TSK_ImplicitInstantiation:
1118 if (D == D->getCanonicalDecl())
1119 dumpDecl(*I);
1120 else
1121 dumpDeclRef(*I);
1122 break;
1123 case TSK_ExplicitSpecialization:
1124 case TSK_ExplicitInstantiationDeclaration:
1125 case TSK_ExplicitInstantiationDefinition:
1126 dumpDeclRef(*I);
1127 break;
1128 }
1129 }
1130}
1131
1132void ASTDumper::VisitVarTemplateSpecializationDecl(
1133 const VarTemplateSpecializationDecl *D) {
1134 dumpTemplateArgumentList(D->getTemplateArgs());
1135 VisitVarDecl(D);
1136}
1137
1138void ASTDumper::VisitVarTemplatePartialSpecializationDecl(
1139 const VarTemplatePartialSpecializationDecl *D) {
1140 dumpTemplateParameters(D->getTemplateParameters());
1141 VisitVarTemplateSpecializationDecl(D);
1142}
1143
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001144void ASTDumper::VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001145 if (D->wasDeclaredWithTypename())
1146 OS << " typename";
1147 else
1148 OS << " class";
1149 if (D->isParameterPack())
1150 OS << " ...";
1151 dumpName(D);
1152 if (D->hasDefaultArgument())
1153 dumpType(D->getDefaultArgument());
1154}
1155
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001156void ASTDumper::VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001157 dumpType(D->getType());
1158 if (D->isParameterPack())
1159 OS << " ...";
1160 dumpName(D);
1161 if (D->hasDefaultArgument())
1162 dumpStmt(D->getDefaultArgument());
1163}
1164
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001165void ASTDumper::VisitTemplateTemplateParmDecl(
1166 const TemplateTemplateParmDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001167 if (D->isParameterPack())
1168 OS << " ...";
1169 dumpName(D);
1170 dumpTemplateParameters(D->getTemplateParameters());
1171 if (D->hasDefaultArgument())
1172 dumpTemplateArgumentLoc(D->getDefaultArgument());
1173}
1174
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001175void ASTDumper::VisitUsingDecl(const UsingDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001176 OS << ' ';
1177 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
1178 OS << D->getNameAsString();
1179}
1180
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001181void ASTDumper::VisitUnresolvedUsingTypenameDecl(
1182 const UnresolvedUsingTypenameDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001183 OS << ' ';
1184 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
1185 OS << D->getNameAsString();
1186}
1187
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001188void ASTDumper::VisitUnresolvedUsingValueDecl(const UnresolvedUsingValueDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001189 OS << ' ';
1190 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
1191 OS << D->getNameAsString();
1192 dumpType(D->getType());
1193}
1194
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001195void ASTDumper::VisitUsingShadowDecl(const UsingShadowDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001196 OS << ' ';
1197 dumpBareDeclRef(D->getTargetDecl());
1198}
1199
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001200void ASTDumper::VisitLinkageSpecDecl(const LinkageSpecDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001201 switch (D->getLanguage()) {
1202 case LinkageSpecDecl::lang_c: OS << " C"; break;
1203 case LinkageSpecDecl::lang_cxx: OS << " C++"; break;
1204 }
1205}
1206
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001207void ASTDumper::VisitAccessSpecDecl(const AccessSpecDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001208 OS << ' ';
1209 dumpAccessSpecifier(D->getAccess());
1210}
1211
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001212void ASTDumper::VisitFriendDecl(const FriendDecl *D) {
Richard Smithf5f43542013-02-07 01:35:44 +00001213 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001214 if (TypeSourceInfo *T = D->getFriendType())
1215 dumpType(T->getType());
1216 else
1217 dumpDecl(D->getFriendDecl());
1218}
1219
1220//===----------------------------------------------------------------------===//
1221// Obj-C Declarations
1222//===----------------------------------------------------------------------===//
1223
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001224void ASTDumper::VisitObjCIvarDecl(const ObjCIvarDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001225 dumpName(D);
1226 dumpType(D->getType());
1227 if (D->getSynthesize())
1228 OS << " synthesize";
1229
1230 switch (D->getAccessControl()) {
1231 case ObjCIvarDecl::None:
1232 OS << " none";
1233 break;
1234 case ObjCIvarDecl::Private:
1235 OS << " private";
1236 break;
1237 case ObjCIvarDecl::Protected:
1238 OS << " protected";
1239 break;
1240 case ObjCIvarDecl::Public:
1241 OS << " public";
1242 break;
1243 case ObjCIvarDecl::Package:
1244 OS << " package";
1245 break;
1246 }
1247}
1248
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001249void ASTDumper::VisitObjCMethodDecl(const ObjCMethodDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001250 if (D->isInstanceMethod())
1251 OS << " -";
1252 else
1253 OS << " +";
1254 dumpName(D);
1255 dumpType(D->getResultType());
1256
Richard Trieude5cc7d2013-01-31 01:44:26 +00001257 bool OldMoreChildren = hasMoreChildren();
1258 bool IsVariadic = D->isVariadic();
1259 bool HasBody = D->hasBody();
1260
1261 setMoreChildren(OldMoreChildren || IsVariadic || HasBody);
1262 if (D->isThisDeclarationADefinition()) {
1263 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001264 dumpDeclContext(D);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001265 } else {
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001266 for (ObjCMethodDecl::param_const_iterator I = D->param_begin(),
1267 E = D->param_end();
1268 I != E; ++I) {
Richard Trieude5cc7d2013-01-31 01:44:26 +00001269 if (I + 1 == E)
1270 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001271 dumpDecl(*I);
1272 }
1273 }
1274
Richard Trieude5cc7d2013-01-31 01:44:26 +00001275 setMoreChildren(OldMoreChildren || HasBody);
1276 if (IsVariadic) {
1277 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001278 IndentScope Indent(*this);
1279 OS << "...";
1280 }
1281
Richard Trieude5cc7d2013-01-31 01:44:26 +00001282 setMoreChildren(OldMoreChildren);
1283 if (HasBody) {
1284 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001285 dumpStmt(D->getBody());
Richard Trieude5cc7d2013-01-31 01:44:26 +00001286 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001287}
1288
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001289void ASTDumper::VisitObjCCategoryDecl(const ObjCCategoryDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001290 dumpName(D);
1291 dumpDeclRef(D->getClassInterface());
Richard Trieude5cc7d2013-01-31 01:44:26 +00001292 if (D->protocol_begin() == D->protocol_end())
1293 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001294 dumpDeclRef(D->getImplementation());
1295 for (ObjCCategoryDecl::protocol_iterator I = D->protocol_begin(),
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001296 E = D->protocol_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 dumpDeclRef(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001301 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001302}
1303
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001304void ASTDumper::VisitObjCCategoryImplDecl(const ObjCCategoryImplDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001305 dumpName(D);
1306 dumpDeclRef(D->getClassInterface());
Richard Trieude5cc7d2013-01-31 01:44:26 +00001307 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001308 dumpDeclRef(D->getCategoryDecl());
1309}
1310
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001311void ASTDumper::VisitObjCProtocolDecl(const ObjCProtocolDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001312 dumpName(D);
1313 for (ObjCProtocolDecl::protocol_iterator I = D->protocol_begin(),
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001314 E = D->protocol_end();
1315 I != E; ++I) {
Richard Trieude5cc7d2013-01-31 01:44:26 +00001316 if (I + 1 == E)
1317 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001318 dumpDeclRef(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001319 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001320}
1321
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001322void ASTDumper::VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001323 dumpName(D);
1324 dumpDeclRef(D->getSuperClass(), "super");
Richard Trieude5cc7d2013-01-31 01:44:26 +00001325 if (D->protocol_begin() == D->protocol_end())
1326 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001327 dumpDeclRef(D->getImplementation());
1328 for (ObjCInterfaceDecl::protocol_iterator I = D->protocol_begin(),
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001329 E = D->protocol_end();
1330 I != E; ++I) {
Richard Trieude5cc7d2013-01-31 01:44:26 +00001331 if (I + 1 == E)
1332 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001333 dumpDeclRef(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001334 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001335}
1336
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001337void ASTDumper::VisitObjCImplementationDecl(const ObjCImplementationDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001338 dumpName(D);
1339 dumpDeclRef(D->getSuperClass(), "super");
Richard Trieude5cc7d2013-01-31 01:44:26 +00001340 if (D->init_begin() == D->init_end())
1341 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001342 dumpDeclRef(D->getClassInterface());
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001343 for (ObjCImplementationDecl::init_const_iterator I = D->init_begin(),
1344 E = D->init_end();
1345 I != E; ++I) {
Richard Trieude5cc7d2013-01-31 01:44:26 +00001346 if (I + 1 == E)
1347 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001348 dumpCXXCtorInitializer(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001349 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001350}
1351
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001352void ASTDumper::VisitObjCCompatibleAliasDecl(const ObjCCompatibleAliasDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001353 dumpName(D);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001354 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001355 dumpDeclRef(D->getClassInterface());
1356}
1357
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001358void ASTDumper::VisitObjCPropertyDecl(const ObjCPropertyDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001359 dumpName(D);
1360 dumpType(D->getType());
1361
1362 if (D->getPropertyImplementation() == ObjCPropertyDecl::Required)
1363 OS << " required";
1364 else if (D->getPropertyImplementation() == ObjCPropertyDecl::Optional)
1365 OS << " optional";
1366
1367 ObjCPropertyDecl::PropertyAttributeKind Attrs = D->getPropertyAttributes();
1368 if (Attrs != ObjCPropertyDecl::OBJC_PR_noattr) {
1369 if (Attrs & ObjCPropertyDecl::OBJC_PR_readonly)
1370 OS << " readonly";
1371 if (Attrs & ObjCPropertyDecl::OBJC_PR_assign)
1372 OS << " assign";
1373 if (Attrs & ObjCPropertyDecl::OBJC_PR_readwrite)
1374 OS << " readwrite";
1375 if (Attrs & ObjCPropertyDecl::OBJC_PR_retain)
1376 OS << " retain";
1377 if (Attrs & ObjCPropertyDecl::OBJC_PR_copy)
1378 OS << " copy";
1379 if (Attrs & ObjCPropertyDecl::OBJC_PR_nonatomic)
1380 OS << " nonatomic";
1381 if (Attrs & ObjCPropertyDecl::OBJC_PR_atomic)
1382 OS << " atomic";
1383 if (Attrs & ObjCPropertyDecl::OBJC_PR_weak)
1384 OS << " weak";
1385 if (Attrs & ObjCPropertyDecl::OBJC_PR_strong)
1386 OS << " strong";
1387 if (Attrs & ObjCPropertyDecl::OBJC_PR_unsafe_unretained)
1388 OS << " unsafe_unretained";
Richard Trieude5cc7d2013-01-31 01:44:26 +00001389 if (Attrs & ObjCPropertyDecl::OBJC_PR_getter) {
1390 if (!(Attrs & ObjCPropertyDecl::OBJC_PR_setter))
1391 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001392 dumpDeclRef(D->getGetterMethodDecl(), "getter");
Richard Trieude5cc7d2013-01-31 01:44:26 +00001393 }
1394 if (Attrs & ObjCPropertyDecl::OBJC_PR_setter) {
1395 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001396 dumpDeclRef(D->getSetterMethodDecl(), "setter");
Richard Trieude5cc7d2013-01-31 01:44:26 +00001397 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001398 }
1399}
1400
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001401void ASTDumper::VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001402 dumpName(D->getPropertyDecl());
1403 if (D->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize)
1404 OS << " synthesize";
1405 else
1406 OS << " dynamic";
1407 dumpDeclRef(D->getPropertyDecl());
Richard Trieude5cc7d2013-01-31 01:44:26 +00001408 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001409 dumpDeclRef(D->getPropertyIvarDecl());
1410}
1411
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001412void ASTDumper::VisitBlockDecl(const BlockDecl *D) {
1413 for (BlockDecl::param_const_iterator I = D->param_begin(), E = D->param_end();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001414 I != E; ++I)
1415 dumpDecl(*I);
1416
1417 if (D->isVariadic()) {
1418 IndentScope Indent(*this);
1419 OS << "...";
1420 }
1421
1422 if (D->capturesCXXThis()) {
1423 IndentScope Indent(*this);
1424 OS << "capture this";
1425 }
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001426 for (BlockDecl::capture_iterator I = D->capture_begin(), E = D->capture_end();
1427 I != E; ++I) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001428 IndentScope Indent(*this);
1429 OS << "capture";
1430 if (I->isByRef())
1431 OS << " byref";
1432 if (I->isNested())
1433 OS << " nested";
1434 if (I->getVariable()) {
1435 OS << ' ';
1436 dumpBareDeclRef(I->getVariable());
1437 }
1438 if (I->hasCopyExpr())
1439 dumpStmt(I->getCopyExpr());
1440 }
Richard Trieude5cc7d2013-01-31 01:44:26 +00001441 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001442 dumpStmt(D->getBody());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001443}
1444
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001445//===----------------------------------------------------------------------===//
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001446// Stmt dumping methods.
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001447//===----------------------------------------------------------------------===//
1448
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001449void ASTDumper::dumpStmt(const Stmt *S) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001450 IndentScope Indent(*this);
1451
1452 if (!S) {
Richard Trieud215b8d2013-01-26 01:31:20 +00001453 ColorScope Color(*this, NullColor);
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001454 OS << "<<<NULL>>>";
1455 return;
1456 }
1457
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001458 if (const DeclStmt *DS = dyn_cast<DeclStmt>(S)) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001459 VisitDeclStmt(DS);
1460 return;
1461 }
1462
David Blaikie7d170102013-05-15 07:37:26 +00001463 setMoreChildren(!S->children().empty());
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001464 ConstStmtVisitor<ASTDumper>::Visit(S);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001465 setMoreChildren(false);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001466 for (Stmt::const_child_range CI = S->children(); CI; ++CI) {
1467 Stmt::const_child_range Next = CI;
Richard Trieude5cc7d2013-01-31 01:44:26 +00001468 ++Next;
1469 if (!Next)
1470 lastChild();
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001471 dumpStmt(*CI);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001472 }
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001473}
1474
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001475void ASTDumper::VisitStmt(const Stmt *Node) {
Richard Trieud215b8d2013-01-26 01:31:20 +00001476 {
1477 ColorScope Color(*this, StmtColor);
1478 OS << Node->getStmtClassName();
1479 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001480 dumpPointer(Node);
1481 dumpSourceRange(Node->getSourceRange());
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001482}
1483
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001484void ASTDumper::VisitDeclStmt(const DeclStmt *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001485 VisitStmt(Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001486 for (DeclStmt::const_decl_iterator I = Node->decl_begin(),
1487 E = Node->decl_end();
Richard Trieude5cc7d2013-01-31 01:44:26 +00001488 I != E; ++I) {
1489 if (I + 1 == E)
1490 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001491 dumpDecl(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001492 }
Ted Kremenek433a4922007-12-12 06:59:42 +00001493}
1494
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001495void ASTDumper::VisitAttributedStmt(const AttributedStmt *Node) {
Alexander Kornienko5bc364e2013-01-07 17:53:08 +00001496 VisitStmt(Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001497 for (ArrayRef<const Attr *>::iterator I = Node->getAttrs().begin(),
1498 E = Node->getAttrs().end();
1499 I != E; ++I) {
Richard Trieude5cc7d2013-01-31 01:44:26 +00001500 if (I + 1 == E)
1501 lastChild();
Alexander Kornienko5bc364e2013-01-07 17:53:08 +00001502 dumpAttr(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001503 }
Alexander Kornienko5bc364e2013-01-07 17:53:08 +00001504}
1505
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001506void ASTDumper::VisitLabelStmt(const LabelStmt *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001507 VisitStmt(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001508 OS << " '" << Node->getName() << "'";
Chris Lattnercbe4f772007-08-08 22:51:59 +00001509}
1510
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001511void ASTDumper::VisitGotoStmt(const GotoStmt *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001512 VisitStmt(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001513 OS << " '" << Node->getLabel()->getName() << "'";
1514 dumpPointer(Node->getLabel());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001515}
1516
Pavel Labath1ef83422013-09-04 14:35:00 +00001517void ASTDumper::VisitCXXCatchStmt(const CXXCatchStmt *Node) {
1518 VisitStmt(Node);
1519 dumpDecl(Node->getExceptionDecl());
1520}
1521
Chris Lattnercbe4f772007-08-08 22:51:59 +00001522//===----------------------------------------------------------------------===//
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001523// Expr dumping methods.
Chris Lattnercbe4f772007-08-08 22:51:59 +00001524//===----------------------------------------------------------------------===//
1525
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001526void ASTDumper::VisitExpr(const Expr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001527 VisitStmt(Node);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001528 dumpType(Node->getType());
1529
Richard Trieud215b8d2013-01-26 01:31:20 +00001530 {
1531 ColorScope Color(*this, ValueKindColor);
1532 switch (Node->getValueKind()) {
1533 case VK_RValue:
1534 break;
1535 case VK_LValue:
1536 OS << " lvalue";
1537 break;
1538 case VK_XValue:
1539 OS << " xvalue";
1540 break;
1541 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001542 }
1543
Richard Trieud215b8d2013-01-26 01:31:20 +00001544 {
1545 ColorScope Color(*this, ObjectKindColor);
1546 switch (Node->getObjectKind()) {
1547 case OK_Ordinary:
1548 break;
1549 case OK_BitField:
1550 OS << " bitfield";
1551 break;
1552 case OK_ObjCProperty:
1553 OS << " objcproperty";
1554 break;
1555 case OK_ObjCSubscript:
1556 OS << " objcsubscript";
1557 break;
1558 case OK_VectorComponent:
1559 OS << " vectorcomponent";
1560 break;
1561 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001562 }
Chris Lattnercbe4f772007-08-08 22:51:59 +00001563}
1564
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001565static void dumpBasePath(raw_ostream &OS, const CastExpr *Node) {
John McCallcf142162010-08-07 06:22:56 +00001566 if (Node->path_empty())
Anders Carlssona70cff62010-04-24 19:06:50 +00001567 return;
1568
1569 OS << " (";
1570 bool First = true;
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001571 for (CastExpr::path_const_iterator I = Node->path_begin(),
1572 E = Node->path_end();
1573 I != E; ++I) {
Anders Carlssona70cff62010-04-24 19:06:50 +00001574 const CXXBaseSpecifier *Base = *I;
1575 if (!First)
1576 OS << " -> ";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001577
Anders Carlssona70cff62010-04-24 19:06:50 +00001578 const CXXRecordDecl *RD =
1579 cast<CXXRecordDecl>(Base->getType()->getAs<RecordType>()->getDecl());
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001580
Anders Carlssona70cff62010-04-24 19:06:50 +00001581 if (Base->isVirtual())
1582 OS << "virtual ";
1583 OS << RD->getName();
1584 First = false;
1585 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001586
Anders Carlssona70cff62010-04-24 19:06:50 +00001587 OS << ')';
1588}
1589
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001590void ASTDumper::VisitCastExpr(const CastExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001591 VisitExpr(Node);
Richard Trieud215b8d2013-01-26 01:31:20 +00001592 OS << " <";
1593 {
1594 ColorScope Color(*this, CastColor);
1595 OS << Node->getCastKindName();
1596 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001597 dumpBasePath(OS, Node);
Anders Carlssona70cff62010-04-24 19:06:50 +00001598 OS << ">";
Anders Carlssond7923c62009-08-22 23:33:40 +00001599}
1600
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001601void ASTDumper::VisitDeclRefExpr(const DeclRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001602 VisitExpr(Node);
Ted Kremenek5f64ca82007-09-10 17:32:55 +00001603
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001604 OS << " ";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001605 dumpBareDeclRef(Node->getDecl());
Chandler Carruth8d26bb02011-05-01 23:48:14 +00001606 if (Node->getDecl() != Node->getFoundDecl()) {
1607 OS << " (";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001608 dumpBareDeclRef(Node->getFoundDecl());
Chandler Carruth8d26bb02011-05-01 23:48:14 +00001609 OS << ")";
1610 }
John McCall351762c2011-02-07 10:33:21 +00001611}
1612
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001613void ASTDumper::VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001614 VisitExpr(Node);
John McCall76d09942009-12-11 21:50:11 +00001615 OS << " (";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001616 if (!Node->requiresADL())
1617 OS << "no ";
Benjamin Kramerb11416d2010-04-17 09:33:03 +00001618 OS << "ADL) = '" << Node->getName() << '\'';
John McCall76d09942009-12-11 21:50:11 +00001619
1620 UnresolvedLookupExpr::decls_iterator
1621 I = Node->decls_begin(), E = Node->decls_end();
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001622 if (I == E)
1623 OS << " empty";
John McCall76d09942009-12-11 21:50:11 +00001624 for (; I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001625 dumpPointer(*I);
John McCall76d09942009-12-11 21:50:11 +00001626}
1627
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001628void ASTDumper::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001629 VisitExpr(Node);
Steve Naroff5d5efca2008-03-12 13:19:12 +00001630
Richard Trieud215b8d2013-01-26 01:31:20 +00001631 {
1632 ColorScope Color(*this, DeclKindNameColor);
1633 OS << " " << Node->getDecl()->getDeclKindName() << "Decl";
1634 }
1635 OS << "='" << *Node->getDecl() << "'";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001636 dumpPointer(Node->getDecl());
Steve Naroffb3424a92008-05-23 22:01:24 +00001637 if (Node->isFreeIvar())
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001638 OS << " isFreeIvar";
Steve Naroff5d5efca2008-03-12 13:19:12 +00001639}
1640
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001641void ASTDumper::VisitPredefinedExpr(const PredefinedExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001642 VisitExpr(Node);
Chris Lattnercbe4f772007-08-08 22:51:59 +00001643 switch (Node->getIdentType()) {
David Blaikie83d382b2011-09-23 05:06:16 +00001644 default: llvm_unreachable("unknown case");
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001645 case PredefinedExpr::Func: OS << " __func__"; break;
1646 case PredefinedExpr::Function: OS << " __FUNCTION__"; break;
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001647 case PredefinedExpr::LFunction: OS << " L__FUNCTION__"; break;
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001648 case PredefinedExpr::PrettyFunction: OS << " __PRETTY_FUNCTION__";break;
Chris Lattnercbe4f772007-08-08 22:51:59 +00001649 }
1650}
1651
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001652void ASTDumper::VisitCharacterLiteral(const CharacterLiteral *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001653 VisitExpr(Node);
Richard Trieud215b8d2013-01-26 01:31:20 +00001654 ColorScope Color(*this, ValueColor);
Richard Trieu364ee422011-11-03 23:56:23 +00001655 OS << " " << Node->getValue();
Chris Lattnercbe4f772007-08-08 22:51:59 +00001656}
1657
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001658void ASTDumper::VisitIntegerLiteral(const IntegerLiteral *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001659 VisitExpr(Node);
Chris Lattnercbe4f772007-08-08 22:51:59 +00001660
1661 bool isSigned = Node->getType()->isSignedIntegerType();
Richard Trieud215b8d2013-01-26 01:31:20 +00001662 ColorScope Color(*this, ValueColor);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001663 OS << " " << Node->getValue().toString(10, isSigned);
Chris Lattnercbe4f772007-08-08 22:51:59 +00001664}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001665
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001666void ASTDumper::VisitFloatingLiteral(const FloatingLiteral *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001667 VisitExpr(Node);
Richard Trieud215b8d2013-01-26 01:31:20 +00001668 ColorScope Color(*this, ValueColor);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001669 OS << " " << Node->getValueAsApproximateDouble();
Chris Lattnercbe4f772007-08-08 22:51:59 +00001670}
Chris Lattner1c20a172007-08-26 03:42:43 +00001671
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001672void ASTDumper::VisitStringLiteral(const StringLiteral *Str) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001673 VisitExpr(Str);
Richard Trieud215b8d2013-01-26 01:31:20 +00001674 ColorScope Color(*this, ValueColor);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001675 OS << " ";
Richard Trieudc355912012-06-13 20:25:24 +00001676 Str->outputString(OS);
Chris Lattnercbe4f772007-08-08 22:51:59 +00001677}
Chris Lattner84ca3762007-08-30 01:00:35 +00001678
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001679void ASTDumper::VisitUnaryOperator(const UnaryOperator *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001680 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001681 OS << " " << (Node->isPostfix() ? "postfix" : "prefix")
1682 << " '" << UnaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
Chris Lattnercbe4f772007-08-08 22:51:59 +00001683}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001684
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001685void ASTDumper::VisitUnaryExprOrTypeTraitExpr(
1686 const UnaryExprOrTypeTraitExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001687 VisitExpr(Node);
Peter Collingbournee190dee2011-03-11 19:24:49 +00001688 switch(Node->getKind()) {
1689 case UETT_SizeOf:
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001690 OS << " sizeof";
Peter Collingbournee190dee2011-03-11 19:24:49 +00001691 break;
1692 case UETT_AlignOf:
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001693 OS << " alignof";
Peter Collingbournee190dee2011-03-11 19:24:49 +00001694 break;
1695 case UETT_VecStep:
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001696 OS << " vec_step";
Peter Collingbournee190dee2011-03-11 19:24:49 +00001697 break;
1698 }
Sebastian Redl6f282892008-11-11 17:56:53 +00001699 if (Node->isArgumentType())
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001700 dumpType(Node->getArgumentType());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001701}
Chris Lattnerdb3b3ff2007-08-09 17:35:30 +00001702
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001703void ASTDumper::VisitMemberExpr(const MemberExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001704 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001705 OS << " " << (Node->isArrow() ? "->" : ".") << *Node->getMemberDecl();
1706 dumpPointer(Node->getMemberDecl());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001707}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001708
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001709void ASTDumper::VisitExtVectorElementExpr(const ExtVectorElementExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001710 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001711 OS << " " << Node->getAccessor().getNameStart();
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::VisitBinaryOperator(const BinaryOperator *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001715 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001716 OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
Chris Lattner86928112007-08-25 02:00:02 +00001717}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001718
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001719void ASTDumper::VisitCompoundAssignOperator(
1720 const CompoundAssignOperator *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001721 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001722 OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode())
1723 << "' ComputeLHSTy=";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001724 dumpBareType(Node->getComputationLHSType());
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001725 OS << " ComputeResultTy=";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001726 dumpBareType(Node->getComputationResultType());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001727}
Chris Lattnercbe4f772007-08-08 22:51:59 +00001728
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001729void ASTDumper::VisitBlockExpr(const BlockExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001730 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001731 dumpDecl(Node->getBlockDecl());
John McCall351762c2011-02-07 10:33:21 +00001732}
1733
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001734void ASTDumper::VisitOpaqueValueExpr(const OpaqueValueExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001735 VisitExpr(Node);
John McCallfe96e0b2011-11-06 09:01:30 +00001736
Richard Trieude5cc7d2013-01-31 01:44:26 +00001737 if (Expr *Source = Node->getSourceExpr()) {
1738 lastChild();
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001739 dumpStmt(Source);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001740 }
John McCallfe96e0b2011-11-06 09:01:30 +00001741}
1742
Chris Lattnercbe4f772007-08-08 22:51:59 +00001743// GNU extensions.
1744
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001745void ASTDumper::VisitAddrLabelExpr(const AddrLabelExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001746 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001747 OS << " " << Node->getLabel()->getName();
1748 dumpPointer(Node->getLabel());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001749}
1750
Chris Lattner8f184b12007-08-09 18:03:18 +00001751//===----------------------------------------------------------------------===//
1752// C++ Expressions
1753//===----------------------------------------------------------------------===//
Chris Lattnercbe4f772007-08-08 22:51:59 +00001754
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001755void ASTDumper::VisitCXXNamedCastExpr(const CXXNamedCastExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001756 VisitExpr(Node);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001757 OS << " " << Node->getCastName()
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001758 << "<" << Node->getTypeAsWritten().getAsString() << ">"
Anders Carlssona70cff62010-04-24 19:06:50 +00001759 << " <" << Node->getCastKindName();
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001760 dumpBasePath(OS, Node);
Anders Carlssona70cff62010-04-24 19:06:50 +00001761 OS << ">";
Chris Lattnercbe4f772007-08-08 22:51:59 +00001762}
1763
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001764void ASTDumper::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001765 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001766 OS << " " << (Node->getValue() ? "true" : "false");
Chris Lattnercbe4f772007-08-08 22:51:59 +00001767}
1768
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001769void ASTDumper::VisitCXXThisExpr(const CXXThisExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001770 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001771 OS << " this";
Douglas Gregor8ea1f532008-11-04 14:56:14 +00001772}
1773
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001774void ASTDumper::VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001775 VisitExpr(Node);
Eli Friedman29538892011-09-02 17:38:59 +00001776 OS << " functional cast to " << Node->getTypeAsWritten().getAsString()
1777 << " <" << Node->getCastKindName() << ">";
Douglas Gregore200adc2008-10-27 19:41:14 +00001778}
1779
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001780void ASTDumper::VisitCXXConstructExpr(const CXXConstructExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001781 VisitExpr(Node);
John McCalleba90cd2010-02-02 19:03:45 +00001782 CXXConstructorDecl *Ctor = Node->getConstructor();
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001783 dumpType(Ctor->getType());
Anders Carlsson073846832009-08-12 00:21:52 +00001784 if (Node->isElidable())
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001785 OS << " elidable";
John McCall85370042010-08-07 06:38:55 +00001786 if (Node->requiresZeroInitialization())
1787 OS << " zeroing";
Anders Carlsson073846832009-08-12 00:21:52 +00001788}
1789
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001790void ASTDumper::VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001791 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001792 OS << " ";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001793 dumpCXXTemporary(Node->getTemporary());
Anders Carlsson073846832009-08-12 00:21:52 +00001794}
1795
Richard Smithe6c01442013-06-05 00:46:14 +00001796void
1797ASTDumper::VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *Node) {
1798 VisitExpr(Node);
1799 if (const ValueDecl *VD = Node->getExtendingDecl()) {
1800 OS << " extended by ";
1801 dumpBareDeclRef(VD);
1802 }
1803}
1804
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001805void ASTDumper::VisitExprWithCleanups(const ExprWithCleanups *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001806 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001807 for (unsigned i = 0, e = Node->getNumObjects(); i != e; ++i)
1808 dumpDeclRef(Node->getObject(i), "cleanup");
Anders Carlsson073846832009-08-12 00:21:52 +00001809}
1810
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001811void ASTDumper::dumpCXXTemporary(const CXXTemporary *Temporary) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001812 OS << "(CXXTemporary";
1813 dumpPointer(Temporary);
1814 OS << ")";
Anders Carlsson073846832009-08-12 00:21:52 +00001815}
1816
Anders Carlsson76f4a902007-08-21 17:43:55 +00001817//===----------------------------------------------------------------------===//
1818// Obj-C Expressions
1819//===----------------------------------------------------------------------===//
1820
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001821void ASTDumper::VisitObjCMessageExpr(const ObjCMessageExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001822 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001823 OS << " selector=" << Node->getSelector().getAsString();
Douglas Gregor9a129192010-04-21 00:45:42 +00001824 switch (Node->getReceiverKind()) {
1825 case ObjCMessageExpr::Instance:
1826 break;
1827
1828 case ObjCMessageExpr::Class:
1829 OS << " class=";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001830 dumpBareType(Node->getClassReceiver());
Douglas Gregor9a129192010-04-21 00:45:42 +00001831 break;
1832
1833 case ObjCMessageExpr::SuperInstance:
1834 OS << " super (instance)";
1835 break;
1836
1837 case ObjCMessageExpr::SuperClass:
1838 OS << " super (class)";
1839 break;
1840 }
Ted Kremenek36748da2008-02-29 22:04:05 +00001841}
1842
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001843void ASTDumper::VisitObjCBoxedExpr(const ObjCBoxedExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001844 VisitExpr(Node);
Argyrios Kyrtzidis9dd40892012-05-10 20:02:31 +00001845 OS << " selector=" << Node->getBoxingMethod()->getSelector().getAsString();
1846}
1847
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001848void ASTDumper::VisitObjCAtCatchStmt(const ObjCAtCatchStmt *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001849 VisitStmt(Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001850 if (const VarDecl *CatchParam = Node->getCatchParamDecl())
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001851 dumpDecl(CatchParam);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001852 else
Douglas Gregor96c79492010-04-23 22:50:49 +00001853 OS << " catch all";
Douglas Gregor96c79492010-04-23 22:50:49 +00001854}
1855
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001856void ASTDumper::VisitObjCEncodeExpr(const ObjCEncodeExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001857 VisitExpr(Node);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001858 dumpType(Node->getEncodedType());
Anders Carlssonc5a81eb2007-08-22 15:14:15 +00001859}
1860
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001861void ASTDumper::VisitObjCSelectorExpr(const ObjCSelectorExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001862 VisitExpr(Node);
Mike Stump11289f42009-09-09 15:08:12 +00001863
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001864 OS << " " << Node->getSelector().getAsString();
Fariborz Jahanian4bef4622007-10-16 20:40:23 +00001865}
1866
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001867void ASTDumper::VisitObjCProtocolExpr(const ObjCProtocolExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001868 VisitExpr(Node);
Mike Stump11289f42009-09-09 15:08:12 +00001869
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001870 OS << ' ' << *Node->getProtocol();
Fariborz Jahaniana32aaef2007-10-17 16:58:11 +00001871}
Daniel Dunbar4b8c6db2008-08-30 05:35:15 +00001872
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001873void ASTDumper::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001874 VisitExpr(Node);
John McCallb7bd14f2010-12-02 01:19:52 +00001875 if (Node->isImplicitProperty()) {
Fariborz Jahanian0f0b3022010-12-22 19:46:35 +00001876 OS << " Kind=MethodRef Getter=\"";
1877 if (Node->getImplicitPropertyGetter())
1878 OS << Node->getImplicitPropertyGetter()->getSelector().getAsString();
1879 else
1880 OS << "(null)";
1881
1882 OS << "\" Setter=\"";
John McCallb7bd14f2010-12-02 01:19:52 +00001883 if (ObjCMethodDecl *Setter = Node->getImplicitPropertySetter())
1884 OS << Setter->getSelector().getAsString();
1885 else
1886 OS << "(null)";
1887 OS << "\"";
1888 } else {
Benjamin Kramerb89514a2011-10-14 18:45:37 +00001889 OS << " Kind=PropertyRef Property=\"" << *Node->getExplicitProperty() <<'"';
John McCallb7bd14f2010-12-02 01:19:52 +00001890 }
Fariborz Jahanian8a1810f2008-11-22 18:39:36 +00001891
Fariborz Jahanian681c0752010-10-14 16:04:05 +00001892 if (Node->isSuperReceiver())
1893 OS << " super";
Argyrios Kyrtzidisab468b02012-03-30 00:19:18 +00001894
1895 OS << " Messaging=";
1896 if (Node->isMessagingGetter() && Node->isMessagingSetter())
1897 OS << "Getter&Setter";
1898 else if (Node->isMessagingGetter())
1899 OS << "Getter";
1900 else if (Node->isMessagingSetter())
1901 OS << "Setter";
Douglas Gregor8ea1f532008-11-04 14:56:14 +00001902}
1903
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001904void ASTDumper::VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001905 VisitExpr(Node);
Ted Kremeneke65b0862012-03-06 20:05:56 +00001906 if (Node->isArraySubscriptRefExpr())
1907 OS << " Kind=ArraySubscript GetterForArray=\"";
1908 else
1909 OS << " Kind=DictionarySubscript GetterForDictionary=\"";
1910 if (Node->getAtIndexMethodDecl())
1911 OS << Node->getAtIndexMethodDecl()->getSelector().getAsString();
1912 else
1913 OS << "(null)";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001914
Ted Kremeneke65b0862012-03-06 20:05:56 +00001915 if (Node->isArraySubscriptRefExpr())
1916 OS << "\" SetterForArray=\"";
1917 else
1918 OS << "\" SetterForDictionary=\"";
1919 if (Node->setAtIndexMethodDecl())
1920 OS << Node->setAtIndexMethodDecl()->getSelector().getAsString();
1921 else
1922 OS << "(null)";
1923}
1924
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001925void ASTDumper::VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001926 VisitExpr(Node);
Ted Kremeneke65b0862012-03-06 20:05:56 +00001927 OS << " " << (Node->getValue() ? "__objc_yes" : "__objc_no");
1928}
1929
Chris Lattnercbe4f772007-08-08 22:51:59 +00001930//===----------------------------------------------------------------------===//
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00001931// Comments
1932//===----------------------------------------------------------------------===//
1933
1934const char *ASTDumper::getCommandName(unsigned CommandID) {
1935 if (Traits)
1936 return Traits->getCommandInfo(CommandID)->Name;
1937 const CommandInfo *Info = CommandTraits::getBuiltinCommandInfo(CommandID);
1938 if (Info)
1939 return Info->Name;
1940 return "<not a builtin command>";
1941}
1942
1943void ASTDumper::dumpFullComment(const FullComment *C) {
1944 if (!C)
1945 return;
1946
1947 FC = C;
1948 dumpComment(C);
1949 FC = 0;
1950}
1951
1952void ASTDumper::dumpComment(const Comment *C) {
1953 IndentScope Indent(*this);
1954
1955 if (!C) {
Richard Trieud215b8d2013-01-26 01:31:20 +00001956 ColorScope Color(*this, NullColor);
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00001957 OS << "<<<NULL>>>";
1958 return;
1959 }
1960
Richard Trieud215b8d2013-01-26 01:31:20 +00001961 {
1962 ColorScope Color(*this, CommentColor);
1963 OS << C->getCommentKindName();
1964 }
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00001965 dumpPointer(C);
1966 dumpSourceRange(C->getSourceRange());
1967 ConstCommentVisitor<ASTDumper>::visit(C);
1968 for (Comment::child_iterator I = C->child_begin(), E = C->child_end();
Richard Trieude5cc7d2013-01-31 01:44:26 +00001969 I != E; ++I) {
1970 if (I + 1 == E)
1971 lastChild();
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00001972 dumpComment(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001973 }
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00001974}
1975
1976void ASTDumper::visitTextComment(const TextComment *C) {
1977 OS << " Text=\"" << C->getText() << "\"";
1978}
1979
1980void ASTDumper::visitInlineCommandComment(const InlineCommandComment *C) {
1981 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\"";
1982 switch (C->getRenderKind()) {
1983 case InlineCommandComment::RenderNormal:
1984 OS << " RenderNormal";
1985 break;
1986 case InlineCommandComment::RenderBold:
1987 OS << " RenderBold";
1988 break;
1989 case InlineCommandComment::RenderMonospaced:
1990 OS << " RenderMonospaced";
1991 break;
1992 case InlineCommandComment::RenderEmphasized:
1993 OS << " RenderEmphasized";
1994 break;
1995 }
1996
1997 for (unsigned i = 0, e = C->getNumArgs(); i != e; ++i)
1998 OS << " Arg[" << i << "]=\"" << C->getArgText(i) << "\"";
1999}
2000
2001void ASTDumper::visitHTMLStartTagComment(const HTMLStartTagComment *C) {
2002 OS << " Name=\"" << C->getTagName() << "\"";
2003 if (C->getNumAttrs() != 0) {
2004 OS << " Attrs: ";
2005 for (unsigned i = 0, e = C->getNumAttrs(); i != e; ++i) {
2006 const HTMLStartTagComment::Attribute &Attr = C->getAttr(i);
2007 OS << " \"" << Attr.Name << "=\"" << Attr.Value << "\"";
2008 }
2009 }
2010 if (C->isSelfClosing())
2011 OS << " SelfClosing";
2012}
2013
2014void ASTDumper::visitHTMLEndTagComment(const HTMLEndTagComment *C) {
2015 OS << " Name=\"" << C->getTagName() << "\"";
2016}
2017
2018void ASTDumper::visitBlockCommandComment(const BlockCommandComment *C) {
2019 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\"";
2020 for (unsigned i = 0, e = C->getNumArgs(); i != e; ++i)
2021 OS << " Arg[" << i << "]=\"" << C->getArgText(i) << "\"";
2022}
2023
2024void ASTDumper::visitParamCommandComment(const ParamCommandComment *C) {
2025 OS << " " << ParamCommandComment::getDirectionAsString(C->getDirection());
2026
2027 if (C->isDirectionExplicit())
2028 OS << " explicitly";
2029 else
2030 OS << " implicitly";
2031
2032 if (C->hasParamName()) {
2033 if (C->isParamIndexValid())
2034 OS << " Param=\"" << C->getParamName(FC) << "\"";
2035 else
2036 OS << " Param=\"" << C->getParamNameAsWritten() << "\"";
2037 }
2038
2039 if (C->isParamIndexValid())
2040 OS << " ParamIndex=" << C->getParamIndex();
2041}
2042
2043void ASTDumper::visitTParamCommandComment(const TParamCommandComment *C) {
2044 if (C->hasParamName()) {
2045 if (C->isPositionValid())
2046 OS << " Param=\"" << C->getParamName(FC) << "\"";
2047 else
2048 OS << " Param=\"" << C->getParamNameAsWritten() << "\"";
2049 }
2050
2051 if (C->isPositionValid()) {
2052 OS << " Position=<";
2053 for (unsigned i = 0, e = C->getDepth(); i != e; ++i) {
2054 OS << C->getIndex(i);
2055 if (i != e - 1)
2056 OS << ", ";
2057 }
2058 OS << ">";
2059 }
2060}
2061
2062void ASTDumper::visitVerbatimBlockComment(const VerbatimBlockComment *C) {
2063 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\""
2064 " CloseName=\"" << C->getCloseName() << "\"";
2065}
2066
2067void ASTDumper::visitVerbatimBlockLineComment(
2068 const VerbatimBlockLineComment *C) {
2069 OS << " Text=\"" << C->getText() << "\"";
2070}
2071
2072void ASTDumper::visitVerbatimLineComment(const VerbatimLineComment *C) {
2073 OS << " Text=\"" << C->getText() << "\"";
2074}
2075
2076//===----------------------------------------------------------------------===//
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002077// Decl method implementations
2078//===----------------------------------------------------------------------===//
2079
2080void Decl::dump() const {
2081 dump(llvm::errs());
2082}
2083
2084void Decl::dump(raw_ostream &OS) const {
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002085 ASTDumper P(OS, &getASTContext().getCommentCommandTraits(),
2086 &getASTContext().getSourceManager());
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002087 P.dumpDecl(this);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002088}
2089
Richard Trieud215b8d2013-01-26 01:31:20 +00002090void Decl::dumpColor() const {
2091 ASTDumper P(llvm::errs(), &getASTContext().getCommentCommandTraits(),
2092 &getASTContext().getSourceManager(), /*ShowColors*/true);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002093 P.dumpDecl(this);
Richard Trieud215b8d2013-01-26 01:31:20 +00002094}
Richard Smith33937e72013-06-22 21:49:40 +00002095
2096void DeclContext::dumpLookups() const {
Richard Smith6ea05822013-06-24 01:45:33 +00002097 dumpLookups(llvm::errs());
2098}
2099
2100void DeclContext::dumpLookups(raw_ostream &OS) const {
Richard Smith33937e72013-06-22 21:49:40 +00002101 const DeclContext *DC = this;
2102 while (!DC->isTranslationUnit())
2103 DC = DC->getParent();
2104 ASTContext &Ctx = cast<TranslationUnitDecl>(DC)->getASTContext();
Richard Smith6ea05822013-06-24 01:45:33 +00002105 ASTDumper P(OS, &Ctx.getCommentCommandTraits(), &Ctx.getSourceManager());
Richard Smith33937e72013-06-22 21:49:40 +00002106 P.dumpLookups(this);
2107}
2108
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002109//===----------------------------------------------------------------------===//
Chris Lattnercbe4f772007-08-08 22:51:59 +00002110// Stmt method implementations
2111//===----------------------------------------------------------------------===//
2112
Chris Lattner11e30d32007-08-30 06:17:34 +00002113void Stmt::dump(SourceManager &SM) const {
Argyrios Kyrtzidisc049f752010-08-09 10:54:31 +00002114 dump(llvm::errs(), SM);
2115}
2116
Chris Lattner0e62c1c2011-07-23 10:55:15 +00002117void Stmt::dump(raw_ostream &OS, SourceManager &SM) const {
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002118 ASTDumper P(OS, 0, &SM);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002119 P.dumpStmt(this);
Chris Lattner779d5d92007-08-30 00:40:08 +00002120}
2121
Chris Lattnercbe4f772007-08-08 22:51:59 +00002122void Stmt::dump() const {
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002123 ASTDumper P(llvm::errs(), 0, 0);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002124 P.dumpStmt(this);
Chris Lattnercbe4f772007-08-08 22:51:59 +00002125}
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002126
Richard Trieud215b8d2013-01-26 01:31:20 +00002127void Stmt::dumpColor() const {
2128 ASTDumper P(llvm::errs(), 0, 0, /*ShowColors*/true);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002129 P.dumpStmt(this);
Richard Trieud215b8d2013-01-26 01:31:20 +00002130}
2131
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002132//===----------------------------------------------------------------------===//
2133// Comment method implementations
2134//===----------------------------------------------------------------------===//
2135
2136void Comment::dump() const {
2137 dump(llvm::errs(), 0, 0);
2138}
2139
2140void Comment::dump(const ASTContext &Context) const {
2141 dump(llvm::errs(), &Context.getCommentCommandTraits(),
2142 &Context.getSourceManager());
2143}
2144
Alexander Kornienko00911f12013-01-15 12:20:21 +00002145void Comment::dump(raw_ostream &OS, const CommandTraits *Traits,
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002146 const SourceManager *SM) const {
2147 const FullComment *FC = dyn_cast<FullComment>(this);
2148 ASTDumper D(OS, Traits, SM);
2149 D.dumpFullComment(FC);
2150}
Richard Trieud215b8d2013-01-26 01:31:20 +00002151
2152void Comment::dumpColor() const {
2153 const FullComment *FC = dyn_cast<FullComment>(this);
2154 ASTDumper D(llvm::errs(), 0, 0, /*ShowColors*/true);
2155 D.dumpFullComment(FC);
2156}