blob: 3dec23d0065308b2cb7e248e8962a5bec9461714 [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"
Alexander Kornienko90ff6072012-12-20 02:09:13 +000024#include "clang/Basic/Module.h"
Chris Lattner11e30d32007-08-30 06:17:34 +000025#include "clang/Basic/SourceManager.h"
Daniel Dunbar34a96c82009-12-03 09:13:13 +000026#include "llvm/Support/raw_ostream.h"
Chris Lattnercbe4f772007-08-08 22:51:59 +000027using namespace clang;
Alexander Kornienkoebc17b52013-01-14 14:07:11 +000028using namespace clang::comments;
Chris Lattnercbe4f772007-08-08 22:51:59 +000029
30//===----------------------------------------------------------------------===//
Alexander Kornienko18ec81b2012-12-13 13:59:55 +000031// ASTDumper Visitor
Chris Lattnercbe4f772007-08-08 22:51:59 +000032//===----------------------------------------------------------------------===//
33
34namespace {
Richard Trieud215b8d2013-01-26 01:31:20 +000035 // Colors used for various parts of the AST dump
Richard Trieu532018f2014-03-06 01:09:03 +000036 // Do not use bold yellow for any text. It is hard to read on white screens.
Richard Trieud215b8d2013-01-26 01:31:20 +000037
38 struct TerminalColor {
39 raw_ostream::Colors Color;
40 bool Bold;
41 };
42
Richard Trieu532018f2014-03-06 01:09:03 +000043 // Red - CastColor
44 // Green - TypeColor
45 // Bold Green - DeclKindNameColor, UndeserializedColor
46 // Yellow - AddressColor, LocationColor
47 // Blue - CommentColor, NullColor, IndentColor
48 // Bold Blue - AttrColor
49 // Bold Magenta - StmtColor
50 // Cyan - ValueKindColor, ObjectKindColor
51 // Bold Cyan - ValueColor, DeclNameColor
52
Richard Trieud215b8d2013-01-26 01:31:20 +000053 // Decl kind names (VarDecl, FunctionDecl, etc)
54 static const TerminalColor DeclKindNameColor = { raw_ostream::GREEN, true };
55 // Attr names (CleanupAttr, GuardedByAttr, etc)
56 static const TerminalColor AttrColor = { raw_ostream::BLUE, true };
57 // Statement names (DeclStmt, ImplicitCastExpr, etc)
58 static const TerminalColor StmtColor = { raw_ostream::MAGENTA, true };
59 // Comment names (FullComment, ParagraphComment, TextComment, etc)
Richard Trieu532018f2014-03-06 01:09:03 +000060 static const TerminalColor CommentColor = { raw_ostream::BLUE, false };
Richard Trieud215b8d2013-01-26 01:31:20 +000061
62 // Type names (int, float, etc, plus user defined types)
63 static const TerminalColor TypeColor = { raw_ostream::GREEN, false };
64
65 // Pointer address
66 static const TerminalColor AddressColor = { raw_ostream::YELLOW, false };
67 // Source locations
68 static const TerminalColor LocationColor = { raw_ostream::YELLOW, false };
69
70 // lvalue/xvalue
71 static const TerminalColor ValueKindColor = { raw_ostream::CYAN, false };
72 // bitfield/objcproperty/objcsubscript/vectorcomponent
73 static const TerminalColor ObjectKindColor = { raw_ostream::CYAN, false };
74
75 // Null statements
76 static const TerminalColor NullColor = { raw_ostream::BLUE, false };
77
Richard Smith1d209d02013-05-23 01:49:11 +000078 // Undeserialized entities
79 static const TerminalColor UndeserializedColor = { raw_ostream::GREEN, true };
80
Richard Trieud215b8d2013-01-26 01:31:20 +000081 // CastKind from CastExpr's
82 static const TerminalColor CastColor = { raw_ostream::RED, false };
83
84 // Value of the statement
85 static const TerminalColor ValueColor = { raw_ostream::CYAN, true };
86 // Decl names
87 static const TerminalColor DeclNameColor = { raw_ostream::CYAN, true };
88
Richard Trieude5cc7d2013-01-31 01:44:26 +000089 // Indents ( `, -. | )
90 static const TerminalColor IndentColor = { raw_ostream::BLUE, false };
91
Alexander Kornienko90ff6072012-12-20 02:09:13 +000092 class ASTDumper
Alexander Kornienko540bacb2013-02-01 12:35:51 +000093 : public ConstDeclVisitor<ASTDumper>, public ConstStmtVisitor<ASTDumper>,
Richard Smithd5e7ff82014-10-31 01:17:45 +000094 public ConstCommentVisitor<ASTDumper>, public TypeVisitor<ASTDumper> {
Chris Lattner0e62c1c2011-07-23 10:55:15 +000095 raw_ostream &OS;
Alexander Kornienkoebc17b52013-01-14 14:07:11 +000096 const CommandTraits *Traits;
97 const SourceManager *SM;
Mike Stump11289f42009-09-09 15:08:12 +000098
Richard Smithf7514452014-10-30 21:02:37 +000099 /// Pending[i] is an action to dump an entity at level i.
100 llvm::SmallVector<std::function<void(bool isLastChild)>, 32> Pending;
Richard Trieude5cc7d2013-01-31 01:44:26 +0000101
Richard Smithf7514452014-10-30 21:02:37 +0000102 /// Indicates whether we're at the top level.
103 bool TopLevel;
Richard Trieude5cc7d2013-01-31 01:44:26 +0000104
Richard Smithf7514452014-10-30 21:02:37 +0000105 /// Indicates if we're handling the first child after entering a new depth.
106 bool FirstChild;
107
108 /// Prefix for currently-being-dumped entity.
109 std::string Prefix;
Richard Trieude5cc7d2013-01-31 01:44:26 +0000110
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000111 /// Keep track of the last location we print out so that we can
112 /// print out deltas from then on out.
Chris Lattner11e30d32007-08-30 06:17:34 +0000113 const char *LastLocFilename;
114 unsigned LastLocLine;
Douglas Gregor7de59662009-05-29 20:38:28 +0000115
Alexander Kornienkoebc17b52013-01-14 14:07:11 +0000116 /// The \c FullComment parent of the comment being dumped.
117 const FullComment *FC;
118
Richard Trieud215b8d2013-01-26 01:31:20 +0000119 bool ShowColors;
120
Richard Smithf7514452014-10-30 21:02:37 +0000121 /// Dump a child of the current node.
122 template<typename Fn> void dumpChild(Fn doDumpChild) {
123 // If we're at the top level, there's nothing interesting to do; just
124 // run the dumper.
125 if (TopLevel) {
126 TopLevel = false;
127 doDumpChild();
128 while (!Pending.empty()) {
129 Pending.back()(true);
130 Pending.pop_back();
131 }
132 Prefix.clear();
133 OS << "\n";
134 TopLevel = true;
135 return;
Manuel Klimek874030e2012-11-07 00:33:12 +0000136 }
Richard Smithf7514452014-10-30 21:02:37 +0000137
138 const FullComment *OrigFC = FC;
139 auto dumpWithIndent = [this, doDumpChild, OrigFC](bool isLastChild) {
140 // Print out the appropriate tree structure and work out the prefix for
141 // children of this node. For instance:
142 //
143 // A Prefix = ""
144 // |-B Prefix = "| "
145 // | `-C Prefix = "| "
146 // `-D Prefix = " "
147 // |-E Prefix = " | "
148 // `-F Prefix = " "
149 // G Prefix = ""
150 //
151 // Note that the first level gets no prefix.
152 {
153 OS << '\n';
154 ColorScope Color(*this, IndentColor);
155 OS << Prefix << (isLastChild ? '`' : '|') << '-';
NAKAMURA Takumic73e4022014-10-31 00:30:37 +0000156 this->Prefix.push_back(isLastChild ? ' ' : '|');
157 this->Prefix.push_back(' ');
Richard Smithf7514452014-10-30 21:02:37 +0000158 }
159
160 FirstChild = true;
161 unsigned Depth = Pending.size();
162
163 FC = OrigFC;
164 doDumpChild();
165
166 // If any children are left, they're the last at their nesting level.
167 // Dump those ones out now.
168 while (Depth < Pending.size()) {
169 Pending.back()(true);
NAKAMURA Takumic73e4022014-10-31 00:30:37 +0000170 this->Pending.pop_back();
Richard Smithf7514452014-10-30 21:02:37 +0000171 }
172
173 // Restore the old prefix.
NAKAMURA Takumic73e4022014-10-31 00:30:37 +0000174 this->Prefix.resize(Prefix.size() - 2);
Richard Smithf7514452014-10-30 21:02:37 +0000175 };
176
177 if (FirstChild) {
178 Pending.push_back(std::move(dumpWithIndent));
179 } else {
180 Pending.back()(false);
181 Pending.back() = std::move(dumpWithIndent);
Manuel Klimek874030e2012-11-07 00:33:12 +0000182 }
Richard Smithf7514452014-10-30 21:02:37 +0000183 FirstChild = false;
184 }
Manuel Klimek874030e2012-11-07 00:33:12 +0000185
Richard Trieud215b8d2013-01-26 01:31:20 +0000186 class ColorScope {
187 ASTDumper &Dumper;
188 public:
189 ColorScope(ASTDumper &Dumper, TerminalColor Color)
190 : Dumper(Dumper) {
191 if (Dumper.ShowColors)
192 Dumper.OS.changeColor(Color.Color, Color.Bold);
193 }
194 ~ColorScope() {
195 if (Dumper.ShowColors)
196 Dumper.OS.resetColor();
197 }
198 };
199
Chris Lattnercbe4f772007-08-08 22:51:59 +0000200 public:
Alexander Kornienkoebc17b52013-01-14 14:07:11 +0000201 ASTDumper(raw_ostream &OS, const CommandTraits *Traits,
202 const SourceManager *SM)
Richard Smithf7514452014-10-30 21:02:37 +0000203 : OS(OS), Traits(Traits), SM(SM), TopLevel(true), FirstChild(true),
Craig Topper36250ad2014-05-12 05:36:57 +0000204 LastLocFilename(""), LastLocLine(~0U), FC(nullptr),
Richard Trieud215b8d2013-01-26 01:31:20 +0000205 ShowColors(SM && SM->getDiagnostics().getShowColors()) { }
206
207 ASTDumper(raw_ostream &OS, const CommandTraits *Traits,
208 const SourceManager *SM, bool ShowColors)
Richard Smithf7514452014-10-30 21:02:37 +0000209 : OS(OS), Traits(Traits), SM(SM), TopLevel(true), FirstChild(true),
Richard Smith56d12152013-01-31 02:04:38 +0000210 LastLocFilename(""), LastLocLine(~0U),
Richard Trieude5cc7d2013-01-31 01:44:26 +0000211 ShowColors(ShowColors) { }
Mike Stump11289f42009-09-09 15:08:12 +0000212
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000213 void dumpDecl(const Decl *D);
214 void dumpStmt(const Stmt *S);
Alexander Kornienkoebc17b52013-01-14 14:07:11 +0000215 void dumpFullComment(const FullComment *C);
Mike Stump11289f42009-09-09 15:08:12 +0000216
Richard Trieude5cc7d2013-01-31 01:44:26 +0000217 // Utilities
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000218 void dumpPointer(const void *Ptr);
219 void dumpSourceRange(SourceRange R);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000220 void dumpLocation(SourceLocation Loc);
Richard Smithd5e7ff82014-10-31 01:17:45 +0000221 void dumpBareType(QualType T, bool Desugar = true);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000222 void dumpType(QualType T);
Richard Smithd5e7ff82014-10-31 01:17:45 +0000223 void dumpTypeAsChild(QualType T);
224 void dumpTypeAsChild(const Type *T);
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000225 void dumpBareDeclRef(const Decl *Node);
Craig Topper36250ad2014-05-12 05:36:57 +0000226 void dumpDeclRef(const Decl *Node, const char *Label = nullptr);
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000227 void dumpName(const NamedDecl *D);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000228 bool hasNodes(const DeclContext *DC);
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000229 void dumpDeclContext(const DeclContext *DC);
Richard Smith35f986d2014-08-11 22:11:07 +0000230 void dumpLookups(const DeclContext *DC, bool DumpDecls);
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000231 void dumpAttr(const Attr *A);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000232
233 // C++ Utilities
234 void dumpAccessSpecifier(AccessSpecifier AS);
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000235 void dumpCXXCtorInitializer(const CXXCtorInitializer *Init);
236 void dumpTemplateParameters(const TemplateParameterList *TPL);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000237 void dumpTemplateArgumentListInfo(const TemplateArgumentListInfo &TALI);
238 void dumpTemplateArgumentLoc(const TemplateArgumentLoc &A);
239 void dumpTemplateArgumentList(const TemplateArgumentList &TAL);
240 void dumpTemplateArgument(const TemplateArgument &A,
241 SourceRange R = SourceRange());
242
Douglas Gregor85f3f952015-07-07 03:57:15 +0000243 // Objective-C utilities.
244 void dumpObjCTypeParamList(const ObjCTypeParamList *typeParams);
245
Richard Smithd5e7ff82014-10-31 01:17:45 +0000246 // Types
247 void VisitComplexType(const ComplexType *T) {
248 dumpTypeAsChild(T->getElementType());
249 }
250 void VisitPointerType(const PointerType *T) {
251 dumpTypeAsChild(T->getPointeeType());
252 }
253 void VisitBlockPointerType(const BlockPointerType *T) {
254 dumpTypeAsChild(T->getPointeeType());
255 }
256 void VisitReferenceType(const ReferenceType *T) {
257 dumpTypeAsChild(T->getPointeeType());
258 }
259 void VisitRValueReferenceType(const ReferenceType *T) {
260 if (T->isSpelledAsLValue())
261 OS << " written as lvalue reference";
262 VisitReferenceType(T);
263 }
264 void VisitMemberPointerType(const MemberPointerType *T) {
265 dumpTypeAsChild(T->getClass());
266 dumpTypeAsChild(T->getPointeeType());
267 }
268 void VisitArrayType(const ArrayType *T) {
269 switch (T->getSizeModifier()) {
270 case ArrayType::Normal: break;
271 case ArrayType::Static: OS << " static"; break;
272 case ArrayType::Star: OS << " *"; break;
273 }
274 OS << " " << T->getIndexTypeQualifiers().getAsString();
275 dumpTypeAsChild(T->getElementType());
276 }
277 void VisitConstantArrayType(const ConstantArrayType *T) {
278 OS << " " << T->getSize();
279 VisitArrayType(T);
280 }
281 void VisitVariableArrayType(const VariableArrayType *T) {
282 OS << " ";
283 dumpSourceRange(T->getBracketsRange());
284 VisitArrayType(T);
285 dumpStmt(T->getSizeExpr());
286 }
287 void VisitDependentSizedArrayType(const DependentSizedArrayType *T) {
288 VisitArrayType(T);
289 OS << " ";
290 dumpSourceRange(T->getBracketsRange());
291 dumpStmt(T->getSizeExpr());
292 }
293 void VisitDependentSizedExtVectorType(
294 const DependentSizedExtVectorType *T) {
295 OS << " ";
296 dumpLocation(T->getAttributeLoc());
297 dumpTypeAsChild(T->getElementType());
298 dumpStmt(T->getSizeExpr());
299 }
300 void VisitVectorType(const VectorType *T) {
301 switch (T->getVectorKind()) {
302 case VectorType::GenericVector: break;
303 case VectorType::AltiVecVector: OS << " altivec"; break;
304 case VectorType::AltiVecPixel: OS << " altivec pixel"; break;
305 case VectorType::AltiVecBool: OS << " altivec bool"; break;
306 case VectorType::NeonVector: OS << " neon"; break;
307 case VectorType::NeonPolyVector: OS << " neon poly"; break;
308 }
309 OS << " " << T->getNumElements();
310 dumpTypeAsChild(T->getElementType());
311 }
312 void VisitFunctionType(const FunctionType *T) {
313 auto EI = T->getExtInfo();
314 if (EI.getNoReturn()) OS << " noreturn";
315 if (EI.getProducesResult()) OS << " produces_result";
316 if (EI.getHasRegParm()) OS << " regparm " << EI.getRegParm();
317 OS << " " << FunctionType::getNameForCallConv(EI.getCC());
318 dumpTypeAsChild(T->getReturnType());
319 }
320 void VisitFunctionProtoType(const FunctionProtoType *T) {
321 auto EPI = T->getExtProtoInfo();
322 if (EPI.HasTrailingReturn) OS << " trailing_return";
323 if (T->isConst()) OS << " const";
324 if (T->isVolatile()) OS << " volatile";
325 if (T->isRestrict()) OS << " restrict";
326 switch (EPI.RefQualifier) {
327 case RQ_None: break;
328 case RQ_LValue: OS << " &"; break;
329 case RQ_RValue: OS << " &&"; break;
330 }
331 // FIXME: Exception specification.
332 // FIXME: Consumed parameters.
333 VisitFunctionType(T);
334 for (QualType PT : T->getParamTypes())
335 dumpTypeAsChild(PT);
336 if (EPI.Variadic)
337 dumpChild([=] { OS << "..."; });
338 }
339 void VisitUnresolvedUsingType(const UnresolvedUsingType *T) {
340 dumpDeclRef(T->getDecl());
341 }
342 void VisitTypedefType(const TypedefType *T) {
343 dumpDeclRef(T->getDecl());
344 }
345 void VisitTypeOfExprType(const TypeOfExprType *T) {
346 dumpStmt(T->getUnderlyingExpr());
347 }
348 void VisitDecltypeType(const DecltypeType *T) {
349 dumpStmt(T->getUnderlyingExpr());
350 }
351 void VisitUnaryTransformType(const UnaryTransformType *T) {
352 switch (T->getUTTKind()) {
353 case UnaryTransformType::EnumUnderlyingType:
354 OS << " underlying_type";
355 break;
356 }
357 dumpTypeAsChild(T->getBaseType());
358 }
359 void VisitTagType(const TagType *T) {
360 dumpDeclRef(T->getDecl());
361 }
362 void VisitAttributedType(const AttributedType *T) {
363 // FIXME: AttrKind
364 dumpTypeAsChild(T->getModifiedType());
365 }
366 void VisitTemplateTypeParmType(const TemplateTypeParmType *T) {
367 OS << " depth " << T->getDepth() << " index " << T->getIndex();
368 if (T->isParameterPack()) OS << " pack";
369 dumpDeclRef(T->getDecl());
370 }
371 void VisitSubstTemplateTypeParmType(const SubstTemplateTypeParmType *T) {
372 dumpTypeAsChild(T->getReplacedParameter());
373 }
374 void VisitSubstTemplateTypeParmPackType(
375 const SubstTemplateTypeParmPackType *T) {
376 dumpTypeAsChild(T->getReplacedParameter());
377 dumpTemplateArgument(T->getArgumentPack());
378 }
379 void VisitAutoType(const AutoType *T) {
380 if (T->isDecltypeAuto()) OS << " decltype(auto)";
381 if (!T->isDeduced())
382 OS << " undeduced";
383 }
384 void VisitTemplateSpecializationType(const TemplateSpecializationType *T) {
385 if (T->isTypeAlias()) OS << " alias";
386 OS << " "; T->getTemplateName().dump(OS);
387 for (auto &Arg : *T)
388 dumpTemplateArgument(Arg);
389 if (T->isTypeAlias())
390 dumpTypeAsChild(T->getAliasedType());
391 }
392 void VisitInjectedClassNameType(const InjectedClassNameType *T) {
393 dumpDeclRef(T->getDecl());
394 }
395 void VisitObjCInterfaceType(const ObjCInterfaceType *T) {
396 dumpDeclRef(T->getDecl());
397 }
398 void VisitObjCObjectPointerType(const ObjCObjectPointerType *T) {
399 dumpTypeAsChild(T->getPointeeType());
400 }
401 void VisitAtomicType(const AtomicType *T) {
402 dumpTypeAsChild(T->getValueType());
403 }
404 void VisitAdjustedType(const AdjustedType *T) {
405 dumpTypeAsChild(T->getOriginalType());
406 }
407 void VisitPackExpansionType(const PackExpansionType *T) {
408 if (auto N = T->getNumExpansions()) OS << " expansions " << *N;
409 if (!T->isSugared())
410 dumpTypeAsChild(T->getPattern());
411 }
412 // FIXME: ElaboratedType, DependentNameType,
413 // DependentTemplateSpecializationType, ObjCObjectType
414
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000415 // Decls
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000416 void VisitLabelDecl(const LabelDecl *D);
417 void VisitTypedefDecl(const TypedefDecl *D);
418 void VisitEnumDecl(const EnumDecl *D);
419 void VisitRecordDecl(const RecordDecl *D);
420 void VisitEnumConstantDecl(const EnumConstantDecl *D);
421 void VisitIndirectFieldDecl(const IndirectFieldDecl *D);
422 void VisitFunctionDecl(const FunctionDecl *D);
423 void VisitFieldDecl(const FieldDecl *D);
424 void VisitVarDecl(const VarDecl *D);
425 void VisitFileScopeAsmDecl(const FileScopeAsmDecl *D);
426 void VisitImportDecl(const ImportDecl *D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000427
428 // C++ Decls
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000429 void VisitNamespaceDecl(const NamespaceDecl *D);
430 void VisitUsingDirectiveDecl(const UsingDirectiveDecl *D);
431 void VisitNamespaceAliasDecl(const NamespaceAliasDecl *D);
432 void VisitTypeAliasDecl(const TypeAliasDecl *D);
433 void VisitTypeAliasTemplateDecl(const TypeAliasTemplateDecl *D);
434 void VisitCXXRecordDecl(const CXXRecordDecl *D);
435 void VisitStaticAssertDecl(const StaticAssertDecl *D);
Richard Smithcbdf7332014-03-18 02:07:28 +0000436 template<typename SpecializationDecl>
Richard Smithf7514452014-10-30 21:02:37 +0000437 void VisitTemplateDeclSpecialization(const SpecializationDecl *D,
Richard Smithcbdf7332014-03-18 02:07:28 +0000438 bool DumpExplicitInst,
439 bool DumpRefOnly);
Richard Smith20ade552014-03-17 23:34:53 +0000440 template<typename TemplateDecl>
441 void VisitTemplateDecl(const TemplateDecl *D, bool DumpExplicitInst);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000442 void VisitFunctionTemplateDecl(const FunctionTemplateDecl *D);
443 void VisitClassTemplateDecl(const ClassTemplateDecl *D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000444 void VisitClassTemplateSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000445 const ClassTemplateSpecializationDecl *D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000446 void VisitClassTemplatePartialSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000447 const ClassTemplatePartialSpecializationDecl *D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000448 void VisitClassScopeFunctionSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000449 const ClassScopeFunctionSpecializationDecl *D);
Richard Smithd25789a2013-09-18 01:36:02 +0000450 void VisitVarTemplateDecl(const VarTemplateDecl *D);
451 void VisitVarTemplateSpecializationDecl(
452 const VarTemplateSpecializationDecl *D);
453 void VisitVarTemplatePartialSpecializationDecl(
454 const VarTemplatePartialSpecializationDecl *D);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000455 void VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D);
456 void VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D);
457 void VisitTemplateTemplateParmDecl(const TemplateTemplateParmDecl *D);
458 void VisitUsingDecl(const UsingDecl *D);
459 void VisitUnresolvedUsingTypenameDecl(const UnresolvedUsingTypenameDecl *D);
460 void VisitUnresolvedUsingValueDecl(const UnresolvedUsingValueDecl *D);
461 void VisitUsingShadowDecl(const UsingShadowDecl *D);
462 void VisitLinkageSpecDecl(const LinkageSpecDecl *D);
463 void VisitAccessSpecDecl(const AccessSpecDecl *D);
464 void VisitFriendDecl(const FriendDecl *D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000465
466 // ObjC Decls
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000467 void VisitObjCIvarDecl(const ObjCIvarDecl *D);
468 void VisitObjCMethodDecl(const ObjCMethodDecl *D);
Douglas Gregor85f3f952015-07-07 03:57:15 +0000469 void VisitObjCTypeParamDecl(const ObjCTypeParamDecl *D);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000470 void VisitObjCCategoryDecl(const ObjCCategoryDecl *D);
471 void VisitObjCCategoryImplDecl(const ObjCCategoryImplDecl *D);
472 void VisitObjCProtocolDecl(const ObjCProtocolDecl *D);
473 void VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D);
474 void VisitObjCImplementationDecl(const ObjCImplementationDecl *D);
475 void VisitObjCCompatibleAliasDecl(const ObjCCompatibleAliasDecl *D);
476 void VisitObjCPropertyDecl(const ObjCPropertyDecl *D);
477 void VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D);
478 void VisitBlockDecl(const BlockDecl *D);
Mike Stump11289f42009-09-09 15:08:12 +0000479
Chris Lattner84ca3762007-08-30 01:00:35 +0000480 // Stmts.
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000481 void VisitStmt(const Stmt *Node);
482 void VisitDeclStmt(const DeclStmt *Node);
483 void VisitAttributedStmt(const AttributedStmt *Node);
484 void VisitLabelStmt(const LabelStmt *Node);
485 void VisitGotoStmt(const GotoStmt *Node);
Pavel Labath1ef83422013-09-04 14:35:00 +0000486 void VisitCXXCatchStmt(const CXXCatchStmt *Node);
Mike Stump11289f42009-09-09 15:08:12 +0000487
Chris Lattner84ca3762007-08-30 01:00:35 +0000488 // Exprs
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000489 void VisitExpr(const Expr *Node);
490 void VisitCastExpr(const CastExpr *Node);
491 void VisitDeclRefExpr(const DeclRefExpr *Node);
492 void VisitPredefinedExpr(const PredefinedExpr *Node);
493 void VisitCharacterLiteral(const CharacterLiteral *Node);
494 void VisitIntegerLiteral(const IntegerLiteral *Node);
495 void VisitFloatingLiteral(const FloatingLiteral *Node);
496 void VisitStringLiteral(const StringLiteral *Str);
Richard Smithf0514962014-06-03 08:24:28 +0000497 void VisitInitListExpr(const InitListExpr *ILE);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000498 void VisitUnaryOperator(const UnaryOperator *Node);
499 void VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *Node);
500 void VisitMemberExpr(const MemberExpr *Node);
501 void VisitExtVectorElementExpr(const ExtVectorElementExpr *Node);
502 void VisitBinaryOperator(const BinaryOperator *Node);
503 void VisitCompoundAssignOperator(const CompoundAssignOperator *Node);
504 void VisitAddrLabelExpr(const AddrLabelExpr *Node);
505 void VisitBlockExpr(const BlockExpr *Node);
506 void VisitOpaqueValueExpr(const OpaqueValueExpr *Node);
Chris Lattner84ca3762007-08-30 01:00:35 +0000507
508 // C++
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000509 void VisitCXXNamedCastExpr(const CXXNamedCastExpr *Node);
510 void VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *Node);
511 void VisitCXXThisExpr(const CXXThisExpr *Node);
512 void VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *Node);
513 void VisitCXXConstructExpr(const CXXConstructExpr *Node);
514 void VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *Node);
Reid Kleckner5c682bc2015-03-19 18:09:25 +0000515 void VisitCXXNewExpr(const CXXNewExpr *Node);
516 void VisitCXXDeleteExpr(const CXXDeleteExpr *Node);
Richard Smithe6c01442013-06-05 00:46:14 +0000517 void VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000518 void VisitExprWithCleanups(const ExprWithCleanups *Node);
519 void VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *Node);
520 void dumpCXXTemporary(const CXXTemporary *Temporary);
Faisal Vali2b391ab2013-09-26 19:54:12 +0000521 void VisitLambdaExpr(const LambdaExpr *Node) {
522 VisitExpr(Node);
523 dumpDecl(Node->getLambdaClass());
524 }
Serge Pavlov6b926032015-02-16 19:58:41 +0000525 void VisitSizeOfPackExpr(const SizeOfPackExpr *Node);
Mike Stump11289f42009-09-09 15:08:12 +0000526
Chris Lattner84ca3762007-08-30 01:00:35 +0000527 // ObjC
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000528 void VisitObjCAtCatchStmt(const ObjCAtCatchStmt *Node);
529 void VisitObjCEncodeExpr(const ObjCEncodeExpr *Node);
530 void VisitObjCMessageExpr(const ObjCMessageExpr *Node);
531 void VisitObjCBoxedExpr(const ObjCBoxedExpr *Node);
532 void VisitObjCSelectorExpr(const ObjCSelectorExpr *Node);
533 void VisitObjCProtocolExpr(const ObjCProtocolExpr *Node);
534 void VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *Node);
535 void VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *Node);
536 void VisitObjCIvarRefExpr(const ObjCIvarRefExpr *Node);
537 void VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *Node);
Alexander Kornienkoebc17b52013-01-14 14:07:11 +0000538
539 // Comments.
540 const char *getCommandName(unsigned CommandID);
541 void dumpComment(const Comment *C);
542
543 // Inline comments.
544 void visitTextComment(const TextComment *C);
545 void visitInlineCommandComment(const InlineCommandComment *C);
546 void visitHTMLStartTagComment(const HTMLStartTagComment *C);
547 void visitHTMLEndTagComment(const HTMLEndTagComment *C);
548
549 // Block comments.
550 void visitBlockCommandComment(const BlockCommandComment *C);
551 void visitParamCommandComment(const ParamCommandComment *C);
552 void visitTParamCommandComment(const TParamCommandComment *C);
553 void visitVerbatimBlockComment(const VerbatimBlockComment *C);
554 void visitVerbatimBlockLineComment(const VerbatimBlockLineComment *C);
555 void visitVerbatimLineComment(const VerbatimLineComment *C);
Chris Lattnercbe4f772007-08-08 22:51:59 +0000556 };
Alexander Kornienkoab9db512015-06-22 23:07:51 +0000557}
Chris Lattnercbe4f772007-08-08 22:51:59 +0000558
559//===----------------------------------------------------------------------===//
Chris Lattner11e30d32007-08-30 06:17:34 +0000560// Utilities
561//===----------------------------------------------------------------------===//
562
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000563void ASTDumper::dumpPointer(const void *Ptr) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000564 ColorScope Color(*this, AddressColor);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000565 OS << ' ' << Ptr;
566}
567
Alexander Kornienko18ec81b2012-12-13 13:59:55 +0000568void ASTDumper::dumpLocation(SourceLocation Loc) {
Alex McCarthye14ddef2014-05-02 20:24:11 +0000569 if (!SM)
570 return;
571
Richard Trieud215b8d2013-01-26 01:31:20 +0000572 ColorScope Color(*this, LocationColor);
Chris Lattner53e384f2009-01-16 07:00:02 +0000573 SourceLocation SpellingLoc = SM->getSpellingLoc(Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000574
Chris Lattner11e30d32007-08-30 06:17:34 +0000575 // The general format we print out is filename:line:col, but we drop pieces
576 // that haven't changed since the last loc printed.
Chris Lattnerf1ca7d32009-01-27 07:57:44 +0000577 PresumedLoc PLoc = SM->getPresumedLoc(SpellingLoc);
578
Douglas Gregor453b0122010-11-12 07:15:47 +0000579 if (PLoc.isInvalid()) {
580 OS << "<invalid sloc>";
581 return;
582 }
583
Chris Lattnerf1ca7d32009-01-27 07:57:44 +0000584 if (strcmp(PLoc.getFilename(), LastLocFilename) != 0) {
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000585 OS << PLoc.getFilename() << ':' << PLoc.getLine()
586 << ':' << PLoc.getColumn();
Chris Lattnerf1ca7d32009-01-27 07:57:44 +0000587 LastLocFilename = PLoc.getFilename();
588 LastLocLine = PLoc.getLine();
589 } else if (PLoc.getLine() != LastLocLine) {
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000590 OS << "line" << ':' << PLoc.getLine()
591 << ':' << PLoc.getColumn();
Chris Lattnerf1ca7d32009-01-27 07:57:44 +0000592 LastLocLine = PLoc.getLine();
Chris Lattner11e30d32007-08-30 06:17:34 +0000593 } else {
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000594 OS << "col" << ':' << PLoc.getColumn();
Chris Lattner11e30d32007-08-30 06:17:34 +0000595 }
596}
597
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000598void ASTDumper::dumpSourceRange(SourceRange R) {
Chris Lattner11e30d32007-08-30 06:17:34 +0000599 // Can't translate locations if a SourceManager isn't available.
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000600 if (!SM)
601 return;
Mike Stump11289f42009-09-09 15:08:12 +0000602
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000603 OS << " <";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000604 dumpLocation(R.getBegin());
Chris Lattnera7c19fe2007-10-16 22:36:42 +0000605 if (R.getBegin() != R.getEnd()) {
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000606 OS << ", ";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000607 dumpLocation(R.getEnd());
Chris Lattner11e30d32007-08-30 06:17:34 +0000608 }
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000609 OS << ">";
Mike Stump11289f42009-09-09 15:08:12 +0000610
Chris Lattner11e30d32007-08-30 06:17:34 +0000611 // <t2.c:123:421[blah], t2.c:412:321>
612
613}
614
Richard Smithd5e7ff82014-10-31 01:17:45 +0000615void ASTDumper::dumpBareType(QualType T, bool Desugar) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000616 ColorScope Color(*this, TypeColor);
Richard Smithd5e7ff82014-10-31 01:17:45 +0000617
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000618 SplitQualType T_split = T.split();
619 OS << "'" << QualType::getAsString(T_split) << "'";
620
Richard Smithd5e7ff82014-10-31 01:17:45 +0000621 if (Desugar && !T.isNull()) {
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000622 // If the type is sugared, also dump a (shallow) desugared type.
623 SplitQualType D_split = T.getSplitDesugaredType();
624 if (T_split != D_split)
625 OS << ":'" << QualType::getAsString(D_split) << "'";
626 }
627}
628
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000629void ASTDumper::dumpType(QualType T) {
630 OS << ' ';
631 dumpBareType(T);
632}
633
Richard Smithd5e7ff82014-10-31 01:17:45 +0000634void ASTDumper::dumpTypeAsChild(QualType T) {
635 SplitQualType SQT = T.split();
636 if (!SQT.Quals.hasQualifiers())
637 return dumpTypeAsChild(SQT.Ty);
638
639 dumpChild([=] {
640 OS << "QualType";
641 dumpPointer(T.getAsOpaquePtr());
642 OS << " ";
643 dumpBareType(T, false);
644 OS << " " << T.split().Quals.getAsString();
645 dumpTypeAsChild(T.split().Ty);
646 });
647}
648
649void ASTDumper::dumpTypeAsChild(const Type *T) {
650 dumpChild([=] {
651 if (!T) {
652 ColorScope Color(*this, NullColor);
653 OS << "<<<NULL>>>";
654 return;
655 }
656
657 {
658 ColorScope Color(*this, TypeColor);
659 OS << T->getTypeClassName() << "Type";
660 }
661 dumpPointer(T);
662 OS << " ";
663 dumpBareType(QualType(T, 0), false);
664
665 QualType SingleStepDesugar =
666 T->getLocallyUnqualifiedSingleStepDesugaredType();
667 if (SingleStepDesugar != QualType(T, 0))
668 OS << " sugar";
669 if (T->isDependentType())
670 OS << " dependent";
671 else if (T->isInstantiationDependentType())
672 OS << " instantiation_dependent";
673 if (T->isVariablyModifiedType())
674 OS << " variably_modified";
675 if (T->containsUnexpandedParameterPack())
676 OS << " contains_unexpanded_pack";
677 if (T->isFromAST())
678 OS << " imported";
679
680 TypeVisitor<ASTDumper>::Visit(T);
681
682 if (SingleStepDesugar != QualType(T, 0))
683 dumpTypeAsChild(SingleStepDesugar);
684 });
685}
686
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000687void ASTDumper::dumpBareDeclRef(const Decl *D) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000688 {
689 ColorScope Color(*this, DeclKindNameColor);
690 OS << D->getDeclKindName();
691 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000692 dumpPointer(D);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000693
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000694 if (const NamedDecl *ND = dyn_cast<NamedDecl>(D)) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000695 ColorScope Color(*this, DeclNameColor);
David Blaikied4da8722013-05-14 21:04:00 +0000696 OS << " '" << ND->getDeclName() << '\'';
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000697 }
698
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000699 if (const ValueDecl *VD = dyn_cast<ValueDecl>(D))
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000700 dumpType(VD->getType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000701}
702
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000703void ASTDumper::dumpDeclRef(const Decl *D, const char *Label) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000704 if (!D)
705 return;
706
Richard Smithf7514452014-10-30 21:02:37 +0000707 dumpChild([=]{
708 if (Label)
709 OS << Label << ' ';
710 dumpBareDeclRef(D);
711 });
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000712}
713
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000714void ASTDumper::dumpName(const NamedDecl *ND) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000715 if (ND->getDeclName()) {
716 ColorScope Color(*this, DeclNameColor);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000717 OS << ' ' << ND->getNameAsString();
Richard Trieud215b8d2013-01-26 01:31:20 +0000718 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000719}
720
Richard Trieude5cc7d2013-01-31 01:44:26 +0000721bool ASTDumper::hasNodes(const DeclContext *DC) {
722 if (!DC)
723 return false;
724
Richard Smith1d209d02013-05-23 01:49:11 +0000725 return DC->hasExternalLexicalStorage() ||
726 DC->noload_decls_begin() != DC->noload_decls_end();
Richard Trieude5cc7d2013-01-31 01:44:26 +0000727}
728
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000729void ASTDumper::dumpDeclContext(const DeclContext *DC) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000730 if (!DC)
731 return;
Richard Smithdcc2c452014-03-17 23:00:06 +0000732
Richard Smithdcc2c452014-03-17 23:00:06 +0000733 for (auto *D : DC->noload_decls())
Richard Smithf7514452014-10-30 21:02:37 +0000734 dumpDecl(D);
Richard Smithdcc2c452014-03-17 23:00:06 +0000735
736 if (DC->hasExternalLexicalStorage()) {
Richard Smithf7514452014-10-30 21:02:37 +0000737 dumpChild([=]{
738 ColorScope Color(*this, UndeserializedColor);
739 OS << "<undeserialized declarations>";
740 });
Richard Smith1d209d02013-05-23 01:49:11 +0000741 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000742}
743
Richard Smith35f986d2014-08-11 22:11:07 +0000744void ASTDumper::dumpLookups(const DeclContext *DC, bool DumpDecls) {
Richard Smithf7514452014-10-30 21:02:37 +0000745 dumpChild([=] {
746 OS << "StoredDeclsMap ";
747 dumpBareDeclRef(cast<Decl>(DC));
Richard Smith33937e72013-06-22 21:49:40 +0000748
Richard Smithf7514452014-10-30 21:02:37 +0000749 const DeclContext *Primary = DC->getPrimaryContext();
750 if (Primary != DC) {
751 OS << " primary";
752 dumpPointer(cast<Decl>(Primary));
Richard Smith33937e72013-06-22 21:49:40 +0000753 }
754
Richard Smithf7514452014-10-30 21:02:37 +0000755 bool HasUndeserializedLookups = Primary->hasExternalVisibleStorage();
Richard Smith35f986d2014-08-11 22:11:07 +0000756
Richard Smithf7514452014-10-30 21:02:37 +0000757 DeclContext::all_lookups_iterator I = Primary->noload_lookups_begin(),
758 E = Primary->noload_lookups_end();
759 while (I != E) {
760 DeclarationName Name = I.getLookupName();
761 DeclContextLookupResult R = *I++;
Richard Smith35f986d2014-08-11 22:11:07 +0000762
Richard Smithf7514452014-10-30 21:02:37 +0000763 dumpChild([=] {
764 OS << "DeclarationName ";
765 {
766 ColorScope Color(*this, DeclNameColor);
767 OS << '\'' << Name << '\'';
768 }
Richard Smith35f986d2014-08-11 22:11:07 +0000769
Richard Smithf7514452014-10-30 21:02:37 +0000770 for (DeclContextLookupResult::iterator RI = R.begin(), RE = R.end();
771 RI != RE; ++RI) {
772 dumpChild([=] {
773 dumpBareDeclRef(*RI);
774
775 if ((*RI)->isHidden())
776 OS << " hidden";
777
778 // If requested, dump the redecl chain for this lookup.
779 if (DumpDecls) {
780 // Dump earliest decl first.
781 std::function<void(Decl *)> DumpWithPrev = [&](Decl *D) {
782 if (Decl *Prev = D->getPreviousDecl())
783 DumpWithPrev(Prev);
784 dumpDecl(D);
785 };
786 DumpWithPrev(*RI);
787 }
788 });
789 }
790 });
Richard Smith33937e72013-06-22 21:49:40 +0000791 }
Richard Smith33937e72013-06-22 21:49:40 +0000792
Richard Smithf7514452014-10-30 21:02:37 +0000793 if (HasUndeserializedLookups) {
794 dumpChild([=] {
795 ColorScope Color(*this, UndeserializedColor);
796 OS << "<undeserialized lookups>";
797 });
798 }
799 });
Richard Smith33937e72013-06-22 21:49:40 +0000800}
801
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000802void ASTDumper::dumpAttr(const Attr *A) {
Richard Smithf7514452014-10-30 21:02:37 +0000803 dumpChild([=] {
804 {
805 ColorScope Color(*this, AttrColor);
Aaron Ballman36a53502014-01-16 13:03:14 +0000806
Richard Smithf7514452014-10-30 21:02:37 +0000807 switch (A->getKind()) {
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000808#define ATTR(X) case attr::X: OS << #X; break;
809#include "clang/Basic/AttrList.inc"
Richard Smithf7514452014-10-30 21:02:37 +0000810 default:
811 llvm_unreachable("unexpected attribute kind");
812 }
813 OS << "Attr";
Richard Trieud215b8d2013-01-26 01:31:20 +0000814 }
Richard Smithf7514452014-10-30 21:02:37 +0000815 dumpPointer(A);
816 dumpSourceRange(A->getRange());
817 if (A->isInherited())
818 OS << " Inherited";
819 if (A->isImplicit())
820 OS << " Implicit";
Hans Wennborgb0a8b4a2014-05-31 04:05:57 +0000821#include "clang/AST/AttrDump.inc"
Richard Smithf7514452014-10-30 21:02:37 +0000822 });
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000823}
824
Richard Smith71bec062013-10-15 21:58:30 +0000825static void dumpPreviousDeclImpl(raw_ostream &OS, ...) {}
826
827template<typename T>
828static void dumpPreviousDeclImpl(raw_ostream &OS, const Mergeable<T> *D) {
Rafael Espindola8db352d2013-10-17 15:37:26 +0000829 const T *First = D->getFirstDecl();
Richard Smith71bec062013-10-15 21:58:30 +0000830 if (First != D)
831 OS << " first " << First;
Richard Smithf5f43542013-02-07 01:35:44 +0000832}
833
834template<typename T>
Richard Smith71bec062013-10-15 21:58:30 +0000835static void dumpPreviousDeclImpl(raw_ostream &OS, const Redeclarable<T> *D) {
836 const T *Prev = D->getPreviousDecl();
837 if (Prev)
838 OS << " prev " << Prev;
Richard Smithf5f43542013-02-07 01:35:44 +0000839}
840
Richard Smith71bec062013-10-15 21:58:30 +0000841/// Dump the previous declaration in the redeclaration chain for a declaration,
842/// if any.
843static void dumpPreviousDecl(raw_ostream &OS, const Decl *D) {
Richard Smithf5f43542013-02-07 01:35:44 +0000844 switch (D->getKind()) {
845#define DECL(DERIVED, BASE) \
846 case Decl::DERIVED: \
Richard Smith71bec062013-10-15 21:58:30 +0000847 return dumpPreviousDeclImpl(OS, cast<DERIVED##Decl>(D));
Richard Smithf5f43542013-02-07 01:35:44 +0000848#define ABSTRACT_DECL(DECL)
849#include "clang/AST/DeclNodes.inc"
850 }
851 llvm_unreachable("Decl that isn't part of DeclNodes.inc!");
852}
853
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000854//===----------------------------------------------------------------------===//
855// C++ Utilities
856//===----------------------------------------------------------------------===//
857
858void ASTDumper::dumpAccessSpecifier(AccessSpecifier AS) {
859 switch (AS) {
860 case AS_none:
861 break;
862 case AS_public:
863 OS << "public";
864 break;
865 case AS_protected:
866 OS << "protected";
867 break;
868 case AS_private:
869 OS << "private";
870 break;
871 }
872}
873
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000874void ASTDumper::dumpCXXCtorInitializer(const CXXCtorInitializer *Init) {
Richard Smithf7514452014-10-30 21:02:37 +0000875 dumpChild([=] {
876 OS << "CXXCtorInitializer";
877 if (Init->isAnyMemberInitializer()) {
878 OS << ' ';
879 dumpBareDeclRef(Init->getAnyMember());
880 } else if (Init->isBaseInitializer()) {
881 dumpType(QualType(Init->getBaseClass(), 0));
882 } else if (Init->isDelegatingInitializer()) {
883 dumpType(Init->getTypeSourceInfo()->getType());
884 } else {
885 llvm_unreachable("Unknown initializer type");
886 }
887 dumpStmt(Init->getInit());
888 });
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000889}
890
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000891void ASTDumper::dumpTemplateParameters(const TemplateParameterList *TPL) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000892 if (!TPL)
893 return;
894
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000895 for (TemplateParameterList::const_iterator I = TPL->begin(), E = TPL->end();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000896 I != E; ++I)
897 dumpDecl(*I);
898}
899
900void ASTDumper::dumpTemplateArgumentListInfo(
901 const TemplateArgumentListInfo &TALI) {
Richard Smithf7514452014-10-30 21:02:37 +0000902 for (unsigned i = 0, e = TALI.size(); i < e; ++i)
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000903 dumpTemplateArgumentLoc(TALI[i]);
904}
905
906void ASTDumper::dumpTemplateArgumentLoc(const TemplateArgumentLoc &A) {
907 dumpTemplateArgument(A.getArgument(), A.getSourceRange());
908}
909
910void ASTDumper::dumpTemplateArgumentList(const TemplateArgumentList &TAL) {
911 for (unsigned i = 0, e = TAL.size(); i < e; ++i)
912 dumpTemplateArgument(TAL[i]);
913}
914
915void ASTDumper::dumpTemplateArgument(const TemplateArgument &A, SourceRange R) {
Richard Smithf7514452014-10-30 21:02:37 +0000916 dumpChild([=] {
917 OS << "TemplateArgument";
918 if (R.isValid())
919 dumpSourceRange(R);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000920
Richard Smithf7514452014-10-30 21:02:37 +0000921 switch (A.getKind()) {
922 case TemplateArgument::Null:
923 OS << " null";
924 break;
925 case TemplateArgument::Type:
926 OS << " type";
927 dumpType(A.getAsType());
928 break;
929 case TemplateArgument::Declaration:
930 OS << " decl";
931 dumpDeclRef(A.getAsDecl());
932 break;
933 case TemplateArgument::NullPtr:
934 OS << " nullptr";
935 break;
936 case TemplateArgument::Integral:
937 OS << " integral " << A.getAsIntegral();
938 break;
939 case TemplateArgument::Template:
940 OS << " template ";
941 A.getAsTemplate().dump(OS);
942 break;
943 case TemplateArgument::TemplateExpansion:
944 OS << " template expansion";
945 A.getAsTemplateOrTemplatePattern().dump(OS);
946 break;
947 case TemplateArgument::Expression:
948 OS << " expr";
949 dumpStmt(A.getAsExpr());
950 break;
951 case TemplateArgument::Pack:
952 OS << " pack";
953 for (TemplateArgument::pack_iterator I = A.pack_begin(), E = A.pack_end();
954 I != E; ++I)
955 dumpTemplateArgument(*I);
956 break;
Richard Trieude5cc7d2013-01-31 01:44:26 +0000957 }
Richard Smithf7514452014-10-30 21:02:37 +0000958 });
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000959}
960
Chris Lattner11e30d32007-08-30 06:17:34 +0000961//===----------------------------------------------------------------------===//
Douglas Gregor85f3f952015-07-07 03:57:15 +0000962// Objective-C Utilities
963//===----------------------------------------------------------------------===//
964void ASTDumper::dumpObjCTypeParamList(const ObjCTypeParamList *typeParams) {
965 if (!typeParams)
966 return;
967
968 for (auto typeParam : *typeParams) {
969 dumpDecl(typeParam);
970 }
971}
972
973//===----------------------------------------------------------------------===//
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000974// Decl dumping methods.
Chris Lattnercbe4f772007-08-08 22:51:59 +0000975//===----------------------------------------------------------------------===//
976
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000977void ASTDumper::dumpDecl(const Decl *D) {
Richard Smithf7514452014-10-30 21:02:37 +0000978 dumpChild([=] {
979 if (!D) {
980 ColorScope Color(*this, NullColor);
981 OS << "<<<NULL>>>";
982 return;
983 }
Mike Stump11289f42009-09-09 15:08:12 +0000984
Richard Smithf7514452014-10-30 21:02:37 +0000985 {
986 ColorScope Color(*this, DeclKindNameColor);
987 OS << D->getDeclKindName() << "Decl";
988 }
989 dumpPointer(D);
990 if (D->getLexicalDeclContext() != D->getDeclContext())
991 OS << " parent " << cast<Decl>(D->getDeclContext());
992 dumpPreviousDecl(OS, D);
993 dumpSourceRange(D->getSourceRange());
994 OS << ' ';
995 dumpLocation(D->getLocation());
Richard Smith42413142015-05-15 20:05:43 +0000996 if (Module *M = D->getImportedOwningModule())
Richard Smithf7514452014-10-30 21:02:37 +0000997 OS << " in " << M->getFullModuleName();
Richard Smith42413142015-05-15 20:05:43 +0000998 else if (Module *M = D->getLocalOwningModule())
999 OS << " in (local) " << M->getFullModuleName();
Richard Smitha2eb4092015-06-22 18:47:01 +00001000 if (auto *ND = dyn_cast<NamedDecl>(D))
1001 for (Module *M : D->getASTContext().getModulesWithMergedDefinition(
1002 const_cast<NamedDecl *>(ND)))
1003 dumpChild([=] { OS << "also in " << M->getFullModuleName(); });
Richard Smithf7514452014-10-30 21:02:37 +00001004 if (const NamedDecl *ND = dyn_cast<NamedDecl>(D))
1005 if (ND->isHidden())
1006 OS << " hidden";
1007 if (D->isImplicit())
1008 OS << " implicit";
1009 if (D->isUsed())
1010 OS << " used";
1011 else if (D->isThisDeclarationReferenced())
1012 OS << " referenced";
1013 if (D->isInvalidDecl())
1014 OS << " invalid";
Hans Wennborg76b00532014-12-05 22:38:57 +00001015 if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
1016 if (FD->isConstexpr())
1017 OS << " constexpr";
1018
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001019
Richard Smithf7514452014-10-30 21:02:37 +00001020 ConstDeclVisitor<ASTDumper>::Visit(D);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001021
Richard Smithf7514452014-10-30 21:02:37 +00001022 for (Decl::attr_iterator I = D->attr_begin(), E = D->attr_end(); I != E;
1023 ++I)
1024 dumpAttr(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001025
Richard Smithf7514452014-10-30 21:02:37 +00001026 if (const FullComment *Comment =
1027 D->getASTContext().getLocalCommentForDeclUncached(D))
1028 dumpFullComment(Comment);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001029
Richard Smithf7514452014-10-30 21:02:37 +00001030 // Decls within functions are visited by the body.
1031 if (!isa<FunctionDecl>(*D) && !isa<ObjCMethodDecl>(*D) &&
1032 hasNodes(dyn_cast<DeclContext>(D)))
1033 dumpDeclContext(cast<DeclContext>(D));
1034 });
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001035}
1036
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001037void ASTDumper::VisitLabelDecl(const LabelDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001038 dumpName(D);
1039}
1040
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001041void ASTDumper::VisitTypedefDecl(const TypedefDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001042 dumpName(D);
1043 dumpType(D->getUnderlyingType());
1044 if (D->isModulePrivate())
1045 OS << " __module_private__";
1046}
1047
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001048void ASTDumper::VisitEnumDecl(const EnumDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001049 if (D->isScoped()) {
1050 if (D->isScopedUsingClassTag())
1051 OS << " class";
1052 else
1053 OS << " struct";
1054 }
1055 dumpName(D);
1056 if (D->isModulePrivate())
1057 OS << " __module_private__";
1058 if (D->isFixed())
1059 dumpType(D->getIntegerType());
1060}
1061
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001062void ASTDumper::VisitRecordDecl(const RecordDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001063 OS << ' ' << D->getKindName();
1064 dumpName(D);
1065 if (D->isModulePrivate())
1066 OS << " __module_private__";
Richard Smith99bc1b92013-08-30 05:32:29 +00001067 if (D->isCompleteDefinition())
1068 OS << " definition";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001069}
1070
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001071void ASTDumper::VisitEnumConstantDecl(const EnumConstantDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001072 dumpName(D);
1073 dumpType(D->getType());
Richard Smithf7514452014-10-30 21:02:37 +00001074 if (const Expr *Init = D->getInitExpr())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001075 dumpStmt(Init);
1076}
1077
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001078void ASTDumper::VisitIndirectFieldDecl(const IndirectFieldDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001079 dumpName(D);
1080 dumpType(D->getType());
Richard Smithdcc2c452014-03-17 23:00:06 +00001081
Richard Smith8aa49222014-03-18 00:35:12 +00001082 for (auto *Child : D->chain())
Richard Smithf7514452014-10-30 21:02:37 +00001083 dumpDeclRef(Child);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001084}
1085
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001086void ASTDumper::VisitFunctionDecl(const FunctionDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001087 dumpName(D);
1088 dumpType(D->getType());
1089
Rafael Espindola6ae7e502013-04-03 19:27:57 +00001090 StorageClass SC = D->getStorageClass();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001091 if (SC != SC_None)
1092 OS << ' ' << VarDecl::getStorageClassSpecifierString(SC);
1093 if (D->isInlineSpecified())
1094 OS << " inline";
1095 if (D->isVirtualAsWritten())
1096 OS << " virtual";
1097 if (D->isModulePrivate())
1098 OS << " __module_private__";
1099
1100 if (D->isPure())
1101 OS << " pure";
1102 else if (D->isDeletedAsWritten())
1103 OS << " delete";
1104
Richard Smithadaa0152013-05-17 02:09:46 +00001105 if (const FunctionProtoType *FPT = D->getType()->getAs<FunctionProtoType>()) {
1106 FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo();
Richard Smith8acb4282014-07-31 21:57:55 +00001107 switch (EPI.ExceptionSpec.Type) {
Richard Smithadaa0152013-05-17 02:09:46 +00001108 default: break;
1109 case EST_Unevaluated:
Richard Smith8acb4282014-07-31 21:57:55 +00001110 OS << " noexcept-unevaluated " << EPI.ExceptionSpec.SourceDecl;
Richard Smithadaa0152013-05-17 02:09:46 +00001111 break;
1112 case EST_Uninstantiated:
Richard Smith8acb4282014-07-31 21:57:55 +00001113 OS << " noexcept-uninstantiated " << EPI.ExceptionSpec.SourceTemplate;
Richard Smithadaa0152013-05-17 02:09:46 +00001114 break;
1115 }
1116 }
1117
Richard Smithf7514452014-10-30 21:02:37 +00001118 if (const FunctionTemplateSpecializationInfo *FTSI =
1119 D->getTemplateSpecializationInfo())
Richard Trieude5cc7d2013-01-31 01:44:26 +00001120 dumpTemplateArgumentList(*FTSI->TemplateArguments);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001121
Dmitri Gribenkof8579502013-01-12 19:30:44 +00001122 for (ArrayRef<NamedDecl *>::iterator
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001123 I = D->getDeclsInPrototypeScope().begin(),
Richard Smithf7514452014-10-30 21:02:37 +00001124 E = D->getDeclsInPrototypeScope().end(); I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001125 dumpDecl(*I);
1126
Richard Smith8a639892015-01-24 01:07:20 +00001127 if (!D->param_begin() && D->getNumParams())
1128 dumpChild([=] { OS << "<<NULL params x " << D->getNumParams() << ">>"; });
1129 else
1130 for (FunctionDecl::param_const_iterator I = D->param_begin(),
1131 E = D->param_end();
1132 I != E; ++I)
1133 dumpDecl(*I);
Richard Smithf7514452014-10-30 21:02:37 +00001134
1135 if (const CXXConstructorDecl *C = dyn_cast<CXXConstructorDecl>(D))
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001136 for (CXXConstructorDecl::init_const_iterator I = C->init_begin(),
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001137 E = C->init_end();
Richard Smithf7514452014-10-30 21:02:37 +00001138 I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001139 dumpCXXCtorInitializer(*I);
1140
Richard Smithf7514452014-10-30 21:02:37 +00001141 if (D->doesThisDeclarationHaveABody())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001142 dumpStmt(D->getBody());
1143}
1144
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001145void ASTDumper::VisitFieldDecl(const FieldDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001146 dumpName(D);
1147 dumpType(D->getType());
1148 if (D->isMutable())
1149 OS << " mutable";
1150 if (D->isModulePrivate())
1151 OS << " __module_private__";
Richard Trieude5cc7d2013-01-31 01:44:26 +00001152
Richard Smithf7514452014-10-30 21:02:37 +00001153 if (D->isBitField())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001154 dumpStmt(D->getBitWidth());
Richard Smithf7514452014-10-30 21:02:37 +00001155 if (Expr *Init = D->getInClassInitializer())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001156 dumpStmt(Init);
1157}
1158
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001159void ASTDumper::VisitVarDecl(const VarDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001160 dumpName(D);
1161 dumpType(D->getType());
Rafael Espindola6ae7e502013-04-03 19:27:57 +00001162 StorageClass SC = D->getStorageClass();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001163 if (SC != SC_None)
1164 OS << ' ' << VarDecl::getStorageClassSpecifierString(SC);
Richard Smithfd3834f2013-04-13 02:43:54 +00001165 switch (D->getTLSKind()) {
1166 case VarDecl::TLS_None: break;
1167 case VarDecl::TLS_Static: OS << " tls"; break;
1168 case VarDecl::TLS_Dynamic: OS << " tls_dynamic"; break;
1169 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001170 if (D->isModulePrivate())
1171 OS << " __module_private__";
1172 if (D->isNRVOVariable())
1173 OS << " nrvo";
Richard Trieude5cc7d2013-01-31 01:44:26 +00001174 if (D->hasInit()) {
Richard Smithd9967cc2014-07-10 22:54:03 +00001175 switch (D->getInitStyle()) {
1176 case VarDecl::CInit: OS << " cinit"; break;
1177 case VarDecl::CallInit: OS << " callinit"; break;
1178 case VarDecl::ListInit: OS << " listinit"; break;
1179 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001180 dumpStmt(D->getInit());
Richard Trieude5cc7d2013-01-31 01:44:26 +00001181 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001182}
1183
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001184void ASTDumper::VisitFileScopeAsmDecl(const FileScopeAsmDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001185 dumpStmt(D->getAsmString());
1186}
1187
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001188void ASTDumper::VisitImportDecl(const ImportDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001189 OS << ' ' << D->getImportedModule()->getFullModuleName();
1190}
1191
1192//===----------------------------------------------------------------------===//
1193// C++ Declarations
1194//===----------------------------------------------------------------------===//
1195
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001196void ASTDumper::VisitNamespaceDecl(const NamespaceDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001197 dumpName(D);
1198 if (D->isInline())
1199 OS << " inline";
1200 if (!D->isOriginalNamespace())
1201 dumpDeclRef(D->getOriginalNamespace(), "original");
1202}
1203
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001204void ASTDumper::VisitUsingDirectiveDecl(const UsingDirectiveDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001205 OS << ' ';
1206 dumpBareDeclRef(D->getNominatedNamespace());
1207}
1208
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001209void ASTDumper::VisitNamespaceAliasDecl(const NamespaceAliasDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001210 dumpName(D);
1211 dumpDeclRef(D->getAliasedNamespace());
1212}
1213
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001214void ASTDumper::VisitTypeAliasDecl(const TypeAliasDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001215 dumpName(D);
1216 dumpType(D->getUnderlyingType());
1217}
1218
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001219void ASTDumper::VisitTypeAliasTemplateDecl(const TypeAliasTemplateDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001220 dumpName(D);
1221 dumpTemplateParameters(D->getTemplateParameters());
1222 dumpDecl(D->getTemplatedDecl());
1223}
1224
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001225void ASTDumper::VisitCXXRecordDecl(const CXXRecordDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001226 VisitRecordDecl(D);
1227 if (!D->isCompleteDefinition())
1228 return;
1229
Aaron Ballman574705e2014-03-13 15:41:46 +00001230 for (const auto &I : D->bases()) {
Richard Smithf7514452014-10-30 21:02:37 +00001231 dumpChild([=] {
1232 if (I.isVirtual())
1233 OS << "virtual ";
1234 dumpAccessSpecifier(I.getAccessSpecifier());
1235 dumpType(I.getType());
1236 if (I.isPackExpansion())
1237 OS << "...";
1238 });
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001239 }
1240}
1241
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001242void ASTDumper::VisitStaticAssertDecl(const StaticAssertDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001243 dumpStmt(D->getAssertExpr());
1244 dumpStmt(D->getMessage());
1245}
1246
Richard Smithcbdf7332014-03-18 02:07:28 +00001247template<typename SpecializationDecl>
Richard Smithf7514452014-10-30 21:02:37 +00001248void ASTDumper::VisitTemplateDeclSpecialization(const SpecializationDecl *D,
Richard Smithcbdf7332014-03-18 02:07:28 +00001249 bool DumpExplicitInst,
1250 bool DumpRefOnly) {
1251 bool DumpedAny = false;
1252 for (auto *RedeclWithBadType : D->redecls()) {
1253 // FIXME: The redecls() range sometimes has elements of a less-specific
1254 // type. (In particular, ClassTemplateSpecializationDecl::redecls() gives
1255 // us TagDecls, and should give CXXRecordDecls).
1256 auto *Redecl = dyn_cast<SpecializationDecl>(RedeclWithBadType);
1257 if (!Redecl) {
1258 // Found the injected-class-name for a class template. This will be dumped
1259 // as part of its surrounding class so we don't need to dump it here.
1260 assert(isa<CXXRecordDecl>(RedeclWithBadType) &&
1261 "expected an injected-class-name");
1262 continue;
1263 }
1264
1265 switch (Redecl->getTemplateSpecializationKind()) {
1266 case TSK_ExplicitInstantiationDeclaration:
1267 case TSK_ExplicitInstantiationDefinition:
1268 if (!DumpExplicitInst)
1269 break;
1270 // Fall through.
1271 case TSK_Undeclared:
1272 case TSK_ImplicitInstantiation:
Richard Smithf7514452014-10-30 21:02:37 +00001273 if (DumpRefOnly)
1274 dumpDeclRef(Redecl);
1275 else
1276 dumpDecl(Redecl);
Richard Smithcbdf7332014-03-18 02:07:28 +00001277 DumpedAny = true;
1278 break;
1279 case TSK_ExplicitSpecialization:
1280 break;
1281 }
1282 }
1283
1284 // Ensure we dump at least one decl for each specialization.
1285 if (!DumpedAny)
Richard Smithf7514452014-10-30 21:02:37 +00001286 dumpDeclRef(D);
Richard Smithcbdf7332014-03-18 02:07:28 +00001287}
1288
Richard Smith20ade552014-03-17 23:34:53 +00001289template<typename TemplateDecl>
1290void ASTDumper::VisitTemplateDecl(const TemplateDecl *D,
1291 bool DumpExplicitInst) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001292 dumpName(D);
1293 dumpTemplateParameters(D->getTemplateParameters());
Richard Smithdcc2c452014-03-17 23:00:06 +00001294
Richard Smithf7514452014-10-30 21:02:37 +00001295 dumpDecl(D->getTemplatedDecl());
Richard Smithdcc2c452014-03-17 23:00:06 +00001296
Richard Smithcbdf7332014-03-18 02:07:28 +00001297 for (auto *Child : D->specializations())
Richard Smithf7514452014-10-30 21:02:37 +00001298 VisitTemplateDeclSpecialization(Child, DumpExplicitInst,
Richard Smithcbdf7332014-03-18 02:07:28 +00001299 !D->isCanonicalDecl());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001300}
1301
Richard Smith20ade552014-03-17 23:34:53 +00001302void ASTDumper::VisitFunctionTemplateDecl(const FunctionTemplateDecl *D) {
1303 // FIXME: We don't add a declaration of a function template specialization
1304 // to its context when it's explicitly instantiated, so dump explicit
1305 // instantiations when we dump the template itself.
1306 VisitTemplateDecl(D, true);
1307}
1308
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001309void ASTDumper::VisitClassTemplateDecl(const ClassTemplateDecl *D) {
Richard Smith20ade552014-03-17 23:34:53 +00001310 VisitTemplateDecl(D, false);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001311}
1312
1313void ASTDumper::VisitClassTemplateSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001314 const ClassTemplateSpecializationDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001315 VisitCXXRecordDecl(D);
1316 dumpTemplateArgumentList(D->getTemplateArgs());
1317}
1318
1319void ASTDumper::VisitClassTemplatePartialSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001320 const ClassTemplatePartialSpecializationDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001321 VisitClassTemplateSpecializationDecl(D);
1322 dumpTemplateParameters(D->getTemplateParameters());
1323}
1324
1325void ASTDumper::VisitClassScopeFunctionSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001326 const ClassScopeFunctionSpecializationDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001327 dumpDeclRef(D->getSpecialization());
1328 if (D->hasExplicitTemplateArgs())
1329 dumpTemplateArgumentListInfo(D->templateArgs());
1330}
1331
Richard Smithd25789a2013-09-18 01:36:02 +00001332void ASTDumper::VisitVarTemplateDecl(const VarTemplateDecl *D) {
Richard Smith20ade552014-03-17 23:34:53 +00001333 VisitTemplateDecl(D, false);
Richard Smithd25789a2013-09-18 01:36:02 +00001334}
1335
1336void ASTDumper::VisitVarTemplateSpecializationDecl(
1337 const VarTemplateSpecializationDecl *D) {
1338 dumpTemplateArgumentList(D->getTemplateArgs());
1339 VisitVarDecl(D);
1340}
1341
1342void ASTDumper::VisitVarTemplatePartialSpecializationDecl(
1343 const VarTemplatePartialSpecializationDecl *D) {
1344 dumpTemplateParameters(D->getTemplateParameters());
1345 VisitVarTemplateSpecializationDecl(D);
1346}
1347
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001348void ASTDumper::VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001349 if (D->wasDeclaredWithTypename())
1350 OS << " typename";
1351 else
1352 OS << " class";
1353 if (D->isParameterPack())
1354 OS << " ...";
1355 dumpName(D);
Richard Smithf7514452014-10-30 21:02:37 +00001356 if (D->hasDefaultArgument())
Richard Smithecf74ff2014-03-23 20:50:39 +00001357 dumpTemplateArgument(D->getDefaultArgument());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001358}
1359
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001360void ASTDumper::VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001361 dumpType(D->getType());
1362 if (D->isParameterPack())
1363 OS << " ...";
1364 dumpName(D);
Richard Smithf7514452014-10-30 21:02:37 +00001365 if (D->hasDefaultArgument())
Richard Smithecf74ff2014-03-23 20:50:39 +00001366 dumpTemplateArgument(D->getDefaultArgument());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001367}
1368
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001369void ASTDumper::VisitTemplateTemplateParmDecl(
1370 const TemplateTemplateParmDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001371 if (D->isParameterPack())
1372 OS << " ...";
1373 dumpName(D);
1374 dumpTemplateParameters(D->getTemplateParameters());
Richard Smithf7514452014-10-30 21:02:37 +00001375 if (D->hasDefaultArgument())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001376 dumpTemplateArgumentLoc(D->getDefaultArgument());
1377}
1378
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001379void ASTDumper::VisitUsingDecl(const UsingDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001380 OS << ' ';
1381 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
1382 OS << D->getNameAsString();
1383}
1384
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001385void ASTDumper::VisitUnresolvedUsingTypenameDecl(
1386 const UnresolvedUsingTypenameDecl *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::VisitUnresolvedUsingValueDecl(const UnresolvedUsingValueDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001393 OS << ' ';
1394 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
1395 OS << D->getNameAsString();
1396 dumpType(D->getType());
1397}
1398
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001399void ASTDumper::VisitUsingShadowDecl(const UsingShadowDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001400 OS << ' ';
1401 dumpBareDeclRef(D->getTargetDecl());
1402}
1403
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001404void ASTDumper::VisitLinkageSpecDecl(const LinkageSpecDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001405 switch (D->getLanguage()) {
1406 case LinkageSpecDecl::lang_c: OS << " C"; break;
1407 case LinkageSpecDecl::lang_cxx: OS << " C++"; break;
1408 }
1409}
1410
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001411void ASTDumper::VisitAccessSpecDecl(const AccessSpecDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001412 OS << ' ';
1413 dumpAccessSpecifier(D->getAccess());
1414}
1415
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001416void ASTDumper::VisitFriendDecl(const FriendDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001417 if (TypeSourceInfo *T = D->getFriendType())
1418 dumpType(T->getType());
1419 else
1420 dumpDecl(D->getFriendDecl());
1421}
1422
1423//===----------------------------------------------------------------------===//
1424// Obj-C Declarations
1425//===----------------------------------------------------------------------===//
1426
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001427void ASTDumper::VisitObjCIvarDecl(const ObjCIvarDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001428 dumpName(D);
1429 dumpType(D->getType());
1430 if (D->getSynthesize())
1431 OS << " synthesize";
1432
1433 switch (D->getAccessControl()) {
1434 case ObjCIvarDecl::None:
1435 OS << " none";
1436 break;
1437 case ObjCIvarDecl::Private:
1438 OS << " private";
1439 break;
1440 case ObjCIvarDecl::Protected:
1441 OS << " protected";
1442 break;
1443 case ObjCIvarDecl::Public:
1444 OS << " public";
1445 break;
1446 case ObjCIvarDecl::Package:
1447 OS << " package";
1448 break;
1449 }
1450}
1451
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001452void ASTDumper::VisitObjCMethodDecl(const ObjCMethodDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001453 if (D->isInstanceMethod())
1454 OS << " -";
1455 else
1456 OS << " +";
1457 dumpName(D);
Alp Toker314cc812014-01-25 16:55:45 +00001458 dumpType(D->getReturnType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001459
Richard Trieude5cc7d2013-01-31 01:44:26 +00001460 if (D->isThisDeclarationADefinition()) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001461 dumpDeclContext(D);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001462 } else {
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001463 for (ObjCMethodDecl::param_const_iterator I = D->param_begin(),
1464 E = D->param_end();
Richard Smithf7514452014-10-30 21:02:37 +00001465 I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001466 dumpDecl(*I);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001467 }
1468
Richard Smithf7514452014-10-30 21:02:37 +00001469 if (D->isVariadic())
1470 dumpChild([=] { OS << "..."; });
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001471
Richard Smithf7514452014-10-30 21:02:37 +00001472 if (D->hasBody())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001473 dumpStmt(D->getBody());
1474}
1475
Douglas Gregor85f3f952015-07-07 03:57:15 +00001476void ASTDumper::VisitObjCTypeParamDecl(const ObjCTypeParamDecl *D) {
1477 dumpName(D);
1478 if (D->hasExplicitBound())
1479 OS << " bounded";
1480 dumpType(D->getUnderlyingType());
1481}
1482
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001483void ASTDumper::VisitObjCCategoryDecl(const ObjCCategoryDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001484 dumpName(D);
1485 dumpDeclRef(D->getClassInterface());
Douglas Gregor85f3f952015-07-07 03:57:15 +00001486 dumpObjCTypeParamList(D->getTypeParamList());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001487 dumpDeclRef(D->getImplementation());
1488 for (ObjCCategoryDecl::protocol_iterator I = D->protocol_begin(),
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001489 E = D->protocol_end();
Richard Smithf7514452014-10-30 21:02:37 +00001490 I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001491 dumpDeclRef(*I);
1492}
1493
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001494void ASTDumper::VisitObjCCategoryImplDecl(const ObjCCategoryImplDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001495 dumpName(D);
1496 dumpDeclRef(D->getClassInterface());
1497 dumpDeclRef(D->getCategoryDecl());
1498}
1499
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001500void ASTDumper::VisitObjCProtocolDecl(const ObjCProtocolDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001501 dumpName(D);
Richard Smithdcc2c452014-03-17 23:00:06 +00001502
Richard Smith7fcb35f2014-03-18 02:37:59 +00001503 for (auto *Child : D->protocols())
Richard Smithf7514452014-10-30 21:02:37 +00001504 dumpDeclRef(Child);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001505}
1506
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001507void ASTDumper::VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001508 dumpName(D);
Douglas Gregor85f3f952015-07-07 03:57:15 +00001509 dumpObjCTypeParamList(D->getTypeParamListAsWritten());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001510 dumpDeclRef(D->getSuperClass(), "super");
Richard Smithdcc2c452014-03-17 23:00:06 +00001511
Richard Smithf7514452014-10-30 21:02:37 +00001512 dumpDeclRef(D->getImplementation());
Richard Smith7fcb35f2014-03-18 02:37:59 +00001513 for (auto *Child : D->protocols())
Richard Smithf7514452014-10-30 21:02:37 +00001514 dumpDeclRef(Child);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001515}
1516
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001517void ASTDumper::VisitObjCImplementationDecl(const ObjCImplementationDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001518 dumpName(D);
1519 dumpDeclRef(D->getSuperClass(), "super");
1520 dumpDeclRef(D->getClassInterface());
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001521 for (ObjCImplementationDecl::init_const_iterator I = D->init_begin(),
1522 E = D->init_end();
Richard Smithf7514452014-10-30 21:02:37 +00001523 I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001524 dumpCXXCtorInitializer(*I);
1525}
1526
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001527void ASTDumper::VisitObjCCompatibleAliasDecl(const ObjCCompatibleAliasDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001528 dumpName(D);
1529 dumpDeclRef(D->getClassInterface());
1530}
1531
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001532void ASTDumper::VisitObjCPropertyDecl(const ObjCPropertyDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001533 dumpName(D);
1534 dumpType(D->getType());
1535
1536 if (D->getPropertyImplementation() == ObjCPropertyDecl::Required)
1537 OS << " required";
1538 else if (D->getPropertyImplementation() == ObjCPropertyDecl::Optional)
1539 OS << " optional";
1540
1541 ObjCPropertyDecl::PropertyAttributeKind Attrs = D->getPropertyAttributes();
1542 if (Attrs != ObjCPropertyDecl::OBJC_PR_noattr) {
1543 if (Attrs & ObjCPropertyDecl::OBJC_PR_readonly)
1544 OS << " readonly";
1545 if (Attrs & ObjCPropertyDecl::OBJC_PR_assign)
1546 OS << " assign";
1547 if (Attrs & ObjCPropertyDecl::OBJC_PR_readwrite)
1548 OS << " readwrite";
1549 if (Attrs & ObjCPropertyDecl::OBJC_PR_retain)
1550 OS << " retain";
1551 if (Attrs & ObjCPropertyDecl::OBJC_PR_copy)
1552 OS << " copy";
1553 if (Attrs & ObjCPropertyDecl::OBJC_PR_nonatomic)
1554 OS << " nonatomic";
1555 if (Attrs & ObjCPropertyDecl::OBJC_PR_atomic)
1556 OS << " atomic";
1557 if (Attrs & ObjCPropertyDecl::OBJC_PR_weak)
1558 OS << " weak";
1559 if (Attrs & ObjCPropertyDecl::OBJC_PR_strong)
1560 OS << " strong";
1561 if (Attrs & ObjCPropertyDecl::OBJC_PR_unsafe_unretained)
1562 OS << " unsafe_unretained";
Richard Smithf7514452014-10-30 21:02:37 +00001563 if (Attrs & ObjCPropertyDecl::OBJC_PR_getter)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001564 dumpDeclRef(D->getGetterMethodDecl(), "getter");
Richard Smithf7514452014-10-30 21:02:37 +00001565 if (Attrs & ObjCPropertyDecl::OBJC_PR_setter)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001566 dumpDeclRef(D->getSetterMethodDecl(), "setter");
1567 }
1568}
1569
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001570void ASTDumper::VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001571 dumpName(D->getPropertyDecl());
1572 if (D->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize)
1573 OS << " synthesize";
1574 else
1575 OS << " dynamic";
1576 dumpDeclRef(D->getPropertyDecl());
1577 dumpDeclRef(D->getPropertyIvarDecl());
1578}
1579
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001580void ASTDumper::VisitBlockDecl(const BlockDecl *D) {
Aaron Ballmanb2b8b1d2014-03-07 16:09:59 +00001581 for (auto I : D->params())
1582 dumpDecl(I);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001583
Richard Smithf7514452014-10-30 21:02:37 +00001584 if (D->isVariadic())
1585 dumpChild([=]{ OS << "..."; });
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001586
Richard Smithf7514452014-10-30 21:02:37 +00001587 if (D->capturesCXXThis())
1588 dumpChild([=]{ OS << "capture this"; });
1589
Aaron Ballman9371dd22014-03-14 18:34:04 +00001590 for (const auto &I : D->captures()) {
Richard Smithf7514452014-10-30 21:02:37 +00001591 dumpChild([=] {
1592 OS << "capture";
1593 if (I.isByRef())
1594 OS << " byref";
1595 if (I.isNested())
1596 OS << " nested";
1597 if (I.getVariable()) {
1598 OS << ' ';
1599 dumpBareDeclRef(I.getVariable());
1600 }
1601 if (I.hasCopyExpr())
1602 dumpStmt(I.getCopyExpr());
1603 });
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001604 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001605 dumpStmt(D->getBody());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001606}
1607
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001608//===----------------------------------------------------------------------===//
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001609// Stmt dumping methods.
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001610//===----------------------------------------------------------------------===//
1611
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001612void ASTDumper::dumpStmt(const Stmt *S) {
Richard Smithf7514452014-10-30 21:02:37 +00001613 dumpChild([=] {
1614 if (!S) {
1615 ColorScope Color(*this, NullColor);
1616 OS << "<<<NULL>>>";
1617 return;
1618 }
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001619
Richard Smithf7514452014-10-30 21:02:37 +00001620 if (const DeclStmt *DS = dyn_cast<DeclStmt>(S)) {
1621 VisitDeclStmt(DS);
1622 return;
1623 }
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001624
Richard Smithf7514452014-10-30 21:02:37 +00001625 ConstStmtVisitor<ASTDumper>::Visit(S);
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001626
Benjamin Kramer642f1732015-07-02 21:03:14 +00001627 for (const Stmt *SubStmt : S->children())
1628 dumpStmt(SubStmt);
Richard Smithf7514452014-10-30 21:02:37 +00001629 });
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001630}
1631
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001632void ASTDumper::VisitStmt(const Stmt *Node) {
Richard Trieud215b8d2013-01-26 01:31:20 +00001633 {
1634 ColorScope Color(*this, StmtColor);
1635 OS << Node->getStmtClassName();
1636 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001637 dumpPointer(Node);
1638 dumpSourceRange(Node->getSourceRange());
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001639}
1640
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001641void ASTDumper::VisitDeclStmt(const DeclStmt *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001642 VisitStmt(Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001643 for (DeclStmt::const_decl_iterator I = Node->decl_begin(),
1644 E = Node->decl_end();
Richard Smithf7514452014-10-30 21:02:37 +00001645 I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001646 dumpDecl(*I);
Ted Kremenek433a4922007-12-12 06:59:42 +00001647}
1648
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001649void ASTDumper::VisitAttributedStmt(const AttributedStmt *Node) {
Alexander Kornienko5bc364e2013-01-07 17:53:08 +00001650 VisitStmt(Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001651 for (ArrayRef<const Attr *>::iterator I = Node->getAttrs().begin(),
1652 E = Node->getAttrs().end();
Richard Smithf7514452014-10-30 21:02:37 +00001653 I != E; ++I)
Alexander Kornienko5bc364e2013-01-07 17:53:08 +00001654 dumpAttr(*I);
1655}
1656
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001657void ASTDumper::VisitLabelStmt(const LabelStmt *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001658 VisitStmt(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001659 OS << " '" << Node->getName() << "'";
Chris Lattnercbe4f772007-08-08 22:51:59 +00001660}
1661
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001662void ASTDumper::VisitGotoStmt(const GotoStmt *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001663 VisitStmt(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001664 OS << " '" << Node->getLabel()->getName() << "'";
1665 dumpPointer(Node->getLabel());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001666}
1667
Pavel Labath1ef83422013-09-04 14:35:00 +00001668void ASTDumper::VisitCXXCatchStmt(const CXXCatchStmt *Node) {
1669 VisitStmt(Node);
1670 dumpDecl(Node->getExceptionDecl());
1671}
1672
Chris Lattnercbe4f772007-08-08 22:51:59 +00001673//===----------------------------------------------------------------------===//
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001674// Expr dumping methods.
Chris Lattnercbe4f772007-08-08 22:51:59 +00001675//===----------------------------------------------------------------------===//
1676
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001677void ASTDumper::VisitExpr(const Expr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001678 VisitStmt(Node);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001679 dumpType(Node->getType());
1680
Richard Trieud215b8d2013-01-26 01:31:20 +00001681 {
1682 ColorScope Color(*this, ValueKindColor);
1683 switch (Node->getValueKind()) {
1684 case VK_RValue:
1685 break;
1686 case VK_LValue:
1687 OS << " lvalue";
1688 break;
1689 case VK_XValue:
1690 OS << " xvalue";
1691 break;
1692 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001693 }
1694
Richard Trieud215b8d2013-01-26 01:31:20 +00001695 {
1696 ColorScope Color(*this, ObjectKindColor);
1697 switch (Node->getObjectKind()) {
1698 case OK_Ordinary:
1699 break;
1700 case OK_BitField:
1701 OS << " bitfield";
1702 break;
1703 case OK_ObjCProperty:
1704 OS << " objcproperty";
1705 break;
1706 case OK_ObjCSubscript:
1707 OS << " objcsubscript";
1708 break;
1709 case OK_VectorComponent:
1710 OS << " vectorcomponent";
1711 break;
1712 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001713 }
Chris Lattnercbe4f772007-08-08 22:51:59 +00001714}
1715
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001716static void dumpBasePath(raw_ostream &OS, const CastExpr *Node) {
John McCallcf142162010-08-07 06:22:56 +00001717 if (Node->path_empty())
Anders Carlssona70cff62010-04-24 19:06:50 +00001718 return;
1719
1720 OS << " (";
1721 bool First = true;
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001722 for (CastExpr::path_const_iterator I = Node->path_begin(),
1723 E = Node->path_end();
1724 I != E; ++I) {
Anders Carlssona70cff62010-04-24 19:06:50 +00001725 const CXXBaseSpecifier *Base = *I;
1726 if (!First)
1727 OS << " -> ";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001728
Anders Carlssona70cff62010-04-24 19:06:50 +00001729 const CXXRecordDecl *RD =
1730 cast<CXXRecordDecl>(Base->getType()->getAs<RecordType>()->getDecl());
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001731
Anders Carlssona70cff62010-04-24 19:06:50 +00001732 if (Base->isVirtual())
1733 OS << "virtual ";
1734 OS << RD->getName();
1735 First = false;
1736 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001737
Anders Carlssona70cff62010-04-24 19:06:50 +00001738 OS << ')';
1739}
1740
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001741void ASTDumper::VisitCastExpr(const CastExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001742 VisitExpr(Node);
Richard Trieud215b8d2013-01-26 01:31:20 +00001743 OS << " <";
1744 {
1745 ColorScope Color(*this, CastColor);
1746 OS << Node->getCastKindName();
1747 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001748 dumpBasePath(OS, Node);
Anders Carlssona70cff62010-04-24 19:06:50 +00001749 OS << ">";
Anders Carlssond7923c62009-08-22 23:33:40 +00001750}
1751
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001752void ASTDumper::VisitDeclRefExpr(const DeclRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001753 VisitExpr(Node);
Ted Kremenek5f64ca82007-09-10 17:32:55 +00001754
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001755 OS << " ";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001756 dumpBareDeclRef(Node->getDecl());
Chandler Carruth8d26bb02011-05-01 23:48:14 +00001757 if (Node->getDecl() != Node->getFoundDecl()) {
1758 OS << " (";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001759 dumpBareDeclRef(Node->getFoundDecl());
Chandler Carruth8d26bb02011-05-01 23:48:14 +00001760 OS << ")";
1761 }
John McCall351762c2011-02-07 10:33:21 +00001762}
1763
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001764void ASTDumper::VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001765 VisitExpr(Node);
John McCall76d09942009-12-11 21:50:11 +00001766 OS << " (";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001767 if (!Node->requiresADL())
1768 OS << "no ";
Benjamin Kramerb11416d2010-04-17 09:33:03 +00001769 OS << "ADL) = '" << Node->getName() << '\'';
John McCall76d09942009-12-11 21:50:11 +00001770
1771 UnresolvedLookupExpr::decls_iterator
1772 I = Node->decls_begin(), E = Node->decls_end();
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001773 if (I == E)
1774 OS << " empty";
John McCall76d09942009-12-11 21:50:11 +00001775 for (; I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001776 dumpPointer(*I);
John McCall76d09942009-12-11 21:50:11 +00001777}
1778
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001779void ASTDumper::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001780 VisitExpr(Node);
Steve Naroff5d5efca2008-03-12 13:19:12 +00001781
Richard Trieud215b8d2013-01-26 01:31:20 +00001782 {
1783 ColorScope Color(*this, DeclKindNameColor);
1784 OS << " " << Node->getDecl()->getDeclKindName() << "Decl";
1785 }
1786 OS << "='" << *Node->getDecl() << "'";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001787 dumpPointer(Node->getDecl());
Steve Naroffb3424a92008-05-23 22:01:24 +00001788 if (Node->isFreeIvar())
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001789 OS << " isFreeIvar";
Steve Naroff5d5efca2008-03-12 13:19:12 +00001790}
1791
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001792void ASTDumper::VisitPredefinedExpr(const PredefinedExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001793 VisitExpr(Node);
Alexey Bataevec474782014-10-09 08:45:04 +00001794 OS << " " << PredefinedExpr::getIdentTypeName(Node->getIdentType());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001795}
1796
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001797void ASTDumper::VisitCharacterLiteral(const CharacterLiteral *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001798 VisitExpr(Node);
Richard Trieud215b8d2013-01-26 01:31:20 +00001799 ColorScope Color(*this, ValueColor);
Richard Trieu364ee422011-11-03 23:56:23 +00001800 OS << " " << Node->getValue();
Chris Lattnercbe4f772007-08-08 22:51:59 +00001801}
1802
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001803void ASTDumper::VisitIntegerLiteral(const IntegerLiteral *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001804 VisitExpr(Node);
Chris Lattnercbe4f772007-08-08 22:51:59 +00001805
1806 bool isSigned = Node->getType()->isSignedIntegerType();
Richard Trieud215b8d2013-01-26 01:31:20 +00001807 ColorScope Color(*this, ValueColor);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001808 OS << " " << Node->getValue().toString(10, isSigned);
Chris Lattnercbe4f772007-08-08 22:51:59 +00001809}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001810
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001811void ASTDumper::VisitFloatingLiteral(const FloatingLiteral *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001812 VisitExpr(Node);
Richard Trieud215b8d2013-01-26 01:31:20 +00001813 ColorScope Color(*this, ValueColor);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001814 OS << " " << Node->getValueAsApproximateDouble();
Chris Lattnercbe4f772007-08-08 22:51:59 +00001815}
Chris Lattner1c20a172007-08-26 03:42:43 +00001816
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001817void ASTDumper::VisitStringLiteral(const StringLiteral *Str) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001818 VisitExpr(Str);
Richard Trieud215b8d2013-01-26 01:31:20 +00001819 ColorScope Color(*this, ValueColor);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001820 OS << " ";
Richard Trieudc355912012-06-13 20:25:24 +00001821 Str->outputString(OS);
Chris Lattnercbe4f772007-08-08 22:51:59 +00001822}
Chris Lattner84ca3762007-08-30 01:00:35 +00001823
Richard Smithf0514962014-06-03 08:24:28 +00001824void ASTDumper::VisitInitListExpr(const InitListExpr *ILE) {
1825 VisitExpr(ILE);
1826 if (auto *Filler = ILE->getArrayFiller()) {
Richard Smithf7514452014-10-30 21:02:37 +00001827 dumpChild([=] {
1828 OS << "array filler";
1829 dumpStmt(Filler);
1830 });
Richard Smithf0514962014-06-03 08:24:28 +00001831 }
1832 if (auto *Field = ILE->getInitializedFieldInUnion()) {
1833 OS << " field ";
1834 dumpBareDeclRef(Field);
1835 }
1836}
1837
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001838void ASTDumper::VisitUnaryOperator(const UnaryOperator *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001839 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001840 OS << " " << (Node->isPostfix() ? "postfix" : "prefix")
1841 << " '" << UnaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
Chris Lattnercbe4f772007-08-08 22:51:59 +00001842}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001843
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001844void ASTDumper::VisitUnaryExprOrTypeTraitExpr(
1845 const UnaryExprOrTypeTraitExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001846 VisitExpr(Node);
Peter Collingbournee190dee2011-03-11 19:24:49 +00001847 switch(Node->getKind()) {
1848 case UETT_SizeOf:
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001849 OS << " sizeof";
Peter Collingbournee190dee2011-03-11 19:24:49 +00001850 break;
1851 case UETT_AlignOf:
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001852 OS << " alignof";
Peter Collingbournee190dee2011-03-11 19:24:49 +00001853 break;
1854 case UETT_VecStep:
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001855 OS << " vec_step";
Peter Collingbournee190dee2011-03-11 19:24:49 +00001856 break;
Alexey Bataev00396512015-07-02 03:40:19 +00001857 case UETT_OpenMPRequiredSimdAlign:
1858 OS << " __builtin_omp_required_simd_align";
1859 break;
Peter Collingbournee190dee2011-03-11 19:24:49 +00001860 }
Sebastian Redl6f282892008-11-11 17:56:53 +00001861 if (Node->isArgumentType())
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001862 dumpType(Node->getArgumentType());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001863}
Chris Lattnerdb3b3ff2007-08-09 17:35:30 +00001864
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001865void ASTDumper::VisitMemberExpr(const MemberExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001866 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001867 OS << " " << (Node->isArrow() ? "->" : ".") << *Node->getMemberDecl();
1868 dumpPointer(Node->getMemberDecl());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001869}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001870
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001871void ASTDumper::VisitExtVectorElementExpr(const ExtVectorElementExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001872 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001873 OS << " " << Node->getAccessor().getNameStart();
Chris Lattnercbe4f772007-08-08 22:51:59 +00001874}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001875
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001876void ASTDumper::VisitBinaryOperator(const BinaryOperator *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001877 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001878 OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
Chris Lattner86928112007-08-25 02:00:02 +00001879}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001880
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001881void ASTDumper::VisitCompoundAssignOperator(
1882 const CompoundAssignOperator *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001883 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001884 OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode())
1885 << "' ComputeLHSTy=";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001886 dumpBareType(Node->getComputationLHSType());
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001887 OS << " ComputeResultTy=";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001888 dumpBareType(Node->getComputationResultType());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001889}
Chris Lattnercbe4f772007-08-08 22:51:59 +00001890
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001891void ASTDumper::VisitBlockExpr(const BlockExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001892 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001893 dumpDecl(Node->getBlockDecl());
John McCall351762c2011-02-07 10:33:21 +00001894}
1895
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001896void ASTDumper::VisitOpaqueValueExpr(const OpaqueValueExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001897 VisitExpr(Node);
John McCallfe96e0b2011-11-06 09:01:30 +00001898
Richard Smithf7514452014-10-30 21:02:37 +00001899 if (Expr *Source = Node->getSourceExpr())
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001900 dumpStmt(Source);
John McCallfe96e0b2011-11-06 09:01:30 +00001901}
1902
Chris Lattnercbe4f772007-08-08 22:51:59 +00001903// GNU extensions.
1904
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001905void ASTDumper::VisitAddrLabelExpr(const AddrLabelExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001906 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001907 OS << " " << Node->getLabel()->getName();
1908 dumpPointer(Node->getLabel());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001909}
1910
Chris Lattner8f184b12007-08-09 18:03:18 +00001911//===----------------------------------------------------------------------===//
1912// C++ Expressions
1913//===----------------------------------------------------------------------===//
Chris Lattnercbe4f772007-08-08 22:51:59 +00001914
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001915void ASTDumper::VisitCXXNamedCastExpr(const CXXNamedCastExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001916 VisitExpr(Node);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001917 OS << " " << Node->getCastName()
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001918 << "<" << Node->getTypeAsWritten().getAsString() << ">"
Anders Carlssona70cff62010-04-24 19:06:50 +00001919 << " <" << Node->getCastKindName();
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001920 dumpBasePath(OS, Node);
Anders Carlssona70cff62010-04-24 19:06:50 +00001921 OS << ">";
Chris Lattnercbe4f772007-08-08 22:51:59 +00001922}
1923
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001924void ASTDumper::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001925 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001926 OS << " " << (Node->getValue() ? "true" : "false");
Chris Lattnercbe4f772007-08-08 22:51:59 +00001927}
1928
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001929void ASTDumper::VisitCXXThisExpr(const CXXThisExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001930 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001931 OS << " this";
Douglas Gregor8ea1f532008-11-04 14:56:14 +00001932}
1933
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001934void ASTDumper::VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001935 VisitExpr(Node);
Eli Friedman29538892011-09-02 17:38:59 +00001936 OS << " functional cast to " << Node->getTypeAsWritten().getAsString()
1937 << " <" << Node->getCastKindName() << ">";
Douglas Gregore200adc2008-10-27 19:41:14 +00001938}
1939
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001940void ASTDumper::VisitCXXConstructExpr(const CXXConstructExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001941 VisitExpr(Node);
John McCalleba90cd2010-02-02 19:03:45 +00001942 CXXConstructorDecl *Ctor = Node->getConstructor();
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001943 dumpType(Ctor->getType());
Anders Carlsson073846832009-08-12 00:21:52 +00001944 if (Node->isElidable())
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001945 OS << " elidable";
John McCall85370042010-08-07 06:38:55 +00001946 if (Node->requiresZeroInitialization())
1947 OS << " zeroing";
Anders Carlsson073846832009-08-12 00:21:52 +00001948}
1949
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001950void ASTDumper::VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001951 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001952 OS << " ";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001953 dumpCXXTemporary(Node->getTemporary());
Anders Carlsson073846832009-08-12 00:21:52 +00001954}
1955
Reid Kleckner5c682bc2015-03-19 18:09:25 +00001956void ASTDumper::VisitCXXNewExpr(const CXXNewExpr *Node) {
1957 VisitExpr(Node);
Reid Kleckner5c682bc2015-03-19 18:09:25 +00001958 if (Node->isGlobalNew())
Reid Kleckner461c0c62015-03-19 18:47:47 +00001959 OS << " global";
Reid Kleckner5c682bc2015-03-19 18:09:25 +00001960 if (Node->isArray())
Reid Kleckner461c0c62015-03-19 18:47:47 +00001961 OS << " array";
1962 if (Node->getOperatorNew()) {
1963 OS << ' ';
1964 dumpBareDeclRef(Node->getOperatorNew());
1965 }
Reid Kleckner5c682bc2015-03-19 18:09:25 +00001966 // We could dump the deallocation function used in case of error, but it's
1967 // usually not that interesting.
1968}
1969
1970void ASTDumper::VisitCXXDeleteExpr(const CXXDeleteExpr *Node) {
1971 VisitExpr(Node);
Reid Kleckner5c682bc2015-03-19 18:09:25 +00001972 if (Node->isGlobalDelete())
Reid Kleckner461c0c62015-03-19 18:47:47 +00001973 OS << " global";
Reid Kleckner5c682bc2015-03-19 18:09:25 +00001974 if (Node->isArrayForm())
Reid Kleckner461c0c62015-03-19 18:47:47 +00001975 OS << " array";
1976 if (Node->getOperatorDelete()) {
1977 OS << ' ';
1978 dumpBareDeclRef(Node->getOperatorDelete());
1979 }
Reid Kleckner5c682bc2015-03-19 18:09:25 +00001980}
1981
Richard Smithe6c01442013-06-05 00:46:14 +00001982void
1983ASTDumper::VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *Node) {
1984 VisitExpr(Node);
1985 if (const ValueDecl *VD = Node->getExtendingDecl()) {
1986 OS << " extended by ";
1987 dumpBareDeclRef(VD);
1988 }
1989}
1990
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001991void ASTDumper::VisitExprWithCleanups(const ExprWithCleanups *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001992 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001993 for (unsigned i = 0, e = Node->getNumObjects(); i != e; ++i)
1994 dumpDeclRef(Node->getObject(i), "cleanup");
Anders Carlsson073846832009-08-12 00:21:52 +00001995}
1996
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001997void ASTDumper::dumpCXXTemporary(const CXXTemporary *Temporary) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001998 OS << "(CXXTemporary";
1999 dumpPointer(Temporary);
2000 OS << ")";
Anders Carlsson073846832009-08-12 00:21:52 +00002001}
2002
Serge Pavlov6b926032015-02-16 19:58:41 +00002003void ASTDumper::VisitSizeOfPackExpr(const SizeOfPackExpr *Node) {
2004 VisitExpr(Node);
2005 dumpPointer(Node->getPack());
2006 dumpName(Node->getPack());
2007}
2008
2009
Anders Carlsson76f4a902007-08-21 17:43:55 +00002010//===----------------------------------------------------------------------===//
2011// Obj-C Expressions
2012//===----------------------------------------------------------------------===//
2013
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002014void ASTDumper::VisitObjCMessageExpr(const ObjCMessageExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002015 VisitExpr(Node);
Aaron Ballmanb190f972014-01-03 17:59:55 +00002016 OS << " selector=";
2017 Node->getSelector().print(OS);
Douglas Gregor9a129192010-04-21 00:45:42 +00002018 switch (Node->getReceiverKind()) {
2019 case ObjCMessageExpr::Instance:
2020 break;
2021
2022 case ObjCMessageExpr::Class:
2023 OS << " class=";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002024 dumpBareType(Node->getClassReceiver());
Douglas Gregor9a129192010-04-21 00:45:42 +00002025 break;
2026
2027 case ObjCMessageExpr::SuperInstance:
2028 OS << " super (instance)";
2029 break;
2030
2031 case ObjCMessageExpr::SuperClass:
2032 OS << " super (class)";
2033 break;
2034 }
Ted Kremenek36748da2008-02-29 22:04:05 +00002035}
2036
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002037void ASTDumper::VisitObjCBoxedExpr(const ObjCBoxedExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002038 VisitExpr(Node);
Aaron Ballmanb190f972014-01-03 17:59:55 +00002039 OS << " selector=";
2040 Node->getBoxingMethod()->getSelector().print(OS);
Argyrios Kyrtzidis9dd40892012-05-10 20:02:31 +00002041}
2042
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002043void ASTDumper::VisitObjCAtCatchStmt(const ObjCAtCatchStmt *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002044 VisitStmt(Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002045 if (const VarDecl *CatchParam = Node->getCatchParamDecl())
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002046 dumpDecl(CatchParam);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002047 else
Douglas Gregor96c79492010-04-23 22:50:49 +00002048 OS << " catch all";
Douglas Gregor96c79492010-04-23 22:50:49 +00002049}
2050
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002051void ASTDumper::VisitObjCEncodeExpr(const ObjCEncodeExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002052 VisitExpr(Node);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002053 dumpType(Node->getEncodedType());
Anders Carlssonc5a81eb2007-08-22 15:14:15 +00002054}
2055
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002056void ASTDumper::VisitObjCSelectorExpr(const ObjCSelectorExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002057 VisitExpr(Node);
Mike Stump11289f42009-09-09 15:08:12 +00002058
Aaron Ballmanb190f972014-01-03 17:59:55 +00002059 OS << " ";
2060 Node->getSelector().print(OS);
Fariborz Jahanian4bef4622007-10-16 20:40:23 +00002061}
2062
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002063void ASTDumper::VisitObjCProtocolExpr(const ObjCProtocolExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002064 VisitExpr(Node);
Mike Stump11289f42009-09-09 15:08:12 +00002065
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002066 OS << ' ' << *Node->getProtocol();
Fariborz Jahaniana32aaef2007-10-17 16:58:11 +00002067}
Daniel Dunbar4b8c6db2008-08-30 05:35:15 +00002068
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002069void ASTDumper::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002070 VisitExpr(Node);
John McCallb7bd14f2010-12-02 01:19:52 +00002071 if (Node->isImplicitProperty()) {
Fariborz Jahanian0f0b3022010-12-22 19:46:35 +00002072 OS << " Kind=MethodRef Getter=\"";
2073 if (Node->getImplicitPropertyGetter())
Aaron Ballmanb190f972014-01-03 17:59:55 +00002074 Node->getImplicitPropertyGetter()->getSelector().print(OS);
Fariborz Jahanian0f0b3022010-12-22 19:46:35 +00002075 else
2076 OS << "(null)";
2077
2078 OS << "\" Setter=\"";
John McCallb7bd14f2010-12-02 01:19:52 +00002079 if (ObjCMethodDecl *Setter = Node->getImplicitPropertySetter())
Aaron Ballmanb190f972014-01-03 17:59:55 +00002080 Setter->getSelector().print(OS);
John McCallb7bd14f2010-12-02 01:19:52 +00002081 else
2082 OS << "(null)";
2083 OS << "\"";
2084 } else {
Benjamin Kramerb89514a2011-10-14 18:45:37 +00002085 OS << " Kind=PropertyRef Property=\"" << *Node->getExplicitProperty() <<'"';
John McCallb7bd14f2010-12-02 01:19:52 +00002086 }
Fariborz Jahanian8a1810f2008-11-22 18:39:36 +00002087
Fariborz Jahanian681c0752010-10-14 16:04:05 +00002088 if (Node->isSuperReceiver())
2089 OS << " super";
Argyrios Kyrtzidisab468b02012-03-30 00:19:18 +00002090
2091 OS << " Messaging=";
2092 if (Node->isMessagingGetter() && Node->isMessagingSetter())
2093 OS << "Getter&Setter";
2094 else if (Node->isMessagingGetter())
2095 OS << "Getter";
2096 else if (Node->isMessagingSetter())
2097 OS << "Setter";
Douglas Gregor8ea1f532008-11-04 14:56:14 +00002098}
2099
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002100void ASTDumper::VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002101 VisitExpr(Node);
Ted Kremeneke65b0862012-03-06 20:05:56 +00002102 if (Node->isArraySubscriptRefExpr())
2103 OS << " Kind=ArraySubscript GetterForArray=\"";
2104 else
2105 OS << " Kind=DictionarySubscript GetterForDictionary=\"";
2106 if (Node->getAtIndexMethodDecl())
Aaron Ballmanb190f972014-01-03 17:59:55 +00002107 Node->getAtIndexMethodDecl()->getSelector().print(OS);
Ted Kremeneke65b0862012-03-06 20:05:56 +00002108 else
2109 OS << "(null)";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002110
Ted Kremeneke65b0862012-03-06 20:05:56 +00002111 if (Node->isArraySubscriptRefExpr())
2112 OS << "\" SetterForArray=\"";
2113 else
2114 OS << "\" SetterForDictionary=\"";
2115 if (Node->setAtIndexMethodDecl())
Aaron Ballmanb190f972014-01-03 17:59:55 +00002116 Node->setAtIndexMethodDecl()->getSelector().print(OS);
Ted Kremeneke65b0862012-03-06 20:05:56 +00002117 else
2118 OS << "(null)";
2119}
2120
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002121void ASTDumper::VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002122 VisitExpr(Node);
Ted Kremeneke65b0862012-03-06 20:05:56 +00002123 OS << " " << (Node->getValue() ? "__objc_yes" : "__objc_no");
2124}
2125
Chris Lattnercbe4f772007-08-08 22:51:59 +00002126//===----------------------------------------------------------------------===//
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002127// Comments
2128//===----------------------------------------------------------------------===//
2129
2130const char *ASTDumper::getCommandName(unsigned CommandID) {
2131 if (Traits)
2132 return Traits->getCommandInfo(CommandID)->Name;
2133 const CommandInfo *Info = CommandTraits::getBuiltinCommandInfo(CommandID);
2134 if (Info)
2135 return Info->Name;
2136 return "<not a builtin command>";
2137}
2138
2139void ASTDumper::dumpFullComment(const FullComment *C) {
2140 if (!C)
2141 return;
2142
2143 FC = C;
2144 dumpComment(C);
Craig Topper36250ad2014-05-12 05:36:57 +00002145 FC = nullptr;
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002146}
2147
2148void ASTDumper::dumpComment(const Comment *C) {
Richard Smithf7514452014-10-30 21:02:37 +00002149 dumpChild([=] {
2150 if (!C) {
2151 ColorScope Color(*this, NullColor);
2152 OS << "<<<NULL>>>";
2153 return;
2154 }
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002155
Richard Smithf7514452014-10-30 21:02:37 +00002156 {
2157 ColorScope Color(*this, CommentColor);
2158 OS << C->getCommentKindName();
2159 }
2160 dumpPointer(C);
2161 dumpSourceRange(C->getSourceRange());
2162 ConstCommentVisitor<ASTDumper>::visit(C);
2163 for (Comment::child_iterator I = C->child_begin(), E = C->child_end();
2164 I != E; ++I)
2165 dumpComment(*I);
2166 });
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002167}
2168
2169void ASTDumper::visitTextComment(const TextComment *C) {
2170 OS << " Text=\"" << C->getText() << "\"";
2171}
2172
2173void ASTDumper::visitInlineCommandComment(const InlineCommandComment *C) {
2174 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\"";
2175 switch (C->getRenderKind()) {
2176 case InlineCommandComment::RenderNormal:
2177 OS << " RenderNormal";
2178 break;
2179 case InlineCommandComment::RenderBold:
2180 OS << " RenderBold";
2181 break;
2182 case InlineCommandComment::RenderMonospaced:
2183 OS << " RenderMonospaced";
2184 break;
2185 case InlineCommandComment::RenderEmphasized:
2186 OS << " RenderEmphasized";
2187 break;
2188 }
2189
2190 for (unsigned i = 0, e = C->getNumArgs(); i != e; ++i)
2191 OS << " Arg[" << i << "]=\"" << C->getArgText(i) << "\"";
2192}
2193
2194void ASTDumper::visitHTMLStartTagComment(const HTMLStartTagComment *C) {
2195 OS << " Name=\"" << C->getTagName() << "\"";
2196 if (C->getNumAttrs() != 0) {
2197 OS << " Attrs: ";
2198 for (unsigned i = 0, e = C->getNumAttrs(); i != e; ++i) {
2199 const HTMLStartTagComment::Attribute &Attr = C->getAttr(i);
2200 OS << " \"" << Attr.Name << "=\"" << Attr.Value << "\"";
2201 }
2202 }
2203 if (C->isSelfClosing())
2204 OS << " SelfClosing";
2205}
2206
2207void ASTDumper::visitHTMLEndTagComment(const HTMLEndTagComment *C) {
2208 OS << " Name=\"" << C->getTagName() << "\"";
2209}
2210
2211void ASTDumper::visitBlockCommandComment(const BlockCommandComment *C) {
2212 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\"";
2213 for (unsigned i = 0, e = C->getNumArgs(); i != e; ++i)
2214 OS << " Arg[" << i << "]=\"" << C->getArgText(i) << "\"";
2215}
2216
2217void ASTDumper::visitParamCommandComment(const ParamCommandComment *C) {
2218 OS << " " << ParamCommandComment::getDirectionAsString(C->getDirection());
2219
2220 if (C->isDirectionExplicit())
2221 OS << " explicitly";
2222 else
2223 OS << " implicitly";
2224
2225 if (C->hasParamName()) {
2226 if (C->isParamIndexValid())
2227 OS << " Param=\"" << C->getParamName(FC) << "\"";
2228 else
2229 OS << " Param=\"" << C->getParamNameAsWritten() << "\"";
2230 }
2231
Dmitri Gribenkodbff5c72014-03-19 14:03:47 +00002232 if (C->isParamIndexValid() && !C->isVarArgParam())
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002233 OS << " ParamIndex=" << C->getParamIndex();
2234}
2235
2236void ASTDumper::visitTParamCommandComment(const TParamCommandComment *C) {
2237 if (C->hasParamName()) {
2238 if (C->isPositionValid())
2239 OS << " Param=\"" << C->getParamName(FC) << "\"";
2240 else
2241 OS << " Param=\"" << C->getParamNameAsWritten() << "\"";
2242 }
2243
2244 if (C->isPositionValid()) {
2245 OS << " Position=<";
2246 for (unsigned i = 0, e = C->getDepth(); i != e; ++i) {
2247 OS << C->getIndex(i);
2248 if (i != e - 1)
2249 OS << ", ";
2250 }
2251 OS << ">";
2252 }
2253}
2254
2255void ASTDumper::visitVerbatimBlockComment(const VerbatimBlockComment *C) {
2256 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\""
2257 " CloseName=\"" << C->getCloseName() << "\"";
2258}
2259
2260void ASTDumper::visitVerbatimBlockLineComment(
2261 const VerbatimBlockLineComment *C) {
2262 OS << " Text=\"" << C->getText() << "\"";
2263}
2264
2265void ASTDumper::visitVerbatimLineComment(const VerbatimLineComment *C) {
2266 OS << " Text=\"" << C->getText() << "\"";
2267}
2268
2269//===----------------------------------------------------------------------===//
Richard Smithd5e7ff82014-10-31 01:17:45 +00002270// Type method implementations
2271//===----------------------------------------------------------------------===//
2272
2273void QualType::dump(const char *msg) const {
2274 if (msg)
2275 llvm::errs() << msg << ": ";
2276 dump();
2277}
2278
2279LLVM_DUMP_METHOD void QualType::dump() const {
2280 ASTDumper Dumper(llvm::errs(), nullptr, nullptr);
2281 Dumper.dumpTypeAsChild(*this);
2282}
2283
2284LLVM_DUMP_METHOD void Type::dump() const { QualType(this, 0).dump(); }
2285
2286//===----------------------------------------------------------------------===//
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002287// Decl method implementations
2288//===----------------------------------------------------------------------===//
2289
Alp Tokeref6b0072014-01-04 13:47:14 +00002290LLVM_DUMP_METHOD void Decl::dump() const { dump(llvm::errs()); }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002291
Alp Tokeref6b0072014-01-04 13:47:14 +00002292LLVM_DUMP_METHOD void Decl::dump(raw_ostream &OS) const {
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002293 ASTDumper P(OS, &getASTContext().getCommentCommandTraits(),
2294 &getASTContext().getSourceManager());
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002295 P.dumpDecl(this);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002296}
2297
Alp Tokeref6b0072014-01-04 13:47:14 +00002298LLVM_DUMP_METHOD void Decl::dumpColor() const {
Richard Trieud215b8d2013-01-26 01:31:20 +00002299 ASTDumper P(llvm::errs(), &getASTContext().getCommentCommandTraits(),
2300 &getASTContext().getSourceManager(), /*ShowColors*/true);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002301 P.dumpDecl(this);
Richard Trieud215b8d2013-01-26 01:31:20 +00002302}
Richard Smith33937e72013-06-22 21:49:40 +00002303
Alp Tokeref6b0072014-01-04 13:47:14 +00002304LLVM_DUMP_METHOD void DeclContext::dumpLookups() const {
Richard Smith6ea05822013-06-24 01:45:33 +00002305 dumpLookups(llvm::errs());
2306}
2307
Richard Smith35f986d2014-08-11 22:11:07 +00002308LLVM_DUMP_METHOD void DeclContext::dumpLookups(raw_ostream &OS,
2309 bool DumpDecls) const {
Richard Smith33937e72013-06-22 21:49:40 +00002310 const DeclContext *DC = this;
2311 while (!DC->isTranslationUnit())
2312 DC = DC->getParent();
2313 ASTContext &Ctx = cast<TranslationUnitDecl>(DC)->getASTContext();
Richard Smith6ea05822013-06-24 01:45:33 +00002314 ASTDumper P(OS, &Ctx.getCommentCommandTraits(), &Ctx.getSourceManager());
Richard Smith35f986d2014-08-11 22:11:07 +00002315 P.dumpLookups(this, DumpDecls);
Richard Smith33937e72013-06-22 21:49:40 +00002316}
2317
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002318//===----------------------------------------------------------------------===//
Chris Lattnercbe4f772007-08-08 22:51:59 +00002319// Stmt method implementations
2320//===----------------------------------------------------------------------===//
2321
Alp Tokeref6b0072014-01-04 13:47:14 +00002322LLVM_DUMP_METHOD void Stmt::dump(SourceManager &SM) const {
Argyrios Kyrtzidisc049f752010-08-09 10:54:31 +00002323 dump(llvm::errs(), SM);
2324}
2325
Alp Tokeref6b0072014-01-04 13:47:14 +00002326LLVM_DUMP_METHOD void Stmt::dump(raw_ostream &OS, SourceManager &SM) const {
Craig Topper36250ad2014-05-12 05:36:57 +00002327 ASTDumper P(OS, nullptr, &SM);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002328 P.dumpStmt(this);
Chris Lattner779d5d92007-08-30 00:40:08 +00002329}
2330
Faisal Vali2da8ed92015-03-22 13:35:56 +00002331LLVM_DUMP_METHOD void Stmt::dump(raw_ostream &OS) const {
2332 ASTDumper P(OS, nullptr, nullptr);
2333 P.dumpStmt(this);
2334}
2335
Alp Tokeref6b0072014-01-04 13:47:14 +00002336LLVM_DUMP_METHOD void Stmt::dump() const {
Craig Topper36250ad2014-05-12 05:36:57 +00002337 ASTDumper P(llvm::errs(), nullptr, nullptr);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002338 P.dumpStmt(this);
Chris Lattnercbe4f772007-08-08 22:51:59 +00002339}
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002340
Alp Tokeref6b0072014-01-04 13:47:14 +00002341LLVM_DUMP_METHOD void Stmt::dumpColor() const {
Craig Topper36250ad2014-05-12 05:36:57 +00002342 ASTDumper P(llvm::errs(), nullptr, nullptr, /*ShowColors*/true);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002343 P.dumpStmt(this);
Richard Trieud215b8d2013-01-26 01:31:20 +00002344}
2345
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002346//===----------------------------------------------------------------------===//
2347// Comment method implementations
2348//===----------------------------------------------------------------------===//
2349
Craig Topper36250ad2014-05-12 05:36:57 +00002350LLVM_DUMP_METHOD void Comment::dump() const {
2351 dump(llvm::errs(), nullptr, nullptr);
2352}
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002353
Alp Tokeref6b0072014-01-04 13:47:14 +00002354LLVM_DUMP_METHOD void Comment::dump(const ASTContext &Context) const {
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002355 dump(llvm::errs(), &Context.getCommentCommandTraits(),
2356 &Context.getSourceManager());
2357}
2358
Alexander Kornienko00911f12013-01-15 12:20:21 +00002359void Comment::dump(raw_ostream &OS, const CommandTraits *Traits,
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002360 const SourceManager *SM) const {
2361 const FullComment *FC = dyn_cast<FullComment>(this);
2362 ASTDumper D(OS, Traits, SM);
2363 D.dumpFullComment(FC);
2364}
Richard Trieud215b8d2013-01-26 01:31:20 +00002365
Alp Tokeref6b0072014-01-04 13:47:14 +00002366LLVM_DUMP_METHOD void Comment::dumpColor() const {
Richard Trieud215b8d2013-01-26 01:31:20 +00002367 const FullComment *FC = dyn_cast<FullComment>(this);
Craig Topper36250ad2014-05-12 05:36:57 +00002368 ASTDumper D(llvm::errs(), nullptr, nullptr, /*ShowColors*/true);
Richard Trieud215b8d2013-01-26 01:31:20 +00002369 D.dumpFullComment(FC);
2370}