blob: d9093e757b2d904443ecc2bf5e5ea1e30af2dea0 [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);
453 void VisitOMPCapturedExprDecl(const OMPCapturedExprDecl *D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000454
455 // C++ Decls
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000456 void VisitNamespaceDecl(const NamespaceDecl *D);
457 void VisitUsingDirectiveDecl(const UsingDirectiveDecl *D);
458 void VisitNamespaceAliasDecl(const NamespaceAliasDecl *D);
459 void VisitTypeAliasDecl(const TypeAliasDecl *D);
460 void VisitTypeAliasTemplateDecl(const TypeAliasTemplateDecl *D);
461 void VisitCXXRecordDecl(const CXXRecordDecl *D);
462 void VisitStaticAssertDecl(const StaticAssertDecl *D);
Richard Smithcbdf7332014-03-18 02:07:28 +0000463 template<typename SpecializationDecl>
Richard Smithf7514452014-10-30 21:02:37 +0000464 void VisitTemplateDeclSpecialization(const SpecializationDecl *D,
Richard Smithcbdf7332014-03-18 02:07:28 +0000465 bool DumpExplicitInst,
466 bool DumpRefOnly);
Richard Smith20ade552014-03-17 23:34:53 +0000467 template<typename TemplateDecl>
468 void VisitTemplateDecl(const TemplateDecl *D, bool DumpExplicitInst);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000469 void VisitFunctionTemplateDecl(const FunctionTemplateDecl *D);
470 void VisitClassTemplateDecl(const ClassTemplateDecl *D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000471 void VisitClassTemplateSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000472 const ClassTemplateSpecializationDecl *D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000473 void VisitClassTemplatePartialSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000474 const ClassTemplatePartialSpecializationDecl *D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000475 void VisitClassScopeFunctionSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000476 const ClassScopeFunctionSpecializationDecl *D);
David Majnemerd9b1a4f2015-11-04 03:40:30 +0000477 void VisitBuiltinTemplateDecl(const BuiltinTemplateDecl *D);
Richard Smithd25789a2013-09-18 01:36:02 +0000478 void VisitVarTemplateDecl(const VarTemplateDecl *D);
479 void VisitVarTemplateSpecializationDecl(
480 const VarTemplateSpecializationDecl *D);
481 void VisitVarTemplatePartialSpecializationDecl(
482 const VarTemplatePartialSpecializationDecl *D);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000483 void VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D);
484 void VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D);
485 void VisitTemplateTemplateParmDecl(const TemplateTemplateParmDecl *D);
486 void VisitUsingDecl(const UsingDecl *D);
487 void VisitUnresolvedUsingTypenameDecl(const UnresolvedUsingTypenameDecl *D);
488 void VisitUnresolvedUsingValueDecl(const UnresolvedUsingValueDecl *D);
489 void VisitUsingShadowDecl(const UsingShadowDecl *D);
Richard Smith5179eb72016-06-28 19:03:57 +0000490 void VisitConstructorUsingShadowDecl(const ConstructorUsingShadowDecl *D);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000491 void VisitLinkageSpecDecl(const LinkageSpecDecl *D);
492 void VisitAccessSpecDecl(const AccessSpecDecl *D);
493 void VisitFriendDecl(const FriendDecl *D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000494
495 // ObjC Decls
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000496 void VisitObjCIvarDecl(const ObjCIvarDecl *D);
497 void VisitObjCMethodDecl(const ObjCMethodDecl *D);
Douglas Gregor85f3f952015-07-07 03:57:15 +0000498 void VisitObjCTypeParamDecl(const ObjCTypeParamDecl *D);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000499 void VisitObjCCategoryDecl(const ObjCCategoryDecl *D);
500 void VisitObjCCategoryImplDecl(const ObjCCategoryImplDecl *D);
501 void VisitObjCProtocolDecl(const ObjCProtocolDecl *D);
502 void VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D);
503 void VisitObjCImplementationDecl(const ObjCImplementationDecl *D);
504 void VisitObjCCompatibleAliasDecl(const ObjCCompatibleAliasDecl *D);
505 void VisitObjCPropertyDecl(const ObjCPropertyDecl *D);
506 void VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D);
507 void VisitBlockDecl(const BlockDecl *D);
Mike Stump11289f42009-09-09 15:08:12 +0000508
Chris Lattner84ca3762007-08-30 01:00:35 +0000509 // Stmts.
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000510 void VisitStmt(const Stmt *Node);
511 void VisitDeclStmt(const DeclStmt *Node);
512 void VisitAttributedStmt(const AttributedStmt *Node);
513 void VisitLabelStmt(const LabelStmt *Node);
514 void VisitGotoStmt(const GotoStmt *Node);
Pavel Labath1ef83422013-09-04 14:35:00 +0000515 void VisitCXXCatchStmt(const CXXCatchStmt *Node);
Alexey Bataev958b9e72016-03-31 09:30:50 +0000516 void VisitCapturedStmt(const CapturedStmt *Node);
517
518 // OpenMP
519 void VisitOMPExecutableDirective(const OMPExecutableDirective *Node);
Mike Stump11289f42009-09-09 15:08:12 +0000520
Chris Lattner84ca3762007-08-30 01:00:35 +0000521 // Exprs
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000522 void VisitExpr(const Expr *Node);
523 void VisitCastExpr(const CastExpr *Node);
Roman Lebedev12216f12018-07-27 07:27:14 +0000524 void VisitImplicitCastExpr(const ImplicitCastExpr *Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000525 void VisitDeclRefExpr(const DeclRefExpr *Node);
526 void VisitPredefinedExpr(const PredefinedExpr *Node);
527 void VisitCharacterLiteral(const CharacterLiteral *Node);
528 void VisitIntegerLiteral(const IntegerLiteral *Node);
Leonard Chandb01c3a2018-06-20 17:19:40 +0000529 void VisitFixedPointLiteral(const FixedPointLiteral *Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000530 void VisitFloatingLiteral(const FloatingLiteral *Node);
531 void VisitStringLiteral(const StringLiteral *Str);
Richard Smithf0514962014-06-03 08:24:28 +0000532 void VisitInitListExpr(const InitListExpr *ILE);
Richard Smith410306b2016-12-12 02:53:20 +0000533 void VisitArrayInitLoopExpr(const ArrayInitLoopExpr *ILE);
534 void VisitArrayInitIndexExpr(const ArrayInitIndexExpr *ILE);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000535 void VisitUnaryOperator(const UnaryOperator *Node);
536 void VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *Node);
537 void VisitMemberExpr(const MemberExpr *Node);
538 void VisitExtVectorElementExpr(const ExtVectorElementExpr *Node);
539 void VisitBinaryOperator(const BinaryOperator *Node);
540 void VisitCompoundAssignOperator(const CompoundAssignOperator *Node);
541 void VisitAddrLabelExpr(const AddrLabelExpr *Node);
542 void VisitBlockExpr(const BlockExpr *Node);
543 void VisitOpaqueValueExpr(const OpaqueValueExpr *Node);
Richard Smith01ccebf2018-01-05 21:31:07 +0000544 void VisitGenericSelectionExpr(const GenericSelectionExpr *E);
Chris Lattner84ca3762007-08-30 01:00:35 +0000545
546 // C++
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000547 void VisitCXXNamedCastExpr(const CXXNamedCastExpr *Node);
548 void VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *Node);
549 void VisitCXXThisExpr(const CXXThisExpr *Node);
550 void VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *Node);
Richard Smith39eca9b2017-08-23 22:12:08 +0000551 void VisitCXXUnresolvedConstructExpr(const CXXUnresolvedConstructExpr *Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000552 void VisitCXXConstructExpr(const CXXConstructExpr *Node);
553 void VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *Node);
Reid Kleckner5c682bc2015-03-19 18:09:25 +0000554 void VisitCXXNewExpr(const CXXNewExpr *Node);
555 void VisitCXXDeleteExpr(const CXXDeleteExpr *Node);
Richard Smithe6c01442013-06-05 00:46:14 +0000556 void VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000557 void VisitExprWithCleanups(const ExprWithCleanups *Node);
558 void VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *Node);
559 void dumpCXXTemporary(const CXXTemporary *Temporary);
Faisal Vali2b391ab2013-09-26 19:54:12 +0000560 void VisitLambdaExpr(const LambdaExpr *Node) {
561 VisitExpr(Node);
562 dumpDecl(Node->getLambdaClass());
563 }
Serge Pavlov6b926032015-02-16 19:58:41 +0000564 void VisitSizeOfPackExpr(const SizeOfPackExpr *Node);
Alex Lorenzddbe0f52016-11-09 14:02:18 +0000565 void
566 VisitCXXDependentScopeMemberExpr(const CXXDependentScopeMemberExpr *Node);
Mike Stump11289f42009-09-09 15:08:12 +0000567
Chris Lattner84ca3762007-08-30 01:00:35 +0000568 // ObjC
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000569 void VisitObjCAtCatchStmt(const ObjCAtCatchStmt *Node);
570 void VisitObjCEncodeExpr(const ObjCEncodeExpr *Node);
571 void VisitObjCMessageExpr(const ObjCMessageExpr *Node);
572 void VisitObjCBoxedExpr(const ObjCBoxedExpr *Node);
573 void VisitObjCSelectorExpr(const ObjCSelectorExpr *Node);
574 void VisitObjCProtocolExpr(const ObjCProtocolExpr *Node);
575 void VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *Node);
576 void VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *Node);
577 void VisitObjCIvarRefExpr(const ObjCIvarRefExpr *Node);
578 void VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *Node);
Alexander Kornienkoebc17b52013-01-14 14:07:11 +0000579
580 // Comments.
581 const char *getCommandName(unsigned CommandID);
582 void dumpComment(const Comment *C);
583
584 // Inline comments.
585 void visitTextComment(const TextComment *C);
586 void visitInlineCommandComment(const InlineCommandComment *C);
587 void visitHTMLStartTagComment(const HTMLStartTagComment *C);
588 void visitHTMLEndTagComment(const HTMLEndTagComment *C);
589
590 // Block comments.
591 void visitBlockCommandComment(const BlockCommandComment *C);
592 void visitParamCommandComment(const ParamCommandComment *C);
593 void visitTParamCommandComment(const TParamCommandComment *C);
594 void visitVerbatimBlockComment(const VerbatimBlockComment *C);
595 void visitVerbatimBlockLineComment(const VerbatimBlockLineComment *C);
596 void visitVerbatimLineComment(const VerbatimLineComment *C);
Chris Lattnercbe4f772007-08-08 22:51:59 +0000597 };
Alexander Kornienkoab9db512015-06-22 23:07:51 +0000598}
Chris Lattnercbe4f772007-08-08 22:51:59 +0000599
600//===----------------------------------------------------------------------===//
Chris Lattner11e30d32007-08-30 06:17:34 +0000601// Utilities
602//===----------------------------------------------------------------------===//
603
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000604void ASTDumper::dumpPointer(const void *Ptr) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000605 ColorScope Color(*this, AddressColor);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000606 OS << ' ' << Ptr;
607}
608
Alexander Kornienko18ec81b2012-12-13 13:59:55 +0000609void ASTDumper::dumpLocation(SourceLocation Loc) {
Alex McCarthye14ddef2014-05-02 20:24:11 +0000610 if (!SM)
611 return;
612
Richard Trieud215b8d2013-01-26 01:31:20 +0000613 ColorScope Color(*this, LocationColor);
Chris Lattner53e384f2009-01-16 07:00:02 +0000614 SourceLocation SpellingLoc = SM->getSpellingLoc(Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000615
Chris Lattner11e30d32007-08-30 06:17:34 +0000616 // The general format we print out is filename:line:col, but we drop pieces
617 // that haven't changed since the last loc printed.
Chris Lattnerf1ca7d32009-01-27 07:57:44 +0000618 PresumedLoc PLoc = SM->getPresumedLoc(SpellingLoc);
619
Douglas Gregor453b0122010-11-12 07:15:47 +0000620 if (PLoc.isInvalid()) {
621 OS << "<invalid sloc>";
622 return;
623 }
624
Chris Lattnerf1ca7d32009-01-27 07:57:44 +0000625 if (strcmp(PLoc.getFilename(), LastLocFilename) != 0) {
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000626 OS << PLoc.getFilename() << ':' << PLoc.getLine()
627 << ':' << PLoc.getColumn();
Chris Lattnerf1ca7d32009-01-27 07:57:44 +0000628 LastLocFilename = PLoc.getFilename();
629 LastLocLine = PLoc.getLine();
630 } else if (PLoc.getLine() != LastLocLine) {
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000631 OS << "line" << ':' << PLoc.getLine()
632 << ':' << PLoc.getColumn();
Chris Lattnerf1ca7d32009-01-27 07:57:44 +0000633 LastLocLine = PLoc.getLine();
Chris Lattner11e30d32007-08-30 06:17:34 +0000634 } else {
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000635 OS << "col" << ':' << PLoc.getColumn();
Chris Lattner11e30d32007-08-30 06:17:34 +0000636 }
637}
638
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000639void ASTDumper::dumpSourceRange(SourceRange R) {
Chris Lattner11e30d32007-08-30 06:17:34 +0000640 // Can't translate locations if a SourceManager isn't available.
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000641 if (!SM)
642 return;
Mike Stump11289f42009-09-09 15:08:12 +0000643
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000644 OS << " <";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000645 dumpLocation(R.getBegin());
Chris Lattnera7c19fe2007-10-16 22:36:42 +0000646 if (R.getBegin() != R.getEnd()) {
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000647 OS << ", ";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000648 dumpLocation(R.getEnd());
Chris Lattner11e30d32007-08-30 06:17:34 +0000649 }
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000650 OS << ">";
Mike Stump11289f42009-09-09 15:08:12 +0000651
Chris Lattner11e30d32007-08-30 06:17:34 +0000652 // <t2.c:123:421[blah], t2.c:412:321>
653
654}
655
Richard Smithd5e7ff82014-10-31 01:17:45 +0000656void ASTDumper::dumpBareType(QualType T, bool Desugar) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000657 ColorScope Color(*this, TypeColor);
Richard Smithd5e7ff82014-10-31 01:17:45 +0000658
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000659 SplitQualType T_split = T.split();
Aaron Ballman8c208282017-12-21 21:42:42 +0000660 OS << "'" << QualType::getAsString(T_split, PrintPolicy) << "'";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000661
Richard Smithd5e7ff82014-10-31 01:17:45 +0000662 if (Desugar && !T.isNull()) {
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000663 // If the type is sugared, also dump a (shallow) desugared type.
664 SplitQualType D_split = T.getSplitDesugaredType();
665 if (T_split != D_split)
Aaron Ballman8c208282017-12-21 21:42:42 +0000666 OS << ":'" << QualType::getAsString(D_split, PrintPolicy) << "'";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000667 }
668}
669
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000670void ASTDumper::dumpType(QualType T) {
671 OS << ' ';
672 dumpBareType(T);
673}
674
Richard Smithd5e7ff82014-10-31 01:17:45 +0000675void ASTDumper::dumpTypeAsChild(QualType T) {
676 SplitQualType SQT = T.split();
677 if (!SQT.Quals.hasQualifiers())
678 return dumpTypeAsChild(SQT.Ty);
679
680 dumpChild([=] {
681 OS << "QualType";
682 dumpPointer(T.getAsOpaquePtr());
683 OS << " ";
684 dumpBareType(T, false);
685 OS << " " << T.split().Quals.getAsString();
686 dumpTypeAsChild(T.split().Ty);
687 });
688}
689
690void ASTDumper::dumpTypeAsChild(const Type *T) {
691 dumpChild([=] {
692 if (!T) {
693 ColorScope Color(*this, NullColor);
694 OS << "<<<NULL>>>";
695 return;
696 }
Serge Pavlova6adc9e2015-12-28 17:19:12 +0000697 if (const LocInfoType *LIT = llvm::dyn_cast<LocInfoType>(T)) {
698 {
699 ColorScope Color(*this, TypeColor);
700 OS << "LocInfo Type";
701 }
702 dumpPointer(T);
703 dumpTypeAsChild(LIT->getTypeSourceInfo()->getType());
704 return;
705 }
Richard Smithd5e7ff82014-10-31 01:17:45 +0000706
707 {
708 ColorScope Color(*this, TypeColor);
709 OS << T->getTypeClassName() << "Type";
710 }
711 dumpPointer(T);
712 OS << " ";
713 dumpBareType(QualType(T, 0), false);
714
715 QualType SingleStepDesugar =
716 T->getLocallyUnqualifiedSingleStepDesugaredType();
717 if (SingleStepDesugar != QualType(T, 0))
718 OS << " sugar";
719 if (T->isDependentType())
720 OS << " dependent";
721 else if (T->isInstantiationDependentType())
722 OS << " instantiation_dependent";
723 if (T->isVariablyModifiedType())
724 OS << " variably_modified";
725 if (T->containsUnexpandedParameterPack())
726 OS << " contains_unexpanded_pack";
727 if (T->isFromAST())
728 OS << " imported";
729
730 TypeVisitor<ASTDumper>::Visit(T);
731
732 if (SingleStepDesugar != QualType(T, 0))
733 dumpTypeAsChild(SingleStepDesugar);
734 });
735}
736
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000737void ASTDumper::dumpBareDeclRef(const Decl *D) {
Richard Smith5179eb72016-06-28 19:03:57 +0000738 if (!D) {
739 ColorScope Color(*this, NullColor);
740 OS << "<<<NULL>>>";
741 return;
742 }
743
Richard Trieud215b8d2013-01-26 01:31:20 +0000744 {
745 ColorScope Color(*this, DeclKindNameColor);
746 OS << D->getDeclKindName();
747 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000748 dumpPointer(D);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000749
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000750 if (const NamedDecl *ND = dyn_cast<NamedDecl>(D)) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000751 ColorScope Color(*this, DeclNameColor);
David Blaikied4da8722013-05-14 21:04:00 +0000752 OS << " '" << ND->getDeclName() << '\'';
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000753 }
754
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000755 if (const ValueDecl *VD = dyn_cast<ValueDecl>(D))
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000756 dumpType(VD->getType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000757}
758
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000759void ASTDumper::dumpDeclRef(const Decl *D, const char *Label) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000760 if (!D)
761 return;
762
Richard Smithf7514452014-10-30 21:02:37 +0000763 dumpChild([=]{
764 if (Label)
765 OS << Label << ' ';
766 dumpBareDeclRef(D);
767 });
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000768}
769
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000770void ASTDumper::dumpName(const NamedDecl *ND) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000771 if (ND->getDeclName()) {
772 ColorScope Color(*this, DeclNameColor);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000773 OS << ' ' << ND->getNameAsString();
Richard Trieud215b8d2013-01-26 01:31:20 +0000774 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000775}
776
Richard Trieude5cc7d2013-01-31 01:44:26 +0000777bool ASTDumper::hasNodes(const DeclContext *DC) {
778 if (!DC)
779 return false;
780
Richard Smith1d209d02013-05-23 01:49:11 +0000781 return DC->hasExternalLexicalStorage() ||
Richard Smith3a36ac12017-03-09 22:00:01 +0000782 (Deserialize ? DC->decls_begin() != DC->decls_end()
783 : DC->noload_decls_begin() != DC->noload_decls_end());
Richard Trieude5cc7d2013-01-31 01:44:26 +0000784}
785
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000786void ASTDumper::dumpDeclContext(const DeclContext *DC) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000787 if (!DC)
788 return;
Richard Smithdcc2c452014-03-17 23:00:06 +0000789
Richard Smith3a36ac12017-03-09 22:00:01 +0000790 for (auto *D : (Deserialize ? DC->decls() : DC->noload_decls()))
Richard Smithf7514452014-10-30 21:02:37 +0000791 dumpDecl(D);
Richard Smithdcc2c452014-03-17 23:00:06 +0000792
793 if (DC->hasExternalLexicalStorage()) {
Richard Smithf7514452014-10-30 21:02:37 +0000794 dumpChild([=]{
795 ColorScope Color(*this, UndeserializedColor);
796 OS << "<undeserialized declarations>";
797 });
Richard Smith1d209d02013-05-23 01:49:11 +0000798 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000799}
800
Richard Smith35f986d2014-08-11 22:11:07 +0000801void ASTDumper::dumpLookups(const DeclContext *DC, bool DumpDecls) {
Richard Smithf7514452014-10-30 21:02:37 +0000802 dumpChild([=] {
803 OS << "StoredDeclsMap ";
804 dumpBareDeclRef(cast<Decl>(DC));
Richard Smith33937e72013-06-22 21:49:40 +0000805
Richard Smithf7514452014-10-30 21:02:37 +0000806 const DeclContext *Primary = DC->getPrimaryContext();
807 if (Primary != DC) {
808 OS << " primary";
809 dumpPointer(cast<Decl>(Primary));
Richard Smith33937e72013-06-22 21:49:40 +0000810 }
811
Richard Smithf7514452014-10-30 21:02:37 +0000812 bool HasUndeserializedLookups = Primary->hasExternalVisibleStorage();
Richard Smith35f986d2014-08-11 22:11:07 +0000813
Sam McCall091b1ef2018-01-16 12:33:46 +0000814 auto Range = Deserialize
815 ? Primary->lookups()
816 : Primary->noload_lookups(/*PreserveInternalState=*/true);
817 for (auto I = Range.begin(), E = Range.end(); I != E; ++I) {
Richard Smithf7514452014-10-30 21:02:37 +0000818 DeclarationName Name = I.getLookupName();
Richard Smith3a36ac12017-03-09 22:00:01 +0000819 DeclContextLookupResult R = *I;
Richard Smith35f986d2014-08-11 22:11:07 +0000820
Richard Smithf7514452014-10-30 21:02:37 +0000821 dumpChild([=] {
822 OS << "DeclarationName ";
823 {
824 ColorScope Color(*this, DeclNameColor);
825 OS << '\'' << Name << '\'';
826 }
Richard Smith35f986d2014-08-11 22:11:07 +0000827
Richard Smithf7514452014-10-30 21:02:37 +0000828 for (DeclContextLookupResult::iterator RI = R.begin(), RE = R.end();
829 RI != RE; ++RI) {
830 dumpChild([=] {
831 dumpBareDeclRef(*RI);
832
833 if ((*RI)->isHidden())
834 OS << " hidden";
835
836 // If requested, dump the redecl chain for this lookup.
837 if (DumpDecls) {
838 // Dump earliest decl first.
839 std::function<void(Decl *)> DumpWithPrev = [&](Decl *D) {
840 if (Decl *Prev = D->getPreviousDecl())
841 DumpWithPrev(Prev);
842 dumpDecl(D);
843 };
844 DumpWithPrev(*RI);
845 }
846 });
847 }
848 });
Richard Smith33937e72013-06-22 21:49:40 +0000849 }
Richard Smith33937e72013-06-22 21:49:40 +0000850
Richard Smithf7514452014-10-30 21:02:37 +0000851 if (HasUndeserializedLookups) {
852 dumpChild([=] {
853 ColorScope Color(*this, UndeserializedColor);
854 OS << "<undeserialized lookups>";
855 });
856 }
857 });
Richard Smith33937e72013-06-22 21:49:40 +0000858}
859
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000860void ASTDumper::dumpAttr(const Attr *A) {
Richard Smithf7514452014-10-30 21:02:37 +0000861 dumpChild([=] {
862 {
863 ColorScope Color(*this, AttrColor);
Aaron Ballman36a53502014-01-16 13:03:14 +0000864
Richard Smithf7514452014-10-30 21:02:37 +0000865 switch (A->getKind()) {
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000866#define ATTR(X) case attr::X: OS << #X; break;
867#include "clang/Basic/AttrList.inc"
Richard Smithf7514452014-10-30 21:02:37 +0000868 }
869 OS << "Attr";
Richard Trieud215b8d2013-01-26 01:31:20 +0000870 }
Richard Smithf7514452014-10-30 21:02:37 +0000871 dumpPointer(A);
872 dumpSourceRange(A->getRange());
873 if (A->isInherited())
874 OS << " Inherited";
875 if (A->isImplicit())
876 OS << " Implicit";
Hans Wennborgb0a8b4a2014-05-31 04:05:57 +0000877#include "clang/AST/AttrDump.inc"
Richard Smithf7514452014-10-30 21:02:37 +0000878 });
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000879}
880
Richard Smith71bec062013-10-15 21:58:30 +0000881static void dumpPreviousDeclImpl(raw_ostream &OS, ...) {}
882
883template<typename T>
884static void dumpPreviousDeclImpl(raw_ostream &OS, const Mergeable<T> *D) {
Rafael Espindola8db352d2013-10-17 15:37:26 +0000885 const T *First = D->getFirstDecl();
Richard Smith71bec062013-10-15 21:58:30 +0000886 if (First != D)
887 OS << " first " << First;
Richard Smithf5f43542013-02-07 01:35:44 +0000888}
889
890template<typename T>
Richard Smith71bec062013-10-15 21:58:30 +0000891static void dumpPreviousDeclImpl(raw_ostream &OS, const Redeclarable<T> *D) {
892 const T *Prev = D->getPreviousDecl();
893 if (Prev)
894 OS << " prev " << Prev;
Richard Smithf5f43542013-02-07 01:35:44 +0000895}
896
Richard Smith71bec062013-10-15 21:58:30 +0000897/// Dump the previous declaration in the redeclaration chain for a declaration,
898/// if any.
899static void dumpPreviousDecl(raw_ostream &OS, const Decl *D) {
Richard Smithf5f43542013-02-07 01:35:44 +0000900 switch (D->getKind()) {
901#define DECL(DERIVED, BASE) \
902 case Decl::DERIVED: \
Richard Smith71bec062013-10-15 21:58:30 +0000903 return dumpPreviousDeclImpl(OS, cast<DERIVED##Decl>(D));
Richard Smithf5f43542013-02-07 01:35:44 +0000904#define ABSTRACT_DECL(DECL)
905#include "clang/AST/DeclNodes.inc"
906 }
907 llvm_unreachable("Decl that isn't part of DeclNodes.inc!");
908}
909
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000910//===----------------------------------------------------------------------===//
911// C++ Utilities
912//===----------------------------------------------------------------------===//
913
914void ASTDumper::dumpAccessSpecifier(AccessSpecifier AS) {
915 switch (AS) {
916 case AS_none:
917 break;
918 case AS_public:
919 OS << "public";
920 break;
921 case AS_protected:
922 OS << "protected";
923 break;
924 case AS_private:
925 OS << "private";
926 break;
927 }
928}
929
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000930void ASTDumper::dumpCXXCtorInitializer(const CXXCtorInitializer *Init) {
Richard Smithf7514452014-10-30 21:02:37 +0000931 dumpChild([=] {
932 OS << "CXXCtorInitializer";
933 if (Init->isAnyMemberInitializer()) {
934 OS << ' ';
935 dumpBareDeclRef(Init->getAnyMember());
936 } else if (Init->isBaseInitializer()) {
937 dumpType(QualType(Init->getBaseClass(), 0));
938 } else if (Init->isDelegatingInitializer()) {
939 dumpType(Init->getTypeSourceInfo()->getType());
940 } else {
941 llvm_unreachable("Unknown initializer type");
942 }
943 dumpStmt(Init->getInit());
944 });
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000945}
946
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000947void ASTDumper::dumpTemplateParameters(const TemplateParameterList *TPL) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000948 if (!TPL)
949 return;
950
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000951 for (TemplateParameterList::const_iterator I = TPL->begin(), E = TPL->end();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000952 I != E; ++I)
953 dumpDecl(*I);
954}
955
956void ASTDumper::dumpTemplateArgumentListInfo(
957 const TemplateArgumentListInfo &TALI) {
Richard Smithf7514452014-10-30 21:02:37 +0000958 for (unsigned i = 0, e = TALI.size(); i < e; ++i)
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000959 dumpTemplateArgumentLoc(TALI[i]);
960}
961
962void ASTDumper::dumpTemplateArgumentLoc(const TemplateArgumentLoc &A) {
963 dumpTemplateArgument(A.getArgument(), A.getSourceRange());
964}
965
966void ASTDumper::dumpTemplateArgumentList(const TemplateArgumentList &TAL) {
967 for (unsigned i = 0, e = TAL.size(); i < e; ++i)
968 dumpTemplateArgument(TAL[i]);
969}
970
971void ASTDumper::dumpTemplateArgument(const TemplateArgument &A, SourceRange R) {
Richard Smithf7514452014-10-30 21:02:37 +0000972 dumpChild([=] {
973 OS << "TemplateArgument";
974 if (R.isValid())
975 dumpSourceRange(R);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000976
Richard Smithf7514452014-10-30 21:02:37 +0000977 switch (A.getKind()) {
978 case TemplateArgument::Null:
979 OS << " null";
980 break;
981 case TemplateArgument::Type:
982 OS << " type";
983 dumpType(A.getAsType());
984 break;
985 case TemplateArgument::Declaration:
986 OS << " decl";
987 dumpDeclRef(A.getAsDecl());
988 break;
989 case TemplateArgument::NullPtr:
990 OS << " nullptr";
991 break;
992 case TemplateArgument::Integral:
993 OS << " integral " << A.getAsIntegral();
994 break;
995 case TemplateArgument::Template:
996 OS << " template ";
997 A.getAsTemplate().dump(OS);
998 break;
999 case TemplateArgument::TemplateExpansion:
Richard Trieu59c289f2018-08-21 22:55:26 +00001000 OS << " template expansion ";
Richard Smithf7514452014-10-30 21:02:37 +00001001 A.getAsTemplateOrTemplatePattern().dump(OS);
1002 break;
1003 case TemplateArgument::Expression:
1004 OS << " expr";
1005 dumpStmt(A.getAsExpr());
1006 break;
1007 case TemplateArgument::Pack:
1008 OS << " pack";
1009 for (TemplateArgument::pack_iterator I = A.pack_begin(), E = A.pack_end();
1010 I != E; ++I)
1011 dumpTemplateArgument(*I);
1012 break;
Richard Trieude5cc7d2013-01-31 01:44:26 +00001013 }
Richard Smithf7514452014-10-30 21:02:37 +00001014 });
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001015}
1016
Chris Lattner11e30d32007-08-30 06:17:34 +00001017//===----------------------------------------------------------------------===//
Douglas Gregor85f3f952015-07-07 03:57:15 +00001018// Objective-C Utilities
1019//===----------------------------------------------------------------------===//
1020void ASTDumper::dumpObjCTypeParamList(const ObjCTypeParamList *typeParams) {
1021 if (!typeParams)
1022 return;
1023
1024 for (auto typeParam : *typeParams) {
1025 dumpDecl(typeParam);
1026 }
1027}
1028
1029//===----------------------------------------------------------------------===//
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001030// Decl dumping methods.
Chris Lattnercbe4f772007-08-08 22:51:59 +00001031//===----------------------------------------------------------------------===//
1032
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001033void ASTDumper::dumpDecl(const Decl *D) {
Richard Smithf7514452014-10-30 21:02:37 +00001034 dumpChild([=] {
1035 if (!D) {
1036 ColorScope Color(*this, NullColor);
1037 OS << "<<<NULL>>>";
1038 return;
1039 }
Mike Stump11289f42009-09-09 15:08:12 +00001040
Richard Smithf7514452014-10-30 21:02:37 +00001041 {
1042 ColorScope Color(*this, DeclKindNameColor);
1043 OS << D->getDeclKindName() << "Decl";
1044 }
1045 dumpPointer(D);
1046 if (D->getLexicalDeclContext() != D->getDeclContext())
1047 OS << " parent " << cast<Decl>(D->getDeclContext());
1048 dumpPreviousDecl(OS, D);
1049 dumpSourceRange(D->getSourceRange());
1050 OS << ' ';
1051 dumpLocation(D->getLocation());
Richard Smith26342f92017-05-17 00:24:14 +00001052 if (D->isFromASTFile())
1053 OS << " imported";
1054 if (Module *M = D->getOwningModule())
Richard Smithf7514452014-10-30 21:02:37 +00001055 OS << " in " << M->getFullModuleName();
Richard Smitha2eb4092015-06-22 18:47:01 +00001056 if (auto *ND = dyn_cast<NamedDecl>(D))
1057 for (Module *M : D->getASTContext().getModulesWithMergedDefinition(
1058 const_cast<NamedDecl *>(ND)))
1059 dumpChild([=] { OS << "also in " << M->getFullModuleName(); });
Richard Smithf7514452014-10-30 21:02:37 +00001060 if (const NamedDecl *ND = dyn_cast<NamedDecl>(D))
1061 if (ND->isHidden())
1062 OS << " hidden";
1063 if (D->isImplicit())
1064 OS << " implicit";
1065 if (D->isUsed())
1066 OS << " used";
1067 else if (D->isThisDeclarationReferenced())
1068 OS << " referenced";
1069 if (D->isInvalidDecl())
1070 OS << " invalid";
Hans Wennborg76b00532014-12-05 22:38:57 +00001071 if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
1072 if (FD->isConstexpr())
1073 OS << " constexpr";
1074
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001075
Richard Smithf7514452014-10-30 21:02:37 +00001076 ConstDeclVisitor<ASTDumper>::Visit(D);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001077
Richard Smithf7514452014-10-30 21:02:37 +00001078 for (Decl::attr_iterator I = D->attr_begin(), E = D->attr_end(); I != E;
1079 ++I)
1080 dumpAttr(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001081
Richard Smithf7514452014-10-30 21:02:37 +00001082 if (const FullComment *Comment =
1083 D->getASTContext().getLocalCommentForDeclUncached(D))
1084 dumpFullComment(Comment);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001085
Richard Smithf7514452014-10-30 21:02:37 +00001086 // Decls within functions are visited by the body.
1087 if (!isa<FunctionDecl>(*D) && !isa<ObjCMethodDecl>(*D) &&
1088 hasNodes(dyn_cast<DeclContext>(D)))
1089 dumpDeclContext(cast<DeclContext>(D));
1090 });
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001091}
1092
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001093void ASTDumper::VisitLabelDecl(const LabelDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001094 dumpName(D);
1095}
1096
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001097void ASTDumper::VisitTypedefDecl(const TypedefDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001098 dumpName(D);
1099 dumpType(D->getUnderlyingType());
1100 if (D->isModulePrivate())
1101 OS << " __module_private__";
Richard Smithba3a4f92016-01-12 21:59:26 +00001102 dumpTypeAsChild(D->getUnderlyingType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001103}
1104
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001105void ASTDumper::VisitEnumDecl(const EnumDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001106 if (D->isScoped()) {
1107 if (D->isScopedUsingClassTag())
1108 OS << " class";
1109 else
1110 OS << " struct";
1111 }
1112 dumpName(D);
1113 if (D->isModulePrivate())
1114 OS << " __module_private__";
1115 if (D->isFixed())
1116 dumpType(D->getIntegerType());
1117}
1118
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001119void ASTDumper::VisitRecordDecl(const RecordDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001120 OS << ' ' << D->getKindName();
1121 dumpName(D);
1122 if (D->isModulePrivate())
1123 OS << " __module_private__";
Richard Smith99bc1b92013-08-30 05:32:29 +00001124 if (D->isCompleteDefinition())
1125 OS << " definition";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001126}
1127
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001128void ASTDumper::VisitEnumConstantDecl(const EnumConstantDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001129 dumpName(D);
1130 dumpType(D->getType());
Richard Smithf7514452014-10-30 21:02:37 +00001131 if (const Expr *Init = D->getInitExpr())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001132 dumpStmt(Init);
1133}
1134
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001135void ASTDumper::VisitIndirectFieldDecl(const IndirectFieldDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001136 dumpName(D);
1137 dumpType(D->getType());
Richard Smithdcc2c452014-03-17 23:00:06 +00001138
Richard Smith8aa49222014-03-18 00:35:12 +00001139 for (auto *Child : D->chain())
Richard Smithf7514452014-10-30 21:02:37 +00001140 dumpDeclRef(Child);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001141}
1142
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001143void ASTDumper::VisitFunctionDecl(const FunctionDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001144 dumpName(D);
1145 dumpType(D->getType());
1146
Rafael Espindola6ae7e502013-04-03 19:27:57 +00001147 StorageClass SC = D->getStorageClass();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001148 if (SC != SC_None)
1149 OS << ' ' << VarDecl::getStorageClassSpecifierString(SC);
1150 if (D->isInlineSpecified())
1151 OS << " inline";
1152 if (D->isVirtualAsWritten())
1153 OS << " virtual";
1154 if (D->isModulePrivate())
1155 OS << " __module_private__";
1156
1157 if (D->isPure())
1158 OS << " pure";
Richard Smith5a2e6b92016-11-21 23:43:54 +00001159 if (D->isDefaulted()) {
1160 OS << " default";
1161 if (D->isDeleted())
1162 OS << "_delete";
1163 }
1164 if (D->isDeletedAsWritten())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001165 OS << " delete";
Richard Smith5a2e6b92016-11-21 23:43:54 +00001166 if (D->isTrivial())
1167 OS << " trivial";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001168
Richard Smithadaa0152013-05-17 02:09:46 +00001169 if (const FunctionProtoType *FPT = D->getType()->getAs<FunctionProtoType>()) {
1170 FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo();
Richard Smith8acb4282014-07-31 21:57:55 +00001171 switch (EPI.ExceptionSpec.Type) {
Richard Smithadaa0152013-05-17 02:09:46 +00001172 default: break;
1173 case EST_Unevaluated:
Richard Smith8acb4282014-07-31 21:57:55 +00001174 OS << " noexcept-unevaluated " << EPI.ExceptionSpec.SourceDecl;
Richard Smithadaa0152013-05-17 02:09:46 +00001175 break;
1176 case EST_Uninstantiated:
Richard Smith8acb4282014-07-31 21:57:55 +00001177 OS << " noexcept-uninstantiated " << EPI.ExceptionSpec.SourceTemplate;
Richard Smithadaa0152013-05-17 02:09:46 +00001178 break;
1179 }
1180 }
1181
Richard Smithf7514452014-10-30 21:02:37 +00001182 if (const FunctionTemplateSpecializationInfo *FTSI =
1183 D->getTemplateSpecializationInfo())
Richard Trieude5cc7d2013-01-31 01:44:26 +00001184 dumpTemplateArgumentList(*FTSI->TemplateArguments);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001185
Richard Smith8a639892015-01-24 01:07:20 +00001186 if (!D->param_begin() && D->getNumParams())
1187 dumpChild([=] { OS << "<<NULL params x " << D->getNumParams() << ">>"; });
1188 else
David Majnemera3debed2016-06-24 05:33:44 +00001189 for (const ParmVarDecl *Parameter : D->parameters())
1190 dumpDecl(Parameter);
Richard Smithf7514452014-10-30 21:02:37 +00001191
1192 if (const CXXConstructorDecl *C = dyn_cast<CXXConstructorDecl>(D))
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001193 for (CXXConstructorDecl::init_const_iterator I = C->init_begin(),
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001194 E = C->init_end();
Richard Smithf7514452014-10-30 21:02:37 +00001195 I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001196 dumpCXXCtorInitializer(*I);
1197
Lenar Safin9ae21552017-07-29 20:42:58 +00001198 if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(D)) {
Lang Hames19e07e12017-06-20 21:06:00 +00001199 if (MD->size_overridden_methods() != 0) {
Aaron Ballman8c208282017-12-21 21:42:42 +00001200 auto dumpOverride = [=](const CXXMethodDecl *D) {
1201 SplitQualType T_split = D->getType().split();
1202 OS << D << " " << D->getParent()->getName()
1203 << "::" << D->getNameAsString() << " '"
1204 << QualType::getAsString(T_split, PrintPolicy) << "'";
1205 };
Lang Hames19e07e12017-06-20 21:06:00 +00001206
1207 dumpChild([=] {
Benjamin Krameracfa3392017-12-17 23:52:45 +00001208 auto Overrides = MD->overridden_methods();
Lang Hames19e07e12017-06-20 21:06:00 +00001209 OS << "Overrides: [ ";
Benjamin Krameracfa3392017-12-17 23:52:45 +00001210 dumpOverride(*Overrides.begin());
Lang Hames19e07e12017-06-20 21:06:00 +00001211 for (const auto *Override :
Benjamin Krameracfa3392017-12-17 23:52:45 +00001212 llvm::make_range(Overrides.begin() + 1, Overrides.end())) {
Lenar Safin9ae21552017-07-29 20:42:58 +00001213 OS << ", ";
Lang Hames19e07e12017-06-20 21:06:00 +00001214 dumpOverride(Override);
Lenar Safin9ae21552017-07-29 20:42:58 +00001215 }
Lang Hames19e07e12017-06-20 21:06:00 +00001216 OS << " ]";
1217 });
1218 }
Lenar Safin9ae21552017-07-29 20:42:58 +00001219 }
Lang Hames19e07e12017-06-20 21:06:00 +00001220
Richard Smithf7514452014-10-30 21:02:37 +00001221 if (D->doesThisDeclarationHaveABody())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001222 dumpStmt(D->getBody());
1223}
1224
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001225void ASTDumper::VisitFieldDecl(const FieldDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001226 dumpName(D);
1227 dumpType(D->getType());
1228 if (D->isMutable())
1229 OS << " mutable";
1230 if (D->isModulePrivate())
1231 OS << " __module_private__";
Richard Trieude5cc7d2013-01-31 01:44:26 +00001232
Richard Smithf7514452014-10-30 21:02:37 +00001233 if (D->isBitField())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001234 dumpStmt(D->getBitWidth());
Richard Smithf7514452014-10-30 21:02:37 +00001235 if (Expr *Init = D->getInClassInitializer())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001236 dumpStmt(Init);
1237}
1238
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001239void ASTDumper::VisitVarDecl(const VarDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001240 dumpName(D);
1241 dumpType(D->getType());
Rafael Espindola6ae7e502013-04-03 19:27:57 +00001242 StorageClass SC = D->getStorageClass();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001243 if (SC != SC_None)
1244 OS << ' ' << VarDecl::getStorageClassSpecifierString(SC);
Richard Smithfd3834f2013-04-13 02:43:54 +00001245 switch (D->getTLSKind()) {
1246 case VarDecl::TLS_None: break;
1247 case VarDecl::TLS_Static: OS << " tls"; break;
1248 case VarDecl::TLS_Dynamic: OS << " tls_dynamic"; break;
1249 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001250 if (D->isModulePrivate())
1251 OS << " __module_private__";
1252 if (D->isNRVOVariable())
1253 OS << " nrvo";
Richard Smith62f19e72016-06-25 00:15:56 +00001254 if (D->isInline())
1255 OS << " inline";
1256 if (D->isConstexpr())
1257 OS << " constexpr";
Richard Trieude5cc7d2013-01-31 01:44:26 +00001258 if (D->hasInit()) {
Richard Smithd9967cc2014-07-10 22:54:03 +00001259 switch (D->getInitStyle()) {
1260 case VarDecl::CInit: OS << " cinit"; break;
1261 case VarDecl::CallInit: OS << " callinit"; break;
1262 case VarDecl::ListInit: OS << " listinit"; break;
1263 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001264 dumpStmt(D->getInit());
Richard Trieude5cc7d2013-01-31 01:44:26 +00001265 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001266}
1267
Richard Smithbdb84f32016-07-22 23:36:59 +00001268void ASTDumper::VisitDecompositionDecl(const DecompositionDecl *D) {
1269 VisitVarDecl(D);
1270 for (auto *B : D->bindings())
1271 dumpDecl(B);
1272}
1273
Richard Smith7873de02016-08-11 22:25:46 +00001274void ASTDumper::VisitBindingDecl(const BindingDecl *D) {
1275 dumpName(D);
1276 dumpType(D->getType());
1277 if (auto *E = D->getBinding())
1278 dumpStmt(E);
1279}
1280
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001281void ASTDumper::VisitFileScopeAsmDecl(const FileScopeAsmDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001282 dumpStmt(D->getAsmString());
1283}
1284
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001285void ASTDumper::VisitImportDecl(const ImportDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001286 OS << ' ' << D->getImportedModule()->getFullModuleName();
1287}
1288
Nico Weber66220292016-03-02 17:28:48 +00001289void ASTDumper::VisitPragmaCommentDecl(const PragmaCommentDecl *D) {
1290 OS << ' ';
1291 switch (D->getCommentKind()) {
1292 case PCK_Unknown: llvm_unreachable("unexpected pragma comment kind");
1293 case PCK_Compiler: OS << "compiler"; break;
1294 case PCK_ExeStr: OS << "exestr"; break;
1295 case PCK_Lib: OS << "lib"; break;
1296 case PCK_Linker: OS << "linker"; break;
1297 case PCK_User: OS << "user"; break;
1298 }
1299 StringRef Arg = D->getArg();
1300 if (!Arg.empty())
1301 OS << " \"" << Arg << "\"";
1302}
1303
Nico Webercbbaeb12016-03-02 19:28:54 +00001304void ASTDumper::VisitPragmaDetectMismatchDecl(
1305 const PragmaDetectMismatchDecl *D) {
1306 OS << " \"" << D->getName() << "\" \"" << D->getValue() << "\"";
1307}
1308
Alexey Bataev958b9e72016-03-31 09:30:50 +00001309void ASTDumper::VisitCapturedDecl(const CapturedDecl *D) {
1310 dumpStmt(D->getBody());
1311}
1312
1313//===----------------------------------------------------------------------===//
1314// OpenMP Declarations
1315//===----------------------------------------------------------------------===//
1316
1317void ASTDumper::VisitOMPThreadPrivateDecl(const OMPThreadPrivateDecl *D) {
1318 for (auto *E : D->varlists())
1319 dumpStmt(E);
1320}
1321
1322void ASTDumper::VisitOMPDeclareReductionDecl(const OMPDeclareReductionDecl *D) {
1323 dumpName(D);
1324 dumpType(D->getType());
1325 OS << " combiner";
1326 dumpStmt(D->getCombiner());
1327 if (auto *Initializer = D->getInitializer()) {
1328 OS << " initializer";
Alexey Bataev070f43a2017-09-06 14:49:58 +00001329 switch (D->getInitializerKind()) {
1330 case OMPDeclareReductionDecl::DirectInit:
1331 OS << " omp_priv = ";
1332 break;
1333 case OMPDeclareReductionDecl::CopyInit:
1334 OS << " omp_priv ()";
1335 break;
1336 case OMPDeclareReductionDecl::CallInit:
1337 break;
1338 }
Alexey Bataev958b9e72016-03-31 09:30:50 +00001339 dumpStmt(Initializer);
1340 }
1341}
1342
1343void ASTDumper::VisitOMPCapturedExprDecl(const OMPCapturedExprDecl *D) {
1344 dumpName(D);
1345 dumpType(D->getType());
1346 dumpStmt(D->getInit());
1347}
Nico Webercbbaeb12016-03-02 19:28:54 +00001348
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001349//===----------------------------------------------------------------------===//
1350// C++ Declarations
1351//===----------------------------------------------------------------------===//
1352
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001353void ASTDumper::VisitNamespaceDecl(const NamespaceDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001354 dumpName(D);
1355 if (D->isInline())
1356 OS << " inline";
1357 if (!D->isOriginalNamespace())
1358 dumpDeclRef(D->getOriginalNamespace(), "original");
1359}
1360
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001361void ASTDumper::VisitUsingDirectiveDecl(const UsingDirectiveDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001362 OS << ' ';
1363 dumpBareDeclRef(D->getNominatedNamespace());
1364}
1365
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001366void ASTDumper::VisitNamespaceAliasDecl(const NamespaceAliasDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001367 dumpName(D);
1368 dumpDeclRef(D->getAliasedNamespace());
1369}
1370
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001371void ASTDumper::VisitTypeAliasDecl(const TypeAliasDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001372 dumpName(D);
1373 dumpType(D->getUnderlyingType());
Richard Smithba3a4f92016-01-12 21:59:26 +00001374 dumpTypeAsChild(D->getUnderlyingType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001375}
1376
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001377void ASTDumper::VisitTypeAliasTemplateDecl(const TypeAliasTemplateDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001378 dumpName(D);
1379 dumpTemplateParameters(D->getTemplateParameters());
1380 dumpDecl(D->getTemplatedDecl());
1381}
1382
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001383void ASTDumper::VisitCXXRecordDecl(const CXXRecordDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001384 VisitRecordDecl(D);
1385 if (!D->isCompleteDefinition())
1386 return;
1387
Richard Smithdfc4bff2017-09-22 00:11:15 +00001388 dumpChild([=] {
1389 {
1390 ColorScope Color(*this, DeclKindNameColor);
1391 OS << "DefinitionData";
1392 }
1393#define FLAG(fn, name) if (D->fn()) OS << " " #name;
1394 FLAG(isParsingBaseSpecifiers, parsing_base_specifiers);
1395
1396 FLAG(isGenericLambda, generic);
1397 FLAG(isLambda, lambda);
1398
1399 FLAG(canPassInRegisters, pass_in_registers);
1400 FLAG(isEmpty, empty);
1401 FLAG(isAggregate, aggregate);
1402 FLAG(isStandardLayout, standard_layout);
1403 FLAG(isTriviallyCopyable, trivially_copyable);
1404 FLAG(isPOD, pod);
1405 FLAG(isTrivial, trivial);
1406 FLAG(isPolymorphic, polymorphic);
1407 FLAG(isAbstract, abstract);
1408 FLAG(isLiteral, literal);
1409
1410 FLAG(hasUserDeclaredConstructor, has_user_declared_ctor);
1411 FLAG(hasConstexprNonCopyMoveConstructor, has_constexpr_non_copy_move_ctor);
1412 FLAG(hasMutableFields, has_mutable_fields);
1413 FLAG(hasVariantMembers, has_variant_members);
1414 FLAG(allowConstDefaultInit, can_const_default_init);
1415
1416 dumpChild([=] {
1417 {
1418 ColorScope Color(*this, DeclKindNameColor);
1419 OS << "DefaultConstructor";
1420 }
1421 FLAG(hasDefaultConstructor, exists);
1422 FLAG(hasTrivialDefaultConstructor, trivial);
1423 FLAG(hasNonTrivialDefaultConstructor, non_trivial);
1424 FLAG(hasUserProvidedDefaultConstructor, user_provided);
1425 FLAG(hasConstexprDefaultConstructor, constexpr);
1426 FLAG(needsImplicitDefaultConstructor, needs_implicit);
1427 FLAG(defaultedDefaultConstructorIsConstexpr, defaulted_is_constexpr);
1428 });
1429
1430 dumpChild([=] {
1431 {
1432 ColorScope Color(*this, DeclKindNameColor);
1433 OS << "CopyConstructor";
1434 }
1435 FLAG(hasSimpleCopyConstructor, simple);
1436 FLAG(hasTrivialCopyConstructor, trivial);
1437 FLAG(hasNonTrivialCopyConstructor, non_trivial);
1438 FLAG(hasUserDeclaredCopyConstructor, user_declared);
1439 FLAG(hasCopyConstructorWithConstParam, has_const_param);
1440 FLAG(needsImplicitCopyConstructor, needs_implicit);
1441 FLAG(needsOverloadResolutionForCopyConstructor,
1442 needs_overload_resolution);
1443 if (!D->needsOverloadResolutionForCopyConstructor())
1444 FLAG(defaultedCopyConstructorIsDeleted, defaulted_is_deleted);
1445 FLAG(implicitCopyConstructorHasConstParam, implicit_has_const_param);
1446 });
1447
1448 dumpChild([=] {
1449 {
1450 ColorScope Color(*this, DeclKindNameColor);
1451 OS << "MoveConstructor";
1452 }
1453 FLAG(hasMoveConstructor, exists);
1454 FLAG(hasSimpleMoveConstructor, simple);
1455 FLAG(hasTrivialMoveConstructor, trivial);
1456 FLAG(hasNonTrivialMoveConstructor, non_trivial);
1457 FLAG(hasUserDeclaredMoveConstructor, user_declared);
1458 FLAG(needsImplicitMoveConstructor, needs_implicit);
1459 FLAG(needsOverloadResolutionForMoveConstructor,
1460 needs_overload_resolution);
1461 if (!D->needsOverloadResolutionForMoveConstructor())
1462 FLAG(defaultedMoveConstructorIsDeleted, defaulted_is_deleted);
1463 });
1464
1465 dumpChild([=] {
1466 {
1467 ColorScope Color(*this, DeclKindNameColor);
1468 OS << "CopyAssignment";
1469 }
1470 FLAG(hasTrivialCopyAssignment, trivial);
1471 FLAG(hasNonTrivialCopyAssignment, non_trivial);
1472 FLAG(hasCopyAssignmentWithConstParam, has_const_param);
1473 FLAG(hasUserDeclaredCopyAssignment, user_declared);
1474 FLAG(needsImplicitCopyAssignment, needs_implicit);
1475 FLAG(needsOverloadResolutionForCopyAssignment, needs_overload_resolution);
1476 FLAG(implicitCopyAssignmentHasConstParam, implicit_has_const_param);
1477 });
1478
1479 dumpChild([=] {
1480 {
1481 ColorScope Color(*this, DeclKindNameColor);
1482 OS << "MoveAssignment";
1483 }
1484 FLAG(hasMoveAssignment, exists);
1485 FLAG(hasSimpleMoveAssignment, simple);
1486 FLAG(hasTrivialMoveAssignment, trivial);
1487 FLAG(hasNonTrivialMoveAssignment, non_trivial);
1488 FLAG(hasUserDeclaredMoveAssignment, user_declared);
1489 FLAG(needsImplicitMoveAssignment, needs_implicit);
1490 FLAG(needsOverloadResolutionForMoveAssignment, needs_overload_resolution);
1491 });
1492
1493 dumpChild([=] {
1494 {
1495 ColorScope Color(*this, DeclKindNameColor);
1496 OS << "Destructor";
1497 }
1498 FLAG(hasSimpleDestructor, simple);
1499 FLAG(hasIrrelevantDestructor, irrelevant);
1500 FLAG(hasTrivialDestructor, trivial);
1501 FLAG(hasNonTrivialDestructor, non_trivial);
1502 FLAG(hasUserDeclaredDestructor, user_declared);
1503 FLAG(needsImplicitDestructor, needs_implicit);
1504 FLAG(needsOverloadResolutionForDestructor, needs_overload_resolution);
1505 if (!D->needsOverloadResolutionForDestructor())
1506 FLAG(defaultedDestructorIsDeleted, defaulted_is_deleted);
1507 });
1508 });
1509
Aaron Ballman574705e2014-03-13 15:41:46 +00001510 for (const auto &I : D->bases()) {
Richard Smithf7514452014-10-30 21:02:37 +00001511 dumpChild([=] {
1512 if (I.isVirtual())
1513 OS << "virtual ";
1514 dumpAccessSpecifier(I.getAccessSpecifier());
1515 dumpType(I.getType());
1516 if (I.isPackExpansion())
1517 OS << "...";
1518 });
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001519 }
1520}
1521
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001522void ASTDumper::VisitStaticAssertDecl(const StaticAssertDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001523 dumpStmt(D->getAssertExpr());
1524 dumpStmt(D->getMessage());
1525}
1526
Richard Smithcbdf7332014-03-18 02:07:28 +00001527template<typename SpecializationDecl>
Richard Smithf7514452014-10-30 21:02:37 +00001528void ASTDumper::VisitTemplateDeclSpecialization(const SpecializationDecl *D,
Richard Smithcbdf7332014-03-18 02:07:28 +00001529 bool DumpExplicitInst,
1530 bool DumpRefOnly) {
1531 bool DumpedAny = false;
1532 for (auto *RedeclWithBadType : D->redecls()) {
1533 // FIXME: The redecls() range sometimes has elements of a less-specific
1534 // type. (In particular, ClassTemplateSpecializationDecl::redecls() gives
1535 // us TagDecls, and should give CXXRecordDecls).
1536 auto *Redecl = dyn_cast<SpecializationDecl>(RedeclWithBadType);
1537 if (!Redecl) {
1538 // Found the injected-class-name for a class template. This will be dumped
1539 // as part of its surrounding class so we don't need to dump it here.
1540 assert(isa<CXXRecordDecl>(RedeclWithBadType) &&
1541 "expected an injected-class-name");
1542 continue;
1543 }
1544
1545 switch (Redecl->getTemplateSpecializationKind()) {
1546 case TSK_ExplicitInstantiationDeclaration:
1547 case TSK_ExplicitInstantiationDefinition:
1548 if (!DumpExplicitInst)
1549 break;
Adrian Prantlf3b3ccd2017-12-19 22:06:11 +00001550 LLVM_FALLTHROUGH;
Richard Smithcbdf7332014-03-18 02:07:28 +00001551 case TSK_Undeclared:
1552 case TSK_ImplicitInstantiation:
Richard Smithf7514452014-10-30 21:02:37 +00001553 if (DumpRefOnly)
1554 dumpDeclRef(Redecl);
1555 else
1556 dumpDecl(Redecl);
Richard Smithcbdf7332014-03-18 02:07:28 +00001557 DumpedAny = true;
1558 break;
1559 case TSK_ExplicitSpecialization:
1560 break;
1561 }
1562 }
1563
1564 // Ensure we dump at least one decl for each specialization.
1565 if (!DumpedAny)
Richard Smithf7514452014-10-30 21:02:37 +00001566 dumpDeclRef(D);
Richard Smithcbdf7332014-03-18 02:07:28 +00001567}
1568
Richard Smith20ade552014-03-17 23:34:53 +00001569template<typename TemplateDecl>
1570void ASTDumper::VisitTemplateDecl(const TemplateDecl *D,
1571 bool DumpExplicitInst) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001572 dumpName(D);
1573 dumpTemplateParameters(D->getTemplateParameters());
Richard Smithdcc2c452014-03-17 23:00:06 +00001574
Richard Smithf7514452014-10-30 21:02:37 +00001575 dumpDecl(D->getTemplatedDecl());
Richard Smithdcc2c452014-03-17 23:00:06 +00001576
Richard Smithcbdf7332014-03-18 02:07:28 +00001577 for (auto *Child : D->specializations())
Richard Smithf7514452014-10-30 21:02:37 +00001578 VisitTemplateDeclSpecialization(Child, DumpExplicitInst,
Richard Smithcbdf7332014-03-18 02:07:28 +00001579 !D->isCanonicalDecl());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001580}
1581
Richard Smith20ade552014-03-17 23:34:53 +00001582void ASTDumper::VisitFunctionTemplateDecl(const FunctionTemplateDecl *D) {
1583 // FIXME: We don't add a declaration of a function template specialization
1584 // to its context when it's explicitly instantiated, so dump explicit
1585 // instantiations when we dump the template itself.
1586 VisitTemplateDecl(D, true);
1587}
1588
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001589void ASTDumper::VisitClassTemplateDecl(const ClassTemplateDecl *D) {
Richard Smith20ade552014-03-17 23:34:53 +00001590 VisitTemplateDecl(D, false);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001591}
1592
1593void ASTDumper::VisitClassTemplateSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001594 const ClassTemplateSpecializationDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001595 VisitCXXRecordDecl(D);
1596 dumpTemplateArgumentList(D->getTemplateArgs());
1597}
1598
1599void ASTDumper::VisitClassTemplatePartialSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001600 const ClassTemplatePartialSpecializationDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001601 VisitClassTemplateSpecializationDecl(D);
1602 dumpTemplateParameters(D->getTemplateParameters());
1603}
1604
1605void ASTDumper::VisitClassScopeFunctionSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001606 const ClassScopeFunctionSpecializationDecl *D) {
Richard Smithc660c8f2018-03-16 13:36:56 +00001607 dumpDecl(D->getSpecialization());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001608 if (D->hasExplicitTemplateArgs())
1609 dumpTemplateArgumentListInfo(D->templateArgs());
1610}
1611
Richard Smithd25789a2013-09-18 01:36:02 +00001612void ASTDumper::VisitVarTemplateDecl(const VarTemplateDecl *D) {
Richard Smith20ade552014-03-17 23:34:53 +00001613 VisitTemplateDecl(D, false);
Richard Smithd25789a2013-09-18 01:36:02 +00001614}
1615
David Majnemerd9b1a4f2015-11-04 03:40:30 +00001616void ASTDumper::VisitBuiltinTemplateDecl(const BuiltinTemplateDecl *D) {
1617 dumpName(D);
1618 dumpTemplateParameters(D->getTemplateParameters());
1619}
1620
Richard Smithd25789a2013-09-18 01:36:02 +00001621void ASTDumper::VisitVarTemplateSpecializationDecl(
1622 const VarTemplateSpecializationDecl *D) {
1623 dumpTemplateArgumentList(D->getTemplateArgs());
1624 VisitVarDecl(D);
1625}
1626
1627void ASTDumper::VisitVarTemplatePartialSpecializationDecl(
1628 const VarTemplatePartialSpecializationDecl *D) {
1629 dumpTemplateParameters(D->getTemplateParameters());
1630 VisitVarTemplateSpecializationDecl(D);
1631}
1632
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001633void ASTDumper::VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001634 if (D->wasDeclaredWithTypename())
1635 OS << " typename";
1636 else
1637 OS << " class";
Richard Smith1832a022017-02-21 02:04:03 +00001638 OS << " depth " << D->getDepth() << " index " << D->getIndex();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001639 if (D->isParameterPack())
1640 OS << " ...";
1641 dumpName(D);
Richard Smithf7514452014-10-30 21:02:37 +00001642 if (D->hasDefaultArgument())
Richard Smithecf74ff2014-03-23 20:50:39 +00001643 dumpTemplateArgument(D->getDefaultArgument());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001644}
1645
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001646void ASTDumper::VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001647 dumpType(D->getType());
Richard Smith1832a022017-02-21 02:04:03 +00001648 OS << " depth " << D->getDepth() << " index " << D->getIndex();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001649 if (D->isParameterPack())
1650 OS << " ...";
1651 dumpName(D);
Richard Smithf7514452014-10-30 21:02:37 +00001652 if (D->hasDefaultArgument())
Richard Smithecf74ff2014-03-23 20:50:39 +00001653 dumpTemplateArgument(D->getDefaultArgument());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001654}
1655
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001656void ASTDumper::VisitTemplateTemplateParmDecl(
1657 const TemplateTemplateParmDecl *D) {
Richard Smith1832a022017-02-21 02:04:03 +00001658 OS << " depth " << D->getDepth() << " index " << D->getIndex();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001659 if (D->isParameterPack())
1660 OS << " ...";
1661 dumpName(D);
1662 dumpTemplateParameters(D->getTemplateParameters());
Richard Smithf7514452014-10-30 21:02:37 +00001663 if (D->hasDefaultArgument())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001664 dumpTemplateArgumentLoc(D->getDefaultArgument());
1665}
1666
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001667void ASTDumper::VisitUsingDecl(const UsingDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001668 OS << ' ';
Dawn Perchikddd03bf2015-12-05 22:37:55 +00001669 if (D->getQualifier())
1670 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001671 OS << D->getNameAsString();
1672}
1673
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001674void ASTDumper::VisitUnresolvedUsingTypenameDecl(
1675 const UnresolvedUsingTypenameDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001676 OS << ' ';
Dawn Perchikddd03bf2015-12-05 22:37:55 +00001677 if (D->getQualifier())
1678 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001679 OS << D->getNameAsString();
1680}
1681
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001682void ASTDumper::VisitUnresolvedUsingValueDecl(const UnresolvedUsingValueDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001683 OS << ' ';
Dawn Perchikddd03bf2015-12-05 22:37:55 +00001684 if (D->getQualifier())
1685 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001686 OS << D->getNameAsString();
1687 dumpType(D->getType());
1688}
1689
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001690void ASTDumper::VisitUsingShadowDecl(const UsingShadowDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001691 OS << ' ';
1692 dumpBareDeclRef(D->getTargetDecl());
Richard Smithba3a4f92016-01-12 21:59:26 +00001693 if (auto *TD = dyn_cast<TypeDecl>(D->getUnderlyingDecl()))
1694 dumpTypeAsChild(TD->getTypeForDecl());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001695}
1696
Richard Smith5179eb72016-06-28 19:03:57 +00001697void ASTDumper::VisitConstructorUsingShadowDecl(
1698 const ConstructorUsingShadowDecl *D) {
1699 if (D->constructsVirtualBase())
1700 OS << " virtual";
1701
1702 dumpChild([=] {
1703 OS << "target ";
1704 dumpBareDeclRef(D->getTargetDecl());
1705 });
1706
1707 dumpChild([=] {
1708 OS << "nominated ";
1709 dumpBareDeclRef(D->getNominatedBaseClass());
1710 OS << ' ';
1711 dumpBareDeclRef(D->getNominatedBaseClassShadowDecl());
1712 });
1713
1714 dumpChild([=] {
1715 OS << "constructed ";
1716 dumpBareDeclRef(D->getConstructedBaseClass());
1717 OS << ' ';
1718 dumpBareDeclRef(D->getConstructedBaseClassShadowDecl());
1719 });
1720}
1721
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001722void ASTDumper::VisitLinkageSpecDecl(const LinkageSpecDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001723 switch (D->getLanguage()) {
1724 case LinkageSpecDecl::lang_c: OS << " C"; break;
1725 case LinkageSpecDecl::lang_cxx: OS << " C++"; break;
1726 }
1727}
1728
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001729void ASTDumper::VisitAccessSpecDecl(const AccessSpecDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001730 OS << ' ';
1731 dumpAccessSpecifier(D->getAccess());
1732}
1733
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001734void ASTDumper::VisitFriendDecl(const FriendDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001735 if (TypeSourceInfo *T = D->getFriendType())
1736 dumpType(T->getType());
1737 else
1738 dumpDecl(D->getFriendDecl());
1739}
1740
1741//===----------------------------------------------------------------------===//
1742// Obj-C Declarations
1743//===----------------------------------------------------------------------===//
1744
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001745void ASTDumper::VisitObjCIvarDecl(const ObjCIvarDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001746 dumpName(D);
1747 dumpType(D->getType());
1748 if (D->getSynthesize())
1749 OS << " synthesize";
1750
1751 switch (D->getAccessControl()) {
1752 case ObjCIvarDecl::None:
1753 OS << " none";
1754 break;
1755 case ObjCIvarDecl::Private:
1756 OS << " private";
1757 break;
1758 case ObjCIvarDecl::Protected:
1759 OS << " protected";
1760 break;
1761 case ObjCIvarDecl::Public:
1762 OS << " public";
1763 break;
1764 case ObjCIvarDecl::Package:
1765 OS << " package";
1766 break;
1767 }
1768}
1769
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001770void ASTDumper::VisitObjCMethodDecl(const ObjCMethodDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001771 if (D->isInstanceMethod())
1772 OS << " -";
1773 else
1774 OS << " +";
1775 dumpName(D);
Alp Toker314cc812014-01-25 16:55:45 +00001776 dumpType(D->getReturnType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001777
Richard Trieude5cc7d2013-01-31 01:44:26 +00001778 if (D->isThisDeclarationADefinition()) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001779 dumpDeclContext(D);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001780 } else {
David Majnemera3debed2016-06-24 05:33:44 +00001781 for (const ParmVarDecl *Parameter : D->parameters())
1782 dumpDecl(Parameter);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001783 }
1784
Richard Smithf7514452014-10-30 21:02:37 +00001785 if (D->isVariadic())
1786 dumpChild([=] { OS << "..."; });
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001787
Richard Smithf7514452014-10-30 21:02:37 +00001788 if (D->hasBody())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001789 dumpStmt(D->getBody());
1790}
1791
Douglas Gregor85f3f952015-07-07 03:57:15 +00001792void ASTDumper::VisitObjCTypeParamDecl(const ObjCTypeParamDecl *D) {
1793 dumpName(D);
Douglas Gregor1ac1b632015-07-07 03:58:54 +00001794 switch (D->getVariance()) {
1795 case ObjCTypeParamVariance::Invariant:
1796 break;
1797
1798 case ObjCTypeParamVariance::Covariant:
1799 OS << " covariant";
1800 break;
1801
1802 case ObjCTypeParamVariance::Contravariant:
1803 OS << " contravariant";
1804 break;
1805 }
1806
Douglas Gregor85f3f952015-07-07 03:57:15 +00001807 if (D->hasExplicitBound())
1808 OS << " bounded";
1809 dumpType(D->getUnderlyingType());
1810}
1811
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001812void ASTDumper::VisitObjCCategoryDecl(const ObjCCategoryDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001813 dumpName(D);
1814 dumpDeclRef(D->getClassInterface());
Douglas Gregor85f3f952015-07-07 03:57:15 +00001815 dumpObjCTypeParamList(D->getTypeParamList());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001816 dumpDeclRef(D->getImplementation());
1817 for (ObjCCategoryDecl::protocol_iterator I = D->protocol_begin(),
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001818 E = D->protocol_end();
Richard Smithf7514452014-10-30 21:02:37 +00001819 I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001820 dumpDeclRef(*I);
1821}
1822
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001823void ASTDumper::VisitObjCCategoryImplDecl(const ObjCCategoryImplDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001824 dumpName(D);
1825 dumpDeclRef(D->getClassInterface());
1826 dumpDeclRef(D->getCategoryDecl());
1827}
1828
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001829void ASTDumper::VisitObjCProtocolDecl(const ObjCProtocolDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001830 dumpName(D);
Richard Smithdcc2c452014-03-17 23:00:06 +00001831
Richard Smith7fcb35f2014-03-18 02:37:59 +00001832 for (auto *Child : D->protocols())
Richard Smithf7514452014-10-30 21:02:37 +00001833 dumpDeclRef(Child);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001834}
1835
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001836void ASTDumper::VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001837 dumpName(D);
Douglas Gregor85f3f952015-07-07 03:57:15 +00001838 dumpObjCTypeParamList(D->getTypeParamListAsWritten());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001839 dumpDeclRef(D->getSuperClass(), "super");
Richard Smithdcc2c452014-03-17 23:00:06 +00001840
Richard Smithf7514452014-10-30 21:02:37 +00001841 dumpDeclRef(D->getImplementation());
Richard Smith7fcb35f2014-03-18 02:37:59 +00001842 for (auto *Child : D->protocols())
Richard Smithf7514452014-10-30 21:02:37 +00001843 dumpDeclRef(Child);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001844}
1845
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001846void ASTDumper::VisitObjCImplementationDecl(const ObjCImplementationDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001847 dumpName(D);
1848 dumpDeclRef(D->getSuperClass(), "super");
1849 dumpDeclRef(D->getClassInterface());
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001850 for (ObjCImplementationDecl::init_const_iterator I = D->init_begin(),
1851 E = D->init_end();
Richard Smithf7514452014-10-30 21:02:37 +00001852 I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001853 dumpCXXCtorInitializer(*I);
1854}
1855
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001856void ASTDumper::VisitObjCCompatibleAliasDecl(const ObjCCompatibleAliasDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001857 dumpName(D);
1858 dumpDeclRef(D->getClassInterface());
1859}
1860
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001861void ASTDumper::VisitObjCPropertyDecl(const ObjCPropertyDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001862 dumpName(D);
1863 dumpType(D->getType());
1864
1865 if (D->getPropertyImplementation() == ObjCPropertyDecl::Required)
1866 OS << " required";
1867 else if (D->getPropertyImplementation() == ObjCPropertyDecl::Optional)
1868 OS << " optional";
1869
1870 ObjCPropertyDecl::PropertyAttributeKind Attrs = D->getPropertyAttributes();
1871 if (Attrs != ObjCPropertyDecl::OBJC_PR_noattr) {
1872 if (Attrs & ObjCPropertyDecl::OBJC_PR_readonly)
1873 OS << " readonly";
1874 if (Attrs & ObjCPropertyDecl::OBJC_PR_assign)
1875 OS << " assign";
1876 if (Attrs & ObjCPropertyDecl::OBJC_PR_readwrite)
1877 OS << " readwrite";
1878 if (Attrs & ObjCPropertyDecl::OBJC_PR_retain)
1879 OS << " retain";
1880 if (Attrs & ObjCPropertyDecl::OBJC_PR_copy)
1881 OS << " copy";
1882 if (Attrs & ObjCPropertyDecl::OBJC_PR_nonatomic)
1883 OS << " nonatomic";
1884 if (Attrs & ObjCPropertyDecl::OBJC_PR_atomic)
1885 OS << " atomic";
1886 if (Attrs & ObjCPropertyDecl::OBJC_PR_weak)
1887 OS << " weak";
1888 if (Attrs & ObjCPropertyDecl::OBJC_PR_strong)
1889 OS << " strong";
1890 if (Attrs & ObjCPropertyDecl::OBJC_PR_unsafe_unretained)
1891 OS << " unsafe_unretained";
Manman Ren387ff7f2016-01-26 18:52:43 +00001892 if (Attrs & ObjCPropertyDecl::OBJC_PR_class)
1893 OS << " class";
Richard Smithf7514452014-10-30 21:02:37 +00001894 if (Attrs & ObjCPropertyDecl::OBJC_PR_getter)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001895 dumpDeclRef(D->getGetterMethodDecl(), "getter");
Richard Smithf7514452014-10-30 21:02:37 +00001896 if (Attrs & ObjCPropertyDecl::OBJC_PR_setter)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001897 dumpDeclRef(D->getSetterMethodDecl(), "setter");
1898 }
1899}
1900
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001901void ASTDumper::VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001902 dumpName(D->getPropertyDecl());
1903 if (D->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize)
1904 OS << " synthesize";
1905 else
1906 OS << " dynamic";
1907 dumpDeclRef(D->getPropertyDecl());
1908 dumpDeclRef(D->getPropertyIvarDecl());
1909}
1910
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001911void ASTDumper::VisitBlockDecl(const BlockDecl *D) {
David Majnemer59f77922016-06-24 04:05:48 +00001912 for (auto I : D->parameters())
Aaron Ballmanb2b8b1d2014-03-07 16:09:59 +00001913 dumpDecl(I);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001914
Richard Smithf7514452014-10-30 21:02:37 +00001915 if (D->isVariadic())
1916 dumpChild([=]{ OS << "..."; });
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001917
Richard Smithf7514452014-10-30 21:02:37 +00001918 if (D->capturesCXXThis())
1919 dumpChild([=]{ OS << "capture this"; });
1920
Aaron Ballman9371dd22014-03-14 18:34:04 +00001921 for (const auto &I : D->captures()) {
Richard Smithf7514452014-10-30 21:02:37 +00001922 dumpChild([=] {
1923 OS << "capture";
1924 if (I.isByRef())
1925 OS << " byref";
1926 if (I.isNested())
1927 OS << " nested";
1928 if (I.getVariable()) {
1929 OS << ' ';
1930 dumpBareDeclRef(I.getVariable());
1931 }
1932 if (I.hasCopyExpr())
1933 dumpStmt(I.getCopyExpr());
1934 });
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001935 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001936 dumpStmt(D->getBody());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001937}
1938
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001939//===----------------------------------------------------------------------===//
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001940// Stmt dumping methods.
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001941//===----------------------------------------------------------------------===//
1942
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001943void ASTDumper::dumpStmt(const Stmt *S) {
Richard Smithf7514452014-10-30 21:02:37 +00001944 dumpChild([=] {
1945 if (!S) {
1946 ColorScope Color(*this, NullColor);
1947 OS << "<<<NULL>>>";
1948 return;
1949 }
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001950
Richard Smith01ccebf2018-01-05 21:31:07 +00001951 // Some statements have custom mechanisms for dumping their children.
Richard Smithf7514452014-10-30 21:02:37 +00001952 if (const DeclStmt *DS = dyn_cast<DeclStmt>(S)) {
1953 VisitDeclStmt(DS);
1954 return;
1955 }
Richard Smith01ccebf2018-01-05 21:31:07 +00001956 if (const GenericSelectionExpr *GSE = dyn_cast<GenericSelectionExpr>(S)) {
1957 VisitGenericSelectionExpr(GSE);
1958 return;
1959 }
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001960
Richard Smithf7514452014-10-30 21:02:37 +00001961 ConstStmtVisitor<ASTDumper>::Visit(S);
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001962
Benjamin Kramer642f1732015-07-02 21:03:14 +00001963 for (const Stmt *SubStmt : S->children())
1964 dumpStmt(SubStmt);
Richard Smithf7514452014-10-30 21:02:37 +00001965 });
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001966}
1967
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001968void ASTDumper::VisitStmt(const Stmt *Node) {
Fangrui Song6907ce22018-07-30 19:24:48 +00001969 {
Richard Trieud215b8d2013-01-26 01:31:20 +00001970 ColorScope Color(*this, StmtColor);
1971 OS << Node->getStmtClassName();
1972 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001973 dumpPointer(Node);
1974 dumpSourceRange(Node->getSourceRange());
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001975}
1976
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001977void ASTDumper::VisitDeclStmt(const DeclStmt *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001978 VisitStmt(Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001979 for (DeclStmt::const_decl_iterator I = Node->decl_begin(),
1980 E = Node->decl_end();
Richard Smithf7514452014-10-30 21:02:37 +00001981 I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001982 dumpDecl(*I);
Ted Kremenek433a4922007-12-12 06:59:42 +00001983}
1984
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001985void ASTDumper::VisitAttributedStmt(const AttributedStmt *Node) {
Alexander Kornienko5bc364e2013-01-07 17:53:08 +00001986 VisitStmt(Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001987 for (ArrayRef<const Attr *>::iterator I = Node->getAttrs().begin(),
1988 E = Node->getAttrs().end();
Richard Smithf7514452014-10-30 21:02:37 +00001989 I != E; ++I)
Alexander Kornienko5bc364e2013-01-07 17:53:08 +00001990 dumpAttr(*I);
1991}
1992
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001993void ASTDumper::VisitLabelStmt(const LabelStmt *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001994 VisitStmt(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001995 OS << " '" << Node->getName() << "'";
Chris Lattnercbe4f772007-08-08 22:51:59 +00001996}
1997
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001998void ASTDumper::VisitGotoStmt(const GotoStmt *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001999 VisitStmt(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002000 OS << " '" << Node->getLabel()->getName() << "'";
2001 dumpPointer(Node->getLabel());
Chris Lattnercbe4f772007-08-08 22:51:59 +00002002}
2003
Pavel Labath1ef83422013-09-04 14:35:00 +00002004void ASTDumper::VisitCXXCatchStmt(const CXXCatchStmt *Node) {
2005 VisitStmt(Node);
2006 dumpDecl(Node->getExceptionDecl());
2007}
2008
Alexey Bataev958b9e72016-03-31 09:30:50 +00002009void ASTDumper::VisitCapturedStmt(const CapturedStmt *Node) {
2010 VisitStmt(Node);
2011 dumpDecl(Node->getCapturedDecl());
2012}
2013
2014//===----------------------------------------------------------------------===//
2015// OpenMP dumping methods.
2016//===----------------------------------------------------------------------===//
2017
2018void ASTDumper::VisitOMPExecutableDirective(
2019 const OMPExecutableDirective *Node) {
2020 VisitStmt(Node);
2021 for (auto *C : Node->clauses()) {
2022 dumpChild([=] {
2023 if (!C) {
2024 ColorScope Color(*this, NullColor);
2025 OS << "<<<NULL>>> OMPClause";
2026 return;
2027 }
2028 {
2029 ColorScope Color(*this, AttrColor);
2030 StringRef ClauseName(getOpenMPClauseName(C->getClauseKind()));
2031 OS << "OMP" << ClauseName.substr(/*Start=*/0, /*N=*/1).upper()
2032 << ClauseName.drop_front() << "Clause";
2033 }
2034 dumpPointer(C);
Stephen Kelly1c301dc2018-08-09 21:09:38 +00002035 dumpSourceRange(SourceRange(C->getBeginLoc(), C->getEndLoc()));
Alexey Bataev958b9e72016-03-31 09:30:50 +00002036 if (C->isImplicit())
2037 OS << " <implicit>";
2038 for (auto *S : C->children())
2039 dumpStmt(S);
2040 });
2041 }
2042}
2043
Chris Lattnercbe4f772007-08-08 22:51:59 +00002044//===----------------------------------------------------------------------===//
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002045// Expr dumping methods.
Chris Lattnercbe4f772007-08-08 22:51:59 +00002046//===----------------------------------------------------------------------===//
2047
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002048void ASTDumper::VisitExpr(const Expr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002049 VisitStmt(Node);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002050 dumpType(Node->getType());
2051
Richard Trieud215b8d2013-01-26 01:31:20 +00002052 {
2053 ColorScope Color(*this, ValueKindColor);
2054 switch (Node->getValueKind()) {
2055 case VK_RValue:
2056 break;
2057 case VK_LValue:
2058 OS << " lvalue";
2059 break;
2060 case VK_XValue:
2061 OS << " xvalue";
2062 break;
2063 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002064 }
2065
Richard Trieud215b8d2013-01-26 01:31:20 +00002066 {
2067 ColorScope Color(*this, ObjectKindColor);
2068 switch (Node->getObjectKind()) {
2069 case OK_Ordinary:
2070 break;
2071 case OK_BitField:
2072 OS << " bitfield";
2073 break;
2074 case OK_ObjCProperty:
2075 OS << " objcproperty";
2076 break;
2077 case OK_ObjCSubscript:
2078 OS << " objcsubscript";
2079 break;
2080 case OK_VectorComponent:
2081 OS << " vectorcomponent";
2082 break;
2083 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002084 }
Chris Lattnercbe4f772007-08-08 22:51:59 +00002085}
2086
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002087static void dumpBasePath(raw_ostream &OS, const CastExpr *Node) {
John McCallcf142162010-08-07 06:22:56 +00002088 if (Node->path_empty())
Anders Carlssona70cff62010-04-24 19:06:50 +00002089 return;
2090
2091 OS << " (";
2092 bool First = true;
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002093 for (CastExpr::path_const_iterator I = Node->path_begin(),
2094 E = Node->path_end();
2095 I != E; ++I) {
Anders Carlssona70cff62010-04-24 19:06:50 +00002096 const CXXBaseSpecifier *Base = *I;
2097 if (!First)
2098 OS << " -> ";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002099
Anders Carlssona70cff62010-04-24 19:06:50 +00002100 const CXXRecordDecl *RD =
2101 cast<CXXRecordDecl>(Base->getType()->getAs<RecordType>()->getDecl());
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002102
Anders Carlssona70cff62010-04-24 19:06:50 +00002103 if (Base->isVirtual())
2104 OS << "virtual ";
2105 OS << RD->getName();
2106 First = false;
2107 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002108
Anders Carlssona70cff62010-04-24 19:06:50 +00002109 OS << ')';
2110}
2111
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002112void ASTDumper::VisitCastExpr(const CastExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002113 VisitExpr(Node);
Richard Trieud215b8d2013-01-26 01:31:20 +00002114 OS << " <";
2115 {
2116 ColorScope Color(*this, CastColor);
2117 OS << Node->getCastKindName();
2118 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002119 dumpBasePath(OS, Node);
Anders Carlssona70cff62010-04-24 19:06:50 +00002120 OS << ">";
Roman Lebedev12216f12018-07-27 07:27:14 +00002121}
Roman Lebedevd55661d2018-07-24 08:16:50 +00002122
Roman Lebedev12216f12018-07-27 07:27:14 +00002123void ASTDumper::VisitImplicitCastExpr(const ImplicitCastExpr *Node) {
2124 VisitCastExpr(Node);
2125 if (Node->isPartOfExplicitCast())
Roman Lebedevd55661d2018-07-24 08:16:50 +00002126 OS << " part_of_explicit_cast";
Anders Carlssond7923c62009-08-22 23:33:40 +00002127}
2128
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002129void ASTDumper::VisitDeclRefExpr(const DeclRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002130 VisitExpr(Node);
Ted Kremenek5f64ca82007-09-10 17:32:55 +00002131
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002132 OS << " ";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002133 dumpBareDeclRef(Node->getDecl());
Chandler Carruth8d26bb02011-05-01 23:48:14 +00002134 if (Node->getDecl() != Node->getFoundDecl()) {
2135 OS << " (";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002136 dumpBareDeclRef(Node->getFoundDecl());
Chandler Carruth8d26bb02011-05-01 23:48:14 +00002137 OS << ")";
2138 }
John McCall351762c2011-02-07 10:33:21 +00002139}
2140
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002141void ASTDumper::VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002142 VisitExpr(Node);
John McCall76d09942009-12-11 21:50:11 +00002143 OS << " (";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002144 if (!Node->requiresADL())
2145 OS << "no ";
Benjamin Kramerb11416d2010-04-17 09:33:03 +00002146 OS << "ADL) = '" << Node->getName() << '\'';
John McCall76d09942009-12-11 21:50:11 +00002147
2148 UnresolvedLookupExpr::decls_iterator
2149 I = Node->decls_begin(), E = Node->decls_end();
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002150 if (I == E)
2151 OS << " empty";
John McCall76d09942009-12-11 21:50:11 +00002152 for (; I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002153 dumpPointer(*I);
John McCall76d09942009-12-11 21:50:11 +00002154}
2155
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002156void ASTDumper::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002157 VisitExpr(Node);
Steve Naroff5d5efca2008-03-12 13:19:12 +00002158
Richard Trieud215b8d2013-01-26 01:31:20 +00002159 {
2160 ColorScope Color(*this, DeclKindNameColor);
2161 OS << " " << Node->getDecl()->getDeclKindName() << "Decl";
2162 }
2163 OS << "='" << *Node->getDecl() << "'";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002164 dumpPointer(Node->getDecl());
Steve Naroffb3424a92008-05-23 22:01:24 +00002165 if (Node->isFreeIvar())
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002166 OS << " isFreeIvar";
Steve Naroff5d5efca2008-03-12 13:19:12 +00002167}
2168
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002169void ASTDumper::VisitPredefinedExpr(const PredefinedExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002170 VisitExpr(Node);
Alexey Bataevec474782014-10-09 08:45:04 +00002171 OS << " " << PredefinedExpr::getIdentTypeName(Node->getIdentType());
Chris Lattnercbe4f772007-08-08 22:51:59 +00002172}
2173
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002174void ASTDumper::VisitCharacterLiteral(const CharacterLiteral *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002175 VisitExpr(Node);
Richard Trieud215b8d2013-01-26 01:31:20 +00002176 ColorScope Color(*this, ValueColor);
Richard Trieu364ee422011-11-03 23:56:23 +00002177 OS << " " << Node->getValue();
Chris Lattnercbe4f772007-08-08 22:51:59 +00002178}
2179
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002180void ASTDumper::VisitIntegerLiteral(const IntegerLiteral *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002181 VisitExpr(Node);
Chris Lattnercbe4f772007-08-08 22:51:59 +00002182
2183 bool isSigned = Node->getType()->isSignedIntegerType();
Richard Trieud215b8d2013-01-26 01:31:20 +00002184 ColorScope Color(*this, ValueColor);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002185 OS << " " << Node->getValue().toString(10, isSigned);
Chris Lattnercbe4f772007-08-08 22:51:59 +00002186}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002187
Leonard Chandb01c3a2018-06-20 17:19:40 +00002188void ASTDumper::VisitFixedPointLiteral(const FixedPointLiteral *Node) {
2189 VisitExpr(Node);
2190
2191 ColorScope Color(*this, ValueColor);
2192 OS << " " << Node->getValueAsString(/*Radix=*/10);
2193}
2194
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002195void ASTDumper::VisitFloatingLiteral(const FloatingLiteral *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002196 VisitExpr(Node);
Richard Trieud215b8d2013-01-26 01:31:20 +00002197 ColorScope Color(*this, ValueColor);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002198 OS << " " << Node->getValueAsApproximateDouble();
Chris Lattnercbe4f772007-08-08 22:51:59 +00002199}
Chris Lattner1c20a172007-08-26 03:42:43 +00002200
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002201void ASTDumper::VisitStringLiteral(const StringLiteral *Str) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002202 VisitExpr(Str);
Richard Trieud215b8d2013-01-26 01:31:20 +00002203 ColorScope Color(*this, ValueColor);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002204 OS << " ";
Richard Trieudc355912012-06-13 20:25:24 +00002205 Str->outputString(OS);
Chris Lattnercbe4f772007-08-08 22:51:59 +00002206}
Chris Lattner84ca3762007-08-30 01:00:35 +00002207
Richard Smithf0514962014-06-03 08:24:28 +00002208void ASTDumper::VisitInitListExpr(const InitListExpr *ILE) {
2209 VisitExpr(ILE);
2210 if (auto *Filler = ILE->getArrayFiller()) {
Richard Smithf7514452014-10-30 21:02:37 +00002211 dumpChild([=] {
2212 OS << "array filler";
2213 dumpStmt(Filler);
2214 });
Richard Smithf0514962014-06-03 08:24:28 +00002215 }
2216 if (auto *Field = ILE->getInitializedFieldInUnion()) {
2217 OS << " field ";
2218 dumpBareDeclRef(Field);
2219 }
2220}
2221
Richard Smith410306b2016-12-12 02:53:20 +00002222void ASTDumper::VisitArrayInitLoopExpr(const ArrayInitLoopExpr *E) {
2223 VisitExpr(E);
2224}
2225
2226void ASTDumper::VisitArrayInitIndexExpr(const ArrayInitIndexExpr *E) {
2227 VisitExpr(E);
2228}
2229
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002230void ASTDumper::VisitUnaryOperator(const UnaryOperator *Node) {
Malcolm Parsonsfab36802018-04-16 08:31:08 +00002231 VisitExpr(Node);
2232 OS << " " << (Node->isPostfix() ? "postfix" : "prefix")
2233 << " '" << UnaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
2234 if (!Node->canOverflow())
2235 OS << " cannot overflow";
2236}
2237
2238void ASTDumper::VisitUnaryExprOrTypeTraitExpr(
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002239 const UnaryExprOrTypeTraitExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002240 VisitExpr(Node);
Peter Collingbournee190dee2011-03-11 19:24:49 +00002241 switch(Node->getKind()) {
2242 case UETT_SizeOf:
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002243 OS << " sizeof";
Peter Collingbournee190dee2011-03-11 19:24:49 +00002244 break;
2245 case UETT_AlignOf:
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002246 OS << " alignof";
Peter Collingbournee190dee2011-03-11 19:24:49 +00002247 break;
2248 case UETT_VecStep:
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002249 OS << " vec_step";
Peter Collingbournee190dee2011-03-11 19:24:49 +00002250 break;
Alexey Bataev00396512015-07-02 03:40:19 +00002251 case UETT_OpenMPRequiredSimdAlign:
2252 OS << " __builtin_omp_required_simd_align";
2253 break;
Peter Collingbournee190dee2011-03-11 19:24:49 +00002254 }
Sebastian Redl6f282892008-11-11 17:56:53 +00002255 if (Node->isArgumentType())
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002256 dumpType(Node->getArgumentType());
Chris Lattnercbe4f772007-08-08 22:51:59 +00002257}
Chris Lattnerdb3b3ff2007-08-09 17:35:30 +00002258
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002259void ASTDumper::VisitMemberExpr(const MemberExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002260 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002261 OS << " " << (Node->isArrow() ? "->" : ".") << *Node->getMemberDecl();
2262 dumpPointer(Node->getMemberDecl());
Chris Lattnercbe4f772007-08-08 22:51:59 +00002263}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002264
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002265void ASTDumper::VisitExtVectorElementExpr(const ExtVectorElementExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002266 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002267 OS << " " << Node->getAccessor().getNameStart();
Chris Lattnercbe4f772007-08-08 22:51:59 +00002268}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002269
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002270void ASTDumper::VisitBinaryOperator(const BinaryOperator *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002271 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002272 OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
Chris Lattner86928112007-08-25 02:00:02 +00002273}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002274
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002275void ASTDumper::VisitCompoundAssignOperator(
2276 const CompoundAssignOperator *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002277 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002278 OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode())
2279 << "' ComputeLHSTy=";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002280 dumpBareType(Node->getComputationLHSType());
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002281 OS << " ComputeResultTy=";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002282 dumpBareType(Node->getComputationResultType());
Chris Lattnercbe4f772007-08-08 22:51:59 +00002283}
Chris Lattnercbe4f772007-08-08 22:51:59 +00002284
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002285void ASTDumper::VisitBlockExpr(const BlockExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002286 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002287 dumpDecl(Node->getBlockDecl());
John McCall351762c2011-02-07 10:33:21 +00002288}
2289
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002290void ASTDumper::VisitOpaqueValueExpr(const OpaqueValueExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002291 VisitExpr(Node);
John McCallfe96e0b2011-11-06 09:01:30 +00002292
Richard Smithf7514452014-10-30 21:02:37 +00002293 if (Expr *Source = Node->getSourceExpr())
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002294 dumpStmt(Source);
John McCallfe96e0b2011-11-06 09:01:30 +00002295}
2296
Richard Smith01ccebf2018-01-05 21:31:07 +00002297void ASTDumper::VisitGenericSelectionExpr(const GenericSelectionExpr *E) {
2298 VisitExpr(E);
2299 if (E->isResultDependent())
2300 OS << " result_dependent";
2301 dumpStmt(E->getControllingExpr());
2302 dumpTypeAsChild(E->getControllingExpr()->getType()); // FIXME: remove
2303
2304 for (unsigned I = 0, N = E->getNumAssocs(); I != N; ++I) {
2305 dumpChild([=] {
2306 if (const TypeSourceInfo *TSI = E->getAssocTypeSourceInfo(I)) {
2307 OS << "case ";
2308 dumpType(TSI->getType());
2309 } else {
2310 OS << "default";
2311 }
2312
2313 if (!E->isResultDependent() && E->getResultIndex() == I)
2314 OS << " selected";
2315
2316 if (const TypeSourceInfo *TSI = E->getAssocTypeSourceInfo(I))
2317 dumpTypeAsChild(TSI->getType());
2318 dumpStmt(E->getAssocExpr(I));
2319 });
2320 }
2321}
2322
Chris Lattnercbe4f772007-08-08 22:51:59 +00002323// GNU extensions.
2324
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002325void ASTDumper::VisitAddrLabelExpr(const AddrLabelExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002326 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002327 OS << " " << Node->getLabel()->getName();
2328 dumpPointer(Node->getLabel());
Chris Lattnercbe4f772007-08-08 22:51:59 +00002329}
2330
Chris Lattner8f184b12007-08-09 18:03:18 +00002331//===----------------------------------------------------------------------===//
2332// C++ Expressions
2333//===----------------------------------------------------------------------===//
Chris Lattnercbe4f772007-08-08 22:51:59 +00002334
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002335void ASTDumper::VisitCXXNamedCastExpr(const CXXNamedCastExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002336 VisitExpr(Node);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002337 OS << " " << Node->getCastName()
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002338 << "<" << Node->getTypeAsWritten().getAsString() << ">"
Anders Carlssona70cff62010-04-24 19:06:50 +00002339 << " <" << Node->getCastKindName();
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002340 dumpBasePath(OS, Node);
Anders Carlssona70cff62010-04-24 19:06:50 +00002341 OS << ">";
Chris Lattnercbe4f772007-08-08 22:51:59 +00002342}
2343
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002344void ASTDumper::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002345 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002346 OS << " " << (Node->getValue() ? "true" : "false");
Chris Lattnercbe4f772007-08-08 22:51:59 +00002347}
2348
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002349void ASTDumper::VisitCXXThisExpr(const CXXThisExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002350 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002351 OS << " this";
Douglas Gregor8ea1f532008-11-04 14:56:14 +00002352}
2353
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002354void ASTDumper::VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002355 VisitExpr(Node);
Eli Friedman29538892011-09-02 17:38:59 +00002356 OS << " functional cast to " << Node->getTypeAsWritten().getAsString()
2357 << " <" << Node->getCastKindName() << ">";
Douglas Gregore200adc2008-10-27 19:41:14 +00002358}
2359
Richard Smith39eca9b2017-08-23 22:12:08 +00002360void ASTDumper::VisitCXXUnresolvedConstructExpr(
2361 const CXXUnresolvedConstructExpr *Node) {
2362 VisitExpr(Node);
2363 dumpType(Node->getTypeAsWritten());
2364 if (Node->isListInitialization())
2365 OS << " list";
2366}
2367
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002368void ASTDumper::VisitCXXConstructExpr(const CXXConstructExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002369 VisitExpr(Node);
John McCalleba90cd2010-02-02 19:03:45 +00002370 CXXConstructorDecl *Ctor = Node->getConstructor();
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002371 dumpType(Ctor->getType());
Anders Carlsson073846832009-08-12 00:21:52 +00002372 if (Node->isElidable())
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002373 OS << " elidable";
Richard Smith39eca9b2017-08-23 22:12:08 +00002374 if (Node->isListInitialization())
2375 OS << " list";
2376 if (Node->isStdInitListInitialization())
2377 OS << " std::initializer_list";
John McCall85370042010-08-07 06:38:55 +00002378 if (Node->requiresZeroInitialization())
2379 OS << " zeroing";
Anders Carlsson073846832009-08-12 00:21:52 +00002380}
2381
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002382void ASTDumper::VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002383 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002384 OS << " ";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002385 dumpCXXTemporary(Node->getTemporary());
Anders Carlsson073846832009-08-12 00:21:52 +00002386}
2387
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002388void ASTDumper::VisitCXXNewExpr(const CXXNewExpr *Node) {
2389 VisitExpr(Node);
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002390 if (Node->isGlobalNew())
Reid Kleckner461c0c62015-03-19 18:47:47 +00002391 OS << " global";
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002392 if (Node->isArray())
Reid Kleckner461c0c62015-03-19 18:47:47 +00002393 OS << " array";
2394 if (Node->getOperatorNew()) {
2395 OS << ' ';
2396 dumpBareDeclRef(Node->getOperatorNew());
2397 }
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002398 // We could dump the deallocation function used in case of error, but it's
2399 // usually not that interesting.
2400}
2401
2402void ASTDumper::VisitCXXDeleteExpr(const CXXDeleteExpr *Node) {
2403 VisitExpr(Node);
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002404 if (Node->isGlobalDelete())
Reid Kleckner461c0c62015-03-19 18:47:47 +00002405 OS << " global";
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002406 if (Node->isArrayForm())
Reid Kleckner461c0c62015-03-19 18:47:47 +00002407 OS << " array";
2408 if (Node->getOperatorDelete()) {
2409 OS << ' ';
2410 dumpBareDeclRef(Node->getOperatorDelete());
2411 }
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002412}
2413
Richard Smithe6c01442013-06-05 00:46:14 +00002414void
2415ASTDumper::VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *Node) {
2416 VisitExpr(Node);
2417 if (const ValueDecl *VD = Node->getExtendingDecl()) {
2418 OS << " extended by ";
2419 dumpBareDeclRef(VD);
2420 }
2421}
2422
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002423void ASTDumper::VisitExprWithCleanups(const ExprWithCleanups *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002424 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002425 for (unsigned i = 0, e = Node->getNumObjects(); i != e; ++i)
2426 dumpDeclRef(Node->getObject(i), "cleanup");
Anders Carlsson073846832009-08-12 00:21:52 +00002427}
2428
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002429void ASTDumper::dumpCXXTemporary(const CXXTemporary *Temporary) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002430 OS << "(CXXTemporary";
2431 dumpPointer(Temporary);
2432 OS << ")";
Anders Carlsson073846832009-08-12 00:21:52 +00002433}
2434
Serge Pavlov6b926032015-02-16 19:58:41 +00002435void ASTDumper::VisitSizeOfPackExpr(const SizeOfPackExpr *Node) {
2436 VisitExpr(Node);
2437 dumpPointer(Node->getPack());
2438 dumpName(Node->getPack());
Richard Smithd784e682015-09-23 21:41:42 +00002439 if (Node->isPartiallySubstituted())
2440 for (const auto &A : Node->getPartialArguments())
2441 dumpTemplateArgument(A);
Serge Pavlov6b926032015-02-16 19:58:41 +00002442}
2443
Alex Lorenzddbe0f52016-11-09 14:02:18 +00002444void ASTDumper::VisitCXXDependentScopeMemberExpr(
2445 const CXXDependentScopeMemberExpr *Node) {
2446 VisitExpr(Node);
2447 OS << " " << (Node->isArrow() ? "->" : ".") << Node->getMember();
2448}
Serge Pavlov6b926032015-02-16 19:58:41 +00002449
Anders Carlsson76f4a902007-08-21 17:43:55 +00002450//===----------------------------------------------------------------------===//
2451// Obj-C Expressions
2452//===----------------------------------------------------------------------===//
2453
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002454void ASTDumper::VisitObjCMessageExpr(const ObjCMessageExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002455 VisitExpr(Node);
Aaron Ballmanb190f972014-01-03 17:59:55 +00002456 OS << " selector=";
2457 Node->getSelector().print(OS);
Douglas Gregor9a129192010-04-21 00:45:42 +00002458 switch (Node->getReceiverKind()) {
2459 case ObjCMessageExpr::Instance:
2460 break;
2461
2462 case ObjCMessageExpr::Class:
2463 OS << " class=";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002464 dumpBareType(Node->getClassReceiver());
Douglas Gregor9a129192010-04-21 00:45:42 +00002465 break;
2466
2467 case ObjCMessageExpr::SuperInstance:
2468 OS << " super (instance)";
2469 break;
2470
2471 case ObjCMessageExpr::SuperClass:
2472 OS << " super (class)";
2473 break;
2474 }
Ted Kremenek36748da2008-02-29 22:04:05 +00002475}
2476
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002477void ASTDumper::VisitObjCBoxedExpr(const ObjCBoxedExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002478 VisitExpr(Node);
Richard Trieu4b259c82016-06-09 22:03:04 +00002479 if (auto *BoxingMethod = Node->getBoxingMethod()) {
2480 OS << " selector=";
2481 BoxingMethod->getSelector().print(OS);
2482 }
Argyrios Kyrtzidis9dd40892012-05-10 20:02:31 +00002483}
2484
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002485void ASTDumper::VisitObjCAtCatchStmt(const ObjCAtCatchStmt *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002486 VisitStmt(Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002487 if (const VarDecl *CatchParam = Node->getCatchParamDecl())
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002488 dumpDecl(CatchParam);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002489 else
Douglas Gregor96c79492010-04-23 22:50:49 +00002490 OS << " catch all";
Douglas Gregor96c79492010-04-23 22:50:49 +00002491}
2492
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002493void ASTDumper::VisitObjCEncodeExpr(const ObjCEncodeExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002494 VisitExpr(Node);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002495 dumpType(Node->getEncodedType());
Anders Carlssonc5a81eb2007-08-22 15:14:15 +00002496}
2497
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002498void ASTDumper::VisitObjCSelectorExpr(const ObjCSelectorExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002499 VisitExpr(Node);
Mike Stump11289f42009-09-09 15:08:12 +00002500
Aaron Ballmanb190f972014-01-03 17:59:55 +00002501 OS << " ";
2502 Node->getSelector().print(OS);
Fariborz Jahanian4bef4622007-10-16 20:40:23 +00002503}
2504
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002505void ASTDumper::VisitObjCProtocolExpr(const ObjCProtocolExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002506 VisitExpr(Node);
Mike Stump11289f42009-09-09 15:08:12 +00002507
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002508 OS << ' ' << *Node->getProtocol();
Fariborz Jahaniana32aaef2007-10-17 16:58:11 +00002509}
Daniel Dunbar4b8c6db2008-08-30 05:35:15 +00002510
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002511void ASTDumper::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002512 VisitExpr(Node);
John McCallb7bd14f2010-12-02 01:19:52 +00002513 if (Node->isImplicitProperty()) {
Fariborz Jahanian0f0b3022010-12-22 19:46:35 +00002514 OS << " Kind=MethodRef Getter=\"";
2515 if (Node->getImplicitPropertyGetter())
Aaron Ballmanb190f972014-01-03 17:59:55 +00002516 Node->getImplicitPropertyGetter()->getSelector().print(OS);
Fariborz Jahanian0f0b3022010-12-22 19:46:35 +00002517 else
2518 OS << "(null)";
2519
2520 OS << "\" Setter=\"";
John McCallb7bd14f2010-12-02 01:19:52 +00002521 if (ObjCMethodDecl *Setter = Node->getImplicitPropertySetter())
Aaron Ballmanb190f972014-01-03 17:59:55 +00002522 Setter->getSelector().print(OS);
John McCallb7bd14f2010-12-02 01:19:52 +00002523 else
2524 OS << "(null)";
2525 OS << "\"";
2526 } else {
Benjamin Kramerb89514a2011-10-14 18:45:37 +00002527 OS << " Kind=PropertyRef Property=\"" << *Node->getExplicitProperty() <<'"';
John McCallb7bd14f2010-12-02 01:19:52 +00002528 }
Fariborz Jahanian8a1810f2008-11-22 18:39:36 +00002529
Fariborz Jahanian681c0752010-10-14 16:04:05 +00002530 if (Node->isSuperReceiver())
2531 OS << " super";
Argyrios Kyrtzidisab468b02012-03-30 00:19:18 +00002532
2533 OS << " Messaging=";
2534 if (Node->isMessagingGetter() && Node->isMessagingSetter())
2535 OS << "Getter&Setter";
2536 else if (Node->isMessagingGetter())
2537 OS << "Getter";
2538 else if (Node->isMessagingSetter())
2539 OS << "Setter";
Douglas Gregor8ea1f532008-11-04 14:56:14 +00002540}
2541
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002542void ASTDumper::VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002543 VisitExpr(Node);
Ted Kremeneke65b0862012-03-06 20:05:56 +00002544 if (Node->isArraySubscriptRefExpr())
2545 OS << " Kind=ArraySubscript GetterForArray=\"";
2546 else
2547 OS << " Kind=DictionarySubscript GetterForDictionary=\"";
2548 if (Node->getAtIndexMethodDecl())
Aaron Ballmanb190f972014-01-03 17:59:55 +00002549 Node->getAtIndexMethodDecl()->getSelector().print(OS);
Ted Kremeneke65b0862012-03-06 20:05:56 +00002550 else
2551 OS << "(null)";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002552
Ted Kremeneke65b0862012-03-06 20:05:56 +00002553 if (Node->isArraySubscriptRefExpr())
2554 OS << "\" SetterForArray=\"";
2555 else
2556 OS << "\" SetterForDictionary=\"";
2557 if (Node->setAtIndexMethodDecl())
Aaron Ballmanb190f972014-01-03 17:59:55 +00002558 Node->setAtIndexMethodDecl()->getSelector().print(OS);
Ted Kremeneke65b0862012-03-06 20:05:56 +00002559 else
2560 OS << "(null)";
2561}
2562
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002563void ASTDumper::VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002564 VisitExpr(Node);
Ted Kremeneke65b0862012-03-06 20:05:56 +00002565 OS << " " << (Node->getValue() ? "__objc_yes" : "__objc_no");
2566}
2567
Chris Lattnercbe4f772007-08-08 22:51:59 +00002568//===----------------------------------------------------------------------===//
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002569// Comments
2570//===----------------------------------------------------------------------===//
2571
2572const char *ASTDumper::getCommandName(unsigned CommandID) {
2573 if (Traits)
2574 return Traits->getCommandInfo(CommandID)->Name;
2575 const CommandInfo *Info = CommandTraits::getBuiltinCommandInfo(CommandID);
2576 if (Info)
2577 return Info->Name;
2578 return "<not a builtin command>";
2579}
2580
2581void ASTDumper::dumpFullComment(const FullComment *C) {
2582 if (!C)
2583 return;
2584
2585 FC = C;
2586 dumpComment(C);
Craig Topper36250ad2014-05-12 05:36:57 +00002587 FC = nullptr;
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002588}
2589
2590void ASTDumper::dumpComment(const Comment *C) {
Richard Smithf7514452014-10-30 21:02:37 +00002591 dumpChild([=] {
2592 if (!C) {
2593 ColorScope Color(*this, NullColor);
2594 OS << "<<<NULL>>>";
2595 return;
2596 }
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002597
Richard Smithf7514452014-10-30 21:02:37 +00002598 {
2599 ColorScope Color(*this, CommentColor);
2600 OS << C->getCommentKindName();
2601 }
2602 dumpPointer(C);
2603 dumpSourceRange(C->getSourceRange());
2604 ConstCommentVisitor<ASTDumper>::visit(C);
2605 for (Comment::child_iterator I = C->child_begin(), E = C->child_end();
2606 I != E; ++I)
2607 dumpComment(*I);
2608 });
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002609}
2610
2611void ASTDumper::visitTextComment(const TextComment *C) {
2612 OS << " Text=\"" << C->getText() << "\"";
2613}
2614
2615void ASTDumper::visitInlineCommandComment(const InlineCommandComment *C) {
2616 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\"";
2617 switch (C->getRenderKind()) {
2618 case InlineCommandComment::RenderNormal:
2619 OS << " RenderNormal";
2620 break;
2621 case InlineCommandComment::RenderBold:
2622 OS << " RenderBold";
2623 break;
2624 case InlineCommandComment::RenderMonospaced:
2625 OS << " RenderMonospaced";
2626 break;
2627 case InlineCommandComment::RenderEmphasized:
2628 OS << " RenderEmphasized";
2629 break;
2630 }
2631
2632 for (unsigned i = 0, e = C->getNumArgs(); i != e; ++i)
2633 OS << " Arg[" << i << "]=\"" << C->getArgText(i) << "\"";
2634}
2635
2636void ASTDumper::visitHTMLStartTagComment(const HTMLStartTagComment *C) {
2637 OS << " Name=\"" << C->getTagName() << "\"";
2638 if (C->getNumAttrs() != 0) {
2639 OS << " Attrs: ";
2640 for (unsigned i = 0, e = C->getNumAttrs(); i != e; ++i) {
2641 const HTMLStartTagComment::Attribute &Attr = C->getAttr(i);
2642 OS << " \"" << Attr.Name << "=\"" << Attr.Value << "\"";
2643 }
2644 }
2645 if (C->isSelfClosing())
2646 OS << " SelfClosing";
2647}
2648
2649void ASTDumper::visitHTMLEndTagComment(const HTMLEndTagComment *C) {
2650 OS << " Name=\"" << C->getTagName() << "\"";
2651}
2652
2653void ASTDumper::visitBlockCommandComment(const BlockCommandComment *C) {
2654 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\"";
2655 for (unsigned i = 0, e = C->getNumArgs(); i != e; ++i)
2656 OS << " Arg[" << i << "]=\"" << C->getArgText(i) << "\"";
2657}
2658
2659void ASTDumper::visitParamCommandComment(const ParamCommandComment *C) {
2660 OS << " " << ParamCommandComment::getDirectionAsString(C->getDirection());
2661
2662 if (C->isDirectionExplicit())
2663 OS << " explicitly";
2664 else
2665 OS << " implicitly";
2666
2667 if (C->hasParamName()) {
2668 if (C->isParamIndexValid())
2669 OS << " Param=\"" << C->getParamName(FC) << "\"";
2670 else
2671 OS << " Param=\"" << C->getParamNameAsWritten() << "\"";
2672 }
2673
Dmitri Gribenkodbff5c72014-03-19 14:03:47 +00002674 if (C->isParamIndexValid() && !C->isVarArgParam())
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002675 OS << " ParamIndex=" << C->getParamIndex();
2676}
2677
2678void ASTDumper::visitTParamCommandComment(const TParamCommandComment *C) {
2679 if (C->hasParamName()) {
2680 if (C->isPositionValid())
2681 OS << " Param=\"" << C->getParamName(FC) << "\"";
2682 else
2683 OS << " Param=\"" << C->getParamNameAsWritten() << "\"";
2684 }
2685
2686 if (C->isPositionValid()) {
2687 OS << " Position=<";
2688 for (unsigned i = 0, e = C->getDepth(); i != e; ++i) {
2689 OS << C->getIndex(i);
2690 if (i != e - 1)
2691 OS << ", ";
2692 }
2693 OS << ">";
2694 }
2695}
2696
2697void ASTDumper::visitVerbatimBlockComment(const VerbatimBlockComment *C) {
2698 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\""
2699 " CloseName=\"" << C->getCloseName() << "\"";
2700}
2701
2702void ASTDumper::visitVerbatimBlockLineComment(
2703 const VerbatimBlockLineComment *C) {
2704 OS << " Text=\"" << C->getText() << "\"";
2705}
2706
2707void ASTDumper::visitVerbatimLineComment(const VerbatimLineComment *C) {
2708 OS << " Text=\"" << C->getText() << "\"";
2709}
2710
2711//===----------------------------------------------------------------------===//
Richard Smithd5e7ff82014-10-31 01:17:45 +00002712// Type method implementations
2713//===----------------------------------------------------------------------===//
2714
2715void QualType::dump(const char *msg) const {
2716 if (msg)
2717 llvm::errs() << msg << ": ";
2718 dump();
2719}
2720
Richard Smith14d04842016-11-02 23:57:18 +00002721LLVM_DUMP_METHOD void QualType::dump() const { dump(llvm::errs()); }
2722
2723LLVM_DUMP_METHOD void QualType::dump(llvm::raw_ostream &OS) const {
2724 ASTDumper Dumper(OS, nullptr, nullptr);
Richard Smithd5e7ff82014-10-31 01:17:45 +00002725 Dumper.dumpTypeAsChild(*this);
2726}
2727
Richard Smith14d04842016-11-02 23:57:18 +00002728LLVM_DUMP_METHOD void Type::dump() const { dump(llvm::errs()); }
2729
2730LLVM_DUMP_METHOD void Type::dump(llvm::raw_ostream &OS) const {
2731 QualType(this, 0).dump(OS);
2732}
Richard Smithd5e7ff82014-10-31 01:17:45 +00002733
2734//===----------------------------------------------------------------------===//
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002735// Decl method implementations
2736//===----------------------------------------------------------------------===//
2737
Alp Tokeref6b0072014-01-04 13:47:14 +00002738LLVM_DUMP_METHOD void Decl::dump() const { dump(llvm::errs()); }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002739
Richard Smith3a36ac12017-03-09 22:00:01 +00002740LLVM_DUMP_METHOD void Decl::dump(raw_ostream &OS, bool Deserialize) const {
Aaron Ballman8c208282017-12-21 21:42:42 +00002741 const ASTContext &Ctx = getASTContext();
2742 const SourceManager &SM = Ctx.getSourceManager();
2743 ASTDumper P(OS, &Ctx.getCommentCommandTraits(), &SM,
2744 SM.getDiagnostics().getShowColors(), Ctx.getPrintingPolicy());
Richard Smith3a36ac12017-03-09 22:00:01 +00002745 P.setDeserialize(Deserialize);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002746 P.dumpDecl(this);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002747}
2748
Alp Tokeref6b0072014-01-04 13:47:14 +00002749LLVM_DUMP_METHOD void Decl::dumpColor() const {
Aaron Ballman8c208282017-12-21 21:42:42 +00002750 const ASTContext &Ctx = getASTContext();
2751 ASTDumper P(llvm::errs(), &Ctx.getCommentCommandTraits(),
2752 &Ctx.getSourceManager(), /*ShowColors*/ true,
2753 Ctx.getPrintingPolicy());
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002754 P.dumpDecl(this);
Richard Trieud215b8d2013-01-26 01:31:20 +00002755}
Richard Smith33937e72013-06-22 21:49:40 +00002756
Alp Tokeref6b0072014-01-04 13:47:14 +00002757LLVM_DUMP_METHOD void DeclContext::dumpLookups() const {
Richard Smith6ea05822013-06-24 01:45:33 +00002758 dumpLookups(llvm::errs());
2759}
2760
Richard Smith35f986d2014-08-11 22:11:07 +00002761LLVM_DUMP_METHOD void DeclContext::dumpLookups(raw_ostream &OS,
Richard Smith3a36ac12017-03-09 22:00:01 +00002762 bool DumpDecls,
2763 bool Deserialize) const {
Richard Smith33937e72013-06-22 21:49:40 +00002764 const DeclContext *DC = this;
2765 while (!DC->isTranslationUnit())
2766 DC = DC->getParent();
2767 ASTContext &Ctx = cast<TranslationUnitDecl>(DC)->getASTContext();
Aaron Ballman8c208282017-12-21 21:42:42 +00002768 const SourceManager &SM = Ctx.getSourceManager();
2769 ASTDumper P(OS, &Ctx.getCommentCommandTraits(), &Ctx.getSourceManager(),
2770 SM.getDiagnostics().getShowColors(), Ctx.getPrintingPolicy());
Richard Smith3a36ac12017-03-09 22:00:01 +00002771 P.setDeserialize(Deserialize);
Richard Smith35f986d2014-08-11 22:11:07 +00002772 P.dumpLookups(this, DumpDecls);
Richard Smith33937e72013-06-22 21:49:40 +00002773}
2774
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002775//===----------------------------------------------------------------------===//
Chris Lattnercbe4f772007-08-08 22:51:59 +00002776// Stmt method implementations
2777//===----------------------------------------------------------------------===//
2778
Alp Tokeref6b0072014-01-04 13:47:14 +00002779LLVM_DUMP_METHOD void Stmt::dump(SourceManager &SM) const {
Argyrios Kyrtzidisc049f752010-08-09 10:54:31 +00002780 dump(llvm::errs(), SM);
2781}
2782
Alp Tokeref6b0072014-01-04 13:47:14 +00002783LLVM_DUMP_METHOD void Stmt::dump(raw_ostream &OS, SourceManager &SM) const {
Craig Topper36250ad2014-05-12 05:36:57 +00002784 ASTDumper P(OS, nullptr, &SM);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002785 P.dumpStmt(this);
Chris Lattner779d5d92007-08-30 00:40:08 +00002786}
2787
Faisal Vali2da8ed92015-03-22 13:35:56 +00002788LLVM_DUMP_METHOD void Stmt::dump(raw_ostream &OS) const {
2789 ASTDumper P(OS, nullptr, nullptr);
2790 P.dumpStmt(this);
2791}
2792
Alp Tokeref6b0072014-01-04 13:47:14 +00002793LLVM_DUMP_METHOD void Stmt::dump() const {
Craig Topper36250ad2014-05-12 05:36:57 +00002794 ASTDumper P(llvm::errs(), nullptr, nullptr);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002795 P.dumpStmt(this);
Chris Lattnercbe4f772007-08-08 22:51:59 +00002796}
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002797
Alp Tokeref6b0072014-01-04 13:47:14 +00002798LLVM_DUMP_METHOD void Stmt::dumpColor() const {
Craig Topper36250ad2014-05-12 05:36:57 +00002799 ASTDumper P(llvm::errs(), nullptr, nullptr, /*ShowColors*/true);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002800 P.dumpStmt(this);
Richard Trieud215b8d2013-01-26 01:31:20 +00002801}
2802
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002803//===----------------------------------------------------------------------===//
2804// Comment method implementations
2805//===----------------------------------------------------------------------===//
2806
Craig Topper36250ad2014-05-12 05:36:57 +00002807LLVM_DUMP_METHOD void Comment::dump() const {
2808 dump(llvm::errs(), nullptr, nullptr);
2809}
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002810
Alp Tokeref6b0072014-01-04 13:47:14 +00002811LLVM_DUMP_METHOD void Comment::dump(const ASTContext &Context) const {
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002812 dump(llvm::errs(), &Context.getCommentCommandTraits(),
2813 &Context.getSourceManager());
2814}
2815
Alexander Kornienko00911f12013-01-15 12:20:21 +00002816void Comment::dump(raw_ostream &OS, const CommandTraits *Traits,
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002817 const SourceManager *SM) const {
2818 const FullComment *FC = dyn_cast<FullComment>(this);
2819 ASTDumper D(OS, Traits, SM);
2820 D.dumpFullComment(FC);
2821}
Richard Trieud215b8d2013-01-26 01:31:20 +00002822
Alp Tokeref6b0072014-01-04 13:47:14 +00002823LLVM_DUMP_METHOD void Comment::dumpColor() const {
Richard Trieud215b8d2013-01-26 01:31:20 +00002824 const FullComment *FC = dyn_cast<FullComment>(this);
Craig Topper36250ad2014-05-12 05:36:57 +00002825 ASTDumper D(llvm::errs(), nullptr, nullptr, /*ShowColors*/true);
Richard Trieud215b8d2013-01-26 01:31:20 +00002826 D.dumpFullComment(FC);
2827}