blob: e84814a96c0cc7b05139422ce70e746ead2bd3da [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"
Alexey Bataev958b9e72016-03-31 09:30:50 +000021#include "clang/AST/DeclOpenMP.h"
Alexander Kornienko90ff6072012-12-20 02:09:13 +000022#include "clang/AST/DeclVisitor.h"
Benjamin Kramer31b382e2016-02-01 17:42:01 +000023#include "clang/AST/LocInfoType.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000024#include "clang/AST/StmtVisitor.h"
Richard Smithd5e7ff82014-10-31 01:17:45 +000025#include "clang/AST/TypeVisitor.h"
David Majnemerd9b1a4f2015-11-04 03:40:30 +000026#include "clang/Basic/Builtins.h"
Alexander Kornienko90ff6072012-12-20 02:09:13 +000027#include "clang/Basic/Module.h"
Chris Lattner11e30d32007-08-30 06:17:34 +000028#include "clang/Basic/SourceManager.h"
Daniel Dunbar34a96c82009-12-03 09:13:13 +000029#include "llvm/Support/raw_ostream.h"
Chris Lattnercbe4f772007-08-08 22:51:59 +000030using namespace clang;
Alexander Kornienkoebc17b52013-01-14 14:07:11 +000031using namespace clang::comments;
Chris Lattnercbe4f772007-08-08 22:51:59 +000032
33//===----------------------------------------------------------------------===//
Alexander Kornienko18ec81b2012-12-13 13:59:55 +000034// ASTDumper Visitor
Chris Lattnercbe4f772007-08-08 22:51:59 +000035//===----------------------------------------------------------------------===//
36
37namespace {
Richard Trieud215b8d2013-01-26 01:31:20 +000038 // Colors used for various parts of the AST dump
Richard Trieu532018f2014-03-06 01:09:03 +000039 // Do not use bold yellow for any text. It is hard to read on white screens.
Richard Trieud215b8d2013-01-26 01:31:20 +000040
41 struct TerminalColor {
42 raw_ostream::Colors Color;
43 bool Bold;
44 };
45
Richard Trieu532018f2014-03-06 01:09:03 +000046 // Red - CastColor
47 // Green - TypeColor
48 // Bold Green - DeclKindNameColor, UndeserializedColor
49 // Yellow - AddressColor, LocationColor
50 // Blue - CommentColor, NullColor, IndentColor
51 // Bold Blue - AttrColor
52 // Bold Magenta - StmtColor
53 // Cyan - ValueKindColor, ObjectKindColor
54 // Bold Cyan - ValueColor, DeclNameColor
55
Richard Trieud215b8d2013-01-26 01:31:20 +000056 // Decl kind names (VarDecl, FunctionDecl, etc)
57 static const TerminalColor DeclKindNameColor = { raw_ostream::GREEN, true };
58 // Attr names (CleanupAttr, GuardedByAttr, etc)
59 static const TerminalColor AttrColor = { raw_ostream::BLUE, true };
60 // Statement names (DeclStmt, ImplicitCastExpr, etc)
61 static const TerminalColor StmtColor = { raw_ostream::MAGENTA, true };
62 // Comment names (FullComment, ParagraphComment, TextComment, etc)
Richard Trieu532018f2014-03-06 01:09:03 +000063 static const TerminalColor CommentColor = { raw_ostream::BLUE, false };
Richard Trieud215b8d2013-01-26 01:31:20 +000064
65 // Type names (int, float, etc, plus user defined types)
66 static const TerminalColor TypeColor = { raw_ostream::GREEN, false };
67
68 // Pointer address
69 static const TerminalColor AddressColor = { raw_ostream::YELLOW, false };
70 // Source locations
71 static const TerminalColor LocationColor = { raw_ostream::YELLOW, false };
72
73 // lvalue/xvalue
74 static const TerminalColor ValueKindColor = { raw_ostream::CYAN, false };
75 // bitfield/objcproperty/objcsubscript/vectorcomponent
76 static const TerminalColor ObjectKindColor = { raw_ostream::CYAN, false };
77
78 // Null statements
79 static const TerminalColor NullColor = { raw_ostream::BLUE, false };
80
Richard Smith1d209d02013-05-23 01:49:11 +000081 // Undeserialized entities
82 static const TerminalColor UndeserializedColor = { raw_ostream::GREEN, true };
83
Richard Trieud215b8d2013-01-26 01:31:20 +000084 // CastKind from CastExpr's
85 static const TerminalColor CastColor = { raw_ostream::RED, false };
86
87 // Value of the statement
88 static const TerminalColor ValueColor = { raw_ostream::CYAN, true };
89 // Decl names
90 static const TerminalColor DeclNameColor = { raw_ostream::CYAN, true };
91
Richard Trieude5cc7d2013-01-31 01:44:26 +000092 // Indents ( `, -. | )
93 static const TerminalColor IndentColor = { raw_ostream::BLUE, false };
94
Alexander Kornienko90ff6072012-12-20 02:09:13 +000095 class ASTDumper
Alexander Kornienko540bacb2013-02-01 12:35:51 +000096 : public ConstDeclVisitor<ASTDumper>, public ConstStmtVisitor<ASTDumper>,
Richard Smithd5e7ff82014-10-31 01:17:45 +000097 public ConstCommentVisitor<ASTDumper>, public TypeVisitor<ASTDumper> {
Chris Lattner0e62c1c2011-07-23 10:55:15 +000098 raw_ostream &OS;
Alexander Kornienkoebc17b52013-01-14 14:07:11 +000099 const CommandTraits *Traits;
100 const SourceManager *SM;
Mike Stump11289f42009-09-09 15:08:12 +0000101
Aaron Ballman8c208282017-12-21 21:42:42 +0000102 /// The policy to use for printing; can be defaulted.
103 PrintingPolicy PrintPolicy;
104
Richard Smithf7514452014-10-30 21:02:37 +0000105 /// Pending[i] is an action to dump an entity at level i.
106 llvm::SmallVector<std::function<void(bool isLastChild)>, 32> Pending;
Richard Trieude5cc7d2013-01-31 01:44:26 +0000107
Richard Smith3a36ac12017-03-09 22:00:01 +0000108 /// Indicates whether we should trigger deserialization of nodes that had
109 /// not already been loaded.
110 bool Deserialize = false;
111
Richard Smithf7514452014-10-30 21:02:37 +0000112 /// Indicates whether we're at the top level.
Richard Smith3a36ac12017-03-09 22:00:01 +0000113 bool TopLevel = true;
Richard Trieude5cc7d2013-01-31 01:44:26 +0000114
Richard Smithf7514452014-10-30 21:02:37 +0000115 /// Indicates if we're handling the first child after entering a new depth.
Richard Smith3a36ac12017-03-09 22:00:01 +0000116 bool FirstChild = true;
Richard Smithf7514452014-10-30 21:02:37 +0000117
118 /// Prefix for currently-being-dumped entity.
119 std::string Prefix;
Richard Trieude5cc7d2013-01-31 01:44:26 +0000120
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000121 /// Keep track of the last location we print out so that we can
122 /// print out deltas from then on out.
Richard Smith3a36ac12017-03-09 22:00:01 +0000123 const char *LastLocFilename = "";
124 unsigned LastLocLine = ~0U;
Douglas Gregor7de59662009-05-29 20:38:28 +0000125
Alexander Kornienkoebc17b52013-01-14 14:07:11 +0000126 /// The \c FullComment parent of the comment being dumped.
Richard Smith3a36ac12017-03-09 22:00:01 +0000127 const FullComment *FC = nullptr;
Alexander Kornienkoebc17b52013-01-14 14:07:11 +0000128
Richard Trieud215b8d2013-01-26 01:31:20 +0000129 bool ShowColors;
130
Richard Smithf7514452014-10-30 21:02:37 +0000131 /// Dump a child of the current node.
132 template<typename Fn> void dumpChild(Fn doDumpChild) {
133 // If we're at the top level, there's nothing interesting to do; just
134 // run the dumper.
135 if (TopLevel) {
136 TopLevel = false;
137 doDumpChild();
138 while (!Pending.empty()) {
139 Pending.back()(true);
140 Pending.pop_back();
141 }
142 Prefix.clear();
143 OS << "\n";
144 TopLevel = true;
145 return;
Manuel Klimek874030e2012-11-07 00:33:12 +0000146 }
Richard Smithf7514452014-10-30 21:02:37 +0000147
148 const FullComment *OrigFC = FC;
149 auto dumpWithIndent = [this, doDumpChild, OrigFC](bool isLastChild) {
150 // Print out the appropriate tree structure and work out the prefix for
151 // children of this node. For instance:
152 //
153 // A Prefix = ""
154 // |-B Prefix = "| "
155 // | `-C Prefix = "| "
156 // `-D Prefix = " "
157 // |-E Prefix = " | "
158 // `-F Prefix = " "
159 // G Prefix = ""
160 //
161 // Note that the first level gets no prefix.
162 {
163 OS << '\n';
164 ColorScope Color(*this, IndentColor);
165 OS << Prefix << (isLastChild ? '`' : '|') << '-';
NAKAMURA Takumic73e4022014-10-31 00:30:37 +0000166 this->Prefix.push_back(isLastChild ? ' ' : '|');
167 this->Prefix.push_back(' ');
Richard Smithf7514452014-10-30 21:02:37 +0000168 }
169
170 FirstChild = true;
171 unsigned Depth = Pending.size();
172
173 FC = OrigFC;
174 doDumpChild();
175
176 // If any children are left, they're the last at their nesting level.
177 // Dump those ones out now.
178 while (Depth < Pending.size()) {
179 Pending.back()(true);
NAKAMURA Takumic73e4022014-10-31 00:30:37 +0000180 this->Pending.pop_back();
Richard Smithf7514452014-10-30 21:02:37 +0000181 }
182
183 // Restore the old prefix.
NAKAMURA Takumic73e4022014-10-31 00:30:37 +0000184 this->Prefix.resize(Prefix.size() - 2);
Richard Smithf7514452014-10-30 21:02:37 +0000185 };
186
187 if (FirstChild) {
188 Pending.push_back(std::move(dumpWithIndent));
189 } else {
190 Pending.back()(false);
191 Pending.back() = std::move(dumpWithIndent);
Manuel Klimek874030e2012-11-07 00:33:12 +0000192 }
Richard Smithf7514452014-10-30 21:02:37 +0000193 FirstChild = false;
194 }
Manuel Klimek874030e2012-11-07 00:33:12 +0000195
Richard Trieud215b8d2013-01-26 01:31:20 +0000196 class ColorScope {
197 ASTDumper &Dumper;
198 public:
199 ColorScope(ASTDumper &Dumper, TerminalColor Color)
200 : Dumper(Dumper) {
201 if (Dumper.ShowColors)
202 Dumper.OS.changeColor(Color.Color, Color.Bold);
203 }
204 ~ColorScope() {
205 if (Dumper.ShowColors)
206 Dumper.OS.resetColor();
207 }
208 };
209
Chris Lattnercbe4f772007-08-08 22:51:59 +0000210 public:
Alexander Kornienkoebc17b52013-01-14 14:07:11 +0000211 ASTDumper(raw_ostream &OS, const CommandTraits *Traits,
212 const SourceManager *SM)
Aaron Ballman8c208282017-12-21 21:42:42 +0000213 : ASTDumper(OS, Traits, SM,
214 SM && SM->getDiagnostics().getShowColors()) {}
Richard Trieud215b8d2013-01-26 01:31:20 +0000215
216 ASTDumper(raw_ostream &OS, const CommandTraits *Traits,
217 const SourceManager *SM, bool ShowColors)
Aaron Ballman8c208282017-12-21 21:42:42 +0000218 : ASTDumper(OS, Traits, SM, ShowColors, LangOptions()) {}
219 ASTDumper(raw_ostream &OS, const CommandTraits *Traits,
220 const SourceManager *SM, bool ShowColors,
221 const PrintingPolicy &PrintPolicy)
222 : OS(OS), Traits(Traits), SM(SM), PrintPolicy(PrintPolicy),
223 ShowColors(ShowColors) {}
Richard Smith3a36ac12017-03-09 22:00:01 +0000224
225 void setDeserialize(bool D) { Deserialize = D; }
Mike Stump11289f42009-09-09 15:08:12 +0000226
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000227 void dumpDecl(const Decl *D);
228 void dumpStmt(const Stmt *S);
Alexander Kornienkoebc17b52013-01-14 14:07:11 +0000229 void dumpFullComment(const FullComment *C);
Mike Stump11289f42009-09-09 15:08:12 +0000230
Richard Trieude5cc7d2013-01-31 01:44:26 +0000231 // Utilities
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000232 void dumpPointer(const void *Ptr);
233 void dumpSourceRange(SourceRange R);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000234 void dumpLocation(SourceLocation Loc);
Richard Smithd5e7ff82014-10-31 01:17:45 +0000235 void dumpBareType(QualType T, bool Desugar = true);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000236 void dumpType(QualType T);
Richard Smithd5e7ff82014-10-31 01:17:45 +0000237 void dumpTypeAsChild(QualType T);
238 void dumpTypeAsChild(const Type *T);
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000239 void dumpBareDeclRef(const Decl *Node);
Craig Topper36250ad2014-05-12 05:36:57 +0000240 void dumpDeclRef(const Decl *Node, const char *Label = nullptr);
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000241 void dumpName(const NamedDecl *D);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000242 bool hasNodes(const DeclContext *DC);
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000243 void dumpDeclContext(const DeclContext *DC);
Richard Smith35f986d2014-08-11 22:11:07 +0000244 void dumpLookups(const DeclContext *DC, bool DumpDecls);
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000245 void dumpAttr(const Attr *A);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000246
247 // C++ Utilities
248 void dumpAccessSpecifier(AccessSpecifier AS);
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000249 void dumpCXXCtorInitializer(const CXXCtorInitializer *Init);
250 void dumpTemplateParameters(const TemplateParameterList *TPL);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000251 void dumpTemplateArgumentListInfo(const TemplateArgumentListInfo &TALI);
252 void dumpTemplateArgumentLoc(const TemplateArgumentLoc &A);
253 void dumpTemplateArgumentList(const TemplateArgumentList &TAL);
254 void dumpTemplateArgument(const TemplateArgument &A,
255 SourceRange R = SourceRange());
256
Douglas Gregor85f3f952015-07-07 03:57:15 +0000257 // Objective-C utilities.
258 void dumpObjCTypeParamList(const ObjCTypeParamList *typeParams);
259
Richard Smithd5e7ff82014-10-31 01:17:45 +0000260 // Types
261 void VisitComplexType(const ComplexType *T) {
262 dumpTypeAsChild(T->getElementType());
263 }
264 void VisitPointerType(const PointerType *T) {
265 dumpTypeAsChild(T->getPointeeType());
266 }
267 void VisitBlockPointerType(const BlockPointerType *T) {
268 dumpTypeAsChild(T->getPointeeType());
269 }
270 void VisitReferenceType(const ReferenceType *T) {
271 dumpTypeAsChild(T->getPointeeType());
272 }
273 void VisitRValueReferenceType(const ReferenceType *T) {
274 if (T->isSpelledAsLValue())
275 OS << " written as lvalue reference";
276 VisitReferenceType(T);
277 }
278 void VisitMemberPointerType(const MemberPointerType *T) {
279 dumpTypeAsChild(T->getClass());
280 dumpTypeAsChild(T->getPointeeType());
281 }
282 void VisitArrayType(const ArrayType *T) {
283 switch (T->getSizeModifier()) {
284 case ArrayType::Normal: break;
285 case ArrayType::Static: OS << " static"; break;
286 case ArrayType::Star: OS << " *"; break;
287 }
288 OS << " " << T->getIndexTypeQualifiers().getAsString();
289 dumpTypeAsChild(T->getElementType());
290 }
291 void VisitConstantArrayType(const ConstantArrayType *T) {
292 OS << " " << T->getSize();
293 VisitArrayType(T);
294 }
295 void VisitVariableArrayType(const VariableArrayType *T) {
296 OS << " ";
297 dumpSourceRange(T->getBracketsRange());
298 VisitArrayType(T);
299 dumpStmt(T->getSizeExpr());
300 }
301 void VisitDependentSizedArrayType(const DependentSizedArrayType *T) {
302 VisitArrayType(T);
303 OS << " ";
304 dumpSourceRange(T->getBracketsRange());
305 dumpStmt(T->getSizeExpr());
306 }
307 void VisitDependentSizedExtVectorType(
308 const DependentSizedExtVectorType *T) {
309 OS << " ";
310 dumpLocation(T->getAttributeLoc());
311 dumpTypeAsChild(T->getElementType());
312 dumpStmt(T->getSizeExpr());
313 }
314 void VisitVectorType(const VectorType *T) {
315 switch (T->getVectorKind()) {
316 case VectorType::GenericVector: break;
317 case VectorType::AltiVecVector: OS << " altivec"; break;
318 case VectorType::AltiVecPixel: OS << " altivec pixel"; break;
319 case VectorType::AltiVecBool: OS << " altivec bool"; break;
320 case VectorType::NeonVector: OS << " neon"; break;
321 case VectorType::NeonPolyVector: OS << " neon poly"; break;
322 }
323 OS << " " << T->getNumElements();
324 dumpTypeAsChild(T->getElementType());
325 }
326 void VisitFunctionType(const FunctionType *T) {
327 auto EI = T->getExtInfo();
328 if (EI.getNoReturn()) OS << " noreturn";
329 if (EI.getProducesResult()) OS << " produces_result";
330 if (EI.getHasRegParm()) OS << " regparm " << EI.getRegParm();
331 OS << " " << FunctionType::getNameForCallConv(EI.getCC());
332 dumpTypeAsChild(T->getReturnType());
333 }
334 void VisitFunctionProtoType(const FunctionProtoType *T) {
335 auto EPI = T->getExtProtoInfo();
336 if (EPI.HasTrailingReturn) OS << " trailing_return";
337 if (T->isConst()) OS << " const";
338 if (T->isVolatile()) OS << " volatile";
339 if (T->isRestrict()) OS << " restrict";
340 switch (EPI.RefQualifier) {
341 case RQ_None: break;
342 case RQ_LValue: OS << " &"; break;
343 case RQ_RValue: OS << " &&"; break;
344 }
345 // FIXME: Exception specification.
346 // FIXME: Consumed parameters.
347 VisitFunctionType(T);
348 for (QualType PT : T->getParamTypes())
349 dumpTypeAsChild(PT);
350 if (EPI.Variadic)
351 dumpChild([=] { OS << "..."; });
352 }
353 void VisitUnresolvedUsingType(const UnresolvedUsingType *T) {
354 dumpDeclRef(T->getDecl());
355 }
356 void VisitTypedefType(const TypedefType *T) {
357 dumpDeclRef(T->getDecl());
358 }
359 void VisitTypeOfExprType(const TypeOfExprType *T) {
360 dumpStmt(T->getUnderlyingExpr());
361 }
362 void VisitDecltypeType(const DecltypeType *T) {
363 dumpStmt(T->getUnderlyingExpr());
364 }
365 void VisitUnaryTransformType(const UnaryTransformType *T) {
366 switch (T->getUTTKind()) {
367 case UnaryTransformType::EnumUnderlyingType:
368 OS << " underlying_type";
369 break;
370 }
371 dumpTypeAsChild(T->getBaseType());
372 }
373 void VisitTagType(const TagType *T) {
374 dumpDeclRef(T->getDecl());
375 }
376 void VisitAttributedType(const AttributedType *T) {
377 // FIXME: AttrKind
378 dumpTypeAsChild(T->getModifiedType());
379 }
380 void VisitTemplateTypeParmType(const TemplateTypeParmType *T) {
381 OS << " depth " << T->getDepth() << " index " << T->getIndex();
382 if (T->isParameterPack()) OS << " pack";
383 dumpDeclRef(T->getDecl());
384 }
385 void VisitSubstTemplateTypeParmType(const SubstTemplateTypeParmType *T) {
386 dumpTypeAsChild(T->getReplacedParameter());
387 }
388 void VisitSubstTemplateTypeParmPackType(
389 const SubstTemplateTypeParmPackType *T) {
390 dumpTypeAsChild(T->getReplacedParameter());
391 dumpTemplateArgument(T->getArgumentPack());
392 }
393 void VisitAutoType(const AutoType *T) {
394 if (T->isDecltypeAuto()) OS << " decltype(auto)";
395 if (!T->isDeduced())
396 OS << " undeduced";
397 }
398 void VisitTemplateSpecializationType(const TemplateSpecializationType *T) {
399 if (T->isTypeAlias()) OS << " alias";
400 OS << " "; T->getTemplateName().dump(OS);
401 for (auto &Arg : *T)
402 dumpTemplateArgument(Arg);
403 if (T->isTypeAlias())
404 dumpTypeAsChild(T->getAliasedType());
405 }
406 void VisitInjectedClassNameType(const InjectedClassNameType *T) {
407 dumpDeclRef(T->getDecl());
408 }
409 void VisitObjCInterfaceType(const ObjCInterfaceType *T) {
410 dumpDeclRef(T->getDecl());
411 }
412 void VisitObjCObjectPointerType(const ObjCObjectPointerType *T) {
413 dumpTypeAsChild(T->getPointeeType());
414 }
415 void VisitAtomicType(const AtomicType *T) {
416 dumpTypeAsChild(T->getValueType());
417 }
Xiuli Pan2d12e652016-05-03 05:37:07 +0000418 void VisitPipeType(const PipeType *T) {
419 dumpTypeAsChild(T->getElementType());
420 }
Richard Smithd5e7ff82014-10-31 01:17:45 +0000421 void VisitAdjustedType(const AdjustedType *T) {
422 dumpTypeAsChild(T->getOriginalType());
423 }
424 void VisitPackExpansionType(const PackExpansionType *T) {
425 if (auto N = T->getNumExpansions()) OS << " expansions " << *N;
426 if (!T->isSugared())
427 dumpTypeAsChild(T->getPattern());
428 }
429 // FIXME: ElaboratedType, DependentNameType,
430 // DependentTemplateSpecializationType, ObjCObjectType
431
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000432 // Decls
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000433 void VisitLabelDecl(const LabelDecl *D);
434 void VisitTypedefDecl(const TypedefDecl *D);
435 void VisitEnumDecl(const EnumDecl *D);
436 void VisitRecordDecl(const RecordDecl *D);
437 void VisitEnumConstantDecl(const EnumConstantDecl *D);
438 void VisitIndirectFieldDecl(const IndirectFieldDecl *D);
439 void VisitFunctionDecl(const FunctionDecl *D);
440 void VisitFieldDecl(const FieldDecl *D);
441 void VisitVarDecl(const VarDecl *D);
Richard Smithbdb84f32016-07-22 23:36:59 +0000442 void VisitDecompositionDecl(const DecompositionDecl *D);
Richard Smith7873de02016-08-11 22:25:46 +0000443 void VisitBindingDecl(const BindingDecl *D);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000444 void VisitFileScopeAsmDecl(const FileScopeAsmDecl *D);
445 void VisitImportDecl(const ImportDecl *D);
Nico Weber66220292016-03-02 17:28:48 +0000446 void VisitPragmaCommentDecl(const PragmaCommentDecl *D);
Nico Webercbbaeb12016-03-02 19:28:54 +0000447 void VisitPragmaDetectMismatchDecl(const PragmaDetectMismatchDecl *D);
Alexey Bataev958b9e72016-03-31 09:30:50 +0000448 void VisitCapturedDecl(const CapturedDecl *D);
449
450 // OpenMP decls
451 void VisitOMPThreadPrivateDecl(const OMPThreadPrivateDecl *D);
452 void VisitOMPDeclareReductionDecl(const OMPDeclareReductionDecl *D);
Kelvin Li1408f912018-09-26 04:28:39 +0000453 void VisitOMPRequiresDecl(const OMPRequiresDecl *D);
Alexey Bataev958b9e72016-03-31 09:30:50 +0000454 void VisitOMPCapturedExprDecl(const OMPCapturedExprDecl *D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000455
456 // C++ Decls
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000457 void VisitNamespaceDecl(const NamespaceDecl *D);
458 void VisitUsingDirectiveDecl(const UsingDirectiveDecl *D);
459 void VisitNamespaceAliasDecl(const NamespaceAliasDecl *D);
460 void VisitTypeAliasDecl(const TypeAliasDecl *D);
461 void VisitTypeAliasTemplateDecl(const TypeAliasTemplateDecl *D);
462 void VisitCXXRecordDecl(const CXXRecordDecl *D);
463 void VisitStaticAssertDecl(const StaticAssertDecl *D);
Richard Smithcbdf7332014-03-18 02:07:28 +0000464 template<typename SpecializationDecl>
Richard Smithf7514452014-10-30 21:02:37 +0000465 void VisitTemplateDeclSpecialization(const SpecializationDecl *D,
Richard Smithcbdf7332014-03-18 02:07:28 +0000466 bool DumpExplicitInst,
467 bool DumpRefOnly);
Richard Smith20ade552014-03-17 23:34:53 +0000468 template<typename TemplateDecl>
469 void VisitTemplateDecl(const TemplateDecl *D, bool DumpExplicitInst);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000470 void VisitFunctionTemplateDecl(const FunctionTemplateDecl *D);
471 void VisitClassTemplateDecl(const ClassTemplateDecl *D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000472 void VisitClassTemplateSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000473 const ClassTemplateSpecializationDecl *D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000474 void VisitClassTemplatePartialSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000475 const ClassTemplatePartialSpecializationDecl *D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000476 void VisitClassScopeFunctionSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000477 const ClassScopeFunctionSpecializationDecl *D);
David Majnemerd9b1a4f2015-11-04 03:40:30 +0000478 void VisitBuiltinTemplateDecl(const BuiltinTemplateDecl *D);
Richard Smithd25789a2013-09-18 01:36:02 +0000479 void VisitVarTemplateDecl(const VarTemplateDecl *D);
480 void VisitVarTemplateSpecializationDecl(
481 const VarTemplateSpecializationDecl *D);
482 void VisitVarTemplatePartialSpecializationDecl(
483 const VarTemplatePartialSpecializationDecl *D);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000484 void VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D);
485 void VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D);
486 void VisitTemplateTemplateParmDecl(const TemplateTemplateParmDecl *D);
487 void VisitUsingDecl(const UsingDecl *D);
488 void VisitUnresolvedUsingTypenameDecl(const UnresolvedUsingTypenameDecl *D);
489 void VisitUnresolvedUsingValueDecl(const UnresolvedUsingValueDecl *D);
490 void VisitUsingShadowDecl(const UsingShadowDecl *D);
Richard Smith5179eb72016-06-28 19:03:57 +0000491 void VisitConstructorUsingShadowDecl(const ConstructorUsingShadowDecl *D);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000492 void VisitLinkageSpecDecl(const LinkageSpecDecl *D);
493 void VisitAccessSpecDecl(const AccessSpecDecl *D);
494 void VisitFriendDecl(const FriendDecl *D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000495
496 // ObjC Decls
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000497 void VisitObjCIvarDecl(const ObjCIvarDecl *D);
498 void VisitObjCMethodDecl(const ObjCMethodDecl *D);
Douglas Gregor85f3f952015-07-07 03:57:15 +0000499 void VisitObjCTypeParamDecl(const ObjCTypeParamDecl *D);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000500 void VisitObjCCategoryDecl(const ObjCCategoryDecl *D);
501 void VisitObjCCategoryImplDecl(const ObjCCategoryImplDecl *D);
502 void VisitObjCProtocolDecl(const ObjCProtocolDecl *D);
503 void VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D);
504 void VisitObjCImplementationDecl(const ObjCImplementationDecl *D);
505 void VisitObjCCompatibleAliasDecl(const ObjCCompatibleAliasDecl *D);
506 void VisitObjCPropertyDecl(const ObjCPropertyDecl *D);
507 void VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D);
508 void VisitBlockDecl(const BlockDecl *D);
Mike Stump11289f42009-09-09 15:08:12 +0000509
Chris Lattner84ca3762007-08-30 01:00:35 +0000510 // Stmts.
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000511 void VisitStmt(const Stmt *Node);
512 void VisitDeclStmt(const DeclStmt *Node);
513 void VisitAttributedStmt(const AttributedStmt *Node);
Bruno Riccib1cc94b2018-10-27 21:12:20 +0000514 void VisitIfStmt(const IfStmt *Node);
Bruno Riccie2806f82018-10-29 16:12:37 +0000515 void VisitSwitchStmt(const SwitchStmt *Node);
Bruno Riccibacf7512018-10-30 13:42:41 +0000516 void VisitWhileStmt(const WhileStmt *Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000517 void VisitLabelStmt(const LabelStmt *Node);
518 void VisitGotoStmt(const GotoStmt *Node);
Pavel Labath1ef83422013-09-04 14:35:00 +0000519 void VisitCXXCatchStmt(const CXXCatchStmt *Node);
Bruno Ricci5b30571752018-10-28 12:30:53 +0000520 void VisitCaseStmt(const CaseStmt *Node);
Alexey Bataev958b9e72016-03-31 09:30:50 +0000521 void VisitCapturedStmt(const CapturedStmt *Node);
522
523 // OpenMP
524 void VisitOMPExecutableDirective(const OMPExecutableDirective *Node);
Mike Stump11289f42009-09-09 15:08:12 +0000525
Chris Lattner84ca3762007-08-30 01:00:35 +0000526 // Exprs
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000527 void VisitExpr(const Expr *Node);
528 void VisitCastExpr(const CastExpr *Node);
Roman Lebedev12216f12018-07-27 07:27:14 +0000529 void VisitImplicitCastExpr(const ImplicitCastExpr *Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000530 void VisitDeclRefExpr(const DeclRefExpr *Node);
531 void VisitPredefinedExpr(const PredefinedExpr *Node);
532 void VisitCharacterLiteral(const CharacterLiteral *Node);
533 void VisitIntegerLiteral(const IntegerLiteral *Node);
Leonard Chandb01c3a2018-06-20 17:19:40 +0000534 void VisitFixedPointLiteral(const FixedPointLiteral *Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000535 void VisitFloatingLiteral(const FloatingLiteral *Node);
536 void VisitStringLiteral(const StringLiteral *Str);
Richard Smithf0514962014-06-03 08:24:28 +0000537 void VisitInitListExpr(const InitListExpr *ILE);
Richard Smith410306b2016-12-12 02:53:20 +0000538 void VisitArrayInitLoopExpr(const ArrayInitLoopExpr *ILE);
539 void VisitArrayInitIndexExpr(const ArrayInitIndexExpr *ILE);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000540 void VisitUnaryOperator(const UnaryOperator *Node);
541 void VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *Node);
542 void VisitMemberExpr(const MemberExpr *Node);
543 void VisitExtVectorElementExpr(const ExtVectorElementExpr *Node);
544 void VisitBinaryOperator(const BinaryOperator *Node);
545 void VisitCompoundAssignOperator(const CompoundAssignOperator *Node);
546 void VisitAddrLabelExpr(const AddrLabelExpr *Node);
547 void VisitBlockExpr(const BlockExpr *Node);
548 void VisitOpaqueValueExpr(const OpaqueValueExpr *Node);
Richard Smith01ccebf2018-01-05 21:31:07 +0000549 void VisitGenericSelectionExpr(const GenericSelectionExpr *E);
Chris Lattner84ca3762007-08-30 01:00:35 +0000550
551 // C++
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000552 void VisitCXXNamedCastExpr(const CXXNamedCastExpr *Node);
553 void VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *Node);
554 void VisitCXXThisExpr(const CXXThisExpr *Node);
555 void VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *Node);
Richard Smith39eca9b2017-08-23 22:12:08 +0000556 void VisitCXXUnresolvedConstructExpr(const CXXUnresolvedConstructExpr *Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000557 void VisitCXXConstructExpr(const CXXConstructExpr *Node);
558 void VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *Node);
Reid Kleckner5c682bc2015-03-19 18:09:25 +0000559 void VisitCXXNewExpr(const CXXNewExpr *Node);
560 void VisitCXXDeleteExpr(const CXXDeleteExpr *Node);
Richard Smithe6c01442013-06-05 00:46:14 +0000561 void VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000562 void VisitExprWithCleanups(const ExprWithCleanups *Node);
563 void VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *Node);
564 void dumpCXXTemporary(const CXXTemporary *Temporary);
Faisal Vali2b391ab2013-09-26 19:54:12 +0000565 void VisitLambdaExpr(const LambdaExpr *Node) {
566 VisitExpr(Node);
567 dumpDecl(Node->getLambdaClass());
568 }
Serge Pavlov6b926032015-02-16 19:58:41 +0000569 void VisitSizeOfPackExpr(const SizeOfPackExpr *Node);
Alex Lorenzddbe0f52016-11-09 14:02:18 +0000570 void
571 VisitCXXDependentScopeMemberExpr(const CXXDependentScopeMemberExpr *Node);
Mike Stump11289f42009-09-09 15:08:12 +0000572
Chris Lattner84ca3762007-08-30 01:00:35 +0000573 // ObjC
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000574 void VisitObjCAtCatchStmt(const ObjCAtCatchStmt *Node);
575 void VisitObjCEncodeExpr(const ObjCEncodeExpr *Node);
576 void VisitObjCMessageExpr(const ObjCMessageExpr *Node);
577 void VisitObjCBoxedExpr(const ObjCBoxedExpr *Node);
578 void VisitObjCSelectorExpr(const ObjCSelectorExpr *Node);
579 void VisitObjCProtocolExpr(const ObjCProtocolExpr *Node);
580 void VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *Node);
581 void VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *Node);
582 void VisitObjCIvarRefExpr(const ObjCIvarRefExpr *Node);
583 void VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *Node);
Alexander Kornienkoebc17b52013-01-14 14:07:11 +0000584
585 // Comments.
586 const char *getCommandName(unsigned CommandID);
587 void dumpComment(const Comment *C);
588
589 // Inline comments.
590 void visitTextComment(const TextComment *C);
591 void visitInlineCommandComment(const InlineCommandComment *C);
592 void visitHTMLStartTagComment(const HTMLStartTagComment *C);
593 void visitHTMLEndTagComment(const HTMLEndTagComment *C);
594
595 // Block comments.
596 void visitBlockCommandComment(const BlockCommandComment *C);
597 void visitParamCommandComment(const ParamCommandComment *C);
598 void visitTParamCommandComment(const TParamCommandComment *C);
599 void visitVerbatimBlockComment(const VerbatimBlockComment *C);
600 void visitVerbatimBlockLineComment(const VerbatimBlockLineComment *C);
601 void visitVerbatimLineComment(const VerbatimLineComment *C);
Chris Lattnercbe4f772007-08-08 22:51:59 +0000602 };
Alexander Kornienkoab9db512015-06-22 23:07:51 +0000603}
Chris Lattnercbe4f772007-08-08 22:51:59 +0000604
605//===----------------------------------------------------------------------===//
Chris Lattner11e30d32007-08-30 06:17:34 +0000606// Utilities
607//===----------------------------------------------------------------------===//
608
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000609void ASTDumper::dumpPointer(const void *Ptr) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000610 ColorScope Color(*this, AddressColor);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000611 OS << ' ' << Ptr;
612}
613
Alexander Kornienko18ec81b2012-12-13 13:59:55 +0000614void ASTDumper::dumpLocation(SourceLocation Loc) {
Alex McCarthye14ddef2014-05-02 20:24:11 +0000615 if (!SM)
616 return;
617
Richard Trieud215b8d2013-01-26 01:31:20 +0000618 ColorScope Color(*this, LocationColor);
Chris Lattner53e384f2009-01-16 07:00:02 +0000619 SourceLocation SpellingLoc = SM->getSpellingLoc(Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000620
Chris Lattner11e30d32007-08-30 06:17:34 +0000621 // The general format we print out is filename:line:col, but we drop pieces
622 // that haven't changed since the last loc printed.
Chris Lattnerf1ca7d32009-01-27 07:57:44 +0000623 PresumedLoc PLoc = SM->getPresumedLoc(SpellingLoc);
624
Douglas Gregor453b0122010-11-12 07:15:47 +0000625 if (PLoc.isInvalid()) {
626 OS << "<invalid sloc>";
627 return;
628 }
629
Chris Lattnerf1ca7d32009-01-27 07:57:44 +0000630 if (strcmp(PLoc.getFilename(), LastLocFilename) != 0) {
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000631 OS << PLoc.getFilename() << ':' << PLoc.getLine()
632 << ':' << PLoc.getColumn();
Chris Lattnerf1ca7d32009-01-27 07:57:44 +0000633 LastLocFilename = PLoc.getFilename();
634 LastLocLine = PLoc.getLine();
635 } else if (PLoc.getLine() != LastLocLine) {
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000636 OS << "line" << ':' << PLoc.getLine()
637 << ':' << PLoc.getColumn();
Chris Lattnerf1ca7d32009-01-27 07:57:44 +0000638 LastLocLine = PLoc.getLine();
Chris Lattner11e30d32007-08-30 06:17:34 +0000639 } else {
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000640 OS << "col" << ':' << PLoc.getColumn();
Chris Lattner11e30d32007-08-30 06:17:34 +0000641 }
642}
643
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000644void ASTDumper::dumpSourceRange(SourceRange R) {
Chris Lattner11e30d32007-08-30 06:17:34 +0000645 // Can't translate locations if a SourceManager isn't available.
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000646 if (!SM)
647 return;
Mike Stump11289f42009-09-09 15:08:12 +0000648
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000649 OS << " <";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000650 dumpLocation(R.getBegin());
Chris Lattnera7c19fe2007-10-16 22:36:42 +0000651 if (R.getBegin() != R.getEnd()) {
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000652 OS << ", ";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000653 dumpLocation(R.getEnd());
Chris Lattner11e30d32007-08-30 06:17:34 +0000654 }
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000655 OS << ">";
Mike Stump11289f42009-09-09 15:08:12 +0000656
Chris Lattner11e30d32007-08-30 06:17:34 +0000657 // <t2.c:123:421[blah], t2.c:412:321>
658
659}
660
Richard Smithd5e7ff82014-10-31 01:17:45 +0000661void ASTDumper::dumpBareType(QualType T, bool Desugar) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000662 ColorScope Color(*this, TypeColor);
Richard Smithd5e7ff82014-10-31 01:17:45 +0000663
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000664 SplitQualType T_split = T.split();
Aaron Ballman8c208282017-12-21 21:42:42 +0000665 OS << "'" << QualType::getAsString(T_split, PrintPolicy) << "'";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000666
Richard Smithd5e7ff82014-10-31 01:17:45 +0000667 if (Desugar && !T.isNull()) {
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000668 // If the type is sugared, also dump a (shallow) desugared type.
669 SplitQualType D_split = T.getSplitDesugaredType();
670 if (T_split != D_split)
Aaron Ballman8c208282017-12-21 21:42:42 +0000671 OS << ":'" << QualType::getAsString(D_split, PrintPolicy) << "'";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000672 }
673}
674
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000675void ASTDumper::dumpType(QualType T) {
676 OS << ' ';
677 dumpBareType(T);
678}
679
Richard Smithd5e7ff82014-10-31 01:17:45 +0000680void ASTDumper::dumpTypeAsChild(QualType T) {
681 SplitQualType SQT = T.split();
682 if (!SQT.Quals.hasQualifiers())
683 return dumpTypeAsChild(SQT.Ty);
684
685 dumpChild([=] {
686 OS << "QualType";
687 dumpPointer(T.getAsOpaquePtr());
688 OS << " ";
689 dumpBareType(T, false);
690 OS << " " << T.split().Quals.getAsString();
691 dumpTypeAsChild(T.split().Ty);
692 });
693}
694
695void ASTDumper::dumpTypeAsChild(const Type *T) {
696 dumpChild([=] {
697 if (!T) {
698 ColorScope Color(*this, NullColor);
699 OS << "<<<NULL>>>";
700 return;
701 }
Serge Pavlova6adc9e2015-12-28 17:19:12 +0000702 if (const LocInfoType *LIT = llvm::dyn_cast<LocInfoType>(T)) {
703 {
704 ColorScope Color(*this, TypeColor);
705 OS << "LocInfo Type";
706 }
707 dumpPointer(T);
708 dumpTypeAsChild(LIT->getTypeSourceInfo()->getType());
709 return;
710 }
Richard Smithd5e7ff82014-10-31 01:17:45 +0000711
712 {
713 ColorScope Color(*this, TypeColor);
714 OS << T->getTypeClassName() << "Type";
715 }
716 dumpPointer(T);
717 OS << " ";
718 dumpBareType(QualType(T, 0), false);
719
720 QualType SingleStepDesugar =
721 T->getLocallyUnqualifiedSingleStepDesugaredType();
722 if (SingleStepDesugar != QualType(T, 0))
723 OS << " sugar";
724 if (T->isDependentType())
725 OS << " dependent";
726 else if (T->isInstantiationDependentType())
727 OS << " instantiation_dependent";
728 if (T->isVariablyModifiedType())
729 OS << " variably_modified";
730 if (T->containsUnexpandedParameterPack())
731 OS << " contains_unexpanded_pack";
732 if (T->isFromAST())
733 OS << " imported";
734
735 TypeVisitor<ASTDumper>::Visit(T);
736
737 if (SingleStepDesugar != QualType(T, 0))
738 dumpTypeAsChild(SingleStepDesugar);
739 });
740}
741
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000742void ASTDumper::dumpBareDeclRef(const Decl *D) {
Richard Smith5179eb72016-06-28 19:03:57 +0000743 if (!D) {
744 ColorScope Color(*this, NullColor);
745 OS << "<<<NULL>>>";
746 return;
747 }
748
Richard Trieud215b8d2013-01-26 01:31:20 +0000749 {
750 ColorScope Color(*this, DeclKindNameColor);
751 OS << D->getDeclKindName();
752 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000753 dumpPointer(D);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000754
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000755 if (const NamedDecl *ND = dyn_cast<NamedDecl>(D)) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000756 ColorScope Color(*this, DeclNameColor);
David Blaikied4da8722013-05-14 21:04:00 +0000757 OS << " '" << ND->getDeclName() << '\'';
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000758 }
759
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000760 if (const ValueDecl *VD = dyn_cast<ValueDecl>(D))
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000761 dumpType(VD->getType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000762}
763
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000764void ASTDumper::dumpDeclRef(const Decl *D, const char *Label) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000765 if (!D)
766 return;
767
Richard Smithf7514452014-10-30 21:02:37 +0000768 dumpChild([=]{
769 if (Label)
770 OS << Label << ' ';
771 dumpBareDeclRef(D);
772 });
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000773}
774
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000775void ASTDumper::dumpName(const NamedDecl *ND) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000776 if (ND->getDeclName()) {
777 ColorScope Color(*this, DeclNameColor);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000778 OS << ' ' << ND->getNameAsString();
Richard Trieud215b8d2013-01-26 01:31:20 +0000779 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000780}
781
Richard Trieude5cc7d2013-01-31 01:44:26 +0000782bool ASTDumper::hasNodes(const DeclContext *DC) {
783 if (!DC)
784 return false;
785
Richard Smith1d209d02013-05-23 01:49:11 +0000786 return DC->hasExternalLexicalStorage() ||
Richard Smith3a36ac12017-03-09 22:00:01 +0000787 (Deserialize ? DC->decls_begin() != DC->decls_end()
788 : DC->noload_decls_begin() != DC->noload_decls_end());
Richard Trieude5cc7d2013-01-31 01:44:26 +0000789}
790
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000791void ASTDumper::dumpDeclContext(const DeclContext *DC) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000792 if (!DC)
793 return;
Richard Smithdcc2c452014-03-17 23:00:06 +0000794
Richard Smith3a36ac12017-03-09 22:00:01 +0000795 for (auto *D : (Deserialize ? DC->decls() : DC->noload_decls()))
Richard Smithf7514452014-10-30 21:02:37 +0000796 dumpDecl(D);
Richard Smithdcc2c452014-03-17 23:00:06 +0000797
798 if (DC->hasExternalLexicalStorage()) {
Richard Smithf7514452014-10-30 21:02:37 +0000799 dumpChild([=]{
800 ColorScope Color(*this, UndeserializedColor);
801 OS << "<undeserialized declarations>";
802 });
Richard Smith1d209d02013-05-23 01:49:11 +0000803 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000804}
805
Richard Smith35f986d2014-08-11 22:11:07 +0000806void ASTDumper::dumpLookups(const DeclContext *DC, bool DumpDecls) {
Richard Smithf7514452014-10-30 21:02:37 +0000807 dumpChild([=] {
808 OS << "StoredDeclsMap ";
809 dumpBareDeclRef(cast<Decl>(DC));
Richard Smith33937e72013-06-22 21:49:40 +0000810
Richard Smithf7514452014-10-30 21:02:37 +0000811 const DeclContext *Primary = DC->getPrimaryContext();
812 if (Primary != DC) {
813 OS << " primary";
814 dumpPointer(cast<Decl>(Primary));
Richard Smith33937e72013-06-22 21:49:40 +0000815 }
816
Richard Smithf7514452014-10-30 21:02:37 +0000817 bool HasUndeserializedLookups = Primary->hasExternalVisibleStorage();
Richard Smith35f986d2014-08-11 22:11:07 +0000818
Sam McCall091b1ef2018-01-16 12:33:46 +0000819 auto Range = Deserialize
820 ? Primary->lookups()
821 : Primary->noload_lookups(/*PreserveInternalState=*/true);
822 for (auto I = Range.begin(), E = Range.end(); I != E; ++I) {
Richard Smithf7514452014-10-30 21:02:37 +0000823 DeclarationName Name = I.getLookupName();
Richard Smith3a36ac12017-03-09 22:00:01 +0000824 DeclContextLookupResult R = *I;
Richard Smith35f986d2014-08-11 22:11:07 +0000825
Richard Smithf7514452014-10-30 21:02:37 +0000826 dumpChild([=] {
827 OS << "DeclarationName ";
828 {
829 ColorScope Color(*this, DeclNameColor);
830 OS << '\'' << Name << '\'';
831 }
Richard Smith35f986d2014-08-11 22:11:07 +0000832
Richard Smithf7514452014-10-30 21:02:37 +0000833 for (DeclContextLookupResult::iterator RI = R.begin(), RE = R.end();
834 RI != RE; ++RI) {
835 dumpChild([=] {
836 dumpBareDeclRef(*RI);
837
838 if ((*RI)->isHidden())
839 OS << " hidden";
840
841 // If requested, dump the redecl chain for this lookup.
842 if (DumpDecls) {
843 // Dump earliest decl first.
844 std::function<void(Decl *)> DumpWithPrev = [&](Decl *D) {
845 if (Decl *Prev = D->getPreviousDecl())
846 DumpWithPrev(Prev);
847 dumpDecl(D);
848 };
849 DumpWithPrev(*RI);
850 }
851 });
852 }
853 });
Richard Smith33937e72013-06-22 21:49:40 +0000854 }
Richard Smith33937e72013-06-22 21:49:40 +0000855
Richard Smithf7514452014-10-30 21:02:37 +0000856 if (HasUndeserializedLookups) {
857 dumpChild([=] {
858 ColorScope Color(*this, UndeserializedColor);
859 OS << "<undeserialized lookups>";
860 });
861 }
862 });
Richard Smith33937e72013-06-22 21:49:40 +0000863}
864
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000865void ASTDumper::dumpAttr(const Attr *A) {
Richard Smithf7514452014-10-30 21:02:37 +0000866 dumpChild([=] {
867 {
868 ColorScope Color(*this, AttrColor);
Aaron Ballman36a53502014-01-16 13:03:14 +0000869
Richard Smithf7514452014-10-30 21:02:37 +0000870 switch (A->getKind()) {
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000871#define ATTR(X) case attr::X: OS << #X; break;
872#include "clang/Basic/AttrList.inc"
Richard Smithf7514452014-10-30 21:02:37 +0000873 }
874 OS << "Attr";
Richard Trieud215b8d2013-01-26 01:31:20 +0000875 }
Richard Smithf7514452014-10-30 21:02:37 +0000876 dumpPointer(A);
877 dumpSourceRange(A->getRange());
878 if (A->isInherited())
879 OS << " Inherited";
880 if (A->isImplicit())
881 OS << " Implicit";
Hans Wennborgb0a8b4a2014-05-31 04:05:57 +0000882#include "clang/AST/AttrDump.inc"
Richard Smithf7514452014-10-30 21:02:37 +0000883 });
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000884}
885
Richard Smith71bec062013-10-15 21:58:30 +0000886static void dumpPreviousDeclImpl(raw_ostream &OS, ...) {}
887
888template<typename T>
889static void dumpPreviousDeclImpl(raw_ostream &OS, const Mergeable<T> *D) {
Rafael Espindola8db352d2013-10-17 15:37:26 +0000890 const T *First = D->getFirstDecl();
Richard Smith71bec062013-10-15 21:58:30 +0000891 if (First != D)
892 OS << " first " << First;
Richard Smithf5f43542013-02-07 01:35:44 +0000893}
894
895template<typename T>
Richard Smith71bec062013-10-15 21:58:30 +0000896static void dumpPreviousDeclImpl(raw_ostream &OS, const Redeclarable<T> *D) {
897 const T *Prev = D->getPreviousDecl();
898 if (Prev)
899 OS << " prev " << Prev;
Richard Smithf5f43542013-02-07 01:35:44 +0000900}
901
Richard Smith71bec062013-10-15 21:58:30 +0000902/// Dump the previous declaration in the redeclaration chain for a declaration,
903/// if any.
904static void dumpPreviousDecl(raw_ostream &OS, const Decl *D) {
Richard Smithf5f43542013-02-07 01:35:44 +0000905 switch (D->getKind()) {
906#define DECL(DERIVED, BASE) \
907 case Decl::DERIVED: \
Richard Smith71bec062013-10-15 21:58:30 +0000908 return dumpPreviousDeclImpl(OS, cast<DERIVED##Decl>(D));
Richard Smithf5f43542013-02-07 01:35:44 +0000909#define ABSTRACT_DECL(DECL)
910#include "clang/AST/DeclNodes.inc"
911 }
912 llvm_unreachable("Decl that isn't part of DeclNodes.inc!");
913}
914
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000915//===----------------------------------------------------------------------===//
916// C++ Utilities
917//===----------------------------------------------------------------------===//
918
919void ASTDumper::dumpAccessSpecifier(AccessSpecifier AS) {
920 switch (AS) {
921 case AS_none:
922 break;
923 case AS_public:
924 OS << "public";
925 break;
926 case AS_protected:
927 OS << "protected";
928 break;
929 case AS_private:
930 OS << "private";
931 break;
932 }
933}
934
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000935void ASTDumper::dumpCXXCtorInitializer(const CXXCtorInitializer *Init) {
Richard Smithf7514452014-10-30 21:02:37 +0000936 dumpChild([=] {
937 OS << "CXXCtorInitializer";
938 if (Init->isAnyMemberInitializer()) {
939 OS << ' ';
940 dumpBareDeclRef(Init->getAnyMember());
941 } else if (Init->isBaseInitializer()) {
942 dumpType(QualType(Init->getBaseClass(), 0));
943 } else if (Init->isDelegatingInitializer()) {
944 dumpType(Init->getTypeSourceInfo()->getType());
945 } else {
946 llvm_unreachable("Unknown initializer type");
947 }
948 dumpStmt(Init->getInit());
949 });
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000950}
951
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000952void ASTDumper::dumpTemplateParameters(const TemplateParameterList *TPL) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000953 if (!TPL)
954 return;
955
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000956 for (TemplateParameterList::const_iterator I = TPL->begin(), E = TPL->end();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000957 I != E; ++I)
958 dumpDecl(*I);
959}
960
961void ASTDumper::dumpTemplateArgumentListInfo(
962 const TemplateArgumentListInfo &TALI) {
Richard Smithf7514452014-10-30 21:02:37 +0000963 for (unsigned i = 0, e = TALI.size(); i < e; ++i)
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000964 dumpTemplateArgumentLoc(TALI[i]);
965}
966
967void ASTDumper::dumpTemplateArgumentLoc(const TemplateArgumentLoc &A) {
968 dumpTemplateArgument(A.getArgument(), A.getSourceRange());
969}
970
971void ASTDumper::dumpTemplateArgumentList(const TemplateArgumentList &TAL) {
972 for (unsigned i = 0, e = TAL.size(); i < e; ++i)
973 dumpTemplateArgument(TAL[i]);
974}
975
976void ASTDumper::dumpTemplateArgument(const TemplateArgument &A, SourceRange R) {
Richard Smithf7514452014-10-30 21:02:37 +0000977 dumpChild([=] {
978 OS << "TemplateArgument";
979 if (R.isValid())
980 dumpSourceRange(R);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000981
Richard Smithf7514452014-10-30 21:02:37 +0000982 switch (A.getKind()) {
983 case TemplateArgument::Null:
984 OS << " null";
985 break;
986 case TemplateArgument::Type:
987 OS << " type";
988 dumpType(A.getAsType());
989 break;
990 case TemplateArgument::Declaration:
991 OS << " decl";
992 dumpDeclRef(A.getAsDecl());
993 break;
994 case TemplateArgument::NullPtr:
995 OS << " nullptr";
996 break;
997 case TemplateArgument::Integral:
998 OS << " integral " << A.getAsIntegral();
999 break;
1000 case TemplateArgument::Template:
1001 OS << " template ";
1002 A.getAsTemplate().dump(OS);
1003 break;
1004 case TemplateArgument::TemplateExpansion:
Richard Trieu59c289f2018-08-21 22:55:26 +00001005 OS << " template expansion ";
Richard Smithf7514452014-10-30 21:02:37 +00001006 A.getAsTemplateOrTemplatePattern().dump(OS);
1007 break;
1008 case TemplateArgument::Expression:
1009 OS << " expr";
1010 dumpStmt(A.getAsExpr());
1011 break;
1012 case TemplateArgument::Pack:
1013 OS << " pack";
1014 for (TemplateArgument::pack_iterator I = A.pack_begin(), E = A.pack_end();
1015 I != E; ++I)
1016 dumpTemplateArgument(*I);
1017 break;
Richard Trieude5cc7d2013-01-31 01:44:26 +00001018 }
Richard Smithf7514452014-10-30 21:02:37 +00001019 });
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001020}
1021
Chris Lattner11e30d32007-08-30 06:17:34 +00001022//===----------------------------------------------------------------------===//
Douglas Gregor85f3f952015-07-07 03:57:15 +00001023// Objective-C Utilities
1024//===----------------------------------------------------------------------===//
1025void ASTDumper::dumpObjCTypeParamList(const ObjCTypeParamList *typeParams) {
1026 if (!typeParams)
1027 return;
1028
1029 for (auto typeParam : *typeParams) {
1030 dumpDecl(typeParam);
1031 }
1032}
1033
1034//===----------------------------------------------------------------------===//
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001035// Decl dumping methods.
Chris Lattnercbe4f772007-08-08 22:51:59 +00001036//===----------------------------------------------------------------------===//
1037
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001038void ASTDumper::dumpDecl(const Decl *D) {
Richard Smithf7514452014-10-30 21:02:37 +00001039 dumpChild([=] {
1040 if (!D) {
1041 ColorScope Color(*this, NullColor);
1042 OS << "<<<NULL>>>";
1043 return;
1044 }
Mike Stump11289f42009-09-09 15:08:12 +00001045
Richard Smithf7514452014-10-30 21:02:37 +00001046 {
1047 ColorScope Color(*this, DeclKindNameColor);
1048 OS << D->getDeclKindName() << "Decl";
1049 }
1050 dumpPointer(D);
1051 if (D->getLexicalDeclContext() != D->getDeclContext())
1052 OS << " parent " << cast<Decl>(D->getDeclContext());
1053 dumpPreviousDecl(OS, D);
1054 dumpSourceRange(D->getSourceRange());
1055 OS << ' ';
1056 dumpLocation(D->getLocation());
Richard Smith26342f92017-05-17 00:24:14 +00001057 if (D->isFromASTFile())
1058 OS << " imported";
1059 if (Module *M = D->getOwningModule())
Richard Smithf7514452014-10-30 21:02:37 +00001060 OS << " in " << M->getFullModuleName();
Richard Smitha2eb4092015-06-22 18:47:01 +00001061 if (auto *ND = dyn_cast<NamedDecl>(D))
1062 for (Module *M : D->getASTContext().getModulesWithMergedDefinition(
1063 const_cast<NamedDecl *>(ND)))
1064 dumpChild([=] { OS << "also in " << M->getFullModuleName(); });
Richard Smithf7514452014-10-30 21:02:37 +00001065 if (const NamedDecl *ND = dyn_cast<NamedDecl>(D))
1066 if (ND->isHidden())
1067 OS << " hidden";
1068 if (D->isImplicit())
1069 OS << " implicit";
1070 if (D->isUsed())
1071 OS << " used";
1072 else if (D->isThisDeclarationReferenced())
1073 OS << " referenced";
1074 if (D->isInvalidDecl())
1075 OS << " invalid";
Hans Wennborg76b00532014-12-05 22:38:57 +00001076 if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
1077 if (FD->isConstexpr())
1078 OS << " constexpr";
1079
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001080
Richard Smithf7514452014-10-30 21:02:37 +00001081 ConstDeclVisitor<ASTDumper>::Visit(D);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001082
Richard Smithf7514452014-10-30 21:02:37 +00001083 for (Decl::attr_iterator I = D->attr_begin(), E = D->attr_end(); I != E;
1084 ++I)
1085 dumpAttr(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001086
Richard Smithf7514452014-10-30 21:02:37 +00001087 if (const FullComment *Comment =
1088 D->getASTContext().getLocalCommentForDeclUncached(D))
1089 dumpFullComment(Comment);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001090
Richard Smithf7514452014-10-30 21:02:37 +00001091 // Decls within functions are visited by the body.
1092 if (!isa<FunctionDecl>(*D) && !isa<ObjCMethodDecl>(*D) &&
1093 hasNodes(dyn_cast<DeclContext>(D)))
1094 dumpDeclContext(cast<DeclContext>(D));
1095 });
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001096}
1097
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001098void ASTDumper::VisitLabelDecl(const LabelDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001099 dumpName(D);
1100}
1101
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001102void ASTDumper::VisitTypedefDecl(const TypedefDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001103 dumpName(D);
1104 dumpType(D->getUnderlyingType());
1105 if (D->isModulePrivate())
1106 OS << " __module_private__";
Richard Smithba3a4f92016-01-12 21:59:26 +00001107 dumpTypeAsChild(D->getUnderlyingType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001108}
1109
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001110void ASTDumper::VisitEnumDecl(const EnumDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001111 if (D->isScoped()) {
1112 if (D->isScopedUsingClassTag())
1113 OS << " class";
1114 else
1115 OS << " struct";
1116 }
1117 dumpName(D);
1118 if (D->isModulePrivate())
1119 OS << " __module_private__";
1120 if (D->isFixed())
1121 dumpType(D->getIntegerType());
1122}
1123
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001124void ASTDumper::VisitRecordDecl(const RecordDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001125 OS << ' ' << D->getKindName();
1126 dumpName(D);
1127 if (D->isModulePrivate())
1128 OS << " __module_private__";
Richard Smith99bc1b92013-08-30 05:32:29 +00001129 if (D->isCompleteDefinition())
1130 OS << " definition";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001131}
1132
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001133void ASTDumper::VisitEnumConstantDecl(const EnumConstantDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001134 dumpName(D);
1135 dumpType(D->getType());
Richard Smithf7514452014-10-30 21:02:37 +00001136 if (const Expr *Init = D->getInitExpr())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001137 dumpStmt(Init);
1138}
1139
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001140void ASTDumper::VisitIndirectFieldDecl(const IndirectFieldDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001141 dumpName(D);
1142 dumpType(D->getType());
Richard Smithdcc2c452014-03-17 23:00:06 +00001143
Richard Smith8aa49222014-03-18 00:35:12 +00001144 for (auto *Child : D->chain())
Richard Smithf7514452014-10-30 21:02:37 +00001145 dumpDeclRef(Child);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001146}
1147
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001148void ASTDumper::VisitFunctionDecl(const FunctionDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001149 dumpName(D);
1150 dumpType(D->getType());
1151
Rafael Espindola6ae7e502013-04-03 19:27:57 +00001152 StorageClass SC = D->getStorageClass();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001153 if (SC != SC_None)
1154 OS << ' ' << VarDecl::getStorageClassSpecifierString(SC);
1155 if (D->isInlineSpecified())
1156 OS << " inline";
1157 if (D->isVirtualAsWritten())
1158 OS << " virtual";
1159 if (D->isModulePrivate())
1160 OS << " __module_private__";
1161
1162 if (D->isPure())
1163 OS << " pure";
Richard Smith5a2e6b92016-11-21 23:43:54 +00001164 if (D->isDefaulted()) {
1165 OS << " default";
1166 if (D->isDeleted())
1167 OS << "_delete";
1168 }
1169 if (D->isDeletedAsWritten())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001170 OS << " delete";
Richard Smith5a2e6b92016-11-21 23:43:54 +00001171 if (D->isTrivial())
1172 OS << " trivial";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001173
Richard Smithadaa0152013-05-17 02:09:46 +00001174 if (const FunctionProtoType *FPT = D->getType()->getAs<FunctionProtoType>()) {
1175 FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo();
Richard Smith8acb4282014-07-31 21:57:55 +00001176 switch (EPI.ExceptionSpec.Type) {
Richard Smithadaa0152013-05-17 02:09:46 +00001177 default: break;
1178 case EST_Unevaluated:
Richard Smith8acb4282014-07-31 21:57:55 +00001179 OS << " noexcept-unevaluated " << EPI.ExceptionSpec.SourceDecl;
Richard Smithadaa0152013-05-17 02:09:46 +00001180 break;
1181 case EST_Uninstantiated:
Richard Smith8acb4282014-07-31 21:57:55 +00001182 OS << " noexcept-uninstantiated " << EPI.ExceptionSpec.SourceTemplate;
Richard Smithadaa0152013-05-17 02:09:46 +00001183 break;
1184 }
1185 }
1186
Richard Smithf7514452014-10-30 21:02:37 +00001187 if (const FunctionTemplateSpecializationInfo *FTSI =
1188 D->getTemplateSpecializationInfo())
Richard Trieude5cc7d2013-01-31 01:44:26 +00001189 dumpTemplateArgumentList(*FTSI->TemplateArguments);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001190
Richard Smith8a639892015-01-24 01:07:20 +00001191 if (!D->param_begin() && D->getNumParams())
1192 dumpChild([=] { OS << "<<NULL params x " << D->getNumParams() << ">>"; });
1193 else
David Majnemera3debed2016-06-24 05:33:44 +00001194 for (const ParmVarDecl *Parameter : D->parameters())
1195 dumpDecl(Parameter);
Richard Smithf7514452014-10-30 21:02:37 +00001196
1197 if (const CXXConstructorDecl *C = dyn_cast<CXXConstructorDecl>(D))
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001198 for (CXXConstructorDecl::init_const_iterator I = C->init_begin(),
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001199 E = C->init_end();
Richard Smithf7514452014-10-30 21:02:37 +00001200 I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001201 dumpCXXCtorInitializer(*I);
1202
Lenar Safin9ae21552017-07-29 20:42:58 +00001203 if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(D)) {
Lang Hames19e07e12017-06-20 21:06:00 +00001204 if (MD->size_overridden_methods() != 0) {
Aaron Ballman8c208282017-12-21 21:42:42 +00001205 auto dumpOverride = [=](const CXXMethodDecl *D) {
1206 SplitQualType T_split = D->getType().split();
1207 OS << D << " " << D->getParent()->getName()
1208 << "::" << D->getNameAsString() << " '"
1209 << QualType::getAsString(T_split, PrintPolicy) << "'";
1210 };
Lang Hames19e07e12017-06-20 21:06:00 +00001211
1212 dumpChild([=] {
Benjamin Krameracfa3392017-12-17 23:52:45 +00001213 auto Overrides = MD->overridden_methods();
Lang Hames19e07e12017-06-20 21:06:00 +00001214 OS << "Overrides: [ ";
Benjamin Krameracfa3392017-12-17 23:52:45 +00001215 dumpOverride(*Overrides.begin());
Lang Hames19e07e12017-06-20 21:06:00 +00001216 for (const auto *Override :
Benjamin Krameracfa3392017-12-17 23:52:45 +00001217 llvm::make_range(Overrides.begin() + 1, Overrides.end())) {
Lenar Safin9ae21552017-07-29 20:42:58 +00001218 OS << ", ";
Lang Hames19e07e12017-06-20 21:06:00 +00001219 dumpOverride(Override);
Lenar Safin9ae21552017-07-29 20:42:58 +00001220 }
Lang Hames19e07e12017-06-20 21:06:00 +00001221 OS << " ]";
1222 });
1223 }
Lenar Safin9ae21552017-07-29 20:42:58 +00001224 }
Lang Hames19e07e12017-06-20 21:06:00 +00001225
Richard Smithf7514452014-10-30 21:02:37 +00001226 if (D->doesThisDeclarationHaveABody())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001227 dumpStmt(D->getBody());
1228}
1229
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001230void ASTDumper::VisitFieldDecl(const FieldDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001231 dumpName(D);
1232 dumpType(D->getType());
1233 if (D->isMutable())
1234 OS << " mutable";
1235 if (D->isModulePrivate())
1236 OS << " __module_private__";
Richard Trieude5cc7d2013-01-31 01:44:26 +00001237
Richard Smithf7514452014-10-30 21:02:37 +00001238 if (D->isBitField())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001239 dumpStmt(D->getBitWidth());
Richard Smithf7514452014-10-30 21:02:37 +00001240 if (Expr *Init = D->getInClassInitializer())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001241 dumpStmt(Init);
1242}
1243
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001244void ASTDumper::VisitVarDecl(const VarDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001245 dumpName(D);
1246 dumpType(D->getType());
Rafael Espindola6ae7e502013-04-03 19:27:57 +00001247 StorageClass SC = D->getStorageClass();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001248 if (SC != SC_None)
1249 OS << ' ' << VarDecl::getStorageClassSpecifierString(SC);
Richard Smithfd3834f2013-04-13 02:43:54 +00001250 switch (D->getTLSKind()) {
1251 case VarDecl::TLS_None: break;
1252 case VarDecl::TLS_Static: OS << " tls"; break;
1253 case VarDecl::TLS_Dynamic: OS << " tls_dynamic"; break;
1254 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001255 if (D->isModulePrivate())
1256 OS << " __module_private__";
1257 if (D->isNRVOVariable())
1258 OS << " nrvo";
Richard Smith62f19e72016-06-25 00:15:56 +00001259 if (D->isInline())
1260 OS << " inline";
1261 if (D->isConstexpr())
1262 OS << " constexpr";
Richard Trieude5cc7d2013-01-31 01:44:26 +00001263 if (D->hasInit()) {
Richard Smithd9967cc2014-07-10 22:54:03 +00001264 switch (D->getInitStyle()) {
1265 case VarDecl::CInit: OS << " cinit"; break;
1266 case VarDecl::CallInit: OS << " callinit"; break;
1267 case VarDecl::ListInit: OS << " listinit"; break;
1268 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001269 dumpStmt(D->getInit());
Richard Trieude5cc7d2013-01-31 01:44:26 +00001270 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001271}
1272
Richard Smithbdb84f32016-07-22 23:36:59 +00001273void ASTDumper::VisitDecompositionDecl(const DecompositionDecl *D) {
1274 VisitVarDecl(D);
1275 for (auto *B : D->bindings())
1276 dumpDecl(B);
1277}
1278
Richard Smith7873de02016-08-11 22:25:46 +00001279void ASTDumper::VisitBindingDecl(const BindingDecl *D) {
1280 dumpName(D);
1281 dumpType(D->getType());
1282 if (auto *E = D->getBinding())
1283 dumpStmt(E);
1284}
1285
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001286void ASTDumper::VisitFileScopeAsmDecl(const FileScopeAsmDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001287 dumpStmt(D->getAsmString());
1288}
1289
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001290void ASTDumper::VisitImportDecl(const ImportDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001291 OS << ' ' << D->getImportedModule()->getFullModuleName();
1292}
1293
Nico Weber66220292016-03-02 17:28:48 +00001294void ASTDumper::VisitPragmaCommentDecl(const PragmaCommentDecl *D) {
1295 OS << ' ';
1296 switch (D->getCommentKind()) {
1297 case PCK_Unknown: llvm_unreachable("unexpected pragma comment kind");
1298 case PCK_Compiler: OS << "compiler"; break;
1299 case PCK_ExeStr: OS << "exestr"; break;
1300 case PCK_Lib: OS << "lib"; break;
1301 case PCK_Linker: OS << "linker"; break;
1302 case PCK_User: OS << "user"; break;
1303 }
1304 StringRef Arg = D->getArg();
1305 if (!Arg.empty())
1306 OS << " \"" << Arg << "\"";
1307}
1308
Nico Webercbbaeb12016-03-02 19:28:54 +00001309void ASTDumper::VisitPragmaDetectMismatchDecl(
1310 const PragmaDetectMismatchDecl *D) {
1311 OS << " \"" << D->getName() << "\" \"" << D->getValue() << "\"";
1312}
1313
Alexey Bataev958b9e72016-03-31 09:30:50 +00001314void ASTDumper::VisitCapturedDecl(const CapturedDecl *D) {
1315 dumpStmt(D->getBody());
1316}
1317
1318//===----------------------------------------------------------------------===//
1319// OpenMP Declarations
1320//===----------------------------------------------------------------------===//
1321
1322void ASTDumper::VisitOMPThreadPrivateDecl(const OMPThreadPrivateDecl *D) {
1323 for (auto *E : D->varlists())
1324 dumpStmt(E);
1325}
1326
1327void ASTDumper::VisitOMPDeclareReductionDecl(const OMPDeclareReductionDecl *D) {
1328 dumpName(D);
1329 dumpType(D->getType());
1330 OS << " combiner";
1331 dumpStmt(D->getCombiner());
1332 if (auto *Initializer = D->getInitializer()) {
1333 OS << " initializer";
Alexey Bataev070f43a2017-09-06 14:49:58 +00001334 switch (D->getInitializerKind()) {
1335 case OMPDeclareReductionDecl::DirectInit:
1336 OS << " omp_priv = ";
1337 break;
1338 case OMPDeclareReductionDecl::CopyInit:
1339 OS << " omp_priv ()";
1340 break;
1341 case OMPDeclareReductionDecl::CallInit:
1342 break;
1343 }
Alexey Bataev958b9e72016-03-31 09:30:50 +00001344 dumpStmt(Initializer);
1345 }
1346}
1347
Kelvin Li1408f912018-09-26 04:28:39 +00001348void ASTDumper::VisitOMPRequiresDecl(const OMPRequiresDecl *D) {
1349 for (auto *C : D->clauselists()) {
1350 dumpChild([=] {
1351 if (!C) {
1352 ColorScope Color(*this, NullColor);
1353 OS << "<<<NULL>>> OMPClause";
1354 return;
1355 }
1356 {
1357 ColorScope Color(*this, AttrColor);
1358 StringRef ClauseName(getOpenMPClauseName(C->getClauseKind()));
1359 OS << "OMP" << ClauseName.substr(/*Start=*/0, /*N=*/1).upper()
1360 << ClauseName.drop_front() << "Clause";
1361 }
1362 dumpPointer(C);
1363 dumpSourceRange(SourceRange(C->getBeginLoc(), C->getEndLoc()));
1364 });
1365 }
1366}
1367
Alexey Bataev958b9e72016-03-31 09:30:50 +00001368void ASTDumper::VisitOMPCapturedExprDecl(const OMPCapturedExprDecl *D) {
1369 dumpName(D);
1370 dumpType(D->getType());
1371 dumpStmt(D->getInit());
1372}
Nico Webercbbaeb12016-03-02 19:28:54 +00001373
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001374//===----------------------------------------------------------------------===//
1375// C++ Declarations
1376//===----------------------------------------------------------------------===//
1377
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001378void ASTDumper::VisitNamespaceDecl(const NamespaceDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001379 dumpName(D);
1380 if (D->isInline())
1381 OS << " inline";
1382 if (!D->isOriginalNamespace())
1383 dumpDeclRef(D->getOriginalNamespace(), "original");
1384}
1385
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001386void ASTDumper::VisitUsingDirectiveDecl(const UsingDirectiveDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001387 OS << ' ';
1388 dumpBareDeclRef(D->getNominatedNamespace());
1389}
1390
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001391void ASTDumper::VisitNamespaceAliasDecl(const NamespaceAliasDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001392 dumpName(D);
1393 dumpDeclRef(D->getAliasedNamespace());
1394}
1395
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001396void ASTDumper::VisitTypeAliasDecl(const TypeAliasDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001397 dumpName(D);
1398 dumpType(D->getUnderlyingType());
Richard Smithba3a4f92016-01-12 21:59:26 +00001399 dumpTypeAsChild(D->getUnderlyingType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001400}
1401
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001402void ASTDumper::VisitTypeAliasTemplateDecl(const TypeAliasTemplateDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001403 dumpName(D);
1404 dumpTemplateParameters(D->getTemplateParameters());
1405 dumpDecl(D->getTemplatedDecl());
1406}
1407
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001408void ASTDumper::VisitCXXRecordDecl(const CXXRecordDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001409 VisitRecordDecl(D);
1410 if (!D->isCompleteDefinition())
1411 return;
1412
Richard Smithdfc4bff2017-09-22 00:11:15 +00001413 dumpChild([=] {
1414 {
1415 ColorScope Color(*this, DeclKindNameColor);
1416 OS << "DefinitionData";
1417 }
1418#define FLAG(fn, name) if (D->fn()) OS << " " #name;
1419 FLAG(isParsingBaseSpecifiers, parsing_base_specifiers);
1420
1421 FLAG(isGenericLambda, generic);
1422 FLAG(isLambda, lambda);
1423
1424 FLAG(canPassInRegisters, pass_in_registers);
1425 FLAG(isEmpty, empty);
1426 FLAG(isAggregate, aggregate);
1427 FLAG(isStandardLayout, standard_layout);
1428 FLAG(isTriviallyCopyable, trivially_copyable);
1429 FLAG(isPOD, pod);
1430 FLAG(isTrivial, trivial);
1431 FLAG(isPolymorphic, polymorphic);
1432 FLAG(isAbstract, abstract);
1433 FLAG(isLiteral, literal);
1434
1435 FLAG(hasUserDeclaredConstructor, has_user_declared_ctor);
1436 FLAG(hasConstexprNonCopyMoveConstructor, has_constexpr_non_copy_move_ctor);
1437 FLAG(hasMutableFields, has_mutable_fields);
1438 FLAG(hasVariantMembers, has_variant_members);
1439 FLAG(allowConstDefaultInit, can_const_default_init);
1440
1441 dumpChild([=] {
1442 {
1443 ColorScope Color(*this, DeclKindNameColor);
1444 OS << "DefaultConstructor";
1445 }
1446 FLAG(hasDefaultConstructor, exists);
1447 FLAG(hasTrivialDefaultConstructor, trivial);
1448 FLAG(hasNonTrivialDefaultConstructor, non_trivial);
1449 FLAG(hasUserProvidedDefaultConstructor, user_provided);
1450 FLAG(hasConstexprDefaultConstructor, constexpr);
1451 FLAG(needsImplicitDefaultConstructor, needs_implicit);
1452 FLAG(defaultedDefaultConstructorIsConstexpr, defaulted_is_constexpr);
1453 });
1454
1455 dumpChild([=] {
1456 {
1457 ColorScope Color(*this, DeclKindNameColor);
1458 OS << "CopyConstructor";
1459 }
1460 FLAG(hasSimpleCopyConstructor, simple);
1461 FLAG(hasTrivialCopyConstructor, trivial);
1462 FLAG(hasNonTrivialCopyConstructor, non_trivial);
1463 FLAG(hasUserDeclaredCopyConstructor, user_declared);
1464 FLAG(hasCopyConstructorWithConstParam, has_const_param);
1465 FLAG(needsImplicitCopyConstructor, needs_implicit);
1466 FLAG(needsOverloadResolutionForCopyConstructor,
1467 needs_overload_resolution);
1468 if (!D->needsOverloadResolutionForCopyConstructor())
1469 FLAG(defaultedCopyConstructorIsDeleted, defaulted_is_deleted);
1470 FLAG(implicitCopyConstructorHasConstParam, implicit_has_const_param);
1471 });
1472
1473 dumpChild([=] {
1474 {
1475 ColorScope Color(*this, DeclKindNameColor);
1476 OS << "MoveConstructor";
1477 }
1478 FLAG(hasMoveConstructor, exists);
1479 FLAG(hasSimpleMoveConstructor, simple);
1480 FLAG(hasTrivialMoveConstructor, trivial);
1481 FLAG(hasNonTrivialMoveConstructor, non_trivial);
1482 FLAG(hasUserDeclaredMoveConstructor, user_declared);
1483 FLAG(needsImplicitMoveConstructor, needs_implicit);
1484 FLAG(needsOverloadResolutionForMoveConstructor,
1485 needs_overload_resolution);
1486 if (!D->needsOverloadResolutionForMoveConstructor())
1487 FLAG(defaultedMoveConstructorIsDeleted, defaulted_is_deleted);
1488 });
1489
1490 dumpChild([=] {
1491 {
1492 ColorScope Color(*this, DeclKindNameColor);
1493 OS << "CopyAssignment";
1494 }
1495 FLAG(hasTrivialCopyAssignment, trivial);
1496 FLAG(hasNonTrivialCopyAssignment, non_trivial);
1497 FLAG(hasCopyAssignmentWithConstParam, has_const_param);
1498 FLAG(hasUserDeclaredCopyAssignment, user_declared);
1499 FLAG(needsImplicitCopyAssignment, needs_implicit);
1500 FLAG(needsOverloadResolutionForCopyAssignment, needs_overload_resolution);
1501 FLAG(implicitCopyAssignmentHasConstParam, implicit_has_const_param);
1502 });
1503
1504 dumpChild([=] {
1505 {
1506 ColorScope Color(*this, DeclKindNameColor);
1507 OS << "MoveAssignment";
1508 }
1509 FLAG(hasMoveAssignment, exists);
1510 FLAG(hasSimpleMoveAssignment, simple);
1511 FLAG(hasTrivialMoveAssignment, trivial);
1512 FLAG(hasNonTrivialMoveAssignment, non_trivial);
1513 FLAG(hasUserDeclaredMoveAssignment, user_declared);
1514 FLAG(needsImplicitMoveAssignment, needs_implicit);
1515 FLAG(needsOverloadResolutionForMoveAssignment, needs_overload_resolution);
1516 });
1517
1518 dumpChild([=] {
1519 {
1520 ColorScope Color(*this, DeclKindNameColor);
1521 OS << "Destructor";
1522 }
1523 FLAG(hasSimpleDestructor, simple);
1524 FLAG(hasIrrelevantDestructor, irrelevant);
1525 FLAG(hasTrivialDestructor, trivial);
1526 FLAG(hasNonTrivialDestructor, non_trivial);
1527 FLAG(hasUserDeclaredDestructor, user_declared);
1528 FLAG(needsImplicitDestructor, needs_implicit);
1529 FLAG(needsOverloadResolutionForDestructor, needs_overload_resolution);
1530 if (!D->needsOverloadResolutionForDestructor())
1531 FLAG(defaultedDestructorIsDeleted, defaulted_is_deleted);
1532 });
1533 });
1534
Aaron Ballman574705e2014-03-13 15:41:46 +00001535 for (const auto &I : D->bases()) {
Richard Smithf7514452014-10-30 21:02:37 +00001536 dumpChild([=] {
1537 if (I.isVirtual())
1538 OS << "virtual ";
1539 dumpAccessSpecifier(I.getAccessSpecifier());
1540 dumpType(I.getType());
1541 if (I.isPackExpansion())
1542 OS << "...";
1543 });
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001544 }
1545}
1546
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001547void ASTDumper::VisitStaticAssertDecl(const StaticAssertDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001548 dumpStmt(D->getAssertExpr());
1549 dumpStmt(D->getMessage());
1550}
1551
Richard Smithcbdf7332014-03-18 02:07:28 +00001552template<typename SpecializationDecl>
Richard Smithf7514452014-10-30 21:02:37 +00001553void ASTDumper::VisitTemplateDeclSpecialization(const SpecializationDecl *D,
Richard Smithcbdf7332014-03-18 02:07:28 +00001554 bool DumpExplicitInst,
1555 bool DumpRefOnly) {
1556 bool DumpedAny = false;
1557 for (auto *RedeclWithBadType : D->redecls()) {
1558 // FIXME: The redecls() range sometimes has elements of a less-specific
1559 // type. (In particular, ClassTemplateSpecializationDecl::redecls() gives
1560 // us TagDecls, and should give CXXRecordDecls).
1561 auto *Redecl = dyn_cast<SpecializationDecl>(RedeclWithBadType);
1562 if (!Redecl) {
1563 // Found the injected-class-name for a class template. This will be dumped
1564 // as part of its surrounding class so we don't need to dump it here.
1565 assert(isa<CXXRecordDecl>(RedeclWithBadType) &&
1566 "expected an injected-class-name");
1567 continue;
1568 }
1569
1570 switch (Redecl->getTemplateSpecializationKind()) {
1571 case TSK_ExplicitInstantiationDeclaration:
1572 case TSK_ExplicitInstantiationDefinition:
1573 if (!DumpExplicitInst)
1574 break;
Adrian Prantlf3b3ccd2017-12-19 22:06:11 +00001575 LLVM_FALLTHROUGH;
Richard Smithcbdf7332014-03-18 02:07:28 +00001576 case TSK_Undeclared:
1577 case TSK_ImplicitInstantiation:
Richard Smithf7514452014-10-30 21:02:37 +00001578 if (DumpRefOnly)
1579 dumpDeclRef(Redecl);
1580 else
1581 dumpDecl(Redecl);
Richard Smithcbdf7332014-03-18 02:07:28 +00001582 DumpedAny = true;
1583 break;
1584 case TSK_ExplicitSpecialization:
1585 break;
1586 }
1587 }
1588
1589 // Ensure we dump at least one decl for each specialization.
1590 if (!DumpedAny)
Richard Smithf7514452014-10-30 21:02:37 +00001591 dumpDeclRef(D);
Richard Smithcbdf7332014-03-18 02:07:28 +00001592}
1593
Richard Smith20ade552014-03-17 23:34:53 +00001594template<typename TemplateDecl>
1595void ASTDumper::VisitTemplateDecl(const TemplateDecl *D,
1596 bool DumpExplicitInst) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001597 dumpName(D);
1598 dumpTemplateParameters(D->getTemplateParameters());
Richard Smithdcc2c452014-03-17 23:00:06 +00001599
Richard Smithf7514452014-10-30 21:02:37 +00001600 dumpDecl(D->getTemplatedDecl());
Richard Smithdcc2c452014-03-17 23:00:06 +00001601
Richard Smithcbdf7332014-03-18 02:07:28 +00001602 for (auto *Child : D->specializations())
Richard Smithf7514452014-10-30 21:02:37 +00001603 VisitTemplateDeclSpecialization(Child, DumpExplicitInst,
Richard Smithcbdf7332014-03-18 02:07:28 +00001604 !D->isCanonicalDecl());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001605}
1606
Richard Smith20ade552014-03-17 23:34:53 +00001607void ASTDumper::VisitFunctionTemplateDecl(const FunctionTemplateDecl *D) {
1608 // FIXME: We don't add a declaration of a function template specialization
1609 // to its context when it's explicitly instantiated, so dump explicit
1610 // instantiations when we dump the template itself.
1611 VisitTemplateDecl(D, true);
1612}
1613
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001614void ASTDumper::VisitClassTemplateDecl(const ClassTemplateDecl *D) {
Richard Smith20ade552014-03-17 23:34:53 +00001615 VisitTemplateDecl(D, false);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001616}
1617
1618void ASTDumper::VisitClassTemplateSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001619 const ClassTemplateSpecializationDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001620 VisitCXXRecordDecl(D);
1621 dumpTemplateArgumentList(D->getTemplateArgs());
1622}
1623
1624void ASTDumper::VisitClassTemplatePartialSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001625 const ClassTemplatePartialSpecializationDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001626 VisitClassTemplateSpecializationDecl(D);
1627 dumpTemplateParameters(D->getTemplateParameters());
1628}
1629
1630void ASTDumper::VisitClassScopeFunctionSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001631 const ClassScopeFunctionSpecializationDecl *D) {
Richard Smithc660c8f2018-03-16 13:36:56 +00001632 dumpDecl(D->getSpecialization());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001633 if (D->hasExplicitTemplateArgs())
1634 dumpTemplateArgumentListInfo(D->templateArgs());
1635}
1636
Richard Smithd25789a2013-09-18 01:36:02 +00001637void ASTDumper::VisitVarTemplateDecl(const VarTemplateDecl *D) {
Richard Smith20ade552014-03-17 23:34:53 +00001638 VisitTemplateDecl(D, false);
Richard Smithd25789a2013-09-18 01:36:02 +00001639}
1640
David Majnemerd9b1a4f2015-11-04 03:40:30 +00001641void ASTDumper::VisitBuiltinTemplateDecl(const BuiltinTemplateDecl *D) {
1642 dumpName(D);
1643 dumpTemplateParameters(D->getTemplateParameters());
1644}
1645
Richard Smithd25789a2013-09-18 01:36:02 +00001646void ASTDumper::VisitVarTemplateSpecializationDecl(
1647 const VarTemplateSpecializationDecl *D) {
1648 dumpTemplateArgumentList(D->getTemplateArgs());
1649 VisitVarDecl(D);
1650}
1651
1652void ASTDumper::VisitVarTemplatePartialSpecializationDecl(
1653 const VarTemplatePartialSpecializationDecl *D) {
1654 dumpTemplateParameters(D->getTemplateParameters());
1655 VisitVarTemplateSpecializationDecl(D);
1656}
1657
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001658void ASTDumper::VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001659 if (D->wasDeclaredWithTypename())
1660 OS << " typename";
1661 else
1662 OS << " class";
Richard Smith1832a022017-02-21 02:04:03 +00001663 OS << " depth " << D->getDepth() << " index " << D->getIndex();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001664 if (D->isParameterPack())
1665 OS << " ...";
1666 dumpName(D);
Richard Smithf7514452014-10-30 21:02:37 +00001667 if (D->hasDefaultArgument())
Richard Smithecf74ff2014-03-23 20:50:39 +00001668 dumpTemplateArgument(D->getDefaultArgument());
Richard Smithc4577662018-09-12 02:13:47 +00001669 if (auto *From = D->getDefaultArgStorage().getInheritedFrom())
1670 dumpDeclRef(From, D->defaultArgumentWasInherited() ? "inherited from"
1671 : "previous");
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001672}
1673
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001674void ASTDumper::VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001675 dumpType(D->getType());
Richard Smith1832a022017-02-21 02:04:03 +00001676 OS << " depth " << D->getDepth() << " index " << D->getIndex();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001677 if (D->isParameterPack())
1678 OS << " ...";
1679 dumpName(D);
Richard Smithf7514452014-10-30 21:02:37 +00001680 if (D->hasDefaultArgument())
Richard Smithecf74ff2014-03-23 20:50:39 +00001681 dumpTemplateArgument(D->getDefaultArgument());
Richard Smithc4577662018-09-12 02:13:47 +00001682 if (auto *From = D->getDefaultArgStorage().getInheritedFrom())
1683 dumpDeclRef(From, D->defaultArgumentWasInherited() ? "inherited from"
1684 : "previous");
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001685}
1686
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001687void ASTDumper::VisitTemplateTemplateParmDecl(
1688 const TemplateTemplateParmDecl *D) {
Richard Smith1832a022017-02-21 02:04:03 +00001689 OS << " depth " << D->getDepth() << " index " << D->getIndex();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001690 if (D->isParameterPack())
1691 OS << " ...";
1692 dumpName(D);
1693 dumpTemplateParameters(D->getTemplateParameters());
Richard Smithf7514452014-10-30 21:02:37 +00001694 if (D->hasDefaultArgument())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001695 dumpTemplateArgumentLoc(D->getDefaultArgument());
Richard Smithc4577662018-09-12 02:13:47 +00001696 if (auto *From = D->getDefaultArgStorage().getInheritedFrom())
1697 dumpDeclRef(From, D->defaultArgumentWasInherited() ? "inherited from"
1698 : "previous");
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001699}
1700
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001701void ASTDumper::VisitUsingDecl(const UsingDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001702 OS << ' ';
Dawn Perchikddd03bf2015-12-05 22:37:55 +00001703 if (D->getQualifier())
1704 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001705 OS << D->getNameAsString();
1706}
1707
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001708void ASTDumper::VisitUnresolvedUsingTypenameDecl(
1709 const UnresolvedUsingTypenameDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001710 OS << ' ';
Dawn Perchikddd03bf2015-12-05 22:37:55 +00001711 if (D->getQualifier())
1712 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001713 OS << D->getNameAsString();
1714}
1715
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001716void ASTDumper::VisitUnresolvedUsingValueDecl(const UnresolvedUsingValueDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001717 OS << ' ';
Dawn Perchikddd03bf2015-12-05 22:37:55 +00001718 if (D->getQualifier())
1719 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001720 OS << D->getNameAsString();
1721 dumpType(D->getType());
1722}
1723
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001724void ASTDumper::VisitUsingShadowDecl(const UsingShadowDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001725 OS << ' ';
1726 dumpBareDeclRef(D->getTargetDecl());
Richard Smithba3a4f92016-01-12 21:59:26 +00001727 if (auto *TD = dyn_cast<TypeDecl>(D->getUnderlyingDecl()))
1728 dumpTypeAsChild(TD->getTypeForDecl());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001729}
1730
Richard Smith5179eb72016-06-28 19:03:57 +00001731void ASTDumper::VisitConstructorUsingShadowDecl(
1732 const ConstructorUsingShadowDecl *D) {
1733 if (D->constructsVirtualBase())
1734 OS << " virtual";
1735
1736 dumpChild([=] {
1737 OS << "target ";
1738 dumpBareDeclRef(D->getTargetDecl());
1739 });
1740
1741 dumpChild([=] {
1742 OS << "nominated ";
1743 dumpBareDeclRef(D->getNominatedBaseClass());
1744 OS << ' ';
1745 dumpBareDeclRef(D->getNominatedBaseClassShadowDecl());
1746 });
1747
1748 dumpChild([=] {
1749 OS << "constructed ";
1750 dumpBareDeclRef(D->getConstructedBaseClass());
1751 OS << ' ';
1752 dumpBareDeclRef(D->getConstructedBaseClassShadowDecl());
1753 });
1754}
1755
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001756void ASTDumper::VisitLinkageSpecDecl(const LinkageSpecDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001757 switch (D->getLanguage()) {
1758 case LinkageSpecDecl::lang_c: OS << " C"; break;
1759 case LinkageSpecDecl::lang_cxx: OS << " C++"; break;
1760 }
1761}
1762
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001763void ASTDumper::VisitAccessSpecDecl(const AccessSpecDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001764 OS << ' ';
1765 dumpAccessSpecifier(D->getAccess());
1766}
1767
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001768void ASTDumper::VisitFriendDecl(const FriendDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001769 if (TypeSourceInfo *T = D->getFriendType())
1770 dumpType(T->getType());
1771 else
1772 dumpDecl(D->getFriendDecl());
1773}
1774
1775//===----------------------------------------------------------------------===//
1776// Obj-C Declarations
1777//===----------------------------------------------------------------------===//
1778
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001779void ASTDumper::VisitObjCIvarDecl(const ObjCIvarDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001780 dumpName(D);
1781 dumpType(D->getType());
1782 if (D->getSynthesize())
1783 OS << " synthesize";
1784
1785 switch (D->getAccessControl()) {
1786 case ObjCIvarDecl::None:
1787 OS << " none";
1788 break;
1789 case ObjCIvarDecl::Private:
1790 OS << " private";
1791 break;
1792 case ObjCIvarDecl::Protected:
1793 OS << " protected";
1794 break;
1795 case ObjCIvarDecl::Public:
1796 OS << " public";
1797 break;
1798 case ObjCIvarDecl::Package:
1799 OS << " package";
1800 break;
1801 }
1802}
1803
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001804void ASTDumper::VisitObjCMethodDecl(const ObjCMethodDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001805 if (D->isInstanceMethod())
1806 OS << " -";
1807 else
1808 OS << " +";
1809 dumpName(D);
Alp Toker314cc812014-01-25 16:55:45 +00001810 dumpType(D->getReturnType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001811
Richard Trieude5cc7d2013-01-31 01:44:26 +00001812 if (D->isThisDeclarationADefinition()) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001813 dumpDeclContext(D);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001814 } else {
David Majnemera3debed2016-06-24 05:33:44 +00001815 for (const ParmVarDecl *Parameter : D->parameters())
1816 dumpDecl(Parameter);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001817 }
1818
Richard Smithf7514452014-10-30 21:02:37 +00001819 if (D->isVariadic())
1820 dumpChild([=] { OS << "..."; });
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001821
Richard Smithf7514452014-10-30 21:02:37 +00001822 if (D->hasBody())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001823 dumpStmt(D->getBody());
1824}
1825
Douglas Gregor85f3f952015-07-07 03:57:15 +00001826void ASTDumper::VisitObjCTypeParamDecl(const ObjCTypeParamDecl *D) {
1827 dumpName(D);
Douglas Gregor1ac1b632015-07-07 03:58:54 +00001828 switch (D->getVariance()) {
1829 case ObjCTypeParamVariance::Invariant:
1830 break;
1831
1832 case ObjCTypeParamVariance::Covariant:
1833 OS << " covariant";
1834 break;
1835
1836 case ObjCTypeParamVariance::Contravariant:
1837 OS << " contravariant";
1838 break;
1839 }
1840
Douglas Gregor85f3f952015-07-07 03:57:15 +00001841 if (D->hasExplicitBound())
1842 OS << " bounded";
1843 dumpType(D->getUnderlyingType());
1844}
1845
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001846void ASTDumper::VisitObjCCategoryDecl(const ObjCCategoryDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001847 dumpName(D);
1848 dumpDeclRef(D->getClassInterface());
Douglas Gregor85f3f952015-07-07 03:57:15 +00001849 dumpObjCTypeParamList(D->getTypeParamList());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001850 dumpDeclRef(D->getImplementation());
1851 for (ObjCCategoryDecl::protocol_iterator I = D->protocol_begin(),
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001852 E = D->protocol_end();
Richard Smithf7514452014-10-30 21:02:37 +00001853 I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001854 dumpDeclRef(*I);
1855}
1856
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001857void ASTDumper::VisitObjCCategoryImplDecl(const ObjCCategoryImplDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001858 dumpName(D);
1859 dumpDeclRef(D->getClassInterface());
1860 dumpDeclRef(D->getCategoryDecl());
1861}
1862
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001863void ASTDumper::VisitObjCProtocolDecl(const ObjCProtocolDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001864 dumpName(D);
Richard Smithdcc2c452014-03-17 23:00:06 +00001865
Richard Smith7fcb35f2014-03-18 02:37:59 +00001866 for (auto *Child : D->protocols())
Richard Smithf7514452014-10-30 21:02:37 +00001867 dumpDeclRef(Child);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001868}
1869
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001870void ASTDumper::VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001871 dumpName(D);
Douglas Gregor85f3f952015-07-07 03:57:15 +00001872 dumpObjCTypeParamList(D->getTypeParamListAsWritten());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001873 dumpDeclRef(D->getSuperClass(), "super");
Richard Smithdcc2c452014-03-17 23:00:06 +00001874
Richard Smithf7514452014-10-30 21:02:37 +00001875 dumpDeclRef(D->getImplementation());
Richard Smith7fcb35f2014-03-18 02:37:59 +00001876 for (auto *Child : D->protocols())
Richard Smithf7514452014-10-30 21:02:37 +00001877 dumpDeclRef(Child);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001878}
1879
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001880void ASTDumper::VisitObjCImplementationDecl(const ObjCImplementationDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001881 dumpName(D);
1882 dumpDeclRef(D->getSuperClass(), "super");
1883 dumpDeclRef(D->getClassInterface());
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001884 for (ObjCImplementationDecl::init_const_iterator I = D->init_begin(),
1885 E = D->init_end();
Richard Smithf7514452014-10-30 21:02:37 +00001886 I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001887 dumpCXXCtorInitializer(*I);
1888}
1889
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001890void ASTDumper::VisitObjCCompatibleAliasDecl(const ObjCCompatibleAliasDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001891 dumpName(D);
1892 dumpDeclRef(D->getClassInterface());
1893}
1894
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001895void ASTDumper::VisitObjCPropertyDecl(const ObjCPropertyDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001896 dumpName(D);
1897 dumpType(D->getType());
1898
1899 if (D->getPropertyImplementation() == ObjCPropertyDecl::Required)
1900 OS << " required";
1901 else if (D->getPropertyImplementation() == ObjCPropertyDecl::Optional)
1902 OS << " optional";
1903
1904 ObjCPropertyDecl::PropertyAttributeKind Attrs = D->getPropertyAttributes();
1905 if (Attrs != ObjCPropertyDecl::OBJC_PR_noattr) {
1906 if (Attrs & ObjCPropertyDecl::OBJC_PR_readonly)
1907 OS << " readonly";
1908 if (Attrs & ObjCPropertyDecl::OBJC_PR_assign)
1909 OS << " assign";
1910 if (Attrs & ObjCPropertyDecl::OBJC_PR_readwrite)
1911 OS << " readwrite";
1912 if (Attrs & ObjCPropertyDecl::OBJC_PR_retain)
1913 OS << " retain";
1914 if (Attrs & ObjCPropertyDecl::OBJC_PR_copy)
1915 OS << " copy";
1916 if (Attrs & ObjCPropertyDecl::OBJC_PR_nonatomic)
1917 OS << " nonatomic";
1918 if (Attrs & ObjCPropertyDecl::OBJC_PR_atomic)
1919 OS << " atomic";
1920 if (Attrs & ObjCPropertyDecl::OBJC_PR_weak)
1921 OS << " weak";
1922 if (Attrs & ObjCPropertyDecl::OBJC_PR_strong)
1923 OS << " strong";
1924 if (Attrs & ObjCPropertyDecl::OBJC_PR_unsafe_unretained)
1925 OS << " unsafe_unretained";
Manman Ren387ff7f2016-01-26 18:52:43 +00001926 if (Attrs & ObjCPropertyDecl::OBJC_PR_class)
1927 OS << " class";
Richard Smithf7514452014-10-30 21:02:37 +00001928 if (Attrs & ObjCPropertyDecl::OBJC_PR_getter)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001929 dumpDeclRef(D->getGetterMethodDecl(), "getter");
Richard Smithf7514452014-10-30 21:02:37 +00001930 if (Attrs & ObjCPropertyDecl::OBJC_PR_setter)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001931 dumpDeclRef(D->getSetterMethodDecl(), "setter");
1932 }
1933}
1934
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001935void ASTDumper::VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001936 dumpName(D->getPropertyDecl());
1937 if (D->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize)
1938 OS << " synthesize";
1939 else
1940 OS << " dynamic";
1941 dumpDeclRef(D->getPropertyDecl());
1942 dumpDeclRef(D->getPropertyIvarDecl());
1943}
1944
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001945void ASTDumper::VisitBlockDecl(const BlockDecl *D) {
David Majnemer59f77922016-06-24 04:05:48 +00001946 for (auto I : D->parameters())
Aaron Ballmanb2b8b1d2014-03-07 16:09:59 +00001947 dumpDecl(I);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001948
Richard Smithf7514452014-10-30 21:02:37 +00001949 if (D->isVariadic())
1950 dumpChild([=]{ OS << "..."; });
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001951
Richard Smithf7514452014-10-30 21:02:37 +00001952 if (D->capturesCXXThis())
1953 dumpChild([=]{ OS << "capture this"; });
1954
Aaron Ballman9371dd22014-03-14 18:34:04 +00001955 for (const auto &I : D->captures()) {
Richard Smithf7514452014-10-30 21:02:37 +00001956 dumpChild([=] {
1957 OS << "capture";
1958 if (I.isByRef())
1959 OS << " byref";
1960 if (I.isNested())
1961 OS << " nested";
1962 if (I.getVariable()) {
1963 OS << ' ';
1964 dumpBareDeclRef(I.getVariable());
1965 }
1966 if (I.hasCopyExpr())
1967 dumpStmt(I.getCopyExpr());
1968 });
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001969 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001970 dumpStmt(D->getBody());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001971}
1972
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001973//===----------------------------------------------------------------------===//
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001974// Stmt dumping methods.
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001975//===----------------------------------------------------------------------===//
1976
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001977void ASTDumper::dumpStmt(const Stmt *S) {
Richard Smithf7514452014-10-30 21:02:37 +00001978 dumpChild([=] {
1979 if (!S) {
1980 ColorScope Color(*this, NullColor);
1981 OS << "<<<NULL>>>";
1982 return;
1983 }
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001984
Richard Smith01ccebf2018-01-05 21:31:07 +00001985 // Some statements have custom mechanisms for dumping their children.
Richard Smithf7514452014-10-30 21:02:37 +00001986 if (const DeclStmt *DS = dyn_cast<DeclStmt>(S)) {
1987 VisitDeclStmt(DS);
1988 return;
1989 }
Richard Smith01ccebf2018-01-05 21:31:07 +00001990 if (const GenericSelectionExpr *GSE = dyn_cast<GenericSelectionExpr>(S)) {
1991 VisitGenericSelectionExpr(GSE);
1992 return;
1993 }
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001994
Richard Smithf7514452014-10-30 21:02:37 +00001995 ConstStmtVisitor<ASTDumper>::Visit(S);
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001996
Benjamin Kramer642f1732015-07-02 21:03:14 +00001997 for (const Stmt *SubStmt : S->children())
1998 dumpStmt(SubStmt);
Richard Smithf7514452014-10-30 21:02:37 +00001999 });
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002000}
2001
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002002void ASTDumper::VisitStmt(const Stmt *Node) {
Fangrui Song6907ce22018-07-30 19:24:48 +00002003 {
Richard Trieud215b8d2013-01-26 01:31:20 +00002004 ColorScope Color(*this, StmtColor);
2005 OS << Node->getStmtClassName();
2006 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002007 dumpPointer(Node);
2008 dumpSourceRange(Node->getSourceRange());
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002009}
2010
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002011void ASTDumper::VisitDeclStmt(const DeclStmt *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002012 VisitStmt(Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002013 for (DeclStmt::const_decl_iterator I = Node->decl_begin(),
2014 E = Node->decl_end();
Richard Smithf7514452014-10-30 21:02:37 +00002015 I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002016 dumpDecl(*I);
Ted Kremenek433a4922007-12-12 06:59:42 +00002017}
2018
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002019void ASTDumper::VisitAttributedStmt(const AttributedStmt *Node) {
Alexander Kornienko5bc364e2013-01-07 17:53:08 +00002020 VisitStmt(Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002021 for (ArrayRef<const Attr *>::iterator I = Node->getAttrs().begin(),
2022 E = Node->getAttrs().end();
Richard Smithf7514452014-10-30 21:02:37 +00002023 I != E; ++I)
Alexander Kornienko5bc364e2013-01-07 17:53:08 +00002024 dumpAttr(*I);
2025}
2026
Bruno Riccib1cc94b2018-10-27 21:12:20 +00002027void ASTDumper::VisitIfStmt(const IfStmt *Node) {
2028 VisitStmt(Node);
2029 if (Node->hasInitStorage())
2030 OS << " has_init";
2031 if (Node->hasVarStorage())
2032 OS << " has_var";
2033 if (Node->hasElseStorage())
2034 OS << " has_else";
2035}
2036
Bruno Riccie2806f82018-10-29 16:12:37 +00002037void ASTDumper::VisitSwitchStmt(const SwitchStmt *Node) {
2038 VisitStmt(Node);
2039 if (Node->hasInitStorage())
2040 OS << " has_init";
2041 if (Node->hasVarStorage())
2042 OS << " has_var";
2043}
2044
Bruno Riccibacf7512018-10-30 13:42:41 +00002045void ASTDumper::VisitWhileStmt(const WhileStmt *Node) {
2046 VisitStmt(Node);
2047 if (Node->hasVarStorage())
2048 OS << " has_var";
2049}
2050
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002051void ASTDumper::VisitLabelStmt(const LabelStmt *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002052 VisitStmt(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002053 OS << " '" << Node->getName() << "'";
Chris Lattnercbe4f772007-08-08 22:51:59 +00002054}
2055
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002056void ASTDumper::VisitGotoStmt(const GotoStmt *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002057 VisitStmt(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002058 OS << " '" << Node->getLabel()->getName() << "'";
2059 dumpPointer(Node->getLabel());
Chris Lattnercbe4f772007-08-08 22:51:59 +00002060}
2061
Pavel Labath1ef83422013-09-04 14:35:00 +00002062void ASTDumper::VisitCXXCatchStmt(const CXXCatchStmt *Node) {
2063 VisitStmt(Node);
2064 dumpDecl(Node->getExceptionDecl());
2065}
2066
Bruno Ricci5b30571752018-10-28 12:30:53 +00002067void ASTDumper::VisitCaseStmt(const CaseStmt *Node) {
2068 VisitStmt(Node);
2069 if (Node->caseStmtIsGNURange())
2070 OS << " gnu_range";
2071}
2072
Alexey Bataev958b9e72016-03-31 09:30:50 +00002073void ASTDumper::VisitCapturedStmt(const CapturedStmt *Node) {
2074 VisitStmt(Node);
2075 dumpDecl(Node->getCapturedDecl());
2076}
2077
2078//===----------------------------------------------------------------------===//
2079// OpenMP dumping methods.
2080//===----------------------------------------------------------------------===//
2081
2082void ASTDumper::VisitOMPExecutableDirective(
2083 const OMPExecutableDirective *Node) {
2084 VisitStmt(Node);
2085 for (auto *C : Node->clauses()) {
2086 dumpChild([=] {
2087 if (!C) {
2088 ColorScope Color(*this, NullColor);
2089 OS << "<<<NULL>>> OMPClause";
2090 return;
2091 }
2092 {
2093 ColorScope Color(*this, AttrColor);
2094 StringRef ClauseName(getOpenMPClauseName(C->getClauseKind()));
2095 OS << "OMP" << ClauseName.substr(/*Start=*/0, /*N=*/1).upper()
2096 << ClauseName.drop_front() << "Clause";
2097 }
2098 dumpPointer(C);
Stephen Kelly1c301dc2018-08-09 21:09:38 +00002099 dumpSourceRange(SourceRange(C->getBeginLoc(), C->getEndLoc()));
Alexey Bataev958b9e72016-03-31 09:30:50 +00002100 if (C->isImplicit())
2101 OS << " <implicit>";
2102 for (auto *S : C->children())
2103 dumpStmt(S);
2104 });
2105 }
2106}
2107
Chris Lattnercbe4f772007-08-08 22:51:59 +00002108//===----------------------------------------------------------------------===//
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002109// Expr dumping methods.
Chris Lattnercbe4f772007-08-08 22:51:59 +00002110//===----------------------------------------------------------------------===//
2111
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002112void ASTDumper::VisitExpr(const Expr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002113 VisitStmt(Node);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002114 dumpType(Node->getType());
2115
Richard Trieud215b8d2013-01-26 01:31:20 +00002116 {
2117 ColorScope Color(*this, ValueKindColor);
2118 switch (Node->getValueKind()) {
2119 case VK_RValue:
2120 break;
2121 case VK_LValue:
2122 OS << " lvalue";
2123 break;
2124 case VK_XValue:
2125 OS << " xvalue";
2126 break;
2127 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002128 }
2129
Richard Trieud215b8d2013-01-26 01:31:20 +00002130 {
2131 ColorScope Color(*this, ObjectKindColor);
2132 switch (Node->getObjectKind()) {
2133 case OK_Ordinary:
2134 break;
2135 case OK_BitField:
2136 OS << " bitfield";
2137 break;
2138 case OK_ObjCProperty:
2139 OS << " objcproperty";
2140 break;
2141 case OK_ObjCSubscript:
2142 OS << " objcsubscript";
2143 break;
2144 case OK_VectorComponent:
2145 OS << " vectorcomponent";
2146 break;
2147 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002148 }
Chris Lattnercbe4f772007-08-08 22:51:59 +00002149}
2150
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002151static void dumpBasePath(raw_ostream &OS, const CastExpr *Node) {
John McCallcf142162010-08-07 06:22:56 +00002152 if (Node->path_empty())
Anders Carlssona70cff62010-04-24 19:06:50 +00002153 return;
2154
2155 OS << " (";
2156 bool First = true;
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002157 for (CastExpr::path_const_iterator I = Node->path_begin(),
2158 E = Node->path_end();
2159 I != E; ++I) {
Anders Carlssona70cff62010-04-24 19:06:50 +00002160 const CXXBaseSpecifier *Base = *I;
2161 if (!First)
2162 OS << " -> ";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002163
Anders Carlssona70cff62010-04-24 19:06:50 +00002164 const CXXRecordDecl *RD =
2165 cast<CXXRecordDecl>(Base->getType()->getAs<RecordType>()->getDecl());
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002166
Anders Carlssona70cff62010-04-24 19:06:50 +00002167 if (Base->isVirtual())
2168 OS << "virtual ";
2169 OS << RD->getName();
2170 First = false;
2171 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002172
Anders Carlssona70cff62010-04-24 19:06:50 +00002173 OS << ')';
2174}
2175
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002176void ASTDumper::VisitCastExpr(const CastExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002177 VisitExpr(Node);
Richard Trieud215b8d2013-01-26 01:31:20 +00002178 OS << " <";
2179 {
2180 ColorScope Color(*this, CastColor);
2181 OS << Node->getCastKindName();
2182 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002183 dumpBasePath(OS, Node);
Anders Carlssona70cff62010-04-24 19:06:50 +00002184 OS << ">";
Roman Lebedev12216f12018-07-27 07:27:14 +00002185}
Roman Lebedevd55661d2018-07-24 08:16:50 +00002186
Roman Lebedev12216f12018-07-27 07:27:14 +00002187void ASTDumper::VisitImplicitCastExpr(const ImplicitCastExpr *Node) {
2188 VisitCastExpr(Node);
2189 if (Node->isPartOfExplicitCast())
Roman Lebedevd55661d2018-07-24 08:16:50 +00002190 OS << " part_of_explicit_cast";
Anders Carlssond7923c62009-08-22 23:33:40 +00002191}
2192
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002193void ASTDumper::VisitDeclRefExpr(const DeclRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002194 VisitExpr(Node);
Ted Kremenek5f64ca82007-09-10 17:32:55 +00002195
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002196 OS << " ";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002197 dumpBareDeclRef(Node->getDecl());
Chandler Carruth8d26bb02011-05-01 23:48:14 +00002198 if (Node->getDecl() != Node->getFoundDecl()) {
2199 OS << " (";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002200 dumpBareDeclRef(Node->getFoundDecl());
Chandler Carruth8d26bb02011-05-01 23:48:14 +00002201 OS << ")";
2202 }
John McCall351762c2011-02-07 10:33:21 +00002203}
2204
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002205void ASTDumper::VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002206 VisitExpr(Node);
John McCall76d09942009-12-11 21:50:11 +00002207 OS << " (";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002208 if (!Node->requiresADL())
2209 OS << "no ";
Benjamin Kramerb11416d2010-04-17 09:33:03 +00002210 OS << "ADL) = '" << Node->getName() << '\'';
John McCall76d09942009-12-11 21:50:11 +00002211
2212 UnresolvedLookupExpr::decls_iterator
2213 I = Node->decls_begin(), E = Node->decls_end();
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002214 if (I == E)
2215 OS << " empty";
John McCall76d09942009-12-11 21:50:11 +00002216 for (; I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002217 dumpPointer(*I);
John McCall76d09942009-12-11 21:50:11 +00002218}
2219
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002220void ASTDumper::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002221 VisitExpr(Node);
Steve Naroff5d5efca2008-03-12 13:19:12 +00002222
Richard Trieud215b8d2013-01-26 01:31:20 +00002223 {
2224 ColorScope Color(*this, DeclKindNameColor);
2225 OS << " " << Node->getDecl()->getDeclKindName() << "Decl";
2226 }
2227 OS << "='" << *Node->getDecl() << "'";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002228 dumpPointer(Node->getDecl());
Steve Naroffb3424a92008-05-23 22:01:24 +00002229 if (Node->isFreeIvar())
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002230 OS << " isFreeIvar";
Steve Naroff5d5efca2008-03-12 13:19:12 +00002231}
2232
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002233void ASTDumper::VisitPredefinedExpr(const PredefinedExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002234 VisitExpr(Node);
Bruno Ricci17ff0262018-10-27 19:21:19 +00002235 OS << " " << PredefinedExpr::getIdentKindName(Node->getIdentKind());
Chris Lattnercbe4f772007-08-08 22:51:59 +00002236}
2237
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002238void ASTDumper::VisitCharacterLiteral(const CharacterLiteral *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002239 VisitExpr(Node);
Richard Trieud215b8d2013-01-26 01:31:20 +00002240 ColorScope Color(*this, ValueColor);
Richard Trieu364ee422011-11-03 23:56:23 +00002241 OS << " " << Node->getValue();
Chris Lattnercbe4f772007-08-08 22:51:59 +00002242}
2243
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002244void ASTDumper::VisitIntegerLiteral(const IntegerLiteral *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002245 VisitExpr(Node);
Chris Lattnercbe4f772007-08-08 22:51:59 +00002246
2247 bool isSigned = Node->getType()->isSignedIntegerType();
Richard Trieud215b8d2013-01-26 01:31:20 +00002248 ColorScope Color(*this, ValueColor);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002249 OS << " " << Node->getValue().toString(10, isSigned);
Chris Lattnercbe4f772007-08-08 22:51:59 +00002250}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002251
Leonard Chandb01c3a2018-06-20 17:19:40 +00002252void ASTDumper::VisitFixedPointLiteral(const FixedPointLiteral *Node) {
2253 VisitExpr(Node);
2254
2255 ColorScope Color(*this, ValueColor);
2256 OS << " " << Node->getValueAsString(/*Radix=*/10);
2257}
2258
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002259void ASTDumper::VisitFloatingLiteral(const FloatingLiteral *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002260 VisitExpr(Node);
Richard Trieud215b8d2013-01-26 01:31:20 +00002261 ColorScope Color(*this, ValueColor);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002262 OS << " " << Node->getValueAsApproximateDouble();
Chris Lattnercbe4f772007-08-08 22:51:59 +00002263}
Chris Lattner1c20a172007-08-26 03:42:43 +00002264
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002265void ASTDumper::VisitStringLiteral(const StringLiteral *Str) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002266 VisitExpr(Str);
Richard Trieud215b8d2013-01-26 01:31:20 +00002267 ColorScope Color(*this, ValueColor);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002268 OS << " ";
Richard Trieudc355912012-06-13 20:25:24 +00002269 Str->outputString(OS);
Chris Lattnercbe4f772007-08-08 22:51:59 +00002270}
Chris Lattner84ca3762007-08-30 01:00:35 +00002271
Richard Smithf0514962014-06-03 08:24:28 +00002272void ASTDumper::VisitInitListExpr(const InitListExpr *ILE) {
2273 VisitExpr(ILE);
2274 if (auto *Filler = ILE->getArrayFiller()) {
Richard Smithf7514452014-10-30 21:02:37 +00002275 dumpChild([=] {
2276 OS << "array filler";
2277 dumpStmt(Filler);
2278 });
Richard Smithf0514962014-06-03 08:24:28 +00002279 }
2280 if (auto *Field = ILE->getInitializedFieldInUnion()) {
2281 OS << " field ";
2282 dumpBareDeclRef(Field);
2283 }
2284}
2285
Richard Smith410306b2016-12-12 02:53:20 +00002286void ASTDumper::VisitArrayInitLoopExpr(const ArrayInitLoopExpr *E) {
2287 VisitExpr(E);
2288}
2289
2290void ASTDumper::VisitArrayInitIndexExpr(const ArrayInitIndexExpr *E) {
2291 VisitExpr(E);
2292}
2293
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002294void ASTDumper::VisitUnaryOperator(const UnaryOperator *Node) {
Malcolm Parsonsfab36802018-04-16 08:31:08 +00002295 VisitExpr(Node);
2296 OS << " " << (Node->isPostfix() ? "postfix" : "prefix")
2297 << " '" << UnaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
2298 if (!Node->canOverflow())
2299 OS << " cannot overflow";
2300}
2301
2302void ASTDumper::VisitUnaryExprOrTypeTraitExpr(
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002303 const UnaryExprOrTypeTraitExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002304 VisitExpr(Node);
Peter Collingbournee190dee2011-03-11 19:24:49 +00002305 switch(Node->getKind()) {
2306 case UETT_SizeOf:
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002307 OS << " sizeof";
Peter Collingbournee190dee2011-03-11 19:24:49 +00002308 break;
2309 case UETT_AlignOf:
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002310 OS << " alignof";
Peter Collingbournee190dee2011-03-11 19:24:49 +00002311 break;
2312 case UETT_VecStep:
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002313 OS << " vec_step";
Peter Collingbournee190dee2011-03-11 19:24:49 +00002314 break;
Alexey Bataev00396512015-07-02 03:40:19 +00002315 case UETT_OpenMPRequiredSimdAlign:
2316 OS << " __builtin_omp_required_simd_align";
2317 break;
Richard Smith6822bd72018-10-26 19:26:45 +00002318 case UETT_PreferredAlignOf:
2319 OS << " __alignof";
2320 break;
Peter Collingbournee190dee2011-03-11 19:24:49 +00002321 }
Sebastian Redl6f282892008-11-11 17:56:53 +00002322 if (Node->isArgumentType())
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002323 dumpType(Node->getArgumentType());
Chris Lattnercbe4f772007-08-08 22:51:59 +00002324}
Chris Lattnerdb3b3ff2007-08-09 17:35:30 +00002325
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002326void ASTDumper::VisitMemberExpr(const MemberExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002327 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002328 OS << " " << (Node->isArrow() ? "->" : ".") << *Node->getMemberDecl();
2329 dumpPointer(Node->getMemberDecl());
Chris Lattnercbe4f772007-08-08 22:51:59 +00002330}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002331
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002332void ASTDumper::VisitExtVectorElementExpr(const ExtVectorElementExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002333 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002334 OS << " " << Node->getAccessor().getNameStart();
Chris Lattnercbe4f772007-08-08 22:51:59 +00002335}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002336
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002337void ASTDumper::VisitBinaryOperator(const BinaryOperator *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002338 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002339 OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
Chris Lattner86928112007-08-25 02:00:02 +00002340}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002341
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002342void ASTDumper::VisitCompoundAssignOperator(
2343 const CompoundAssignOperator *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002344 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002345 OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode())
2346 << "' ComputeLHSTy=";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002347 dumpBareType(Node->getComputationLHSType());
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002348 OS << " ComputeResultTy=";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002349 dumpBareType(Node->getComputationResultType());
Chris Lattnercbe4f772007-08-08 22:51:59 +00002350}
Chris Lattnercbe4f772007-08-08 22:51:59 +00002351
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002352void ASTDumper::VisitBlockExpr(const BlockExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002353 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002354 dumpDecl(Node->getBlockDecl());
John McCall351762c2011-02-07 10:33:21 +00002355}
2356
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002357void ASTDumper::VisitOpaqueValueExpr(const OpaqueValueExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002358 VisitExpr(Node);
John McCallfe96e0b2011-11-06 09:01:30 +00002359
Richard Smithf7514452014-10-30 21:02:37 +00002360 if (Expr *Source = Node->getSourceExpr())
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002361 dumpStmt(Source);
John McCallfe96e0b2011-11-06 09:01:30 +00002362}
2363
Richard Smith01ccebf2018-01-05 21:31:07 +00002364void ASTDumper::VisitGenericSelectionExpr(const GenericSelectionExpr *E) {
2365 VisitExpr(E);
2366 if (E->isResultDependent())
2367 OS << " result_dependent";
2368 dumpStmt(E->getControllingExpr());
2369 dumpTypeAsChild(E->getControllingExpr()->getType()); // FIXME: remove
2370
2371 for (unsigned I = 0, N = E->getNumAssocs(); I != N; ++I) {
2372 dumpChild([=] {
2373 if (const TypeSourceInfo *TSI = E->getAssocTypeSourceInfo(I)) {
2374 OS << "case ";
2375 dumpType(TSI->getType());
2376 } else {
2377 OS << "default";
2378 }
2379
2380 if (!E->isResultDependent() && E->getResultIndex() == I)
2381 OS << " selected";
2382
2383 if (const TypeSourceInfo *TSI = E->getAssocTypeSourceInfo(I))
2384 dumpTypeAsChild(TSI->getType());
2385 dumpStmt(E->getAssocExpr(I));
2386 });
2387 }
2388}
2389
Chris Lattnercbe4f772007-08-08 22:51:59 +00002390// GNU extensions.
2391
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002392void ASTDumper::VisitAddrLabelExpr(const AddrLabelExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002393 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002394 OS << " " << Node->getLabel()->getName();
2395 dumpPointer(Node->getLabel());
Chris Lattnercbe4f772007-08-08 22:51:59 +00002396}
2397
Chris Lattner8f184b12007-08-09 18:03:18 +00002398//===----------------------------------------------------------------------===//
2399// C++ Expressions
2400//===----------------------------------------------------------------------===//
Chris Lattnercbe4f772007-08-08 22:51:59 +00002401
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002402void ASTDumper::VisitCXXNamedCastExpr(const CXXNamedCastExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002403 VisitExpr(Node);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002404 OS << " " << Node->getCastName()
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002405 << "<" << Node->getTypeAsWritten().getAsString() << ">"
Anders Carlssona70cff62010-04-24 19:06:50 +00002406 << " <" << Node->getCastKindName();
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002407 dumpBasePath(OS, Node);
Anders Carlssona70cff62010-04-24 19:06:50 +00002408 OS << ">";
Chris Lattnercbe4f772007-08-08 22:51:59 +00002409}
2410
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002411void ASTDumper::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002412 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002413 OS << " " << (Node->getValue() ? "true" : "false");
Chris Lattnercbe4f772007-08-08 22:51:59 +00002414}
2415
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002416void ASTDumper::VisitCXXThisExpr(const CXXThisExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002417 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002418 OS << " this";
Douglas Gregor8ea1f532008-11-04 14:56:14 +00002419}
2420
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002421void ASTDumper::VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002422 VisitExpr(Node);
Eli Friedman29538892011-09-02 17:38:59 +00002423 OS << " functional cast to " << Node->getTypeAsWritten().getAsString()
2424 << " <" << Node->getCastKindName() << ">";
Douglas Gregore200adc2008-10-27 19:41:14 +00002425}
2426
Richard Smith39eca9b2017-08-23 22:12:08 +00002427void ASTDumper::VisitCXXUnresolvedConstructExpr(
2428 const CXXUnresolvedConstructExpr *Node) {
2429 VisitExpr(Node);
2430 dumpType(Node->getTypeAsWritten());
2431 if (Node->isListInitialization())
2432 OS << " list";
2433}
2434
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002435void ASTDumper::VisitCXXConstructExpr(const CXXConstructExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002436 VisitExpr(Node);
John McCalleba90cd2010-02-02 19:03:45 +00002437 CXXConstructorDecl *Ctor = Node->getConstructor();
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002438 dumpType(Ctor->getType());
Anders Carlsson073846832009-08-12 00:21:52 +00002439 if (Node->isElidable())
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002440 OS << " elidable";
Richard Smith39eca9b2017-08-23 22:12:08 +00002441 if (Node->isListInitialization())
2442 OS << " list";
2443 if (Node->isStdInitListInitialization())
2444 OS << " std::initializer_list";
John McCall85370042010-08-07 06:38:55 +00002445 if (Node->requiresZeroInitialization())
2446 OS << " zeroing";
Anders Carlsson073846832009-08-12 00:21:52 +00002447}
2448
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002449void ASTDumper::VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002450 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002451 OS << " ";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002452 dumpCXXTemporary(Node->getTemporary());
Anders Carlsson073846832009-08-12 00:21:52 +00002453}
2454
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002455void ASTDumper::VisitCXXNewExpr(const CXXNewExpr *Node) {
2456 VisitExpr(Node);
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002457 if (Node->isGlobalNew())
Reid Kleckner461c0c62015-03-19 18:47:47 +00002458 OS << " global";
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002459 if (Node->isArray())
Reid Kleckner461c0c62015-03-19 18:47:47 +00002460 OS << " array";
2461 if (Node->getOperatorNew()) {
2462 OS << ' ';
2463 dumpBareDeclRef(Node->getOperatorNew());
2464 }
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002465 // We could dump the deallocation function used in case of error, but it's
2466 // usually not that interesting.
2467}
2468
2469void ASTDumper::VisitCXXDeleteExpr(const CXXDeleteExpr *Node) {
2470 VisitExpr(Node);
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002471 if (Node->isGlobalDelete())
Reid Kleckner461c0c62015-03-19 18:47:47 +00002472 OS << " global";
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002473 if (Node->isArrayForm())
Reid Kleckner461c0c62015-03-19 18:47:47 +00002474 OS << " array";
2475 if (Node->getOperatorDelete()) {
2476 OS << ' ';
2477 dumpBareDeclRef(Node->getOperatorDelete());
2478 }
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002479}
2480
Richard Smithe6c01442013-06-05 00:46:14 +00002481void
2482ASTDumper::VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *Node) {
2483 VisitExpr(Node);
2484 if (const ValueDecl *VD = Node->getExtendingDecl()) {
2485 OS << " extended by ";
2486 dumpBareDeclRef(VD);
2487 }
2488}
2489
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002490void ASTDumper::VisitExprWithCleanups(const ExprWithCleanups *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002491 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002492 for (unsigned i = 0, e = Node->getNumObjects(); i != e; ++i)
2493 dumpDeclRef(Node->getObject(i), "cleanup");
Anders Carlsson073846832009-08-12 00:21:52 +00002494}
2495
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002496void ASTDumper::dumpCXXTemporary(const CXXTemporary *Temporary) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002497 OS << "(CXXTemporary";
2498 dumpPointer(Temporary);
2499 OS << ")";
Anders Carlsson073846832009-08-12 00:21:52 +00002500}
2501
Serge Pavlov6b926032015-02-16 19:58:41 +00002502void ASTDumper::VisitSizeOfPackExpr(const SizeOfPackExpr *Node) {
2503 VisitExpr(Node);
2504 dumpPointer(Node->getPack());
2505 dumpName(Node->getPack());
Richard Smithd784e682015-09-23 21:41:42 +00002506 if (Node->isPartiallySubstituted())
2507 for (const auto &A : Node->getPartialArguments())
2508 dumpTemplateArgument(A);
Serge Pavlov6b926032015-02-16 19:58:41 +00002509}
2510
Alex Lorenzddbe0f52016-11-09 14:02:18 +00002511void ASTDumper::VisitCXXDependentScopeMemberExpr(
2512 const CXXDependentScopeMemberExpr *Node) {
2513 VisitExpr(Node);
2514 OS << " " << (Node->isArrow() ? "->" : ".") << Node->getMember();
2515}
Serge Pavlov6b926032015-02-16 19:58:41 +00002516
Anders Carlsson76f4a902007-08-21 17:43:55 +00002517//===----------------------------------------------------------------------===//
2518// Obj-C Expressions
2519//===----------------------------------------------------------------------===//
2520
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002521void ASTDumper::VisitObjCMessageExpr(const ObjCMessageExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002522 VisitExpr(Node);
Aaron Ballmanb190f972014-01-03 17:59:55 +00002523 OS << " selector=";
2524 Node->getSelector().print(OS);
Douglas Gregor9a129192010-04-21 00:45:42 +00002525 switch (Node->getReceiverKind()) {
2526 case ObjCMessageExpr::Instance:
2527 break;
2528
2529 case ObjCMessageExpr::Class:
2530 OS << " class=";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002531 dumpBareType(Node->getClassReceiver());
Douglas Gregor9a129192010-04-21 00:45:42 +00002532 break;
2533
2534 case ObjCMessageExpr::SuperInstance:
2535 OS << " super (instance)";
2536 break;
2537
2538 case ObjCMessageExpr::SuperClass:
2539 OS << " super (class)";
2540 break;
2541 }
Ted Kremenek36748da2008-02-29 22:04:05 +00002542}
2543
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002544void ASTDumper::VisitObjCBoxedExpr(const ObjCBoxedExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002545 VisitExpr(Node);
Richard Trieu4b259c82016-06-09 22:03:04 +00002546 if (auto *BoxingMethod = Node->getBoxingMethod()) {
2547 OS << " selector=";
2548 BoxingMethod->getSelector().print(OS);
2549 }
Argyrios Kyrtzidis9dd40892012-05-10 20:02:31 +00002550}
2551
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002552void ASTDumper::VisitObjCAtCatchStmt(const ObjCAtCatchStmt *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002553 VisitStmt(Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002554 if (const VarDecl *CatchParam = Node->getCatchParamDecl())
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002555 dumpDecl(CatchParam);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002556 else
Douglas Gregor96c79492010-04-23 22:50:49 +00002557 OS << " catch all";
Douglas Gregor96c79492010-04-23 22:50:49 +00002558}
2559
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002560void ASTDumper::VisitObjCEncodeExpr(const ObjCEncodeExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002561 VisitExpr(Node);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002562 dumpType(Node->getEncodedType());
Anders Carlssonc5a81eb2007-08-22 15:14:15 +00002563}
2564
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002565void ASTDumper::VisitObjCSelectorExpr(const ObjCSelectorExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002566 VisitExpr(Node);
Mike Stump11289f42009-09-09 15:08:12 +00002567
Aaron Ballmanb190f972014-01-03 17:59:55 +00002568 OS << " ";
2569 Node->getSelector().print(OS);
Fariborz Jahanian4bef4622007-10-16 20:40:23 +00002570}
2571
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002572void ASTDumper::VisitObjCProtocolExpr(const ObjCProtocolExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002573 VisitExpr(Node);
Mike Stump11289f42009-09-09 15:08:12 +00002574
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002575 OS << ' ' << *Node->getProtocol();
Fariborz Jahaniana32aaef2007-10-17 16:58:11 +00002576}
Daniel Dunbar4b8c6db2008-08-30 05:35:15 +00002577
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002578void ASTDumper::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002579 VisitExpr(Node);
John McCallb7bd14f2010-12-02 01:19:52 +00002580 if (Node->isImplicitProperty()) {
Fariborz Jahanian0f0b3022010-12-22 19:46:35 +00002581 OS << " Kind=MethodRef Getter=\"";
2582 if (Node->getImplicitPropertyGetter())
Aaron Ballmanb190f972014-01-03 17:59:55 +00002583 Node->getImplicitPropertyGetter()->getSelector().print(OS);
Fariborz Jahanian0f0b3022010-12-22 19:46:35 +00002584 else
2585 OS << "(null)";
2586
2587 OS << "\" Setter=\"";
John McCallb7bd14f2010-12-02 01:19:52 +00002588 if (ObjCMethodDecl *Setter = Node->getImplicitPropertySetter())
Aaron Ballmanb190f972014-01-03 17:59:55 +00002589 Setter->getSelector().print(OS);
John McCallb7bd14f2010-12-02 01:19:52 +00002590 else
2591 OS << "(null)";
2592 OS << "\"";
2593 } else {
Benjamin Kramerb89514a2011-10-14 18:45:37 +00002594 OS << " Kind=PropertyRef Property=\"" << *Node->getExplicitProperty() <<'"';
John McCallb7bd14f2010-12-02 01:19:52 +00002595 }
Fariborz Jahanian8a1810f2008-11-22 18:39:36 +00002596
Fariborz Jahanian681c0752010-10-14 16:04:05 +00002597 if (Node->isSuperReceiver())
2598 OS << " super";
Argyrios Kyrtzidisab468b02012-03-30 00:19:18 +00002599
2600 OS << " Messaging=";
2601 if (Node->isMessagingGetter() && Node->isMessagingSetter())
2602 OS << "Getter&Setter";
2603 else if (Node->isMessagingGetter())
2604 OS << "Getter";
2605 else if (Node->isMessagingSetter())
2606 OS << "Setter";
Douglas Gregor8ea1f532008-11-04 14:56:14 +00002607}
2608
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002609void ASTDumper::VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002610 VisitExpr(Node);
Ted Kremeneke65b0862012-03-06 20:05:56 +00002611 if (Node->isArraySubscriptRefExpr())
2612 OS << " Kind=ArraySubscript GetterForArray=\"";
2613 else
2614 OS << " Kind=DictionarySubscript GetterForDictionary=\"";
2615 if (Node->getAtIndexMethodDecl())
Aaron Ballmanb190f972014-01-03 17:59:55 +00002616 Node->getAtIndexMethodDecl()->getSelector().print(OS);
Ted Kremeneke65b0862012-03-06 20:05:56 +00002617 else
2618 OS << "(null)";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002619
Ted Kremeneke65b0862012-03-06 20:05:56 +00002620 if (Node->isArraySubscriptRefExpr())
2621 OS << "\" SetterForArray=\"";
2622 else
2623 OS << "\" SetterForDictionary=\"";
2624 if (Node->setAtIndexMethodDecl())
Aaron Ballmanb190f972014-01-03 17:59:55 +00002625 Node->setAtIndexMethodDecl()->getSelector().print(OS);
Ted Kremeneke65b0862012-03-06 20:05:56 +00002626 else
2627 OS << "(null)";
2628}
2629
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002630void ASTDumper::VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002631 VisitExpr(Node);
Ted Kremeneke65b0862012-03-06 20:05:56 +00002632 OS << " " << (Node->getValue() ? "__objc_yes" : "__objc_no");
2633}
2634
Chris Lattnercbe4f772007-08-08 22:51:59 +00002635//===----------------------------------------------------------------------===//
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002636// Comments
2637//===----------------------------------------------------------------------===//
2638
2639const char *ASTDumper::getCommandName(unsigned CommandID) {
2640 if (Traits)
2641 return Traits->getCommandInfo(CommandID)->Name;
2642 const CommandInfo *Info = CommandTraits::getBuiltinCommandInfo(CommandID);
2643 if (Info)
2644 return Info->Name;
2645 return "<not a builtin command>";
2646}
2647
2648void ASTDumper::dumpFullComment(const FullComment *C) {
2649 if (!C)
2650 return;
2651
2652 FC = C;
2653 dumpComment(C);
Craig Topper36250ad2014-05-12 05:36:57 +00002654 FC = nullptr;
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002655}
2656
2657void ASTDumper::dumpComment(const Comment *C) {
Richard Smithf7514452014-10-30 21:02:37 +00002658 dumpChild([=] {
2659 if (!C) {
2660 ColorScope Color(*this, NullColor);
2661 OS << "<<<NULL>>>";
2662 return;
2663 }
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002664
Richard Smithf7514452014-10-30 21:02:37 +00002665 {
2666 ColorScope Color(*this, CommentColor);
2667 OS << C->getCommentKindName();
2668 }
2669 dumpPointer(C);
2670 dumpSourceRange(C->getSourceRange());
2671 ConstCommentVisitor<ASTDumper>::visit(C);
2672 for (Comment::child_iterator I = C->child_begin(), E = C->child_end();
2673 I != E; ++I)
2674 dumpComment(*I);
2675 });
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002676}
2677
2678void ASTDumper::visitTextComment(const TextComment *C) {
2679 OS << " Text=\"" << C->getText() << "\"";
2680}
2681
2682void ASTDumper::visitInlineCommandComment(const InlineCommandComment *C) {
2683 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\"";
2684 switch (C->getRenderKind()) {
2685 case InlineCommandComment::RenderNormal:
2686 OS << " RenderNormal";
2687 break;
2688 case InlineCommandComment::RenderBold:
2689 OS << " RenderBold";
2690 break;
2691 case InlineCommandComment::RenderMonospaced:
2692 OS << " RenderMonospaced";
2693 break;
2694 case InlineCommandComment::RenderEmphasized:
2695 OS << " RenderEmphasized";
2696 break;
2697 }
2698
2699 for (unsigned i = 0, e = C->getNumArgs(); i != e; ++i)
2700 OS << " Arg[" << i << "]=\"" << C->getArgText(i) << "\"";
2701}
2702
2703void ASTDumper::visitHTMLStartTagComment(const HTMLStartTagComment *C) {
2704 OS << " Name=\"" << C->getTagName() << "\"";
2705 if (C->getNumAttrs() != 0) {
2706 OS << " Attrs: ";
2707 for (unsigned i = 0, e = C->getNumAttrs(); i != e; ++i) {
2708 const HTMLStartTagComment::Attribute &Attr = C->getAttr(i);
2709 OS << " \"" << Attr.Name << "=\"" << Attr.Value << "\"";
2710 }
2711 }
2712 if (C->isSelfClosing())
2713 OS << " SelfClosing";
2714}
2715
2716void ASTDumper::visitHTMLEndTagComment(const HTMLEndTagComment *C) {
2717 OS << " Name=\"" << C->getTagName() << "\"";
2718}
2719
2720void ASTDumper::visitBlockCommandComment(const BlockCommandComment *C) {
2721 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\"";
2722 for (unsigned i = 0, e = C->getNumArgs(); i != e; ++i)
2723 OS << " Arg[" << i << "]=\"" << C->getArgText(i) << "\"";
2724}
2725
2726void ASTDumper::visitParamCommandComment(const ParamCommandComment *C) {
2727 OS << " " << ParamCommandComment::getDirectionAsString(C->getDirection());
2728
2729 if (C->isDirectionExplicit())
2730 OS << " explicitly";
2731 else
2732 OS << " implicitly";
2733
2734 if (C->hasParamName()) {
2735 if (C->isParamIndexValid())
2736 OS << " Param=\"" << C->getParamName(FC) << "\"";
2737 else
2738 OS << " Param=\"" << C->getParamNameAsWritten() << "\"";
2739 }
2740
Dmitri Gribenkodbff5c72014-03-19 14:03:47 +00002741 if (C->isParamIndexValid() && !C->isVarArgParam())
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002742 OS << " ParamIndex=" << C->getParamIndex();
2743}
2744
2745void ASTDumper::visitTParamCommandComment(const TParamCommandComment *C) {
2746 if (C->hasParamName()) {
2747 if (C->isPositionValid())
2748 OS << " Param=\"" << C->getParamName(FC) << "\"";
2749 else
2750 OS << " Param=\"" << C->getParamNameAsWritten() << "\"";
2751 }
2752
2753 if (C->isPositionValid()) {
2754 OS << " Position=<";
2755 for (unsigned i = 0, e = C->getDepth(); i != e; ++i) {
2756 OS << C->getIndex(i);
2757 if (i != e - 1)
2758 OS << ", ";
2759 }
2760 OS << ">";
2761 }
2762}
2763
2764void ASTDumper::visitVerbatimBlockComment(const VerbatimBlockComment *C) {
2765 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\""
2766 " CloseName=\"" << C->getCloseName() << "\"";
2767}
2768
2769void ASTDumper::visitVerbatimBlockLineComment(
2770 const VerbatimBlockLineComment *C) {
2771 OS << " Text=\"" << C->getText() << "\"";
2772}
2773
2774void ASTDumper::visitVerbatimLineComment(const VerbatimLineComment *C) {
2775 OS << " Text=\"" << C->getText() << "\"";
2776}
2777
2778//===----------------------------------------------------------------------===//
Richard Smithd5e7ff82014-10-31 01:17:45 +00002779// Type method implementations
2780//===----------------------------------------------------------------------===//
2781
2782void QualType::dump(const char *msg) const {
2783 if (msg)
2784 llvm::errs() << msg << ": ";
2785 dump();
2786}
2787
Richard Smith14d04842016-11-02 23:57:18 +00002788LLVM_DUMP_METHOD void QualType::dump() const { dump(llvm::errs()); }
2789
2790LLVM_DUMP_METHOD void QualType::dump(llvm::raw_ostream &OS) const {
2791 ASTDumper Dumper(OS, nullptr, nullptr);
Richard Smithd5e7ff82014-10-31 01:17:45 +00002792 Dumper.dumpTypeAsChild(*this);
2793}
2794
Richard Smith14d04842016-11-02 23:57:18 +00002795LLVM_DUMP_METHOD void Type::dump() const { dump(llvm::errs()); }
2796
2797LLVM_DUMP_METHOD void Type::dump(llvm::raw_ostream &OS) const {
2798 QualType(this, 0).dump(OS);
2799}
Richard Smithd5e7ff82014-10-31 01:17:45 +00002800
2801//===----------------------------------------------------------------------===//
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002802// Decl method implementations
2803//===----------------------------------------------------------------------===//
2804
Alp Tokeref6b0072014-01-04 13:47:14 +00002805LLVM_DUMP_METHOD void Decl::dump() const { dump(llvm::errs()); }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002806
Richard Smith3a36ac12017-03-09 22:00:01 +00002807LLVM_DUMP_METHOD void Decl::dump(raw_ostream &OS, bool Deserialize) const {
Aaron Ballman8c208282017-12-21 21:42:42 +00002808 const ASTContext &Ctx = getASTContext();
2809 const SourceManager &SM = Ctx.getSourceManager();
2810 ASTDumper P(OS, &Ctx.getCommentCommandTraits(), &SM,
2811 SM.getDiagnostics().getShowColors(), Ctx.getPrintingPolicy());
Richard Smith3a36ac12017-03-09 22:00:01 +00002812 P.setDeserialize(Deserialize);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002813 P.dumpDecl(this);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002814}
2815
Alp Tokeref6b0072014-01-04 13:47:14 +00002816LLVM_DUMP_METHOD void Decl::dumpColor() const {
Aaron Ballman8c208282017-12-21 21:42:42 +00002817 const ASTContext &Ctx = getASTContext();
2818 ASTDumper P(llvm::errs(), &Ctx.getCommentCommandTraits(),
2819 &Ctx.getSourceManager(), /*ShowColors*/ true,
2820 Ctx.getPrintingPolicy());
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002821 P.dumpDecl(this);
Richard Trieud215b8d2013-01-26 01:31:20 +00002822}
Richard Smith33937e72013-06-22 21:49:40 +00002823
Alp Tokeref6b0072014-01-04 13:47:14 +00002824LLVM_DUMP_METHOD void DeclContext::dumpLookups() const {
Richard Smith6ea05822013-06-24 01:45:33 +00002825 dumpLookups(llvm::errs());
2826}
2827
Richard Smith35f986d2014-08-11 22:11:07 +00002828LLVM_DUMP_METHOD void DeclContext::dumpLookups(raw_ostream &OS,
Richard Smith3a36ac12017-03-09 22:00:01 +00002829 bool DumpDecls,
2830 bool Deserialize) const {
Richard Smith33937e72013-06-22 21:49:40 +00002831 const DeclContext *DC = this;
2832 while (!DC->isTranslationUnit())
2833 DC = DC->getParent();
2834 ASTContext &Ctx = cast<TranslationUnitDecl>(DC)->getASTContext();
Aaron Ballman8c208282017-12-21 21:42:42 +00002835 const SourceManager &SM = Ctx.getSourceManager();
2836 ASTDumper P(OS, &Ctx.getCommentCommandTraits(), &Ctx.getSourceManager(),
2837 SM.getDiagnostics().getShowColors(), Ctx.getPrintingPolicy());
Richard Smith3a36ac12017-03-09 22:00:01 +00002838 P.setDeserialize(Deserialize);
Richard Smith35f986d2014-08-11 22:11:07 +00002839 P.dumpLookups(this, DumpDecls);
Richard Smith33937e72013-06-22 21:49:40 +00002840}
2841
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002842//===----------------------------------------------------------------------===//
Chris Lattnercbe4f772007-08-08 22:51:59 +00002843// Stmt method implementations
2844//===----------------------------------------------------------------------===//
2845
Alp Tokeref6b0072014-01-04 13:47:14 +00002846LLVM_DUMP_METHOD void Stmt::dump(SourceManager &SM) const {
Argyrios Kyrtzidisc049f752010-08-09 10:54:31 +00002847 dump(llvm::errs(), SM);
2848}
2849
Alp Tokeref6b0072014-01-04 13:47:14 +00002850LLVM_DUMP_METHOD void Stmt::dump(raw_ostream &OS, SourceManager &SM) const {
Craig Topper36250ad2014-05-12 05:36:57 +00002851 ASTDumper P(OS, nullptr, &SM);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002852 P.dumpStmt(this);
Chris Lattner779d5d92007-08-30 00:40:08 +00002853}
2854
Faisal Vali2da8ed92015-03-22 13:35:56 +00002855LLVM_DUMP_METHOD void Stmt::dump(raw_ostream &OS) const {
2856 ASTDumper P(OS, nullptr, nullptr);
2857 P.dumpStmt(this);
2858}
2859
Alp Tokeref6b0072014-01-04 13:47:14 +00002860LLVM_DUMP_METHOD void Stmt::dump() const {
Craig Topper36250ad2014-05-12 05:36:57 +00002861 ASTDumper P(llvm::errs(), nullptr, nullptr);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002862 P.dumpStmt(this);
Chris Lattnercbe4f772007-08-08 22:51:59 +00002863}
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002864
Alp Tokeref6b0072014-01-04 13:47:14 +00002865LLVM_DUMP_METHOD void Stmt::dumpColor() const {
Craig Topper36250ad2014-05-12 05:36:57 +00002866 ASTDumper P(llvm::errs(), nullptr, nullptr, /*ShowColors*/true);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002867 P.dumpStmt(this);
Richard Trieud215b8d2013-01-26 01:31:20 +00002868}
2869
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002870//===----------------------------------------------------------------------===//
2871// Comment method implementations
2872//===----------------------------------------------------------------------===//
2873
Craig Topper36250ad2014-05-12 05:36:57 +00002874LLVM_DUMP_METHOD void Comment::dump() const {
2875 dump(llvm::errs(), nullptr, nullptr);
2876}
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002877
Alp Tokeref6b0072014-01-04 13:47:14 +00002878LLVM_DUMP_METHOD void Comment::dump(const ASTContext &Context) const {
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002879 dump(llvm::errs(), &Context.getCommentCommandTraits(),
2880 &Context.getSourceManager());
2881}
2882
Alexander Kornienko00911f12013-01-15 12:20:21 +00002883void Comment::dump(raw_ostream &OS, const CommandTraits *Traits,
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002884 const SourceManager *SM) const {
2885 const FullComment *FC = dyn_cast<FullComment>(this);
2886 ASTDumper D(OS, Traits, SM);
2887 D.dumpFullComment(FC);
2888}
Richard Trieud215b8d2013-01-26 01:31:20 +00002889
Alp Tokeref6b0072014-01-04 13:47:14 +00002890LLVM_DUMP_METHOD void Comment::dumpColor() const {
Richard Trieud215b8d2013-01-26 01:31:20 +00002891 const FullComment *FC = dyn_cast<FullComment>(this);
Craig Topper36250ad2014-05-12 05:36:57 +00002892 ASTDumper D(llvm::errs(), nullptr, nullptr, /*ShowColors*/true);
Richard Trieud215b8d2013-01-26 01:31:20 +00002893 D.dumpFullComment(FC);
2894}