blob: a21acba0cd9e28b68711e45c1a351130169591d0 [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 Smith71bec062013-10-15 21:58:30 +0000581static void dumpPreviousDeclImpl(raw_ostream &OS, ...) {}
582
583template<typename T>
584static void dumpPreviousDeclImpl(raw_ostream &OS, const Mergeable<T> *D) {
Rafael Espindola8db352d2013-10-17 15:37:26 +0000585 const T *First = D->getFirstDecl();
Richard Smith71bec062013-10-15 21:58:30 +0000586 if (First != D)
587 OS << " first " << First;
Richard Smithf5f43542013-02-07 01:35:44 +0000588}
589
590template<typename T>
Richard Smith71bec062013-10-15 21:58:30 +0000591static void dumpPreviousDeclImpl(raw_ostream &OS, const Redeclarable<T> *D) {
592 const T *Prev = D->getPreviousDecl();
593 if (Prev)
594 OS << " prev " << Prev;
Richard Smithf5f43542013-02-07 01:35:44 +0000595}
596
Richard Smith71bec062013-10-15 21:58:30 +0000597/// Dump the previous declaration in the redeclaration chain for a declaration,
598/// if any.
599static void dumpPreviousDecl(raw_ostream &OS, const Decl *D) {
Richard Smithf5f43542013-02-07 01:35:44 +0000600 switch (D->getKind()) {
601#define DECL(DERIVED, BASE) \
602 case Decl::DERIVED: \
Richard Smith71bec062013-10-15 21:58:30 +0000603 return dumpPreviousDeclImpl(OS, cast<DERIVED##Decl>(D));
Richard Smithf5f43542013-02-07 01:35:44 +0000604#define ABSTRACT_DECL(DECL)
605#include "clang/AST/DeclNodes.inc"
606 }
607 llvm_unreachable("Decl that isn't part of DeclNodes.inc!");
608}
609
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000610//===----------------------------------------------------------------------===//
611// C++ Utilities
612//===----------------------------------------------------------------------===//
613
614void ASTDumper::dumpAccessSpecifier(AccessSpecifier AS) {
615 switch (AS) {
616 case AS_none:
617 break;
618 case AS_public:
619 OS << "public";
620 break;
621 case AS_protected:
622 OS << "protected";
623 break;
624 case AS_private:
625 OS << "private";
626 break;
627 }
628}
629
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000630void ASTDumper::dumpCXXCtorInitializer(const CXXCtorInitializer *Init) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000631 IndentScope Indent(*this);
632 OS << "CXXCtorInitializer";
633 if (Init->isAnyMemberInitializer()) {
634 OS << ' ';
635 dumpBareDeclRef(Init->getAnyMember());
636 } else {
637 dumpType(QualType(Init->getBaseClass(), 0));
638 }
639 dumpStmt(Init->getInit());
640}
641
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000642void ASTDumper::dumpTemplateParameters(const TemplateParameterList *TPL) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000643 if (!TPL)
644 return;
645
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000646 for (TemplateParameterList::const_iterator I = TPL->begin(), E = TPL->end();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000647 I != E; ++I)
648 dumpDecl(*I);
649}
650
651void ASTDumper::dumpTemplateArgumentListInfo(
652 const TemplateArgumentListInfo &TALI) {
Richard Trieude5cc7d2013-01-31 01:44:26 +0000653 for (unsigned i = 0, e = TALI.size(); i < e; ++i) {
654 if (i + 1 == e)
655 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000656 dumpTemplateArgumentLoc(TALI[i]);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000657 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000658}
659
660void ASTDumper::dumpTemplateArgumentLoc(const TemplateArgumentLoc &A) {
661 dumpTemplateArgument(A.getArgument(), A.getSourceRange());
662}
663
664void ASTDumper::dumpTemplateArgumentList(const TemplateArgumentList &TAL) {
665 for (unsigned i = 0, e = TAL.size(); i < e; ++i)
666 dumpTemplateArgument(TAL[i]);
667}
668
669void ASTDumper::dumpTemplateArgument(const TemplateArgument &A, SourceRange R) {
670 IndentScope Indent(*this);
671 OS << "TemplateArgument";
672 if (R.isValid())
673 dumpSourceRange(R);
674
675 switch (A.getKind()) {
676 case TemplateArgument::Null:
677 OS << " null";
678 break;
679 case TemplateArgument::Type:
680 OS << " type";
Richard Trieude5cc7d2013-01-31 01:44:26 +0000681 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000682 dumpType(A.getAsType());
683 break;
684 case TemplateArgument::Declaration:
685 OS << " decl";
Richard Trieude5cc7d2013-01-31 01:44:26 +0000686 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000687 dumpDeclRef(A.getAsDecl());
688 break;
689 case TemplateArgument::NullPtr:
690 OS << " nullptr";
691 break;
692 case TemplateArgument::Integral:
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000693 OS << " integral " << A.getAsIntegral();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000694 break;
695 case TemplateArgument::Template:
696 OS << " template ";
697 A.getAsTemplate().dump(OS);
698 break;
699 case TemplateArgument::TemplateExpansion:
700 OS << " template expansion";
701 A.getAsTemplateOrTemplatePattern().dump(OS);
702 break;
703 case TemplateArgument::Expression:
704 OS << " expr";
Richard Trieude5cc7d2013-01-31 01:44:26 +0000705 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000706 dumpStmt(A.getAsExpr());
707 break;
708 case TemplateArgument::Pack:
709 OS << " pack";
710 for (TemplateArgument::pack_iterator I = A.pack_begin(), E = A.pack_end();
Richard Trieude5cc7d2013-01-31 01:44:26 +0000711 I != E; ++I) {
712 if (I + 1 == E)
713 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000714 dumpTemplateArgument(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000715 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000716 break;
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000717 }
718}
719
Chris Lattner11e30d32007-08-30 06:17:34 +0000720//===----------------------------------------------------------------------===//
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000721// Decl dumping methods.
Chris Lattnercbe4f772007-08-08 22:51:59 +0000722//===----------------------------------------------------------------------===//
723
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000724void ASTDumper::dumpDecl(const Decl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000725 IndentScope Indent(*this);
Mike Stump11289f42009-09-09 15:08:12 +0000726
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000727 if (!D) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000728 ColorScope Color(*this, NullColor);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000729 OS << "<<<NULL>>>";
730 return;
Chris Lattnercbe4f772007-08-08 22:51:59 +0000731 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000732
Richard Trieud215b8d2013-01-26 01:31:20 +0000733 {
734 ColorScope Color(*this, DeclKindNameColor);
735 OS << D->getDeclKindName() << "Decl";
736 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000737 dumpPointer(D);
Richard Smithf5f43542013-02-07 01:35:44 +0000738 if (D->getLexicalDeclContext() != D->getDeclContext())
739 OS << " parent " << cast<Decl>(D->getDeclContext());
Richard Smith71bec062013-10-15 21:58:30 +0000740 dumpPreviousDecl(OS, D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000741 dumpSourceRange(D->getSourceRange());
Richard Trieude5cc7d2013-01-31 01:44:26 +0000742
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000743 bool HasAttrs = D->attr_begin() != D->attr_end();
Richard Smithb39b9d52013-05-21 05:24:00 +0000744 const FullComment *Comment =
745 D->getASTContext().getLocalCommentForDeclUncached(D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000746 // Decls within functions are visited by the body
Richard Trieude5cc7d2013-01-31 01:44:26 +0000747 bool HasDeclContext = !isa<FunctionDecl>(*D) && !isa<ObjCMethodDecl>(*D) &&
748 hasNodes(dyn_cast<DeclContext>(D));
749
Richard Smithb39b9d52013-05-21 05:24:00 +0000750 setMoreChildren(HasAttrs || Comment || HasDeclContext);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000751 ConstDeclVisitor<ASTDumper>::Visit(D);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000752
Richard Smithb39b9d52013-05-21 05:24:00 +0000753 setMoreChildren(Comment || HasDeclContext);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000754 for (Decl::attr_iterator I = D->attr_begin(), E = D->attr_end();
755 I != E; ++I) {
756 if (I + 1 == E)
757 lastChild();
758 dumpAttr(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000759 }
760
761 setMoreChildren(HasDeclContext);
762 lastChild();
Richard Smithb39b9d52013-05-21 05:24:00 +0000763 dumpFullComment(Comment);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000764
Nick Lewyckya382db02013-08-27 03:15:56 +0000765 if (D->isInvalidDecl())
766 OS << " invalid";
767
Richard Trieude5cc7d2013-01-31 01:44:26 +0000768 setMoreChildren(false);
769 if (HasDeclContext)
Richard Smithf5f43542013-02-07 01:35:44 +0000770 dumpDeclContext(cast<DeclContext>(D));
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000771}
772
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000773void ASTDumper::VisitLabelDecl(const LabelDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000774 dumpName(D);
775}
776
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000777void ASTDumper::VisitTypedefDecl(const TypedefDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000778 dumpName(D);
779 dumpType(D->getUnderlyingType());
780 if (D->isModulePrivate())
781 OS << " __module_private__";
782}
783
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000784void ASTDumper::VisitEnumDecl(const EnumDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000785 if (D->isScoped()) {
786 if (D->isScopedUsingClassTag())
787 OS << " class";
788 else
789 OS << " struct";
790 }
791 dumpName(D);
792 if (D->isModulePrivate())
793 OS << " __module_private__";
794 if (D->isFixed())
795 dumpType(D->getIntegerType());
796}
797
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000798void ASTDumper::VisitRecordDecl(const RecordDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000799 OS << ' ' << D->getKindName();
800 dumpName(D);
801 if (D->isModulePrivate())
802 OS << " __module_private__";
Richard Smith99bc1b92013-08-30 05:32:29 +0000803 if (D->isCompleteDefinition())
804 OS << " definition";
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000805}
806
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000807void ASTDumper::VisitEnumConstantDecl(const EnumConstantDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000808 dumpName(D);
809 dumpType(D->getType());
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000810 if (const Expr *Init = D->getInitExpr()) {
Richard Trieude5cc7d2013-01-31 01:44:26 +0000811 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000812 dumpStmt(Init);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000813 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000814}
815
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000816void ASTDumper::VisitIndirectFieldDecl(const IndirectFieldDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000817 dumpName(D);
818 dumpType(D->getType());
819 for (IndirectFieldDecl::chain_iterator I = D->chain_begin(),
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000820 E = D->chain_end();
821 I != E; ++I) {
Richard Trieude5cc7d2013-01-31 01:44:26 +0000822 if (I + 1 == E)
823 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000824 dumpDeclRef(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000825 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000826}
827
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000828void ASTDumper::VisitFunctionDecl(const FunctionDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000829 dumpName(D);
830 dumpType(D->getType());
831
Rafael Espindola6ae7e502013-04-03 19:27:57 +0000832 StorageClass SC = D->getStorageClass();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000833 if (SC != SC_None)
834 OS << ' ' << VarDecl::getStorageClassSpecifierString(SC);
835 if (D->isInlineSpecified())
836 OS << " inline";
837 if (D->isVirtualAsWritten())
838 OS << " virtual";
839 if (D->isModulePrivate())
840 OS << " __module_private__";
841
842 if (D->isPure())
843 OS << " pure";
844 else if (D->isDeletedAsWritten())
845 OS << " delete";
846
Richard Smithadaa0152013-05-17 02:09:46 +0000847 if (const FunctionProtoType *FPT = D->getType()->getAs<FunctionProtoType>()) {
848 FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo();
849 switch (EPI.ExceptionSpecType) {
850 default: break;
851 case EST_Unevaluated:
852 OS << " noexcept-unevaluated " << EPI.ExceptionSpecDecl;
853 break;
854 case EST_Uninstantiated:
855 OS << " noexcept-uninstantiated " << EPI.ExceptionSpecTemplate;
856 break;
857 }
858 }
859
Richard Trieude5cc7d2013-01-31 01:44:26 +0000860 bool OldMoreChildren = hasMoreChildren();
861 const FunctionTemplateSpecializationInfo *FTSI =
862 D->getTemplateSpecializationInfo();
863 bool HasTemplateSpecialization = FTSI;
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000864
Richard Trieude5cc7d2013-01-31 01:44:26 +0000865 bool HasNamedDecls = D->getDeclsInPrototypeScope().begin() !=
866 D->getDeclsInPrototypeScope().end();
867
868 bool HasFunctionDecls = D->param_begin() != D->param_end();
869
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000870 const CXXConstructorDecl *C = dyn_cast<CXXConstructorDecl>(D);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000871 bool HasCtorInitializers = C && C->init_begin() != C->init_end();
872
873 bool HasDeclarationBody = D->doesThisDeclarationHaveABody();
874
875 setMoreChildren(OldMoreChildren || HasNamedDecls || HasFunctionDecls ||
876 HasCtorInitializers || HasDeclarationBody);
877 if (HasTemplateSpecialization) {
878 lastChild();
879 dumpTemplateArgumentList(*FTSI->TemplateArguments);
880 }
881
882 setMoreChildren(OldMoreChildren || HasFunctionDecls ||
883 HasCtorInitializers || HasDeclarationBody);
Dmitri Gribenkof8579502013-01-12 19:30:44 +0000884 for (ArrayRef<NamedDecl *>::iterator
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000885 I = D->getDeclsInPrototypeScope().begin(),
Richard Trieude5cc7d2013-01-31 01:44:26 +0000886 E = D->getDeclsInPrototypeScope().end(); I != E; ++I) {
887 if (I + 1 == E)
888 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000889 dumpDecl(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000890 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000891
Richard Trieude5cc7d2013-01-31 01:44:26 +0000892 setMoreChildren(OldMoreChildren || HasCtorInitializers || HasDeclarationBody);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000893 for (FunctionDecl::param_const_iterator I = D->param_begin(),
894 E = D->param_end();
Richard Trieude5cc7d2013-01-31 01:44:26 +0000895 I != E; ++I) {
896 if (I + 1 == E)
897 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000898 dumpDecl(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000899 }
900
901 setMoreChildren(OldMoreChildren || HasDeclarationBody);
902 if (HasCtorInitializers)
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000903 for (CXXConstructorDecl::init_const_iterator I = C->init_begin(),
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000904 E = C->init_end();
905 I != E; ++I) {
Richard Trieude5cc7d2013-01-31 01:44:26 +0000906 if (I + 1 == E)
907 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000908 dumpCXXCtorInitializer(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000909 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000910
Richard Trieude5cc7d2013-01-31 01:44:26 +0000911 setMoreChildren(OldMoreChildren);
912 if (HasDeclarationBody) {
913 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000914 dumpStmt(D->getBody());
Richard Trieude5cc7d2013-01-31 01:44:26 +0000915 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000916}
917
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000918void ASTDumper::VisitFieldDecl(const FieldDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000919 dumpName(D);
920 dumpType(D->getType());
921 if (D->isMutable())
922 OS << " mutable";
923 if (D->isModulePrivate())
924 OS << " __module_private__";
Richard Trieude5cc7d2013-01-31 01:44:26 +0000925
926 bool OldMoreChildren = hasMoreChildren();
927 bool IsBitField = D->isBitField();
928 Expr *Init = D->getInClassInitializer();
929 bool HasInit = Init;
930
931 setMoreChildren(OldMoreChildren || HasInit);
932 if (IsBitField) {
933 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000934 dumpStmt(D->getBitWidth());
Richard Trieude5cc7d2013-01-31 01:44:26 +0000935 }
936 setMoreChildren(OldMoreChildren);
937 if (HasInit) {
938 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000939 dumpStmt(Init);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000940 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000941}
942
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000943void ASTDumper::VisitVarDecl(const VarDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000944 dumpName(D);
945 dumpType(D->getType());
Rafael Espindola6ae7e502013-04-03 19:27:57 +0000946 StorageClass SC = D->getStorageClass();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000947 if (SC != SC_None)
948 OS << ' ' << VarDecl::getStorageClassSpecifierString(SC);
Richard Smithfd3834f2013-04-13 02:43:54 +0000949 switch (D->getTLSKind()) {
950 case VarDecl::TLS_None: break;
951 case VarDecl::TLS_Static: OS << " tls"; break;
952 case VarDecl::TLS_Dynamic: OS << " tls_dynamic"; break;
953 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000954 if (D->isModulePrivate())
955 OS << " __module_private__";
956 if (D->isNRVOVariable())
957 OS << " nrvo";
Richard Trieude5cc7d2013-01-31 01:44:26 +0000958 if (D->hasInit()) {
959 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000960 dumpStmt(D->getInit());
Richard Trieude5cc7d2013-01-31 01:44:26 +0000961 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000962}
963
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000964void ASTDumper::VisitFileScopeAsmDecl(const FileScopeAsmDecl *D) {
Richard Trieude5cc7d2013-01-31 01:44:26 +0000965 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000966 dumpStmt(D->getAsmString());
967}
968
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000969void ASTDumper::VisitImportDecl(const ImportDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000970 OS << ' ' << D->getImportedModule()->getFullModuleName();
971}
972
973//===----------------------------------------------------------------------===//
974// C++ Declarations
975//===----------------------------------------------------------------------===//
976
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000977void ASTDumper::VisitNamespaceDecl(const NamespaceDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000978 dumpName(D);
979 if (D->isInline())
980 OS << " inline";
981 if (!D->isOriginalNamespace())
982 dumpDeclRef(D->getOriginalNamespace(), "original");
983}
984
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000985void ASTDumper::VisitUsingDirectiveDecl(const UsingDirectiveDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000986 OS << ' ';
987 dumpBareDeclRef(D->getNominatedNamespace());
988}
989
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000990void ASTDumper::VisitNamespaceAliasDecl(const NamespaceAliasDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000991 dumpName(D);
992 dumpDeclRef(D->getAliasedNamespace());
993}
994
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000995void ASTDumper::VisitTypeAliasDecl(const TypeAliasDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000996 dumpName(D);
997 dumpType(D->getUnderlyingType());
998}
999
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001000void ASTDumper::VisitTypeAliasTemplateDecl(const TypeAliasTemplateDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001001 dumpName(D);
1002 dumpTemplateParameters(D->getTemplateParameters());
1003 dumpDecl(D->getTemplatedDecl());
1004}
1005
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001006void ASTDumper::VisitCXXRecordDecl(const CXXRecordDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001007 VisitRecordDecl(D);
1008 if (!D->isCompleteDefinition())
1009 return;
1010
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001011 for (CXXRecordDecl::base_class_const_iterator I = D->bases_begin(),
1012 E = D->bases_end();
1013 I != E; ++I) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001014 IndentScope Indent(*this);
1015 if (I->isVirtual())
1016 OS << "virtual ";
1017 dumpAccessSpecifier(I->getAccessSpecifier());
1018 dumpType(I->getType());
1019 if (I->isPackExpansion())
1020 OS << "...";
1021 }
1022}
1023
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001024void ASTDumper::VisitStaticAssertDecl(const StaticAssertDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001025 dumpStmt(D->getAssertExpr());
Richard Trieude5cc7d2013-01-31 01:44:26 +00001026 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001027 dumpStmt(D->getMessage());
1028}
1029
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001030void ASTDumper::VisitFunctionTemplateDecl(const FunctionTemplateDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001031 dumpName(D);
1032 dumpTemplateParameters(D->getTemplateParameters());
1033 dumpDecl(D->getTemplatedDecl());
Dmitri Gribenko81f25752013-02-14 13:20:36 +00001034 for (FunctionTemplateDecl::spec_iterator I = D->spec_begin(),
1035 E = D->spec_end();
1036 I != E; ++I) {
Richard Trieude5cc7d2013-01-31 01:44:26 +00001037 FunctionTemplateDecl::spec_iterator Next = I;
1038 ++Next;
1039 if (Next == E)
1040 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001041 switch (I->getTemplateSpecializationKind()) {
1042 case TSK_Undeclared:
1043 case TSK_ImplicitInstantiation:
1044 case TSK_ExplicitInstantiationDeclaration:
1045 case TSK_ExplicitInstantiationDefinition:
Dmitri Gribenkoefc6dfb2013-02-21 22:01:10 +00001046 if (D == D->getCanonicalDecl())
1047 dumpDecl(*I);
1048 else
1049 dumpDeclRef(*I);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001050 break;
1051 case TSK_ExplicitSpecialization:
1052 dumpDeclRef(*I);
1053 break;
1054 }
1055 }
1056}
1057
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001058void ASTDumper::VisitClassTemplateDecl(const ClassTemplateDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001059 dumpName(D);
1060 dumpTemplateParameters(D->getTemplateParameters());
Richard Trieude5cc7d2013-01-31 01:44:26 +00001061
Dmitri Gribenko81f25752013-02-14 13:20:36 +00001062 ClassTemplateDecl::spec_iterator I = D->spec_begin();
1063 ClassTemplateDecl::spec_iterator E = D->spec_end();
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001064 if (I == E)
Richard Trieude5cc7d2013-01-31 01:44:26 +00001065 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001066 dumpDecl(D->getTemplatedDecl());
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001067 for (; I != E; ++I) {
Richard Trieude5cc7d2013-01-31 01:44:26 +00001068 ClassTemplateDecl::spec_iterator Next = I;
1069 ++Next;
1070 if (Next == E)
1071 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001072 switch (I->getTemplateSpecializationKind()) {
1073 case TSK_Undeclared:
1074 case TSK_ImplicitInstantiation:
Dmitri Gribenkoefc6dfb2013-02-21 22:01:10 +00001075 if (D == D->getCanonicalDecl())
1076 dumpDecl(*I);
1077 else
1078 dumpDeclRef(*I);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001079 break;
1080 case TSK_ExplicitSpecialization:
1081 case TSK_ExplicitInstantiationDeclaration:
1082 case TSK_ExplicitInstantiationDefinition:
1083 dumpDeclRef(*I);
1084 break;
1085 }
1086 }
1087}
1088
1089void ASTDumper::VisitClassTemplateSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001090 const ClassTemplateSpecializationDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001091 VisitCXXRecordDecl(D);
1092 dumpTemplateArgumentList(D->getTemplateArgs());
1093}
1094
1095void ASTDumper::VisitClassTemplatePartialSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001096 const ClassTemplatePartialSpecializationDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001097 VisitClassTemplateSpecializationDecl(D);
1098 dumpTemplateParameters(D->getTemplateParameters());
1099}
1100
1101void ASTDumper::VisitClassScopeFunctionSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001102 const ClassScopeFunctionSpecializationDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001103 dumpDeclRef(D->getSpecialization());
1104 if (D->hasExplicitTemplateArgs())
1105 dumpTemplateArgumentListInfo(D->templateArgs());
1106}
1107
Richard Smithd25789a2013-09-18 01:36:02 +00001108void ASTDumper::VisitVarTemplateDecl(const VarTemplateDecl *D) {
1109 dumpName(D);
1110 dumpTemplateParameters(D->getTemplateParameters());
1111
1112 VarTemplateDecl::spec_iterator I = D->spec_begin();
1113 VarTemplateDecl::spec_iterator E = D->spec_end();
1114 if (I == E)
1115 lastChild();
1116 dumpDecl(D->getTemplatedDecl());
1117 for (; I != E; ++I) {
1118 VarTemplateDecl::spec_iterator Next = I;
1119 ++Next;
1120 if (Next == E)
1121 lastChild();
1122 switch (I->getTemplateSpecializationKind()) {
1123 case TSK_Undeclared:
1124 case TSK_ImplicitInstantiation:
1125 if (D == D->getCanonicalDecl())
1126 dumpDecl(*I);
1127 else
1128 dumpDeclRef(*I);
1129 break;
1130 case TSK_ExplicitSpecialization:
1131 case TSK_ExplicitInstantiationDeclaration:
1132 case TSK_ExplicitInstantiationDefinition:
1133 dumpDeclRef(*I);
1134 break;
1135 }
1136 }
1137}
1138
1139void ASTDumper::VisitVarTemplateSpecializationDecl(
1140 const VarTemplateSpecializationDecl *D) {
1141 dumpTemplateArgumentList(D->getTemplateArgs());
1142 VisitVarDecl(D);
1143}
1144
1145void ASTDumper::VisitVarTemplatePartialSpecializationDecl(
1146 const VarTemplatePartialSpecializationDecl *D) {
1147 dumpTemplateParameters(D->getTemplateParameters());
1148 VisitVarTemplateSpecializationDecl(D);
1149}
1150
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001151void ASTDumper::VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001152 if (D->wasDeclaredWithTypename())
1153 OS << " typename";
1154 else
1155 OS << " class";
1156 if (D->isParameterPack())
1157 OS << " ...";
1158 dumpName(D);
1159 if (D->hasDefaultArgument())
1160 dumpType(D->getDefaultArgument());
1161}
1162
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001163void ASTDumper::VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001164 dumpType(D->getType());
1165 if (D->isParameterPack())
1166 OS << " ...";
1167 dumpName(D);
1168 if (D->hasDefaultArgument())
1169 dumpStmt(D->getDefaultArgument());
1170}
1171
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001172void ASTDumper::VisitTemplateTemplateParmDecl(
1173 const TemplateTemplateParmDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001174 if (D->isParameterPack())
1175 OS << " ...";
1176 dumpName(D);
1177 dumpTemplateParameters(D->getTemplateParameters());
1178 if (D->hasDefaultArgument())
1179 dumpTemplateArgumentLoc(D->getDefaultArgument());
1180}
1181
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001182void ASTDumper::VisitUsingDecl(const UsingDecl *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::VisitUnresolvedUsingTypenameDecl(
1189 const UnresolvedUsingTypenameDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001190 OS << ' ';
1191 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
1192 OS << D->getNameAsString();
1193}
1194
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001195void ASTDumper::VisitUnresolvedUsingValueDecl(const UnresolvedUsingValueDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001196 OS << ' ';
1197 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
1198 OS << D->getNameAsString();
1199 dumpType(D->getType());
1200}
1201
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001202void ASTDumper::VisitUsingShadowDecl(const UsingShadowDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001203 OS << ' ';
1204 dumpBareDeclRef(D->getTargetDecl());
1205}
1206
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001207void ASTDumper::VisitLinkageSpecDecl(const LinkageSpecDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001208 switch (D->getLanguage()) {
1209 case LinkageSpecDecl::lang_c: OS << " C"; break;
1210 case LinkageSpecDecl::lang_cxx: OS << " C++"; break;
1211 }
1212}
1213
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001214void ASTDumper::VisitAccessSpecDecl(const AccessSpecDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001215 OS << ' ';
1216 dumpAccessSpecifier(D->getAccess());
1217}
1218
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001219void ASTDumper::VisitFriendDecl(const FriendDecl *D) {
Richard Smithf5f43542013-02-07 01:35:44 +00001220 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001221 if (TypeSourceInfo *T = D->getFriendType())
1222 dumpType(T->getType());
1223 else
1224 dumpDecl(D->getFriendDecl());
1225}
1226
1227//===----------------------------------------------------------------------===//
1228// Obj-C Declarations
1229//===----------------------------------------------------------------------===//
1230
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001231void ASTDumper::VisitObjCIvarDecl(const ObjCIvarDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001232 dumpName(D);
1233 dumpType(D->getType());
1234 if (D->getSynthesize())
1235 OS << " synthesize";
1236
1237 switch (D->getAccessControl()) {
1238 case ObjCIvarDecl::None:
1239 OS << " none";
1240 break;
1241 case ObjCIvarDecl::Private:
1242 OS << " private";
1243 break;
1244 case ObjCIvarDecl::Protected:
1245 OS << " protected";
1246 break;
1247 case ObjCIvarDecl::Public:
1248 OS << " public";
1249 break;
1250 case ObjCIvarDecl::Package:
1251 OS << " package";
1252 break;
1253 }
1254}
1255
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001256void ASTDumper::VisitObjCMethodDecl(const ObjCMethodDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001257 if (D->isInstanceMethod())
1258 OS << " -";
1259 else
1260 OS << " +";
1261 dumpName(D);
1262 dumpType(D->getResultType());
1263
Richard Trieude5cc7d2013-01-31 01:44:26 +00001264 bool OldMoreChildren = hasMoreChildren();
1265 bool IsVariadic = D->isVariadic();
1266 bool HasBody = D->hasBody();
1267
1268 setMoreChildren(OldMoreChildren || IsVariadic || HasBody);
1269 if (D->isThisDeclarationADefinition()) {
1270 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001271 dumpDeclContext(D);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001272 } else {
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001273 for (ObjCMethodDecl::param_const_iterator I = D->param_begin(),
1274 E = D->param_end();
1275 I != E; ++I) {
Richard Trieude5cc7d2013-01-31 01:44:26 +00001276 if (I + 1 == E)
1277 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001278 dumpDecl(*I);
1279 }
1280 }
1281
Richard Trieude5cc7d2013-01-31 01:44:26 +00001282 setMoreChildren(OldMoreChildren || HasBody);
1283 if (IsVariadic) {
1284 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001285 IndentScope Indent(*this);
1286 OS << "...";
1287 }
1288
Richard Trieude5cc7d2013-01-31 01:44:26 +00001289 setMoreChildren(OldMoreChildren);
1290 if (HasBody) {
1291 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001292 dumpStmt(D->getBody());
Richard Trieude5cc7d2013-01-31 01:44:26 +00001293 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001294}
1295
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001296void ASTDumper::VisitObjCCategoryDecl(const ObjCCategoryDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001297 dumpName(D);
1298 dumpDeclRef(D->getClassInterface());
Richard Trieude5cc7d2013-01-31 01:44:26 +00001299 if (D->protocol_begin() == D->protocol_end())
1300 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001301 dumpDeclRef(D->getImplementation());
1302 for (ObjCCategoryDecl::protocol_iterator I = D->protocol_begin(),
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001303 E = D->protocol_end();
1304 I != E; ++I) {
Richard Trieude5cc7d2013-01-31 01:44:26 +00001305 if (I + 1 == E)
1306 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001307 dumpDeclRef(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001308 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001309}
1310
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001311void ASTDumper::VisitObjCCategoryImplDecl(const ObjCCategoryImplDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001312 dumpName(D);
1313 dumpDeclRef(D->getClassInterface());
Richard Trieude5cc7d2013-01-31 01:44:26 +00001314 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001315 dumpDeclRef(D->getCategoryDecl());
1316}
1317
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001318void ASTDumper::VisitObjCProtocolDecl(const ObjCProtocolDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001319 dumpName(D);
1320 for (ObjCProtocolDecl::protocol_iterator I = D->protocol_begin(),
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001321 E = D->protocol_end();
1322 I != E; ++I) {
Richard Trieude5cc7d2013-01-31 01:44:26 +00001323 if (I + 1 == E)
1324 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001325 dumpDeclRef(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001326 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001327}
1328
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001329void ASTDumper::VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001330 dumpName(D);
1331 dumpDeclRef(D->getSuperClass(), "super");
Richard Trieude5cc7d2013-01-31 01:44:26 +00001332 if (D->protocol_begin() == D->protocol_end())
1333 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001334 dumpDeclRef(D->getImplementation());
1335 for (ObjCInterfaceDecl::protocol_iterator I = D->protocol_begin(),
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001336 E = D->protocol_end();
1337 I != E; ++I) {
Richard Trieude5cc7d2013-01-31 01:44:26 +00001338 if (I + 1 == E)
1339 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001340 dumpDeclRef(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001341 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001342}
1343
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001344void ASTDumper::VisitObjCImplementationDecl(const ObjCImplementationDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001345 dumpName(D);
1346 dumpDeclRef(D->getSuperClass(), "super");
Richard Trieude5cc7d2013-01-31 01:44:26 +00001347 if (D->init_begin() == D->init_end())
1348 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001349 dumpDeclRef(D->getClassInterface());
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001350 for (ObjCImplementationDecl::init_const_iterator I = D->init_begin(),
1351 E = D->init_end();
1352 I != E; ++I) {
Richard Trieude5cc7d2013-01-31 01:44:26 +00001353 if (I + 1 == E)
1354 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001355 dumpCXXCtorInitializer(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001356 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001357}
1358
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001359void ASTDumper::VisitObjCCompatibleAliasDecl(const ObjCCompatibleAliasDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001360 dumpName(D);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001361 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001362 dumpDeclRef(D->getClassInterface());
1363}
1364
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001365void ASTDumper::VisitObjCPropertyDecl(const ObjCPropertyDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001366 dumpName(D);
1367 dumpType(D->getType());
1368
1369 if (D->getPropertyImplementation() == ObjCPropertyDecl::Required)
1370 OS << " required";
1371 else if (D->getPropertyImplementation() == ObjCPropertyDecl::Optional)
1372 OS << " optional";
1373
1374 ObjCPropertyDecl::PropertyAttributeKind Attrs = D->getPropertyAttributes();
1375 if (Attrs != ObjCPropertyDecl::OBJC_PR_noattr) {
1376 if (Attrs & ObjCPropertyDecl::OBJC_PR_readonly)
1377 OS << " readonly";
1378 if (Attrs & ObjCPropertyDecl::OBJC_PR_assign)
1379 OS << " assign";
1380 if (Attrs & ObjCPropertyDecl::OBJC_PR_readwrite)
1381 OS << " readwrite";
1382 if (Attrs & ObjCPropertyDecl::OBJC_PR_retain)
1383 OS << " retain";
1384 if (Attrs & ObjCPropertyDecl::OBJC_PR_copy)
1385 OS << " copy";
1386 if (Attrs & ObjCPropertyDecl::OBJC_PR_nonatomic)
1387 OS << " nonatomic";
1388 if (Attrs & ObjCPropertyDecl::OBJC_PR_atomic)
1389 OS << " atomic";
1390 if (Attrs & ObjCPropertyDecl::OBJC_PR_weak)
1391 OS << " weak";
1392 if (Attrs & ObjCPropertyDecl::OBJC_PR_strong)
1393 OS << " strong";
1394 if (Attrs & ObjCPropertyDecl::OBJC_PR_unsafe_unretained)
1395 OS << " unsafe_unretained";
Richard Trieude5cc7d2013-01-31 01:44:26 +00001396 if (Attrs & ObjCPropertyDecl::OBJC_PR_getter) {
1397 if (!(Attrs & ObjCPropertyDecl::OBJC_PR_setter))
1398 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001399 dumpDeclRef(D->getGetterMethodDecl(), "getter");
Richard Trieude5cc7d2013-01-31 01:44:26 +00001400 }
1401 if (Attrs & ObjCPropertyDecl::OBJC_PR_setter) {
1402 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001403 dumpDeclRef(D->getSetterMethodDecl(), "setter");
Richard Trieude5cc7d2013-01-31 01:44:26 +00001404 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001405 }
1406}
1407
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001408void ASTDumper::VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001409 dumpName(D->getPropertyDecl());
1410 if (D->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize)
1411 OS << " synthesize";
1412 else
1413 OS << " dynamic";
1414 dumpDeclRef(D->getPropertyDecl());
Richard Trieude5cc7d2013-01-31 01:44:26 +00001415 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001416 dumpDeclRef(D->getPropertyIvarDecl());
1417}
1418
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001419void ASTDumper::VisitBlockDecl(const BlockDecl *D) {
1420 for (BlockDecl::param_const_iterator I = D->param_begin(), E = D->param_end();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001421 I != E; ++I)
1422 dumpDecl(*I);
1423
1424 if (D->isVariadic()) {
1425 IndentScope Indent(*this);
1426 OS << "...";
1427 }
1428
1429 if (D->capturesCXXThis()) {
1430 IndentScope Indent(*this);
1431 OS << "capture this";
1432 }
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001433 for (BlockDecl::capture_iterator I = D->capture_begin(), E = D->capture_end();
1434 I != E; ++I) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001435 IndentScope Indent(*this);
1436 OS << "capture";
1437 if (I->isByRef())
1438 OS << " byref";
1439 if (I->isNested())
1440 OS << " nested";
1441 if (I->getVariable()) {
1442 OS << ' ';
1443 dumpBareDeclRef(I->getVariable());
1444 }
1445 if (I->hasCopyExpr())
1446 dumpStmt(I->getCopyExpr());
1447 }
Richard Trieude5cc7d2013-01-31 01:44:26 +00001448 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001449 dumpStmt(D->getBody());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001450}
1451
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001452//===----------------------------------------------------------------------===//
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001453// Stmt dumping methods.
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001454//===----------------------------------------------------------------------===//
1455
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001456void ASTDumper::dumpStmt(const Stmt *S) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001457 IndentScope Indent(*this);
1458
1459 if (!S) {
Richard Trieud215b8d2013-01-26 01:31:20 +00001460 ColorScope Color(*this, NullColor);
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001461 OS << "<<<NULL>>>";
1462 return;
1463 }
1464
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001465 if (const DeclStmt *DS = dyn_cast<DeclStmt>(S)) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001466 VisitDeclStmt(DS);
1467 return;
1468 }
1469
David Blaikie7d170102013-05-15 07:37:26 +00001470 setMoreChildren(!S->children().empty());
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001471 ConstStmtVisitor<ASTDumper>::Visit(S);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001472 setMoreChildren(false);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001473 for (Stmt::const_child_range CI = S->children(); CI; ++CI) {
1474 Stmt::const_child_range Next = CI;
Richard Trieude5cc7d2013-01-31 01:44:26 +00001475 ++Next;
1476 if (!Next)
1477 lastChild();
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001478 dumpStmt(*CI);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001479 }
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001480}
1481
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001482void ASTDumper::VisitStmt(const Stmt *Node) {
Richard Trieud215b8d2013-01-26 01:31:20 +00001483 {
1484 ColorScope Color(*this, StmtColor);
1485 OS << Node->getStmtClassName();
1486 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001487 dumpPointer(Node);
1488 dumpSourceRange(Node->getSourceRange());
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001489}
1490
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001491void ASTDumper::VisitDeclStmt(const DeclStmt *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001492 VisitStmt(Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001493 for (DeclStmt::const_decl_iterator I = Node->decl_begin(),
1494 E = Node->decl_end();
Richard Trieude5cc7d2013-01-31 01:44:26 +00001495 I != E; ++I) {
1496 if (I + 1 == E)
1497 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001498 dumpDecl(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001499 }
Ted Kremenek433a4922007-12-12 06:59:42 +00001500}
1501
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001502void ASTDumper::VisitAttributedStmt(const AttributedStmt *Node) {
Alexander Kornienko5bc364e2013-01-07 17:53:08 +00001503 VisitStmt(Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001504 for (ArrayRef<const Attr *>::iterator I = Node->getAttrs().begin(),
1505 E = Node->getAttrs().end();
1506 I != E; ++I) {
Richard Trieude5cc7d2013-01-31 01:44:26 +00001507 if (I + 1 == E)
1508 lastChild();
Alexander Kornienko5bc364e2013-01-07 17:53:08 +00001509 dumpAttr(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001510 }
Alexander Kornienko5bc364e2013-01-07 17:53:08 +00001511}
1512
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001513void ASTDumper::VisitLabelStmt(const LabelStmt *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001514 VisitStmt(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001515 OS << " '" << Node->getName() << "'";
Chris Lattnercbe4f772007-08-08 22:51:59 +00001516}
1517
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001518void ASTDumper::VisitGotoStmt(const GotoStmt *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001519 VisitStmt(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001520 OS << " '" << Node->getLabel()->getName() << "'";
1521 dumpPointer(Node->getLabel());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001522}
1523
Pavel Labath1ef83422013-09-04 14:35:00 +00001524void ASTDumper::VisitCXXCatchStmt(const CXXCatchStmt *Node) {
1525 VisitStmt(Node);
1526 dumpDecl(Node->getExceptionDecl());
1527}
1528
Chris Lattnercbe4f772007-08-08 22:51:59 +00001529//===----------------------------------------------------------------------===//
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001530// Expr dumping methods.
Chris Lattnercbe4f772007-08-08 22:51:59 +00001531//===----------------------------------------------------------------------===//
1532
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001533void ASTDumper::VisitExpr(const Expr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001534 VisitStmt(Node);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001535 dumpType(Node->getType());
1536
Richard Trieud215b8d2013-01-26 01:31:20 +00001537 {
1538 ColorScope Color(*this, ValueKindColor);
1539 switch (Node->getValueKind()) {
1540 case VK_RValue:
1541 break;
1542 case VK_LValue:
1543 OS << " lvalue";
1544 break;
1545 case VK_XValue:
1546 OS << " xvalue";
1547 break;
1548 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001549 }
1550
Richard Trieud215b8d2013-01-26 01:31:20 +00001551 {
1552 ColorScope Color(*this, ObjectKindColor);
1553 switch (Node->getObjectKind()) {
1554 case OK_Ordinary:
1555 break;
1556 case OK_BitField:
1557 OS << " bitfield";
1558 break;
1559 case OK_ObjCProperty:
1560 OS << " objcproperty";
1561 break;
1562 case OK_ObjCSubscript:
1563 OS << " objcsubscript";
1564 break;
1565 case OK_VectorComponent:
1566 OS << " vectorcomponent";
1567 break;
1568 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001569 }
Chris Lattnercbe4f772007-08-08 22:51:59 +00001570}
1571
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001572static void dumpBasePath(raw_ostream &OS, const CastExpr *Node) {
John McCallcf142162010-08-07 06:22:56 +00001573 if (Node->path_empty())
Anders Carlssona70cff62010-04-24 19:06:50 +00001574 return;
1575
1576 OS << " (";
1577 bool First = true;
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001578 for (CastExpr::path_const_iterator I = Node->path_begin(),
1579 E = Node->path_end();
1580 I != E; ++I) {
Anders Carlssona70cff62010-04-24 19:06:50 +00001581 const CXXBaseSpecifier *Base = *I;
1582 if (!First)
1583 OS << " -> ";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001584
Anders Carlssona70cff62010-04-24 19:06:50 +00001585 const CXXRecordDecl *RD =
1586 cast<CXXRecordDecl>(Base->getType()->getAs<RecordType>()->getDecl());
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001587
Anders Carlssona70cff62010-04-24 19:06:50 +00001588 if (Base->isVirtual())
1589 OS << "virtual ";
1590 OS << RD->getName();
1591 First = false;
1592 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001593
Anders Carlssona70cff62010-04-24 19:06:50 +00001594 OS << ')';
1595}
1596
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001597void ASTDumper::VisitCastExpr(const CastExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001598 VisitExpr(Node);
Richard Trieud215b8d2013-01-26 01:31:20 +00001599 OS << " <";
1600 {
1601 ColorScope Color(*this, CastColor);
1602 OS << Node->getCastKindName();
1603 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001604 dumpBasePath(OS, Node);
Anders Carlssona70cff62010-04-24 19:06:50 +00001605 OS << ">";
Anders Carlssond7923c62009-08-22 23:33:40 +00001606}
1607
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001608void ASTDumper::VisitDeclRefExpr(const DeclRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001609 VisitExpr(Node);
Ted Kremenek5f64ca82007-09-10 17:32:55 +00001610
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001611 OS << " ";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001612 dumpBareDeclRef(Node->getDecl());
Chandler Carruth8d26bb02011-05-01 23:48:14 +00001613 if (Node->getDecl() != Node->getFoundDecl()) {
1614 OS << " (";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001615 dumpBareDeclRef(Node->getFoundDecl());
Chandler Carruth8d26bb02011-05-01 23:48:14 +00001616 OS << ")";
1617 }
John McCall351762c2011-02-07 10:33:21 +00001618}
1619
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001620void ASTDumper::VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001621 VisitExpr(Node);
John McCall76d09942009-12-11 21:50:11 +00001622 OS << " (";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001623 if (!Node->requiresADL())
1624 OS << "no ";
Benjamin Kramerb11416d2010-04-17 09:33:03 +00001625 OS << "ADL) = '" << Node->getName() << '\'';
John McCall76d09942009-12-11 21:50:11 +00001626
1627 UnresolvedLookupExpr::decls_iterator
1628 I = Node->decls_begin(), E = Node->decls_end();
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001629 if (I == E)
1630 OS << " empty";
John McCall76d09942009-12-11 21:50:11 +00001631 for (; I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001632 dumpPointer(*I);
John McCall76d09942009-12-11 21:50:11 +00001633}
1634
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001635void ASTDumper::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001636 VisitExpr(Node);
Steve Naroff5d5efca2008-03-12 13:19:12 +00001637
Richard Trieud215b8d2013-01-26 01:31:20 +00001638 {
1639 ColorScope Color(*this, DeclKindNameColor);
1640 OS << " " << Node->getDecl()->getDeclKindName() << "Decl";
1641 }
1642 OS << "='" << *Node->getDecl() << "'";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001643 dumpPointer(Node->getDecl());
Steve Naroffb3424a92008-05-23 22:01:24 +00001644 if (Node->isFreeIvar())
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001645 OS << " isFreeIvar";
Steve Naroff5d5efca2008-03-12 13:19:12 +00001646}
1647
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001648void ASTDumper::VisitPredefinedExpr(const PredefinedExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001649 VisitExpr(Node);
Chris Lattnercbe4f772007-08-08 22:51:59 +00001650 switch (Node->getIdentType()) {
David Blaikie83d382b2011-09-23 05:06:16 +00001651 default: llvm_unreachable("unknown case");
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001652 case PredefinedExpr::Func: OS << " __func__"; break;
1653 case PredefinedExpr::Function: OS << " __FUNCTION__"; break;
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001654 case PredefinedExpr::LFunction: OS << " L__FUNCTION__"; break;
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001655 case PredefinedExpr::PrettyFunction: OS << " __PRETTY_FUNCTION__";break;
Chris Lattnercbe4f772007-08-08 22:51:59 +00001656 }
1657}
1658
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001659void ASTDumper::VisitCharacterLiteral(const CharacterLiteral *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001660 VisitExpr(Node);
Richard Trieud215b8d2013-01-26 01:31:20 +00001661 ColorScope Color(*this, ValueColor);
Richard Trieu364ee422011-11-03 23:56:23 +00001662 OS << " " << Node->getValue();
Chris Lattnercbe4f772007-08-08 22:51:59 +00001663}
1664
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001665void ASTDumper::VisitIntegerLiteral(const IntegerLiteral *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001666 VisitExpr(Node);
Chris Lattnercbe4f772007-08-08 22:51:59 +00001667
1668 bool isSigned = Node->getType()->isSignedIntegerType();
Richard Trieud215b8d2013-01-26 01:31:20 +00001669 ColorScope Color(*this, ValueColor);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001670 OS << " " << Node->getValue().toString(10, isSigned);
Chris Lattnercbe4f772007-08-08 22:51:59 +00001671}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001672
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001673void ASTDumper::VisitFloatingLiteral(const FloatingLiteral *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001674 VisitExpr(Node);
Richard Trieud215b8d2013-01-26 01:31:20 +00001675 ColorScope Color(*this, ValueColor);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001676 OS << " " << Node->getValueAsApproximateDouble();
Chris Lattnercbe4f772007-08-08 22:51:59 +00001677}
Chris Lattner1c20a172007-08-26 03:42:43 +00001678
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001679void ASTDumper::VisitStringLiteral(const StringLiteral *Str) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001680 VisitExpr(Str);
Richard Trieud215b8d2013-01-26 01:31:20 +00001681 ColorScope Color(*this, ValueColor);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001682 OS << " ";
Richard Trieudc355912012-06-13 20:25:24 +00001683 Str->outputString(OS);
Chris Lattnercbe4f772007-08-08 22:51:59 +00001684}
Chris Lattner84ca3762007-08-30 01:00:35 +00001685
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001686void ASTDumper::VisitUnaryOperator(const UnaryOperator *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001687 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001688 OS << " " << (Node->isPostfix() ? "postfix" : "prefix")
1689 << " '" << UnaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
Chris Lattnercbe4f772007-08-08 22:51:59 +00001690}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001691
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001692void ASTDumper::VisitUnaryExprOrTypeTraitExpr(
1693 const UnaryExprOrTypeTraitExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001694 VisitExpr(Node);
Peter Collingbournee190dee2011-03-11 19:24:49 +00001695 switch(Node->getKind()) {
1696 case UETT_SizeOf:
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001697 OS << " sizeof";
Peter Collingbournee190dee2011-03-11 19:24:49 +00001698 break;
1699 case UETT_AlignOf:
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001700 OS << " alignof";
Peter Collingbournee190dee2011-03-11 19:24:49 +00001701 break;
1702 case UETT_VecStep:
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001703 OS << " vec_step";
Peter Collingbournee190dee2011-03-11 19:24:49 +00001704 break;
1705 }
Sebastian Redl6f282892008-11-11 17:56:53 +00001706 if (Node->isArgumentType())
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001707 dumpType(Node->getArgumentType());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001708}
Chris Lattnerdb3b3ff2007-08-09 17:35:30 +00001709
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001710void ASTDumper::VisitMemberExpr(const MemberExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001711 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001712 OS << " " << (Node->isArrow() ? "->" : ".") << *Node->getMemberDecl();
1713 dumpPointer(Node->getMemberDecl());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001714}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001715
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001716void ASTDumper::VisitExtVectorElementExpr(const ExtVectorElementExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001717 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001718 OS << " " << Node->getAccessor().getNameStart();
Chris Lattnercbe4f772007-08-08 22:51:59 +00001719}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001720
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001721void ASTDumper::VisitBinaryOperator(const BinaryOperator *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001722 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001723 OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
Chris Lattner86928112007-08-25 02:00:02 +00001724}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001725
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001726void ASTDumper::VisitCompoundAssignOperator(
1727 const CompoundAssignOperator *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001728 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001729 OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode())
1730 << "' ComputeLHSTy=";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001731 dumpBareType(Node->getComputationLHSType());
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001732 OS << " ComputeResultTy=";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001733 dumpBareType(Node->getComputationResultType());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001734}
Chris Lattnercbe4f772007-08-08 22:51:59 +00001735
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001736void ASTDumper::VisitBlockExpr(const BlockExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001737 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001738 dumpDecl(Node->getBlockDecl());
John McCall351762c2011-02-07 10:33:21 +00001739}
1740
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001741void ASTDumper::VisitOpaqueValueExpr(const OpaqueValueExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001742 VisitExpr(Node);
John McCallfe96e0b2011-11-06 09:01:30 +00001743
Richard Trieude5cc7d2013-01-31 01:44:26 +00001744 if (Expr *Source = Node->getSourceExpr()) {
1745 lastChild();
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001746 dumpStmt(Source);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001747 }
John McCallfe96e0b2011-11-06 09:01:30 +00001748}
1749
Chris Lattnercbe4f772007-08-08 22:51:59 +00001750// GNU extensions.
1751
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001752void ASTDumper::VisitAddrLabelExpr(const AddrLabelExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001753 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001754 OS << " " << Node->getLabel()->getName();
1755 dumpPointer(Node->getLabel());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001756}
1757
Chris Lattner8f184b12007-08-09 18:03:18 +00001758//===----------------------------------------------------------------------===//
1759// C++ Expressions
1760//===----------------------------------------------------------------------===//
Chris Lattnercbe4f772007-08-08 22:51:59 +00001761
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001762void ASTDumper::VisitCXXNamedCastExpr(const CXXNamedCastExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001763 VisitExpr(Node);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001764 OS << " " << Node->getCastName()
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001765 << "<" << Node->getTypeAsWritten().getAsString() << ">"
Anders Carlssona70cff62010-04-24 19:06:50 +00001766 << " <" << Node->getCastKindName();
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001767 dumpBasePath(OS, Node);
Anders Carlssona70cff62010-04-24 19:06:50 +00001768 OS << ">";
Chris Lattnercbe4f772007-08-08 22:51:59 +00001769}
1770
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001771void ASTDumper::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001772 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001773 OS << " " << (Node->getValue() ? "true" : "false");
Chris Lattnercbe4f772007-08-08 22:51:59 +00001774}
1775
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001776void ASTDumper::VisitCXXThisExpr(const CXXThisExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001777 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001778 OS << " this";
Douglas Gregor8ea1f532008-11-04 14:56:14 +00001779}
1780
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001781void ASTDumper::VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001782 VisitExpr(Node);
Eli Friedman29538892011-09-02 17:38:59 +00001783 OS << " functional cast to " << Node->getTypeAsWritten().getAsString()
1784 << " <" << Node->getCastKindName() << ">";
Douglas Gregore200adc2008-10-27 19:41:14 +00001785}
1786
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001787void ASTDumper::VisitCXXConstructExpr(const CXXConstructExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001788 VisitExpr(Node);
John McCalleba90cd2010-02-02 19:03:45 +00001789 CXXConstructorDecl *Ctor = Node->getConstructor();
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001790 dumpType(Ctor->getType());
Anders Carlsson073846832009-08-12 00:21:52 +00001791 if (Node->isElidable())
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001792 OS << " elidable";
John McCall85370042010-08-07 06:38:55 +00001793 if (Node->requiresZeroInitialization())
1794 OS << " zeroing";
Anders Carlsson073846832009-08-12 00:21:52 +00001795}
1796
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001797void ASTDumper::VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001798 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001799 OS << " ";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001800 dumpCXXTemporary(Node->getTemporary());
Anders Carlsson073846832009-08-12 00:21:52 +00001801}
1802
Richard Smithe6c01442013-06-05 00:46:14 +00001803void
1804ASTDumper::VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *Node) {
1805 VisitExpr(Node);
1806 if (const ValueDecl *VD = Node->getExtendingDecl()) {
1807 OS << " extended by ";
1808 dumpBareDeclRef(VD);
1809 }
1810}
1811
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001812void ASTDumper::VisitExprWithCleanups(const ExprWithCleanups *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001813 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001814 for (unsigned i = 0, e = Node->getNumObjects(); i != e; ++i)
1815 dumpDeclRef(Node->getObject(i), "cleanup");
Anders Carlsson073846832009-08-12 00:21:52 +00001816}
1817
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001818void ASTDumper::dumpCXXTemporary(const CXXTemporary *Temporary) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001819 OS << "(CXXTemporary";
1820 dumpPointer(Temporary);
1821 OS << ")";
Anders Carlsson073846832009-08-12 00:21:52 +00001822}
1823
Anders Carlsson76f4a902007-08-21 17:43:55 +00001824//===----------------------------------------------------------------------===//
1825// Obj-C Expressions
1826//===----------------------------------------------------------------------===//
1827
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001828void ASTDumper::VisitObjCMessageExpr(const ObjCMessageExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001829 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001830 OS << " selector=" << Node->getSelector().getAsString();
Douglas Gregor9a129192010-04-21 00:45:42 +00001831 switch (Node->getReceiverKind()) {
1832 case ObjCMessageExpr::Instance:
1833 break;
1834
1835 case ObjCMessageExpr::Class:
1836 OS << " class=";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001837 dumpBareType(Node->getClassReceiver());
Douglas Gregor9a129192010-04-21 00:45:42 +00001838 break;
1839
1840 case ObjCMessageExpr::SuperInstance:
1841 OS << " super (instance)";
1842 break;
1843
1844 case ObjCMessageExpr::SuperClass:
1845 OS << " super (class)";
1846 break;
1847 }
Ted Kremenek36748da2008-02-29 22:04:05 +00001848}
1849
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001850void ASTDumper::VisitObjCBoxedExpr(const ObjCBoxedExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001851 VisitExpr(Node);
Argyrios Kyrtzidis9dd40892012-05-10 20:02:31 +00001852 OS << " selector=" << Node->getBoxingMethod()->getSelector().getAsString();
1853}
1854
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001855void ASTDumper::VisitObjCAtCatchStmt(const ObjCAtCatchStmt *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001856 VisitStmt(Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001857 if (const VarDecl *CatchParam = Node->getCatchParamDecl())
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001858 dumpDecl(CatchParam);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001859 else
Douglas Gregor96c79492010-04-23 22:50:49 +00001860 OS << " catch all";
Douglas Gregor96c79492010-04-23 22:50:49 +00001861}
1862
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001863void ASTDumper::VisitObjCEncodeExpr(const ObjCEncodeExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001864 VisitExpr(Node);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001865 dumpType(Node->getEncodedType());
Anders Carlssonc5a81eb2007-08-22 15:14:15 +00001866}
1867
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001868void ASTDumper::VisitObjCSelectorExpr(const ObjCSelectorExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001869 VisitExpr(Node);
Mike Stump11289f42009-09-09 15:08:12 +00001870
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001871 OS << " " << Node->getSelector().getAsString();
Fariborz Jahanian4bef4622007-10-16 20:40:23 +00001872}
1873
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001874void ASTDumper::VisitObjCProtocolExpr(const ObjCProtocolExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001875 VisitExpr(Node);
Mike Stump11289f42009-09-09 15:08:12 +00001876
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001877 OS << ' ' << *Node->getProtocol();
Fariborz Jahaniana32aaef2007-10-17 16:58:11 +00001878}
Daniel Dunbar4b8c6db2008-08-30 05:35:15 +00001879
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001880void ASTDumper::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001881 VisitExpr(Node);
John McCallb7bd14f2010-12-02 01:19:52 +00001882 if (Node->isImplicitProperty()) {
Fariborz Jahanian0f0b3022010-12-22 19:46:35 +00001883 OS << " Kind=MethodRef Getter=\"";
1884 if (Node->getImplicitPropertyGetter())
1885 OS << Node->getImplicitPropertyGetter()->getSelector().getAsString();
1886 else
1887 OS << "(null)";
1888
1889 OS << "\" Setter=\"";
John McCallb7bd14f2010-12-02 01:19:52 +00001890 if (ObjCMethodDecl *Setter = Node->getImplicitPropertySetter())
1891 OS << Setter->getSelector().getAsString();
1892 else
1893 OS << "(null)";
1894 OS << "\"";
1895 } else {
Benjamin Kramerb89514a2011-10-14 18:45:37 +00001896 OS << " Kind=PropertyRef Property=\"" << *Node->getExplicitProperty() <<'"';
John McCallb7bd14f2010-12-02 01:19:52 +00001897 }
Fariborz Jahanian8a1810f2008-11-22 18:39:36 +00001898
Fariborz Jahanian681c0752010-10-14 16:04:05 +00001899 if (Node->isSuperReceiver())
1900 OS << " super";
Argyrios Kyrtzidisab468b02012-03-30 00:19:18 +00001901
1902 OS << " Messaging=";
1903 if (Node->isMessagingGetter() && Node->isMessagingSetter())
1904 OS << "Getter&Setter";
1905 else if (Node->isMessagingGetter())
1906 OS << "Getter";
1907 else if (Node->isMessagingSetter())
1908 OS << "Setter";
Douglas Gregor8ea1f532008-11-04 14:56:14 +00001909}
1910
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001911void ASTDumper::VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001912 VisitExpr(Node);
Ted Kremeneke65b0862012-03-06 20:05:56 +00001913 if (Node->isArraySubscriptRefExpr())
1914 OS << " Kind=ArraySubscript GetterForArray=\"";
1915 else
1916 OS << " Kind=DictionarySubscript GetterForDictionary=\"";
1917 if (Node->getAtIndexMethodDecl())
1918 OS << Node->getAtIndexMethodDecl()->getSelector().getAsString();
1919 else
1920 OS << "(null)";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001921
Ted Kremeneke65b0862012-03-06 20:05:56 +00001922 if (Node->isArraySubscriptRefExpr())
1923 OS << "\" SetterForArray=\"";
1924 else
1925 OS << "\" SetterForDictionary=\"";
1926 if (Node->setAtIndexMethodDecl())
1927 OS << Node->setAtIndexMethodDecl()->getSelector().getAsString();
1928 else
1929 OS << "(null)";
1930}
1931
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001932void ASTDumper::VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001933 VisitExpr(Node);
Ted Kremeneke65b0862012-03-06 20:05:56 +00001934 OS << " " << (Node->getValue() ? "__objc_yes" : "__objc_no");
1935}
1936
Chris Lattnercbe4f772007-08-08 22:51:59 +00001937//===----------------------------------------------------------------------===//
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00001938// Comments
1939//===----------------------------------------------------------------------===//
1940
1941const char *ASTDumper::getCommandName(unsigned CommandID) {
1942 if (Traits)
1943 return Traits->getCommandInfo(CommandID)->Name;
1944 const CommandInfo *Info = CommandTraits::getBuiltinCommandInfo(CommandID);
1945 if (Info)
1946 return Info->Name;
1947 return "<not a builtin command>";
1948}
1949
1950void ASTDumper::dumpFullComment(const FullComment *C) {
1951 if (!C)
1952 return;
1953
1954 FC = C;
1955 dumpComment(C);
1956 FC = 0;
1957}
1958
1959void ASTDumper::dumpComment(const Comment *C) {
1960 IndentScope Indent(*this);
1961
1962 if (!C) {
Richard Trieud215b8d2013-01-26 01:31:20 +00001963 ColorScope Color(*this, NullColor);
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00001964 OS << "<<<NULL>>>";
1965 return;
1966 }
1967
Richard Trieud215b8d2013-01-26 01:31:20 +00001968 {
1969 ColorScope Color(*this, CommentColor);
1970 OS << C->getCommentKindName();
1971 }
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00001972 dumpPointer(C);
1973 dumpSourceRange(C->getSourceRange());
1974 ConstCommentVisitor<ASTDumper>::visit(C);
1975 for (Comment::child_iterator I = C->child_begin(), E = C->child_end();
Richard Trieude5cc7d2013-01-31 01:44:26 +00001976 I != E; ++I) {
1977 if (I + 1 == E)
1978 lastChild();
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00001979 dumpComment(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001980 }
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00001981}
1982
1983void ASTDumper::visitTextComment(const TextComment *C) {
1984 OS << " Text=\"" << C->getText() << "\"";
1985}
1986
1987void ASTDumper::visitInlineCommandComment(const InlineCommandComment *C) {
1988 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\"";
1989 switch (C->getRenderKind()) {
1990 case InlineCommandComment::RenderNormal:
1991 OS << " RenderNormal";
1992 break;
1993 case InlineCommandComment::RenderBold:
1994 OS << " RenderBold";
1995 break;
1996 case InlineCommandComment::RenderMonospaced:
1997 OS << " RenderMonospaced";
1998 break;
1999 case InlineCommandComment::RenderEmphasized:
2000 OS << " RenderEmphasized";
2001 break;
2002 }
2003
2004 for (unsigned i = 0, e = C->getNumArgs(); i != e; ++i)
2005 OS << " Arg[" << i << "]=\"" << C->getArgText(i) << "\"";
2006}
2007
2008void ASTDumper::visitHTMLStartTagComment(const HTMLStartTagComment *C) {
2009 OS << " Name=\"" << C->getTagName() << "\"";
2010 if (C->getNumAttrs() != 0) {
2011 OS << " Attrs: ";
2012 for (unsigned i = 0, e = C->getNumAttrs(); i != e; ++i) {
2013 const HTMLStartTagComment::Attribute &Attr = C->getAttr(i);
2014 OS << " \"" << Attr.Name << "=\"" << Attr.Value << "\"";
2015 }
2016 }
2017 if (C->isSelfClosing())
2018 OS << " SelfClosing";
2019}
2020
2021void ASTDumper::visitHTMLEndTagComment(const HTMLEndTagComment *C) {
2022 OS << " Name=\"" << C->getTagName() << "\"";
2023}
2024
2025void ASTDumper::visitBlockCommandComment(const BlockCommandComment *C) {
2026 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\"";
2027 for (unsigned i = 0, e = C->getNumArgs(); i != e; ++i)
2028 OS << " Arg[" << i << "]=\"" << C->getArgText(i) << "\"";
2029}
2030
2031void ASTDumper::visitParamCommandComment(const ParamCommandComment *C) {
2032 OS << " " << ParamCommandComment::getDirectionAsString(C->getDirection());
2033
2034 if (C->isDirectionExplicit())
2035 OS << " explicitly";
2036 else
2037 OS << " implicitly";
2038
2039 if (C->hasParamName()) {
2040 if (C->isParamIndexValid())
2041 OS << " Param=\"" << C->getParamName(FC) << "\"";
2042 else
2043 OS << " Param=\"" << C->getParamNameAsWritten() << "\"";
2044 }
2045
2046 if (C->isParamIndexValid())
2047 OS << " ParamIndex=" << C->getParamIndex();
2048}
2049
2050void ASTDumper::visitTParamCommandComment(const TParamCommandComment *C) {
2051 if (C->hasParamName()) {
2052 if (C->isPositionValid())
2053 OS << " Param=\"" << C->getParamName(FC) << "\"";
2054 else
2055 OS << " Param=\"" << C->getParamNameAsWritten() << "\"";
2056 }
2057
2058 if (C->isPositionValid()) {
2059 OS << " Position=<";
2060 for (unsigned i = 0, e = C->getDepth(); i != e; ++i) {
2061 OS << C->getIndex(i);
2062 if (i != e - 1)
2063 OS << ", ";
2064 }
2065 OS << ">";
2066 }
2067}
2068
2069void ASTDumper::visitVerbatimBlockComment(const VerbatimBlockComment *C) {
2070 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\""
2071 " CloseName=\"" << C->getCloseName() << "\"";
2072}
2073
2074void ASTDumper::visitVerbatimBlockLineComment(
2075 const VerbatimBlockLineComment *C) {
2076 OS << " Text=\"" << C->getText() << "\"";
2077}
2078
2079void ASTDumper::visitVerbatimLineComment(const VerbatimLineComment *C) {
2080 OS << " Text=\"" << C->getText() << "\"";
2081}
2082
2083//===----------------------------------------------------------------------===//
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002084// Decl method implementations
2085//===----------------------------------------------------------------------===//
2086
2087void Decl::dump() const {
2088 dump(llvm::errs());
2089}
2090
2091void Decl::dump(raw_ostream &OS) const {
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002092 ASTDumper P(OS, &getASTContext().getCommentCommandTraits(),
2093 &getASTContext().getSourceManager());
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002094 P.dumpDecl(this);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002095}
2096
Richard Trieud215b8d2013-01-26 01:31:20 +00002097void Decl::dumpColor() const {
2098 ASTDumper P(llvm::errs(), &getASTContext().getCommentCommandTraits(),
2099 &getASTContext().getSourceManager(), /*ShowColors*/true);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002100 P.dumpDecl(this);
Richard Trieud215b8d2013-01-26 01:31:20 +00002101}
Richard Smith33937e72013-06-22 21:49:40 +00002102
2103void DeclContext::dumpLookups() const {
Richard Smith6ea05822013-06-24 01:45:33 +00002104 dumpLookups(llvm::errs());
2105}
2106
2107void DeclContext::dumpLookups(raw_ostream &OS) const {
Richard Smith33937e72013-06-22 21:49:40 +00002108 const DeclContext *DC = this;
2109 while (!DC->isTranslationUnit())
2110 DC = DC->getParent();
2111 ASTContext &Ctx = cast<TranslationUnitDecl>(DC)->getASTContext();
Richard Smith6ea05822013-06-24 01:45:33 +00002112 ASTDumper P(OS, &Ctx.getCommentCommandTraits(), &Ctx.getSourceManager());
Richard Smith33937e72013-06-22 21:49:40 +00002113 P.dumpLookups(this);
2114}
2115
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002116//===----------------------------------------------------------------------===//
Chris Lattnercbe4f772007-08-08 22:51:59 +00002117// Stmt method implementations
2118//===----------------------------------------------------------------------===//
2119
Chris Lattner11e30d32007-08-30 06:17:34 +00002120void Stmt::dump(SourceManager &SM) const {
Argyrios Kyrtzidisc049f752010-08-09 10:54:31 +00002121 dump(llvm::errs(), SM);
2122}
2123
Chris Lattner0e62c1c2011-07-23 10:55:15 +00002124void Stmt::dump(raw_ostream &OS, SourceManager &SM) const {
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002125 ASTDumper P(OS, 0, &SM);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002126 P.dumpStmt(this);
Chris Lattner779d5d92007-08-30 00:40:08 +00002127}
2128
Chris Lattnercbe4f772007-08-08 22:51:59 +00002129void Stmt::dump() const {
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002130 ASTDumper P(llvm::errs(), 0, 0);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002131 P.dumpStmt(this);
Chris Lattnercbe4f772007-08-08 22:51:59 +00002132}
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002133
Richard Trieud215b8d2013-01-26 01:31:20 +00002134void Stmt::dumpColor() const {
2135 ASTDumper P(llvm::errs(), 0, 0, /*ShowColors*/true);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002136 P.dumpStmt(this);
Richard Trieud215b8d2013-01-26 01:31:20 +00002137}
2138
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002139//===----------------------------------------------------------------------===//
2140// Comment method implementations
2141//===----------------------------------------------------------------------===//
2142
2143void Comment::dump() const {
2144 dump(llvm::errs(), 0, 0);
2145}
2146
2147void Comment::dump(const ASTContext &Context) const {
2148 dump(llvm::errs(), &Context.getCommentCommandTraits(),
2149 &Context.getSourceManager());
2150}
2151
Alexander Kornienko00911f12013-01-15 12:20:21 +00002152void Comment::dump(raw_ostream &OS, const CommandTraits *Traits,
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002153 const SourceManager *SM) const {
2154 const FullComment *FC = dyn_cast<FullComment>(this);
2155 ASTDumper D(OS, Traits, SM);
2156 D.dumpFullComment(FC);
2157}
Richard Trieud215b8d2013-01-26 01:31:20 +00002158
2159void Comment::dumpColor() const {
2160 const FullComment *FC = dyn_cast<FullComment>(this);
2161 ASTDumper D(llvm::errs(), 0, 0, /*ShowColors*/true);
2162 D.dumpFullComment(FC);
2163}