blob: 872420606b6f6e1e6e34ef9626f897b5a58001c1 [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"
Benjamin Kramer31b382e2016-02-01 17:42:01 +000022#include "clang/AST/LocInfoType.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000023#include "clang/AST/StmtVisitor.h"
Richard Smithd5e7ff82014-10-31 01:17:45 +000024#include "clang/AST/TypeVisitor.h"
David Majnemerd9b1a4f2015-11-04 03:40:30 +000025#include "clang/Basic/Builtins.h"
Alexander Kornienko90ff6072012-12-20 02:09:13 +000026#include "clang/Basic/Module.h"
Chris Lattner11e30d32007-08-30 06:17:34 +000027#include "clang/Basic/SourceManager.h"
Daniel Dunbar34a96c82009-12-03 09:13:13 +000028#include "llvm/Support/raw_ostream.h"
Chris Lattnercbe4f772007-08-08 22:51:59 +000029using namespace clang;
Alexander Kornienkoebc17b52013-01-14 14:07:11 +000030using namespace clang::comments;
Chris Lattnercbe4f772007-08-08 22:51:59 +000031
32//===----------------------------------------------------------------------===//
Alexander Kornienko18ec81b2012-12-13 13:59:55 +000033// ASTDumper Visitor
Chris Lattnercbe4f772007-08-08 22:51:59 +000034//===----------------------------------------------------------------------===//
35
36namespace {
Richard Trieud215b8d2013-01-26 01:31:20 +000037 // Colors used for various parts of the AST dump
Richard Trieu532018f2014-03-06 01:09:03 +000038 // Do not use bold yellow for any text. It is hard to read on white screens.
Richard Trieud215b8d2013-01-26 01:31:20 +000039
40 struct TerminalColor {
41 raw_ostream::Colors Color;
42 bool Bold;
43 };
44
Richard Trieu532018f2014-03-06 01:09:03 +000045 // Red - CastColor
46 // Green - TypeColor
47 // Bold Green - DeclKindNameColor, UndeserializedColor
48 // Yellow - AddressColor, LocationColor
49 // Blue - CommentColor, NullColor, IndentColor
50 // Bold Blue - AttrColor
51 // Bold Magenta - StmtColor
52 // Cyan - ValueKindColor, ObjectKindColor
53 // Bold Cyan - ValueColor, DeclNameColor
54
Richard Trieud215b8d2013-01-26 01:31:20 +000055 // Decl kind names (VarDecl, FunctionDecl, etc)
56 static const TerminalColor DeclKindNameColor = { raw_ostream::GREEN, true };
57 // Attr names (CleanupAttr, GuardedByAttr, etc)
58 static const TerminalColor AttrColor = { raw_ostream::BLUE, true };
59 // Statement names (DeclStmt, ImplicitCastExpr, etc)
60 static const TerminalColor StmtColor = { raw_ostream::MAGENTA, true };
61 // Comment names (FullComment, ParagraphComment, TextComment, etc)
Richard Trieu532018f2014-03-06 01:09:03 +000062 static const TerminalColor CommentColor = { raw_ostream::BLUE, false };
Richard Trieud215b8d2013-01-26 01:31:20 +000063
64 // Type names (int, float, etc, plus user defined types)
65 static const TerminalColor TypeColor = { raw_ostream::GREEN, false };
66
67 // Pointer address
68 static const TerminalColor AddressColor = { raw_ostream::YELLOW, false };
69 // Source locations
70 static const TerminalColor LocationColor = { raw_ostream::YELLOW, false };
71
72 // lvalue/xvalue
73 static const TerminalColor ValueKindColor = { raw_ostream::CYAN, false };
74 // bitfield/objcproperty/objcsubscript/vectorcomponent
75 static const TerminalColor ObjectKindColor = { raw_ostream::CYAN, false };
76
77 // Null statements
78 static const TerminalColor NullColor = { raw_ostream::BLUE, false };
79
Richard Smith1d209d02013-05-23 01:49:11 +000080 // Undeserialized entities
81 static const TerminalColor UndeserializedColor = { raw_ostream::GREEN, true };
82
Richard Trieud215b8d2013-01-26 01:31:20 +000083 // CastKind from CastExpr's
84 static const TerminalColor CastColor = { raw_ostream::RED, false };
85
86 // Value of the statement
87 static const TerminalColor ValueColor = { raw_ostream::CYAN, true };
88 // Decl names
89 static const TerminalColor DeclNameColor = { raw_ostream::CYAN, true };
90
Richard Trieude5cc7d2013-01-31 01:44:26 +000091 // Indents ( `, -. | )
92 static const TerminalColor IndentColor = { raw_ostream::BLUE, false };
93
Alexander Kornienko90ff6072012-12-20 02:09:13 +000094 class ASTDumper
Alexander Kornienko540bacb2013-02-01 12:35:51 +000095 : public ConstDeclVisitor<ASTDumper>, public ConstStmtVisitor<ASTDumper>,
Richard Smithd5e7ff82014-10-31 01:17:45 +000096 public ConstCommentVisitor<ASTDumper>, public TypeVisitor<ASTDumper> {
Chris Lattner0e62c1c2011-07-23 10:55:15 +000097 raw_ostream &OS;
Alexander Kornienkoebc17b52013-01-14 14:07:11 +000098 const CommandTraits *Traits;
99 const SourceManager *SM;
Mike Stump11289f42009-09-09 15:08:12 +0000100
Richard Smithf7514452014-10-30 21:02:37 +0000101 /// Pending[i] is an action to dump an entity at level i.
102 llvm::SmallVector<std::function<void(bool isLastChild)>, 32> Pending;
Richard Trieude5cc7d2013-01-31 01:44:26 +0000103
Richard Smithf7514452014-10-30 21:02:37 +0000104 /// Indicates whether we're at the top level.
105 bool TopLevel;
Richard Trieude5cc7d2013-01-31 01:44:26 +0000106
Richard Smithf7514452014-10-30 21:02:37 +0000107 /// Indicates if we're handling the first child after entering a new depth.
108 bool FirstChild;
109
110 /// Prefix for currently-being-dumped entity.
111 std::string Prefix;
Richard Trieude5cc7d2013-01-31 01:44:26 +0000112
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000113 /// Keep track of the last location we print out so that we can
114 /// print out deltas from then on out.
Chris Lattner11e30d32007-08-30 06:17:34 +0000115 const char *LastLocFilename;
116 unsigned LastLocLine;
Douglas Gregor7de59662009-05-29 20:38:28 +0000117
Alexander Kornienkoebc17b52013-01-14 14:07:11 +0000118 /// The \c FullComment parent of the comment being dumped.
119 const FullComment *FC;
120
Richard Trieud215b8d2013-01-26 01:31:20 +0000121 bool ShowColors;
122
Richard Smithf7514452014-10-30 21:02:37 +0000123 /// Dump a child of the current node.
124 template<typename Fn> void dumpChild(Fn doDumpChild) {
125 // If we're at the top level, there's nothing interesting to do; just
126 // run the dumper.
127 if (TopLevel) {
128 TopLevel = false;
129 doDumpChild();
130 while (!Pending.empty()) {
131 Pending.back()(true);
132 Pending.pop_back();
133 }
134 Prefix.clear();
135 OS << "\n";
136 TopLevel = true;
137 return;
Manuel Klimek874030e2012-11-07 00:33:12 +0000138 }
Richard Smithf7514452014-10-30 21:02:37 +0000139
140 const FullComment *OrigFC = FC;
141 auto dumpWithIndent = [this, doDumpChild, OrigFC](bool isLastChild) {
142 // Print out the appropriate tree structure and work out the prefix for
143 // children of this node. For instance:
144 //
145 // A Prefix = ""
146 // |-B Prefix = "| "
147 // | `-C Prefix = "| "
148 // `-D Prefix = " "
149 // |-E Prefix = " | "
150 // `-F Prefix = " "
151 // G Prefix = ""
152 //
153 // Note that the first level gets no prefix.
154 {
155 OS << '\n';
156 ColorScope Color(*this, IndentColor);
157 OS << Prefix << (isLastChild ? '`' : '|') << '-';
NAKAMURA Takumic73e4022014-10-31 00:30:37 +0000158 this->Prefix.push_back(isLastChild ? ' ' : '|');
159 this->Prefix.push_back(' ');
Richard Smithf7514452014-10-30 21:02:37 +0000160 }
161
162 FirstChild = true;
163 unsigned Depth = Pending.size();
164
165 FC = OrigFC;
166 doDumpChild();
167
168 // If any children are left, they're the last at their nesting level.
169 // Dump those ones out now.
170 while (Depth < Pending.size()) {
171 Pending.back()(true);
NAKAMURA Takumic73e4022014-10-31 00:30:37 +0000172 this->Pending.pop_back();
Richard Smithf7514452014-10-30 21:02:37 +0000173 }
174
175 // Restore the old prefix.
NAKAMURA Takumic73e4022014-10-31 00:30:37 +0000176 this->Prefix.resize(Prefix.size() - 2);
Richard Smithf7514452014-10-30 21:02:37 +0000177 };
178
179 if (FirstChild) {
180 Pending.push_back(std::move(dumpWithIndent));
181 } else {
182 Pending.back()(false);
183 Pending.back() = std::move(dumpWithIndent);
Manuel Klimek874030e2012-11-07 00:33:12 +0000184 }
Richard Smithf7514452014-10-30 21:02:37 +0000185 FirstChild = false;
186 }
Manuel Klimek874030e2012-11-07 00:33:12 +0000187
Richard Trieud215b8d2013-01-26 01:31:20 +0000188 class ColorScope {
189 ASTDumper &Dumper;
190 public:
191 ColorScope(ASTDumper &Dumper, TerminalColor Color)
192 : Dumper(Dumper) {
193 if (Dumper.ShowColors)
194 Dumper.OS.changeColor(Color.Color, Color.Bold);
195 }
196 ~ColorScope() {
197 if (Dumper.ShowColors)
198 Dumper.OS.resetColor();
199 }
200 };
201
Chris Lattnercbe4f772007-08-08 22:51:59 +0000202 public:
Alexander Kornienkoebc17b52013-01-14 14:07:11 +0000203 ASTDumper(raw_ostream &OS, const CommandTraits *Traits,
204 const SourceManager *SM)
Richard Smithf7514452014-10-30 21:02:37 +0000205 : OS(OS), Traits(Traits), SM(SM), TopLevel(true), FirstChild(true),
Craig Topper36250ad2014-05-12 05:36:57 +0000206 LastLocFilename(""), LastLocLine(~0U), FC(nullptr),
Richard Trieud215b8d2013-01-26 01:31:20 +0000207 ShowColors(SM && SM->getDiagnostics().getShowColors()) { }
208
209 ASTDumper(raw_ostream &OS, const CommandTraits *Traits,
210 const SourceManager *SM, bool ShowColors)
Richard Smithf7514452014-10-30 21:02:37 +0000211 : OS(OS), Traits(Traits), SM(SM), TopLevel(true), FirstChild(true),
Richard Smith56d12152013-01-31 02:04:38 +0000212 LastLocFilename(""), LastLocLine(~0U),
Richard Trieude5cc7d2013-01-31 01:44:26 +0000213 ShowColors(ShowColors) { }
Mike Stump11289f42009-09-09 15:08:12 +0000214
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000215 void dumpDecl(const Decl *D);
216 void dumpStmt(const Stmt *S);
Alexander Kornienkoebc17b52013-01-14 14:07:11 +0000217 void dumpFullComment(const FullComment *C);
Mike Stump11289f42009-09-09 15:08:12 +0000218
Richard Trieude5cc7d2013-01-31 01:44:26 +0000219 // Utilities
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000220 void dumpPointer(const void *Ptr);
221 void dumpSourceRange(SourceRange R);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000222 void dumpLocation(SourceLocation Loc);
Richard Smithd5e7ff82014-10-31 01:17:45 +0000223 void dumpBareType(QualType T, bool Desugar = true);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000224 void dumpType(QualType T);
Richard Smithd5e7ff82014-10-31 01:17:45 +0000225 void dumpTypeAsChild(QualType T);
226 void dumpTypeAsChild(const Type *T);
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000227 void dumpBareDeclRef(const Decl *Node);
Craig Topper36250ad2014-05-12 05:36:57 +0000228 void dumpDeclRef(const Decl *Node, const char *Label = nullptr);
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000229 void dumpName(const NamedDecl *D);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000230 bool hasNodes(const DeclContext *DC);
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000231 void dumpDeclContext(const DeclContext *DC);
Richard Smith35f986d2014-08-11 22:11:07 +0000232 void dumpLookups(const DeclContext *DC, bool DumpDecls);
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000233 void dumpAttr(const Attr *A);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000234
235 // C++ Utilities
236 void dumpAccessSpecifier(AccessSpecifier AS);
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000237 void dumpCXXCtorInitializer(const CXXCtorInitializer *Init);
238 void dumpTemplateParameters(const TemplateParameterList *TPL);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000239 void dumpTemplateArgumentListInfo(const TemplateArgumentListInfo &TALI);
240 void dumpTemplateArgumentLoc(const TemplateArgumentLoc &A);
241 void dumpTemplateArgumentList(const TemplateArgumentList &TAL);
242 void dumpTemplateArgument(const TemplateArgument &A,
243 SourceRange R = SourceRange());
244
Douglas Gregor85f3f952015-07-07 03:57:15 +0000245 // Objective-C utilities.
246 void dumpObjCTypeParamList(const ObjCTypeParamList *typeParams);
247
Richard Smithd5e7ff82014-10-31 01:17:45 +0000248 // Types
249 void VisitComplexType(const ComplexType *T) {
250 dumpTypeAsChild(T->getElementType());
251 }
252 void VisitPointerType(const PointerType *T) {
253 dumpTypeAsChild(T->getPointeeType());
254 }
255 void VisitBlockPointerType(const BlockPointerType *T) {
256 dumpTypeAsChild(T->getPointeeType());
257 }
258 void VisitReferenceType(const ReferenceType *T) {
259 dumpTypeAsChild(T->getPointeeType());
260 }
261 void VisitRValueReferenceType(const ReferenceType *T) {
262 if (T->isSpelledAsLValue())
263 OS << " written as lvalue reference";
264 VisitReferenceType(T);
265 }
266 void VisitMemberPointerType(const MemberPointerType *T) {
267 dumpTypeAsChild(T->getClass());
268 dumpTypeAsChild(T->getPointeeType());
269 }
270 void VisitArrayType(const ArrayType *T) {
271 switch (T->getSizeModifier()) {
272 case ArrayType::Normal: break;
273 case ArrayType::Static: OS << " static"; break;
274 case ArrayType::Star: OS << " *"; break;
275 }
276 OS << " " << T->getIndexTypeQualifiers().getAsString();
277 dumpTypeAsChild(T->getElementType());
278 }
279 void VisitConstantArrayType(const ConstantArrayType *T) {
280 OS << " " << T->getSize();
281 VisitArrayType(T);
282 }
283 void VisitVariableArrayType(const VariableArrayType *T) {
284 OS << " ";
285 dumpSourceRange(T->getBracketsRange());
286 VisitArrayType(T);
287 dumpStmt(T->getSizeExpr());
288 }
289 void VisitDependentSizedArrayType(const DependentSizedArrayType *T) {
290 VisitArrayType(T);
291 OS << " ";
292 dumpSourceRange(T->getBracketsRange());
293 dumpStmt(T->getSizeExpr());
294 }
295 void VisitDependentSizedExtVectorType(
296 const DependentSizedExtVectorType *T) {
297 OS << " ";
298 dumpLocation(T->getAttributeLoc());
299 dumpTypeAsChild(T->getElementType());
300 dumpStmt(T->getSizeExpr());
301 }
302 void VisitVectorType(const VectorType *T) {
303 switch (T->getVectorKind()) {
304 case VectorType::GenericVector: break;
305 case VectorType::AltiVecVector: OS << " altivec"; break;
306 case VectorType::AltiVecPixel: OS << " altivec pixel"; break;
307 case VectorType::AltiVecBool: OS << " altivec bool"; break;
308 case VectorType::NeonVector: OS << " neon"; break;
309 case VectorType::NeonPolyVector: OS << " neon poly"; break;
310 }
311 OS << " " << T->getNumElements();
312 dumpTypeAsChild(T->getElementType());
313 }
314 void VisitFunctionType(const FunctionType *T) {
315 auto EI = T->getExtInfo();
316 if (EI.getNoReturn()) OS << " noreturn";
317 if (EI.getProducesResult()) OS << " produces_result";
318 if (EI.getHasRegParm()) OS << " regparm " << EI.getRegParm();
319 OS << " " << FunctionType::getNameForCallConv(EI.getCC());
320 dumpTypeAsChild(T->getReturnType());
321 }
322 void VisitFunctionProtoType(const FunctionProtoType *T) {
323 auto EPI = T->getExtProtoInfo();
324 if (EPI.HasTrailingReturn) OS << " trailing_return";
325 if (T->isConst()) OS << " const";
326 if (T->isVolatile()) OS << " volatile";
327 if (T->isRestrict()) OS << " restrict";
328 switch (EPI.RefQualifier) {
329 case RQ_None: break;
330 case RQ_LValue: OS << " &"; break;
331 case RQ_RValue: OS << " &&"; break;
332 }
333 // FIXME: Exception specification.
334 // FIXME: Consumed parameters.
335 VisitFunctionType(T);
336 for (QualType PT : T->getParamTypes())
337 dumpTypeAsChild(PT);
338 if (EPI.Variadic)
339 dumpChild([=] { OS << "..."; });
340 }
341 void VisitUnresolvedUsingType(const UnresolvedUsingType *T) {
342 dumpDeclRef(T->getDecl());
343 }
344 void VisitTypedefType(const TypedefType *T) {
345 dumpDeclRef(T->getDecl());
346 }
347 void VisitTypeOfExprType(const TypeOfExprType *T) {
348 dumpStmt(T->getUnderlyingExpr());
349 }
350 void VisitDecltypeType(const DecltypeType *T) {
351 dumpStmt(T->getUnderlyingExpr());
352 }
353 void VisitUnaryTransformType(const UnaryTransformType *T) {
354 switch (T->getUTTKind()) {
355 case UnaryTransformType::EnumUnderlyingType:
356 OS << " underlying_type";
357 break;
358 }
359 dumpTypeAsChild(T->getBaseType());
360 }
361 void VisitTagType(const TagType *T) {
362 dumpDeclRef(T->getDecl());
363 }
364 void VisitAttributedType(const AttributedType *T) {
365 // FIXME: AttrKind
366 dumpTypeAsChild(T->getModifiedType());
367 }
368 void VisitTemplateTypeParmType(const TemplateTypeParmType *T) {
369 OS << " depth " << T->getDepth() << " index " << T->getIndex();
370 if (T->isParameterPack()) OS << " pack";
371 dumpDeclRef(T->getDecl());
372 }
373 void VisitSubstTemplateTypeParmType(const SubstTemplateTypeParmType *T) {
374 dumpTypeAsChild(T->getReplacedParameter());
375 }
376 void VisitSubstTemplateTypeParmPackType(
377 const SubstTemplateTypeParmPackType *T) {
378 dumpTypeAsChild(T->getReplacedParameter());
379 dumpTemplateArgument(T->getArgumentPack());
380 }
381 void VisitAutoType(const AutoType *T) {
382 if (T->isDecltypeAuto()) OS << " decltype(auto)";
383 if (!T->isDeduced())
384 OS << " undeduced";
385 }
386 void VisitTemplateSpecializationType(const TemplateSpecializationType *T) {
387 if (T->isTypeAlias()) OS << " alias";
388 OS << " "; T->getTemplateName().dump(OS);
389 for (auto &Arg : *T)
390 dumpTemplateArgument(Arg);
391 if (T->isTypeAlias())
392 dumpTypeAsChild(T->getAliasedType());
393 }
394 void VisitInjectedClassNameType(const InjectedClassNameType *T) {
395 dumpDeclRef(T->getDecl());
396 }
397 void VisitObjCInterfaceType(const ObjCInterfaceType *T) {
398 dumpDeclRef(T->getDecl());
399 }
400 void VisitObjCObjectPointerType(const ObjCObjectPointerType *T) {
401 dumpTypeAsChild(T->getPointeeType());
402 }
403 void VisitAtomicType(const AtomicType *T) {
404 dumpTypeAsChild(T->getValueType());
405 }
406 void VisitAdjustedType(const AdjustedType *T) {
407 dumpTypeAsChild(T->getOriginalType());
408 }
409 void VisitPackExpansionType(const PackExpansionType *T) {
410 if (auto N = T->getNumExpansions()) OS << " expansions " << *N;
411 if (!T->isSugared())
412 dumpTypeAsChild(T->getPattern());
413 }
414 // FIXME: ElaboratedType, DependentNameType,
415 // DependentTemplateSpecializationType, ObjCObjectType
416
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000417 // Decls
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000418 void VisitLabelDecl(const LabelDecl *D);
419 void VisitTypedefDecl(const TypedefDecl *D);
420 void VisitEnumDecl(const EnumDecl *D);
421 void VisitRecordDecl(const RecordDecl *D);
422 void VisitEnumConstantDecl(const EnumConstantDecl *D);
423 void VisitIndirectFieldDecl(const IndirectFieldDecl *D);
424 void VisitFunctionDecl(const FunctionDecl *D);
425 void VisitFieldDecl(const FieldDecl *D);
426 void VisitVarDecl(const VarDecl *D);
427 void VisitFileScopeAsmDecl(const FileScopeAsmDecl *D);
428 void VisitImportDecl(const ImportDecl *D);
Nico Weber66220292016-03-02 17:28:48 +0000429 void VisitPragmaCommentDecl(const PragmaCommentDecl *D);
Nico Webercbbaeb12016-03-02 19:28:54 +0000430 void VisitPragmaDetectMismatchDecl(const PragmaDetectMismatchDecl *D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000431
432 // C++ Decls
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000433 void VisitNamespaceDecl(const NamespaceDecl *D);
434 void VisitUsingDirectiveDecl(const UsingDirectiveDecl *D);
435 void VisitNamespaceAliasDecl(const NamespaceAliasDecl *D);
436 void VisitTypeAliasDecl(const TypeAliasDecl *D);
437 void VisitTypeAliasTemplateDecl(const TypeAliasTemplateDecl *D);
438 void VisitCXXRecordDecl(const CXXRecordDecl *D);
439 void VisitStaticAssertDecl(const StaticAssertDecl *D);
Richard Smithcbdf7332014-03-18 02:07:28 +0000440 template<typename SpecializationDecl>
Richard Smithf7514452014-10-30 21:02:37 +0000441 void VisitTemplateDeclSpecialization(const SpecializationDecl *D,
Richard Smithcbdf7332014-03-18 02:07:28 +0000442 bool DumpExplicitInst,
443 bool DumpRefOnly);
Richard Smith20ade552014-03-17 23:34:53 +0000444 template<typename TemplateDecl>
445 void VisitTemplateDecl(const TemplateDecl *D, bool DumpExplicitInst);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000446 void VisitFunctionTemplateDecl(const FunctionTemplateDecl *D);
447 void VisitClassTemplateDecl(const ClassTemplateDecl *D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000448 void VisitClassTemplateSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000449 const ClassTemplateSpecializationDecl *D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000450 void VisitClassTemplatePartialSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000451 const ClassTemplatePartialSpecializationDecl *D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000452 void VisitClassScopeFunctionSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000453 const ClassScopeFunctionSpecializationDecl *D);
David Majnemerd9b1a4f2015-11-04 03:40:30 +0000454 void VisitBuiltinTemplateDecl(const BuiltinTemplateDecl *D);
Richard Smithd25789a2013-09-18 01:36:02 +0000455 void VisitVarTemplateDecl(const VarTemplateDecl *D);
456 void VisitVarTemplateSpecializationDecl(
457 const VarTemplateSpecializationDecl *D);
458 void VisitVarTemplatePartialSpecializationDecl(
459 const VarTemplatePartialSpecializationDecl *D);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000460 void VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D);
461 void VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D);
462 void VisitTemplateTemplateParmDecl(const TemplateTemplateParmDecl *D);
463 void VisitUsingDecl(const UsingDecl *D);
464 void VisitUnresolvedUsingTypenameDecl(const UnresolvedUsingTypenameDecl *D);
465 void VisitUnresolvedUsingValueDecl(const UnresolvedUsingValueDecl *D);
466 void VisitUsingShadowDecl(const UsingShadowDecl *D);
467 void VisitLinkageSpecDecl(const LinkageSpecDecl *D);
468 void VisitAccessSpecDecl(const AccessSpecDecl *D);
469 void VisitFriendDecl(const FriendDecl *D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000470
471 // ObjC Decls
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000472 void VisitObjCIvarDecl(const ObjCIvarDecl *D);
473 void VisitObjCMethodDecl(const ObjCMethodDecl *D);
Douglas Gregor85f3f952015-07-07 03:57:15 +0000474 void VisitObjCTypeParamDecl(const ObjCTypeParamDecl *D);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000475 void VisitObjCCategoryDecl(const ObjCCategoryDecl *D);
476 void VisitObjCCategoryImplDecl(const ObjCCategoryImplDecl *D);
477 void VisitObjCProtocolDecl(const ObjCProtocolDecl *D);
478 void VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D);
479 void VisitObjCImplementationDecl(const ObjCImplementationDecl *D);
480 void VisitObjCCompatibleAliasDecl(const ObjCCompatibleAliasDecl *D);
481 void VisitObjCPropertyDecl(const ObjCPropertyDecl *D);
482 void VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D);
483 void VisitBlockDecl(const BlockDecl *D);
Mike Stump11289f42009-09-09 15:08:12 +0000484
Chris Lattner84ca3762007-08-30 01:00:35 +0000485 // Stmts.
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000486 void VisitStmt(const Stmt *Node);
487 void VisitDeclStmt(const DeclStmt *Node);
488 void VisitAttributedStmt(const AttributedStmt *Node);
489 void VisitLabelStmt(const LabelStmt *Node);
490 void VisitGotoStmt(const GotoStmt *Node);
Pavel Labath1ef83422013-09-04 14:35:00 +0000491 void VisitCXXCatchStmt(const CXXCatchStmt *Node);
Mike Stump11289f42009-09-09 15:08:12 +0000492
Chris Lattner84ca3762007-08-30 01:00:35 +0000493 // Exprs
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000494 void VisitExpr(const Expr *Node);
495 void VisitCastExpr(const CastExpr *Node);
496 void VisitDeclRefExpr(const DeclRefExpr *Node);
497 void VisitPredefinedExpr(const PredefinedExpr *Node);
498 void VisitCharacterLiteral(const CharacterLiteral *Node);
499 void VisitIntegerLiteral(const IntegerLiteral *Node);
500 void VisitFloatingLiteral(const FloatingLiteral *Node);
501 void VisitStringLiteral(const StringLiteral *Str);
Richard Smithf0514962014-06-03 08:24:28 +0000502 void VisitInitListExpr(const InitListExpr *ILE);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000503 void VisitUnaryOperator(const UnaryOperator *Node);
504 void VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *Node);
505 void VisitMemberExpr(const MemberExpr *Node);
506 void VisitExtVectorElementExpr(const ExtVectorElementExpr *Node);
507 void VisitBinaryOperator(const BinaryOperator *Node);
508 void VisitCompoundAssignOperator(const CompoundAssignOperator *Node);
509 void VisitAddrLabelExpr(const AddrLabelExpr *Node);
510 void VisitBlockExpr(const BlockExpr *Node);
511 void VisitOpaqueValueExpr(const OpaqueValueExpr *Node);
Chris Lattner84ca3762007-08-30 01:00:35 +0000512
513 // C++
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000514 void VisitCXXNamedCastExpr(const CXXNamedCastExpr *Node);
515 void VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *Node);
516 void VisitCXXThisExpr(const CXXThisExpr *Node);
517 void VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *Node);
518 void VisitCXXConstructExpr(const CXXConstructExpr *Node);
519 void VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *Node);
Reid Kleckner5c682bc2015-03-19 18:09:25 +0000520 void VisitCXXNewExpr(const CXXNewExpr *Node);
521 void VisitCXXDeleteExpr(const CXXDeleteExpr *Node);
Richard Smithe6c01442013-06-05 00:46:14 +0000522 void VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000523 void VisitExprWithCleanups(const ExprWithCleanups *Node);
524 void VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *Node);
525 void dumpCXXTemporary(const CXXTemporary *Temporary);
Faisal Vali2b391ab2013-09-26 19:54:12 +0000526 void VisitLambdaExpr(const LambdaExpr *Node) {
527 VisitExpr(Node);
528 dumpDecl(Node->getLambdaClass());
529 }
Serge Pavlov6b926032015-02-16 19:58:41 +0000530 void VisitSizeOfPackExpr(const SizeOfPackExpr *Node);
Mike Stump11289f42009-09-09 15:08:12 +0000531
Chris Lattner84ca3762007-08-30 01:00:35 +0000532 // ObjC
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000533 void VisitObjCAtCatchStmt(const ObjCAtCatchStmt *Node);
534 void VisitObjCEncodeExpr(const ObjCEncodeExpr *Node);
535 void VisitObjCMessageExpr(const ObjCMessageExpr *Node);
536 void VisitObjCBoxedExpr(const ObjCBoxedExpr *Node);
537 void VisitObjCSelectorExpr(const ObjCSelectorExpr *Node);
538 void VisitObjCProtocolExpr(const ObjCProtocolExpr *Node);
539 void VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *Node);
540 void VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *Node);
541 void VisitObjCIvarRefExpr(const ObjCIvarRefExpr *Node);
542 void VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *Node);
Alexander Kornienkoebc17b52013-01-14 14:07:11 +0000543
544 // Comments.
545 const char *getCommandName(unsigned CommandID);
546 void dumpComment(const Comment *C);
547
548 // Inline comments.
549 void visitTextComment(const TextComment *C);
550 void visitInlineCommandComment(const InlineCommandComment *C);
551 void visitHTMLStartTagComment(const HTMLStartTagComment *C);
552 void visitHTMLEndTagComment(const HTMLEndTagComment *C);
553
554 // Block comments.
555 void visitBlockCommandComment(const BlockCommandComment *C);
556 void visitParamCommandComment(const ParamCommandComment *C);
557 void visitTParamCommandComment(const TParamCommandComment *C);
558 void visitVerbatimBlockComment(const VerbatimBlockComment *C);
559 void visitVerbatimBlockLineComment(const VerbatimBlockLineComment *C);
560 void visitVerbatimLineComment(const VerbatimLineComment *C);
Chris Lattnercbe4f772007-08-08 22:51:59 +0000561 };
Alexander Kornienkoab9db512015-06-22 23:07:51 +0000562}
Chris Lattnercbe4f772007-08-08 22:51:59 +0000563
564//===----------------------------------------------------------------------===//
Chris Lattner11e30d32007-08-30 06:17:34 +0000565// Utilities
566//===----------------------------------------------------------------------===//
567
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000568void ASTDumper::dumpPointer(const void *Ptr) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000569 ColorScope Color(*this, AddressColor);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000570 OS << ' ' << Ptr;
571}
572
Alexander Kornienko18ec81b2012-12-13 13:59:55 +0000573void ASTDumper::dumpLocation(SourceLocation Loc) {
Alex McCarthye14ddef2014-05-02 20:24:11 +0000574 if (!SM)
575 return;
576
Richard Trieud215b8d2013-01-26 01:31:20 +0000577 ColorScope Color(*this, LocationColor);
Chris Lattner53e384f2009-01-16 07:00:02 +0000578 SourceLocation SpellingLoc = SM->getSpellingLoc(Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000579
Chris Lattner11e30d32007-08-30 06:17:34 +0000580 // The general format we print out is filename:line:col, but we drop pieces
581 // that haven't changed since the last loc printed.
Chris Lattnerf1ca7d32009-01-27 07:57:44 +0000582 PresumedLoc PLoc = SM->getPresumedLoc(SpellingLoc);
583
Douglas Gregor453b0122010-11-12 07:15:47 +0000584 if (PLoc.isInvalid()) {
585 OS << "<invalid sloc>";
586 return;
587 }
588
Chris Lattnerf1ca7d32009-01-27 07:57:44 +0000589 if (strcmp(PLoc.getFilename(), LastLocFilename) != 0) {
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000590 OS << PLoc.getFilename() << ':' << PLoc.getLine()
591 << ':' << PLoc.getColumn();
Chris Lattnerf1ca7d32009-01-27 07:57:44 +0000592 LastLocFilename = PLoc.getFilename();
593 LastLocLine = PLoc.getLine();
594 } else if (PLoc.getLine() != LastLocLine) {
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000595 OS << "line" << ':' << PLoc.getLine()
596 << ':' << PLoc.getColumn();
Chris Lattnerf1ca7d32009-01-27 07:57:44 +0000597 LastLocLine = PLoc.getLine();
Chris Lattner11e30d32007-08-30 06:17:34 +0000598 } else {
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000599 OS << "col" << ':' << PLoc.getColumn();
Chris Lattner11e30d32007-08-30 06:17:34 +0000600 }
601}
602
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000603void ASTDumper::dumpSourceRange(SourceRange R) {
Chris Lattner11e30d32007-08-30 06:17:34 +0000604 // Can't translate locations if a SourceManager isn't available.
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000605 if (!SM)
606 return;
Mike Stump11289f42009-09-09 15:08:12 +0000607
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000608 OS << " <";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000609 dumpLocation(R.getBegin());
Chris Lattnera7c19fe2007-10-16 22:36:42 +0000610 if (R.getBegin() != R.getEnd()) {
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000611 OS << ", ";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000612 dumpLocation(R.getEnd());
Chris Lattner11e30d32007-08-30 06:17:34 +0000613 }
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000614 OS << ">";
Mike Stump11289f42009-09-09 15:08:12 +0000615
Chris Lattner11e30d32007-08-30 06:17:34 +0000616 // <t2.c:123:421[blah], t2.c:412:321>
617
618}
619
Richard Smithd5e7ff82014-10-31 01:17:45 +0000620void ASTDumper::dumpBareType(QualType T, bool Desugar) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000621 ColorScope Color(*this, TypeColor);
Richard Smithd5e7ff82014-10-31 01:17:45 +0000622
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000623 SplitQualType T_split = T.split();
624 OS << "'" << QualType::getAsString(T_split) << "'";
625
Richard Smithd5e7ff82014-10-31 01:17:45 +0000626 if (Desugar && !T.isNull()) {
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000627 // If the type is sugared, also dump a (shallow) desugared type.
628 SplitQualType D_split = T.getSplitDesugaredType();
629 if (T_split != D_split)
630 OS << ":'" << QualType::getAsString(D_split) << "'";
631 }
632}
633
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000634void ASTDumper::dumpType(QualType T) {
635 OS << ' ';
636 dumpBareType(T);
637}
638
Richard Smithd5e7ff82014-10-31 01:17:45 +0000639void ASTDumper::dumpTypeAsChild(QualType T) {
640 SplitQualType SQT = T.split();
641 if (!SQT.Quals.hasQualifiers())
642 return dumpTypeAsChild(SQT.Ty);
643
644 dumpChild([=] {
645 OS << "QualType";
646 dumpPointer(T.getAsOpaquePtr());
647 OS << " ";
648 dumpBareType(T, false);
649 OS << " " << T.split().Quals.getAsString();
650 dumpTypeAsChild(T.split().Ty);
651 });
652}
653
654void ASTDumper::dumpTypeAsChild(const Type *T) {
655 dumpChild([=] {
656 if (!T) {
657 ColorScope Color(*this, NullColor);
658 OS << "<<<NULL>>>";
659 return;
660 }
Serge Pavlova6adc9e2015-12-28 17:19:12 +0000661 if (const LocInfoType *LIT = llvm::dyn_cast<LocInfoType>(T)) {
662 {
663 ColorScope Color(*this, TypeColor);
664 OS << "LocInfo Type";
665 }
666 dumpPointer(T);
667 dumpTypeAsChild(LIT->getTypeSourceInfo()->getType());
668 return;
669 }
Richard Smithd5e7ff82014-10-31 01:17:45 +0000670
671 {
672 ColorScope Color(*this, TypeColor);
673 OS << T->getTypeClassName() << "Type";
674 }
675 dumpPointer(T);
676 OS << " ";
677 dumpBareType(QualType(T, 0), false);
678
679 QualType SingleStepDesugar =
680 T->getLocallyUnqualifiedSingleStepDesugaredType();
681 if (SingleStepDesugar != QualType(T, 0))
682 OS << " sugar";
683 if (T->isDependentType())
684 OS << " dependent";
685 else if (T->isInstantiationDependentType())
686 OS << " instantiation_dependent";
687 if (T->isVariablyModifiedType())
688 OS << " variably_modified";
689 if (T->containsUnexpandedParameterPack())
690 OS << " contains_unexpanded_pack";
691 if (T->isFromAST())
692 OS << " imported";
693
694 TypeVisitor<ASTDumper>::Visit(T);
695
696 if (SingleStepDesugar != QualType(T, 0))
697 dumpTypeAsChild(SingleStepDesugar);
698 });
699}
700
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000701void ASTDumper::dumpBareDeclRef(const Decl *D) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000702 {
703 ColorScope Color(*this, DeclKindNameColor);
704 OS << D->getDeclKindName();
705 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000706 dumpPointer(D);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000707
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000708 if (const NamedDecl *ND = dyn_cast<NamedDecl>(D)) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000709 ColorScope Color(*this, DeclNameColor);
David Blaikied4da8722013-05-14 21:04:00 +0000710 OS << " '" << ND->getDeclName() << '\'';
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000711 }
712
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000713 if (const ValueDecl *VD = dyn_cast<ValueDecl>(D))
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000714 dumpType(VD->getType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000715}
716
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000717void ASTDumper::dumpDeclRef(const Decl *D, const char *Label) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000718 if (!D)
719 return;
720
Richard Smithf7514452014-10-30 21:02:37 +0000721 dumpChild([=]{
722 if (Label)
723 OS << Label << ' ';
724 dumpBareDeclRef(D);
725 });
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000726}
727
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000728void ASTDumper::dumpName(const NamedDecl *ND) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000729 if (ND->getDeclName()) {
730 ColorScope Color(*this, DeclNameColor);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000731 OS << ' ' << ND->getNameAsString();
Richard Trieud215b8d2013-01-26 01:31:20 +0000732 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000733}
734
Richard Trieude5cc7d2013-01-31 01:44:26 +0000735bool ASTDumper::hasNodes(const DeclContext *DC) {
736 if (!DC)
737 return false;
738
Richard Smith1d209d02013-05-23 01:49:11 +0000739 return DC->hasExternalLexicalStorage() ||
740 DC->noload_decls_begin() != DC->noload_decls_end();
Richard Trieude5cc7d2013-01-31 01:44:26 +0000741}
742
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000743void ASTDumper::dumpDeclContext(const DeclContext *DC) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000744 if (!DC)
745 return;
Richard Smithdcc2c452014-03-17 23:00:06 +0000746
Richard Smithdcc2c452014-03-17 23:00:06 +0000747 for (auto *D : DC->noload_decls())
Richard Smithf7514452014-10-30 21:02:37 +0000748 dumpDecl(D);
Richard Smithdcc2c452014-03-17 23:00:06 +0000749
750 if (DC->hasExternalLexicalStorage()) {
Richard Smithf7514452014-10-30 21:02:37 +0000751 dumpChild([=]{
752 ColorScope Color(*this, UndeserializedColor);
753 OS << "<undeserialized declarations>";
754 });
Richard Smith1d209d02013-05-23 01:49:11 +0000755 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000756}
757
Richard Smith35f986d2014-08-11 22:11:07 +0000758void ASTDumper::dumpLookups(const DeclContext *DC, bool DumpDecls) {
Richard Smithf7514452014-10-30 21:02:37 +0000759 dumpChild([=] {
760 OS << "StoredDeclsMap ";
761 dumpBareDeclRef(cast<Decl>(DC));
Richard Smith33937e72013-06-22 21:49:40 +0000762
Richard Smithf7514452014-10-30 21:02:37 +0000763 const DeclContext *Primary = DC->getPrimaryContext();
764 if (Primary != DC) {
765 OS << " primary";
766 dumpPointer(cast<Decl>(Primary));
Richard Smith33937e72013-06-22 21:49:40 +0000767 }
768
Richard Smithf7514452014-10-30 21:02:37 +0000769 bool HasUndeserializedLookups = Primary->hasExternalVisibleStorage();
Richard Smith35f986d2014-08-11 22:11:07 +0000770
Richard Smithf7514452014-10-30 21:02:37 +0000771 DeclContext::all_lookups_iterator I = Primary->noload_lookups_begin(),
772 E = Primary->noload_lookups_end();
773 while (I != E) {
774 DeclarationName Name = I.getLookupName();
775 DeclContextLookupResult R = *I++;
Richard Smith35f986d2014-08-11 22:11:07 +0000776
Richard Smithf7514452014-10-30 21:02:37 +0000777 dumpChild([=] {
778 OS << "DeclarationName ";
779 {
780 ColorScope Color(*this, DeclNameColor);
781 OS << '\'' << Name << '\'';
782 }
Richard Smith35f986d2014-08-11 22:11:07 +0000783
Richard Smithf7514452014-10-30 21:02:37 +0000784 for (DeclContextLookupResult::iterator RI = R.begin(), RE = R.end();
785 RI != RE; ++RI) {
786 dumpChild([=] {
787 dumpBareDeclRef(*RI);
788
789 if ((*RI)->isHidden())
790 OS << " hidden";
791
792 // If requested, dump the redecl chain for this lookup.
793 if (DumpDecls) {
794 // Dump earliest decl first.
795 std::function<void(Decl *)> DumpWithPrev = [&](Decl *D) {
796 if (Decl *Prev = D->getPreviousDecl())
797 DumpWithPrev(Prev);
798 dumpDecl(D);
799 };
800 DumpWithPrev(*RI);
801 }
802 });
803 }
804 });
Richard Smith33937e72013-06-22 21:49:40 +0000805 }
Richard Smith33937e72013-06-22 21:49:40 +0000806
Richard Smithf7514452014-10-30 21:02:37 +0000807 if (HasUndeserializedLookups) {
808 dumpChild([=] {
809 ColorScope Color(*this, UndeserializedColor);
810 OS << "<undeserialized lookups>";
811 });
812 }
813 });
Richard Smith33937e72013-06-22 21:49:40 +0000814}
815
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000816void ASTDumper::dumpAttr(const Attr *A) {
Richard Smithf7514452014-10-30 21:02:37 +0000817 dumpChild([=] {
818 {
819 ColorScope Color(*this, AttrColor);
Aaron Ballman36a53502014-01-16 13:03:14 +0000820
Richard Smithf7514452014-10-30 21:02:37 +0000821 switch (A->getKind()) {
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000822#define ATTR(X) case attr::X: OS << #X; break;
823#include "clang/Basic/AttrList.inc"
Richard Smithf7514452014-10-30 21:02:37 +0000824 }
825 OS << "Attr";
Richard Trieud215b8d2013-01-26 01:31:20 +0000826 }
Richard Smithf7514452014-10-30 21:02:37 +0000827 dumpPointer(A);
828 dumpSourceRange(A->getRange());
829 if (A->isInherited())
830 OS << " Inherited";
831 if (A->isImplicit())
832 OS << " Implicit";
Hans Wennborgb0a8b4a2014-05-31 04:05:57 +0000833#include "clang/AST/AttrDump.inc"
Richard Smithf7514452014-10-30 21:02:37 +0000834 });
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000835}
836
Richard Smith71bec062013-10-15 21:58:30 +0000837static void dumpPreviousDeclImpl(raw_ostream &OS, ...) {}
838
839template<typename T>
840static void dumpPreviousDeclImpl(raw_ostream &OS, const Mergeable<T> *D) {
Rafael Espindola8db352d2013-10-17 15:37:26 +0000841 const T *First = D->getFirstDecl();
Richard Smith71bec062013-10-15 21:58:30 +0000842 if (First != D)
843 OS << " first " << First;
Richard Smithf5f43542013-02-07 01:35:44 +0000844}
845
846template<typename T>
Richard Smith71bec062013-10-15 21:58:30 +0000847static void dumpPreviousDeclImpl(raw_ostream &OS, const Redeclarable<T> *D) {
848 const T *Prev = D->getPreviousDecl();
849 if (Prev)
850 OS << " prev " << Prev;
Richard Smithf5f43542013-02-07 01:35:44 +0000851}
852
Richard Smith71bec062013-10-15 21:58:30 +0000853/// Dump the previous declaration in the redeclaration chain for a declaration,
854/// if any.
855static void dumpPreviousDecl(raw_ostream &OS, const Decl *D) {
Richard Smithf5f43542013-02-07 01:35:44 +0000856 switch (D->getKind()) {
857#define DECL(DERIVED, BASE) \
858 case Decl::DERIVED: \
Richard Smith71bec062013-10-15 21:58:30 +0000859 return dumpPreviousDeclImpl(OS, cast<DERIVED##Decl>(D));
Richard Smithf5f43542013-02-07 01:35:44 +0000860#define ABSTRACT_DECL(DECL)
861#include "clang/AST/DeclNodes.inc"
862 }
863 llvm_unreachable("Decl that isn't part of DeclNodes.inc!");
864}
865
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000866//===----------------------------------------------------------------------===//
867// C++ Utilities
868//===----------------------------------------------------------------------===//
869
870void ASTDumper::dumpAccessSpecifier(AccessSpecifier AS) {
871 switch (AS) {
872 case AS_none:
873 break;
874 case AS_public:
875 OS << "public";
876 break;
877 case AS_protected:
878 OS << "protected";
879 break;
880 case AS_private:
881 OS << "private";
882 break;
883 }
884}
885
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000886void ASTDumper::dumpCXXCtorInitializer(const CXXCtorInitializer *Init) {
Richard Smithf7514452014-10-30 21:02:37 +0000887 dumpChild([=] {
888 OS << "CXXCtorInitializer";
889 if (Init->isAnyMemberInitializer()) {
890 OS << ' ';
891 dumpBareDeclRef(Init->getAnyMember());
892 } else if (Init->isBaseInitializer()) {
893 dumpType(QualType(Init->getBaseClass(), 0));
894 } else if (Init->isDelegatingInitializer()) {
895 dumpType(Init->getTypeSourceInfo()->getType());
896 } else {
897 llvm_unreachable("Unknown initializer type");
898 }
899 dumpStmt(Init->getInit());
900 });
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000901}
902
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000903void ASTDumper::dumpTemplateParameters(const TemplateParameterList *TPL) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000904 if (!TPL)
905 return;
906
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000907 for (TemplateParameterList::const_iterator I = TPL->begin(), E = TPL->end();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000908 I != E; ++I)
909 dumpDecl(*I);
910}
911
912void ASTDumper::dumpTemplateArgumentListInfo(
913 const TemplateArgumentListInfo &TALI) {
Richard Smithf7514452014-10-30 21:02:37 +0000914 for (unsigned i = 0, e = TALI.size(); i < e; ++i)
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000915 dumpTemplateArgumentLoc(TALI[i]);
916}
917
918void ASTDumper::dumpTemplateArgumentLoc(const TemplateArgumentLoc &A) {
919 dumpTemplateArgument(A.getArgument(), A.getSourceRange());
920}
921
922void ASTDumper::dumpTemplateArgumentList(const TemplateArgumentList &TAL) {
923 for (unsigned i = 0, e = TAL.size(); i < e; ++i)
924 dumpTemplateArgument(TAL[i]);
925}
926
927void ASTDumper::dumpTemplateArgument(const TemplateArgument &A, SourceRange R) {
Richard Smithf7514452014-10-30 21:02:37 +0000928 dumpChild([=] {
929 OS << "TemplateArgument";
930 if (R.isValid())
931 dumpSourceRange(R);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000932
Richard Smithf7514452014-10-30 21:02:37 +0000933 switch (A.getKind()) {
934 case TemplateArgument::Null:
935 OS << " null";
936 break;
937 case TemplateArgument::Type:
938 OS << " type";
939 dumpType(A.getAsType());
940 break;
941 case TemplateArgument::Declaration:
942 OS << " decl";
943 dumpDeclRef(A.getAsDecl());
944 break;
945 case TemplateArgument::NullPtr:
946 OS << " nullptr";
947 break;
948 case TemplateArgument::Integral:
949 OS << " integral " << A.getAsIntegral();
950 break;
951 case TemplateArgument::Template:
952 OS << " template ";
953 A.getAsTemplate().dump(OS);
954 break;
955 case TemplateArgument::TemplateExpansion:
956 OS << " template expansion";
957 A.getAsTemplateOrTemplatePattern().dump(OS);
958 break;
959 case TemplateArgument::Expression:
960 OS << " expr";
961 dumpStmt(A.getAsExpr());
962 break;
963 case TemplateArgument::Pack:
964 OS << " pack";
965 for (TemplateArgument::pack_iterator I = A.pack_begin(), E = A.pack_end();
966 I != E; ++I)
967 dumpTemplateArgument(*I);
968 break;
Richard Trieude5cc7d2013-01-31 01:44:26 +0000969 }
Richard Smithf7514452014-10-30 21:02:37 +0000970 });
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000971}
972
Chris Lattner11e30d32007-08-30 06:17:34 +0000973//===----------------------------------------------------------------------===//
Douglas Gregor85f3f952015-07-07 03:57:15 +0000974// Objective-C Utilities
975//===----------------------------------------------------------------------===//
976void ASTDumper::dumpObjCTypeParamList(const ObjCTypeParamList *typeParams) {
977 if (!typeParams)
978 return;
979
980 for (auto typeParam : *typeParams) {
981 dumpDecl(typeParam);
982 }
983}
984
985//===----------------------------------------------------------------------===//
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000986// Decl dumping methods.
Chris Lattnercbe4f772007-08-08 22:51:59 +0000987//===----------------------------------------------------------------------===//
988
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000989void ASTDumper::dumpDecl(const Decl *D) {
Richard Smithf7514452014-10-30 21:02:37 +0000990 dumpChild([=] {
991 if (!D) {
992 ColorScope Color(*this, NullColor);
993 OS << "<<<NULL>>>";
994 return;
995 }
Mike Stump11289f42009-09-09 15:08:12 +0000996
Richard Smithf7514452014-10-30 21:02:37 +0000997 {
998 ColorScope Color(*this, DeclKindNameColor);
999 OS << D->getDeclKindName() << "Decl";
1000 }
1001 dumpPointer(D);
1002 if (D->getLexicalDeclContext() != D->getDeclContext())
1003 OS << " parent " << cast<Decl>(D->getDeclContext());
1004 dumpPreviousDecl(OS, D);
1005 dumpSourceRange(D->getSourceRange());
1006 OS << ' ';
1007 dumpLocation(D->getLocation());
Richard Smith42413142015-05-15 20:05:43 +00001008 if (Module *M = D->getImportedOwningModule())
Richard Smithf7514452014-10-30 21:02:37 +00001009 OS << " in " << M->getFullModuleName();
Richard Smith42413142015-05-15 20:05:43 +00001010 else if (Module *M = D->getLocalOwningModule())
1011 OS << " in (local) " << M->getFullModuleName();
Richard Smitha2eb4092015-06-22 18:47:01 +00001012 if (auto *ND = dyn_cast<NamedDecl>(D))
1013 for (Module *M : D->getASTContext().getModulesWithMergedDefinition(
1014 const_cast<NamedDecl *>(ND)))
1015 dumpChild([=] { OS << "also in " << M->getFullModuleName(); });
Richard Smithf7514452014-10-30 21:02:37 +00001016 if (const NamedDecl *ND = dyn_cast<NamedDecl>(D))
1017 if (ND->isHidden())
1018 OS << " hidden";
1019 if (D->isImplicit())
1020 OS << " implicit";
1021 if (D->isUsed())
1022 OS << " used";
1023 else if (D->isThisDeclarationReferenced())
1024 OS << " referenced";
1025 if (D->isInvalidDecl())
1026 OS << " invalid";
Hans Wennborg76b00532014-12-05 22:38:57 +00001027 if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
1028 if (FD->isConstexpr())
1029 OS << " constexpr";
1030
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001031
Richard Smithf7514452014-10-30 21:02:37 +00001032 ConstDeclVisitor<ASTDumper>::Visit(D);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001033
Richard Smithf7514452014-10-30 21:02:37 +00001034 for (Decl::attr_iterator I = D->attr_begin(), E = D->attr_end(); I != E;
1035 ++I)
1036 dumpAttr(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001037
Richard Smithf7514452014-10-30 21:02:37 +00001038 if (const FullComment *Comment =
1039 D->getASTContext().getLocalCommentForDeclUncached(D))
1040 dumpFullComment(Comment);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001041
Richard Smithf7514452014-10-30 21:02:37 +00001042 // Decls within functions are visited by the body.
1043 if (!isa<FunctionDecl>(*D) && !isa<ObjCMethodDecl>(*D) &&
1044 hasNodes(dyn_cast<DeclContext>(D)))
1045 dumpDeclContext(cast<DeclContext>(D));
1046 });
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001047}
1048
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001049void ASTDumper::VisitLabelDecl(const LabelDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001050 dumpName(D);
1051}
1052
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001053void ASTDumper::VisitTypedefDecl(const TypedefDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001054 dumpName(D);
1055 dumpType(D->getUnderlyingType());
1056 if (D->isModulePrivate())
1057 OS << " __module_private__";
Richard Smithba3a4f92016-01-12 21:59:26 +00001058 dumpTypeAsChild(D->getUnderlyingType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001059}
1060
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001061void ASTDumper::VisitEnumDecl(const EnumDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001062 if (D->isScoped()) {
1063 if (D->isScopedUsingClassTag())
1064 OS << " class";
1065 else
1066 OS << " struct";
1067 }
1068 dumpName(D);
1069 if (D->isModulePrivate())
1070 OS << " __module_private__";
1071 if (D->isFixed())
1072 dumpType(D->getIntegerType());
1073}
1074
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001075void ASTDumper::VisitRecordDecl(const RecordDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001076 OS << ' ' << D->getKindName();
1077 dumpName(D);
1078 if (D->isModulePrivate())
1079 OS << " __module_private__";
Richard Smith99bc1b92013-08-30 05:32:29 +00001080 if (D->isCompleteDefinition())
1081 OS << " definition";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001082}
1083
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001084void ASTDumper::VisitEnumConstantDecl(const EnumConstantDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001085 dumpName(D);
1086 dumpType(D->getType());
Richard Smithf7514452014-10-30 21:02:37 +00001087 if (const Expr *Init = D->getInitExpr())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001088 dumpStmt(Init);
1089}
1090
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001091void ASTDumper::VisitIndirectFieldDecl(const IndirectFieldDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001092 dumpName(D);
1093 dumpType(D->getType());
Richard Smithdcc2c452014-03-17 23:00:06 +00001094
Richard Smith8aa49222014-03-18 00:35:12 +00001095 for (auto *Child : D->chain())
Richard Smithf7514452014-10-30 21:02:37 +00001096 dumpDeclRef(Child);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001097}
1098
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001099void ASTDumper::VisitFunctionDecl(const FunctionDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001100 dumpName(D);
1101 dumpType(D->getType());
1102
Rafael Espindola6ae7e502013-04-03 19:27:57 +00001103 StorageClass SC = D->getStorageClass();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001104 if (SC != SC_None)
1105 OS << ' ' << VarDecl::getStorageClassSpecifierString(SC);
1106 if (D->isInlineSpecified())
1107 OS << " inline";
1108 if (D->isVirtualAsWritten())
1109 OS << " virtual";
1110 if (D->isModulePrivate())
1111 OS << " __module_private__";
1112
1113 if (D->isPure())
1114 OS << " pure";
1115 else if (D->isDeletedAsWritten())
1116 OS << " delete";
1117
Richard Smithadaa0152013-05-17 02:09:46 +00001118 if (const FunctionProtoType *FPT = D->getType()->getAs<FunctionProtoType>()) {
1119 FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo();
Richard Smith8acb4282014-07-31 21:57:55 +00001120 switch (EPI.ExceptionSpec.Type) {
Richard Smithadaa0152013-05-17 02:09:46 +00001121 default: break;
1122 case EST_Unevaluated:
Richard Smith8acb4282014-07-31 21:57:55 +00001123 OS << " noexcept-unevaluated " << EPI.ExceptionSpec.SourceDecl;
Richard Smithadaa0152013-05-17 02:09:46 +00001124 break;
1125 case EST_Uninstantiated:
Richard Smith8acb4282014-07-31 21:57:55 +00001126 OS << " noexcept-uninstantiated " << EPI.ExceptionSpec.SourceTemplate;
Richard Smithadaa0152013-05-17 02:09:46 +00001127 break;
1128 }
1129 }
1130
Richard Smithf7514452014-10-30 21:02:37 +00001131 if (const FunctionTemplateSpecializationInfo *FTSI =
1132 D->getTemplateSpecializationInfo())
Richard Trieude5cc7d2013-01-31 01:44:26 +00001133 dumpTemplateArgumentList(*FTSI->TemplateArguments);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001134
Dmitri Gribenkof8579502013-01-12 19:30:44 +00001135 for (ArrayRef<NamedDecl *>::iterator
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001136 I = D->getDeclsInPrototypeScope().begin(),
Richard Smithf7514452014-10-30 21:02:37 +00001137 E = D->getDeclsInPrototypeScope().end(); I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001138 dumpDecl(*I);
1139
Richard Smith8a639892015-01-24 01:07:20 +00001140 if (!D->param_begin() && D->getNumParams())
1141 dumpChild([=] { OS << "<<NULL params x " << D->getNumParams() << ">>"; });
1142 else
1143 for (FunctionDecl::param_const_iterator I = D->param_begin(),
1144 E = D->param_end();
1145 I != E; ++I)
1146 dumpDecl(*I);
Richard Smithf7514452014-10-30 21:02:37 +00001147
1148 if (const CXXConstructorDecl *C = dyn_cast<CXXConstructorDecl>(D))
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001149 for (CXXConstructorDecl::init_const_iterator I = C->init_begin(),
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001150 E = C->init_end();
Richard Smithf7514452014-10-30 21:02:37 +00001151 I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001152 dumpCXXCtorInitializer(*I);
1153
Richard Smithf7514452014-10-30 21:02:37 +00001154 if (D->doesThisDeclarationHaveABody())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001155 dumpStmt(D->getBody());
1156}
1157
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001158void ASTDumper::VisitFieldDecl(const FieldDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001159 dumpName(D);
1160 dumpType(D->getType());
1161 if (D->isMutable())
1162 OS << " mutable";
1163 if (D->isModulePrivate())
1164 OS << " __module_private__";
Richard Trieude5cc7d2013-01-31 01:44:26 +00001165
Richard Smithf7514452014-10-30 21:02:37 +00001166 if (D->isBitField())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001167 dumpStmt(D->getBitWidth());
Richard Smithf7514452014-10-30 21:02:37 +00001168 if (Expr *Init = D->getInClassInitializer())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001169 dumpStmt(Init);
1170}
1171
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001172void ASTDumper::VisitVarDecl(const VarDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001173 dumpName(D);
1174 dumpType(D->getType());
Rafael Espindola6ae7e502013-04-03 19:27:57 +00001175 StorageClass SC = D->getStorageClass();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001176 if (SC != SC_None)
1177 OS << ' ' << VarDecl::getStorageClassSpecifierString(SC);
Richard Smithfd3834f2013-04-13 02:43:54 +00001178 switch (D->getTLSKind()) {
1179 case VarDecl::TLS_None: break;
1180 case VarDecl::TLS_Static: OS << " tls"; break;
1181 case VarDecl::TLS_Dynamic: OS << " tls_dynamic"; break;
1182 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001183 if (D->isModulePrivate())
1184 OS << " __module_private__";
1185 if (D->isNRVOVariable())
1186 OS << " nrvo";
Richard Trieude5cc7d2013-01-31 01:44:26 +00001187 if (D->hasInit()) {
Richard Smithd9967cc2014-07-10 22:54:03 +00001188 switch (D->getInitStyle()) {
1189 case VarDecl::CInit: OS << " cinit"; break;
1190 case VarDecl::CallInit: OS << " callinit"; break;
1191 case VarDecl::ListInit: OS << " listinit"; break;
1192 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001193 dumpStmt(D->getInit());
Richard Trieude5cc7d2013-01-31 01:44:26 +00001194 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001195}
1196
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001197void ASTDumper::VisitFileScopeAsmDecl(const FileScopeAsmDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001198 dumpStmt(D->getAsmString());
1199}
1200
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001201void ASTDumper::VisitImportDecl(const ImportDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001202 OS << ' ' << D->getImportedModule()->getFullModuleName();
1203}
1204
Nico Weber66220292016-03-02 17:28:48 +00001205void ASTDumper::VisitPragmaCommentDecl(const PragmaCommentDecl *D) {
1206 OS << ' ';
1207 switch (D->getCommentKind()) {
1208 case PCK_Unknown: llvm_unreachable("unexpected pragma comment kind");
1209 case PCK_Compiler: OS << "compiler"; break;
1210 case PCK_ExeStr: OS << "exestr"; break;
1211 case PCK_Lib: OS << "lib"; break;
1212 case PCK_Linker: OS << "linker"; break;
1213 case PCK_User: OS << "user"; break;
1214 }
1215 StringRef Arg = D->getArg();
1216 if (!Arg.empty())
1217 OS << " \"" << Arg << "\"";
1218}
1219
Nico Webercbbaeb12016-03-02 19:28:54 +00001220void ASTDumper::VisitPragmaDetectMismatchDecl(
1221 const PragmaDetectMismatchDecl *D) {
1222 OS << " \"" << D->getName() << "\" \"" << D->getValue() << "\"";
1223}
1224
1225
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001226//===----------------------------------------------------------------------===//
1227// C++ Declarations
1228//===----------------------------------------------------------------------===//
1229
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001230void ASTDumper::VisitNamespaceDecl(const NamespaceDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001231 dumpName(D);
1232 if (D->isInline())
1233 OS << " inline";
1234 if (!D->isOriginalNamespace())
1235 dumpDeclRef(D->getOriginalNamespace(), "original");
1236}
1237
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001238void ASTDumper::VisitUsingDirectiveDecl(const UsingDirectiveDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001239 OS << ' ';
1240 dumpBareDeclRef(D->getNominatedNamespace());
1241}
1242
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001243void ASTDumper::VisitNamespaceAliasDecl(const NamespaceAliasDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001244 dumpName(D);
1245 dumpDeclRef(D->getAliasedNamespace());
1246}
1247
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001248void ASTDumper::VisitTypeAliasDecl(const TypeAliasDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001249 dumpName(D);
1250 dumpType(D->getUnderlyingType());
Richard Smithba3a4f92016-01-12 21:59:26 +00001251 dumpTypeAsChild(D->getUnderlyingType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001252}
1253
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001254void ASTDumper::VisitTypeAliasTemplateDecl(const TypeAliasTemplateDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001255 dumpName(D);
1256 dumpTemplateParameters(D->getTemplateParameters());
1257 dumpDecl(D->getTemplatedDecl());
1258}
1259
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001260void ASTDumper::VisitCXXRecordDecl(const CXXRecordDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001261 VisitRecordDecl(D);
1262 if (!D->isCompleteDefinition())
1263 return;
1264
Aaron Ballman574705e2014-03-13 15:41:46 +00001265 for (const auto &I : D->bases()) {
Richard Smithf7514452014-10-30 21:02:37 +00001266 dumpChild([=] {
1267 if (I.isVirtual())
1268 OS << "virtual ";
1269 dumpAccessSpecifier(I.getAccessSpecifier());
1270 dumpType(I.getType());
1271 if (I.isPackExpansion())
1272 OS << "...";
1273 });
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001274 }
1275}
1276
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001277void ASTDumper::VisitStaticAssertDecl(const StaticAssertDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001278 dumpStmt(D->getAssertExpr());
1279 dumpStmt(D->getMessage());
1280}
1281
Richard Smithcbdf7332014-03-18 02:07:28 +00001282template<typename SpecializationDecl>
Richard Smithf7514452014-10-30 21:02:37 +00001283void ASTDumper::VisitTemplateDeclSpecialization(const SpecializationDecl *D,
Richard Smithcbdf7332014-03-18 02:07:28 +00001284 bool DumpExplicitInst,
1285 bool DumpRefOnly) {
1286 bool DumpedAny = false;
1287 for (auto *RedeclWithBadType : D->redecls()) {
1288 // FIXME: The redecls() range sometimes has elements of a less-specific
1289 // type. (In particular, ClassTemplateSpecializationDecl::redecls() gives
1290 // us TagDecls, and should give CXXRecordDecls).
1291 auto *Redecl = dyn_cast<SpecializationDecl>(RedeclWithBadType);
1292 if (!Redecl) {
1293 // Found the injected-class-name for a class template. This will be dumped
1294 // as part of its surrounding class so we don't need to dump it here.
1295 assert(isa<CXXRecordDecl>(RedeclWithBadType) &&
1296 "expected an injected-class-name");
1297 continue;
1298 }
1299
1300 switch (Redecl->getTemplateSpecializationKind()) {
1301 case TSK_ExplicitInstantiationDeclaration:
1302 case TSK_ExplicitInstantiationDefinition:
1303 if (!DumpExplicitInst)
1304 break;
1305 // Fall through.
1306 case TSK_Undeclared:
1307 case TSK_ImplicitInstantiation:
Richard Smithf7514452014-10-30 21:02:37 +00001308 if (DumpRefOnly)
1309 dumpDeclRef(Redecl);
1310 else
1311 dumpDecl(Redecl);
Richard Smithcbdf7332014-03-18 02:07:28 +00001312 DumpedAny = true;
1313 break;
1314 case TSK_ExplicitSpecialization:
1315 break;
1316 }
1317 }
1318
1319 // Ensure we dump at least one decl for each specialization.
1320 if (!DumpedAny)
Richard Smithf7514452014-10-30 21:02:37 +00001321 dumpDeclRef(D);
Richard Smithcbdf7332014-03-18 02:07:28 +00001322}
1323
Richard Smith20ade552014-03-17 23:34:53 +00001324template<typename TemplateDecl>
1325void ASTDumper::VisitTemplateDecl(const TemplateDecl *D,
1326 bool DumpExplicitInst) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001327 dumpName(D);
1328 dumpTemplateParameters(D->getTemplateParameters());
Richard Smithdcc2c452014-03-17 23:00:06 +00001329
Richard Smithf7514452014-10-30 21:02:37 +00001330 dumpDecl(D->getTemplatedDecl());
Richard Smithdcc2c452014-03-17 23:00:06 +00001331
Richard Smithcbdf7332014-03-18 02:07:28 +00001332 for (auto *Child : D->specializations())
Richard Smithf7514452014-10-30 21:02:37 +00001333 VisitTemplateDeclSpecialization(Child, DumpExplicitInst,
Richard Smithcbdf7332014-03-18 02:07:28 +00001334 !D->isCanonicalDecl());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001335}
1336
Richard Smith20ade552014-03-17 23:34:53 +00001337void ASTDumper::VisitFunctionTemplateDecl(const FunctionTemplateDecl *D) {
1338 // FIXME: We don't add a declaration of a function template specialization
1339 // to its context when it's explicitly instantiated, so dump explicit
1340 // instantiations when we dump the template itself.
1341 VisitTemplateDecl(D, true);
1342}
1343
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001344void ASTDumper::VisitClassTemplateDecl(const ClassTemplateDecl *D) {
Richard Smith20ade552014-03-17 23:34:53 +00001345 VisitTemplateDecl(D, false);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001346}
1347
1348void ASTDumper::VisitClassTemplateSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001349 const ClassTemplateSpecializationDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001350 VisitCXXRecordDecl(D);
1351 dumpTemplateArgumentList(D->getTemplateArgs());
1352}
1353
1354void ASTDumper::VisitClassTemplatePartialSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001355 const ClassTemplatePartialSpecializationDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001356 VisitClassTemplateSpecializationDecl(D);
1357 dumpTemplateParameters(D->getTemplateParameters());
1358}
1359
1360void ASTDumper::VisitClassScopeFunctionSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001361 const ClassScopeFunctionSpecializationDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001362 dumpDeclRef(D->getSpecialization());
1363 if (D->hasExplicitTemplateArgs())
1364 dumpTemplateArgumentListInfo(D->templateArgs());
1365}
1366
Richard Smithd25789a2013-09-18 01:36:02 +00001367void ASTDumper::VisitVarTemplateDecl(const VarTemplateDecl *D) {
Richard Smith20ade552014-03-17 23:34:53 +00001368 VisitTemplateDecl(D, false);
Richard Smithd25789a2013-09-18 01:36:02 +00001369}
1370
David Majnemerd9b1a4f2015-11-04 03:40:30 +00001371void ASTDumper::VisitBuiltinTemplateDecl(const BuiltinTemplateDecl *D) {
1372 dumpName(D);
1373 dumpTemplateParameters(D->getTemplateParameters());
1374}
1375
Richard Smithd25789a2013-09-18 01:36:02 +00001376void ASTDumper::VisitVarTemplateSpecializationDecl(
1377 const VarTemplateSpecializationDecl *D) {
1378 dumpTemplateArgumentList(D->getTemplateArgs());
1379 VisitVarDecl(D);
1380}
1381
1382void ASTDumper::VisitVarTemplatePartialSpecializationDecl(
1383 const VarTemplatePartialSpecializationDecl *D) {
1384 dumpTemplateParameters(D->getTemplateParameters());
1385 VisitVarTemplateSpecializationDecl(D);
1386}
1387
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001388void ASTDumper::VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001389 if (D->wasDeclaredWithTypename())
1390 OS << " typename";
1391 else
1392 OS << " class";
1393 if (D->isParameterPack())
1394 OS << " ...";
1395 dumpName(D);
Richard Smithf7514452014-10-30 21:02:37 +00001396 if (D->hasDefaultArgument())
Richard Smithecf74ff2014-03-23 20:50:39 +00001397 dumpTemplateArgument(D->getDefaultArgument());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001398}
1399
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001400void ASTDumper::VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001401 dumpType(D->getType());
1402 if (D->isParameterPack())
1403 OS << " ...";
1404 dumpName(D);
Richard Smithf7514452014-10-30 21:02:37 +00001405 if (D->hasDefaultArgument())
Richard Smithecf74ff2014-03-23 20:50:39 +00001406 dumpTemplateArgument(D->getDefaultArgument());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001407}
1408
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001409void ASTDumper::VisitTemplateTemplateParmDecl(
1410 const TemplateTemplateParmDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001411 if (D->isParameterPack())
1412 OS << " ...";
1413 dumpName(D);
1414 dumpTemplateParameters(D->getTemplateParameters());
Richard Smithf7514452014-10-30 21:02:37 +00001415 if (D->hasDefaultArgument())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001416 dumpTemplateArgumentLoc(D->getDefaultArgument());
1417}
1418
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001419void ASTDumper::VisitUsingDecl(const UsingDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001420 OS << ' ';
Dawn Perchikddd03bf2015-12-05 22:37:55 +00001421 if (D->getQualifier())
1422 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001423 OS << D->getNameAsString();
1424}
1425
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001426void ASTDumper::VisitUnresolvedUsingTypenameDecl(
1427 const UnresolvedUsingTypenameDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001428 OS << ' ';
Dawn Perchikddd03bf2015-12-05 22:37:55 +00001429 if (D->getQualifier())
1430 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001431 OS << D->getNameAsString();
1432}
1433
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001434void ASTDumper::VisitUnresolvedUsingValueDecl(const UnresolvedUsingValueDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001435 OS << ' ';
Dawn Perchikddd03bf2015-12-05 22:37:55 +00001436 if (D->getQualifier())
1437 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001438 OS << D->getNameAsString();
1439 dumpType(D->getType());
1440}
1441
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001442void ASTDumper::VisitUsingShadowDecl(const UsingShadowDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001443 OS << ' ';
1444 dumpBareDeclRef(D->getTargetDecl());
Richard Smithba3a4f92016-01-12 21:59:26 +00001445 if (auto *TD = dyn_cast<TypeDecl>(D->getUnderlyingDecl()))
1446 dumpTypeAsChild(TD->getTypeForDecl());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001447}
1448
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001449void ASTDumper::VisitLinkageSpecDecl(const LinkageSpecDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001450 switch (D->getLanguage()) {
1451 case LinkageSpecDecl::lang_c: OS << " C"; break;
1452 case LinkageSpecDecl::lang_cxx: OS << " C++"; break;
1453 }
1454}
1455
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001456void ASTDumper::VisitAccessSpecDecl(const AccessSpecDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001457 OS << ' ';
1458 dumpAccessSpecifier(D->getAccess());
1459}
1460
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001461void ASTDumper::VisitFriendDecl(const FriendDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001462 if (TypeSourceInfo *T = D->getFriendType())
1463 dumpType(T->getType());
1464 else
1465 dumpDecl(D->getFriendDecl());
1466}
1467
1468//===----------------------------------------------------------------------===//
1469// Obj-C Declarations
1470//===----------------------------------------------------------------------===//
1471
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001472void ASTDumper::VisitObjCIvarDecl(const ObjCIvarDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001473 dumpName(D);
1474 dumpType(D->getType());
1475 if (D->getSynthesize())
1476 OS << " synthesize";
1477
1478 switch (D->getAccessControl()) {
1479 case ObjCIvarDecl::None:
1480 OS << " none";
1481 break;
1482 case ObjCIvarDecl::Private:
1483 OS << " private";
1484 break;
1485 case ObjCIvarDecl::Protected:
1486 OS << " protected";
1487 break;
1488 case ObjCIvarDecl::Public:
1489 OS << " public";
1490 break;
1491 case ObjCIvarDecl::Package:
1492 OS << " package";
1493 break;
1494 }
1495}
1496
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001497void ASTDumper::VisitObjCMethodDecl(const ObjCMethodDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001498 if (D->isInstanceMethod())
1499 OS << " -";
1500 else
1501 OS << " +";
1502 dumpName(D);
Alp Toker314cc812014-01-25 16:55:45 +00001503 dumpType(D->getReturnType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001504
Richard Trieude5cc7d2013-01-31 01:44:26 +00001505 if (D->isThisDeclarationADefinition()) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001506 dumpDeclContext(D);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001507 } else {
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001508 for (ObjCMethodDecl::param_const_iterator I = D->param_begin(),
1509 E = D->param_end();
Richard Smithf7514452014-10-30 21:02:37 +00001510 I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001511 dumpDecl(*I);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001512 }
1513
Richard Smithf7514452014-10-30 21:02:37 +00001514 if (D->isVariadic())
1515 dumpChild([=] { OS << "..."; });
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001516
Richard Smithf7514452014-10-30 21:02:37 +00001517 if (D->hasBody())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001518 dumpStmt(D->getBody());
1519}
1520
Douglas Gregor85f3f952015-07-07 03:57:15 +00001521void ASTDumper::VisitObjCTypeParamDecl(const ObjCTypeParamDecl *D) {
1522 dumpName(D);
Douglas Gregor1ac1b632015-07-07 03:58:54 +00001523 switch (D->getVariance()) {
1524 case ObjCTypeParamVariance::Invariant:
1525 break;
1526
1527 case ObjCTypeParamVariance::Covariant:
1528 OS << " covariant";
1529 break;
1530
1531 case ObjCTypeParamVariance::Contravariant:
1532 OS << " contravariant";
1533 break;
1534 }
1535
Douglas Gregor85f3f952015-07-07 03:57:15 +00001536 if (D->hasExplicitBound())
1537 OS << " bounded";
1538 dumpType(D->getUnderlyingType());
1539}
1540
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001541void ASTDumper::VisitObjCCategoryDecl(const ObjCCategoryDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001542 dumpName(D);
1543 dumpDeclRef(D->getClassInterface());
Douglas Gregor85f3f952015-07-07 03:57:15 +00001544 dumpObjCTypeParamList(D->getTypeParamList());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001545 dumpDeclRef(D->getImplementation());
1546 for (ObjCCategoryDecl::protocol_iterator I = D->protocol_begin(),
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001547 E = D->protocol_end();
Richard Smithf7514452014-10-30 21:02:37 +00001548 I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001549 dumpDeclRef(*I);
1550}
1551
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001552void ASTDumper::VisitObjCCategoryImplDecl(const ObjCCategoryImplDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001553 dumpName(D);
1554 dumpDeclRef(D->getClassInterface());
1555 dumpDeclRef(D->getCategoryDecl());
1556}
1557
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001558void ASTDumper::VisitObjCProtocolDecl(const ObjCProtocolDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001559 dumpName(D);
Richard Smithdcc2c452014-03-17 23:00:06 +00001560
Richard Smith7fcb35f2014-03-18 02:37:59 +00001561 for (auto *Child : D->protocols())
Richard Smithf7514452014-10-30 21:02:37 +00001562 dumpDeclRef(Child);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001563}
1564
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001565void ASTDumper::VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001566 dumpName(D);
Douglas Gregor85f3f952015-07-07 03:57:15 +00001567 dumpObjCTypeParamList(D->getTypeParamListAsWritten());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001568 dumpDeclRef(D->getSuperClass(), "super");
Richard Smithdcc2c452014-03-17 23:00:06 +00001569
Richard Smithf7514452014-10-30 21:02:37 +00001570 dumpDeclRef(D->getImplementation());
Richard Smith7fcb35f2014-03-18 02:37:59 +00001571 for (auto *Child : D->protocols())
Richard Smithf7514452014-10-30 21:02:37 +00001572 dumpDeclRef(Child);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001573}
1574
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001575void ASTDumper::VisitObjCImplementationDecl(const ObjCImplementationDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001576 dumpName(D);
1577 dumpDeclRef(D->getSuperClass(), "super");
1578 dumpDeclRef(D->getClassInterface());
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001579 for (ObjCImplementationDecl::init_const_iterator I = D->init_begin(),
1580 E = D->init_end();
Richard Smithf7514452014-10-30 21:02:37 +00001581 I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001582 dumpCXXCtorInitializer(*I);
1583}
1584
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001585void ASTDumper::VisitObjCCompatibleAliasDecl(const ObjCCompatibleAliasDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001586 dumpName(D);
1587 dumpDeclRef(D->getClassInterface());
1588}
1589
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001590void ASTDumper::VisitObjCPropertyDecl(const ObjCPropertyDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001591 dumpName(D);
1592 dumpType(D->getType());
1593
1594 if (D->getPropertyImplementation() == ObjCPropertyDecl::Required)
1595 OS << " required";
1596 else if (D->getPropertyImplementation() == ObjCPropertyDecl::Optional)
1597 OS << " optional";
1598
1599 ObjCPropertyDecl::PropertyAttributeKind Attrs = D->getPropertyAttributes();
1600 if (Attrs != ObjCPropertyDecl::OBJC_PR_noattr) {
1601 if (Attrs & ObjCPropertyDecl::OBJC_PR_readonly)
1602 OS << " readonly";
1603 if (Attrs & ObjCPropertyDecl::OBJC_PR_assign)
1604 OS << " assign";
1605 if (Attrs & ObjCPropertyDecl::OBJC_PR_readwrite)
1606 OS << " readwrite";
1607 if (Attrs & ObjCPropertyDecl::OBJC_PR_retain)
1608 OS << " retain";
1609 if (Attrs & ObjCPropertyDecl::OBJC_PR_copy)
1610 OS << " copy";
1611 if (Attrs & ObjCPropertyDecl::OBJC_PR_nonatomic)
1612 OS << " nonatomic";
1613 if (Attrs & ObjCPropertyDecl::OBJC_PR_atomic)
1614 OS << " atomic";
1615 if (Attrs & ObjCPropertyDecl::OBJC_PR_weak)
1616 OS << " weak";
1617 if (Attrs & ObjCPropertyDecl::OBJC_PR_strong)
1618 OS << " strong";
1619 if (Attrs & ObjCPropertyDecl::OBJC_PR_unsafe_unretained)
1620 OS << " unsafe_unretained";
Manman Ren387ff7f2016-01-26 18:52:43 +00001621 if (Attrs & ObjCPropertyDecl::OBJC_PR_class)
1622 OS << " class";
Richard Smithf7514452014-10-30 21:02:37 +00001623 if (Attrs & ObjCPropertyDecl::OBJC_PR_getter)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001624 dumpDeclRef(D->getGetterMethodDecl(), "getter");
Richard Smithf7514452014-10-30 21:02:37 +00001625 if (Attrs & ObjCPropertyDecl::OBJC_PR_setter)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001626 dumpDeclRef(D->getSetterMethodDecl(), "setter");
1627 }
1628}
1629
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001630void ASTDumper::VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001631 dumpName(D->getPropertyDecl());
1632 if (D->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize)
1633 OS << " synthesize";
1634 else
1635 OS << " dynamic";
1636 dumpDeclRef(D->getPropertyDecl());
1637 dumpDeclRef(D->getPropertyIvarDecl());
1638}
1639
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001640void ASTDumper::VisitBlockDecl(const BlockDecl *D) {
Aaron Ballmanb2b8b1d2014-03-07 16:09:59 +00001641 for (auto I : D->params())
1642 dumpDecl(I);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001643
Richard Smithf7514452014-10-30 21:02:37 +00001644 if (D->isVariadic())
1645 dumpChild([=]{ OS << "..."; });
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001646
Richard Smithf7514452014-10-30 21:02:37 +00001647 if (D->capturesCXXThis())
1648 dumpChild([=]{ OS << "capture this"; });
1649
Aaron Ballman9371dd22014-03-14 18:34:04 +00001650 for (const auto &I : D->captures()) {
Richard Smithf7514452014-10-30 21:02:37 +00001651 dumpChild([=] {
1652 OS << "capture";
1653 if (I.isByRef())
1654 OS << " byref";
1655 if (I.isNested())
1656 OS << " nested";
1657 if (I.getVariable()) {
1658 OS << ' ';
1659 dumpBareDeclRef(I.getVariable());
1660 }
1661 if (I.hasCopyExpr())
1662 dumpStmt(I.getCopyExpr());
1663 });
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001664 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001665 dumpStmt(D->getBody());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001666}
1667
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001668//===----------------------------------------------------------------------===//
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001669// Stmt dumping methods.
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001670//===----------------------------------------------------------------------===//
1671
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001672void ASTDumper::dumpStmt(const Stmt *S) {
Richard Smithf7514452014-10-30 21:02:37 +00001673 dumpChild([=] {
1674 if (!S) {
1675 ColorScope Color(*this, NullColor);
1676 OS << "<<<NULL>>>";
1677 return;
1678 }
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001679
Richard Smithf7514452014-10-30 21:02:37 +00001680 if (const DeclStmt *DS = dyn_cast<DeclStmt>(S)) {
1681 VisitDeclStmt(DS);
1682 return;
1683 }
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001684
Richard Smithf7514452014-10-30 21:02:37 +00001685 ConstStmtVisitor<ASTDumper>::Visit(S);
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001686
Benjamin Kramer642f1732015-07-02 21:03:14 +00001687 for (const Stmt *SubStmt : S->children())
1688 dumpStmt(SubStmt);
Richard Smithf7514452014-10-30 21:02:37 +00001689 });
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001690}
1691
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001692void ASTDumper::VisitStmt(const Stmt *Node) {
Richard Trieud215b8d2013-01-26 01:31:20 +00001693 {
1694 ColorScope Color(*this, StmtColor);
1695 OS << Node->getStmtClassName();
1696 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001697 dumpPointer(Node);
1698 dumpSourceRange(Node->getSourceRange());
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001699}
1700
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001701void ASTDumper::VisitDeclStmt(const DeclStmt *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001702 VisitStmt(Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001703 for (DeclStmt::const_decl_iterator I = Node->decl_begin(),
1704 E = Node->decl_end();
Richard Smithf7514452014-10-30 21:02:37 +00001705 I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001706 dumpDecl(*I);
Ted Kremenek433a4922007-12-12 06:59:42 +00001707}
1708
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001709void ASTDumper::VisitAttributedStmt(const AttributedStmt *Node) {
Alexander Kornienko5bc364e2013-01-07 17:53:08 +00001710 VisitStmt(Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001711 for (ArrayRef<const Attr *>::iterator I = Node->getAttrs().begin(),
1712 E = Node->getAttrs().end();
Richard Smithf7514452014-10-30 21:02:37 +00001713 I != E; ++I)
Alexander Kornienko5bc364e2013-01-07 17:53:08 +00001714 dumpAttr(*I);
1715}
1716
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001717void ASTDumper::VisitLabelStmt(const LabelStmt *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001718 VisitStmt(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001719 OS << " '" << Node->getName() << "'";
Chris Lattnercbe4f772007-08-08 22:51:59 +00001720}
1721
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001722void ASTDumper::VisitGotoStmt(const GotoStmt *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001723 VisitStmt(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001724 OS << " '" << Node->getLabel()->getName() << "'";
1725 dumpPointer(Node->getLabel());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001726}
1727
Pavel Labath1ef83422013-09-04 14:35:00 +00001728void ASTDumper::VisitCXXCatchStmt(const CXXCatchStmt *Node) {
1729 VisitStmt(Node);
1730 dumpDecl(Node->getExceptionDecl());
1731}
1732
Chris Lattnercbe4f772007-08-08 22:51:59 +00001733//===----------------------------------------------------------------------===//
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001734// Expr dumping methods.
Chris Lattnercbe4f772007-08-08 22:51:59 +00001735//===----------------------------------------------------------------------===//
1736
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001737void ASTDumper::VisitExpr(const Expr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001738 VisitStmt(Node);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001739 dumpType(Node->getType());
1740
Richard Trieud215b8d2013-01-26 01:31:20 +00001741 {
1742 ColorScope Color(*this, ValueKindColor);
1743 switch (Node->getValueKind()) {
1744 case VK_RValue:
1745 break;
1746 case VK_LValue:
1747 OS << " lvalue";
1748 break;
1749 case VK_XValue:
1750 OS << " xvalue";
1751 break;
1752 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001753 }
1754
Richard Trieud215b8d2013-01-26 01:31:20 +00001755 {
1756 ColorScope Color(*this, ObjectKindColor);
1757 switch (Node->getObjectKind()) {
1758 case OK_Ordinary:
1759 break;
1760 case OK_BitField:
1761 OS << " bitfield";
1762 break;
1763 case OK_ObjCProperty:
1764 OS << " objcproperty";
1765 break;
1766 case OK_ObjCSubscript:
1767 OS << " objcsubscript";
1768 break;
1769 case OK_VectorComponent:
1770 OS << " vectorcomponent";
1771 break;
1772 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001773 }
Chris Lattnercbe4f772007-08-08 22:51:59 +00001774}
1775
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001776static void dumpBasePath(raw_ostream &OS, const CastExpr *Node) {
John McCallcf142162010-08-07 06:22:56 +00001777 if (Node->path_empty())
Anders Carlssona70cff62010-04-24 19:06:50 +00001778 return;
1779
1780 OS << " (";
1781 bool First = true;
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001782 for (CastExpr::path_const_iterator I = Node->path_begin(),
1783 E = Node->path_end();
1784 I != E; ++I) {
Anders Carlssona70cff62010-04-24 19:06:50 +00001785 const CXXBaseSpecifier *Base = *I;
1786 if (!First)
1787 OS << " -> ";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001788
Anders Carlssona70cff62010-04-24 19:06:50 +00001789 const CXXRecordDecl *RD =
1790 cast<CXXRecordDecl>(Base->getType()->getAs<RecordType>()->getDecl());
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001791
Anders Carlssona70cff62010-04-24 19:06:50 +00001792 if (Base->isVirtual())
1793 OS << "virtual ";
1794 OS << RD->getName();
1795 First = false;
1796 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001797
Anders Carlssona70cff62010-04-24 19:06:50 +00001798 OS << ')';
1799}
1800
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001801void ASTDumper::VisitCastExpr(const CastExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001802 VisitExpr(Node);
Richard Trieud215b8d2013-01-26 01:31:20 +00001803 OS << " <";
1804 {
1805 ColorScope Color(*this, CastColor);
1806 OS << Node->getCastKindName();
1807 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001808 dumpBasePath(OS, Node);
Anders Carlssona70cff62010-04-24 19:06:50 +00001809 OS << ">";
Anders Carlssond7923c62009-08-22 23:33:40 +00001810}
1811
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001812void ASTDumper::VisitDeclRefExpr(const DeclRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001813 VisitExpr(Node);
Ted Kremenek5f64ca82007-09-10 17:32:55 +00001814
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001815 OS << " ";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001816 dumpBareDeclRef(Node->getDecl());
Chandler Carruth8d26bb02011-05-01 23:48:14 +00001817 if (Node->getDecl() != Node->getFoundDecl()) {
1818 OS << " (";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001819 dumpBareDeclRef(Node->getFoundDecl());
Chandler Carruth8d26bb02011-05-01 23:48:14 +00001820 OS << ")";
1821 }
John McCall351762c2011-02-07 10:33:21 +00001822}
1823
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001824void ASTDumper::VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001825 VisitExpr(Node);
John McCall76d09942009-12-11 21:50:11 +00001826 OS << " (";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001827 if (!Node->requiresADL())
1828 OS << "no ";
Benjamin Kramerb11416d2010-04-17 09:33:03 +00001829 OS << "ADL) = '" << Node->getName() << '\'';
John McCall76d09942009-12-11 21:50:11 +00001830
1831 UnresolvedLookupExpr::decls_iterator
1832 I = Node->decls_begin(), E = Node->decls_end();
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001833 if (I == E)
1834 OS << " empty";
John McCall76d09942009-12-11 21:50:11 +00001835 for (; I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001836 dumpPointer(*I);
John McCall76d09942009-12-11 21:50:11 +00001837}
1838
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001839void ASTDumper::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001840 VisitExpr(Node);
Steve Naroff5d5efca2008-03-12 13:19:12 +00001841
Richard Trieud215b8d2013-01-26 01:31:20 +00001842 {
1843 ColorScope Color(*this, DeclKindNameColor);
1844 OS << " " << Node->getDecl()->getDeclKindName() << "Decl";
1845 }
1846 OS << "='" << *Node->getDecl() << "'";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001847 dumpPointer(Node->getDecl());
Steve Naroffb3424a92008-05-23 22:01:24 +00001848 if (Node->isFreeIvar())
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001849 OS << " isFreeIvar";
Steve Naroff5d5efca2008-03-12 13:19:12 +00001850}
1851
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001852void ASTDumper::VisitPredefinedExpr(const PredefinedExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001853 VisitExpr(Node);
Alexey Bataevec474782014-10-09 08:45:04 +00001854 OS << " " << PredefinedExpr::getIdentTypeName(Node->getIdentType());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001855}
1856
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001857void ASTDumper::VisitCharacterLiteral(const CharacterLiteral *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001858 VisitExpr(Node);
Richard Trieud215b8d2013-01-26 01:31:20 +00001859 ColorScope Color(*this, ValueColor);
Richard Trieu364ee422011-11-03 23:56:23 +00001860 OS << " " << Node->getValue();
Chris Lattnercbe4f772007-08-08 22:51:59 +00001861}
1862
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001863void ASTDumper::VisitIntegerLiteral(const IntegerLiteral *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001864 VisitExpr(Node);
Chris Lattnercbe4f772007-08-08 22:51:59 +00001865
1866 bool isSigned = Node->getType()->isSignedIntegerType();
Richard Trieud215b8d2013-01-26 01:31:20 +00001867 ColorScope Color(*this, ValueColor);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001868 OS << " " << Node->getValue().toString(10, isSigned);
Chris Lattnercbe4f772007-08-08 22:51:59 +00001869}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001870
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001871void ASTDumper::VisitFloatingLiteral(const FloatingLiteral *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001872 VisitExpr(Node);
Richard Trieud215b8d2013-01-26 01:31:20 +00001873 ColorScope Color(*this, ValueColor);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001874 OS << " " << Node->getValueAsApproximateDouble();
Chris Lattnercbe4f772007-08-08 22:51:59 +00001875}
Chris Lattner1c20a172007-08-26 03:42:43 +00001876
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001877void ASTDumper::VisitStringLiteral(const StringLiteral *Str) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001878 VisitExpr(Str);
Richard Trieud215b8d2013-01-26 01:31:20 +00001879 ColorScope Color(*this, ValueColor);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001880 OS << " ";
Richard Trieudc355912012-06-13 20:25:24 +00001881 Str->outputString(OS);
Chris Lattnercbe4f772007-08-08 22:51:59 +00001882}
Chris Lattner84ca3762007-08-30 01:00:35 +00001883
Richard Smithf0514962014-06-03 08:24:28 +00001884void ASTDumper::VisitInitListExpr(const InitListExpr *ILE) {
1885 VisitExpr(ILE);
1886 if (auto *Filler = ILE->getArrayFiller()) {
Richard Smithf7514452014-10-30 21:02:37 +00001887 dumpChild([=] {
1888 OS << "array filler";
1889 dumpStmt(Filler);
1890 });
Richard Smithf0514962014-06-03 08:24:28 +00001891 }
1892 if (auto *Field = ILE->getInitializedFieldInUnion()) {
1893 OS << " field ";
1894 dumpBareDeclRef(Field);
1895 }
1896}
1897
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001898void ASTDumper::VisitUnaryOperator(const UnaryOperator *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001899 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001900 OS << " " << (Node->isPostfix() ? "postfix" : "prefix")
1901 << " '" << UnaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
Chris Lattnercbe4f772007-08-08 22:51:59 +00001902}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001903
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001904void ASTDumper::VisitUnaryExprOrTypeTraitExpr(
1905 const UnaryExprOrTypeTraitExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001906 VisitExpr(Node);
Peter Collingbournee190dee2011-03-11 19:24:49 +00001907 switch(Node->getKind()) {
1908 case UETT_SizeOf:
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001909 OS << " sizeof";
Peter Collingbournee190dee2011-03-11 19:24:49 +00001910 break;
1911 case UETT_AlignOf:
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001912 OS << " alignof";
Peter Collingbournee190dee2011-03-11 19:24:49 +00001913 break;
1914 case UETT_VecStep:
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001915 OS << " vec_step";
Peter Collingbournee190dee2011-03-11 19:24:49 +00001916 break;
Alexey Bataev00396512015-07-02 03:40:19 +00001917 case UETT_OpenMPRequiredSimdAlign:
1918 OS << " __builtin_omp_required_simd_align";
1919 break;
Peter Collingbournee190dee2011-03-11 19:24:49 +00001920 }
Sebastian Redl6f282892008-11-11 17:56:53 +00001921 if (Node->isArgumentType())
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001922 dumpType(Node->getArgumentType());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001923}
Chris Lattnerdb3b3ff2007-08-09 17:35:30 +00001924
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001925void ASTDumper::VisitMemberExpr(const MemberExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001926 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001927 OS << " " << (Node->isArrow() ? "->" : ".") << *Node->getMemberDecl();
1928 dumpPointer(Node->getMemberDecl());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001929}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001930
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001931void ASTDumper::VisitExtVectorElementExpr(const ExtVectorElementExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001932 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001933 OS << " " << Node->getAccessor().getNameStart();
Chris Lattnercbe4f772007-08-08 22:51:59 +00001934}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001935
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001936void ASTDumper::VisitBinaryOperator(const BinaryOperator *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001937 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001938 OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
Chris Lattner86928112007-08-25 02:00:02 +00001939}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001940
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001941void ASTDumper::VisitCompoundAssignOperator(
1942 const CompoundAssignOperator *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001943 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001944 OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode())
1945 << "' ComputeLHSTy=";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001946 dumpBareType(Node->getComputationLHSType());
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001947 OS << " ComputeResultTy=";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001948 dumpBareType(Node->getComputationResultType());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001949}
Chris Lattnercbe4f772007-08-08 22:51:59 +00001950
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001951void ASTDumper::VisitBlockExpr(const BlockExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001952 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001953 dumpDecl(Node->getBlockDecl());
John McCall351762c2011-02-07 10:33:21 +00001954}
1955
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001956void ASTDumper::VisitOpaqueValueExpr(const OpaqueValueExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001957 VisitExpr(Node);
John McCallfe96e0b2011-11-06 09:01:30 +00001958
Richard Smithf7514452014-10-30 21:02:37 +00001959 if (Expr *Source = Node->getSourceExpr())
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001960 dumpStmt(Source);
John McCallfe96e0b2011-11-06 09:01:30 +00001961}
1962
Chris Lattnercbe4f772007-08-08 22:51:59 +00001963// GNU extensions.
1964
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001965void ASTDumper::VisitAddrLabelExpr(const AddrLabelExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001966 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001967 OS << " " << Node->getLabel()->getName();
1968 dumpPointer(Node->getLabel());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001969}
1970
Chris Lattner8f184b12007-08-09 18:03:18 +00001971//===----------------------------------------------------------------------===//
1972// C++ Expressions
1973//===----------------------------------------------------------------------===//
Chris Lattnercbe4f772007-08-08 22:51:59 +00001974
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001975void ASTDumper::VisitCXXNamedCastExpr(const CXXNamedCastExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001976 VisitExpr(Node);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001977 OS << " " << Node->getCastName()
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001978 << "<" << Node->getTypeAsWritten().getAsString() << ">"
Anders Carlssona70cff62010-04-24 19:06:50 +00001979 << " <" << Node->getCastKindName();
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001980 dumpBasePath(OS, Node);
Anders Carlssona70cff62010-04-24 19:06:50 +00001981 OS << ">";
Chris Lattnercbe4f772007-08-08 22:51:59 +00001982}
1983
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001984void ASTDumper::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001985 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001986 OS << " " << (Node->getValue() ? "true" : "false");
Chris Lattnercbe4f772007-08-08 22:51:59 +00001987}
1988
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001989void ASTDumper::VisitCXXThisExpr(const CXXThisExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001990 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001991 OS << " this";
Douglas Gregor8ea1f532008-11-04 14:56:14 +00001992}
1993
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001994void ASTDumper::VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001995 VisitExpr(Node);
Eli Friedman29538892011-09-02 17:38:59 +00001996 OS << " functional cast to " << Node->getTypeAsWritten().getAsString()
1997 << " <" << Node->getCastKindName() << ">";
Douglas Gregore200adc2008-10-27 19:41:14 +00001998}
1999
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002000void ASTDumper::VisitCXXConstructExpr(const CXXConstructExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002001 VisitExpr(Node);
John McCalleba90cd2010-02-02 19:03:45 +00002002 CXXConstructorDecl *Ctor = Node->getConstructor();
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002003 dumpType(Ctor->getType());
Anders Carlsson073846832009-08-12 00:21:52 +00002004 if (Node->isElidable())
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002005 OS << " elidable";
John McCall85370042010-08-07 06:38:55 +00002006 if (Node->requiresZeroInitialization())
2007 OS << " zeroing";
Anders Carlsson073846832009-08-12 00:21:52 +00002008}
2009
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002010void ASTDumper::VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002011 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002012 OS << " ";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002013 dumpCXXTemporary(Node->getTemporary());
Anders Carlsson073846832009-08-12 00:21:52 +00002014}
2015
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002016void ASTDumper::VisitCXXNewExpr(const CXXNewExpr *Node) {
2017 VisitExpr(Node);
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002018 if (Node->isGlobalNew())
Reid Kleckner461c0c62015-03-19 18:47:47 +00002019 OS << " global";
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002020 if (Node->isArray())
Reid Kleckner461c0c62015-03-19 18:47:47 +00002021 OS << " array";
2022 if (Node->getOperatorNew()) {
2023 OS << ' ';
2024 dumpBareDeclRef(Node->getOperatorNew());
2025 }
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002026 // We could dump the deallocation function used in case of error, but it's
2027 // usually not that interesting.
2028}
2029
2030void ASTDumper::VisitCXXDeleteExpr(const CXXDeleteExpr *Node) {
2031 VisitExpr(Node);
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002032 if (Node->isGlobalDelete())
Reid Kleckner461c0c62015-03-19 18:47:47 +00002033 OS << " global";
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002034 if (Node->isArrayForm())
Reid Kleckner461c0c62015-03-19 18:47:47 +00002035 OS << " array";
2036 if (Node->getOperatorDelete()) {
2037 OS << ' ';
2038 dumpBareDeclRef(Node->getOperatorDelete());
2039 }
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002040}
2041
Richard Smithe6c01442013-06-05 00:46:14 +00002042void
2043ASTDumper::VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *Node) {
2044 VisitExpr(Node);
2045 if (const ValueDecl *VD = Node->getExtendingDecl()) {
2046 OS << " extended by ";
2047 dumpBareDeclRef(VD);
2048 }
2049}
2050
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002051void ASTDumper::VisitExprWithCleanups(const ExprWithCleanups *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002052 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002053 for (unsigned i = 0, e = Node->getNumObjects(); i != e; ++i)
2054 dumpDeclRef(Node->getObject(i), "cleanup");
Anders Carlsson073846832009-08-12 00:21:52 +00002055}
2056
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002057void ASTDumper::dumpCXXTemporary(const CXXTemporary *Temporary) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002058 OS << "(CXXTemporary";
2059 dumpPointer(Temporary);
2060 OS << ")";
Anders Carlsson073846832009-08-12 00:21:52 +00002061}
2062
Serge Pavlov6b926032015-02-16 19:58:41 +00002063void ASTDumper::VisitSizeOfPackExpr(const SizeOfPackExpr *Node) {
2064 VisitExpr(Node);
2065 dumpPointer(Node->getPack());
2066 dumpName(Node->getPack());
Richard Smithd784e682015-09-23 21:41:42 +00002067 if (Node->isPartiallySubstituted())
2068 for (const auto &A : Node->getPartialArguments())
2069 dumpTemplateArgument(A);
Serge Pavlov6b926032015-02-16 19:58:41 +00002070}
2071
2072
Anders Carlsson76f4a902007-08-21 17:43:55 +00002073//===----------------------------------------------------------------------===//
2074// Obj-C Expressions
2075//===----------------------------------------------------------------------===//
2076
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002077void ASTDumper::VisitObjCMessageExpr(const ObjCMessageExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002078 VisitExpr(Node);
Aaron Ballmanb190f972014-01-03 17:59:55 +00002079 OS << " selector=";
2080 Node->getSelector().print(OS);
Douglas Gregor9a129192010-04-21 00:45:42 +00002081 switch (Node->getReceiverKind()) {
2082 case ObjCMessageExpr::Instance:
2083 break;
2084
2085 case ObjCMessageExpr::Class:
2086 OS << " class=";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002087 dumpBareType(Node->getClassReceiver());
Douglas Gregor9a129192010-04-21 00:45:42 +00002088 break;
2089
2090 case ObjCMessageExpr::SuperInstance:
2091 OS << " super (instance)";
2092 break;
2093
2094 case ObjCMessageExpr::SuperClass:
2095 OS << " super (class)";
2096 break;
2097 }
Ted Kremenek36748da2008-02-29 22:04:05 +00002098}
2099
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002100void ASTDumper::VisitObjCBoxedExpr(const ObjCBoxedExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002101 VisitExpr(Node);
Aaron Ballmanb190f972014-01-03 17:59:55 +00002102 OS << " selector=";
2103 Node->getBoxingMethod()->getSelector().print(OS);
Argyrios Kyrtzidis9dd40892012-05-10 20:02:31 +00002104}
2105
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002106void ASTDumper::VisitObjCAtCatchStmt(const ObjCAtCatchStmt *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002107 VisitStmt(Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002108 if (const VarDecl *CatchParam = Node->getCatchParamDecl())
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002109 dumpDecl(CatchParam);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002110 else
Douglas Gregor96c79492010-04-23 22:50:49 +00002111 OS << " catch all";
Douglas Gregor96c79492010-04-23 22:50:49 +00002112}
2113
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002114void ASTDumper::VisitObjCEncodeExpr(const ObjCEncodeExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002115 VisitExpr(Node);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002116 dumpType(Node->getEncodedType());
Anders Carlssonc5a81eb2007-08-22 15:14:15 +00002117}
2118
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002119void ASTDumper::VisitObjCSelectorExpr(const ObjCSelectorExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002120 VisitExpr(Node);
Mike Stump11289f42009-09-09 15:08:12 +00002121
Aaron Ballmanb190f972014-01-03 17:59:55 +00002122 OS << " ";
2123 Node->getSelector().print(OS);
Fariborz Jahanian4bef4622007-10-16 20:40:23 +00002124}
2125
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002126void ASTDumper::VisitObjCProtocolExpr(const ObjCProtocolExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002127 VisitExpr(Node);
Mike Stump11289f42009-09-09 15:08:12 +00002128
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002129 OS << ' ' << *Node->getProtocol();
Fariborz Jahaniana32aaef2007-10-17 16:58:11 +00002130}
Daniel Dunbar4b8c6db2008-08-30 05:35:15 +00002131
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002132void ASTDumper::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002133 VisitExpr(Node);
John McCallb7bd14f2010-12-02 01:19:52 +00002134 if (Node->isImplicitProperty()) {
Fariborz Jahanian0f0b3022010-12-22 19:46:35 +00002135 OS << " Kind=MethodRef Getter=\"";
2136 if (Node->getImplicitPropertyGetter())
Aaron Ballmanb190f972014-01-03 17:59:55 +00002137 Node->getImplicitPropertyGetter()->getSelector().print(OS);
Fariborz Jahanian0f0b3022010-12-22 19:46:35 +00002138 else
2139 OS << "(null)";
2140
2141 OS << "\" Setter=\"";
John McCallb7bd14f2010-12-02 01:19:52 +00002142 if (ObjCMethodDecl *Setter = Node->getImplicitPropertySetter())
Aaron Ballmanb190f972014-01-03 17:59:55 +00002143 Setter->getSelector().print(OS);
John McCallb7bd14f2010-12-02 01:19:52 +00002144 else
2145 OS << "(null)";
2146 OS << "\"";
2147 } else {
Benjamin Kramerb89514a2011-10-14 18:45:37 +00002148 OS << " Kind=PropertyRef Property=\"" << *Node->getExplicitProperty() <<'"';
John McCallb7bd14f2010-12-02 01:19:52 +00002149 }
Fariborz Jahanian8a1810f2008-11-22 18:39:36 +00002150
Fariborz Jahanian681c0752010-10-14 16:04:05 +00002151 if (Node->isSuperReceiver())
2152 OS << " super";
Argyrios Kyrtzidisab468b02012-03-30 00:19:18 +00002153
2154 OS << " Messaging=";
2155 if (Node->isMessagingGetter() && Node->isMessagingSetter())
2156 OS << "Getter&Setter";
2157 else if (Node->isMessagingGetter())
2158 OS << "Getter";
2159 else if (Node->isMessagingSetter())
2160 OS << "Setter";
Douglas Gregor8ea1f532008-11-04 14:56:14 +00002161}
2162
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002163void ASTDumper::VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002164 VisitExpr(Node);
Ted Kremeneke65b0862012-03-06 20:05:56 +00002165 if (Node->isArraySubscriptRefExpr())
2166 OS << " Kind=ArraySubscript GetterForArray=\"";
2167 else
2168 OS << " Kind=DictionarySubscript GetterForDictionary=\"";
2169 if (Node->getAtIndexMethodDecl())
Aaron Ballmanb190f972014-01-03 17:59:55 +00002170 Node->getAtIndexMethodDecl()->getSelector().print(OS);
Ted Kremeneke65b0862012-03-06 20:05:56 +00002171 else
2172 OS << "(null)";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002173
Ted Kremeneke65b0862012-03-06 20:05:56 +00002174 if (Node->isArraySubscriptRefExpr())
2175 OS << "\" SetterForArray=\"";
2176 else
2177 OS << "\" SetterForDictionary=\"";
2178 if (Node->setAtIndexMethodDecl())
Aaron Ballmanb190f972014-01-03 17:59:55 +00002179 Node->setAtIndexMethodDecl()->getSelector().print(OS);
Ted Kremeneke65b0862012-03-06 20:05:56 +00002180 else
2181 OS << "(null)";
2182}
2183
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002184void ASTDumper::VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002185 VisitExpr(Node);
Ted Kremeneke65b0862012-03-06 20:05:56 +00002186 OS << " " << (Node->getValue() ? "__objc_yes" : "__objc_no");
2187}
2188
Chris Lattnercbe4f772007-08-08 22:51:59 +00002189//===----------------------------------------------------------------------===//
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002190// Comments
2191//===----------------------------------------------------------------------===//
2192
2193const char *ASTDumper::getCommandName(unsigned CommandID) {
2194 if (Traits)
2195 return Traits->getCommandInfo(CommandID)->Name;
2196 const CommandInfo *Info = CommandTraits::getBuiltinCommandInfo(CommandID);
2197 if (Info)
2198 return Info->Name;
2199 return "<not a builtin command>";
2200}
2201
2202void ASTDumper::dumpFullComment(const FullComment *C) {
2203 if (!C)
2204 return;
2205
2206 FC = C;
2207 dumpComment(C);
Craig Topper36250ad2014-05-12 05:36:57 +00002208 FC = nullptr;
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002209}
2210
2211void ASTDumper::dumpComment(const Comment *C) {
Richard Smithf7514452014-10-30 21:02:37 +00002212 dumpChild([=] {
2213 if (!C) {
2214 ColorScope Color(*this, NullColor);
2215 OS << "<<<NULL>>>";
2216 return;
2217 }
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002218
Richard Smithf7514452014-10-30 21:02:37 +00002219 {
2220 ColorScope Color(*this, CommentColor);
2221 OS << C->getCommentKindName();
2222 }
2223 dumpPointer(C);
2224 dumpSourceRange(C->getSourceRange());
2225 ConstCommentVisitor<ASTDumper>::visit(C);
2226 for (Comment::child_iterator I = C->child_begin(), E = C->child_end();
2227 I != E; ++I)
2228 dumpComment(*I);
2229 });
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002230}
2231
2232void ASTDumper::visitTextComment(const TextComment *C) {
2233 OS << " Text=\"" << C->getText() << "\"";
2234}
2235
2236void ASTDumper::visitInlineCommandComment(const InlineCommandComment *C) {
2237 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\"";
2238 switch (C->getRenderKind()) {
2239 case InlineCommandComment::RenderNormal:
2240 OS << " RenderNormal";
2241 break;
2242 case InlineCommandComment::RenderBold:
2243 OS << " RenderBold";
2244 break;
2245 case InlineCommandComment::RenderMonospaced:
2246 OS << " RenderMonospaced";
2247 break;
2248 case InlineCommandComment::RenderEmphasized:
2249 OS << " RenderEmphasized";
2250 break;
2251 }
2252
2253 for (unsigned i = 0, e = C->getNumArgs(); i != e; ++i)
2254 OS << " Arg[" << i << "]=\"" << C->getArgText(i) << "\"";
2255}
2256
2257void ASTDumper::visitHTMLStartTagComment(const HTMLStartTagComment *C) {
2258 OS << " Name=\"" << C->getTagName() << "\"";
2259 if (C->getNumAttrs() != 0) {
2260 OS << " Attrs: ";
2261 for (unsigned i = 0, e = C->getNumAttrs(); i != e; ++i) {
2262 const HTMLStartTagComment::Attribute &Attr = C->getAttr(i);
2263 OS << " \"" << Attr.Name << "=\"" << Attr.Value << "\"";
2264 }
2265 }
2266 if (C->isSelfClosing())
2267 OS << " SelfClosing";
2268}
2269
2270void ASTDumper::visitHTMLEndTagComment(const HTMLEndTagComment *C) {
2271 OS << " Name=\"" << C->getTagName() << "\"";
2272}
2273
2274void ASTDumper::visitBlockCommandComment(const BlockCommandComment *C) {
2275 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\"";
2276 for (unsigned i = 0, e = C->getNumArgs(); i != e; ++i)
2277 OS << " Arg[" << i << "]=\"" << C->getArgText(i) << "\"";
2278}
2279
2280void ASTDumper::visitParamCommandComment(const ParamCommandComment *C) {
2281 OS << " " << ParamCommandComment::getDirectionAsString(C->getDirection());
2282
2283 if (C->isDirectionExplicit())
2284 OS << " explicitly";
2285 else
2286 OS << " implicitly";
2287
2288 if (C->hasParamName()) {
2289 if (C->isParamIndexValid())
2290 OS << " Param=\"" << C->getParamName(FC) << "\"";
2291 else
2292 OS << " Param=\"" << C->getParamNameAsWritten() << "\"";
2293 }
2294
Dmitri Gribenkodbff5c72014-03-19 14:03:47 +00002295 if (C->isParamIndexValid() && !C->isVarArgParam())
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002296 OS << " ParamIndex=" << C->getParamIndex();
2297}
2298
2299void ASTDumper::visitTParamCommandComment(const TParamCommandComment *C) {
2300 if (C->hasParamName()) {
2301 if (C->isPositionValid())
2302 OS << " Param=\"" << C->getParamName(FC) << "\"";
2303 else
2304 OS << " Param=\"" << C->getParamNameAsWritten() << "\"";
2305 }
2306
2307 if (C->isPositionValid()) {
2308 OS << " Position=<";
2309 for (unsigned i = 0, e = C->getDepth(); i != e; ++i) {
2310 OS << C->getIndex(i);
2311 if (i != e - 1)
2312 OS << ", ";
2313 }
2314 OS << ">";
2315 }
2316}
2317
2318void ASTDumper::visitVerbatimBlockComment(const VerbatimBlockComment *C) {
2319 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\""
2320 " CloseName=\"" << C->getCloseName() << "\"";
2321}
2322
2323void ASTDumper::visitVerbatimBlockLineComment(
2324 const VerbatimBlockLineComment *C) {
2325 OS << " Text=\"" << C->getText() << "\"";
2326}
2327
2328void ASTDumper::visitVerbatimLineComment(const VerbatimLineComment *C) {
2329 OS << " Text=\"" << C->getText() << "\"";
2330}
2331
2332//===----------------------------------------------------------------------===//
Richard Smithd5e7ff82014-10-31 01:17:45 +00002333// Type method implementations
2334//===----------------------------------------------------------------------===//
2335
2336void QualType::dump(const char *msg) const {
2337 if (msg)
2338 llvm::errs() << msg << ": ";
2339 dump();
2340}
2341
2342LLVM_DUMP_METHOD void QualType::dump() const {
2343 ASTDumper Dumper(llvm::errs(), nullptr, nullptr);
2344 Dumper.dumpTypeAsChild(*this);
2345}
2346
2347LLVM_DUMP_METHOD void Type::dump() const { QualType(this, 0).dump(); }
2348
2349//===----------------------------------------------------------------------===//
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002350// Decl method implementations
2351//===----------------------------------------------------------------------===//
2352
Alp Tokeref6b0072014-01-04 13:47:14 +00002353LLVM_DUMP_METHOD void Decl::dump() const { dump(llvm::errs()); }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002354
Alp Tokeref6b0072014-01-04 13:47:14 +00002355LLVM_DUMP_METHOD void Decl::dump(raw_ostream &OS) const {
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002356 ASTDumper P(OS, &getASTContext().getCommentCommandTraits(),
2357 &getASTContext().getSourceManager());
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002358 P.dumpDecl(this);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002359}
2360
Alp Tokeref6b0072014-01-04 13:47:14 +00002361LLVM_DUMP_METHOD void Decl::dumpColor() const {
Richard Trieud215b8d2013-01-26 01:31:20 +00002362 ASTDumper P(llvm::errs(), &getASTContext().getCommentCommandTraits(),
2363 &getASTContext().getSourceManager(), /*ShowColors*/true);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002364 P.dumpDecl(this);
Richard Trieud215b8d2013-01-26 01:31:20 +00002365}
Richard Smith33937e72013-06-22 21:49:40 +00002366
Alp Tokeref6b0072014-01-04 13:47:14 +00002367LLVM_DUMP_METHOD void DeclContext::dumpLookups() const {
Richard Smith6ea05822013-06-24 01:45:33 +00002368 dumpLookups(llvm::errs());
2369}
2370
Richard Smith35f986d2014-08-11 22:11:07 +00002371LLVM_DUMP_METHOD void DeclContext::dumpLookups(raw_ostream &OS,
2372 bool DumpDecls) const {
Richard Smith33937e72013-06-22 21:49:40 +00002373 const DeclContext *DC = this;
2374 while (!DC->isTranslationUnit())
2375 DC = DC->getParent();
2376 ASTContext &Ctx = cast<TranslationUnitDecl>(DC)->getASTContext();
Richard Smith6ea05822013-06-24 01:45:33 +00002377 ASTDumper P(OS, &Ctx.getCommentCommandTraits(), &Ctx.getSourceManager());
Richard Smith35f986d2014-08-11 22:11:07 +00002378 P.dumpLookups(this, DumpDecls);
Richard Smith33937e72013-06-22 21:49:40 +00002379}
2380
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002381//===----------------------------------------------------------------------===//
Chris Lattnercbe4f772007-08-08 22:51:59 +00002382// Stmt method implementations
2383//===----------------------------------------------------------------------===//
2384
Alp Tokeref6b0072014-01-04 13:47:14 +00002385LLVM_DUMP_METHOD void Stmt::dump(SourceManager &SM) const {
Argyrios Kyrtzidisc049f752010-08-09 10:54:31 +00002386 dump(llvm::errs(), SM);
2387}
2388
Alp Tokeref6b0072014-01-04 13:47:14 +00002389LLVM_DUMP_METHOD void Stmt::dump(raw_ostream &OS, SourceManager &SM) const {
Craig Topper36250ad2014-05-12 05:36:57 +00002390 ASTDumper P(OS, nullptr, &SM);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002391 P.dumpStmt(this);
Chris Lattner779d5d92007-08-30 00:40:08 +00002392}
2393
Faisal Vali2da8ed92015-03-22 13:35:56 +00002394LLVM_DUMP_METHOD void Stmt::dump(raw_ostream &OS) const {
2395 ASTDumper P(OS, nullptr, nullptr);
2396 P.dumpStmt(this);
2397}
2398
Alp Tokeref6b0072014-01-04 13:47:14 +00002399LLVM_DUMP_METHOD void Stmt::dump() const {
Craig Topper36250ad2014-05-12 05:36:57 +00002400 ASTDumper P(llvm::errs(), nullptr, nullptr);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002401 P.dumpStmt(this);
Chris Lattnercbe4f772007-08-08 22:51:59 +00002402}
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002403
Alp Tokeref6b0072014-01-04 13:47:14 +00002404LLVM_DUMP_METHOD void Stmt::dumpColor() const {
Craig Topper36250ad2014-05-12 05:36:57 +00002405 ASTDumper P(llvm::errs(), nullptr, nullptr, /*ShowColors*/true);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002406 P.dumpStmt(this);
Richard Trieud215b8d2013-01-26 01:31:20 +00002407}
2408
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002409//===----------------------------------------------------------------------===//
2410// Comment method implementations
2411//===----------------------------------------------------------------------===//
2412
Craig Topper36250ad2014-05-12 05:36:57 +00002413LLVM_DUMP_METHOD void Comment::dump() const {
2414 dump(llvm::errs(), nullptr, nullptr);
2415}
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002416
Alp Tokeref6b0072014-01-04 13:47:14 +00002417LLVM_DUMP_METHOD void Comment::dump(const ASTContext &Context) const {
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002418 dump(llvm::errs(), &Context.getCommentCommandTraits(),
2419 &Context.getSourceManager());
2420}
2421
Alexander Kornienko00911f12013-01-15 12:20:21 +00002422void Comment::dump(raw_ostream &OS, const CommandTraits *Traits,
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002423 const SourceManager *SM) const {
2424 const FullComment *FC = dyn_cast<FullComment>(this);
2425 ASTDumper D(OS, Traits, SM);
2426 D.dumpFullComment(FC);
2427}
Richard Trieud215b8d2013-01-26 01:31:20 +00002428
Alp Tokeref6b0072014-01-04 13:47:14 +00002429LLVM_DUMP_METHOD void Comment::dumpColor() const {
Richard Trieud215b8d2013-01-26 01:31:20 +00002430 const FullComment *FC = dyn_cast<FullComment>(this);
Craig Topper36250ad2014-05-12 05:36:57 +00002431 ASTDumper D(llvm::errs(), nullptr, nullptr, /*ShowColors*/true);
Richard Trieud215b8d2013-01-26 01:31:20 +00002432 D.dumpFullComment(FC);
2433}