blob: 2f402559f4da32b4c616936de3618f39c1bfca28 [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();
Richard Smith77c5bb52013-10-18 01:34:56 +0000504 for (DeclContext::decl_iterator I = DC->noload_decls_begin(),
505 E = DC->noload_decls_end();
Richard Trieude5cc7d2013-01-31 01:44:26 +0000506 I != E; ++I) {
507 DeclContext::decl_iterator Next = I;
508 ++Next;
Richard Smith1d209d02013-05-23 01:49:11 +0000509 if (Next == E && !HasUndeserializedDecls)
Richard Trieude5cc7d2013-01-31 01:44:26 +0000510 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000511 dumpDecl(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000512 }
Richard Smith1d209d02013-05-23 01:49:11 +0000513 if (HasUndeserializedDecls) {
514 lastChild();
515 IndentScope Indent(*this);
516 ColorScope Color(*this, UndeserializedColor);
517 OS << "<undeserialized declarations>";
518 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000519}
520
Richard Smith33937e72013-06-22 21:49:40 +0000521void ASTDumper::dumpLookups(const DeclContext *DC) {
522 IndentScope Indent(*this);
523
524 OS << "StoredDeclsMap ";
525 dumpBareDeclRef(cast<Decl>(DC));
526
527 const DeclContext *Primary = DC->getPrimaryContext();
528 if (Primary != DC) {
529 OS << " primary";
530 dumpPointer(cast<Decl>(Primary));
531 }
532
533 bool HasUndeserializedLookups = Primary->hasExternalVisibleStorage();
534
535 DeclContext::all_lookups_iterator I = Primary->noload_lookups_begin(),
536 E = Primary->noload_lookups_end();
537 while (I != E) {
538 DeclarationName Name = I.getLookupName();
539 DeclContextLookupResult R = *I++;
540 if (I == E && !HasUndeserializedLookups)
541 lastChild();
542
543 IndentScope Indent(*this);
544 OS << "DeclarationName ";
545 {
546 ColorScope Color(*this, DeclNameColor);
547 OS << '\'' << Name << '\'';
548 }
549
550 for (DeclContextLookupResult::iterator RI = R.begin(), RE = R.end();
551 RI != RE; ++RI) {
552 if (RI + 1 == RE)
553 lastChild();
554 dumpDeclRef(*RI);
Richard Smith15fc7df2013-10-22 23:50:38 +0000555 if ((*RI)->isHidden())
556 OS << " hidden";
Richard Smith33937e72013-06-22 21:49:40 +0000557 }
558 }
559
560 if (HasUndeserializedLookups) {
561 lastChild();
562 IndentScope Indent(*this);
563 ColorScope Color(*this, UndeserializedColor);
564 OS << "<undeserialized lookups>";
565 }
566}
567
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000568void ASTDumper::dumpAttr(const Attr *A) {
569 IndentScope Indent(*this);
Richard Trieud215b8d2013-01-26 01:31:20 +0000570 {
571 ColorScope Color(*this, AttrColor);
572 switch (A->getKind()) {
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000573#define ATTR(X) case attr::X: OS << #X; break;
574#include "clang/Basic/AttrList.inc"
Richard Trieud215b8d2013-01-26 01:31:20 +0000575 default: llvm_unreachable("unexpected attribute kind");
576 }
577 OS << "Attr";
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000578 }
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000579 dumpPointer(A);
580 dumpSourceRange(A->getRange());
581#include "clang/AST/AttrDump.inc"
582}
583
Richard Smith71bec062013-10-15 21:58:30 +0000584static void dumpPreviousDeclImpl(raw_ostream &OS, ...) {}
585
586template<typename T>
587static void dumpPreviousDeclImpl(raw_ostream &OS, const Mergeable<T> *D) {
Rafael Espindola8db352d2013-10-17 15:37:26 +0000588 const T *First = D->getFirstDecl();
Richard Smith71bec062013-10-15 21:58:30 +0000589 if (First != D)
590 OS << " first " << First;
Richard Smithf5f43542013-02-07 01:35:44 +0000591}
592
593template<typename T>
Richard Smith71bec062013-10-15 21:58:30 +0000594static void dumpPreviousDeclImpl(raw_ostream &OS, const Redeclarable<T> *D) {
595 const T *Prev = D->getPreviousDecl();
596 if (Prev)
597 OS << " prev " << Prev;
Richard Smithf5f43542013-02-07 01:35:44 +0000598}
599
Richard Smith71bec062013-10-15 21:58:30 +0000600/// Dump the previous declaration in the redeclaration chain for a declaration,
601/// if any.
602static void dumpPreviousDecl(raw_ostream &OS, const Decl *D) {
Richard Smithf5f43542013-02-07 01:35:44 +0000603 switch (D->getKind()) {
604#define DECL(DERIVED, BASE) \
605 case Decl::DERIVED: \
Richard Smith71bec062013-10-15 21:58:30 +0000606 return dumpPreviousDeclImpl(OS, cast<DERIVED##Decl>(D));
Richard Smithf5f43542013-02-07 01:35:44 +0000607#define ABSTRACT_DECL(DECL)
608#include "clang/AST/DeclNodes.inc"
609 }
610 llvm_unreachable("Decl that isn't part of DeclNodes.inc!");
611}
612
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000613//===----------------------------------------------------------------------===//
614// C++ Utilities
615//===----------------------------------------------------------------------===//
616
617void ASTDumper::dumpAccessSpecifier(AccessSpecifier AS) {
618 switch (AS) {
619 case AS_none:
620 break;
621 case AS_public:
622 OS << "public";
623 break;
624 case AS_protected:
625 OS << "protected";
626 break;
627 case AS_private:
628 OS << "private";
629 break;
630 }
631}
632
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000633void ASTDumper::dumpCXXCtorInitializer(const CXXCtorInitializer *Init) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000634 IndentScope Indent(*this);
635 OS << "CXXCtorInitializer";
636 if (Init->isAnyMemberInitializer()) {
637 OS << ' ';
638 dumpBareDeclRef(Init->getAnyMember());
639 } else {
640 dumpType(QualType(Init->getBaseClass(), 0));
641 }
642 dumpStmt(Init->getInit());
643}
644
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000645void ASTDumper::dumpTemplateParameters(const TemplateParameterList *TPL) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000646 if (!TPL)
647 return;
648
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000649 for (TemplateParameterList::const_iterator I = TPL->begin(), E = TPL->end();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000650 I != E; ++I)
651 dumpDecl(*I);
652}
653
654void ASTDumper::dumpTemplateArgumentListInfo(
655 const TemplateArgumentListInfo &TALI) {
Richard Trieude5cc7d2013-01-31 01:44:26 +0000656 for (unsigned i = 0, e = TALI.size(); i < e; ++i) {
657 if (i + 1 == e)
658 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000659 dumpTemplateArgumentLoc(TALI[i]);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000660 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000661}
662
663void ASTDumper::dumpTemplateArgumentLoc(const TemplateArgumentLoc &A) {
664 dumpTemplateArgument(A.getArgument(), A.getSourceRange());
665}
666
667void ASTDumper::dumpTemplateArgumentList(const TemplateArgumentList &TAL) {
668 for (unsigned i = 0, e = TAL.size(); i < e; ++i)
669 dumpTemplateArgument(TAL[i]);
670}
671
672void ASTDumper::dumpTemplateArgument(const TemplateArgument &A, SourceRange R) {
673 IndentScope Indent(*this);
674 OS << "TemplateArgument";
675 if (R.isValid())
676 dumpSourceRange(R);
677
678 switch (A.getKind()) {
679 case TemplateArgument::Null:
680 OS << " null";
681 break;
682 case TemplateArgument::Type:
683 OS << " type";
Richard Trieude5cc7d2013-01-31 01:44:26 +0000684 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000685 dumpType(A.getAsType());
686 break;
687 case TemplateArgument::Declaration:
688 OS << " decl";
Richard Trieude5cc7d2013-01-31 01:44:26 +0000689 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000690 dumpDeclRef(A.getAsDecl());
691 break;
692 case TemplateArgument::NullPtr:
693 OS << " nullptr";
694 break;
695 case TemplateArgument::Integral:
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000696 OS << " integral " << A.getAsIntegral();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000697 break;
698 case TemplateArgument::Template:
699 OS << " template ";
700 A.getAsTemplate().dump(OS);
701 break;
702 case TemplateArgument::TemplateExpansion:
703 OS << " template expansion";
704 A.getAsTemplateOrTemplatePattern().dump(OS);
705 break;
706 case TemplateArgument::Expression:
707 OS << " expr";
Richard Trieude5cc7d2013-01-31 01:44:26 +0000708 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000709 dumpStmt(A.getAsExpr());
710 break;
711 case TemplateArgument::Pack:
712 OS << " pack";
713 for (TemplateArgument::pack_iterator I = A.pack_begin(), E = A.pack_end();
Richard Trieude5cc7d2013-01-31 01:44:26 +0000714 I != E; ++I) {
715 if (I + 1 == E)
716 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000717 dumpTemplateArgument(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000718 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000719 break;
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000720 }
721}
722
Chris Lattner11e30d32007-08-30 06:17:34 +0000723//===----------------------------------------------------------------------===//
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000724// Decl dumping methods.
Chris Lattnercbe4f772007-08-08 22:51:59 +0000725//===----------------------------------------------------------------------===//
726
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000727void ASTDumper::dumpDecl(const Decl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000728 IndentScope Indent(*this);
Mike Stump11289f42009-09-09 15:08:12 +0000729
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000730 if (!D) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000731 ColorScope Color(*this, NullColor);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000732 OS << "<<<NULL>>>";
733 return;
Chris Lattnercbe4f772007-08-08 22:51:59 +0000734 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000735
Richard Trieud215b8d2013-01-26 01:31:20 +0000736 {
737 ColorScope Color(*this, DeclKindNameColor);
738 OS << D->getDeclKindName() << "Decl";
739 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000740 dumpPointer(D);
Richard Smithf5f43542013-02-07 01:35:44 +0000741 if (D->getLexicalDeclContext() != D->getDeclContext())
742 OS << " parent " << cast<Decl>(D->getDeclContext());
Richard Smith71bec062013-10-15 21:58:30 +0000743 dumpPreviousDecl(OS, D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000744 dumpSourceRange(D->getSourceRange());
Richard Smith15fc7df2013-10-22 23:50:38 +0000745 if (Module *M = D->getOwningModule())
746 OS << " in " << M->getFullModuleName();
747 if (const NamedDecl *ND = dyn_cast<NamedDecl>(D))
748 if (ND->isHidden())
749 OS << " hidden";
Richard Trieude5cc7d2013-01-31 01:44:26 +0000750
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000751 bool HasAttrs = D->attr_begin() != D->attr_end();
Richard Smithb39b9d52013-05-21 05:24:00 +0000752 const FullComment *Comment =
753 D->getASTContext().getLocalCommentForDeclUncached(D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000754 // Decls within functions are visited by the body
Richard Trieude5cc7d2013-01-31 01:44:26 +0000755 bool HasDeclContext = !isa<FunctionDecl>(*D) && !isa<ObjCMethodDecl>(*D) &&
756 hasNodes(dyn_cast<DeclContext>(D));
757
Richard Smithb39b9d52013-05-21 05:24:00 +0000758 setMoreChildren(HasAttrs || Comment || HasDeclContext);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000759 ConstDeclVisitor<ASTDumper>::Visit(D);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000760
Richard Smithb39b9d52013-05-21 05:24:00 +0000761 setMoreChildren(Comment || HasDeclContext);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000762 for (Decl::attr_iterator I = D->attr_begin(), E = D->attr_end();
763 I != E; ++I) {
764 if (I + 1 == E)
765 lastChild();
766 dumpAttr(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000767 }
768
769 setMoreChildren(HasDeclContext);
770 lastChild();
Richard Smithb39b9d52013-05-21 05:24:00 +0000771 dumpFullComment(Comment);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000772
Nick Lewyckya382db02013-08-27 03:15:56 +0000773 if (D->isInvalidDecl())
774 OS << " invalid";
775
Richard Trieude5cc7d2013-01-31 01:44:26 +0000776 setMoreChildren(false);
777 if (HasDeclContext)
Richard Smithf5f43542013-02-07 01:35:44 +0000778 dumpDeclContext(cast<DeclContext>(D));
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000779}
780
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000781void ASTDumper::VisitLabelDecl(const LabelDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000782 dumpName(D);
783}
784
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000785void ASTDumper::VisitTypedefDecl(const TypedefDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000786 dumpName(D);
787 dumpType(D->getUnderlyingType());
788 if (D->isModulePrivate())
789 OS << " __module_private__";
790}
791
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000792void ASTDumper::VisitEnumDecl(const EnumDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000793 if (D->isScoped()) {
794 if (D->isScopedUsingClassTag())
795 OS << " class";
796 else
797 OS << " struct";
798 }
799 dumpName(D);
800 if (D->isModulePrivate())
801 OS << " __module_private__";
802 if (D->isFixed())
803 dumpType(D->getIntegerType());
804}
805
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000806void ASTDumper::VisitRecordDecl(const RecordDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000807 OS << ' ' << D->getKindName();
808 dumpName(D);
809 if (D->isModulePrivate())
810 OS << " __module_private__";
Richard Smith99bc1b92013-08-30 05:32:29 +0000811 if (D->isCompleteDefinition())
812 OS << " definition";
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000813}
814
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000815void ASTDumper::VisitEnumConstantDecl(const EnumConstantDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000816 dumpName(D);
817 dumpType(D->getType());
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000818 if (const Expr *Init = D->getInitExpr()) {
Richard Trieude5cc7d2013-01-31 01:44:26 +0000819 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000820 dumpStmt(Init);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000821 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000822}
823
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000824void ASTDumper::VisitIndirectFieldDecl(const IndirectFieldDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000825 dumpName(D);
826 dumpType(D->getType());
827 for (IndirectFieldDecl::chain_iterator I = D->chain_begin(),
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000828 E = D->chain_end();
829 I != E; ++I) {
Richard Trieude5cc7d2013-01-31 01:44:26 +0000830 if (I + 1 == E)
831 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000832 dumpDeclRef(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000833 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000834}
835
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000836void ASTDumper::VisitFunctionDecl(const FunctionDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000837 dumpName(D);
838 dumpType(D->getType());
839
Rafael Espindola6ae7e502013-04-03 19:27:57 +0000840 StorageClass SC = D->getStorageClass();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000841 if (SC != SC_None)
842 OS << ' ' << VarDecl::getStorageClassSpecifierString(SC);
843 if (D->isInlineSpecified())
844 OS << " inline";
845 if (D->isVirtualAsWritten())
846 OS << " virtual";
847 if (D->isModulePrivate())
848 OS << " __module_private__";
849
850 if (D->isPure())
851 OS << " pure";
852 else if (D->isDeletedAsWritten())
853 OS << " delete";
854
Richard Smithadaa0152013-05-17 02:09:46 +0000855 if (const FunctionProtoType *FPT = D->getType()->getAs<FunctionProtoType>()) {
856 FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo();
857 switch (EPI.ExceptionSpecType) {
858 default: break;
859 case EST_Unevaluated:
860 OS << " noexcept-unevaluated " << EPI.ExceptionSpecDecl;
861 break;
862 case EST_Uninstantiated:
863 OS << " noexcept-uninstantiated " << EPI.ExceptionSpecTemplate;
864 break;
865 }
866 }
867
Richard Trieude5cc7d2013-01-31 01:44:26 +0000868 bool OldMoreChildren = hasMoreChildren();
869 const FunctionTemplateSpecializationInfo *FTSI =
870 D->getTemplateSpecializationInfo();
871 bool HasTemplateSpecialization = FTSI;
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000872
Richard Trieude5cc7d2013-01-31 01:44:26 +0000873 bool HasNamedDecls = D->getDeclsInPrototypeScope().begin() !=
874 D->getDeclsInPrototypeScope().end();
875
876 bool HasFunctionDecls = D->param_begin() != D->param_end();
877
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000878 const CXXConstructorDecl *C = dyn_cast<CXXConstructorDecl>(D);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000879 bool HasCtorInitializers = C && C->init_begin() != C->init_end();
880
881 bool HasDeclarationBody = D->doesThisDeclarationHaveABody();
882
883 setMoreChildren(OldMoreChildren || HasNamedDecls || HasFunctionDecls ||
884 HasCtorInitializers || HasDeclarationBody);
885 if (HasTemplateSpecialization) {
886 lastChild();
887 dumpTemplateArgumentList(*FTSI->TemplateArguments);
888 }
889
890 setMoreChildren(OldMoreChildren || HasFunctionDecls ||
891 HasCtorInitializers || HasDeclarationBody);
Dmitri Gribenkof8579502013-01-12 19:30:44 +0000892 for (ArrayRef<NamedDecl *>::iterator
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000893 I = D->getDeclsInPrototypeScope().begin(),
Richard Trieude5cc7d2013-01-31 01:44:26 +0000894 E = D->getDeclsInPrototypeScope().end(); I != E; ++I) {
895 if (I + 1 == E)
896 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000897 dumpDecl(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000898 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000899
Richard Trieude5cc7d2013-01-31 01:44:26 +0000900 setMoreChildren(OldMoreChildren || HasCtorInitializers || HasDeclarationBody);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000901 for (FunctionDecl::param_const_iterator I = D->param_begin(),
902 E = D->param_end();
Richard Trieude5cc7d2013-01-31 01:44:26 +0000903 I != E; ++I) {
904 if (I + 1 == E)
905 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000906 dumpDecl(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000907 }
908
909 setMoreChildren(OldMoreChildren || HasDeclarationBody);
910 if (HasCtorInitializers)
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000911 for (CXXConstructorDecl::init_const_iterator I = C->init_begin(),
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000912 E = C->init_end();
913 I != E; ++I) {
Richard Trieude5cc7d2013-01-31 01:44:26 +0000914 if (I + 1 == E)
915 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000916 dumpCXXCtorInitializer(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000917 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000918
Richard Trieude5cc7d2013-01-31 01:44:26 +0000919 setMoreChildren(OldMoreChildren);
920 if (HasDeclarationBody) {
921 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000922 dumpStmt(D->getBody());
Richard Trieude5cc7d2013-01-31 01:44:26 +0000923 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000924}
925
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000926void ASTDumper::VisitFieldDecl(const FieldDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000927 dumpName(D);
928 dumpType(D->getType());
929 if (D->isMutable())
930 OS << " mutable";
931 if (D->isModulePrivate())
932 OS << " __module_private__";
Richard Trieude5cc7d2013-01-31 01:44:26 +0000933
934 bool OldMoreChildren = hasMoreChildren();
935 bool IsBitField = D->isBitField();
936 Expr *Init = D->getInClassInitializer();
937 bool HasInit = Init;
938
939 setMoreChildren(OldMoreChildren || HasInit);
940 if (IsBitField) {
941 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000942 dumpStmt(D->getBitWidth());
Richard Trieude5cc7d2013-01-31 01:44:26 +0000943 }
944 setMoreChildren(OldMoreChildren);
945 if (HasInit) {
946 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000947 dumpStmt(Init);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000948 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000949}
950
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000951void ASTDumper::VisitVarDecl(const VarDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000952 dumpName(D);
953 dumpType(D->getType());
Rafael Espindola6ae7e502013-04-03 19:27:57 +0000954 StorageClass SC = D->getStorageClass();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000955 if (SC != SC_None)
956 OS << ' ' << VarDecl::getStorageClassSpecifierString(SC);
Richard Smithfd3834f2013-04-13 02:43:54 +0000957 switch (D->getTLSKind()) {
958 case VarDecl::TLS_None: break;
959 case VarDecl::TLS_Static: OS << " tls"; break;
960 case VarDecl::TLS_Dynamic: OS << " tls_dynamic"; break;
961 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000962 if (D->isModulePrivate())
963 OS << " __module_private__";
964 if (D->isNRVOVariable())
965 OS << " nrvo";
Richard Trieude5cc7d2013-01-31 01:44:26 +0000966 if (D->hasInit()) {
967 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000968 dumpStmt(D->getInit());
Richard Trieude5cc7d2013-01-31 01:44:26 +0000969 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000970}
971
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000972void ASTDumper::VisitFileScopeAsmDecl(const FileScopeAsmDecl *D) {
Richard Trieude5cc7d2013-01-31 01:44:26 +0000973 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000974 dumpStmt(D->getAsmString());
975}
976
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000977void ASTDumper::VisitImportDecl(const ImportDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000978 OS << ' ' << D->getImportedModule()->getFullModuleName();
979}
980
981//===----------------------------------------------------------------------===//
982// C++ Declarations
983//===----------------------------------------------------------------------===//
984
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000985void ASTDumper::VisitNamespaceDecl(const NamespaceDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000986 dumpName(D);
987 if (D->isInline())
988 OS << " inline";
989 if (!D->isOriginalNamespace())
990 dumpDeclRef(D->getOriginalNamespace(), "original");
991}
992
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000993void ASTDumper::VisitUsingDirectiveDecl(const UsingDirectiveDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000994 OS << ' ';
995 dumpBareDeclRef(D->getNominatedNamespace());
996}
997
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000998void ASTDumper::VisitNamespaceAliasDecl(const NamespaceAliasDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000999 dumpName(D);
1000 dumpDeclRef(D->getAliasedNamespace());
1001}
1002
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001003void ASTDumper::VisitTypeAliasDecl(const TypeAliasDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001004 dumpName(D);
1005 dumpType(D->getUnderlyingType());
1006}
1007
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001008void ASTDumper::VisitTypeAliasTemplateDecl(const TypeAliasTemplateDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001009 dumpName(D);
1010 dumpTemplateParameters(D->getTemplateParameters());
1011 dumpDecl(D->getTemplatedDecl());
1012}
1013
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001014void ASTDumper::VisitCXXRecordDecl(const CXXRecordDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001015 VisitRecordDecl(D);
1016 if (!D->isCompleteDefinition())
1017 return;
1018
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001019 for (CXXRecordDecl::base_class_const_iterator I = D->bases_begin(),
1020 E = D->bases_end();
1021 I != E; ++I) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001022 IndentScope Indent(*this);
1023 if (I->isVirtual())
1024 OS << "virtual ";
1025 dumpAccessSpecifier(I->getAccessSpecifier());
1026 dumpType(I->getType());
1027 if (I->isPackExpansion())
1028 OS << "...";
1029 }
1030}
1031
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001032void ASTDumper::VisitStaticAssertDecl(const StaticAssertDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001033 dumpStmt(D->getAssertExpr());
Richard Trieude5cc7d2013-01-31 01:44:26 +00001034 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001035 dumpStmt(D->getMessage());
1036}
1037
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001038void ASTDumper::VisitFunctionTemplateDecl(const FunctionTemplateDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001039 dumpName(D);
1040 dumpTemplateParameters(D->getTemplateParameters());
1041 dumpDecl(D->getTemplatedDecl());
Dmitri Gribenko81f25752013-02-14 13:20:36 +00001042 for (FunctionTemplateDecl::spec_iterator I = D->spec_begin(),
1043 E = D->spec_end();
1044 I != E; ++I) {
Richard Trieude5cc7d2013-01-31 01:44:26 +00001045 FunctionTemplateDecl::spec_iterator Next = I;
1046 ++Next;
1047 if (Next == E)
1048 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001049 switch (I->getTemplateSpecializationKind()) {
1050 case TSK_Undeclared:
1051 case TSK_ImplicitInstantiation:
1052 case TSK_ExplicitInstantiationDeclaration:
1053 case TSK_ExplicitInstantiationDefinition:
Dmitri Gribenkoefc6dfb2013-02-21 22:01:10 +00001054 if (D == D->getCanonicalDecl())
1055 dumpDecl(*I);
1056 else
1057 dumpDeclRef(*I);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001058 break;
1059 case TSK_ExplicitSpecialization:
1060 dumpDeclRef(*I);
1061 break;
1062 }
1063 }
1064}
1065
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001066void ASTDumper::VisitClassTemplateDecl(const ClassTemplateDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001067 dumpName(D);
1068 dumpTemplateParameters(D->getTemplateParameters());
Richard Trieude5cc7d2013-01-31 01:44:26 +00001069
Dmitri Gribenko81f25752013-02-14 13:20:36 +00001070 ClassTemplateDecl::spec_iterator I = D->spec_begin();
1071 ClassTemplateDecl::spec_iterator E = D->spec_end();
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001072 if (I == E)
Richard Trieude5cc7d2013-01-31 01:44:26 +00001073 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001074 dumpDecl(D->getTemplatedDecl());
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001075 for (; I != E; ++I) {
Richard Trieude5cc7d2013-01-31 01:44:26 +00001076 ClassTemplateDecl::spec_iterator Next = I;
1077 ++Next;
1078 if (Next == E)
1079 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001080 switch (I->getTemplateSpecializationKind()) {
1081 case TSK_Undeclared:
1082 case TSK_ImplicitInstantiation:
Dmitri Gribenkoefc6dfb2013-02-21 22:01:10 +00001083 if (D == D->getCanonicalDecl())
1084 dumpDecl(*I);
1085 else
1086 dumpDeclRef(*I);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001087 break;
1088 case TSK_ExplicitSpecialization:
1089 case TSK_ExplicitInstantiationDeclaration:
1090 case TSK_ExplicitInstantiationDefinition:
1091 dumpDeclRef(*I);
1092 break;
1093 }
1094 }
1095}
1096
1097void ASTDumper::VisitClassTemplateSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001098 const ClassTemplateSpecializationDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001099 VisitCXXRecordDecl(D);
1100 dumpTemplateArgumentList(D->getTemplateArgs());
1101}
1102
1103void ASTDumper::VisitClassTemplatePartialSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001104 const ClassTemplatePartialSpecializationDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001105 VisitClassTemplateSpecializationDecl(D);
1106 dumpTemplateParameters(D->getTemplateParameters());
1107}
1108
1109void ASTDumper::VisitClassScopeFunctionSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001110 const ClassScopeFunctionSpecializationDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001111 dumpDeclRef(D->getSpecialization());
1112 if (D->hasExplicitTemplateArgs())
1113 dumpTemplateArgumentListInfo(D->templateArgs());
1114}
1115
Richard Smithd25789a2013-09-18 01:36:02 +00001116void ASTDumper::VisitVarTemplateDecl(const VarTemplateDecl *D) {
1117 dumpName(D);
1118 dumpTemplateParameters(D->getTemplateParameters());
1119
1120 VarTemplateDecl::spec_iterator I = D->spec_begin();
1121 VarTemplateDecl::spec_iterator E = D->spec_end();
1122 if (I == E)
1123 lastChild();
1124 dumpDecl(D->getTemplatedDecl());
1125 for (; I != E; ++I) {
1126 VarTemplateDecl::spec_iterator Next = I;
1127 ++Next;
1128 if (Next == E)
1129 lastChild();
1130 switch (I->getTemplateSpecializationKind()) {
1131 case TSK_Undeclared:
1132 case TSK_ImplicitInstantiation:
1133 if (D == D->getCanonicalDecl())
1134 dumpDecl(*I);
1135 else
1136 dumpDeclRef(*I);
1137 break;
1138 case TSK_ExplicitSpecialization:
1139 case TSK_ExplicitInstantiationDeclaration:
1140 case TSK_ExplicitInstantiationDefinition:
1141 dumpDeclRef(*I);
1142 break;
1143 }
1144 }
1145}
1146
1147void ASTDumper::VisitVarTemplateSpecializationDecl(
1148 const VarTemplateSpecializationDecl *D) {
1149 dumpTemplateArgumentList(D->getTemplateArgs());
1150 VisitVarDecl(D);
1151}
1152
1153void ASTDumper::VisitVarTemplatePartialSpecializationDecl(
1154 const VarTemplatePartialSpecializationDecl *D) {
1155 dumpTemplateParameters(D->getTemplateParameters());
1156 VisitVarTemplateSpecializationDecl(D);
1157}
1158
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001159void ASTDumper::VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001160 if (D->wasDeclaredWithTypename())
1161 OS << " typename";
1162 else
1163 OS << " class";
1164 if (D->isParameterPack())
1165 OS << " ...";
1166 dumpName(D);
1167 if (D->hasDefaultArgument())
1168 dumpType(D->getDefaultArgument());
1169}
1170
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001171void ASTDumper::VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001172 dumpType(D->getType());
1173 if (D->isParameterPack())
1174 OS << " ...";
1175 dumpName(D);
1176 if (D->hasDefaultArgument())
1177 dumpStmt(D->getDefaultArgument());
1178}
1179
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001180void ASTDumper::VisitTemplateTemplateParmDecl(
1181 const TemplateTemplateParmDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001182 if (D->isParameterPack())
1183 OS << " ...";
1184 dumpName(D);
1185 dumpTemplateParameters(D->getTemplateParameters());
1186 if (D->hasDefaultArgument())
1187 dumpTemplateArgumentLoc(D->getDefaultArgument());
1188}
1189
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001190void ASTDumper::VisitUsingDecl(const UsingDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001191 OS << ' ';
1192 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
1193 OS << D->getNameAsString();
1194}
1195
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001196void ASTDumper::VisitUnresolvedUsingTypenameDecl(
1197 const UnresolvedUsingTypenameDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001198 OS << ' ';
1199 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
1200 OS << D->getNameAsString();
1201}
1202
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001203void ASTDumper::VisitUnresolvedUsingValueDecl(const UnresolvedUsingValueDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001204 OS << ' ';
1205 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
1206 OS << D->getNameAsString();
1207 dumpType(D->getType());
1208}
1209
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001210void ASTDumper::VisitUsingShadowDecl(const UsingShadowDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001211 OS << ' ';
1212 dumpBareDeclRef(D->getTargetDecl());
1213}
1214
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001215void ASTDumper::VisitLinkageSpecDecl(const LinkageSpecDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001216 switch (D->getLanguage()) {
1217 case LinkageSpecDecl::lang_c: OS << " C"; break;
1218 case LinkageSpecDecl::lang_cxx: OS << " C++"; break;
1219 }
1220}
1221
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001222void ASTDumper::VisitAccessSpecDecl(const AccessSpecDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001223 OS << ' ';
1224 dumpAccessSpecifier(D->getAccess());
1225}
1226
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001227void ASTDumper::VisitFriendDecl(const FriendDecl *D) {
Richard Smithf5f43542013-02-07 01:35:44 +00001228 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001229 if (TypeSourceInfo *T = D->getFriendType())
1230 dumpType(T->getType());
1231 else
1232 dumpDecl(D->getFriendDecl());
1233}
1234
1235//===----------------------------------------------------------------------===//
1236// Obj-C Declarations
1237//===----------------------------------------------------------------------===//
1238
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001239void ASTDumper::VisitObjCIvarDecl(const ObjCIvarDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001240 dumpName(D);
1241 dumpType(D->getType());
1242 if (D->getSynthesize())
1243 OS << " synthesize";
Fariborz Jahanian5e3429c2013-10-25 21:44:50 +00001244 if (D->getBackingIvarReferencedInAccessor())
1245 OS << " BackingIvarReferencedInAccessor";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001246
1247 switch (D->getAccessControl()) {
1248 case ObjCIvarDecl::None:
1249 OS << " none";
1250 break;
1251 case ObjCIvarDecl::Private:
1252 OS << " private";
1253 break;
1254 case ObjCIvarDecl::Protected:
1255 OS << " protected";
1256 break;
1257 case ObjCIvarDecl::Public:
1258 OS << " public";
1259 break;
1260 case ObjCIvarDecl::Package:
1261 OS << " package";
1262 break;
1263 }
1264}
1265
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001266void ASTDumper::VisitObjCMethodDecl(const ObjCMethodDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001267 if (D->isInstanceMethod())
1268 OS << " -";
1269 else
1270 OS << " +";
1271 dumpName(D);
1272 dumpType(D->getResultType());
1273
Richard Trieude5cc7d2013-01-31 01:44:26 +00001274 bool OldMoreChildren = hasMoreChildren();
1275 bool IsVariadic = D->isVariadic();
1276 bool HasBody = D->hasBody();
1277
1278 setMoreChildren(OldMoreChildren || IsVariadic || HasBody);
1279 if (D->isThisDeclarationADefinition()) {
1280 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001281 dumpDeclContext(D);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001282 } else {
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001283 for (ObjCMethodDecl::param_const_iterator I = D->param_begin(),
1284 E = D->param_end();
1285 I != E; ++I) {
Richard Trieude5cc7d2013-01-31 01:44:26 +00001286 if (I + 1 == E)
1287 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001288 dumpDecl(*I);
1289 }
1290 }
1291
Richard Trieude5cc7d2013-01-31 01:44:26 +00001292 setMoreChildren(OldMoreChildren || HasBody);
1293 if (IsVariadic) {
1294 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001295 IndentScope Indent(*this);
1296 OS << "...";
1297 }
1298
Richard Trieude5cc7d2013-01-31 01:44:26 +00001299 setMoreChildren(OldMoreChildren);
1300 if (HasBody) {
1301 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001302 dumpStmt(D->getBody());
Richard Trieude5cc7d2013-01-31 01:44:26 +00001303 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001304}
1305
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001306void ASTDumper::VisitObjCCategoryDecl(const ObjCCategoryDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001307 dumpName(D);
1308 dumpDeclRef(D->getClassInterface());
Richard Trieude5cc7d2013-01-31 01:44:26 +00001309 if (D->protocol_begin() == D->protocol_end())
1310 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001311 dumpDeclRef(D->getImplementation());
1312 for (ObjCCategoryDecl::protocol_iterator I = D->protocol_begin(),
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001313 E = D->protocol_end();
1314 I != E; ++I) {
Richard Trieude5cc7d2013-01-31 01:44:26 +00001315 if (I + 1 == E)
1316 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001317 dumpDeclRef(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001318 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001319}
1320
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001321void ASTDumper::VisitObjCCategoryImplDecl(const ObjCCategoryImplDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001322 dumpName(D);
1323 dumpDeclRef(D->getClassInterface());
Richard Trieude5cc7d2013-01-31 01:44:26 +00001324 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001325 dumpDeclRef(D->getCategoryDecl());
1326}
1327
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001328void ASTDumper::VisitObjCProtocolDecl(const ObjCProtocolDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001329 dumpName(D);
1330 for (ObjCProtocolDecl::protocol_iterator I = D->protocol_begin(),
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001331 E = D->protocol_end();
1332 I != E; ++I) {
Richard Trieude5cc7d2013-01-31 01:44:26 +00001333 if (I + 1 == E)
1334 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001335 dumpDeclRef(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001336 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001337}
1338
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001339void ASTDumper::VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001340 dumpName(D);
1341 dumpDeclRef(D->getSuperClass(), "super");
Richard Trieude5cc7d2013-01-31 01:44:26 +00001342 if (D->protocol_begin() == D->protocol_end())
1343 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001344 dumpDeclRef(D->getImplementation());
1345 for (ObjCInterfaceDecl::protocol_iterator I = D->protocol_begin(),
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001346 E = D->protocol_end();
1347 I != E; ++I) {
Richard Trieude5cc7d2013-01-31 01:44:26 +00001348 if (I + 1 == E)
1349 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001350 dumpDeclRef(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001351 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001352}
1353
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001354void ASTDumper::VisitObjCImplementationDecl(const ObjCImplementationDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001355 dumpName(D);
1356 dumpDeclRef(D->getSuperClass(), "super");
Richard Trieude5cc7d2013-01-31 01:44:26 +00001357 if (D->init_begin() == D->init_end())
1358 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001359 dumpDeclRef(D->getClassInterface());
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001360 for (ObjCImplementationDecl::init_const_iterator I = D->init_begin(),
1361 E = D->init_end();
1362 I != E; ++I) {
Richard Trieude5cc7d2013-01-31 01:44:26 +00001363 if (I + 1 == E)
1364 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001365 dumpCXXCtorInitializer(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001366 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001367}
1368
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001369void ASTDumper::VisitObjCCompatibleAliasDecl(const ObjCCompatibleAliasDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001370 dumpName(D);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001371 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001372 dumpDeclRef(D->getClassInterface());
1373}
1374
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001375void ASTDumper::VisitObjCPropertyDecl(const ObjCPropertyDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001376 dumpName(D);
1377 dumpType(D->getType());
1378
1379 if (D->getPropertyImplementation() == ObjCPropertyDecl::Required)
1380 OS << " required";
1381 else if (D->getPropertyImplementation() == ObjCPropertyDecl::Optional)
1382 OS << " optional";
1383
1384 ObjCPropertyDecl::PropertyAttributeKind Attrs = D->getPropertyAttributes();
1385 if (Attrs != ObjCPropertyDecl::OBJC_PR_noattr) {
1386 if (Attrs & ObjCPropertyDecl::OBJC_PR_readonly)
1387 OS << " readonly";
1388 if (Attrs & ObjCPropertyDecl::OBJC_PR_assign)
1389 OS << " assign";
1390 if (Attrs & ObjCPropertyDecl::OBJC_PR_readwrite)
1391 OS << " readwrite";
1392 if (Attrs & ObjCPropertyDecl::OBJC_PR_retain)
1393 OS << " retain";
1394 if (Attrs & ObjCPropertyDecl::OBJC_PR_copy)
1395 OS << " copy";
1396 if (Attrs & ObjCPropertyDecl::OBJC_PR_nonatomic)
1397 OS << " nonatomic";
1398 if (Attrs & ObjCPropertyDecl::OBJC_PR_atomic)
1399 OS << " atomic";
1400 if (Attrs & ObjCPropertyDecl::OBJC_PR_weak)
1401 OS << " weak";
1402 if (Attrs & ObjCPropertyDecl::OBJC_PR_strong)
1403 OS << " strong";
1404 if (Attrs & ObjCPropertyDecl::OBJC_PR_unsafe_unretained)
1405 OS << " unsafe_unretained";
Richard Trieude5cc7d2013-01-31 01:44:26 +00001406 if (Attrs & ObjCPropertyDecl::OBJC_PR_getter) {
1407 if (!(Attrs & ObjCPropertyDecl::OBJC_PR_setter))
1408 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001409 dumpDeclRef(D->getGetterMethodDecl(), "getter");
Richard Trieude5cc7d2013-01-31 01:44:26 +00001410 }
1411 if (Attrs & ObjCPropertyDecl::OBJC_PR_setter) {
1412 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001413 dumpDeclRef(D->getSetterMethodDecl(), "setter");
Richard Trieude5cc7d2013-01-31 01:44:26 +00001414 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001415 }
1416}
1417
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001418void ASTDumper::VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001419 dumpName(D->getPropertyDecl());
1420 if (D->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize)
1421 OS << " synthesize";
1422 else
1423 OS << " dynamic";
1424 dumpDeclRef(D->getPropertyDecl());
Richard Trieude5cc7d2013-01-31 01:44:26 +00001425 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001426 dumpDeclRef(D->getPropertyIvarDecl());
1427}
1428
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001429void ASTDumper::VisitBlockDecl(const BlockDecl *D) {
1430 for (BlockDecl::param_const_iterator I = D->param_begin(), E = D->param_end();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001431 I != E; ++I)
1432 dumpDecl(*I);
1433
1434 if (D->isVariadic()) {
1435 IndentScope Indent(*this);
1436 OS << "...";
1437 }
1438
1439 if (D->capturesCXXThis()) {
1440 IndentScope Indent(*this);
1441 OS << "capture this";
1442 }
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001443 for (BlockDecl::capture_iterator I = D->capture_begin(), E = D->capture_end();
1444 I != E; ++I) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001445 IndentScope Indent(*this);
1446 OS << "capture";
1447 if (I->isByRef())
1448 OS << " byref";
1449 if (I->isNested())
1450 OS << " nested";
1451 if (I->getVariable()) {
1452 OS << ' ';
1453 dumpBareDeclRef(I->getVariable());
1454 }
1455 if (I->hasCopyExpr())
1456 dumpStmt(I->getCopyExpr());
1457 }
Richard Trieude5cc7d2013-01-31 01:44:26 +00001458 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001459 dumpStmt(D->getBody());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001460}
1461
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001462//===----------------------------------------------------------------------===//
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001463// Stmt dumping methods.
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001464//===----------------------------------------------------------------------===//
1465
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001466void ASTDumper::dumpStmt(const Stmt *S) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001467 IndentScope Indent(*this);
1468
1469 if (!S) {
Richard Trieud215b8d2013-01-26 01:31:20 +00001470 ColorScope Color(*this, NullColor);
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001471 OS << "<<<NULL>>>";
1472 return;
1473 }
1474
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001475 if (const DeclStmt *DS = dyn_cast<DeclStmt>(S)) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001476 VisitDeclStmt(DS);
1477 return;
1478 }
1479
David Blaikie7d170102013-05-15 07:37:26 +00001480 setMoreChildren(!S->children().empty());
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001481 ConstStmtVisitor<ASTDumper>::Visit(S);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001482 setMoreChildren(false);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001483 for (Stmt::const_child_range CI = S->children(); CI; ++CI) {
1484 Stmt::const_child_range Next = CI;
Richard Trieude5cc7d2013-01-31 01:44:26 +00001485 ++Next;
1486 if (!Next)
1487 lastChild();
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001488 dumpStmt(*CI);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001489 }
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001490}
1491
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001492void ASTDumper::VisitStmt(const Stmt *Node) {
Richard Trieud215b8d2013-01-26 01:31:20 +00001493 {
1494 ColorScope Color(*this, StmtColor);
1495 OS << Node->getStmtClassName();
1496 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001497 dumpPointer(Node);
1498 dumpSourceRange(Node->getSourceRange());
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001499}
1500
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001501void ASTDumper::VisitDeclStmt(const DeclStmt *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001502 VisitStmt(Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001503 for (DeclStmt::const_decl_iterator I = Node->decl_begin(),
1504 E = Node->decl_end();
Richard Trieude5cc7d2013-01-31 01:44:26 +00001505 I != E; ++I) {
1506 if (I + 1 == E)
1507 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001508 dumpDecl(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001509 }
Ted Kremenek433a4922007-12-12 06:59:42 +00001510}
1511
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001512void ASTDumper::VisitAttributedStmt(const AttributedStmt *Node) {
Alexander Kornienko5bc364e2013-01-07 17:53:08 +00001513 VisitStmt(Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001514 for (ArrayRef<const Attr *>::iterator I = Node->getAttrs().begin(),
1515 E = Node->getAttrs().end();
1516 I != E; ++I) {
Richard Trieude5cc7d2013-01-31 01:44:26 +00001517 if (I + 1 == E)
1518 lastChild();
Alexander Kornienko5bc364e2013-01-07 17:53:08 +00001519 dumpAttr(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001520 }
Alexander Kornienko5bc364e2013-01-07 17:53:08 +00001521}
1522
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001523void ASTDumper::VisitLabelStmt(const LabelStmt *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001524 VisitStmt(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001525 OS << " '" << Node->getName() << "'";
Chris Lattnercbe4f772007-08-08 22:51:59 +00001526}
1527
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001528void ASTDumper::VisitGotoStmt(const GotoStmt *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001529 VisitStmt(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001530 OS << " '" << Node->getLabel()->getName() << "'";
1531 dumpPointer(Node->getLabel());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001532}
1533
Pavel Labath1ef83422013-09-04 14:35:00 +00001534void ASTDumper::VisitCXXCatchStmt(const CXXCatchStmt *Node) {
1535 VisitStmt(Node);
1536 dumpDecl(Node->getExceptionDecl());
1537}
1538
Chris Lattnercbe4f772007-08-08 22:51:59 +00001539//===----------------------------------------------------------------------===//
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001540// Expr dumping methods.
Chris Lattnercbe4f772007-08-08 22:51:59 +00001541//===----------------------------------------------------------------------===//
1542
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001543void ASTDumper::VisitExpr(const Expr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001544 VisitStmt(Node);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001545 dumpType(Node->getType());
1546
Richard Trieud215b8d2013-01-26 01:31:20 +00001547 {
1548 ColorScope Color(*this, ValueKindColor);
1549 switch (Node->getValueKind()) {
1550 case VK_RValue:
1551 break;
1552 case VK_LValue:
1553 OS << " lvalue";
1554 break;
1555 case VK_XValue:
1556 OS << " xvalue";
1557 break;
1558 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001559 }
1560
Richard Trieud215b8d2013-01-26 01:31:20 +00001561 {
1562 ColorScope Color(*this, ObjectKindColor);
1563 switch (Node->getObjectKind()) {
1564 case OK_Ordinary:
1565 break;
1566 case OK_BitField:
1567 OS << " bitfield";
1568 break;
1569 case OK_ObjCProperty:
1570 OS << " objcproperty";
1571 break;
1572 case OK_ObjCSubscript:
1573 OS << " objcsubscript";
1574 break;
1575 case OK_VectorComponent:
1576 OS << " vectorcomponent";
1577 break;
1578 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001579 }
Chris Lattnercbe4f772007-08-08 22:51:59 +00001580}
1581
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001582static void dumpBasePath(raw_ostream &OS, const CastExpr *Node) {
John McCallcf142162010-08-07 06:22:56 +00001583 if (Node->path_empty())
Anders Carlssona70cff62010-04-24 19:06:50 +00001584 return;
1585
1586 OS << " (";
1587 bool First = true;
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001588 for (CastExpr::path_const_iterator I = Node->path_begin(),
1589 E = Node->path_end();
1590 I != E; ++I) {
Anders Carlssona70cff62010-04-24 19:06:50 +00001591 const CXXBaseSpecifier *Base = *I;
1592 if (!First)
1593 OS << " -> ";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001594
Anders Carlssona70cff62010-04-24 19:06:50 +00001595 const CXXRecordDecl *RD =
1596 cast<CXXRecordDecl>(Base->getType()->getAs<RecordType>()->getDecl());
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001597
Anders Carlssona70cff62010-04-24 19:06:50 +00001598 if (Base->isVirtual())
1599 OS << "virtual ";
1600 OS << RD->getName();
1601 First = false;
1602 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001603
Anders Carlssona70cff62010-04-24 19:06:50 +00001604 OS << ')';
1605}
1606
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001607void ASTDumper::VisitCastExpr(const CastExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001608 VisitExpr(Node);
Richard Trieud215b8d2013-01-26 01:31:20 +00001609 OS << " <";
1610 {
1611 ColorScope Color(*this, CastColor);
1612 OS << Node->getCastKindName();
1613 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001614 dumpBasePath(OS, Node);
Anders Carlssona70cff62010-04-24 19:06:50 +00001615 OS << ">";
Anders Carlssond7923c62009-08-22 23:33:40 +00001616}
1617
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001618void ASTDumper::VisitDeclRefExpr(const DeclRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001619 VisitExpr(Node);
Ted Kremenek5f64ca82007-09-10 17:32:55 +00001620
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001621 OS << " ";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001622 dumpBareDeclRef(Node->getDecl());
Chandler Carruth8d26bb02011-05-01 23:48:14 +00001623 if (Node->getDecl() != Node->getFoundDecl()) {
1624 OS << " (";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001625 dumpBareDeclRef(Node->getFoundDecl());
Chandler Carruth8d26bb02011-05-01 23:48:14 +00001626 OS << ")";
1627 }
John McCall351762c2011-02-07 10:33:21 +00001628}
1629
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001630void ASTDumper::VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001631 VisitExpr(Node);
John McCall76d09942009-12-11 21:50:11 +00001632 OS << " (";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001633 if (!Node->requiresADL())
1634 OS << "no ";
Benjamin Kramerb11416d2010-04-17 09:33:03 +00001635 OS << "ADL) = '" << Node->getName() << '\'';
John McCall76d09942009-12-11 21:50:11 +00001636
1637 UnresolvedLookupExpr::decls_iterator
1638 I = Node->decls_begin(), E = Node->decls_end();
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001639 if (I == E)
1640 OS << " empty";
John McCall76d09942009-12-11 21:50:11 +00001641 for (; I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001642 dumpPointer(*I);
John McCall76d09942009-12-11 21:50:11 +00001643}
1644
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001645void ASTDumper::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001646 VisitExpr(Node);
Steve Naroff5d5efca2008-03-12 13:19:12 +00001647
Richard Trieud215b8d2013-01-26 01:31:20 +00001648 {
1649 ColorScope Color(*this, DeclKindNameColor);
1650 OS << " " << Node->getDecl()->getDeclKindName() << "Decl";
1651 }
1652 OS << "='" << *Node->getDecl() << "'";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001653 dumpPointer(Node->getDecl());
Steve Naroffb3424a92008-05-23 22:01:24 +00001654 if (Node->isFreeIvar())
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001655 OS << " isFreeIvar";
Steve Naroff5d5efca2008-03-12 13:19:12 +00001656}
1657
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001658void ASTDumper::VisitPredefinedExpr(const PredefinedExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001659 VisitExpr(Node);
Chris Lattnercbe4f772007-08-08 22:51:59 +00001660 switch (Node->getIdentType()) {
David Blaikie83d382b2011-09-23 05:06:16 +00001661 default: llvm_unreachable("unknown case");
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001662 case PredefinedExpr::Func: OS << " __func__"; break;
1663 case PredefinedExpr::Function: OS << " __FUNCTION__"; break;
David Majnemerbed356a2013-11-06 23:31:56 +00001664 case PredefinedExpr::FuncDName: OS << " __FUNCDNAME__"; break;
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001665 case PredefinedExpr::LFunction: OS << " L__FUNCTION__"; break;
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001666 case PredefinedExpr::PrettyFunction: OS << " __PRETTY_FUNCTION__";break;
Chris Lattnercbe4f772007-08-08 22:51:59 +00001667 }
1668}
1669
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001670void ASTDumper::VisitCharacterLiteral(const CharacterLiteral *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001671 VisitExpr(Node);
Richard Trieud215b8d2013-01-26 01:31:20 +00001672 ColorScope Color(*this, ValueColor);
Richard Trieu364ee422011-11-03 23:56:23 +00001673 OS << " " << Node->getValue();
Chris Lattnercbe4f772007-08-08 22:51:59 +00001674}
1675
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001676void ASTDumper::VisitIntegerLiteral(const IntegerLiteral *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001677 VisitExpr(Node);
Chris Lattnercbe4f772007-08-08 22:51:59 +00001678
1679 bool isSigned = Node->getType()->isSignedIntegerType();
Richard Trieud215b8d2013-01-26 01:31:20 +00001680 ColorScope Color(*this, ValueColor);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001681 OS << " " << Node->getValue().toString(10, isSigned);
Chris Lattnercbe4f772007-08-08 22:51:59 +00001682}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001683
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001684void ASTDumper::VisitFloatingLiteral(const FloatingLiteral *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001685 VisitExpr(Node);
Richard Trieud215b8d2013-01-26 01:31:20 +00001686 ColorScope Color(*this, ValueColor);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001687 OS << " " << Node->getValueAsApproximateDouble();
Chris Lattnercbe4f772007-08-08 22:51:59 +00001688}
Chris Lattner1c20a172007-08-26 03:42:43 +00001689
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001690void ASTDumper::VisitStringLiteral(const StringLiteral *Str) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001691 VisitExpr(Str);
Richard Trieud215b8d2013-01-26 01:31:20 +00001692 ColorScope Color(*this, ValueColor);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001693 OS << " ";
Richard Trieudc355912012-06-13 20:25:24 +00001694 Str->outputString(OS);
Chris Lattnercbe4f772007-08-08 22:51:59 +00001695}
Chris Lattner84ca3762007-08-30 01:00:35 +00001696
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001697void ASTDumper::VisitUnaryOperator(const UnaryOperator *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001698 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001699 OS << " " << (Node->isPostfix() ? "postfix" : "prefix")
1700 << " '" << UnaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
Chris Lattnercbe4f772007-08-08 22:51:59 +00001701}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001702
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001703void ASTDumper::VisitUnaryExprOrTypeTraitExpr(
1704 const UnaryExprOrTypeTraitExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001705 VisitExpr(Node);
Peter Collingbournee190dee2011-03-11 19:24:49 +00001706 switch(Node->getKind()) {
1707 case UETT_SizeOf:
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001708 OS << " sizeof";
Peter Collingbournee190dee2011-03-11 19:24:49 +00001709 break;
1710 case UETT_AlignOf:
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001711 OS << " alignof";
Peter Collingbournee190dee2011-03-11 19:24:49 +00001712 break;
1713 case UETT_VecStep:
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001714 OS << " vec_step";
Peter Collingbournee190dee2011-03-11 19:24:49 +00001715 break;
1716 }
Sebastian Redl6f282892008-11-11 17:56:53 +00001717 if (Node->isArgumentType())
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001718 dumpType(Node->getArgumentType());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001719}
Chris Lattnerdb3b3ff2007-08-09 17:35:30 +00001720
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001721void ASTDumper::VisitMemberExpr(const MemberExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001722 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001723 OS << " " << (Node->isArrow() ? "->" : ".") << *Node->getMemberDecl();
1724 dumpPointer(Node->getMemberDecl());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001725}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001726
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001727void ASTDumper::VisitExtVectorElementExpr(const ExtVectorElementExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001728 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001729 OS << " " << Node->getAccessor().getNameStart();
Chris Lattnercbe4f772007-08-08 22:51:59 +00001730}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001731
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001732void ASTDumper::VisitBinaryOperator(const BinaryOperator *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001733 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001734 OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
Chris Lattner86928112007-08-25 02:00:02 +00001735}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001736
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001737void ASTDumper::VisitCompoundAssignOperator(
1738 const CompoundAssignOperator *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001739 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001740 OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode())
1741 << "' ComputeLHSTy=";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001742 dumpBareType(Node->getComputationLHSType());
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001743 OS << " ComputeResultTy=";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001744 dumpBareType(Node->getComputationResultType());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001745}
Chris Lattnercbe4f772007-08-08 22:51:59 +00001746
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001747void ASTDumper::VisitBlockExpr(const BlockExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001748 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001749 dumpDecl(Node->getBlockDecl());
John McCall351762c2011-02-07 10:33:21 +00001750}
1751
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001752void ASTDumper::VisitOpaqueValueExpr(const OpaqueValueExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001753 VisitExpr(Node);
John McCallfe96e0b2011-11-06 09:01:30 +00001754
Richard Trieude5cc7d2013-01-31 01:44:26 +00001755 if (Expr *Source = Node->getSourceExpr()) {
1756 lastChild();
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001757 dumpStmt(Source);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001758 }
John McCallfe96e0b2011-11-06 09:01:30 +00001759}
1760
Chris Lattnercbe4f772007-08-08 22:51:59 +00001761// GNU extensions.
1762
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001763void ASTDumper::VisitAddrLabelExpr(const AddrLabelExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001764 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001765 OS << " " << Node->getLabel()->getName();
1766 dumpPointer(Node->getLabel());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001767}
1768
Chris Lattner8f184b12007-08-09 18:03:18 +00001769//===----------------------------------------------------------------------===//
1770// C++ Expressions
1771//===----------------------------------------------------------------------===//
Chris Lattnercbe4f772007-08-08 22:51:59 +00001772
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001773void ASTDumper::VisitCXXNamedCastExpr(const CXXNamedCastExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001774 VisitExpr(Node);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001775 OS << " " << Node->getCastName()
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001776 << "<" << Node->getTypeAsWritten().getAsString() << ">"
Anders Carlssona70cff62010-04-24 19:06:50 +00001777 << " <" << Node->getCastKindName();
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001778 dumpBasePath(OS, Node);
Anders Carlssona70cff62010-04-24 19:06:50 +00001779 OS << ">";
Chris Lattnercbe4f772007-08-08 22:51:59 +00001780}
1781
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001782void ASTDumper::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001783 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001784 OS << " " << (Node->getValue() ? "true" : "false");
Chris Lattnercbe4f772007-08-08 22:51:59 +00001785}
1786
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001787void ASTDumper::VisitCXXThisExpr(const CXXThisExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001788 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001789 OS << " this";
Douglas Gregor8ea1f532008-11-04 14:56:14 +00001790}
1791
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001792void ASTDumper::VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001793 VisitExpr(Node);
Eli Friedman29538892011-09-02 17:38:59 +00001794 OS << " functional cast to " << Node->getTypeAsWritten().getAsString()
1795 << " <" << Node->getCastKindName() << ">";
Douglas Gregore200adc2008-10-27 19:41:14 +00001796}
1797
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001798void ASTDumper::VisitCXXConstructExpr(const CXXConstructExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001799 VisitExpr(Node);
John McCalleba90cd2010-02-02 19:03:45 +00001800 CXXConstructorDecl *Ctor = Node->getConstructor();
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001801 dumpType(Ctor->getType());
Anders Carlsson073846832009-08-12 00:21:52 +00001802 if (Node->isElidable())
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001803 OS << " elidable";
John McCall85370042010-08-07 06:38:55 +00001804 if (Node->requiresZeroInitialization())
1805 OS << " zeroing";
Anders Carlsson073846832009-08-12 00:21:52 +00001806}
1807
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001808void ASTDumper::VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001809 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001810 OS << " ";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001811 dumpCXXTemporary(Node->getTemporary());
Anders Carlsson073846832009-08-12 00:21:52 +00001812}
1813
Richard Smithe6c01442013-06-05 00:46:14 +00001814void
1815ASTDumper::VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *Node) {
1816 VisitExpr(Node);
1817 if (const ValueDecl *VD = Node->getExtendingDecl()) {
1818 OS << " extended by ";
1819 dumpBareDeclRef(VD);
1820 }
1821}
1822
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001823void ASTDumper::VisitExprWithCleanups(const ExprWithCleanups *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001824 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001825 for (unsigned i = 0, e = Node->getNumObjects(); i != e; ++i)
1826 dumpDeclRef(Node->getObject(i), "cleanup");
Anders Carlsson073846832009-08-12 00:21:52 +00001827}
1828
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001829void ASTDumper::dumpCXXTemporary(const CXXTemporary *Temporary) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001830 OS << "(CXXTemporary";
1831 dumpPointer(Temporary);
1832 OS << ")";
Anders Carlsson073846832009-08-12 00:21:52 +00001833}
1834
Anders Carlsson76f4a902007-08-21 17:43:55 +00001835//===----------------------------------------------------------------------===//
1836// Obj-C Expressions
1837//===----------------------------------------------------------------------===//
1838
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001839void ASTDumper::VisitObjCMessageExpr(const ObjCMessageExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001840 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001841 OS << " selector=" << Node->getSelector().getAsString();
Douglas Gregor9a129192010-04-21 00:45:42 +00001842 switch (Node->getReceiverKind()) {
1843 case ObjCMessageExpr::Instance:
1844 break;
1845
1846 case ObjCMessageExpr::Class:
1847 OS << " class=";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001848 dumpBareType(Node->getClassReceiver());
Douglas Gregor9a129192010-04-21 00:45:42 +00001849 break;
1850
1851 case ObjCMessageExpr::SuperInstance:
1852 OS << " super (instance)";
1853 break;
1854
1855 case ObjCMessageExpr::SuperClass:
1856 OS << " super (class)";
1857 break;
1858 }
Ted Kremenek36748da2008-02-29 22:04:05 +00001859}
1860
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001861void ASTDumper::VisitObjCBoxedExpr(const ObjCBoxedExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001862 VisitExpr(Node);
Argyrios Kyrtzidis9dd40892012-05-10 20:02:31 +00001863 OS << " selector=" << Node->getBoxingMethod()->getSelector().getAsString();
1864}
1865
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001866void ASTDumper::VisitObjCAtCatchStmt(const ObjCAtCatchStmt *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001867 VisitStmt(Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001868 if (const VarDecl *CatchParam = Node->getCatchParamDecl())
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001869 dumpDecl(CatchParam);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001870 else
Douglas Gregor96c79492010-04-23 22:50:49 +00001871 OS << " catch all";
Douglas Gregor96c79492010-04-23 22:50:49 +00001872}
1873
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001874void ASTDumper::VisitObjCEncodeExpr(const ObjCEncodeExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001875 VisitExpr(Node);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001876 dumpType(Node->getEncodedType());
Anders Carlssonc5a81eb2007-08-22 15:14:15 +00001877}
1878
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001879void ASTDumper::VisitObjCSelectorExpr(const ObjCSelectorExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001880 VisitExpr(Node);
Mike Stump11289f42009-09-09 15:08:12 +00001881
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001882 OS << " " << Node->getSelector().getAsString();
Fariborz Jahanian4bef4622007-10-16 20:40:23 +00001883}
1884
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001885void ASTDumper::VisitObjCProtocolExpr(const ObjCProtocolExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001886 VisitExpr(Node);
Mike Stump11289f42009-09-09 15:08:12 +00001887
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001888 OS << ' ' << *Node->getProtocol();
Fariborz Jahaniana32aaef2007-10-17 16:58:11 +00001889}
Daniel Dunbar4b8c6db2008-08-30 05:35:15 +00001890
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001891void ASTDumper::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001892 VisitExpr(Node);
John McCallb7bd14f2010-12-02 01:19:52 +00001893 if (Node->isImplicitProperty()) {
Fariborz Jahanian0f0b3022010-12-22 19:46:35 +00001894 OS << " Kind=MethodRef Getter=\"";
1895 if (Node->getImplicitPropertyGetter())
1896 OS << Node->getImplicitPropertyGetter()->getSelector().getAsString();
1897 else
1898 OS << "(null)";
1899
1900 OS << "\" Setter=\"";
John McCallb7bd14f2010-12-02 01:19:52 +00001901 if (ObjCMethodDecl *Setter = Node->getImplicitPropertySetter())
1902 OS << Setter->getSelector().getAsString();
1903 else
1904 OS << "(null)";
1905 OS << "\"";
1906 } else {
Benjamin Kramerb89514a2011-10-14 18:45:37 +00001907 OS << " Kind=PropertyRef Property=\"" << *Node->getExplicitProperty() <<'"';
John McCallb7bd14f2010-12-02 01:19:52 +00001908 }
Fariborz Jahanian8a1810f2008-11-22 18:39:36 +00001909
Fariborz Jahanian681c0752010-10-14 16:04:05 +00001910 if (Node->isSuperReceiver())
1911 OS << " super";
Argyrios Kyrtzidisab468b02012-03-30 00:19:18 +00001912
1913 OS << " Messaging=";
1914 if (Node->isMessagingGetter() && Node->isMessagingSetter())
1915 OS << "Getter&Setter";
1916 else if (Node->isMessagingGetter())
1917 OS << "Getter";
1918 else if (Node->isMessagingSetter())
1919 OS << "Setter";
Douglas Gregor8ea1f532008-11-04 14:56:14 +00001920}
1921
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001922void ASTDumper::VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001923 VisitExpr(Node);
Ted Kremeneke65b0862012-03-06 20:05:56 +00001924 if (Node->isArraySubscriptRefExpr())
1925 OS << " Kind=ArraySubscript GetterForArray=\"";
1926 else
1927 OS << " Kind=DictionarySubscript GetterForDictionary=\"";
1928 if (Node->getAtIndexMethodDecl())
1929 OS << Node->getAtIndexMethodDecl()->getSelector().getAsString();
1930 else
1931 OS << "(null)";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001932
Ted Kremeneke65b0862012-03-06 20:05:56 +00001933 if (Node->isArraySubscriptRefExpr())
1934 OS << "\" SetterForArray=\"";
1935 else
1936 OS << "\" SetterForDictionary=\"";
1937 if (Node->setAtIndexMethodDecl())
1938 OS << Node->setAtIndexMethodDecl()->getSelector().getAsString();
1939 else
1940 OS << "(null)";
1941}
1942
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001943void ASTDumper::VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001944 VisitExpr(Node);
Ted Kremeneke65b0862012-03-06 20:05:56 +00001945 OS << " " << (Node->getValue() ? "__objc_yes" : "__objc_no");
1946}
1947
Chris Lattnercbe4f772007-08-08 22:51:59 +00001948//===----------------------------------------------------------------------===//
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00001949// Comments
1950//===----------------------------------------------------------------------===//
1951
1952const char *ASTDumper::getCommandName(unsigned CommandID) {
1953 if (Traits)
1954 return Traits->getCommandInfo(CommandID)->Name;
1955 const CommandInfo *Info = CommandTraits::getBuiltinCommandInfo(CommandID);
1956 if (Info)
1957 return Info->Name;
1958 return "<not a builtin command>";
1959}
1960
1961void ASTDumper::dumpFullComment(const FullComment *C) {
1962 if (!C)
1963 return;
1964
1965 FC = C;
1966 dumpComment(C);
1967 FC = 0;
1968}
1969
1970void ASTDumper::dumpComment(const Comment *C) {
1971 IndentScope Indent(*this);
1972
1973 if (!C) {
Richard Trieud215b8d2013-01-26 01:31:20 +00001974 ColorScope Color(*this, NullColor);
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00001975 OS << "<<<NULL>>>";
1976 return;
1977 }
1978
Richard Trieud215b8d2013-01-26 01:31:20 +00001979 {
1980 ColorScope Color(*this, CommentColor);
1981 OS << C->getCommentKindName();
1982 }
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00001983 dumpPointer(C);
1984 dumpSourceRange(C->getSourceRange());
1985 ConstCommentVisitor<ASTDumper>::visit(C);
1986 for (Comment::child_iterator I = C->child_begin(), E = C->child_end();
Richard Trieude5cc7d2013-01-31 01:44:26 +00001987 I != E; ++I) {
1988 if (I + 1 == E)
1989 lastChild();
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00001990 dumpComment(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001991 }
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00001992}
1993
1994void ASTDumper::visitTextComment(const TextComment *C) {
1995 OS << " Text=\"" << C->getText() << "\"";
1996}
1997
1998void ASTDumper::visitInlineCommandComment(const InlineCommandComment *C) {
1999 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\"";
2000 switch (C->getRenderKind()) {
2001 case InlineCommandComment::RenderNormal:
2002 OS << " RenderNormal";
2003 break;
2004 case InlineCommandComment::RenderBold:
2005 OS << " RenderBold";
2006 break;
2007 case InlineCommandComment::RenderMonospaced:
2008 OS << " RenderMonospaced";
2009 break;
2010 case InlineCommandComment::RenderEmphasized:
2011 OS << " RenderEmphasized";
2012 break;
2013 }
2014
2015 for (unsigned i = 0, e = C->getNumArgs(); i != e; ++i)
2016 OS << " Arg[" << i << "]=\"" << C->getArgText(i) << "\"";
2017}
2018
2019void ASTDumper::visitHTMLStartTagComment(const HTMLStartTagComment *C) {
2020 OS << " Name=\"" << C->getTagName() << "\"";
2021 if (C->getNumAttrs() != 0) {
2022 OS << " Attrs: ";
2023 for (unsigned i = 0, e = C->getNumAttrs(); i != e; ++i) {
2024 const HTMLStartTagComment::Attribute &Attr = C->getAttr(i);
2025 OS << " \"" << Attr.Name << "=\"" << Attr.Value << "\"";
2026 }
2027 }
2028 if (C->isSelfClosing())
2029 OS << " SelfClosing";
2030}
2031
2032void ASTDumper::visitHTMLEndTagComment(const HTMLEndTagComment *C) {
2033 OS << " Name=\"" << C->getTagName() << "\"";
2034}
2035
2036void ASTDumper::visitBlockCommandComment(const BlockCommandComment *C) {
2037 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\"";
2038 for (unsigned i = 0, e = C->getNumArgs(); i != e; ++i)
2039 OS << " Arg[" << i << "]=\"" << C->getArgText(i) << "\"";
2040}
2041
2042void ASTDumper::visitParamCommandComment(const ParamCommandComment *C) {
2043 OS << " " << ParamCommandComment::getDirectionAsString(C->getDirection());
2044
2045 if (C->isDirectionExplicit())
2046 OS << " explicitly";
2047 else
2048 OS << " implicitly";
2049
2050 if (C->hasParamName()) {
2051 if (C->isParamIndexValid())
2052 OS << " Param=\"" << C->getParamName(FC) << "\"";
2053 else
2054 OS << " Param=\"" << C->getParamNameAsWritten() << "\"";
2055 }
2056
2057 if (C->isParamIndexValid())
2058 OS << " ParamIndex=" << C->getParamIndex();
2059}
2060
2061void ASTDumper::visitTParamCommandComment(const TParamCommandComment *C) {
2062 if (C->hasParamName()) {
2063 if (C->isPositionValid())
2064 OS << " Param=\"" << C->getParamName(FC) << "\"";
2065 else
2066 OS << " Param=\"" << C->getParamNameAsWritten() << "\"";
2067 }
2068
2069 if (C->isPositionValid()) {
2070 OS << " Position=<";
2071 for (unsigned i = 0, e = C->getDepth(); i != e; ++i) {
2072 OS << C->getIndex(i);
2073 if (i != e - 1)
2074 OS << ", ";
2075 }
2076 OS << ">";
2077 }
2078}
2079
2080void ASTDumper::visitVerbatimBlockComment(const VerbatimBlockComment *C) {
2081 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\""
2082 " CloseName=\"" << C->getCloseName() << "\"";
2083}
2084
2085void ASTDumper::visitVerbatimBlockLineComment(
2086 const VerbatimBlockLineComment *C) {
2087 OS << " Text=\"" << C->getText() << "\"";
2088}
2089
2090void ASTDumper::visitVerbatimLineComment(const VerbatimLineComment *C) {
2091 OS << " Text=\"" << C->getText() << "\"";
2092}
2093
2094//===----------------------------------------------------------------------===//
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002095// Decl method implementations
2096//===----------------------------------------------------------------------===//
2097
2098void Decl::dump() const {
2099 dump(llvm::errs());
2100}
2101
2102void Decl::dump(raw_ostream &OS) const {
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002103 ASTDumper P(OS, &getASTContext().getCommentCommandTraits(),
2104 &getASTContext().getSourceManager());
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002105 P.dumpDecl(this);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002106}
2107
Richard Trieud215b8d2013-01-26 01:31:20 +00002108void Decl::dumpColor() const {
2109 ASTDumper P(llvm::errs(), &getASTContext().getCommentCommandTraits(),
2110 &getASTContext().getSourceManager(), /*ShowColors*/true);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002111 P.dumpDecl(this);
Richard Trieud215b8d2013-01-26 01:31:20 +00002112}
Richard Smith33937e72013-06-22 21:49:40 +00002113
2114void DeclContext::dumpLookups() const {
Richard Smith6ea05822013-06-24 01:45:33 +00002115 dumpLookups(llvm::errs());
2116}
2117
2118void DeclContext::dumpLookups(raw_ostream &OS) const {
Richard Smith33937e72013-06-22 21:49:40 +00002119 const DeclContext *DC = this;
2120 while (!DC->isTranslationUnit())
2121 DC = DC->getParent();
2122 ASTContext &Ctx = cast<TranslationUnitDecl>(DC)->getASTContext();
Richard Smith6ea05822013-06-24 01:45:33 +00002123 ASTDumper P(OS, &Ctx.getCommentCommandTraits(), &Ctx.getSourceManager());
Richard Smith33937e72013-06-22 21:49:40 +00002124 P.dumpLookups(this);
2125}
2126
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002127//===----------------------------------------------------------------------===//
Chris Lattnercbe4f772007-08-08 22:51:59 +00002128// Stmt method implementations
2129//===----------------------------------------------------------------------===//
2130
Chris Lattner11e30d32007-08-30 06:17:34 +00002131void Stmt::dump(SourceManager &SM) const {
Argyrios Kyrtzidisc049f752010-08-09 10:54:31 +00002132 dump(llvm::errs(), SM);
2133}
2134
Chris Lattner0e62c1c2011-07-23 10:55:15 +00002135void Stmt::dump(raw_ostream &OS, SourceManager &SM) const {
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002136 ASTDumper P(OS, 0, &SM);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002137 P.dumpStmt(this);
Chris Lattner779d5d92007-08-30 00:40:08 +00002138}
2139
Chris Lattnercbe4f772007-08-08 22:51:59 +00002140void Stmt::dump() const {
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002141 ASTDumper P(llvm::errs(), 0, 0);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002142 P.dumpStmt(this);
Chris Lattnercbe4f772007-08-08 22:51:59 +00002143}
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002144
Richard Trieud215b8d2013-01-26 01:31:20 +00002145void Stmt::dumpColor() const {
2146 ASTDumper P(llvm::errs(), 0, 0, /*ShowColors*/true);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002147 P.dumpStmt(this);
Richard Trieud215b8d2013-01-26 01:31:20 +00002148}
2149
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002150//===----------------------------------------------------------------------===//
2151// Comment method implementations
2152//===----------------------------------------------------------------------===//
2153
2154void Comment::dump() const {
2155 dump(llvm::errs(), 0, 0);
2156}
2157
2158void Comment::dump(const ASTContext &Context) const {
2159 dump(llvm::errs(), &Context.getCommentCommandTraits(),
2160 &Context.getSourceManager());
2161}
2162
Alexander Kornienko00911f12013-01-15 12:20:21 +00002163void Comment::dump(raw_ostream &OS, const CommandTraits *Traits,
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002164 const SourceManager *SM) const {
2165 const FullComment *FC = dyn_cast<FullComment>(this);
2166 ASTDumper D(OS, Traits, SM);
2167 D.dumpFullComment(FC);
2168}
Richard Trieud215b8d2013-01-26 01:31:20 +00002169
2170void Comment::dumpColor() const {
2171 const FullComment *FC = dyn_cast<FullComment>(this);
2172 ASTDumper D(llvm::errs(), 0, 0, /*ShowColors*/true);
2173 D.dumpFullComment(FC);
2174}