blob: d5e5372f01fd3b9f8bc54c1f9e558423436f93ca [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"
Richard Smithd5e7ff82014-10-31 01:17:45 +000023#include "clang/AST/TypeVisitor.h"
David Majnemerd9b1a4f2015-11-04 03:40:30 +000024#include "clang/Basic/Builtins.h"
Alexander Kornienko90ff6072012-12-20 02:09:13 +000025#include "clang/Basic/Module.h"
Chris Lattner11e30d32007-08-30 06:17:34 +000026#include "clang/Basic/SourceManager.h"
Daniel Dunbar34a96c82009-12-03 09:13:13 +000027#include "llvm/Support/raw_ostream.h"
Chris Lattnercbe4f772007-08-08 22:51:59 +000028using namespace clang;
Alexander Kornienkoebc17b52013-01-14 14:07:11 +000029using namespace clang::comments;
Chris Lattnercbe4f772007-08-08 22:51:59 +000030
31//===----------------------------------------------------------------------===//
Alexander Kornienko18ec81b2012-12-13 13:59:55 +000032// ASTDumper Visitor
Chris Lattnercbe4f772007-08-08 22:51:59 +000033//===----------------------------------------------------------------------===//
34
35namespace {
Richard Trieud215b8d2013-01-26 01:31:20 +000036 // Colors used for various parts of the AST dump
Richard Trieu532018f2014-03-06 01:09:03 +000037 // Do not use bold yellow for any text. It is hard to read on white screens.
Richard Trieud215b8d2013-01-26 01:31:20 +000038
39 struct TerminalColor {
40 raw_ostream::Colors Color;
41 bool Bold;
42 };
43
Richard Trieu532018f2014-03-06 01:09:03 +000044 // Red - CastColor
45 // Green - TypeColor
46 // Bold Green - DeclKindNameColor, UndeserializedColor
47 // Yellow - AddressColor, LocationColor
48 // Blue - CommentColor, NullColor, IndentColor
49 // Bold Blue - AttrColor
50 // Bold Magenta - StmtColor
51 // Cyan - ValueKindColor, ObjectKindColor
52 // Bold Cyan - ValueColor, DeclNameColor
53
Richard Trieud215b8d2013-01-26 01:31:20 +000054 // Decl kind names (VarDecl, FunctionDecl, etc)
55 static const TerminalColor DeclKindNameColor = { raw_ostream::GREEN, true };
56 // Attr names (CleanupAttr, GuardedByAttr, etc)
57 static const TerminalColor AttrColor = { raw_ostream::BLUE, true };
58 // Statement names (DeclStmt, ImplicitCastExpr, etc)
59 static const TerminalColor StmtColor = { raw_ostream::MAGENTA, true };
60 // Comment names (FullComment, ParagraphComment, TextComment, etc)
Richard Trieu532018f2014-03-06 01:09:03 +000061 static const TerminalColor CommentColor = { raw_ostream::BLUE, false };
Richard Trieud215b8d2013-01-26 01:31:20 +000062
63 // Type names (int, float, etc, plus user defined types)
64 static const TerminalColor TypeColor = { raw_ostream::GREEN, false };
65
66 // Pointer address
67 static const TerminalColor AddressColor = { raw_ostream::YELLOW, false };
68 // Source locations
69 static const TerminalColor LocationColor = { raw_ostream::YELLOW, false };
70
71 // lvalue/xvalue
72 static const TerminalColor ValueKindColor = { raw_ostream::CYAN, false };
73 // bitfield/objcproperty/objcsubscript/vectorcomponent
74 static const TerminalColor ObjectKindColor = { raw_ostream::CYAN, false };
75
76 // Null statements
77 static const TerminalColor NullColor = { raw_ostream::BLUE, false };
78
Richard Smith1d209d02013-05-23 01:49:11 +000079 // Undeserialized entities
80 static const TerminalColor UndeserializedColor = { raw_ostream::GREEN, true };
81
Richard Trieud215b8d2013-01-26 01:31:20 +000082 // CastKind from CastExpr's
83 static const TerminalColor CastColor = { raw_ostream::RED, false };
84
85 // Value of the statement
86 static const TerminalColor ValueColor = { raw_ostream::CYAN, true };
87 // Decl names
88 static const TerminalColor DeclNameColor = { raw_ostream::CYAN, true };
89
Richard Trieude5cc7d2013-01-31 01:44:26 +000090 // Indents ( `, -. | )
91 static const TerminalColor IndentColor = { raw_ostream::BLUE, false };
92
Alexander Kornienko90ff6072012-12-20 02:09:13 +000093 class ASTDumper
Alexander Kornienko540bacb2013-02-01 12:35:51 +000094 : public ConstDeclVisitor<ASTDumper>, public ConstStmtVisitor<ASTDumper>,
Richard Smithd5e7ff82014-10-31 01:17:45 +000095 public ConstCommentVisitor<ASTDumper>, public TypeVisitor<ASTDumper> {
Chris Lattner0e62c1c2011-07-23 10:55:15 +000096 raw_ostream &OS;
Alexander Kornienkoebc17b52013-01-14 14:07:11 +000097 const CommandTraits *Traits;
98 const SourceManager *SM;
Mike Stump11289f42009-09-09 15:08:12 +000099
Richard Smithf7514452014-10-30 21:02:37 +0000100 /// Pending[i] is an action to dump an entity at level i.
101 llvm::SmallVector<std::function<void(bool isLastChild)>, 32> Pending;
Richard Trieude5cc7d2013-01-31 01:44:26 +0000102
Richard Smithf7514452014-10-30 21:02:37 +0000103 /// Indicates whether we're at the top level.
104 bool TopLevel;
Richard Trieude5cc7d2013-01-31 01:44:26 +0000105
Richard Smithf7514452014-10-30 21:02:37 +0000106 /// Indicates if we're handling the first child after entering a new depth.
107 bool FirstChild;
108
109 /// Prefix for currently-being-dumped entity.
110 std::string Prefix;
Richard Trieude5cc7d2013-01-31 01:44:26 +0000111
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000112 /// Keep track of the last location we print out so that we can
113 /// print out deltas from then on out.
Chris Lattner11e30d32007-08-30 06:17:34 +0000114 const char *LastLocFilename;
115 unsigned LastLocLine;
Douglas Gregor7de59662009-05-29 20:38:28 +0000116
Alexander Kornienkoebc17b52013-01-14 14:07:11 +0000117 /// The \c FullComment parent of the comment being dumped.
118 const FullComment *FC;
119
Richard Trieud215b8d2013-01-26 01:31:20 +0000120 bool ShowColors;
121
Richard Smithf7514452014-10-30 21:02:37 +0000122 /// Dump a child of the current node.
123 template<typename Fn> void dumpChild(Fn doDumpChild) {
124 // If we're at the top level, there's nothing interesting to do; just
125 // run the dumper.
126 if (TopLevel) {
127 TopLevel = false;
128 doDumpChild();
129 while (!Pending.empty()) {
130 Pending.back()(true);
131 Pending.pop_back();
132 }
133 Prefix.clear();
134 OS << "\n";
135 TopLevel = true;
136 return;
Manuel Klimek874030e2012-11-07 00:33:12 +0000137 }
Richard Smithf7514452014-10-30 21:02:37 +0000138
139 const FullComment *OrigFC = FC;
140 auto dumpWithIndent = [this, doDumpChild, OrigFC](bool isLastChild) {
141 // Print out the appropriate tree structure and work out the prefix for
142 // children of this node. For instance:
143 //
144 // A Prefix = ""
145 // |-B Prefix = "| "
146 // | `-C Prefix = "| "
147 // `-D Prefix = " "
148 // |-E Prefix = " | "
149 // `-F Prefix = " "
150 // G Prefix = ""
151 //
152 // Note that the first level gets no prefix.
153 {
154 OS << '\n';
155 ColorScope Color(*this, IndentColor);
156 OS << Prefix << (isLastChild ? '`' : '|') << '-';
NAKAMURA Takumic73e4022014-10-31 00:30:37 +0000157 this->Prefix.push_back(isLastChild ? ' ' : '|');
158 this->Prefix.push_back(' ');
Richard Smithf7514452014-10-30 21:02:37 +0000159 }
160
161 FirstChild = true;
162 unsigned Depth = Pending.size();
163
164 FC = OrigFC;
165 doDumpChild();
166
167 // If any children are left, they're the last at their nesting level.
168 // Dump those ones out now.
169 while (Depth < Pending.size()) {
170 Pending.back()(true);
NAKAMURA Takumic73e4022014-10-31 00:30:37 +0000171 this->Pending.pop_back();
Richard Smithf7514452014-10-30 21:02:37 +0000172 }
173
174 // Restore the old prefix.
NAKAMURA Takumic73e4022014-10-31 00:30:37 +0000175 this->Prefix.resize(Prefix.size() - 2);
Richard Smithf7514452014-10-30 21:02:37 +0000176 };
177
178 if (FirstChild) {
179 Pending.push_back(std::move(dumpWithIndent));
180 } else {
181 Pending.back()(false);
182 Pending.back() = std::move(dumpWithIndent);
Manuel Klimek874030e2012-11-07 00:33:12 +0000183 }
Richard Smithf7514452014-10-30 21:02:37 +0000184 FirstChild = false;
185 }
Manuel Klimek874030e2012-11-07 00:33:12 +0000186
Richard Trieud215b8d2013-01-26 01:31:20 +0000187 class ColorScope {
188 ASTDumper &Dumper;
189 public:
190 ColorScope(ASTDumper &Dumper, TerminalColor Color)
191 : Dumper(Dumper) {
192 if (Dumper.ShowColors)
193 Dumper.OS.changeColor(Color.Color, Color.Bold);
194 }
195 ~ColorScope() {
196 if (Dumper.ShowColors)
197 Dumper.OS.resetColor();
198 }
199 };
200
Chris Lattnercbe4f772007-08-08 22:51:59 +0000201 public:
Alexander Kornienkoebc17b52013-01-14 14:07:11 +0000202 ASTDumper(raw_ostream &OS, const CommandTraits *Traits,
203 const SourceManager *SM)
Richard Smithf7514452014-10-30 21:02:37 +0000204 : OS(OS), Traits(Traits), SM(SM), TopLevel(true), FirstChild(true),
Craig Topper36250ad2014-05-12 05:36:57 +0000205 LastLocFilename(""), LastLocLine(~0U), FC(nullptr),
Richard Trieud215b8d2013-01-26 01:31:20 +0000206 ShowColors(SM && SM->getDiagnostics().getShowColors()) { }
207
208 ASTDumper(raw_ostream &OS, const CommandTraits *Traits,
209 const SourceManager *SM, bool ShowColors)
Richard Smithf7514452014-10-30 21:02:37 +0000210 : OS(OS), Traits(Traits), SM(SM), TopLevel(true), FirstChild(true),
Richard Smith56d12152013-01-31 02:04:38 +0000211 LastLocFilename(""), LastLocLine(~0U),
Richard Trieude5cc7d2013-01-31 01:44:26 +0000212 ShowColors(ShowColors) { }
Mike Stump11289f42009-09-09 15:08:12 +0000213
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000214 void dumpDecl(const Decl *D);
215 void dumpStmt(const Stmt *S);
Alexander Kornienkoebc17b52013-01-14 14:07:11 +0000216 void dumpFullComment(const FullComment *C);
Mike Stump11289f42009-09-09 15:08:12 +0000217
Richard Trieude5cc7d2013-01-31 01:44:26 +0000218 // Utilities
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000219 void dumpPointer(const void *Ptr);
220 void dumpSourceRange(SourceRange R);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000221 void dumpLocation(SourceLocation Loc);
Richard Smithd5e7ff82014-10-31 01:17:45 +0000222 void dumpBareType(QualType T, bool Desugar = true);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000223 void dumpType(QualType T);
Richard Smithd5e7ff82014-10-31 01:17:45 +0000224 void dumpTypeAsChild(QualType T);
225 void dumpTypeAsChild(const Type *T);
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000226 void dumpBareDeclRef(const Decl *Node);
Craig Topper36250ad2014-05-12 05:36:57 +0000227 void dumpDeclRef(const Decl *Node, const char *Label = nullptr);
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000228 void dumpName(const NamedDecl *D);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000229 bool hasNodes(const DeclContext *DC);
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000230 void dumpDeclContext(const DeclContext *DC);
Richard Smith35f986d2014-08-11 22:11:07 +0000231 void dumpLookups(const DeclContext *DC, bool DumpDecls);
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000232 void dumpAttr(const Attr *A);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000233
234 // C++ Utilities
235 void dumpAccessSpecifier(AccessSpecifier AS);
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000236 void dumpCXXCtorInitializer(const CXXCtorInitializer *Init);
237 void dumpTemplateParameters(const TemplateParameterList *TPL);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000238 void dumpTemplateArgumentListInfo(const TemplateArgumentListInfo &TALI);
239 void dumpTemplateArgumentLoc(const TemplateArgumentLoc &A);
240 void dumpTemplateArgumentList(const TemplateArgumentList &TAL);
241 void dumpTemplateArgument(const TemplateArgument &A,
242 SourceRange R = SourceRange());
243
Douglas Gregor85f3f952015-07-07 03:57:15 +0000244 // Objective-C utilities.
245 void dumpObjCTypeParamList(const ObjCTypeParamList *typeParams);
246
Richard Smithd5e7ff82014-10-31 01:17:45 +0000247 // Types
248 void VisitComplexType(const ComplexType *T) {
249 dumpTypeAsChild(T->getElementType());
250 }
251 void VisitPointerType(const PointerType *T) {
252 dumpTypeAsChild(T->getPointeeType());
253 }
254 void VisitBlockPointerType(const BlockPointerType *T) {
255 dumpTypeAsChild(T->getPointeeType());
256 }
257 void VisitReferenceType(const ReferenceType *T) {
258 dumpTypeAsChild(T->getPointeeType());
259 }
260 void VisitRValueReferenceType(const ReferenceType *T) {
261 if (T->isSpelledAsLValue())
262 OS << " written as lvalue reference";
263 VisitReferenceType(T);
264 }
265 void VisitMemberPointerType(const MemberPointerType *T) {
266 dumpTypeAsChild(T->getClass());
267 dumpTypeAsChild(T->getPointeeType());
268 }
269 void VisitArrayType(const ArrayType *T) {
270 switch (T->getSizeModifier()) {
271 case ArrayType::Normal: break;
272 case ArrayType::Static: OS << " static"; break;
273 case ArrayType::Star: OS << " *"; break;
274 }
275 OS << " " << T->getIndexTypeQualifiers().getAsString();
276 dumpTypeAsChild(T->getElementType());
277 }
278 void VisitConstantArrayType(const ConstantArrayType *T) {
279 OS << " " << T->getSize();
280 VisitArrayType(T);
281 }
282 void VisitVariableArrayType(const VariableArrayType *T) {
283 OS << " ";
284 dumpSourceRange(T->getBracketsRange());
285 VisitArrayType(T);
286 dumpStmt(T->getSizeExpr());
287 }
288 void VisitDependentSizedArrayType(const DependentSizedArrayType *T) {
289 VisitArrayType(T);
290 OS << " ";
291 dumpSourceRange(T->getBracketsRange());
292 dumpStmt(T->getSizeExpr());
293 }
294 void VisitDependentSizedExtVectorType(
295 const DependentSizedExtVectorType *T) {
296 OS << " ";
297 dumpLocation(T->getAttributeLoc());
298 dumpTypeAsChild(T->getElementType());
299 dumpStmt(T->getSizeExpr());
300 }
301 void VisitVectorType(const VectorType *T) {
302 switch (T->getVectorKind()) {
303 case VectorType::GenericVector: break;
304 case VectorType::AltiVecVector: OS << " altivec"; break;
305 case VectorType::AltiVecPixel: OS << " altivec pixel"; break;
306 case VectorType::AltiVecBool: OS << " altivec bool"; break;
307 case VectorType::NeonVector: OS << " neon"; break;
308 case VectorType::NeonPolyVector: OS << " neon poly"; break;
309 }
310 OS << " " << T->getNumElements();
311 dumpTypeAsChild(T->getElementType());
312 }
313 void VisitFunctionType(const FunctionType *T) {
314 auto EI = T->getExtInfo();
315 if (EI.getNoReturn()) OS << " noreturn";
316 if (EI.getProducesResult()) OS << " produces_result";
317 if (EI.getHasRegParm()) OS << " regparm " << EI.getRegParm();
318 OS << " " << FunctionType::getNameForCallConv(EI.getCC());
319 dumpTypeAsChild(T->getReturnType());
320 }
321 void VisitFunctionProtoType(const FunctionProtoType *T) {
322 auto EPI = T->getExtProtoInfo();
323 if (EPI.HasTrailingReturn) OS << " trailing_return";
324 if (T->isConst()) OS << " const";
325 if (T->isVolatile()) OS << " volatile";
326 if (T->isRestrict()) OS << " restrict";
327 switch (EPI.RefQualifier) {
328 case RQ_None: break;
329 case RQ_LValue: OS << " &"; break;
330 case RQ_RValue: OS << " &&"; break;
331 }
332 // FIXME: Exception specification.
333 // FIXME: Consumed parameters.
334 VisitFunctionType(T);
335 for (QualType PT : T->getParamTypes())
336 dumpTypeAsChild(PT);
337 if (EPI.Variadic)
338 dumpChild([=] { OS << "..."; });
339 }
340 void VisitUnresolvedUsingType(const UnresolvedUsingType *T) {
341 dumpDeclRef(T->getDecl());
342 }
343 void VisitTypedefType(const TypedefType *T) {
344 dumpDeclRef(T->getDecl());
345 }
346 void VisitTypeOfExprType(const TypeOfExprType *T) {
347 dumpStmt(T->getUnderlyingExpr());
348 }
349 void VisitDecltypeType(const DecltypeType *T) {
350 dumpStmt(T->getUnderlyingExpr());
351 }
352 void VisitUnaryTransformType(const UnaryTransformType *T) {
353 switch (T->getUTTKind()) {
354 case UnaryTransformType::EnumUnderlyingType:
355 OS << " underlying_type";
356 break;
357 }
358 dumpTypeAsChild(T->getBaseType());
359 }
360 void VisitTagType(const TagType *T) {
361 dumpDeclRef(T->getDecl());
362 }
363 void VisitAttributedType(const AttributedType *T) {
364 // FIXME: AttrKind
365 dumpTypeAsChild(T->getModifiedType());
366 }
367 void VisitTemplateTypeParmType(const TemplateTypeParmType *T) {
368 OS << " depth " << T->getDepth() << " index " << T->getIndex();
369 if (T->isParameterPack()) OS << " pack";
370 dumpDeclRef(T->getDecl());
371 }
372 void VisitSubstTemplateTypeParmType(const SubstTemplateTypeParmType *T) {
373 dumpTypeAsChild(T->getReplacedParameter());
374 }
375 void VisitSubstTemplateTypeParmPackType(
376 const SubstTemplateTypeParmPackType *T) {
377 dumpTypeAsChild(T->getReplacedParameter());
378 dumpTemplateArgument(T->getArgumentPack());
379 }
380 void VisitAutoType(const AutoType *T) {
381 if (T->isDecltypeAuto()) OS << " decltype(auto)";
382 if (!T->isDeduced())
383 OS << " undeduced";
384 }
385 void VisitTemplateSpecializationType(const TemplateSpecializationType *T) {
386 if (T->isTypeAlias()) OS << " alias";
387 OS << " "; T->getTemplateName().dump(OS);
388 for (auto &Arg : *T)
389 dumpTemplateArgument(Arg);
390 if (T->isTypeAlias())
391 dumpTypeAsChild(T->getAliasedType());
392 }
393 void VisitInjectedClassNameType(const InjectedClassNameType *T) {
394 dumpDeclRef(T->getDecl());
395 }
396 void VisitObjCInterfaceType(const ObjCInterfaceType *T) {
397 dumpDeclRef(T->getDecl());
398 }
399 void VisitObjCObjectPointerType(const ObjCObjectPointerType *T) {
400 dumpTypeAsChild(T->getPointeeType());
401 }
402 void VisitAtomicType(const AtomicType *T) {
403 dumpTypeAsChild(T->getValueType());
404 }
405 void VisitAdjustedType(const AdjustedType *T) {
406 dumpTypeAsChild(T->getOriginalType());
407 }
408 void VisitPackExpansionType(const PackExpansionType *T) {
409 if (auto N = T->getNumExpansions()) OS << " expansions " << *N;
410 if (!T->isSugared())
411 dumpTypeAsChild(T->getPattern());
412 }
413 // FIXME: ElaboratedType, DependentNameType,
414 // DependentTemplateSpecializationType, ObjCObjectType
415
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000416 // Decls
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000417 void VisitLabelDecl(const LabelDecl *D);
418 void VisitTypedefDecl(const TypedefDecl *D);
419 void VisitEnumDecl(const EnumDecl *D);
420 void VisitRecordDecl(const RecordDecl *D);
421 void VisitEnumConstantDecl(const EnumConstantDecl *D);
422 void VisitIndirectFieldDecl(const IndirectFieldDecl *D);
423 void VisitFunctionDecl(const FunctionDecl *D);
424 void VisitFieldDecl(const FieldDecl *D);
425 void VisitVarDecl(const VarDecl *D);
426 void VisitFileScopeAsmDecl(const FileScopeAsmDecl *D);
427 void VisitImportDecl(const ImportDecl *D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000428
429 // C++ Decls
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000430 void VisitNamespaceDecl(const NamespaceDecl *D);
431 void VisitUsingDirectiveDecl(const UsingDirectiveDecl *D);
432 void VisitNamespaceAliasDecl(const NamespaceAliasDecl *D);
433 void VisitTypeAliasDecl(const TypeAliasDecl *D);
434 void VisitTypeAliasTemplateDecl(const TypeAliasTemplateDecl *D);
435 void VisitCXXRecordDecl(const CXXRecordDecl *D);
436 void VisitStaticAssertDecl(const StaticAssertDecl *D);
Richard Smithcbdf7332014-03-18 02:07:28 +0000437 template<typename SpecializationDecl>
Richard Smithf7514452014-10-30 21:02:37 +0000438 void VisitTemplateDeclSpecialization(const SpecializationDecl *D,
Richard Smithcbdf7332014-03-18 02:07:28 +0000439 bool DumpExplicitInst,
440 bool DumpRefOnly);
Richard Smith20ade552014-03-17 23:34:53 +0000441 template<typename TemplateDecl>
442 void VisitTemplateDecl(const TemplateDecl *D, bool DumpExplicitInst);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000443 void VisitFunctionTemplateDecl(const FunctionTemplateDecl *D);
444 void VisitClassTemplateDecl(const ClassTemplateDecl *D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000445 void VisitClassTemplateSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000446 const ClassTemplateSpecializationDecl *D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000447 void VisitClassTemplatePartialSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000448 const ClassTemplatePartialSpecializationDecl *D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000449 void VisitClassScopeFunctionSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000450 const ClassScopeFunctionSpecializationDecl *D);
David Majnemerd9b1a4f2015-11-04 03:40:30 +0000451 void VisitBuiltinTemplateDecl(const BuiltinTemplateDecl *D);
Richard Smithd25789a2013-09-18 01:36:02 +0000452 void VisitVarTemplateDecl(const VarTemplateDecl *D);
453 void VisitVarTemplateSpecializationDecl(
454 const VarTemplateSpecializationDecl *D);
455 void VisitVarTemplatePartialSpecializationDecl(
456 const VarTemplatePartialSpecializationDecl *D);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000457 void VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D);
458 void VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D);
459 void VisitTemplateTemplateParmDecl(const TemplateTemplateParmDecl *D);
460 void VisitUsingDecl(const UsingDecl *D);
461 void VisitUnresolvedUsingTypenameDecl(const UnresolvedUsingTypenameDecl *D);
462 void VisitUnresolvedUsingValueDecl(const UnresolvedUsingValueDecl *D);
463 void VisitUsingShadowDecl(const UsingShadowDecl *D);
464 void VisitLinkageSpecDecl(const LinkageSpecDecl *D);
465 void VisitAccessSpecDecl(const AccessSpecDecl *D);
466 void VisitFriendDecl(const FriendDecl *D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000467
468 // ObjC Decls
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000469 void VisitObjCIvarDecl(const ObjCIvarDecl *D);
470 void VisitObjCMethodDecl(const ObjCMethodDecl *D);
Douglas Gregor85f3f952015-07-07 03:57:15 +0000471 void VisitObjCTypeParamDecl(const ObjCTypeParamDecl *D);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000472 void VisitObjCCategoryDecl(const ObjCCategoryDecl *D);
473 void VisitObjCCategoryImplDecl(const ObjCCategoryImplDecl *D);
474 void VisitObjCProtocolDecl(const ObjCProtocolDecl *D);
475 void VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D);
476 void VisitObjCImplementationDecl(const ObjCImplementationDecl *D);
477 void VisitObjCCompatibleAliasDecl(const ObjCCompatibleAliasDecl *D);
478 void VisitObjCPropertyDecl(const ObjCPropertyDecl *D);
479 void VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D);
480 void VisitBlockDecl(const BlockDecl *D);
Mike Stump11289f42009-09-09 15:08:12 +0000481
Chris Lattner84ca3762007-08-30 01:00:35 +0000482 // Stmts.
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000483 void VisitStmt(const Stmt *Node);
484 void VisitDeclStmt(const DeclStmt *Node);
485 void VisitAttributedStmt(const AttributedStmt *Node);
486 void VisitLabelStmt(const LabelStmt *Node);
487 void VisitGotoStmt(const GotoStmt *Node);
Pavel Labath1ef83422013-09-04 14:35:00 +0000488 void VisitCXXCatchStmt(const CXXCatchStmt *Node);
Mike Stump11289f42009-09-09 15:08:12 +0000489
Chris Lattner84ca3762007-08-30 01:00:35 +0000490 // Exprs
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000491 void VisitExpr(const Expr *Node);
492 void VisitCastExpr(const CastExpr *Node);
493 void VisitDeclRefExpr(const DeclRefExpr *Node);
494 void VisitPredefinedExpr(const PredefinedExpr *Node);
495 void VisitCharacterLiteral(const CharacterLiteral *Node);
496 void VisitIntegerLiteral(const IntegerLiteral *Node);
497 void VisitFloatingLiteral(const FloatingLiteral *Node);
498 void VisitStringLiteral(const StringLiteral *Str);
Richard Smithf0514962014-06-03 08:24:28 +0000499 void VisitInitListExpr(const InitListExpr *ILE);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000500 void VisitUnaryOperator(const UnaryOperator *Node);
501 void VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *Node);
502 void VisitMemberExpr(const MemberExpr *Node);
503 void VisitExtVectorElementExpr(const ExtVectorElementExpr *Node);
504 void VisitBinaryOperator(const BinaryOperator *Node);
505 void VisitCompoundAssignOperator(const CompoundAssignOperator *Node);
506 void VisitAddrLabelExpr(const AddrLabelExpr *Node);
507 void VisitBlockExpr(const BlockExpr *Node);
508 void VisitOpaqueValueExpr(const OpaqueValueExpr *Node);
Chris Lattner84ca3762007-08-30 01:00:35 +0000509
510 // C++
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000511 void VisitCXXNamedCastExpr(const CXXNamedCastExpr *Node);
512 void VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *Node);
513 void VisitCXXThisExpr(const CXXThisExpr *Node);
514 void VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *Node);
515 void VisitCXXConstructExpr(const CXXConstructExpr *Node);
516 void VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *Node);
Reid Kleckner5c682bc2015-03-19 18:09:25 +0000517 void VisitCXXNewExpr(const CXXNewExpr *Node);
518 void VisitCXXDeleteExpr(const CXXDeleteExpr *Node);
Richard Smithe6c01442013-06-05 00:46:14 +0000519 void VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000520 void VisitExprWithCleanups(const ExprWithCleanups *Node);
521 void VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *Node);
522 void dumpCXXTemporary(const CXXTemporary *Temporary);
Faisal Vali2b391ab2013-09-26 19:54:12 +0000523 void VisitLambdaExpr(const LambdaExpr *Node) {
524 VisitExpr(Node);
525 dumpDecl(Node->getLambdaClass());
526 }
Serge Pavlov6b926032015-02-16 19:58:41 +0000527 void VisitSizeOfPackExpr(const SizeOfPackExpr *Node);
Mike Stump11289f42009-09-09 15:08:12 +0000528
Chris Lattner84ca3762007-08-30 01:00:35 +0000529 // ObjC
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000530 void VisitObjCAtCatchStmt(const ObjCAtCatchStmt *Node);
531 void VisitObjCEncodeExpr(const ObjCEncodeExpr *Node);
532 void VisitObjCMessageExpr(const ObjCMessageExpr *Node);
533 void VisitObjCBoxedExpr(const ObjCBoxedExpr *Node);
534 void VisitObjCSelectorExpr(const ObjCSelectorExpr *Node);
535 void VisitObjCProtocolExpr(const ObjCProtocolExpr *Node);
536 void VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *Node);
537 void VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *Node);
538 void VisitObjCIvarRefExpr(const ObjCIvarRefExpr *Node);
539 void VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *Node);
Alexander Kornienkoebc17b52013-01-14 14:07:11 +0000540
541 // Comments.
542 const char *getCommandName(unsigned CommandID);
543 void dumpComment(const Comment *C);
544
545 // Inline comments.
546 void visitTextComment(const TextComment *C);
547 void visitInlineCommandComment(const InlineCommandComment *C);
548 void visitHTMLStartTagComment(const HTMLStartTagComment *C);
549 void visitHTMLEndTagComment(const HTMLEndTagComment *C);
550
551 // Block comments.
552 void visitBlockCommandComment(const BlockCommandComment *C);
553 void visitParamCommandComment(const ParamCommandComment *C);
554 void visitTParamCommandComment(const TParamCommandComment *C);
555 void visitVerbatimBlockComment(const VerbatimBlockComment *C);
556 void visitVerbatimBlockLineComment(const VerbatimBlockLineComment *C);
557 void visitVerbatimLineComment(const VerbatimLineComment *C);
Chris Lattnercbe4f772007-08-08 22:51:59 +0000558 };
Alexander Kornienkoab9db512015-06-22 23:07:51 +0000559}
Chris Lattnercbe4f772007-08-08 22:51:59 +0000560
561//===----------------------------------------------------------------------===//
Chris Lattner11e30d32007-08-30 06:17:34 +0000562// Utilities
563//===----------------------------------------------------------------------===//
564
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000565void ASTDumper::dumpPointer(const void *Ptr) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000566 ColorScope Color(*this, AddressColor);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000567 OS << ' ' << Ptr;
568}
569
Alexander Kornienko18ec81b2012-12-13 13:59:55 +0000570void ASTDumper::dumpLocation(SourceLocation Loc) {
Alex McCarthye14ddef2014-05-02 20:24:11 +0000571 if (!SM)
572 return;
573
Richard Trieud215b8d2013-01-26 01:31:20 +0000574 ColorScope Color(*this, LocationColor);
Chris Lattner53e384f2009-01-16 07:00:02 +0000575 SourceLocation SpellingLoc = SM->getSpellingLoc(Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000576
Chris Lattner11e30d32007-08-30 06:17:34 +0000577 // The general format we print out is filename:line:col, but we drop pieces
578 // that haven't changed since the last loc printed.
Chris Lattnerf1ca7d32009-01-27 07:57:44 +0000579 PresumedLoc PLoc = SM->getPresumedLoc(SpellingLoc);
580
Douglas Gregor453b0122010-11-12 07:15:47 +0000581 if (PLoc.isInvalid()) {
582 OS << "<invalid sloc>";
583 return;
584 }
585
Chris Lattnerf1ca7d32009-01-27 07:57:44 +0000586 if (strcmp(PLoc.getFilename(), LastLocFilename) != 0) {
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000587 OS << PLoc.getFilename() << ':' << PLoc.getLine()
588 << ':' << PLoc.getColumn();
Chris Lattnerf1ca7d32009-01-27 07:57:44 +0000589 LastLocFilename = PLoc.getFilename();
590 LastLocLine = PLoc.getLine();
591 } else if (PLoc.getLine() != LastLocLine) {
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000592 OS << "line" << ':' << PLoc.getLine()
593 << ':' << PLoc.getColumn();
Chris Lattnerf1ca7d32009-01-27 07:57:44 +0000594 LastLocLine = PLoc.getLine();
Chris Lattner11e30d32007-08-30 06:17:34 +0000595 } else {
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000596 OS << "col" << ':' << PLoc.getColumn();
Chris Lattner11e30d32007-08-30 06:17:34 +0000597 }
598}
599
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000600void ASTDumper::dumpSourceRange(SourceRange R) {
Chris Lattner11e30d32007-08-30 06:17:34 +0000601 // Can't translate locations if a SourceManager isn't available.
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000602 if (!SM)
603 return;
Mike Stump11289f42009-09-09 15:08:12 +0000604
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000605 OS << " <";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000606 dumpLocation(R.getBegin());
Chris Lattnera7c19fe2007-10-16 22:36:42 +0000607 if (R.getBegin() != R.getEnd()) {
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000608 OS << ", ";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000609 dumpLocation(R.getEnd());
Chris Lattner11e30d32007-08-30 06:17:34 +0000610 }
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000611 OS << ">";
Mike Stump11289f42009-09-09 15:08:12 +0000612
Chris Lattner11e30d32007-08-30 06:17:34 +0000613 // <t2.c:123:421[blah], t2.c:412:321>
614
615}
616
Richard Smithd5e7ff82014-10-31 01:17:45 +0000617void ASTDumper::dumpBareType(QualType T, bool Desugar) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000618 ColorScope Color(*this, TypeColor);
Richard Smithd5e7ff82014-10-31 01:17:45 +0000619
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000620 SplitQualType T_split = T.split();
621 OS << "'" << QualType::getAsString(T_split) << "'";
622
Richard Smithd5e7ff82014-10-31 01:17:45 +0000623 if (Desugar && !T.isNull()) {
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000624 // If the type is sugared, also dump a (shallow) desugared type.
625 SplitQualType D_split = T.getSplitDesugaredType();
626 if (T_split != D_split)
627 OS << ":'" << QualType::getAsString(D_split) << "'";
628 }
629}
630
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000631void ASTDumper::dumpType(QualType T) {
632 OS << ' ';
633 dumpBareType(T);
634}
635
Richard Smithd5e7ff82014-10-31 01:17:45 +0000636void ASTDumper::dumpTypeAsChild(QualType T) {
637 SplitQualType SQT = T.split();
638 if (!SQT.Quals.hasQualifiers())
639 return dumpTypeAsChild(SQT.Ty);
640
641 dumpChild([=] {
642 OS << "QualType";
643 dumpPointer(T.getAsOpaquePtr());
644 OS << " ";
645 dumpBareType(T, false);
646 OS << " " << T.split().Quals.getAsString();
647 dumpTypeAsChild(T.split().Ty);
648 });
649}
650
651void ASTDumper::dumpTypeAsChild(const Type *T) {
652 dumpChild([=] {
653 if (!T) {
654 ColorScope Color(*this, NullColor);
655 OS << "<<<NULL>>>";
656 return;
657 }
658
659 {
660 ColorScope Color(*this, TypeColor);
661 OS << T->getTypeClassName() << "Type";
662 }
663 dumpPointer(T);
664 OS << " ";
665 dumpBareType(QualType(T, 0), false);
666
667 QualType SingleStepDesugar =
668 T->getLocallyUnqualifiedSingleStepDesugaredType();
669 if (SingleStepDesugar != QualType(T, 0))
670 OS << " sugar";
671 if (T->isDependentType())
672 OS << " dependent";
673 else if (T->isInstantiationDependentType())
674 OS << " instantiation_dependent";
675 if (T->isVariablyModifiedType())
676 OS << " variably_modified";
677 if (T->containsUnexpandedParameterPack())
678 OS << " contains_unexpanded_pack";
679 if (T->isFromAST())
680 OS << " imported";
681
682 TypeVisitor<ASTDumper>::Visit(T);
683
684 if (SingleStepDesugar != QualType(T, 0))
685 dumpTypeAsChild(SingleStepDesugar);
686 });
687}
688
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000689void ASTDumper::dumpBareDeclRef(const Decl *D) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000690 {
691 ColorScope Color(*this, DeclKindNameColor);
692 OS << D->getDeclKindName();
693 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000694 dumpPointer(D);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000695
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000696 if (const NamedDecl *ND = dyn_cast<NamedDecl>(D)) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000697 ColorScope Color(*this, DeclNameColor);
David Blaikied4da8722013-05-14 21:04:00 +0000698 OS << " '" << ND->getDeclName() << '\'';
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000699 }
700
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000701 if (const ValueDecl *VD = dyn_cast<ValueDecl>(D))
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000702 dumpType(VD->getType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000703}
704
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000705void ASTDumper::dumpDeclRef(const Decl *D, const char *Label) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000706 if (!D)
707 return;
708
Richard Smithf7514452014-10-30 21:02:37 +0000709 dumpChild([=]{
710 if (Label)
711 OS << Label << ' ';
712 dumpBareDeclRef(D);
713 });
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000714}
715
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000716void ASTDumper::dumpName(const NamedDecl *ND) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000717 if (ND->getDeclName()) {
718 ColorScope Color(*this, DeclNameColor);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000719 OS << ' ' << ND->getNameAsString();
Richard Trieud215b8d2013-01-26 01:31:20 +0000720 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000721}
722
Richard Trieude5cc7d2013-01-31 01:44:26 +0000723bool ASTDumper::hasNodes(const DeclContext *DC) {
724 if (!DC)
725 return false;
726
Richard Smith1d209d02013-05-23 01:49:11 +0000727 return DC->hasExternalLexicalStorage() ||
728 DC->noload_decls_begin() != DC->noload_decls_end();
Richard Trieude5cc7d2013-01-31 01:44:26 +0000729}
730
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000731void ASTDumper::dumpDeclContext(const DeclContext *DC) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000732 if (!DC)
733 return;
Richard Smithdcc2c452014-03-17 23:00:06 +0000734
Richard Smithdcc2c452014-03-17 23:00:06 +0000735 for (auto *D : DC->noload_decls())
Richard Smithf7514452014-10-30 21:02:37 +0000736 dumpDecl(D);
Richard Smithdcc2c452014-03-17 23:00:06 +0000737
738 if (DC->hasExternalLexicalStorage()) {
Richard Smithf7514452014-10-30 21:02:37 +0000739 dumpChild([=]{
740 ColorScope Color(*this, UndeserializedColor);
741 OS << "<undeserialized declarations>";
742 });
Richard Smith1d209d02013-05-23 01:49:11 +0000743 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000744}
745
Richard Smith35f986d2014-08-11 22:11:07 +0000746void ASTDumper::dumpLookups(const DeclContext *DC, bool DumpDecls) {
Richard Smithf7514452014-10-30 21:02:37 +0000747 dumpChild([=] {
748 OS << "StoredDeclsMap ";
749 dumpBareDeclRef(cast<Decl>(DC));
Richard Smith33937e72013-06-22 21:49:40 +0000750
Richard Smithf7514452014-10-30 21:02:37 +0000751 const DeclContext *Primary = DC->getPrimaryContext();
752 if (Primary != DC) {
753 OS << " primary";
754 dumpPointer(cast<Decl>(Primary));
Richard Smith33937e72013-06-22 21:49:40 +0000755 }
756
Richard Smithf7514452014-10-30 21:02:37 +0000757 bool HasUndeserializedLookups = Primary->hasExternalVisibleStorage();
Richard Smith35f986d2014-08-11 22:11:07 +0000758
Richard Smithf7514452014-10-30 21:02:37 +0000759 DeclContext::all_lookups_iterator I = Primary->noload_lookups_begin(),
760 E = Primary->noload_lookups_end();
761 while (I != E) {
762 DeclarationName Name = I.getLookupName();
763 DeclContextLookupResult R = *I++;
Richard Smith35f986d2014-08-11 22:11:07 +0000764
Richard Smithf7514452014-10-30 21:02:37 +0000765 dumpChild([=] {
766 OS << "DeclarationName ";
767 {
768 ColorScope Color(*this, DeclNameColor);
769 OS << '\'' << Name << '\'';
770 }
Richard Smith35f986d2014-08-11 22:11:07 +0000771
Richard Smithf7514452014-10-30 21:02:37 +0000772 for (DeclContextLookupResult::iterator RI = R.begin(), RE = R.end();
773 RI != RE; ++RI) {
774 dumpChild([=] {
775 dumpBareDeclRef(*RI);
776
777 if ((*RI)->isHidden())
778 OS << " hidden";
779
780 // If requested, dump the redecl chain for this lookup.
781 if (DumpDecls) {
782 // Dump earliest decl first.
783 std::function<void(Decl *)> DumpWithPrev = [&](Decl *D) {
784 if (Decl *Prev = D->getPreviousDecl())
785 DumpWithPrev(Prev);
786 dumpDecl(D);
787 };
788 DumpWithPrev(*RI);
789 }
790 });
791 }
792 });
Richard Smith33937e72013-06-22 21:49:40 +0000793 }
Richard Smith33937e72013-06-22 21:49:40 +0000794
Richard Smithf7514452014-10-30 21:02:37 +0000795 if (HasUndeserializedLookups) {
796 dumpChild([=] {
797 ColorScope Color(*this, UndeserializedColor);
798 OS << "<undeserialized lookups>";
799 });
800 }
801 });
Richard Smith33937e72013-06-22 21:49:40 +0000802}
803
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000804void ASTDumper::dumpAttr(const Attr *A) {
Richard Smithf7514452014-10-30 21:02:37 +0000805 dumpChild([=] {
806 {
807 ColorScope Color(*this, AttrColor);
Aaron Ballman36a53502014-01-16 13:03:14 +0000808
Richard Smithf7514452014-10-30 21:02:37 +0000809 switch (A->getKind()) {
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000810#define ATTR(X) case attr::X: OS << #X; break;
811#include "clang/Basic/AttrList.inc"
Richard Smithf7514452014-10-30 21:02:37 +0000812 default:
813 llvm_unreachable("unexpected attribute kind");
814 }
815 OS << "Attr";
Richard Trieud215b8d2013-01-26 01:31:20 +0000816 }
Richard Smithf7514452014-10-30 21:02:37 +0000817 dumpPointer(A);
818 dumpSourceRange(A->getRange());
819 if (A->isInherited())
820 OS << " Inherited";
821 if (A->isImplicit())
822 OS << " Implicit";
Hans Wennborgb0a8b4a2014-05-31 04:05:57 +0000823#include "clang/AST/AttrDump.inc"
Richard Smithf7514452014-10-30 21:02:37 +0000824 });
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000825}
826
Richard Smith71bec062013-10-15 21:58:30 +0000827static void dumpPreviousDeclImpl(raw_ostream &OS, ...) {}
828
829template<typename T>
830static void dumpPreviousDeclImpl(raw_ostream &OS, const Mergeable<T> *D) {
Rafael Espindola8db352d2013-10-17 15:37:26 +0000831 const T *First = D->getFirstDecl();
Richard Smith71bec062013-10-15 21:58:30 +0000832 if (First != D)
833 OS << " first " << First;
Richard Smithf5f43542013-02-07 01:35:44 +0000834}
835
836template<typename T>
Richard Smith71bec062013-10-15 21:58:30 +0000837static void dumpPreviousDeclImpl(raw_ostream &OS, const Redeclarable<T> *D) {
838 const T *Prev = D->getPreviousDecl();
839 if (Prev)
840 OS << " prev " << Prev;
Richard Smithf5f43542013-02-07 01:35:44 +0000841}
842
Richard Smith71bec062013-10-15 21:58:30 +0000843/// Dump the previous declaration in the redeclaration chain for a declaration,
844/// if any.
845static void dumpPreviousDecl(raw_ostream &OS, const Decl *D) {
Richard Smithf5f43542013-02-07 01:35:44 +0000846 switch (D->getKind()) {
847#define DECL(DERIVED, BASE) \
848 case Decl::DERIVED: \
Richard Smith71bec062013-10-15 21:58:30 +0000849 return dumpPreviousDeclImpl(OS, cast<DERIVED##Decl>(D));
Richard Smithf5f43542013-02-07 01:35:44 +0000850#define ABSTRACT_DECL(DECL)
851#include "clang/AST/DeclNodes.inc"
852 }
853 llvm_unreachable("Decl that isn't part of DeclNodes.inc!");
854}
855
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000856//===----------------------------------------------------------------------===//
857// C++ Utilities
858//===----------------------------------------------------------------------===//
859
860void ASTDumper::dumpAccessSpecifier(AccessSpecifier AS) {
861 switch (AS) {
862 case AS_none:
863 break;
864 case AS_public:
865 OS << "public";
866 break;
867 case AS_protected:
868 OS << "protected";
869 break;
870 case AS_private:
871 OS << "private";
872 break;
873 }
874}
875
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000876void ASTDumper::dumpCXXCtorInitializer(const CXXCtorInitializer *Init) {
Richard Smithf7514452014-10-30 21:02:37 +0000877 dumpChild([=] {
878 OS << "CXXCtorInitializer";
879 if (Init->isAnyMemberInitializer()) {
880 OS << ' ';
881 dumpBareDeclRef(Init->getAnyMember());
882 } else if (Init->isBaseInitializer()) {
883 dumpType(QualType(Init->getBaseClass(), 0));
884 } else if (Init->isDelegatingInitializer()) {
885 dumpType(Init->getTypeSourceInfo()->getType());
886 } else {
887 llvm_unreachable("Unknown initializer type");
888 }
889 dumpStmt(Init->getInit());
890 });
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000891}
892
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000893void ASTDumper::dumpTemplateParameters(const TemplateParameterList *TPL) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000894 if (!TPL)
895 return;
896
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000897 for (TemplateParameterList::const_iterator I = TPL->begin(), E = TPL->end();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000898 I != E; ++I)
899 dumpDecl(*I);
900}
901
902void ASTDumper::dumpTemplateArgumentListInfo(
903 const TemplateArgumentListInfo &TALI) {
Richard Smithf7514452014-10-30 21:02:37 +0000904 for (unsigned i = 0, e = TALI.size(); i < e; ++i)
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000905 dumpTemplateArgumentLoc(TALI[i]);
906}
907
908void ASTDumper::dumpTemplateArgumentLoc(const TemplateArgumentLoc &A) {
909 dumpTemplateArgument(A.getArgument(), A.getSourceRange());
910}
911
912void ASTDumper::dumpTemplateArgumentList(const TemplateArgumentList &TAL) {
913 for (unsigned i = 0, e = TAL.size(); i < e; ++i)
914 dumpTemplateArgument(TAL[i]);
915}
916
917void ASTDumper::dumpTemplateArgument(const TemplateArgument &A, SourceRange R) {
Richard Smithf7514452014-10-30 21:02:37 +0000918 dumpChild([=] {
919 OS << "TemplateArgument";
920 if (R.isValid())
921 dumpSourceRange(R);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000922
Richard Smithf7514452014-10-30 21:02:37 +0000923 switch (A.getKind()) {
924 case TemplateArgument::Null:
925 OS << " null";
926 break;
927 case TemplateArgument::Type:
928 OS << " type";
929 dumpType(A.getAsType());
930 break;
931 case TemplateArgument::Declaration:
932 OS << " decl";
933 dumpDeclRef(A.getAsDecl());
934 break;
935 case TemplateArgument::NullPtr:
936 OS << " nullptr";
937 break;
938 case TemplateArgument::Integral:
939 OS << " integral " << A.getAsIntegral();
940 break;
941 case TemplateArgument::Template:
942 OS << " template ";
943 A.getAsTemplate().dump(OS);
944 break;
945 case TemplateArgument::TemplateExpansion:
946 OS << " template expansion";
947 A.getAsTemplateOrTemplatePattern().dump(OS);
948 break;
949 case TemplateArgument::Expression:
950 OS << " expr";
951 dumpStmt(A.getAsExpr());
952 break;
953 case TemplateArgument::Pack:
954 OS << " pack";
955 for (TemplateArgument::pack_iterator I = A.pack_begin(), E = A.pack_end();
956 I != E; ++I)
957 dumpTemplateArgument(*I);
958 break;
Richard Trieude5cc7d2013-01-31 01:44:26 +0000959 }
Richard Smithf7514452014-10-30 21:02:37 +0000960 });
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000961}
962
Chris Lattner11e30d32007-08-30 06:17:34 +0000963//===----------------------------------------------------------------------===//
Douglas Gregor85f3f952015-07-07 03:57:15 +0000964// Objective-C Utilities
965//===----------------------------------------------------------------------===//
966void ASTDumper::dumpObjCTypeParamList(const ObjCTypeParamList *typeParams) {
967 if (!typeParams)
968 return;
969
970 for (auto typeParam : *typeParams) {
971 dumpDecl(typeParam);
972 }
973}
974
975//===----------------------------------------------------------------------===//
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000976// Decl dumping methods.
Chris Lattnercbe4f772007-08-08 22:51:59 +0000977//===----------------------------------------------------------------------===//
978
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000979void ASTDumper::dumpDecl(const Decl *D) {
Richard Smithf7514452014-10-30 21:02:37 +0000980 dumpChild([=] {
981 if (!D) {
982 ColorScope Color(*this, NullColor);
983 OS << "<<<NULL>>>";
984 return;
985 }
Mike Stump11289f42009-09-09 15:08:12 +0000986
Richard Smithf7514452014-10-30 21:02:37 +0000987 {
988 ColorScope Color(*this, DeclKindNameColor);
989 OS << D->getDeclKindName() << "Decl";
990 }
991 dumpPointer(D);
992 if (D->getLexicalDeclContext() != D->getDeclContext())
993 OS << " parent " << cast<Decl>(D->getDeclContext());
994 dumpPreviousDecl(OS, D);
995 dumpSourceRange(D->getSourceRange());
996 OS << ' ';
997 dumpLocation(D->getLocation());
Richard Smith42413142015-05-15 20:05:43 +0000998 if (Module *M = D->getImportedOwningModule())
Richard Smithf7514452014-10-30 21:02:37 +0000999 OS << " in " << M->getFullModuleName();
Richard Smith42413142015-05-15 20:05:43 +00001000 else if (Module *M = D->getLocalOwningModule())
1001 OS << " in (local) " << M->getFullModuleName();
Richard Smitha2eb4092015-06-22 18:47:01 +00001002 if (auto *ND = dyn_cast<NamedDecl>(D))
1003 for (Module *M : D->getASTContext().getModulesWithMergedDefinition(
1004 const_cast<NamedDecl *>(ND)))
1005 dumpChild([=] { OS << "also in " << M->getFullModuleName(); });
Richard Smithf7514452014-10-30 21:02:37 +00001006 if (const NamedDecl *ND = dyn_cast<NamedDecl>(D))
1007 if (ND->isHidden())
1008 OS << " hidden";
1009 if (D->isImplicit())
1010 OS << " implicit";
1011 if (D->isUsed())
1012 OS << " used";
1013 else if (D->isThisDeclarationReferenced())
1014 OS << " referenced";
1015 if (D->isInvalidDecl())
1016 OS << " invalid";
Hans Wennborg76b00532014-12-05 22:38:57 +00001017 if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
1018 if (FD->isConstexpr())
1019 OS << " constexpr";
1020
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001021
Richard Smithf7514452014-10-30 21:02:37 +00001022 ConstDeclVisitor<ASTDumper>::Visit(D);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001023
Richard Smithf7514452014-10-30 21:02:37 +00001024 for (Decl::attr_iterator I = D->attr_begin(), E = D->attr_end(); I != E;
1025 ++I)
1026 dumpAttr(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001027
Richard Smithf7514452014-10-30 21:02:37 +00001028 if (const FullComment *Comment =
1029 D->getASTContext().getLocalCommentForDeclUncached(D))
1030 dumpFullComment(Comment);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001031
Richard Smithf7514452014-10-30 21:02:37 +00001032 // Decls within functions are visited by the body.
1033 if (!isa<FunctionDecl>(*D) && !isa<ObjCMethodDecl>(*D) &&
1034 hasNodes(dyn_cast<DeclContext>(D)))
1035 dumpDeclContext(cast<DeclContext>(D));
1036 });
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001037}
1038
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001039void ASTDumper::VisitLabelDecl(const LabelDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001040 dumpName(D);
1041}
1042
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001043void ASTDumper::VisitTypedefDecl(const TypedefDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001044 dumpName(D);
1045 dumpType(D->getUnderlyingType());
1046 if (D->isModulePrivate())
1047 OS << " __module_private__";
1048}
1049
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001050void ASTDumper::VisitEnumDecl(const EnumDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001051 if (D->isScoped()) {
1052 if (D->isScopedUsingClassTag())
1053 OS << " class";
1054 else
1055 OS << " struct";
1056 }
1057 dumpName(D);
1058 if (D->isModulePrivate())
1059 OS << " __module_private__";
1060 if (D->isFixed())
1061 dumpType(D->getIntegerType());
1062}
1063
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001064void ASTDumper::VisitRecordDecl(const RecordDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001065 OS << ' ' << D->getKindName();
1066 dumpName(D);
1067 if (D->isModulePrivate())
1068 OS << " __module_private__";
Richard Smith99bc1b92013-08-30 05:32:29 +00001069 if (D->isCompleteDefinition())
1070 OS << " definition";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001071}
1072
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001073void ASTDumper::VisitEnumConstantDecl(const EnumConstantDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001074 dumpName(D);
1075 dumpType(D->getType());
Richard Smithf7514452014-10-30 21:02:37 +00001076 if (const Expr *Init = D->getInitExpr())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001077 dumpStmt(Init);
1078}
1079
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001080void ASTDumper::VisitIndirectFieldDecl(const IndirectFieldDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001081 dumpName(D);
1082 dumpType(D->getType());
Richard Smithdcc2c452014-03-17 23:00:06 +00001083
Richard Smith8aa49222014-03-18 00:35:12 +00001084 for (auto *Child : D->chain())
Richard Smithf7514452014-10-30 21:02:37 +00001085 dumpDeclRef(Child);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001086}
1087
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001088void ASTDumper::VisitFunctionDecl(const FunctionDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001089 dumpName(D);
1090 dumpType(D->getType());
1091
Rafael Espindola6ae7e502013-04-03 19:27:57 +00001092 StorageClass SC = D->getStorageClass();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001093 if (SC != SC_None)
1094 OS << ' ' << VarDecl::getStorageClassSpecifierString(SC);
1095 if (D->isInlineSpecified())
1096 OS << " inline";
1097 if (D->isVirtualAsWritten())
1098 OS << " virtual";
1099 if (D->isModulePrivate())
1100 OS << " __module_private__";
1101
1102 if (D->isPure())
1103 OS << " pure";
1104 else if (D->isDeletedAsWritten())
1105 OS << " delete";
1106
Richard Smithadaa0152013-05-17 02:09:46 +00001107 if (const FunctionProtoType *FPT = D->getType()->getAs<FunctionProtoType>()) {
1108 FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo();
Richard Smith8acb4282014-07-31 21:57:55 +00001109 switch (EPI.ExceptionSpec.Type) {
Richard Smithadaa0152013-05-17 02:09:46 +00001110 default: break;
1111 case EST_Unevaluated:
Richard Smith8acb4282014-07-31 21:57:55 +00001112 OS << " noexcept-unevaluated " << EPI.ExceptionSpec.SourceDecl;
Richard Smithadaa0152013-05-17 02:09:46 +00001113 break;
1114 case EST_Uninstantiated:
Richard Smith8acb4282014-07-31 21:57:55 +00001115 OS << " noexcept-uninstantiated " << EPI.ExceptionSpec.SourceTemplate;
Richard Smithadaa0152013-05-17 02:09:46 +00001116 break;
1117 }
1118 }
1119
Richard Smithf7514452014-10-30 21:02:37 +00001120 if (const FunctionTemplateSpecializationInfo *FTSI =
1121 D->getTemplateSpecializationInfo())
Richard Trieude5cc7d2013-01-31 01:44:26 +00001122 dumpTemplateArgumentList(*FTSI->TemplateArguments);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001123
Dmitri Gribenkof8579502013-01-12 19:30:44 +00001124 for (ArrayRef<NamedDecl *>::iterator
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001125 I = D->getDeclsInPrototypeScope().begin(),
Richard Smithf7514452014-10-30 21:02:37 +00001126 E = D->getDeclsInPrototypeScope().end(); I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001127 dumpDecl(*I);
1128
Richard Smith8a639892015-01-24 01:07:20 +00001129 if (!D->param_begin() && D->getNumParams())
1130 dumpChild([=] { OS << "<<NULL params x " << D->getNumParams() << ">>"; });
1131 else
1132 for (FunctionDecl::param_const_iterator I = D->param_begin(),
1133 E = D->param_end();
1134 I != E; ++I)
1135 dumpDecl(*I);
Richard Smithf7514452014-10-30 21:02:37 +00001136
1137 if (const CXXConstructorDecl *C = dyn_cast<CXXConstructorDecl>(D))
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001138 for (CXXConstructorDecl::init_const_iterator I = C->init_begin(),
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001139 E = C->init_end();
Richard Smithf7514452014-10-30 21:02:37 +00001140 I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001141 dumpCXXCtorInitializer(*I);
1142
Richard Smithf7514452014-10-30 21:02:37 +00001143 if (D->doesThisDeclarationHaveABody())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001144 dumpStmt(D->getBody());
1145}
1146
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001147void ASTDumper::VisitFieldDecl(const FieldDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001148 dumpName(D);
1149 dumpType(D->getType());
1150 if (D->isMutable())
1151 OS << " mutable";
1152 if (D->isModulePrivate())
1153 OS << " __module_private__";
Richard Trieude5cc7d2013-01-31 01:44:26 +00001154
Richard Smithf7514452014-10-30 21:02:37 +00001155 if (D->isBitField())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001156 dumpStmt(D->getBitWidth());
Richard Smithf7514452014-10-30 21:02:37 +00001157 if (Expr *Init = D->getInClassInitializer())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001158 dumpStmt(Init);
1159}
1160
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001161void ASTDumper::VisitVarDecl(const VarDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001162 dumpName(D);
1163 dumpType(D->getType());
Rafael Espindola6ae7e502013-04-03 19:27:57 +00001164 StorageClass SC = D->getStorageClass();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001165 if (SC != SC_None)
1166 OS << ' ' << VarDecl::getStorageClassSpecifierString(SC);
Richard Smithfd3834f2013-04-13 02:43:54 +00001167 switch (D->getTLSKind()) {
1168 case VarDecl::TLS_None: break;
1169 case VarDecl::TLS_Static: OS << " tls"; break;
1170 case VarDecl::TLS_Dynamic: OS << " tls_dynamic"; break;
1171 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001172 if (D->isModulePrivate())
1173 OS << " __module_private__";
1174 if (D->isNRVOVariable())
1175 OS << " nrvo";
Richard Trieude5cc7d2013-01-31 01:44:26 +00001176 if (D->hasInit()) {
Richard Smithd9967cc2014-07-10 22:54:03 +00001177 switch (D->getInitStyle()) {
1178 case VarDecl::CInit: OS << " cinit"; break;
1179 case VarDecl::CallInit: OS << " callinit"; break;
1180 case VarDecl::ListInit: OS << " listinit"; break;
1181 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001182 dumpStmt(D->getInit());
Richard Trieude5cc7d2013-01-31 01:44:26 +00001183 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001184}
1185
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001186void ASTDumper::VisitFileScopeAsmDecl(const FileScopeAsmDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001187 dumpStmt(D->getAsmString());
1188}
1189
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001190void ASTDumper::VisitImportDecl(const ImportDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001191 OS << ' ' << D->getImportedModule()->getFullModuleName();
1192}
1193
1194//===----------------------------------------------------------------------===//
1195// C++ Declarations
1196//===----------------------------------------------------------------------===//
1197
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001198void ASTDumper::VisitNamespaceDecl(const NamespaceDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001199 dumpName(D);
1200 if (D->isInline())
1201 OS << " inline";
1202 if (!D->isOriginalNamespace())
1203 dumpDeclRef(D->getOriginalNamespace(), "original");
1204}
1205
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001206void ASTDumper::VisitUsingDirectiveDecl(const UsingDirectiveDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001207 OS << ' ';
1208 dumpBareDeclRef(D->getNominatedNamespace());
1209}
1210
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001211void ASTDumper::VisitNamespaceAliasDecl(const NamespaceAliasDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001212 dumpName(D);
1213 dumpDeclRef(D->getAliasedNamespace());
1214}
1215
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001216void ASTDumper::VisitTypeAliasDecl(const TypeAliasDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001217 dumpName(D);
1218 dumpType(D->getUnderlyingType());
1219}
1220
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001221void ASTDumper::VisitTypeAliasTemplateDecl(const TypeAliasTemplateDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001222 dumpName(D);
1223 dumpTemplateParameters(D->getTemplateParameters());
1224 dumpDecl(D->getTemplatedDecl());
1225}
1226
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001227void ASTDumper::VisitCXXRecordDecl(const CXXRecordDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001228 VisitRecordDecl(D);
1229 if (!D->isCompleteDefinition())
1230 return;
1231
Aaron Ballman574705e2014-03-13 15:41:46 +00001232 for (const auto &I : D->bases()) {
Richard Smithf7514452014-10-30 21:02:37 +00001233 dumpChild([=] {
1234 if (I.isVirtual())
1235 OS << "virtual ";
1236 dumpAccessSpecifier(I.getAccessSpecifier());
1237 dumpType(I.getType());
1238 if (I.isPackExpansion())
1239 OS << "...";
1240 });
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001241 }
1242}
1243
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001244void ASTDumper::VisitStaticAssertDecl(const StaticAssertDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001245 dumpStmt(D->getAssertExpr());
1246 dumpStmt(D->getMessage());
1247}
1248
Richard Smithcbdf7332014-03-18 02:07:28 +00001249template<typename SpecializationDecl>
Richard Smithf7514452014-10-30 21:02:37 +00001250void ASTDumper::VisitTemplateDeclSpecialization(const SpecializationDecl *D,
Richard Smithcbdf7332014-03-18 02:07:28 +00001251 bool DumpExplicitInst,
1252 bool DumpRefOnly) {
1253 bool DumpedAny = false;
1254 for (auto *RedeclWithBadType : D->redecls()) {
1255 // FIXME: The redecls() range sometimes has elements of a less-specific
1256 // type. (In particular, ClassTemplateSpecializationDecl::redecls() gives
1257 // us TagDecls, and should give CXXRecordDecls).
1258 auto *Redecl = dyn_cast<SpecializationDecl>(RedeclWithBadType);
1259 if (!Redecl) {
1260 // Found the injected-class-name for a class template. This will be dumped
1261 // as part of its surrounding class so we don't need to dump it here.
1262 assert(isa<CXXRecordDecl>(RedeclWithBadType) &&
1263 "expected an injected-class-name");
1264 continue;
1265 }
1266
1267 switch (Redecl->getTemplateSpecializationKind()) {
1268 case TSK_ExplicitInstantiationDeclaration:
1269 case TSK_ExplicitInstantiationDefinition:
1270 if (!DumpExplicitInst)
1271 break;
1272 // Fall through.
1273 case TSK_Undeclared:
1274 case TSK_ImplicitInstantiation:
Richard Smithf7514452014-10-30 21:02:37 +00001275 if (DumpRefOnly)
1276 dumpDeclRef(Redecl);
1277 else
1278 dumpDecl(Redecl);
Richard Smithcbdf7332014-03-18 02:07:28 +00001279 DumpedAny = true;
1280 break;
1281 case TSK_ExplicitSpecialization:
1282 break;
1283 }
1284 }
1285
1286 // Ensure we dump at least one decl for each specialization.
1287 if (!DumpedAny)
Richard Smithf7514452014-10-30 21:02:37 +00001288 dumpDeclRef(D);
Richard Smithcbdf7332014-03-18 02:07:28 +00001289}
1290
Richard Smith20ade552014-03-17 23:34:53 +00001291template<typename TemplateDecl>
1292void ASTDumper::VisitTemplateDecl(const TemplateDecl *D,
1293 bool DumpExplicitInst) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001294 dumpName(D);
1295 dumpTemplateParameters(D->getTemplateParameters());
Richard Smithdcc2c452014-03-17 23:00:06 +00001296
Richard Smithf7514452014-10-30 21:02:37 +00001297 dumpDecl(D->getTemplatedDecl());
Richard Smithdcc2c452014-03-17 23:00:06 +00001298
Richard Smithcbdf7332014-03-18 02:07:28 +00001299 for (auto *Child : D->specializations())
Richard Smithf7514452014-10-30 21:02:37 +00001300 VisitTemplateDeclSpecialization(Child, DumpExplicitInst,
Richard Smithcbdf7332014-03-18 02:07:28 +00001301 !D->isCanonicalDecl());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001302}
1303
Richard Smith20ade552014-03-17 23:34:53 +00001304void ASTDumper::VisitFunctionTemplateDecl(const FunctionTemplateDecl *D) {
1305 // FIXME: We don't add a declaration of a function template specialization
1306 // to its context when it's explicitly instantiated, so dump explicit
1307 // instantiations when we dump the template itself.
1308 VisitTemplateDecl(D, true);
1309}
1310
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001311void ASTDumper::VisitClassTemplateDecl(const ClassTemplateDecl *D) {
Richard Smith20ade552014-03-17 23:34:53 +00001312 VisitTemplateDecl(D, false);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001313}
1314
1315void ASTDumper::VisitClassTemplateSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001316 const ClassTemplateSpecializationDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001317 VisitCXXRecordDecl(D);
1318 dumpTemplateArgumentList(D->getTemplateArgs());
1319}
1320
1321void ASTDumper::VisitClassTemplatePartialSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001322 const ClassTemplatePartialSpecializationDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001323 VisitClassTemplateSpecializationDecl(D);
1324 dumpTemplateParameters(D->getTemplateParameters());
1325}
1326
1327void ASTDumper::VisitClassScopeFunctionSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001328 const ClassScopeFunctionSpecializationDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001329 dumpDeclRef(D->getSpecialization());
1330 if (D->hasExplicitTemplateArgs())
1331 dumpTemplateArgumentListInfo(D->templateArgs());
1332}
1333
Richard Smithd25789a2013-09-18 01:36:02 +00001334void ASTDumper::VisitVarTemplateDecl(const VarTemplateDecl *D) {
Richard Smith20ade552014-03-17 23:34:53 +00001335 VisitTemplateDecl(D, false);
Richard Smithd25789a2013-09-18 01:36:02 +00001336}
1337
David Majnemerd9b1a4f2015-11-04 03:40:30 +00001338void ASTDumper::VisitBuiltinTemplateDecl(const BuiltinTemplateDecl *D) {
1339 dumpName(D);
1340 dumpTemplateParameters(D->getTemplateParameters());
1341}
1342
Richard Smithd25789a2013-09-18 01:36:02 +00001343void ASTDumper::VisitVarTemplateSpecializationDecl(
1344 const VarTemplateSpecializationDecl *D) {
1345 dumpTemplateArgumentList(D->getTemplateArgs());
1346 VisitVarDecl(D);
1347}
1348
1349void ASTDumper::VisitVarTemplatePartialSpecializationDecl(
1350 const VarTemplatePartialSpecializationDecl *D) {
1351 dumpTemplateParameters(D->getTemplateParameters());
1352 VisitVarTemplateSpecializationDecl(D);
1353}
1354
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001355void ASTDumper::VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001356 if (D->wasDeclaredWithTypename())
1357 OS << " typename";
1358 else
1359 OS << " class";
1360 if (D->isParameterPack())
1361 OS << " ...";
1362 dumpName(D);
Richard Smithf7514452014-10-30 21:02:37 +00001363 if (D->hasDefaultArgument())
Richard Smithecf74ff2014-03-23 20:50:39 +00001364 dumpTemplateArgument(D->getDefaultArgument());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001365}
1366
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001367void ASTDumper::VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001368 dumpType(D->getType());
1369 if (D->isParameterPack())
1370 OS << " ...";
1371 dumpName(D);
Richard Smithf7514452014-10-30 21:02:37 +00001372 if (D->hasDefaultArgument())
Richard Smithecf74ff2014-03-23 20:50:39 +00001373 dumpTemplateArgument(D->getDefaultArgument());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001374}
1375
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001376void ASTDumper::VisitTemplateTemplateParmDecl(
1377 const TemplateTemplateParmDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001378 if (D->isParameterPack())
1379 OS << " ...";
1380 dumpName(D);
1381 dumpTemplateParameters(D->getTemplateParameters());
Richard Smithf7514452014-10-30 21:02:37 +00001382 if (D->hasDefaultArgument())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001383 dumpTemplateArgumentLoc(D->getDefaultArgument());
1384}
1385
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001386void ASTDumper::VisitUsingDecl(const UsingDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001387 OS << ' ';
1388 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
1389 OS << D->getNameAsString();
1390}
1391
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001392void ASTDumper::VisitUnresolvedUsingTypenameDecl(
1393 const UnresolvedUsingTypenameDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001394 OS << ' ';
1395 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
1396 OS << D->getNameAsString();
1397}
1398
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001399void ASTDumper::VisitUnresolvedUsingValueDecl(const UnresolvedUsingValueDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001400 OS << ' ';
1401 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
1402 OS << D->getNameAsString();
1403 dumpType(D->getType());
1404}
1405
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001406void ASTDumper::VisitUsingShadowDecl(const UsingShadowDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001407 OS << ' ';
1408 dumpBareDeclRef(D->getTargetDecl());
1409}
1410
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001411void ASTDumper::VisitLinkageSpecDecl(const LinkageSpecDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001412 switch (D->getLanguage()) {
1413 case LinkageSpecDecl::lang_c: OS << " C"; break;
1414 case LinkageSpecDecl::lang_cxx: OS << " C++"; break;
1415 }
1416}
1417
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001418void ASTDumper::VisitAccessSpecDecl(const AccessSpecDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001419 OS << ' ';
1420 dumpAccessSpecifier(D->getAccess());
1421}
1422
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001423void ASTDumper::VisitFriendDecl(const FriendDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001424 if (TypeSourceInfo *T = D->getFriendType())
1425 dumpType(T->getType());
1426 else
1427 dumpDecl(D->getFriendDecl());
1428}
1429
1430//===----------------------------------------------------------------------===//
1431// Obj-C Declarations
1432//===----------------------------------------------------------------------===//
1433
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001434void ASTDumper::VisitObjCIvarDecl(const ObjCIvarDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001435 dumpName(D);
1436 dumpType(D->getType());
1437 if (D->getSynthesize())
1438 OS << " synthesize";
1439
1440 switch (D->getAccessControl()) {
1441 case ObjCIvarDecl::None:
1442 OS << " none";
1443 break;
1444 case ObjCIvarDecl::Private:
1445 OS << " private";
1446 break;
1447 case ObjCIvarDecl::Protected:
1448 OS << " protected";
1449 break;
1450 case ObjCIvarDecl::Public:
1451 OS << " public";
1452 break;
1453 case ObjCIvarDecl::Package:
1454 OS << " package";
1455 break;
1456 }
1457}
1458
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001459void ASTDumper::VisitObjCMethodDecl(const ObjCMethodDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001460 if (D->isInstanceMethod())
1461 OS << " -";
1462 else
1463 OS << " +";
1464 dumpName(D);
Alp Toker314cc812014-01-25 16:55:45 +00001465 dumpType(D->getReturnType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001466
Richard Trieude5cc7d2013-01-31 01:44:26 +00001467 if (D->isThisDeclarationADefinition()) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001468 dumpDeclContext(D);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001469 } else {
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001470 for (ObjCMethodDecl::param_const_iterator I = D->param_begin(),
1471 E = D->param_end();
Richard Smithf7514452014-10-30 21:02:37 +00001472 I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001473 dumpDecl(*I);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001474 }
1475
Richard Smithf7514452014-10-30 21:02:37 +00001476 if (D->isVariadic())
1477 dumpChild([=] { OS << "..."; });
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001478
Richard Smithf7514452014-10-30 21:02:37 +00001479 if (D->hasBody())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001480 dumpStmt(D->getBody());
1481}
1482
Douglas Gregor85f3f952015-07-07 03:57:15 +00001483void ASTDumper::VisitObjCTypeParamDecl(const ObjCTypeParamDecl *D) {
1484 dumpName(D);
Douglas Gregor1ac1b632015-07-07 03:58:54 +00001485 switch (D->getVariance()) {
1486 case ObjCTypeParamVariance::Invariant:
1487 break;
1488
1489 case ObjCTypeParamVariance::Covariant:
1490 OS << " covariant";
1491 break;
1492
1493 case ObjCTypeParamVariance::Contravariant:
1494 OS << " contravariant";
1495 break;
1496 }
1497
Douglas Gregor85f3f952015-07-07 03:57:15 +00001498 if (D->hasExplicitBound())
1499 OS << " bounded";
1500 dumpType(D->getUnderlyingType());
1501}
1502
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001503void ASTDumper::VisitObjCCategoryDecl(const ObjCCategoryDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001504 dumpName(D);
1505 dumpDeclRef(D->getClassInterface());
Douglas Gregor85f3f952015-07-07 03:57:15 +00001506 dumpObjCTypeParamList(D->getTypeParamList());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001507 dumpDeclRef(D->getImplementation());
1508 for (ObjCCategoryDecl::protocol_iterator I = D->protocol_begin(),
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001509 E = D->protocol_end();
Richard Smithf7514452014-10-30 21:02:37 +00001510 I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001511 dumpDeclRef(*I);
1512}
1513
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001514void ASTDumper::VisitObjCCategoryImplDecl(const ObjCCategoryImplDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001515 dumpName(D);
1516 dumpDeclRef(D->getClassInterface());
1517 dumpDeclRef(D->getCategoryDecl());
1518}
1519
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001520void ASTDumper::VisitObjCProtocolDecl(const ObjCProtocolDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001521 dumpName(D);
Richard Smithdcc2c452014-03-17 23:00:06 +00001522
Richard Smith7fcb35f2014-03-18 02:37:59 +00001523 for (auto *Child : D->protocols())
Richard Smithf7514452014-10-30 21:02:37 +00001524 dumpDeclRef(Child);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001525}
1526
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001527void ASTDumper::VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001528 dumpName(D);
Douglas Gregor85f3f952015-07-07 03:57:15 +00001529 dumpObjCTypeParamList(D->getTypeParamListAsWritten());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001530 dumpDeclRef(D->getSuperClass(), "super");
Richard Smithdcc2c452014-03-17 23:00:06 +00001531
Richard Smithf7514452014-10-30 21:02:37 +00001532 dumpDeclRef(D->getImplementation());
Richard Smith7fcb35f2014-03-18 02:37:59 +00001533 for (auto *Child : D->protocols())
Richard Smithf7514452014-10-30 21:02:37 +00001534 dumpDeclRef(Child);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001535}
1536
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001537void ASTDumper::VisitObjCImplementationDecl(const ObjCImplementationDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001538 dumpName(D);
1539 dumpDeclRef(D->getSuperClass(), "super");
1540 dumpDeclRef(D->getClassInterface());
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001541 for (ObjCImplementationDecl::init_const_iterator I = D->init_begin(),
1542 E = D->init_end();
Richard Smithf7514452014-10-30 21:02:37 +00001543 I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001544 dumpCXXCtorInitializer(*I);
1545}
1546
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001547void ASTDumper::VisitObjCCompatibleAliasDecl(const ObjCCompatibleAliasDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001548 dumpName(D);
1549 dumpDeclRef(D->getClassInterface());
1550}
1551
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001552void ASTDumper::VisitObjCPropertyDecl(const ObjCPropertyDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001553 dumpName(D);
1554 dumpType(D->getType());
1555
1556 if (D->getPropertyImplementation() == ObjCPropertyDecl::Required)
1557 OS << " required";
1558 else if (D->getPropertyImplementation() == ObjCPropertyDecl::Optional)
1559 OS << " optional";
1560
1561 ObjCPropertyDecl::PropertyAttributeKind Attrs = D->getPropertyAttributes();
1562 if (Attrs != ObjCPropertyDecl::OBJC_PR_noattr) {
1563 if (Attrs & ObjCPropertyDecl::OBJC_PR_readonly)
1564 OS << " readonly";
1565 if (Attrs & ObjCPropertyDecl::OBJC_PR_assign)
1566 OS << " assign";
1567 if (Attrs & ObjCPropertyDecl::OBJC_PR_readwrite)
1568 OS << " readwrite";
1569 if (Attrs & ObjCPropertyDecl::OBJC_PR_retain)
1570 OS << " retain";
1571 if (Attrs & ObjCPropertyDecl::OBJC_PR_copy)
1572 OS << " copy";
1573 if (Attrs & ObjCPropertyDecl::OBJC_PR_nonatomic)
1574 OS << " nonatomic";
1575 if (Attrs & ObjCPropertyDecl::OBJC_PR_atomic)
1576 OS << " atomic";
1577 if (Attrs & ObjCPropertyDecl::OBJC_PR_weak)
1578 OS << " weak";
1579 if (Attrs & ObjCPropertyDecl::OBJC_PR_strong)
1580 OS << " strong";
1581 if (Attrs & ObjCPropertyDecl::OBJC_PR_unsafe_unretained)
1582 OS << " unsafe_unretained";
Richard Smithf7514452014-10-30 21:02:37 +00001583 if (Attrs & ObjCPropertyDecl::OBJC_PR_getter)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001584 dumpDeclRef(D->getGetterMethodDecl(), "getter");
Richard Smithf7514452014-10-30 21:02:37 +00001585 if (Attrs & ObjCPropertyDecl::OBJC_PR_setter)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001586 dumpDeclRef(D->getSetterMethodDecl(), "setter");
1587 }
1588}
1589
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001590void ASTDumper::VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001591 dumpName(D->getPropertyDecl());
1592 if (D->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize)
1593 OS << " synthesize";
1594 else
1595 OS << " dynamic";
1596 dumpDeclRef(D->getPropertyDecl());
1597 dumpDeclRef(D->getPropertyIvarDecl());
1598}
1599
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001600void ASTDumper::VisitBlockDecl(const BlockDecl *D) {
Aaron Ballmanb2b8b1d2014-03-07 16:09:59 +00001601 for (auto I : D->params())
1602 dumpDecl(I);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001603
Richard Smithf7514452014-10-30 21:02:37 +00001604 if (D->isVariadic())
1605 dumpChild([=]{ OS << "..."; });
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001606
Richard Smithf7514452014-10-30 21:02:37 +00001607 if (D->capturesCXXThis())
1608 dumpChild([=]{ OS << "capture this"; });
1609
Aaron Ballman9371dd22014-03-14 18:34:04 +00001610 for (const auto &I : D->captures()) {
Richard Smithf7514452014-10-30 21:02:37 +00001611 dumpChild([=] {
1612 OS << "capture";
1613 if (I.isByRef())
1614 OS << " byref";
1615 if (I.isNested())
1616 OS << " nested";
1617 if (I.getVariable()) {
1618 OS << ' ';
1619 dumpBareDeclRef(I.getVariable());
1620 }
1621 if (I.hasCopyExpr())
1622 dumpStmt(I.getCopyExpr());
1623 });
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001624 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001625 dumpStmt(D->getBody());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001626}
1627
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001628//===----------------------------------------------------------------------===//
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001629// Stmt dumping methods.
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001630//===----------------------------------------------------------------------===//
1631
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001632void ASTDumper::dumpStmt(const Stmt *S) {
Richard Smithf7514452014-10-30 21:02:37 +00001633 dumpChild([=] {
1634 if (!S) {
1635 ColorScope Color(*this, NullColor);
1636 OS << "<<<NULL>>>";
1637 return;
1638 }
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001639
Richard Smithf7514452014-10-30 21:02:37 +00001640 if (const DeclStmt *DS = dyn_cast<DeclStmt>(S)) {
1641 VisitDeclStmt(DS);
1642 return;
1643 }
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001644
Richard Smithf7514452014-10-30 21:02:37 +00001645 ConstStmtVisitor<ASTDumper>::Visit(S);
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001646
Benjamin Kramer642f1732015-07-02 21:03:14 +00001647 for (const Stmt *SubStmt : S->children())
1648 dumpStmt(SubStmt);
Richard Smithf7514452014-10-30 21:02:37 +00001649 });
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001650}
1651
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001652void ASTDumper::VisitStmt(const Stmt *Node) {
Richard Trieud215b8d2013-01-26 01:31:20 +00001653 {
1654 ColorScope Color(*this, StmtColor);
1655 OS << Node->getStmtClassName();
1656 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001657 dumpPointer(Node);
1658 dumpSourceRange(Node->getSourceRange());
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001659}
1660
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001661void ASTDumper::VisitDeclStmt(const DeclStmt *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001662 VisitStmt(Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001663 for (DeclStmt::const_decl_iterator I = Node->decl_begin(),
1664 E = Node->decl_end();
Richard Smithf7514452014-10-30 21:02:37 +00001665 I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001666 dumpDecl(*I);
Ted Kremenek433a4922007-12-12 06:59:42 +00001667}
1668
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001669void ASTDumper::VisitAttributedStmt(const AttributedStmt *Node) {
Alexander Kornienko5bc364e2013-01-07 17:53:08 +00001670 VisitStmt(Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001671 for (ArrayRef<const Attr *>::iterator I = Node->getAttrs().begin(),
1672 E = Node->getAttrs().end();
Richard Smithf7514452014-10-30 21:02:37 +00001673 I != E; ++I)
Alexander Kornienko5bc364e2013-01-07 17:53:08 +00001674 dumpAttr(*I);
1675}
1676
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001677void ASTDumper::VisitLabelStmt(const LabelStmt *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001678 VisitStmt(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001679 OS << " '" << Node->getName() << "'";
Chris Lattnercbe4f772007-08-08 22:51:59 +00001680}
1681
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001682void ASTDumper::VisitGotoStmt(const GotoStmt *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001683 VisitStmt(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001684 OS << " '" << Node->getLabel()->getName() << "'";
1685 dumpPointer(Node->getLabel());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001686}
1687
Pavel Labath1ef83422013-09-04 14:35:00 +00001688void ASTDumper::VisitCXXCatchStmt(const CXXCatchStmt *Node) {
1689 VisitStmt(Node);
1690 dumpDecl(Node->getExceptionDecl());
1691}
1692
Chris Lattnercbe4f772007-08-08 22:51:59 +00001693//===----------------------------------------------------------------------===//
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001694// Expr dumping methods.
Chris Lattnercbe4f772007-08-08 22:51:59 +00001695//===----------------------------------------------------------------------===//
1696
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001697void ASTDumper::VisitExpr(const Expr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001698 VisitStmt(Node);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001699 dumpType(Node->getType());
1700
Richard Trieud215b8d2013-01-26 01:31:20 +00001701 {
1702 ColorScope Color(*this, ValueKindColor);
1703 switch (Node->getValueKind()) {
1704 case VK_RValue:
1705 break;
1706 case VK_LValue:
1707 OS << " lvalue";
1708 break;
1709 case VK_XValue:
1710 OS << " xvalue";
1711 break;
1712 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001713 }
1714
Richard Trieud215b8d2013-01-26 01:31:20 +00001715 {
1716 ColorScope Color(*this, ObjectKindColor);
1717 switch (Node->getObjectKind()) {
1718 case OK_Ordinary:
1719 break;
1720 case OK_BitField:
1721 OS << " bitfield";
1722 break;
1723 case OK_ObjCProperty:
1724 OS << " objcproperty";
1725 break;
1726 case OK_ObjCSubscript:
1727 OS << " objcsubscript";
1728 break;
1729 case OK_VectorComponent:
1730 OS << " vectorcomponent";
1731 break;
1732 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001733 }
Chris Lattnercbe4f772007-08-08 22:51:59 +00001734}
1735
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001736static void dumpBasePath(raw_ostream &OS, const CastExpr *Node) {
John McCallcf142162010-08-07 06:22:56 +00001737 if (Node->path_empty())
Anders Carlssona70cff62010-04-24 19:06:50 +00001738 return;
1739
1740 OS << " (";
1741 bool First = true;
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001742 for (CastExpr::path_const_iterator I = Node->path_begin(),
1743 E = Node->path_end();
1744 I != E; ++I) {
Anders Carlssona70cff62010-04-24 19:06:50 +00001745 const CXXBaseSpecifier *Base = *I;
1746 if (!First)
1747 OS << " -> ";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001748
Anders Carlssona70cff62010-04-24 19:06:50 +00001749 const CXXRecordDecl *RD =
1750 cast<CXXRecordDecl>(Base->getType()->getAs<RecordType>()->getDecl());
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001751
Anders Carlssona70cff62010-04-24 19:06:50 +00001752 if (Base->isVirtual())
1753 OS << "virtual ";
1754 OS << RD->getName();
1755 First = false;
1756 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001757
Anders Carlssona70cff62010-04-24 19:06:50 +00001758 OS << ')';
1759}
1760
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001761void ASTDumper::VisitCastExpr(const CastExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001762 VisitExpr(Node);
Richard Trieud215b8d2013-01-26 01:31:20 +00001763 OS << " <";
1764 {
1765 ColorScope Color(*this, CastColor);
1766 OS << Node->getCastKindName();
1767 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001768 dumpBasePath(OS, Node);
Anders Carlssona70cff62010-04-24 19:06:50 +00001769 OS << ">";
Anders Carlssond7923c62009-08-22 23:33:40 +00001770}
1771
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001772void ASTDumper::VisitDeclRefExpr(const DeclRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001773 VisitExpr(Node);
Ted Kremenek5f64ca82007-09-10 17:32:55 +00001774
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001775 OS << " ";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001776 dumpBareDeclRef(Node->getDecl());
Chandler Carruth8d26bb02011-05-01 23:48:14 +00001777 if (Node->getDecl() != Node->getFoundDecl()) {
1778 OS << " (";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001779 dumpBareDeclRef(Node->getFoundDecl());
Chandler Carruth8d26bb02011-05-01 23:48:14 +00001780 OS << ")";
1781 }
John McCall351762c2011-02-07 10:33:21 +00001782}
1783
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001784void ASTDumper::VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001785 VisitExpr(Node);
John McCall76d09942009-12-11 21:50:11 +00001786 OS << " (";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001787 if (!Node->requiresADL())
1788 OS << "no ";
Benjamin Kramerb11416d2010-04-17 09:33:03 +00001789 OS << "ADL) = '" << Node->getName() << '\'';
John McCall76d09942009-12-11 21:50:11 +00001790
1791 UnresolvedLookupExpr::decls_iterator
1792 I = Node->decls_begin(), E = Node->decls_end();
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001793 if (I == E)
1794 OS << " empty";
John McCall76d09942009-12-11 21:50:11 +00001795 for (; I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001796 dumpPointer(*I);
John McCall76d09942009-12-11 21:50:11 +00001797}
1798
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001799void ASTDumper::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001800 VisitExpr(Node);
Steve Naroff5d5efca2008-03-12 13:19:12 +00001801
Richard Trieud215b8d2013-01-26 01:31:20 +00001802 {
1803 ColorScope Color(*this, DeclKindNameColor);
1804 OS << " " << Node->getDecl()->getDeclKindName() << "Decl";
1805 }
1806 OS << "='" << *Node->getDecl() << "'";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001807 dumpPointer(Node->getDecl());
Steve Naroffb3424a92008-05-23 22:01:24 +00001808 if (Node->isFreeIvar())
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001809 OS << " isFreeIvar";
Steve Naroff5d5efca2008-03-12 13:19:12 +00001810}
1811
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001812void ASTDumper::VisitPredefinedExpr(const PredefinedExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001813 VisitExpr(Node);
Alexey Bataevec474782014-10-09 08:45:04 +00001814 OS << " " << PredefinedExpr::getIdentTypeName(Node->getIdentType());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001815}
1816
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001817void ASTDumper::VisitCharacterLiteral(const CharacterLiteral *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001818 VisitExpr(Node);
Richard Trieud215b8d2013-01-26 01:31:20 +00001819 ColorScope Color(*this, ValueColor);
Richard Trieu364ee422011-11-03 23:56:23 +00001820 OS << " " << Node->getValue();
Chris Lattnercbe4f772007-08-08 22:51:59 +00001821}
1822
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001823void ASTDumper::VisitIntegerLiteral(const IntegerLiteral *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001824 VisitExpr(Node);
Chris Lattnercbe4f772007-08-08 22:51:59 +00001825
1826 bool isSigned = Node->getType()->isSignedIntegerType();
Richard Trieud215b8d2013-01-26 01:31:20 +00001827 ColorScope Color(*this, ValueColor);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001828 OS << " " << Node->getValue().toString(10, isSigned);
Chris Lattnercbe4f772007-08-08 22:51:59 +00001829}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001830
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001831void ASTDumper::VisitFloatingLiteral(const FloatingLiteral *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001832 VisitExpr(Node);
Richard Trieud215b8d2013-01-26 01:31:20 +00001833 ColorScope Color(*this, ValueColor);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001834 OS << " " << Node->getValueAsApproximateDouble();
Chris Lattnercbe4f772007-08-08 22:51:59 +00001835}
Chris Lattner1c20a172007-08-26 03:42:43 +00001836
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001837void ASTDumper::VisitStringLiteral(const StringLiteral *Str) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001838 VisitExpr(Str);
Richard Trieud215b8d2013-01-26 01:31:20 +00001839 ColorScope Color(*this, ValueColor);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001840 OS << " ";
Richard Trieudc355912012-06-13 20:25:24 +00001841 Str->outputString(OS);
Chris Lattnercbe4f772007-08-08 22:51:59 +00001842}
Chris Lattner84ca3762007-08-30 01:00:35 +00001843
Richard Smithf0514962014-06-03 08:24:28 +00001844void ASTDumper::VisitInitListExpr(const InitListExpr *ILE) {
1845 VisitExpr(ILE);
1846 if (auto *Filler = ILE->getArrayFiller()) {
Richard Smithf7514452014-10-30 21:02:37 +00001847 dumpChild([=] {
1848 OS << "array filler";
1849 dumpStmt(Filler);
1850 });
Richard Smithf0514962014-06-03 08:24:28 +00001851 }
1852 if (auto *Field = ILE->getInitializedFieldInUnion()) {
1853 OS << " field ";
1854 dumpBareDeclRef(Field);
1855 }
1856}
1857
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001858void ASTDumper::VisitUnaryOperator(const UnaryOperator *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001859 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001860 OS << " " << (Node->isPostfix() ? "postfix" : "prefix")
1861 << " '" << UnaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
Chris Lattnercbe4f772007-08-08 22:51:59 +00001862}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001863
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001864void ASTDumper::VisitUnaryExprOrTypeTraitExpr(
1865 const UnaryExprOrTypeTraitExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001866 VisitExpr(Node);
Peter Collingbournee190dee2011-03-11 19:24:49 +00001867 switch(Node->getKind()) {
1868 case UETT_SizeOf:
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001869 OS << " sizeof";
Peter Collingbournee190dee2011-03-11 19:24:49 +00001870 break;
1871 case UETT_AlignOf:
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001872 OS << " alignof";
Peter Collingbournee190dee2011-03-11 19:24:49 +00001873 break;
1874 case UETT_VecStep:
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001875 OS << " vec_step";
Peter Collingbournee190dee2011-03-11 19:24:49 +00001876 break;
Alexey Bataev00396512015-07-02 03:40:19 +00001877 case UETT_OpenMPRequiredSimdAlign:
1878 OS << " __builtin_omp_required_simd_align";
1879 break;
Peter Collingbournee190dee2011-03-11 19:24:49 +00001880 }
Sebastian Redl6f282892008-11-11 17:56:53 +00001881 if (Node->isArgumentType())
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001882 dumpType(Node->getArgumentType());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001883}
Chris Lattnerdb3b3ff2007-08-09 17:35:30 +00001884
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001885void ASTDumper::VisitMemberExpr(const MemberExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001886 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001887 OS << " " << (Node->isArrow() ? "->" : ".") << *Node->getMemberDecl();
1888 dumpPointer(Node->getMemberDecl());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001889}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001890
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001891void ASTDumper::VisitExtVectorElementExpr(const ExtVectorElementExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001892 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001893 OS << " " << Node->getAccessor().getNameStart();
Chris Lattnercbe4f772007-08-08 22:51:59 +00001894}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001895
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001896void ASTDumper::VisitBinaryOperator(const BinaryOperator *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001897 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001898 OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
Chris Lattner86928112007-08-25 02:00:02 +00001899}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001900
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001901void ASTDumper::VisitCompoundAssignOperator(
1902 const CompoundAssignOperator *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001903 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001904 OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode())
1905 << "' ComputeLHSTy=";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001906 dumpBareType(Node->getComputationLHSType());
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001907 OS << " ComputeResultTy=";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001908 dumpBareType(Node->getComputationResultType());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001909}
Chris Lattnercbe4f772007-08-08 22:51:59 +00001910
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001911void ASTDumper::VisitBlockExpr(const BlockExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001912 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001913 dumpDecl(Node->getBlockDecl());
John McCall351762c2011-02-07 10:33:21 +00001914}
1915
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001916void ASTDumper::VisitOpaqueValueExpr(const OpaqueValueExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001917 VisitExpr(Node);
John McCallfe96e0b2011-11-06 09:01:30 +00001918
Richard Smithf7514452014-10-30 21:02:37 +00001919 if (Expr *Source = Node->getSourceExpr())
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001920 dumpStmt(Source);
John McCallfe96e0b2011-11-06 09:01:30 +00001921}
1922
Chris Lattnercbe4f772007-08-08 22:51:59 +00001923// GNU extensions.
1924
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001925void ASTDumper::VisitAddrLabelExpr(const AddrLabelExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001926 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001927 OS << " " << Node->getLabel()->getName();
1928 dumpPointer(Node->getLabel());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001929}
1930
Chris Lattner8f184b12007-08-09 18:03:18 +00001931//===----------------------------------------------------------------------===//
1932// C++ Expressions
1933//===----------------------------------------------------------------------===//
Chris Lattnercbe4f772007-08-08 22:51:59 +00001934
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001935void ASTDumper::VisitCXXNamedCastExpr(const CXXNamedCastExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001936 VisitExpr(Node);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001937 OS << " " << Node->getCastName()
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001938 << "<" << Node->getTypeAsWritten().getAsString() << ">"
Anders Carlssona70cff62010-04-24 19:06:50 +00001939 << " <" << Node->getCastKindName();
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001940 dumpBasePath(OS, Node);
Anders Carlssona70cff62010-04-24 19:06:50 +00001941 OS << ">";
Chris Lattnercbe4f772007-08-08 22:51:59 +00001942}
1943
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001944void ASTDumper::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001945 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001946 OS << " " << (Node->getValue() ? "true" : "false");
Chris Lattnercbe4f772007-08-08 22:51:59 +00001947}
1948
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001949void ASTDumper::VisitCXXThisExpr(const CXXThisExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001950 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001951 OS << " this";
Douglas Gregor8ea1f532008-11-04 14:56:14 +00001952}
1953
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001954void ASTDumper::VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001955 VisitExpr(Node);
Eli Friedman29538892011-09-02 17:38:59 +00001956 OS << " functional cast to " << Node->getTypeAsWritten().getAsString()
1957 << " <" << Node->getCastKindName() << ">";
Douglas Gregore200adc2008-10-27 19:41:14 +00001958}
1959
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001960void ASTDumper::VisitCXXConstructExpr(const CXXConstructExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001961 VisitExpr(Node);
John McCalleba90cd2010-02-02 19:03:45 +00001962 CXXConstructorDecl *Ctor = Node->getConstructor();
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001963 dumpType(Ctor->getType());
Anders Carlsson073846832009-08-12 00:21:52 +00001964 if (Node->isElidable())
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001965 OS << " elidable";
John McCall85370042010-08-07 06:38:55 +00001966 if (Node->requiresZeroInitialization())
1967 OS << " zeroing";
Anders Carlsson073846832009-08-12 00:21:52 +00001968}
1969
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001970void ASTDumper::VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001971 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001972 OS << " ";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001973 dumpCXXTemporary(Node->getTemporary());
Anders Carlsson073846832009-08-12 00:21:52 +00001974}
1975
Reid Kleckner5c682bc2015-03-19 18:09:25 +00001976void ASTDumper::VisitCXXNewExpr(const CXXNewExpr *Node) {
1977 VisitExpr(Node);
Reid Kleckner5c682bc2015-03-19 18:09:25 +00001978 if (Node->isGlobalNew())
Reid Kleckner461c0c62015-03-19 18:47:47 +00001979 OS << " global";
Reid Kleckner5c682bc2015-03-19 18:09:25 +00001980 if (Node->isArray())
Reid Kleckner461c0c62015-03-19 18:47:47 +00001981 OS << " array";
1982 if (Node->getOperatorNew()) {
1983 OS << ' ';
1984 dumpBareDeclRef(Node->getOperatorNew());
1985 }
Reid Kleckner5c682bc2015-03-19 18:09:25 +00001986 // We could dump the deallocation function used in case of error, but it's
1987 // usually not that interesting.
1988}
1989
1990void ASTDumper::VisitCXXDeleteExpr(const CXXDeleteExpr *Node) {
1991 VisitExpr(Node);
Reid Kleckner5c682bc2015-03-19 18:09:25 +00001992 if (Node->isGlobalDelete())
Reid Kleckner461c0c62015-03-19 18:47:47 +00001993 OS << " global";
Reid Kleckner5c682bc2015-03-19 18:09:25 +00001994 if (Node->isArrayForm())
Reid Kleckner461c0c62015-03-19 18:47:47 +00001995 OS << " array";
1996 if (Node->getOperatorDelete()) {
1997 OS << ' ';
1998 dumpBareDeclRef(Node->getOperatorDelete());
1999 }
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002000}
2001
Richard Smithe6c01442013-06-05 00:46:14 +00002002void
2003ASTDumper::VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *Node) {
2004 VisitExpr(Node);
2005 if (const ValueDecl *VD = Node->getExtendingDecl()) {
2006 OS << " extended by ";
2007 dumpBareDeclRef(VD);
2008 }
2009}
2010
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002011void ASTDumper::VisitExprWithCleanups(const ExprWithCleanups *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002012 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002013 for (unsigned i = 0, e = Node->getNumObjects(); i != e; ++i)
2014 dumpDeclRef(Node->getObject(i), "cleanup");
Anders Carlsson073846832009-08-12 00:21:52 +00002015}
2016
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002017void ASTDumper::dumpCXXTemporary(const CXXTemporary *Temporary) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002018 OS << "(CXXTemporary";
2019 dumpPointer(Temporary);
2020 OS << ")";
Anders Carlsson073846832009-08-12 00:21:52 +00002021}
2022
Serge Pavlov6b926032015-02-16 19:58:41 +00002023void ASTDumper::VisitSizeOfPackExpr(const SizeOfPackExpr *Node) {
2024 VisitExpr(Node);
2025 dumpPointer(Node->getPack());
2026 dumpName(Node->getPack());
Richard Smithd784e682015-09-23 21:41:42 +00002027 if (Node->isPartiallySubstituted())
2028 for (const auto &A : Node->getPartialArguments())
2029 dumpTemplateArgument(A);
Serge Pavlov6b926032015-02-16 19:58:41 +00002030}
2031
2032
Anders Carlsson76f4a902007-08-21 17:43:55 +00002033//===----------------------------------------------------------------------===//
2034// Obj-C Expressions
2035//===----------------------------------------------------------------------===//
2036
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002037void ASTDumper::VisitObjCMessageExpr(const ObjCMessageExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002038 VisitExpr(Node);
Aaron Ballmanb190f972014-01-03 17:59:55 +00002039 OS << " selector=";
2040 Node->getSelector().print(OS);
Douglas Gregor9a129192010-04-21 00:45:42 +00002041 switch (Node->getReceiverKind()) {
2042 case ObjCMessageExpr::Instance:
2043 break;
2044
2045 case ObjCMessageExpr::Class:
2046 OS << " class=";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002047 dumpBareType(Node->getClassReceiver());
Douglas Gregor9a129192010-04-21 00:45:42 +00002048 break;
2049
2050 case ObjCMessageExpr::SuperInstance:
2051 OS << " super (instance)";
2052 break;
2053
2054 case ObjCMessageExpr::SuperClass:
2055 OS << " super (class)";
2056 break;
2057 }
Ted Kremenek36748da2008-02-29 22:04:05 +00002058}
2059
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002060void ASTDumper::VisitObjCBoxedExpr(const ObjCBoxedExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002061 VisitExpr(Node);
Aaron Ballmanb190f972014-01-03 17:59:55 +00002062 OS << " selector=";
2063 Node->getBoxingMethod()->getSelector().print(OS);
Argyrios Kyrtzidis9dd40892012-05-10 20:02:31 +00002064}
2065
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002066void ASTDumper::VisitObjCAtCatchStmt(const ObjCAtCatchStmt *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002067 VisitStmt(Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002068 if (const VarDecl *CatchParam = Node->getCatchParamDecl())
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002069 dumpDecl(CatchParam);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002070 else
Douglas Gregor96c79492010-04-23 22:50:49 +00002071 OS << " catch all";
Douglas Gregor96c79492010-04-23 22:50:49 +00002072}
2073
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002074void ASTDumper::VisitObjCEncodeExpr(const ObjCEncodeExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002075 VisitExpr(Node);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002076 dumpType(Node->getEncodedType());
Anders Carlssonc5a81eb2007-08-22 15:14:15 +00002077}
2078
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002079void ASTDumper::VisitObjCSelectorExpr(const ObjCSelectorExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002080 VisitExpr(Node);
Mike Stump11289f42009-09-09 15:08:12 +00002081
Aaron Ballmanb190f972014-01-03 17:59:55 +00002082 OS << " ";
2083 Node->getSelector().print(OS);
Fariborz Jahanian4bef4622007-10-16 20:40:23 +00002084}
2085
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002086void ASTDumper::VisitObjCProtocolExpr(const ObjCProtocolExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002087 VisitExpr(Node);
Mike Stump11289f42009-09-09 15:08:12 +00002088
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002089 OS << ' ' << *Node->getProtocol();
Fariborz Jahaniana32aaef2007-10-17 16:58:11 +00002090}
Daniel Dunbar4b8c6db2008-08-30 05:35:15 +00002091
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002092void ASTDumper::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002093 VisitExpr(Node);
John McCallb7bd14f2010-12-02 01:19:52 +00002094 if (Node->isImplicitProperty()) {
Fariborz Jahanian0f0b3022010-12-22 19:46:35 +00002095 OS << " Kind=MethodRef Getter=\"";
2096 if (Node->getImplicitPropertyGetter())
Aaron Ballmanb190f972014-01-03 17:59:55 +00002097 Node->getImplicitPropertyGetter()->getSelector().print(OS);
Fariborz Jahanian0f0b3022010-12-22 19:46:35 +00002098 else
2099 OS << "(null)";
2100
2101 OS << "\" Setter=\"";
John McCallb7bd14f2010-12-02 01:19:52 +00002102 if (ObjCMethodDecl *Setter = Node->getImplicitPropertySetter())
Aaron Ballmanb190f972014-01-03 17:59:55 +00002103 Setter->getSelector().print(OS);
John McCallb7bd14f2010-12-02 01:19:52 +00002104 else
2105 OS << "(null)";
2106 OS << "\"";
2107 } else {
Benjamin Kramerb89514a2011-10-14 18:45:37 +00002108 OS << " Kind=PropertyRef Property=\"" << *Node->getExplicitProperty() <<'"';
John McCallb7bd14f2010-12-02 01:19:52 +00002109 }
Fariborz Jahanian8a1810f2008-11-22 18:39:36 +00002110
Fariborz Jahanian681c0752010-10-14 16:04:05 +00002111 if (Node->isSuperReceiver())
2112 OS << " super";
Argyrios Kyrtzidisab468b02012-03-30 00:19:18 +00002113
2114 OS << " Messaging=";
2115 if (Node->isMessagingGetter() && Node->isMessagingSetter())
2116 OS << "Getter&Setter";
2117 else if (Node->isMessagingGetter())
2118 OS << "Getter";
2119 else if (Node->isMessagingSetter())
2120 OS << "Setter";
Douglas Gregor8ea1f532008-11-04 14:56:14 +00002121}
2122
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002123void ASTDumper::VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002124 VisitExpr(Node);
Ted Kremeneke65b0862012-03-06 20:05:56 +00002125 if (Node->isArraySubscriptRefExpr())
2126 OS << " Kind=ArraySubscript GetterForArray=\"";
2127 else
2128 OS << " Kind=DictionarySubscript GetterForDictionary=\"";
2129 if (Node->getAtIndexMethodDecl())
Aaron Ballmanb190f972014-01-03 17:59:55 +00002130 Node->getAtIndexMethodDecl()->getSelector().print(OS);
Ted Kremeneke65b0862012-03-06 20:05:56 +00002131 else
2132 OS << "(null)";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002133
Ted Kremeneke65b0862012-03-06 20:05:56 +00002134 if (Node->isArraySubscriptRefExpr())
2135 OS << "\" SetterForArray=\"";
2136 else
2137 OS << "\" SetterForDictionary=\"";
2138 if (Node->setAtIndexMethodDecl())
Aaron Ballmanb190f972014-01-03 17:59:55 +00002139 Node->setAtIndexMethodDecl()->getSelector().print(OS);
Ted Kremeneke65b0862012-03-06 20:05:56 +00002140 else
2141 OS << "(null)";
2142}
2143
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002144void ASTDumper::VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002145 VisitExpr(Node);
Ted Kremeneke65b0862012-03-06 20:05:56 +00002146 OS << " " << (Node->getValue() ? "__objc_yes" : "__objc_no");
2147}
2148
Chris Lattnercbe4f772007-08-08 22:51:59 +00002149//===----------------------------------------------------------------------===//
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002150// Comments
2151//===----------------------------------------------------------------------===//
2152
2153const char *ASTDumper::getCommandName(unsigned CommandID) {
2154 if (Traits)
2155 return Traits->getCommandInfo(CommandID)->Name;
2156 const CommandInfo *Info = CommandTraits::getBuiltinCommandInfo(CommandID);
2157 if (Info)
2158 return Info->Name;
2159 return "<not a builtin command>";
2160}
2161
2162void ASTDumper::dumpFullComment(const FullComment *C) {
2163 if (!C)
2164 return;
2165
2166 FC = C;
2167 dumpComment(C);
Craig Topper36250ad2014-05-12 05:36:57 +00002168 FC = nullptr;
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002169}
2170
2171void ASTDumper::dumpComment(const Comment *C) {
Richard Smithf7514452014-10-30 21:02:37 +00002172 dumpChild([=] {
2173 if (!C) {
2174 ColorScope Color(*this, NullColor);
2175 OS << "<<<NULL>>>";
2176 return;
2177 }
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002178
Richard Smithf7514452014-10-30 21:02:37 +00002179 {
2180 ColorScope Color(*this, CommentColor);
2181 OS << C->getCommentKindName();
2182 }
2183 dumpPointer(C);
2184 dumpSourceRange(C->getSourceRange());
2185 ConstCommentVisitor<ASTDumper>::visit(C);
2186 for (Comment::child_iterator I = C->child_begin(), E = C->child_end();
2187 I != E; ++I)
2188 dumpComment(*I);
2189 });
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002190}
2191
2192void ASTDumper::visitTextComment(const TextComment *C) {
2193 OS << " Text=\"" << C->getText() << "\"";
2194}
2195
2196void ASTDumper::visitInlineCommandComment(const InlineCommandComment *C) {
2197 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\"";
2198 switch (C->getRenderKind()) {
2199 case InlineCommandComment::RenderNormal:
2200 OS << " RenderNormal";
2201 break;
2202 case InlineCommandComment::RenderBold:
2203 OS << " RenderBold";
2204 break;
2205 case InlineCommandComment::RenderMonospaced:
2206 OS << " RenderMonospaced";
2207 break;
2208 case InlineCommandComment::RenderEmphasized:
2209 OS << " RenderEmphasized";
2210 break;
2211 }
2212
2213 for (unsigned i = 0, e = C->getNumArgs(); i != e; ++i)
2214 OS << " Arg[" << i << "]=\"" << C->getArgText(i) << "\"";
2215}
2216
2217void ASTDumper::visitHTMLStartTagComment(const HTMLStartTagComment *C) {
2218 OS << " Name=\"" << C->getTagName() << "\"";
2219 if (C->getNumAttrs() != 0) {
2220 OS << " Attrs: ";
2221 for (unsigned i = 0, e = C->getNumAttrs(); i != e; ++i) {
2222 const HTMLStartTagComment::Attribute &Attr = C->getAttr(i);
2223 OS << " \"" << Attr.Name << "=\"" << Attr.Value << "\"";
2224 }
2225 }
2226 if (C->isSelfClosing())
2227 OS << " SelfClosing";
2228}
2229
2230void ASTDumper::visitHTMLEndTagComment(const HTMLEndTagComment *C) {
2231 OS << " Name=\"" << C->getTagName() << "\"";
2232}
2233
2234void ASTDumper::visitBlockCommandComment(const BlockCommandComment *C) {
2235 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\"";
2236 for (unsigned i = 0, e = C->getNumArgs(); i != e; ++i)
2237 OS << " Arg[" << i << "]=\"" << C->getArgText(i) << "\"";
2238}
2239
2240void ASTDumper::visitParamCommandComment(const ParamCommandComment *C) {
2241 OS << " " << ParamCommandComment::getDirectionAsString(C->getDirection());
2242
2243 if (C->isDirectionExplicit())
2244 OS << " explicitly";
2245 else
2246 OS << " implicitly";
2247
2248 if (C->hasParamName()) {
2249 if (C->isParamIndexValid())
2250 OS << " Param=\"" << C->getParamName(FC) << "\"";
2251 else
2252 OS << " Param=\"" << C->getParamNameAsWritten() << "\"";
2253 }
2254
Dmitri Gribenkodbff5c72014-03-19 14:03:47 +00002255 if (C->isParamIndexValid() && !C->isVarArgParam())
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002256 OS << " ParamIndex=" << C->getParamIndex();
2257}
2258
2259void ASTDumper::visitTParamCommandComment(const TParamCommandComment *C) {
2260 if (C->hasParamName()) {
2261 if (C->isPositionValid())
2262 OS << " Param=\"" << C->getParamName(FC) << "\"";
2263 else
2264 OS << " Param=\"" << C->getParamNameAsWritten() << "\"";
2265 }
2266
2267 if (C->isPositionValid()) {
2268 OS << " Position=<";
2269 for (unsigned i = 0, e = C->getDepth(); i != e; ++i) {
2270 OS << C->getIndex(i);
2271 if (i != e - 1)
2272 OS << ", ";
2273 }
2274 OS << ">";
2275 }
2276}
2277
2278void ASTDumper::visitVerbatimBlockComment(const VerbatimBlockComment *C) {
2279 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\""
2280 " CloseName=\"" << C->getCloseName() << "\"";
2281}
2282
2283void ASTDumper::visitVerbatimBlockLineComment(
2284 const VerbatimBlockLineComment *C) {
2285 OS << " Text=\"" << C->getText() << "\"";
2286}
2287
2288void ASTDumper::visitVerbatimLineComment(const VerbatimLineComment *C) {
2289 OS << " Text=\"" << C->getText() << "\"";
2290}
2291
2292//===----------------------------------------------------------------------===//
Richard Smithd5e7ff82014-10-31 01:17:45 +00002293// Type method implementations
2294//===----------------------------------------------------------------------===//
2295
2296void QualType::dump(const char *msg) const {
2297 if (msg)
2298 llvm::errs() << msg << ": ";
2299 dump();
2300}
2301
2302LLVM_DUMP_METHOD void QualType::dump() const {
2303 ASTDumper Dumper(llvm::errs(), nullptr, nullptr);
2304 Dumper.dumpTypeAsChild(*this);
2305}
2306
2307LLVM_DUMP_METHOD void Type::dump() const { QualType(this, 0).dump(); }
2308
2309//===----------------------------------------------------------------------===//
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002310// Decl method implementations
2311//===----------------------------------------------------------------------===//
2312
Alp Tokeref6b0072014-01-04 13:47:14 +00002313LLVM_DUMP_METHOD void Decl::dump() const { dump(llvm::errs()); }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002314
Alp Tokeref6b0072014-01-04 13:47:14 +00002315LLVM_DUMP_METHOD void Decl::dump(raw_ostream &OS) const {
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002316 ASTDumper P(OS, &getASTContext().getCommentCommandTraits(),
2317 &getASTContext().getSourceManager());
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002318 P.dumpDecl(this);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002319}
2320
Alp Tokeref6b0072014-01-04 13:47:14 +00002321LLVM_DUMP_METHOD void Decl::dumpColor() const {
Richard Trieud215b8d2013-01-26 01:31:20 +00002322 ASTDumper P(llvm::errs(), &getASTContext().getCommentCommandTraits(),
2323 &getASTContext().getSourceManager(), /*ShowColors*/true);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002324 P.dumpDecl(this);
Richard Trieud215b8d2013-01-26 01:31:20 +00002325}
Richard Smith33937e72013-06-22 21:49:40 +00002326
Alp Tokeref6b0072014-01-04 13:47:14 +00002327LLVM_DUMP_METHOD void DeclContext::dumpLookups() const {
Richard Smith6ea05822013-06-24 01:45:33 +00002328 dumpLookups(llvm::errs());
2329}
2330
Richard Smith35f986d2014-08-11 22:11:07 +00002331LLVM_DUMP_METHOD void DeclContext::dumpLookups(raw_ostream &OS,
2332 bool DumpDecls) const {
Richard Smith33937e72013-06-22 21:49:40 +00002333 const DeclContext *DC = this;
2334 while (!DC->isTranslationUnit())
2335 DC = DC->getParent();
2336 ASTContext &Ctx = cast<TranslationUnitDecl>(DC)->getASTContext();
Richard Smith6ea05822013-06-24 01:45:33 +00002337 ASTDumper P(OS, &Ctx.getCommentCommandTraits(), &Ctx.getSourceManager());
Richard Smith35f986d2014-08-11 22:11:07 +00002338 P.dumpLookups(this, DumpDecls);
Richard Smith33937e72013-06-22 21:49:40 +00002339}
2340
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002341//===----------------------------------------------------------------------===//
Chris Lattnercbe4f772007-08-08 22:51:59 +00002342// Stmt method implementations
2343//===----------------------------------------------------------------------===//
2344
Alp Tokeref6b0072014-01-04 13:47:14 +00002345LLVM_DUMP_METHOD void Stmt::dump(SourceManager &SM) const {
Argyrios Kyrtzidisc049f752010-08-09 10:54:31 +00002346 dump(llvm::errs(), SM);
2347}
2348
Alp Tokeref6b0072014-01-04 13:47:14 +00002349LLVM_DUMP_METHOD void Stmt::dump(raw_ostream &OS, SourceManager &SM) const {
Craig Topper36250ad2014-05-12 05:36:57 +00002350 ASTDumper P(OS, nullptr, &SM);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002351 P.dumpStmt(this);
Chris Lattner779d5d92007-08-30 00:40:08 +00002352}
2353
Faisal Vali2da8ed92015-03-22 13:35:56 +00002354LLVM_DUMP_METHOD void Stmt::dump(raw_ostream &OS) const {
2355 ASTDumper P(OS, nullptr, nullptr);
2356 P.dumpStmt(this);
2357}
2358
Alp Tokeref6b0072014-01-04 13:47:14 +00002359LLVM_DUMP_METHOD void Stmt::dump() const {
Craig Topper36250ad2014-05-12 05:36:57 +00002360 ASTDumper P(llvm::errs(), nullptr, nullptr);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002361 P.dumpStmt(this);
Chris Lattnercbe4f772007-08-08 22:51:59 +00002362}
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002363
Alp Tokeref6b0072014-01-04 13:47:14 +00002364LLVM_DUMP_METHOD void Stmt::dumpColor() const {
Craig Topper36250ad2014-05-12 05:36:57 +00002365 ASTDumper P(llvm::errs(), nullptr, nullptr, /*ShowColors*/true);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002366 P.dumpStmt(this);
Richard Trieud215b8d2013-01-26 01:31:20 +00002367}
2368
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002369//===----------------------------------------------------------------------===//
2370// Comment method implementations
2371//===----------------------------------------------------------------------===//
2372
Craig Topper36250ad2014-05-12 05:36:57 +00002373LLVM_DUMP_METHOD void Comment::dump() const {
2374 dump(llvm::errs(), nullptr, nullptr);
2375}
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002376
Alp Tokeref6b0072014-01-04 13:47:14 +00002377LLVM_DUMP_METHOD void Comment::dump(const ASTContext &Context) const {
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002378 dump(llvm::errs(), &Context.getCommentCommandTraits(),
2379 &Context.getSourceManager());
2380}
2381
Alexander Kornienko00911f12013-01-15 12:20:21 +00002382void Comment::dump(raw_ostream &OS, const CommandTraits *Traits,
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002383 const SourceManager *SM) const {
2384 const FullComment *FC = dyn_cast<FullComment>(this);
2385 ASTDumper D(OS, Traits, SM);
2386 D.dumpFullComment(FC);
2387}
Richard Trieud215b8d2013-01-26 01:31:20 +00002388
Alp Tokeref6b0072014-01-04 13:47:14 +00002389LLVM_DUMP_METHOD void Comment::dumpColor() const {
Richard Trieud215b8d2013-01-26 01:31:20 +00002390 const FullComment *FC = dyn_cast<FullComment>(this);
Craig Topper36250ad2014-05-12 05:36:57 +00002391 ASTDumper D(llvm::errs(), nullptr, nullptr, /*ShowColors*/true);
Richard Trieud215b8d2013-01-26 01:31:20 +00002392 D.dumpFullComment(FC);
2393}