blob: 81342573359b5b229cf9f5c5aaf2b06fe58d17f2 [file] [log] [blame]
Alexander Kornienko18ec81b2012-12-13 13:59:55 +00001//===--- ASTDumper.cpp - Dumping implementation for ASTs ------------------===//
Chris Lattnercbe4f772007-08-08 22:51:59 +00002//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner5b12ab82007-12-29 19:59:25 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattnercbe4f772007-08-08 22:51:59 +00007//
8//===----------------------------------------------------------------------===//
9//
Alexander Kornienko18ec81b2012-12-13 13:59:55 +000010// This file implements the AST dump methods, which dump out the
Chris Lattnercbe4f772007-08-08 22:51:59 +000011// AST in a form that exposes type details and other fields.
12//
13//===----------------------------------------------------------------------===//
14
Chandler Carruth3a022472012-12-04 09:13:33 +000015#include "clang/AST/ASTContext.h"
Alexander Kornienko5bc364e2013-01-07 17:53:08 +000016#include "clang/AST/Attr.h"
Alexander Kornienkoebc17b52013-01-14 14:07:11 +000017#include "clang/AST/CommentVisitor.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000018#include "clang/AST/DeclCXX.h"
Richard Smith33937e72013-06-22 21:49:40 +000019#include "clang/AST/DeclLookups.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000020#include "clang/AST/DeclObjC.h"
Alexander Kornienko90ff6072012-12-20 02:09:13 +000021#include "clang/AST/DeclVisitor.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000022#include "clang/AST/StmtVisitor.h"
Alexander Kornienko90ff6072012-12-20 02:09:13 +000023#include "clang/Basic/Module.h"
Chris Lattner11e30d32007-08-30 06:17:34 +000024#include "clang/Basic/SourceManager.h"
Daniel Dunbar34a96c82009-12-03 09:13:13 +000025#include "llvm/Support/raw_ostream.h"
Chris Lattnercbe4f772007-08-08 22:51:59 +000026using namespace clang;
Alexander Kornienkoebc17b52013-01-14 14:07:11 +000027using namespace clang::comments;
Chris Lattnercbe4f772007-08-08 22:51:59 +000028
29//===----------------------------------------------------------------------===//
Alexander Kornienko18ec81b2012-12-13 13:59:55 +000030// ASTDumper Visitor
Chris Lattnercbe4f772007-08-08 22:51:59 +000031//===----------------------------------------------------------------------===//
32
33namespace {
Richard Trieud215b8d2013-01-26 01:31:20 +000034 // Colors used for various parts of the AST dump
Richard Trieu532018f2014-03-06 01:09:03 +000035 // Do not use bold yellow for any text. It is hard to read on white screens.
Richard Trieud215b8d2013-01-26 01:31:20 +000036
37 struct TerminalColor {
38 raw_ostream::Colors Color;
39 bool Bold;
40 };
41
Richard Trieu532018f2014-03-06 01:09:03 +000042 // Red - CastColor
43 // Green - TypeColor
44 // Bold Green - DeclKindNameColor, UndeserializedColor
45 // Yellow - AddressColor, LocationColor
46 // Blue - CommentColor, NullColor, IndentColor
47 // Bold Blue - AttrColor
48 // Bold Magenta - StmtColor
49 // Cyan - ValueKindColor, ObjectKindColor
50 // Bold Cyan - ValueColor, DeclNameColor
51
Richard Trieud215b8d2013-01-26 01:31:20 +000052 // Decl kind names (VarDecl, FunctionDecl, etc)
53 static const TerminalColor DeclKindNameColor = { raw_ostream::GREEN, true };
54 // Attr names (CleanupAttr, GuardedByAttr, etc)
55 static const TerminalColor AttrColor = { raw_ostream::BLUE, true };
56 // Statement names (DeclStmt, ImplicitCastExpr, etc)
57 static const TerminalColor StmtColor = { raw_ostream::MAGENTA, true };
58 // Comment names (FullComment, ParagraphComment, TextComment, etc)
Richard Trieu532018f2014-03-06 01:09:03 +000059 static const TerminalColor CommentColor = { raw_ostream::BLUE, false };
Richard Trieud215b8d2013-01-26 01:31:20 +000060
61 // Type names (int, float, etc, plus user defined types)
62 static const TerminalColor TypeColor = { raw_ostream::GREEN, false };
63
64 // Pointer address
65 static const TerminalColor AddressColor = { raw_ostream::YELLOW, false };
66 // Source locations
67 static const TerminalColor LocationColor = { raw_ostream::YELLOW, false };
68
69 // lvalue/xvalue
70 static const TerminalColor ValueKindColor = { raw_ostream::CYAN, false };
71 // bitfield/objcproperty/objcsubscript/vectorcomponent
72 static const TerminalColor ObjectKindColor = { raw_ostream::CYAN, false };
73
74 // Null statements
75 static const TerminalColor NullColor = { raw_ostream::BLUE, false };
76
Richard Smith1d209d02013-05-23 01:49:11 +000077 // Undeserialized entities
78 static const TerminalColor UndeserializedColor = { raw_ostream::GREEN, true };
79
Richard Trieud215b8d2013-01-26 01:31:20 +000080 // CastKind from CastExpr's
81 static const TerminalColor CastColor = { raw_ostream::RED, false };
82
83 // Value of the statement
84 static const TerminalColor ValueColor = { raw_ostream::CYAN, true };
85 // Decl names
86 static const TerminalColor DeclNameColor = { raw_ostream::CYAN, true };
87
Richard Trieude5cc7d2013-01-31 01:44:26 +000088 // Indents ( `, -. | )
89 static const TerminalColor IndentColor = { raw_ostream::BLUE, false };
90
Alexander Kornienko90ff6072012-12-20 02:09:13 +000091 class ASTDumper
Alexander Kornienko540bacb2013-02-01 12:35:51 +000092 : public ConstDeclVisitor<ASTDumper>, public ConstStmtVisitor<ASTDumper>,
Alexander Kornienkoebc17b52013-01-14 14:07:11 +000093 public ConstCommentVisitor<ASTDumper> {
Chris Lattner0e62c1c2011-07-23 10:55:15 +000094 raw_ostream &OS;
Alexander Kornienkoebc17b52013-01-14 14:07:11 +000095 const CommandTraits *Traits;
96 const SourceManager *SM;
Manuel Klimek874030e2012-11-07 00:33:12 +000097 bool IsFirstLine;
Mike Stump11289f42009-09-09 15:08:12 +000098
Richard Trieude5cc7d2013-01-31 01:44:26 +000099 // Indicates whether more child are expected at the current tree depth
100 enum IndentType { IT_Child, IT_LastChild };
101
102 /// Indents[i] indicates if another child exists at level i.
103 /// Used by Indent() to print the tree structure.
104 llvm::SmallVector<IndentType, 32> Indents;
105
106 /// Indicates that more children will be needed at this indent level.
107 /// If true, prevents lastChild() from marking the node as the last child.
108 /// This is used when there are multiple collections of children to be
109 /// dumped as well as during conditional node dumping.
110 bool MoreChildren;
111
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000112 /// Keep track of the last location we print out so that we can
113 /// print out deltas from then on out.
Chris Lattner11e30d32007-08-30 06:17:34 +0000114 const char *LastLocFilename;
115 unsigned LastLocLine;
Douglas Gregor7de59662009-05-29 20:38:28 +0000116
Alexander Kornienkoebc17b52013-01-14 14:07:11 +0000117 /// The \c FullComment parent of the comment being dumped.
118 const FullComment *FC;
119
Richard Trieud215b8d2013-01-26 01:31:20 +0000120 bool ShowColors;
121
Manuel Klimek874030e2012-11-07 00:33:12 +0000122 class IndentScope {
Alexander Kornienko18ec81b2012-12-13 13:59:55 +0000123 ASTDumper &Dumper;
Richard Trieude5cc7d2013-01-31 01:44:26 +0000124 // Preserve the Dumper's MoreChildren value from the previous IndentScope
125 bool MoreChildren;
Manuel Klimek874030e2012-11-07 00:33:12 +0000126 public:
Alexander Kornienko18ec81b2012-12-13 13:59:55 +0000127 IndentScope(ASTDumper &Dumper) : Dumper(Dumper) {
Richard Trieude5cc7d2013-01-31 01:44:26 +0000128 MoreChildren = Dumper.hasMoreChildren();
129 Dumper.setMoreChildren(false);
Manuel Klimek874030e2012-11-07 00:33:12 +0000130 Dumper.indent();
131 }
132 ~IndentScope() {
Richard Trieude5cc7d2013-01-31 01:44:26 +0000133 Dumper.setMoreChildren(MoreChildren);
Manuel Klimek874030e2012-11-07 00:33:12 +0000134 Dumper.unindent();
135 }
136 };
137
Richard Trieud215b8d2013-01-26 01:31:20 +0000138 class ColorScope {
139 ASTDumper &Dumper;
140 public:
141 ColorScope(ASTDumper &Dumper, TerminalColor Color)
142 : Dumper(Dumper) {
143 if (Dumper.ShowColors)
144 Dumper.OS.changeColor(Color.Color, Color.Bold);
145 }
146 ~ColorScope() {
147 if (Dumper.ShowColors)
148 Dumper.OS.resetColor();
149 }
150 };
151
Richard Smithdcc2c452014-03-17 23:00:06 +0000152 class ChildDumper {
153 ASTDumper &Dumper;
154
155 const Decl *Prev;
156 bool PrevRef;
157 public:
158 ChildDumper(ASTDumper &Dumper) : Dumper(Dumper), Prev(0) {}
159 ~ChildDumper() {
160 if (Prev) {
161 Dumper.lastChild();
162 dump(0);
163 }
164 }
165
166 // FIXME: This should take an arbitrary callable as the dumping action.
167 void dump(const Decl *D, bool Ref = false) {
168 if (Prev) {
169 if (PrevRef)
170 Dumper.dumpDeclRef(Prev);
171 else
172 Dumper.dumpDecl(Prev);
173 }
174 Prev = D;
175 PrevRef = Ref;
176 }
177 void dumpRef(const Decl *D) { dump(D, true); }
178
179 // Give up ownership of the children of the node. By calling this,
180 // the caller takes back responsibility for calling lastChild().
181 void release() { dump(0); }
182 };
183
Chris Lattnercbe4f772007-08-08 22:51:59 +0000184 public:
Alexander Kornienkoebc17b52013-01-14 14:07:11 +0000185 ASTDumper(raw_ostream &OS, const CommandTraits *Traits,
186 const SourceManager *SM)
Richard Smith56d12152013-01-31 02:04:38 +0000187 : OS(OS), Traits(Traits), SM(SM), IsFirstLine(true), MoreChildren(false),
188 LastLocFilename(""), LastLocLine(~0U), FC(0),
Richard Trieud215b8d2013-01-26 01:31:20 +0000189 ShowColors(SM && SM->getDiagnostics().getShowColors()) { }
190
191 ASTDumper(raw_ostream &OS, const CommandTraits *Traits,
192 const SourceManager *SM, bool ShowColors)
Richard Smith56d12152013-01-31 02:04:38 +0000193 : OS(OS), Traits(Traits), SM(SM), IsFirstLine(true), MoreChildren(false),
194 LastLocFilename(""), LastLocLine(~0U),
Richard Trieude5cc7d2013-01-31 01:44:26 +0000195 ShowColors(ShowColors) { }
Mike Stump11289f42009-09-09 15:08:12 +0000196
Alexander Kornienko18ec81b2012-12-13 13:59:55 +0000197 ~ASTDumper() {
Manuel Klimek874030e2012-11-07 00:33:12 +0000198 OS << "\n";
199 }
200
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000201 void dumpDecl(const Decl *D);
202 void dumpStmt(const Stmt *S);
Alexander Kornienkoebc17b52013-01-14 14:07:11 +0000203 void dumpFullComment(const FullComment *C);
Mike Stump11289f42009-09-09 15:08:12 +0000204
Richard Trieude5cc7d2013-01-31 01:44:26 +0000205 // Formatting
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000206 void indent();
207 void unindent();
Richard Trieude5cc7d2013-01-31 01:44:26 +0000208 void lastChild();
209 bool hasMoreChildren();
210 void setMoreChildren(bool Value);
211
212 // Utilities
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000213 void dumpPointer(const void *Ptr);
214 void dumpSourceRange(SourceRange R);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000215 void dumpLocation(SourceLocation Loc);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000216 void dumpBareType(QualType T);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000217 void dumpType(QualType T);
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000218 void dumpBareDeclRef(const Decl *Node);
Alexander Kornienko9bdeb112012-12-20 12:23:54 +0000219 void dumpDeclRef(const Decl *Node, const char *Label = 0);
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000220 void dumpName(const NamedDecl *D);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000221 bool hasNodes(const DeclContext *DC);
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000222 void dumpDeclContext(const DeclContext *DC);
Richard Smith33937e72013-06-22 21:49:40 +0000223 void dumpLookups(const DeclContext *DC);
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000224 void dumpAttr(const Attr *A);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000225
226 // C++ Utilities
227 void dumpAccessSpecifier(AccessSpecifier AS);
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000228 void dumpCXXCtorInitializer(const CXXCtorInitializer *Init);
229 void dumpTemplateParameters(const TemplateParameterList *TPL);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000230 void dumpTemplateArgumentListInfo(const TemplateArgumentListInfo &TALI);
231 void dumpTemplateArgumentLoc(const TemplateArgumentLoc &A);
232 void dumpTemplateArgumentList(const TemplateArgumentList &TAL);
233 void dumpTemplateArgument(const TemplateArgument &A,
234 SourceRange R = SourceRange());
235
236 // Decls
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000237 void VisitLabelDecl(const LabelDecl *D);
238 void VisitTypedefDecl(const TypedefDecl *D);
239 void VisitEnumDecl(const EnumDecl *D);
240 void VisitRecordDecl(const RecordDecl *D);
241 void VisitEnumConstantDecl(const EnumConstantDecl *D);
242 void VisitIndirectFieldDecl(const IndirectFieldDecl *D);
243 void VisitFunctionDecl(const FunctionDecl *D);
244 void VisitFieldDecl(const FieldDecl *D);
245 void VisitVarDecl(const VarDecl *D);
246 void VisitFileScopeAsmDecl(const FileScopeAsmDecl *D);
247 void VisitImportDecl(const ImportDecl *D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000248
249 // C++ Decls
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000250 void VisitNamespaceDecl(const NamespaceDecl *D);
251 void VisitUsingDirectiveDecl(const UsingDirectiveDecl *D);
252 void VisitNamespaceAliasDecl(const NamespaceAliasDecl *D);
253 void VisitTypeAliasDecl(const TypeAliasDecl *D);
254 void VisitTypeAliasTemplateDecl(const TypeAliasTemplateDecl *D);
255 void VisitCXXRecordDecl(const CXXRecordDecl *D);
256 void VisitStaticAssertDecl(const StaticAssertDecl *D);
Richard Smith20ade552014-03-17 23:34:53 +0000257 template<typename TemplateDecl>
258 void VisitTemplateDecl(const TemplateDecl *D, bool DumpExplicitInst);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000259 void VisitFunctionTemplateDecl(const FunctionTemplateDecl *D);
260 void VisitClassTemplateDecl(const ClassTemplateDecl *D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000261 void VisitClassTemplateSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000262 const ClassTemplateSpecializationDecl *D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000263 void VisitClassTemplatePartialSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000264 const ClassTemplatePartialSpecializationDecl *D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000265 void VisitClassScopeFunctionSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000266 const ClassScopeFunctionSpecializationDecl *D);
Richard Smithd25789a2013-09-18 01:36:02 +0000267 void VisitVarTemplateDecl(const VarTemplateDecl *D);
268 void VisitVarTemplateSpecializationDecl(
269 const VarTemplateSpecializationDecl *D);
270 void VisitVarTemplatePartialSpecializationDecl(
271 const VarTemplatePartialSpecializationDecl *D);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000272 void VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D);
273 void VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D);
274 void VisitTemplateTemplateParmDecl(const TemplateTemplateParmDecl *D);
275 void VisitUsingDecl(const UsingDecl *D);
276 void VisitUnresolvedUsingTypenameDecl(const UnresolvedUsingTypenameDecl *D);
277 void VisitUnresolvedUsingValueDecl(const UnresolvedUsingValueDecl *D);
278 void VisitUsingShadowDecl(const UsingShadowDecl *D);
279 void VisitLinkageSpecDecl(const LinkageSpecDecl *D);
280 void VisitAccessSpecDecl(const AccessSpecDecl *D);
281 void VisitFriendDecl(const FriendDecl *D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000282
283 // ObjC Decls
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000284 void VisitObjCIvarDecl(const ObjCIvarDecl *D);
285 void VisitObjCMethodDecl(const ObjCMethodDecl *D);
286 void VisitObjCCategoryDecl(const ObjCCategoryDecl *D);
287 void VisitObjCCategoryImplDecl(const ObjCCategoryImplDecl *D);
288 void VisitObjCProtocolDecl(const ObjCProtocolDecl *D);
289 void VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D);
290 void VisitObjCImplementationDecl(const ObjCImplementationDecl *D);
291 void VisitObjCCompatibleAliasDecl(const ObjCCompatibleAliasDecl *D);
292 void VisitObjCPropertyDecl(const ObjCPropertyDecl *D);
293 void VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D);
294 void VisitBlockDecl(const BlockDecl *D);
Mike Stump11289f42009-09-09 15:08:12 +0000295
Chris Lattner84ca3762007-08-30 01:00:35 +0000296 // Stmts.
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000297 void VisitStmt(const Stmt *Node);
298 void VisitDeclStmt(const DeclStmt *Node);
299 void VisitAttributedStmt(const AttributedStmt *Node);
300 void VisitLabelStmt(const LabelStmt *Node);
301 void VisitGotoStmt(const GotoStmt *Node);
Pavel Labath1ef83422013-09-04 14:35:00 +0000302 void VisitCXXCatchStmt(const CXXCatchStmt *Node);
Mike Stump11289f42009-09-09 15:08:12 +0000303
Chris Lattner84ca3762007-08-30 01:00:35 +0000304 // Exprs
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000305 void VisitExpr(const Expr *Node);
306 void VisitCastExpr(const CastExpr *Node);
307 void VisitDeclRefExpr(const DeclRefExpr *Node);
308 void VisitPredefinedExpr(const PredefinedExpr *Node);
309 void VisitCharacterLiteral(const CharacterLiteral *Node);
310 void VisitIntegerLiteral(const IntegerLiteral *Node);
311 void VisitFloatingLiteral(const FloatingLiteral *Node);
312 void VisitStringLiteral(const StringLiteral *Str);
313 void VisitUnaryOperator(const UnaryOperator *Node);
314 void VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *Node);
315 void VisitMemberExpr(const MemberExpr *Node);
316 void VisitExtVectorElementExpr(const ExtVectorElementExpr *Node);
317 void VisitBinaryOperator(const BinaryOperator *Node);
318 void VisitCompoundAssignOperator(const CompoundAssignOperator *Node);
319 void VisitAddrLabelExpr(const AddrLabelExpr *Node);
320 void VisitBlockExpr(const BlockExpr *Node);
321 void VisitOpaqueValueExpr(const OpaqueValueExpr *Node);
Chris Lattner84ca3762007-08-30 01:00:35 +0000322
323 // C++
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000324 void VisitCXXNamedCastExpr(const CXXNamedCastExpr *Node);
325 void VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *Node);
326 void VisitCXXThisExpr(const CXXThisExpr *Node);
327 void VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *Node);
328 void VisitCXXConstructExpr(const CXXConstructExpr *Node);
329 void VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *Node);
Richard Smithe6c01442013-06-05 00:46:14 +0000330 void VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000331 void VisitExprWithCleanups(const ExprWithCleanups *Node);
332 void VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *Node);
333 void dumpCXXTemporary(const CXXTemporary *Temporary);
Faisal Vali2b391ab2013-09-26 19:54:12 +0000334 void VisitLambdaExpr(const LambdaExpr *Node) {
335 VisitExpr(Node);
336 dumpDecl(Node->getLambdaClass());
337 }
Mike Stump11289f42009-09-09 15:08:12 +0000338
Chris Lattner84ca3762007-08-30 01:00:35 +0000339 // ObjC
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000340 void VisitObjCAtCatchStmt(const ObjCAtCatchStmt *Node);
341 void VisitObjCEncodeExpr(const ObjCEncodeExpr *Node);
342 void VisitObjCMessageExpr(const ObjCMessageExpr *Node);
343 void VisitObjCBoxedExpr(const ObjCBoxedExpr *Node);
344 void VisitObjCSelectorExpr(const ObjCSelectorExpr *Node);
345 void VisitObjCProtocolExpr(const ObjCProtocolExpr *Node);
346 void VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *Node);
347 void VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *Node);
348 void VisitObjCIvarRefExpr(const ObjCIvarRefExpr *Node);
349 void VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *Node);
Alexander Kornienkoebc17b52013-01-14 14:07:11 +0000350
351 // Comments.
352 const char *getCommandName(unsigned CommandID);
353 void dumpComment(const Comment *C);
354
355 // Inline comments.
356 void visitTextComment(const TextComment *C);
357 void visitInlineCommandComment(const InlineCommandComment *C);
358 void visitHTMLStartTagComment(const HTMLStartTagComment *C);
359 void visitHTMLEndTagComment(const HTMLEndTagComment *C);
360
361 // Block comments.
362 void visitBlockCommandComment(const BlockCommandComment *C);
363 void visitParamCommandComment(const ParamCommandComment *C);
364 void visitTParamCommandComment(const TParamCommandComment *C);
365 void visitVerbatimBlockComment(const VerbatimBlockComment *C);
366 void visitVerbatimBlockLineComment(const VerbatimBlockLineComment *C);
367 void visitVerbatimLineComment(const VerbatimLineComment *C);
Chris Lattnercbe4f772007-08-08 22:51:59 +0000368 };
369}
370
371//===----------------------------------------------------------------------===//
Chris Lattner11e30d32007-08-30 06:17:34 +0000372// Utilities
373//===----------------------------------------------------------------------===//
374
Richard Trieude5cc7d2013-01-31 01:44:26 +0000375// Print out the appropriate tree structure using the Indents vector.
376// Example of tree and the Indents vector at each level.
377// A { }
378// |-B { IT_Child }
379// | `-C { IT_Child, IT_LastChild }
380// `-D { IT_LastChild }
381// |-E { IT_LastChild, IT_Child }
382// `-F { IT_LastChild, IT_LastChild }
383// Type non-last element, last element
384// IT_Child "| " "|-"
385// IT_LastChild " " "`-"
Alexander Kornienko18ec81b2012-12-13 13:59:55 +0000386void ASTDumper::indent() {
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000387 if (IsFirstLine)
388 IsFirstLine = false;
389 else
390 OS << "\n";
Richard Trieude5cc7d2013-01-31 01:44:26 +0000391
392 ColorScope Color(*this, IndentColor);
Craig Topper2341c0d2013-07-04 03:08:24 +0000393 for (SmallVectorImpl<IndentType>::const_iterator I = Indents.begin(),
394 E = Indents.end();
Richard Trieude5cc7d2013-01-31 01:44:26 +0000395 I != E; ++I) {
396 switch (*I) {
Richard Smith56d12152013-01-31 02:04:38 +0000397 case IT_Child:
398 if (I == E - 1)
399 OS << "|-";
400 else
401 OS << "| ";
402 continue;
403 case IT_LastChild:
404 if (I == E - 1)
405 OS << "`-";
406 else
407 OS << " ";
408 continue;
Richard Trieude5cc7d2013-01-31 01:44:26 +0000409 }
Richard Smith56d12152013-01-31 02:04:38 +0000410 llvm_unreachable("Invalid IndentType");
Richard Trieude5cc7d2013-01-31 01:44:26 +0000411 }
412 Indents.push_back(IT_Child);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000413}
414
Alexander Kornienko18ec81b2012-12-13 13:59:55 +0000415void ASTDumper::unindent() {
Richard Trieude5cc7d2013-01-31 01:44:26 +0000416 Indents.pop_back();
417}
418
419// Call before each potential last child node is to be dumped. If MoreChildren
420// is false, then this is the last child, otherwise treat as a regular node.
421void ASTDumper::lastChild() {
422 if (!hasMoreChildren())
423 Indents.back() = IT_LastChild;
424}
425
426// MoreChildren should be set before calling another function that may print
427// additional nodes to prevent conflicting final child nodes.
428bool ASTDumper::hasMoreChildren() {
429 return MoreChildren;
430}
431
432void ASTDumper::setMoreChildren(bool Value) {
433 MoreChildren = Value;
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000434}
435
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000436void ASTDumper::dumpPointer(const void *Ptr) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000437 ColorScope Color(*this, AddressColor);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000438 OS << ' ' << Ptr;
439}
440
Alexander Kornienko18ec81b2012-12-13 13:59:55 +0000441void ASTDumper::dumpLocation(SourceLocation Loc) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000442 ColorScope Color(*this, LocationColor);
Chris Lattner53e384f2009-01-16 07:00:02 +0000443 SourceLocation SpellingLoc = SM->getSpellingLoc(Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000444
Chris Lattner11e30d32007-08-30 06:17:34 +0000445 // The general format we print out is filename:line:col, but we drop pieces
446 // that haven't changed since the last loc printed.
Chris Lattnerf1ca7d32009-01-27 07:57:44 +0000447 PresumedLoc PLoc = SM->getPresumedLoc(SpellingLoc);
448
Douglas Gregor453b0122010-11-12 07:15:47 +0000449 if (PLoc.isInvalid()) {
450 OS << "<invalid sloc>";
451 return;
452 }
453
Chris Lattnerf1ca7d32009-01-27 07:57:44 +0000454 if (strcmp(PLoc.getFilename(), LastLocFilename) != 0) {
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000455 OS << PLoc.getFilename() << ':' << PLoc.getLine()
456 << ':' << PLoc.getColumn();
Chris Lattnerf1ca7d32009-01-27 07:57:44 +0000457 LastLocFilename = PLoc.getFilename();
458 LastLocLine = PLoc.getLine();
459 } else if (PLoc.getLine() != LastLocLine) {
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000460 OS << "line" << ':' << PLoc.getLine()
461 << ':' << PLoc.getColumn();
Chris Lattnerf1ca7d32009-01-27 07:57:44 +0000462 LastLocLine = PLoc.getLine();
Chris Lattner11e30d32007-08-30 06:17:34 +0000463 } else {
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000464 OS << "col" << ':' << PLoc.getColumn();
Chris Lattner11e30d32007-08-30 06:17:34 +0000465 }
466}
467
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000468void ASTDumper::dumpSourceRange(SourceRange R) {
Chris Lattner11e30d32007-08-30 06:17:34 +0000469 // Can't translate locations if a SourceManager isn't available.
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000470 if (!SM)
471 return;
Mike Stump11289f42009-09-09 15:08:12 +0000472
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000473 OS << " <";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000474 dumpLocation(R.getBegin());
Chris Lattnera7c19fe2007-10-16 22:36:42 +0000475 if (R.getBegin() != R.getEnd()) {
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000476 OS << ", ";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000477 dumpLocation(R.getEnd());
Chris Lattner11e30d32007-08-30 06:17:34 +0000478 }
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000479 OS << ">";
Mike Stump11289f42009-09-09 15:08:12 +0000480
Chris Lattner11e30d32007-08-30 06:17:34 +0000481 // <t2.c:123:421[blah], t2.c:412:321>
482
483}
484
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000485void ASTDumper::dumpBareType(QualType T) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000486 ColorScope Color(*this, TypeColor);
487
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000488 SplitQualType T_split = T.split();
489 OS << "'" << QualType::getAsString(T_split) << "'";
490
491 if (!T.isNull()) {
492 // If the type is sugared, also dump a (shallow) desugared type.
493 SplitQualType D_split = T.getSplitDesugaredType();
494 if (T_split != D_split)
495 OS << ":'" << QualType::getAsString(D_split) << "'";
496 }
497}
498
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000499void ASTDumper::dumpType(QualType T) {
500 OS << ' ';
501 dumpBareType(T);
502}
503
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000504void ASTDumper::dumpBareDeclRef(const Decl *D) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000505 {
506 ColorScope Color(*this, DeclKindNameColor);
507 OS << D->getDeclKindName();
508 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000509 dumpPointer(D);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000510
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000511 if (const NamedDecl *ND = dyn_cast<NamedDecl>(D)) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000512 ColorScope Color(*this, DeclNameColor);
David Blaikied4da8722013-05-14 21:04:00 +0000513 OS << " '" << ND->getDeclName() << '\'';
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000514 }
515
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000516 if (const ValueDecl *VD = dyn_cast<ValueDecl>(D))
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000517 dumpType(VD->getType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000518}
519
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000520void ASTDumper::dumpDeclRef(const Decl *D, const char *Label) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000521 if (!D)
522 return;
523
524 IndentScope Indent(*this);
525 if (Label)
526 OS << Label << ' ';
527 dumpBareDeclRef(D);
528}
529
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000530void ASTDumper::dumpName(const NamedDecl *ND) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000531 if (ND->getDeclName()) {
532 ColorScope Color(*this, DeclNameColor);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000533 OS << ' ' << ND->getNameAsString();
Richard Trieud215b8d2013-01-26 01:31:20 +0000534 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000535}
536
Richard Trieude5cc7d2013-01-31 01:44:26 +0000537bool ASTDumper::hasNodes(const DeclContext *DC) {
538 if (!DC)
539 return false;
540
Richard Smith1d209d02013-05-23 01:49:11 +0000541 return DC->hasExternalLexicalStorage() ||
542 DC->noload_decls_begin() != DC->noload_decls_end();
Richard Trieude5cc7d2013-01-31 01:44:26 +0000543}
544
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000545void ASTDumper::dumpDeclContext(const DeclContext *DC) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000546 if (!DC)
547 return;
Richard Smithdcc2c452014-03-17 23:00:06 +0000548
549 ChildDumper Children(*this);
550 for (auto *D : DC->noload_decls())
551 Children.dump(D);
552
553 if (DC->hasExternalLexicalStorage()) {
554 Children.release();
555
Richard Smith1d209d02013-05-23 01:49:11 +0000556 lastChild();
557 IndentScope Indent(*this);
558 ColorScope Color(*this, UndeserializedColor);
559 OS << "<undeserialized declarations>";
560 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000561}
562
Richard Smith33937e72013-06-22 21:49:40 +0000563void ASTDumper::dumpLookups(const DeclContext *DC) {
564 IndentScope Indent(*this);
565
566 OS << "StoredDeclsMap ";
567 dumpBareDeclRef(cast<Decl>(DC));
568
569 const DeclContext *Primary = DC->getPrimaryContext();
570 if (Primary != DC) {
571 OS << " primary";
572 dumpPointer(cast<Decl>(Primary));
573 }
574
575 bool HasUndeserializedLookups = Primary->hasExternalVisibleStorage();
576
577 DeclContext::all_lookups_iterator I = Primary->noload_lookups_begin(),
578 E = Primary->noload_lookups_end();
579 while (I != E) {
580 DeclarationName Name = I.getLookupName();
581 DeclContextLookupResult R = *I++;
582 if (I == E && !HasUndeserializedLookups)
583 lastChild();
584
585 IndentScope Indent(*this);
586 OS << "DeclarationName ";
587 {
588 ColorScope Color(*this, DeclNameColor);
589 OS << '\'' << Name << '\'';
590 }
591
592 for (DeclContextLookupResult::iterator RI = R.begin(), RE = R.end();
593 RI != RE; ++RI) {
594 if (RI + 1 == RE)
595 lastChild();
596 dumpDeclRef(*RI);
Richard Smith15fc7df2013-10-22 23:50:38 +0000597 if ((*RI)->isHidden())
598 OS << " hidden";
Richard Smith33937e72013-06-22 21:49:40 +0000599 }
600 }
601
602 if (HasUndeserializedLookups) {
603 lastChild();
604 IndentScope Indent(*this);
605 ColorScope Color(*this, UndeserializedColor);
606 OS << "<undeserialized lookups>";
607 }
608}
609
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000610void ASTDumper::dumpAttr(const Attr *A) {
611 IndentScope Indent(*this);
Richard Trieud215b8d2013-01-26 01:31:20 +0000612 {
613 ColorScope Color(*this, AttrColor);
Aaron Ballman36a53502014-01-16 13:03:14 +0000614
Richard Trieud215b8d2013-01-26 01:31:20 +0000615 switch (A->getKind()) {
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000616#define ATTR(X) case attr::X: OS << #X; break;
617#include "clang/Basic/AttrList.inc"
Richard Trieud215b8d2013-01-26 01:31:20 +0000618 default: llvm_unreachable("unexpected attribute kind");
619 }
620 OS << "Attr";
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000621 }
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000622 dumpPointer(A);
623 dumpSourceRange(A->getRange());
624#include "clang/AST/AttrDump.inc"
Aaron Ballman36a53502014-01-16 13:03:14 +0000625 if (A->isImplicit())
626 OS << " Implicit";
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000627}
628
Richard Smith71bec062013-10-15 21:58:30 +0000629static void dumpPreviousDeclImpl(raw_ostream &OS, ...) {}
630
631template<typename T>
632static void dumpPreviousDeclImpl(raw_ostream &OS, const Mergeable<T> *D) {
Rafael Espindola8db352d2013-10-17 15:37:26 +0000633 const T *First = D->getFirstDecl();
Richard Smith71bec062013-10-15 21:58:30 +0000634 if (First != D)
635 OS << " first " << First;
Richard Smithf5f43542013-02-07 01:35:44 +0000636}
637
638template<typename T>
Richard Smith71bec062013-10-15 21:58:30 +0000639static void dumpPreviousDeclImpl(raw_ostream &OS, const Redeclarable<T> *D) {
640 const T *Prev = D->getPreviousDecl();
641 if (Prev)
642 OS << " prev " << Prev;
Richard Smithf5f43542013-02-07 01:35:44 +0000643}
644
Richard Smith71bec062013-10-15 21:58:30 +0000645/// Dump the previous declaration in the redeclaration chain for a declaration,
646/// if any.
647static void dumpPreviousDecl(raw_ostream &OS, const Decl *D) {
Richard Smithf5f43542013-02-07 01:35:44 +0000648 switch (D->getKind()) {
649#define DECL(DERIVED, BASE) \
650 case Decl::DERIVED: \
Richard Smith71bec062013-10-15 21:58:30 +0000651 return dumpPreviousDeclImpl(OS, cast<DERIVED##Decl>(D));
Richard Smithf5f43542013-02-07 01:35:44 +0000652#define ABSTRACT_DECL(DECL)
653#include "clang/AST/DeclNodes.inc"
654 }
655 llvm_unreachable("Decl that isn't part of DeclNodes.inc!");
656}
657
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000658//===----------------------------------------------------------------------===//
659// C++ Utilities
660//===----------------------------------------------------------------------===//
661
662void ASTDumper::dumpAccessSpecifier(AccessSpecifier AS) {
663 switch (AS) {
664 case AS_none:
665 break;
666 case AS_public:
667 OS << "public";
668 break;
669 case AS_protected:
670 OS << "protected";
671 break;
672 case AS_private:
673 OS << "private";
674 break;
675 }
676}
677
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000678void ASTDumper::dumpCXXCtorInitializer(const CXXCtorInitializer *Init) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000679 IndentScope Indent(*this);
680 OS << "CXXCtorInitializer";
681 if (Init->isAnyMemberInitializer()) {
682 OS << ' ';
683 dumpBareDeclRef(Init->getAnyMember());
684 } else {
685 dumpType(QualType(Init->getBaseClass(), 0));
686 }
687 dumpStmt(Init->getInit());
688}
689
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000690void ASTDumper::dumpTemplateParameters(const TemplateParameterList *TPL) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000691 if (!TPL)
692 return;
693
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000694 for (TemplateParameterList::const_iterator I = TPL->begin(), E = TPL->end();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000695 I != E; ++I)
696 dumpDecl(*I);
697}
698
699void ASTDumper::dumpTemplateArgumentListInfo(
700 const TemplateArgumentListInfo &TALI) {
Richard Trieude5cc7d2013-01-31 01:44:26 +0000701 for (unsigned i = 0, e = TALI.size(); i < e; ++i) {
702 if (i + 1 == e)
703 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000704 dumpTemplateArgumentLoc(TALI[i]);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000705 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000706}
707
708void ASTDumper::dumpTemplateArgumentLoc(const TemplateArgumentLoc &A) {
709 dumpTemplateArgument(A.getArgument(), A.getSourceRange());
710}
711
712void ASTDumper::dumpTemplateArgumentList(const TemplateArgumentList &TAL) {
713 for (unsigned i = 0, e = TAL.size(); i < e; ++i)
714 dumpTemplateArgument(TAL[i]);
715}
716
717void ASTDumper::dumpTemplateArgument(const TemplateArgument &A, SourceRange R) {
718 IndentScope Indent(*this);
719 OS << "TemplateArgument";
720 if (R.isValid())
721 dumpSourceRange(R);
722
723 switch (A.getKind()) {
724 case TemplateArgument::Null:
725 OS << " null";
726 break;
727 case TemplateArgument::Type:
728 OS << " type";
Richard Trieude5cc7d2013-01-31 01:44:26 +0000729 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000730 dumpType(A.getAsType());
731 break;
732 case TemplateArgument::Declaration:
733 OS << " decl";
Richard Trieude5cc7d2013-01-31 01:44:26 +0000734 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000735 dumpDeclRef(A.getAsDecl());
736 break;
737 case TemplateArgument::NullPtr:
738 OS << " nullptr";
739 break;
740 case TemplateArgument::Integral:
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000741 OS << " integral " << A.getAsIntegral();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000742 break;
743 case TemplateArgument::Template:
744 OS << " template ";
745 A.getAsTemplate().dump(OS);
746 break;
747 case TemplateArgument::TemplateExpansion:
748 OS << " template expansion";
749 A.getAsTemplateOrTemplatePattern().dump(OS);
750 break;
751 case TemplateArgument::Expression:
752 OS << " expr";
Richard Trieude5cc7d2013-01-31 01:44:26 +0000753 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000754 dumpStmt(A.getAsExpr());
755 break;
756 case TemplateArgument::Pack:
757 OS << " pack";
758 for (TemplateArgument::pack_iterator I = A.pack_begin(), E = A.pack_end();
Richard Trieude5cc7d2013-01-31 01:44:26 +0000759 I != E; ++I) {
760 if (I + 1 == E)
761 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000762 dumpTemplateArgument(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000763 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000764 break;
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000765 }
766}
767
Chris Lattner11e30d32007-08-30 06:17:34 +0000768//===----------------------------------------------------------------------===//
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000769// Decl dumping methods.
Chris Lattnercbe4f772007-08-08 22:51:59 +0000770//===----------------------------------------------------------------------===//
771
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000772void ASTDumper::dumpDecl(const Decl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000773 IndentScope Indent(*this);
Mike Stump11289f42009-09-09 15:08:12 +0000774
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000775 if (!D) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000776 ColorScope Color(*this, NullColor);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000777 OS << "<<<NULL>>>";
778 return;
Chris Lattnercbe4f772007-08-08 22:51:59 +0000779 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000780
Richard Trieud215b8d2013-01-26 01:31:20 +0000781 {
782 ColorScope Color(*this, DeclKindNameColor);
783 OS << D->getDeclKindName() << "Decl";
784 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000785 dumpPointer(D);
Richard Smithf5f43542013-02-07 01:35:44 +0000786 if (D->getLexicalDeclContext() != D->getDeclContext())
787 OS << " parent " << cast<Decl>(D->getDeclContext());
Richard Smith71bec062013-10-15 21:58:30 +0000788 dumpPreviousDecl(OS, D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000789 dumpSourceRange(D->getSourceRange());
Richard Smith15fc7df2013-10-22 23:50:38 +0000790 if (Module *M = D->getOwningModule())
791 OS << " in " << M->getFullModuleName();
792 if (const NamedDecl *ND = dyn_cast<NamedDecl>(D))
793 if (ND->isHidden())
794 OS << " hidden";
Richard Trieude5cc7d2013-01-31 01:44:26 +0000795
Aaron Ballmanb97112e2014-03-08 22:19:01 +0000796 bool HasAttrs = D->hasAttrs();
Richard Smithb39b9d52013-05-21 05:24:00 +0000797 const FullComment *Comment =
798 D->getASTContext().getLocalCommentForDeclUncached(D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000799 // Decls within functions are visited by the body
Richard Trieude5cc7d2013-01-31 01:44:26 +0000800 bool HasDeclContext = !isa<FunctionDecl>(*D) && !isa<ObjCMethodDecl>(*D) &&
801 hasNodes(dyn_cast<DeclContext>(D));
802
Richard Smithb39b9d52013-05-21 05:24:00 +0000803 setMoreChildren(HasAttrs || Comment || HasDeclContext);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000804 ConstDeclVisitor<ASTDumper>::Visit(D);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000805
Richard Smithb39b9d52013-05-21 05:24:00 +0000806 setMoreChildren(Comment || HasDeclContext);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000807 for (Decl::attr_iterator I = D->attr_begin(), E = D->attr_end();
808 I != E; ++I) {
809 if (I + 1 == E)
810 lastChild();
811 dumpAttr(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000812 }
813
814 setMoreChildren(HasDeclContext);
815 lastChild();
Richard Smithb39b9d52013-05-21 05:24:00 +0000816 dumpFullComment(Comment);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000817
Nick Lewyckya382db02013-08-27 03:15:56 +0000818 if (D->isInvalidDecl())
819 OS << " invalid";
820
Richard Trieude5cc7d2013-01-31 01:44:26 +0000821 setMoreChildren(false);
822 if (HasDeclContext)
Richard Smithf5f43542013-02-07 01:35:44 +0000823 dumpDeclContext(cast<DeclContext>(D));
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000824}
825
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000826void ASTDumper::VisitLabelDecl(const LabelDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000827 dumpName(D);
828}
829
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000830void ASTDumper::VisitTypedefDecl(const TypedefDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000831 dumpName(D);
832 dumpType(D->getUnderlyingType());
833 if (D->isModulePrivate())
834 OS << " __module_private__";
835}
836
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000837void ASTDumper::VisitEnumDecl(const EnumDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000838 if (D->isScoped()) {
839 if (D->isScopedUsingClassTag())
840 OS << " class";
841 else
842 OS << " struct";
843 }
844 dumpName(D);
845 if (D->isModulePrivate())
846 OS << " __module_private__";
847 if (D->isFixed())
848 dumpType(D->getIntegerType());
849}
850
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000851void ASTDumper::VisitRecordDecl(const RecordDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000852 OS << ' ' << D->getKindName();
853 dumpName(D);
854 if (D->isModulePrivate())
855 OS << " __module_private__";
Richard Smith99bc1b92013-08-30 05:32:29 +0000856 if (D->isCompleteDefinition())
857 OS << " definition";
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000858}
859
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000860void ASTDumper::VisitEnumConstantDecl(const EnumConstantDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000861 dumpName(D);
862 dumpType(D->getType());
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000863 if (const Expr *Init = D->getInitExpr()) {
Richard Trieude5cc7d2013-01-31 01:44:26 +0000864 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000865 dumpStmt(Init);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000866 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000867}
868
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000869void ASTDumper::VisitIndirectFieldDecl(const IndirectFieldDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000870 dumpName(D);
871 dumpType(D->getType());
Richard Smithdcc2c452014-03-17 23:00:06 +0000872
873 ChildDumper Children(*this);
Richard Smith8aa49222014-03-18 00:35:12 +0000874 for (auto *Child : D->chain())
875 Children.dumpRef(Child);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000876}
877
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000878void ASTDumper::VisitFunctionDecl(const FunctionDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000879 dumpName(D);
880 dumpType(D->getType());
881
Rafael Espindola6ae7e502013-04-03 19:27:57 +0000882 StorageClass SC = D->getStorageClass();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000883 if (SC != SC_None)
884 OS << ' ' << VarDecl::getStorageClassSpecifierString(SC);
885 if (D->isInlineSpecified())
886 OS << " inline";
887 if (D->isVirtualAsWritten())
888 OS << " virtual";
889 if (D->isModulePrivate())
890 OS << " __module_private__";
891
892 if (D->isPure())
893 OS << " pure";
894 else if (D->isDeletedAsWritten())
895 OS << " delete";
896
Richard Smithadaa0152013-05-17 02:09:46 +0000897 if (const FunctionProtoType *FPT = D->getType()->getAs<FunctionProtoType>()) {
898 FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo();
899 switch (EPI.ExceptionSpecType) {
900 default: break;
901 case EST_Unevaluated:
902 OS << " noexcept-unevaluated " << EPI.ExceptionSpecDecl;
903 break;
904 case EST_Uninstantiated:
905 OS << " noexcept-uninstantiated " << EPI.ExceptionSpecTemplate;
906 break;
907 }
908 }
909
Richard Trieude5cc7d2013-01-31 01:44:26 +0000910 bool OldMoreChildren = hasMoreChildren();
911 const FunctionTemplateSpecializationInfo *FTSI =
912 D->getTemplateSpecializationInfo();
913 bool HasTemplateSpecialization = FTSI;
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000914
Richard Trieude5cc7d2013-01-31 01:44:26 +0000915 bool HasNamedDecls = D->getDeclsInPrototypeScope().begin() !=
916 D->getDeclsInPrototypeScope().end();
917
918 bool HasFunctionDecls = D->param_begin() != D->param_end();
919
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000920 const CXXConstructorDecl *C = dyn_cast<CXXConstructorDecl>(D);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000921 bool HasCtorInitializers = C && C->init_begin() != C->init_end();
922
923 bool HasDeclarationBody = D->doesThisDeclarationHaveABody();
924
925 setMoreChildren(OldMoreChildren || HasNamedDecls || HasFunctionDecls ||
926 HasCtorInitializers || HasDeclarationBody);
927 if (HasTemplateSpecialization) {
928 lastChild();
929 dumpTemplateArgumentList(*FTSI->TemplateArguments);
930 }
931
932 setMoreChildren(OldMoreChildren || HasFunctionDecls ||
933 HasCtorInitializers || HasDeclarationBody);
Dmitri Gribenkof8579502013-01-12 19:30:44 +0000934 for (ArrayRef<NamedDecl *>::iterator
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000935 I = D->getDeclsInPrototypeScope().begin(),
Richard Trieude5cc7d2013-01-31 01:44:26 +0000936 E = D->getDeclsInPrototypeScope().end(); I != E; ++I) {
937 if (I + 1 == E)
938 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000939 dumpDecl(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000940 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000941
Richard Trieude5cc7d2013-01-31 01:44:26 +0000942 setMoreChildren(OldMoreChildren || HasCtorInitializers || HasDeclarationBody);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000943 for (FunctionDecl::param_const_iterator I = D->param_begin(),
944 E = D->param_end();
Richard Trieude5cc7d2013-01-31 01:44:26 +0000945 I != E; ++I) {
946 if (I + 1 == E)
947 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000948 dumpDecl(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000949 }
950
951 setMoreChildren(OldMoreChildren || HasDeclarationBody);
952 if (HasCtorInitializers)
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000953 for (CXXConstructorDecl::init_const_iterator I = C->init_begin(),
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000954 E = C->init_end();
955 I != E; ++I) {
Richard Trieude5cc7d2013-01-31 01:44:26 +0000956 if (I + 1 == E)
957 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000958 dumpCXXCtorInitializer(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000959 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000960
Richard Trieude5cc7d2013-01-31 01:44:26 +0000961 setMoreChildren(OldMoreChildren);
962 if (HasDeclarationBody) {
963 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000964 dumpStmt(D->getBody());
Richard Trieude5cc7d2013-01-31 01:44:26 +0000965 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000966}
967
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000968void ASTDumper::VisitFieldDecl(const FieldDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000969 dumpName(D);
970 dumpType(D->getType());
971 if (D->isMutable())
972 OS << " mutable";
973 if (D->isModulePrivate())
974 OS << " __module_private__";
Richard Trieude5cc7d2013-01-31 01:44:26 +0000975
976 bool OldMoreChildren = hasMoreChildren();
977 bool IsBitField = D->isBitField();
978 Expr *Init = D->getInClassInitializer();
979 bool HasInit = Init;
980
981 setMoreChildren(OldMoreChildren || HasInit);
982 if (IsBitField) {
983 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000984 dumpStmt(D->getBitWidth());
Richard Trieude5cc7d2013-01-31 01:44:26 +0000985 }
986 setMoreChildren(OldMoreChildren);
987 if (HasInit) {
988 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000989 dumpStmt(Init);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000990 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000991}
992
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000993void ASTDumper::VisitVarDecl(const VarDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000994 dumpName(D);
995 dumpType(D->getType());
Rafael Espindola6ae7e502013-04-03 19:27:57 +0000996 StorageClass SC = D->getStorageClass();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000997 if (SC != SC_None)
998 OS << ' ' << VarDecl::getStorageClassSpecifierString(SC);
Richard Smithfd3834f2013-04-13 02:43:54 +0000999 switch (D->getTLSKind()) {
1000 case VarDecl::TLS_None: break;
1001 case VarDecl::TLS_Static: OS << " tls"; break;
1002 case VarDecl::TLS_Dynamic: OS << " tls_dynamic"; break;
1003 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001004 if (D->isModulePrivate())
1005 OS << " __module_private__";
1006 if (D->isNRVOVariable())
1007 OS << " nrvo";
Richard Trieude5cc7d2013-01-31 01:44:26 +00001008 if (D->hasInit()) {
1009 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001010 dumpStmt(D->getInit());
Richard Trieude5cc7d2013-01-31 01:44:26 +00001011 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001012}
1013
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001014void ASTDumper::VisitFileScopeAsmDecl(const FileScopeAsmDecl *D) {
Richard Trieude5cc7d2013-01-31 01:44:26 +00001015 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001016 dumpStmt(D->getAsmString());
1017}
1018
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001019void ASTDumper::VisitImportDecl(const ImportDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001020 OS << ' ' << D->getImportedModule()->getFullModuleName();
1021}
1022
1023//===----------------------------------------------------------------------===//
1024// C++ Declarations
1025//===----------------------------------------------------------------------===//
1026
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001027void ASTDumper::VisitNamespaceDecl(const NamespaceDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001028 dumpName(D);
1029 if (D->isInline())
1030 OS << " inline";
1031 if (!D->isOriginalNamespace())
1032 dumpDeclRef(D->getOriginalNamespace(), "original");
1033}
1034
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001035void ASTDumper::VisitUsingDirectiveDecl(const UsingDirectiveDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001036 OS << ' ';
1037 dumpBareDeclRef(D->getNominatedNamespace());
1038}
1039
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001040void ASTDumper::VisitNamespaceAliasDecl(const NamespaceAliasDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001041 dumpName(D);
1042 dumpDeclRef(D->getAliasedNamespace());
1043}
1044
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001045void ASTDumper::VisitTypeAliasDecl(const TypeAliasDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001046 dumpName(D);
1047 dumpType(D->getUnderlyingType());
1048}
1049
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001050void ASTDumper::VisitTypeAliasTemplateDecl(const TypeAliasTemplateDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001051 dumpName(D);
1052 dumpTemplateParameters(D->getTemplateParameters());
1053 dumpDecl(D->getTemplatedDecl());
1054}
1055
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001056void ASTDumper::VisitCXXRecordDecl(const CXXRecordDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001057 VisitRecordDecl(D);
1058 if (!D->isCompleteDefinition())
1059 return;
1060
Aaron Ballman574705e2014-03-13 15:41:46 +00001061 for (const auto &I : D->bases()) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001062 IndentScope Indent(*this);
Aaron Ballman574705e2014-03-13 15:41:46 +00001063 if (I.isVirtual())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001064 OS << "virtual ";
Aaron Ballman574705e2014-03-13 15:41:46 +00001065 dumpAccessSpecifier(I.getAccessSpecifier());
1066 dumpType(I.getType());
1067 if (I.isPackExpansion())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001068 OS << "...";
1069 }
1070}
1071
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001072void ASTDumper::VisitStaticAssertDecl(const StaticAssertDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001073 dumpStmt(D->getAssertExpr());
Richard Trieude5cc7d2013-01-31 01:44:26 +00001074 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001075 dumpStmt(D->getMessage());
1076}
1077
Richard Smith20ade552014-03-17 23:34:53 +00001078template<typename TemplateDecl>
1079void ASTDumper::VisitTemplateDecl(const TemplateDecl *D,
1080 bool DumpExplicitInst) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001081 dumpName(D);
1082 dumpTemplateParameters(D->getTemplateParameters());
Richard Smithdcc2c452014-03-17 23:00:06 +00001083
1084 ChildDumper Children(*this);
1085 Children.dump(D->getTemplatedDecl());
1086
1087 for (auto *Child : D->specializations()) {
1088 switch (Child->getTemplateSpecializationKind()) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001089 case TSK_Undeclared:
1090 case TSK_ImplicitInstantiation:
Richard Smith20ade552014-03-17 23:34:53 +00001091 Children.dump(Child, /*Ref*/D != D->getCanonicalDecl());
1092 break;
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001093 case TSK_ExplicitInstantiationDeclaration:
1094 case TSK_ExplicitInstantiationDefinition:
Richard Smith20ade552014-03-17 23:34:53 +00001095 Children.dump(Child, /*Ref*/D != D->getCanonicalDecl() ||
1096 !DumpExplicitInst);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001097 break;
1098 case TSK_ExplicitSpecialization:
Richard Smithdcc2c452014-03-17 23:00:06 +00001099 Children.dumpRef(Child);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001100 break;
1101 }
1102 }
1103}
1104
Richard Smith20ade552014-03-17 23:34:53 +00001105void ASTDumper::VisitFunctionTemplateDecl(const FunctionTemplateDecl *D) {
1106 // FIXME: We don't add a declaration of a function template specialization
1107 // to its context when it's explicitly instantiated, so dump explicit
1108 // instantiations when we dump the template itself.
1109 VisitTemplateDecl(D, true);
1110}
1111
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001112void ASTDumper::VisitClassTemplateDecl(const ClassTemplateDecl *D) {
Richard Smith20ade552014-03-17 23:34:53 +00001113 VisitTemplateDecl(D, false);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001114}
1115
1116void ASTDumper::VisitClassTemplateSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001117 const ClassTemplateSpecializationDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001118 VisitCXXRecordDecl(D);
1119 dumpTemplateArgumentList(D->getTemplateArgs());
1120}
1121
1122void ASTDumper::VisitClassTemplatePartialSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001123 const ClassTemplatePartialSpecializationDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001124 VisitClassTemplateSpecializationDecl(D);
1125 dumpTemplateParameters(D->getTemplateParameters());
1126}
1127
1128void ASTDumper::VisitClassScopeFunctionSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001129 const ClassScopeFunctionSpecializationDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001130 dumpDeclRef(D->getSpecialization());
1131 if (D->hasExplicitTemplateArgs())
1132 dumpTemplateArgumentListInfo(D->templateArgs());
1133}
1134
Richard Smithd25789a2013-09-18 01:36:02 +00001135void ASTDumper::VisitVarTemplateDecl(const VarTemplateDecl *D) {
Richard Smith20ade552014-03-17 23:34:53 +00001136 VisitTemplateDecl(D, false);
Richard Smithd25789a2013-09-18 01:36:02 +00001137}
1138
1139void ASTDumper::VisitVarTemplateSpecializationDecl(
1140 const VarTemplateSpecializationDecl *D) {
1141 dumpTemplateArgumentList(D->getTemplateArgs());
1142 VisitVarDecl(D);
1143}
1144
1145void ASTDumper::VisitVarTemplatePartialSpecializationDecl(
1146 const VarTemplatePartialSpecializationDecl *D) {
1147 dumpTemplateParameters(D->getTemplateParameters());
1148 VisitVarTemplateSpecializationDecl(D);
1149}
1150
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001151void ASTDumper::VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001152 if (D->wasDeclaredWithTypename())
1153 OS << " typename";
1154 else
1155 OS << " class";
1156 if (D->isParameterPack())
1157 OS << " ...";
1158 dumpName(D);
1159 if (D->hasDefaultArgument())
1160 dumpType(D->getDefaultArgument());
1161}
1162
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001163void ASTDumper::VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001164 dumpType(D->getType());
1165 if (D->isParameterPack())
1166 OS << " ...";
1167 dumpName(D);
1168 if (D->hasDefaultArgument())
1169 dumpStmt(D->getDefaultArgument());
1170}
1171
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001172void ASTDumper::VisitTemplateTemplateParmDecl(
1173 const TemplateTemplateParmDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001174 if (D->isParameterPack())
1175 OS << " ...";
1176 dumpName(D);
1177 dumpTemplateParameters(D->getTemplateParameters());
1178 if (D->hasDefaultArgument())
1179 dumpTemplateArgumentLoc(D->getDefaultArgument());
1180}
1181
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001182void ASTDumper::VisitUsingDecl(const UsingDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001183 OS << ' ';
1184 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
1185 OS << D->getNameAsString();
1186}
1187
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001188void ASTDumper::VisitUnresolvedUsingTypenameDecl(
1189 const UnresolvedUsingTypenameDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001190 OS << ' ';
1191 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
1192 OS << D->getNameAsString();
1193}
1194
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001195void ASTDumper::VisitUnresolvedUsingValueDecl(const UnresolvedUsingValueDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001196 OS << ' ';
1197 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
1198 OS << D->getNameAsString();
1199 dumpType(D->getType());
1200}
1201
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001202void ASTDumper::VisitUsingShadowDecl(const UsingShadowDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001203 OS << ' ';
1204 dumpBareDeclRef(D->getTargetDecl());
1205}
1206
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001207void ASTDumper::VisitLinkageSpecDecl(const LinkageSpecDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001208 switch (D->getLanguage()) {
1209 case LinkageSpecDecl::lang_c: OS << " C"; break;
1210 case LinkageSpecDecl::lang_cxx: OS << " C++"; break;
1211 }
1212}
1213
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001214void ASTDumper::VisitAccessSpecDecl(const AccessSpecDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001215 OS << ' ';
1216 dumpAccessSpecifier(D->getAccess());
1217}
1218
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001219void ASTDumper::VisitFriendDecl(const FriendDecl *D) {
Richard Smithf5f43542013-02-07 01:35:44 +00001220 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001221 if (TypeSourceInfo *T = D->getFriendType())
1222 dumpType(T->getType());
1223 else
1224 dumpDecl(D->getFriendDecl());
1225}
1226
1227//===----------------------------------------------------------------------===//
1228// Obj-C Declarations
1229//===----------------------------------------------------------------------===//
1230
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001231void ASTDumper::VisitObjCIvarDecl(const ObjCIvarDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001232 dumpName(D);
1233 dumpType(D->getType());
1234 if (D->getSynthesize())
1235 OS << " synthesize";
1236
1237 switch (D->getAccessControl()) {
1238 case ObjCIvarDecl::None:
1239 OS << " none";
1240 break;
1241 case ObjCIvarDecl::Private:
1242 OS << " private";
1243 break;
1244 case ObjCIvarDecl::Protected:
1245 OS << " protected";
1246 break;
1247 case ObjCIvarDecl::Public:
1248 OS << " public";
1249 break;
1250 case ObjCIvarDecl::Package:
1251 OS << " package";
1252 break;
1253 }
1254}
1255
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001256void ASTDumper::VisitObjCMethodDecl(const ObjCMethodDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001257 if (D->isInstanceMethod())
1258 OS << " -";
1259 else
1260 OS << " +";
1261 dumpName(D);
Alp Toker314cc812014-01-25 16:55:45 +00001262 dumpType(D->getReturnType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001263
Richard Trieude5cc7d2013-01-31 01:44:26 +00001264 bool OldMoreChildren = hasMoreChildren();
1265 bool IsVariadic = D->isVariadic();
1266 bool HasBody = D->hasBody();
1267
1268 setMoreChildren(OldMoreChildren || IsVariadic || HasBody);
1269 if (D->isThisDeclarationADefinition()) {
1270 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001271 dumpDeclContext(D);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001272 } else {
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001273 for (ObjCMethodDecl::param_const_iterator I = D->param_begin(),
1274 E = D->param_end();
1275 I != E; ++I) {
Richard Trieude5cc7d2013-01-31 01:44:26 +00001276 if (I + 1 == E)
1277 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001278 dumpDecl(*I);
1279 }
1280 }
1281
Richard Trieude5cc7d2013-01-31 01:44:26 +00001282 setMoreChildren(OldMoreChildren || HasBody);
1283 if (IsVariadic) {
1284 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001285 IndentScope Indent(*this);
1286 OS << "...";
1287 }
1288
Richard Trieude5cc7d2013-01-31 01:44:26 +00001289 setMoreChildren(OldMoreChildren);
1290 if (HasBody) {
1291 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001292 dumpStmt(D->getBody());
Richard Trieude5cc7d2013-01-31 01:44:26 +00001293 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001294}
1295
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001296void ASTDumper::VisitObjCCategoryDecl(const ObjCCategoryDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001297 dumpName(D);
1298 dumpDeclRef(D->getClassInterface());
Richard Trieude5cc7d2013-01-31 01:44:26 +00001299 if (D->protocol_begin() == D->protocol_end())
1300 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001301 dumpDeclRef(D->getImplementation());
1302 for (ObjCCategoryDecl::protocol_iterator I = D->protocol_begin(),
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001303 E = D->protocol_end();
1304 I != E; ++I) {
Richard Trieude5cc7d2013-01-31 01:44:26 +00001305 if (I + 1 == E)
1306 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001307 dumpDeclRef(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001308 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001309}
1310
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001311void ASTDumper::VisitObjCCategoryImplDecl(const ObjCCategoryImplDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001312 dumpName(D);
1313 dumpDeclRef(D->getClassInterface());
Richard Trieude5cc7d2013-01-31 01:44:26 +00001314 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001315 dumpDeclRef(D->getCategoryDecl());
1316}
1317
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001318void ASTDumper::VisitObjCProtocolDecl(const ObjCProtocolDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001319 dumpName(D);
Richard Smithdcc2c452014-03-17 23:00:06 +00001320
1321 ChildDumper Children(*this);
1322 for (auto *D : D->protocols())
1323 Children.dumpRef(D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001324}
1325
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001326void ASTDumper::VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001327 dumpName(D);
1328 dumpDeclRef(D->getSuperClass(), "super");
Richard Smithdcc2c452014-03-17 23:00:06 +00001329
1330 ChildDumper Children(*this);
1331 Children.dumpRef(D->getImplementation());
1332 for (auto *D : D->protocols())
1333 Children.dumpRef(D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001334}
1335
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001336void ASTDumper::VisitObjCImplementationDecl(const ObjCImplementationDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001337 dumpName(D);
1338 dumpDeclRef(D->getSuperClass(), "super");
Richard Trieude5cc7d2013-01-31 01:44:26 +00001339 if (D->init_begin() == D->init_end())
1340 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001341 dumpDeclRef(D->getClassInterface());
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001342 for (ObjCImplementationDecl::init_const_iterator I = D->init_begin(),
1343 E = D->init_end();
1344 I != E; ++I) {
Richard Trieude5cc7d2013-01-31 01:44:26 +00001345 if (I + 1 == E)
1346 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001347 dumpCXXCtorInitializer(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001348 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001349}
1350
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001351void ASTDumper::VisitObjCCompatibleAliasDecl(const ObjCCompatibleAliasDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001352 dumpName(D);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001353 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001354 dumpDeclRef(D->getClassInterface());
1355}
1356
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001357void ASTDumper::VisitObjCPropertyDecl(const ObjCPropertyDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001358 dumpName(D);
1359 dumpType(D->getType());
1360
1361 if (D->getPropertyImplementation() == ObjCPropertyDecl::Required)
1362 OS << " required";
1363 else if (D->getPropertyImplementation() == ObjCPropertyDecl::Optional)
1364 OS << " optional";
1365
1366 ObjCPropertyDecl::PropertyAttributeKind Attrs = D->getPropertyAttributes();
1367 if (Attrs != ObjCPropertyDecl::OBJC_PR_noattr) {
1368 if (Attrs & ObjCPropertyDecl::OBJC_PR_readonly)
1369 OS << " readonly";
1370 if (Attrs & ObjCPropertyDecl::OBJC_PR_assign)
1371 OS << " assign";
1372 if (Attrs & ObjCPropertyDecl::OBJC_PR_readwrite)
1373 OS << " readwrite";
1374 if (Attrs & ObjCPropertyDecl::OBJC_PR_retain)
1375 OS << " retain";
1376 if (Attrs & ObjCPropertyDecl::OBJC_PR_copy)
1377 OS << " copy";
1378 if (Attrs & ObjCPropertyDecl::OBJC_PR_nonatomic)
1379 OS << " nonatomic";
1380 if (Attrs & ObjCPropertyDecl::OBJC_PR_atomic)
1381 OS << " atomic";
1382 if (Attrs & ObjCPropertyDecl::OBJC_PR_weak)
1383 OS << " weak";
1384 if (Attrs & ObjCPropertyDecl::OBJC_PR_strong)
1385 OS << " strong";
1386 if (Attrs & ObjCPropertyDecl::OBJC_PR_unsafe_unretained)
1387 OS << " unsafe_unretained";
Richard Trieude5cc7d2013-01-31 01:44:26 +00001388 if (Attrs & ObjCPropertyDecl::OBJC_PR_getter) {
1389 if (!(Attrs & ObjCPropertyDecl::OBJC_PR_setter))
1390 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001391 dumpDeclRef(D->getGetterMethodDecl(), "getter");
Richard Trieude5cc7d2013-01-31 01:44:26 +00001392 }
1393 if (Attrs & ObjCPropertyDecl::OBJC_PR_setter) {
1394 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001395 dumpDeclRef(D->getSetterMethodDecl(), "setter");
Richard Trieude5cc7d2013-01-31 01:44:26 +00001396 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001397 }
1398}
1399
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001400void ASTDumper::VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001401 dumpName(D->getPropertyDecl());
1402 if (D->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize)
1403 OS << " synthesize";
1404 else
1405 OS << " dynamic";
1406 dumpDeclRef(D->getPropertyDecl());
Richard Trieude5cc7d2013-01-31 01:44:26 +00001407 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001408 dumpDeclRef(D->getPropertyIvarDecl());
1409}
1410
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001411void ASTDumper::VisitBlockDecl(const BlockDecl *D) {
Aaron Ballmanb2b8b1d2014-03-07 16:09:59 +00001412 for (auto I : D->params())
1413 dumpDecl(I);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001414
1415 if (D->isVariadic()) {
1416 IndentScope Indent(*this);
1417 OS << "...";
1418 }
1419
1420 if (D->capturesCXXThis()) {
1421 IndentScope Indent(*this);
1422 OS << "capture this";
1423 }
Aaron Ballman9371dd22014-03-14 18:34:04 +00001424 for (const auto &I : D->captures()) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001425 IndentScope Indent(*this);
1426 OS << "capture";
Aaron Ballman9371dd22014-03-14 18:34:04 +00001427 if (I.isByRef())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001428 OS << " byref";
Aaron Ballman9371dd22014-03-14 18:34:04 +00001429 if (I.isNested())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001430 OS << " nested";
Aaron Ballman9371dd22014-03-14 18:34:04 +00001431 if (I.getVariable()) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001432 OS << ' ';
Aaron Ballman9371dd22014-03-14 18:34:04 +00001433 dumpBareDeclRef(I.getVariable());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001434 }
Aaron Ballman9371dd22014-03-14 18:34:04 +00001435 if (I.hasCopyExpr())
1436 dumpStmt(I.getCopyExpr());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001437 }
Richard Trieude5cc7d2013-01-31 01:44:26 +00001438 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001439 dumpStmt(D->getBody());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001440}
1441
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001442//===----------------------------------------------------------------------===//
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001443// Stmt dumping methods.
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001444//===----------------------------------------------------------------------===//
1445
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001446void ASTDumper::dumpStmt(const Stmt *S) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001447 IndentScope Indent(*this);
1448
1449 if (!S) {
Richard Trieud215b8d2013-01-26 01:31:20 +00001450 ColorScope Color(*this, NullColor);
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001451 OS << "<<<NULL>>>";
1452 return;
1453 }
1454
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001455 if (const DeclStmt *DS = dyn_cast<DeclStmt>(S)) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001456 VisitDeclStmt(DS);
1457 return;
1458 }
1459
David Blaikie7d170102013-05-15 07:37:26 +00001460 setMoreChildren(!S->children().empty());
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001461 ConstStmtVisitor<ASTDumper>::Visit(S);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001462 setMoreChildren(false);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001463 for (Stmt::const_child_range CI = S->children(); CI; ++CI) {
1464 Stmt::const_child_range Next = CI;
Richard Trieude5cc7d2013-01-31 01:44:26 +00001465 ++Next;
1466 if (!Next)
1467 lastChild();
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001468 dumpStmt(*CI);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001469 }
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001470}
1471
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001472void ASTDumper::VisitStmt(const Stmt *Node) {
Richard Trieud215b8d2013-01-26 01:31:20 +00001473 {
1474 ColorScope Color(*this, StmtColor);
1475 OS << Node->getStmtClassName();
1476 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001477 dumpPointer(Node);
1478 dumpSourceRange(Node->getSourceRange());
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001479}
1480
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001481void ASTDumper::VisitDeclStmt(const DeclStmt *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001482 VisitStmt(Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001483 for (DeclStmt::const_decl_iterator I = Node->decl_begin(),
1484 E = Node->decl_end();
Richard Trieude5cc7d2013-01-31 01:44:26 +00001485 I != E; ++I) {
1486 if (I + 1 == E)
1487 lastChild();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001488 dumpDecl(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001489 }
Ted Kremenek433a4922007-12-12 06:59:42 +00001490}
1491
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001492void ASTDumper::VisitAttributedStmt(const AttributedStmt *Node) {
Alexander Kornienko5bc364e2013-01-07 17:53:08 +00001493 VisitStmt(Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001494 for (ArrayRef<const Attr *>::iterator I = Node->getAttrs().begin(),
1495 E = Node->getAttrs().end();
1496 I != E; ++I) {
Richard Trieude5cc7d2013-01-31 01:44:26 +00001497 if (I + 1 == E)
1498 lastChild();
Alexander Kornienko5bc364e2013-01-07 17:53:08 +00001499 dumpAttr(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001500 }
Alexander Kornienko5bc364e2013-01-07 17:53:08 +00001501}
1502
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001503void ASTDumper::VisitLabelStmt(const LabelStmt *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001504 VisitStmt(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001505 OS << " '" << Node->getName() << "'";
Chris Lattnercbe4f772007-08-08 22:51:59 +00001506}
1507
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001508void ASTDumper::VisitGotoStmt(const GotoStmt *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001509 VisitStmt(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001510 OS << " '" << Node->getLabel()->getName() << "'";
1511 dumpPointer(Node->getLabel());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001512}
1513
Pavel Labath1ef83422013-09-04 14:35:00 +00001514void ASTDumper::VisitCXXCatchStmt(const CXXCatchStmt *Node) {
1515 VisitStmt(Node);
1516 dumpDecl(Node->getExceptionDecl());
1517}
1518
Chris Lattnercbe4f772007-08-08 22:51:59 +00001519//===----------------------------------------------------------------------===//
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001520// Expr dumping methods.
Chris Lattnercbe4f772007-08-08 22:51:59 +00001521//===----------------------------------------------------------------------===//
1522
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001523void ASTDumper::VisitExpr(const Expr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001524 VisitStmt(Node);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001525 dumpType(Node->getType());
1526
Richard Trieud215b8d2013-01-26 01:31:20 +00001527 {
1528 ColorScope Color(*this, ValueKindColor);
1529 switch (Node->getValueKind()) {
1530 case VK_RValue:
1531 break;
1532 case VK_LValue:
1533 OS << " lvalue";
1534 break;
1535 case VK_XValue:
1536 OS << " xvalue";
1537 break;
1538 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001539 }
1540
Richard Trieud215b8d2013-01-26 01:31:20 +00001541 {
1542 ColorScope Color(*this, ObjectKindColor);
1543 switch (Node->getObjectKind()) {
1544 case OK_Ordinary:
1545 break;
1546 case OK_BitField:
1547 OS << " bitfield";
1548 break;
1549 case OK_ObjCProperty:
1550 OS << " objcproperty";
1551 break;
1552 case OK_ObjCSubscript:
1553 OS << " objcsubscript";
1554 break;
1555 case OK_VectorComponent:
1556 OS << " vectorcomponent";
1557 break;
1558 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001559 }
Chris Lattnercbe4f772007-08-08 22:51:59 +00001560}
1561
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001562static void dumpBasePath(raw_ostream &OS, const CastExpr *Node) {
John McCallcf142162010-08-07 06:22:56 +00001563 if (Node->path_empty())
Anders Carlssona70cff62010-04-24 19:06:50 +00001564 return;
1565
1566 OS << " (";
1567 bool First = true;
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001568 for (CastExpr::path_const_iterator I = Node->path_begin(),
1569 E = Node->path_end();
1570 I != E; ++I) {
Anders Carlssona70cff62010-04-24 19:06:50 +00001571 const CXXBaseSpecifier *Base = *I;
1572 if (!First)
1573 OS << " -> ";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001574
Anders Carlssona70cff62010-04-24 19:06:50 +00001575 const CXXRecordDecl *RD =
1576 cast<CXXRecordDecl>(Base->getType()->getAs<RecordType>()->getDecl());
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001577
Anders Carlssona70cff62010-04-24 19:06:50 +00001578 if (Base->isVirtual())
1579 OS << "virtual ";
1580 OS << RD->getName();
1581 First = false;
1582 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001583
Anders Carlssona70cff62010-04-24 19:06:50 +00001584 OS << ')';
1585}
1586
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001587void ASTDumper::VisitCastExpr(const CastExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001588 VisitExpr(Node);
Richard Trieud215b8d2013-01-26 01:31:20 +00001589 OS << " <";
1590 {
1591 ColorScope Color(*this, CastColor);
1592 OS << Node->getCastKindName();
1593 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001594 dumpBasePath(OS, Node);
Anders Carlssona70cff62010-04-24 19:06:50 +00001595 OS << ">";
Anders Carlssond7923c62009-08-22 23:33:40 +00001596}
1597
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001598void ASTDumper::VisitDeclRefExpr(const DeclRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001599 VisitExpr(Node);
Ted Kremenek5f64ca82007-09-10 17:32:55 +00001600
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001601 OS << " ";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001602 dumpBareDeclRef(Node->getDecl());
Chandler Carruth8d26bb02011-05-01 23:48:14 +00001603 if (Node->getDecl() != Node->getFoundDecl()) {
1604 OS << " (";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001605 dumpBareDeclRef(Node->getFoundDecl());
Chandler Carruth8d26bb02011-05-01 23:48:14 +00001606 OS << ")";
1607 }
John McCall351762c2011-02-07 10:33:21 +00001608}
1609
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001610void ASTDumper::VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001611 VisitExpr(Node);
John McCall76d09942009-12-11 21:50:11 +00001612 OS << " (";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001613 if (!Node->requiresADL())
1614 OS << "no ";
Benjamin Kramerb11416d2010-04-17 09:33:03 +00001615 OS << "ADL) = '" << Node->getName() << '\'';
John McCall76d09942009-12-11 21:50:11 +00001616
1617 UnresolvedLookupExpr::decls_iterator
1618 I = Node->decls_begin(), E = Node->decls_end();
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001619 if (I == E)
1620 OS << " empty";
John McCall76d09942009-12-11 21:50:11 +00001621 for (; I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001622 dumpPointer(*I);
John McCall76d09942009-12-11 21:50:11 +00001623}
1624
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001625void ASTDumper::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001626 VisitExpr(Node);
Steve Naroff5d5efca2008-03-12 13:19:12 +00001627
Richard Trieud215b8d2013-01-26 01:31:20 +00001628 {
1629 ColorScope Color(*this, DeclKindNameColor);
1630 OS << " " << Node->getDecl()->getDeclKindName() << "Decl";
1631 }
1632 OS << "='" << *Node->getDecl() << "'";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001633 dumpPointer(Node->getDecl());
Steve Naroffb3424a92008-05-23 22:01:24 +00001634 if (Node->isFreeIvar())
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001635 OS << " isFreeIvar";
Steve Naroff5d5efca2008-03-12 13:19:12 +00001636}
1637
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001638void ASTDumper::VisitPredefinedExpr(const PredefinedExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001639 VisitExpr(Node);
Chris Lattnercbe4f772007-08-08 22:51:59 +00001640 switch (Node->getIdentType()) {
David Blaikie83d382b2011-09-23 05:06:16 +00001641 default: llvm_unreachable("unknown case");
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001642 case PredefinedExpr::Func: OS << " __func__"; break;
1643 case PredefinedExpr::Function: OS << " __FUNCTION__"; break;
David Majnemerbed356a2013-11-06 23:31:56 +00001644 case PredefinedExpr::FuncDName: OS << " __FUNCDNAME__"; break;
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001645 case PredefinedExpr::LFunction: OS << " L__FUNCTION__"; break;
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001646 case PredefinedExpr::PrettyFunction: OS << " __PRETTY_FUNCTION__";break;
Chris Lattnercbe4f772007-08-08 22:51:59 +00001647 }
1648}
1649
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001650void ASTDumper::VisitCharacterLiteral(const CharacterLiteral *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001651 VisitExpr(Node);
Richard Trieud215b8d2013-01-26 01:31:20 +00001652 ColorScope Color(*this, ValueColor);
Richard Trieu364ee422011-11-03 23:56:23 +00001653 OS << " " << Node->getValue();
Chris Lattnercbe4f772007-08-08 22:51:59 +00001654}
1655
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001656void ASTDumper::VisitIntegerLiteral(const IntegerLiteral *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001657 VisitExpr(Node);
Chris Lattnercbe4f772007-08-08 22:51:59 +00001658
1659 bool isSigned = Node->getType()->isSignedIntegerType();
Richard Trieud215b8d2013-01-26 01:31:20 +00001660 ColorScope Color(*this, ValueColor);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001661 OS << " " << Node->getValue().toString(10, isSigned);
Chris Lattnercbe4f772007-08-08 22:51:59 +00001662}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001663
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001664void ASTDumper::VisitFloatingLiteral(const FloatingLiteral *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001665 VisitExpr(Node);
Richard Trieud215b8d2013-01-26 01:31:20 +00001666 ColorScope Color(*this, ValueColor);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001667 OS << " " << Node->getValueAsApproximateDouble();
Chris Lattnercbe4f772007-08-08 22:51:59 +00001668}
Chris Lattner1c20a172007-08-26 03:42:43 +00001669
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001670void ASTDumper::VisitStringLiteral(const StringLiteral *Str) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001671 VisitExpr(Str);
Richard Trieud215b8d2013-01-26 01:31:20 +00001672 ColorScope Color(*this, ValueColor);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001673 OS << " ";
Richard Trieudc355912012-06-13 20:25:24 +00001674 Str->outputString(OS);
Chris Lattnercbe4f772007-08-08 22:51:59 +00001675}
Chris Lattner84ca3762007-08-30 01:00:35 +00001676
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001677void ASTDumper::VisitUnaryOperator(const UnaryOperator *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001678 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001679 OS << " " << (Node->isPostfix() ? "postfix" : "prefix")
1680 << " '" << UnaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
Chris Lattnercbe4f772007-08-08 22:51:59 +00001681}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001682
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001683void ASTDumper::VisitUnaryExprOrTypeTraitExpr(
1684 const UnaryExprOrTypeTraitExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001685 VisitExpr(Node);
Peter Collingbournee190dee2011-03-11 19:24:49 +00001686 switch(Node->getKind()) {
1687 case UETT_SizeOf:
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001688 OS << " sizeof";
Peter Collingbournee190dee2011-03-11 19:24:49 +00001689 break;
1690 case UETT_AlignOf:
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001691 OS << " alignof";
Peter Collingbournee190dee2011-03-11 19:24:49 +00001692 break;
1693 case UETT_VecStep:
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001694 OS << " vec_step";
Peter Collingbournee190dee2011-03-11 19:24:49 +00001695 break;
1696 }
Sebastian Redl6f282892008-11-11 17:56:53 +00001697 if (Node->isArgumentType())
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001698 dumpType(Node->getArgumentType());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001699}
Chris Lattnerdb3b3ff2007-08-09 17:35:30 +00001700
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001701void ASTDumper::VisitMemberExpr(const MemberExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001702 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001703 OS << " " << (Node->isArrow() ? "->" : ".") << *Node->getMemberDecl();
1704 dumpPointer(Node->getMemberDecl());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001705}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001706
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001707void ASTDumper::VisitExtVectorElementExpr(const ExtVectorElementExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001708 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001709 OS << " " << Node->getAccessor().getNameStart();
Chris Lattnercbe4f772007-08-08 22:51:59 +00001710}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001711
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001712void ASTDumper::VisitBinaryOperator(const BinaryOperator *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001713 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001714 OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
Chris Lattner86928112007-08-25 02:00:02 +00001715}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001716
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001717void ASTDumper::VisitCompoundAssignOperator(
1718 const CompoundAssignOperator *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001719 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001720 OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode())
1721 << "' ComputeLHSTy=";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001722 dumpBareType(Node->getComputationLHSType());
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001723 OS << " ComputeResultTy=";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001724 dumpBareType(Node->getComputationResultType());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001725}
Chris Lattnercbe4f772007-08-08 22:51:59 +00001726
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001727void ASTDumper::VisitBlockExpr(const BlockExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001728 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001729 dumpDecl(Node->getBlockDecl());
John McCall351762c2011-02-07 10:33:21 +00001730}
1731
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001732void ASTDumper::VisitOpaqueValueExpr(const OpaqueValueExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001733 VisitExpr(Node);
John McCallfe96e0b2011-11-06 09:01:30 +00001734
Richard Trieude5cc7d2013-01-31 01:44:26 +00001735 if (Expr *Source = Node->getSourceExpr()) {
1736 lastChild();
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001737 dumpStmt(Source);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001738 }
John McCallfe96e0b2011-11-06 09:01:30 +00001739}
1740
Chris Lattnercbe4f772007-08-08 22:51:59 +00001741// GNU extensions.
1742
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001743void ASTDumper::VisitAddrLabelExpr(const AddrLabelExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001744 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001745 OS << " " << Node->getLabel()->getName();
1746 dumpPointer(Node->getLabel());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001747}
1748
Chris Lattner8f184b12007-08-09 18:03:18 +00001749//===----------------------------------------------------------------------===//
1750// C++ Expressions
1751//===----------------------------------------------------------------------===//
Chris Lattnercbe4f772007-08-08 22:51:59 +00001752
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001753void ASTDumper::VisitCXXNamedCastExpr(const CXXNamedCastExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001754 VisitExpr(Node);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001755 OS << " " << Node->getCastName()
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001756 << "<" << Node->getTypeAsWritten().getAsString() << ">"
Anders Carlssona70cff62010-04-24 19:06:50 +00001757 << " <" << Node->getCastKindName();
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001758 dumpBasePath(OS, Node);
Anders Carlssona70cff62010-04-24 19:06:50 +00001759 OS << ">";
Chris Lattnercbe4f772007-08-08 22:51:59 +00001760}
1761
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001762void ASTDumper::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001763 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001764 OS << " " << (Node->getValue() ? "true" : "false");
Chris Lattnercbe4f772007-08-08 22:51:59 +00001765}
1766
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001767void ASTDumper::VisitCXXThisExpr(const CXXThisExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001768 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001769 OS << " this";
Douglas Gregor8ea1f532008-11-04 14:56:14 +00001770}
1771
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001772void ASTDumper::VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001773 VisitExpr(Node);
Eli Friedman29538892011-09-02 17:38:59 +00001774 OS << " functional cast to " << Node->getTypeAsWritten().getAsString()
1775 << " <" << Node->getCastKindName() << ">";
Douglas Gregore200adc2008-10-27 19:41:14 +00001776}
1777
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001778void ASTDumper::VisitCXXConstructExpr(const CXXConstructExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001779 VisitExpr(Node);
John McCalleba90cd2010-02-02 19:03:45 +00001780 CXXConstructorDecl *Ctor = Node->getConstructor();
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001781 dumpType(Ctor->getType());
Anders Carlsson073846832009-08-12 00:21:52 +00001782 if (Node->isElidable())
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001783 OS << " elidable";
John McCall85370042010-08-07 06:38:55 +00001784 if (Node->requiresZeroInitialization())
1785 OS << " zeroing";
Anders Carlsson073846832009-08-12 00:21:52 +00001786}
1787
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001788void ASTDumper::VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001789 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001790 OS << " ";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001791 dumpCXXTemporary(Node->getTemporary());
Anders Carlsson073846832009-08-12 00:21:52 +00001792}
1793
Richard Smithe6c01442013-06-05 00:46:14 +00001794void
1795ASTDumper::VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *Node) {
1796 VisitExpr(Node);
1797 if (const ValueDecl *VD = Node->getExtendingDecl()) {
1798 OS << " extended by ";
1799 dumpBareDeclRef(VD);
1800 }
1801}
1802
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001803void ASTDumper::VisitExprWithCleanups(const ExprWithCleanups *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001804 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001805 for (unsigned i = 0, e = Node->getNumObjects(); i != e; ++i)
1806 dumpDeclRef(Node->getObject(i), "cleanup");
Anders Carlsson073846832009-08-12 00:21:52 +00001807}
1808
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001809void ASTDumper::dumpCXXTemporary(const CXXTemporary *Temporary) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001810 OS << "(CXXTemporary";
1811 dumpPointer(Temporary);
1812 OS << ")";
Anders Carlsson073846832009-08-12 00:21:52 +00001813}
1814
Anders Carlsson76f4a902007-08-21 17:43:55 +00001815//===----------------------------------------------------------------------===//
1816// Obj-C Expressions
1817//===----------------------------------------------------------------------===//
1818
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001819void ASTDumper::VisitObjCMessageExpr(const ObjCMessageExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001820 VisitExpr(Node);
Aaron Ballmanb190f972014-01-03 17:59:55 +00001821 OS << " selector=";
1822 Node->getSelector().print(OS);
Douglas Gregor9a129192010-04-21 00:45:42 +00001823 switch (Node->getReceiverKind()) {
1824 case ObjCMessageExpr::Instance:
1825 break;
1826
1827 case ObjCMessageExpr::Class:
1828 OS << " class=";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001829 dumpBareType(Node->getClassReceiver());
Douglas Gregor9a129192010-04-21 00:45:42 +00001830 break;
1831
1832 case ObjCMessageExpr::SuperInstance:
1833 OS << " super (instance)";
1834 break;
1835
1836 case ObjCMessageExpr::SuperClass:
1837 OS << " super (class)";
1838 break;
1839 }
Ted Kremenek36748da2008-02-29 22:04:05 +00001840}
1841
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001842void ASTDumper::VisitObjCBoxedExpr(const ObjCBoxedExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001843 VisitExpr(Node);
Aaron Ballmanb190f972014-01-03 17:59:55 +00001844 OS << " selector=";
1845 Node->getBoxingMethod()->getSelector().print(OS);
Argyrios Kyrtzidis9dd40892012-05-10 20:02:31 +00001846}
1847
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001848void ASTDumper::VisitObjCAtCatchStmt(const ObjCAtCatchStmt *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001849 VisitStmt(Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001850 if (const VarDecl *CatchParam = Node->getCatchParamDecl())
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001851 dumpDecl(CatchParam);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001852 else
Douglas Gregor96c79492010-04-23 22:50:49 +00001853 OS << " catch all";
Douglas Gregor96c79492010-04-23 22:50:49 +00001854}
1855
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001856void ASTDumper::VisitObjCEncodeExpr(const ObjCEncodeExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001857 VisitExpr(Node);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001858 dumpType(Node->getEncodedType());
Anders Carlssonc5a81eb2007-08-22 15:14:15 +00001859}
1860
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001861void ASTDumper::VisitObjCSelectorExpr(const ObjCSelectorExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001862 VisitExpr(Node);
Mike Stump11289f42009-09-09 15:08:12 +00001863
Aaron Ballmanb190f972014-01-03 17:59:55 +00001864 OS << " ";
1865 Node->getSelector().print(OS);
Fariborz Jahanian4bef4622007-10-16 20:40:23 +00001866}
1867
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001868void ASTDumper::VisitObjCProtocolExpr(const ObjCProtocolExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001869 VisitExpr(Node);
Mike Stump11289f42009-09-09 15:08:12 +00001870
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001871 OS << ' ' << *Node->getProtocol();
Fariborz Jahaniana32aaef2007-10-17 16:58:11 +00001872}
Daniel Dunbar4b8c6db2008-08-30 05:35:15 +00001873
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001874void ASTDumper::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001875 VisitExpr(Node);
John McCallb7bd14f2010-12-02 01:19:52 +00001876 if (Node->isImplicitProperty()) {
Fariborz Jahanian0f0b3022010-12-22 19:46:35 +00001877 OS << " Kind=MethodRef Getter=\"";
1878 if (Node->getImplicitPropertyGetter())
Aaron Ballmanb190f972014-01-03 17:59:55 +00001879 Node->getImplicitPropertyGetter()->getSelector().print(OS);
Fariborz Jahanian0f0b3022010-12-22 19:46:35 +00001880 else
1881 OS << "(null)";
1882
1883 OS << "\" Setter=\"";
John McCallb7bd14f2010-12-02 01:19:52 +00001884 if (ObjCMethodDecl *Setter = Node->getImplicitPropertySetter())
Aaron Ballmanb190f972014-01-03 17:59:55 +00001885 Setter->getSelector().print(OS);
John McCallb7bd14f2010-12-02 01:19:52 +00001886 else
1887 OS << "(null)";
1888 OS << "\"";
1889 } else {
Benjamin Kramerb89514a2011-10-14 18:45:37 +00001890 OS << " Kind=PropertyRef Property=\"" << *Node->getExplicitProperty() <<'"';
John McCallb7bd14f2010-12-02 01:19:52 +00001891 }
Fariborz Jahanian8a1810f2008-11-22 18:39:36 +00001892
Fariborz Jahanian681c0752010-10-14 16:04:05 +00001893 if (Node->isSuperReceiver())
1894 OS << " super";
Argyrios Kyrtzidisab468b02012-03-30 00:19:18 +00001895
1896 OS << " Messaging=";
1897 if (Node->isMessagingGetter() && Node->isMessagingSetter())
1898 OS << "Getter&Setter";
1899 else if (Node->isMessagingGetter())
1900 OS << "Getter";
1901 else if (Node->isMessagingSetter())
1902 OS << "Setter";
Douglas Gregor8ea1f532008-11-04 14:56:14 +00001903}
1904
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001905void ASTDumper::VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001906 VisitExpr(Node);
Ted Kremeneke65b0862012-03-06 20:05:56 +00001907 if (Node->isArraySubscriptRefExpr())
1908 OS << " Kind=ArraySubscript GetterForArray=\"";
1909 else
1910 OS << " Kind=DictionarySubscript GetterForDictionary=\"";
1911 if (Node->getAtIndexMethodDecl())
Aaron Ballmanb190f972014-01-03 17:59:55 +00001912 Node->getAtIndexMethodDecl()->getSelector().print(OS);
Ted Kremeneke65b0862012-03-06 20:05:56 +00001913 else
1914 OS << "(null)";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001915
Ted Kremeneke65b0862012-03-06 20:05:56 +00001916 if (Node->isArraySubscriptRefExpr())
1917 OS << "\" SetterForArray=\"";
1918 else
1919 OS << "\" SetterForDictionary=\"";
1920 if (Node->setAtIndexMethodDecl())
Aaron Ballmanb190f972014-01-03 17:59:55 +00001921 Node->setAtIndexMethodDecl()->getSelector().print(OS);
Ted Kremeneke65b0862012-03-06 20:05:56 +00001922 else
1923 OS << "(null)";
1924}
1925
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001926void ASTDumper::VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001927 VisitExpr(Node);
Ted Kremeneke65b0862012-03-06 20:05:56 +00001928 OS << " " << (Node->getValue() ? "__objc_yes" : "__objc_no");
1929}
1930
Chris Lattnercbe4f772007-08-08 22:51:59 +00001931//===----------------------------------------------------------------------===//
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00001932// Comments
1933//===----------------------------------------------------------------------===//
1934
1935const char *ASTDumper::getCommandName(unsigned CommandID) {
1936 if (Traits)
1937 return Traits->getCommandInfo(CommandID)->Name;
1938 const CommandInfo *Info = CommandTraits::getBuiltinCommandInfo(CommandID);
1939 if (Info)
1940 return Info->Name;
1941 return "<not a builtin command>";
1942}
1943
1944void ASTDumper::dumpFullComment(const FullComment *C) {
1945 if (!C)
1946 return;
1947
1948 FC = C;
1949 dumpComment(C);
1950 FC = 0;
1951}
1952
1953void ASTDumper::dumpComment(const Comment *C) {
1954 IndentScope Indent(*this);
1955
1956 if (!C) {
Richard Trieud215b8d2013-01-26 01:31:20 +00001957 ColorScope Color(*this, NullColor);
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00001958 OS << "<<<NULL>>>";
1959 return;
1960 }
1961
Richard Trieud215b8d2013-01-26 01:31:20 +00001962 {
1963 ColorScope Color(*this, CommentColor);
1964 OS << C->getCommentKindName();
1965 }
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00001966 dumpPointer(C);
1967 dumpSourceRange(C->getSourceRange());
1968 ConstCommentVisitor<ASTDumper>::visit(C);
1969 for (Comment::child_iterator I = C->child_begin(), E = C->child_end();
Richard Trieude5cc7d2013-01-31 01:44:26 +00001970 I != E; ++I) {
1971 if (I + 1 == E)
1972 lastChild();
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00001973 dumpComment(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001974 }
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00001975}
1976
1977void ASTDumper::visitTextComment(const TextComment *C) {
1978 OS << " Text=\"" << C->getText() << "\"";
1979}
1980
1981void ASTDumper::visitInlineCommandComment(const InlineCommandComment *C) {
1982 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\"";
1983 switch (C->getRenderKind()) {
1984 case InlineCommandComment::RenderNormal:
1985 OS << " RenderNormal";
1986 break;
1987 case InlineCommandComment::RenderBold:
1988 OS << " RenderBold";
1989 break;
1990 case InlineCommandComment::RenderMonospaced:
1991 OS << " RenderMonospaced";
1992 break;
1993 case InlineCommandComment::RenderEmphasized:
1994 OS << " RenderEmphasized";
1995 break;
1996 }
1997
1998 for (unsigned i = 0, e = C->getNumArgs(); i != e; ++i)
1999 OS << " Arg[" << i << "]=\"" << C->getArgText(i) << "\"";
2000}
2001
2002void ASTDumper::visitHTMLStartTagComment(const HTMLStartTagComment *C) {
2003 OS << " Name=\"" << C->getTagName() << "\"";
2004 if (C->getNumAttrs() != 0) {
2005 OS << " Attrs: ";
2006 for (unsigned i = 0, e = C->getNumAttrs(); i != e; ++i) {
2007 const HTMLStartTagComment::Attribute &Attr = C->getAttr(i);
2008 OS << " \"" << Attr.Name << "=\"" << Attr.Value << "\"";
2009 }
2010 }
2011 if (C->isSelfClosing())
2012 OS << " SelfClosing";
2013}
2014
2015void ASTDumper::visitHTMLEndTagComment(const HTMLEndTagComment *C) {
2016 OS << " Name=\"" << C->getTagName() << "\"";
2017}
2018
2019void ASTDumper::visitBlockCommandComment(const BlockCommandComment *C) {
2020 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\"";
2021 for (unsigned i = 0, e = C->getNumArgs(); i != e; ++i)
2022 OS << " Arg[" << i << "]=\"" << C->getArgText(i) << "\"";
2023}
2024
2025void ASTDumper::visitParamCommandComment(const ParamCommandComment *C) {
2026 OS << " " << ParamCommandComment::getDirectionAsString(C->getDirection());
2027
2028 if (C->isDirectionExplicit())
2029 OS << " explicitly";
2030 else
2031 OS << " implicitly";
2032
2033 if (C->hasParamName()) {
2034 if (C->isParamIndexValid())
2035 OS << " Param=\"" << C->getParamName(FC) << "\"";
2036 else
2037 OS << " Param=\"" << C->getParamNameAsWritten() << "\"";
2038 }
2039
2040 if (C->isParamIndexValid())
2041 OS << " ParamIndex=" << C->getParamIndex();
2042}
2043
2044void ASTDumper::visitTParamCommandComment(const TParamCommandComment *C) {
2045 if (C->hasParamName()) {
2046 if (C->isPositionValid())
2047 OS << " Param=\"" << C->getParamName(FC) << "\"";
2048 else
2049 OS << " Param=\"" << C->getParamNameAsWritten() << "\"";
2050 }
2051
2052 if (C->isPositionValid()) {
2053 OS << " Position=<";
2054 for (unsigned i = 0, e = C->getDepth(); i != e; ++i) {
2055 OS << C->getIndex(i);
2056 if (i != e - 1)
2057 OS << ", ";
2058 }
2059 OS << ">";
2060 }
2061}
2062
2063void ASTDumper::visitVerbatimBlockComment(const VerbatimBlockComment *C) {
2064 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\""
2065 " CloseName=\"" << C->getCloseName() << "\"";
2066}
2067
2068void ASTDumper::visitVerbatimBlockLineComment(
2069 const VerbatimBlockLineComment *C) {
2070 OS << " Text=\"" << C->getText() << "\"";
2071}
2072
2073void ASTDumper::visitVerbatimLineComment(const VerbatimLineComment *C) {
2074 OS << " Text=\"" << C->getText() << "\"";
2075}
2076
2077//===----------------------------------------------------------------------===//
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002078// Decl method implementations
2079//===----------------------------------------------------------------------===//
2080
Alp Tokeref6b0072014-01-04 13:47:14 +00002081LLVM_DUMP_METHOD void Decl::dump() const { dump(llvm::errs()); }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002082
Alp Tokeref6b0072014-01-04 13:47:14 +00002083LLVM_DUMP_METHOD void Decl::dump(raw_ostream &OS) const {
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002084 ASTDumper P(OS, &getASTContext().getCommentCommandTraits(),
2085 &getASTContext().getSourceManager());
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002086 P.dumpDecl(this);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002087}
2088
Alp Tokeref6b0072014-01-04 13:47:14 +00002089LLVM_DUMP_METHOD void Decl::dumpColor() const {
Richard Trieud215b8d2013-01-26 01:31:20 +00002090 ASTDumper P(llvm::errs(), &getASTContext().getCommentCommandTraits(),
2091 &getASTContext().getSourceManager(), /*ShowColors*/true);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002092 P.dumpDecl(this);
Richard Trieud215b8d2013-01-26 01:31:20 +00002093}
Richard Smith33937e72013-06-22 21:49:40 +00002094
Alp Tokeref6b0072014-01-04 13:47:14 +00002095LLVM_DUMP_METHOD void DeclContext::dumpLookups() const {
Richard Smith6ea05822013-06-24 01:45:33 +00002096 dumpLookups(llvm::errs());
2097}
2098
Alp Tokeref6b0072014-01-04 13:47:14 +00002099LLVM_DUMP_METHOD void DeclContext::dumpLookups(raw_ostream &OS) const {
Richard Smith33937e72013-06-22 21:49:40 +00002100 const DeclContext *DC = this;
2101 while (!DC->isTranslationUnit())
2102 DC = DC->getParent();
2103 ASTContext &Ctx = cast<TranslationUnitDecl>(DC)->getASTContext();
Richard Smith6ea05822013-06-24 01:45:33 +00002104 ASTDumper P(OS, &Ctx.getCommentCommandTraits(), &Ctx.getSourceManager());
Richard Smith33937e72013-06-22 21:49:40 +00002105 P.dumpLookups(this);
2106}
2107
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002108//===----------------------------------------------------------------------===//
Chris Lattnercbe4f772007-08-08 22:51:59 +00002109// Stmt method implementations
2110//===----------------------------------------------------------------------===//
2111
Alp Tokeref6b0072014-01-04 13:47:14 +00002112LLVM_DUMP_METHOD void Stmt::dump(SourceManager &SM) const {
Argyrios Kyrtzidisc049f752010-08-09 10:54:31 +00002113 dump(llvm::errs(), SM);
2114}
2115
Alp Tokeref6b0072014-01-04 13:47:14 +00002116LLVM_DUMP_METHOD void Stmt::dump(raw_ostream &OS, SourceManager &SM) const {
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002117 ASTDumper P(OS, 0, &SM);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002118 P.dumpStmt(this);
Chris Lattner779d5d92007-08-30 00:40:08 +00002119}
2120
Alp Tokeref6b0072014-01-04 13:47:14 +00002121LLVM_DUMP_METHOD void Stmt::dump() const {
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002122 ASTDumper P(llvm::errs(), 0, 0);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002123 P.dumpStmt(this);
Chris Lattnercbe4f772007-08-08 22:51:59 +00002124}
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002125
Alp Tokeref6b0072014-01-04 13:47:14 +00002126LLVM_DUMP_METHOD void Stmt::dumpColor() const {
Richard Trieud215b8d2013-01-26 01:31:20 +00002127 ASTDumper P(llvm::errs(), 0, 0, /*ShowColors*/true);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002128 P.dumpStmt(this);
Richard Trieud215b8d2013-01-26 01:31:20 +00002129}
2130
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002131//===----------------------------------------------------------------------===//
2132// Comment method implementations
2133//===----------------------------------------------------------------------===//
2134
Alp Tokeref6b0072014-01-04 13:47:14 +00002135LLVM_DUMP_METHOD void Comment::dump() const { dump(llvm::errs(), 0, 0); }
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002136
Alp Tokeref6b0072014-01-04 13:47:14 +00002137LLVM_DUMP_METHOD void Comment::dump(const ASTContext &Context) const {
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002138 dump(llvm::errs(), &Context.getCommentCommandTraits(),
2139 &Context.getSourceManager());
2140}
2141
Alexander Kornienko00911f12013-01-15 12:20:21 +00002142void Comment::dump(raw_ostream &OS, const CommandTraits *Traits,
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002143 const SourceManager *SM) const {
2144 const FullComment *FC = dyn_cast<FullComment>(this);
2145 ASTDumper D(OS, Traits, SM);
2146 D.dumpFullComment(FC);
2147}
Richard Trieud215b8d2013-01-26 01:31:20 +00002148
Alp Tokeref6b0072014-01-04 13:47:14 +00002149LLVM_DUMP_METHOD void Comment::dumpColor() const {
Richard Trieud215b8d2013-01-26 01:31:20 +00002150 const FullComment *FC = dyn_cast<FullComment>(this);
2151 ASTDumper D(llvm::errs(), 0, 0, /*ShowColors*/true);
2152 D.dumpFullComment(FC);
2153}