blob: 908099a23a5f833a90bf47d0c08e852034b376c9 [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);
555 }
556 }
557
558 if (HasUndeserializedLookups) {
559 lastChild();
560 IndentScope Indent(*this);
561 ColorScope Color(*this, UndeserializedColor);
562 OS << "<undeserialized lookups>";
563 }
564}
565
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000566void ASTDumper::dumpAttr(const Attr *A) {
567 IndentScope Indent(*this);
Richard Trieud215b8d2013-01-26 01:31:20 +0000568 {
569 ColorScope Color(*this, AttrColor);
570 switch (A->getKind()) {
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000571#define ATTR(X) case attr::X: OS << #X; break;
572#include "clang/Basic/AttrList.inc"
Richard Trieud215b8d2013-01-26 01:31:20 +0000573 default: llvm_unreachable("unexpected attribute kind");
574 }
575 OS << "Attr";
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000576 }
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000577 dumpPointer(A);
578 dumpSourceRange(A->getRange());
579#include "clang/AST/AttrDump.inc"
580}
581
Richard Smith71bec062013-10-15 21:58:30 +0000582static void dumpPreviousDeclImpl(raw_ostream &OS, ...) {}
583
584template<typename T>
585static void dumpPreviousDeclImpl(raw_ostream &OS, const Mergeable<T> *D) {
Rafael Espindola8db352d2013-10-17 15:37:26 +0000586 const T *First = D->getFirstDecl();
Richard Smith71bec062013-10-15 21:58:30 +0000587 if (First != D)
588 OS << " first " << First;
Richard Smithf5f43542013-02-07 01:35:44 +0000589}
590
591template<typename T>
Richard Smith71bec062013-10-15 21:58:30 +0000592static void dumpPreviousDeclImpl(raw_ostream &OS, const Redeclarable<T> *D) {
593 const T *Prev = D->getPreviousDecl();
594 if (Prev)
595 OS << " prev " << Prev;
Richard Smithf5f43542013-02-07 01:35:44 +0000596}
597
Richard Smith71bec062013-10-15 21:58:30 +0000598/// Dump the previous declaration in the redeclaration chain for a declaration,
599/// if any.
600static void dumpPreviousDecl(raw_ostream &OS, const Decl *D) {
Richard Smithf5f43542013-02-07 01:35:44 +0000601 switch (D->getKind()) {
602#define DECL(DERIVED, BASE) \
603 case Decl::DERIVED: \
Richard Smith71bec062013-10-15 21:58:30 +0000604 return dumpPreviousDeclImpl(OS, cast<DERIVED##Decl>(D));
Richard Smithf5f43542013-02-07 01:35:44 +0000605#define ABSTRACT_DECL(DECL)
606#include "clang/AST/DeclNodes.inc"
607 }
608 llvm_unreachable("Decl that isn't part of DeclNodes.inc!");
609}
610
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000611//===----------------------------------------------------------------------===//
612// C++ Utilities
613//===----------------------------------------------------------------------===//
614
615void ASTDumper::dumpAccessSpecifier(AccessSpecifier AS) {
616 switch (AS) {
617 case AS_none:
618 break;
619 case AS_public:
620 OS << "public";
621 break;
622 case AS_protected:
623 OS << "protected";
624 break;
625 case AS_private:
626 OS << "private";
627 break;
628 }
629}
630
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000631void ASTDumper::dumpCXXCtorInitializer(const CXXCtorInitializer *Init) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000632 IndentScope Indent(*this);
633 OS << "CXXCtorInitializer";
634 if (Init->isAnyMemberInitializer()) {
635 OS << ' ';
636 dumpBareDeclRef(Init->getAnyMember());
637 } else {
638 dumpType(QualType(Init->getBaseClass(), 0));
639 }
640 dumpStmt(Init->getInit());
641}
642
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000643void ASTDumper::dumpTemplateParameters(const TemplateParameterList *TPL) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000644 if (!TPL)
645 return;
646
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000647 for (TemplateParameterList::const_iterator I = TPL->begin(), E = TPL->end();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000648 I != E; ++I)
649 dumpDecl(*I);
650}
651
652void ASTDumper::dumpTemplateArgumentListInfo(
653 const TemplateArgumentListInfo &TALI) {
Richard Trieude5cc7d2013-01-31 01:44:26 +0000654 for (unsigned i = 0, e = TALI.size(); i < e; ++i) {
655 if (i + 1 == e)
656 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000657 dumpTemplateArgumentLoc(TALI[i]);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000658 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000659}
660
661void ASTDumper::dumpTemplateArgumentLoc(const TemplateArgumentLoc &A) {
662 dumpTemplateArgument(A.getArgument(), A.getSourceRange());
663}
664
665void ASTDumper::dumpTemplateArgumentList(const TemplateArgumentList &TAL) {
666 for (unsigned i = 0, e = TAL.size(); i < e; ++i)
667 dumpTemplateArgument(TAL[i]);
668}
669
670void ASTDumper::dumpTemplateArgument(const TemplateArgument &A, SourceRange R) {
671 IndentScope Indent(*this);
672 OS << "TemplateArgument";
673 if (R.isValid())
674 dumpSourceRange(R);
675
676 switch (A.getKind()) {
677 case TemplateArgument::Null:
678 OS << " null";
679 break;
680 case TemplateArgument::Type:
681 OS << " type";
Richard Trieude5cc7d2013-01-31 01:44:26 +0000682 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000683 dumpType(A.getAsType());
684 break;
685 case TemplateArgument::Declaration:
686 OS << " decl";
Richard Trieude5cc7d2013-01-31 01:44:26 +0000687 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000688 dumpDeclRef(A.getAsDecl());
689 break;
690 case TemplateArgument::NullPtr:
691 OS << " nullptr";
692 break;
693 case TemplateArgument::Integral:
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000694 OS << " integral " << A.getAsIntegral();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000695 break;
696 case TemplateArgument::Template:
697 OS << " template ";
698 A.getAsTemplate().dump(OS);
699 break;
700 case TemplateArgument::TemplateExpansion:
701 OS << " template expansion";
702 A.getAsTemplateOrTemplatePattern().dump(OS);
703 break;
704 case TemplateArgument::Expression:
705 OS << " expr";
Richard Trieude5cc7d2013-01-31 01:44:26 +0000706 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000707 dumpStmt(A.getAsExpr());
708 break;
709 case TemplateArgument::Pack:
710 OS << " pack";
711 for (TemplateArgument::pack_iterator I = A.pack_begin(), E = A.pack_end();
Richard Trieude5cc7d2013-01-31 01:44:26 +0000712 I != E; ++I) {
713 if (I + 1 == E)
714 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000715 dumpTemplateArgument(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000716 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000717 break;
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000718 }
719}
720
Chris Lattner11e30d32007-08-30 06:17:34 +0000721//===----------------------------------------------------------------------===//
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000722// Decl dumping methods.
Chris Lattnercbe4f772007-08-08 22:51:59 +0000723//===----------------------------------------------------------------------===//
724
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000725void ASTDumper::dumpDecl(const Decl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000726 IndentScope Indent(*this);
Mike Stump11289f42009-09-09 15:08:12 +0000727
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000728 if (!D) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000729 ColorScope Color(*this, NullColor);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000730 OS << "<<<NULL>>>";
731 return;
Chris Lattnercbe4f772007-08-08 22:51:59 +0000732 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000733
Richard Trieud215b8d2013-01-26 01:31:20 +0000734 {
735 ColorScope Color(*this, DeclKindNameColor);
736 OS << D->getDeclKindName() << "Decl";
737 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000738 dumpPointer(D);
Richard Smithf5f43542013-02-07 01:35:44 +0000739 if (D->getLexicalDeclContext() != D->getDeclContext())
740 OS << " parent " << cast<Decl>(D->getDeclContext());
Richard Smith71bec062013-10-15 21:58:30 +0000741 dumpPreviousDecl(OS, D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000742 dumpSourceRange(D->getSourceRange());
Richard Trieude5cc7d2013-01-31 01:44:26 +0000743
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000744 bool HasAttrs = D->attr_begin() != D->attr_end();
Richard Smithb39b9d52013-05-21 05:24:00 +0000745 const FullComment *Comment =
746 D->getASTContext().getLocalCommentForDeclUncached(D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000747 // Decls within functions are visited by the body
Richard Trieude5cc7d2013-01-31 01:44:26 +0000748 bool HasDeclContext = !isa<FunctionDecl>(*D) && !isa<ObjCMethodDecl>(*D) &&
749 hasNodes(dyn_cast<DeclContext>(D));
750
Richard Smithb39b9d52013-05-21 05:24:00 +0000751 setMoreChildren(HasAttrs || Comment || HasDeclContext);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000752 ConstDeclVisitor<ASTDumper>::Visit(D);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000753
Richard Smithb39b9d52013-05-21 05:24:00 +0000754 setMoreChildren(Comment || HasDeclContext);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000755 for (Decl::attr_iterator I = D->attr_begin(), E = D->attr_end();
756 I != E; ++I) {
757 if (I + 1 == E)
758 lastChild();
759 dumpAttr(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000760 }
761
762 setMoreChildren(HasDeclContext);
763 lastChild();
Richard Smithb39b9d52013-05-21 05:24:00 +0000764 dumpFullComment(Comment);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000765
Nick Lewyckya382db02013-08-27 03:15:56 +0000766 if (D->isInvalidDecl())
767 OS << " invalid";
768
Richard Trieude5cc7d2013-01-31 01:44:26 +0000769 setMoreChildren(false);
770 if (HasDeclContext)
Richard Smithf5f43542013-02-07 01:35:44 +0000771 dumpDeclContext(cast<DeclContext>(D));
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000772}
773
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000774void ASTDumper::VisitLabelDecl(const LabelDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000775 dumpName(D);
776}
777
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000778void ASTDumper::VisitTypedefDecl(const TypedefDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000779 dumpName(D);
780 dumpType(D->getUnderlyingType());
781 if (D->isModulePrivate())
782 OS << " __module_private__";
783}
784
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000785void ASTDumper::VisitEnumDecl(const EnumDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000786 if (D->isScoped()) {
787 if (D->isScopedUsingClassTag())
788 OS << " class";
789 else
790 OS << " struct";
791 }
792 dumpName(D);
793 if (D->isModulePrivate())
794 OS << " __module_private__";
795 if (D->isFixed())
796 dumpType(D->getIntegerType());
797}
798
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000799void ASTDumper::VisitRecordDecl(const RecordDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000800 OS << ' ' << D->getKindName();
801 dumpName(D);
802 if (D->isModulePrivate())
803 OS << " __module_private__";
Richard Smith99bc1b92013-08-30 05:32:29 +0000804 if (D->isCompleteDefinition())
805 OS << " definition";
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000806}
807
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000808void ASTDumper::VisitEnumConstantDecl(const EnumConstantDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000809 dumpName(D);
810 dumpType(D->getType());
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000811 if (const Expr *Init = D->getInitExpr()) {
Richard Trieude5cc7d2013-01-31 01:44:26 +0000812 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000813 dumpStmt(Init);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000814 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000815}
816
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000817void ASTDumper::VisitIndirectFieldDecl(const IndirectFieldDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000818 dumpName(D);
819 dumpType(D->getType());
820 for (IndirectFieldDecl::chain_iterator I = D->chain_begin(),
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000821 E = D->chain_end();
822 I != E; ++I) {
Richard Trieude5cc7d2013-01-31 01:44:26 +0000823 if (I + 1 == E)
824 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000825 dumpDeclRef(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000826 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000827}
828
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000829void ASTDumper::VisitFunctionDecl(const FunctionDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000830 dumpName(D);
831 dumpType(D->getType());
832
Rafael Espindola6ae7e502013-04-03 19:27:57 +0000833 StorageClass SC = D->getStorageClass();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000834 if (SC != SC_None)
835 OS << ' ' << VarDecl::getStorageClassSpecifierString(SC);
836 if (D->isInlineSpecified())
837 OS << " inline";
838 if (D->isVirtualAsWritten())
839 OS << " virtual";
840 if (D->isModulePrivate())
841 OS << " __module_private__";
842
843 if (D->isPure())
844 OS << " pure";
845 else if (D->isDeletedAsWritten())
846 OS << " delete";
847
Richard Smithadaa0152013-05-17 02:09:46 +0000848 if (const FunctionProtoType *FPT = D->getType()->getAs<FunctionProtoType>()) {
849 FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo();
850 switch (EPI.ExceptionSpecType) {
851 default: break;
852 case EST_Unevaluated:
853 OS << " noexcept-unevaluated " << EPI.ExceptionSpecDecl;
854 break;
855 case EST_Uninstantiated:
856 OS << " noexcept-uninstantiated " << EPI.ExceptionSpecTemplate;
857 break;
858 }
859 }
860
Richard Trieude5cc7d2013-01-31 01:44:26 +0000861 bool OldMoreChildren = hasMoreChildren();
862 const FunctionTemplateSpecializationInfo *FTSI =
863 D->getTemplateSpecializationInfo();
864 bool HasTemplateSpecialization = FTSI;
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000865
Richard Trieude5cc7d2013-01-31 01:44:26 +0000866 bool HasNamedDecls = D->getDeclsInPrototypeScope().begin() !=
867 D->getDeclsInPrototypeScope().end();
868
869 bool HasFunctionDecls = D->param_begin() != D->param_end();
870
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000871 const CXXConstructorDecl *C = dyn_cast<CXXConstructorDecl>(D);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000872 bool HasCtorInitializers = C && C->init_begin() != C->init_end();
873
874 bool HasDeclarationBody = D->doesThisDeclarationHaveABody();
875
876 setMoreChildren(OldMoreChildren || HasNamedDecls || HasFunctionDecls ||
877 HasCtorInitializers || HasDeclarationBody);
878 if (HasTemplateSpecialization) {
879 lastChild();
880 dumpTemplateArgumentList(*FTSI->TemplateArguments);
881 }
882
883 setMoreChildren(OldMoreChildren || HasFunctionDecls ||
884 HasCtorInitializers || HasDeclarationBody);
Dmitri Gribenkof8579502013-01-12 19:30:44 +0000885 for (ArrayRef<NamedDecl *>::iterator
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000886 I = D->getDeclsInPrototypeScope().begin(),
Richard Trieude5cc7d2013-01-31 01:44:26 +0000887 E = D->getDeclsInPrototypeScope().end(); I != E; ++I) {
888 if (I + 1 == E)
889 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000890 dumpDecl(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000891 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000892
Richard Trieude5cc7d2013-01-31 01:44:26 +0000893 setMoreChildren(OldMoreChildren || HasCtorInitializers || HasDeclarationBody);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000894 for (FunctionDecl::param_const_iterator I = D->param_begin(),
895 E = D->param_end();
Richard Trieude5cc7d2013-01-31 01:44:26 +0000896 I != E; ++I) {
897 if (I + 1 == E)
898 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000899 dumpDecl(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000900 }
901
902 setMoreChildren(OldMoreChildren || HasDeclarationBody);
903 if (HasCtorInitializers)
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000904 for (CXXConstructorDecl::init_const_iterator I = C->init_begin(),
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000905 E = C->init_end();
906 I != E; ++I) {
Richard Trieude5cc7d2013-01-31 01:44:26 +0000907 if (I + 1 == E)
908 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000909 dumpCXXCtorInitializer(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000910 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000911
Richard Trieude5cc7d2013-01-31 01:44:26 +0000912 setMoreChildren(OldMoreChildren);
913 if (HasDeclarationBody) {
914 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000915 dumpStmt(D->getBody());
Richard Trieude5cc7d2013-01-31 01:44:26 +0000916 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000917}
918
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000919void ASTDumper::VisitFieldDecl(const FieldDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000920 dumpName(D);
921 dumpType(D->getType());
922 if (D->isMutable())
923 OS << " mutable";
924 if (D->isModulePrivate())
925 OS << " __module_private__";
Richard Trieude5cc7d2013-01-31 01:44:26 +0000926
927 bool OldMoreChildren = hasMoreChildren();
928 bool IsBitField = D->isBitField();
929 Expr *Init = D->getInClassInitializer();
930 bool HasInit = Init;
931
932 setMoreChildren(OldMoreChildren || HasInit);
933 if (IsBitField) {
934 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000935 dumpStmt(D->getBitWidth());
Richard Trieude5cc7d2013-01-31 01:44:26 +0000936 }
937 setMoreChildren(OldMoreChildren);
938 if (HasInit) {
939 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000940 dumpStmt(Init);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000941 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000942}
943
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000944void ASTDumper::VisitVarDecl(const VarDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000945 dumpName(D);
946 dumpType(D->getType());
Rafael Espindola6ae7e502013-04-03 19:27:57 +0000947 StorageClass SC = D->getStorageClass();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000948 if (SC != SC_None)
949 OS << ' ' << VarDecl::getStorageClassSpecifierString(SC);
Richard Smithfd3834f2013-04-13 02:43:54 +0000950 switch (D->getTLSKind()) {
951 case VarDecl::TLS_None: break;
952 case VarDecl::TLS_Static: OS << " tls"; break;
953 case VarDecl::TLS_Dynamic: OS << " tls_dynamic"; break;
954 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000955 if (D->isModulePrivate())
956 OS << " __module_private__";
957 if (D->isNRVOVariable())
958 OS << " nrvo";
Richard Trieude5cc7d2013-01-31 01:44:26 +0000959 if (D->hasInit()) {
960 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000961 dumpStmt(D->getInit());
Richard Trieude5cc7d2013-01-31 01:44:26 +0000962 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000963}
964
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000965void ASTDumper::VisitFileScopeAsmDecl(const FileScopeAsmDecl *D) {
Richard Trieude5cc7d2013-01-31 01:44:26 +0000966 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000967 dumpStmt(D->getAsmString());
968}
969
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000970void ASTDumper::VisitImportDecl(const ImportDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000971 OS << ' ' << D->getImportedModule()->getFullModuleName();
972}
973
974//===----------------------------------------------------------------------===//
975// C++ Declarations
976//===----------------------------------------------------------------------===//
977
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000978void ASTDumper::VisitNamespaceDecl(const NamespaceDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000979 dumpName(D);
980 if (D->isInline())
981 OS << " inline";
982 if (!D->isOriginalNamespace())
983 dumpDeclRef(D->getOriginalNamespace(), "original");
984}
985
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000986void ASTDumper::VisitUsingDirectiveDecl(const UsingDirectiveDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000987 OS << ' ';
988 dumpBareDeclRef(D->getNominatedNamespace());
989}
990
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000991void ASTDumper::VisitNamespaceAliasDecl(const NamespaceAliasDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000992 dumpName(D);
993 dumpDeclRef(D->getAliasedNamespace());
994}
995
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000996void ASTDumper::VisitTypeAliasDecl(const TypeAliasDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000997 dumpName(D);
998 dumpType(D->getUnderlyingType());
999}
1000
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001001void ASTDumper::VisitTypeAliasTemplateDecl(const TypeAliasTemplateDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001002 dumpName(D);
1003 dumpTemplateParameters(D->getTemplateParameters());
1004 dumpDecl(D->getTemplatedDecl());
1005}
1006
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001007void ASTDumper::VisitCXXRecordDecl(const CXXRecordDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001008 VisitRecordDecl(D);
1009 if (!D->isCompleteDefinition())
1010 return;
1011
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001012 for (CXXRecordDecl::base_class_const_iterator I = D->bases_begin(),
1013 E = D->bases_end();
1014 I != E; ++I) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001015 IndentScope Indent(*this);
1016 if (I->isVirtual())
1017 OS << "virtual ";
1018 dumpAccessSpecifier(I->getAccessSpecifier());
1019 dumpType(I->getType());
1020 if (I->isPackExpansion())
1021 OS << "...";
1022 }
1023}
1024
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001025void ASTDumper::VisitStaticAssertDecl(const StaticAssertDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001026 dumpStmt(D->getAssertExpr());
Richard Trieude5cc7d2013-01-31 01:44:26 +00001027 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001028 dumpStmt(D->getMessage());
1029}
1030
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001031void ASTDumper::VisitFunctionTemplateDecl(const FunctionTemplateDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001032 dumpName(D);
1033 dumpTemplateParameters(D->getTemplateParameters());
1034 dumpDecl(D->getTemplatedDecl());
Dmitri Gribenko81f25752013-02-14 13:20:36 +00001035 for (FunctionTemplateDecl::spec_iterator I = D->spec_begin(),
1036 E = D->spec_end();
1037 I != E; ++I) {
Richard Trieude5cc7d2013-01-31 01:44:26 +00001038 FunctionTemplateDecl::spec_iterator Next = I;
1039 ++Next;
1040 if (Next == E)
1041 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001042 switch (I->getTemplateSpecializationKind()) {
1043 case TSK_Undeclared:
1044 case TSK_ImplicitInstantiation:
1045 case TSK_ExplicitInstantiationDeclaration:
1046 case TSK_ExplicitInstantiationDefinition:
Dmitri Gribenkoefc6dfb2013-02-21 22:01:10 +00001047 if (D == D->getCanonicalDecl())
1048 dumpDecl(*I);
1049 else
1050 dumpDeclRef(*I);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001051 break;
1052 case TSK_ExplicitSpecialization:
1053 dumpDeclRef(*I);
1054 break;
1055 }
1056 }
1057}
1058
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001059void ASTDumper::VisitClassTemplateDecl(const ClassTemplateDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001060 dumpName(D);
1061 dumpTemplateParameters(D->getTemplateParameters());
Richard Trieude5cc7d2013-01-31 01:44:26 +00001062
Dmitri Gribenko81f25752013-02-14 13:20:36 +00001063 ClassTemplateDecl::spec_iterator I = D->spec_begin();
1064 ClassTemplateDecl::spec_iterator E = D->spec_end();
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001065 if (I == E)
Richard Trieude5cc7d2013-01-31 01:44:26 +00001066 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001067 dumpDecl(D->getTemplatedDecl());
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001068 for (; I != E; ++I) {
Richard Trieude5cc7d2013-01-31 01:44:26 +00001069 ClassTemplateDecl::spec_iterator Next = I;
1070 ++Next;
1071 if (Next == E)
1072 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001073 switch (I->getTemplateSpecializationKind()) {
1074 case TSK_Undeclared:
1075 case TSK_ImplicitInstantiation:
Dmitri Gribenkoefc6dfb2013-02-21 22:01:10 +00001076 if (D == D->getCanonicalDecl())
1077 dumpDecl(*I);
1078 else
1079 dumpDeclRef(*I);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001080 break;
1081 case TSK_ExplicitSpecialization:
1082 case TSK_ExplicitInstantiationDeclaration:
1083 case TSK_ExplicitInstantiationDefinition:
1084 dumpDeclRef(*I);
1085 break;
1086 }
1087 }
1088}
1089
1090void ASTDumper::VisitClassTemplateSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001091 const ClassTemplateSpecializationDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001092 VisitCXXRecordDecl(D);
1093 dumpTemplateArgumentList(D->getTemplateArgs());
1094}
1095
1096void ASTDumper::VisitClassTemplatePartialSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001097 const ClassTemplatePartialSpecializationDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001098 VisitClassTemplateSpecializationDecl(D);
1099 dumpTemplateParameters(D->getTemplateParameters());
1100}
1101
1102void ASTDumper::VisitClassScopeFunctionSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001103 const ClassScopeFunctionSpecializationDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001104 dumpDeclRef(D->getSpecialization());
1105 if (D->hasExplicitTemplateArgs())
1106 dumpTemplateArgumentListInfo(D->templateArgs());
1107}
1108
Richard Smithd25789a2013-09-18 01:36:02 +00001109void ASTDumper::VisitVarTemplateDecl(const VarTemplateDecl *D) {
1110 dumpName(D);
1111 dumpTemplateParameters(D->getTemplateParameters());
1112
1113 VarTemplateDecl::spec_iterator I = D->spec_begin();
1114 VarTemplateDecl::spec_iterator E = D->spec_end();
1115 if (I == E)
1116 lastChild();
1117 dumpDecl(D->getTemplatedDecl());
1118 for (; I != E; ++I) {
1119 VarTemplateDecl::spec_iterator Next = I;
1120 ++Next;
1121 if (Next == E)
1122 lastChild();
1123 switch (I->getTemplateSpecializationKind()) {
1124 case TSK_Undeclared:
1125 case TSK_ImplicitInstantiation:
1126 if (D == D->getCanonicalDecl())
1127 dumpDecl(*I);
1128 else
1129 dumpDeclRef(*I);
1130 break;
1131 case TSK_ExplicitSpecialization:
1132 case TSK_ExplicitInstantiationDeclaration:
1133 case TSK_ExplicitInstantiationDefinition:
1134 dumpDeclRef(*I);
1135 break;
1136 }
1137 }
1138}
1139
1140void ASTDumper::VisitVarTemplateSpecializationDecl(
1141 const VarTemplateSpecializationDecl *D) {
1142 dumpTemplateArgumentList(D->getTemplateArgs());
1143 VisitVarDecl(D);
1144}
1145
1146void ASTDumper::VisitVarTemplatePartialSpecializationDecl(
1147 const VarTemplatePartialSpecializationDecl *D) {
1148 dumpTemplateParameters(D->getTemplateParameters());
1149 VisitVarTemplateSpecializationDecl(D);
1150}
1151
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001152void ASTDumper::VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001153 if (D->wasDeclaredWithTypename())
1154 OS << " typename";
1155 else
1156 OS << " class";
1157 if (D->isParameterPack())
1158 OS << " ...";
1159 dumpName(D);
1160 if (D->hasDefaultArgument())
1161 dumpType(D->getDefaultArgument());
1162}
1163
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001164void ASTDumper::VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001165 dumpType(D->getType());
1166 if (D->isParameterPack())
1167 OS << " ...";
1168 dumpName(D);
1169 if (D->hasDefaultArgument())
1170 dumpStmt(D->getDefaultArgument());
1171}
1172
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001173void ASTDumper::VisitTemplateTemplateParmDecl(
1174 const TemplateTemplateParmDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001175 if (D->isParameterPack())
1176 OS << " ...";
1177 dumpName(D);
1178 dumpTemplateParameters(D->getTemplateParameters());
1179 if (D->hasDefaultArgument())
1180 dumpTemplateArgumentLoc(D->getDefaultArgument());
1181}
1182
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001183void ASTDumper::VisitUsingDecl(const UsingDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001184 OS << ' ';
1185 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
1186 OS << D->getNameAsString();
1187}
1188
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001189void ASTDumper::VisitUnresolvedUsingTypenameDecl(
1190 const UnresolvedUsingTypenameDecl *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::VisitUnresolvedUsingValueDecl(const UnresolvedUsingValueDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001197 OS << ' ';
1198 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
1199 OS << D->getNameAsString();
1200 dumpType(D->getType());
1201}
1202
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001203void ASTDumper::VisitUsingShadowDecl(const UsingShadowDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001204 OS << ' ';
1205 dumpBareDeclRef(D->getTargetDecl());
1206}
1207
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001208void ASTDumper::VisitLinkageSpecDecl(const LinkageSpecDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001209 switch (D->getLanguage()) {
1210 case LinkageSpecDecl::lang_c: OS << " C"; break;
1211 case LinkageSpecDecl::lang_cxx: OS << " C++"; break;
1212 }
1213}
1214
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001215void ASTDumper::VisitAccessSpecDecl(const AccessSpecDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001216 OS << ' ';
1217 dumpAccessSpecifier(D->getAccess());
1218}
1219
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001220void ASTDumper::VisitFriendDecl(const FriendDecl *D) {
Richard Smithf5f43542013-02-07 01:35:44 +00001221 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001222 if (TypeSourceInfo *T = D->getFriendType())
1223 dumpType(T->getType());
1224 else
1225 dumpDecl(D->getFriendDecl());
1226}
1227
1228//===----------------------------------------------------------------------===//
1229// Obj-C Declarations
1230//===----------------------------------------------------------------------===//
1231
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001232void ASTDumper::VisitObjCIvarDecl(const ObjCIvarDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001233 dumpName(D);
1234 dumpType(D->getType());
1235 if (D->getSynthesize())
1236 OS << " synthesize";
1237
1238 switch (D->getAccessControl()) {
1239 case ObjCIvarDecl::None:
1240 OS << " none";
1241 break;
1242 case ObjCIvarDecl::Private:
1243 OS << " private";
1244 break;
1245 case ObjCIvarDecl::Protected:
1246 OS << " protected";
1247 break;
1248 case ObjCIvarDecl::Public:
1249 OS << " public";
1250 break;
1251 case ObjCIvarDecl::Package:
1252 OS << " package";
1253 break;
1254 }
1255}
1256
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001257void ASTDumper::VisitObjCMethodDecl(const ObjCMethodDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001258 if (D->isInstanceMethod())
1259 OS << " -";
1260 else
1261 OS << " +";
1262 dumpName(D);
1263 dumpType(D->getResultType());
1264
Richard Trieude5cc7d2013-01-31 01:44:26 +00001265 bool OldMoreChildren = hasMoreChildren();
1266 bool IsVariadic = D->isVariadic();
1267 bool HasBody = D->hasBody();
1268
1269 setMoreChildren(OldMoreChildren || IsVariadic || HasBody);
1270 if (D->isThisDeclarationADefinition()) {
1271 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001272 dumpDeclContext(D);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001273 } else {
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001274 for (ObjCMethodDecl::param_const_iterator I = D->param_begin(),
1275 E = D->param_end();
1276 I != E; ++I) {
Richard Trieude5cc7d2013-01-31 01:44:26 +00001277 if (I + 1 == E)
1278 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001279 dumpDecl(*I);
1280 }
1281 }
1282
Richard Trieude5cc7d2013-01-31 01:44:26 +00001283 setMoreChildren(OldMoreChildren || HasBody);
1284 if (IsVariadic) {
1285 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001286 IndentScope Indent(*this);
1287 OS << "...";
1288 }
1289
Richard Trieude5cc7d2013-01-31 01:44:26 +00001290 setMoreChildren(OldMoreChildren);
1291 if (HasBody) {
1292 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001293 dumpStmt(D->getBody());
Richard Trieude5cc7d2013-01-31 01:44:26 +00001294 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001295}
1296
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001297void ASTDumper::VisitObjCCategoryDecl(const ObjCCategoryDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001298 dumpName(D);
1299 dumpDeclRef(D->getClassInterface());
Richard Trieude5cc7d2013-01-31 01:44:26 +00001300 if (D->protocol_begin() == D->protocol_end())
1301 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001302 dumpDeclRef(D->getImplementation());
1303 for (ObjCCategoryDecl::protocol_iterator I = D->protocol_begin(),
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001304 E = D->protocol_end();
1305 I != E; ++I) {
Richard Trieude5cc7d2013-01-31 01:44:26 +00001306 if (I + 1 == E)
1307 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001308 dumpDeclRef(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001309 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001310}
1311
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001312void ASTDumper::VisitObjCCategoryImplDecl(const ObjCCategoryImplDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001313 dumpName(D);
1314 dumpDeclRef(D->getClassInterface());
Richard Trieude5cc7d2013-01-31 01:44:26 +00001315 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001316 dumpDeclRef(D->getCategoryDecl());
1317}
1318
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001319void ASTDumper::VisitObjCProtocolDecl(const ObjCProtocolDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001320 dumpName(D);
1321 for (ObjCProtocolDecl::protocol_iterator I = D->protocol_begin(),
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001322 E = D->protocol_end();
1323 I != E; ++I) {
Richard Trieude5cc7d2013-01-31 01:44:26 +00001324 if (I + 1 == E)
1325 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001326 dumpDeclRef(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001327 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001328}
1329
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001330void ASTDumper::VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001331 dumpName(D);
1332 dumpDeclRef(D->getSuperClass(), "super");
Richard Trieude5cc7d2013-01-31 01:44:26 +00001333 if (D->protocol_begin() == D->protocol_end())
1334 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001335 dumpDeclRef(D->getImplementation());
1336 for (ObjCInterfaceDecl::protocol_iterator I = D->protocol_begin(),
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001337 E = D->protocol_end();
1338 I != E; ++I) {
Richard Trieude5cc7d2013-01-31 01:44:26 +00001339 if (I + 1 == E)
1340 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001341 dumpDeclRef(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001342 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001343}
1344
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001345void ASTDumper::VisitObjCImplementationDecl(const ObjCImplementationDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001346 dumpName(D);
1347 dumpDeclRef(D->getSuperClass(), "super");
Richard Trieude5cc7d2013-01-31 01:44:26 +00001348 if (D->init_begin() == D->init_end())
1349 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001350 dumpDeclRef(D->getClassInterface());
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001351 for (ObjCImplementationDecl::init_const_iterator I = D->init_begin(),
1352 E = D->init_end();
1353 I != E; ++I) {
Richard Trieude5cc7d2013-01-31 01:44:26 +00001354 if (I + 1 == E)
1355 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001356 dumpCXXCtorInitializer(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001357 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001358}
1359
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001360void ASTDumper::VisitObjCCompatibleAliasDecl(const ObjCCompatibleAliasDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001361 dumpName(D);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001362 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001363 dumpDeclRef(D->getClassInterface());
1364}
1365
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001366void ASTDumper::VisitObjCPropertyDecl(const ObjCPropertyDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001367 dumpName(D);
1368 dumpType(D->getType());
1369
1370 if (D->getPropertyImplementation() == ObjCPropertyDecl::Required)
1371 OS << " required";
1372 else if (D->getPropertyImplementation() == ObjCPropertyDecl::Optional)
1373 OS << " optional";
1374
1375 ObjCPropertyDecl::PropertyAttributeKind Attrs = D->getPropertyAttributes();
1376 if (Attrs != ObjCPropertyDecl::OBJC_PR_noattr) {
1377 if (Attrs & ObjCPropertyDecl::OBJC_PR_readonly)
1378 OS << " readonly";
1379 if (Attrs & ObjCPropertyDecl::OBJC_PR_assign)
1380 OS << " assign";
1381 if (Attrs & ObjCPropertyDecl::OBJC_PR_readwrite)
1382 OS << " readwrite";
1383 if (Attrs & ObjCPropertyDecl::OBJC_PR_retain)
1384 OS << " retain";
1385 if (Attrs & ObjCPropertyDecl::OBJC_PR_copy)
1386 OS << " copy";
1387 if (Attrs & ObjCPropertyDecl::OBJC_PR_nonatomic)
1388 OS << " nonatomic";
1389 if (Attrs & ObjCPropertyDecl::OBJC_PR_atomic)
1390 OS << " atomic";
1391 if (Attrs & ObjCPropertyDecl::OBJC_PR_weak)
1392 OS << " weak";
1393 if (Attrs & ObjCPropertyDecl::OBJC_PR_strong)
1394 OS << " strong";
1395 if (Attrs & ObjCPropertyDecl::OBJC_PR_unsafe_unretained)
1396 OS << " unsafe_unretained";
Richard Trieude5cc7d2013-01-31 01:44:26 +00001397 if (Attrs & ObjCPropertyDecl::OBJC_PR_getter) {
1398 if (!(Attrs & ObjCPropertyDecl::OBJC_PR_setter))
1399 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001400 dumpDeclRef(D->getGetterMethodDecl(), "getter");
Richard Trieude5cc7d2013-01-31 01:44:26 +00001401 }
1402 if (Attrs & ObjCPropertyDecl::OBJC_PR_setter) {
1403 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001404 dumpDeclRef(D->getSetterMethodDecl(), "setter");
Richard Trieude5cc7d2013-01-31 01:44:26 +00001405 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001406 }
1407}
1408
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001409void ASTDumper::VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001410 dumpName(D->getPropertyDecl());
1411 if (D->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize)
1412 OS << " synthesize";
1413 else
1414 OS << " dynamic";
1415 dumpDeclRef(D->getPropertyDecl());
Richard Trieude5cc7d2013-01-31 01:44:26 +00001416 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001417 dumpDeclRef(D->getPropertyIvarDecl());
1418}
1419
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001420void ASTDumper::VisitBlockDecl(const BlockDecl *D) {
1421 for (BlockDecl::param_const_iterator I = D->param_begin(), E = D->param_end();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001422 I != E; ++I)
1423 dumpDecl(*I);
1424
1425 if (D->isVariadic()) {
1426 IndentScope Indent(*this);
1427 OS << "...";
1428 }
1429
1430 if (D->capturesCXXThis()) {
1431 IndentScope Indent(*this);
1432 OS << "capture this";
1433 }
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001434 for (BlockDecl::capture_iterator I = D->capture_begin(), E = D->capture_end();
1435 I != E; ++I) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001436 IndentScope Indent(*this);
1437 OS << "capture";
1438 if (I->isByRef())
1439 OS << " byref";
1440 if (I->isNested())
1441 OS << " nested";
1442 if (I->getVariable()) {
1443 OS << ' ';
1444 dumpBareDeclRef(I->getVariable());
1445 }
1446 if (I->hasCopyExpr())
1447 dumpStmt(I->getCopyExpr());
1448 }
Richard Trieude5cc7d2013-01-31 01:44:26 +00001449 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001450 dumpStmt(D->getBody());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001451}
1452
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001453//===----------------------------------------------------------------------===//
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001454// Stmt dumping methods.
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001455//===----------------------------------------------------------------------===//
1456
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001457void ASTDumper::dumpStmt(const Stmt *S) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001458 IndentScope Indent(*this);
1459
1460 if (!S) {
Richard Trieud215b8d2013-01-26 01:31:20 +00001461 ColorScope Color(*this, NullColor);
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001462 OS << "<<<NULL>>>";
1463 return;
1464 }
1465
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001466 if (const DeclStmt *DS = dyn_cast<DeclStmt>(S)) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001467 VisitDeclStmt(DS);
1468 return;
1469 }
1470
David Blaikie7d170102013-05-15 07:37:26 +00001471 setMoreChildren(!S->children().empty());
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001472 ConstStmtVisitor<ASTDumper>::Visit(S);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001473 setMoreChildren(false);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001474 for (Stmt::const_child_range CI = S->children(); CI; ++CI) {
1475 Stmt::const_child_range Next = CI;
Richard Trieude5cc7d2013-01-31 01:44:26 +00001476 ++Next;
1477 if (!Next)
1478 lastChild();
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001479 dumpStmt(*CI);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001480 }
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001481}
1482
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001483void ASTDumper::VisitStmt(const Stmt *Node) {
Richard Trieud215b8d2013-01-26 01:31:20 +00001484 {
1485 ColorScope Color(*this, StmtColor);
1486 OS << Node->getStmtClassName();
1487 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001488 dumpPointer(Node);
1489 dumpSourceRange(Node->getSourceRange());
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001490}
1491
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001492void ASTDumper::VisitDeclStmt(const DeclStmt *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001493 VisitStmt(Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001494 for (DeclStmt::const_decl_iterator I = Node->decl_begin(),
1495 E = Node->decl_end();
Richard Trieude5cc7d2013-01-31 01:44:26 +00001496 I != E; ++I) {
1497 if (I + 1 == E)
1498 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001499 dumpDecl(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001500 }
Ted Kremenek433a4922007-12-12 06:59:42 +00001501}
1502
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001503void ASTDumper::VisitAttributedStmt(const AttributedStmt *Node) {
Alexander Kornienko5bc364e2013-01-07 17:53:08 +00001504 VisitStmt(Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001505 for (ArrayRef<const Attr *>::iterator I = Node->getAttrs().begin(),
1506 E = Node->getAttrs().end();
1507 I != E; ++I) {
Richard Trieude5cc7d2013-01-31 01:44:26 +00001508 if (I + 1 == E)
1509 lastChild();
Alexander Kornienko5bc364e2013-01-07 17:53:08 +00001510 dumpAttr(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001511 }
Alexander Kornienko5bc364e2013-01-07 17:53:08 +00001512}
1513
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001514void ASTDumper::VisitLabelStmt(const LabelStmt *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001515 VisitStmt(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001516 OS << " '" << Node->getName() << "'";
Chris Lattnercbe4f772007-08-08 22:51:59 +00001517}
1518
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001519void ASTDumper::VisitGotoStmt(const GotoStmt *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001520 VisitStmt(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001521 OS << " '" << Node->getLabel()->getName() << "'";
1522 dumpPointer(Node->getLabel());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001523}
1524
Pavel Labath1ef83422013-09-04 14:35:00 +00001525void ASTDumper::VisitCXXCatchStmt(const CXXCatchStmt *Node) {
1526 VisitStmt(Node);
1527 dumpDecl(Node->getExceptionDecl());
1528}
1529
Chris Lattnercbe4f772007-08-08 22:51:59 +00001530//===----------------------------------------------------------------------===//
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001531// Expr dumping methods.
Chris Lattnercbe4f772007-08-08 22:51:59 +00001532//===----------------------------------------------------------------------===//
1533
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001534void ASTDumper::VisitExpr(const Expr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001535 VisitStmt(Node);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001536 dumpType(Node->getType());
1537
Richard Trieud215b8d2013-01-26 01:31:20 +00001538 {
1539 ColorScope Color(*this, ValueKindColor);
1540 switch (Node->getValueKind()) {
1541 case VK_RValue:
1542 break;
1543 case VK_LValue:
1544 OS << " lvalue";
1545 break;
1546 case VK_XValue:
1547 OS << " xvalue";
1548 break;
1549 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001550 }
1551
Richard Trieud215b8d2013-01-26 01:31:20 +00001552 {
1553 ColorScope Color(*this, ObjectKindColor);
1554 switch (Node->getObjectKind()) {
1555 case OK_Ordinary:
1556 break;
1557 case OK_BitField:
1558 OS << " bitfield";
1559 break;
1560 case OK_ObjCProperty:
1561 OS << " objcproperty";
1562 break;
1563 case OK_ObjCSubscript:
1564 OS << " objcsubscript";
1565 break;
1566 case OK_VectorComponent:
1567 OS << " vectorcomponent";
1568 break;
1569 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001570 }
Chris Lattnercbe4f772007-08-08 22:51:59 +00001571}
1572
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001573static void dumpBasePath(raw_ostream &OS, const CastExpr *Node) {
John McCallcf142162010-08-07 06:22:56 +00001574 if (Node->path_empty())
Anders Carlssona70cff62010-04-24 19:06:50 +00001575 return;
1576
1577 OS << " (";
1578 bool First = true;
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001579 for (CastExpr::path_const_iterator I = Node->path_begin(),
1580 E = Node->path_end();
1581 I != E; ++I) {
Anders Carlssona70cff62010-04-24 19:06:50 +00001582 const CXXBaseSpecifier *Base = *I;
1583 if (!First)
1584 OS << " -> ";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001585
Anders Carlssona70cff62010-04-24 19:06:50 +00001586 const CXXRecordDecl *RD =
1587 cast<CXXRecordDecl>(Base->getType()->getAs<RecordType>()->getDecl());
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001588
Anders Carlssona70cff62010-04-24 19:06:50 +00001589 if (Base->isVirtual())
1590 OS << "virtual ";
1591 OS << RD->getName();
1592 First = false;
1593 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001594
Anders Carlssona70cff62010-04-24 19:06:50 +00001595 OS << ')';
1596}
1597
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001598void ASTDumper::VisitCastExpr(const CastExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001599 VisitExpr(Node);
Richard Trieud215b8d2013-01-26 01:31:20 +00001600 OS << " <";
1601 {
1602 ColorScope Color(*this, CastColor);
1603 OS << Node->getCastKindName();
1604 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001605 dumpBasePath(OS, Node);
Anders Carlssona70cff62010-04-24 19:06:50 +00001606 OS << ">";
Anders Carlssond7923c62009-08-22 23:33:40 +00001607}
1608
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001609void ASTDumper::VisitDeclRefExpr(const DeclRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001610 VisitExpr(Node);
Ted Kremenek5f64ca82007-09-10 17:32:55 +00001611
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001612 OS << " ";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001613 dumpBareDeclRef(Node->getDecl());
Chandler Carruth8d26bb02011-05-01 23:48:14 +00001614 if (Node->getDecl() != Node->getFoundDecl()) {
1615 OS << " (";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001616 dumpBareDeclRef(Node->getFoundDecl());
Chandler Carruth8d26bb02011-05-01 23:48:14 +00001617 OS << ")";
1618 }
John McCall351762c2011-02-07 10:33:21 +00001619}
1620
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001621void ASTDumper::VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001622 VisitExpr(Node);
John McCall76d09942009-12-11 21:50:11 +00001623 OS << " (";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001624 if (!Node->requiresADL())
1625 OS << "no ";
Benjamin Kramerb11416d2010-04-17 09:33:03 +00001626 OS << "ADL) = '" << Node->getName() << '\'';
John McCall76d09942009-12-11 21:50:11 +00001627
1628 UnresolvedLookupExpr::decls_iterator
1629 I = Node->decls_begin(), E = Node->decls_end();
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001630 if (I == E)
1631 OS << " empty";
John McCall76d09942009-12-11 21:50:11 +00001632 for (; I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001633 dumpPointer(*I);
John McCall76d09942009-12-11 21:50:11 +00001634}
1635
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001636void ASTDumper::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001637 VisitExpr(Node);
Steve Naroff5d5efca2008-03-12 13:19:12 +00001638
Richard Trieud215b8d2013-01-26 01:31:20 +00001639 {
1640 ColorScope Color(*this, DeclKindNameColor);
1641 OS << " " << Node->getDecl()->getDeclKindName() << "Decl";
1642 }
1643 OS << "='" << *Node->getDecl() << "'";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001644 dumpPointer(Node->getDecl());
Steve Naroffb3424a92008-05-23 22:01:24 +00001645 if (Node->isFreeIvar())
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001646 OS << " isFreeIvar";
Steve Naroff5d5efca2008-03-12 13:19:12 +00001647}
1648
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001649void ASTDumper::VisitPredefinedExpr(const PredefinedExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001650 VisitExpr(Node);
Chris Lattnercbe4f772007-08-08 22:51:59 +00001651 switch (Node->getIdentType()) {
David Blaikie83d382b2011-09-23 05:06:16 +00001652 default: llvm_unreachable("unknown case");
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001653 case PredefinedExpr::Func: OS << " __func__"; break;
1654 case PredefinedExpr::Function: OS << " __FUNCTION__"; break;
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001655 case PredefinedExpr::LFunction: OS << " L__FUNCTION__"; break;
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001656 case PredefinedExpr::PrettyFunction: OS << " __PRETTY_FUNCTION__";break;
Chris Lattnercbe4f772007-08-08 22:51:59 +00001657 }
1658}
1659
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001660void ASTDumper::VisitCharacterLiteral(const CharacterLiteral *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001661 VisitExpr(Node);
Richard Trieud215b8d2013-01-26 01:31:20 +00001662 ColorScope Color(*this, ValueColor);
Richard Trieu364ee422011-11-03 23:56:23 +00001663 OS << " " << Node->getValue();
Chris Lattnercbe4f772007-08-08 22:51:59 +00001664}
1665
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001666void ASTDumper::VisitIntegerLiteral(const IntegerLiteral *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001667 VisitExpr(Node);
Chris Lattnercbe4f772007-08-08 22:51:59 +00001668
1669 bool isSigned = Node->getType()->isSignedIntegerType();
Richard Trieud215b8d2013-01-26 01:31:20 +00001670 ColorScope Color(*this, ValueColor);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001671 OS << " " << Node->getValue().toString(10, isSigned);
Chris Lattnercbe4f772007-08-08 22:51:59 +00001672}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001673
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001674void ASTDumper::VisitFloatingLiteral(const FloatingLiteral *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001675 VisitExpr(Node);
Richard Trieud215b8d2013-01-26 01:31:20 +00001676 ColorScope Color(*this, ValueColor);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001677 OS << " " << Node->getValueAsApproximateDouble();
Chris Lattnercbe4f772007-08-08 22:51:59 +00001678}
Chris Lattner1c20a172007-08-26 03:42:43 +00001679
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001680void ASTDumper::VisitStringLiteral(const StringLiteral *Str) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001681 VisitExpr(Str);
Richard Trieud215b8d2013-01-26 01:31:20 +00001682 ColorScope Color(*this, ValueColor);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001683 OS << " ";
Richard Trieudc355912012-06-13 20:25:24 +00001684 Str->outputString(OS);
Chris Lattnercbe4f772007-08-08 22:51:59 +00001685}
Chris Lattner84ca3762007-08-30 01:00:35 +00001686
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001687void ASTDumper::VisitUnaryOperator(const UnaryOperator *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001688 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001689 OS << " " << (Node->isPostfix() ? "postfix" : "prefix")
1690 << " '" << UnaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
Chris Lattnercbe4f772007-08-08 22:51:59 +00001691}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001692
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001693void ASTDumper::VisitUnaryExprOrTypeTraitExpr(
1694 const UnaryExprOrTypeTraitExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001695 VisitExpr(Node);
Peter Collingbournee190dee2011-03-11 19:24:49 +00001696 switch(Node->getKind()) {
1697 case UETT_SizeOf:
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001698 OS << " sizeof";
Peter Collingbournee190dee2011-03-11 19:24:49 +00001699 break;
1700 case UETT_AlignOf:
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001701 OS << " alignof";
Peter Collingbournee190dee2011-03-11 19:24:49 +00001702 break;
1703 case UETT_VecStep:
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001704 OS << " vec_step";
Peter Collingbournee190dee2011-03-11 19:24:49 +00001705 break;
1706 }
Sebastian Redl6f282892008-11-11 17:56:53 +00001707 if (Node->isArgumentType())
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001708 dumpType(Node->getArgumentType());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001709}
Chris Lattnerdb3b3ff2007-08-09 17:35:30 +00001710
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001711void ASTDumper::VisitMemberExpr(const MemberExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001712 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001713 OS << " " << (Node->isArrow() ? "->" : ".") << *Node->getMemberDecl();
1714 dumpPointer(Node->getMemberDecl());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001715}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001716
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001717void ASTDumper::VisitExtVectorElementExpr(const ExtVectorElementExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001718 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001719 OS << " " << Node->getAccessor().getNameStart();
Chris Lattnercbe4f772007-08-08 22:51:59 +00001720}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001721
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001722void ASTDumper::VisitBinaryOperator(const BinaryOperator *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001723 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001724 OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
Chris Lattner86928112007-08-25 02:00:02 +00001725}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001726
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001727void ASTDumper::VisitCompoundAssignOperator(
1728 const CompoundAssignOperator *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001729 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001730 OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode())
1731 << "' ComputeLHSTy=";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001732 dumpBareType(Node->getComputationLHSType());
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001733 OS << " ComputeResultTy=";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001734 dumpBareType(Node->getComputationResultType());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001735}
Chris Lattnercbe4f772007-08-08 22:51:59 +00001736
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001737void ASTDumper::VisitBlockExpr(const BlockExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001738 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001739 dumpDecl(Node->getBlockDecl());
John McCall351762c2011-02-07 10:33:21 +00001740}
1741
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001742void ASTDumper::VisitOpaqueValueExpr(const OpaqueValueExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001743 VisitExpr(Node);
John McCallfe96e0b2011-11-06 09:01:30 +00001744
Richard Trieude5cc7d2013-01-31 01:44:26 +00001745 if (Expr *Source = Node->getSourceExpr()) {
1746 lastChild();
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001747 dumpStmt(Source);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001748 }
John McCallfe96e0b2011-11-06 09:01:30 +00001749}
1750
Chris Lattnercbe4f772007-08-08 22:51:59 +00001751// GNU extensions.
1752
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001753void ASTDumper::VisitAddrLabelExpr(const AddrLabelExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001754 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001755 OS << " " << Node->getLabel()->getName();
1756 dumpPointer(Node->getLabel());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001757}
1758
Chris Lattner8f184b12007-08-09 18:03:18 +00001759//===----------------------------------------------------------------------===//
1760// C++ Expressions
1761//===----------------------------------------------------------------------===//
Chris Lattnercbe4f772007-08-08 22:51:59 +00001762
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001763void ASTDumper::VisitCXXNamedCastExpr(const CXXNamedCastExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001764 VisitExpr(Node);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001765 OS << " " << Node->getCastName()
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001766 << "<" << Node->getTypeAsWritten().getAsString() << ">"
Anders Carlssona70cff62010-04-24 19:06:50 +00001767 << " <" << Node->getCastKindName();
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001768 dumpBasePath(OS, Node);
Anders Carlssona70cff62010-04-24 19:06:50 +00001769 OS << ">";
Chris Lattnercbe4f772007-08-08 22:51:59 +00001770}
1771
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001772void ASTDumper::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001773 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001774 OS << " " << (Node->getValue() ? "true" : "false");
Chris Lattnercbe4f772007-08-08 22:51:59 +00001775}
1776
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001777void ASTDumper::VisitCXXThisExpr(const CXXThisExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001778 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001779 OS << " this";
Douglas Gregor8ea1f532008-11-04 14:56:14 +00001780}
1781
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001782void ASTDumper::VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001783 VisitExpr(Node);
Eli Friedman29538892011-09-02 17:38:59 +00001784 OS << " functional cast to " << Node->getTypeAsWritten().getAsString()
1785 << " <" << Node->getCastKindName() << ">";
Douglas Gregore200adc2008-10-27 19:41:14 +00001786}
1787
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001788void ASTDumper::VisitCXXConstructExpr(const CXXConstructExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001789 VisitExpr(Node);
John McCalleba90cd2010-02-02 19:03:45 +00001790 CXXConstructorDecl *Ctor = Node->getConstructor();
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001791 dumpType(Ctor->getType());
Anders Carlsson073846832009-08-12 00:21:52 +00001792 if (Node->isElidable())
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001793 OS << " elidable";
John McCall85370042010-08-07 06:38:55 +00001794 if (Node->requiresZeroInitialization())
1795 OS << " zeroing";
Anders Carlsson073846832009-08-12 00:21:52 +00001796}
1797
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001798void ASTDumper::VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001799 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001800 OS << " ";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001801 dumpCXXTemporary(Node->getTemporary());
Anders Carlsson073846832009-08-12 00:21:52 +00001802}
1803
Richard Smithe6c01442013-06-05 00:46:14 +00001804void
1805ASTDumper::VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *Node) {
1806 VisitExpr(Node);
1807 if (const ValueDecl *VD = Node->getExtendingDecl()) {
1808 OS << " extended by ";
1809 dumpBareDeclRef(VD);
1810 }
1811}
1812
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001813void ASTDumper::VisitExprWithCleanups(const ExprWithCleanups *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001814 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001815 for (unsigned i = 0, e = Node->getNumObjects(); i != e; ++i)
1816 dumpDeclRef(Node->getObject(i), "cleanup");
Anders Carlsson073846832009-08-12 00:21:52 +00001817}
1818
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001819void ASTDumper::dumpCXXTemporary(const CXXTemporary *Temporary) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001820 OS << "(CXXTemporary";
1821 dumpPointer(Temporary);
1822 OS << ")";
Anders Carlsson073846832009-08-12 00:21:52 +00001823}
1824
Anders Carlsson76f4a902007-08-21 17:43:55 +00001825//===----------------------------------------------------------------------===//
1826// Obj-C Expressions
1827//===----------------------------------------------------------------------===//
1828
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001829void ASTDumper::VisitObjCMessageExpr(const ObjCMessageExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001830 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001831 OS << " selector=" << Node->getSelector().getAsString();
Douglas Gregor9a129192010-04-21 00:45:42 +00001832 switch (Node->getReceiverKind()) {
1833 case ObjCMessageExpr::Instance:
1834 break;
1835
1836 case ObjCMessageExpr::Class:
1837 OS << " class=";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001838 dumpBareType(Node->getClassReceiver());
Douglas Gregor9a129192010-04-21 00:45:42 +00001839 break;
1840
1841 case ObjCMessageExpr::SuperInstance:
1842 OS << " super (instance)";
1843 break;
1844
1845 case ObjCMessageExpr::SuperClass:
1846 OS << " super (class)";
1847 break;
1848 }
Ted Kremenek36748da2008-02-29 22:04:05 +00001849}
1850
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001851void ASTDumper::VisitObjCBoxedExpr(const ObjCBoxedExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001852 VisitExpr(Node);
Argyrios Kyrtzidis9dd40892012-05-10 20:02:31 +00001853 OS << " selector=" << Node->getBoxingMethod()->getSelector().getAsString();
1854}
1855
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001856void ASTDumper::VisitObjCAtCatchStmt(const ObjCAtCatchStmt *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001857 VisitStmt(Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001858 if (const VarDecl *CatchParam = Node->getCatchParamDecl())
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001859 dumpDecl(CatchParam);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001860 else
Douglas Gregor96c79492010-04-23 22:50:49 +00001861 OS << " catch all";
Douglas Gregor96c79492010-04-23 22:50:49 +00001862}
1863
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001864void ASTDumper::VisitObjCEncodeExpr(const ObjCEncodeExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001865 VisitExpr(Node);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001866 dumpType(Node->getEncodedType());
Anders Carlssonc5a81eb2007-08-22 15:14:15 +00001867}
1868
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001869void ASTDumper::VisitObjCSelectorExpr(const ObjCSelectorExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001870 VisitExpr(Node);
Mike Stump11289f42009-09-09 15:08:12 +00001871
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001872 OS << " " << Node->getSelector().getAsString();
Fariborz Jahanian4bef4622007-10-16 20:40:23 +00001873}
1874
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001875void ASTDumper::VisitObjCProtocolExpr(const ObjCProtocolExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001876 VisitExpr(Node);
Mike Stump11289f42009-09-09 15:08:12 +00001877
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001878 OS << ' ' << *Node->getProtocol();
Fariborz Jahaniana32aaef2007-10-17 16:58:11 +00001879}
Daniel Dunbar4b8c6db2008-08-30 05:35:15 +00001880
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001881void ASTDumper::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001882 VisitExpr(Node);
John McCallb7bd14f2010-12-02 01:19:52 +00001883 if (Node->isImplicitProperty()) {
Fariborz Jahanian0f0b3022010-12-22 19:46:35 +00001884 OS << " Kind=MethodRef Getter=\"";
1885 if (Node->getImplicitPropertyGetter())
1886 OS << Node->getImplicitPropertyGetter()->getSelector().getAsString();
1887 else
1888 OS << "(null)";
1889
1890 OS << "\" Setter=\"";
John McCallb7bd14f2010-12-02 01:19:52 +00001891 if (ObjCMethodDecl *Setter = Node->getImplicitPropertySetter())
1892 OS << Setter->getSelector().getAsString();
1893 else
1894 OS << "(null)";
1895 OS << "\"";
1896 } else {
Benjamin Kramerb89514a2011-10-14 18:45:37 +00001897 OS << " Kind=PropertyRef Property=\"" << *Node->getExplicitProperty() <<'"';
John McCallb7bd14f2010-12-02 01:19:52 +00001898 }
Fariborz Jahanian8a1810f2008-11-22 18:39:36 +00001899
Fariborz Jahanian681c0752010-10-14 16:04:05 +00001900 if (Node->isSuperReceiver())
1901 OS << " super";
Argyrios Kyrtzidisab468b02012-03-30 00:19:18 +00001902
1903 OS << " Messaging=";
1904 if (Node->isMessagingGetter() && Node->isMessagingSetter())
1905 OS << "Getter&Setter";
1906 else if (Node->isMessagingGetter())
1907 OS << "Getter";
1908 else if (Node->isMessagingSetter())
1909 OS << "Setter";
Douglas Gregor8ea1f532008-11-04 14:56:14 +00001910}
1911
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001912void ASTDumper::VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001913 VisitExpr(Node);
Ted Kremeneke65b0862012-03-06 20:05:56 +00001914 if (Node->isArraySubscriptRefExpr())
1915 OS << " Kind=ArraySubscript GetterForArray=\"";
1916 else
1917 OS << " Kind=DictionarySubscript GetterForDictionary=\"";
1918 if (Node->getAtIndexMethodDecl())
1919 OS << Node->getAtIndexMethodDecl()->getSelector().getAsString();
1920 else
1921 OS << "(null)";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001922
Ted Kremeneke65b0862012-03-06 20:05:56 +00001923 if (Node->isArraySubscriptRefExpr())
1924 OS << "\" SetterForArray=\"";
1925 else
1926 OS << "\" SetterForDictionary=\"";
1927 if (Node->setAtIndexMethodDecl())
1928 OS << Node->setAtIndexMethodDecl()->getSelector().getAsString();
1929 else
1930 OS << "(null)";
1931}
1932
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001933void ASTDumper::VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001934 VisitExpr(Node);
Ted Kremeneke65b0862012-03-06 20:05:56 +00001935 OS << " " << (Node->getValue() ? "__objc_yes" : "__objc_no");
1936}
1937
Chris Lattnercbe4f772007-08-08 22:51:59 +00001938//===----------------------------------------------------------------------===//
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00001939// Comments
1940//===----------------------------------------------------------------------===//
1941
1942const char *ASTDumper::getCommandName(unsigned CommandID) {
1943 if (Traits)
1944 return Traits->getCommandInfo(CommandID)->Name;
1945 const CommandInfo *Info = CommandTraits::getBuiltinCommandInfo(CommandID);
1946 if (Info)
1947 return Info->Name;
1948 return "<not a builtin command>";
1949}
1950
1951void ASTDumper::dumpFullComment(const FullComment *C) {
1952 if (!C)
1953 return;
1954
1955 FC = C;
1956 dumpComment(C);
1957 FC = 0;
1958}
1959
1960void ASTDumper::dumpComment(const Comment *C) {
1961 IndentScope Indent(*this);
1962
1963 if (!C) {
Richard Trieud215b8d2013-01-26 01:31:20 +00001964 ColorScope Color(*this, NullColor);
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00001965 OS << "<<<NULL>>>";
1966 return;
1967 }
1968
Richard Trieud215b8d2013-01-26 01:31:20 +00001969 {
1970 ColorScope Color(*this, CommentColor);
1971 OS << C->getCommentKindName();
1972 }
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00001973 dumpPointer(C);
1974 dumpSourceRange(C->getSourceRange());
1975 ConstCommentVisitor<ASTDumper>::visit(C);
1976 for (Comment::child_iterator I = C->child_begin(), E = C->child_end();
Richard Trieude5cc7d2013-01-31 01:44:26 +00001977 I != E; ++I) {
1978 if (I + 1 == E)
1979 lastChild();
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00001980 dumpComment(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001981 }
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00001982}
1983
1984void ASTDumper::visitTextComment(const TextComment *C) {
1985 OS << " Text=\"" << C->getText() << "\"";
1986}
1987
1988void ASTDumper::visitInlineCommandComment(const InlineCommandComment *C) {
1989 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\"";
1990 switch (C->getRenderKind()) {
1991 case InlineCommandComment::RenderNormal:
1992 OS << " RenderNormal";
1993 break;
1994 case InlineCommandComment::RenderBold:
1995 OS << " RenderBold";
1996 break;
1997 case InlineCommandComment::RenderMonospaced:
1998 OS << " RenderMonospaced";
1999 break;
2000 case InlineCommandComment::RenderEmphasized:
2001 OS << " RenderEmphasized";
2002 break;
2003 }
2004
2005 for (unsigned i = 0, e = C->getNumArgs(); i != e; ++i)
2006 OS << " Arg[" << i << "]=\"" << C->getArgText(i) << "\"";
2007}
2008
2009void ASTDumper::visitHTMLStartTagComment(const HTMLStartTagComment *C) {
2010 OS << " Name=\"" << C->getTagName() << "\"";
2011 if (C->getNumAttrs() != 0) {
2012 OS << " Attrs: ";
2013 for (unsigned i = 0, e = C->getNumAttrs(); i != e; ++i) {
2014 const HTMLStartTagComment::Attribute &Attr = C->getAttr(i);
2015 OS << " \"" << Attr.Name << "=\"" << Attr.Value << "\"";
2016 }
2017 }
2018 if (C->isSelfClosing())
2019 OS << " SelfClosing";
2020}
2021
2022void ASTDumper::visitHTMLEndTagComment(const HTMLEndTagComment *C) {
2023 OS << " Name=\"" << C->getTagName() << "\"";
2024}
2025
2026void ASTDumper::visitBlockCommandComment(const BlockCommandComment *C) {
2027 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\"";
2028 for (unsigned i = 0, e = C->getNumArgs(); i != e; ++i)
2029 OS << " Arg[" << i << "]=\"" << C->getArgText(i) << "\"";
2030}
2031
2032void ASTDumper::visitParamCommandComment(const ParamCommandComment *C) {
2033 OS << " " << ParamCommandComment::getDirectionAsString(C->getDirection());
2034
2035 if (C->isDirectionExplicit())
2036 OS << " explicitly";
2037 else
2038 OS << " implicitly";
2039
2040 if (C->hasParamName()) {
2041 if (C->isParamIndexValid())
2042 OS << " Param=\"" << C->getParamName(FC) << "\"";
2043 else
2044 OS << " Param=\"" << C->getParamNameAsWritten() << "\"";
2045 }
2046
2047 if (C->isParamIndexValid())
2048 OS << " ParamIndex=" << C->getParamIndex();
2049}
2050
2051void ASTDumper::visitTParamCommandComment(const TParamCommandComment *C) {
2052 if (C->hasParamName()) {
2053 if (C->isPositionValid())
2054 OS << " Param=\"" << C->getParamName(FC) << "\"";
2055 else
2056 OS << " Param=\"" << C->getParamNameAsWritten() << "\"";
2057 }
2058
2059 if (C->isPositionValid()) {
2060 OS << " Position=<";
2061 for (unsigned i = 0, e = C->getDepth(); i != e; ++i) {
2062 OS << C->getIndex(i);
2063 if (i != e - 1)
2064 OS << ", ";
2065 }
2066 OS << ">";
2067 }
2068}
2069
2070void ASTDumper::visitVerbatimBlockComment(const VerbatimBlockComment *C) {
2071 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\""
2072 " CloseName=\"" << C->getCloseName() << "\"";
2073}
2074
2075void ASTDumper::visitVerbatimBlockLineComment(
2076 const VerbatimBlockLineComment *C) {
2077 OS << " Text=\"" << C->getText() << "\"";
2078}
2079
2080void ASTDumper::visitVerbatimLineComment(const VerbatimLineComment *C) {
2081 OS << " Text=\"" << C->getText() << "\"";
2082}
2083
2084//===----------------------------------------------------------------------===//
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002085// Decl method implementations
2086//===----------------------------------------------------------------------===//
2087
2088void Decl::dump() const {
2089 dump(llvm::errs());
2090}
2091
2092void Decl::dump(raw_ostream &OS) const {
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002093 ASTDumper P(OS, &getASTContext().getCommentCommandTraits(),
2094 &getASTContext().getSourceManager());
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002095 P.dumpDecl(this);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002096}
2097
Richard Trieud215b8d2013-01-26 01:31:20 +00002098void Decl::dumpColor() const {
2099 ASTDumper P(llvm::errs(), &getASTContext().getCommentCommandTraits(),
2100 &getASTContext().getSourceManager(), /*ShowColors*/true);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002101 P.dumpDecl(this);
Richard Trieud215b8d2013-01-26 01:31:20 +00002102}
Richard Smith33937e72013-06-22 21:49:40 +00002103
2104void DeclContext::dumpLookups() const {
Richard Smith6ea05822013-06-24 01:45:33 +00002105 dumpLookups(llvm::errs());
2106}
2107
2108void DeclContext::dumpLookups(raw_ostream &OS) const {
Richard Smith33937e72013-06-22 21:49:40 +00002109 const DeclContext *DC = this;
2110 while (!DC->isTranslationUnit())
2111 DC = DC->getParent();
2112 ASTContext &Ctx = cast<TranslationUnitDecl>(DC)->getASTContext();
Richard Smith6ea05822013-06-24 01:45:33 +00002113 ASTDumper P(OS, &Ctx.getCommentCommandTraits(), &Ctx.getSourceManager());
Richard Smith33937e72013-06-22 21:49:40 +00002114 P.dumpLookups(this);
2115}
2116
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002117//===----------------------------------------------------------------------===//
Chris Lattnercbe4f772007-08-08 22:51:59 +00002118// Stmt method implementations
2119//===----------------------------------------------------------------------===//
2120
Chris Lattner11e30d32007-08-30 06:17:34 +00002121void Stmt::dump(SourceManager &SM) const {
Argyrios Kyrtzidisc049f752010-08-09 10:54:31 +00002122 dump(llvm::errs(), SM);
2123}
2124
Chris Lattner0e62c1c2011-07-23 10:55:15 +00002125void Stmt::dump(raw_ostream &OS, SourceManager &SM) const {
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002126 ASTDumper P(OS, 0, &SM);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002127 P.dumpStmt(this);
Chris Lattner779d5d92007-08-30 00:40:08 +00002128}
2129
Chris Lattnercbe4f772007-08-08 22:51:59 +00002130void Stmt::dump() const {
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002131 ASTDumper P(llvm::errs(), 0, 0);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002132 P.dumpStmt(this);
Chris Lattnercbe4f772007-08-08 22:51:59 +00002133}
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002134
Richard Trieud215b8d2013-01-26 01:31:20 +00002135void Stmt::dumpColor() const {
2136 ASTDumper P(llvm::errs(), 0, 0, /*ShowColors*/true);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002137 P.dumpStmt(this);
Richard Trieud215b8d2013-01-26 01:31:20 +00002138}
2139
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002140//===----------------------------------------------------------------------===//
2141// Comment method implementations
2142//===----------------------------------------------------------------------===//
2143
2144void Comment::dump() const {
2145 dump(llvm::errs(), 0, 0);
2146}
2147
2148void Comment::dump(const ASTContext &Context) const {
2149 dump(llvm::errs(), &Context.getCommentCommandTraits(),
2150 &Context.getSourceManager());
2151}
2152
Alexander Kornienko00911f12013-01-15 12:20:21 +00002153void Comment::dump(raw_ostream &OS, const CommandTraits *Traits,
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002154 const SourceManager *SM) const {
2155 const FullComment *FC = dyn_cast<FullComment>(this);
2156 ASTDumper D(OS, Traits, SM);
2157 D.dumpFullComment(FC);
2158}
Richard Trieud215b8d2013-01-26 01:31:20 +00002159
2160void Comment::dumpColor() const {
2161 const FullComment *FC = dyn_cast<FullComment>(this);
2162 ASTDumper D(llvm::errs(), 0, 0, /*ShowColors*/true);
2163 D.dumpFullComment(FC);
2164}