blob: 0c9c14ba308a9d1aa8516fecff058de08d50a124 [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);
Douglas Gregor1ac1b632015-07-07 03:58:54 +00001478 switch (D->getVariance()) {
1479 case ObjCTypeParamVariance::Invariant:
1480 break;
1481
1482 case ObjCTypeParamVariance::Covariant:
1483 OS << " covariant";
1484 break;
1485
1486 case ObjCTypeParamVariance::Contravariant:
1487 OS << " contravariant";
1488 break;
1489 }
1490
Douglas Gregor85f3f952015-07-07 03:57:15 +00001491 if (D->hasExplicitBound())
1492 OS << " bounded";
1493 dumpType(D->getUnderlyingType());
1494}
1495
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001496void ASTDumper::VisitObjCCategoryDecl(const ObjCCategoryDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001497 dumpName(D);
1498 dumpDeclRef(D->getClassInterface());
Douglas Gregor85f3f952015-07-07 03:57:15 +00001499 dumpObjCTypeParamList(D->getTypeParamList());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001500 dumpDeclRef(D->getImplementation());
1501 for (ObjCCategoryDecl::protocol_iterator I = D->protocol_begin(),
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001502 E = D->protocol_end();
Richard Smithf7514452014-10-30 21:02:37 +00001503 I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001504 dumpDeclRef(*I);
1505}
1506
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001507void ASTDumper::VisitObjCCategoryImplDecl(const ObjCCategoryImplDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001508 dumpName(D);
1509 dumpDeclRef(D->getClassInterface());
1510 dumpDeclRef(D->getCategoryDecl());
1511}
1512
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001513void ASTDumper::VisitObjCProtocolDecl(const ObjCProtocolDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001514 dumpName(D);
Richard Smithdcc2c452014-03-17 23:00:06 +00001515
Richard Smith7fcb35f2014-03-18 02:37:59 +00001516 for (auto *Child : D->protocols())
Richard Smithf7514452014-10-30 21:02:37 +00001517 dumpDeclRef(Child);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001518}
1519
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001520void ASTDumper::VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001521 dumpName(D);
Douglas Gregor85f3f952015-07-07 03:57:15 +00001522 dumpObjCTypeParamList(D->getTypeParamListAsWritten());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001523 dumpDeclRef(D->getSuperClass(), "super");
Richard Smithdcc2c452014-03-17 23:00:06 +00001524
Richard Smithf7514452014-10-30 21:02:37 +00001525 dumpDeclRef(D->getImplementation());
Richard Smith7fcb35f2014-03-18 02:37:59 +00001526 for (auto *Child : D->protocols())
Richard Smithf7514452014-10-30 21:02:37 +00001527 dumpDeclRef(Child);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001528}
1529
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001530void ASTDumper::VisitObjCImplementationDecl(const ObjCImplementationDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001531 dumpName(D);
1532 dumpDeclRef(D->getSuperClass(), "super");
1533 dumpDeclRef(D->getClassInterface());
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001534 for (ObjCImplementationDecl::init_const_iterator I = D->init_begin(),
1535 E = D->init_end();
Richard Smithf7514452014-10-30 21:02:37 +00001536 I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001537 dumpCXXCtorInitializer(*I);
1538}
1539
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001540void ASTDumper::VisitObjCCompatibleAliasDecl(const ObjCCompatibleAliasDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001541 dumpName(D);
1542 dumpDeclRef(D->getClassInterface());
1543}
1544
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001545void ASTDumper::VisitObjCPropertyDecl(const ObjCPropertyDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001546 dumpName(D);
1547 dumpType(D->getType());
1548
1549 if (D->getPropertyImplementation() == ObjCPropertyDecl::Required)
1550 OS << " required";
1551 else if (D->getPropertyImplementation() == ObjCPropertyDecl::Optional)
1552 OS << " optional";
1553
1554 ObjCPropertyDecl::PropertyAttributeKind Attrs = D->getPropertyAttributes();
1555 if (Attrs != ObjCPropertyDecl::OBJC_PR_noattr) {
1556 if (Attrs & ObjCPropertyDecl::OBJC_PR_readonly)
1557 OS << " readonly";
1558 if (Attrs & ObjCPropertyDecl::OBJC_PR_assign)
1559 OS << " assign";
1560 if (Attrs & ObjCPropertyDecl::OBJC_PR_readwrite)
1561 OS << " readwrite";
1562 if (Attrs & ObjCPropertyDecl::OBJC_PR_retain)
1563 OS << " retain";
1564 if (Attrs & ObjCPropertyDecl::OBJC_PR_copy)
1565 OS << " copy";
1566 if (Attrs & ObjCPropertyDecl::OBJC_PR_nonatomic)
1567 OS << " nonatomic";
1568 if (Attrs & ObjCPropertyDecl::OBJC_PR_atomic)
1569 OS << " atomic";
1570 if (Attrs & ObjCPropertyDecl::OBJC_PR_weak)
1571 OS << " weak";
1572 if (Attrs & ObjCPropertyDecl::OBJC_PR_strong)
1573 OS << " strong";
1574 if (Attrs & ObjCPropertyDecl::OBJC_PR_unsafe_unretained)
1575 OS << " unsafe_unretained";
Richard Smithf7514452014-10-30 21:02:37 +00001576 if (Attrs & ObjCPropertyDecl::OBJC_PR_getter)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001577 dumpDeclRef(D->getGetterMethodDecl(), "getter");
Richard Smithf7514452014-10-30 21:02:37 +00001578 if (Attrs & ObjCPropertyDecl::OBJC_PR_setter)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001579 dumpDeclRef(D->getSetterMethodDecl(), "setter");
1580 }
1581}
1582
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001583void ASTDumper::VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001584 dumpName(D->getPropertyDecl());
1585 if (D->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize)
1586 OS << " synthesize";
1587 else
1588 OS << " dynamic";
1589 dumpDeclRef(D->getPropertyDecl());
1590 dumpDeclRef(D->getPropertyIvarDecl());
1591}
1592
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001593void ASTDumper::VisitBlockDecl(const BlockDecl *D) {
Aaron Ballmanb2b8b1d2014-03-07 16:09:59 +00001594 for (auto I : D->params())
1595 dumpDecl(I);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001596
Richard Smithf7514452014-10-30 21:02:37 +00001597 if (D->isVariadic())
1598 dumpChild([=]{ OS << "..."; });
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001599
Richard Smithf7514452014-10-30 21:02:37 +00001600 if (D->capturesCXXThis())
1601 dumpChild([=]{ OS << "capture this"; });
1602
Aaron Ballman9371dd22014-03-14 18:34:04 +00001603 for (const auto &I : D->captures()) {
Richard Smithf7514452014-10-30 21:02:37 +00001604 dumpChild([=] {
1605 OS << "capture";
1606 if (I.isByRef())
1607 OS << " byref";
1608 if (I.isNested())
1609 OS << " nested";
1610 if (I.getVariable()) {
1611 OS << ' ';
1612 dumpBareDeclRef(I.getVariable());
1613 }
1614 if (I.hasCopyExpr())
1615 dumpStmt(I.getCopyExpr());
1616 });
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001617 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001618 dumpStmt(D->getBody());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001619}
1620
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001621//===----------------------------------------------------------------------===//
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001622// Stmt dumping methods.
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001623//===----------------------------------------------------------------------===//
1624
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001625void ASTDumper::dumpStmt(const Stmt *S) {
Richard Smithf7514452014-10-30 21:02:37 +00001626 dumpChild([=] {
1627 if (!S) {
1628 ColorScope Color(*this, NullColor);
1629 OS << "<<<NULL>>>";
1630 return;
1631 }
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001632
Richard Smithf7514452014-10-30 21:02:37 +00001633 if (const DeclStmt *DS = dyn_cast<DeclStmt>(S)) {
1634 VisitDeclStmt(DS);
1635 return;
1636 }
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001637
Richard Smithf7514452014-10-30 21:02:37 +00001638 ConstStmtVisitor<ASTDumper>::Visit(S);
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001639
Benjamin Kramer642f1732015-07-02 21:03:14 +00001640 for (const Stmt *SubStmt : S->children())
1641 dumpStmt(SubStmt);
Richard Smithf7514452014-10-30 21:02:37 +00001642 });
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001643}
1644
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001645void ASTDumper::VisitStmt(const Stmt *Node) {
Richard Trieud215b8d2013-01-26 01:31:20 +00001646 {
1647 ColorScope Color(*this, StmtColor);
1648 OS << Node->getStmtClassName();
1649 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001650 dumpPointer(Node);
1651 dumpSourceRange(Node->getSourceRange());
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001652}
1653
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001654void ASTDumper::VisitDeclStmt(const DeclStmt *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001655 VisitStmt(Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001656 for (DeclStmt::const_decl_iterator I = Node->decl_begin(),
1657 E = Node->decl_end();
Richard Smithf7514452014-10-30 21:02:37 +00001658 I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001659 dumpDecl(*I);
Ted Kremenek433a4922007-12-12 06:59:42 +00001660}
1661
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001662void ASTDumper::VisitAttributedStmt(const AttributedStmt *Node) {
Alexander Kornienko5bc364e2013-01-07 17:53:08 +00001663 VisitStmt(Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001664 for (ArrayRef<const Attr *>::iterator I = Node->getAttrs().begin(),
1665 E = Node->getAttrs().end();
Richard Smithf7514452014-10-30 21:02:37 +00001666 I != E; ++I)
Alexander Kornienko5bc364e2013-01-07 17:53:08 +00001667 dumpAttr(*I);
1668}
1669
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001670void ASTDumper::VisitLabelStmt(const LabelStmt *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001671 VisitStmt(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001672 OS << " '" << Node->getName() << "'";
Chris Lattnercbe4f772007-08-08 22:51:59 +00001673}
1674
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001675void ASTDumper::VisitGotoStmt(const GotoStmt *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001676 VisitStmt(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001677 OS << " '" << Node->getLabel()->getName() << "'";
1678 dumpPointer(Node->getLabel());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001679}
1680
Pavel Labath1ef83422013-09-04 14:35:00 +00001681void ASTDumper::VisitCXXCatchStmt(const CXXCatchStmt *Node) {
1682 VisitStmt(Node);
1683 dumpDecl(Node->getExceptionDecl());
1684}
1685
Chris Lattnercbe4f772007-08-08 22:51:59 +00001686//===----------------------------------------------------------------------===//
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001687// Expr dumping methods.
Chris Lattnercbe4f772007-08-08 22:51:59 +00001688//===----------------------------------------------------------------------===//
1689
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001690void ASTDumper::VisitExpr(const Expr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001691 VisitStmt(Node);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001692 dumpType(Node->getType());
1693
Richard Trieud215b8d2013-01-26 01:31:20 +00001694 {
1695 ColorScope Color(*this, ValueKindColor);
1696 switch (Node->getValueKind()) {
1697 case VK_RValue:
1698 break;
1699 case VK_LValue:
1700 OS << " lvalue";
1701 break;
1702 case VK_XValue:
1703 OS << " xvalue";
1704 break;
1705 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001706 }
1707
Richard Trieud215b8d2013-01-26 01:31:20 +00001708 {
1709 ColorScope Color(*this, ObjectKindColor);
1710 switch (Node->getObjectKind()) {
1711 case OK_Ordinary:
1712 break;
1713 case OK_BitField:
1714 OS << " bitfield";
1715 break;
1716 case OK_ObjCProperty:
1717 OS << " objcproperty";
1718 break;
1719 case OK_ObjCSubscript:
1720 OS << " objcsubscript";
1721 break;
1722 case OK_VectorComponent:
1723 OS << " vectorcomponent";
1724 break;
1725 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001726 }
Chris Lattnercbe4f772007-08-08 22:51:59 +00001727}
1728
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001729static void dumpBasePath(raw_ostream &OS, const CastExpr *Node) {
John McCallcf142162010-08-07 06:22:56 +00001730 if (Node->path_empty())
Anders Carlssona70cff62010-04-24 19:06:50 +00001731 return;
1732
1733 OS << " (";
1734 bool First = true;
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001735 for (CastExpr::path_const_iterator I = Node->path_begin(),
1736 E = Node->path_end();
1737 I != E; ++I) {
Anders Carlssona70cff62010-04-24 19:06:50 +00001738 const CXXBaseSpecifier *Base = *I;
1739 if (!First)
1740 OS << " -> ";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001741
Anders Carlssona70cff62010-04-24 19:06:50 +00001742 const CXXRecordDecl *RD =
1743 cast<CXXRecordDecl>(Base->getType()->getAs<RecordType>()->getDecl());
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001744
Anders Carlssona70cff62010-04-24 19:06:50 +00001745 if (Base->isVirtual())
1746 OS << "virtual ";
1747 OS << RD->getName();
1748 First = false;
1749 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001750
Anders Carlssona70cff62010-04-24 19:06:50 +00001751 OS << ')';
1752}
1753
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001754void ASTDumper::VisitCastExpr(const CastExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001755 VisitExpr(Node);
Richard Trieud215b8d2013-01-26 01:31:20 +00001756 OS << " <";
1757 {
1758 ColorScope Color(*this, CastColor);
1759 OS << Node->getCastKindName();
1760 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001761 dumpBasePath(OS, Node);
Anders Carlssona70cff62010-04-24 19:06:50 +00001762 OS << ">";
Anders Carlssond7923c62009-08-22 23:33:40 +00001763}
1764
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001765void ASTDumper::VisitDeclRefExpr(const DeclRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001766 VisitExpr(Node);
Ted Kremenek5f64ca82007-09-10 17:32:55 +00001767
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001768 OS << " ";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001769 dumpBareDeclRef(Node->getDecl());
Chandler Carruth8d26bb02011-05-01 23:48:14 +00001770 if (Node->getDecl() != Node->getFoundDecl()) {
1771 OS << " (";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001772 dumpBareDeclRef(Node->getFoundDecl());
Chandler Carruth8d26bb02011-05-01 23:48:14 +00001773 OS << ")";
1774 }
John McCall351762c2011-02-07 10:33:21 +00001775}
1776
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001777void ASTDumper::VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001778 VisitExpr(Node);
John McCall76d09942009-12-11 21:50:11 +00001779 OS << " (";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001780 if (!Node->requiresADL())
1781 OS << "no ";
Benjamin Kramerb11416d2010-04-17 09:33:03 +00001782 OS << "ADL) = '" << Node->getName() << '\'';
John McCall76d09942009-12-11 21:50:11 +00001783
1784 UnresolvedLookupExpr::decls_iterator
1785 I = Node->decls_begin(), E = Node->decls_end();
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001786 if (I == E)
1787 OS << " empty";
John McCall76d09942009-12-11 21:50:11 +00001788 for (; I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001789 dumpPointer(*I);
John McCall76d09942009-12-11 21:50:11 +00001790}
1791
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001792void ASTDumper::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001793 VisitExpr(Node);
Steve Naroff5d5efca2008-03-12 13:19:12 +00001794
Richard Trieud215b8d2013-01-26 01:31:20 +00001795 {
1796 ColorScope Color(*this, DeclKindNameColor);
1797 OS << " " << Node->getDecl()->getDeclKindName() << "Decl";
1798 }
1799 OS << "='" << *Node->getDecl() << "'";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001800 dumpPointer(Node->getDecl());
Steve Naroffb3424a92008-05-23 22:01:24 +00001801 if (Node->isFreeIvar())
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001802 OS << " isFreeIvar";
Steve Naroff5d5efca2008-03-12 13:19:12 +00001803}
1804
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001805void ASTDumper::VisitPredefinedExpr(const PredefinedExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001806 VisitExpr(Node);
Alexey Bataevec474782014-10-09 08:45:04 +00001807 OS << " " << PredefinedExpr::getIdentTypeName(Node->getIdentType());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001808}
1809
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001810void ASTDumper::VisitCharacterLiteral(const CharacterLiteral *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001811 VisitExpr(Node);
Richard Trieud215b8d2013-01-26 01:31:20 +00001812 ColorScope Color(*this, ValueColor);
Richard Trieu364ee422011-11-03 23:56:23 +00001813 OS << " " << Node->getValue();
Chris Lattnercbe4f772007-08-08 22:51:59 +00001814}
1815
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001816void ASTDumper::VisitIntegerLiteral(const IntegerLiteral *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001817 VisitExpr(Node);
Chris Lattnercbe4f772007-08-08 22:51:59 +00001818
1819 bool isSigned = Node->getType()->isSignedIntegerType();
Richard Trieud215b8d2013-01-26 01:31:20 +00001820 ColorScope Color(*this, ValueColor);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001821 OS << " " << Node->getValue().toString(10, isSigned);
Chris Lattnercbe4f772007-08-08 22:51:59 +00001822}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001823
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001824void ASTDumper::VisitFloatingLiteral(const FloatingLiteral *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001825 VisitExpr(Node);
Richard Trieud215b8d2013-01-26 01:31:20 +00001826 ColorScope Color(*this, ValueColor);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001827 OS << " " << Node->getValueAsApproximateDouble();
Chris Lattnercbe4f772007-08-08 22:51:59 +00001828}
Chris Lattner1c20a172007-08-26 03:42:43 +00001829
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001830void ASTDumper::VisitStringLiteral(const StringLiteral *Str) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001831 VisitExpr(Str);
Richard Trieud215b8d2013-01-26 01:31:20 +00001832 ColorScope Color(*this, ValueColor);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001833 OS << " ";
Richard Trieudc355912012-06-13 20:25:24 +00001834 Str->outputString(OS);
Chris Lattnercbe4f772007-08-08 22:51:59 +00001835}
Chris Lattner84ca3762007-08-30 01:00:35 +00001836
Richard Smithf0514962014-06-03 08:24:28 +00001837void ASTDumper::VisitInitListExpr(const InitListExpr *ILE) {
1838 VisitExpr(ILE);
1839 if (auto *Filler = ILE->getArrayFiller()) {
Richard Smithf7514452014-10-30 21:02:37 +00001840 dumpChild([=] {
1841 OS << "array filler";
1842 dumpStmt(Filler);
1843 });
Richard Smithf0514962014-06-03 08:24:28 +00001844 }
1845 if (auto *Field = ILE->getInitializedFieldInUnion()) {
1846 OS << " field ";
1847 dumpBareDeclRef(Field);
1848 }
1849}
1850
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001851void ASTDumper::VisitUnaryOperator(const UnaryOperator *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001852 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001853 OS << " " << (Node->isPostfix() ? "postfix" : "prefix")
1854 << " '" << UnaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
Chris Lattnercbe4f772007-08-08 22:51:59 +00001855}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001856
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001857void ASTDumper::VisitUnaryExprOrTypeTraitExpr(
1858 const UnaryExprOrTypeTraitExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001859 VisitExpr(Node);
Peter Collingbournee190dee2011-03-11 19:24:49 +00001860 switch(Node->getKind()) {
1861 case UETT_SizeOf:
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001862 OS << " sizeof";
Peter Collingbournee190dee2011-03-11 19:24:49 +00001863 break;
1864 case UETT_AlignOf:
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001865 OS << " alignof";
Peter Collingbournee190dee2011-03-11 19:24:49 +00001866 break;
1867 case UETT_VecStep:
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001868 OS << " vec_step";
Peter Collingbournee190dee2011-03-11 19:24:49 +00001869 break;
Alexey Bataev00396512015-07-02 03:40:19 +00001870 case UETT_OpenMPRequiredSimdAlign:
1871 OS << " __builtin_omp_required_simd_align";
1872 break;
Peter Collingbournee190dee2011-03-11 19:24:49 +00001873 }
Sebastian Redl6f282892008-11-11 17:56:53 +00001874 if (Node->isArgumentType())
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001875 dumpType(Node->getArgumentType());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001876}
Chris Lattnerdb3b3ff2007-08-09 17:35:30 +00001877
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001878void ASTDumper::VisitMemberExpr(const MemberExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001879 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001880 OS << " " << (Node->isArrow() ? "->" : ".") << *Node->getMemberDecl();
1881 dumpPointer(Node->getMemberDecl());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001882}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001883
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001884void ASTDumper::VisitExtVectorElementExpr(const ExtVectorElementExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001885 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001886 OS << " " << Node->getAccessor().getNameStart();
Chris Lattnercbe4f772007-08-08 22:51:59 +00001887}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001888
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001889void ASTDumper::VisitBinaryOperator(const BinaryOperator *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001890 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001891 OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
Chris Lattner86928112007-08-25 02:00:02 +00001892}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001893
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001894void ASTDumper::VisitCompoundAssignOperator(
1895 const CompoundAssignOperator *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001896 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001897 OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode())
1898 << "' ComputeLHSTy=";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001899 dumpBareType(Node->getComputationLHSType());
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001900 OS << " ComputeResultTy=";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001901 dumpBareType(Node->getComputationResultType());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001902}
Chris Lattnercbe4f772007-08-08 22:51:59 +00001903
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001904void ASTDumper::VisitBlockExpr(const BlockExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001905 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001906 dumpDecl(Node->getBlockDecl());
John McCall351762c2011-02-07 10:33:21 +00001907}
1908
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001909void ASTDumper::VisitOpaqueValueExpr(const OpaqueValueExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001910 VisitExpr(Node);
John McCallfe96e0b2011-11-06 09:01:30 +00001911
Richard Smithf7514452014-10-30 21:02:37 +00001912 if (Expr *Source = Node->getSourceExpr())
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001913 dumpStmt(Source);
John McCallfe96e0b2011-11-06 09:01:30 +00001914}
1915
Chris Lattnercbe4f772007-08-08 22:51:59 +00001916// GNU extensions.
1917
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001918void ASTDumper::VisitAddrLabelExpr(const AddrLabelExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001919 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001920 OS << " " << Node->getLabel()->getName();
1921 dumpPointer(Node->getLabel());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001922}
1923
Chris Lattner8f184b12007-08-09 18:03:18 +00001924//===----------------------------------------------------------------------===//
1925// C++ Expressions
1926//===----------------------------------------------------------------------===//
Chris Lattnercbe4f772007-08-08 22:51:59 +00001927
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001928void ASTDumper::VisitCXXNamedCastExpr(const CXXNamedCastExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001929 VisitExpr(Node);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001930 OS << " " << Node->getCastName()
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001931 << "<" << Node->getTypeAsWritten().getAsString() << ">"
Anders Carlssona70cff62010-04-24 19:06:50 +00001932 << " <" << Node->getCastKindName();
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001933 dumpBasePath(OS, Node);
Anders Carlssona70cff62010-04-24 19:06:50 +00001934 OS << ">";
Chris Lattnercbe4f772007-08-08 22:51:59 +00001935}
1936
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001937void ASTDumper::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001938 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001939 OS << " " << (Node->getValue() ? "true" : "false");
Chris Lattnercbe4f772007-08-08 22:51:59 +00001940}
1941
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001942void ASTDumper::VisitCXXThisExpr(const CXXThisExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001943 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001944 OS << " this";
Douglas Gregor8ea1f532008-11-04 14:56:14 +00001945}
1946
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001947void ASTDumper::VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001948 VisitExpr(Node);
Eli Friedman29538892011-09-02 17:38:59 +00001949 OS << " functional cast to " << Node->getTypeAsWritten().getAsString()
1950 << " <" << Node->getCastKindName() << ">";
Douglas Gregore200adc2008-10-27 19:41:14 +00001951}
1952
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001953void ASTDumper::VisitCXXConstructExpr(const CXXConstructExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001954 VisitExpr(Node);
John McCalleba90cd2010-02-02 19:03:45 +00001955 CXXConstructorDecl *Ctor = Node->getConstructor();
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001956 dumpType(Ctor->getType());
Anders Carlsson073846832009-08-12 00:21:52 +00001957 if (Node->isElidable())
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001958 OS << " elidable";
John McCall85370042010-08-07 06:38:55 +00001959 if (Node->requiresZeroInitialization())
1960 OS << " zeroing";
Anders Carlsson073846832009-08-12 00:21:52 +00001961}
1962
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001963void ASTDumper::VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001964 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001965 OS << " ";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001966 dumpCXXTemporary(Node->getTemporary());
Anders Carlsson073846832009-08-12 00:21:52 +00001967}
1968
Reid Kleckner5c682bc2015-03-19 18:09:25 +00001969void ASTDumper::VisitCXXNewExpr(const CXXNewExpr *Node) {
1970 VisitExpr(Node);
Reid Kleckner5c682bc2015-03-19 18:09:25 +00001971 if (Node->isGlobalNew())
Reid Kleckner461c0c62015-03-19 18:47:47 +00001972 OS << " global";
Reid Kleckner5c682bc2015-03-19 18:09:25 +00001973 if (Node->isArray())
Reid Kleckner461c0c62015-03-19 18:47:47 +00001974 OS << " array";
1975 if (Node->getOperatorNew()) {
1976 OS << ' ';
1977 dumpBareDeclRef(Node->getOperatorNew());
1978 }
Reid Kleckner5c682bc2015-03-19 18:09:25 +00001979 // We could dump the deallocation function used in case of error, but it's
1980 // usually not that interesting.
1981}
1982
1983void ASTDumper::VisitCXXDeleteExpr(const CXXDeleteExpr *Node) {
1984 VisitExpr(Node);
Reid Kleckner5c682bc2015-03-19 18:09:25 +00001985 if (Node->isGlobalDelete())
Reid Kleckner461c0c62015-03-19 18:47:47 +00001986 OS << " global";
Reid Kleckner5c682bc2015-03-19 18:09:25 +00001987 if (Node->isArrayForm())
Reid Kleckner461c0c62015-03-19 18:47:47 +00001988 OS << " array";
1989 if (Node->getOperatorDelete()) {
1990 OS << ' ';
1991 dumpBareDeclRef(Node->getOperatorDelete());
1992 }
Reid Kleckner5c682bc2015-03-19 18:09:25 +00001993}
1994
Richard Smithe6c01442013-06-05 00:46:14 +00001995void
1996ASTDumper::VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *Node) {
1997 VisitExpr(Node);
1998 if (const ValueDecl *VD = Node->getExtendingDecl()) {
1999 OS << " extended by ";
2000 dumpBareDeclRef(VD);
2001 }
2002}
2003
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002004void ASTDumper::VisitExprWithCleanups(const ExprWithCleanups *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002005 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002006 for (unsigned i = 0, e = Node->getNumObjects(); i != e; ++i)
2007 dumpDeclRef(Node->getObject(i), "cleanup");
Anders Carlsson073846832009-08-12 00:21:52 +00002008}
2009
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002010void ASTDumper::dumpCXXTemporary(const CXXTemporary *Temporary) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002011 OS << "(CXXTemporary";
2012 dumpPointer(Temporary);
2013 OS << ")";
Anders Carlsson073846832009-08-12 00:21:52 +00002014}
2015
Serge Pavlov6b926032015-02-16 19:58:41 +00002016void ASTDumper::VisitSizeOfPackExpr(const SizeOfPackExpr *Node) {
2017 VisitExpr(Node);
2018 dumpPointer(Node->getPack());
2019 dumpName(Node->getPack());
Richard Smithd784e682015-09-23 21:41:42 +00002020 if (Node->isPartiallySubstituted())
2021 for (const auto &A : Node->getPartialArguments())
2022 dumpTemplateArgument(A);
Serge Pavlov6b926032015-02-16 19:58:41 +00002023}
2024
2025
Anders Carlsson76f4a902007-08-21 17:43:55 +00002026//===----------------------------------------------------------------------===//
2027// Obj-C Expressions
2028//===----------------------------------------------------------------------===//
2029
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002030void ASTDumper::VisitObjCMessageExpr(const ObjCMessageExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002031 VisitExpr(Node);
Aaron Ballmanb190f972014-01-03 17:59:55 +00002032 OS << " selector=";
2033 Node->getSelector().print(OS);
Douglas Gregor9a129192010-04-21 00:45:42 +00002034 switch (Node->getReceiverKind()) {
2035 case ObjCMessageExpr::Instance:
2036 break;
2037
2038 case ObjCMessageExpr::Class:
2039 OS << " class=";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002040 dumpBareType(Node->getClassReceiver());
Douglas Gregor9a129192010-04-21 00:45:42 +00002041 break;
2042
2043 case ObjCMessageExpr::SuperInstance:
2044 OS << " super (instance)";
2045 break;
2046
2047 case ObjCMessageExpr::SuperClass:
2048 OS << " super (class)";
2049 break;
2050 }
Ted Kremenek36748da2008-02-29 22:04:05 +00002051}
2052
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002053void ASTDumper::VisitObjCBoxedExpr(const ObjCBoxedExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002054 VisitExpr(Node);
Aaron Ballmanb190f972014-01-03 17:59:55 +00002055 OS << " selector=";
2056 Node->getBoxingMethod()->getSelector().print(OS);
Argyrios Kyrtzidis9dd40892012-05-10 20:02:31 +00002057}
2058
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002059void ASTDumper::VisitObjCAtCatchStmt(const ObjCAtCatchStmt *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002060 VisitStmt(Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002061 if (const VarDecl *CatchParam = Node->getCatchParamDecl())
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002062 dumpDecl(CatchParam);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002063 else
Douglas Gregor96c79492010-04-23 22:50:49 +00002064 OS << " catch all";
Douglas Gregor96c79492010-04-23 22:50:49 +00002065}
2066
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002067void ASTDumper::VisitObjCEncodeExpr(const ObjCEncodeExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002068 VisitExpr(Node);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002069 dumpType(Node->getEncodedType());
Anders Carlssonc5a81eb2007-08-22 15:14:15 +00002070}
2071
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002072void ASTDumper::VisitObjCSelectorExpr(const ObjCSelectorExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002073 VisitExpr(Node);
Mike Stump11289f42009-09-09 15:08:12 +00002074
Aaron Ballmanb190f972014-01-03 17:59:55 +00002075 OS << " ";
2076 Node->getSelector().print(OS);
Fariborz Jahanian4bef4622007-10-16 20:40:23 +00002077}
2078
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002079void ASTDumper::VisitObjCProtocolExpr(const ObjCProtocolExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002080 VisitExpr(Node);
Mike Stump11289f42009-09-09 15:08:12 +00002081
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002082 OS << ' ' << *Node->getProtocol();
Fariborz Jahaniana32aaef2007-10-17 16:58:11 +00002083}
Daniel Dunbar4b8c6db2008-08-30 05:35:15 +00002084
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002085void ASTDumper::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002086 VisitExpr(Node);
John McCallb7bd14f2010-12-02 01:19:52 +00002087 if (Node->isImplicitProperty()) {
Fariborz Jahanian0f0b3022010-12-22 19:46:35 +00002088 OS << " Kind=MethodRef Getter=\"";
2089 if (Node->getImplicitPropertyGetter())
Aaron Ballmanb190f972014-01-03 17:59:55 +00002090 Node->getImplicitPropertyGetter()->getSelector().print(OS);
Fariborz Jahanian0f0b3022010-12-22 19:46:35 +00002091 else
2092 OS << "(null)";
2093
2094 OS << "\" Setter=\"";
John McCallb7bd14f2010-12-02 01:19:52 +00002095 if (ObjCMethodDecl *Setter = Node->getImplicitPropertySetter())
Aaron Ballmanb190f972014-01-03 17:59:55 +00002096 Setter->getSelector().print(OS);
John McCallb7bd14f2010-12-02 01:19:52 +00002097 else
2098 OS << "(null)";
2099 OS << "\"";
2100 } else {
Benjamin Kramerb89514a2011-10-14 18:45:37 +00002101 OS << " Kind=PropertyRef Property=\"" << *Node->getExplicitProperty() <<'"';
John McCallb7bd14f2010-12-02 01:19:52 +00002102 }
Fariborz Jahanian8a1810f2008-11-22 18:39:36 +00002103
Fariborz Jahanian681c0752010-10-14 16:04:05 +00002104 if (Node->isSuperReceiver())
2105 OS << " super";
Argyrios Kyrtzidisab468b02012-03-30 00:19:18 +00002106
2107 OS << " Messaging=";
2108 if (Node->isMessagingGetter() && Node->isMessagingSetter())
2109 OS << "Getter&Setter";
2110 else if (Node->isMessagingGetter())
2111 OS << "Getter";
2112 else if (Node->isMessagingSetter())
2113 OS << "Setter";
Douglas Gregor8ea1f532008-11-04 14:56:14 +00002114}
2115
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002116void ASTDumper::VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002117 VisitExpr(Node);
Ted Kremeneke65b0862012-03-06 20:05:56 +00002118 if (Node->isArraySubscriptRefExpr())
2119 OS << " Kind=ArraySubscript GetterForArray=\"";
2120 else
2121 OS << " Kind=DictionarySubscript GetterForDictionary=\"";
2122 if (Node->getAtIndexMethodDecl())
Aaron Ballmanb190f972014-01-03 17:59:55 +00002123 Node->getAtIndexMethodDecl()->getSelector().print(OS);
Ted Kremeneke65b0862012-03-06 20:05:56 +00002124 else
2125 OS << "(null)";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002126
Ted Kremeneke65b0862012-03-06 20:05:56 +00002127 if (Node->isArraySubscriptRefExpr())
2128 OS << "\" SetterForArray=\"";
2129 else
2130 OS << "\" SetterForDictionary=\"";
2131 if (Node->setAtIndexMethodDecl())
Aaron Ballmanb190f972014-01-03 17:59:55 +00002132 Node->setAtIndexMethodDecl()->getSelector().print(OS);
Ted Kremeneke65b0862012-03-06 20:05:56 +00002133 else
2134 OS << "(null)";
2135}
2136
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002137void ASTDumper::VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002138 VisitExpr(Node);
Ted Kremeneke65b0862012-03-06 20:05:56 +00002139 OS << " " << (Node->getValue() ? "__objc_yes" : "__objc_no");
2140}
2141
Chris Lattnercbe4f772007-08-08 22:51:59 +00002142//===----------------------------------------------------------------------===//
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002143// Comments
2144//===----------------------------------------------------------------------===//
2145
2146const char *ASTDumper::getCommandName(unsigned CommandID) {
2147 if (Traits)
2148 return Traits->getCommandInfo(CommandID)->Name;
2149 const CommandInfo *Info = CommandTraits::getBuiltinCommandInfo(CommandID);
2150 if (Info)
2151 return Info->Name;
2152 return "<not a builtin command>";
2153}
2154
2155void ASTDumper::dumpFullComment(const FullComment *C) {
2156 if (!C)
2157 return;
2158
2159 FC = C;
2160 dumpComment(C);
Craig Topper36250ad2014-05-12 05:36:57 +00002161 FC = nullptr;
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002162}
2163
2164void ASTDumper::dumpComment(const Comment *C) {
Richard Smithf7514452014-10-30 21:02:37 +00002165 dumpChild([=] {
2166 if (!C) {
2167 ColorScope Color(*this, NullColor);
2168 OS << "<<<NULL>>>";
2169 return;
2170 }
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002171
Richard Smithf7514452014-10-30 21:02:37 +00002172 {
2173 ColorScope Color(*this, CommentColor);
2174 OS << C->getCommentKindName();
2175 }
2176 dumpPointer(C);
2177 dumpSourceRange(C->getSourceRange());
2178 ConstCommentVisitor<ASTDumper>::visit(C);
2179 for (Comment::child_iterator I = C->child_begin(), E = C->child_end();
2180 I != E; ++I)
2181 dumpComment(*I);
2182 });
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002183}
2184
2185void ASTDumper::visitTextComment(const TextComment *C) {
2186 OS << " Text=\"" << C->getText() << "\"";
2187}
2188
2189void ASTDumper::visitInlineCommandComment(const InlineCommandComment *C) {
2190 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\"";
2191 switch (C->getRenderKind()) {
2192 case InlineCommandComment::RenderNormal:
2193 OS << " RenderNormal";
2194 break;
2195 case InlineCommandComment::RenderBold:
2196 OS << " RenderBold";
2197 break;
2198 case InlineCommandComment::RenderMonospaced:
2199 OS << " RenderMonospaced";
2200 break;
2201 case InlineCommandComment::RenderEmphasized:
2202 OS << " RenderEmphasized";
2203 break;
2204 }
2205
2206 for (unsigned i = 0, e = C->getNumArgs(); i != e; ++i)
2207 OS << " Arg[" << i << "]=\"" << C->getArgText(i) << "\"";
2208}
2209
2210void ASTDumper::visitHTMLStartTagComment(const HTMLStartTagComment *C) {
2211 OS << " Name=\"" << C->getTagName() << "\"";
2212 if (C->getNumAttrs() != 0) {
2213 OS << " Attrs: ";
2214 for (unsigned i = 0, e = C->getNumAttrs(); i != e; ++i) {
2215 const HTMLStartTagComment::Attribute &Attr = C->getAttr(i);
2216 OS << " \"" << Attr.Name << "=\"" << Attr.Value << "\"";
2217 }
2218 }
2219 if (C->isSelfClosing())
2220 OS << " SelfClosing";
2221}
2222
2223void ASTDumper::visitHTMLEndTagComment(const HTMLEndTagComment *C) {
2224 OS << " Name=\"" << C->getTagName() << "\"";
2225}
2226
2227void ASTDumper::visitBlockCommandComment(const BlockCommandComment *C) {
2228 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\"";
2229 for (unsigned i = 0, e = C->getNumArgs(); i != e; ++i)
2230 OS << " Arg[" << i << "]=\"" << C->getArgText(i) << "\"";
2231}
2232
2233void ASTDumper::visitParamCommandComment(const ParamCommandComment *C) {
2234 OS << " " << ParamCommandComment::getDirectionAsString(C->getDirection());
2235
2236 if (C->isDirectionExplicit())
2237 OS << " explicitly";
2238 else
2239 OS << " implicitly";
2240
2241 if (C->hasParamName()) {
2242 if (C->isParamIndexValid())
2243 OS << " Param=\"" << C->getParamName(FC) << "\"";
2244 else
2245 OS << " Param=\"" << C->getParamNameAsWritten() << "\"";
2246 }
2247
Dmitri Gribenkodbff5c72014-03-19 14:03:47 +00002248 if (C->isParamIndexValid() && !C->isVarArgParam())
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002249 OS << " ParamIndex=" << C->getParamIndex();
2250}
2251
2252void ASTDumper::visitTParamCommandComment(const TParamCommandComment *C) {
2253 if (C->hasParamName()) {
2254 if (C->isPositionValid())
2255 OS << " Param=\"" << C->getParamName(FC) << "\"";
2256 else
2257 OS << " Param=\"" << C->getParamNameAsWritten() << "\"";
2258 }
2259
2260 if (C->isPositionValid()) {
2261 OS << " Position=<";
2262 for (unsigned i = 0, e = C->getDepth(); i != e; ++i) {
2263 OS << C->getIndex(i);
2264 if (i != e - 1)
2265 OS << ", ";
2266 }
2267 OS << ">";
2268 }
2269}
2270
2271void ASTDumper::visitVerbatimBlockComment(const VerbatimBlockComment *C) {
2272 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\""
2273 " CloseName=\"" << C->getCloseName() << "\"";
2274}
2275
2276void ASTDumper::visitVerbatimBlockLineComment(
2277 const VerbatimBlockLineComment *C) {
2278 OS << " Text=\"" << C->getText() << "\"";
2279}
2280
2281void ASTDumper::visitVerbatimLineComment(const VerbatimLineComment *C) {
2282 OS << " Text=\"" << C->getText() << "\"";
2283}
2284
2285//===----------------------------------------------------------------------===//
Richard Smithd5e7ff82014-10-31 01:17:45 +00002286// Type method implementations
2287//===----------------------------------------------------------------------===//
2288
2289void QualType::dump(const char *msg) const {
2290 if (msg)
2291 llvm::errs() << msg << ": ";
2292 dump();
2293}
2294
2295LLVM_DUMP_METHOD void QualType::dump() const {
2296 ASTDumper Dumper(llvm::errs(), nullptr, nullptr);
2297 Dumper.dumpTypeAsChild(*this);
2298}
2299
2300LLVM_DUMP_METHOD void Type::dump() const { QualType(this, 0).dump(); }
2301
2302//===----------------------------------------------------------------------===//
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002303// Decl method implementations
2304//===----------------------------------------------------------------------===//
2305
Alp Tokeref6b0072014-01-04 13:47:14 +00002306LLVM_DUMP_METHOD void Decl::dump() const { dump(llvm::errs()); }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002307
Alp Tokeref6b0072014-01-04 13:47:14 +00002308LLVM_DUMP_METHOD void Decl::dump(raw_ostream &OS) const {
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002309 ASTDumper P(OS, &getASTContext().getCommentCommandTraits(),
2310 &getASTContext().getSourceManager());
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002311 P.dumpDecl(this);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002312}
2313
Alp Tokeref6b0072014-01-04 13:47:14 +00002314LLVM_DUMP_METHOD void Decl::dumpColor() const {
Richard Trieud215b8d2013-01-26 01:31:20 +00002315 ASTDumper P(llvm::errs(), &getASTContext().getCommentCommandTraits(),
2316 &getASTContext().getSourceManager(), /*ShowColors*/true);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002317 P.dumpDecl(this);
Richard Trieud215b8d2013-01-26 01:31:20 +00002318}
Richard Smith33937e72013-06-22 21:49:40 +00002319
Alp Tokeref6b0072014-01-04 13:47:14 +00002320LLVM_DUMP_METHOD void DeclContext::dumpLookups() const {
Richard Smith6ea05822013-06-24 01:45:33 +00002321 dumpLookups(llvm::errs());
2322}
2323
Richard Smith35f986d2014-08-11 22:11:07 +00002324LLVM_DUMP_METHOD void DeclContext::dumpLookups(raw_ostream &OS,
2325 bool DumpDecls) const {
Richard Smith33937e72013-06-22 21:49:40 +00002326 const DeclContext *DC = this;
2327 while (!DC->isTranslationUnit())
2328 DC = DC->getParent();
2329 ASTContext &Ctx = cast<TranslationUnitDecl>(DC)->getASTContext();
Richard Smith6ea05822013-06-24 01:45:33 +00002330 ASTDumper P(OS, &Ctx.getCommentCommandTraits(), &Ctx.getSourceManager());
Richard Smith35f986d2014-08-11 22:11:07 +00002331 P.dumpLookups(this, DumpDecls);
Richard Smith33937e72013-06-22 21:49:40 +00002332}
2333
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002334//===----------------------------------------------------------------------===//
Chris Lattnercbe4f772007-08-08 22:51:59 +00002335// Stmt method implementations
2336//===----------------------------------------------------------------------===//
2337
Alp Tokeref6b0072014-01-04 13:47:14 +00002338LLVM_DUMP_METHOD void Stmt::dump(SourceManager &SM) const {
Argyrios Kyrtzidisc049f752010-08-09 10:54:31 +00002339 dump(llvm::errs(), SM);
2340}
2341
Alp Tokeref6b0072014-01-04 13:47:14 +00002342LLVM_DUMP_METHOD void Stmt::dump(raw_ostream &OS, SourceManager &SM) const {
Craig Topper36250ad2014-05-12 05:36:57 +00002343 ASTDumper P(OS, nullptr, &SM);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002344 P.dumpStmt(this);
Chris Lattner779d5d92007-08-30 00:40:08 +00002345}
2346
Faisal Vali2da8ed92015-03-22 13:35:56 +00002347LLVM_DUMP_METHOD void Stmt::dump(raw_ostream &OS) const {
2348 ASTDumper P(OS, nullptr, nullptr);
2349 P.dumpStmt(this);
2350}
2351
Alp Tokeref6b0072014-01-04 13:47:14 +00002352LLVM_DUMP_METHOD void Stmt::dump() const {
Craig Topper36250ad2014-05-12 05:36:57 +00002353 ASTDumper P(llvm::errs(), nullptr, nullptr);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002354 P.dumpStmt(this);
Chris Lattnercbe4f772007-08-08 22:51:59 +00002355}
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002356
Alp Tokeref6b0072014-01-04 13:47:14 +00002357LLVM_DUMP_METHOD void Stmt::dumpColor() const {
Craig Topper36250ad2014-05-12 05:36:57 +00002358 ASTDumper P(llvm::errs(), nullptr, nullptr, /*ShowColors*/true);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002359 P.dumpStmt(this);
Richard Trieud215b8d2013-01-26 01:31:20 +00002360}
2361
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002362//===----------------------------------------------------------------------===//
2363// Comment method implementations
2364//===----------------------------------------------------------------------===//
2365
Craig Topper36250ad2014-05-12 05:36:57 +00002366LLVM_DUMP_METHOD void Comment::dump() const {
2367 dump(llvm::errs(), nullptr, nullptr);
2368}
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002369
Alp Tokeref6b0072014-01-04 13:47:14 +00002370LLVM_DUMP_METHOD void Comment::dump(const ASTContext &Context) const {
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002371 dump(llvm::errs(), &Context.getCommentCommandTraits(),
2372 &Context.getSourceManager());
2373}
2374
Alexander Kornienko00911f12013-01-15 12:20:21 +00002375void Comment::dump(raw_ostream &OS, const CommandTraits *Traits,
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002376 const SourceManager *SM) const {
2377 const FullComment *FC = dyn_cast<FullComment>(this);
2378 ASTDumper D(OS, Traits, SM);
2379 D.dumpFullComment(FC);
2380}
Richard Trieud215b8d2013-01-26 01:31:20 +00002381
Alp Tokeref6b0072014-01-04 13:47:14 +00002382LLVM_DUMP_METHOD void Comment::dumpColor() const {
Richard Trieud215b8d2013-01-26 01:31:20 +00002383 const FullComment *FC = dyn_cast<FullComment>(this);
Craig Topper36250ad2014-05-12 05:36:57 +00002384 ASTDumper D(llvm::errs(), nullptr, nullptr, /*ShowColors*/true);
Richard Trieud215b8d2013-01-26 01:31:20 +00002385 D.dumpFullComment(FC);
2386}