blob: 9ece41d4b309ab5fb468caac3ce314d704561950 [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);
Richard Smithf0514962014-06-03 08:24:28 +0000318 void VisitInitListExpr(const InitListExpr *ILE);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000319 void VisitUnaryOperator(const UnaryOperator *Node);
320 void VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *Node);
321 void VisitMemberExpr(const MemberExpr *Node);
322 void VisitExtVectorElementExpr(const ExtVectorElementExpr *Node);
323 void VisitBinaryOperator(const BinaryOperator *Node);
324 void VisitCompoundAssignOperator(const CompoundAssignOperator *Node);
325 void VisitAddrLabelExpr(const AddrLabelExpr *Node);
326 void VisitBlockExpr(const BlockExpr *Node);
327 void VisitOpaqueValueExpr(const OpaqueValueExpr *Node);
Chris Lattner84ca3762007-08-30 01:00:35 +0000328
329 // C++
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000330 void VisitCXXNamedCastExpr(const CXXNamedCastExpr *Node);
331 void VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *Node);
332 void VisitCXXThisExpr(const CXXThisExpr *Node);
333 void VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *Node);
334 void VisitCXXConstructExpr(const CXXConstructExpr *Node);
335 void VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *Node);
Richard Smithe6c01442013-06-05 00:46:14 +0000336 void VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000337 void VisitExprWithCleanups(const ExprWithCleanups *Node);
338 void VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *Node);
339 void dumpCXXTemporary(const CXXTemporary *Temporary);
Faisal Vali2b391ab2013-09-26 19:54:12 +0000340 void VisitLambdaExpr(const LambdaExpr *Node) {
341 VisitExpr(Node);
342 dumpDecl(Node->getLambdaClass());
343 }
Mike Stump11289f42009-09-09 15:08:12 +0000344
Chris Lattner84ca3762007-08-30 01:00:35 +0000345 // ObjC
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000346 void VisitObjCAtCatchStmt(const ObjCAtCatchStmt *Node);
347 void VisitObjCEncodeExpr(const ObjCEncodeExpr *Node);
348 void VisitObjCMessageExpr(const ObjCMessageExpr *Node);
349 void VisitObjCBoxedExpr(const ObjCBoxedExpr *Node);
350 void VisitObjCSelectorExpr(const ObjCSelectorExpr *Node);
351 void VisitObjCProtocolExpr(const ObjCProtocolExpr *Node);
352 void VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *Node);
353 void VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *Node);
354 void VisitObjCIvarRefExpr(const ObjCIvarRefExpr *Node);
355 void VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *Node);
Alexander Kornienkoebc17b52013-01-14 14:07:11 +0000356
357 // Comments.
358 const char *getCommandName(unsigned CommandID);
359 void dumpComment(const Comment *C);
360
361 // Inline comments.
362 void visitTextComment(const TextComment *C);
363 void visitInlineCommandComment(const InlineCommandComment *C);
364 void visitHTMLStartTagComment(const HTMLStartTagComment *C);
365 void visitHTMLEndTagComment(const HTMLEndTagComment *C);
366
367 // Block comments.
368 void visitBlockCommandComment(const BlockCommandComment *C);
369 void visitParamCommandComment(const ParamCommandComment *C);
370 void visitTParamCommandComment(const TParamCommandComment *C);
371 void visitVerbatimBlockComment(const VerbatimBlockComment *C);
372 void visitVerbatimBlockLineComment(const VerbatimBlockLineComment *C);
373 void visitVerbatimLineComment(const VerbatimLineComment *C);
Chris Lattnercbe4f772007-08-08 22:51:59 +0000374 };
375}
376
377//===----------------------------------------------------------------------===//
Chris Lattner11e30d32007-08-30 06:17:34 +0000378// Utilities
379//===----------------------------------------------------------------------===//
380
Richard Trieude5cc7d2013-01-31 01:44:26 +0000381// Print out the appropriate tree structure using the Indents vector.
382// Example of tree and the Indents vector at each level.
383// A { }
384// |-B { IT_Child }
385// | `-C { IT_Child, IT_LastChild }
386// `-D { IT_LastChild }
387// |-E { IT_LastChild, IT_Child }
388// `-F { IT_LastChild, IT_LastChild }
389// Type non-last element, last element
390// IT_Child "| " "|-"
391// IT_LastChild " " "`-"
Alexander Kornienko18ec81b2012-12-13 13:59:55 +0000392void ASTDumper::indent() {
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000393 if (IsFirstLine)
394 IsFirstLine = false;
395 else
396 OS << "\n";
Richard Trieude5cc7d2013-01-31 01:44:26 +0000397
398 ColorScope Color(*this, IndentColor);
Craig Topper2341c0d2013-07-04 03:08:24 +0000399 for (SmallVectorImpl<IndentType>::const_iterator I = Indents.begin(),
400 E = Indents.end();
Richard Trieude5cc7d2013-01-31 01:44:26 +0000401 I != E; ++I) {
402 switch (*I) {
Richard Smith56d12152013-01-31 02:04:38 +0000403 case IT_Child:
404 if (I == E - 1)
405 OS << "|-";
406 else
407 OS << "| ";
408 continue;
409 case IT_LastChild:
410 if (I == E - 1)
411 OS << "`-";
412 else
413 OS << " ";
414 continue;
Richard Trieude5cc7d2013-01-31 01:44:26 +0000415 }
Richard Smith56d12152013-01-31 02:04:38 +0000416 llvm_unreachable("Invalid IndentType");
Richard Trieude5cc7d2013-01-31 01:44:26 +0000417 }
418 Indents.push_back(IT_Child);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000419}
420
Alexander Kornienko18ec81b2012-12-13 13:59:55 +0000421void ASTDumper::unindent() {
Richard Trieude5cc7d2013-01-31 01:44:26 +0000422 Indents.pop_back();
423}
424
425// Call before each potential last child node is to be dumped. If MoreChildren
426// is false, then this is the last child, otherwise treat as a regular node.
427void ASTDumper::lastChild() {
428 if (!hasMoreChildren())
429 Indents.back() = IT_LastChild;
430}
431
432// MoreChildren should be set before calling another function that may print
433// additional nodes to prevent conflicting final child nodes.
434bool ASTDumper::hasMoreChildren() {
435 return MoreChildren;
436}
437
438void ASTDumper::setMoreChildren(bool Value) {
439 MoreChildren = Value;
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000440}
441
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000442void ASTDumper::dumpPointer(const void *Ptr) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000443 ColorScope Color(*this, AddressColor);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000444 OS << ' ' << Ptr;
445}
446
Alexander Kornienko18ec81b2012-12-13 13:59:55 +0000447void ASTDumper::dumpLocation(SourceLocation Loc) {
Alex McCarthye14ddef2014-05-02 20:24:11 +0000448 if (!SM)
449 return;
450
Richard Trieud215b8d2013-01-26 01:31:20 +0000451 ColorScope Color(*this, LocationColor);
Chris Lattner53e384f2009-01-16 07:00:02 +0000452 SourceLocation SpellingLoc = SM->getSpellingLoc(Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000453
Chris Lattner11e30d32007-08-30 06:17:34 +0000454 // The general format we print out is filename:line:col, but we drop pieces
455 // that haven't changed since the last loc printed.
Chris Lattnerf1ca7d32009-01-27 07:57:44 +0000456 PresumedLoc PLoc = SM->getPresumedLoc(SpellingLoc);
457
Douglas Gregor453b0122010-11-12 07:15:47 +0000458 if (PLoc.isInvalid()) {
459 OS << "<invalid sloc>";
460 return;
461 }
462
Chris Lattnerf1ca7d32009-01-27 07:57:44 +0000463 if (strcmp(PLoc.getFilename(), LastLocFilename) != 0) {
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000464 OS << PLoc.getFilename() << ':' << PLoc.getLine()
465 << ':' << PLoc.getColumn();
Chris Lattnerf1ca7d32009-01-27 07:57:44 +0000466 LastLocFilename = PLoc.getFilename();
467 LastLocLine = PLoc.getLine();
468 } else if (PLoc.getLine() != LastLocLine) {
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000469 OS << "line" << ':' << PLoc.getLine()
470 << ':' << PLoc.getColumn();
Chris Lattnerf1ca7d32009-01-27 07:57:44 +0000471 LastLocLine = PLoc.getLine();
Chris Lattner11e30d32007-08-30 06:17:34 +0000472 } else {
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000473 OS << "col" << ':' << PLoc.getColumn();
Chris Lattner11e30d32007-08-30 06:17:34 +0000474 }
475}
476
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000477void ASTDumper::dumpSourceRange(SourceRange R) {
Chris Lattner11e30d32007-08-30 06:17:34 +0000478 // Can't translate locations if a SourceManager isn't available.
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000479 if (!SM)
480 return;
Mike Stump11289f42009-09-09 15:08:12 +0000481
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000482 OS << " <";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000483 dumpLocation(R.getBegin());
Chris Lattnera7c19fe2007-10-16 22:36:42 +0000484 if (R.getBegin() != R.getEnd()) {
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000485 OS << ", ";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000486 dumpLocation(R.getEnd());
Chris Lattner11e30d32007-08-30 06:17:34 +0000487 }
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000488 OS << ">";
Mike Stump11289f42009-09-09 15:08:12 +0000489
Chris Lattner11e30d32007-08-30 06:17:34 +0000490 // <t2.c:123:421[blah], t2.c:412:321>
491
492}
493
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000494void ASTDumper::dumpBareType(QualType T) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000495 ColorScope Color(*this, TypeColor);
496
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000497 SplitQualType T_split = T.split();
498 OS << "'" << QualType::getAsString(T_split) << "'";
499
500 if (!T.isNull()) {
501 // If the type is sugared, also dump a (shallow) desugared type.
502 SplitQualType D_split = T.getSplitDesugaredType();
503 if (T_split != D_split)
504 OS << ":'" << QualType::getAsString(D_split) << "'";
505 }
506}
507
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000508void ASTDumper::dumpType(QualType T) {
509 OS << ' ';
510 dumpBareType(T);
511}
512
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000513void ASTDumper::dumpBareDeclRef(const Decl *D) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000514 {
515 ColorScope Color(*this, DeclKindNameColor);
516 OS << D->getDeclKindName();
517 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000518 dumpPointer(D);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000519
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000520 if (const NamedDecl *ND = dyn_cast<NamedDecl>(D)) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000521 ColorScope Color(*this, DeclNameColor);
David Blaikied4da8722013-05-14 21:04:00 +0000522 OS << " '" << ND->getDeclName() << '\'';
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000523 }
524
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000525 if (const ValueDecl *VD = dyn_cast<ValueDecl>(D))
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000526 dumpType(VD->getType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000527}
528
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000529void ASTDumper::dumpDeclRef(const Decl *D, const char *Label) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000530 if (!D)
531 return;
532
533 IndentScope Indent(*this);
534 if (Label)
535 OS << Label << ' ';
536 dumpBareDeclRef(D);
537}
538
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000539void ASTDumper::dumpName(const NamedDecl *ND) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000540 if (ND->getDeclName()) {
541 ColorScope Color(*this, DeclNameColor);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000542 OS << ' ' << ND->getNameAsString();
Richard Trieud215b8d2013-01-26 01:31:20 +0000543 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000544}
545
Richard Trieude5cc7d2013-01-31 01:44:26 +0000546bool ASTDumper::hasNodes(const DeclContext *DC) {
547 if (!DC)
548 return false;
549
Richard Smith1d209d02013-05-23 01:49:11 +0000550 return DC->hasExternalLexicalStorage() ||
551 DC->noload_decls_begin() != DC->noload_decls_end();
Richard Trieude5cc7d2013-01-31 01:44:26 +0000552}
553
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000554void ASTDumper::dumpDeclContext(const DeclContext *DC) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000555 if (!DC)
556 return;
Richard Smithdcc2c452014-03-17 23:00:06 +0000557
558 ChildDumper Children(*this);
559 for (auto *D : DC->noload_decls())
560 Children.dump(D);
561
562 if (DC->hasExternalLexicalStorage()) {
563 Children.release();
564
Richard Smith1d209d02013-05-23 01:49:11 +0000565 lastChild();
566 IndentScope Indent(*this);
567 ColorScope Color(*this, UndeserializedColor);
568 OS << "<undeserialized declarations>";
569 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000570}
571
Richard Smith33937e72013-06-22 21:49:40 +0000572void ASTDumper::dumpLookups(const DeclContext *DC) {
573 IndentScope Indent(*this);
574
575 OS << "StoredDeclsMap ";
576 dumpBareDeclRef(cast<Decl>(DC));
577
578 const DeclContext *Primary = DC->getPrimaryContext();
579 if (Primary != DC) {
580 OS << " primary";
581 dumpPointer(cast<Decl>(Primary));
582 }
583
584 bool HasUndeserializedLookups = Primary->hasExternalVisibleStorage();
585
586 DeclContext::all_lookups_iterator I = Primary->noload_lookups_begin(),
587 E = Primary->noload_lookups_end();
588 while (I != E) {
589 DeclarationName Name = I.getLookupName();
590 DeclContextLookupResult R = *I++;
591 if (I == E && !HasUndeserializedLookups)
592 lastChild();
593
594 IndentScope Indent(*this);
595 OS << "DeclarationName ";
596 {
597 ColorScope Color(*this, DeclNameColor);
598 OS << '\'' << Name << '\'';
599 }
600
601 for (DeclContextLookupResult::iterator RI = R.begin(), RE = R.end();
602 RI != RE; ++RI) {
603 if (RI + 1 == RE)
604 lastChild();
605 dumpDeclRef(*RI);
Richard Smith15fc7df2013-10-22 23:50:38 +0000606 if ((*RI)->isHidden())
607 OS << " hidden";
Richard Smith33937e72013-06-22 21:49:40 +0000608 }
609 }
610
611 if (HasUndeserializedLookups) {
612 lastChild();
613 IndentScope Indent(*this);
614 ColorScope Color(*this, UndeserializedColor);
615 OS << "<undeserialized lookups>";
616 }
617}
618
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000619void ASTDumper::dumpAttr(const Attr *A) {
620 IndentScope Indent(*this);
Richard Trieud215b8d2013-01-26 01:31:20 +0000621 {
622 ColorScope Color(*this, AttrColor);
Aaron Ballman36a53502014-01-16 13:03:14 +0000623
Richard Trieud215b8d2013-01-26 01:31:20 +0000624 switch (A->getKind()) {
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000625#define ATTR(X) case attr::X: OS << #X; break;
626#include "clang/Basic/AttrList.inc"
Richard Trieud215b8d2013-01-26 01:31:20 +0000627 default: llvm_unreachable("unexpected attribute kind");
628 }
629 OS << "Attr";
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000630 }
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000631 dumpPointer(A);
632 dumpSourceRange(A->getRange());
Hans Wennborgb0a8b4a2014-05-31 04:05:57 +0000633 if (A->isInherited())
634 OS << " Inherited";
Aaron Ballman36a53502014-01-16 13:03:14 +0000635 if (A->isImplicit())
636 OS << " Implicit";
Hans Wennborgb0a8b4a2014-05-31 04:05:57 +0000637#include "clang/AST/AttrDump.inc"
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000638}
639
Richard Smith71bec062013-10-15 21:58:30 +0000640static void dumpPreviousDeclImpl(raw_ostream &OS, ...) {}
641
642template<typename T>
643static void dumpPreviousDeclImpl(raw_ostream &OS, const Mergeable<T> *D) {
Rafael Espindola8db352d2013-10-17 15:37:26 +0000644 const T *First = D->getFirstDecl();
Richard Smith71bec062013-10-15 21:58:30 +0000645 if (First != D)
646 OS << " first " << First;
Richard Smithf5f43542013-02-07 01:35:44 +0000647}
648
649template<typename T>
Richard Smith71bec062013-10-15 21:58:30 +0000650static void dumpPreviousDeclImpl(raw_ostream &OS, const Redeclarable<T> *D) {
651 const T *Prev = D->getPreviousDecl();
652 if (Prev)
653 OS << " prev " << Prev;
Richard Smithf5f43542013-02-07 01:35:44 +0000654}
655
Richard Smith71bec062013-10-15 21:58:30 +0000656/// Dump the previous declaration in the redeclaration chain for a declaration,
657/// if any.
658static void dumpPreviousDecl(raw_ostream &OS, const Decl *D) {
Richard Smithf5f43542013-02-07 01:35:44 +0000659 switch (D->getKind()) {
660#define DECL(DERIVED, BASE) \
661 case Decl::DERIVED: \
Richard Smith71bec062013-10-15 21:58:30 +0000662 return dumpPreviousDeclImpl(OS, cast<DERIVED##Decl>(D));
Richard Smithf5f43542013-02-07 01:35:44 +0000663#define ABSTRACT_DECL(DECL)
664#include "clang/AST/DeclNodes.inc"
665 }
666 llvm_unreachable("Decl that isn't part of DeclNodes.inc!");
667}
668
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000669//===----------------------------------------------------------------------===//
670// C++ Utilities
671//===----------------------------------------------------------------------===//
672
673void ASTDumper::dumpAccessSpecifier(AccessSpecifier AS) {
674 switch (AS) {
675 case AS_none:
676 break;
677 case AS_public:
678 OS << "public";
679 break;
680 case AS_protected:
681 OS << "protected";
682 break;
683 case AS_private:
684 OS << "private";
685 break;
686 }
687}
688
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000689void ASTDumper::dumpCXXCtorInitializer(const CXXCtorInitializer *Init) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000690 IndentScope Indent(*this);
691 OS << "CXXCtorInitializer";
692 if (Init->isAnyMemberInitializer()) {
693 OS << ' ';
694 dumpBareDeclRef(Init->getAnyMember());
695 } else {
696 dumpType(QualType(Init->getBaseClass(), 0));
697 }
698 dumpStmt(Init->getInit());
699}
700
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000701void ASTDumper::dumpTemplateParameters(const TemplateParameterList *TPL) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000702 if (!TPL)
703 return;
704
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000705 for (TemplateParameterList::const_iterator I = TPL->begin(), E = TPL->end();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000706 I != E; ++I)
707 dumpDecl(*I);
708}
709
710void ASTDumper::dumpTemplateArgumentListInfo(
711 const TemplateArgumentListInfo &TALI) {
Richard Trieude5cc7d2013-01-31 01:44:26 +0000712 for (unsigned i = 0, e = TALI.size(); i < e; ++i) {
713 if (i + 1 == e)
714 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000715 dumpTemplateArgumentLoc(TALI[i]);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000716 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000717}
718
719void ASTDumper::dumpTemplateArgumentLoc(const TemplateArgumentLoc &A) {
720 dumpTemplateArgument(A.getArgument(), A.getSourceRange());
721}
722
723void ASTDumper::dumpTemplateArgumentList(const TemplateArgumentList &TAL) {
724 for (unsigned i = 0, e = TAL.size(); i < e; ++i)
725 dumpTemplateArgument(TAL[i]);
726}
727
728void ASTDumper::dumpTemplateArgument(const TemplateArgument &A, SourceRange R) {
729 IndentScope Indent(*this);
730 OS << "TemplateArgument";
731 if (R.isValid())
732 dumpSourceRange(R);
733
734 switch (A.getKind()) {
735 case TemplateArgument::Null:
736 OS << " null";
737 break;
738 case TemplateArgument::Type:
739 OS << " type";
Richard Trieude5cc7d2013-01-31 01:44:26 +0000740 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000741 dumpType(A.getAsType());
742 break;
743 case TemplateArgument::Declaration:
744 OS << " decl";
Richard Trieude5cc7d2013-01-31 01:44:26 +0000745 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000746 dumpDeclRef(A.getAsDecl());
747 break;
748 case TemplateArgument::NullPtr:
749 OS << " nullptr";
750 break;
751 case TemplateArgument::Integral:
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000752 OS << " integral " << A.getAsIntegral();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000753 break;
754 case TemplateArgument::Template:
755 OS << " template ";
756 A.getAsTemplate().dump(OS);
757 break;
758 case TemplateArgument::TemplateExpansion:
759 OS << " template expansion";
760 A.getAsTemplateOrTemplatePattern().dump(OS);
761 break;
762 case TemplateArgument::Expression:
763 OS << " expr";
Richard Trieude5cc7d2013-01-31 01:44:26 +0000764 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000765 dumpStmt(A.getAsExpr());
766 break;
767 case TemplateArgument::Pack:
768 OS << " pack";
769 for (TemplateArgument::pack_iterator I = A.pack_begin(), E = A.pack_end();
Richard Trieude5cc7d2013-01-31 01:44:26 +0000770 I != E; ++I) {
771 if (I + 1 == E)
772 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000773 dumpTemplateArgument(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000774 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000775 break;
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000776 }
777}
778
Chris Lattner11e30d32007-08-30 06:17:34 +0000779//===----------------------------------------------------------------------===//
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000780// Decl dumping methods.
Chris Lattnercbe4f772007-08-08 22:51:59 +0000781//===----------------------------------------------------------------------===//
782
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000783void ASTDumper::dumpDecl(const Decl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000784 IndentScope Indent(*this);
Mike Stump11289f42009-09-09 15:08:12 +0000785
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000786 if (!D) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000787 ColorScope Color(*this, NullColor);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000788 OS << "<<<NULL>>>";
789 return;
Chris Lattnercbe4f772007-08-08 22:51:59 +0000790 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000791
Richard Trieud215b8d2013-01-26 01:31:20 +0000792 {
793 ColorScope Color(*this, DeclKindNameColor);
794 OS << D->getDeclKindName() << "Decl";
795 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000796 dumpPointer(D);
Richard Smithf5f43542013-02-07 01:35:44 +0000797 if (D->getLexicalDeclContext() != D->getDeclContext())
798 OS << " parent " << cast<Decl>(D->getDeclContext());
Richard Smith71bec062013-10-15 21:58:30 +0000799 dumpPreviousDecl(OS, D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000800 dumpSourceRange(D->getSourceRange());
David Blaikie5ee3d002014-04-02 05:48:29 +0000801 OS << ' ';
802 dumpLocation(D->getLocation());
Richard Smith15fc7df2013-10-22 23:50:38 +0000803 if (Module *M = D->getOwningModule())
804 OS << " in " << M->getFullModuleName();
805 if (const NamedDecl *ND = dyn_cast<NamedDecl>(D))
806 if (ND->isHidden())
807 OS << " hidden";
Alexander Kornienko83a4e182014-05-27 21:29:22 +0000808 if (D->isImplicit())
809 OS << " implicit";
Richard Smith71b09ac2014-06-13 02:24:47 +0000810 if (D->isUsed())
811 OS << " used";
812 else if (D->isReferenced())
813 OS << " referenced";
814 if (D->isInvalidDecl())
815 OS << " invalid";
Richard Trieude5cc7d2013-01-31 01:44:26 +0000816
Aaron Ballmanb97112e2014-03-08 22:19:01 +0000817 bool HasAttrs = D->hasAttrs();
Richard Smithb39b9d52013-05-21 05:24:00 +0000818 const FullComment *Comment =
819 D->getASTContext().getLocalCommentForDeclUncached(D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000820 // Decls within functions are visited by the body
Richard Trieude5cc7d2013-01-31 01:44:26 +0000821 bool HasDeclContext = !isa<FunctionDecl>(*D) && !isa<ObjCMethodDecl>(*D) &&
822 hasNodes(dyn_cast<DeclContext>(D));
823
Richard Smithb39b9d52013-05-21 05:24:00 +0000824 setMoreChildren(HasAttrs || Comment || HasDeclContext);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000825 ConstDeclVisitor<ASTDumper>::Visit(D);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000826
Richard Smithb39b9d52013-05-21 05:24:00 +0000827 setMoreChildren(Comment || HasDeclContext);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000828 for (Decl::attr_iterator I = D->attr_begin(), E = D->attr_end();
829 I != E; ++I) {
830 if (I + 1 == E)
831 lastChild();
832 dumpAttr(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000833 }
834
835 setMoreChildren(HasDeclContext);
836 lastChild();
Richard Smithb39b9d52013-05-21 05:24:00 +0000837 dumpFullComment(Comment);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000838
839 setMoreChildren(false);
840 if (HasDeclContext)
Richard Smithf5f43542013-02-07 01:35:44 +0000841 dumpDeclContext(cast<DeclContext>(D));
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000842}
843
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000844void ASTDumper::VisitLabelDecl(const LabelDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000845 dumpName(D);
846}
847
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000848void ASTDumper::VisitTypedefDecl(const TypedefDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000849 dumpName(D);
850 dumpType(D->getUnderlyingType());
851 if (D->isModulePrivate())
852 OS << " __module_private__";
853}
854
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000855void ASTDumper::VisitEnumDecl(const EnumDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000856 if (D->isScoped()) {
857 if (D->isScopedUsingClassTag())
858 OS << " class";
859 else
860 OS << " struct";
861 }
862 dumpName(D);
863 if (D->isModulePrivate())
864 OS << " __module_private__";
865 if (D->isFixed())
866 dumpType(D->getIntegerType());
867}
868
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000869void ASTDumper::VisitRecordDecl(const RecordDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000870 OS << ' ' << D->getKindName();
871 dumpName(D);
872 if (D->isModulePrivate())
873 OS << " __module_private__";
Richard Smith99bc1b92013-08-30 05:32:29 +0000874 if (D->isCompleteDefinition())
875 OS << " definition";
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000876}
877
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000878void ASTDumper::VisitEnumConstantDecl(const EnumConstantDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000879 dumpName(D);
880 dumpType(D->getType());
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000881 if (const Expr *Init = D->getInitExpr()) {
Richard Trieude5cc7d2013-01-31 01:44:26 +0000882 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000883 dumpStmt(Init);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000884 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000885}
886
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000887void ASTDumper::VisitIndirectFieldDecl(const IndirectFieldDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000888 dumpName(D);
889 dumpType(D->getType());
Richard Smithdcc2c452014-03-17 23:00:06 +0000890
891 ChildDumper Children(*this);
Richard Smith8aa49222014-03-18 00:35:12 +0000892 for (auto *Child : D->chain())
893 Children.dumpRef(Child);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000894}
895
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000896void ASTDumper::VisitFunctionDecl(const FunctionDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000897 dumpName(D);
898 dumpType(D->getType());
899
Rafael Espindola6ae7e502013-04-03 19:27:57 +0000900 StorageClass SC = D->getStorageClass();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000901 if (SC != SC_None)
902 OS << ' ' << VarDecl::getStorageClassSpecifierString(SC);
903 if (D->isInlineSpecified())
904 OS << " inline";
905 if (D->isVirtualAsWritten())
906 OS << " virtual";
907 if (D->isModulePrivate())
908 OS << " __module_private__";
909
910 if (D->isPure())
911 OS << " pure";
912 else if (D->isDeletedAsWritten())
913 OS << " delete";
914
Richard Smithadaa0152013-05-17 02:09:46 +0000915 if (const FunctionProtoType *FPT = D->getType()->getAs<FunctionProtoType>()) {
916 FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo();
917 switch (EPI.ExceptionSpecType) {
918 default: break;
919 case EST_Unevaluated:
920 OS << " noexcept-unevaluated " << EPI.ExceptionSpecDecl;
921 break;
922 case EST_Uninstantiated:
923 OS << " noexcept-uninstantiated " << EPI.ExceptionSpecTemplate;
924 break;
925 }
926 }
927
Richard Trieude5cc7d2013-01-31 01:44:26 +0000928 bool OldMoreChildren = hasMoreChildren();
929 const FunctionTemplateSpecializationInfo *FTSI =
930 D->getTemplateSpecializationInfo();
931 bool HasTemplateSpecialization = FTSI;
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000932
Richard Trieude5cc7d2013-01-31 01:44:26 +0000933 bool HasNamedDecls = D->getDeclsInPrototypeScope().begin() !=
934 D->getDeclsInPrototypeScope().end();
935
936 bool HasFunctionDecls = D->param_begin() != D->param_end();
937
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000938 const CXXConstructorDecl *C = dyn_cast<CXXConstructorDecl>(D);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000939 bool HasCtorInitializers = C && C->init_begin() != C->init_end();
940
941 bool HasDeclarationBody = D->doesThisDeclarationHaveABody();
942
943 setMoreChildren(OldMoreChildren || HasNamedDecls || HasFunctionDecls ||
944 HasCtorInitializers || HasDeclarationBody);
945 if (HasTemplateSpecialization) {
946 lastChild();
947 dumpTemplateArgumentList(*FTSI->TemplateArguments);
948 }
949
950 setMoreChildren(OldMoreChildren || HasFunctionDecls ||
951 HasCtorInitializers || HasDeclarationBody);
Dmitri Gribenkof8579502013-01-12 19:30:44 +0000952 for (ArrayRef<NamedDecl *>::iterator
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000953 I = D->getDeclsInPrototypeScope().begin(),
Richard Trieude5cc7d2013-01-31 01:44:26 +0000954 E = D->getDeclsInPrototypeScope().end(); I != E; ++I) {
955 if (I + 1 == E)
956 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000957 dumpDecl(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000958 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000959
Richard Trieude5cc7d2013-01-31 01:44:26 +0000960 setMoreChildren(OldMoreChildren || HasCtorInitializers || HasDeclarationBody);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000961 for (FunctionDecl::param_const_iterator I = D->param_begin(),
962 E = D->param_end();
Richard Trieude5cc7d2013-01-31 01:44:26 +0000963 I != E; ++I) {
964 if (I + 1 == E)
965 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000966 dumpDecl(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000967 }
968
969 setMoreChildren(OldMoreChildren || HasDeclarationBody);
970 if (HasCtorInitializers)
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000971 for (CXXConstructorDecl::init_const_iterator I = C->init_begin(),
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000972 E = C->init_end();
973 I != E; ++I) {
Richard Trieude5cc7d2013-01-31 01:44:26 +0000974 if (I + 1 == E)
975 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000976 dumpCXXCtorInitializer(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000977 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000978
Richard Trieude5cc7d2013-01-31 01:44:26 +0000979 setMoreChildren(OldMoreChildren);
980 if (HasDeclarationBody) {
981 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000982 dumpStmt(D->getBody());
Richard Trieude5cc7d2013-01-31 01:44:26 +0000983 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000984}
985
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000986void ASTDumper::VisitFieldDecl(const FieldDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000987 dumpName(D);
988 dumpType(D->getType());
989 if (D->isMutable())
990 OS << " mutable";
991 if (D->isModulePrivate())
992 OS << " __module_private__";
Richard Trieude5cc7d2013-01-31 01:44:26 +0000993
994 bool OldMoreChildren = hasMoreChildren();
995 bool IsBitField = D->isBitField();
996 Expr *Init = D->getInClassInitializer();
997 bool HasInit = Init;
998
999 setMoreChildren(OldMoreChildren || HasInit);
1000 if (IsBitField) {
1001 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001002 dumpStmt(D->getBitWidth());
Richard Trieude5cc7d2013-01-31 01:44:26 +00001003 }
1004 setMoreChildren(OldMoreChildren);
1005 if (HasInit) {
1006 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001007 dumpStmt(Init);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001008 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001009}
1010
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001011void ASTDumper::VisitVarDecl(const VarDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001012 dumpName(D);
1013 dumpType(D->getType());
Rafael Espindola6ae7e502013-04-03 19:27:57 +00001014 StorageClass SC = D->getStorageClass();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001015 if (SC != SC_None)
1016 OS << ' ' << VarDecl::getStorageClassSpecifierString(SC);
Richard Smithfd3834f2013-04-13 02:43:54 +00001017 switch (D->getTLSKind()) {
1018 case VarDecl::TLS_None: break;
1019 case VarDecl::TLS_Static: OS << " tls"; break;
1020 case VarDecl::TLS_Dynamic: OS << " tls_dynamic"; break;
1021 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001022 if (D->isModulePrivate())
1023 OS << " __module_private__";
1024 if (D->isNRVOVariable())
1025 OS << " nrvo";
Richard Trieude5cc7d2013-01-31 01:44:26 +00001026 if (D->hasInit()) {
1027 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001028 dumpStmt(D->getInit());
Richard Trieude5cc7d2013-01-31 01:44:26 +00001029 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001030}
1031
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001032void ASTDumper::VisitFileScopeAsmDecl(const FileScopeAsmDecl *D) {
Richard Trieude5cc7d2013-01-31 01:44:26 +00001033 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001034 dumpStmt(D->getAsmString());
1035}
1036
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001037void ASTDumper::VisitImportDecl(const ImportDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001038 OS << ' ' << D->getImportedModule()->getFullModuleName();
1039}
1040
1041//===----------------------------------------------------------------------===//
1042// C++ Declarations
1043//===----------------------------------------------------------------------===//
1044
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001045void ASTDumper::VisitNamespaceDecl(const NamespaceDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001046 dumpName(D);
1047 if (D->isInline())
1048 OS << " inline";
1049 if (!D->isOriginalNamespace())
1050 dumpDeclRef(D->getOriginalNamespace(), "original");
1051}
1052
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001053void ASTDumper::VisitUsingDirectiveDecl(const UsingDirectiveDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001054 OS << ' ';
1055 dumpBareDeclRef(D->getNominatedNamespace());
1056}
1057
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001058void ASTDumper::VisitNamespaceAliasDecl(const NamespaceAliasDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001059 dumpName(D);
1060 dumpDeclRef(D->getAliasedNamespace());
1061}
1062
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001063void ASTDumper::VisitTypeAliasDecl(const TypeAliasDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001064 dumpName(D);
1065 dumpType(D->getUnderlyingType());
1066}
1067
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001068void ASTDumper::VisitTypeAliasTemplateDecl(const TypeAliasTemplateDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001069 dumpName(D);
1070 dumpTemplateParameters(D->getTemplateParameters());
1071 dumpDecl(D->getTemplatedDecl());
1072}
1073
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001074void ASTDumper::VisitCXXRecordDecl(const CXXRecordDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001075 VisitRecordDecl(D);
1076 if (!D->isCompleteDefinition())
1077 return;
1078
Aaron Ballman574705e2014-03-13 15:41:46 +00001079 for (const auto &I : D->bases()) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001080 IndentScope Indent(*this);
Aaron Ballman574705e2014-03-13 15:41:46 +00001081 if (I.isVirtual())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001082 OS << "virtual ";
Aaron Ballman574705e2014-03-13 15:41:46 +00001083 dumpAccessSpecifier(I.getAccessSpecifier());
1084 dumpType(I.getType());
1085 if (I.isPackExpansion())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001086 OS << "...";
1087 }
1088}
1089
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001090void ASTDumper::VisitStaticAssertDecl(const StaticAssertDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001091 dumpStmt(D->getAssertExpr());
Richard Trieude5cc7d2013-01-31 01:44:26 +00001092 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001093 dumpStmt(D->getMessage());
1094}
1095
Richard Smithcbdf7332014-03-18 02:07:28 +00001096template<typename SpecializationDecl>
1097void ASTDumper::VisitTemplateDeclSpecialization(ChildDumper &Children,
1098 const SpecializationDecl *D,
1099 bool DumpExplicitInst,
1100 bool DumpRefOnly) {
1101 bool DumpedAny = false;
1102 for (auto *RedeclWithBadType : D->redecls()) {
1103 // FIXME: The redecls() range sometimes has elements of a less-specific
1104 // type. (In particular, ClassTemplateSpecializationDecl::redecls() gives
1105 // us TagDecls, and should give CXXRecordDecls).
1106 auto *Redecl = dyn_cast<SpecializationDecl>(RedeclWithBadType);
1107 if (!Redecl) {
1108 // Found the injected-class-name for a class template. This will be dumped
1109 // as part of its surrounding class so we don't need to dump it here.
1110 assert(isa<CXXRecordDecl>(RedeclWithBadType) &&
1111 "expected an injected-class-name");
1112 continue;
1113 }
1114
1115 switch (Redecl->getTemplateSpecializationKind()) {
1116 case TSK_ExplicitInstantiationDeclaration:
1117 case TSK_ExplicitInstantiationDefinition:
1118 if (!DumpExplicitInst)
1119 break;
1120 // Fall through.
1121 case TSK_Undeclared:
1122 case TSK_ImplicitInstantiation:
1123 Children.dump(Redecl, DumpRefOnly);
1124 DumpedAny = true;
1125 break;
1126 case TSK_ExplicitSpecialization:
1127 break;
1128 }
1129 }
1130
1131 // Ensure we dump at least one decl for each specialization.
1132 if (!DumpedAny)
1133 Children.dumpRef(D);
1134}
1135
Richard Smith20ade552014-03-17 23:34:53 +00001136template<typename TemplateDecl>
1137void ASTDumper::VisitTemplateDecl(const TemplateDecl *D,
1138 bool DumpExplicitInst) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001139 dumpName(D);
1140 dumpTemplateParameters(D->getTemplateParameters());
Richard Smithdcc2c452014-03-17 23:00:06 +00001141
1142 ChildDumper Children(*this);
1143 Children.dump(D->getTemplatedDecl());
1144
Richard Smithcbdf7332014-03-18 02:07:28 +00001145 for (auto *Child : D->specializations())
1146 VisitTemplateDeclSpecialization(Children, Child, DumpExplicitInst,
1147 !D->isCanonicalDecl());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001148}
1149
Richard Smith20ade552014-03-17 23:34:53 +00001150void ASTDumper::VisitFunctionTemplateDecl(const FunctionTemplateDecl *D) {
1151 // FIXME: We don't add a declaration of a function template specialization
1152 // to its context when it's explicitly instantiated, so dump explicit
1153 // instantiations when we dump the template itself.
1154 VisitTemplateDecl(D, true);
1155}
1156
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001157void ASTDumper::VisitClassTemplateDecl(const ClassTemplateDecl *D) {
Richard Smith20ade552014-03-17 23:34:53 +00001158 VisitTemplateDecl(D, false);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001159}
1160
1161void ASTDumper::VisitClassTemplateSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001162 const ClassTemplateSpecializationDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001163 VisitCXXRecordDecl(D);
1164 dumpTemplateArgumentList(D->getTemplateArgs());
1165}
1166
1167void ASTDumper::VisitClassTemplatePartialSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001168 const ClassTemplatePartialSpecializationDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001169 VisitClassTemplateSpecializationDecl(D);
1170 dumpTemplateParameters(D->getTemplateParameters());
1171}
1172
1173void ASTDumper::VisitClassScopeFunctionSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001174 const ClassScopeFunctionSpecializationDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001175 dumpDeclRef(D->getSpecialization());
1176 if (D->hasExplicitTemplateArgs())
1177 dumpTemplateArgumentListInfo(D->templateArgs());
1178}
1179
Richard Smithd25789a2013-09-18 01:36:02 +00001180void ASTDumper::VisitVarTemplateDecl(const VarTemplateDecl *D) {
Richard Smith20ade552014-03-17 23:34:53 +00001181 VisitTemplateDecl(D, false);
Richard Smithd25789a2013-09-18 01:36:02 +00001182}
1183
1184void ASTDumper::VisitVarTemplateSpecializationDecl(
1185 const VarTemplateSpecializationDecl *D) {
1186 dumpTemplateArgumentList(D->getTemplateArgs());
1187 VisitVarDecl(D);
1188}
1189
1190void ASTDumper::VisitVarTemplatePartialSpecializationDecl(
1191 const VarTemplatePartialSpecializationDecl *D) {
1192 dumpTemplateParameters(D->getTemplateParameters());
1193 VisitVarTemplateSpecializationDecl(D);
1194}
1195
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001196void ASTDumper::VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001197 if (D->wasDeclaredWithTypename())
1198 OS << " typename";
1199 else
1200 OS << " class";
1201 if (D->isParameterPack())
1202 OS << " ...";
1203 dumpName(D);
Richard Smithecf74ff2014-03-23 20:50:39 +00001204 if (D->hasDefaultArgument()) {
1205 lastChild();
1206 dumpTemplateArgument(D->getDefaultArgument());
1207 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001208}
1209
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001210void ASTDumper::VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001211 dumpType(D->getType());
1212 if (D->isParameterPack())
1213 OS << " ...";
1214 dumpName(D);
Richard Smithecf74ff2014-03-23 20:50:39 +00001215 if (D->hasDefaultArgument()) {
1216 lastChild();
1217 dumpTemplateArgument(D->getDefaultArgument());
1218 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001219}
1220
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001221void ASTDumper::VisitTemplateTemplateParmDecl(
1222 const TemplateTemplateParmDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001223 if (D->isParameterPack())
1224 OS << " ...";
1225 dumpName(D);
1226 dumpTemplateParameters(D->getTemplateParameters());
Richard Smithecf74ff2014-03-23 20:50:39 +00001227 if (D->hasDefaultArgument()) {
1228 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001229 dumpTemplateArgumentLoc(D->getDefaultArgument());
Richard Smithecf74ff2014-03-23 20:50:39 +00001230 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001231}
1232
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001233void ASTDumper::VisitUsingDecl(const UsingDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001234 OS << ' ';
1235 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
1236 OS << D->getNameAsString();
1237}
1238
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001239void ASTDumper::VisitUnresolvedUsingTypenameDecl(
1240 const UnresolvedUsingTypenameDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001241 OS << ' ';
1242 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
1243 OS << D->getNameAsString();
1244}
1245
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001246void ASTDumper::VisitUnresolvedUsingValueDecl(const UnresolvedUsingValueDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001247 OS << ' ';
1248 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
1249 OS << D->getNameAsString();
1250 dumpType(D->getType());
1251}
1252
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001253void ASTDumper::VisitUsingShadowDecl(const UsingShadowDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001254 OS << ' ';
1255 dumpBareDeclRef(D->getTargetDecl());
1256}
1257
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001258void ASTDumper::VisitLinkageSpecDecl(const LinkageSpecDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001259 switch (D->getLanguage()) {
1260 case LinkageSpecDecl::lang_c: OS << " C"; break;
1261 case LinkageSpecDecl::lang_cxx: OS << " C++"; break;
1262 }
1263}
1264
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001265void ASTDumper::VisitAccessSpecDecl(const AccessSpecDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001266 OS << ' ';
1267 dumpAccessSpecifier(D->getAccess());
1268}
1269
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001270void ASTDumper::VisitFriendDecl(const FriendDecl *D) {
Richard Smithf5f43542013-02-07 01:35:44 +00001271 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001272 if (TypeSourceInfo *T = D->getFriendType())
1273 dumpType(T->getType());
1274 else
1275 dumpDecl(D->getFriendDecl());
1276}
1277
1278//===----------------------------------------------------------------------===//
1279// Obj-C Declarations
1280//===----------------------------------------------------------------------===//
1281
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001282void ASTDumper::VisitObjCIvarDecl(const ObjCIvarDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001283 dumpName(D);
1284 dumpType(D->getType());
1285 if (D->getSynthesize())
1286 OS << " synthesize";
1287
1288 switch (D->getAccessControl()) {
1289 case ObjCIvarDecl::None:
1290 OS << " none";
1291 break;
1292 case ObjCIvarDecl::Private:
1293 OS << " private";
1294 break;
1295 case ObjCIvarDecl::Protected:
1296 OS << " protected";
1297 break;
1298 case ObjCIvarDecl::Public:
1299 OS << " public";
1300 break;
1301 case ObjCIvarDecl::Package:
1302 OS << " package";
1303 break;
1304 }
1305}
1306
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001307void ASTDumper::VisitObjCMethodDecl(const ObjCMethodDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001308 if (D->isInstanceMethod())
1309 OS << " -";
1310 else
1311 OS << " +";
1312 dumpName(D);
Alp Toker314cc812014-01-25 16:55:45 +00001313 dumpType(D->getReturnType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001314
Richard Trieude5cc7d2013-01-31 01:44:26 +00001315 bool OldMoreChildren = hasMoreChildren();
1316 bool IsVariadic = D->isVariadic();
1317 bool HasBody = D->hasBody();
1318
1319 setMoreChildren(OldMoreChildren || IsVariadic || HasBody);
1320 if (D->isThisDeclarationADefinition()) {
1321 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001322 dumpDeclContext(D);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001323 } else {
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001324 for (ObjCMethodDecl::param_const_iterator I = D->param_begin(),
1325 E = D->param_end();
1326 I != E; ++I) {
Richard Trieude5cc7d2013-01-31 01:44:26 +00001327 if (I + 1 == E)
1328 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001329 dumpDecl(*I);
1330 }
1331 }
1332
Richard Trieude5cc7d2013-01-31 01:44:26 +00001333 setMoreChildren(OldMoreChildren || HasBody);
1334 if (IsVariadic) {
1335 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001336 IndentScope Indent(*this);
1337 OS << "...";
1338 }
1339
Richard Trieude5cc7d2013-01-31 01:44:26 +00001340 setMoreChildren(OldMoreChildren);
1341 if (HasBody) {
1342 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001343 dumpStmt(D->getBody());
Richard Trieude5cc7d2013-01-31 01:44:26 +00001344 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001345}
1346
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001347void ASTDumper::VisitObjCCategoryDecl(const ObjCCategoryDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001348 dumpName(D);
1349 dumpDeclRef(D->getClassInterface());
Richard Trieude5cc7d2013-01-31 01:44:26 +00001350 if (D->protocol_begin() == D->protocol_end())
1351 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001352 dumpDeclRef(D->getImplementation());
1353 for (ObjCCategoryDecl::protocol_iterator I = D->protocol_begin(),
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001354 E = D->protocol_end();
1355 I != E; ++I) {
Richard Trieude5cc7d2013-01-31 01:44:26 +00001356 if (I + 1 == E)
1357 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001358 dumpDeclRef(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001359 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001360}
1361
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001362void ASTDumper::VisitObjCCategoryImplDecl(const ObjCCategoryImplDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001363 dumpName(D);
1364 dumpDeclRef(D->getClassInterface());
Richard Trieude5cc7d2013-01-31 01:44:26 +00001365 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001366 dumpDeclRef(D->getCategoryDecl());
1367}
1368
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001369void ASTDumper::VisitObjCProtocolDecl(const ObjCProtocolDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001370 dumpName(D);
Richard Smithdcc2c452014-03-17 23:00:06 +00001371
1372 ChildDumper Children(*this);
Richard Smith7fcb35f2014-03-18 02:37:59 +00001373 for (auto *Child : D->protocols())
1374 Children.dumpRef(Child);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001375}
1376
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001377void ASTDumper::VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001378 dumpName(D);
1379 dumpDeclRef(D->getSuperClass(), "super");
Richard Smithdcc2c452014-03-17 23:00:06 +00001380
1381 ChildDumper Children(*this);
1382 Children.dumpRef(D->getImplementation());
Richard Smith7fcb35f2014-03-18 02:37:59 +00001383 for (auto *Child : D->protocols())
1384 Children.dumpRef(Child);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001385}
1386
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001387void ASTDumper::VisitObjCImplementationDecl(const ObjCImplementationDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001388 dumpName(D);
1389 dumpDeclRef(D->getSuperClass(), "super");
Richard Trieude5cc7d2013-01-31 01:44:26 +00001390 if (D->init_begin() == D->init_end())
1391 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001392 dumpDeclRef(D->getClassInterface());
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001393 for (ObjCImplementationDecl::init_const_iterator I = D->init_begin(),
1394 E = D->init_end();
1395 I != E; ++I) {
Richard Trieude5cc7d2013-01-31 01:44:26 +00001396 if (I + 1 == E)
1397 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001398 dumpCXXCtorInitializer(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001399 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001400}
1401
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001402void ASTDumper::VisitObjCCompatibleAliasDecl(const ObjCCompatibleAliasDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001403 dumpName(D);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001404 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001405 dumpDeclRef(D->getClassInterface());
1406}
1407
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001408void ASTDumper::VisitObjCPropertyDecl(const ObjCPropertyDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001409 dumpName(D);
1410 dumpType(D->getType());
1411
1412 if (D->getPropertyImplementation() == ObjCPropertyDecl::Required)
1413 OS << " required";
1414 else if (D->getPropertyImplementation() == ObjCPropertyDecl::Optional)
1415 OS << " optional";
1416
1417 ObjCPropertyDecl::PropertyAttributeKind Attrs = D->getPropertyAttributes();
1418 if (Attrs != ObjCPropertyDecl::OBJC_PR_noattr) {
1419 if (Attrs & ObjCPropertyDecl::OBJC_PR_readonly)
1420 OS << " readonly";
1421 if (Attrs & ObjCPropertyDecl::OBJC_PR_assign)
1422 OS << " assign";
1423 if (Attrs & ObjCPropertyDecl::OBJC_PR_readwrite)
1424 OS << " readwrite";
1425 if (Attrs & ObjCPropertyDecl::OBJC_PR_retain)
1426 OS << " retain";
1427 if (Attrs & ObjCPropertyDecl::OBJC_PR_copy)
1428 OS << " copy";
1429 if (Attrs & ObjCPropertyDecl::OBJC_PR_nonatomic)
1430 OS << " nonatomic";
1431 if (Attrs & ObjCPropertyDecl::OBJC_PR_atomic)
1432 OS << " atomic";
1433 if (Attrs & ObjCPropertyDecl::OBJC_PR_weak)
1434 OS << " weak";
1435 if (Attrs & ObjCPropertyDecl::OBJC_PR_strong)
1436 OS << " strong";
1437 if (Attrs & ObjCPropertyDecl::OBJC_PR_unsafe_unretained)
1438 OS << " unsafe_unretained";
Richard Trieude5cc7d2013-01-31 01:44:26 +00001439 if (Attrs & ObjCPropertyDecl::OBJC_PR_getter) {
1440 if (!(Attrs & ObjCPropertyDecl::OBJC_PR_setter))
1441 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001442 dumpDeclRef(D->getGetterMethodDecl(), "getter");
Richard Trieude5cc7d2013-01-31 01:44:26 +00001443 }
1444 if (Attrs & ObjCPropertyDecl::OBJC_PR_setter) {
1445 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001446 dumpDeclRef(D->getSetterMethodDecl(), "setter");
Richard Trieude5cc7d2013-01-31 01:44:26 +00001447 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001448 }
1449}
1450
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001451void ASTDumper::VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001452 dumpName(D->getPropertyDecl());
1453 if (D->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize)
1454 OS << " synthesize";
1455 else
1456 OS << " dynamic";
1457 dumpDeclRef(D->getPropertyDecl());
Richard Trieude5cc7d2013-01-31 01:44:26 +00001458 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001459 dumpDeclRef(D->getPropertyIvarDecl());
1460}
1461
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001462void ASTDumper::VisitBlockDecl(const BlockDecl *D) {
Aaron Ballmanb2b8b1d2014-03-07 16:09:59 +00001463 for (auto I : D->params())
1464 dumpDecl(I);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001465
1466 if (D->isVariadic()) {
1467 IndentScope Indent(*this);
1468 OS << "...";
1469 }
1470
1471 if (D->capturesCXXThis()) {
1472 IndentScope Indent(*this);
1473 OS << "capture this";
1474 }
Aaron Ballman9371dd22014-03-14 18:34:04 +00001475 for (const auto &I : D->captures()) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001476 IndentScope Indent(*this);
1477 OS << "capture";
Aaron Ballman9371dd22014-03-14 18:34:04 +00001478 if (I.isByRef())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001479 OS << " byref";
Aaron Ballman9371dd22014-03-14 18:34:04 +00001480 if (I.isNested())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001481 OS << " nested";
Aaron Ballman9371dd22014-03-14 18:34:04 +00001482 if (I.getVariable()) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001483 OS << ' ';
Aaron Ballman9371dd22014-03-14 18:34:04 +00001484 dumpBareDeclRef(I.getVariable());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001485 }
Aaron Ballman9371dd22014-03-14 18:34:04 +00001486 if (I.hasCopyExpr())
1487 dumpStmt(I.getCopyExpr());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001488 }
Richard Trieude5cc7d2013-01-31 01:44:26 +00001489 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001490 dumpStmt(D->getBody());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001491}
1492
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001493//===----------------------------------------------------------------------===//
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001494// Stmt dumping methods.
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001495//===----------------------------------------------------------------------===//
1496
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001497void ASTDumper::dumpStmt(const Stmt *S) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001498 IndentScope Indent(*this);
1499
1500 if (!S) {
Richard Trieud215b8d2013-01-26 01:31:20 +00001501 ColorScope Color(*this, NullColor);
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001502 OS << "<<<NULL>>>";
1503 return;
1504 }
1505
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001506 if (const DeclStmt *DS = dyn_cast<DeclStmt>(S)) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001507 VisitDeclStmt(DS);
1508 return;
1509 }
1510
David Blaikie7d170102013-05-15 07:37:26 +00001511 setMoreChildren(!S->children().empty());
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001512 ConstStmtVisitor<ASTDumper>::Visit(S);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001513 setMoreChildren(false);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001514 for (Stmt::const_child_range CI = S->children(); CI; ++CI) {
1515 Stmt::const_child_range Next = CI;
Richard Trieude5cc7d2013-01-31 01:44:26 +00001516 ++Next;
1517 if (!Next)
1518 lastChild();
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001519 dumpStmt(*CI);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001520 }
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001521}
1522
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001523void ASTDumper::VisitStmt(const Stmt *Node) {
Richard Trieud215b8d2013-01-26 01:31:20 +00001524 {
1525 ColorScope Color(*this, StmtColor);
1526 OS << Node->getStmtClassName();
1527 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001528 dumpPointer(Node);
1529 dumpSourceRange(Node->getSourceRange());
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001530}
1531
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001532void ASTDumper::VisitDeclStmt(const DeclStmt *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001533 VisitStmt(Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001534 for (DeclStmt::const_decl_iterator I = Node->decl_begin(),
1535 E = Node->decl_end();
Richard Trieude5cc7d2013-01-31 01:44:26 +00001536 I != E; ++I) {
1537 if (I + 1 == E)
1538 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001539 dumpDecl(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001540 }
Ted Kremenek433a4922007-12-12 06:59:42 +00001541}
1542
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001543void ASTDumper::VisitAttributedStmt(const AttributedStmt *Node) {
Alexander Kornienko5bc364e2013-01-07 17:53:08 +00001544 VisitStmt(Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001545 for (ArrayRef<const Attr *>::iterator I = Node->getAttrs().begin(),
1546 E = Node->getAttrs().end();
1547 I != E; ++I) {
Richard Trieude5cc7d2013-01-31 01:44:26 +00001548 if (I + 1 == E)
1549 lastChild();
Alexander Kornienko5bc364e2013-01-07 17:53:08 +00001550 dumpAttr(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001551 }
Alexander Kornienko5bc364e2013-01-07 17:53:08 +00001552}
1553
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001554void ASTDumper::VisitLabelStmt(const LabelStmt *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001555 VisitStmt(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001556 OS << " '" << Node->getName() << "'";
Chris Lattnercbe4f772007-08-08 22:51:59 +00001557}
1558
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001559void ASTDumper::VisitGotoStmt(const GotoStmt *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001560 VisitStmt(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001561 OS << " '" << Node->getLabel()->getName() << "'";
1562 dumpPointer(Node->getLabel());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001563}
1564
Pavel Labath1ef83422013-09-04 14:35:00 +00001565void ASTDumper::VisitCXXCatchStmt(const CXXCatchStmt *Node) {
1566 VisitStmt(Node);
1567 dumpDecl(Node->getExceptionDecl());
1568}
1569
Chris Lattnercbe4f772007-08-08 22:51:59 +00001570//===----------------------------------------------------------------------===//
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001571// Expr dumping methods.
Chris Lattnercbe4f772007-08-08 22:51:59 +00001572//===----------------------------------------------------------------------===//
1573
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001574void ASTDumper::VisitExpr(const Expr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001575 VisitStmt(Node);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001576 dumpType(Node->getType());
1577
Richard Trieud215b8d2013-01-26 01:31:20 +00001578 {
1579 ColorScope Color(*this, ValueKindColor);
1580 switch (Node->getValueKind()) {
1581 case VK_RValue:
1582 break;
1583 case VK_LValue:
1584 OS << " lvalue";
1585 break;
1586 case VK_XValue:
1587 OS << " xvalue";
1588 break;
1589 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001590 }
1591
Richard Trieud215b8d2013-01-26 01:31:20 +00001592 {
1593 ColorScope Color(*this, ObjectKindColor);
1594 switch (Node->getObjectKind()) {
1595 case OK_Ordinary:
1596 break;
1597 case OK_BitField:
1598 OS << " bitfield";
1599 break;
1600 case OK_ObjCProperty:
1601 OS << " objcproperty";
1602 break;
1603 case OK_ObjCSubscript:
1604 OS << " objcsubscript";
1605 break;
1606 case OK_VectorComponent:
1607 OS << " vectorcomponent";
1608 break;
1609 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001610 }
Chris Lattnercbe4f772007-08-08 22:51:59 +00001611}
1612
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001613static void dumpBasePath(raw_ostream &OS, const CastExpr *Node) {
John McCallcf142162010-08-07 06:22:56 +00001614 if (Node->path_empty())
Anders Carlssona70cff62010-04-24 19:06:50 +00001615 return;
1616
1617 OS << " (";
1618 bool First = true;
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001619 for (CastExpr::path_const_iterator I = Node->path_begin(),
1620 E = Node->path_end();
1621 I != E; ++I) {
Anders Carlssona70cff62010-04-24 19:06:50 +00001622 const CXXBaseSpecifier *Base = *I;
1623 if (!First)
1624 OS << " -> ";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001625
Anders Carlssona70cff62010-04-24 19:06:50 +00001626 const CXXRecordDecl *RD =
1627 cast<CXXRecordDecl>(Base->getType()->getAs<RecordType>()->getDecl());
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001628
Anders Carlssona70cff62010-04-24 19:06:50 +00001629 if (Base->isVirtual())
1630 OS << "virtual ";
1631 OS << RD->getName();
1632 First = false;
1633 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001634
Anders Carlssona70cff62010-04-24 19:06:50 +00001635 OS << ')';
1636}
1637
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001638void ASTDumper::VisitCastExpr(const CastExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001639 VisitExpr(Node);
Richard Trieud215b8d2013-01-26 01:31:20 +00001640 OS << " <";
1641 {
1642 ColorScope Color(*this, CastColor);
1643 OS << Node->getCastKindName();
1644 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001645 dumpBasePath(OS, Node);
Anders Carlssona70cff62010-04-24 19:06:50 +00001646 OS << ">";
Anders Carlssond7923c62009-08-22 23:33:40 +00001647}
1648
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001649void ASTDumper::VisitDeclRefExpr(const DeclRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001650 VisitExpr(Node);
Ted Kremenek5f64ca82007-09-10 17:32:55 +00001651
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001652 OS << " ";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001653 dumpBareDeclRef(Node->getDecl());
Chandler Carruth8d26bb02011-05-01 23:48:14 +00001654 if (Node->getDecl() != Node->getFoundDecl()) {
1655 OS << " (";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001656 dumpBareDeclRef(Node->getFoundDecl());
Chandler Carruth8d26bb02011-05-01 23:48:14 +00001657 OS << ")";
1658 }
John McCall351762c2011-02-07 10:33:21 +00001659}
1660
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001661void ASTDumper::VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001662 VisitExpr(Node);
John McCall76d09942009-12-11 21:50:11 +00001663 OS << " (";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001664 if (!Node->requiresADL())
1665 OS << "no ";
Benjamin Kramerb11416d2010-04-17 09:33:03 +00001666 OS << "ADL) = '" << Node->getName() << '\'';
John McCall76d09942009-12-11 21:50:11 +00001667
1668 UnresolvedLookupExpr::decls_iterator
1669 I = Node->decls_begin(), E = Node->decls_end();
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001670 if (I == E)
1671 OS << " empty";
John McCall76d09942009-12-11 21:50:11 +00001672 for (; I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001673 dumpPointer(*I);
John McCall76d09942009-12-11 21:50:11 +00001674}
1675
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001676void ASTDumper::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001677 VisitExpr(Node);
Steve Naroff5d5efca2008-03-12 13:19:12 +00001678
Richard Trieud215b8d2013-01-26 01:31:20 +00001679 {
1680 ColorScope Color(*this, DeclKindNameColor);
1681 OS << " " << Node->getDecl()->getDeclKindName() << "Decl";
1682 }
1683 OS << "='" << *Node->getDecl() << "'";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001684 dumpPointer(Node->getDecl());
Steve Naroffb3424a92008-05-23 22:01:24 +00001685 if (Node->isFreeIvar())
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001686 OS << " isFreeIvar";
Steve Naroff5d5efca2008-03-12 13:19:12 +00001687}
1688
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001689void ASTDumper::VisitPredefinedExpr(const PredefinedExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001690 VisitExpr(Node);
Chris Lattnercbe4f772007-08-08 22:51:59 +00001691 switch (Node->getIdentType()) {
David Blaikie83d382b2011-09-23 05:06:16 +00001692 default: llvm_unreachable("unknown case");
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001693 case PredefinedExpr::Func: OS << " __func__"; break;
1694 case PredefinedExpr::Function: OS << " __FUNCTION__"; break;
David Majnemerbed356a2013-11-06 23:31:56 +00001695 case PredefinedExpr::FuncDName: OS << " __FUNCDNAME__"; break;
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001696 case PredefinedExpr::LFunction: OS << " L__FUNCTION__"; break;
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001697 case PredefinedExpr::PrettyFunction: OS << " __PRETTY_FUNCTION__";break;
Reid Kleckner52eddda2014-04-08 18:13:24 +00001698 case PredefinedExpr::FuncSig: OS << " __FUNCSIG__"; break;
Chris Lattnercbe4f772007-08-08 22:51:59 +00001699 }
1700}
1701
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001702void ASTDumper::VisitCharacterLiteral(const CharacterLiteral *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001703 VisitExpr(Node);
Richard Trieud215b8d2013-01-26 01:31:20 +00001704 ColorScope Color(*this, ValueColor);
Richard Trieu364ee422011-11-03 23:56:23 +00001705 OS << " " << Node->getValue();
Chris Lattnercbe4f772007-08-08 22:51:59 +00001706}
1707
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001708void ASTDumper::VisitIntegerLiteral(const IntegerLiteral *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001709 VisitExpr(Node);
Chris Lattnercbe4f772007-08-08 22:51:59 +00001710
1711 bool isSigned = Node->getType()->isSignedIntegerType();
Richard Trieud215b8d2013-01-26 01:31:20 +00001712 ColorScope Color(*this, ValueColor);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001713 OS << " " << Node->getValue().toString(10, isSigned);
Chris Lattnercbe4f772007-08-08 22:51:59 +00001714}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001715
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001716void ASTDumper::VisitFloatingLiteral(const FloatingLiteral *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001717 VisitExpr(Node);
Richard Trieud215b8d2013-01-26 01:31:20 +00001718 ColorScope Color(*this, ValueColor);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001719 OS << " " << Node->getValueAsApproximateDouble();
Chris Lattnercbe4f772007-08-08 22:51:59 +00001720}
Chris Lattner1c20a172007-08-26 03:42:43 +00001721
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001722void ASTDumper::VisitStringLiteral(const StringLiteral *Str) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001723 VisitExpr(Str);
Richard Trieud215b8d2013-01-26 01:31:20 +00001724 ColorScope Color(*this, ValueColor);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001725 OS << " ";
Richard Trieudc355912012-06-13 20:25:24 +00001726 Str->outputString(OS);
Chris Lattnercbe4f772007-08-08 22:51:59 +00001727}
Chris Lattner84ca3762007-08-30 01:00:35 +00001728
Richard Smithf0514962014-06-03 08:24:28 +00001729void ASTDumper::VisitInitListExpr(const InitListExpr *ILE) {
1730 VisitExpr(ILE);
1731 if (auto *Filler = ILE->getArrayFiller()) {
1732 if (!ILE->getNumInits())
1733 lastChild();
1734 IndentScope Indent(*this);
1735 OS << "array filler";
1736 lastChild();
1737 dumpStmt(Filler);
1738 }
1739 if (auto *Field = ILE->getInitializedFieldInUnion()) {
1740 OS << " field ";
1741 dumpBareDeclRef(Field);
1742 }
1743}
1744
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001745void ASTDumper::VisitUnaryOperator(const UnaryOperator *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001746 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001747 OS << " " << (Node->isPostfix() ? "postfix" : "prefix")
1748 << " '" << UnaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
Chris Lattnercbe4f772007-08-08 22:51:59 +00001749}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001750
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001751void ASTDumper::VisitUnaryExprOrTypeTraitExpr(
1752 const UnaryExprOrTypeTraitExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001753 VisitExpr(Node);
Peter Collingbournee190dee2011-03-11 19:24:49 +00001754 switch(Node->getKind()) {
1755 case UETT_SizeOf:
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001756 OS << " sizeof";
Peter Collingbournee190dee2011-03-11 19:24:49 +00001757 break;
1758 case UETT_AlignOf:
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001759 OS << " alignof";
Peter Collingbournee190dee2011-03-11 19:24:49 +00001760 break;
1761 case UETT_VecStep:
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001762 OS << " vec_step";
Peter Collingbournee190dee2011-03-11 19:24:49 +00001763 break;
1764 }
Sebastian Redl6f282892008-11-11 17:56:53 +00001765 if (Node->isArgumentType())
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001766 dumpType(Node->getArgumentType());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001767}
Chris Lattnerdb3b3ff2007-08-09 17:35:30 +00001768
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001769void ASTDumper::VisitMemberExpr(const MemberExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001770 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001771 OS << " " << (Node->isArrow() ? "->" : ".") << *Node->getMemberDecl();
1772 dumpPointer(Node->getMemberDecl());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001773}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001774
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001775void ASTDumper::VisitExtVectorElementExpr(const ExtVectorElementExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001776 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001777 OS << " " << Node->getAccessor().getNameStart();
Chris Lattnercbe4f772007-08-08 22:51:59 +00001778}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001779
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001780void ASTDumper::VisitBinaryOperator(const BinaryOperator *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001781 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001782 OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
Chris Lattner86928112007-08-25 02:00:02 +00001783}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001784
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001785void ASTDumper::VisitCompoundAssignOperator(
1786 const CompoundAssignOperator *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001787 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001788 OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode())
1789 << "' ComputeLHSTy=";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001790 dumpBareType(Node->getComputationLHSType());
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001791 OS << " ComputeResultTy=";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001792 dumpBareType(Node->getComputationResultType());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001793}
Chris Lattnercbe4f772007-08-08 22:51:59 +00001794
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001795void ASTDumper::VisitBlockExpr(const BlockExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001796 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001797 dumpDecl(Node->getBlockDecl());
John McCall351762c2011-02-07 10:33:21 +00001798}
1799
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001800void ASTDumper::VisitOpaqueValueExpr(const OpaqueValueExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001801 VisitExpr(Node);
John McCallfe96e0b2011-11-06 09:01:30 +00001802
Richard Trieude5cc7d2013-01-31 01:44:26 +00001803 if (Expr *Source = Node->getSourceExpr()) {
1804 lastChild();
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001805 dumpStmt(Source);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001806 }
John McCallfe96e0b2011-11-06 09:01:30 +00001807}
1808
Chris Lattnercbe4f772007-08-08 22:51:59 +00001809// GNU extensions.
1810
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001811void ASTDumper::VisitAddrLabelExpr(const AddrLabelExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001812 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001813 OS << " " << Node->getLabel()->getName();
1814 dumpPointer(Node->getLabel());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001815}
1816
Chris Lattner8f184b12007-08-09 18:03:18 +00001817//===----------------------------------------------------------------------===//
1818// C++ Expressions
1819//===----------------------------------------------------------------------===//
Chris Lattnercbe4f772007-08-08 22:51:59 +00001820
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001821void ASTDumper::VisitCXXNamedCastExpr(const CXXNamedCastExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001822 VisitExpr(Node);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001823 OS << " " << Node->getCastName()
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001824 << "<" << Node->getTypeAsWritten().getAsString() << ">"
Anders Carlssona70cff62010-04-24 19:06:50 +00001825 << " <" << Node->getCastKindName();
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001826 dumpBasePath(OS, Node);
Anders Carlssona70cff62010-04-24 19:06:50 +00001827 OS << ">";
Chris Lattnercbe4f772007-08-08 22:51:59 +00001828}
1829
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001830void ASTDumper::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001831 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001832 OS << " " << (Node->getValue() ? "true" : "false");
Chris Lattnercbe4f772007-08-08 22:51:59 +00001833}
1834
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001835void ASTDumper::VisitCXXThisExpr(const CXXThisExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001836 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001837 OS << " this";
Douglas Gregor8ea1f532008-11-04 14:56:14 +00001838}
1839
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001840void ASTDumper::VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001841 VisitExpr(Node);
Eli Friedman29538892011-09-02 17:38:59 +00001842 OS << " functional cast to " << Node->getTypeAsWritten().getAsString()
1843 << " <" << Node->getCastKindName() << ">";
Douglas Gregore200adc2008-10-27 19:41:14 +00001844}
1845
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001846void ASTDumper::VisitCXXConstructExpr(const CXXConstructExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001847 VisitExpr(Node);
John McCalleba90cd2010-02-02 19:03:45 +00001848 CXXConstructorDecl *Ctor = Node->getConstructor();
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001849 dumpType(Ctor->getType());
Anders Carlsson073846832009-08-12 00:21:52 +00001850 if (Node->isElidable())
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001851 OS << " elidable";
John McCall85370042010-08-07 06:38:55 +00001852 if (Node->requiresZeroInitialization())
1853 OS << " zeroing";
Anders Carlsson073846832009-08-12 00:21:52 +00001854}
1855
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001856void ASTDumper::VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001857 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001858 OS << " ";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001859 dumpCXXTemporary(Node->getTemporary());
Anders Carlsson073846832009-08-12 00:21:52 +00001860}
1861
Richard Smithe6c01442013-06-05 00:46:14 +00001862void
1863ASTDumper::VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *Node) {
1864 VisitExpr(Node);
1865 if (const ValueDecl *VD = Node->getExtendingDecl()) {
1866 OS << " extended by ";
1867 dumpBareDeclRef(VD);
1868 }
1869}
1870
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001871void ASTDumper::VisitExprWithCleanups(const ExprWithCleanups *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001872 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001873 for (unsigned i = 0, e = Node->getNumObjects(); i != e; ++i)
1874 dumpDeclRef(Node->getObject(i), "cleanup");
Anders Carlsson073846832009-08-12 00:21:52 +00001875}
1876
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001877void ASTDumper::dumpCXXTemporary(const CXXTemporary *Temporary) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001878 OS << "(CXXTemporary";
1879 dumpPointer(Temporary);
1880 OS << ")";
Anders Carlsson073846832009-08-12 00:21:52 +00001881}
1882
Anders Carlsson76f4a902007-08-21 17:43:55 +00001883//===----------------------------------------------------------------------===//
1884// Obj-C Expressions
1885//===----------------------------------------------------------------------===//
1886
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001887void ASTDumper::VisitObjCMessageExpr(const ObjCMessageExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001888 VisitExpr(Node);
Aaron Ballmanb190f972014-01-03 17:59:55 +00001889 OS << " selector=";
1890 Node->getSelector().print(OS);
Douglas Gregor9a129192010-04-21 00:45:42 +00001891 switch (Node->getReceiverKind()) {
1892 case ObjCMessageExpr::Instance:
1893 break;
1894
1895 case ObjCMessageExpr::Class:
1896 OS << " class=";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001897 dumpBareType(Node->getClassReceiver());
Douglas Gregor9a129192010-04-21 00:45:42 +00001898 break;
1899
1900 case ObjCMessageExpr::SuperInstance:
1901 OS << " super (instance)";
1902 break;
1903
1904 case ObjCMessageExpr::SuperClass:
1905 OS << " super (class)";
1906 break;
1907 }
Ted Kremenek36748da2008-02-29 22:04:05 +00001908}
1909
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001910void ASTDumper::VisitObjCBoxedExpr(const ObjCBoxedExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001911 VisitExpr(Node);
Aaron Ballmanb190f972014-01-03 17:59:55 +00001912 OS << " selector=";
1913 Node->getBoxingMethod()->getSelector().print(OS);
Argyrios Kyrtzidis9dd40892012-05-10 20:02:31 +00001914}
1915
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001916void ASTDumper::VisitObjCAtCatchStmt(const ObjCAtCatchStmt *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001917 VisitStmt(Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001918 if (const VarDecl *CatchParam = Node->getCatchParamDecl())
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001919 dumpDecl(CatchParam);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001920 else
Douglas Gregor96c79492010-04-23 22:50:49 +00001921 OS << " catch all";
Douglas Gregor96c79492010-04-23 22:50:49 +00001922}
1923
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001924void ASTDumper::VisitObjCEncodeExpr(const ObjCEncodeExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001925 VisitExpr(Node);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001926 dumpType(Node->getEncodedType());
Anders Carlssonc5a81eb2007-08-22 15:14:15 +00001927}
1928
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001929void ASTDumper::VisitObjCSelectorExpr(const ObjCSelectorExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001930 VisitExpr(Node);
Mike Stump11289f42009-09-09 15:08:12 +00001931
Aaron Ballmanb190f972014-01-03 17:59:55 +00001932 OS << " ";
1933 Node->getSelector().print(OS);
Fariborz Jahanian4bef4622007-10-16 20:40:23 +00001934}
1935
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001936void ASTDumper::VisitObjCProtocolExpr(const ObjCProtocolExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001937 VisitExpr(Node);
Mike Stump11289f42009-09-09 15:08:12 +00001938
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001939 OS << ' ' << *Node->getProtocol();
Fariborz Jahaniana32aaef2007-10-17 16:58:11 +00001940}
Daniel Dunbar4b8c6db2008-08-30 05:35:15 +00001941
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001942void ASTDumper::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001943 VisitExpr(Node);
John McCallb7bd14f2010-12-02 01:19:52 +00001944 if (Node->isImplicitProperty()) {
Fariborz Jahanian0f0b3022010-12-22 19:46:35 +00001945 OS << " Kind=MethodRef Getter=\"";
1946 if (Node->getImplicitPropertyGetter())
Aaron Ballmanb190f972014-01-03 17:59:55 +00001947 Node->getImplicitPropertyGetter()->getSelector().print(OS);
Fariborz Jahanian0f0b3022010-12-22 19:46:35 +00001948 else
1949 OS << "(null)";
1950
1951 OS << "\" Setter=\"";
John McCallb7bd14f2010-12-02 01:19:52 +00001952 if (ObjCMethodDecl *Setter = Node->getImplicitPropertySetter())
Aaron Ballmanb190f972014-01-03 17:59:55 +00001953 Setter->getSelector().print(OS);
John McCallb7bd14f2010-12-02 01:19:52 +00001954 else
1955 OS << "(null)";
1956 OS << "\"";
1957 } else {
Benjamin Kramerb89514a2011-10-14 18:45:37 +00001958 OS << " Kind=PropertyRef Property=\"" << *Node->getExplicitProperty() <<'"';
John McCallb7bd14f2010-12-02 01:19:52 +00001959 }
Fariborz Jahanian8a1810f2008-11-22 18:39:36 +00001960
Fariborz Jahanian681c0752010-10-14 16:04:05 +00001961 if (Node->isSuperReceiver())
1962 OS << " super";
Argyrios Kyrtzidisab468b02012-03-30 00:19:18 +00001963
1964 OS << " Messaging=";
1965 if (Node->isMessagingGetter() && Node->isMessagingSetter())
1966 OS << "Getter&Setter";
1967 else if (Node->isMessagingGetter())
1968 OS << "Getter";
1969 else if (Node->isMessagingSetter())
1970 OS << "Setter";
Douglas Gregor8ea1f532008-11-04 14:56:14 +00001971}
1972
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001973void ASTDumper::VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001974 VisitExpr(Node);
Ted Kremeneke65b0862012-03-06 20:05:56 +00001975 if (Node->isArraySubscriptRefExpr())
1976 OS << " Kind=ArraySubscript GetterForArray=\"";
1977 else
1978 OS << " Kind=DictionarySubscript GetterForDictionary=\"";
1979 if (Node->getAtIndexMethodDecl())
Aaron Ballmanb190f972014-01-03 17:59:55 +00001980 Node->getAtIndexMethodDecl()->getSelector().print(OS);
Ted Kremeneke65b0862012-03-06 20:05:56 +00001981 else
1982 OS << "(null)";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001983
Ted Kremeneke65b0862012-03-06 20:05:56 +00001984 if (Node->isArraySubscriptRefExpr())
1985 OS << "\" SetterForArray=\"";
1986 else
1987 OS << "\" SetterForDictionary=\"";
1988 if (Node->setAtIndexMethodDecl())
Aaron Ballmanb190f972014-01-03 17:59:55 +00001989 Node->setAtIndexMethodDecl()->getSelector().print(OS);
Ted Kremeneke65b0862012-03-06 20:05:56 +00001990 else
1991 OS << "(null)";
1992}
1993
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001994void ASTDumper::VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001995 VisitExpr(Node);
Ted Kremeneke65b0862012-03-06 20:05:56 +00001996 OS << " " << (Node->getValue() ? "__objc_yes" : "__objc_no");
1997}
1998
Chris Lattnercbe4f772007-08-08 22:51:59 +00001999//===----------------------------------------------------------------------===//
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002000// Comments
2001//===----------------------------------------------------------------------===//
2002
2003const char *ASTDumper::getCommandName(unsigned CommandID) {
2004 if (Traits)
2005 return Traits->getCommandInfo(CommandID)->Name;
2006 const CommandInfo *Info = CommandTraits::getBuiltinCommandInfo(CommandID);
2007 if (Info)
2008 return Info->Name;
2009 return "<not a builtin command>";
2010}
2011
2012void ASTDumper::dumpFullComment(const FullComment *C) {
2013 if (!C)
2014 return;
2015
2016 FC = C;
2017 dumpComment(C);
Craig Topper36250ad2014-05-12 05:36:57 +00002018 FC = nullptr;
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002019}
2020
2021void ASTDumper::dumpComment(const Comment *C) {
2022 IndentScope Indent(*this);
2023
2024 if (!C) {
Richard Trieud215b8d2013-01-26 01:31:20 +00002025 ColorScope Color(*this, NullColor);
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002026 OS << "<<<NULL>>>";
2027 return;
2028 }
2029
Richard Trieud215b8d2013-01-26 01:31:20 +00002030 {
2031 ColorScope Color(*this, CommentColor);
2032 OS << C->getCommentKindName();
2033 }
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002034 dumpPointer(C);
2035 dumpSourceRange(C->getSourceRange());
2036 ConstCommentVisitor<ASTDumper>::visit(C);
2037 for (Comment::child_iterator I = C->child_begin(), E = C->child_end();
Richard Trieude5cc7d2013-01-31 01:44:26 +00002038 I != E; ++I) {
2039 if (I + 1 == E)
2040 lastChild();
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002041 dumpComment(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +00002042 }
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002043}
2044
2045void ASTDumper::visitTextComment(const TextComment *C) {
2046 OS << " Text=\"" << C->getText() << "\"";
2047}
2048
2049void ASTDumper::visitInlineCommandComment(const InlineCommandComment *C) {
2050 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\"";
2051 switch (C->getRenderKind()) {
2052 case InlineCommandComment::RenderNormal:
2053 OS << " RenderNormal";
2054 break;
2055 case InlineCommandComment::RenderBold:
2056 OS << " RenderBold";
2057 break;
2058 case InlineCommandComment::RenderMonospaced:
2059 OS << " RenderMonospaced";
2060 break;
2061 case InlineCommandComment::RenderEmphasized:
2062 OS << " RenderEmphasized";
2063 break;
2064 }
2065
2066 for (unsigned i = 0, e = C->getNumArgs(); i != e; ++i)
2067 OS << " Arg[" << i << "]=\"" << C->getArgText(i) << "\"";
2068}
2069
2070void ASTDumper::visitHTMLStartTagComment(const HTMLStartTagComment *C) {
2071 OS << " Name=\"" << C->getTagName() << "\"";
2072 if (C->getNumAttrs() != 0) {
2073 OS << " Attrs: ";
2074 for (unsigned i = 0, e = C->getNumAttrs(); i != e; ++i) {
2075 const HTMLStartTagComment::Attribute &Attr = C->getAttr(i);
2076 OS << " \"" << Attr.Name << "=\"" << Attr.Value << "\"";
2077 }
2078 }
2079 if (C->isSelfClosing())
2080 OS << " SelfClosing";
2081}
2082
2083void ASTDumper::visitHTMLEndTagComment(const HTMLEndTagComment *C) {
2084 OS << " Name=\"" << C->getTagName() << "\"";
2085}
2086
2087void ASTDumper::visitBlockCommandComment(const BlockCommandComment *C) {
2088 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\"";
2089 for (unsigned i = 0, e = C->getNumArgs(); i != e; ++i)
2090 OS << " Arg[" << i << "]=\"" << C->getArgText(i) << "\"";
2091}
2092
2093void ASTDumper::visitParamCommandComment(const ParamCommandComment *C) {
2094 OS << " " << ParamCommandComment::getDirectionAsString(C->getDirection());
2095
2096 if (C->isDirectionExplicit())
2097 OS << " explicitly";
2098 else
2099 OS << " implicitly";
2100
2101 if (C->hasParamName()) {
2102 if (C->isParamIndexValid())
2103 OS << " Param=\"" << C->getParamName(FC) << "\"";
2104 else
2105 OS << " Param=\"" << C->getParamNameAsWritten() << "\"";
2106 }
2107
Dmitri Gribenkodbff5c72014-03-19 14:03:47 +00002108 if (C->isParamIndexValid() && !C->isVarArgParam())
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002109 OS << " ParamIndex=" << C->getParamIndex();
2110}
2111
2112void ASTDumper::visitTParamCommandComment(const TParamCommandComment *C) {
2113 if (C->hasParamName()) {
2114 if (C->isPositionValid())
2115 OS << " Param=\"" << C->getParamName(FC) << "\"";
2116 else
2117 OS << " Param=\"" << C->getParamNameAsWritten() << "\"";
2118 }
2119
2120 if (C->isPositionValid()) {
2121 OS << " Position=<";
2122 for (unsigned i = 0, e = C->getDepth(); i != e; ++i) {
2123 OS << C->getIndex(i);
2124 if (i != e - 1)
2125 OS << ", ";
2126 }
2127 OS << ">";
2128 }
2129}
2130
2131void ASTDumper::visitVerbatimBlockComment(const VerbatimBlockComment *C) {
2132 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\""
2133 " CloseName=\"" << C->getCloseName() << "\"";
2134}
2135
2136void ASTDumper::visitVerbatimBlockLineComment(
2137 const VerbatimBlockLineComment *C) {
2138 OS << " Text=\"" << C->getText() << "\"";
2139}
2140
2141void ASTDumper::visitVerbatimLineComment(const VerbatimLineComment *C) {
2142 OS << " Text=\"" << C->getText() << "\"";
2143}
2144
2145//===----------------------------------------------------------------------===//
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002146// Decl method implementations
2147//===----------------------------------------------------------------------===//
2148
Alp Tokeref6b0072014-01-04 13:47:14 +00002149LLVM_DUMP_METHOD void Decl::dump() const { dump(llvm::errs()); }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002150
Alp Tokeref6b0072014-01-04 13:47:14 +00002151LLVM_DUMP_METHOD void Decl::dump(raw_ostream &OS) const {
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002152 ASTDumper P(OS, &getASTContext().getCommentCommandTraits(),
2153 &getASTContext().getSourceManager());
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002154 P.dumpDecl(this);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002155}
2156
Alp Tokeref6b0072014-01-04 13:47:14 +00002157LLVM_DUMP_METHOD void Decl::dumpColor() const {
Richard Trieud215b8d2013-01-26 01:31:20 +00002158 ASTDumper P(llvm::errs(), &getASTContext().getCommentCommandTraits(),
2159 &getASTContext().getSourceManager(), /*ShowColors*/true);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002160 P.dumpDecl(this);
Richard Trieud215b8d2013-01-26 01:31:20 +00002161}
Richard Smith33937e72013-06-22 21:49:40 +00002162
Alp Tokeref6b0072014-01-04 13:47:14 +00002163LLVM_DUMP_METHOD void DeclContext::dumpLookups() const {
Richard Smith6ea05822013-06-24 01:45:33 +00002164 dumpLookups(llvm::errs());
2165}
2166
Alp Tokeref6b0072014-01-04 13:47:14 +00002167LLVM_DUMP_METHOD void DeclContext::dumpLookups(raw_ostream &OS) const {
Richard Smith33937e72013-06-22 21:49:40 +00002168 const DeclContext *DC = this;
2169 while (!DC->isTranslationUnit())
2170 DC = DC->getParent();
2171 ASTContext &Ctx = cast<TranslationUnitDecl>(DC)->getASTContext();
Richard Smith6ea05822013-06-24 01:45:33 +00002172 ASTDumper P(OS, &Ctx.getCommentCommandTraits(), &Ctx.getSourceManager());
Richard Smith33937e72013-06-22 21:49:40 +00002173 P.dumpLookups(this);
2174}
2175
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002176//===----------------------------------------------------------------------===//
Chris Lattnercbe4f772007-08-08 22:51:59 +00002177// Stmt method implementations
2178//===----------------------------------------------------------------------===//
2179
Alp Tokeref6b0072014-01-04 13:47:14 +00002180LLVM_DUMP_METHOD void Stmt::dump(SourceManager &SM) const {
Argyrios Kyrtzidisc049f752010-08-09 10:54:31 +00002181 dump(llvm::errs(), SM);
2182}
2183
Alp Tokeref6b0072014-01-04 13:47:14 +00002184LLVM_DUMP_METHOD void Stmt::dump(raw_ostream &OS, SourceManager &SM) const {
Craig Topper36250ad2014-05-12 05:36:57 +00002185 ASTDumper P(OS, nullptr, &SM);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002186 P.dumpStmt(this);
Chris Lattner779d5d92007-08-30 00:40:08 +00002187}
2188
Alp Tokeref6b0072014-01-04 13:47:14 +00002189LLVM_DUMP_METHOD void Stmt::dump() const {
Craig Topper36250ad2014-05-12 05:36:57 +00002190 ASTDumper P(llvm::errs(), nullptr, nullptr);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002191 P.dumpStmt(this);
Chris Lattnercbe4f772007-08-08 22:51:59 +00002192}
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002193
Alp Tokeref6b0072014-01-04 13:47:14 +00002194LLVM_DUMP_METHOD void Stmt::dumpColor() const {
Craig Topper36250ad2014-05-12 05:36:57 +00002195 ASTDumper P(llvm::errs(), nullptr, nullptr, /*ShowColors*/true);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002196 P.dumpStmt(this);
Richard Trieud215b8d2013-01-26 01:31:20 +00002197}
2198
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002199//===----------------------------------------------------------------------===//
2200// Comment method implementations
2201//===----------------------------------------------------------------------===//
2202
Craig Topper36250ad2014-05-12 05:36:57 +00002203LLVM_DUMP_METHOD void Comment::dump() const {
2204 dump(llvm::errs(), nullptr, nullptr);
2205}
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002206
Alp Tokeref6b0072014-01-04 13:47:14 +00002207LLVM_DUMP_METHOD void Comment::dump(const ASTContext &Context) const {
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002208 dump(llvm::errs(), &Context.getCommentCommandTraits(),
2209 &Context.getSourceManager());
2210}
2211
Alexander Kornienko00911f12013-01-15 12:20:21 +00002212void Comment::dump(raw_ostream &OS, const CommandTraits *Traits,
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002213 const SourceManager *SM) const {
2214 const FullComment *FC = dyn_cast<FullComment>(this);
2215 ASTDumper D(OS, Traits, SM);
2216 D.dumpFullComment(FC);
2217}
Richard Trieud215b8d2013-01-26 01:31:20 +00002218
Alp Tokeref6b0072014-01-04 13:47:14 +00002219LLVM_DUMP_METHOD void Comment::dumpColor() const {
Richard Trieud215b8d2013-01-26 01:31:20 +00002220 const FullComment *FC = dyn_cast<FullComment>(this);
Craig Topper36250ad2014-05-12 05:36:57 +00002221 ASTDumper D(llvm::errs(), nullptr, nullptr, /*ShowColors*/true);
Richard Trieud215b8d2013-01-26 01:31:20 +00002222 D.dumpFullComment(FC);
2223}