blob: ac35a2e43c21c5424c8b08b3ec627f6bf2982044 [file] [log] [blame]
Alexander Kornienko18ec81b2012-12-13 13:59:55 +00001//===--- ASTDumper.cpp - Dumping implementation for ASTs ------------------===//
Chris Lattnercbe4f772007-08-08 22:51:59 +00002//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner5b12ab82007-12-29 19:59:25 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattnercbe4f772007-08-08 22:51:59 +00007//
8//===----------------------------------------------------------------------===//
9//
Alexander Kornienko18ec81b2012-12-13 13:59:55 +000010// This file implements the AST dump methods, which dump out the
Chris Lattnercbe4f772007-08-08 22:51:59 +000011// AST in a form that exposes type details and other fields.
12//
13//===----------------------------------------------------------------------===//
14
Chandler Carruth3a022472012-12-04 09:13:33 +000015#include "clang/AST/ASTContext.h"
Alexander Kornienko5bc364e2013-01-07 17:53:08 +000016#include "clang/AST/Attr.h"
Alexander Kornienkoebc17b52013-01-14 14:07:11 +000017#include "clang/AST/CommentVisitor.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000018#include "clang/AST/DeclCXX.h"
Richard Smith33937e72013-06-22 21:49:40 +000019#include "clang/AST/DeclLookups.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000020#include "clang/AST/DeclObjC.h"
Alexander Kornienko90ff6072012-12-20 02:09:13 +000021#include "clang/AST/DeclVisitor.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000022#include "clang/AST/StmtVisitor.h"
Alexander Kornienko90ff6072012-12-20 02:09:13 +000023#include "clang/Basic/Module.h"
Chris Lattner11e30d32007-08-30 06:17:34 +000024#include "clang/Basic/SourceManager.h"
Daniel Dunbar34a96c82009-12-03 09:13:13 +000025#include "llvm/Support/raw_ostream.h"
Chris Lattnercbe4f772007-08-08 22:51:59 +000026using namespace clang;
Alexander Kornienkoebc17b52013-01-14 14:07:11 +000027using namespace clang::comments;
Chris Lattnercbe4f772007-08-08 22:51:59 +000028
29//===----------------------------------------------------------------------===//
Alexander Kornienko18ec81b2012-12-13 13:59:55 +000030// ASTDumper Visitor
Chris Lattnercbe4f772007-08-08 22:51:59 +000031//===----------------------------------------------------------------------===//
32
33namespace {
Richard Trieud215b8d2013-01-26 01:31:20 +000034 // Colors used for various parts of the AST dump
Richard Trieu532018f2014-03-06 01:09:03 +000035 // Do not use bold yellow for any text. It is hard to read on white screens.
Richard Trieud215b8d2013-01-26 01:31:20 +000036
37 struct TerminalColor {
38 raw_ostream::Colors Color;
39 bool Bold;
40 };
41
Richard Trieu532018f2014-03-06 01:09:03 +000042 // Red - CastColor
43 // Green - TypeColor
44 // Bold Green - DeclKindNameColor, UndeserializedColor
45 // Yellow - AddressColor, LocationColor
46 // Blue - CommentColor, NullColor, IndentColor
47 // Bold Blue - AttrColor
48 // Bold Magenta - StmtColor
49 // Cyan - ValueKindColor, ObjectKindColor
50 // Bold Cyan - ValueColor, DeclNameColor
51
Richard Trieud215b8d2013-01-26 01:31:20 +000052 // Decl kind names (VarDecl, FunctionDecl, etc)
53 static const TerminalColor DeclKindNameColor = { raw_ostream::GREEN, true };
54 // Attr names (CleanupAttr, GuardedByAttr, etc)
55 static const TerminalColor AttrColor = { raw_ostream::BLUE, true };
56 // Statement names (DeclStmt, ImplicitCastExpr, etc)
57 static const TerminalColor StmtColor = { raw_ostream::MAGENTA, true };
58 // Comment names (FullComment, ParagraphComment, TextComment, etc)
Richard Trieu532018f2014-03-06 01:09:03 +000059 static const TerminalColor CommentColor = { raw_ostream::BLUE, false };
Richard Trieud215b8d2013-01-26 01:31:20 +000060
61 // Type names (int, float, etc, plus user defined types)
62 static const TerminalColor TypeColor = { raw_ostream::GREEN, false };
63
64 // Pointer address
65 static const TerminalColor AddressColor = { raw_ostream::YELLOW, false };
66 // Source locations
67 static const TerminalColor LocationColor = { raw_ostream::YELLOW, false };
68
69 // lvalue/xvalue
70 static const TerminalColor ValueKindColor = { raw_ostream::CYAN, false };
71 // bitfield/objcproperty/objcsubscript/vectorcomponent
72 static const TerminalColor ObjectKindColor = { raw_ostream::CYAN, false };
73
74 // Null statements
75 static const TerminalColor NullColor = { raw_ostream::BLUE, false };
76
Richard Smith1d209d02013-05-23 01:49:11 +000077 // Undeserialized entities
78 static const TerminalColor UndeserializedColor = { raw_ostream::GREEN, true };
79
Richard Trieud215b8d2013-01-26 01:31:20 +000080 // CastKind from CastExpr's
81 static const TerminalColor CastColor = { raw_ostream::RED, false };
82
83 // Value of the statement
84 static const TerminalColor ValueColor = { raw_ostream::CYAN, true };
85 // Decl names
86 static const TerminalColor DeclNameColor = { raw_ostream::CYAN, true };
87
Richard Trieude5cc7d2013-01-31 01:44:26 +000088 // Indents ( `, -. | )
89 static const TerminalColor IndentColor = { raw_ostream::BLUE, false };
90
Alexander Kornienko90ff6072012-12-20 02:09:13 +000091 class ASTDumper
Alexander Kornienko540bacb2013-02-01 12:35:51 +000092 : public ConstDeclVisitor<ASTDumper>, public ConstStmtVisitor<ASTDumper>,
Alexander Kornienkoebc17b52013-01-14 14:07:11 +000093 public ConstCommentVisitor<ASTDumper> {
Chris Lattner0e62c1c2011-07-23 10:55:15 +000094 raw_ostream &OS;
Alexander Kornienkoebc17b52013-01-14 14:07:11 +000095 const CommandTraits *Traits;
96 const SourceManager *SM;
Manuel Klimek874030e2012-11-07 00:33:12 +000097 bool IsFirstLine;
Mike Stump11289f42009-09-09 15:08:12 +000098
Richard Trieude5cc7d2013-01-31 01:44:26 +000099 // Indicates whether more child are expected at the current tree depth
100 enum IndentType { IT_Child, IT_LastChild };
101
102 /// Indents[i] indicates if another child exists at level i.
103 /// Used by Indent() to print the tree structure.
104 llvm::SmallVector<IndentType, 32> Indents;
105
106 /// Indicates that more children will be needed at this indent level.
107 /// If true, prevents lastChild() from marking the node as the last child.
108 /// This is used when there are multiple collections of children to be
109 /// dumped as well as during conditional node dumping.
110 bool MoreChildren;
111
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000112 /// Keep track of the last location we print out so that we can
113 /// print out deltas from then on out.
Chris Lattner11e30d32007-08-30 06:17:34 +0000114 const char *LastLocFilename;
115 unsigned LastLocLine;
Douglas Gregor7de59662009-05-29 20:38:28 +0000116
Alexander Kornienkoebc17b52013-01-14 14:07:11 +0000117 /// The \c FullComment parent of the comment being dumped.
118 const FullComment *FC;
119
Richard Trieud215b8d2013-01-26 01:31:20 +0000120 bool ShowColors;
121
Manuel Klimek874030e2012-11-07 00:33:12 +0000122 class IndentScope {
Alexander Kornienko18ec81b2012-12-13 13:59:55 +0000123 ASTDumper &Dumper;
Richard Trieude5cc7d2013-01-31 01:44:26 +0000124 // Preserve the Dumper's MoreChildren value from the previous IndentScope
125 bool MoreChildren;
Manuel Klimek874030e2012-11-07 00:33:12 +0000126 public:
Alexander Kornienko18ec81b2012-12-13 13:59:55 +0000127 IndentScope(ASTDumper &Dumper) : Dumper(Dumper) {
Richard Trieude5cc7d2013-01-31 01:44:26 +0000128 MoreChildren = Dumper.hasMoreChildren();
129 Dumper.setMoreChildren(false);
Manuel Klimek874030e2012-11-07 00:33:12 +0000130 Dumper.indent();
131 }
132 ~IndentScope() {
Richard Trieude5cc7d2013-01-31 01:44:26 +0000133 Dumper.setMoreChildren(MoreChildren);
Manuel Klimek874030e2012-11-07 00:33:12 +0000134 Dumper.unindent();
135 }
136 };
137
Richard Trieud215b8d2013-01-26 01:31:20 +0000138 class ColorScope {
139 ASTDumper &Dumper;
140 public:
141 ColorScope(ASTDumper &Dumper, TerminalColor Color)
142 : Dumper(Dumper) {
143 if (Dumper.ShowColors)
144 Dumper.OS.changeColor(Color.Color, Color.Bold);
145 }
146 ~ColorScope() {
147 if (Dumper.ShowColors)
148 Dumper.OS.resetColor();
149 }
150 };
151
Richard Smithdcc2c452014-03-17 23:00:06 +0000152 class ChildDumper {
153 ASTDumper &Dumper;
154
155 const Decl *Prev;
156 bool PrevRef;
157 public:
158 ChildDumper(ASTDumper &Dumper) : Dumper(Dumper), Prev(0) {}
159 ~ChildDumper() {
160 if (Prev) {
161 Dumper.lastChild();
162 dump(0);
163 }
164 }
165
166 // FIXME: This should take an arbitrary callable as the dumping action.
167 void dump(const Decl *D, bool Ref = false) {
168 if (Prev) {
169 if (PrevRef)
170 Dumper.dumpDeclRef(Prev);
171 else
172 Dumper.dumpDecl(Prev);
173 }
174 Prev = D;
175 PrevRef = Ref;
176 }
177 void dumpRef(const Decl *D) { dump(D, true); }
178
179 // Give up ownership of the children of the node. By calling this,
180 // the caller takes back responsibility for calling lastChild().
181 void release() { dump(0); }
182 };
183
Chris Lattnercbe4f772007-08-08 22:51:59 +0000184 public:
Alexander Kornienkoebc17b52013-01-14 14:07:11 +0000185 ASTDumper(raw_ostream &OS, const CommandTraits *Traits,
186 const SourceManager *SM)
Richard Smith56d12152013-01-31 02:04:38 +0000187 : OS(OS), Traits(Traits), SM(SM), IsFirstLine(true), MoreChildren(false),
188 LastLocFilename(""), LastLocLine(~0U), FC(0),
Richard Trieud215b8d2013-01-26 01:31:20 +0000189 ShowColors(SM && SM->getDiagnostics().getShowColors()) { }
190
191 ASTDumper(raw_ostream &OS, const CommandTraits *Traits,
192 const SourceManager *SM, bool ShowColors)
Richard Smith56d12152013-01-31 02:04:38 +0000193 : OS(OS), Traits(Traits), SM(SM), IsFirstLine(true), MoreChildren(false),
194 LastLocFilename(""), LastLocLine(~0U),
Richard Trieude5cc7d2013-01-31 01:44:26 +0000195 ShowColors(ShowColors) { }
Mike Stump11289f42009-09-09 15:08:12 +0000196
Alexander Kornienko18ec81b2012-12-13 13:59:55 +0000197 ~ASTDumper() {
Manuel Klimek874030e2012-11-07 00:33:12 +0000198 OS << "\n";
199 }
200
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000201 void dumpDecl(const Decl *D);
202 void dumpStmt(const Stmt *S);
Alexander Kornienkoebc17b52013-01-14 14:07:11 +0000203 void dumpFullComment(const FullComment *C);
Mike Stump11289f42009-09-09 15:08:12 +0000204
Richard Trieude5cc7d2013-01-31 01:44:26 +0000205 // Formatting
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000206 void indent();
207 void unindent();
Richard Trieude5cc7d2013-01-31 01:44:26 +0000208 void lastChild();
209 bool hasMoreChildren();
210 void setMoreChildren(bool Value);
211
212 // Utilities
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000213 void dumpPointer(const void *Ptr);
214 void dumpSourceRange(SourceRange R);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000215 void dumpLocation(SourceLocation Loc);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000216 void dumpBareType(QualType T);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000217 void dumpType(QualType T);
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000218 void dumpBareDeclRef(const Decl *Node);
Alexander Kornienko9bdeb112012-12-20 12:23:54 +0000219 void dumpDeclRef(const Decl *Node, const char *Label = 0);
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000220 void dumpName(const NamedDecl *D);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000221 bool hasNodes(const DeclContext *DC);
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000222 void dumpDeclContext(const DeclContext *DC);
Richard Smith33937e72013-06-22 21:49:40 +0000223 void dumpLookups(const DeclContext *DC);
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000224 void dumpAttr(const Attr *A);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000225
226 // C++ Utilities
227 void dumpAccessSpecifier(AccessSpecifier AS);
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000228 void dumpCXXCtorInitializer(const CXXCtorInitializer *Init);
229 void dumpTemplateParameters(const TemplateParameterList *TPL);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000230 void dumpTemplateArgumentListInfo(const TemplateArgumentListInfo &TALI);
231 void dumpTemplateArgumentLoc(const TemplateArgumentLoc &A);
232 void dumpTemplateArgumentList(const TemplateArgumentList &TAL);
233 void dumpTemplateArgument(const TemplateArgument &A,
234 SourceRange R = SourceRange());
235
236 // Decls
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000237 void VisitLabelDecl(const LabelDecl *D);
238 void VisitTypedefDecl(const TypedefDecl *D);
239 void VisitEnumDecl(const EnumDecl *D);
240 void VisitRecordDecl(const RecordDecl *D);
241 void VisitEnumConstantDecl(const EnumConstantDecl *D);
242 void VisitIndirectFieldDecl(const IndirectFieldDecl *D);
243 void VisitFunctionDecl(const FunctionDecl *D);
244 void VisitFieldDecl(const FieldDecl *D);
245 void VisitVarDecl(const VarDecl *D);
246 void VisitFileScopeAsmDecl(const FileScopeAsmDecl *D);
247 void VisitImportDecl(const ImportDecl *D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000248
249 // C++ Decls
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000250 void VisitNamespaceDecl(const NamespaceDecl *D);
251 void VisitUsingDirectiveDecl(const UsingDirectiveDecl *D);
252 void VisitNamespaceAliasDecl(const NamespaceAliasDecl *D);
253 void VisitTypeAliasDecl(const TypeAliasDecl *D);
254 void VisitTypeAliasTemplateDecl(const TypeAliasTemplateDecl *D);
255 void VisitCXXRecordDecl(const CXXRecordDecl *D);
256 void VisitStaticAssertDecl(const StaticAssertDecl *D);
Richard Smithcbdf7332014-03-18 02:07:28 +0000257 template<typename SpecializationDecl>
258 void VisitTemplateDeclSpecialization(ChildDumper &Children,
259 const SpecializationDecl *D,
260 bool DumpExplicitInst,
261 bool DumpRefOnly);
Richard Smith20ade552014-03-17 23:34:53 +0000262 template<typename TemplateDecl>
263 void VisitTemplateDecl(const TemplateDecl *D, bool DumpExplicitInst);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000264 void VisitFunctionTemplateDecl(const FunctionTemplateDecl *D);
265 void VisitClassTemplateDecl(const ClassTemplateDecl *D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000266 void VisitClassTemplateSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000267 const ClassTemplateSpecializationDecl *D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000268 void VisitClassTemplatePartialSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000269 const ClassTemplatePartialSpecializationDecl *D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000270 void VisitClassScopeFunctionSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000271 const ClassScopeFunctionSpecializationDecl *D);
Richard Smithd25789a2013-09-18 01:36:02 +0000272 void VisitVarTemplateDecl(const VarTemplateDecl *D);
273 void VisitVarTemplateSpecializationDecl(
274 const VarTemplateSpecializationDecl *D);
275 void VisitVarTemplatePartialSpecializationDecl(
276 const VarTemplatePartialSpecializationDecl *D);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000277 void VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D);
278 void VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D);
279 void VisitTemplateTemplateParmDecl(const TemplateTemplateParmDecl *D);
280 void VisitUsingDecl(const UsingDecl *D);
281 void VisitUnresolvedUsingTypenameDecl(const UnresolvedUsingTypenameDecl *D);
282 void VisitUnresolvedUsingValueDecl(const UnresolvedUsingValueDecl *D);
283 void VisitUsingShadowDecl(const UsingShadowDecl *D);
284 void VisitLinkageSpecDecl(const LinkageSpecDecl *D);
285 void VisitAccessSpecDecl(const AccessSpecDecl *D);
286 void VisitFriendDecl(const FriendDecl *D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000287
288 // ObjC Decls
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000289 void VisitObjCIvarDecl(const ObjCIvarDecl *D);
290 void VisitObjCMethodDecl(const ObjCMethodDecl *D);
291 void VisitObjCCategoryDecl(const ObjCCategoryDecl *D);
292 void VisitObjCCategoryImplDecl(const ObjCCategoryImplDecl *D);
293 void VisitObjCProtocolDecl(const ObjCProtocolDecl *D);
294 void VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D);
295 void VisitObjCImplementationDecl(const ObjCImplementationDecl *D);
296 void VisitObjCCompatibleAliasDecl(const ObjCCompatibleAliasDecl *D);
297 void VisitObjCPropertyDecl(const ObjCPropertyDecl *D);
298 void VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D);
299 void VisitBlockDecl(const BlockDecl *D);
Mike Stump11289f42009-09-09 15:08:12 +0000300
Chris Lattner84ca3762007-08-30 01:00:35 +0000301 // Stmts.
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000302 void VisitStmt(const Stmt *Node);
303 void VisitDeclStmt(const DeclStmt *Node);
304 void VisitAttributedStmt(const AttributedStmt *Node);
305 void VisitLabelStmt(const LabelStmt *Node);
306 void VisitGotoStmt(const GotoStmt *Node);
Pavel Labath1ef83422013-09-04 14:35:00 +0000307 void VisitCXXCatchStmt(const CXXCatchStmt *Node);
Mike Stump11289f42009-09-09 15:08:12 +0000308
Chris Lattner84ca3762007-08-30 01:00:35 +0000309 // Exprs
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000310 void VisitExpr(const Expr *Node);
311 void VisitCastExpr(const CastExpr *Node);
312 void VisitDeclRefExpr(const DeclRefExpr *Node);
313 void VisitPredefinedExpr(const PredefinedExpr *Node);
314 void VisitCharacterLiteral(const CharacterLiteral *Node);
315 void VisitIntegerLiteral(const IntegerLiteral *Node);
316 void VisitFloatingLiteral(const FloatingLiteral *Node);
317 void VisitStringLiteral(const StringLiteral *Str);
318 void VisitUnaryOperator(const UnaryOperator *Node);
319 void VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *Node);
320 void VisitMemberExpr(const MemberExpr *Node);
321 void VisitExtVectorElementExpr(const ExtVectorElementExpr *Node);
322 void VisitBinaryOperator(const BinaryOperator *Node);
323 void VisitCompoundAssignOperator(const CompoundAssignOperator *Node);
324 void VisitAddrLabelExpr(const AddrLabelExpr *Node);
325 void VisitBlockExpr(const BlockExpr *Node);
326 void VisitOpaqueValueExpr(const OpaqueValueExpr *Node);
Chris Lattner84ca3762007-08-30 01:00:35 +0000327
328 // C++
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000329 void VisitCXXNamedCastExpr(const CXXNamedCastExpr *Node);
330 void VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *Node);
331 void VisitCXXThisExpr(const CXXThisExpr *Node);
332 void VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *Node);
333 void VisitCXXConstructExpr(const CXXConstructExpr *Node);
334 void VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *Node);
Richard Smithe6c01442013-06-05 00:46:14 +0000335 void VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000336 void VisitExprWithCleanups(const ExprWithCleanups *Node);
337 void VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *Node);
338 void dumpCXXTemporary(const CXXTemporary *Temporary);
Faisal Vali2b391ab2013-09-26 19:54:12 +0000339 void VisitLambdaExpr(const LambdaExpr *Node) {
340 VisitExpr(Node);
341 dumpDecl(Node->getLambdaClass());
342 }
Mike Stump11289f42009-09-09 15:08:12 +0000343
Chris Lattner84ca3762007-08-30 01:00:35 +0000344 // ObjC
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000345 void VisitObjCAtCatchStmt(const ObjCAtCatchStmt *Node);
346 void VisitObjCEncodeExpr(const ObjCEncodeExpr *Node);
347 void VisitObjCMessageExpr(const ObjCMessageExpr *Node);
348 void VisitObjCBoxedExpr(const ObjCBoxedExpr *Node);
349 void VisitObjCSelectorExpr(const ObjCSelectorExpr *Node);
350 void VisitObjCProtocolExpr(const ObjCProtocolExpr *Node);
351 void VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *Node);
352 void VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *Node);
353 void VisitObjCIvarRefExpr(const ObjCIvarRefExpr *Node);
354 void VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *Node);
Alexander Kornienkoebc17b52013-01-14 14:07:11 +0000355
356 // Comments.
357 const char *getCommandName(unsigned CommandID);
358 void dumpComment(const Comment *C);
359
360 // Inline comments.
361 void visitTextComment(const TextComment *C);
362 void visitInlineCommandComment(const InlineCommandComment *C);
363 void visitHTMLStartTagComment(const HTMLStartTagComment *C);
364 void visitHTMLEndTagComment(const HTMLEndTagComment *C);
365
366 // Block comments.
367 void visitBlockCommandComment(const BlockCommandComment *C);
368 void visitParamCommandComment(const ParamCommandComment *C);
369 void visitTParamCommandComment(const TParamCommandComment *C);
370 void visitVerbatimBlockComment(const VerbatimBlockComment *C);
371 void visitVerbatimBlockLineComment(const VerbatimBlockLineComment *C);
372 void visitVerbatimLineComment(const VerbatimLineComment *C);
Chris Lattnercbe4f772007-08-08 22:51:59 +0000373 };
374}
375
376//===----------------------------------------------------------------------===//
Chris Lattner11e30d32007-08-30 06:17:34 +0000377// Utilities
378//===----------------------------------------------------------------------===//
379
Richard Trieude5cc7d2013-01-31 01:44:26 +0000380// Print out the appropriate tree structure using the Indents vector.
381// Example of tree and the Indents vector at each level.
382// A { }
383// |-B { IT_Child }
384// | `-C { IT_Child, IT_LastChild }
385// `-D { IT_LastChild }
386// |-E { IT_LastChild, IT_Child }
387// `-F { IT_LastChild, IT_LastChild }
388// Type non-last element, last element
389// IT_Child "| " "|-"
390// IT_LastChild " " "`-"
Alexander Kornienko18ec81b2012-12-13 13:59:55 +0000391void ASTDumper::indent() {
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000392 if (IsFirstLine)
393 IsFirstLine = false;
394 else
395 OS << "\n";
Richard Trieude5cc7d2013-01-31 01:44:26 +0000396
397 ColorScope Color(*this, IndentColor);
Craig Topper2341c0d2013-07-04 03:08:24 +0000398 for (SmallVectorImpl<IndentType>::const_iterator I = Indents.begin(),
399 E = Indents.end();
Richard Trieude5cc7d2013-01-31 01:44:26 +0000400 I != E; ++I) {
401 switch (*I) {
Richard Smith56d12152013-01-31 02:04:38 +0000402 case IT_Child:
403 if (I == E - 1)
404 OS << "|-";
405 else
406 OS << "| ";
407 continue;
408 case IT_LastChild:
409 if (I == E - 1)
410 OS << "`-";
411 else
412 OS << " ";
413 continue;
Richard Trieude5cc7d2013-01-31 01:44:26 +0000414 }
Richard Smith56d12152013-01-31 02:04:38 +0000415 llvm_unreachable("Invalid IndentType");
Richard Trieude5cc7d2013-01-31 01:44:26 +0000416 }
417 Indents.push_back(IT_Child);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000418}
419
Alexander Kornienko18ec81b2012-12-13 13:59:55 +0000420void ASTDumper::unindent() {
Richard Trieude5cc7d2013-01-31 01:44:26 +0000421 Indents.pop_back();
422}
423
424// Call before each potential last child node is to be dumped. If MoreChildren
425// is false, then this is the last child, otherwise treat as a regular node.
426void ASTDumper::lastChild() {
427 if (!hasMoreChildren())
428 Indents.back() = IT_LastChild;
429}
430
431// MoreChildren should be set before calling another function that may print
432// additional nodes to prevent conflicting final child nodes.
433bool ASTDumper::hasMoreChildren() {
434 return MoreChildren;
435}
436
437void ASTDumper::setMoreChildren(bool Value) {
438 MoreChildren = Value;
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000439}
440
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000441void ASTDumper::dumpPointer(const void *Ptr) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000442 ColorScope Color(*this, AddressColor);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000443 OS << ' ' << Ptr;
444}
445
Alexander Kornienko18ec81b2012-12-13 13:59:55 +0000446void ASTDumper::dumpLocation(SourceLocation Loc) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000447 ColorScope Color(*this, LocationColor);
Chris Lattner53e384f2009-01-16 07:00:02 +0000448 SourceLocation SpellingLoc = SM->getSpellingLoc(Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000449
Chris Lattner11e30d32007-08-30 06:17:34 +0000450 // The general format we print out is filename:line:col, but we drop pieces
451 // that haven't changed since the last loc printed.
Chris Lattnerf1ca7d32009-01-27 07:57:44 +0000452 PresumedLoc PLoc = SM->getPresumedLoc(SpellingLoc);
453
Douglas Gregor453b0122010-11-12 07:15:47 +0000454 if (PLoc.isInvalid()) {
455 OS << "<invalid sloc>";
456 return;
457 }
458
Chris Lattnerf1ca7d32009-01-27 07:57:44 +0000459 if (strcmp(PLoc.getFilename(), LastLocFilename) != 0) {
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000460 OS << PLoc.getFilename() << ':' << PLoc.getLine()
461 << ':' << PLoc.getColumn();
Chris Lattnerf1ca7d32009-01-27 07:57:44 +0000462 LastLocFilename = PLoc.getFilename();
463 LastLocLine = PLoc.getLine();
464 } else if (PLoc.getLine() != LastLocLine) {
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000465 OS << "line" << ':' << PLoc.getLine()
466 << ':' << PLoc.getColumn();
Chris Lattnerf1ca7d32009-01-27 07:57:44 +0000467 LastLocLine = PLoc.getLine();
Chris Lattner11e30d32007-08-30 06:17:34 +0000468 } else {
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000469 OS << "col" << ':' << PLoc.getColumn();
Chris Lattner11e30d32007-08-30 06:17:34 +0000470 }
471}
472
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000473void ASTDumper::dumpSourceRange(SourceRange R) {
Chris Lattner11e30d32007-08-30 06:17:34 +0000474 // Can't translate locations if a SourceManager isn't available.
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000475 if (!SM)
476 return;
Mike Stump11289f42009-09-09 15:08:12 +0000477
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000478 OS << " <";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000479 dumpLocation(R.getBegin());
Chris Lattnera7c19fe2007-10-16 22:36:42 +0000480 if (R.getBegin() != R.getEnd()) {
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000481 OS << ", ";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000482 dumpLocation(R.getEnd());
Chris Lattner11e30d32007-08-30 06:17:34 +0000483 }
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000484 OS << ">";
Mike Stump11289f42009-09-09 15:08:12 +0000485
Chris Lattner11e30d32007-08-30 06:17:34 +0000486 // <t2.c:123:421[blah], t2.c:412:321>
487
488}
489
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000490void ASTDumper::dumpBareType(QualType T) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000491 ColorScope Color(*this, TypeColor);
492
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000493 SplitQualType T_split = T.split();
494 OS << "'" << QualType::getAsString(T_split) << "'";
495
496 if (!T.isNull()) {
497 // If the type is sugared, also dump a (shallow) desugared type.
498 SplitQualType D_split = T.getSplitDesugaredType();
499 if (T_split != D_split)
500 OS << ":'" << QualType::getAsString(D_split) << "'";
501 }
502}
503
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000504void ASTDumper::dumpType(QualType T) {
505 OS << ' ';
506 dumpBareType(T);
507}
508
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000509void ASTDumper::dumpBareDeclRef(const Decl *D) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000510 {
511 ColorScope Color(*this, DeclKindNameColor);
512 OS << D->getDeclKindName();
513 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000514 dumpPointer(D);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000515
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000516 if (const NamedDecl *ND = dyn_cast<NamedDecl>(D)) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000517 ColorScope Color(*this, DeclNameColor);
David Blaikied4da8722013-05-14 21:04:00 +0000518 OS << " '" << ND->getDeclName() << '\'';
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000519 }
520
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000521 if (const ValueDecl *VD = dyn_cast<ValueDecl>(D))
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000522 dumpType(VD->getType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000523}
524
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000525void ASTDumper::dumpDeclRef(const Decl *D, const char *Label) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000526 if (!D)
527 return;
528
529 IndentScope Indent(*this);
530 if (Label)
531 OS << Label << ' ';
532 dumpBareDeclRef(D);
533}
534
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000535void ASTDumper::dumpName(const NamedDecl *ND) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000536 if (ND->getDeclName()) {
537 ColorScope Color(*this, DeclNameColor);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000538 OS << ' ' << ND->getNameAsString();
Richard Trieud215b8d2013-01-26 01:31:20 +0000539 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000540}
541
Richard Trieude5cc7d2013-01-31 01:44:26 +0000542bool ASTDumper::hasNodes(const DeclContext *DC) {
543 if (!DC)
544 return false;
545
Richard Smith1d209d02013-05-23 01:49:11 +0000546 return DC->hasExternalLexicalStorage() ||
547 DC->noload_decls_begin() != DC->noload_decls_end();
Richard Trieude5cc7d2013-01-31 01:44:26 +0000548}
549
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000550void ASTDumper::dumpDeclContext(const DeclContext *DC) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000551 if (!DC)
552 return;
Richard Smithdcc2c452014-03-17 23:00:06 +0000553
554 ChildDumper Children(*this);
555 for (auto *D : DC->noload_decls())
556 Children.dump(D);
557
558 if (DC->hasExternalLexicalStorage()) {
559 Children.release();
560
Richard Smith1d209d02013-05-23 01:49:11 +0000561 lastChild();
562 IndentScope Indent(*this);
563 ColorScope Color(*this, UndeserializedColor);
564 OS << "<undeserialized declarations>";
565 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000566}
567
Richard Smith33937e72013-06-22 21:49:40 +0000568void ASTDumper::dumpLookups(const DeclContext *DC) {
569 IndentScope Indent(*this);
570
571 OS << "StoredDeclsMap ";
572 dumpBareDeclRef(cast<Decl>(DC));
573
574 const DeclContext *Primary = DC->getPrimaryContext();
575 if (Primary != DC) {
576 OS << " primary";
577 dumpPointer(cast<Decl>(Primary));
578 }
579
580 bool HasUndeserializedLookups = Primary->hasExternalVisibleStorage();
581
582 DeclContext::all_lookups_iterator I = Primary->noload_lookups_begin(),
583 E = Primary->noload_lookups_end();
584 while (I != E) {
585 DeclarationName Name = I.getLookupName();
586 DeclContextLookupResult R = *I++;
587 if (I == E && !HasUndeserializedLookups)
588 lastChild();
589
590 IndentScope Indent(*this);
591 OS << "DeclarationName ";
592 {
593 ColorScope Color(*this, DeclNameColor);
594 OS << '\'' << Name << '\'';
595 }
596
597 for (DeclContextLookupResult::iterator RI = R.begin(), RE = R.end();
598 RI != RE; ++RI) {
599 if (RI + 1 == RE)
600 lastChild();
601 dumpDeclRef(*RI);
Richard Smith15fc7df2013-10-22 23:50:38 +0000602 if ((*RI)->isHidden())
603 OS << " hidden";
Richard Smith33937e72013-06-22 21:49:40 +0000604 }
605 }
606
607 if (HasUndeserializedLookups) {
608 lastChild();
609 IndentScope Indent(*this);
610 ColorScope Color(*this, UndeserializedColor);
611 OS << "<undeserialized lookups>";
612 }
613}
614
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000615void ASTDumper::dumpAttr(const Attr *A) {
616 IndentScope Indent(*this);
Richard Trieud215b8d2013-01-26 01:31:20 +0000617 {
618 ColorScope Color(*this, AttrColor);
Aaron Ballman36a53502014-01-16 13:03:14 +0000619
Richard Trieud215b8d2013-01-26 01:31:20 +0000620 switch (A->getKind()) {
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000621#define ATTR(X) case attr::X: OS << #X; break;
622#include "clang/Basic/AttrList.inc"
Richard Trieud215b8d2013-01-26 01:31:20 +0000623 default: llvm_unreachable("unexpected attribute kind");
624 }
625 OS << "Attr";
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000626 }
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000627 dumpPointer(A);
628 dumpSourceRange(A->getRange());
629#include "clang/AST/AttrDump.inc"
Aaron Ballman36a53502014-01-16 13:03:14 +0000630 if (A->isImplicit())
631 OS << " Implicit";
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000632}
633
Richard Smith71bec062013-10-15 21:58:30 +0000634static void dumpPreviousDeclImpl(raw_ostream &OS, ...) {}
635
636template<typename T>
637static void dumpPreviousDeclImpl(raw_ostream &OS, const Mergeable<T> *D) {
Rafael Espindola8db352d2013-10-17 15:37:26 +0000638 const T *First = D->getFirstDecl();
Richard Smith71bec062013-10-15 21:58:30 +0000639 if (First != D)
640 OS << " first " << First;
Richard Smithf5f43542013-02-07 01:35:44 +0000641}
642
643template<typename T>
Richard Smith71bec062013-10-15 21:58:30 +0000644static void dumpPreviousDeclImpl(raw_ostream &OS, const Redeclarable<T> *D) {
645 const T *Prev = D->getPreviousDecl();
646 if (Prev)
647 OS << " prev " << Prev;
Richard Smithf5f43542013-02-07 01:35:44 +0000648}
649
Richard Smith71bec062013-10-15 21:58:30 +0000650/// Dump the previous declaration in the redeclaration chain for a declaration,
651/// if any.
652static void dumpPreviousDecl(raw_ostream &OS, const Decl *D) {
Richard Smithf5f43542013-02-07 01:35:44 +0000653 switch (D->getKind()) {
654#define DECL(DERIVED, BASE) \
655 case Decl::DERIVED: \
Richard Smith71bec062013-10-15 21:58:30 +0000656 return dumpPreviousDeclImpl(OS, cast<DERIVED##Decl>(D));
Richard Smithf5f43542013-02-07 01:35:44 +0000657#define ABSTRACT_DECL(DECL)
658#include "clang/AST/DeclNodes.inc"
659 }
660 llvm_unreachable("Decl that isn't part of DeclNodes.inc!");
661}
662
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000663//===----------------------------------------------------------------------===//
664// C++ Utilities
665//===----------------------------------------------------------------------===//
666
667void ASTDumper::dumpAccessSpecifier(AccessSpecifier AS) {
668 switch (AS) {
669 case AS_none:
670 break;
671 case AS_public:
672 OS << "public";
673 break;
674 case AS_protected:
675 OS << "protected";
676 break;
677 case AS_private:
678 OS << "private";
679 break;
680 }
681}
682
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000683void ASTDumper::dumpCXXCtorInitializer(const CXXCtorInitializer *Init) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000684 IndentScope Indent(*this);
685 OS << "CXXCtorInitializer";
686 if (Init->isAnyMemberInitializer()) {
687 OS << ' ';
688 dumpBareDeclRef(Init->getAnyMember());
689 } else {
690 dumpType(QualType(Init->getBaseClass(), 0));
691 }
692 dumpStmt(Init->getInit());
693}
694
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000695void ASTDumper::dumpTemplateParameters(const TemplateParameterList *TPL) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000696 if (!TPL)
697 return;
698
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000699 for (TemplateParameterList::const_iterator I = TPL->begin(), E = TPL->end();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000700 I != E; ++I)
701 dumpDecl(*I);
702}
703
704void ASTDumper::dumpTemplateArgumentListInfo(
705 const TemplateArgumentListInfo &TALI) {
Richard Trieude5cc7d2013-01-31 01:44:26 +0000706 for (unsigned i = 0, e = TALI.size(); i < e; ++i) {
707 if (i + 1 == e)
708 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000709 dumpTemplateArgumentLoc(TALI[i]);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000710 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000711}
712
713void ASTDumper::dumpTemplateArgumentLoc(const TemplateArgumentLoc &A) {
714 dumpTemplateArgument(A.getArgument(), A.getSourceRange());
715}
716
717void ASTDumper::dumpTemplateArgumentList(const TemplateArgumentList &TAL) {
718 for (unsigned i = 0, e = TAL.size(); i < e; ++i)
719 dumpTemplateArgument(TAL[i]);
720}
721
722void ASTDumper::dumpTemplateArgument(const TemplateArgument &A, SourceRange R) {
723 IndentScope Indent(*this);
724 OS << "TemplateArgument";
725 if (R.isValid())
726 dumpSourceRange(R);
727
728 switch (A.getKind()) {
729 case TemplateArgument::Null:
730 OS << " null";
731 break;
732 case TemplateArgument::Type:
733 OS << " type";
Richard Trieude5cc7d2013-01-31 01:44:26 +0000734 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000735 dumpType(A.getAsType());
736 break;
737 case TemplateArgument::Declaration:
738 OS << " decl";
Richard Trieude5cc7d2013-01-31 01:44:26 +0000739 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000740 dumpDeclRef(A.getAsDecl());
741 break;
742 case TemplateArgument::NullPtr:
743 OS << " nullptr";
744 break;
745 case TemplateArgument::Integral:
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000746 OS << " integral " << A.getAsIntegral();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000747 break;
748 case TemplateArgument::Template:
749 OS << " template ";
750 A.getAsTemplate().dump(OS);
751 break;
752 case TemplateArgument::TemplateExpansion:
753 OS << " template expansion";
754 A.getAsTemplateOrTemplatePattern().dump(OS);
755 break;
756 case TemplateArgument::Expression:
757 OS << " expr";
Richard Trieude5cc7d2013-01-31 01:44:26 +0000758 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000759 dumpStmt(A.getAsExpr());
760 break;
761 case TemplateArgument::Pack:
762 OS << " pack";
763 for (TemplateArgument::pack_iterator I = A.pack_begin(), E = A.pack_end();
Richard Trieude5cc7d2013-01-31 01:44:26 +0000764 I != E; ++I) {
765 if (I + 1 == E)
766 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000767 dumpTemplateArgument(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000768 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000769 break;
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000770 }
771}
772
Chris Lattner11e30d32007-08-30 06:17:34 +0000773//===----------------------------------------------------------------------===//
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000774// Decl dumping methods.
Chris Lattnercbe4f772007-08-08 22:51:59 +0000775//===----------------------------------------------------------------------===//
776
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000777void ASTDumper::dumpDecl(const Decl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000778 IndentScope Indent(*this);
Mike Stump11289f42009-09-09 15:08:12 +0000779
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000780 if (!D) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000781 ColorScope Color(*this, NullColor);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000782 OS << "<<<NULL>>>";
783 return;
Chris Lattnercbe4f772007-08-08 22:51:59 +0000784 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000785
Richard Trieud215b8d2013-01-26 01:31:20 +0000786 {
787 ColorScope Color(*this, DeclKindNameColor);
788 OS << D->getDeclKindName() << "Decl";
789 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000790 dumpPointer(D);
Richard Smithf5f43542013-02-07 01:35:44 +0000791 if (D->getLexicalDeclContext() != D->getDeclContext())
792 OS << " parent " << cast<Decl>(D->getDeclContext());
Richard Smith71bec062013-10-15 21:58:30 +0000793 dumpPreviousDecl(OS, D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000794 dumpSourceRange(D->getSourceRange());
Richard Smith15fc7df2013-10-22 23:50:38 +0000795 if (Module *M = D->getOwningModule())
796 OS << " in " << M->getFullModuleName();
797 if (const NamedDecl *ND = dyn_cast<NamedDecl>(D))
798 if (ND->isHidden())
799 OS << " hidden";
Richard Trieude5cc7d2013-01-31 01:44:26 +0000800
Aaron Ballmanb97112e2014-03-08 22:19:01 +0000801 bool HasAttrs = D->hasAttrs();
Richard Smithb39b9d52013-05-21 05:24:00 +0000802 const FullComment *Comment =
803 D->getASTContext().getLocalCommentForDeclUncached(D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000804 // Decls within functions are visited by the body
Richard Trieude5cc7d2013-01-31 01:44:26 +0000805 bool HasDeclContext = !isa<FunctionDecl>(*D) && !isa<ObjCMethodDecl>(*D) &&
806 hasNodes(dyn_cast<DeclContext>(D));
807
Richard Smithb39b9d52013-05-21 05:24:00 +0000808 setMoreChildren(HasAttrs || Comment || HasDeclContext);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000809 ConstDeclVisitor<ASTDumper>::Visit(D);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000810
Richard Smithb39b9d52013-05-21 05:24:00 +0000811 setMoreChildren(Comment || HasDeclContext);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000812 for (Decl::attr_iterator I = D->attr_begin(), E = D->attr_end();
813 I != E; ++I) {
814 if (I + 1 == E)
815 lastChild();
816 dumpAttr(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000817 }
818
819 setMoreChildren(HasDeclContext);
820 lastChild();
Richard Smithb39b9d52013-05-21 05:24:00 +0000821 dumpFullComment(Comment);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000822
Nick Lewyckya382db02013-08-27 03:15:56 +0000823 if (D->isInvalidDecl())
824 OS << " invalid";
825
Richard Trieude5cc7d2013-01-31 01:44:26 +0000826 setMoreChildren(false);
827 if (HasDeclContext)
Richard Smithf5f43542013-02-07 01:35:44 +0000828 dumpDeclContext(cast<DeclContext>(D));
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000829}
830
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000831void ASTDumper::VisitLabelDecl(const LabelDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000832 dumpName(D);
833}
834
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000835void ASTDumper::VisitTypedefDecl(const TypedefDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000836 dumpName(D);
837 dumpType(D->getUnderlyingType());
838 if (D->isModulePrivate())
839 OS << " __module_private__";
840}
841
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000842void ASTDumper::VisitEnumDecl(const EnumDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000843 if (D->isScoped()) {
844 if (D->isScopedUsingClassTag())
845 OS << " class";
846 else
847 OS << " struct";
848 }
849 dumpName(D);
850 if (D->isModulePrivate())
851 OS << " __module_private__";
852 if (D->isFixed())
853 dumpType(D->getIntegerType());
854}
855
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000856void ASTDumper::VisitRecordDecl(const RecordDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000857 OS << ' ' << D->getKindName();
858 dumpName(D);
859 if (D->isModulePrivate())
860 OS << " __module_private__";
Richard Smith99bc1b92013-08-30 05:32:29 +0000861 if (D->isCompleteDefinition())
862 OS << " definition";
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000863}
864
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000865void ASTDumper::VisitEnumConstantDecl(const EnumConstantDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000866 dumpName(D);
867 dumpType(D->getType());
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000868 if (const Expr *Init = D->getInitExpr()) {
Richard Trieude5cc7d2013-01-31 01:44:26 +0000869 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000870 dumpStmt(Init);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000871 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000872}
873
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000874void ASTDumper::VisitIndirectFieldDecl(const IndirectFieldDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000875 dumpName(D);
876 dumpType(D->getType());
Richard Smithdcc2c452014-03-17 23:00:06 +0000877
878 ChildDumper Children(*this);
Richard Smith8aa49222014-03-18 00:35:12 +0000879 for (auto *Child : D->chain())
880 Children.dumpRef(Child);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000881}
882
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000883void ASTDumper::VisitFunctionDecl(const FunctionDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000884 dumpName(D);
885 dumpType(D->getType());
886
Rafael Espindola6ae7e502013-04-03 19:27:57 +0000887 StorageClass SC = D->getStorageClass();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000888 if (SC != SC_None)
889 OS << ' ' << VarDecl::getStorageClassSpecifierString(SC);
890 if (D->isInlineSpecified())
891 OS << " inline";
892 if (D->isVirtualAsWritten())
893 OS << " virtual";
894 if (D->isModulePrivate())
895 OS << " __module_private__";
896
897 if (D->isPure())
898 OS << " pure";
899 else if (D->isDeletedAsWritten())
900 OS << " delete";
901
Richard Smithadaa0152013-05-17 02:09:46 +0000902 if (const FunctionProtoType *FPT = D->getType()->getAs<FunctionProtoType>()) {
903 FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo();
904 switch (EPI.ExceptionSpecType) {
905 default: break;
906 case EST_Unevaluated:
907 OS << " noexcept-unevaluated " << EPI.ExceptionSpecDecl;
908 break;
909 case EST_Uninstantiated:
910 OS << " noexcept-uninstantiated " << EPI.ExceptionSpecTemplate;
911 break;
912 }
913 }
914
Richard Trieude5cc7d2013-01-31 01:44:26 +0000915 bool OldMoreChildren = hasMoreChildren();
916 const FunctionTemplateSpecializationInfo *FTSI =
917 D->getTemplateSpecializationInfo();
918 bool HasTemplateSpecialization = FTSI;
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000919
Richard Trieude5cc7d2013-01-31 01:44:26 +0000920 bool HasNamedDecls = D->getDeclsInPrototypeScope().begin() !=
921 D->getDeclsInPrototypeScope().end();
922
923 bool HasFunctionDecls = D->param_begin() != D->param_end();
924
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000925 const CXXConstructorDecl *C = dyn_cast<CXXConstructorDecl>(D);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000926 bool HasCtorInitializers = C && C->init_begin() != C->init_end();
927
928 bool HasDeclarationBody = D->doesThisDeclarationHaveABody();
929
930 setMoreChildren(OldMoreChildren || HasNamedDecls || HasFunctionDecls ||
931 HasCtorInitializers || HasDeclarationBody);
932 if (HasTemplateSpecialization) {
933 lastChild();
934 dumpTemplateArgumentList(*FTSI->TemplateArguments);
935 }
936
937 setMoreChildren(OldMoreChildren || HasFunctionDecls ||
938 HasCtorInitializers || HasDeclarationBody);
Dmitri Gribenkof8579502013-01-12 19:30:44 +0000939 for (ArrayRef<NamedDecl *>::iterator
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000940 I = D->getDeclsInPrototypeScope().begin(),
Richard Trieude5cc7d2013-01-31 01:44:26 +0000941 E = D->getDeclsInPrototypeScope().end(); I != E; ++I) {
942 if (I + 1 == E)
943 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000944 dumpDecl(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000945 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000946
Richard Trieude5cc7d2013-01-31 01:44:26 +0000947 setMoreChildren(OldMoreChildren || HasCtorInitializers || HasDeclarationBody);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000948 for (FunctionDecl::param_const_iterator I = D->param_begin(),
949 E = D->param_end();
Richard Trieude5cc7d2013-01-31 01:44:26 +0000950 I != E; ++I) {
951 if (I + 1 == E)
952 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000953 dumpDecl(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000954 }
955
956 setMoreChildren(OldMoreChildren || HasDeclarationBody);
957 if (HasCtorInitializers)
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000958 for (CXXConstructorDecl::init_const_iterator I = C->init_begin(),
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000959 E = C->init_end();
960 I != E; ++I) {
Richard Trieude5cc7d2013-01-31 01:44:26 +0000961 if (I + 1 == E)
962 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000963 dumpCXXCtorInitializer(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000964 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000965
Richard Trieude5cc7d2013-01-31 01:44:26 +0000966 setMoreChildren(OldMoreChildren);
967 if (HasDeclarationBody) {
968 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000969 dumpStmt(D->getBody());
Richard Trieude5cc7d2013-01-31 01:44:26 +0000970 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000971}
972
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000973void ASTDumper::VisitFieldDecl(const FieldDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000974 dumpName(D);
975 dumpType(D->getType());
976 if (D->isMutable())
977 OS << " mutable";
978 if (D->isModulePrivate())
979 OS << " __module_private__";
Richard Trieude5cc7d2013-01-31 01:44:26 +0000980
981 bool OldMoreChildren = hasMoreChildren();
982 bool IsBitField = D->isBitField();
983 Expr *Init = D->getInClassInitializer();
984 bool HasInit = Init;
985
986 setMoreChildren(OldMoreChildren || HasInit);
987 if (IsBitField) {
988 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000989 dumpStmt(D->getBitWidth());
Richard Trieude5cc7d2013-01-31 01:44:26 +0000990 }
991 setMoreChildren(OldMoreChildren);
992 if (HasInit) {
993 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000994 dumpStmt(Init);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000995 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000996}
997
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000998void ASTDumper::VisitVarDecl(const VarDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000999 dumpName(D);
1000 dumpType(D->getType());
Rafael Espindola6ae7e502013-04-03 19:27:57 +00001001 StorageClass SC = D->getStorageClass();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001002 if (SC != SC_None)
1003 OS << ' ' << VarDecl::getStorageClassSpecifierString(SC);
Richard Smithfd3834f2013-04-13 02:43:54 +00001004 switch (D->getTLSKind()) {
1005 case VarDecl::TLS_None: break;
1006 case VarDecl::TLS_Static: OS << " tls"; break;
1007 case VarDecl::TLS_Dynamic: OS << " tls_dynamic"; break;
1008 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001009 if (D->isModulePrivate())
1010 OS << " __module_private__";
1011 if (D->isNRVOVariable())
1012 OS << " nrvo";
Richard Trieude5cc7d2013-01-31 01:44:26 +00001013 if (D->hasInit()) {
1014 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001015 dumpStmt(D->getInit());
Richard Trieude5cc7d2013-01-31 01:44:26 +00001016 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001017}
1018
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001019void ASTDumper::VisitFileScopeAsmDecl(const FileScopeAsmDecl *D) {
Richard Trieude5cc7d2013-01-31 01:44:26 +00001020 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001021 dumpStmt(D->getAsmString());
1022}
1023
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001024void ASTDumper::VisitImportDecl(const ImportDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001025 OS << ' ' << D->getImportedModule()->getFullModuleName();
1026}
1027
1028//===----------------------------------------------------------------------===//
1029// C++ Declarations
1030//===----------------------------------------------------------------------===//
1031
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001032void ASTDumper::VisitNamespaceDecl(const NamespaceDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001033 dumpName(D);
1034 if (D->isInline())
1035 OS << " inline";
1036 if (!D->isOriginalNamespace())
1037 dumpDeclRef(D->getOriginalNamespace(), "original");
1038}
1039
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001040void ASTDumper::VisitUsingDirectiveDecl(const UsingDirectiveDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001041 OS << ' ';
1042 dumpBareDeclRef(D->getNominatedNamespace());
1043}
1044
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001045void ASTDumper::VisitNamespaceAliasDecl(const NamespaceAliasDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001046 dumpName(D);
1047 dumpDeclRef(D->getAliasedNamespace());
1048}
1049
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001050void ASTDumper::VisitTypeAliasDecl(const TypeAliasDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001051 dumpName(D);
1052 dumpType(D->getUnderlyingType());
1053}
1054
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001055void ASTDumper::VisitTypeAliasTemplateDecl(const TypeAliasTemplateDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001056 dumpName(D);
1057 dumpTemplateParameters(D->getTemplateParameters());
1058 dumpDecl(D->getTemplatedDecl());
1059}
1060
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001061void ASTDumper::VisitCXXRecordDecl(const CXXRecordDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001062 VisitRecordDecl(D);
1063 if (!D->isCompleteDefinition())
1064 return;
1065
Aaron Ballman574705e2014-03-13 15:41:46 +00001066 for (const auto &I : D->bases()) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001067 IndentScope Indent(*this);
Aaron Ballman574705e2014-03-13 15:41:46 +00001068 if (I.isVirtual())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001069 OS << "virtual ";
Aaron Ballman574705e2014-03-13 15:41:46 +00001070 dumpAccessSpecifier(I.getAccessSpecifier());
1071 dumpType(I.getType());
1072 if (I.isPackExpansion())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001073 OS << "...";
1074 }
1075}
1076
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001077void ASTDumper::VisitStaticAssertDecl(const StaticAssertDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001078 dumpStmt(D->getAssertExpr());
Richard Trieude5cc7d2013-01-31 01:44:26 +00001079 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001080 dumpStmt(D->getMessage());
1081}
1082
Richard Smithcbdf7332014-03-18 02:07:28 +00001083template<typename SpecializationDecl>
1084void ASTDumper::VisitTemplateDeclSpecialization(ChildDumper &Children,
1085 const SpecializationDecl *D,
1086 bool DumpExplicitInst,
1087 bool DumpRefOnly) {
1088 bool DumpedAny = false;
1089 for (auto *RedeclWithBadType : D->redecls()) {
1090 // FIXME: The redecls() range sometimes has elements of a less-specific
1091 // type. (In particular, ClassTemplateSpecializationDecl::redecls() gives
1092 // us TagDecls, and should give CXXRecordDecls).
1093 auto *Redecl = dyn_cast<SpecializationDecl>(RedeclWithBadType);
1094 if (!Redecl) {
1095 // Found the injected-class-name for a class template. This will be dumped
1096 // as part of its surrounding class so we don't need to dump it here.
1097 assert(isa<CXXRecordDecl>(RedeclWithBadType) &&
1098 "expected an injected-class-name");
1099 continue;
1100 }
1101
1102 switch (Redecl->getTemplateSpecializationKind()) {
1103 case TSK_ExplicitInstantiationDeclaration:
1104 case TSK_ExplicitInstantiationDefinition:
1105 if (!DumpExplicitInst)
1106 break;
1107 // Fall through.
1108 case TSK_Undeclared:
1109 case TSK_ImplicitInstantiation:
1110 Children.dump(Redecl, DumpRefOnly);
1111 DumpedAny = true;
1112 break;
1113 case TSK_ExplicitSpecialization:
1114 break;
1115 }
1116 }
1117
1118 // Ensure we dump at least one decl for each specialization.
1119 if (!DumpedAny)
1120 Children.dumpRef(D);
1121}
1122
Richard Smith20ade552014-03-17 23:34:53 +00001123template<typename TemplateDecl>
1124void ASTDumper::VisitTemplateDecl(const TemplateDecl *D,
1125 bool DumpExplicitInst) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001126 dumpName(D);
1127 dumpTemplateParameters(D->getTemplateParameters());
Richard Smithdcc2c452014-03-17 23:00:06 +00001128
1129 ChildDumper Children(*this);
1130 Children.dump(D->getTemplatedDecl());
1131
Richard Smithcbdf7332014-03-18 02:07:28 +00001132 for (auto *Child : D->specializations())
1133 VisitTemplateDeclSpecialization(Children, Child, DumpExplicitInst,
1134 !D->isCanonicalDecl());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001135}
1136
Richard Smith20ade552014-03-17 23:34:53 +00001137void ASTDumper::VisitFunctionTemplateDecl(const FunctionTemplateDecl *D) {
1138 // FIXME: We don't add a declaration of a function template specialization
1139 // to its context when it's explicitly instantiated, so dump explicit
1140 // instantiations when we dump the template itself.
1141 VisitTemplateDecl(D, true);
1142}
1143
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001144void ASTDumper::VisitClassTemplateDecl(const ClassTemplateDecl *D) {
Richard Smith20ade552014-03-17 23:34:53 +00001145 VisitTemplateDecl(D, false);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001146}
1147
1148void ASTDumper::VisitClassTemplateSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001149 const ClassTemplateSpecializationDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001150 VisitCXXRecordDecl(D);
1151 dumpTemplateArgumentList(D->getTemplateArgs());
1152}
1153
1154void ASTDumper::VisitClassTemplatePartialSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001155 const ClassTemplatePartialSpecializationDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001156 VisitClassTemplateSpecializationDecl(D);
1157 dumpTemplateParameters(D->getTemplateParameters());
1158}
1159
1160void ASTDumper::VisitClassScopeFunctionSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001161 const ClassScopeFunctionSpecializationDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001162 dumpDeclRef(D->getSpecialization());
1163 if (D->hasExplicitTemplateArgs())
1164 dumpTemplateArgumentListInfo(D->templateArgs());
1165}
1166
Richard Smithd25789a2013-09-18 01:36:02 +00001167void ASTDumper::VisitVarTemplateDecl(const VarTemplateDecl *D) {
Richard Smith20ade552014-03-17 23:34:53 +00001168 VisitTemplateDecl(D, false);
Richard Smithd25789a2013-09-18 01:36:02 +00001169}
1170
1171void ASTDumper::VisitVarTemplateSpecializationDecl(
1172 const VarTemplateSpecializationDecl *D) {
1173 dumpTemplateArgumentList(D->getTemplateArgs());
1174 VisitVarDecl(D);
1175}
1176
1177void ASTDumper::VisitVarTemplatePartialSpecializationDecl(
1178 const VarTemplatePartialSpecializationDecl *D) {
1179 dumpTemplateParameters(D->getTemplateParameters());
1180 VisitVarTemplateSpecializationDecl(D);
1181}
1182
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001183void ASTDumper::VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001184 if (D->wasDeclaredWithTypename())
1185 OS << " typename";
1186 else
1187 OS << " class";
1188 if (D->isParameterPack())
1189 OS << " ...";
1190 dumpName(D);
Richard Smithecf74ff2014-03-23 20:50:39 +00001191 if (D->hasDefaultArgument()) {
1192 lastChild();
1193 dumpTemplateArgument(D->getDefaultArgument());
1194 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001195}
1196
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001197void ASTDumper::VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001198 dumpType(D->getType());
1199 if (D->isParameterPack())
1200 OS << " ...";
1201 dumpName(D);
Richard Smithecf74ff2014-03-23 20:50:39 +00001202 if (D->hasDefaultArgument()) {
1203 lastChild();
1204 dumpTemplateArgument(D->getDefaultArgument());
1205 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001206}
1207
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001208void ASTDumper::VisitTemplateTemplateParmDecl(
1209 const TemplateTemplateParmDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001210 if (D->isParameterPack())
1211 OS << " ...";
1212 dumpName(D);
1213 dumpTemplateParameters(D->getTemplateParameters());
Richard Smithecf74ff2014-03-23 20:50:39 +00001214 if (D->hasDefaultArgument()) {
1215 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001216 dumpTemplateArgumentLoc(D->getDefaultArgument());
Richard Smithecf74ff2014-03-23 20:50:39 +00001217 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001218}
1219
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001220void ASTDumper::VisitUsingDecl(const UsingDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001221 OS << ' ';
1222 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
1223 OS << D->getNameAsString();
1224}
1225
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001226void ASTDumper::VisitUnresolvedUsingTypenameDecl(
1227 const UnresolvedUsingTypenameDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001228 OS << ' ';
1229 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
1230 OS << D->getNameAsString();
1231}
1232
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001233void ASTDumper::VisitUnresolvedUsingValueDecl(const UnresolvedUsingValueDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001234 OS << ' ';
1235 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
1236 OS << D->getNameAsString();
1237 dumpType(D->getType());
1238}
1239
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001240void ASTDumper::VisitUsingShadowDecl(const UsingShadowDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001241 OS << ' ';
1242 dumpBareDeclRef(D->getTargetDecl());
1243}
1244
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001245void ASTDumper::VisitLinkageSpecDecl(const LinkageSpecDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001246 switch (D->getLanguage()) {
1247 case LinkageSpecDecl::lang_c: OS << " C"; break;
1248 case LinkageSpecDecl::lang_cxx: OS << " C++"; break;
1249 }
1250}
1251
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001252void ASTDumper::VisitAccessSpecDecl(const AccessSpecDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001253 OS << ' ';
1254 dumpAccessSpecifier(D->getAccess());
1255}
1256
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001257void ASTDumper::VisitFriendDecl(const FriendDecl *D) {
Richard Smithf5f43542013-02-07 01:35:44 +00001258 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001259 if (TypeSourceInfo *T = D->getFriendType())
1260 dumpType(T->getType());
1261 else
1262 dumpDecl(D->getFriendDecl());
1263}
1264
1265//===----------------------------------------------------------------------===//
1266// Obj-C Declarations
1267//===----------------------------------------------------------------------===//
1268
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001269void ASTDumper::VisitObjCIvarDecl(const ObjCIvarDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001270 dumpName(D);
1271 dumpType(D->getType());
1272 if (D->getSynthesize())
1273 OS << " synthesize";
1274
1275 switch (D->getAccessControl()) {
1276 case ObjCIvarDecl::None:
1277 OS << " none";
1278 break;
1279 case ObjCIvarDecl::Private:
1280 OS << " private";
1281 break;
1282 case ObjCIvarDecl::Protected:
1283 OS << " protected";
1284 break;
1285 case ObjCIvarDecl::Public:
1286 OS << " public";
1287 break;
1288 case ObjCIvarDecl::Package:
1289 OS << " package";
1290 break;
1291 }
1292}
1293
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001294void ASTDumper::VisitObjCMethodDecl(const ObjCMethodDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001295 if (D->isInstanceMethod())
1296 OS << " -";
1297 else
1298 OS << " +";
1299 dumpName(D);
Alp Toker314cc812014-01-25 16:55:45 +00001300 dumpType(D->getReturnType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001301
Richard Trieude5cc7d2013-01-31 01:44:26 +00001302 bool OldMoreChildren = hasMoreChildren();
1303 bool IsVariadic = D->isVariadic();
1304 bool HasBody = D->hasBody();
1305
1306 setMoreChildren(OldMoreChildren || IsVariadic || HasBody);
1307 if (D->isThisDeclarationADefinition()) {
1308 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001309 dumpDeclContext(D);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001310 } else {
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001311 for (ObjCMethodDecl::param_const_iterator I = D->param_begin(),
1312 E = D->param_end();
1313 I != E; ++I) {
Richard Trieude5cc7d2013-01-31 01:44:26 +00001314 if (I + 1 == E)
1315 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001316 dumpDecl(*I);
1317 }
1318 }
1319
Richard Trieude5cc7d2013-01-31 01:44:26 +00001320 setMoreChildren(OldMoreChildren || HasBody);
1321 if (IsVariadic) {
1322 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001323 IndentScope Indent(*this);
1324 OS << "...";
1325 }
1326
Richard Trieude5cc7d2013-01-31 01:44:26 +00001327 setMoreChildren(OldMoreChildren);
1328 if (HasBody) {
1329 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001330 dumpStmt(D->getBody());
Richard Trieude5cc7d2013-01-31 01:44:26 +00001331 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001332}
1333
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001334void ASTDumper::VisitObjCCategoryDecl(const ObjCCategoryDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001335 dumpName(D);
1336 dumpDeclRef(D->getClassInterface());
Richard Trieude5cc7d2013-01-31 01:44:26 +00001337 if (D->protocol_begin() == D->protocol_end())
1338 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001339 dumpDeclRef(D->getImplementation());
1340 for (ObjCCategoryDecl::protocol_iterator I = D->protocol_begin(),
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001341 E = D->protocol_end();
1342 I != E; ++I) {
Richard Trieude5cc7d2013-01-31 01:44:26 +00001343 if (I + 1 == E)
1344 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001345 dumpDeclRef(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001346 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001347}
1348
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001349void ASTDumper::VisitObjCCategoryImplDecl(const ObjCCategoryImplDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001350 dumpName(D);
1351 dumpDeclRef(D->getClassInterface());
Richard Trieude5cc7d2013-01-31 01:44:26 +00001352 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001353 dumpDeclRef(D->getCategoryDecl());
1354}
1355
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001356void ASTDumper::VisitObjCProtocolDecl(const ObjCProtocolDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001357 dumpName(D);
Richard Smithdcc2c452014-03-17 23:00:06 +00001358
1359 ChildDumper Children(*this);
Richard Smith7fcb35f2014-03-18 02:37:59 +00001360 for (auto *Child : D->protocols())
1361 Children.dumpRef(Child);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001362}
1363
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001364void ASTDumper::VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001365 dumpName(D);
1366 dumpDeclRef(D->getSuperClass(), "super");
Richard Smithdcc2c452014-03-17 23:00:06 +00001367
1368 ChildDumper Children(*this);
1369 Children.dumpRef(D->getImplementation());
Richard Smith7fcb35f2014-03-18 02:37:59 +00001370 for (auto *Child : D->protocols())
1371 Children.dumpRef(Child);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001372}
1373
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001374void ASTDumper::VisitObjCImplementationDecl(const ObjCImplementationDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001375 dumpName(D);
1376 dumpDeclRef(D->getSuperClass(), "super");
Richard Trieude5cc7d2013-01-31 01:44:26 +00001377 if (D->init_begin() == D->init_end())
1378 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001379 dumpDeclRef(D->getClassInterface());
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001380 for (ObjCImplementationDecl::init_const_iterator I = D->init_begin(),
1381 E = D->init_end();
1382 I != E; ++I) {
Richard Trieude5cc7d2013-01-31 01:44:26 +00001383 if (I + 1 == E)
1384 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001385 dumpCXXCtorInitializer(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001386 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001387}
1388
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001389void ASTDumper::VisitObjCCompatibleAliasDecl(const ObjCCompatibleAliasDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001390 dumpName(D);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001391 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001392 dumpDeclRef(D->getClassInterface());
1393}
1394
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001395void ASTDumper::VisitObjCPropertyDecl(const ObjCPropertyDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001396 dumpName(D);
1397 dumpType(D->getType());
1398
1399 if (D->getPropertyImplementation() == ObjCPropertyDecl::Required)
1400 OS << " required";
1401 else if (D->getPropertyImplementation() == ObjCPropertyDecl::Optional)
1402 OS << " optional";
1403
1404 ObjCPropertyDecl::PropertyAttributeKind Attrs = D->getPropertyAttributes();
1405 if (Attrs != ObjCPropertyDecl::OBJC_PR_noattr) {
1406 if (Attrs & ObjCPropertyDecl::OBJC_PR_readonly)
1407 OS << " readonly";
1408 if (Attrs & ObjCPropertyDecl::OBJC_PR_assign)
1409 OS << " assign";
1410 if (Attrs & ObjCPropertyDecl::OBJC_PR_readwrite)
1411 OS << " readwrite";
1412 if (Attrs & ObjCPropertyDecl::OBJC_PR_retain)
1413 OS << " retain";
1414 if (Attrs & ObjCPropertyDecl::OBJC_PR_copy)
1415 OS << " copy";
1416 if (Attrs & ObjCPropertyDecl::OBJC_PR_nonatomic)
1417 OS << " nonatomic";
1418 if (Attrs & ObjCPropertyDecl::OBJC_PR_atomic)
1419 OS << " atomic";
1420 if (Attrs & ObjCPropertyDecl::OBJC_PR_weak)
1421 OS << " weak";
1422 if (Attrs & ObjCPropertyDecl::OBJC_PR_strong)
1423 OS << " strong";
1424 if (Attrs & ObjCPropertyDecl::OBJC_PR_unsafe_unretained)
1425 OS << " unsafe_unretained";
Richard Trieude5cc7d2013-01-31 01:44:26 +00001426 if (Attrs & ObjCPropertyDecl::OBJC_PR_getter) {
1427 if (!(Attrs & ObjCPropertyDecl::OBJC_PR_setter))
1428 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001429 dumpDeclRef(D->getGetterMethodDecl(), "getter");
Richard Trieude5cc7d2013-01-31 01:44:26 +00001430 }
1431 if (Attrs & ObjCPropertyDecl::OBJC_PR_setter) {
1432 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001433 dumpDeclRef(D->getSetterMethodDecl(), "setter");
Richard Trieude5cc7d2013-01-31 01:44:26 +00001434 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001435 }
1436}
1437
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001438void ASTDumper::VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001439 dumpName(D->getPropertyDecl());
1440 if (D->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize)
1441 OS << " synthesize";
1442 else
1443 OS << " dynamic";
1444 dumpDeclRef(D->getPropertyDecl());
Richard Trieude5cc7d2013-01-31 01:44:26 +00001445 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001446 dumpDeclRef(D->getPropertyIvarDecl());
1447}
1448
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001449void ASTDumper::VisitBlockDecl(const BlockDecl *D) {
Aaron Ballmanb2b8b1d2014-03-07 16:09:59 +00001450 for (auto I : D->params())
1451 dumpDecl(I);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001452
1453 if (D->isVariadic()) {
1454 IndentScope Indent(*this);
1455 OS << "...";
1456 }
1457
1458 if (D->capturesCXXThis()) {
1459 IndentScope Indent(*this);
1460 OS << "capture this";
1461 }
Aaron Ballman9371dd22014-03-14 18:34:04 +00001462 for (const auto &I : D->captures()) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001463 IndentScope Indent(*this);
1464 OS << "capture";
Aaron Ballman9371dd22014-03-14 18:34:04 +00001465 if (I.isByRef())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001466 OS << " byref";
Aaron Ballman9371dd22014-03-14 18:34:04 +00001467 if (I.isNested())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001468 OS << " nested";
Aaron Ballman9371dd22014-03-14 18:34:04 +00001469 if (I.getVariable()) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001470 OS << ' ';
Aaron Ballman9371dd22014-03-14 18:34:04 +00001471 dumpBareDeclRef(I.getVariable());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001472 }
Aaron Ballman9371dd22014-03-14 18:34:04 +00001473 if (I.hasCopyExpr())
1474 dumpStmt(I.getCopyExpr());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001475 }
Richard Trieude5cc7d2013-01-31 01:44:26 +00001476 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001477 dumpStmt(D->getBody());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001478}
1479
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001480//===----------------------------------------------------------------------===//
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001481// Stmt dumping methods.
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001482//===----------------------------------------------------------------------===//
1483
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001484void ASTDumper::dumpStmt(const Stmt *S) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001485 IndentScope Indent(*this);
1486
1487 if (!S) {
Richard Trieud215b8d2013-01-26 01:31:20 +00001488 ColorScope Color(*this, NullColor);
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001489 OS << "<<<NULL>>>";
1490 return;
1491 }
1492
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001493 if (const DeclStmt *DS = dyn_cast<DeclStmt>(S)) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001494 VisitDeclStmt(DS);
1495 return;
1496 }
1497
David Blaikie7d170102013-05-15 07:37:26 +00001498 setMoreChildren(!S->children().empty());
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001499 ConstStmtVisitor<ASTDumper>::Visit(S);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001500 setMoreChildren(false);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001501 for (Stmt::const_child_range CI = S->children(); CI; ++CI) {
1502 Stmt::const_child_range Next = CI;
Richard Trieude5cc7d2013-01-31 01:44:26 +00001503 ++Next;
1504 if (!Next)
1505 lastChild();
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001506 dumpStmt(*CI);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001507 }
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001508}
1509
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001510void ASTDumper::VisitStmt(const Stmt *Node) {
Richard Trieud215b8d2013-01-26 01:31:20 +00001511 {
1512 ColorScope Color(*this, StmtColor);
1513 OS << Node->getStmtClassName();
1514 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001515 dumpPointer(Node);
1516 dumpSourceRange(Node->getSourceRange());
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001517}
1518
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001519void ASTDumper::VisitDeclStmt(const DeclStmt *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001520 VisitStmt(Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001521 for (DeclStmt::const_decl_iterator I = Node->decl_begin(),
1522 E = Node->decl_end();
Richard Trieude5cc7d2013-01-31 01:44:26 +00001523 I != E; ++I) {
1524 if (I + 1 == E)
1525 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001526 dumpDecl(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001527 }
Ted Kremenek433a4922007-12-12 06:59:42 +00001528}
1529
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001530void ASTDumper::VisitAttributedStmt(const AttributedStmt *Node) {
Alexander Kornienko5bc364e2013-01-07 17:53:08 +00001531 VisitStmt(Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001532 for (ArrayRef<const Attr *>::iterator I = Node->getAttrs().begin(),
1533 E = Node->getAttrs().end();
1534 I != E; ++I) {
Richard Trieude5cc7d2013-01-31 01:44:26 +00001535 if (I + 1 == E)
1536 lastChild();
Alexander Kornienko5bc364e2013-01-07 17:53:08 +00001537 dumpAttr(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001538 }
Alexander Kornienko5bc364e2013-01-07 17:53:08 +00001539}
1540
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001541void ASTDumper::VisitLabelStmt(const LabelStmt *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001542 VisitStmt(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001543 OS << " '" << Node->getName() << "'";
Chris Lattnercbe4f772007-08-08 22:51:59 +00001544}
1545
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001546void ASTDumper::VisitGotoStmt(const GotoStmt *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001547 VisitStmt(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001548 OS << " '" << Node->getLabel()->getName() << "'";
1549 dumpPointer(Node->getLabel());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001550}
1551
Pavel Labath1ef83422013-09-04 14:35:00 +00001552void ASTDumper::VisitCXXCatchStmt(const CXXCatchStmt *Node) {
1553 VisitStmt(Node);
1554 dumpDecl(Node->getExceptionDecl());
1555}
1556
Chris Lattnercbe4f772007-08-08 22:51:59 +00001557//===----------------------------------------------------------------------===//
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001558// Expr dumping methods.
Chris Lattnercbe4f772007-08-08 22:51:59 +00001559//===----------------------------------------------------------------------===//
1560
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001561void ASTDumper::VisitExpr(const Expr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001562 VisitStmt(Node);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001563 dumpType(Node->getType());
1564
Richard Trieud215b8d2013-01-26 01:31:20 +00001565 {
1566 ColorScope Color(*this, ValueKindColor);
1567 switch (Node->getValueKind()) {
1568 case VK_RValue:
1569 break;
1570 case VK_LValue:
1571 OS << " lvalue";
1572 break;
1573 case VK_XValue:
1574 OS << " xvalue";
1575 break;
1576 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001577 }
1578
Richard Trieud215b8d2013-01-26 01:31:20 +00001579 {
1580 ColorScope Color(*this, ObjectKindColor);
1581 switch (Node->getObjectKind()) {
1582 case OK_Ordinary:
1583 break;
1584 case OK_BitField:
1585 OS << " bitfield";
1586 break;
1587 case OK_ObjCProperty:
1588 OS << " objcproperty";
1589 break;
1590 case OK_ObjCSubscript:
1591 OS << " objcsubscript";
1592 break;
1593 case OK_VectorComponent:
1594 OS << " vectorcomponent";
1595 break;
1596 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001597 }
Chris Lattnercbe4f772007-08-08 22:51:59 +00001598}
1599
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001600static void dumpBasePath(raw_ostream &OS, const CastExpr *Node) {
John McCallcf142162010-08-07 06:22:56 +00001601 if (Node->path_empty())
Anders Carlssona70cff62010-04-24 19:06:50 +00001602 return;
1603
1604 OS << " (";
1605 bool First = true;
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001606 for (CastExpr::path_const_iterator I = Node->path_begin(),
1607 E = Node->path_end();
1608 I != E; ++I) {
Anders Carlssona70cff62010-04-24 19:06:50 +00001609 const CXXBaseSpecifier *Base = *I;
1610 if (!First)
1611 OS << " -> ";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001612
Anders Carlssona70cff62010-04-24 19:06:50 +00001613 const CXXRecordDecl *RD =
1614 cast<CXXRecordDecl>(Base->getType()->getAs<RecordType>()->getDecl());
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001615
Anders Carlssona70cff62010-04-24 19:06:50 +00001616 if (Base->isVirtual())
1617 OS << "virtual ";
1618 OS << RD->getName();
1619 First = false;
1620 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001621
Anders Carlssona70cff62010-04-24 19:06:50 +00001622 OS << ')';
1623}
1624
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001625void ASTDumper::VisitCastExpr(const CastExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001626 VisitExpr(Node);
Richard Trieud215b8d2013-01-26 01:31:20 +00001627 OS << " <";
1628 {
1629 ColorScope Color(*this, CastColor);
1630 OS << Node->getCastKindName();
1631 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001632 dumpBasePath(OS, Node);
Anders Carlssona70cff62010-04-24 19:06:50 +00001633 OS << ">";
Anders Carlssond7923c62009-08-22 23:33:40 +00001634}
1635
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001636void ASTDumper::VisitDeclRefExpr(const DeclRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001637 VisitExpr(Node);
Ted Kremenek5f64ca82007-09-10 17:32:55 +00001638
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001639 OS << " ";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001640 dumpBareDeclRef(Node->getDecl());
Chandler Carruth8d26bb02011-05-01 23:48:14 +00001641 if (Node->getDecl() != Node->getFoundDecl()) {
1642 OS << " (";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001643 dumpBareDeclRef(Node->getFoundDecl());
Chandler Carruth8d26bb02011-05-01 23:48:14 +00001644 OS << ")";
1645 }
John McCall351762c2011-02-07 10:33:21 +00001646}
1647
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001648void ASTDumper::VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001649 VisitExpr(Node);
John McCall76d09942009-12-11 21:50:11 +00001650 OS << " (";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001651 if (!Node->requiresADL())
1652 OS << "no ";
Benjamin Kramerb11416d2010-04-17 09:33:03 +00001653 OS << "ADL) = '" << Node->getName() << '\'';
John McCall76d09942009-12-11 21:50:11 +00001654
1655 UnresolvedLookupExpr::decls_iterator
1656 I = Node->decls_begin(), E = Node->decls_end();
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001657 if (I == E)
1658 OS << " empty";
John McCall76d09942009-12-11 21:50:11 +00001659 for (; I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001660 dumpPointer(*I);
John McCall76d09942009-12-11 21:50:11 +00001661}
1662
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001663void ASTDumper::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001664 VisitExpr(Node);
Steve Naroff5d5efca2008-03-12 13:19:12 +00001665
Richard Trieud215b8d2013-01-26 01:31:20 +00001666 {
1667 ColorScope Color(*this, DeclKindNameColor);
1668 OS << " " << Node->getDecl()->getDeclKindName() << "Decl";
1669 }
1670 OS << "='" << *Node->getDecl() << "'";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001671 dumpPointer(Node->getDecl());
Steve Naroffb3424a92008-05-23 22:01:24 +00001672 if (Node->isFreeIvar())
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001673 OS << " isFreeIvar";
Steve Naroff5d5efca2008-03-12 13:19:12 +00001674}
1675
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001676void ASTDumper::VisitPredefinedExpr(const PredefinedExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001677 VisitExpr(Node);
Chris Lattnercbe4f772007-08-08 22:51:59 +00001678 switch (Node->getIdentType()) {
David Blaikie83d382b2011-09-23 05:06:16 +00001679 default: llvm_unreachable("unknown case");
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001680 case PredefinedExpr::Func: OS << " __func__"; break;
1681 case PredefinedExpr::Function: OS << " __FUNCTION__"; break;
David Majnemerbed356a2013-11-06 23:31:56 +00001682 case PredefinedExpr::FuncDName: OS << " __FUNCDNAME__"; break;
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001683 case PredefinedExpr::LFunction: OS << " L__FUNCTION__"; break;
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001684 case PredefinedExpr::PrettyFunction: OS << " __PRETTY_FUNCTION__";break;
Chris Lattnercbe4f772007-08-08 22:51:59 +00001685 }
1686}
1687
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001688void ASTDumper::VisitCharacterLiteral(const CharacterLiteral *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001689 VisitExpr(Node);
Richard Trieud215b8d2013-01-26 01:31:20 +00001690 ColorScope Color(*this, ValueColor);
Richard Trieu364ee422011-11-03 23:56:23 +00001691 OS << " " << Node->getValue();
Chris Lattnercbe4f772007-08-08 22:51:59 +00001692}
1693
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001694void ASTDumper::VisitIntegerLiteral(const IntegerLiteral *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001695 VisitExpr(Node);
Chris Lattnercbe4f772007-08-08 22:51:59 +00001696
1697 bool isSigned = Node->getType()->isSignedIntegerType();
Richard Trieud215b8d2013-01-26 01:31:20 +00001698 ColorScope Color(*this, ValueColor);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001699 OS << " " << Node->getValue().toString(10, isSigned);
Chris Lattnercbe4f772007-08-08 22:51:59 +00001700}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001701
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001702void ASTDumper::VisitFloatingLiteral(const FloatingLiteral *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001703 VisitExpr(Node);
Richard Trieud215b8d2013-01-26 01:31:20 +00001704 ColorScope Color(*this, ValueColor);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001705 OS << " " << Node->getValueAsApproximateDouble();
Chris Lattnercbe4f772007-08-08 22:51:59 +00001706}
Chris Lattner1c20a172007-08-26 03:42:43 +00001707
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001708void ASTDumper::VisitStringLiteral(const StringLiteral *Str) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001709 VisitExpr(Str);
Richard Trieud215b8d2013-01-26 01:31:20 +00001710 ColorScope Color(*this, ValueColor);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001711 OS << " ";
Richard Trieudc355912012-06-13 20:25:24 +00001712 Str->outputString(OS);
Chris Lattnercbe4f772007-08-08 22:51:59 +00001713}
Chris Lattner84ca3762007-08-30 01:00:35 +00001714
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001715void ASTDumper::VisitUnaryOperator(const UnaryOperator *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001716 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001717 OS << " " << (Node->isPostfix() ? "postfix" : "prefix")
1718 << " '" << UnaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
Chris Lattnercbe4f772007-08-08 22:51:59 +00001719}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001720
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001721void ASTDumper::VisitUnaryExprOrTypeTraitExpr(
1722 const UnaryExprOrTypeTraitExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001723 VisitExpr(Node);
Peter Collingbournee190dee2011-03-11 19:24:49 +00001724 switch(Node->getKind()) {
1725 case UETT_SizeOf:
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001726 OS << " sizeof";
Peter Collingbournee190dee2011-03-11 19:24:49 +00001727 break;
1728 case UETT_AlignOf:
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001729 OS << " alignof";
Peter Collingbournee190dee2011-03-11 19:24:49 +00001730 break;
1731 case UETT_VecStep:
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001732 OS << " vec_step";
Peter Collingbournee190dee2011-03-11 19:24:49 +00001733 break;
1734 }
Sebastian Redl6f282892008-11-11 17:56:53 +00001735 if (Node->isArgumentType())
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001736 dumpType(Node->getArgumentType());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001737}
Chris Lattnerdb3b3ff2007-08-09 17:35:30 +00001738
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001739void ASTDumper::VisitMemberExpr(const MemberExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001740 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001741 OS << " " << (Node->isArrow() ? "->" : ".") << *Node->getMemberDecl();
1742 dumpPointer(Node->getMemberDecl());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001743}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001744
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001745void ASTDumper::VisitExtVectorElementExpr(const ExtVectorElementExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001746 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001747 OS << " " << Node->getAccessor().getNameStart();
Chris Lattnercbe4f772007-08-08 22:51:59 +00001748}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001749
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001750void ASTDumper::VisitBinaryOperator(const BinaryOperator *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001751 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001752 OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
Chris Lattner86928112007-08-25 02:00:02 +00001753}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001754
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001755void ASTDumper::VisitCompoundAssignOperator(
1756 const CompoundAssignOperator *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001757 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001758 OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode())
1759 << "' ComputeLHSTy=";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001760 dumpBareType(Node->getComputationLHSType());
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001761 OS << " ComputeResultTy=";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001762 dumpBareType(Node->getComputationResultType());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001763}
Chris Lattnercbe4f772007-08-08 22:51:59 +00001764
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001765void ASTDumper::VisitBlockExpr(const BlockExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001766 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001767 dumpDecl(Node->getBlockDecl());
John McCall351762c2011-02-07 10:33:21 +00001768}
1769
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001770void ASTDumper::VisitOpaqueValueExpr(const OpaqueValueExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001771 VisitExpr(Node);
John McCallfe96e0b2011-11-06 09:01:30 +00001772
Richard Trieude5cc7d2013-01-31 01:44:26 +00001773 if (Expr *Source = Node->getSourceExpr()) {
1774 lastChild();
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001775 dumpStmt(Source);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001776 }
John McCallfe96e0b2011-11-06 09:01:30 +00001777}
1778
Chris Lattnercbe4f772007-08-08 22:51:59 +00001779// GNU extensions.
1780
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001781void ASTDumper::VisitAddrLabelExpr(const AddrLabelExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001782 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001783 OS << " " << Node->getLabel()->getName();
1784 dumpPointer(Node->getLabel());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001785}
1786
Chris Lattner8f184b12007-08-09 18:03:18 +00001787//===----------------------------------------------------------------------===//
1788// C++ Expressions
1789//===----------------------------------------------------------------------===//
Chris Lattnercbe4f772007-08-08 22:51:59 +00001790
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001791void ASTDumper::VisitCXXNamedCastExpr(const CXXNamedCastExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001792 VisitExpr(Node);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001793 OS << " " << Node->getCastName()
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001794 << "<" << Node->getTypeAsWritten().getAsString() << ">"
Anders Carlssona70cff62010-04-24 19:06:50 +00001795 << " <" << Node->getCastKindName();
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001796 dumpBasePath(OS, Node);
Anders Carlssona70cff62010-04-24 19:06:50 +00001797 OS << ">";
Chris Lattnercbe4f772007-08-08 22:51:59 +00001798}
1799
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001800void ASTDumper::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001801 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001802 OS << " " << (Node->getValue() ? "true" : "false");
Chris Lattnercbe4f772007-08-08 22:51:59 +00001803}
1804
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001805void ASTDumper::VisitCXXThisExpr(const CXXThisExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001806 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001807 OS << " this";
Douglas Gregor8ea1f532008-11-04 14:56:14 +00001808}
1809
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001810void ASTDumper::VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001811 VisitExpr(Node);
Eli Friedman29538892011-09-02 17:38:59 +00001812 OS << " functional cast to " << Node->getTypeAsWritten().getAsString()
1813 << " <" << Node->getCastKindName() << ">";
Douglas Gregore200adc2008-10-27 19:41:14 +00001814}
1815
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001816void ASTDumper::VisitCXXConstructExpr(const CXXConstructExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001817 VisitExpr(Node);
John McCalleba90cd2010-02-02 19:03:45 +00001818 CXXConstructorDecl *Ctor = Node->getConstructor();
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001819 dumpType(Ctor->getType());
Anders Carlsson073846832009-08-12 00:21:52 +00001820 if (Node->isElidable())
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001821 OS << " elidable";
John McCall85370042010-08-07 06:38:55 +00001822 if (Node->requiresZeroInitialization())
1823 OS << " zeroing";
Anders Carlsson073846832009-08-12 00:21:52 +00001824}
1825
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001826void ASTDumper::VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001827 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001828 OS << " ";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001829 dumpCXXTemporary(Node->getTemporary());
Anders Carlsson073846832009-08-12 00:21:52 +00001830}
1831
Richard Smithe6c01442013-06-05 00:46:14 +00001832void
1833ASTDumper::VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *Node) {
1834 VisitExpr(Node);
1835 if (const ValueDecl *VD = Node->getExtendingDecl()) {
1836 OS << " extended by ";
1837 dumpBareDeclRef(VD);
1838 }
1839}
1840
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001841void ASTDumper::VisitExprWithCleanups(const ExprWithCleanups *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001842 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001843 for (unsigned i = 0, e = Node->getNumObjects(); i != e; ++i)
1844 dumpDeclRef(Node->getObject(i), "cleanup");
Anders Carlsson073846832009-08-12 00:21:52 +00001845}
1846
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001847void ASTDumper::dumpCXXTemporary(const CXXTemporary *Temporary) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001848 OS << "(CXXTemporary";
1849 dumpPointer(Temporary);
1850 OS << ")";
Anders Carlsson073846832009-08-12 00:21:52 +00001851}
1852
Anders Carlsson76f4a902007-08-21 17:43:55 +00001853//===----------------------------------------------------------------------===//
1854// Obj-C Expressions
1855//===----------------------------------------------------------------------===//
1856
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001857void ASTDumper::VisitObjCMessageExpr(const ObjCMessageExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001858 VisitExpr(Node);
Aaron Ballmanb190f972014-01-03 17:59:55 +00001859 OS << " selector=";
1860 Node->getSelector().print(OS);
Douglas Gregor9a129192010-04-21 00:45:42 +00001861 switch (Node->getReceiverKind()) {
1862 case ObjCMessageExpr::Instance:
1863 break;
1864
1865 case ObjCMessageExpr::Class:
1866 OS << " class=";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001867 dumpBareType(Node->getClassReceiver());
Douglas Gregor9a129192010-04-21 00:45:42 +00001868 break;
1869
1870 case ObjCMessageExpr::SuperInstance:
1871 OS << " super (instance)";
1872 break;
1873
1874 case ObjCMessageExpr::SuperClass:
1875 OS << " super (class)";
1876 break;
1877 }
Ted Kremenek36748da2008-02-29 22:04:05 +00001878}
1879
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001880void ASTDumper::VisitObjCBoxedExpr(const ObjCBoxedExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001881 VisitExpr(Node);
Aaron Ballmanb190f972014-01-03 17:59:55 +00001882 OS << " selector=";
1883 Node->getBoxingMethod()->getSelector().print(OS);
Argyrios Kyrtzidis9dd40892012-05-10 20:02:31 +00001884}
1885
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001886void ASTDumper::VisitObjCAtCatchStmt(const ObjCAtCatchStmt *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001887 VisitStmt(Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001888 if (const VarDecl *CatchParam = Node->getCatchParamDecl())
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001889 dumpDecl(CatchParam);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001890 else
Douglas Gregor96c79492010-04-23 22:50:49 +00001891 OS << " catch all";
Douglas Gregor96c79492010-04-23 22:50:49 +00001892}
1893
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001894void ASTDumper::VisitObjCEncodeExpr(const ObjCEncodeExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001895 VisitExpr(Node);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001896 dumpType(Node->getEncodedType());
Anders Carlssonc5a81eb2007-08-22 15:14:15 +00001897}
1898
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001899void ASTDumper::VisitObjCSelectorExpr(const ObjCSelectorExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001900 VisitExpr(Node);
Mike Stump11289f42009-09-09 15:08:12 +00001901
Aaron Ballmanb190f972014-01-03 17:59:55 +00001902 OS << " ";
1903 Node->getSelector().print(OS);
Fariborz Jahanian4bef4622007-10-16 20:40:23 +00001904}
1905
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001906void ASTDumper::VisitObjCProtocolExpr(const ObjCProtocolExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001907 VisitExpr(Node);
Mike Stump11289f42009-09-09 15:08:12 +00001908
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001909 OS << ' ' << *Node->getProtocol();
Fariborz Jahaniana32aaef2007-10-17 16:58:11 +00001910}
Daniel Dunbar4b8c6db2008-08-30 05:35:15 +00001911
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001912void ASTDumper::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001913 VisitExpr(Node);
John McCallb7bd14f2010-12-02 01:19:52 +00001914 if (Node->isImplicitProperty()) {
Fariborz Jahanian0f0b3022010-12-22 19:46:35 +00001915 OS << " Kind=MethodRef Getter=\"";
1916 if (Node->getImplicitPropertyGetter())
Aaron Ballmanb190f972014-01-03 17:59:55 +00001917 Node->getImplicitPropertyGetter()->getSelector().print(OS);
Fariborz Jahanian0f0b3022010-12-22 19:46:35 +00001918 else
1919 OS << "(null)";
1920
1921 OS << "\" Setter=\"";
John McCallb7bd14f2010-12-02 01:19:52 +00001922 if (ObjCMethodDecl *Setter = Node->getImplicitPropertySetter())
Aaron Ballmanb190f972014-01-03 17:59:55 +00001923 Setter->getSelector().print(OS);
John McCallb7bd14f2010-12-02 01:19:52 +00001924 else
1925 OS << "(null)";
1926 OS << "\"";
1927 } else {
Benjamin Kramerb89514a2011-10-14 18:45:37 +00001928 OS << " Kind=PropertyRef Property=\"" << *Node->getExplicitProperty() <<'"';
John McCallb7bd14f2010-12-02 01:19:52 +00001929 }
Fariborz Jahanian8a1810f2008-11-22 18:39:36 +00001930
Fariborz Jahanian681c0752010-10-14 16:04:05 +00001931 if (Node->isSuperReceiver())
1932 OS << " super";
Argyrios Kyrtzidisab468b02012-03-30 00:19:18 +00001933
1934 OS << " Messaging=";
1935 if (Node->isMessagingGetter() && Node->isMessagingSetter())
1936 OS << "Getter&Setter";
1937 else if (Node->isMessagingGetter())
1938 OS << "Getter";
1939 else if (Node->isMessagingSetter())
1940 OS << "Setter";
Douglas Gregor8ea1f532008-11-04 14:56:14 +00001941}
1942
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001943void ASTDumper::VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001944 VisitExpr(Node);
Ted Kremeneke65b0862012-03-06 20:05:56 +00001945 if (Node->isArraySubscriptRefExpr())
1946 OS << " Kind=ArraySubscript GetterForArray=\"";
1947 else
1948 OS << " Kind=DictionarySubscript GetterForDictionary=\"";
1949 if (Node->getAtIndexMethodDecl())
Aaron Ballmanb190f972014-01-03 17:59:55 +00001950 Node->getAtIndexMethodDecl()->getSelector().print(OS);
Ted Kremeneke65b0862012-03-06 20:05:56 +00001951 else
1952 OS << "(null)";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001953
Ted Kremeneke65b0862012-03-06 20:05:56 +00001954 if (Node->isArraySubscriptRefExpr())
1955 OS << "\" SetterForArray=\"";
1956 else
1957 OS << "\" SetterForDictionary=\"";
1958 if (Node->setAtIndexMethodDecl())
Aaron Ballmanb190f972014-01-03 17:59:55 +00001959 Node->setAtIndexMethodDecl()->getSelector().print(OS);
Ted Kremeneke65b0862012-03-06 20:05:56 +00001960 else
1961 OS << "(null)";
1962}
1963
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001964void ASTDumper::VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001965 VisitExpr(Node);
Ted Kremeneke65b0862012-03-06 20:05:56 +00001966 OS << " " << (Node->getValue() ? "__objc_yes" : "__objc_no");
1967}
1968
Chris Lattnercbe4f772007-08-08 22:51:59 +00001969//===----------------------------------------------------------------------===//
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00001970// Comments
1971//===----------------------------------------------------------------------===//
1972
1973const char *ASTDumper::getCommandName(unsigned CommandID) {
1974 if (Traits)
1975 return Traits->getCommandInfo(CommandID)->Name;
1976 const CommandInfo *Info = CommandTraits::getBuiltinCommandInfo(CommandID);
1977 if (Info)
1978 return Info->Name;
1979 return "<not a builtin command>";
1980}
1981
1982void ASTDumper::dumpFullComment(const FullComment *C) {
1983 if (!C)
1984 return;
1985
1986 FC = C;
1987 dumpComment(C);
1988 FC = 0;
1989}
1990
1991void ASTDumper::dumpComment(const Comment *C) {
1992 IndentScope Indent(*this);
1993
1994 if (!C) {
Richard Trieud215b8d2013-01-26 01:31:20 +00001995 ColorScope Color(*this, NullColor);
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00001996 OS << "<<<NULL>>>";
1997 return;
1998 }
1999
Richard Trieud215b8d2013-01-26 01:31:20 +00002000 {
2001 ColorScope Color(*this, CommentColor);
2002 OS << C->getCommentKindName();
2003 }
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002004 dumpPointer(C);
2005 dumpSourceRange(C->getSourceRange());
2006 ConstCommentVisitor<ASTDumper>::visit(C);
2007 for (Comment::child_iterator I = C->child_begin(), E = C->child_end();
Richard Trieude5cc7d2013-01-31 01:44:26 +00002008 I != E; ++I) {
2009 if (I + 1 == E)
2010 lastChild();
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002011 dumpComment(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +00002012 }
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002013}
2014
2015void ASTDumper::visitTextComment(const TextComment *C) {
2016 OS << " Text=\"" << C->getText() << "\"";
2017}
2018
2019void ASTDumper::visitInlineCommandComment(const InlineCommandComment *C) {
2020 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\"";
2021 switch (C->getRenderKind()) {
2022 case InlineCommandComment::RenderNormal:
2023 OS << " RenderNormal";
2024 break;
2025 case InlineCommandComment::RenderBold:
2026 OS << " RenderBold";
2027 break;
2028 case InlineCommandComment::RenderMonospaced:
2029 OS << " RenderMonospaced";
2030 break;
2031 case InlineCommandComment::RenderEmphasized:
2032 OS << " RenderEmphasized";
2033 break;
2034 }
2035
2036 for (unsigned i = 0, e = C->getNumArgs(); i != e; ++i)
2037 OS << " Arg[" << i << "]=\"" << C->getArgText(i) << "\"";
2038}
2039
2040void ASTDumper::visitHTMLStartTagComment(const HTMLStartTagComment *C) {
2041 OS << " Name=\"" << C->getTagName() << "\"";
2042 if (C->getNumAttrs() != 0) {
2043 OS << " Attrs: ";
2044 for (unsigned i = 0, e = C->getNumAttrs(); i != e; ++i) {
2045 const HTMLStartTagComment::Attribute &Attr = C->getAttr(i);
2046 OS << " \"" << Attr.Name << "=\"" << Attr.Value << "\"";
2047 }
2048 }
2049 if (C->isSelfClosing())
2050 OS << " SelfClosing";
2051}
2052
2053void ASTDumper::visitHTMLEndTagComment(const HTMLEndTagComment *C) {
2054 OS << " Name=\"" << C->getTagName() << "\"";
2055}
2056
2057void ASTDumper::visitBlockCommandComment(const BlockCommandComment *C) {
2058 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\"";
2059 for (unsigned i = 0, e = C->getNumArgs(); i != e; ++i)
2060 OS << " Arg[" << i << "]=\"" << C->getArgText(i) << "\"";
2061}
2062
2063void ASTDumper::visitParamCommandComment(const ParamCommandComment *C) {
2064 OS << " " << ParamCommandComment::getDirectionAsString(C->getDirection());
2065
2066 if (C->isDirectionExplicit())
2067 OS << " explicitly";
2068 else
2069 OS << " implicitly";
2070
2071 if (C->hasParamName()) {
2072 if (C->isParamIndexValid())
2073 OS << " Param=\"" << C->getParamName(FC) << "\"";
2074 else
2075 OS << " Param=\"" << C->getParamNameAsWritten() << "\"";
2076 }
2077
Dmitri Gribenkodbff5c72014-03-19 14:03:47 +00002078 if (C->isParamIndexValid() && !C->isVarArgParam())
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002079 OS << " ParamIndex=" << C->getParamIndex();
2080}
2081
2082void ASTDumper::visitTParamCommandComment(const TParamCommandComment *C) {
2083 if (C->hasParamName()) {
2084 if (C->isPositionValid())
2085 OS << " Param=\"" << C->getParamName(FC) << "\"";
2086 else
2087 OS << " Param=\"" << C->getParamNameAsWritten() << "\"";
2088 }
2089
2090 if (C->isPositionValid()) {
2091 OS << " Position=<";
2092 for (unsigned i = 0, e = C->getDepth(); i != e; ++i) {
2093 OS << C->getIndex(i);
2094 if (i != e - 1)
2095 OS << ", ";
2096 }
2097 OS << ">";
2098 }
2099}
2100
2101void ASTDumper::visitVerbatimBlockComment(const VerbatimBlockComment *C) {
2102 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\""
2103 " CloseName=\"" << C->getCloseName() << "\"";
2104}
2105
2106void ASTDumper::visitVerbatimBlockLineComment(
2107 const VerbatimBlockLineComment *C) {
2108 OS << " Text=\"" << C->getText() << "\"";
2109}
2110
2111void ASTDumper::visitVerbatimLineComment(const VerbatimLineComment *C) {
2112 OS << " Text=\"" << C->getText() << "\"";
2113}
2114
2115//===----------------------------------------------------------------------===//
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002116// Decl method implementations
2117//===----------------------------------------------------------------------===//
2118
Alp Tokeref6b0072014-01-04 13:47:14 +00002119LLVM_DUMP_METHOD void Decl::dump() const { dump(llvm::errs()); }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002120
Alp Tokeref6b0072014-01-04 13:47:14 +00002121LLVM_DUMP_METHOD void Decl::dump(raw_ostream &OS) const {
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002122 ASTDumper P(OS, &getASTContext().getCommentCommandTraits(),
2123 &getASTContext().getSourceManager());
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002124 P.dumpDecl(this);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002125}
2126
Alp Tokeref6b0072014-01-04 13:47:14 +00002127LLVM_DUMP_METHOD void Decl::dumpColor() const {
Richard Trieud215b8d2013-01-26 01:31:20 +00002128 ASTDumper P(llvm::errs(), &getASTContext().getCommentCommandTraits(),
2129 &getASTContext().getSourceManager(), /*ShowColors*/true);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002130 P.dumpDecl(this);
Richard Trieud215b8d2013-01-26 01:31:20 +00002131}
Richard Smith33937e72013-06-22 21:49:40 +00002132
Alp Tokeref6b0072014-01-04 13:47:14 +00002133LLVM_DUMP_METHOD void DeclContext::dumpLookups() const {
Richard Smith6ea05822013-06-24 01:45:33 +00002134 dumpLookups(llvm::errs());
2135}
2136
Alp Tokeref6b0072014-01-04 13:47:14 +00002137LLVM_DUMP_METHOD void DeclContext::dumpLookups(raw_ostream &OS) const {
Richard Smith33937e72013-06-22 21:49:40 +00002138 const DeclContext *DC = this;
2139 while (!DC->isTranslationUnit())
2140 DC = DC->getParent();
2141 ASTContext &Ctx = cast<TranslationUnitDecl>(DC)->getASTContext();
Richard Smith6ea05822013-06-24 01:45:33 +00002142 ASTDumper P(OS, &Ctx.getCommentCommandTraits(), &Ctx.getSourceManager());
Richard Smith33937e72013-06-22 21:49:40 +00002143 P.dumpLookups(this);
2144}
2145
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002146//===----------------------------------------------------------------------===//
Chris Lattnercbe4f772007-08-08 22:51:59 +00002147// Stmt method implementations
2148//===----------------------------------------------------------------------===//
2149
Alp Tokeref6b0072014-01-04 13:47:14 +00002150LLVM_DUMP_METHOD void Stmt::dump(SourceManager &SM) const {
Argyrios Kyrtzidisc049f752010-08-09 10:54:31 +00002151 dump(llvm::errs(), SM);
2152}
2153
Alp Tokeref6b0072014-01-04 13:47:14 +00002154LLVM_DUMP_METHOD void Stmt::dump(raw_ostream &OS, SourceManager &SM) const {
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002155 ASTDumper P(OS, 0, &SM);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002156 P.dumpStmt(this);
Chris Lattner779d5d92007-08-30 00:40:08 +00002157}
2158
Alp Tokeref6b0072014-01-04 13:47:14 +00002159LLVM_DUMP_METHOD void Stmt::dump() const {
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002160 ASTDumper P(llvm::errs(), 0, 0);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002161 P.dumpStmt(this);
Chris Lattnercbe4f772007-08-08 22:51:59 +00002162}
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002163
Alp Tokeref6b0072014-01-04 13:47:14 +00002164LLVM_DUMP_METHOD void Stmt::dumpColor() const {
Richard Trieud215b8d2013-01-26 01:31:20 +00002165 ASTDumper P(llvm::errs(), 0, 0, /*ShowColors*/true);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002166 P.dumpStmt(this);
Richard Trieud215b8d2013-01-26 01:31:20 +00002167}
2168
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002169//===----------------------------------------------------------------------===//
2170// Comment method implementations
2171//===----------------------------------------------------------------------===//
2172
Alp Tokeref6b0072014-01-04 13:47:14 +00002173LLVM_DUMP_METHOD void Comment::dump() const { dump(llvm::errs(), 0, 0); }
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002174
Alp Tokeref6b0072014-01-04 13:47:14 +00002175LLVM_DUMP_METHOD void Comment::dump(const ASTContext &Context) const {
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002176 dump(llvm::errs(), &Context.getCommentCommandTraits(),
2177 &Context.getSourceManager());
2178}
2179
Alexander Kornienko00911f12013-01-15 12:20:21 +00002180void Comment::dump(raw_ostream &OS, const CommandTraits *Traits,
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002181 const SourceManager *SM) const {
2182 const FullComment *FC = dyn_cast<FullComment>(this);
2183 ASTDumper D(OS, Traits, SM);
2184 D.dumpFullComment(FC);
2185}
Richard Trieud215b8d2013-01-26 01:31:20 +00002186
Alp Tokeref6b0072014-01-04 13:47:14 +00002187LLVM_DUMP_METHOD void Comment::dumpColor() const {
Richard Trieud215b8d2013-01-26 01:31:20 +00002188 const FullComment *FC = dyn_cast<FullComment>(this);
2189 ASTDumper D(llvm::errs(), 0, 0, /*ShowColors*/true);
2190 D.dumpFullComment(FC);
2191}