blob: d121d0d52776468c9b3cca01d77225d63d38a84c [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;
Mike Stump11289f42009-09-09 15:08:12 +000097
Richard Smithf7514452014-10-30 21:02:37 +000098 /// Pending[i] is an action to dump an entity at level i.
99 llvm::SmallVector<std::function<void(bool isLastChild)>, 32> Pending;
Richard Trieude5cc7d2013-01-31 01:44:26 +0000100
Richard Smithf7514452014-10-30 21:02:37 +0000101 /// Indicates whether we're at the top level.
102 bool TopLevel;
Richard Trieude5cc7d2013-01-31 01:44:26 +0000103
Richard Smithf7514452014-10-30 21:02:37 +0000104 /// Indicates if we're handling the first child after entering a new depth.
105 bool FirstChild;
106
107 /// Prefix for currently-being-dumped entity.
108 std::string Prefix;
Richard Trieude5cc7d2013-01-31 01:44:26 +0000109
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000110 /// Keep track of the last location we print out so that we can
111 /// print out deltas from then on out.
Chris Lattner11e30d32007-08-30 06:17:34 +0000112 const char *LastLocFilename;
113 unsigned LastLocLine;
Douglas Gregor7de59662009-05-29 20:38:28 +0000114
Alexander Kornienkoebc17b52013-01-14 14:07:11 +0000115 /// The \c FullComment parent of the comment being dumped.
116 const FullComment *FC;
117
Richard Trieud215b8d2013-01-26 01:31:20 +0000118 bool ShowColors;
119
Richard Smithf7514452014-10-30 21:02:37 +0000120 /// Dump a child of the current node.
121 template<typename Fn> void dumpChild(Fn doDumpChild) {
122 // If we're at the top level, there's nothing interesting to do; just
123 // run the dumper.
124 if (TopLevel) {
125 TopLevel = false;
126 doDumpChild();
127 while (!Pending.empty()) {
128 Pending.back()(true);
129 Pending.pop_back();
130 }
131 Prefix.clear();
132 OS << "\n";
133 TopLevel = true;
134 return;
Manuel Klimek874030e2012-11-07 00:33:12 +0000135 }
Richard Smithf7514452014-10-30 21:02:37 +0000136
137 const FullComment *OrigFC = FC;
138 auto dumpWithIndent = [this, doDumpChild, OrigFC](bool isLastChild) {
139 // Print out the appropriate tree structure and work out the prefix for
140 // children of this node. For instance:
141 //
142 // A Prefix = ""
143 // |-B Prefix = "| "
144 // | `-C Prefix = "| "
145 // `-D Prefix = " "
146 // |-E Prefix = " | "
147 // `-F Prefix = " "
148 // G Prefix = ""
149 //
150 // Note that the first level gets no prefix.
151 {
152 OS << '\n';
153 ColorScope Color(*this, IndentColor);
154 OS << Prefix << (isLastChild ? '`' : '|') << '-';
NAKAMURA Takumic73e4022014-10-31 00:30:37 +0000155 this->Prefix.push_back(isLastChild ? ' ' : '|');
156 this->Prefix.push_back(' ');
Richard Smithf7514452014-10-30 21:02:37 +0000157 }
158
159 FirstChild = true;
160 unsigned Depth = Pending.size();
161
162 FC = OrigFC;
163 doDumpChild();
164
165 // If any children are left, they're the last at their nesting level.
166 // Dump those ones out now.
167 while (Depth < Pending.size()) {
168 Pending.back()(true);
NAKAMURA Takumic73e4022014-10-31 00:30:37 +0000169 this->Pending.pop_back();
Richard Smithf7514452014-10-30 21:02:37 +0000170 }
171
172 // Restore the old prefix.
NAKAMURA Takumic73e4022014-10-31 00:30:37 +0000173 this->Prefix.resize(Prefix.size() - 2);
Richard Smithf7514452014-10-30 21:02:37 +0000174 };
175
176 if (FirstChild) {
177 Pending.push_back(std::move(dumpWithIndent));
178 } else {
179 Pending.back()(false);
180 Pending.back() = std::move(dumpWithIndent);
Manuel Klimek874030e2012-11-07 00:33:12 +0000181 }
Richard Smithf7514452014-10-30 21:02:37 +0000182 FirstChild = false;
183 }
Manuel Klimek874030e2012-11-07 00:33:12 +0000184
Richard Trieud215b8d2013-01-26 01:31:20 +0000185 class ColorScope {
186 ASTDumper &Dumper;
187 public:
188 ColorScope(ASTDumper &Dumper, TerminalColor Color)
189 : Dumper(Dumper) {
190 if (Dumper.ShowColors)
191 Dumper.OS.changeColor(Color.Color, Color.Bold);
192 }
193 ~ColorScope() {
194 if (Dumper.ShowColors)
195 Dumper.OS.resetColor();
196 }
197 };
198
Chris Lattnercbe4f772007-08-08 22:51:59 +0000199 public:
Alexander Kornienkoebc17b52013-01-14 14:07:11 +0000200 ASTDumper(raw_ostream &OS, const CommandTraits *Traits,
201 const SourceManager *SM)
Richard Smithf7514452014-10-30 21:02:37 +0000202 : OS(OS), Traits(Traits), SM(SM), TopLevel(true), FirstChild(true),
Craig Topper36250ad2014-05-12 05:36:57 +0000203 LastLocFilename(""), LastLocLine(~0U), FC(nullptr),
Richard Trieud215b8d2013-01-26 01:31:20 +0000204 ShowColors(SM && SM->getDiagnostics().getShowColors()) { }
205
206 ASTDumper(raw_ostream &OS, const CommandTraits *Traits,
207 const SourceManager *SM, bool ShowColors)
Richard Smithf7514452014-10-30 21:02:37 +0000208 : OS(OS), Traits(Traits), SM(SM), TopLevel(true), FirstChild(true),
Richard Smith56d12152013-01-31 02:04:38 +0000209 LastLocFilename(""), LastLocLine(~0U),
Richard Trieude5cc7d2013-01-31 01:44:26 +0000210 ShowColors(ShowColors) { }
Mike Stump11289f42009-09-09 15:08:12 +0000211
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000212 void dumpDecl(const Decl *D);
213 void dumpStmt(const Stmt *S);
Alexander Kornienkoebc17b52013-01-14 14:07:11 +0000214 void dumpFullComment(const FullComment *C);
Mike Stump11289f42009-09-09 15:08:12 +0000215
Richard Trieude5cc7d2013-01-31 01:44:26 +0000216 // Utilities
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000217 void dumpPointer(const void *Ptr);
218 void dumpSourceRange(SourceRange R);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000219 void dumpLocation(SourceLocation Loc);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000220 void dumpBareType(QualType T);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000221 void dumpType(QualType T);
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000222 void dumpBareDeclRef(const Decl *Node);
Craig Topper36250ad2014-05-12 05:36:57 +0000223 void dumpDeclRef(const Decl *Node, const char *Label = nullptr);
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000224 void dumpName(const NamedDecl *D);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000225 bool hasNodes(const DeclContext *DC);
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000226 void dumpDeclContext(const DeclContext *DC);
Richard Smith35f986d2014-08-11 22:11:07 +0000227 void dumpLookups(const DeclContext *DC, bool DumpDecls);
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000228 void dumpAttr(const Attr *A);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000229
230 // C++ Utilities
231 void dumpAccessSpecifier(AccessSpecifier AS);
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000232 void dumpCXXCtorInitializer(const CXXCtorInitializer *Init);
233 void dumpTemplateParameters(const TemplateParameterList *TPL);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000234 void dumpTemplateArgumentListInfo(const TemplateArgumentListInfo &TALI);
235 void dumpTemplateArgumentLoc(const TemplateArgumentLoc &A);
236 void dumpTemplateArgumentList(const TemplateArgumentList &TAL);
237 void dumpTemplateArgument(const TemplateArgument &A,
238 SourceRange R = SourceRange());
239
240 // Decls
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000241 void VisitLabelDecl(const LabelDecl *D);
242 void VisitTypedefDecl(const TypedefDecl *D);
243 void VisitEnumDecl(const EnumDecl *D);
244 void VisitRecordDecl(const RecordDecl *D);
245 void VisitEnumConstantDecl(const EnumConstantDecl *D);
246 void VisitIndirectFieldDecl(const IndirectFieldDecl *D);
247 void VisitFunctionDecl(const FunctionDecl *D);
248 void VisitFieldDecl(const FieldDecl *D);
249 void VisitVarDecl(const VarDecl *D);
250 void VisitFileScopeAsmDecl(const FileScopeAsmDecl *D);
251 void VisitImportDecl(const ImportDecl *D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000252
253 // C++ Decls
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000254 void VisitNamespaceDecl(const NamespaceDecl *D);
255 void VisitUsingDirectiveDecl(const UsingDirectiveDecl *D);
256 void VisitNamespaceAliasDecl(const NamespaceAliasDecl *D);
257 void VisitTypeAliasDecl(const TypeAliasDecl *D);
258 void VisitTypeAliasTemplateDecl(const TypeAliasTemplateDecl *D);
259 void VisitCXXRecordDecl(const CXXRecordDecl *D);
260 void VisitStaticAssertDecl(const StaticAssertDecl *D);
Richard Smithcbdf7332014-03-18 02:07:28 +0000261 template<typename SpecializationDecl>
Richard Smithf7514452014-10-30 21:02:37 +0000262 void VisitTemplateDeclSpecialization(const SpecializationDecl *D,
Richard Smithcbdf7332014-03-18 02:07:28 +0000263 bool DumpExplicitInst,
264 bool DumpRefOnly);
Richard Smith20ade552014-03-17 23:34:53 +0000265 template<typename TemplateDecl>
266 void VisitTemplateDecl(const TemplateDecl *D, bool DumpExplicitInst);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000267 void VisitFunctionTemplateDecl(const FunctionTemplateDecl *D);
268 void VisitClassTemplateDecl(const ClassTemplateDecl *D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000269 void VisitClassTemplateSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000270 const ClassTemplateSpecializationDecl *D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000271 void VisitClassTemplatePartialSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000272 const ClassTemplatePartialSpecializationDecl *D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000273 void VisitClassScopeFunctionSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000274 const ClassScopeFunctionSpecializationDecl *D);
Richard Smithd25789a2013-09-18 01:36:02 +0000275 void VisitVarTemplateDecl(const VarTemplateDecl *D);
276 void VisitVarTemplateSpecializationDecl(
277 const VarTemplateSpecializationDecl *D);
278 void VisitVarTemplatePartialSpecializationDecl(
279 const VarTemplatePartialSpecializationDecl *D);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000280 void VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D);
281 void VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D);
282 void VisitTemplateTemplateParmDecl(const TemplateTemplateParmDecl *D);
283 void VisitUsingDecl(const UsingDecl *D);
284 void VisitUnresolvedUsingTypenameDecl(const UnresolvedUsingTypenameDecl *D);
285 void VisitUnresolvedUsingValueDecl(const UnresolvedUsingValueDecl *D);
286 void VisitUsingShadowDecl(const UsingShadowDecl *D);
287 void VisitLinkageSpecDecl(const LinkageSpecDecl *D);
288 void VisitAccessSpecDecl(const AccessSpecDecl *D);
289 void VisitFriendDecl(const FriendDecl *D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000290
291 // ObjC Decls
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000292 void VisitObjCIvarDecl(const ObjCIvarDecl *D);
293 void VisitObjCMethodDecl(const ObjCMethodDecl *D);
294 void VisitObjCCategoryDecl(const ObjCCategoryDecl *D);
295 void VisitObjCCategoryImplDecl(const ObjCCategoryImplDecl *D);
296 void VisitObjCProtocolDecl(const ObjCProtocolDecl *D);
297 void VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D);
298 void VisitObjCImplementationDecl(const ObjCImplementationDecl *D);
299 void VisitObjCCompatibleAliasDecl(const ObjCCompatibleAliasDecl *D);
300 void VisitObjCPropertyDecl(const ObjCPropertyDecl *D);
301 void VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D);
302 void VisitBlockDecl(const BlockDecl *D);
Mike Stump11289f42009-09-09 15:08:12 +0000303
Chris Lattner84ca3762007-08-30 01:00:35 +0000304 // Stmts.
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000305 void VisitStmt(const Stmt *Node);
306 void VisitDeclStmt(const DeclStmt *Node);
307 void VisitAttributedStmt(const AttributedStmt *Node);
308 void VisitLabelStmt(const LabelStmt *Node);
309 void VisitGotoStmt(const GotoStmt *Node);
Pavel Labath1ef83422013-09-04 14:35:00 +0000310 void VisitCXXCatchStmt(const CXXCatchStmt *Node);
Mike Stump11289f42009-09-09 15:08:12 +0000311
Chris Lattner84ca3762007-08-30 01:00:35 +0000312 // Exprs
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000313 void VisitExpr(const Expr *Node);
314 void VisitCastExpr(const CastExpr *Node);
315 void VisitDeclRefExpr(const DeclRefExpr *Node);
316 void VisitPredefinedExpr(const PredefinedExpr *Node);
317 void VisitCharacterLiteral(const CharacterLiteral *Node);
318 void VisitIntegerLiteral(const IntegerLiteral *Node);
319 void VisitFloatingLiteral(const FloatingLiteral *Node);
320 void VisitStringLiteral(const StringLiteral *Str);
Richard Smithf0514962014-06-03 08:24:28 +0000321 void VisitInitListExpr(const InitListExpr *ILE);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000322 void VisitUnaryOperator(const UnaryOperator *Node);
323 void VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *Node);
324 void VisitMemberExpr(const MemberExpr *Node);
325 void VisitExtVectorElementExpr(const ExtVectorElementExpr *Node);
326 void VisitBinaryOperator(const BinaryOperator *Node);
327 void VisitCompoundAssignOperator(const CompoundAssignOperator *Node);
328 void VisitAddrLabelExpr(const AddrLabelExpr *Node);
329 void VisitBlockExpr(const BlockExpr *Node);
330 void VisitOpaqueValueExpr(const OpaqueValueExpr *Node);
Chris Lattner84ca3762007-08-30 01:00:35 +0000331
332 // C++
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000333 void VisitCXXNamedCastExpr(const CXXNamedCastExpr *Node);
334 void VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *Node);
335 void VisitCXXThisExpr(const CXXThisExpr *Node);
336 void VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *Node);
337 void VisitCXXConstructExpr(const CXXConstructExpr *Node);
338 void VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *Node);
Richard Smithe6c01442013-06-05 00:46:14 +0000339 void VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000340 void VisitExprWithCleanups(const ExprWithCleanups *Node);
341 void VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *Node);
342 void dumpCXXTemporary(const CXXTemporary *Temporary);
Faisal Vali2b391ab2013-09-26 19:54:12 +0000343 void VisitLambdaExpr(const LambdaExpr *Node) {
344 VisitExpr(Node);
345 dumpDecl(Node->getLambdaClass());
346 }
Mike Stump11289f42009-09-09 15:08:12 +0000347
Chris Lattner84ca3762007-08-30 01:00:35 +0000348 // ObjC
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000349 void VisitObjCAtCatchStmt(const ObjCAtCatchStmt *Node);
350 void VisitObjCEncodeExpr(const ObjCEncodeExpr *Node);
351 void VisitObjCMessageExpr(const ObjCMessageExpr *Node);
352 void VisitObjCBoxedExpr(const ObjCBoxedExpr *Node);
353 void VisitObjCSelectorExpr(const ObjCSelectorExpr *Node);
354 void VisitObjCProtocolExpr(const ObjCProtocolExpr *Node);
355 void VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *Node);
356 void VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *Node);
357 void VisitObjCIvarRefExpr(const ObjCIvarRefExpr *Node);
358 void VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *Node);
Alexander Kornienkoebc17b52013-01-14 14:07:11 +0000359
360 // Comments.
361 const char *getCommandName(unsigned CommandID);
362 void dumpComment(const Comment *C);
363
364 // Inline comments.
365 void visitTextComment(const TextComment *C);
366 void visitInlineCommandComment(const InlineCommandComment *C);
367 void visitHTMLStartTagComment(const HTMLStartTagComment *C);
368 void visitHTMLEndTagComment(const HTMLEndTagComment *C);
369
370 // Block comments.
371 void visitBlockCommandComment(const BlockCommandComment *C);
372 void visitParamCommandComment(const ParamCommandComment *C);
373 void visitTParamCommandComment(const TParamCommandComment *C);
374 void visitVerbatimBlockComment(const VerbatimBlockComment *C);
375 void visitVerbatimBlockLineComment(const VerbatimBlockLineComment *C);
376 void visitVerbatimLineComment(const VerbatimLineComment *C);
Chris Lattnercbe4f772007-08-08 22:51:59 +0000377 };
378}
379
380//===----------------------------------------------------------------------===//
Chris Lattner11e30d32007-08-30 06:17:34 +0000381// Utilities
382//===----------------------------------------------------------------------===//
383
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000384void ASTDumper::dumpPointer(const void *Ptr) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000385 ColorScope Color(*this, AddressColor);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000386 OS << ' ' << Ptr;
387}
388
Alexander Kornienko18ec81b2012-12-13 13:59:55 +0000389void ASTDumper::dumpLocation(SourceLocation Loc) {
Alex McCarthye14ddef2014-05-02 20:24:11 +0000390 if (!SM)
391 return;
392
Richard Trieud215b8d2013-01-26 01:31:20 +0000393 ColorScope Color(*this, LocationColor);
Chris Lattner53e384f2009-01-16 07:00:02 +0000394 SourceLocation SpellingLoc = SM->getSpellingLoc(Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000395
Chris Lattner11e30d32007-08-30 06:17:34 +0000396 // The general format we print out is filename:line:col, but we drop pieces
397 // that haven't changed since the last loc printed.
Chris Lattnerf1ca7d32009-01-27 07:57:44 +0000398 PresumedLoc PLoc = SM->getPresumedLoc(SpellingLoc);
399
Douglas Gregor453b0122010-11-12 07:15:47 +0000400 if (PLoc.isInvalid()) {
401 OS << "<invalid sloc>";
402 return;
403 }
404
Chris Lattnerf1ca7d32009-01-27 07:57:44 +0000405 if (strcmp(PLoc.getFilename(), LastLocFilename) != 0) {
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000406 OS << PLoc.getFilename() << ':' << PLoc.getLine()
407 << ':' << PLoc.getColumn();
Chris Lattnerf1ca7d32009-01-27 07:57:44 +0000408 LastLocFilename = PLoc.getFilename();
409 LastLocLine = PLoc.getLine();
410 } else if (PLoc.getLine() != LastLocLine) {
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000411 OS << "line" << ':' << PLoc.getLine()
412 << ':' << PLoc.getColumn();
Chris Lattnerf1ca7d32009-01-27 07:57:44 +0000413 LastLocLine = PLoc.getLine();
Chris Lattner11e30d32007-08-30 06:17:34 +0000414 } else {
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000415 OS << "col" << ':' << PLoc.getColumn();
Chris Lattner11e30d32007-08-30 06:17:34 +0000416 }
417}
418
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000419void ASTDumper::dumpSourceRange(SourceRange R) {
Chris Lattner11e30d32007-08-30 06:17:34 +0000420 // Can't translate locations if a SourceManager isn't available.
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000421 if (!SM)
422 return;
Mike Stump11289f42009-09-09 15:08:12 +0000423
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000424 OS << " <";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000425 dumpLocation(R.getBegin());
Chris Lattnera7c19fe2007-10-16 22:36:42 +0000426 if (R.getBegin() != R.getEnd()) {
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000427 OS << ", ";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000428 dumpLocation(R.getEnd());
Chris Lattner11e30d32007-08-30 06:17:34 +0000429 }
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000430 OS << ">";
Mike Stump11289f42009-09-09 15:08:12 +0000431
Chris Lattner11e30d32007-08-30 06:17:34 +0000432 // <t2.c:123:421[blah], t2.c:412:321>
433
434}
435
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000436void ASTDumper::dumpBareType(QualType T) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000437 ColorScope Color(*this, TypeColor);
438
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000439 SplitQualType T_split = T.split();
440 OS << "'" << QualType::getAsString(T_split) << "'";
441
442 if (!T.isNull()) {
443 // If the type is sugared, also dump a (shallow) desugared type.
444 SplitQualType D_split = T.getSplitDesugaredType();
445 if (T_split != D_split)
446 OS << ":'" << QualType::getAsString(D_split) << "'";
447 }
448}
449
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000450void ASTDumper::dumpType(QualType T) {
451 OS << ' ';
452 dumpBareType(T);
453}
454
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000455void ASTDumper::dumpBareDeclRef(const Decl *D) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000456 {
457 ColorScope Color(*this, DeclKindNameColor);
458 OS << D->getDeclKindName();
459 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000460 dumpPointer(D);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000461
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000462 if (const NamedDecl *ND = dyn_cast<NamedDecl>(D)) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000463 ColorScope Color(*this, DeclNameColor);
David Blaikied4da8722013-05-14 21:04:00 +0000464 OS << " '" << ND->getDeclName() << '\'';
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000465 }
466
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000467 if (const ValueDecl *VD = dyn_cast<ValueDecl>(D))
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000468 dumpType(VD->getType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000469}
470
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000471void ASTDumper::dumpDeclRef(const Decl *D, const char *Label) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000472 if (!D)
473 return;
474
Richard Smithf7514452014-10-30 21:02:37 +0000475 dumpChild([=]{
476 if (Label)
477 OS << Label << ' ';
478 dumpBareDeclRef(D);
479 });
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000480}
481
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000482void ASTDumper::dumpName(const NamedDecl *ND) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000483 if (ND->getDeclName()) {
484 ColorScope Color(*this, DeclNameColor);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000485 OS << ' ' << ND->getNameAsString();
Richard Trieud215b8d2013-01-26 01:31:20 +0000486 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000487}
488
Richard Trieude5cc7d2013-01-31 01:44:26 +0000489bool ASTDumper::hasNodes(const DeclContext *DC) {
490 if (!DC)
491 return false;
492
Richard Smith1d209d02013-05-23 01:49:11 +0000493 return DC->hasExternalLexicalStorage() ||
494 DC->noload_decls_begin() != DC->noload_decls_end();
Richard Trieude5cc7d2013-01-31 01:44:26 +0000495}
496
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000497void ASTDumper::dumpDeclContext(const DeclContext *DC) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000498 if (!DC)
499 return;
Richard Smithdcc2c452014-03-17 23:00:06 +0000500
Richard Smithdcc2c452014-03-17 23:00:06 +0000501 for (auto *D : DC->noload_decls())
Richard Smithf7514452014-10-30 21:02:37 +0000502 dumpDecl(D);
Richard Smithdcc2c452014-03-17 23:00:06 +0000503
504 if (DC->hasExternalLexicalStorage()) {
Richard Smithf7514452014-10-30 21:02:37 +0000505 dumpChild([=]{
506 ColorScope Color(*this, UndeserializedColor);
507 OS << "<undeserialized declarations>";
508 });
Richard Smith1d209d02013-05-23 01:49:11 +0000509 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000510}
511
Richard Smith35f986d2014-08-11 22:11:07 +0000512void ASTDumper::dumpLookups(const DeclContext *DC, bool DumpDecls) {
Richard Smithf7514452014-10-30 21:02:37 +0000513 dumpChild([=] {
514 OS << "StoredDeclsMap ";
515 dumpBareDeclRef(cast<Decl>(DC));
Richard Smith33937e72013-06-22 21:49:40 +0000516
Richard Smithf7514452014-10-30 21:02:37 +0000517 const DeclContext *Primary = DC->getPrimaryContext();
518 if (Primary != DC) {
519 OS << " primary";
520 dumpPointer(cast<Decl>(Primary));
Richard Smith33937e72013-06-22 21:49:40 +0000521 }
522
Richard Smithf7514452014-10-30 21:02:37 +0000523 bool HasUndeserializedLookups = Primary->hasExternalVisibleStorage();
Richard Smith35f986d2014-08-11 22:11:07 +0000524
Richard Smithf7514452014-10-30 21:02:37 +0000525 DeclContext::all_lookups_iterator I = Primary->noload_lookups_begin(),
526 E = Primary->noload_lookups_end();
527 while (I != E) {
528 DeclarationName Name = I.getLookupName();
529 DeclContextLookupResult R = *I++;
Richard Smith35f986d2014-08-11 22:11:07 +0000530
Richard Smithf7514452014-10-30 21:02:37 +0000531 dumpChild([=] {
532 OS << "DeclarationName ";
533 {
534 ColorScope Color(*this, DeclNameColor);
535 OS << '\'' << Name << '\'';
536 }
Richard Smith35f986d2014-08-11 22:11:07 +0000537
Richard Smithf7514452014-10-30 21:02:37 +0000538 for (DeclContextLookupResult::iterator RI = R.begin(), RE = R.end();
539 RI != RE; ++RI) {
540 dumpChild([=] {
541 dumpBareDeclRef(*RI);
542
543 if ((*RI)->isHidden())
544 OS << " hidden";
545
546 // If requested, dump the redecl chain for this lookup.
547 if (DumpDecls) {
548 // Dump earliest decl first.
549 std::function<void(Decl *)> DumpWithPrev = [&](Decl *D) {
550 if (Decl *Prev = D->getPreviousDecl())
551 DumpWithPrev(Prev);
552 dumpDecl(D);
553 };
554 DumpWithPrev(*RI);
555 }
556 });
557 }
558 });
Richard Smith33937e72013-06-22 21:49:40 +0000559 }
Richard Smith33937e72013-06-22 21:49:40 +0000560
Richard Smithf7514452014-10-30 21:02:37 +0000561 if (HasUndeserializedLookups) {
562 dumpChild([=] {
563 ColorScope Color(*this, UndeserializedColor);
564 OS << "<undeserialized lookups>";
565 });
566 }
567 });
Richard Smith33937e72013-06-22 21:49:40 +0000568}
569
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000570void ASTDumper::dumpAttr(const Attr *A) {
Richard Smithf7514452014-10-30 21:02:37 +0000571 dumpChild([=] {
572 {
573 ColorScope Color(*this, AttrColor);
Aaron Ballman36a53502014-01-16 13:03:14 +0000574
Richard Smithf7514452014-10-30 21:02:37 +0000575 switch (A->getKind()) {
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000576#define ATTR(X) case attr::X: OS << #X; break;
577#include "clang/Basic/AttrList.inc"
Richard Smithf7514452014-10-30 21:02:37 +0000578 default:
579 llvm_unreachable("unexpected attribute kind");
580 }
581 OS << "Attr";
Richard Trieud215b8d2013-01-26 01:31:20 +0000582 }
Richard Smithf7514452014-10-30 21:02:37 +0000583 dumpPointer(A);
584 dumpSourceRange(A->getRange());
585 if (A->isInherited())
586 OS << " Inherited";
587 if (A->isImplicit())
588 OS << " Implicit";
Hans Wennborgb0a8b4a2014-05-31 04:05:57 +0000589#include "clang/AST/AttrDump.inc"
Richard Smithf7514452014-10-30 21:02:37 +0000590 });
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000591}
592
Richard Smith71bec062013-10-15 21:58:30 +0000593static void dumpPreviousDeclImpl(raw_ostream &OS, ...) {}
594
595template<typename T>
596static void dumpPreviousDeclImpl(raw_ostream &OS, const Mergeable<T> *D) {
Rafael Espindola8db352d2013-10-17 15:37:26 +0000597 const T *First = D->getFirstDecl();
Richard Smith71bec062013-10-15 21:58:30 +0000598 if (First != D)
599 OS << " first " << First;
Richard Smithf5f43542013-02-07 01:35:44 +0000600}
601
602template<typename T>
Richard Smith71bec062013-10-15 21:58:30 +0000603static void dumpPreviousDeclImpl(raw_ostream &OS, const Redeclarable<T> *D) {
604 const T *Prev = D->getPreviousDecl();
605 if (Prev)
606 OS << " prev " << Prev;
Richard Smithf5f43542013-02-07 01:35:44 +0000607}
608
Richard Smith71bec062013-10-15 21:58:30 +0000609/// Dump the previous declaration in the redeclaration chain for a declaration,
610/// if any.
611static void dumpPreviousDecl(raw_ostream &OS, const Decl *D) {
Richard Smithf5f43542013-02-07 01:35:44 +0000612 switch (D->getKind()) {
613#define DECL(DERIVED, BASE) \
614 case Decl::DERIVED: \
Richard Smith71bec062013-10-15 21:58:30 +0000615 return dumpPreviousDeclImpl(OS, cast<DERIVED##Decl>(D));
Richard Smithf5f43542013-02-07 01:35:44 +0000616#define ABSTRACT_DECL(DECL)
617#include "clang/AST/DeclNodes.inc"
618 }
619 llvm_unreachable("Decl that isn't part of DeclNodes.inc!");
620}
621
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000622//===----------------------------------------------------------------------===//
623// C++ Utilities
624//===----------------------------------------------------------------------===//
625
626void ASTDumper::dumpAccessSpecifier(AccessSpecifier AS) {
627 switch (AS) {
628 case AS_none:
629 break;
630 case AS_public:
631 OS << "public";
632 break;
633 case AS_protected:
634 OS << "protected";
635 break;
636 case AS_private:
637 OS << "private";
638 break;
639 }
640}
641
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000642void ASTDumper::dumpCXXCtorInitializer(const CXXCtorInitializer *Init) {
Richard Smithf7514452014-10-30 21:02:37 +0000643 dumpChild([=] {
644 OS << "CXXCtorInitializer";
645 if (Init->isAnyMemberInitializer()) {
646 OS << ' ';
647 dumpBareDeclRef(Init->getAnyMember());
648 } else if (Init->isBaseInitializer()) {
649 dumpType(QualType(Init->getBaseClass(), 0));
650 } else if (Init->isDelegatingInitializer()) {
651 dumpType(Init->getTypeSourceInfo()->getType());
652 } else {
653 llvm_unreachable("Unknown initializer type");
654 }
655 dumpStmt(Init->getInit());
656 });
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000657}
658
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000659void ASTDumper::dumpTemplateParameters(const TemplateParameterList *TPL) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000660 if (!TPL)
661 return;
662
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000663 for (TemplateParameterList::const_iterator I = TPL->begin(), E = TPL->end();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000664 I != E; ++I)
665 dumpDecl(*I);
666}
667
668void ASTDumper::dumpTemplateArgumentListInfo(
669 const TemplateArgumentListInfo &TALI) {
Richard Smithf7514452014-10-30 21:02:37 +0000670 for (unsigned i = 0, e = TALI.size(); i < e; ++i)
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000671 dumpTemplateArgumentLoc(TALI[i]);
672}
673
674void ASTDumper::dumpTemplateArgumentLoc(const TemplateArgumentLoc &A) {
675 dumpTemplateArgument(A.getArgument(), A.getSourceRange());
676}
677
678void ASTDumper::dumpTemplateArgumentList(const TemplateArgumentList &TAL) {
679 for (unsigned i = 0, e = TAL.size(); i < e; ++i)
680 dumpTemplateArgument(TAL[i]);
681}
682
683void ASTDumper::dumpTemplateArgument(const TemplateArgument &A, SourceRange R) {
Richard Smithf7514452014-10-30 21:02:37 +0000684 dumpChild([=] {
685 OS << "TemplateArgument";
686 if (R.isValid())
687 dumpSourceRange(R);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000688
Richard Smithf7514452014-10-30 21:02:37 +0000689 switch (A.getKind()) {
690 case TemplateArgument::Null:
691 OS << " null";
692 break;
693 case TemplateArgument::Type:
694 OS << " type";
695 dumpType(A.getAsType());
696 break;
697 case TemplateArgument::Declaration:
698 OS << " decl";
699 dumpDeclRef(A.getAsDecl());
700 break;
701 case TemplateArgument::NullPtr:
702 OS << " nullptr";
703 break;
704 case TemplateArgument::Integral:
705 OS << " integral " << A.getAsIntegral();
706 break;
707 case TemplateArgument::Template:
708 OS << " template ";
709 A.getAsTemplate().dump(OS);
710 break;
711 case TemplateArgument::TemplateExpansion:
712 OS << " template expansion";
713 A.getAsTemplateOrTemplatePattern().dump(OS);
714 break;
715 case TemplateArgument::Expression:
716 OS << " expr";
717 dumpStmt(A.getAsExpr());
718 break;
719 case TemplateArgument::Pack:
720 OS << " pack";
721 for (TemplateArgument::pack_iterator I = A.pack_begin(), E = A.pack_end();
722 I != E; ++I)
723 dumpTemplateArgument(*I);
724 break;
Richard Trieude5cc7d2013-01-31 01:44:26 +0000725 }
Richard Smithf7514452014-10-30 21:02:37 +0000726 });
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000727}
728
Chris Lattner11e30d32007-08-30 06:17:34 +0000729//===----------------------------------------------------------------------===//
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000730// Decl dumping methods.
Chris Lattnercbe4f772007-08-08 22:51:59 +0000731//===----------------------------------------------------------------------===//
732
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000733void ASTDumper::dumpDecl(const Decl *D) {
Richard Smithf7514452014-10-30 21:02:37 +0000734 dumpChild([=] {
735 if (!D) {
736 ColorScope Color(*this, NullColor);
737 OS << "<<<NULL>>>";
738 return;
739 }
Mike Stump11289f42009-09-09 15:08:12 +0000740
Richard Smithf7514452014-10-30 21:02:37 +0000741 {
742 ColorScope Color(*this, DeclKindNameColor);
743 OS << D->getDeclKindName() << "Decl";
744 }
745 dumpPointer(D);
746 if (D->getLexicalDeclContext() != D->getDeclContext())
747 OS << " parent " << cast<Decl>(D->getDeclContext());
748 dumpPreviousDecl(OS, D);
749 dumpSourceRange(D->getSourceRange());
750 OS << ' ';
751 dumpLocation(D->getLocation());
752 if (Module *M = D->getOwningModule())
753 OS << " in " << M->getFullModuleName();
754 if (const NamedDecl *ND = dyn_cast<NamedDecl>(D))
755 if (ND->isHidden())
756 OS << " hidden";
757 if (D->isImplicit())
758 OS << " implicit";
759 if (D->isUsed())
760 OS << " used";
761 else if (D->isThisDeclarationReferenced())
762 OS << " referenced";
763 if (D->isInvalidDecl())
764 OS << " invalid";
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000765
Richard Smithf7514452014-10-30 21:02:37 +0000766 ConstDeclVisitor<ASTDumper>::Visit(D);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000767
Richard Smithf7514452014-10-30 21:02:37 +0000768 for (Decl::attr_iterator I = D->attr_begin(), E = D->attr_end(); I != E;
769 ++I)
770 dumpAttr(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000771
Richard Smithf7514452014-10-30 21:02:37 +0000772 if (const FullComment *Comment =
773 D->getASTContext().getLocalCommentForDeclUncached(D))
774 dumpFullComment(Comment);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000775
Richard Smithf7514452014-10-30 21:02:37 +0000776 // Decls within functions are visited by the body.
777 if (!isa<FunctionDecl>(*D) && !isa<ObjCMethodDecl>(*D) &&
778 hasNodes(dyn_cast<DeclContext>(D)))
779 dumpDeclContext(cast<DeclContext>(D));
780 });
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000781}
782
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000783void ASTDumper::VisitLabelDecl(const LabelDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000784 dumpName(D);
785}
786
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000787void ASTDumper::VisitTypedefDecl(const TypedefDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000788 dumpName(D);
789 dumpType(D->getUnderlyingType());
790 if (D->isModulePrivate())
791 OS << " __module_private__";
792}
793
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000794void ASTDumper::VisitEnumDecl(const EnumDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000795 if (D->isScoped()) {
796 if (D->isScopedUsingClassTag())
797 OS << " class";
798 else
799 OS << " struct";
800 }
801 dumpName(D);
802 if (D->isModulePrivate())
803 OS << " __module_private__";
804 if (D->isFixed())
805 dumpType(D->getIntegerType());
806}
807
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000808void ASTDumper::VisitRecordDecl(const RecordDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000809 OS << ' ' << D->getKindName();
810 dumpName(D);
811 if (D->isModulePrivate())
812 OS << " __module_private__";
Richard Smith99bc1b92013-08-30 05:32:29 +0000813 if (D->isCompleteDefinition())
814 OS << " definition";
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000815}
816
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000817void ASTDumper::VisitEnumConstantDecl(const EnumConstantDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000818 dumpName(D);
819 dumpType(D->getType());
Richard Smithf7514452014-10-30 21:02:37 +0000820 if (const Expr *Init = D->getInitExpr())
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000821 dumpStmt(Init);
822}
823
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000824void ASTDumper::VisitIndirectFieldDecl(const IndirectFieldDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000825 dumpName(D);
826 dumpType(D->getType());
Richard Smithdcc2c452014-03-17 23:00:06 +0000827
Richard Smith8aa49222014-03-18 00:35:12 +0000828 for (auto *Child : D->chain())
Richard Smithf7514452014-10-30 21:02:37 +0000829 dumpDeclRef(Child);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000830}
831
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000832void ASTDumper::VisitFunctionDecl(const FunctionDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000833 dumpName(D);
834 dumpType(D->getType());
835
Rafael Espindola6ae7e502013-04-03 19:27:57 +0000836 StorageClass SC = D->getStorageClass();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000837 if (SC != SC_None)
838 OS << ' ' << VarDecl::getStorageClassSpecifierString(SC);
839 if (D->isInlineSpecified())
840 OS << " inline";
841 if (D->isVirtualAsWritten())
842 OS << " virtual";
843 if (D->isModulePrivate())
844 OS << " __module_private__";
845
846 if (D->isPure())
847 OS << " pure";
848 else if (D->isDeletedAsWritten())
849 OS << " delete";
850
Richard Smithadaa0152013-05-17 02:09:46 +0000851 if (const FunctionProtoType *FPT = D->getType()->getAs<FunctionProtoType>()) {
852 FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo();
Richard Smith8acb4282014-07-31 21:57:55 +0000853 switch (EPI.ExceptionSpec.Type) {
Richard Smithadaa0152013-05-17 02:09:46 +0000854 default: break;
855 case EST_Unevaluated:
Richard Smith8acb4282014-07-31 21:57:55 +0000856 OS << " noexcept-unevaluated " << EPI.ExceptionSpec.SourceDecl;
Richard Smithadaa0152013-05-17 02:09:46 +0000857 break;
858 case EST_Uninstantiated:
Richard Smith8acb4282014-07-31 21:57:55 +0000859 OS << " noexcept-uninstantiated " << EPI.ExceptionSpec.SourceTemplate;
Richard Smithadaa0152013-05-17 02:09:46 +0000860 break;
861 }
862 }
863
Richard Smithf7514452014-10-30 21:02:37 +0000864 if (const FunctionTemplateSpecializationInfo *FTSI =
865 D->getTemplateSpecializationInfo())
Richard Trieude5cc7d2013-01-31 01:44:26 +0000866 dumpTemplateArgumentList(*FTSI->TemplateArguments);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000867
Dmitri Gribenkof8579502013-01-12 19:30:44 +0000868 for (ArrayRef<NamedDecl *>::iterator
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000869 I = D->getDeclsInPrototypeScope().begin(),
Richard Smithf7514452014-10-30 21:02:37 +0000870 E = D->getDeclsInPrototypeScope().end(); I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000871 dumpDecl(*I);
872
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000873 for (FunctionDecl::param_const_iterator I = D->param_begin(),
874 E = D->param_end();
Richard Smithf7514452014-10-30 21:02:37 +0000875 I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000876 dumpDecl(*I);
Richard Smithf7514452014-10-30 21:02:37 +0000877
878 if (const CXXConstructorDecl *C = dyn_cast<CXXConstructorDecl>(D))
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000879 for (CXXConstructorDecl::init_const_iterator I = C->init_begin(),
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000880 E = C->init_end();
Richard Smithf7514452014-10-30 21:02:37 +0000881 I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000882 dumpCXXCtorInitializer(*I);
883
Richard Smithf7514452014-10-30 21:02:37 +0000884 if (D->doesThisDeclarationHaveABody())
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000885 dumpStmt(D->getBody());
886}
887
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000888void ASTDumper::VisitFieldDecl(const FieldDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000889 dumpName(D);
890 dumpType(D->getType());
891 if (D->isMutable())
892 OS << " mutable";
893 if (D->isModulePrivate())
894 OS << " __module_private__";
Richard Trieude5cc7d2013-01-31 01:44:26 +0000895
Richard Smithf7514452014-10-30 21:02:37 +0000896 if (D->isBitField())
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000897 dumpStmt(D->getBitWidth());
Richard Smithf7514452014-10-30 21:02:37 +0000898 if (Expr *Init = D->getInClassInitializer())
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000899 dumpStmt(Init);
900}
901
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000902void ASTDumper::VisitVarDecl(const VarDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000903 dumpName(D);
904 dumpType(D->getType());
Rafael Espindola6ae7e502013-04-03 19:27:57 +0000905 StorageClass SC = D->getStorageClass();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000906 if (SC != SC_None)
907 OS << ' ' << VarDecl::getStorageClassSpecifierString(SC);
Richard Smithfd3834f2013-04-13 02:43:54 +0000908 switch (D->getTLSKind()) {
909 case VarDecl::TLS_None: break;
910 case VarDecl::TLS_Static: OS << " tls"; break;
911 case VarDecl::TLS_Dynamic: OS << " tls_dynamic"; break;
912 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000913 if (D->isModulePrivate())
914 OS << " __module_private__";
915 if (D->isNRVOVariable())
916 OS << " nrvo";
Richard Trieude5cc7d2013-01-31 01:44:26 +0000917 if (D->hasInit()) {
Richard Smithd9967cc2014-07-10 22:54:03 +0000918 switch (D->getInitStyle()) {
919 case VarDecl::CInit: OS << " cinit"; break;
920 case VarDecl::CallInit: OS << " callinit"; break;
921 case VarDecl::ListInit: OS << " listinit"; break;
922 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000923 dumpStmt(D->getInit());
Richard Trieude5cc7d2013-01-31 01:44:26 +0000924 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000925}
926
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000927void ASTDumper::VisitFileScopeAsmDecl(const FileScopeAsmDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000928 dumpStmt(D->getAsmString());
929}
930
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000931void ASTDumper::VisitImportDecl(const ImportDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000932 OS << ' ' << D->getImportedModule()->getFullModuleName();
933}
934
935//===----------------------------------------------------------------------===//
936// C++ Declarations
937//===----------------------------------------------------------------------===//
938
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000939void ASTDumper::VisitNamespaceDecl(const NamespaceDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000940 dumpName(D);
941 if (D->isInline())
942 OS << " inline";
943 if (!D->isOriginalNamespace())
944 dumpDeclRef(D->getOriginalNamespace(), "original");
945}
946
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000947void ASTDumper::VisitUsingDirectiveDecl(const UsingDirectiveDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000948 OS << ' ';
949 dumpBareDeclRef(D->getNominatedNamespace());
950}
951
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000952void ASTDumper::VisitNamespaceAliasDecl(const NamespaceAliasDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000953 dumpName(D);
954 dumpDeclRef(D->getAliasedNamespace());
955}
956
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000957void ASTDumper::VisitTypeAliasDecl(const TypeAliasDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000958 dumpName(D);
959 dumpType(D->getUnderlyingType());
960}
961
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000962void ASTDumper::VisitTypeAliasTemplateDecl(const TypeAliasTemplateDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000963 dumpName(D);
964 dumpTemplateParameters(D->getTemplateParameters());
965 dumpDecl(D->getTemplatedDecl());
966}
967
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000968void ASTDumper::VisitCXXRecordDecl(const CXXRecordDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000969 VisitRecordDecl(D);
970 if (!D->isCompleteDefinition())
971 return;
972
Aaron Ballman574705e2014-03-13 15:41:46 +0000973 for (const auto &I : D->bases()) {
Richard Smithf7514452014-10-30 21:02:37 +0000974 dumpChild([=] {
975 if (I.isVirtual())
976 OS << "virtual ";
977 dumpAccessSpecifier(I.getAccessSpecifier());
978 dumpType(I.getType());
979 if (I.isPackExpansion())
980 OS << "...";
981 });
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000982 }
983}
984
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000985void ASTDumper::VisitStaticAssertDecl(const StaticAssertDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000986 dumpStmt(D->getAssertExpr());
987 dumpStmt(D->getMessage());
988}
989
Richard Smithcbdf7332014-03-18 02:07:28 +0000990template<typename SpecializationDecl>
Richard Smithf7514452014-10-30 21:02:37 +0000991void ASTDumper::VisitTemplateDeclSpecialization(const SpecializationDecl *D,
Richard Smithcbdf7332014-03-18 02:07:28 +0000992 bool DumpExplicitInst,
993 bool DumpRefOnly) {
994 bool DumpedAny = false;
995 for (auto *RedeclWithBadType : D->redecls()) {
996 // FIXME: The redecls() range sometimes has elements of a less-specific
997 // type. (In particular, ClassTemplateSpecializationDecl::redecls() gives
998 // us TagDecls, and should give CXXRecordDecls).
999 auto *Redecl = dyn_cast<SpecializationDecl>(RedeclWithBadType);
1000 if (!Redecl) {
1001 // Found the injected-class-name for a class template. This will be dumped
1002 // as part of its surrounding class so we don't need to dump it here.
1003 assert(isa<CXXRecordDecl>(RedeclWithBadType) &&
1004 "expected an injected-class-name");
1005 continue;
1006 }
1007
1008 switch (Redecl->getTemplateSpecializationKind()) {
1009 case TSK_ExplicitInstantiationDeclaration:
1010 case TSK_ExplicitInstantiationDefinition:
1011 if (!DumpExplicitInst)
1012 break;
1013 // Fall through.
1014 case TSK_Undeclared:
1015 case TSK_ImplicitInstantiation:
Richard Smithf7514452014-10-30 21:02:37 +00001016 if (DumpRefOnly)
1017 dumpDeclRef(Redecl);
1018 else
1019 dumpDecl(Redecl);
Richard Smithcbdf7332014-03-18 02:07:28 +00001020 DumpedAny = true;
1021 break;
1022 case TSK_ExplicitSpecialization:
1023 break;
1024 }
1025 }
1026
1027 // Ensure we dump at least one decl for each specialization.
1028 if (!DumpedAny)
Richard Smithf7514452014-10-30 21:02:37 +00001029 dumpDeclRef(D);
Richard Smithcbdf7332014-03-18 02:07:28 +00001030}
1031
Richard Smith20ade552014-03-17 23:34:53 +00001032template<typename TemplateDecl>
1033void ASTDumper::VisitTemplateDecl(const TemplateDecl *D,
1034 bool DumpExplicitInst) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001035 dumpName(D);
1036 dumpTemplateParameters(D->getTemplateParameters());
Richard Smithdcc2c452014-03-17 23:00:06 +00001037
Richard Smithf7514452014-10-30 21:02:37 +00001038 dumpDecl(D->getTemplatedDecl());
Richard Smithdcc2c452014-03-17 23:00:06 +00001039
Richard Smithcbdf7332014-03-18 02:07:28 +00001040 for (auto *Child : D->specializations())
Richard Smithf7514452014-10-30 21:02:37 +00001041 VisitTemplateDeclSpecialization(Child, DumpExplicitInst,
Richard Smithcbdf7332014-03-18 02:07:28 +00001042 !D->isCanonicalDecl());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001043}
1044
Richard Smith20ade552014-03-17 23:34:53 +00001045void ASTDumper::VisitFunctionTemplateDecl(const FunctionTemplateDecl *D) {
1046 // FIXME: We don't add a declaration of a function template specialization
1047 // to its context when it's explicitly instantiated, so dump explicit
1048 // instantiations when we dump the template itself.
1049 VisitTemplateDecl(D, true);
1050}
1051
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001052void ASTDumper::VisitClassTemplateDecl(const ClassTemplateDecl *D) {
Richard Smith20ade552014-03-17 23:34:53 +00001053 VisitTemplateDecl(D, false);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001054}
1055
1056void ASTDumper::VisitClassTemplateSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001057 const ClassTemplateSpecializationDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001058 VisitCXXRecordDecl(D);
1059 dumpTemplateArgumentList(D->getTemplateArgs());
1060}
1061
1062void ASTDumper::VisitClassTemplatePartialSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001063 const ClassTemplatePartialSpecializationDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001064 VisitClassTemplateSpecializationDecl(D);
1065 dumpTemplateParameters(D->getTemplateParameters());
1066}
1067
1068void ASTDumper::VisitClassScopeFunctionSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001069 const ClassScopeFunctionSpecializationDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001070 dumpDeclRef(D->getSpecialization());
1071 if (D->hasExplicitTemplateArgs())
1072 dumpTemplateArgumentListInfo(D->templateArgs());
1073}
1074
Richard Smithd25789a2013-09-18 01:36:02 +00001075void ASTDumper::VisitVarTemplateDecl(const VarTemplateDecl *D) {
Richard Smith20ade552014-03-17 23:34:53 +00001076 VisitTemplateDecl(D, false);
Richard Smithd25789a2013-09-18 01:36:02 +00001077}
1078
1079void ASTDumper::VisitVarTemplateSpecializationDecl(
1080 const VarTemplateSpecializationDecl *D) {
1081 dumpTemplateArgumentList(D->getTemplateArgs());
1082 VisitVarDecl(D);
1083}
1084
1085void ASTDumper::VisitVarTemplatePartialSpecializationDecl(
1086 const VarTemplatePartialSpecializationDecl *D) {
1087 dumpTemplateParameters(D->getTemplateParameters());
1088 VisitVarTemplateSpecializationDecl(D);
1089}
1090
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001091void ASTDumper::VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001092 if (D->wasDeclaredWithTypename())
1093 OS << " typename";
1094 else
1095 OS << " class";
1096 if (D->isParameterPack())
1097 OS << " ...";
1098 dumpName(D);
Richard Smithf7514452014-10-30 21:02:37 +00001099 if (D->hasDefaultArgument())
Richard Smithecf74ff2014-03-23 20:50:39 +00001100 dumpTemplateArgument(D->getDefaultArgument());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001101}
1102
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001103void ASTDumper::VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001104 dumpType(D->getType());
1105 if (D->isParameterPack())
1106 OS << " ...";
1107 dumpName(D);
Richard Smithf7514452014-10-30 21:02:37 +00001108 if (D->hasDefaultArgument())
Richard Smithecf74ff2014-03-23 20:50:39 +00001109 dumpTemplateArgument(D->getDefaultArgument());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001110}
1111
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001112void ASTDumper::VisitTemplateTemplateParmDecl(
1113 const TemplateTemplateParmDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001114 if (D->isParameterPack())
1115 OS << " ...";
1116 dumpName(D);
1117 dumpTemplateParameters(D->getTemplateParameters());
Richard Smithf7514452014-10-30 21:02:37 +00001118 if (D->hasDefaultArgument())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001119 dumpTemplateArgumentLoc(D->getDefaultArgument());
1120}
1121
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001122void ASTDumper::VisitUsingDecl(const UsingDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001123 OS << ' ';
1124 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
1125 OS << D->getNameAsString();
1126}
1127
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001128void ASTDumper::VisitUnresolvedUsingTypenameDecl(
1129 const UnresolvedUsingTypenameDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001130 OS << ' ';
1131 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
1132 OS << D->getNameAsString();
1133}
1134
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001135void ASTDumper::VisitUnresolvedUsingValueDecl(const UnresolvedUsingValueDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001136 OS << ' ';
1137 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
1138 OS << D->getNameAsString();
1139 dumpType(D->getType());
1140}
1141
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001142void ASTDumper::VisitUsingShadowDecl(const UsingShadowDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001143 OS << ' ';
1144 dumpBareDeclRef(D->getTargetDecl());
1145}
1146
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001147void ASTDumper::VisitLinkageSpecDecl(const LinkageSpecDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001148 switch (D->getLanguage()) {
1149 case LinkageSpecDecl::lang_c: OS << " C"; break;
1150 case LinkageSpecDecl::lang_cxx: OS << " C++"; break;
1151 }
1152}
1153
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001154void ASTDumper::VisitAccessSpecDecl(const AccessSpecDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001155 OS << ' ';
1156 dumpAccessSpecifier(D->getAccess());
1157}
1158
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001159void ASTDumper::VisitFriendDecl(const FriendDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001160 if (TypeSourceInfo *T = D->getFriendType())
1161 dumpType(T->getType());
1162 else
1163 dumpDecl(D->getFriendDecl());
1164}
1165
1166//===----------------------------------------------------------------------===//
1167// Obj-C Declarations
1168//===----------------------------------------------------------------------===//
1169
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001170void ASTDumper::VisitObjCIvarDecl(const ObjCIvarDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001171 dumpName(D);
1172 dumpType(D->getType());
1173 if (D->getSynthesize())
1174 OS << " synthesize";
1175
1176 switch (D->getAccessControl()) {
1177 case ObjCIvarDecl::None:
1178 OS << " none";
1179 break;
1180 case ObjCIvarDecl::Private:
1181 OS << " private";
1182 break;
1183 case ObjCIvarDecl::Protected:
1184 OS << " protected";
1185 break;
1186 case ObjCIvarDecl::Public:
1187 OS << " public";
1188 break;
1189 case ObjCIvarDecl::Package:
1190 OS << " package";
1191 break;
1192 }
1193}
1194
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001195void ASTDumper::VisitObjCMethodDecl(const ObjCMethodDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001196 if (D->isInstanceMethod())
1197 OS << " -";
1198 else
1199 OS << " +";
1200 dumpName(D);
Alp Toker314cc812014-01-25 16:55:45 +00001201 dumpType(D->getReturnType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001202
Richard Trieude5cc7d2013-01-31 01:44:26 +00001203 if (D->isThisDeclarationADefinition()) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001204 dumpDeclContext(D);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001205 } else {
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001206 for (ObjCMethodDecl::param_const_iterator I = D->param_begin(),
1207 E = D->param_end();
Richard Smithf7514452014-10-30 21:02:37 +00001208 I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001209 dumpDecl(*I);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001210 }
1211
Richard Smithf7514452014-10-30 21:02:37 +00001212 if (D->isVariadic())
1213 dumpChild([=] { OS << "..."; });
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001214
Richard Smithf7514452014-10-30 21:02:37 +00001215 if (D->hasBody())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001216 dumpStmt(D->getBody());
1217}
1218
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001219void ASTDumper::VisitObjCCategoryDecl(const ObjCCategoryDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001220 dumpName(D);
1221 dumpDeclRef(D->getClassInterface());
1222 dumpDeclRef(D->getImplementation());
1223 for (ObjCCategoryDecl::protocol_iterator I = D->protocol_begin(),
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001224 E = D->protocol_end();
Richard Smithf7514452014-10-30 21:02:37 +00001225 I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001226 dumpDeclRef(*I);
1227}
1228
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001229void ASTDumper::VisitObjCCategoryImplDecl(const ObjCCategoryImplDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001230 dumpName(D);
1231 dumpDeclRef(D->getClassInterface());
1232 dumpDeclRef(D->getCategoryDecl());
1233}
1234
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001235void ASTDumper::VisitObjCProtocolDecl(const ObjCProtocolDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001236 dumpName(D);
Richard Smithdcc2c452014-03-17 23:00:06 +00001237
Richard Smith7fcb35f2014-03-18 02:37:59 +00001238 for (auto *Child : D->protocols())
Richard Smithf7514452014-10-30 21:02:37 +00001239 dumpDeclRef(Child);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001240}
1241
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001242void ASTDumper::VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001243 dumpName(D);
1244 dumpDeclRef(D->getSuperClass(), "super");
Richard Smithdcc2c452014-03-17 23:00:06 +00001245
Richard Smithf7514452014-10-30 21:02:37 +00001246 dumpDeclRef(D->getImplementation());
Richard Smith7fcb35f2014-03-18 02:37:59 +00001247 for (auto *Child : D->protocols())
Richard Smithf7514452014-10-30 21:02:37 +00001248 dumpDeclRef(Child);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001249}
1250
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001251void ASTDumper::VisitObjCImplementationDecl(const ObjCImplementationDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001252 dumpName(D);
1253 dumpDeclRef(D->getSuperClass(), "super");
1254 dumpDeclRef(D->getClassInterface());
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001255 for (ObjCImplementationDecl::init_const_iterator I = D->init_begin(),
1256 E = D->init_end();
Richard Smithf7514452014-10-30 21:02:37 +00001257 I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001258 dumpCXXCtorInitializer(*I);
1259}
1260
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001261void ASTDumper::VisitObjCCompatibleAliasDecl(const ObjCCompatibleAliasDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001262 dumpName(D);
1263 dumpDeclRef(D->getClassInterface());
1264}
1265
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001266void ASTDumper::VisitObjCPropertyDecl(const ObjCPropertyDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001267 dumpName(D);
1268 dumpType(D->getType());
1269
1270 if (D->getPropertyImplementation() == ObjCPropertyDecl::Required)
1271 OS << " required";
1272 else if (D->getPropertyImplementation() == ObjCPropertyDecl::Optional)
1273 OS << " optional";
1274
1275 ObjCPropertyDecl::PropertyAttributeKind Attrs = D->getPropertyAttributes();
1276 if (Attrs != ObjCPropertyDecl::OBJC_PR_noattr) {
1277 if (Attrs & ObjCPropertyDecl::OBJC_PR_readonly)
1278 OS << " readonly";
1279 if (Attrs & ObjCPropertyDecl::OBJC_PR_assign)
1280 OS << " assign";
1281 if (Attrs & ObjCPropertyDecl::OBJC_PR_readwrite)
1282 OS << " readwrite";
1283 if (Attrs & ObjCPropertyDecl::OBJC_PR_retain)
1284 OS << " retain";
1285 if (Attrs & ObjCPropertyDecl::OBJC_PR_copy)
1286 OS << " copy";
1287 if (Attrs & ObjCPropertyDecl::OBJC_PR_nonatomic)
1288 OS << " nonatomic";
1289 if (Attrs & ObjCPropertyDecl::OBJC_PR_atomic)
1290 OS << " atomic";
1291 if (Attrs & ObjCPropertyDecl::OBJC_PR_weak)
1292 OS << " weak";
1293 if (Attrs & ObjCPropertyDecl::OBJC_PR_strong)
1294 OS << " strong";
1295 if (Attrs & ObjCPropertyDecl::OBJC_PR_unsafe_unretained)
1296 OS << " unsafe_unretained";
Richard Smithf7514452014-10-30 21:02:37 +00001297 if (Attrs & ObjCPropertyDecl::OBJC_PR_getter)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001298 dumpDeclRef(D->getGetterMethodDecl(), "getter");
Richard Smithf7514452014-10-30 21:02:37 +00001299 if (Attrs & ObjCPropertyDecl::OBJC_PR_setter)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001300 dumpDeclRef(D->getSetterMethodDecl(), "setter");
1301 }
1302}
1303
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001304void ASTDumper::VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001305 dumpName(D->getPropertyDecl());
1306 if (D->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize)
1307 OS << " synthesize";
1308 else
1309 OS << " dynamic";
1310 dumpDeclRef(D->getPropertyDecl());
1311 dumpDeclRef(D->getPropertyIvarDecl());
1312}
1313
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001314void ASTDumper::VisitBlockDecl(const BlockDecl *D) {
Aaron Ballmanb2b8b1d2014-03-07 16:09:59 +00001315 for (auto I : D->params())
1316 dumpDecl(I);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001317
Richard Smithf7514452014-10-30 21:02:37 +00001318 if (D->isVariadic())
1319 dumpChild([=]{ OS << "..."; });
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001320
Richard Smithf7514452014-10-30 21:02:37 +00001321 if (D->capturesCXXThis())
1322 dumpChild([=]{ OS << "capture this"; });
1323
Aaron Ballman9371dd22014-03-14 18:34:04 +00001324 for (const auto &I : D->captures()) {
Richard Smithf7514452014-10-30 21:02:37 +00001325 dumpChild([=] {
1326 OS << "capture";
1327 if (I.isByRef())
1328 OS << " byref";
1329 if (I.isNested())
1330 OS << " nested";
1331 if (I.getVariable()) {
1332 OS << ' ';
1333 dumpBareDeclRef(I.getVariable());
1334 }
1335 if (I.hasCopyExpr())
1336 dumpStmt(I.getCopyExpr());
1337 });
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001338 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001339 dumpStmt(D->getBody());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001340}
1341
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001342//===----------------------------------------------------------------------===//
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001343// Stmt dumping methods.
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001344//===----------------------------------------------------------------------===//
1345
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001346void ASTDumper::dumpStmt(const Stmt *S) {
Richard Smithf7514452014-10-30 21:02:37 +00001347 dumpChild([=] {
1348 if (!S) {
1349 ColorScope Color(*this, NullColor);
1350 OS << "<<<NULL>>>";
1351 return;
1352 }
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001353
Richard Smithf7514452014-10-30 21:02:37 +00001354 if (const DeclStmt *DS = dyn_cast<DeclStmt>(S)) {
1355 VisitDeclStmt(DS);
1356 return;
1357 }
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001358
Richard Smithf7514452014-10-30 21:02:37 +00001359 ConstStmtVisitor<ASTDumper>::Visit(S);
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001360
Richard Smithf7514452014-10-30 21:02:37 +00001361 for (Stmt::const_child_range CI = S->children(); CI; ++CI)
1362 dumpStmt(*CI);
1363 });
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001364}
1365
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001366void ASTDumper::VisitStmt(const Stmt *Node) {
Richard Trieud215b8d2013-01-26 01:31:20 +00001367 {
1368 ColorScope Color(*this, StmtColor);
1369 OS << Node->getStmtClassName();
1370 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001371 dumpPointer(Node);
1372 dumpSourceRange(Node->getSourceRange());
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001373}
1374
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001375void ASTDumper::VisitDeclStmt(const DeclStmt *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001376 VisitStmt(Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001377 for (DeclStmt::const_decl_iterator I = Node->decl_begin(),
1378 E = Node->decl_end();
Richard Smithf7514452014-10-30 21:02:37 +00001379 I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001380 dumpDecl(*I);
Ted Kremenek433a4922007-12-12 06:59:42 +00001381}
1382
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001383void ASTDumper::VisitAttributedStmt(const AttributedStmt *Node) {
Alexander Kornienko5bc364e2013-01-07 17:53:08 +00001384 VisitStmt(Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001385 for (ArrayRef<const Attr *>::iterator I = Node->getAttrs().begin(),
1386 E = Node->getAttrs().end();
Richard Smithf7514452014-10-30 21:02:37 +00001387 I != E; ++I)
Alexander Kornienko5bc364e2013-01-07 17:53:08 +00001388 dumpAttr(*I);
1389}
1390
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001391void ASTDumper::VisitLabelStmt(const LabelStmt *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001392 VisitStmt(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001393 OS << " '" << Node->getName() << "'";
Chris Lattnercbe4f772007-08-08 22:51:59 +00001394}
1395
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001396void ASTDumper::VisitGotoStmt(const GotoStmt *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001397 VisitStmt(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001398 OS << " '" << Node->getLabel()->getName() << "'";
1399 dumpPointer(Node->getLabel());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001400}
1401
Pavel Labath1ef83422013-09-04 14:35:00 +00001402void ASTDumper::VisitCXXCatchStmt(const CXXCatchStmt *Node) {
1403 VisitStmt(Node);
1404 dumpDecl(Node->getExceptionDecl());
1405}
1406
Chris Lattnercbe4f772007-08-08 22:51:59 +00001407//===----------------------------------------------------------------------===//
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001408// Expr dumping methods.
Chris Lattnercbe4f772007-08-08 22:51:59 +00001409//===----------------------------------------------------------------------===//
1410
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001411void ASTDumper::VisitExpr(const Expr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001412 VisitStmt(Node);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001413 dumpType(Node->getType());
1414
Richard Trieud215b8d2013-01-26 01:31:20 +00001415 {
1416 ColorScope Color(*this, ValueKindColor);
1417 switch (Node->getValueKind()) {
1418 case VK_RValue:
1419 break;
1420 case VK_LValue:
1421 OS << " lvalue";
1422 break;
1423 case VK_XValue:
1424 OS << " xvalue";
1425 break;
1426 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001427 }
1428
Richard Trieud215b8d2013-01-26 01:31:20 +00001429 {
1430 ColorScope Color(*this, ObjectKindColor);
1431 switch (Node->getObjectKind()) {
1432 case OK_Ordinary:
1433 break;
1434 case OK_BitField:
1435 OS << " bitfield";
1436 break;
1437 case OK_ObjCProperty:
1438 OS << " objcproperty";
1439 break;
1440 case OK_ObjCSubscript:
1441 OS << " objcsubscript";
1442 break;
1443 case OK_VectorComponent:
1444 OS << " vectorcomponent";
1445 break;
1446 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001447 }
Chris Lattnercbe4f772007-08-08 22:51:59 +00001448}
1449
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001450static void dumpBasePath(raw_ostream &OS, const CastExpr *Node) {
John McCallcf142162010-08-07 06:22:56 +00001451 if (Node->path_empty())
Anders Carlssona70cff62010-04-24 19:06:50 +00001452 return;
1453
1454 OS << " (";
1455 bool First = true;
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001456 for (CastExpr::path_const_iterator I = Node->path_begin(),
1457 E = Node->path_end();
1458 I != E; ++I) {
Anders Carlssona70cff62010-04-24 19:06:50 +00001459 const CXXBaseSpecifier *Base = *I;
1460 if (!First)
1461 OS << " -> ";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001462
Anders Carlssona70cff62010-04-24 19:06:50 +00001463 const CXXRecordDecl *RD =
1464 cast<CXXRecordDecl>(Base->getType()->getAs<RecordType>()->getDecl());
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001465
Anders Carlssona70cff62010-04-24 19:06:50 +00001466 if (Base->isVirtual())
1467 OS << "virtual ";
1468 OS << RD->getName();
1469 First = false;
1470 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001471
Anders Carlssona70cff62010-04-24 19:06:50 +00001472 OS << ')';
1473}
1474
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001475void ASTDumper::VisitCastExpr(const CastExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001476 VisitExpr(Node);
Richard Trieud215b8d2013-01-26 01:31:20 +00001477 OS << " <";
1478 {
1479 ColorScope Color(*this, CastColor);
1480 OS << Node->getCastKindName();
1481 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001482 dumpBasePath(OS, Node);
Anders Carlssona70cff62010-04-24 19:06:50 +00001483 OS << ">";
Anders Carlssond7923c62009-08-22 23:33:40 +00001484}
1485
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001486void ASTDumper::VisitDeclRefExpr(const DeclRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001487 VisitExpr(Node);
Ted Kremenek5f64ca82007-09-10 17:32:55 +00001488
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001489 OS << " ";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001490 dumpBareDeclRef(Node->getDecl());
Chandler Carruth8d26bb02011-05-01 23:48:14 +00001491 if (Node->getDecl() != Node->getFoundDecl()) {
1492 OS << " (";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001493 dumpBareDeclRef(Node->getFoundDecl());
Chandler Carruth8d26bb02011-05-01 23:48:14 +00001494 OS << ")";
1495 }
John McCall351762c2011-02-07 10:33:21 +00001496}
1497
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001498void ASTDumper::VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001499 VisitExpr(Node);
John McCall76d09942009-12-11 21:50:11 +00001500 OS << " (";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001501 if (!Node->requiresADL())
1502 OS << "no ";
Benjamin Kramerb11416d2010-04-17 09:33:03 +00001503 OS << "ADL) = '" << Node->getName() << '\'';
John McCall76d09942009-12-11 21:50:11 +00001504
1505 UnresolvedLookupExpr::decls_iterator
1506 I = Node->decls_begin(), E = Node->decls_end();
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001507 if (I == E)
1508 OS << " empty";
John McCall76d09942009-12-11 21:50:11 +00001509 for (; I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001510 dumpPointer(*I);
John McCall76d09942009-12-11 21:50:11 +00001511}
1512
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001513void ASTDumper::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001514 VisitExpr(Node);
Steve Naroff5d5efca2008-03-12 13:19:12 +00001515
Richard Trieud215b8d2013-01-26 01:31:20 +00001516 {
1517 ColorScope Color(*this, DeclKindNameColor);
1518 OS << " " << Node->getDecl()->getDeclKindName() << "Decl";
1519 }
1520 OS << "='" << *Node->getDecl() << "'";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001521 dumpPointer(Node->getDecl());
Steve Naroffb3424a92008-05-23 22:01:24 +00001522 if (Node->isFreeIvar())
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001523 OS << " isFreeIvar";
Steve Naroff5d5efca2008-03-12 13:19:12 +00001524}
1525
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001526void ASTDumper::VisitPredefinedExpr(const PredefinedExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001527 VisitExpr(Node);
Alexey Bataevec474782014-10-09 08:45:04 +00001528 OS << " " << PredefinedExpr::getIdentTypeName(Node->getIdentType());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001529}
1530
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001531void ASTDumper::VisitCharacterLiteral(const CharacterLiteral *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001532 VisitExpr(Node);
Richard Trieud215b8d2013-01-26 01:31:20 +00001533 ColorScope Color(*this, ValueColor);
Richard Trieu364ee422011-11-03 23:56:23 +00001534 OS << " " << Node->getValue();
Chris Lattnercbe4f772007-08-08 22:51:59 +00001535}
1536
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001537void ASTDumper::VisitIntegerLiteral(const IntegerLiteral *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001538 VisitExpr(Node);
Chris Lattnercbe4f772007-08-08 22:51:59 +00001539
1540 bool isSigned = Node->getType()->isSignedIntegerType();
Richard Trieud215b8d2013-01-26 01:31:20 +00001541 ColorScope Color(*this, ValueColor);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001542 OS << " " << Node->getValue().toString(10, isSigned);
Chris Lattnercbe4f772007-08-08 22:51:59 +00001543}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001544
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001545void ASTDumper::VisitFloatingLiteral(const FloatingLiteral *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001546 VisitExpr(Node);
Richard Trieud215b8d2013-01-26 01:31:20 +00001547 ColorScope Color(*this, ValueColor);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001548 OS << " " << Node->getValueAsApproximateDouble();
Chris Lattnercbe4f772007-08-08 22:51:59 +00001549}
Chris Lattner1c20a172007-08-26 03:42:43 +00001550
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001551void ASTDumper::VisitStringLiteral(const StringLiteral *Str) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001552 VisitExpr(Str);
Richard Trieud215b8d2013-01-26 01:31:20 +00001553 ColorScope Color(*this, ValueColor);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001554 OS << " ";
Richard Trieudc355912012-06-13 20:25:24 +00001555 Str->outputString(OS);
Chris Lattnercbe4f772007-08-08 22:51:59 +00001556}
Chris Lattner84ca3762007-08-30 01:00:35 +00001557
Richard Smithf0514962014-06-03 08:24:28 +00001558void ASTDumper::VisitInitListExpr(const InitListExpr *ILE) {
1559 VisitExpr(ILE);
1560 if (auto *Filler = ILE->getArrayFiller()) {
Richard Smithf7514452014-10-30 21:02:37 +00001561 dumpChild([=] {
1562 OS << "array filler";
1563 dumpStmt(Filler);
1564 });
Richard Smithf0514962014-06-03 08:24:28 +00001565 }
1566 if (auto *Field = ILE->getInitializedFieldInUnion()) {
1567 OS << " field ";
1568 dumpBareDeclRef(Field);
1569 }
1570}
1571
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001572void ASTDumper::VisitUnaryOperator(const UnaryOperator *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001573 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001574 OS << " " << (Node->isPostfix() ? "postfix" : "prefix")
1575 << " '" << UnaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
Chris Lattnercbe4f772007-08-08 22:51:59 +00001576}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001577
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001578void ASTDumper::VisitUnaryExprOrTypeTraitExpr(
1579 const UnaryExprOrTypeTraitExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001580 VisitExpr(Node);
Peter Collingbournee190dee2011-03-11 19:24:49 +00001581 switch(Node->getKind()) {
1582 case UETT_SizeOf:
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001583 OS << " sizeof";
Peter Collingbournee190dee2011-03-11 19:24:49 +00001584 break;
1585 case UETT_AlignOf:
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001586 OS << " alignof";
Peter Collingbournee190dee2011-03-11 19:24:49 +00001587 break;
1588 case UETT_VecStep:
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001589 OS << " vec_step";
Peter Collingbournee190dee2011-03-11 19:24:49 +00001590 break;
1591 }
Sebastian Redl6f282892008-11-11 17:56:53 +00001592 if (Node->isArgumentType())
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001593 dumpType(Node->getArgumentType());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001594}
Chris Lattnerdb3b3ff2007-08-09 17:35:30 +00001595
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001596void ASTDumper::VisitMemberExpr(const MemberExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001597 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001598 OS << " " << (Node->isArrow() ? "->" : ".") << *Node->getMemberDecl();
1599 dumpPointer(Node->getMemberDecl());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001600}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001601
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001602void ASTDumper::VisitExtVectorElementExpr(const ExtVectorElementExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001603 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001604 OS << " " << Node->getAccessor().getNameStart();
Chris Lattnercbe4f772007-08-08 22:51:59 +00001605}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001606
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001607void ASTDumper::VisitBinaryOperator(const BinaryOperator *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001608 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001609 OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
Chris Lattner86928112007-08-25 02:00:02 +00001610}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001611
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001612void ASTDumper::VisitCompoundAssignOperator(
1613 const CompoundAssignOperator *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001614 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001615 OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode())
1616 << "' ComputeLHSTy=";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001617 dumpBareType(Node->getComputationLHSType());
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001618 OS << " ComputeResultTy=";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001619 dumpBareType(Node->getComputationResultType());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001620}
Chris Lattnercbe4f772007-08-08 22:51:59 +00001621
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001622void ASTDumper::VisitBlockExpr(const BlockExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001623 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001624 dumpDecl(Node->getBlockDecl());
John McCall351762c2011-02-07 10:33:21 +00001625}
1626
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001627void ASTDumper::VisitOpaqueValueExpr(const OpaqueValueExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001628 VisitExpr(Node);
John McCallfe96e0b2011-11-06 09:01:30 +00001629
Richard Smithf7514452014-10-30 21:02:37 +00001630 if (Expr *Source = Node->getSourceExpr())
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001631 dumpStmt(Source);
John McCallfe96e0b2011-11-06 09:01:30 +00001632}
1633
Chris Lattnercbe4f772007-08-08 22:51:59 +00001634// GNU extensions.
1635
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001636void ASTDumper::VisitAddrLabelExpr(const AddrLabelExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001637 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001638 OS << " " << Node->getLabel()->getName();
1639 dumpPointer(Node->getLabel());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001640}
1641
Chris Lattner8f184b12007-08-09 18:03:18 +00001642//===----------------------------------------------------------------------===//
1643// C++ Expressions
1644//===----------------------------------------------------------------------===//
Chris Lattnercbe4f772007-08-08 22:51:59 +00001645
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001646void ASTDumper::VisitCXXNamedCastExpr(const CXXNamedCastExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001647 VisitExpr(Node);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001648 OS << " " << Node->getCastName()
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001649 << "<" << Node->getTypeAsWritten().getAsString() << ">"
Anders Carlssona70cff62010-04-24 19:06:50 +00001650 << " <" << Node->getCastKindName();
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001651 dumpBasePath(OS, Node);
Anders Carlssona70cff62010-04-24 19:06:50 +00001652 OS << ">";
Chris Lattnercbe4f772007-08-08 22:51:59 +00001653}
1654
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001655void ASTDumper::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001656 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001657 OS << " " << (Node->getValue() ? "true" : "false");
Chris Lattnercbe4f772007-08-08 22:51:59 +00001658}
1659
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001660void ASTDumper::VisitCXXThisExpr(const CXXThisExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001661 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001662 OS << " this";
Douglas Gregor8ea1f532008-11-04 14:56:14 +00001663}
1664
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001665void ASTDumper::VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001666 VisitExpr(Node);
Eli Friedman29538892011-09-02 17:38:59 +00001667 OS << " functional cast to " << Node->getTypeAsWritten().getAsString()
1668 << " <" << Node->getCastKindName() << ">";
Douglas Gregore200adc2008-10-27 19:41:14 +00001669}
1670
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001671void ASTDumper::VisitCXXConstructExpr(const CXXConstructExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001672 VisitExpr(Node);
John McCalleba90cd2010-02-02 19:03:45 +00001673 CXXConstructorDecl *Ctor = Node->getConstructor();
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001674 dumpType(Ctor->getType());
Anders Carlsson073846832009-08-12 00:21:52 +00001675 if (Node->isElidable())
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001676 OS << " elidable";
John McCall85370042010-08-07 06:38:55 +00001677 if (Node->requiresZeroInitialization())
1678 OS << " zeroing";
Anders Carlsson073846832009-08-12 00:21:52 +00001679}
1680
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001681void ASTDumper::VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001682 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001683 OS << " ";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001684 dumpCXXTemporary(Node->getTemporary());
Anders Carlsson073846832009-08-12 00:21:52 +00001685}
1686
Richard Smithe6c01442013-06-05 00:46:14 +00001687void
1688ASTDumper::VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *Node) {
1689 VisitExpr(Node);
1690 if (const ValueDecl *VD = Node->getExtendingDecl()) {
1691 OS << " extended by ";
1692 dumpBareDeclRef(VD);
1693 }
1694}
1695
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001696void ASTDumper::VisitExprWithCleanups(const ExprWithCleanups *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001697 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001698 for (unsigned i = 0, e = Node->getNumObjects(); i != e; ++i)
1699 dumpDeclRef(Node->getObject(i), "cleanup");
Anders Carlsson073846832009-08-12 00:21:52 +00001700}
1701
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001702void ASTDumper::dumpCXXTemporary(const CXXTemporary *Temporary) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001703 OS << "(CXXTemporary";
1704 dumpPointer(Temporary);
1705 OS << ")";
Anders Carlsson073846832009-08-12 00:21:52 +00001706}
1707
Anders Carlsson76f4a902007-08-21 17:43:55 +00001708//===----------------------------------------------------------------------===//
1709// Obj-C Expressions
1710//===----------------------------------------------------------------------===//
1711
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001712void ASTDumper::VisitObjCMessageExpr(const ObjCMessageExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001713 VisitExpr(Node);
Aaron Ballmanb190f972014-01-03 17:59:55 +00001714 OS << " selector=";
1715 Node->getSelector().print(OS);
Douglas Gregor9a129192010-04-21 00:45:42 +00001716 switch (Node->getReceiverKind()) {
1717 case ObjCMessageExpr::Instance:
1718 break;
1719
1720 case ObjCMessageExpr::Class:
1721 OS << " class=";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001722 dumpBareType(Node->getClassReceiver());
Douglas Gregor9a129192010-04-21 00:45:42 +00001723 break;
1724
1725 case ObjCMessageExpr::SuperInstance:
1726 OS << " super (instance)";
1727 break;
1728
1729 case ObjCMessageExpr::SuperClass:
1730 OS << " super (class)";
1731 break;
1732 }
Ted Kremenek36748da2008-02-29 22:04:05 +00001733}
1734
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001735void ASTDumper::VisitObjCBoxedExpr(const ObjCBoxedExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001736 VisitExpr(Node);
Aaron Ballmanb190f972014-01-03 17:59:55 +00001737 OS << " selector=";
1738 Node->getBoxingMethod()->getSelector().print(OS);
Argyrios Kyrtzidis9dd40892012-05-10 20:02:31 +00001739}
1740
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001741void ASTDumper::VisitObjCAtCatchStmt(const ObjCAtCatchStmt *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001742 VisitStmt(Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001743 if (const VarDecl *CatchParam = Node->getCatchParamDecl())
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001744 dumpDecl(CatchParam);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001745 else
Douglas Gregor96c79492010-04-23 22:50:49 +00001746 OS << " catch all";
Douglas Gregor96c79492010-04-23 22:50:49 +00001747}
1748
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001749void ASTDumper::VisitObjCEncodeExpr(const ObjCEncodeExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001750 VisitExpr(Node);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001751 dumpType(Node->getEncodedType());
Anders Carlssonc5a81eb2007-08-22 15:14:15 +00001752}
1753
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001754void ASTDumper::VisitObjCSelectorExpr(const ObjCSelectorExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001755 VisitExpr(Node);
Mike Stump11289f42009-09-09 15:08:12 +00001756
Aaron Ballmanb190f972014-01-03 17:59:55 +00001757 OS << " ";
1758 Node->getSelector().print(OS);
Fariborz Jahanian4bef4622007-10-16 20:40:23 +00001759}
1760
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001761void ASTDumper::VisitObjCProtocolExpr(const ObjCProtocolExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001762 VisitExpr(Node);
Mike Stump11289f42009-09-09 15:08:12 +00001763
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001764 OS << ' ' << *Node->getProtocol();
Fariborz Jahaniana32aaef2007-10-17 16:58:11 +00001765}
Daniel Dunbar4b8c6db2008-08-30 05:35:15 +00001766
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001767void ASTDumper::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001768 VisitExpr(Node);
John McCallb7bd14f2010-12-02 01:19:52 +00001769 if (Node->isImplicitProperty()) {
Fariborz Jahanian0f0b3022010-12-22 19:46:35 +00001770 OS << " Kind=MethodRef Getter=\"";
1771 if (Node->getImplicitPropertyGetter())
Aaron Ballmanb190f972014-01-03 17:59:55 +00001772 Node->getImplicitPropertyGetter()->getSelector().print(OS);
Fariborz Jahanian0f0b3022010-12-22 19:46:35 +00001773 else
1774 OS << "(null)";
1775
1776 OS << "\" Setter=\"";
John McCallb7bd14f2010-12-02 01:19:52 +00001777 if (ObjCMethodDecl *Setter = Node->getImplicitPropertySetter())
Aaron Ballmanb190f972014-01-03 17:59:55 +00001778 Setter->getSelector().print(OS);
John McCallb7bd14f2010-12-02 01:19:52 +00001779 else
1780 OS << "(null)";
1781 OS << "\"";
1782 } else {
Benjamin Kramerb89514a2011-10-14 18:45:37 +00001783 OS << " Kind=PropertyRef Property=\"" << *Node->getExplicitProperty() <<'"';
John McCallb7bd14f2010-12-02 01:19:52 +00001784 }
Fariborz Jahanian8a1810f2008-11-22 18:39:36 +00001785
Fariborz Jahanian681c0752010-10-14 16:04:05 +00001786 if (Node->isSuperReceiver())
1787 OS << " super";
Argyrios Kyrtzidisab468b02012-03-30 00:19:18 +00001788
1789 OS << " Messaging=";
1790 if (Node->isMessagingGetter() && Node->isMessagingSetter())
1791 OS << "Getter&Setter";
1792 else if (Node->isMessagingGetter())
1793 OS << "Getter";
1794 else if (Node->isMessagingSetter())
1795 OS << "Setter";
Douglas Gregor8ea1f532008-11-04 14:56:14 +00001796}
1797
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001798void ASTDumper::VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001799 VisitExpr(Node);
Ted Kremeneke65b0862012-03-06 20:05:56 +00001800 if (Node->isArraySubscriptRefExpr())
1801 OS << " Kind=ArraySubscript GetterForArray=\"";
1802 else
1803 OS << " Kind=DictionarySubscript GetterForDictionary=\"";
1804 if (Node->getAtIndexMethodDecl())
Aaron Ballmanb190f972014-01-03 17:59:55 +00001805 Node->getAtIndexMethodDecl()->getSelector().print(OS);
Ted Kremeneke65b0862012-03-06 20:05:56 +00001806 else
1807 OS << "(null)";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001808
Ted Kremeneke65b0862012-03-06 20:05:56 +00001809 if (Node->isArraySubscriptRefExpr())
1810 OS << "\" SetterForArray=\"";
1811 else
1812 OS << "\" SetterForDictionary=\"";
1813 if (Node->setAtIndexMethodDecl())
Aaron Ballmanb190f972014-01-03 17:59:55 +00001814 Node->setAtIndexMethodDecl()->getSelector().print(OS);
Ted Kremeneke65b0862012-03-06 20:05:56 +00001815 else
1816 OS << "(null)";
1817}
1818
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001819void ASTDumper::VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001820 VisitExpr(Node);
Ted Kremeneke65b0862012-03-06 20:05:56 +00001821 OS << " " << (Node->getValue() ? "__objc_yes" : "__objc_no");
1822}
1823
Chris Lattnercbe4f772007-08-08 22:51:59 +00001824//===----------------------------------------------------------------------===//
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00001825// Comments
1826//===----------------------------------------------------------------------===//
1827
1828const char *ASTDumper::getCommandName(unsigned CommandID) {
1829 if (Traits)
1830 return Traits->getCommandInfo(CommandID)->Name;
1831 const CommandInfo *Info = CommandTraits::getBuiltinCommandInfo(CommandID);
1832 if (Info)
1833 return Info->Name;
1834 return "<not a builtin command>";
1835}
1836
1837void ASTDumper::dumpFullComment(const FullComment *C) {
1838 if (!C)
1839 return;
1840
1841 FC = C;
1842 dumpComment(C);
Craig Topper36250ad2014-05-12 05:36:57 +00001843 FC = nullptr;
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00001844}
1845
1846void ASTDumper::dumpComment(const Comment *C) {
Richard Smithf7514452014-10-30 21:02:37 +00001847 dumpChild([=] {
1848 if (!C) {
1849 ColorScope Color(*this, NullColor);
1850 OS << "<<<NULL>>>";
1851 return;
1852 }
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00001853
Richard Smithf7514452014-10-30 21:02:37 +00001854 {
1855 ColorScope Color(*this, CommentColor);
1856 OS << C->getCommentKindName();
1857 }
1858 dumpPointer(C);
1859 dumpSourceRange(C->getSourceRange());
1860 ConstCommentVisitor<ASTDumper>::visit(C);
1861 for (Comment::child_iterator I = C->child_begin(), E = C->child_end();
1862 I != E; ++I)
1863 dumpComment(*I);
1864 });
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00001865}
1866
1867void ASTDumper::visitTextComment(const TextComment *C) {
1868 OS << " Text=\"" << C->getText() << "\"";
1869}
1870
1871void ASTDumper::visitInlineCommandComment(const InlineCommandComment *C) {
1872 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\"";
1873 switch (C->getRenderKind()) {
1874 case InlineCommandComment::RenderNormal:
1875 OS << " RenderNormal";
1876 break;
1877 case InlineCommandComment::RenderBold:
1878 OS << " RenderBold";
1879 break;
1880 case InlineCommandComment::RenderMonospaced:
1881 OS << " RenderMonospaced";
1882 break;
1883 case InlineCommandComment::RenderEmphasized:
1884 OS << " RenderEmphasized";
1885 break;
1886 }
1887
1888 for (unsigned i = 0, e = C->getNumArgs(); i != e; ++i)
1889 OS << " Arg[" << i << "]=\"" << C->getArgText(i) << "\"";
1890}
1891
1892void ASTDumper::visitHTMLStartTagComment(const HTMLStartTagComment *C) {
1893 OS << " Name=\"" << C->getTagName() << "\"";
1894 if (C->getNumAttrs() != 0) {
1895 OS << " Attrs: ";
1896 for (unsigned i = 0, e = C->getNumAttrs(); i != e; ++i) {
1897 const HTMLStartTagComment::Attribute &Attr = C->getAttr(i);
1898 OS << " \"" << Attr.Name << "=\"" << Attr.Value << "\"";
1899 }
1900 }
1901 if (C->isSelfClosing())
1902 OS << " SelfClosing";
1903}
1904
1905void ASTDumper::visitHTMLEndTagComment(const HTMLEndTagComment *C) {
1906 OS << " Name=\"" << C->getTagName() << "\"";
1907}
1908
1909void ASTDumper::visitBlockCommandComment(const BlockCommandComment *C) {
1910 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\"";
1911 for (unsigned i = 0, e = C->getNumArgs(); i != e; ++i)
1912 OS << " Arg[" << i << "]=\"" << C->getArgText(i) << "\"";
1913}
1914
1915void ASTDumper::visitParamCommandComment(const ParamCommandComment *C) {
1916 OS << " " << ParamCommandComment::getDirectionAsString(C->getDirection());
1917
1918 if (C->isDirectionExplicit())
1919 OS << " explicitly";
1920 else
1921 OS << " implicitly";
1922
1923 if (C->hasParamName()) {
1924 if (C->isParamIndexValid())
1925 OS << " Param=\"" << C->getParamName(FC) << "\"";
1926 else
1927 OS << " Param=\"" << C->getParamNameAsWritten() << "\"";
1928 }
1929
Dmitri Gribenkodbff5c72014-03-19 14:03:47 +00001930 if (C->isParamIndexValid() && !C->isVarArgParam())
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00001931 OS << " ParamIndex=" << C->getParamIndex();
1932}
1933
1934void ASTDumper::visitTParamCommandComment(const TParamCommandComment *C) {
1935 if (C->hasParamName()) {
1936 if (C->isPositionValid())
1937 OS << " Param=\"" << C->getParamName(FC) << "\"";
1938 else
1939 OS << " Param=\"" << C->getParamNameAsWritten() << "\"";
1940 }
1941
1942 if (C->isPositionValid()) {
1943 OS << " Position=<";
1944 for (unsigned i = 0, e = C->getDepth(); i != e; ++i) {
1945 OS << C->getIndex(i);
1946 if (i != e - 1)
1947 OS << ", ";
1948 }
1949 OS << ">";
1950 }
1951}
1952
1953void ASTDumper::visitVerbatimBlockComment(const VerbatimBlockComment *C) {
1954 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\""
1955 " CloseName=\"" << C->getCloseName() << "\"";
1956}
1957
1958void ASTDumper::visitVerbatimBlockLineComment(
1959 const VerbatimBlockLineComment *C) {
1960 OS << " Text=\"" << C->getText() << "\"";
1961}
1962
1963void ASTDumper::visitVerbatimLineComment(const VerbatimLineComment *C) {
1964 OS << " Text=\"" << C->getText() << "\"";
1965}
1966
1967//===----------------------------------------------------------------------===//
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001968// Decl method implementations
1969//===----------------------------------------------------------------------===//
1970
Alp Tokeref6b0072014-01-04 13:47:14 +00001971LLVM_DUMP_METHOD void Decl::dump() const { dump(llvm::errs()); }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001972
Alp Tokeref6b0072014-01-04 13:47:14 +00001973LLVM_DUMP_METHOD void Decl::dump(raw_ostream &OS) const {
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00001974 ASTDumper P(OS, &getASTContext().getCommentCommandTraits(),
1975 &getASTContext().getSourceManager());
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001976 P.dumpDecl(this);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001977}
1978
Alp Tokeref6b0072014-01-04 13:47:14 +00001979LLVM_DUMP_METHOD void Decl::dumpColor() const {
Richard Trieud215b8d2013-01-26 01:31:20 +00001980 ASTDumper P(llvm::errs(), &getASTContext().getCommentCommandTraits(),
1981 &getASTContext().getSourceManager(), /*ShowColors*/true);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001982 P.dumpDecl(this);
Richard Trieud215b8d2013-01-26 01:31:20 +00001983}
Richard Smith33937e72013-06-22 21:49:40 +00001984
Alp Tokeref6b0072014-01-04 13:47:14 +00001985LLVM_DUMP_METHOD void DeclContext::dumpLookups() const {
Richard Smith6ea05822013-06-24 01:45:33 +00001986 dumpLookups(llvm::errs());
1987}
1988
Richard Smith35f986d2014-08-11 22:11:07 +00001989LLVM_DUMP_METHOD void DeclContext::dumpLookups(raw_ostream &OS,
1990 bool DumpDecls) const {
Richard Smith33937e72013-06-22 21:49:40 +00001991 const DeclContext *DC = this;
1992 while (!DC->isTranslationUnit())
1993 DC = DC->getParent();
1994 ASTContext &Ctx = cast<TranslationUnitDecl>(DC)->getASTContext();
Richard Smith6ea05822013-06-24 01:45:33 +00001995 ASTDumper P(OS, &Ctx.getCommentCommandTraits(), &Ctx.getSourceManager());
Richard Smith35f986d2014-08-11 22:11:07 +00001996 P.dumpLookups(this, DumpDecls);
Richard Smith33937e72013-06-22 21:49:40 +00001997}
1998
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001999//===----------------------------------------------------------------------===//
Chris Lattnercbe4f772007-08-08 22:51:59 +00002000// Stmt method implementations
2001//===----------------------------------------------------------------------===//
2002
Alp Tokeref6b0072014-01-04 13:47:14 +00002003LLVM_DUMP_METHOD void Stmt::dump(SourceManager &SM) const {
Argyrios Kyrtzidisc049f752010-08-09 10:54:31 +00002004 dump(llvm::errs(), SM);
2005}
2006
Alp Tokeref6b0072014-01-04 13:47:14 +00002007LLVM_DUMP_METHOD void Stmt::dump(raw_ostream &OS, SourceManager &SM) const {
Craig Topper36250ad2014-05-12 05:36:57 +00002008 ASTDumper P(OS, nullptr, &SM);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002009 P.dumpStmt(this);
Chris Lattner779d5d92007-08-30 00:40:08 +00002010}
2011
Alp Tokeref6b0072014-01-04 13:47:14 +00002012LLVM_DUMP_METHOD void Stmt::dump() const {
Craig Topper36250ad2014-05-12 05:36:57 +00002013 ASTDumper P(llvm::errs(), nullptr, nullptr);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002014 P.dumpStmt(this);
Chris Lattnercbe4f772007-08-08 22:51:59 +00002015}
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002016
Alp Tokeref6b0072014-01-04 13:47:14 +00002017LLVM_DUMP_METHOD void Stmt::dumpColor() const {
Craig Topper36250ad2014-05-12 05:36:57 +00002018 ASTDumper P(llvm::errs(), nullptr, nullptr, /*ShowColors*/true);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002019 P.dumpStmt(this);
Richard Trieud215b8d2013-01-26 01:31:20 +00002020}
2021
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002022//===----------------------------------------------------------------------===//
2023// Comment method implementations
2024//===----------------------------------------------------------------------===//
2025
Craig Topper36250ad2014-05-12 05:36:57 +00002026LLVM_DUMP_METHOD void Comment::dump() const {
2027 dump(llvm::errs(), nullptr, nullptr);
2028}
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002029
Alp Tokeref6b0072014-01-04 13:47:14 +00002030LLVM_DUMP_METHOD void Comment::dump(const ASTContext &Context) const {
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002031 dump(llvm::errs(), &Context.getCommentCommandTraits(),
2032 &Context.getSourceManager());
2033}
2034
Alexander Kornienko00911f12013-01-15 12:20:21 +00002035void Comment::dump(raw_ostream &OS, const CommandTraits *Traits,
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002036 const SourceManager *SM) const {
2037 const FullComment *FC = dyn_cast<FullComment>(this);
2038 ASTDumper D(OS, Traits, SM);
2039 D.dumpFullComment(FC);
2040}
Richard Trieud215b8d2013-01-26 01:31:20 +00002041
Alp Tokeref6b0072014-01-04 13:47:14 +00002042LLVM_DUMP_METHOD void Comment::dumpColor() const {
Richard Trieud215b8d2013-01-26 01:31:20 +00002043 const FullComment *FC = dyn_cast<FullComment>(this);
Craig Topper36250ad2014-05-12 05:36:57 +00002044 ASTDumper D(llvm::errs(), nullptr, nullptr, /*ShowColors*/true);
Richard Trieud215b8d2013-01-26 01:31:20 +00002045 D.dumpFullComment(FC);
2046}