blob: 03833ef640afefa8d1265683547c46360e8e8257 [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);
514 void VisitLabelStmt(const LabelStmt *Node);
515 void VisitGotoStmt(const GotoStmt *Node);
Pavel Labath1ef83422013-09-04 14:35:00 +0000516 void VisitCXXCatchStmt(const CXXCatchStmt *Node);
Alexey Bataev958b9e72016-03-31 09:30:50 +0000517 void VisitCapturedStmt(const CapturedStmt *Node);
518
519 // OpenMP
520 void VisitOMPExecutableDirective(const OMPExecutableDirective *Node);
Mike Stump11289f42009-09-09 15:08:12 +0000521
Chris Lattner84ca3762007-08-30 01:00:35 +0000522 // Exprs
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000523 void VisitExpr(const Expr *Node);
524 void VisitCastExpr(const CastExpr *Node);
Roman Lebedev12216f12018-07-27 07:27:14 +0000525 void VisitImplicitCastExpr(const ImplicitCastExpr *Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000526 void VisitDeclRefExpr(const DeclRefExpr *Node);
527 void VisitPredefinedExpr(const PredefinedExpr *Node);
528 void VisitCharacterLiteral(const CharacterLiteral *Node);
529 void VisitIntegerLiteral(const IntegerLiteral *Node);
Leonard Chandb01c3a2018-06-20 17:19:40 +0000530 void VisitFixedPointLiteral(const FixedPointLiteral *Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000531 void VisitFloatingLiteral(const FloatingLiteral *Node);
532 void VisitStringLiteral(const StringLiteral *Str);
Richard Smithf0514962014-06-03 08:24:28 +0000533 void VisitInitListExpr(const InitListExpr *ILE);
Richard Smith410306b2016-12-12 02:53:20 +0000534 void VisitArrayInitLoopExpr(const ArrayInitLoopExpr *ILE);
535 void VisitArrayInitIndexExpr(const ArrayInitIndexExpr *ILE);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000536 void VisitUnaryOperator(const UnaryOperator *Node);
537 void VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *Node);
538 void VisitMemberExpr(const MemberExpr *Node);
539 void VisitExtVectorElementExpr(const ExtVectorElementExpr *Node);
540 void VisitBinaryOperator(const BinaryOperator *Node);
541 void VisitCompoundAssignOperator(const CompoundAssignOperator *Node);
542 void VisitAddrLabelExpr(const AddrLabelExpr *Node);
543 void VisitBlockExpr(const BlockExpr *Node);
544 void VisitOpaqueValueExpr(const OpaqueValueExpr *Node);
Richard Smith01ccebf2018-01-05 21:31:07 +0000545 void VisitGenericSelectionExpr(const GenericSelectionExpr *E);
Chris Lattner84ca3762007-08-30 01:00:35 +0000546
547 // C++
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000548 void VisitCXXNamedCastExpr(const CXXNamedCastExpr *Node);
549 void VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *Node);
550 void VisitCXXThisExpr(const CXXThisExpr *Node);
551 void VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *Node);
Richard Smith39eca9b2017-08-23 22:12:08 +0000552 void VisitCXXUnresolvedConstructExpr(const CXXUnresolvedConstructExpr *Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000553 void VisitCXXConstructExpr(const CXXConstructExpr *Node);
554 void VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *Node);
Reid Kleckner5c682bc2015-03-19 18:09:25 +0000555 void VisitCXXNewExpr(const CXXNewExpr *Node);
556 void VisitCXXDeleteExpr(const CXXDeleteExpr *Node);
Richard Smithe6c01442013-06-05 00:46:14 +0000557 void VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000558 void VisitExprWithCleanups(const ExprWithCleanups *Node);
559 void VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *Node);
560 void dumpCXXTemporary(const CXXTemporary *Temporary);
Faisal Vali2b391ab2013-09-26 19:54:12 +0000561 void VisitLambdaExpr(const LambdaExpr *Node) {
562 VisitExpr(Node);
563 dumpDecl(Node->getLambdaClass());
564 }
Serge Pavlov6b926032015-02-16 19:58:41 +0000565 void VisitSizeOfPackExpr(const SizeOfPackExpr *Node);
Alex Lorenzddbe0f52016-11-09 14:02:18 +0000566 void
567 VisitCXXDependentScopeMemberExpr(const CXXDependentScopeMemberExpr *Node);
Mike Stump11289f42009-09-09 15:08:12 +0000568
Chris Lattner84ca3762007-08-30 01:00:35 +0000569 // ObjC
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000570 void VisitObjCAtCatchStmt(const ObjCAtCatchStmt *Node);
571 void VisitObjCEncodeExpr(const ObjCEncodeExpr *Node);
572 void VisitObjCMessageExpr(const ObjCMessageExpr *Node);
573 void VisitObjCBoxedExpr(const ObjCBoxedExpr *Node);
574 void VisitObjCSelectorExpr(const ObjCSelectorExpr *Node);
575 void VisitObjCProtocolExpr(const ObjCProtocolExpr *Node);
576 void VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *Node);
577 void VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *Node);
578 void VisitObjCIvarRefExpr(const ObjCIvarRefExpr *Node);
579 void VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *Node);
Alexander Kornienkoebc17b52013-01-14 14:07:11 +0000580
581 // Comments.
582 const char *getCommandName(unsigned CommandID);
583 void dumpComment(const Comment *C);
584
585 // Inline comments.
586 void visitTextComment(const TextComment *C);
587 void visitInlineCommandComment(const InlineCommandComment *C);
588 void visitHTMLStartTagComment(const HTMLStartTagComment *C);
589 void visitHTMLEndTagComment(const HTMLEndTagComment *C);
590
591 // Block comments.
592 void visitBlockCommandComment(const BlockCommandComment *C);
593 void visitParamCommandComment(const ParamCommandComment *C);
594 void visitTParamCommandComment(const TParamCommandComment *C);
595 void visitVerbatimBlockComment(const VerbatimBlockComment *C);
596 void visitVerbatimBlockLineComment(const VerbatimBlockLineComment *C);
597 void visitVerbatimLineComment(const VerbatimLineComment *C);
Chris Lattnercbe4f772007-08-08 22:51:59 +0000598 };
Alexander Kornienkoab9db512015-06-22 23:07:51 +0000599}
Chris Lattnercbe4f772007-08-08 22:51:59 +0000600
601//===----------------------------------------------------------------------===//
Chris Lattner11e30d32007-08-30 06:17:34 +0000602// Utilities
603//===----------------------------------------------------------------------===//
604
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000605void ASTDumper::dumpPointer(const void *Ptr) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000606 ColorScope Color(*this, AddressColor);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000607 OS << ' ' << Ptr;
608}
609
Alexander Kornienko18ec81b2012-12-13 13:59:55 +0000610void ASTDumper::dumpLocation(SourceLocation Loc) {
Alex McCarthye14ddef2014-05-02 20:24:11 +0000611 if (!SM)
612 return;
613
Richard Trieud215b8d2013-01-26 01:31:20 +0000614 ColorScope Color(*this, LocationColor);
Chris Lattner53e384f2009-01-16 07:00:02 +0000615 SourceLocation SpellingLoc = SM->getSpellingLoc(Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000616
Chris Lattner11e30d32007-08-30 06:17:34 +0000617 // The general format we print out is filename:line:col, but we drop pieces
618 // that haven't changed since the last loc printed.
Chris Lattnerf1ca7d32009-01-27 07:57:44 +0000619 PresumedLoc PLoc = SM->getPresumedLoc(SpellingLoc);
620
Douglas Gregor453b0122010-11-12 07:15:47 +0000621 if (PLoc.isInvalid()) {
622 OS << "<invalid sloc>";
623 return;
624 }
625
Chris Lattnerf1ca7d32009-01-27 07:57:44 +0000626 if (strcmp(PLoc.getFilename(), LastLocFilename) != 0) {
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000627 OS << PLoc.getFilename() << ':' << PLoc.getLine()
628 << ':' << PLoc.getColumn();
Chris Lattnerf1ca7d32009-01-27 07:57:44 +0000629 LastLocFilename = PLoc.getFilename();
630 LastLocLine = PLoc.getLine();
631 } else if (PLoc.getLine() != LastLocLine) {
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000632 OS << "line" << ':' << PLoc.getLine()
633 << ':' << PLoc.getColumn();
Chris Lattnerf1ca7d32009-01-27 07:57:44 +0000634 LastLocLine = PLoc.getLine();
Chris Lattner11e30d32007-08-30 06:17:34 +0000635 } else {
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000636 OS << "col" << ':' << PLoc.getColumn();
Chris Lattner11e30d32007-08-30 06:17:34 +0000637 }
638}
639
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000640void ASTDumper::dumpSourceRange(SourceRange R) {
Chris Lattner11e30d32007-08-30 06:17:34 +0000641 // Can't translate locations if a SourceManager isn't available.
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000642 if (!SM)
643 return;
Mike Stump11289f42009-09-09 15:08:12 +0000644
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000645 OS << " <";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000646 dumpLocation(R.getBegin());
Chris Lattnera7c19fe2007-10-16 22:36:42 +0000647 if (R.getBegin() != R.getEnd()) {
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000648 OS << ", ";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000649 dumpLocation(R.getEnd());
Chris Lattner11e30d32007-08-30 06:17:34 +0000650 }
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000651 OS << ">";
Mike Stump11289f42009-09-09 15:08:12 +0000652
Chris Lattner11e30d32007-08-30 06:17:34 +0000653 // <t2.c:123:421[blah], t2.c:412:321>
654
655}
656
Richard Smithd5e7ff82014-10-31 01:17:45 +0000657void ASTDumper::dumpBareType(QualType T, bool Desugar) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000658 ColorScope Color(*this, TypeColor);
Richard Smithd5e7ff82014-10-31 01:17:45 +0000659
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000660 SplitQualType T_split = T.split();
Aaron Ballman8c208282017-12-21 21:42:42 +0000661 OS << "'" << QualType::getAsString(T_split, PrintPolicy) << "'";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000662
Richard Smithd5e7ff82014-10-31 01:17:45 +0000663 if (Desugar && !T.isNull()) {
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000664 // If the type is sugared, also dump a (shallow) desugared type.
665 SplitQualType D_split = T.getSplitDesugaredType();
666 if (T_split != D_split)
Aaron Ballman8c208282017-12-21 21:42:42 +0000667 OS << ":'" << QualType::getAsString(D_split, PrintPolicy) << "'";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000668 }
669}
670
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000671void ASTDumper::dumpType(QualType T) {
672 OS << ' ';
673 dumpBareType(T);
674}
675
Richard Smithd5e7ff82014-10-31 01:17:45 +0000676void ASTDumper::dumpTypeAsChild(QualType T) {
677 SplitQualType SQT = T.split();
678 if (!SQT.Quals.hasQualifiers())
679 return dumpTypeAsChild(SQT.Ty);
680
681 dumpChild([=] {
682 OS << "QualType";
683 dumpPointer(T.getAsOpaquePtr());
684 OS << " ";
685 dumpBareType(T, false);
686 OS << " " << T.split().Quals.getAsString();
687 dumpTypeAsChild(T.split().Ty);
688 });
689}
690
691void ASTDumper::dumpTypeAsChild(const Type *T) {
692 dumpChild([=] {
693 if (!T) {
694 ColorScope Color(*this, NullColor);
695 OS << "<<<NULL>>>";
696 return;
697 }
Serge Pavlova6adc9e2015-12-28 17:19:12 +0000698 if (const LocInfoType *LIT = llvm::dyn_cast<LocInfoType>(T)) {
699 {
700 ColorScope Color(*this, TypeColor);
701 OS << "LocInfo Type";
702 }
703 dumpPointer(T);
704 dumpTypeAsChild(LIT->getTypeSourceInfo()->getType());
705 return;
706 }
Richard Smithd5e7ff82014-10-31 01:17:45 +0000707
708 {
709 ColorScope Color(*this, TypeColor);
710 OS << T->getTypeClassName() << "Type";
711 }
712 dumpPointer(T);
713 OS << " ";
714 dumpBareType(QualType(T, 0), false);
715
716 QualType SingleStepDesugar =
717 T->getLocallyUnqualifiedSingleStepDesugaredType();
718 if (SingleStepDesugar != QualType(T, 0))
719 OS << " sugar";
720 if (T->isDependentType())
721 OS << " dependent";
722 else if (T->isInstantiationDependentType())
723 OS << " instantiation_dependent";
724 if (T->isVariablyModifiedType())
725 OS << " variably_modified";
726 if (T->containsUnexpandedParameterPack())
727 OS << " contains_unexpanded_pack";
728 if (T->isFromAST())
729 OS << " imported";
730
731 TypeVisitor<ASTDumper>::Visit(T);
732
733 if (SingleStepDesugar != QualType(T, 0))
734 dumpTypeAsChild(SingleStepDesugar);
735 });
736}
737
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000738void ASTDumper::dumpBareDeclRef(const Decl *D) {
Richard Smith5179eb72016-06-28 19:03:57 +0000739 if (!D) {
740 ColorScope Color(*this, NullColor);
741 OS << "<<<NULL>>>";
742 return;
743 }
744
Richard Trieud215b8d2013-01-26 01:31:20 +0000745 {
746 ColorScope Color(*this, DeclKindNameColor);
747 OS << D->getDeclKindName();
748 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000749 dumpPointer(D);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000750
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000751 if (const NamedDecl *ND = dyn_cast<NamedDecl>(D)) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000752 ColorScope Color(*this, DeclNameColor);
David Blaikied4da8722013-05-14 21:04:00 +0000753 OS << " '" << ND->getDeclName() << '\'';
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000754 }
755
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000756 if (const ValueDecl *VD = dyn_cast<ValueDecl>(D))
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000757 dumpType(VD->getType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000758}
759
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000760void ASTDumper::dumpDeclRef(const Decl *D, const char *Label) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000761 if (!D)
762 return;
763
Richard Smithf7514452014-10-30 21:02:37 +0000764 dumpChild([=]{
765 if (Label)
766 OS << Label << ' ';
767 dumpBareDeclRef(D);
768 });
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000769}
770
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000771void ASTDumper::dumpName(const NamedDecl *ND) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000772 if (ND->getDeclName()) {
773 ColorScope Color(*this, DeclNameColor);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000774 OS << ' ' << ND->getNameAsString();
Richard Trieud215b8d2013-01-26 01:31:20 +0000775 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000776}
777
Richard Trieude5cc7d2013-01-31 01:44:26 +0000778bool ASTDumper::hasNodes(const DeclContext *DC) {
779 if (!DC)
780 return false;
781
Richard Smith1d209d02013-05-23 01:49:11 +0000782 return DC->hasExternalLexicalStorage() ||
Richard Smith3a36ac12017-03-09 22:00:01 +0000783 (Deserialize ? DC->decls_begin() != DC->decls_end()
784 : DC->noload_decls_begin() != DC->noload_decls_end());
Richard Trieude5cc7d2013-01-31 01:44:26 +0000785}
786
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000787void ASTDumper::dumpDeclContext(const DeclContext *DC) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000788 if (!DC)
789 return;
Richard Smithdcc2c452014-03-17 23:00:06 +0000790
Richard Smith3a36ac12017-03-09 22:00:01 +0000791 for (auto *D : (Deserialize ? DC->decls() : DC->noload_decls()))
Richard Smithf7514452014-10-30 21:02:37 +0000792 dumpDecl(D);
Richard Smithdcc2c452014-03-17 23:00:06 +0000793
794 if (DC->hasExternalLexicalStorage()) {
Richard Smithf7514452014-10-30 21:02:37 +0000795 dumpChild([=]{
796 ColorScope Color(*this, UndeserializedColor);
797 OS << "<undeserialized declarations>";
798 });
Richard Smith1d209d02013-05-23 01:49:11 +0000799 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000800}
801
Richard Smith35f986d2014-08-11 22:11:07 +0000802void ASTDumper::dumpLookups(const DeclContext *DC, bool DumpDecls) {
Richard Smithf7514452014-10-30 21:02:37 +0000803 dumpChild([=] {
804 OS << "StoredDeclsMap ";
805 dumpBareDeclRef(cast<Decl>(DC));
Richard Smith33937e72013-06-22 21:49:40 +0000806
Richard Smithf7514452014-10-30 21:02:37 +0000807 const DeclContext *Primary = DC->getPrimaryContext();
808 if (Primary != DC) {
809 OS << " primary";
810 dumpPointer(cast<Decl>(Primary));
Richard Smith33937e72013-06-22 21:49:40 +0000811 }
812
Richard Smithf7514452014-10-30 21:02:37 +0000813 bool HasUndeserializedLookups = Primary->hasExternalVisibleStorage();
Richard Smith35f986d2014-08-11 22:11:07 +0000814
Sam McCall091b1ef2018-01-16 12:33:46 +0000815 auto Range = Deserialize
816 ? Primary->lookups()
817 : Primary->noload_lookups(/*PreserveInternalState=*/true);
818 for (auto I = Range.begin(), E = Range.end(); I != E; ++I) {
Richard Smithf7514452014-10-30 21:02:37 +0000819 DeclarationName Name = I.getLookupName();
Richard Smith3a36ac12017-03-09 22:00:01 +0000820 DeclContextLookupResult R = *I;
Richard Smith35f986d2014-08-11 22:11:07 +0000821
Richard Smithf7514452014-10-30 21:02:37 +0000822 dumpChild([=] {
823 OS << "DeclarationName ";
824 {
825 ColorScope Color(*this, DeclNameColor);
826 OS << '\'' << Name << '\'';
827 }
Richard Smith35f986d2014-08-11 22:11:07 +0000828
Richard Smithf7514452014-10-30 21:02:37 +0000829 for (DeclContextLookupResult::iterator RI = R.begin(), RE = R.end();
830 RI != RE; ++RI) {
831 dumpChild([=] {
832 dumpBareDeclRef(*RI);
833
834 if ((*RI)->isHidden())
835 OS << " hidden";
836
837 // If requested, dump the redecl chain for this lookup.
838 if (DumpDecls) {
839 // Dump earliest decl first.
840 std::function<void(Decl *)> DumpWithPrev = [&](Decl *D) {
841 if (Decl *Prev = D->getPreviousDecl())
842 DumpWithPrev(Prev);
843 dumpDecl(D);
844 };
845 DumpWithPrev(*RI);
846 }
847 });
848 }
849 });
Richard Smith33937e72013-06-22 21:49:40 +0000850 }
Richard Smith33937e72013-06-22 21:49:40 +0000851
Richard Smithf7514452014-10-30 21:02:37 +0000852 if (HasUndeserializedLookups) {
853 dumpChild([=] {
854 ColorScope Color(*this, UndeserializedColor);
855 OS << "<undeserialized lookups>";
856 });
857 }
858 });
Richard Smith33937e72013-06-22 21:49:40 +0000859}
860
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000861void ASTDumper::dumpAttr(const Attr *A) {
Richard Smithf7514452014-10-30 21:02:37 +0000862 dumpChild([=] {
863 {
864 ColorScope Color(*this, AttrColor);
Aaron Ballman36a53502014-01-16 13:03:14 +0000865
Richard Smithf7514452014-10-30 21:02:37 +0000866 switch (A->getKind()) {
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000867#define ATTR(X) case attr::X: OS << #X; break;
868#include "clang/Basic/AttrList.inc"
Richard Smithf7514452014-10-30 21:02:37 +0000869 }
870 OS << "Attr";
Richard Trieud215b8d2013-01-26 01:31:20 +0000871 }
Richard Smithf7514452014-10-30 21:02:37 +0000872 dumpPointer(A);
873 dumpSourceRange(A->getRange());
874 if (A->isInherited())
875 OS << " Inherited";
876 if (A->isImplicit())
877 OS << " Implicit";
Hans Wennborgb0a8b4a2014-05-31 04:05:57 +0000878#include "clang/AST/AttrDump.inc"
Richard Smithf7514452014-10-30 21:02:37 +0000879 });
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000880}
881
Richard Smith71bec062013-10-15 21:58:30 +0000882static void dumpPreviousDeclImpl(raw_ostream &OS, ...) {}
883
884template<typename T>
885static void dumpPreviousDeclImpl(raw_ostream &OS, const Mergeable<T> *D) {
Rafael Espindola8db352d2013-10-17 15:37:26 +0000886 const T *First = D->getFirstDecl();
Richard Smith71bec062013-10-15 21:58:30 +0000887 if (First != D)
888 OS << " first " << First;
Richard Smithf5f43542013-02-07 01:35:44 +0000889}
890
891template<typename T>
Richard Smith71bec062013-10-15 21:58:30 +0000892static void dumpPreviousDeclImpl(raw_ostream &OS, const Redeclarable<T> *D) {
893 const T *Prev = D->getPreviousDecl();
894 if (Prev)
895 OS << " prev " << Prev;
Richard Smithf5f43542013-02-07 01:35:44 +0000896}
897
Richard Smith71bec062013-10-15 21:58:30 +0000898/// Dump the previous declaration in the redeclaration chain for a declaration,
899/// if any.
900static void dumpPreviousDecl(raw_ostream &OS, const Decl *D) {
Richard Smithf5f43542013-02-07 01:35:44 +0000901 switch (D->getKind()) {
902#define DECL(DERIVED, BASE) \
903 case Decl::DERIVED: \
Richard Smith71bec062013-10-15 21:58:30 +0000904 return dumpPreviousDeclImpl(OS, cast<DERIVED##Decl>(D));
Richard Smithf5f43542013-02-07 01:35:44 +0000905#define ABSTRACT_DECL(DECL)
906#include "clang/AST/DeclNodes.inc"
907 }
908 llvm_unreachable("Decl that isn't part of DeclNodes.inc!");
909}
910
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000911//===----------------------------------------------------------------------===//
912// C++ Utilities
913//===----------------------------------------------------------------------===//
914
915void ASTDumper::dumpAccessSpecifier(AccessSpecifier AS) {
916 switch (AS) {
917 case AS_none:
918 break;
919 case AS_public:
920 OS << "public";
921 break;
922 case AS_protected:
923 OS << "protected";
924 break;
925 case AS_private:
926 OS << "private";
927 break;
928 }
929}
930
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000931void ASTDumper::dumpCXXCtorInitializer(const CXXCtorInitializer *Init) {
Richard Smithf7514452014-10-30 21:02:37 +0000932 dumpChild([=] {
933 OS << "CXXCtorInitializer";
934 if (Init->isAnyMemberInitializer()) {
935 OS << ' ';
936 dumpBareDeclRef(Init->getAnyMember());
937 } else if (Init->isBaseInitializer()) {
938 dumpType(QualType(Init->getBaseClass(), 0));
939 } else if (Init->isDelegatingInitializer()) {
940 dumpType(Init->getTypeSourceInfo()->getType());
941 } else {
942 llvm_unreachable("Unknown initializer type");
943 }
944 dumpStmt(Init->getInit());
945 });
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000946}
947
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000948void ASTDumper::dumpTemplateParameters(const TemplateParameterList *TPL) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000949 if (!TPL)
950 return;
951
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000952 for (TemplateParameterList::const_iterator I = TPL->begin(), E = TPL->end();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000953 I != E; ++I)
954 dumpDecl(*I);
955}
956
957void ASTDumper::dumpTemplateArgumentListInfo(
958 const TemplateArgumentListInfo &TALI) {
Richard Smithf7514452014-10-30 21:02:37 +0000959 for (unsigned i = 0, e = TALI.size(); i < e; ++i)
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000960 dumpTemplateArgumentLoc(TALI[i]);
961}
962
963void ASTDumper::dumpTemplateArgumentLoc(const TemplateArgumentLoc &A) {
964 dumpTemplateArgument(A.getArgument(), A.getSourceRange());
965}
966
967void ASTDumper::dumpTemplateArgumentList(const TemplateArgumentList &TAL) {
968 for (unsigned i = 0, e = TAL.size(); i < e; ++i)
969 dumpTemplateArgument(TAL[i]);
970}
971
972void ASTDumper::dumpTemplateArgument(const TemplateArgument &A, SourceRange R) {
Richard Smithf7514452014-10-30 21:02:37 +0000973 dumpChild([=] {
974 OS << "TemplateArgument";
975 if (R.isValid())
976 dumpSourceRange(R);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000977
Richard Smithf7514452014-10-30 21:02:37 +0000978 switch (A.getKind()) {
979 case TemplateArgument::Null:
980 OS << " null";
981 break;
982 case TemplateArgument::Type:
983 OS << " type";
984 dumpType(A.getAsType());
985 break;
986 case TemplateArgument::Declaration:
987 OS << " decl";
988 dumpDeclRef(A.getAsDecl());
989 break;
990 case TemplateArgument::NullPtr:
991 OS << " nullptr";
992 break;
993 case TemplateArgument::Integral:
994 OS << " integral " << A.getAsIntegral();
995 break;
996 case TemplateArgument::Template:
997 OS << " template ";
998 A.getAsTemplate().dump(OS);
999 break;
1000 case TemplateArgument::TemplateExpansion:
Richard Trieu59c289f2018-08-21 22:55:26 +00001001 OS << " template expansion ";
Richard Smithf7514452014-10-30 21:02:37 +00001002 A.getAsTemplateOrTemplatePattern().dump(OS);
1003 break;
1004 case TemplateArgument::Expression:
1005 OS << " expr";
1006 dumpStmt(A.getAsExpr());
1007 break;
1008 case TemplateArgument::Pack:
1009 OS << " pack";
1010 for (TemplateArgument::pack_iterator I = A.pack_begin(), E = A.pack_end();
1011 I != E; ++I)
1012 dumpTemplateArgument(*I);
1013 break;
Richard Trieude5cc7d2013-01-31 01:44:26 +00001014 }
Richard Smithf7514452014-10-30 21:02:37 +00001015 });
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001016}
1017
Chris Lattner11e30d32007-08-30 06:17:34 +00001018//===----------------------------------------------------------------------===//
Douglas Gregor85f3f952015-07-07 03:57:15 +00001019// Objective-C Utilities
1020//===----------------------------------------------------------------------===//
1021void ASTDumper::dumpObjCTypeParamList(const ObjCTypeParamList *typeParams) {
1022 if (!typeParams)
1023 return;
1024
1025 for (auto typeParam : *typeParams) {
1026 dumpDecl(typeParam);
1027 }
1028}
1029
1030//===----------------------------------------------------------------------===//
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001031// Decl dumping methods.
Chris Lattnercbe4f772007-08-08 22:51:59 +00001032//===----------------------------------------------------------------------===//
1033
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001034void ASTDumper::dumpDecl(const Decl *D) {
Richard Smithf7514452014-10-30 21:02:37 +00001035 dumpChild([=] {
1036 if (!D) {
1037 ColorScope Color(*this, NullColor);
1038 OS << "<<<NULL>>>";
1039 return;
1040 }
Mike Stump11289f42009-09-09 15:08:12 +00001041
Richard Smithf7514452014-10-30 21:02:37 +00001042 {
1043 ColorScope Color(*this, DeclKindNameColor);
1044 OS << D->getDeclKindName() << "Decl";
1045 }
1046 dumpPointer(D);
1047 if (D->getLexicalDeclContext() != D->getDeclContext())
1048 OS << " parent " << cast<Decl>(D->getDeclContext());
1049 dumpPreviousDecl(OS, D);
1050 dumpSourceRange(D->getSourceRange());
1051 OS << ' ';
1052 dumpLocation(D->getLocation());
Richard Smith26342f92017-05-17 00:24:14 +00001053 if (D->isFromASTFile())
1054 OS << " imported";
1055 if (Module *M = D->getOwningModule())
Richard Smithf7514452014-10-30 21:02:37 +00001056 OS << " in " << M->getFullModuleName();
Richard Smitha2eb4092015-06-22 18:47:01 +00001057 if (auto *ND = dyn_cast<NamedDecl>(D))
1058 for (Module *M : D->getASTContext().getModulesWithMergedDefinition(
1059 const_cast<NamedDecl *>(ND)))
1060 dumpChild([=] { OS << "also in " << M->getFullModuleName(); });
Richard Smithf7514452014-10-30 21:02:37 +00001061 if (const NamedDecl *ND = dyn_cast<NamedDecl>(D))
1062 if (ND->isHidden())
1063 OS << " hidden";
1064 if (D->isImplicit())
1065 OS << " implicit";
1066 if (D->isUsed())
1067 OS << " used";
1068 else if (D->isThisDeclarationReferenced())
1069 OS << " referenced";
1070 if (D->isInvalidDecl())
1071 OS << " invalid";
Hans Wennborg76b00532014-12-05 22:38:57 +00001072 if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
1073 if (FD->isConstexpr())
1074 OS << " constexpr";
1075
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001076
Richard Smithf7514452014-10-30 21:02:37 +00001077 ConstDeclVisitor<ASTDumper>::Visit(D);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001078
Richard Smithf7514452014-10-30 21:02:37 +00001079 for (Decl::attr_iterator I = D->attr_begin(), E = D->attr_end(); I != E;
1080 ++I)
1081 dumpAttr(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001082
Richard Smithf7514452014-10-30 21:02:37 +00001083 if (const FullComment *Comment =
1084 D->getASTContext().getLocalCommentForDeclUncached(D))
1085 dumpFullComment(Comment);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001086
Richard Smithf7514452014-10-30 21:02:37 +00001087 // Decls within functions are visited by the body.
1088 if (!isa<FunctionDecl>(*D) && !isa<ObjCMethodDecl>(*D) &&
1089 hasNodes(dyn_cast<DeclContext>(D)))
1090 dumpDeclContext(cast<DeclContext>(D));
1091 });
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001092}
1093
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001094void ASTDumper::VisitLabelDecl(const LabelDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001095 dumpName(D);
1096}
1097
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001098void ASTDumper::VisitTypedefDecl(const TypedefDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001099 dumpName(D);
1100 dumpType(D->getUnderlyingType());
1101 if (D->isModulePrivate())
1102 OS << " __module_private__";
Richard Smithba3a4f92016-01-12 21:59:26 +00001103 dumpTypeAsChild(D->getUnderlyingType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001104}
1105
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001106void ASTDumper::VisitEnumDecl(const EnumDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001107 if (D->isScoped()) {
1108 if (D->isScopedUsingClassTag())
1109 OS << " class";
1110 else
1111 OS << " struct";
1112 }
1113 dumpName(D);
1114 if (D->isModulePrivate())
1115 OS << " __module_private__";
1116 if (D->isFixed())
1117 dumpType(D->getIntegerType());
1118}
1119
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001120void ASTDumper::VisitRecordDecl(const RecordDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001121 OS << ' ' << D->getKindName();
1122 dumpName(D);
1123 if (D->isModulePrivate())
1124 OS << " __module_private__";
Richard Smith99bc1b92013-08-30 05:32:29 +00001125 if (D->isCompleteDefinition())
1126 OS << " definition";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001127}
1128
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001129void ASTDumper::VisitEnumConstantDecl(const EnumConstantDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001130 dumpName(D);
1131 dumpType(D->getType());
Richard Smithf7514452014-10-30 21:02:37 +00001132 if (const Expr *Init = D->getInitExpr())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001133 dumpStmt(Init);
1134}
1135
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001136void ASTDumper::VisitIndirectFieldDecl(const IndirectFieldDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001137 dumpName(D);
1138 dumpType(D->getType());
Richard Smithdcc2c452014-03-17 23:00:06 +00001139
Richard Smith8aa49222014-03-18 00:35:12 +00001140 for (auto *Child : D->chain())
Richard Smithf7514452014-10-30 21:02:37 +00001141 dumpDeclRef(Child);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001142}
1143
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001144void ASTDumper::VisitFunctionDecl(const FunctionDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001145 dumpName(D);
1146 dumpType(D->getType());
1147
Rafael Espindola6ae7e502013-04-03 19:27:57 +00001148 StorageClass SC = D->getStorageClass();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001149 if (SC != SC_None)
1150 OS << ' ' << VarDecl::getStorageClassSpecifierString(SC);
1151 if (D->isInlineSpecified())
1152 OS << " inline";
1153 if (D->isVirtualAsWritten())
1154 OS << " virtual";
1155 if (D->isModulePrivate())
1156 OS << " __module_private__";
1157
1158 if (D->isPure())
1159 OS << " pure";
Richard Smith5a2e6b92016-11-21 23:43:54 +00001160 if (D->isDefaulted()) {
1161 OS << " default";
1162 if (D->isDeleted())
1163 OS << "_delete";
1164 }
1165 if (D->isDeletedAsWritten())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001166 OS << " delete";
Richard Smith5a2e6b92016-11-21 23:43:54 +00001167 if (D->isTrivial())
1168 OS << " trivial";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001169
Richard Smithadaa0152013-05-17 02:09:46 +00001170 if (const FunctionProtoType *FPT = D->getType()->getAs<FunctionProtoType>()) {
1171 FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo();
Richard Smith8acb4282014-07-31 21:57:55 +00001172 switch (EPI.ExceptionSpec.Type) {
Richard Smithadaa0152013-05-17 02:09:46 +00001173 default: break;
1174 case EST_Unevaluated:
Richard Smith8acb4282014-07-31 21:57:55 +00001175 OS << " noexcept-unevaluated " << EPI.ExceptionSpec.SourceDecl;
Richard Smithadaa0152013-05-17 02:09:46 +00001176 break;
1177 case EST_Uninstantiated:
Richard Smith8acb4282014-07-31 21:57:55 +00001178 OS << " noexcept-uninstantiated " << EPI.ExceptionSpec.SourceTemplate;
Richard Smithadaa0152013-05-17 02:09:46 +00001179 break;
1180 }
1181 }
1182
Richard Smithf7514452014-10-30 21:02:37 +00001183 if (const FunctionTemplateSpecializationInfo *FTSI =
1184 D->getTemplateSpecializationInfo())
Richard Trieude5cc7d2013-01-31 01:44:26 +00001185 dumpTemplateArgumentList(*FTSI->TemplateArguments);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001186
Richard Smith8a639892015-01-24 01:07:20 +00001187 if (!D->param_begin() && D->getNumParams())
1188 dumpChild([=] { OS << "<<NULL params x " << D->getNumParams() << ">>"; });
1189 else
David Majnemera3debed2016-06-24 05:33:44 +00001190 for (const ParmVarDecl *Parameter : D->parameters())
1191 dumpDecl(Parameter);
Richard Smithf7514452014-10-30 21:02:37 +00001192
1193 if (const CXXConstructorDecl *C = dyn_cast<CXXConstructorDecl>(D))
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001194 for (CXXConstructorDecl::init_const_iterator I = C->init_begin(),
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001195 E = C->init_end();
Richard Smithf7514452014-10-30 21:02:37 +00001196 I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001197 dumpCXXCtorInitializer(*I);
1198
Lenar Safin9ae21552017-07-29 20:42:58 +00001199 if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(D)) {
Lang Hames19e07e12017-06-20 21:06:00 +00001200 if (MD->size_overridden_methods() != 0) {
Aaron Ballman8c208282017-12-21 21:42:42 +00001201 auto dumpOverride = [=](const CXXMethodDecl *D) {
1202 SplitQualType T_split = D->getType().split();
1203 OS << D << " " << D->getParent()->getName()
1204 << "::" << D->getNameAsString() << " '"
1205 << QualType::getAsString(T_split, PrintPolicy) << "'";
1206 };
Lang Hames19e07e12017-06-20 21:06:00 +00001207
1208 dumpChild([=] {
Benjamin Krameracfa3392017-12-17 23:52:45 +00001209 auto Overrides = MD->overridden_methods();
Lang Hames19e07e12017-06-20 21:06:00 +00001210 OS << "Overrides: [ ";
Benjamin Krameracfa3392017-12-17 23:52:45 +00001211 dumpOverride(*Overrides.begin());
Lang Hames19e07e12017-06-20 21:06:00 +00001212 for (const auto *Override :
Benjamin Krameracfa3392017-12-17 23:52:45 +00001213 llvm::make_range(Overrides.begin() + 1, Overrides.end())) {
Lenar Safin9ae21552017-07-29 20:42:58 +00001214 OS << ", ";
Lang Hames19e07e12017-06-20 21:06:00 +00001215 dumpOverride(Override);
Lenar Safin9ae21552017-07-29 20:42:58 +00001216 }
Lang Hames19e07e12017-06-20 21:06:00 +00001217 OS << " ]";
1218 });
1219 }
Lenar Safin9ae21552017-07-29 20:42:58 +00001220 }
Lang Hames19e07e12017-06-20 21:06:00 +00001221
Richard Smithf7514452014-10-30 21:02:37 +00001222 if (D->doesThisDeclarationHaveABody())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001223 dumpStmt(D->getBody());
1224}
1225
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001226void ASTDumper::VisitFieldDecl(const FieldDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001227 dumpName(D);
1228 dumpType(D->getType());
1229 if (D->isMutable())
1230 OS << " mutable";
1231 if (D->isModulePrivate())
1232 OS << " __module_private__";
Richard Trieude5cc7d2013-01-31 01:44:26 +00001233
Richard Smithf7514452014-10-30 21:02:37 +00001234 if (D->isBitField())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001235 dumpStmt(D->getBitWidth());
Richard Smithf7514452014-10-30 21:02:37 +00001236 if (Expr *Init = D->getInClassInitializer())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001237 dumpStmt(Init);
1238}
1239
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001240void ASTDumper::VisitVarDecl(const VarDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001241 dumpName(D);
1242 dumpType(D->getType());
Rafael Espindola6ae7e502013-04-03 19:27:57 +00001243 StorageClass SC = D->getStorageClass();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001244 if (SC != SC_None)
1245 OS << ' ' << VarDecl::getStorageClassSpecifierString(SC);
Richard Smithfd3834f2013-04-13 02:43:54 +00001246 switch (D->getTLSKind()) {
1247 case VarDecl::TLS_None: break;
1248 case VarDecl::TLS_Static: OS << " tls"; break;
1249 case VarDecl::TLS_Dynamic: OS << " tls_dynamic"; break;
1250 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001251 if (D->isModulePrivate())
1252 OS << " __module_private__";
1253 if (D->isNRVOVariable())
1254 OS << " nrvo";
Richard Smith62f19e72016-06-25 00:15:56 +00001255 if (D->isInline())
1256 OS << " inline";
1257 if (D->isConstexpr())
1258 OS << " constexpr";
Richard Trieude5cc7d2013-01-31 01:44:26 +00001259 if (D->hasInit()) {
Richard Smithd9967cc2014-07-10 22:54:03 +00001260 switch (D->getInitStyle()) {
1261 case VarDecl::CInit: OS << " cinit"; break;
1262 case VarDecl::CallInit: OS << " callinit"; break;
1263 case VarDecl::ListInit: OS << " listinit"; break;
1264 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001265 dumpStmt(D->getInit());
Richard Trieude5cc7d2013-01-31 01:44:26 +00001266 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001267}
1268
Richard Smithbdb84f32016-07-22 23:36:59 +00001269void ASTDumper::VisitDecompositionDecl(const DecompositionDecl *D) {
1270 VisitVarDecl(D);
1271 for (auto *B : D->bindings())
1272 dumpDecl(B);
1273}
1274
Richard Smith7873de02016-08-11 22:25:46 +00001275void ASTDumper::VisitBindingDecl(const BindingDecl *D) {
1276 dumpName(D);
1277 dumpType(D->getType());
1278 if (auto *E = D->getBinding())
1279 dumpStmt(E);
1280}
1281
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001282void ASTDumper::VisitFileScopeAsmDecl(const FileScopeAsmDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001283 dumpStmt(D->getAsmString());
1284}
1285
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001286void ASTDumper::VisitImportDecl(const ImportDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001287 OS << ' ' << D->getImportedModule()->getFullModuleName();
1288}
1289
Nico Weber66220292016-03-02 17:28:48 +00001290void ASTDumper::VisitPragmaCommentDecl(const PragmaCommentDecl *D) {
1291 OS << ' ';
1292 switch (D->getCommentKind()) {
1293 case PCK_Unknown: llvm_unreachable("unexpected pragma comment kind");
1294 case PCK_Compiler: OS << "compiler"; break;
1295 case PCK_ExeStr: OS << "exestr"; break;
1296 case PCK_Lib: OS << "lib"; break;
1297 case PCK_Linker: OS << "linker"; break;
1298 case PCK_User: OS << "user"; break;
1299 }
1300 StringRef Arg = D->getArg();
1301 if (!Arg.empty())
1302 OS << " \"" << Arg << "\"";
1303}
1304
Nico Webercbbaeb12016-03-02 19:28:54 +00001305void ASTDumper::VisitPragmaDetectMismatchDecl(
1306 const PragmaDetectMismatchDecl *D) {
1307 OS << " \"" << D->getName() << "\" \"" << D->getValue() << "\"";
1308}
1309
Alexey Bataev958b9e72016-03-31 09:30:50 +00001310void ASTDumper::VisitCapturedDecl(const CapturedDecl *D) {
1311 dumpStmt(D->getBody());
1312}
1313
1314//===----------------------------------------------------------------------===//
1315// OpenMP Declarations
1316//===----------------------------------------------------------------------===//
1317
1318void ASTDumper::VisitOMPThreadPrivateDecl(const OMPThreadPrivateDecl *D) {
1319 for (auto *E : D->varlists())
1320 dumpStmt(E);
1321}
1322
1323void ASTDumper::VisitOMPDeclareReductionDecl(const OMPDeclareReductionDecl *D) {
1324 dumpName(D);
1325 dumpType(D->getType());
1326 OS << " combiner";
1327 dumpStmt(D->getCombiner());
1328 if (auto *Initializer = D->getInitializer()) {
1329 OS << " initializer";
Alexey Bataev070f43a2017-09-06 14:49:58 +00001330 switch (D->getInitializerKind()) {
1331 case OMPDeclareReductionDecl::DirectInit:
1332 OS << " omp_priv = ";
1333 break;
1334 case OMPDeclareReductionDecl::CopyInit:
1335 OS << " omp_priv ()";
1336 break;
1337 case OMPDeclareReductionDecl::CallInit:
1338 break;
1339 }
Alexey Bataev958b9e72016-03-31 09:30:50 +00001340 dumpStmt(Initializer);
1341 }
1342}
1343
Kelvin Li1408f912018-09-26 04:28:39 +00001344void ASTDumper::VisitOMPRequiresDecl(const OMPRequiresDecl *D) {
1345 for (auto *C : D->clauselists()) {
1346 dumpChild([=] {
1347 if (!C) {
1348 ColorScope Color(*this, NullColor);
1349 OS << "<<<NULL>>> OMPClause";
1350 return;
1351 }
1352 {
1353 ColorScope Color(*this, AttrColor);
1354 StringRef ClauseName(getOpenMPClauseName(C->getClauseKind()));
1355 OS << "OMP" << ClauseName.substr(/*Start=*/0, /*N=*/1).upper()
1356 << ClauseName.drop_front() << "Clause";
1357 }
1358 dumpPointer(C);
1359 dumpSourceRange(SourceRange(C->getBeginLoc(), C->getEndLoc()));
1360 });
1361 }
1362}
1363
Alexey Bataev958b9e72016-03-31 09:30:50 +00001364void ASTDumper::VisitOMPCapturedExprDecl(const OMPCapturedExprDecl *D) {
1365 dumpName(D);
1366 dumpType(D->getType());
1367 dumpStmt(D->getInit());
1368}
Nico Webercbbaeb12016-03-02 19:28:54 +00001369
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001370//===----------------------------------------------------------------------===//
1371// C++ Declarations
1372//===----------------------------------------------------------------------===//
1373
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001374void ASTDumper::VisitNamespaceDecl(const NamespaceDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001375 dumpName(D);
1376 if (D->isInline())
1377 OS << " inline";
1378 if (!D->isOriginalNamespace())
1379 dumpDeclRef(D->getOriginalNamespace(), "original");
1380}
1381
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001382void ASTDumper::VisitUsingDirectiveDecl(const UsingDirectiveDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001383 OS << ' ';
1384 dumpBareDeclRef(D->getNominatedNamespace());
1385}
1386
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001387void ASTDumper::VisitNamespaceAliasDecl(const NamespaceAliasDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001388 dumpName(D);
1389 dumpDeclRef(D->getAliasedNamespace());
1390}
1391
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001392void ASTDumper::VisitTypeAliasDecl(const TypeAliasDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001393 dumpName(D);
1394 dumpType(D->getUnderlyingType());
Richard Smithba3a4f92016-01-12 21:59:26 +00001395 dumpTypeAsChild(D->getUnderlyingType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001396}
1397
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001398void ASTDumper::VisitTypeAliasTemplateDecl(const TypeAliasTemplateDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001399 dumpName(D);
1400 dumpTemplateParameters(D->getTemplateParameters());
1401 dumpDecl(D->getTemplatedDecl());
1402}
1403
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001404void ASTDumper::VisitCXXRecordDecl(const CXXRecordDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001405 VisitRecordDecl(D);
1406 if (!D->isCompleteDefinition())
1407 return;
1408
Richard Smithdfc4bff2017-09-22 00:11:15 +00001409 dumpChild([=] {
1410 {
1411 ColorScope Color(*this, DeclKindNameColor);
1412 OS << "DefinitionData";
1413 }
1414#define FLAG(fn, name) if (D->fn()) OS << " " #name;
1415 FLAG(isParsingBaseSpecifiers, parsing_base_specifiers);
1416
1417 FLAG(isGenericLambda, generic);
1418 FLAG(isLambda, lambda);
1419
1420 FLAG(canPassInRegisters, pass_in_registers);
1421 FLAG(isEmpty, empty);
1422 FLAG(isAggregate, aggregate);
1423 FLAG(isStandardLayout, standard_layout);
1424 FLAG(isTriviallyCopyable, trivially_copyable);
1425 FLAG(isPOD, pod);
1426 FLAG(isTrivial, trivial);
1427 FLAG(isPolymorphic, polymorphic);
1428 FLAG(isAbstract, abstract);
1429 FLAG(isLiteral, literal);
1430
1431 FLAG(hasUserDeclaredConstructor, has_user_declared_ctor);
1432 FLAG(hasConstexprNonCopyMoveConstructor, has_constexpr_non_copy_move_ctor);
1433 FLAG(hasMutableFields, has_mutable_fields);
1434 FLAG(hasVariantMembers, has_variant_members);
1435 FLAG(allowConstDefaultInit, can_const_default_init);
1436
1437 dumpChild([=] {
1438 {
1439 ColorScope Color(*this, DeclKindNameColor);
1440 OS << "DefaultConstructor";
1441 }
1442 FLAG(hasDefaultConstructor, exists);
1443 FLAG(hasTrivialDefaultConstructor, trivial);
1444 FLAG(hasNonTrivialDefaultConstructor, non_trivial);
1445 FLAG(hasUserProvidedDefaultConstructor, user_provided);
1446 FLAG(hasConstexprDefaultConstructor, constexpr);
1447 FLAG(needsImplicitDefaultConstructor, needs_implicit);
1448 FLAG(defaultedDefaultConstructorIsConstexpr, defaulted_is_constexpr);
1449 });
1450
1451 dumpChild([=] {
1452 {
1453 ColorScope Color(*this, DeclKindNameColor);
1454 OS << "CopyConstructor";
1455 }
1456 FLAG(hasSimpleCopyConstructor, simple);
1457 FLAG(hasTrivialCopyConstructor, trivial);
1458 FLAG(hasNonTrivialCopyConstructor, non_trivial);
1459 FLAG(hasUserDeclaredCopyConstructor, user_declared);
1460 FLAG(hasCopyConstructorWithConstParam, has_const_param);
1461 FLAG(needsImplicitCopyConstructor, needs_implicit);
1462 FLAG(needsOverloadResolutionForCopyConstructor,
1463 needs_overload_resolution);
1464 if (!D->needsOverloadResolutionForCopyConstructor())
1465 FLAG(defaultedCopyConstructorIsDeleted, defaulted_is_deleted);
1466 FLAG(implicitCopyConstructorHasConstParam, implicit_has_const_param);
1467 });
1468
1469 dumpChild([=] {
1470 {
1471 ColorScope Color(*this, DeclKindNameColor);
1472 OS << "MoveConstructor";
1473 }
1474 FLAG(hasMoveConstructor, exists);
1475 FLAG(hasSimpleMoveConstructor, simple);
1476 FLAG(hasTrivialMoveConstructor, trivial);
1477 FLAG(hasNonTrivialMoveConstructor, non_trivial);
1478 FLAG(hasUserDeclaredMoveConstructor, user_declared);
1479 FLAG(needsImplicitMoveConstructor, needs_implicit);
1480 FLAG(needsOverloadResolutionForMoveConstructor,
1481 needs_overload_resolution);
1482 if (!D->needsOverloadResolutionForMoveConstructor())
1483 FLAG(defaultedMoveConstructorIsDeleted, defaulted_is_deleted);
1484 });
1485
1486 dumpChild([=] {
1487 {
1488 ColorScope Color(*this, DeclKindNameColor);
1489 OS << "CopyAssignment";
1490 }
1491 FLAG(hasTrivialCopyAssignment, trivial);
1492 FLAG(hasNonTrivialCopyAssignment, non_trivial);
1493 FLAG(hasCopyAssignmentWithConstParam, has_const_param);
1494 FLAG(hasUserDeclaredCopyAssignment, user_declared);
1495 FLAG(needsImplicitCopyAssignment, needs_implicit);
1496 FLAG(needsOverloadResolutionForCopyAssignment, needs_overload_resolution);
1497 FLAG(implicitCopyAssignmentHasConstParam, implicit_has_const_param);
1498 });
1499
1500 dumpChild([=] {
1501 {
1502 ColorScope Color(*this, DeclKindNameColor);
1503 OS << "MoveAssignment";
1504 }
1505 FLAG(hasMoveAssignment, exists);
1506 FLAG(hasSimpleMoveAssignment, simple);
1507 FLAG(hasTrivialMoveAssignment, trivial);
1508 FLAG(hasNonTrivialMoveAssignment, non_trivial);
1509 FLAG(hasUserDeclaredMoveAssignment, user_declared);
1510 FLAG(needsImplicitMoveAssignment, needs_implicit);
1511 FLAG(needsOverloadResolutionForMoveAssignment, needs_overload_resolution);
1512 });
1513
1514 dumpChild([=] {
1515 {
1516 ColorScope Color(*this, DeclKindNameColor);
1517 OS << "Destructor";
1518 }
1519 FLAG(hasSimpleDestructor, simple);
1520 FLAG(hasIrrelevantDestructor, irrelevant);
1521 FLAG(hasTrivialDestructor, trivial);
1522 FLAG(hasNonTrivialDestructor, non_trivial);
1523 FLAG(hasUserDeclaredDestructor, user_declared);
1524 FLAG(needsImplicitDestructor, needs_implicit);
1525 FLAG(needsOverloadResolutionForDestructor, needs_overload_resolution);
1526 if (!D->needsOverloadResolutionForDestructor())
1527 FLAG(defaultedDestructorIsDeleted, defaulted_is_deleted);
1528 });
1529 });
1530
Aaron Ballman574705e2014-03-13 15:41:46 +00001531 for (const auto &I : D->bases()) {
Richard Smithf7514452014-10-30 21:02:37 +00001532 dumpChild([=] {
1533 if (I.isVirtual())
1534 OS << "virtual ";
1535 dumpAccessSpecifier(I.getAccessSpecifier());
1536 dumpType(I.getType());
1537 if (I.isPackExpansion())
1538 OS << "...";
1539 });
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001540 }
1541}
1542
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001543void ASTDumper::VisitStaticAssertDecl(const StaticAssertDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001544 dumpStmt(D->getAssertExpr());
1545 dumpStmt(D->getMessage());
1546}
1547
Richard Smithcbdf7332014-03-18 02:07:28 +00001548template<typename SpecializationDecl>
Richard Smithf7514452014-10-30 21:02:37 +00001549void ASTDumper::VisitTemplateDeclSpecialization(const SpecializationDecl *D,
Richard Smithcbdf7332014-03-18 02:07:28 +00001550 bool DumpExplicitInst,
1551 bool DumpRefOnly) {
1552 bool DumpedAny = false;
1553 for (auto *RedeclWithBadType : D->redecls()) {
1554 // FIXME: The redecls() range sometimes has elements of a less-specific
1555 // type. (In particular, ClassTemplateSpecializationDecl::redecls() gives
1556 // us TagDecls, and should give CXXRecordDecls).
1557 auto *Redecl = dyn_cast<SpecializationDecl>(RedeclWithBadType);
1558 if (!Redecl) {
1559 // Found the injected-class-name for a class template. This will be dumped
1560 // as part of its surrounding class so we don't need to dump it here.
1561 assert(isa<CXXRecordDecl>(RedeclWithBadType) &&
1562 "expected an injected-class-name");
1563 continue;
1564 }
1565
1566 switch (Redecl->getTemplateSpecializationKind()) {
1567 case TSK_ExplicitInstantiationDeclaration:
1568 case TSK_ExplicitInstantiationDefinition:
1569 if (!DumpExplicitInst)
1570 break;
Adrian Prantlf3b3ccd2017-12-19 22:06:11 +00001571 LLVM_FALLTHROUGH;
Richard Smithcbdf7332014-03-18 02:07:28 +00001572 case TSK_Undeclared:
1573 case TSK_ImplicitInstantiation:
Richard Smithf7514452014-10-30 21:02:37 +00001574 if (DumpRefOnly)
1575 dumpDeclRef(Redecl);
1576 else
1577 dumpDecl(Redecl);
Richard Smithcbdf7332014-03-18 02:07:28 +00001578 DumpedAny = true;
1579 break;
1580 case TSK_ExplicitSpecialization:
1581 break;
1582 }
1583 }
1584
1585 // Ensure we dump at least one decl for each specialization.
1586 if (!DumpedAny)
Richard Smithf7514452014-10-30 21:02:37 +00001587 dumpDeclRef(D);
Richard Smithcbdf7332014-03-18 02:07:28 +00001588}
1589
Richard Smith20ade552014-03-17 23:34:53 +00001590template<typename TemplateDecl>
1591void ASTDumper::VisitTemplateDecl(const TemplateDecl *D,
1592 bool DumpExplicitInst) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001593 dumpName(D);
1594 dumpTemplateParameters(D->getTemplateParameters());
Richard Smithdcc2c452014-03-17 23:00:06 +00001595
Richard Smithf7514452014-10-30 21:02:37 +00001596 dumpDecl(D->getTemplatedDecl());
Richard Smithdcc2c452014-03-17 23:00:06 +00001597
Richard Smithcbdf7332014-03-18 02:07:28 +00001598 for (auto *Child : D->specializations())
Richard Smithf7514452014-10-30 21:02:37 +00001599 VisitTemplateDeclSpecialization(Child, DumpExplicitInst,
Richard Smithcbdf7332014-03-18 02:07:28 +00001600 !D->isCanonicalDecl());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001601}
1602
Richard Smith20ade552014-03-17 23:34:53 +00001603void ASTDumper::VisitFunctionTemplateDecl(const FunctionTemplateDecl *D) {
1604 // FIXME: We don't add a declaration of a function template specialization
1605 // to its context when it's explicitly instantiated, so dump explicit
1606 // instantiations when we dump the template itself.
1607 VisitTemplateDecl(D, true);
1608}
1609
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001610void ASTDumper::VisitClassTemplateDecl(const ClassTemplateDecl *D) {
Richard Smith20ade552014-03-17 23:34:53 +00001611 VisitTemplateDecl(D, false);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001612}
1613
1614void ASTDumper::VisitClassTemplateSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001615 const ClassTemplateSpecializationDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001616 VisitCXXRecordDecl(D);
1617 dumpTemplateArgumentList(D->getTemplateArgs());
1618}
1619
1620void ASTDumper::VisitClassTemplatePartialSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001621 const ClassTemplatePartialSpecializationDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001622 VisitClassTemplateSpecializationDecl(D);
1623 dumpTemplateParameters(D->getTemplateParameters());
1624}
1625
1626void ASTDumper::VisitClassScopeFunctionSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001627 const ClassScopeFunctionSpecializationDecl *D) {
Richard Smithc660c8f2018-03-16 13:36:56 +00001628 dumpDecl(D->getSpecialization());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001629 if (D->hasExplicitTemplateArgs())
1630 dumpTemplateArgumentListInfo(D->templateArgs());
1631}
1632
Richard Smithd25789a2013-09-18 01:36:02 +00001633void ASTDumper::VisitVarTemplateDecl(const VarTemplateDecl *D) {
Richard Smith20ade552014-03-17 23:34:53 +00001634 VisitTemplateDecl(D, false);
Richard Smithd25789a2013-09-18 01:36:02 +00001635}
1636
David Majnemerd9b1a4f2015-11-04 03:40:30 +00001637void ASTDumper::VisitBuiltinTemplateDecl(const BuiltinTemplateDecl *D) {
1638 dumpName(D);
1639 dumpTemplateParameters(D->getTemplateParameters());
1640}
1641
Richard Smithd25789a2013-09-18 01:36:02 +00001642void ASTDumper::VisitVarTemplateSpecializationDecl(
1643 const VarTemplateSpecializationDecl *D) {
1644 dumpTemplateArgumentList(D->getTemplateArgs());
1645 VisitVarDecl(D);
1646}
1647
1648void ASTDumper::VisitVarTemplatePartialSpecializationDecl(
1649 const VarTemplatePartialSpecializationDecl *D) {
1650 dumpTemplateParameters(D->getTemplateParameters());
1651 VisitVarTemplateSpecializationDecl(D);
1652}
1653
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001654void ASTDumper::VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001655 if (D->wasDeclaredWithTypename())
1656 OS << " typename";
1657 else
1658 OS << " class";
Richard Smith1832a022017-02-21 02:04:03 +00001659 OS << " depth " << D->getDepth() << " index " << D->getIndex();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001660 if (D->isParameterPack())
1661 OS << " ...";
1662 dumpName(D);
Richard Smithf7514452014-10-30 21:02:37 +00001663 if (D->hasDefaultArgument())
Richard Smithecf74ff2014-03-23 20:50:39 +00001664 dumpTemplateArgument(D->getDefaultArgument());
Richard Smithc4577662018-09-12 02:13:47 +00001665 if (auto *From = D->getDefaultArgStorage().getInheritedFrom())
1666 dumpDeclRef(From, D->defaultArgumentWasInherited() ? "inherited from"
1667 : "previous");
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001668}
1669
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001670void ASTDumper::VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001671 dumpType(D->getType());
Richard Smith1832a022017-02-21 02:04:03 +00001672 OS << " depth " << D->getDepth() << " index " << D->getIndex();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001673 if (D->isParameterPack())
1674 OS << " ...";
1675 dumpName(D);
Richard Smithf7514452014-10-30 21:02:37 +00001676 if (D->hasDefaultArgument())
Richard Smithecf74ff2014-03-23 20:50:39 +00001677 dumpTemplateArgument(D->getDefaultArgument());
Richard Smithc4577662018-09-12 02:13:47 +00001678 if (auto *From = D->getDefaultArgStorage().getInheritedFrom())
1679 dumpDeclRef(From, D->defaultArgumentWasInherited() ? "inherited from"
1680 : "previous");
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001681}
1682
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001683void ASTDumper::VisitTemplateTemplateParmDecl(
1684 const TemplateTemplateParmDecl *D) {
Richard Smith1832a022017-02-21 02:04:03 +00001685 OS << " depth " << D->getDepth() << " index " << D->getIndex();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001686 if (D->isParameterPack())
1687 OS << " ...";
1688 dumpName(D);
1689 dumpTemplateParameters(D->getTemplateParameters());
Richard Smithf7514452014-10-30 21:02:37 +00001690 if (D->hasDefaultArgument())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001691 dumpTemplateArgumentLoc(D->getDefaultArgument());
Richard Smithc4577662018-09-12 02:13:47 +00001692 if (auto *From = D->getDefaultArgStorage().getInheritedFrom())
1693 dumpDeclRef(From, D->defaultArgumentWasInherited() ? "inherited from"
1694 : "previous");
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001695}
1696
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001697void ASTDumper::VisitUsingDecl(const UsingDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001698 OS << ' ';
Dawn Perchikddd03bf2015-12-05 22:37:55 +00001699 if (D->getQualifier())
1700 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001701 OS << D->getNameAsString();
1702}
1703
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001704void ASTDumper::VisitUnresolvedUsingTypenameDecl(
1705 const UnresolvedUsingTypenameDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001706 OS << ' ';
Dawn Perchikddd03bf2015-12-05 22:37:55 +00001707 if (D->getQualifier())
1708 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001709 OS << D->getNameAsString();
1710}
1711
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001712void ASTDumper::VisitUnresolvedUsingValueDecl(const UnresolvedUsingValueDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001713 OS << ' ';
Dawn Perchikddd03bf2015-12-05 22:37:55 +00001714 if (D->getQualifier())
1715 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001716 OS << D->getNameAsString();
1717 dumpType(D->getType());
1718}
1719
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001720void ASTDumper::VisitUsingShadowDecl(const UsingShadowDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001721 OS << ' ';
1722 dumpBareDeclRef(D->getTargetDecl());
Richard Smithba3a4f92016-01-12 21:59:26 +00001723 if (auto *TD = dyn_cast<TypeDecl>(D->getUnderlyingDecl()))
1724 dumpTypeAsChild(TD->getTypeForDecl());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001725}
1726
Richard Smith5179eb72016-06-28 19:03:57 +00001727void ASTDumper::VisitConstructorUsingShadowDecl(
1728 const ConstructorUsingShadowDecl *D) {
1729 if (D->constructsVirtualBase())
1730 OS << " virtual";
1731
1732 dumpChild([=] {
1733 OS << "target ";
1734 dumpBareDeclRef(D->getTargetDecl());
1735 });
1736
1737 dumpChild([=] {
1738 OS << "nominated ";
1739 dumpBareDeclRef(D->getNominatedBaseClass());
1740 OS << ' ';
1741 dumpBareDeclRef(D->getNominatedBaseClassShadowDecl());
1742 });
1743
1744 dumpChild([=] {
1745 OS << "constructed ";
1746 dumpBareDeclRef(D->getConstructedBaseClass());
1747 OS << ' ';
1748 dumpBareDeclRef(D->getConstructedBaseClassShadowDecl());
1749 });
1750}
1751
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001752void ASTDumper::VisitLinkageSpecDecl(const LinkageSpecDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001753 switch (D->getLanguage()) {
1754 case LinkageSpecDecl::lang_c: OS << " C"; break;
1755 case LinkageSpecDecl::lang_cxx: OS << " C++"; break;
1756 }
1757}
1758
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001759void ASTDumper::VisitAccessSpecDecl(const AccessSpecDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001760 OS << ' ';
1761 dumpAccessSpecifier(D->getAccess());
1762}
1763
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001764void ASTDumper::VisitFriendDecl(const FriendDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001765 if (TypeSourceInfo *T = D->getFriendType())
1766 dumpType(T->getType());
1767 else
1768 dumpDecl(D->getFriendDecl());
1769}
1770
1771//===----------------------------------------------------------------------===//
1772// Obj-C Declarations
1773//===----------------------------------------------------------------------===//
1774
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001775void ASTDumper::VisitObjCIvarDecl(const ObjCIvarDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001776 dumpName(D);
1777 dumpType(D->getType());
1778 if (D->getSynthesize())
1779 OS << " synthesize";
1780
1781 switch (D->getAccessControl()) {
1782 case ObjCIvarDecl::None:
1783 OS << " none";
1784 break;
1785 case ObjCIvarDecl::Private:
1786 OS << " private";
1787 break;
1788 case ObjCIvarDecl::Protected:
1789 OS << " protected";
1790 break;
1791 case ObjCIvarDecl::Public:
1792 OS << " public";
1793 break;
1794 case ObjCIvarDecl::Package:
1795 OS << " package";
1796 break;
1797 }
1798}
1799
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001800void ASTDumper::VisitObjCMethodDecl(const ObjCMethodDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001801 if (D->isInstanceMethod())
1802 OS << " -";
1803 else
1804 OS << " +";
1805 dumpName(D);
Alp Toker314cc812014-01-25 16:55:45 +00001806 dumpType(D->getReturnType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001807
Richard Trieude5cc7d2013-01-31 01:44:26 +00001808 if (D->isThisDeclarationADefinition()) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001809 dumpDeclContext(D);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001810 } else {
David Majnemera3debed2016-06-24 05:33:44 +00001811 for (const ParmVarDecl *Parameter : D->parameters())
1812 dumpDecl(Parameter);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001813 }
1814
Richard Smithf7514452014-10-30 21:02:37 +00001815 if (D->isVariadic())
1816 dumpChild([=] { OS << "..."; });
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001817
Richard Smithf7514452014-10-30 21:02:37 +00001818 if (D->hasBody())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001819 dumpStmt(D->getBody());
1820}
1821
Douglas Gregor85f3f952015-07-07 03:57:15 +00001822void ASTDumper::VisitObjCTypeParamDecl(const ObjCTypeParamDecl *D) {
1823 dumpName(D);
Douglas Gregor1ac1b632015-07-07 03:58:54 +00001824 switch (D->getVariance()) {
1825 case ObjCTypeParamVariance::Invariant:
1826 break;
1827
1828 case ObjCTypeParamVariance::Covariant:
1829 OS << " covariant";
1830 break;
1831
1832 case ObjCTypeParamVariance::Contravariant:
1833 OS << " contravariant";
1834 break;
1835 }
1836
Douglas Gregor85f3f952015-07-07 03:57:15 +00001837 if (D->hasExplicitBound())
1838 OS << " bounded";
1839 dumpType(D->getUnderlyingType());
1840}
1841
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001842void ASTDumper::VisitObjCCategoryDecl(const ObjCCategoryDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001843 dumpName(D);
1844 dumpDeclRef(D->getClassInterface());
Douglas Gregor85f3f952015-07-07 03:57:15 +00001845 dumpObjCTypeParamList(D->getTypeParamList());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001846 dumpDeclRef(D->getImplementation());
1847 for (ObjCCategoryDecl::protocol_iterator I = D->protocol_begin(),
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001848 E = D->protocol_end();
Richard Smithf7514452014-10-30 21:02:37 +00001849 I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001850 dumpDeclRef(*I);
1851}
1852
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001853void ASTDumper::VisitObjCCategoryImplDecl(const ObjCCategoryImplDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001854 dumpName(D);
1855 dumpDeclRef(D->getClassInterface());
1856 dumpDeclRef(D->getCategoryDecl());
1857}
1858
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001859void ASTDumper::VisitObjCProtocolDecl(const ObjCProtocolDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001860 dumpName(D);
Richard Smithdcc2c452014-03-17 23:00:06 +00001861
Richard Smith7fcb35f2014-03-18 02:37:59 +00001862 for (auto *Child : D->protocols())
Richard Smithf7514452014-10-30 21:02:37 +00001863 dumpDeclRef(Child);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001864}
1865
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001866void ASTDumper::VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001867 dumpName(D);
Douglas Gregor85f3f952015-07-07 03:57:15 +00001868 dumpObjCTypeParamList(D->getTypeParamListAsWritten());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001869 dumpDeclRef(D->getSuperClass(), "super");
Richard Smithdcc2c452014-03-17 23:00:06 +00001870
Richard Smithf7514452014-10-30 21:02:37 +00001871 dumpDeclRef(D->getImplementation());
Richard Smith7fcb35f2014-03-18 02:37:59 +00001872 for (auto *Child : D->protocols())
Richard Smithf7514452014-10-30 21:02:37 +00001873 dumpDeclRef(Child);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001874}
1875
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001876void ASTDumper::VisitObjCImplementationDecl(const ObjCImplementationDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001877 dumpName(D);
1878 dumpDeclRef(D->getSuperClass(), "super");
1879 dumpDeclRef(D->getClassInterface());
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001880 for (ObjCImplementationDecl::init_const_iterator I = D->init_begin(),
1881 E = D->init_end();
Richard Smithf7514452014-10-30 21:02:37 +00001882 I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001883 dumpCXXCtorInitializer(*I);
1884}
1885
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001886void ASTDumper::VisitObjCCompatibleAliasDecl(const ObjCCompatibleAliasDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001887 dumpName(D);
1888 dumpDeclRef(D->getClassInterface());
1889}
1890
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001891void ASTDumper::VisitObjCPropertyDecl(const ObjCPropertyDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001892 dumpName(D);
1893 dumpType(D->getType());
1894
1895 if (D->getPropertyImplementation() == ObjCPropertyDecl::Required)
1896 OS << " required";
1897 else if (D->getPropertyImplementation() == ObjCPropertyDecl::Optional)
1898 OS << " optional";
1899
1900 ObjCPropertyDecl::PropertyAttributeKind Attrs = D->getPropertyAttributes();
1901 if (Attrs != ObjCPropertyDecl::OBJC_PR_noattr) {
1902 if (Attrs & ObjCPropertyDecl::OBJC_PR_readonly)
1903 OS << " readonly";
1904 if (Attrs & ObjCPropertyDecl::OBJC_PR_assign)
1905 OS << " assign";
1906 if (Attrs & ObjCPropertyDecl::OBJC_PR_readwrite)
1907 OS << " readwrite";
1908 if (Attrs & ObjCPropertyDecl::OBJC_PR_retain)
1909 OS << " retain";
1910 if (Attrs & ObjCPropertyDecl::OBJC_PR_copy)
1911 OS << " copy";
1912 if (Attrs & ObjCPropertyDecl::OBJC_PR_nonatomic)
1913 OS << " nonatomic";
1914 if (Attrs & ObjCPropertyDecl::OBJC_PR_atomic)
1915 OS << " atomic";
1916 if (Attrs & ObjCPropertyDecl::OBJC_PR_weak)
1917 OS << " weak";
1918 if (Attrs & ObjCPropertyDecl::OBJC_PR_strong)
1919 OS << " strong";
1920 if (Attrs & ObjCPropertyDecl::OBJC_PR_unsafe_unretained)
1921 OS << " unsafe_unretained";
Manman Ren387ff7f2016-01-26 18:52:43 +00001922 if (Attrs & ObjCPropertyDecl::OBJC_PR_class)
1923 OS << " class";
Richard Smithf7514452014-10-30 21:02:37 +00001924 if (Attrs & ObjCPropertyDecl::OBJC_PR_getter)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001925 dumpDeclRef(D->getGetterMethodDecl(), "getter");
Richard Smithf7514452014-10-30 21:02:37 +00001926 if (Attrs & ObjCPropertyDecl::OBJC_PR_setter)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001927 dumpDeclRef(D->getSetterMethodDecl(), "setter");
1928 }
1929}
1930
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001931void ASTDumper::VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001932 dumpName(D->getPropertyDecl());
1933 if (D->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize)
1934 OS << " synthesize";
1935 else
1936 OS << " dynamic";
1937 dumpDeclRef(D->getPropertyDecl());
1938 dumpDeclRef(D->getPropertyIvarDecl());
1939}
1940
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001941void ASTDumper::VisitBlockDecl(const BlockDecl *D) {
David Majnemer59f77922016-06-24 04:05:48 +00001942 for (auto I : D->parameters())
Aaron Ballmanb2b8b1d2014-03-07 16:09:59 +00001943 dumpDecl(I);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001944
Richard Smithf7514452014-10-30 21:02:37 +00001945 if (D->isVariadic())
1946 dumpChild([=]{ OS << "..."; });
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001947
Richard Smithf7514452014-10-30 21:02:37 +00001948 if (D->capturesCXXThis())
1949 dumpChild([=]{ OS << "capture this"; });
1950
Aaron Ballman9371dd22014-03-14 18:34:04 +00001951 for (const auto &I : D->captures()) {
Richard Smithf7514452014-10-30 21:02:37 +00001952 dumpChild([=] {
1953 OS << "capture";
1954 if (I.isByRef())
1955 OS << " byref";
1956 if (I.isNested())
1957 OS << " nested";
1958 if (I.getVariable()) {
1959 OS << ' ';
1960 dumpBareDeclRef(I.getVariable());
1961 }
1962 if (I.hasCopyExpr())
1963 dumpStmt(I.getCopyExpr());
1964 });
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001965 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001966 dumpStmt(D->getBody());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001967}
1968
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001969//===----------------------------------------------------------------------===//
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001970// Stmt dumping methods.
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001971//===----------------------------------------------------------------------===//
1972
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001973void ASTDumper::dumpStmt(const Stmt *S) {
Richard Smithf7514452014-10-30 21:02:37 +00001974 dumpChild([=] {
1975 if (!S) {
1976 ColorScope Color(*this, NullColor);
1977 OS << "<<<NULL>>>";
1978 return;
1979 }
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001980
Richard Smith01ccebf2018-01-05 21:31:07 +00001981 // Some statements have custom mechanisms for dumping their children.
Richard Smithf7514452014-10-30 21:02:37 +00001982 if (const DeclStmt *DS = dyn_cast<DeclStmt>(S)) {
1983 VisitDeclStmt(DS);
1984 return;
1985 }
Richard Smith01ccebf2018-01-05 21:31:07 +00001986 if (const GenericSelectionExpr *GSE = dyn_cast<GenericSelectionExpr>(S)) {
1987 VisitGenericSelectionExpr(GSE);
1988 return;
1989 }
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001990
Richard Smithf7514452014-10-30 21:02:37 +00001991 ConstStmtVisitor<ASTDumper>::Visit(S);
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001992
Benjamin Kramer642f1732015-07-02 21:03:14 +00001993 for (const Stmt *SubStmt : S->children())
1994 dumpStmt(SubStmt);
Richard Smithf7514452014-10-30 21:02:37 +00001995 });
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001996}
1997
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001998void ASTDumper::VisitStmt(const Stmt *Node) {
Fangrui Song6907ce22018-07-30 19:24:48 +00001999 {
Richard Trieud215b8d2013-01-26 01:31:20 +00002000 ColorScope Color(*this, StmtColor);
2001 OS << Node->getStmtClassName();
2002 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002003 dumpPointer(Node);
2004 dumpSourceRange(Node->getSourceRange());
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002005}
2006
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002007void ASTDumper::VisitDeclStmt(const DeclStmt *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002008 VisitStmt(Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002009 for (DeclStmt::const_decl_iterator I = Node->decl_begin(),
2010 E = Node->decl_end();
Richard Smithf7514452014-10-30 21:02:37 +00002011 I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002012 dumpDecl(*I);
Ted Kremenek433a4922007-12-12 06:59:42 +00002013}
2014
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002015void ASTDumper::VisitAttributedStmt(const AttributedStmt *Node) {
Alexander Kornienko5bc364e2013-01-07 17:53:08 +00002016 VisitStmt(Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002017 for (ArrayRef<const Attr *>::iterator I = Node->getAttrs().begin(),
2018 E = Node->getAttrs().end();
Richard Smithf7514452014-10-30 21:02:37 +00002019 I != E; ++I)
Alexander Kornienko5bc364e2013-01-07 17:53:08 +00002020 dumpAttr(*I);
2021}
2022
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002023void ASTDumper::VisitLabelStmt(const LabelStmt *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002024 VisitStmt(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002025 OS << " '" << Node->getName() << "'";
Chris Lattnercbe4f772007-08-08 22:51:59 +00002026}
2027
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002028void ASTDumper::VisitGotoStmt(const GotoStmt *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002029 VisitStmt(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002030 OS << " '" << Node->getLabel()->getName() << "'";
2031 dumpPointer(Node->getLabel());
Chris Lattnercbe4f772007-08-08 22:51:59 +00002032}
2033
Pavel Labath1ef83422013-09-04 14:35:00 +00002034void ASTDumper::VisitCXXCatchStmt(const CXXCatchStmt *Node) {
2035 VisitStmt(Node);
2036 dumpDecl(Node->getExceptionDecl());
2037}
2038
Alexey Bataev958b9e72016-03-31 09:30:50 +00002039void ASTDumper::VisitCapturedStmt(const CapturedStmt *Node) {
2040 VisitStmt(Node);
2041 dumpDecl(Node->getCapturedDecl());
2042}
2043
2044//===----------------------------------------------------------------------===//
2045// OpenMP dumping methods.
2046//===----------------------------------------------------------------------===//
2047
2048void ASTDumper::VisitOMPExecutableDirective(
2049 const OMPExecutableDirective *Node) {
2050 VisitStmt(Node);
2051 for (auto *C : Node->clauses()) {
2052 dumpChild([=] {
2053 if (!C) {
2054 ColorScope Color(*this, NullColor);
2055 OS << "<<<NULL>>> OMPClause";
2056 return;
2057 }
2058 {
2059 ColorScope Color(*this, AttrColor);
2060 StringRef ClauseName(getOpenMPClauseName(C->getClauseKind()));
2061 OS << "OMP" << ClauseName.substr(/*Start=*/0, /*N=*/1).upper()
2062 << ClauseName.drop_front() << "Clause";
2063 }
2064 dumpPointer(C);
Stephen Kelly1c301dc2018-08-09 21:09:38 +00002065 dumpSourceRange(SourceRange(C->getBeginLoc(), C->getEndLoc()));
Alexey Bataev958b9e72016-03-31 09:30:50 +00002066 if (C->isImplicit())
2067 OS << " <implicit>";
2068 for (auto *S : C->children())
2069 dumpStmt(S);
2070 });
2071 }
2072}
2073
Chris Lattnercbe4f772007-08-08 22:51:59 +00002074//===----------------------------------------------------------------------===//
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002075// Expr dumping methods.
Chris Lattnercbe4f772007-08-08 22:51:59 +00002076//===----------------------------------------------------------------------===//
2077
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002078void ASTDumper::VisitExpr(const Expr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002079 VisitStmt(Node);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002080 dumpType(Node->getType());
2081
Richard Trieud215b8d2013-01-26 01:31:20 +00002082 {
2083 ColorScope Color(*this, ValueKindColor);
2084 switch (Node->getValueKind()) {
2085 case VK_RValue:
2086 break;
2087 case VK_LValue:
2088 OS << " lvalue";
2089 break;
2090 case VK_XValue:
2091 OS << " xvalue";
2092 break;
2093 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002094 }
2095
Richard Trieud215b8d2013-01-26 01:31:20 +00002096 {
2097 ColorScope Color(*this, ObjectKindColor);
2098 switch (Node->getObjectKind()) {
2099 case OK_Ordinary:
2100 break;
2101 case OK_BitField:
2102 OS << " bitfield";
2103 break;
2104 case OK_ObjCProperty:
2105 OS << " objcproperty";
2106 break;
2107 case OK_ObjCSubscript:
2108 OS << " objcsubscript";
2109 break;
2110 case OK_VectorComponent:
2111 OS << " vectorcomponent";
2112 break;
2113 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002114 }
Chris Lattnercbe4f772007-08-08 22:51:59 +00002115}
2116
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002117static void dumpBasePath(raw_ostream &OS, const CastExpr *Node) {
John McCallcf142162010-08-07 06:22:56 +00002118 if (Node->path_empty())
Anders Carlssona70cff62010-04-24 19:06:50 +00002119 return;
2120
2121 OS << " (";
2122 bool First = true;
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002123 for (CastExpr::path_const_iterator I = Node->path_begin(),
2124 E = Node->path_end();
2125 I != E; ++I) {
Anders Carlssona70cff62010-04-24 19:06:50 +00002126 const CXXBaseSpecifier *Base = *I;
2127 if (!First)
2128 OS << " -> ";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002129
Anders Carlssona70cff62010-04-24 19:06:50 +00002130 const CXXRecordDecl *RD =
2131 cast<CXXRecordDecl>(Base->getType()->getAs<RecordType>()->getDecl());
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002132
Anders Carlssona70cff62010-04-24 19:06:50 +00002133 if (Base->isVirtual())
2134 OS << "virtual ";
2135 OS << RD->getName();
2136 First = false;
2137 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002138
Anders Carlssona70cff62010-04-24 19:06:50 +00002139 OS << ')';
2140}
2141
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002142void ASTDumper::VisitCastExpr(const CastExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002143 VisitExpr(Node);
Richard Trieud215b8d2013-01-26 01:31:20 +00002144 OS << " <";
2145 {
2146 ColorScope Color(*this, CastColor);
2147 OS << Node->getCastKindName();
2148 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002149 dumpBasePath(OS, Node);
Anders Carlssona70cff62010-04-24 19:06:50 +00002150 OS << ">";
Roman Lebedev12216f12018-07-27 07:27:14 +00002151}
Roman Lebedevd55661d2018-07-24 08:16:50 +00002152
Roman Lebedev12216f12018-07-27 07:27:14 +00002153void ASTDumper::VisitImplicitCastExpr(const ImplicitCastExpr *Node) {
2154 VisitCastExpr(Node);
2155 if (Node->isPartOfExplicitCast())
Roman Lebedevd55661d2018-07-24 08:16:50 +00002156 OS << " part_of_explicit_cast";
Anders Carlssond7923c62009-08-22 23:33:40 +00002157}
2158
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002159void ASTDumper::VisitDeclRefExpr(const DeclRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002160 VisitExpr(Node);
Ted Kremenek5f64ca82007-09-10 17:32:55 +00002161
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002162 OS << " ";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002163 dumpBareDeclRef(Node->getDecl());
Chandler Carruth8d26bb02011-05-01 23:48:14 +00002164 if (Node->getDecl() != Node->getFoundDecl()) {
2165 OS << " (";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002166 dumpBareDeclRef(Node->getFoundDecl());
Chandler Carruth8d26bb02011-05-01 23:48:14 +00002167 OS << ")";
2168 }
John McCall351762c2011-02-07 10:33:21 +00002169}
2170
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002171void ASTDumper::VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002172 VisitExpr(Node);
John McCall76d09942009-12-11 21:50:11 +00002173 OS << " (";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002174 if (!Node->requiresADL())
2175 OS << "no ";
Benjamin Kramerb11416d2010-04-17 09:33:03 +00002176 OS << "ADL) = '" << Node->getName() << '\'';
John McCall76d09942009-12-11 21:50:11 +00002177
2178 UnresolvedLookupExpr::decls_iterator
2179 I = Node->decls_begin(), E = Node->decls_end();
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002180 if (I == E)
2181 OS << " empty";
John McCall76d09942009-12-11 21:50:11 +00002182 for (; I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002183 dumpPointer(*I);
John McCall76d09942009-12-11 21:50:11 +00002184}
2185
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002186void ASTDumper::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002187 VisitExpr(Node);
Steve Naroff5d5efca2008-03-12 13:19:12 +00002188
Richard Trieud215b8d2013-01-26 01:31:20 +00002189 {
2190 ColorScope Color(*this, DeclKindNameColor);
2191 OS << " " << Node->getDecl()->getDeclKindName() << "Decl";
2192 }
2193 OS << "='" << *Node->getDecl() << "'";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002194 dumpPointer(Node->getDecl());
Steve Naroffb3424a92008-05-23 22:01:24 +00002195 if (Node->isFreeIvar())
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002196 OS << " isFreeIvar";
Steve Naroff5d5efca2008-03-12 13:19:12 +00002197}
2198
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002199void ASTDumper::VisitPredefinedExpr(const PredefinedExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002200 VisitExpr(Node);
Alexey Bataevec474782014-10-09 08:45:04 +00002201 OS << " " << PredefinedExpr::getIdentTypeName(Node->getIdentType());
Chris Lattnercbe4f772007-08-08 22:51:59 +00002202}
2203
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002204void ASTDumper::VisitCharacterLiteral(const CharacterLiteral *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002205 VisitExpr(Node);
Richard Trieud215b8d2013-01-26 01:31:20 +00002206 ColorScope Color(*this, ValueColor);
Richard Trieu364ee422011-11-03 23:56:23 +00002207 OS << " " << Node->getValue();
Chris Lattnercbe4f772007-08-08 22:51:59 +00002208}
2209
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002210void ASTDumper::VisitIntegerLiteral(const IntegerLiteral *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002211 VisitExpr(Node);
Chris Lattnercbe4f772007-08-08 22:51:59 +00002212
2213 bool isSigned = Node->getType()->isSignedIntegerType();
Richard Trieud215b8d2013-01-26 01:31:20 +00002214 ColorScope Color(*this, ValueColor);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002215 OS << " " << Node->getValue().toString(10, isSigned);
Chris Lattnercbe4f772007-08-08 22:51:59 +00002216}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002217
Leonard Chandb01c3a2018-06-20 17:19:40 +00002218void ASTDumper::VisitFixedPointLiteral(const FixedPointLiteral *Node) {
2219 VisitExpr(Node);
2220
2221 ColorScope Color(*this, ValueColor);
2222 OS << " " << Node->getValueAsString(/*Radix=*/10);
2223}
2224
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002225void ASTDumper::VisitFloatingLiteral(const FloatingLiteral *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002226 VisitExpr(Node);
Richard Trieud215b8d2013-01-26 01:31:20 +00002227 ColorScope Color(*this, ValueColor);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002228 OS << " " << Node->getValueAsApproximateDouble();
Chris Lattnercbe4f772007-08-08 22:51:59 +00002229}
Chris Lattner1c20a172007-08-26 03:42:43 +00002230
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002231void ASTDumper::VisitStringLiteral(const StringLiteral *Str) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002232 VisitExpr(Str);
Richard Trieud215b8d2013-01-26 01:31:20 +00002233 ColorScope Color(*this, ValueColor);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002234 OS << " ";
Richard Trieudc355912012-06-13 20:25:24 +00002235 Str->outputString(OS);
Chris Lattnercbe4f772007-08-08 22:51:59 +00002236}
Chris Lattner84ca3762007-08-30 01:00:35 +00002237
Richard Smithf0514962014-06-03 08:24:28 +00002238void ASTDumper::VisitInitListExpr(const InitListExpr *ILE) {
2239 VisitExpr(ILE);
2240 if (auto *Filler = ILE->getArrayFiller()) {
Richard Smithf7514452014-10-30 21:02:37 +00002241 dumpChild([=] {
2242 OS << "array filler";
2243 dumpStmt(Filler);
2244 });
Richard Smithf0514962014-06-03 08:24:28 +00002245 }
2246 if (auto *Field = ILE->getInitializedFieldInUnion()) {
2247 OS << " field ";
2248 dumpBareDeclRef(Field);
2249 }
2250}
2251
Richard Smith410306b2016-12-12 02:53:20 +00002252void ASTDumper::VisitArrayInitLoopExpr(const ArrayInitLoopExpr *E) {
2253 VisitExpr(E);
2254}
2255
2256void ASTDumper::VisitArrayInitIndexExpr(const ArrayInitIndexExpr *E) {
2257 VisitExpr(E);
2258}
2259
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002260void ASTDumper::VisitUnaryOperator(const UnaryOperator *Node) {
Malcolm Parsonsfab36802018-04-16 08:31:08 +00002261 VisitExpr(Node);
2262 OS << " " << (Node->isPostfix() ? "postfix" : "prefix")
2263 << " '" << UnaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
2264 if (!Node->canOverflow())
2265 OS << " cannot overflow";
2266}
2267
2268void ASTDumper::VisitUnaryExprOrTypeTraitExpr(
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002269 const UnaryExprOrTypeTraitExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002270 VisitExpr(Node);
Peter Collingbournee190dee2011-03-11 19:24:49 +00002271 switch(Node->getKind()) {
2272 case UETT_SizeOf:
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002273 OS << " sizeof";
Peter Collingbournee190dee2011-03-11 19:24:49 +00002274 break;
2275 case UETT_AlignOf:
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002276 OS << " alignof";
Peter Collingbournee190dee2011-03-11 19:24:49 +00002277 break;
2278 case UETT_VecStep:
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002279 OS << " vec_step";
Peter Collingbournee190dee2011-03-11 19:24:49 +00002280 break;
Alexey Bataev00396512015-07-02 03:40:19 +00002281 case UETT_OpenMPRequiredSimdAlign:
2282 OS << " __builtin_omp_required_simd_align";
2283 break;
Richard Smith6822bd72018-10-26 19:26:45 +00002284 case UETT_PreferredAlignOf:
2285 OS << " __alignof";
2286 break;
Peter Collingbournee190dee2011-03-11 19:24:49 +00002287 }
Sebastian Redl6f282892008-11-11 17:56:53 +00002288 if (Node->isArgumentType())
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002289 dumpType(Node->getArgumentType());
Chris Lattnercbe4f772007-08-08 22:51:59 +00002290}
Chris Lattnerdb3b3ff2007-08-09 17:35:30 +00002291
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002292void ASTDumper::VisitMemberExpr(const MemberExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002293 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002294 OS << " " << (Node->isArrow() ? "->" : ".") << *Node->getMemberDecl();
2295 dumpPointer(Node->getMemberDecl());
Chris Lattnercbe4f772007-08-08 22:51:59 +00002296}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002297
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002298void ASTDumper::VisitExtVectorElementExpr(const ExtVectorElementExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002299 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002300 OS << " " << Node->getAccessor().getNameStart();
Chris Lattnercbe4f772007-08-08 22:51:59 +00002301}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002302
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002303void ASTDumper::VisitBinaryOperator(const BinaryOperator *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002304 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002305 OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
Chris Lattner86928112007-08-25 02:00:02 +00002306}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002307
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002308void ASTDumper::VisitCompoundAssignOperator(
2309 const CompoundAssignOperator *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002310 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002311 OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode())
2312 << "' ComputeLHSTy=";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002313 dumpBareType(Node->getComputationLHSType());
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002314 OS << " ComputeResultTy=";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002315 dumpBareType(Node->getComputationResultType());
Chris Lattnercbe4f772007-08-08 22:51:59 +00002316}
Chris Lattnercbe4f772007-08-08 22:51:59 +00002317
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002318void ASTDumper::VisitBlockExpr(const BlockExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002319 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002320 dumpDecl(Node->getBlockDecl());
John McCall351762c2011-02-07 10:33:21 +00002321}
2322
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002323void ASTDumper::VisitOpaqueValueExpr(const OpaqueValueExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002324 VisitExpr(Node);
John McCallfe96e0b2011-11-06 09:01:30 +00002325
Richard Smithf7514452014-10-30 21:02:37 +00002326 if (Expr *Source = Node->getSourceExpr())
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002327 dumpStmt(Source);
John McCallfe96e0b2011-11-06 09:01:30 +00002328}
2329
Richard Smith01ccebf2018-01-05 21:31:07 +00002330void ASTDumper::VisitGenericSelectionExpr(const GenericSelectionExpr *E) {
2331 VisitExpr(E);
2332 if (E->isResultDependent())
2333 OS << " result_dependent";
2334 dumpStmt(E->getControllingExpr());
2335 dumpTypeAsChild(E->getControllingExpr()->getType()); // FIXME: remove
2336
2337 for (unsigned I = 0, N = E->getNumAssocs(); I != N; ++I) {
2338 dumpChild([=] {
2339 if (const TypeSourceInfo *TSI = E->getAssocTypeSourceInfo(I)) {
2340 OS << "case ";
2341 dumpType(TSI->getType());
2342 } else {
2343 OS << "default";
2344 }
2345
2346 if (!E->isResultDependent() && E->getResultIndex() == I)
2347 OS << " selected";
2348
2349 if (const TypeSourceInfo *TSI = E->getAssocTypeSourceInfo(I))
2350 dumpTypeAsChild(TSI->getType());
2351 dumpStmt(E->getAssocExpr(I));
2352 });
2353 }
2354}
2355
Chris Lattnercbe4f772007-08-08 22:51:59 +00002356// GNU extensions.
2357
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002358void ASTDumper::VisitAddrLabelExpr(const AddrLabelExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002359 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002360 OS << " " << Node->getLabel()->getName();
2361 dumpPointer(Node->getLabel());
Chris Lattnercbe4f772007-08-08 22:51:59 +00002362}
2363
Chris Lattner8f184b12007-08-09 18:03:18 +00002364//===----------------------------------------------------------------------===//
2365// C++ Expressions
2366//===----------------------------------------------------------------------===//
Chris Lattnercbe4f772007-08-08 22:51:59 +00002367
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002368void ASTDumper::VisitCXXNamedCastExpr(const CXXNamedCastExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002369 VisitExpr(Node);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002370 OS << " " << Node->getCastName()
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002371 << "<" << Node->getTypeAsWritten().getAsString() << ">"
Anders Carlssona70cff62010-04-24 19:06:50 +00002372 << " <" << Node->getCastKindName();
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002373 dumpBasePath(OS, Node);
Anders Carlssona70cff62010-04-24 19:06:50 +00002374 OS << ">";
Chris Lattnercbe4f772007-08-08 22:51:59 +00002375}
2376
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002377void ASTDumper::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002378 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002379 OS << " " << (Node->getValue() ? "true" : "false");
Chris Lattnercbe4f772007-08-08 22:51:59 +00002380}
2381
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002382void ASTDumper::VisitCXXThisExpr(const CXXThisExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002383 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002384 OS << " this";
Douglas Gregor8ea1f532008-11-04 14:56:14 +00002385}
2386
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002387void ASTDumper::VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002388 VisitExpr(Node);
Eli Friedman29538892011-09-02 17:38:59 +00002389 OS << " functional cast to " << Node->getTypeAsWritten().getAsString()
2390 << " <" << Node->getCastKindName() << ">";
Douglas Gregore200adc2008-10-27 19:41:14 +00002391}
2392
Richard Smith39eca9b2017-08-23 22:12:08 +00002393void ASTDumper::VisitCXXUnresolvedConstructExpr(
2394 const CXXUnresolvedConstructExpr *Node) {
2395 VisitExpr(Node);
2396 dumpType(Node->getTypeAsWritten());
2397 if (Node->isListInitialization())
2398 OS << " list";
2399}
2400
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002401void ASTDumper::VisitCXXConstructExpr(const CXXConstructExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002402 VisitExpr(Node);
John McCalleba90cd2010-02-02 19:03:45 +00002403 CXXConstructorDecl *Ctor = Node->getConstructor();
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002404 dumpType(Ctor->getType());
Anders Carlsson073846832009-08-12 00:21:52 +00002405 if (Node->isElidable())
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002406 OS << " elidable";
Richard Smith39eca9b2017-08-23 22:12:08 +00002407 if (Node->isListInitialization())
2408 OS << " list";
2409 if (Node->isStdInitListInitialization())
2410 OS << " std::initializer_list";
John McCall85370042010-08-07 06:38:55 +00002411 if (Node->requiresZeroInitialization())
2412 OS << " zeroing";
Anders Carlsson073846832009-08-12 00:21:52 +00002413}
2414
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002415void ASTDumper::VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002416 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002417 OS << " ";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002418 dumpCXXTemporary(Node->getTemporary());
Anders Carlsson073846832009-08-12 00:21:52 +00002419}
2420
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002421void ASTDumper::VisitCXXNewExpr(const CXXNewExpr *Node) {
2422 VisitExpr(Node);
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002423 if (Node->isGlobalNew())
Reid Kleckner461c0c62015-03-19 18:47:47 +00002424 OS << " global";
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002425 if (Node->isArray())
Reid Kleckner461c0c62015-03-19 18:47:47 +00002426 OS << " array";
2427 if (Node->getOperatorNew()) {
2428 OS << ' ';
2429 dumpBareDeclRef(Node->getOperatorNew());
2430 }
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002431 // We could dump the deallocation function used in case of error, but it's
2432 // usually not that interesting.
2433}
2434
2435void ASTDumper::VisitCXXDeleteExpr(const CXXDeleteExpr *Node) {
2436 VisitExpr(Node);
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002437 if (Node->isGlobalDelete())
Reid Kleckner461c0c62015-03-19 18:47:47 +00002438 OS << " global";
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002439 if (Node->isArrayForm())
Reid Kleckner461c0c62015-03-19 18:47:47 +00002440 OS << " array";
2441 if (Node->getOperatorDelete()) {
2442 OS << ' ';
2443 dumpBareDeclRef(Node->getOperatorDelete());
2444 }
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002445}
2446
Richard Smithe6c01442013-06-05 00:46:14 +00002447void
2448ASTDumper::VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *Node) {
2449 VisitExpr(Node);
2450 if (const ValueDecl *VD = Node->getExtendingDecl()) {
2451 OS << " extended by ";
2452 dumpBareDeclRef(VD);
2453 }
2454}
2455
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002456void ASTDumper::VisitExprWithCleanups(const ExprWithCleanups *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002457 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002458 for (unsigned i = 0, e = Node->getNumObjects(); i != e; ++i)
2459 dumpDeclRef(Node->getObject(i), "cleanup");
Anders Carlsson073846832009-08-12 00:21:52 +00002460}
2461
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002462void ASTDumper::dumpCXXTemporary(const CXXTemporary *Temporary) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002463 OS << "(CXXTemporary";
2464 dumpPointer(Temporary);
2465 OS << ")";
Anders Carlsson073846832009-08-12 00:21:52 +00002466}
2467
Serge Pavlov6b926032015-02-16 19:58:41 +00002468void ASTDumper::VisitSizeOfPackExpr(const SizeOfPackExpr *Node) {
2469 VisitExpr(Node);
2470 dumpPointer(Node->getPack());
2471 dumpName(Node->getPack());
Richard Smithd784e682015-09-23 21:41:42 +00002472 if (Node->isPartiallySubstituted())
2473 for (const auto &A : Node->getPartialArguments())
2474 dumpTemplateArgument(A);
Serge Pavlov6b926032015-02-16 19:58:41 +00002475}
2476
Alex Lorenzddbe0f52016-11-09 14:02:18 +00002477void ASTDumper::VisitCXXDependentScopeMemberExpr(
2478 const CXXDependentScopeMemberExpr *Node) {
2479 VisitExpr(Node);
2480 OS << " " << (Node->isArrow() ? "->" : ".") << Node->getMember();
2481}
Serge Pavlov6b926032015-02-16 19:58:41 +00002482
Anders Carlsson76f4a902007-08-21 17:43:55 +00002483//===----------------------------------------------------------------------===//
2484// Obj-C Expressions
2485//===----------------------------------------------------------------------===//
2486
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002487void ASTDumper::VisitObjCMessageExpr(const ObjCMessageExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002488 VisitExpr(Node);
Aaron Ballmanb190f972014-01-03 17:59:55 +00002489 OS << " selector=";
2490 Node->getSelector().print(OS);
Douglas Gregor9a129192010-04-21 00:45:42 +00002491 switch (Node->getReceiverKind()) {
2492 case ObjCMessageExpr::Instance:
2493 break;
2494
2495 case ObjCMessageExpr::Class:
2496 OS << " class=";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002497 dumpBareType(Node->getClassReceiver());
Douglas Gregor9a129192010-04-21 00:45:42 +00002498 break;
2499
2500 case ObjCMessageExpr::SuperInstance:
2501 OS << " super (instance)";
2502 break;
2503
2504 case ObjCMessageExpr::SuperClass:
2505 OS << " super (class)";
2506 break;
2507 }
Ted Kremenek36748da2008-02-29 22:04:05 +00002508}
2509
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002510void ASTDumper::VisitObjCBoxedExpr(const ObjCBoxedExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002511 VisitExpr(Node);
Richard Trieu4b259c82016-06-09 22:03:04 +00002512 if (auto *BoxingMethod = Node->getBoxingMethod()) {
2513 OS << " selector=";
2514 BoxingMethod->getSelector().print(OS);
2515 }
Argyrios Kyrtzidis9dd40892012-05-10 20:02:31 +00002516}
2517
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002518void ASTDumper::VisitObjCAtCatchStmt(const ObjCAtCatchStmt *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002519 VisitStmt(Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002520 if (const VarDecl *CatchParam = Node->getCatchParamDecl())
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002521 dumpDecl(CatchParam);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002522 else
Douglas Gregor96c79492010-04-23 22:50:49 +00002523 OS << " catch all";
Douglas Gregor96c79492010-04-23 22:50:49 +00002524}
2525
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002526void ASTDumper::VisitObjCEncodeExpr(const ObjCEncodeExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002527 VisitExpr(Node);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002528 dumpType(Node->getEncodedType());
Anders Carlssonc5a81eb2007-08-22 15:14:15 +00002529}
2530
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002531void ASTDumper::VisitObjCSelectorExpr(const ObjCSelectorExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002532 VisitExpr(Node);
Mike Stump11289f42009-09-09 15:08:12 +00002533
Aaron Ballmanb190f972014-01-03 17:59:55 +00002534 OS << " ";
2535 Node->getSelector().print(OS);
Fariborz Jahanian4bef4622007-10-16 20:40:23 +00002536}
2537
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002538void ASTDumper::VisitObjCProtocolExpr(const ObjCProtocolExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002539 VisitExpr(Node);
Mike Stump11289f42009-09-09 15:08:12 +00002540
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002541 OS << ' ' << *Node->getProtocol();
Fariborz Jahaniana32aaef2007-10-17 16:58:11 +00002542}
Daniel Dunbar4b8c6db2008-08-30 05:35:15 +00002543
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002544void ASTDumper::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002545 VisitExpr(Node);
John McCallb7bd14f2010-12-02 01:19:52 +00002546 if (Node->isImplicitProperty()) {
Fariborz Jahanian0f0b3022010-12-22 19:46:35 +00002547 OS << " Kind=MethodRef Getter=\"";
2548 if (Node->getImplicitPropertyGetter())
Aaron Ballmanb190f972014-01-03 17:59:55 +00002549 Node->getImplicitPropertyGetter()->getSelector().print(OS);
Fariborz Jahanian0f0b3022010-12-22 19:46:35 +00002550 else
2551 OS << "(null)";
2552
2553 OS << "\" Setter=\"";
John McCallb7bd14f2010-12-02 01:19:52 +00002554 if (ObjCMethodDecl *Setter = Node->getImplicitPropertySetter())
Aaron Ballmanb190f972014-01-03 17:59:55 +00002555 Setter->getSelector().print(OS);
John McCallb7bd14f2010-12-02 01:19:52 +00002556 else
2557 OS << "(null)";
2558 OS << "\"";
2559 } else {
Benjamin Kramerb89514a2011-10-14 18:45:37 +00002560 OS << " Kind=PropertyRef Property=\"" << *Node->getExplicitProperty() <<'"';
John McCallb7bd14f2010-12-02 01:19:52 +00002561 }
Fariborz Jahanian8a1810f2008-11-22 18:39:36 +00002562
Fariborz Jahanian681c0752010-10-14 16:04:05 +00002563 if (Node->isSuperReceiver())
2564 OS << " super";
Argyrios Kyrtzidisab468b02012-03-30 00:19:18 +00002565
2566 OS << " Messaging=";
2567 if (Node->isMessagingGetter() && Node->isMessagingSetter())
2568 OS << "Getter&Setter";
2569 else if (Node->isMessagingGetter())
2570 OS << "Getter";
2571 else if (Node->isMessagingSetter())
2572 OS << "Setter";
Douglas Gregor8ea1f532008-11-04 14:56:14 +00002573}
2574
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002575void ASTDumper::VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002576 VisitExpr(Node);
Ted Kremeneke65b0862012-03-06 20:05:56 +00002577 if (Node->isArraySubscriptRefExpr())
2578 OS << " Kind=ArraySubscript GetterForArray=\"";
2579 else
2580 OS << " Kind=DictionarySubscript GetterForDictionary=\"";
2581 if (Node->getAtIndexMethodDecl())
Aaron Ballmanb190f972014-01-03 17:59:55 +00002582 Node->getAtIndexMethodDecl()->getSelector().print(OS);
Ted Kremeneke65b0862012-03-06 20:05:56 +00002583 else
2584 OS << "(null)";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002585
Ted Kremeneke65b0862012-03-06 20:05:56 +00002586 if (Node->isArraySubscriptRefExpr())
2587 OS << "\" SetterForArray=\"";
2588 else
2589 OS << "\" SetterForDictionary=\"";
2590 if (Node->setAtIndexMethodDecl())
Aaron Ballmanb190f972014-01-03 17:59:55 +00002591 Node->setAtIndexMethodDecl()->getSelector().print(OS);
Ted Kremeneke65b0862012-03-06 20:05:56 +00002592 else
2593 OS << "(null)";
2594}
2595
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002596void ASTDumper::VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002597 VisitExpr(Node);
Ted Kremeneke65b0862012-03-06 20:05:56 +00002598 OS << " " << (Node->getValue() ? "__objc_yes" : "__objc_no");
2599}
2600
Chris Lattnercbe4f772007-08-08 22:51:59 +00002601//===----------------------------------------------------------------------===//
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002602// Comments
2603//===----------------------------------------------------------------------===//
2604
2605const char *ASTDumper::getCommandName(unsigned CommandID) {
2606 if (Traits)
2607 return Traits->getCommandInfo(CommandID)->Name;
2608 const CommandInfo *Info = CommandTraits::getBuiltinCommandInfo(CommandID);
2609 if (Info)
2610 return Info->Name;
2611 return "<not a builtin command>";
2612}
2613
2614void ASTDumper::dumpFullComment(const FullComment *C) {
2615 if (!C)
2616 return;
2617
2618 FC = C;
2619 dumpComment(C);
Craig Topper36250ad2014-05-12 05:36:57 +00002620 FC = nullptr;
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002621}
2622
2623void ASTDumper::dumpComment(const Comment *C) {
Richard Smithf7514452014-10-30 21:02:37 +00002624 dumpChild([=] {
2625 if (!C) {
2626 ColorScope Color(*this, NullColor);
2627 OS << "<<<NULL>>>";
2628 return;
2629 }
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002630
Richard Smithf7514452014-10-30 21:02:37 +00002631 {
2632 ColorScope Color(*this, CommentColor);
2633 OS << C->getCommentKindName();
2634 }
2635 dumpPointer(C);
2636 dumpSourceRange(C->getSourceRange());
2637 ConstCommentVisitor<ASTDumper>::visit(C);
2638 for (Comment::child_iterator I = C->child_begin(), E = C->child_end();
2639 I != E; ++I)
2640 dumpComment(*I);
2641 });
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002642}
2643
2644void ASTDumper::visitTextComment(const TextComment *C) {
2645 OS << " Text=\"" << C->getText() << "\"";
2646}
2647
2648void ASTDumper::visitInlineCommandComment(const InlineCommandComment *C) {
2649 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\"";
2650 switch (C->getRenderKind()) {
2651 case InlineCommandComment::RenderNormal:
2652 OS << " RenderNormal";
2653 break;
2654 case InlineCommandComment::RenderBold:
2655 OS << " RenderBold";
2656 break;
2657 case InlineCommandComment::RenderMonospaced:
2658 OS << " RenderMonospaced";
2659 break;
2660 case InlineCommandComment::RenderEmphasized:
2661 OS << " RenderEmphasized";
2662 break;
2663 }
2664
2665 for (unsigned i = 0, e = C->getNumArgs(); i != e; ++i)
2666 OS << " Arg[" << i << "]=\"" << C->getArgText(i) << "\"";
2667}
2668
2669void ASTDumper::visitHTMLStartTagComment(const HTMLStartTagComment *C) {
2670 OS << " Name=\"" << C->getTagName() << "\"";
2671 if (C->getNumAttrs() != 0) {
2672 OS << " Attrs: ";
2673 for (unsigned i = 0, e = C->getNumAttrs(); i != e; ++i) {
2674 const HTMLStartTagComment::Attribute &Attr = C->getAttr(i);
2675 OS << " \"" << Attr.Name << "=\"" << Attr.Value << "\"";
2676 }
2677 }
2678 if (C->isSelfClosing())
2679 OS << " SelfClosing";
2680}
2681
2682void ASTDumper::visitHTMLEndTagComment(const HTMLEndTagComment *C) {
2683 OS << " Name=\"" << C->getTagName() << "\"";
2684}
2685
2686void ASTDumper::visitBlockCommandComment(const BlockCommandComment *C) {
2687 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\"";
2688 for (unsigned i = 0, e = C->getNumArgs(); i != e; ++i)
2689 OS << " Arg[" << i << "]=\"" << C->getArgText(i) << "\"";
2690}
2691
2692void ASTDumper::visitParamCommandComment(const ParamCommandComment *C) {
2693 OS << " " << ParamCommandComment::getDirectionAsString(C->getDirection());
2694
2695 if (C->isDirectionExplicit())
2696 OS << " explicitly";
2697 else
2698 OS << " implicitly";
2699
2700 if (C->hasParamName()) {
2701 if (C->isParamIndexValid())
2702 OS << " Param=\"" << C->getParamName(FC) << "\"";
2703 else
2704 OS << " Param=\"" << C->getParamNameAsWritten() << "\"";
2705 }
2706
Dmitri Gribenkodbff5c72014-03-19 14:03:47 +00002707 if (C->isParamIndexValid() && !C->isVarArgParam())
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002708 OS << " ParamIndex=" << C->getParamIndex();
2709}
2710
2711void ASTDumper::visitTParamCommandComment(const TParamCommandComment *C) {
2712 if (C->hasParamName()) {
2713 if (C->isPositionValid())
2714 OS << " Param=\"" << C->getParamName(FC) << "\"";
2715 else
2716 OS << " Param=\"" << C->getParamNameAsWritten() << "\"";
2717 }
2718
2719 if (C->isPositionValid()) {
2720 OS << " Position=<";
2721 for (unsigned i = 0, e = C->getDepth(); i != e; ++i) {
2722 OS << C->getIndex(i);
2723 if (i != e - 1)
2724 OS << ", ";
2725 }
2726 OS << ">";
2727 }
2728}
2729
2730void ASTDumper::visitVerbatimBlockComment(const VerbatimBlockComment *C) {
2731 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\""
2732 " CloseName=\"" << C->getCloseName() << "\"";
2733}
2734
2735void ASTDumper::visitVerbatimBlockLineComment(
2736 const VerbatimBlockLineComment *C) {
2737 OS << " Text=\"" << C->getText() << "\"";
2738}
2739
2740void ASTDumper::visitVerbatimLineComment(const VerbatimLineComment *C) {
2741 OS << " Text=\"" << C->getText() << "\"";
2742}
2743
2744//===----------------------------------------------------------------------===//
Richard Smithd5e7ff82014-10-31 01:17:45 +00002745// Type method implementations
2746//===----------------------------------------------------------------------===//
2747
2748void QualType::dump(const char *msg) const {
2749 if (msg)
2750 llvm::errs() << msg << ": ";
2751 dump();
2752}
2753
Richard Smith14d04842016-11-02 23:57:18 +00002754LLVM_DUMP_METHOD void QualType::dump() const { dump(llvm::errs()); }
2755
2756LLVM_DUMP_METHOD void QualType::dump(llvm::raw_ostream &OS) const {
2757 ASTDumper Dumper(OS, nullptr, nullptr);
Richard Smithd5e7ff82014-10-31 01:17:45 +00002758 Dumper.dumpTypeAsChild(*this);
2759}
2760
Richard Smith14d04842016-11-02 23:57:18 +00002761LLVM_DUMP_METHOD void Type::dump() const { dump(llvm::errs()); }
2762
2763LLVM_DUMP_METHOD void Type::dump(llvm::raw_ostream &OS) const {
2764 QualType(this, 0).dump(OS);
2765}
Richard Smithd5e7ff82014-10-31 01:17:45 +00002766
2767//===----------------------------------------------------------------------===//
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002768// Decl method implementations
2769//===----------------------------------------------------------------------===//
2770
Alp Tokeref6b0072014-01-04 13:47:14 +00002771LLVM_DUMP_METHOD void Decl::dump() const { dump(llvm::errs()); }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002772
Richard Smith3a36ac12017-03-09 22:00:01 +00002773LLVM_DUMP_METHOD void Decl::dump(raw_ostream &OS, bool Deserialize) const {
Aaron Ballman8c208282017-12-21 21:42:42 +00002774 const ASTContext &Ctx = getASTContext();
2775 const SourceManager &SM = Ctx.getSourceManager();
2776 ASTDumper P(OS, &Ctx.getCommentCommandTraits(), &SM,
2777 SM.getDiagnostics().getShowColors(), Ctx.getPrintingPolicy());
Richard Smith3a36ac12017-03-09 22:00:01 +00002778 P.setDeserialize(Deserialize);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002779 P.dumpDecl(this);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002780}
2781
Alp Tokeref6b0072014-01-04 13:47:14 +00002782LLVM_DUMP_METHOD void Decl::dumpColor() const {
Aaron Ballman8c208282017-12-21 21:42:42 +00002783 const ASTContext &Ctx = getASTContext();
2784 ASTDumper P(llvm::errs(), &Ctx.getCommentCommandTraits(),
2785 &Ctx.getSourceManager(), /*ShowColors*/ true,
2786 Ctx.getPrintingPolicy());
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002787 P.dumpDecl(this);
Richard Trieud215b8d2013-01-26 01:31:20 +00002788}
Richard Smith33937e72013-06-22 21:49:40 +00002789
Alp Tokeref6b0072014-01-04 13:47:14 +00002790LLVM_DUMP_METHOD void DeclContext::dumpLookups() const {
Richard Smith6ea05822013-06-24 01:45:33 +00002791 dumpLookups(llvm::errs());
2792}
2793
Richard Smith35f986d2014-08-11 22:11:07 +00002794LLVM_DUMP_METHOD void DeclContext::dumpLookups(raw_ostream &OS,
Richard Smith3a36ac12017-03-09 22:00:01 +00002795 bool DumpDecls,
2796 bool Deserialize) const {
Richard Smith33937e72013-06-22 21:49:40 +00002797 const DeclContext *DC = this;
2798 while (!DC->isTranslationUnit())
2799 DC = DC->getParent();
2800 ASTContext &Ctx = cast<TranslationUnitDecl>(DC)->getASTContext();
Aaron Ballman8c208282017-12-21 21:42:42 +00002801 const SourceManager &SM = Ctx.getSourceManager();
2802 ASTDumper P(OS, &Ctx.getCommentCommandTraits(), &Ctx.getSourceManager(),
2803 SM.getDiagnostics().getShowColors(), Ctx.getPrintingPolicy());
Richard Smith3a36ac12017-03-09 22:00:01 +00002804 P.setDeserialize(Deserialize);
Richard Smith35f986d2014-08-11 22:11:07 +00002805 P.dumpLookups(this, DumpDecls);
Richard Smith33937e72013-06-22 21:49:40 +00002806}
2807
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002808//===----------------------------------------------------------------------===//
Chris Lattnercbe4f772007-08-08 22:51:59 +00002809// Stmt method implementations
2810//===----------------------------------------------------------------------===//
2811
Alp Tokeref6b0072014-01-04 13:47:14 +00002812LLVM_DUMP_METHOD void Stmt::dump(SourceManager &SM) const {
Argyrios Kyrtzidisc049f752010-08-09 10:54:31 +00002813 dump(llvm::errs(), SM);
2814}
2815
Alp Tokeref6b0072014-01-04 13:47:14 +00002816LLVM_DUMP_METHOD void Stmt::dump(raw_ostream &OS, SourceManager &SM) const {
Craig Topper36250ad2014-05-12 05:36:57 +00002817 ASTDumper P(OS, nullptr, &SM);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002818 P.dumpStmt(this);
Chris Lattner779d5d92007-08-30 00:40:08 +00002819}
2820
Faisal Vali2da8ed92015-03-22 13:35:56 +00002821LLVM_DUMP_METHOD void Stmt::dump(raw_ostream &OS) const {
2822 ASTDumper P(OS, nullptr, nullptr);
2823 P.dumpStmt(this);
2824}
2825
Alp Tokeref6b0072014-01-04 13:47:14 +00002826LLVM_DUMP_METHOD void Stmt::dump() const {
Craig Topper36250ad2014-05-12 05:36:57 +00002827 ASTDumper P(llvm::errs(), nullptr, nullptr);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002828 P.dumpStmt(this);
Chris Lattnercbe4f772007-08-08 22:51:59 +00002829}
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002830
Alp Tokeref6b0072014-01-04 13:47:14 +00002831LLVM_DUMP_METHOD void Stmt::dumpColor() const {
Craig Topper36250ad2014-05-12 05:36:57 +00002832 ASTDumper P(llvm::errs(), nullptr, nullptr, /*ShowColors*/true);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002833 P.dumpStmt(this);
Richard Trieud215b8d2013-01-26 01:31:20 +00002834}
2835
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002836//===----------------------------------------------------------------------===//
2837// Comment method implementations
2838//===----------------------------------------------------------------------===//
2839
Craig Topper36250ad2014-05-12 05:36:57 +00002840LLVM_DUMP_METHOD void Comment::dump() const {
2841 dump(llvm::errs(), nullptr, nullptr);
2842}
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002843
Alp Tokeref6b0072014-01-04 13:47:14 +00002844LLVM_DUMP_METHOD void Comment::dump(const ASTContext &Context) const {
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002845 dump(llvm::errs(), &Context.getCommentCommandTraits(),
2846 &Context.getSourceManager());
2847}
2848
Alexander Kornienko00911f12013-01-15 12:20:21 +00002849void Comment::dump(raw_ostream &OS, const CommandTraits *Traits,
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002850 const SourceManager *SM) const {
2851 const FullComment *FC = dyn_cast<FullComment>(this);
2852 ASTDumper D(OS, Traits, SM);
2853 D.dumpFullComment(FC);
2854}
Richard Trieud215b8d2013-01-26 01:31:20 +00002855
Alp Tokeref6b0072014-01-04 13:47:14 +00002856LLVM_DUMP_METHOD void Comment::dumpColor() const {
Richard Trieud215b8d2013-01-26 01:31:20 +00002857 const FullComment *FC = dyn_cast<FullComment>(this);
Craig Topper36250ad2014-05-12 05:36:57 +00002858 ASTDumper D(llvm::errs(), nullptr, nullptr, /*ShowColors*/true);
Richard Trieud215b8d2013-01-26 01:31:20 +00002859 D.dumpFullComment(FC);
2860}