blob: 14e0e0160d7679d34f60fdda30a747f7b0196128 [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:
Craig Topper36250ad2014-05-12 05:36:57 +0000158 ChildDumper(ASTDumper &Dumper) : Dumper(Dumper), Prev(nullptr) {}
Richard Smithdcc2c452014-03-17 23:00:06 +0000159 ~ChildDumper() {
160 if (Prev) {
161 Dumper.lastChild();
Craig Topper36250ad2014-05-12 05:36:57 +0000162 dump(nullptr);
Richard Smithdcc2c452014-03-17 23:00:06 +0000163 }
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().
Craig Topper36250ad2014-05-12 05:36:57 +0000181 void release() { dump(nullptr); }
Richard Smithdcc2c452014-03-17 23:00:06 +0000182 };
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),
Craig Topper36250ad2014-05-12 05:36:57 +0000188 LastLocFilename(""), LastLocLine(~0U), FC(nullptr),
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);
Craig Topper36250ad2014-05-12 05:36:57 +0000219 void dumpDeclRef(const Decl *Node, const char *Label = nullptr);
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) {
Alex McCarthye14ddef2014-05-02 20:24:11 +0000447 if (!SM)
448 return;
449
Richard Trieud215b8d2013-01-26 01:31:20 +0000450 ColorScope Color(*this, LocationColor);
Chris Lattner53e384f2009-01-16 07:00:02 +0000451 SourceLocation SpellingLoc = SM->getSpellingLoc(Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000452
Chris Lattner11e30d32007-08-30 06:17:34 +0000453 // The general format we print out is filename:line:col, but we drop pieces
454 // that haven't changed since the last loc printed.
Chris Lattnerf1ca7d32009-01-27 07:57:44 +0000455 PresumedLoc PLoc = SM->getPresumedLoc(SpellingLoc);
456
Douglas Gregor453b0122010-11-12 07:15:47 +0000457 if (PLoc.isInvalid()) {
458 OS << "<invalid sloc>";
459 return;
460 }
461
Chris Lattnerf1ca7d32009-01-27 07:57:44 +0000462 if (strcmp(PLoc.getFilename(), LastLocFilename) != 0) {
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000463 OS << PLoc.getFilename() << ':' << PLoc.getLine()
464 << ':' << PLoc.getColumn();
Chris Lattnerf1ca7d32009-01-27 07:57:44 +0000465 LastLocFilename = PLoc.getFilename();
466 LastLocLine = PLoc.getLine();
467 } else if (PLoc.getLine() != LastLocLine) {
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000468 OS << "line" << ':' << PLoc.getLine()
469 << ':' << PLoc.getColumn();
Chris Lattnerf1ca7d32009-01-27 07:57:44 +0000470 LastLocLine = PLoc.getLine();
Chris Lattner11e30d32007-08-30 06:17:34 +0000471 } else {
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000472 OS << "col" << ':' << PLoc.getColumn();
Chris Lattner11e30d32007-08-30 06:17:34 +0000473 }
474}
475
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000476void ASTDumper::dumpSourceRange(SourceRange R) {
Chris Lattner11e30d32007-08-30 06:17:34 +0000477 // Can't translate locations if a SourceManager isn't available.
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000478 if (!SM)
479 return;
Mike Stump11289f42009-09-09 15:08:12 +0000480
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000481 OS << " <";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000482 dumpLocation(R.getBegin());
Chris Lattnera7c19fe2007-10-16 22:36:42 +0000483 if (R.getBegin() != R.getEnd()) {
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000484 OS << ", ";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000485 dumpLocation(R.getEnd());
Chris Lattner11e30d32007-08-30 06:17:34 +0000486 }
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000487 OS << ">";
Mike Stump11289f42009-09-09 15:08:12 +0000488
Chris Lattner11e30d32007-08-30 06:17:34 +0000489 // <t2.c:123:421[blah], t2.c:412:321>
490
491}
492
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000493void ASTDumper::dumpBareType(QualType T) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000494 ColorScope Color(*this, TypeColor);
495
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000496 SplitQualType T_split = T.split();
497 OS << "'" << QualType::getAsString(T_split) << "'";
498
499 if (!T.isNull()) {
500 // If the type is sugared, also dump a (shallow) desugared type.
501 SplitQualType D_split = T.getSplitDesugaredType();
502 if (T_split != D_split)
503 OS << ":'" << QualType::getAsString(D_split) << "'";
504 }
505}
506
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000507void ASTDumper::dumpType(QualType T) {
508 OS << ' ';
509 dumpBareType(T);
510}
511
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000512void ASTDumper::dumpBareDeclRef(const Decl *D) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000513 {
514 ColorScope Color(*this, DeclKindNameColor);
515 OS << D->getDeclKindName();
516 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000517 dumpPointer(D);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000518
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000519 if (const NamedDecl *ND = dyn_cast<NamedDecl>(D)) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000520 ColorScope Color(*this, DeclNameColor);
David Blaikied4da8722013-05-14 21:04:00 +0000521 OS << " '" << ND->getDeclName() << '\'';
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000522 }
523
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000524 if (const ValueDecl *VD = dyn_cast<ValueDecl>(D))
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000525 dumpType(VD->getType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000526}
527
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000528void ASTDumper::dumpDeclRef(const Decl *D, const char *Label) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000529 if (!D)
530 return;
531
532 IndentScope Indent(*this);
533 if (Label)
534 OS << Label << ' ';
535 dumpBareDeclRef(D);
536}
537
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000538void ASTDumper::dumpName(const NamedDecl *ND) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000539 if (ND->getDeclName()) {
540 ColorScope Color(*this, DeclNameColor);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000541 OS << ' ' << ND->getNameAsString();
Richard Trieud215b8d2013-01-26 01:31:20 +0000542 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000543}
544
Richard Trieude5cc7d2013-01-31 01:44:26 +0000545bool ASTDumper::hasNodes(const DeclContext *DC) {
546 if (!DC)
547 return false;
548
Richard Smith1d209d02013-05-23 01:49:11 +0000549 return DC->hasExternalLexicalStorage() ||
550 DC->noload_decls_begin() != DC->noload_decls_end();
Richard Trieude5cc7d2013-01-31 01:44:26 +0000551}
552
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000553void ASTDumper::dumpDeclContext(const DeclContext *DC) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000554 if (!DC)
555 return;
Richard Smithdcc2c452014-03-17 23:00:06 +0000556
557 ChildDumper Children(*this);
558 for (auto *D : DC->noload_decls())
559 Children.dump(D);
560
561 if (DC->hasExternalLexicalStorage()) {
562 Children.release();
563
Richard Smith1d209d02013-05-23 01:49:11 +0000564 lastChild();
565 IndentScope Indent(*this);
566 ColorScope Color(*this, UndeserializedColor);
567 OS << "<undeserialized declarations>";
568 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000569}
570
Richard Smith33937e72013-06-22 21:49:40 +0000571void ASTDumper::dumpLookups(const DeclContext *DC) {
572 IndentScope Indent(*this);
573
574 OS << "StoredDeclsMap ";
575 dumpBareDeclRef(cast<Decl>(DC));
576
577 const DeclContext *Primary = DC->getPrimaryContext();
578 if (Primary != DC) {
579 OS << " primary";
580 dumpPointer(cast<Decl>(Primary));
581 }
582
583 bool HasUndeserializedLookups = Primary->hasExternalVisibleStorage();
584
585 DeclContext::all_lookups_iterator I = Primary->noload_lookups_begin(),
586 E = Primary->noload_lookups_end();
587 while (I != E) {
588 DeclarationName Name = I.getLookupName();
589 DeclContextLookupResult R = *I++;
590 if (I == E && !HasUndeserializedLookups)
591 lastChild();
592
593 IndentScope Indent(*this);
594 OS << "DeclarationName ";
595 {
596 ColorScope Color(*this, DeclNameColor);
597 OS << '\'' << Name << '\'';
598 }
599
600 for (DeclContextLookupResult::iterator RI = R.begin(), RE = R.end();
601 RI != RE; ++RI) {
602 if (RI + 1 == RE)
603 lastChild();
604 dumpDeclRef(*RI);
Richard Smith15fc7df2013-10-22 23:50:38 +0000605 if ((*RI)->isHidden())
606 OS << " hidden";
Richard Smith33937e72013-06-22 21:49:40 +0000607 }
608 }
609
610 if (HasUndeserializedLookups) {
611 lastChild();
612 IndentScope Indent(*this);
613 ColorScope Color(*this, UndeserializedColor);
614 OS << "<undeserialized lookups>";
615 }
616}
617
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000618void ASTDumper::dumpAttr(const Attr *A) {
619 IndentScope Indent(*this);
Richard Trieud215b8d2013-01-26 01:31:20 +0000620 {
621 ColorScope Color(*this, AttrColor);
Aaron Ballman36a53502014-01-16 13:03:14 +0000622
Richard Trieud215b8d2013-01-26 01:31:20 +0000623 switch (A->getKind()) {
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000624#define ATTR(X) case attr::X: OS << #X; break;
625#include "clang/Basic/AttrList.inc"
Richard Trieud215b8d2013-01-26 01:31:20 +0000626 default: llvm_unreachable("unexpected attribute kind");
627 }
628 OS << "Attr";
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000629 }
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000630 dumpPointer(A);
631 dumpSourceRange(A->getRange());
632#include "clang/AST/AttrDump.inc"
Aaron Ballman36a53502014-01-16 13:03:14 +0000633 if (A->isImplicit())
634 OS << " Implicit";
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000635}
636
Richard Smith71bec062013-10-15 21:58:30 +0000637static void dumpPreviousDeclImpl(raw_ostream &OS, ...) {}
638
639template<typename T>
640static void dumpPreviousDeclImpl(raw_ostream &OS, const Mergeable<T> *D) {
Rafael Espindola8db352d2013-10-17 15:37:26 +0000641 const T *First = D->getFirstDecl();
Richard Smith71bec062013-10-15 21:58:30 +0000642 if (First != D)
643 OS << " first " << First;
Richard Smithf5f43542013-02-07 01:35:44 +0000644}
645
646template<typename T>
Richard Smith71bec062013-10-15 21:58:30 +0000647static void dumpPreviousDeclImpl(raw_ostream &OS, const Redeclarable<T> *D) {
648 const T *Prev = D->getPreviousDecl();
649 if (Prev)
650 OS << " prev " << Prev;
Richard Smithf5f43542013-02-07 01:35:44 +0000651}
652
Richard Smith71bec062013-10-15 21:58:30 +0000653/// Dump the previous declaration in the redeclaration chain for a declaration,
654/// if any.
655static void dumpPreviousDecl(raw_ostream &OS, const Decl *D) {
Richard Smithf5f43542013-02-07 01:35:44 +0000656 switch (D->getKind()) {
657#define DECL(DERIVED, BASE) \
658 case Decl::DERIVED: \
Richard Smith71bec062013-10-15 21:58:30 +0000659 return dumpPreviousDeclImpl(OS, cast<DERIVED##Decl>(D));
Richard Smithf5f43542013-02-07 01:35:44 +0000660#define ABSTRACT_DECL(DECL)
661#include "clang/AST/DeclNodes.inc"
662 }
663 llvm_unreachable("Decl that isn't part of DeclNodes.inc!");
664}
665
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000666//===----------------------------------------------------------------------===//
667// C++ Utilities
668//===----------------------------------------------------------------------===//
669
670void ASTDumper::dumpAccessSpecifier(AccessSpecifier AS) {
671 switch (AS) {
672 case AS_none:
673 break;
674 case AS_public:
675 OS << "public";
676 break;
677 case AS_protected:
678 OS << "protected";
679 break;
680 case AS_private:
681 OS << "private";
682 break;
683 }
684}
685
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000686void ASTDumper::dumpCXXCtorInitializer(const CXXCtorInitializer *Init) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000687 IndentScope Indent(*this);
688 OS << "CXXCtorInitializer";
689 if (Init->isAnyMemberInitializer()) {
690 OS << ' ';
691 dumpBareDeclRef(Init->getAnyMember());
692 } else {
693 dumpType(QualType(Init->getBaseClass(), 0));
694 }
695 dumpStmt(Init->getInit());
696}
697
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000698void ASTDumper::dumpTemplateParameters(const TemplateParameterList *TPL) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000699 if (!TPL)
700 return;
701
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000702 for (TemplateParameterList::const_iterator I = TPL->begin(), E = TPL->end();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000703 I != E; ++I)
704 dumpDecl(*I);
705}
706
707void ASTDumper::dumpTemplateArgumentListInfo(
708 const TemplateArgumentListInfo &TALI) {
Richard Trieude5cc7d2013-01-31 01:44:26 +0000709 for (unsigned i = 0, e = TALI.size(); i < e; ++i) {
710 if (i + 1 == e)
711 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000712 dumpTemplateArgumentLoc(TALI[i]);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000713 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000714}
715
716void ASTDumper::dumpTemplateArgumentLoc(const TemplateArgumentLoc &A) {
717 dumpTemplateArgument(A.getArgument(), A.getSourceRange());
718}
719
720void ASTDumper::dumpTemplateArgumentList(const TemplateArgumentList &TAL) {
721 for (unsigned i = 0, e = TAL.size(); i < e; ++i)
722 dumpTemplateArgument(TAL[i]);
723}
724
725void ASTDumper::dumpTemplateArgument(const TemplateArgument &A, SourceRange R) {
726 IndentScope Indent(*this);
727 OS << "TemplateArgument";
728 if (R.isValid())
729 dumpSourceRange(R);
730
731 switch (A.getKind()) {
732 case TemplateArgument::Null:
733 OS << " null";
734 break;
735 case TemplateArgument::Type:
736 OS << " type";
Richard Trieude5cc7d2013-01-31 01:44:26 +0000737 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000738 dumpType(A.getAsType());
739 break;
740 case TemplateArgument::Declaration:
741 OS << " decl";
Richard Trieude5cc7d2013-01-31 01:44:26 +0000742 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000743 dumpDeclRef(A.getAsDecl());
744 break;
745 case TemplateArgument::NullPtr:
746 OS << " nullptr";
747 break;
748 case TemplateArgument::Integral:
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000749 OS << " integral " << A.getAsIntegral();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000750 break;
751 case TemplateArgument::Template:
752 OS << " template ";
753 A.getAsTemplate().dump(OS);
754 break;
755 case TemplateArgument::TemplateExpansion:
756 OS << " template expansion";
757 A.getAsTemplateOrTemplatePattern().dump(OS);
758 break;
759 case TemplateArgument::Expression:
760 OS << " expr";
Richard Trieude5cc7d2013-01-31 01:44:26 +0000761 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000762 dumpStmt(A.getAsExpr());
763 break;
764 case TemplateArgument::Pack:
765 OS << " pack";
766 for (TemplateArgument::pack_iterator I = A.pack_begin(), E = A.pack_end();
Richard Trieude5cc7d2013-01-31 01:44:26 +0000767 I != E; ++I) {
768 if (I + 1 == E)
769 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000770 dumpTemplateArgument(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000771 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000772 break;
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000773 }
774}
775
Chris Lattner11e30d32007-08-30 06:17:34 +0000776//===----------------------------------------------------------------------===//
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000777// Decl dumping methods.
Chris Lattnercbe4f772007-08-08 22:51:59 +0000778//===----------------------------------------------------------------------===//
779
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000780void ASTDumper::dumpDecl(const Decl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000781 IndentScope Indent(*this);
Mike Stump11289f42009-09-09 15:08:12 +0000782
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000783 if (!D) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000784 ColorScope Color(*this, NullColor);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000785 OS << "<<<NULL>>>";
786 return;
Chris Lattnercbe4f772007-08-08 22:51:59 +0000787 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000788
Richard Trieud215b8d2013-01-26 01:31:20 +0000789 {
790 ColorScope Color(*this, DeclKindNameColor);
791 OS << D->getDeclKindName() << "Decl";
792 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000793 dumpPointer(D);
Richard Smithf5f43542013-02-07 01:35:44 +0000794 if (D->getLexicalDeclContext() != D->getDeclContext())
795 OS << " parent " << cast<Decl>(D->getDeclContext());
Richard Smith71bec062013-10-15 21:58:30 +0000796 dumpPreviousDecl(OS, D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000797 dumpSourceRange(D->getSourceRange());
David Blaikie5ee3d002014-04-02 05:48:29 +0000798 OS << ' ';
799 dumpLocation(D->getLocation());
Richard Smith15fc7df2013-10-22 23:50:38 +0000800 if (Module *M = D->getOwningModule())
801 OS << " in " << M->getFullModuleName();
802 if (const NamedDecl *ND = dyn_cast<NamedDecl>(D))
803 if (ND->isHidden())
804 OS << " hidden";
Alexander Kornienko83a4e182014-05-27 21:29:22 +0000805 if (D->isImplicit())
806 OS << " implicit";
Richard Trieude5cc7d2013-01-31 01:44:26 +0000807
Aaron Ballmanb97112e2014-03-08 22:19:01 +0000808 bool HasAttrs = D->hasAttrs();
Richard Smithb39b9d52013-05-21 05:24:00 +0000809 const FullComment *Comment =
810 D->getASTContext().getLocalCommentForDeclUncached(D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000811 // Decls within functions are visited by the body
Richard Trieude5cc7d2013-01-31 01:44:26 +0000812 bool HasDeclContext = !isa<FunctionDecl>(*D) && !isa<ObjCMethodDecl>(*D) &&
813 hasNodes(dyn_cast<DeclContext>(D));
814
Richard Smithb39b9d52013-05-21 05:24:00 +0000815 setMoreChildren(HasAttrs || Comment || HasDeclContext);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000816 ConstDeclVisitor<ASTDumper>::Visit(D);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000817
Richard Smithb39b9d52013-05-21 05:24:00 +0000818 setMoreChildren(Comment || HasDeclContext);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000819 for (Decl::attr_iterator I = D->attr_begin(), E = D->attr_end();
820 I != E; ++I) {
821 if (I + 1 == E)
822 lastChild();
823 dumpAttr(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000824 }
825
826 setMoreChildren(HasDeclContext);
827 lastChild();
Richard Smithb39b9d52013-05-21 05:24:00 +0000828 dumpFullComment(Comment);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000829
Nick Lewyckya382db02013-08-27 03:15:56 +0000830 if (D->isInvalidDecl())
831 OS << " invalid";
832
Richard Trieude5cc7d2013-01-31 01:44:26 +0000833 setMoreChildren(false);
834 if (HasDeclContext)
Richard Smithf5f43542013-02-07 01:35:44 +0000835 dumpDeclContext(cast<DeclContext>(D));
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000836}
837
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000838void ASTDumper::VisitLabelDecl(const LabelDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000839 dumpName(D);
840}
841
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000842void ASTDumper::VisitTypedefDecl(const TypedefDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000843 dumpName(D);
844 dumpType(D->getUnderlyingType());
845 if (D->isModulePrivate())
846 OS << " __module_private__";
847}
848
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000849void ASTDumper::VisitEnumDecl(const EnumDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000850 if (D->isScoped()) {
851 if (D->isScopedUsingClassTag())
852 OS << " class";
853 else
854 OS << " struct";
855 }
856 dumpName(D);
857 if (D->isModulePrivate())
858 OS << " __module_private__";
859 if (D->isFixed())
860 dumpType(D->getIntegerType());
861}
862
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000863void ASTDumper::VisitRecordDecl(const RecordDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000864 OS << ' ' << D->getKindName();
865 dumpName(D);
866 if (D->isModulePrivate())
867 OS << " __module_private__";
Richard Smith99bc1b92013-08-30 05:32:29 +0000868 if (D->isCompleteDefinition())
869 OS << " definition";
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000870}
871
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000872void ASTDumper::VisitEnumConstantDecl(const EnumConstantDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000873 dumpName(D);
874 dumpType(D->getType());
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000875 if (const Expr *Init = D->getInitExpr()) {
Richard Trieude5cc7d2013-01-31 01:44:26 +0000876 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000877 dumpStmt(Init);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000878 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000879}
880
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000881void ASTDumper::VisitIndirectFieldDecl(const IndirectFieldDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000882 dumpName(D);
883 dumpType(D->getType());
Richard Smithdcc2c452014-03-17 23:00:06 +0000884
885 ChildDumper Children(*this);
Richard Smith8aa49222014-03-18 00:35:12 +0000886 for (auto *Child : D->chain())
887 Children.dumpRef(Child);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000888}
889
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000890void ASTDumper::VisitFunctionDecl(const FunctionDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000891 dumpName(D);
892 dumpType(D->getType());
893
Rafael Espindola6ae7e502013-04-03 19:27:57 +0000894 StorageClass SC = D->getStorageClass();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000895 if (SC != SC_None)
896 OS << ' ' << VarDecl::getStorageClassSpecifierString(SC);
897 if (D->isInlineSpecified())
898 OS << " inline";
899 if (D->isVirtualAsWritten())
900 OS << " virtual";
901 if (D->isModulePrivate())
902 OS << " __module_private__";
903
904 if (D->isPure())
905 OS << " pure";
906 else if (D->isDeletedAsWritten())
907 OS << " delete";
908
Richard Smithadaa0152013-05-17 02:09:46 +0000909 if (const FunctionProtoType *FPT = D->getType()->getAs<FunctionProtoType>()) {
910 FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo();
911 switch (EPI.ExceptionSpecType) {
912 default: break;
913 case EST_Unevaluated:
914 OS << " noexcept-unevaluated " << EPI.ExceptionSpecDecl;
915 break;
916 case EST_Uninstantiated:
917 OS << " noexcept-uninstantiated " << EPI.ExceptionSpecTemplate;
918 break;
919 }
920 }
921
Richard Trieude5cc7d2013-01-31 01:44:26 +0000922 bool OldMoreChildren = hasMoreChildren();
923 const FunctionTemplateSpecializationInfo *FTSI =
924 D->getTemplateSpecializationInfo();
925 bool HasTemplateSpecialization = FTSI;
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000926
Richard Trieude5cc7d2013-01-31 01:44:26 +0000927 bool HasNamedDecls = D->getDeclsInPrototypeScope().begin() !=
928 D->getDeclsInPrototypeScope().end();
929
930 bool HasFunctionDecls = D->param_begin() != D->param_end();
931
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000932 const CXXConstructorDecl *C = dyn_cast<CXXConstructorDecl>(D);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000933 bool HasCtorInitializers = C && C->init_begin() != C->init_end();
934
935 bool HasDeclarationBody = D->doesThisDeclarationHaveABody();
936
937 setMoreChildren(OldMoreChildren || HasNamedDecls || HasFunctionDecls ||
938 HasCtorInitializers || HasDeclarationBody);
939 if (HasTemplateSpecialization) {
940 lastChild();
941 dumpTemplateArgumentList(*FTSI->TemplateArguments);
942 }
943
944 setMoreChildren(OldMoreChildren || HasFunctionDecls ||
945 HasCtorInitializers || HasDeclarationBody);
Dmitri Gribenkof8579502013-01-12 19:30:44 +0000946 for (ArrayRef<NamedDecl *>::iterator
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000947 I = D->getDeclsInPrototypeScope().begin(),
Richard Trieude5cc7d2013-01-31 01:44:26 +0000948 E = D->getDeclsInPrototypeScope().end(); I != E; ++I) {
949 if (I + 1 == E)
950 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000951 dumpDecl(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000952 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000953
Richard Trieude5cc7d2013-01-31 01:44:26 +0000954 setMoreChildren(OldMoreChildren || HasCtorInitializers || HasDeclarationBody);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000955 for (FunctionDecl::param_const_iterator I = D->param_begin(),
956 E = D->param_end();
Richard Trieude5cc7d2013-01-31 01:44:26 +0000957 I != E; ++I) {
958 if (I + 1 == E)
959 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000960 dumpDecl(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000961 }
962
963 setMoreChildren(OldMoreChildren || HasDeclarationBody);
964 if (HasCtorInitializers)
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000965 for (CXXConstructorDecl::init_const_iterator I = C->init_begin(),
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000966 E = C->init_end();
967 I != E; ++I) {
Richard Trieude5cc7d2013-01-31 01:44:26 +0000968 if (I + 1 == E)
969 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000970 dumpCXXCtorInitializer(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000971 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000972
Richard Trieude5cc7d2013-01-31 01:44:26 +0000973 setMoreChildren(OldMoreChildren);
974 if (HasDeclarationBody) {
975 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000976 dumpStmt(D->getBody());
Richard Trieude5cc7d2013-01-31 01:44:26 +0000977 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000978}
979
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000980void ASTDumper::VisitFieldDecl(const FieldDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000981 dumpName(D);
982 dumpType(D->getType());
983 if (D->isMutable())
984 OS << " mutable";
985 if (D->isModulePrivate())
986 OS << " __module_private__";
Richard Trieude5cc7d2013-01-31 01:44:26 +0000987
988 bool OldMoreChildren = hasMoreChildren();
989 bool IsBitField = D->isBitField();
990 Expr *Init = D->getInClassInitializer();
991 bool HasInit = Init;
992
993 setMoreChildren(OldMoreChildren || HasInit);
994 if (IsBitField) {
995 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000996 dumpStmt(D->getBitWidth());
Richard Trieude5cc7d2013-01-31 01:44:26 +0000997 }
998 setMoreChildren(OldMoreChildren);
999 if (HasInit) {
1000 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001001 dumpStmt(Init);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001002 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001003}
1004
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001005void ASTDumper::VisitVarDecl(const VarDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001006 dumpName(D);
1007 dumpType(D->getType());
Rafael Espindola6ae7e502013-04-03 19:27:57 +00001008 StorageClass SC = D->getStorageClass();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001009 if (SC != SC_None)
1010 OS << ' ' << VarDecl::getStorageClassSpecifierString(SC);
Richard Smithfd3834f2013-04-13 02:43:54 +00001011 switch (D->getTLSKind()) {
1012 case VarDecl::TLS_None: break;
1013 case VarDecl::TLS_Static: OS << " tls"; break;
1014 case VarDecl::TLS_Dynamic: OS << " tls_dynamic"; break;
1015 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001016 if (D->isModulePrivate())
1017 OS << " __module_private__";
1018 if (D->isNRVOVariable())
1019 OS << " nrvo";
Richard Trieude5cc7d2013-01-31 01:44:26 +00001020 if (D->hasInit()) {
1021 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001022 dumpStmt(D->getInit());
Richard Trieude5cc7d2013-01-31 01:44:26 +00001023 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001024}
1025
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001026void ASTDumper::VisitFileScopeAsmDecl(const FileScopeAsmDecl *D) {
Richard Trieude5cc7d2013-01-31 01:44:26 +00001027 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001028 dumpStmt(D->getAsmString());
1029}
1030
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001031void ASTDumper::VisitImportDecl(const ImportDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001032 OS << ' ' << D->getImportedModule()->getFullModuleName();
1033}
1034
1035//===----------------------------------------------------------------------===//
1036// C++ Declarations
1037//===----------------------------------------------------------------------===//
1038
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001039void ASTDumper::VisitNamespaceDecl(const NamespaceDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001040 dumpName(D);
1041 if (D->isInline())
1042 OS << " inline";
1043 if (!D->isOriginalNamespace())
1044 dumpDeclRef(D->getOriginalNamespace(), "original");
1045}
1046
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001047void ASTDumper::VisitUsingDirectiveDecl(const UsingDirectiveDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001048 OS << ' ';
1049 dumpBareDeclRef(D->getNominatedNamespace());
1050}
1051
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001052void ASTDumper::VisitNamespaceAliasDecl(const NamespaceAliasDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001053 dumpName(D);
1054 dumpDeclRef(D->getAliasedNamespace());
1055}
1056
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001057void ASTDumper::VisitTypeAliasDecl(const TypeAliasDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001058 dumpName(D);
1059 dumpType(D->getUnderlyingType());
1060}
1061
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001062void ASTDumper::VisitTypeAliasTemplateDecl(const TypeAliasTemplateDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001063 dumpName(D);
1064 dumpTemplateParameters(D->getTemplateParameters());
1065 dumpDecl(D->getTemplatedDecl());
1066}
1067
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001068void ASTDumper::VisitCXXRecordDecl(const CXXRecordDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001069 VisitRecordDecl(D);
1070 if (!D->isCompleteDefinition())
1071 return;
1072
Aaron Ballman574705e2014-03-13 15:41:46 +00001073 for (const auto &I : D->bases()) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001074 IndentScope Indent(*this);
Aaron Ballman574705e2014-03-13 15:41:46 +00001075 if (I.isVirtual())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001076 OS << "virtual ";
Aaron Ballman574705e2014-03-13 15:41:46 +00001077 dumpAccessSpecifier(I.getAccessSpecifier());
1078 dumpType(I.getType());
1079 if (I.isPackExpansion())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001080 OS << "...";
1081 }
1082}
1083
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001084void ASTDumper::VisitStaticAssertDecl(const StaticAssertDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001085 dumpStmt(D->getAssertExpr());
Richard Trieude5cc7d2013-01-31 01:44:26 +00001086 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001087 dumpStmt(D->getMessage());
1088}
1089
Richard Smithcbdf7332014-03-18 02:07:28 +00001090template<typename SpecializationDecl>
1091void ASTDumper::VisitTemplateDeclSpecialization(ChildDumper &Children,
1092 const SpecializationDecl *D,
1093 bool DumpExplicitInst,
1094 bool DumpRefOnly) {
1095 bool DumpedAny = false;
1096 for (auto *RedeclWithBadType : D->redecls()) {
1097 // FIXME: The redecls() range sometimes has elements of a less-specific
1098 // type. (In particular, ClassTemplateSpecializationDecl::redecls() gives
1099 // us TagDecls, and should give CXXRecordDecls).
1100 auto *Redecl = dyn_cast<SpecializationDecl>(RedeclWithBadType);
1101 if (!Redecl) {
1102 // Found the injected-class-name for a class template. This will be dumped
1103 // as part of its surrounding class so we don't need to dump it here.
1104 assert(isa<CXXRecordDecl>(RedeclWithBadType) &&
1105 "expected an injected-class-name");
1106 continue;
1107 }
1108
1109 switch (Redecl->getTemplateSpecializationKind()) {
1110 case TSK_ExplicitInstantiationDeclaration:
1111 case TSK_ExplicitInstantiationDefinition:
1112 if (!DumpExplicitInst)
1113 break;
1114 // Fall through.
1115 case TSK_Undeclared:
1116 case TSK_ImplicitInstantiation:
1117 Children.dump(Redecl, DumpRefOnly);
1118 DumpedAny = true;
1119 break;
1120 case TSK_ExplicitSpecialization:
1121 break;
1122 }
1123 }
1124
1125 // Ensure we dump at least one decl for each specialization.
1126 if (!DumpedAny)
1127 Children.dumpRef(D);
1128}
1129
Richard Smith20ade552014-03-17 23:34:53 +00001130template<typename TemplateDecl>
1131void ASTDumper::VisitTemplateDecl(const TemplateDecl *D,
1132 bool DumpExplicitInst) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001133 dumpName(D);
1134 dumpTemplateParameters(D->getTemplateParameters());
Richard Smithdcc2c452014-03-17 23:00:06 +00001135
1136 ChildDumper Children(*this);
1137 Children.dump(D->getTemplatedDecl());
1138
Richard Smithcbdf7332014-03-18 02:07:28 +00001139 for (auto *Child : D->specializations())
1140 VisitTemplateDeclSpecialization(Children, Child, DumpExplicitInst,
1141 !D->isCanonicalDecl());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001142}
1143
Richard Smith20ade552014-03-17 23:34:53 +00001144void ASTDumper::VisitFunctionTemplateDecl(const FunctionTemplateDecl *D) {
1145 // FIXME: We don't add a declaration of a function template specialization
1146 // to its context when it's explicitly instantiated, so dump explicit
1147 // instantiations when we dump the template itself.
1148 VisitTemplateDecl(D, true);
1149}
1150
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001151void ASTDumper::VisitClassTemplateDecl(const ClassTemplateDecl *D) {
Richard Smith20ade552014-03-17 23:34:53 +00001152 VisitTemplateDecl(D, false);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001153}
1154
1155void ASTDumper::VisitClassTemplateSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001156 const ClassTemplateSpecializationDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001157 VisitCXXRecordDecl(D);
1158 dumpTemplateArgumentList(D->getTemplateArgs());
1159}
1160
1161void ASTDumper::VisitClassTemplatePartialSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001162 const ClassTemplatePartialSpecializationDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001163 VisitClassTemplateSpecializationDecl(D);
1164 dumpTemplateParameters(D->getTemplateParameters());
1165}
1166
1167void ASTDumper::VisitClassScopeFunctionSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001168 const ClassScopeFunctionSpecializationDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001169 dumpDeclRef(D->getSpecialization());
1170 if (D->hasExplicitTemplateArgs())
1171 dumpTemplateArgumentListInfo(D->templateArgs());
1172}
1173
Richard Smithd25789a2013-09-18 01:36:02 +00001174void ASTDumper::VisitVarTemplateDecl(const VarTemplateDecl *D) {
Richard Smith20ade552014-03-17 23:34:53 +00001175 VisitTemplateDecl(D, false);
Richard Smithd25789a2013-09-18 01:36:02 +00001176}
1177
1178void ASTDumper::VisitVarTemplateSpecializationDecl(
1179 const VarTemplateSpecializationDecl *D) {
1180 dumpTemplateArgumentList(D->getTemplateArgs());
1181 VisitVarDecl(D);
1182}
1183
1184void ASTDumper::VisitVarTemplatePartialSpecializationDecl(
1185 const VarTemplatePartialSpecializationDecl *D) {
1186 dumpTemplateParameters(D->getTemplateParameters());
1187 VisitVarTemplateSpecializationDecl(D);
1188}
1189
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001190void ASTDumper::VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001191 if (D->wasDeclaredWithTypename())
1192 OS << " typename";
1193 else
1194 OS << " class";
1195 if (D->isParameterPack())
1196 OS << " ...";
1197 dumpName(D);
Richard Smithecf74ff2014-03-23 20:50:39 +00001198 if (D->hasDefaultArgument()) {
1199 lastChild();
1200 dumpTemplateArgument(D->getDefaultArgument());
1201 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001202}
1203
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001204void ASTDumper::VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001205 dumpType(D->getType());
1206 if (D->isParameterPack())
1207 OS << " ...";
1208 dumpName(D);
Richard Smithecf74ff2014-03-23 20:50:39 +00001209 if (D->hasDefaultArgument()) {
1210 lastChild();
1211 dumpTemplateArgument(D->getDefaultArgument());
1212 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001213}
1214
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001215void ASTDumper::VisitTemplateTemplateParmDecl(
1216 const TemplateTemplateParmDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001217 if (D->isParameterPack())
1218 OS << " ...";
1219 dumpName(D);
1220 dumpTemplateParameters(D->getTemplateParameters());
Richard Smithecf74ff2014-03-23 20:50:39 +00001221 if (D->hasDefaultArgument()) {
1222 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001223 dumpTemplateArgumentLoc(D->getDefaultArgument());
Richard Smithecf74ff2014-03-23 20:50:39 +00001224 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001225}
1226
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001227void ASTDumper::VisitUsingDecl(const UsingDecl *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::VisitUnresolvedUsingTypenameDecl(
1234 const UnresolvedUsingTypenameDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001235 OS << ' ';
1236 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
1237 OS << D->getNameAsString();
1238}
1239
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001240void ASTDumper::VisitUnresolvedUsingValueDecl(const UnresolvedUsingValueDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001241 OS << ' ';
1242 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
1243 OS << D->getNameAsString();
1244 dumpType(D->getType());
1245}
1246
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001247void ASTDumper::VisitUsingShadowDecl(const UsingShadowDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001248 OS << ' ';
1249 dumpBareDeclRef(D->getTargetDecl());
1250}
1251
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001252void ASTDumper::VisitLinkageSpecDecl(const LinkageSpecDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001253 switch (D->getLanguage()) {
1254 case LinkageSpecDecl::lang_c: OS << " C"; break;
1255 case LinkageSpecDecl::lang_cxx: OS << " C++"; break;
1256 }
1257}
1258
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001259void ASTDumper::VisitAccessSpecDecl(const AccessSpecDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001260 OS << ' ';
1261 dumpAccessSpecifier(D->getAccess());
1262}
1263
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001264void ASTDumper::VisitFriendDecl(const FriendDecl *D) {
Richard Smithf5f43542013-02-07 01:35:44 +00001265 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001266 if (TypeSourceInfo *T = D->getFriendType())
1267 dumpType(T->getType());
1268 else
1269 dumpDecl(D->getFriendDecl());
1270}
1271
1272//===----------------------------------------------------------------------===//
1273// Obj-C Declarations
1274//===----------------------------------------------------------------------===//
1275
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001276void ASTDumper::VisitObjCIvarDecl(const ObjCIvarDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001277 dumpName(D);
1278 dumpType(D->getType());
1279 if (D->getSynthesize())
1280 OS << " synthesize";
1281
1282 switch (D->getAccessControl()) {
1283 case ObjCIvarDecl::None:
1284 OS << " none";
1285 break;
1286 case ObjCIvarDecl::Private:
1287 OS << " private";
1288 break;
1289 case ObjCIvarDecl::Protected:
1290 OS << " protected";
1291 break;
1292 case ObjCIvarDecl::Public:
1293 OS << " public";
1294 break;
1295 case ObjCIvarDecl::Package:
1296 OS << " package";
1297 break;
1298 }
1299}
1300
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001301void ASTDumper::VisitObjCMethodDecl(const ObjCMethodDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001302 if (D->isInstanceMethod())
1303 OS << " -";
1304 else
1305 OS << " +";
1306 dumpName(D);
Alp Toker314cc812014-01-25 16:55:45 +00001307 dumpType(D->getReturnType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001308
Richard Trieude5cc7d2013-01-31 01:44:26 +00001309 bool OldMoreChildren = hasMoreChildren();
1310 bool IsVariadic = D->isVariadic();
1311 bool HasBody = D->hasBody();
1312
1313 setMoreChildren(OldMoreChildren || IsVariadic || HasBody);
1314 if (D->isThisDeclarationADefinition()) {
1315 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001316 dumpDeclContext(D);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001317 } else {
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001318 for (ObjCMethodDecl::param_const_iterator I = D->param_begin(),
1319 E = D->param_end();
1320 I != E; ++I) {
Richard Trieude5cc7d2013-01-31 01:44:26 +00001321 if (I + 1 == E)
1322 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001323 dumpDecl(*I);
1324 }
1325 }
1326
Richard Trieude5cc7d2013-01-31 01:44:26 +00001327 setMoreChildren(OldMoreChildren || HasBody);
1328 if (IsVariadic) {
1329 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001330 IndentScope Indent(*this);
1331 OS << "...";
1332 }
1333
Richard Trieude5cc7d2013-01-31 01:44:26 +00001334 setMoreChildren(OldMoreChildren);
1335 if (HasBody) {
1336 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001337 dumpStmt(D->getBody());
Richard Trieude5cc7d2013-01-31 01:44:26 +00001338 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001339}
1340
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001341void ASTDumper::VisitObjCCategoryDecl(const ObjCCategoryDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001342 dumpName(D);
1343 dumpDeclRef(D->getClassInterface());
Richard Trieude5cc7d2013-01-31 01:44:26 +00001344 if (D->protocol_begin() == D->protocol_end())
1345 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001346 dumpDeclRef(D->getImplementation());
1347 for (ObjCCategoryDecl::protocol_iterator I = D->protocol_begin(),
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001348 E = D->protocol_end();
1349 I != E; ++I) {
Richard Trieude5cc7d2013-01-31 01:44:26 +00001350 if (I + 1 == E)
1351 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001352 dumpDeclRef(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001353 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001354}
1355
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001356void ASTDumper::VisitObjCCategoryImplDecl(const ObjCCategoryImplDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001357 dumpName(D);
1358 dumpDeclRef(D->getClassInterface());
Richard Trieude5cc7d2013-01-31 01:44:26 +00001359 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001360 dumpDeclRef(D->getCategoryDecl());
1361}
1362
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001363void ASTDumper::VisitObjCProtocolDecl(const ObjCProtocolDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001364 dumpName(D);
Richard Smithdcc2c452014-03-17 23:00:06 +00001365
1366 ChildDumper Children(*this);
Richard Smith7fcb35f2014-03-18 02:37:59 +00001367 for (auto *Child : D->protocols())
1368 Children.dumpRef(Child);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001369}
1370
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001371void ASTDumper::VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001372 dumpName(D);
1373 dumpDeclRef(D->getSuperClass(), "super");
Richard Smithdcc2c452014-03-17 23:00:06 +00001374
1375 ChildDumper Children(*this);
1376 Children.dumpRef(D->getImplementation());
Richard Smith7fcb35f2014-03-18 02:37:59 +00001377 for (auto *Child : D->protocols())
1378 Children.dumpRef(Child);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001379}
1380
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001381void ASTDumper::VisitObjCImplementationDecl(const ObjCImplementationDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001382 dumpName(D);
1383 dumpDeclRef(D->getSuperClass(), "super");
Richard Trieude5cc7d2013-01-31 01:44:26 +00001384 if (D->init_begin() == D->init_end())
1385 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001386 dumpDeclRef(D->getClassInterface());
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001387 for (ObjCImplementationDecl::init_const_iterator I = D->init_begin(),
1388 E = D->init_end();
1389 I != E; ++I) {
Richard Trieude5cc7d2013-01-31 01:44:26 +00001390 if (I + 1 == E)
1391 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001392 dumpCXXCtorInitializer(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001393 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001394}
1395
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001396void ASTDumper::VisitObjCCompatibleAliasDecl(const ObjCCompatibleAliasDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001397 dumpName(D);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001398 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001399 dumpDeclRef(D->getClassInterface());
1400}
1401
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001402void ASTDumper::VisitObjCPropertyDecl(const ObjCPropertyDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001403 dumpName(D);
1404 dumpType(D->getType());
1405
1406 if (D->getPropertyImplementation() == ObjCPropertyDecl::Required)
1407 OS << " required";
1408 else if (D->getPropertyImplementation() == ObjCPropertyDecl::Optional)
1409 OS << " optional";
1410
1411 ObjCPropertyDecl::PropertyAttributeKind Attrs = D->getPropertyAttributes();
1412 if (Attrs != ObjCPropertyDecl::OBJC_PR_noattr) {
1413 if (Attrs & ObjCPropertyDecl::OBJC_PR_readonly)
1414 OS << " readonly";
1415 if (Attrs & ObjCPropertyDecl::OBJC_PR_assign)
1416 OS << " assign";
1417 if (Attrs & ObjCPropertyDecl::OBJC_PR_readwrite)
1418 OS << " readwrite";
1419 if (Attrs & ObjCPropertyDecl::OBJC_PR_retain)
1420 OS << " retain";
1421 if (Attrs & ObjCPropertyDecl::OBJC_PR_copy)
1422 OS << " copy";
1423 if (Attrs & ObjCPropertyDecl::OBJC_PR_nonatomic)
1424 OS << " nonatomic";
1425 if (Attrs & ObjCPropertyDecl::OBJC_PR_atomic)
1426 OS << " atomic";
1427 if (Attrs & ObjCPropertyDecl::OBJC_PR_weak)
1428 OS << " weak";
1429 if (Attrs & ObjCPropertyDecl::OBJC_PR_strong)
1430 OS << " strong";
1431 if (Attrs & ObjCPropertyDecl::OBJC_PR_unsafe_unretained)
1432 OS << " unsafe_unretained";
Richard Trieude5cc7d2013-01-31 01:44:26 +00001433 if (Attrs & ObjCPropertyDecl::OBJC_PR_getter) {
1434 if (!(Attrs & ObjCPropertyDecl::OBJC_PR_setter))
1435 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001436 dumpDeclRef(D->getGetterMethodDecl(), "getter");
Richard Trieude5cc7d2013-01-31 01:44:26 +00001437 }
1438 if (Attrs & ObjCPropertyDecl::OBJC_PR_setter) {
1439 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001440 dumpDeclRef(D->getSetterMethodDecl(), "setter");
Richard Trieude5cc7d2013-01-31 01:44:26 +00001441 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001442 }
1443}
1444
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001445void ASTDumper::VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001446 dumpName(D->getPropertyDecl());
1447 if (D->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize)
1448 OS << " synthesize";
1449 else
1450 OS << " dynamic";
1451 dumpDeclRef(D->getPropertyDecl());
Richard Trieude5cc7d2013-01-31 01:44:26 +00001452 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001453 dumpDeclRef(D->getPropertyIvarDecl());
1454}
1455
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001456void ASTDumper::VisitBlockDecl(const BlockDecl *D) {
Aaron Ballmanb2b8b1d2014-03-07 16:09:59 +00001457 for (auto I : D->params())
1458 dumpDecl(I);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001459
1460 if (D->isVariadic()) {
1461 IndentScope Indent(*this);
1462 OS << "...";
1463 }
1464
1465 if (D->capturesCXXThis()) {
1466 IndentScope Indent(*this);
1467 OS << "capture this";
1468 }
Aaron Ballman9371dd22014-03-14 18:34:04 +00001469 for (const auto &I : D->captures()) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001470 IndentScope Indent(*this);
1471 OS << "capture";
Aaron Ballman9371dd22014-03-14 18:34:04 +00001472 if (I.isByRef())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001473 OS << " byref";
Aaron Ballman9371dd22014-03-14 18:34:04 +00001474 if (I.isNested())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001475 OS << " nested";
Aaron Ballman9371dd22014-03-14 18:34:04 +00001476 if (I.getVariable()) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001477 OS << ' ';
Aaron Ballman9371dd22014-03-14 18:34:04 +00001478 dumpBareDeclRef(I.getVariable());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001479 }
Aaron Ballman9371dd22014-03-14 18:34:04 +00001480 if (I.hasCopyExpr())
1481 dumpStmt(I.getCopyExpr());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001482 }
Richard Trieude5cc7d2013-01-31 01:44:26 +00001483 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001484 dumpStmt(D->getBody());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001485}
1486
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001487//===----------------------------------------------------------------------===//
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001488// Stmt dumping methods.
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001489//===----------------------------------------------------------------------===//
1490
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001491void ASTDumper::dumpStmt(const Stmt *S) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001492 IndentScope Indent(*this);
1493
1494 if (!S) {
Richard Trieud215b8d2013-01-26 01:31:20 +00001495 ColorScope Color(*this, NullColor);
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001496 OS << "<<<NULL>>>";
1497 return;
1498 }
1499
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001500 if (const DeclStmt *DS = dyn_cast<DeclStmt>(S)) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001501 VisitDeclStmt(DS);
1502 return;
1503 }
1504
David Blaikie7d170102013-05-15 07:37:26 +00001505 setMoreChildren(!S->children().empty());
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001506 ConstStmtVisitor<ASTDumper>::Visit(S);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001507 setMoreChildren(false);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001508 for (Stmt::const_child_range CI = S->children(); CI; ++CI) {
1509 Stmt::const_child_range Next = CI;
Richard Trieude5cc7d2013-01-31 01:44:26 +00001510 ++Next;
1511 if (!Next)
1512 lastChild();
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001513 dumpStmt(*CI);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001514 }
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001515}
1516
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001517void ASTDumper::VisitStmt(const Stmt *Node) {
Richard Trieud215b8d2013-01-26 01:31:20 +00001518 {
1519 ColorScope Color(*this, StmtColor);
1520 OS << Node->getStmtClassName();
1521 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001522 dumpPointer(Node);
1523 dumpSourceRange(Node->getSourceRange());
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001524}
1525
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001526void ASTDumper::VisitDeclStmt(const DeclStmt *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001527 VisitStmt(Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001528 for (DeclStmt::const_decl_iterator I = Node->decl_begin(),
1529 E = Node->decl_end();
Richard Trieude5cc7d2013-01-31 01:44:26 +00001530 I != E; ++I) {
1531 if (I + 1 == E)
1532 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001533 dumpDecl(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001534 }
Ted Kremenek433a4922007-12-12 06:59:42 +00001535}
1536
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001537void ASTDumper::VisitAttributedStmt(const AttributedStmt *Node) {
Alexander Kornienko5bc364e2013-01-07 17:53:08 +00001538 VisitStmt(Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001539 for (ArrayRef<const Attr *>::iterator I = Node->getAttrs().begin(),
1540 E = Node->getAttrs().end();
1541 I != E; ++I) {
Richard Trieude5cc7d2013-01-31 01:44:26 +00001542 if (I + 1 == E)
1543 lastChild();
Alexander Kornienko5bc364e2013-01-07 17:53:08 +00001544 dumpAttr(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001545 }
Alexander Kornienko5bc364e2013-01-07 17:53:08 +00001546}
1547
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001548void ASTDumper::VisitLabelStmt(const LabelStmt *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001549 VisitStmt(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001550 OS << " '" << Node->getName() << "'";
Chris Lattnercbe4f772007-08-08 22:51:59 +00001551}
1552
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001553void ASTDumper::VisitGotoStmt(const GotoStmt *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001554 VisitStmt(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001555 OS << " '" << Node->getLabel()->getName() << "'";
1556 dumpPointer(Node->getLabel());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001557}
1558
Pavel Labath1ef83422013-09-04 14:35:00 +00001559void ASTDumper::VisitCXXCatchStmt(const CXXCatchStmt *Node) {
1560 VisitStmt(Node);
1561 dumpDecl(Node->getExceptionDecl());
1562}
1563
Chris Lattnercbe4f772007-08-08 22:51:59 +00001564//===----------------------------------------------------------------------===//
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001565// Expr dumping methods.
Chris Lattnercbe4f772007-08-08 22:51:59 +00001566//===----------------------------------------------------------------------===//
1567
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001568void ASTDumper::VisitExpr(const Expr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001569 VisitStmt(Node);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001570 dumpType(Node->getType());
1571
Richard Trieud215b8d2013-01-26 01:31:20 +00001572 {
1573 ColorScope Color(*this, ValueKindColor);
1574 switch (Node->getValueKind()) {
1575 case VK_RValue:
1576 break;
1577 case VK_LValue:
1578 OS << " lvalue";
1579 break;
1580 case VK_XValue:
1581 OS << " xvalue";
1582 break;
1583 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001584 }
1585
Richard Trieud215b8d2013-01-26 01:31:20 +00001586 {
1587 ColorScope Color(*this, ObjectKindColor);
1588 switch (Node->getObjectKind()) {
1589 case OK_Ordinary:
1590 break;
1591 case OK_BitField:
1592 OS << " bitfield";
1593 break;
1594 case OK_ObjCProperty:
1595 OS << " objcproperty";
1596 break;
1597 case OK_ObjCSubscript:
1598 OS << " objcsubscript";
1599 break;
1600 case OK_VectorComponent:
1601 OS << " vectorcomponent";
1602 break;
1603 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001604 }
Chris Lattnercbe4f772007-08-08 22:51:59 +00001605}
1606
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001607static void dumpBasePath(raw_ostream &OS, const CastExpr *Node) {
John McCallcf142162010-08-07 06:22:56 +00001608 if (Node->path_empty())
Anders Carlssona70cff62010-04-24 19:06:50 +00001609 return;
1610
1611 OS << " (";
1612 bool First = true;
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001613 for (CastExpr::path_const_iterator I = Node->path_begin(),
1614 E = Node->path_end();
1615 I != E; ++I) {
Anders Carlssona70cff62010-04-24 19:06:50 +00001616 const CXXBaseSpecifier *Base = *I;
1617 if (!First)
1618 OS << " -> ";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001619
Anders Carlssona70cff62010-04-24 19:06:50 +00001620 const CXXRecordDecl *RD =
1621 cast<CXXRecordDecl>(Base->getType()->getAs<RecordType>()->getDecl());
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001622
Anders Carlssona70cff62010-04-24 19:06:50 +00001623 if (Base->isVirtual())
1624 OS << "virtual ";
1625 OS << RD->getName();
1626 First = false;
1627 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001628
Anders Carlssona70cff62010-04-24 19:06:50 +00001629 OS << ')';
1630}
1631
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001632void ASTDumper::VisitCastExpr(const CastExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001633 VisitExpr(Node);
Richard Trieud215b8d2013-01-26 01:31:20 +00001634 OS << " <";
1635 {
1636 ColorScope Color(*this, CastColor);
1637 OS << Node->getCastKindName();
1638 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001639 dumpBasePath(OS, Node);
Anders Carlssona70cff62010-04-24 19:06:50 +00001640 OS << ">";
Anders Carlssond7923c62009-08-22 23:33:40 +00001641}
1642
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001643void ASTDumper::VisitDeclRefExpr(const DeclRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001644 VisitExpr(Node);
Ted Kremenek5f64ca82007-09-10 17:32:55 +00001645
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001646 OS << " ";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001647 dumpBareDeclRef(Node->getDecl());
Chandler Carruth8d26bb02011-05-01 23:48:14 +00001648 if (Node->getDecl() != Node->getFoundDecl()) {
1649 OS << " (";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001650 dumpBareDeclRef(Node->getFoundDecl());
Chandler Carruth8d26bb02011-05-01 23:48:14 +00001651 OS << ")";
1652 }
John McCall351762c2011-02-07 10:33:21 +00001653}
1654
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001655void ASTDumper::VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001656 VisitExpr(Node);
John McCall76d09942009-12-11 21:50:11 +00001657 OS << " (";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001658 if (!Node->requiresADL())
1659 OS << "no ";
Benjamin Kramerb11416d2010-04-17 09:33:03 +00001660 OS << "ADL) = '" << Node->getName() << '\'';
John McCall76d09942009-12-11 21:50:11 +00001661
1662 UnresolvedLookupExpr::decls_iterator
1663 I = Node->decls_begin(), E = Node->decls_end();
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001664 if (I == E)
1665 OS << " empty";
John McCall76d09942009-12-11 21:50:11 +00001666 for (; I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001667 dumpPointer(*I);
John McCall76d09942009-12-11 21:50:11 +00001668}
1669
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001670void ASTDumper::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001671 VisitExpr(Node);
Steve Naroff5d5efca2008-03-12 13:19:12 +00001672
Richard Trieud215b8d2013-01-26 01:31:20 +00001673 {
1674 ColorScope Color(*this, DeclKindNameColor);
1675 OS << " " << Node->getDecl()->getDeclKindName() << "Decl";
1676 }
1677 OS << "='" << *Node->getDecl() << "'";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001678 dumpPointer(Node->getDecl());
Steve Naroffb3424a92008-05-23 22:01:24 +00001679 if (Node->isFreeIvar())
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001680 OS << " isFreeIvar";
Steve Naroff5d5efca2008-03-12 13:19:12 +00001681}
1682
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001683void ASTDumper::VisitPredefinedExpr(const PredefinedExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001684 VisitExpr(Node);
Chris Lattnercbe4f772007-08-08 22:51:59 +00001685 switch (Node->getIdentType()) {
David Blaikie83d382b2011-09-23 05:06:16 +00001686 default: llvm_unreachable("unknown case");
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001687 case PredefinedExpr::Func: OS << " __func__"; break;
1688 case PredefinedExpr::Function: OS << " __FUNCTION__"; break;
David Majnemerbed356a2013-11-06 23:31:56 +00001689 case PredefinedExpr::FuncDName: OS << " __FUNCDNAME__"; break;
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001690 case PredefinedExpr::LFunction: OS << " L__FUNCTION__"; break;
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001691 case PredefinedExpr::PrettyFunction: OS << " __PRETTY_FUNCTION__";break;
Reid Kleckner52eddda2014-04-08 18:13:24 +00001692 case PredefinedExpr::FuncSig: OS << " __FUNCSIG__"; break;
Chris Lattnercbe4f772007-08-08 22:51:59 +00001693 }
1694}
1695
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001696void ASTDumper::VisitCharacterLiteral(const CharacterLiteral *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001697 VisitExpr(Node);
Richard Trieud215b8d2013-01-26 01:31:20 +00001698 ColorScope Color(*this, ValueColor);
Richard Trieu364ee422011-11-03 23:56:23 +00001699 OS << " " << Node->getValue();
Chris Lattnercbe4f772007-08-08 22:51:59 +00001700}
1701
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001702void ASTDumper::VisitIntegerLiteral(const IntegerLiteral *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001703 VisitExpr(Node);
Chris Lattnercbe4f772007-08-08 22:51:59 +00001704
1705 bool isSigned = Node->getType()->isSignedIntegerType();
Richard Trieud215b8d2013-01-26 01:31:20 +00001706 ColorScope Color(*this, ValueColor);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001707 OS << " " << Node->getValue().toString(10, isSigned);
Chris Lattnercbe4f772007-08-08 22:51:59 +00001708}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001709
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001710void ASTDumper::VisitFloatingLiteral(const FloatingLiteral *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001711 VisitExpr(Node);
Richard Trieud215b8d2013-01-26 01:31:20 +00001712 ColorScope Color(*this, ValueColor);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001713 OS << " " << Node->getValueAsApproximateDouble();
Chris Lattnercbe4f772007-08-08 22:51:59 +00001714}
Chris Lattner1c20a172007-08-26 03:42:43 +00001715
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001716void ASTDumper::VisitStringLiteral(const StringLiteral *Str) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001717 VisitExpr(Str);
Richard Trieud215b8d2013-01-26 01:31:20 +00001718 ColorScope Color(*this, ValueColor);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001719 OS << " ";
Richard Trieudc355912012-06-13 20:25:24 +00001720 Str->outputString(OS);
Chris Lattnercbe4f772007-08-08 22:51:59 +00001721}
Chris Lattner84ca3762007-08-30 01:00:35 +00001722
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001723void ASTDumper::VisitUnaryOperator(const UnaryOperator *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001724 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001725 OS << " " << (Node->isPostfix() ? "postfix" : "prefix")
1726 << " '" << UnaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
Chris Lattnercbe4f772007-08-08 22:51:59 +00001727}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001728
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001729void ASTDumper::VisitUnaryExprOrTypeTraitExpr(
1730 const UnaryExprOrTypeTraitExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001731 VisitExpr(Node);
Peter Collingbournee190dee2011-03-11 19:24:49 +00001732 switch(Node->getKind()) {
1733 case UETT_SizeOf:
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001734 OS << " sizeof";
Peter Collingbournee190dee2011-03-11 19:24:49 +00001735 break;
1736 case UETT_AlignOf:
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001737 OS << " alignof";
Peter Collingbournee190dee2011-03-11 19:24:49 +00001738 break;
1739 case UETT_VecStep:
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001740 OS << " vec_step";
Peter Collingbournee190dee2011-03-11 19:24:49 +00001741 break;
1742 }
Sebastian Redl6f282892008-11-11 17:56:53 +00001743 if (Node->isArgumentType())
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001744 dumpType(Node->getArgumentType());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001745}
Chris Lattnerdb3b3ff2007-08-09 17:35:30 +00001746
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001747void ASTDumper::VisitMemberExpr(const MemberExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001748 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001749 OS << " " << (Node->isArrow() ? "->" : ".") << *Node->getMemberDecl();
1750 dumpPointer(Node->getMemberDecl());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001751}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001752
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001753void ASTDumper::VisitExtVectorElementExpr(const ExtVectorElementExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001754 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001755 OS << " " << Node->getAccessor().getNameStart();
Chris Lattnercbe4f772007-08-08 22:51:59 +00001756}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001757
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001758void ASTDumper::VisitBinaryOperator(const BinaryOperator *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001759 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001760 OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
Chris Lattner86928112007-08-25 02:00:02 +00001761}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001762
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001763void ASTDumper::VisitCompoundAssignOperator(
1764 const CompoundAssignOperator *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001765 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001766 OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode())
1767 << "' ComputeLHSTy=";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001768 dumpBareType(Node->getComputationLHSType());
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001769 OS << " ComputeResultTy=";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001770 dumpBareType(Node->getComputationResultType());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001771}
Chris Lattnercbe4f772007-08-08 22:51:59 +00001772
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001773void ASTDumper::VisitBlockExpr(const BlockExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001774 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001775 dumpDecl(Node->getBlockDecl());
John McCall351762c2011-02-07 10:33:21 +00001776}
1777
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001778void ASTDumper::VisitOpaqueValueExpr(const OpaqueValueExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001779 VisitExpr(Node);
John McCallfe96e0b2011-11-06 09:01:30 +00001780
Richard Trieude5cc7d2013-01-31 01:44:26 +00001781 if (Expr *Source = Node->getSourceExpr()) {
1782 lastChild();
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001783 dumpStmt(Source);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001784 }
John McCallfe96e0b2011-11-06 09:01:30 +00001785}
1786
Chris Lattnercbe4f772007-08-08 22:51:59 +00001787// GNU extensions.
1788
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001789void ASTDumper::VisitAddrLabelExpr(const AddrLabelExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001790 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001791 OS << " " << Node->getLabel()->getName();
1792 dumpPointer(Node->getLabel());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001793}
1794
Chris Lattner8f184b12007-08-09 18:03:18 +00001795//===----------------------------------------------------------------------===//
1796// C++ Expressions
1797//===----------------------------------------------------------------------===//
Chris Lattnercbe4f772007-08-08 22:51:59 +00001798
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001799void ASTDumper::VisitCXXNamedCastExpr(const CXXNamedCastExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001800 VisitExpr(Node);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001801 OS << " " << Node->getCastName()
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001802 << "<" << Node->getTypeAsWritten().getAsString() << ">"
Anders Carlssona70cff62010-04-24 19:06:50 +00001803 << " <" << Node->getCastKindName();
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001804 dumpBasePath(OS, Node);
Anders Carlssona70cff62010-04-24 19:06:50 +00001805 OS << ">";
Chris Lattnercbe4f772007-08-08 22:51:59 +00001806}
1807
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001808void ASTDumper::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001809 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001810 OS << " " << (Node->getValue() ? "true" : "false");
Chris Lattnercbe4f772007-08-08 22:51:59 +00001811}
1812
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001813void ASTDumper::VisitCXXThisExpr(const CXXThisExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001814 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001815 OS << " this";
Douglas Gregor8ea1f532008-11-04 14:56:14 +00001816}
1817
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001818void ASTDumper::VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001819 VisitExpr(Node);
Eli Friedman29538892011-09-02 17:38:59 +00001820 OS << " functional cast to " << Node->getTypeAsWritten().getAsString()
1821 << " <" << Node->getCastKindName() << ">";
Douglas Gregore200adc2008-10-27 19:41:14 +00001822}
1823
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001824void ASTDumper::VisitCXXConstructExpr(const CXXConstructExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001825 VisitExpr(Node);
John McCalleba90cd2010-02-02 19:03:45 +00001826 CXXConstructorDecl *Ctor = Node->getConstructor();
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001827 dumpType(Ctor->getType());
Anders Carlsson073846832009-08-12 00:21:52 +00001828 if (Node->isElidable())
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001829 OS << " elidable";
John McCall85370042010-08-07 06:38:55 +00001830 if (Node->requiresZeroInitialization())
1831 OS << " zeroing";
Anders Carlsson073846832009-08-12 00:21:52 +00001832}
1833
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001834void ASTDumper::VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001835 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001836 OS << " ";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001837 dumpCXXTemporary(Node->getTemporary());
Anders Carlsson073846832009-08-12 00:21:52 +00001838}
1839
Richard Smithe6c01442013-06-05 00:46:14 +00001840void
1841ASTDumper::VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *Node) {
1842 VisitExpr(Node);
1843 if (const ValueDecl *VD = Node->getExtendingDecl()) {
1844 OS << " extended by ";
1845 dumpBareDeclRef(VD);
1846 }
1847}
1848
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001849void ASTDumper::VisitExprWithCleanups(const ExprWithCleanups *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001850 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001851 for (unsigned i = 0, e = Node->getNumObjects(); i != e; ++i)
1852 dumpDeclRef(Node->getObject(i), "cleanup");
Anders Carlsson073846832009-08-12 00:21:52 +00001853}
1854
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001855void ASTDumper::dumpCXXTemporary(const CXXTemporary *Temporary) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001856 OS << "(CXXTemporary";
1857 dumpPointer(Temporary);
1858 OS << ")";
Anders Carlsson073846832009-08-12 00:21:52 +00001859}
1860
Anders Carlsson76f4a902007-08-21 17:43:55 +00001861//===----------------------------------------------------------------------===//
1862// Obj-C Expressions
1863//===----------------------------------------------------------------------===//
1864
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001865void ASTDumper::VisitObjCMessageExpr(const ObjCMessageExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001866 VisitExpr(Node);
Aaron Ballmanb190f972014-01-03 17:59:55 +00001867 OS << " selector=";
1868 Node->getSelector().print(OS);
Douglas Gregor9a129192010-04-21 00:45:42 +00001869 switch (Node->getReceiverKind()) {
1870 case ObjCMessageExpr::Instance:
1871 break;
1872
1873 case ObjCMessageExpr::Class:
1874 OS << " class=";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001875 dumpBareType(Node->getClassReceiver());
Douglas Gregor9a129192010-04-21 00:45:42 +00001876 break;
1877
1878 case ObjCMessageExpr::SuperInstance:
1879 OS << " super (instance)";
1880 break;
1881
1882 case ObjCMessageExpr::SuperClass:
1883 OS << " super (class)";
1884 break;
1885 }
Ted Kremenek36748da2008-02-29 22:04:05 +00001886}
1887
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001888void ASTDumper::VisitObjCBoxedExpr(const ObjCBoxedExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001889 VisitExpr(Node);
Aaron Ballmanb190f972014-01-03 17:59:55 +00001890 OS << " selector=";
1891 Node->getBoxingMethod()->getSelector().print(OS);
Argyrios Kyrtzidis9dd40892012-05-10 20:02:31 +00001892}
1893
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001894void ASTDumper::VisitObjCAtCatchStmt(const ObjCAtCatchStmt *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001895 VisitStmt(Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001896 if (const VarDecl *CatchParam = Node->getCatchParamDecl())
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001897 dumpDecl(CatchParam);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001898 else
Douglas Gregor96c79492010-04-23 22:50:49 +00001899 OS << " catch all";
Douglas Gregor96c79492010-04-23 22:50:49 +00001900}
1901
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001902void ASTDumper::VisitObjCEncodeExpr(const ObjCEncodeExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001903 VisitExpr(Node);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001904 dumpType(Node->getEncodedType());
Anders Carlssonc5a81eb2007-08-22 15:14:15 +00001905}
1906
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001907void ASTDumper::VisitObjCSelectorExpr(const ObjCSelectorExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001908 VisitExpr(Node);
Mike Stump11289f42009-09-09 15:08:12 +00001909
Aaron Ballmanb190f972014-01-03 17:59:55 +00001910 OS << " ";
1911 Node->getSelector().print(OS);
Fariborz Jahanian4bef4622007-10-16 20:40:23 +00001912}
1913
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001914void ASTDumper::VisitObjCProtocolExpr(const ObjCProtocolExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001915 VisitExpr(Node);
Mike Stump11289f42009-09-09 15:08:12 +00001916
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001917 OS << ' ' << *Node->getProtocol();
Fariborz Jahaniana32aaef2007-10-17 16:58:11 +00001918}
Daniel Dunbar4b8c6db2008-08-30 05:35:15 +00001919
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001920void ASTDumper::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001921 VisitExpr(Node);
John McCallb7bd14f2010-12-02 01:19:52 +00001922 if (Node->isImplicitProperty()) {
Fariborz Jahanian0f0b3022010-12-22 19:46:35 +00001923 OS << " Kind=MethodRef Getter=\"";
1924 if (Node->getImplicitPropertyGetter())
Aaron Ballmanb190f972014-01-03 17:59:55 +00001925 Node->getImplicitPropertyGetter()->getSelector().print(OS);
Fariborz Jahanian0f0b3022010-12-22 19:46:35 +00001926 else
1927 OS << "(null)";
1928
1929 OS << "\" Setter=\"";
John McCallb7bd14f2010-12-02 01:19:52 +00001930 if (ObjCMethodDecl *Setter = Node->getImplicitPropertySetter())
Aaron Ballmanb190f972014-01-03 17:59:55 +00001931 Setter->getSelector().print(OS);
John McCallb7bd14f2010-12-02 01:19:52 +00001932 else
1933 OS << "(null)";
1934 OS << "\"";
1935 } else {
Benjamin Kramerb89514a2011-10-14 18:45:37 +00001936 OS << " Kind=PropertyRef Property=\"" << *Node->getExplicitProperty() <<'"';
John McCallb7bd14f2010-12-02 01:19:52 +00001937 }
Fariborz Jahanian8a1810f2008-11-22 18:39:36 +00001938
Fariborz Jahanian681c0752010-10-14 16:04:05 +00001939 if (Node->isSuperReceiver())
1940 OS << " super";
Argyrios Kyrtzidisab468b02012-03-30 00:19:18 +00001941
1942 OS << " Messaging=";
1943 if (Node->isMessagingGetter() && Node->isMessagingSetter())
1944 OS << "Getter&Setter";
1945 else if (Node->isMessagingGetter())
1946 OS << "Getter";
1947 else if (Node->isMessagingSetter())
1948 OS << "Setter";
Douglas Gregor8ea1f532008-11-04 14:56:14 +00001949}
1950
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001951void ASTDumper::VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001952 VisitExpr(Node);
Ted Kremeneke65b0862012-03-06 20:05:56 +00001953 if (Node->isArraySubscriptRefExpr())
1954 OS << " Kind=ArraySubscript GetterForArray=\"";
1955 else
1956 OS << " Kind=DictionarySubscript GetterForDictionary=\"";
1957 if (Node->getAtIndexMethodDecl())
Aaron Ballmanb190f972014-01-03 17:59:55 +00001958 Node->getAtIndexMethodDecl()->getSelector().print(OS);
Ted Kremeneke65b0862012-03-06 20:05:56 +00001959 else
1960 OS << "(null)";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001961
Ted Kremeneke65b0862012-03-06 20:05:56 +00001962 if (Node->isArraySubscriptRefExpr())
1963 OS << "\" SetterForArray=\"";
1964 else
1965 OS << "\" SetterForDictionary=\"";
1966 if (Node->setAtIndexMethodDecl())
Aaron Ballmanb190f972014-01-03 17:59:55 +00001967 Node->setAtIndexMethodDecl()->getSelector().print(OS);
Ted Kremeneke65b0862012-03-06 20:05:56 +00001968 else
1969 OS << "(null)";
1970}
1971
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001972void ASTDumper::VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001973 VisitExpr(Node);
Ted Kremeneke65b0862012-03-06 20:05:56 +00001974 OS << " " << (Node->getValue() ? "__objc_yes" : "__objc_no");
1975}
1976
Chris Lattnercbe4f772007-08-08 22:51:59 +00001977//===----------------------------------------------------------------------===//
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00001978// Comments
1979//===----------------------------------------------------------------------===//
1980
1981const char *ASTDumper::getCommandName(unsigned CommandID) {
1982 if (Traits)
1983 return Traits->getCommandInfo(CommandID)->Name;
1984 const CommandInfo *Info = CommandTraits::getBuiltinCommandInfo(CommandID);
1985 if (Info)
1986 return Info->Name;
1987 return "<not a builtin command>";
1988}
1989
1990void ASTDumper::dumpFullComment(const FullComment *C) {
1991 if (!C)
1992 return;
1993
1994 FC = C;
1995 dumpComment(C);
Craig Topper36250ad2014-05-12 05:36:57 +00001996 FC = nullptr;
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00001997}
1998
1999void ASTDumper::dumpComment(const Comment *C) {
2000 IndentScope Indent(*this);
2001
2002 if (!C) {
Richard Trieud215b8d2013-01-26 01:31:20 +00002003 ColorScope Color(*this, NullColor);
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002004 OS << "<<<NULL>>>";
2005 return;
2006 }
2007
Richard Trieud215b8d2013-01-26 01:31:20 +00002008 {
2009 ColorScope Color(*this, CommentColor);
2010 OS << C->getCommentKindName();
2011 }
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002012 dumpPointer(C);
2013 dumpSourceRange(C->getSourceRange());
2014 ConstCommentVisitor<ASTDumper>::visit(C);
2015 for (Comment::child_iterator I = C->child_begin(), E = C->child_end();
Richard Trieude5cc7d2013-01-31 01:44:26 +00002016 I != E; ++I) {
2017 if (I + 1 == E)
2018 lastChild();
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002019 dumpComment(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +00002020 }
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002021}
2022
2023void ASTDumper::visitTextComment(const TextComment *C) {
2024 OS << " Text=\"" << C->getText() << "\"";
2025}
2026
2027void ASTDumper::visitInlineCommandComment(const InlineCommandComment *C) {
2028 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\"";
2029 switch (C->getRenderKind()) {
2030 case InlineCommandComment::RenderNormal:
2031 OS << " RenderNormal";
2032 break;
2033 case InlineCommandComment::RenderBold:
2034 OS << " RenderBold";
2035 break;
2036 case InlineCommandComment::RenderMonospaced:
2037 OS << " RenderMonospaced";
2038 break;
2039 case InlineCommandComment::RenderEmphasized:
2040 OS << " RenderEmphasized";
2041 break;
2042 }
2043
2044 for (unsigned i = 0, e = C->getNumArgs(); i != e; ++i)
2045 OS << " Arg[" << i << "]=\"" << C->getArgText(i) << "\"";
2046}
2047
2048void ASTDumper::visitHTMLStartTagComment(const HTMLStartTagComment *C) {
2049 OS << " Name=\"" << C->getTagName() << "\"";
2050 if (C->getNumAttrs() != 0) {
2051 OS << " Attrs: ";
2052 for (unsigned i = 0, e = C->getNumAttrs(); i != e; ++i) {
2053 const HTMLStartTagComment::Attribute &Attr = C->getAttr(i);
2054 OS << " \"" << Attr.Name << "=\"" << Attr.Value << "\"";
2055 }
2056 }
2057 if (C->isSelfClosing())
2058 OS << " SelfClosing";
2059}
2060
2061void ASTDumper::visitHTMLEndTagComment(const HTMLEndTagComment *C) {
2062 OS << " Name=\"" << C->getTagName() << "\"";
2063}
2064
2065void ASTDumper::visitBlockCommandComment(const BlockCommandComment *C) {
2066 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\"";
2067 for (unsigned i = 0, e = C->getNumArgs(); i != e; ++i)
2068 OS << " Arg[" << i << "]=\"" << C->getArgText(i) << "\"";
2069}
2070
2071void ASTDumper::visitParamCommandComment(const ParamCommandComment *C) {
2072 OS << " " << ParamCommandComment::getDirectionAsString(C->getDirection());
2073
2074 if (C->isDirectionExplicit())
2075 OS << " explicitly";
2076 else
2077 OS << " implicitly";
2078
2079 if (C->hasParamName()) {
2080 if (C->isParamIndexValid())
2081 OS << " Param=\"" << C->getParamName(FC) << "\"";
2082 else
2083 OS << " Param=\"" << C->getParamNameAsWritten() << "\"";
2084 }
2085
Dmitri Gribenkodbff5c72014-03-19 14:03:47 +00002086 if (C->isParamIndexValid() && !C->isVarArgParam())
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002087 OS << " ParamIndex=" << C->getParamIndex();
2088}
2089
2090void ASTDumper::visitTParamCommandComment(const TParamCommandComment *C) {
2091 if (C->hasParamName()) {
2092 if (C->isPositionValid())
2093 OS << " Param=\"" << C->getParamName(FC) << "\"";
2094 else
2095 OS << " Param=\"" << C->getParamNameAsWritten() << "\"";
2096 }
2097
2098 if (C->isPositionValid()) {
2099 OS << " Position=<";
2100 for (unsigned i = 0, e = C->getDepth(); i != e; ++i) {
2101 OS << C->getIndex(i);
2102 if (i != e - 1)
2103 OS << ", ";
2104 }
2105 OS << ">";
2106 }
2107}
2108
2109void ASTDumper::visitVerbatimBlockComment(const VerbatimBlockComment *C) {
2110 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\""
2111 " CloseName=\"" << C->getCloseName() << "\"";
2112}
2113
2114void ASTDumper::visitVerbatimBlockLineComment(
2115 const VerbatimBlockLineComment *C) {
2116 OS << " Text=\"" << C->getText() << "\"";
2117}
2118
2119void ASTDumper::visitVerbatimLineComment(const VerbatimLineComment *C) {
2120 OS << " Text=\"" << C->getText() << "\"";
2121}
2122
2123//===----------------------------------------------------------------------===//
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002124// Decl method implementations
2125//===----------------------------------------------------------------------===//
2126
Alp Tokeref6b0072014-01-04 13:47:14 +00002127LLVM_DUMP_METHOD void Decl::dump() const { dump(llvm::errs()); }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002128
Alp Tokeref6b0072014-01-04 13:47:14 +00002129LLVM_DUMP_METHOD void Decl::dump(raw_ostream &OS) const {
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002130 ASTDumper P(OS, &getASTContext().getCommentCommandTraits(),
2131 &getASTContext().getSourceManager());
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002132 P.dumpDecl(this);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002133}
2134
Alp Tokeref6b0072014-01-04 13:47:14 +00002135LLVM_DUMP_METHOD void Decl::dumpColor() const {
Richard Trieud215b8d2013-01-26 01:31:20 +00002136 ASTDumper P(llvm::errs(), &getASTContext().getCommentCommandTraits(),
2137 &getASTContext().getSourceManager(), /*ShowColors*/true);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002138 P.dumpDecl(this);
Richard Trieud215b8d2013-01-26 01:31:20 +00002139}
Richard Smith33937e72013-06-22 21:49:40 +00002140
Alp Tokeref6b0072014-01-04 13:47:14 +00002141LLVM_DUMP_METHOD void DeclContext::dumpLookups() const {
Richard Smith6ea05822013-06-24 01:45:33 +00002142 dumpLookups(llvm::errs());
2143}
2144
Alp Tokeref6b0072014-01-04 13:47:14 +00002145LLVM_DUMP_METHOD void DeclContext::dumpLookups(raw_ostream &OS) const {
Richard Smith33937e72013-06-22 21:49:40 +00002146 const DeclContext *DC = this;
2147 while (!DC->isTranslationUnit())
2148 DC = DC->getParent();
2149 ASTContext &Ctx = cast<TranslationUnitDecl>(DC)->getASTContext();
Richard Smith6ea05822013-06-24 01:45:33 +00002150 ASTDumper P(OS, &Ctx.getCommentCommandTraits(), &Ctx.getSourceManager());
Richard Smith33937e72013-06-22 21:49:40 +00002151 P.dumpLookups(this);
2152}
2153
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002154//===----------------------------------------------------------------------===//
Chris Lattnercbe4f772007-08-08 22:51:59 +00002155// Stmt method implementations
2156//===----------------------------------------------------------------------===//
2157
Alp Tokeref6b0072014-01-04 13:47:14 +00002158LLVM_DUMP_METHOD void Stmt::dump(SourceManager &SM) const {
Argyrios Kyrtzidisc049f752010-08-09 10:54:31 +00002159 dump(llvm::errs(), SM);
2160}
2161
Alp Tokeref6b0072014-01-04 13:47:14 +00002162LLVM_DUMP_METHOD void Stmt::dump(raw_ostream &OS, SourceManager &SM) const {
Craig Topper36250ad2014-05-12 05:36:57 +00002163 ASTDumper P(OS, nullptr, &SM);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002164 P.dumpStmt(this);
Chris Lattner779d5d92007-08-30 00:40:08 +00002165}
2166
Alp Tokeref6b0072014-01-04 13:47:14 +00002167LLVM_DUMP_METHOD void Stmt::dump() const {
Craig Topper36250ad2014-05-12 05:36:57 +00002168 ASTDumper P(llvm::errs(), nullptr, nullptr);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002169 P.dumpStmt(this);
Chris Lattnercbe4f772007-08-08 22:51:59 +00002170}
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002171
Alp Tokeref6b0072014-01-04 13:47:14 +00002172LLVM_DUMP_METHOD void Stmt::dumpColor() const {
Craig Topper36250ad2014-05-12 05:36:57 +00002173 ASTDumper P(llvm::errs(), nullptr, nullptr, /*ShowColors*/true);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002174 P.dumpStmt(this);
Richard Trieud215b8d2013-01-26 01:31:20 +00002175}
2176
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002177//===----------------------------------------------------------------------===//
2178// Comment method implementations
2179//===----------------------------------------------------------------------===//
2180
Craig Topper36250ad2014-05-12 05:36:57 +00002181LLVM_DUMP_METHOD void Comment::dump() const {
2182 dump(llvm::errs(), nullptr, nullptr);
2183}
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002184
Alp Tokeref6b0072014-01-04 13:47:14 +00002185LLVM_DUMP_METHOD void Comment::dump(const ASTContext &Context) const {
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002186 dump(llvm::errs(), &Context.getCommentCommandTraits(),
2187 &Context.getSourceManager());
2188}
2189
Alexander Kornienko00911f12013-01-15 12:20:21 +00002190void Comment::dump(raw_ostream &OS, const CommandTraits *Traits,
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002191 const SourceManager *SM) const {
2192 const FullComment *FC = dyn_cast<FullComment>(this);
2193 ASTDumper D(OS, Traits, SM);
2194 D.dumpFullComment(FC);
2195}
Richard Trieud215b8d2013-01-26 01:31:20 +00002196
Alp Tokeref6b0072014-01-04 13:47:14 +00002197LLVM_DUMP_METHOD void Comment::dumpColor() const {
Richard Trieud215b8d2013-01-26 01:31:20 +00002198 const FullComment *FC = dyn_cast<FullComment>(this);
Craig Topper36250ad2014-05-12 05:36:57 +00002199 ASTDumper D(llvm::errs(), nullptr, nullptr, /*ShowColors*/true);
Richard Trieud215b8d2013-01-26 01:31:20 +00002200 D.dumpFullComment(FC);
2201}