blob: 0ac29087d6e3fdb8fb7baf5fcbfe7b805b277bbd [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);
524 void VisitDeclRefExpr(const DeclRefExpr *Node);
525 void VisitPredefinedExpr(const PredefinedExpr *Node);
526 void VisitCharacterLiteral(const CharacterLiteral *Node);
527 void VisitIntegerLiteral(const IntegerLiteral *Node);
528 void VisitFloatingLiteral(const FloatingLiteral *Node);
529 void VisitStringLiteral(const StringLiteral *Str);
Richard Smithf0514962014-06-03 08:24:28 +0000530 void VisitInitListExpr(const InitListExpr *ILE);
Richard Smith410306b2016-12-12 02:53:20 +0000531 void VisitArrayInitLoopExpr(const ArrayInitLoopExpr *ILE);
532 void VisitArrayInitIndexExpr(const ArrayInitIndexExpr *ILE);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000533 void VisitUnaryOperator(const UnaryOperator *Node);
534 void VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *Node);
535 void VisitMemberExpr(const MemberExpr *Node);
536 void VisitExtVectorElementExpr(const ExtVectorElementExpr *Node);
537 void VisitBinaryOperator(const BinaryOperator *Node);
538 void VisitCompoundAssignOperator(const CompoundAssignOperator *Node);
539 void VisitAddrLabelExpr(const AddrLabelExpr *Node);
540 void VisitBlockExpr(const BlockExpr *Node);
541 void VisitOpaqueValueExpr(const OpaqueValueExpr *Node);
Richard Smith01ccebf2018-01-05 21:31:07 +0000542 void VisitGenericSelectionExpr(const GenericSelectionExpr *E);
Chris Lattner84ca3762007-08-30 01:00:35 +0000543
544 // C++
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000545 void VisitCXXNamedCastExpr(const CXXNamedCastExpr *Node);
546 void VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *Node);
547 void VisitCXXThisExpr(const CXXThisExpr *Node);
548 void VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *Node);
Richard Smith39eca9b2017-08-23 22:12:08 +0000549 void VisitCXXUnresolvedConstructExpr(const CXXUnresolvedConstructExpr *Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000550 void VisitCXXConstructExpr(const CXXConstructExpr *Node);
551 void VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *Node);
Reid Kleckner5c682bc2015-03-19 18:09:25 +0000552 void VisitCXXNewExpr(const CXXNewExpr *Node);
553 void VisitCXXDeleteExpr(const CXXDeleteExpr *Node);
Richard Smithe6c01442013-06-05 00:46:14 +0000554 void VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000555 void VisitExprWithCleanups(const ExprWithCleanups *Node);
556 void VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *Node);
557 void dumpCXXTemporary(const CXXTemporary *Temporary);
Faisal Vali2b391ab2013-09-26 19:54:12 +0000558 void VisitLambdaExpr(const LambdaExpr *Node) {
559 VisitExpr(Node);
560 dumpDecl(Node->getLambdaClass());
561 }
Serge Pavlov6b926032015-02-16 19:58:41 +0000562 void VisitSizeOfPackExpr(const SizeOfPackExpr *Node);
Alex Lorenzddbe0f52016-11-09 14:02:18 +0000563 void
564 VisitCXXDependentScopeMemberExpr(const CXXDependentScopeMemberExpr *Node);
Mike Stump11289f42009-09-09 15:08:12 +0000565
Chris Lattner84ca3762007-08-30 01:00:35 +0000566 // ObjC
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000567 void VisitObjCAtCatchStmt(const ObjCAtCatchStmt *Node);
568 void VisitObjCEncodeExpr(const ObjCEncodeExpr *Node);
569 void VisitObjCMessageExpr(const ObjCMessageExpr *Node);
570 void VisitObjCBoxedExpr(const ObjCBoxedExpr *Node);
571 void VisitObjCSelectorExpr(const ObjCSelectorExpr *Node);
572 void VisitObjCProtocolExpr(const ObjCProtocolExpr *Node);
573 void VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *Node);
574 void VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *Node);
575 void VisitObjCIvarRefExpr(const ObjCIvarRefExpr *Node);
576 void VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *Node);
Alexander Kornienkoebc17b52013-01-14 14:07:11 +0000577
578 // Comments.
579 const char *getCommandName(unsigned CommandID);
580 void dumpComment(const Comment *C);
581
582 // Inline comments.
583 void visitTextComment(const TextComment *C);
584 void visitInlineCommandComment(const InlineCommandComment *C);
585 void visitHTMLStartTagComment(const HTMLStartTagComment *C);
586 void visitHTMLEndTagComment(const HTMLEndTagComment *C);
587
588 // Block comments.
589 void visitBlockCommandComment(const BlockCommandComment *C);
590 void visitParamCommandComment(const ParamCommandComment *C);
591 void visitTParamCommandComment(const TParamCommandComment *C);
592 void visitVerbatimBlockComment(const VerbatimBlockComment *C);
593 void visitVerbatimBlockLineComment(const VerbatimBlockLineComment *C);
594 void visitVerbatimLineComment(const VerbatimLineComment *C);
Chris Lattnercbe4f772007-08-08 22:51:59 +0000595 };
Alexander Kornienkoab9db512015-06-22 23:07:51 +0000596}
Chris Lattnercbe4f772007-08-08 22:51:59 +0000597
598//===----------------------------------------------------------------------===//
Chris Lattner11e30d32007-08-30 06:17:34 +0000599// Utilities
600//===----------------------------------------------------------------------===//
601
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000602void ASTDumper::dumpPointer(const void *Ptr) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000603 ColorScope Color(*this, AddressColor);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000604 OS << ' ' << Ptr;
605}
606
Alexander Kornienko18ec81b2012-12-13 13:59:55 +0000607void ASTDumper::dumpLocation(SourceLocation Loc) {
Alex McCarthye14ddef2014-05-02 20:24:11 +0000608 if (!SM)
609 return;
610
Richard Trieud215b8d2013-01-26 01:31:20 +0000611 ColorScope Color(*this, LocationColor);
Chris Lattner53e384f2009-01-16 07:00:02 +0000612 SourceLocation SpellingLoc = SM->getSpellingLoc(Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000613
Chris Lattner11e30d32007-08-30 06:17:34 +0000614 // The general format we print out is filename:line:col, but we drop pieces
615 // that haven't changed since the last loc printed.
Chris Lattnerf1ca7d32009-01-27 07:57:44 +0000616 PresumedLoc PLoc = SM->getPresumedLoc(SpellingLoc);
617
Douglas Gregor453b0122010-11-12 07:15:47 +0000618 if (PLoc.isInvalid()) {
619 OS << "<invalid sloc>";
620 return;
621 }
622
Chris Lattnerf1ca7d32009-01-27 07:57:44 +0000623 if (strcmp(PLoc.getFilename(), LastLocFilename) != 0) {
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000624 OS << PLoc.getFilename() << ':' << PLoc.getLine()
625 << ':' << PLoc.getColumn();
Chris Lattnerf1ca7d32009-01-27 07:57:44 +0000626 LastLocFilename = PLoc.getFilename();
627 LastLocLine = PLoc.getLine();
628 } else if (PLoc.getLine() != LastLocLine) {
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000629 OS << "line" << ':' << PLoc.getLine()
630 << ':' << PLoc.getColumn();
Chris Lattnerf1ca7d32009-01-27 07:57:44 +0000631 LastLocLine = PLoc.getLine();
Chris Lattner11e30d32007-08-30 06:17:34 +0000632 } else {
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000633 OS << "col" << ':' << PLoc.getColumn();
Chris Lattner11e30d32007-08-30 06:17:34 +0000634 }
635}
636
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000637void ASTDumper::dumpSourceRange(SourceRange R) {
Chris Lattner11e30d32007-08-30 06:17:34 +0000638 // Can't translate locations if a SourceManager isn't available.
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000639 if (!SM)
640 return;
Mike Stump11289f42009-09-09 15:08:12 +0000641
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000642 OS << " <";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000643 dumpLocation(R.getBegin());
Chris Lattnera7c19fe2007-10-16 22:36:42 +0000644 if (R.getBegin() != R.getEnd()) {
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000645 OS << ", ";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000646 dumpLocation(R.getEnd());
Chris Lattner11e30d32007-08-30 06:17:34 +0000647 }
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000648 OS << ">";
Mike Stump11289f42009-09-09 15:08:12 +0000649
Chris Lattner11e30d32007-08-30 06:17:34 +0000650 // <t2.c:123:421[blah], t2.c:412:321>
651
652}
653
Richard Smithd5e7ff82014-10-31 01:17:45 +0000654void ASTDumper::dumpBareType(QualType T, bool Desugar) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000655 ColorScope Color(*this, TypeColor);
Richard Smithd5e7ff82014-10-31 01:17:45 +0000656
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000657 SplitQualType T_split = T.split();
Aaron Ballman8c208282017-12-21 21:42:42 +0000658 OS << "'" << QualType::getAsString(T_split, PrintPolicy) << "'";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000659
Richard Smithd5e7ff82014-10-31 01:17:45 +0000660 if (Desugar && !T.isNull()) {
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000661 // If the type is sugared, also dump a (shallow) desugared type.
662 SplitQualType D_split = T.getSplitDesugaredType();
663 if (T_split != D_split)
Aaron Ballman8c208282017-12-21 21:42:42 +0000664 OS << ":'" << QualType::getAsString(D_split, PrintPolicy) << "'";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000665 }
666}
667
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000668void ASTDumper::dumpType(QualType T) {
669 OS << ' ';
670 dumpBareType(T);
671}
672
Richard Smithd5e7ff82014-10-31 01:17:45 +0000673void ASTDumper::dumpTypeAsChild(QualType T) {
674 SplitQualType SQT = T.split();
675 if (!SQT.Quals.hasQualifiers())
676 return dumpTypeAsChild(SQT.Ty);
677
678 dumpChild([=] {
679 OS << "QualType";
680 dumpPointer(T.getAsOpaquePtr());
681 OS << " ";
682 dumpBareType(T, false);
683 OS << " " << T.split().Quals.getAsString();
684 dumpTypeAsChild(T.split().Ty);
685 });
686}
687
688void ASTDumper::dumpTypeAsChild(const Type *T) {
689 dumpChild([=] {
690 if (!T) {
691 ColorScope Color(*this, NullColor);
692 OS << "<<<NULL>>>";
693 return;
694 }
Serge Pavlova6adc9e2015-12-28 17:19:12 +0000695 if (const LocInfoType *LIT = llvm::dyn_cast<LocInfoType>(T)) {
696 {
697 ColorScope Color(*this, TypeColor);
698 OS << "LocInfo Type";
699 }
700 dumpPointer(T);
701 dumpTypeAsChild(LIT->getTypeSourceInfo()->getType());
702 return;
703 }
Richard Smithd5e7ff82014-10-31 01:17:45 +0000704
705 {
706 ColorScope Color(*this, TypeColor);
707 OS << T->getTypeClassName() << "Type";
708 }
709 dumpPointer(T);
710 OS << " ";
711 dumpBareType(QualType(T, 0), false);
712
713 QualType SingleStepDesugar =
714 T->getLocallyUnqualifiedSingleStepDesugaredType();
715 if (SingleStepDesugar != QualType(T, 0))
716 OS << " sugar";
717 if (T->isDependentType())
718 OS << " dependent";
719 else if (T->isInstantiationDependentType())
720 OS << " instantiation_dependent";
721 if (T->isVariablyModifiedType())
722 OS << " variably_modified";
723 if (T->containsUnexpandedParameterPack())
724 OS << " contains_unexpanded_pack";
725 if (T->isFromAST())
726 OS << " imported";
727
728 TypeVisitor<ASTDumper>::Visit(T);
729
730 if (SingleStepDesugar != QualType(T, 0))
731 dumpTypeAsChild(SingleStepDesugar);
732 });
733}
734
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000735void ASTDumper::dumpBareDeclRef(const Decl *D) {
Richard Smith5179eb72016-06-28 19:03:57 +0000736 if (!D) {
737 ColorScope Color(*this, NullColor);
738 OS << "<<<NULL>>>";
739 return;
740 }
741
Richard Trieud215b8d2013-01-26 01:31:20 +0000742 {
743 ColorScope Color(*this, DeclKindNameColor);
744 OS << D->getDeclKindName();
745 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000746 dumpPointer(D);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000747
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000748 if (const NamedDecl *ND = dyn_cast<NamedDecl>(D)) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000749 ColorScope Color(*this, DeclNameColor);
David Blaikied4da8722013-05-14 21:04:00 +0000750 OS << " '" << ND->getDeclName() << '\'';
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000751 }
752
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000753 if (const ValueDecl *VD = dyn_cast<ValueDecl>(D))
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000754 dumpType(VD->getType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000755}
756
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000757void ASTDumper::dumpDeclRef(const Decl *D, const char *Label) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000758 if (!D)
759 return;
760
Richard Smithf7514452014-10-30 21:02:37 +0000761 dumpChild([=]{
762 if (Label)
763 OS << Label << ' ';
764 dumpBareDeclRef(D);
765 });
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000766}
767
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000768void ASTDumper::dumpName(const NamedDecl *ND) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000769 if (ND->getDeclName()) {
770 ColorScope Color(*this, DeclNameColor);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000771 OS << ' ' << ND->getNameAsString();
Richard Trieud215b8d2013-01-26 01:31:20 +0000772 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000773}
774
Richard Trieude5cc7d2013-01-31 01:44:26 +0000775bool ASTDumper::hasNodes(const DeclContext *DC) {
776 if (!DC)
777 return false;
778
Richard Smith1d209d02013-05-23 01:49:11 +0000779 return DC->hasExternalLexicalStorage() ||
Richard Smith3a36ac12017-03-09 22:00:01 +0000780 (Deserialize ? DC->decls_begin() != DC->decls_end()
781 : DC->noload_decls_begin() != DC->noload_decls_end());
Richard Trieude5cc7d2013-01-31 01:44:26 +0000782}
783
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000784void ASTDumper::dumpDeclContext(const DeclContext *DC) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000785 if (!DC)
786 return;
Richard Smithdcc2c452014-03-17 23:00:06 +0000787
Richard Smith3a36ac12017-03-09 22:00:01 +0000788 for (auto *D : (Deserialize ? DC->decls() : DC->noload_decls()))
Richard Smithf7514452014-10-30 21:02:37 +0000789 dumpDecl(D);
Richard Smithdcc2c452014-03-17 23:00:06 +0000790
791 if (DC->hasExternalLexicalStorage()) {
Richard Smithf7514452014-10-30 21:02:37 +0000792 dumpChild([=]{
793 ColorScope Color(*this, UndeserializedColor);
794 OS << "<undeserialized declarations>";
795 });
Richard Smith1d209d02013-05-23 01:49:11 +0000796 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000797}
798
Richard Smith35f986d2014-08-11 22:11:07 +0000799void ASTDumper::dumpLookups(const DeclContext *DC, bool DumpDecls) {
Richard Smithf7514452014-10-30 21:02:37 +0000800 dumpChild([=] {
801 OS << "StoredDeclsMap ";
802 dumpBareDeclRef(cast<Decl>(DC));
Richard Smith33937e72013-06-22 21:49:40 +0000803
Richard Smithf7514452014-10-30 21:02:37 +0000804 const DeclContext *Primary = DC->getPrimaryContext();
805 if (Primary != DC) {
806 OS << " primary";
807 dumpPointer(cast<Decl>(Primary));
Richard Smith33937e72013-06-22 21:49:40 +0000808 }
809
Richard Smithf7514452014-10-30 21:02:37 +0000810 bool HasUndeserializedLookups = Primary->hasExternalVisibleStorage();
Richard Smith35f986d2014-08-11 22:11:07 +0000811
Sam McCall091b1ef2018-01-16 12:33:46 +0000812 auto Range = Deserialize
813 ? Primary->lookups()
814 : Primary->noload_lookups(/*PreserveInternalState=*/true);
815 for (auto I = Range.begin(), E = Range.end(); I != E; ++I) {
Richard Smithf7514452014-10-30 21:02:37 +0000816 DeclarationName Name = I.getLookupName();
Richard Smith3a36ac12017-03-09 22:00:01 +0000817 DeclContextLookupResult R = *I;
Richard Smith35f986d2014-08-11 22:11:07 +0000818
Richard Smithf7514452014-10-30 21:02:37 +0000819 dumpChild([=] {
820 OS << "DeclarationName ";
821 {
822 ColorScope Color(*this, DeclNameColor);
823 OS << '\'' << Name << '\'';
824 }
Richard Smith35f986d2014-08-11 22:11:07 +0000825
Richard Smithf7514452014-10-30 21:02:37 +0000826 for (DeclContextLookupResult::iterator RI = R.begin(), RE = R.end();
827 RI != RE; ++RI) {
828 dumpChild([=] {
829 dumpBareDeclRef(*RI);
830
831 if ((*RI)->isHidden())
832 OS << " hidden";
833
834 // If requested, dump the redecl chain for this lookup.
835 if (DumpDecls) {
836 // Dump earliest decl first.
837 std::function<void(Decl *)> DumpWithPrev = [&](Decl *D) {
838 if (Decl *Prev = D->getPreviousDecl())
839 DumpWithPrev(Prev);
840 dumpDecl(D);
841 };
842 DumpWithPrev(*RI);
843 }
844 });
845 }
846 });
Richard Smith33937e72013-06-22 21:49:40 +0000847 }
Richard Smith33937e72013-06-22 21:49:40 +0000848
Richard Smithf7514452014-10-30 21:02:37 +0000849 if (HasUndeserializedLookups) {
850 dumpChild([=] {
851 ColorScope Color(*this, UndeserializedColor);
852 OS << "<undeserialized lookups>";
853 });
854 }
855 });
Richard Smith33937e72013-06-22 21:49:40 +0000856}
857
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000858void ASTDumper::dumpAttr(const Attr *A) {
Richard Smithf7514452014-10-30 21:02:37 +0000859 dumpChild([=] {
860 {
861 ColorScope Color(*this, AttrColor);
Aaron Ballman36a53502014-01-16 13:03:14 +0000862
Richard Smithf7514452014-10-30 21:02:37 +0000863 switch (A->getKind()) {
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000864#define ATTR(X) case attr::X: OS << #X; break;
865#include "clang/Basic/AttrList.inc"
Richard Smithf7514452014-10-30 21:02:37 +0000866 }
867 OS << "Attr";
Richard Trieud215b8d2013-01-26 01:31:20 +0000868 }
Richard Smithf7514452014-10-30 21:02:37 +0000869 dumpPointer(A);
870 dumpSourceRange(A->getRange());
871 if (A->isInherited())
872 OS << " Inherited";
873 if (A->isImplicit())
874 OS << " Implicit";
Hans Wennborgb0a8b4a2014-05-31 04:05:57 +0000875#include "clang/AST/AttrDump.inc"
Richard Smithf7514452014-10-30 21:02:37 +0000876 });
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000877}
878
Richard Smith71bec062013-10-15 21:58:30 +0000879static void dumpPreviousDeclImpl(raw_ostream &OS, ...) {}
880
881template<typename T>
882static void dumpPreviousDeclImpl(raw_ostream &OS, const Mergeable<T> *D) {
Rafael Espindola8db352d2013-10-17 15:37:26 +0000883 const T *First = D->getFirstDecl();
Richard Smith71bec062013-10-15 21:58:30 +0000884 if (First != D)
885 OS << " first " << First;
Richard Smithf5f43542013-02-07 01:35:44 +0000886}
887
888template<typename T>
Richard Smith71bec062013-10-15 21:58:30 +0000889static void dumpPreviousDeclImpl(raw_ostream &OS, const Redeclarable<T> *D) {
890 const T *Prev = D->getPreviousDecl();
891 if (Prev)
892 OS << " prev " << Prev;
Richard Smithf5f43542013-02-07 01:35:44 +0000893}
894
Richard Smith71bec062013-10-15 21:58:30 +0000895/// Dump the previous declaration in the redeclaration chain for a declaration,
896/// if any.
897static void dumpPreviousDecl(raw_ostream &OS, const Decl *D) {
Richard Smithf5f43542013-02-07 01:35:44 +0000898 switch (D->getKind()) {
899#define DECL(DERIVED, BASE) \
900 case Decl::DERIVED: \
Richard Smith71bec062013-10-15 21:58:30 +0000901 return dumpPreviousDeclImpl(OS, cast<DERIVED##Decl>(D));
Richard Smithf5f43542013-02-07 01:35:44 +0000902#define ABSTRACT_DECL(DECL)
903#include "clang/AST/DeclNodes.inc"
904 }
905 llvm_unreachable("Decl that isn't part of DeclNodes.inc!");
906}
907
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000908//===----------------------------------------------------------------------===//
909// C++ Utilities
910//===----------------------------------------------------------------------===//
911
912void ASTDumper::dumpAccessSpecifier(AccessSpecifier AS) {
913 switch (AS) {
914 case AS_none:
915 break;
916 case AS_public:
917 OS << "public";
918 break;
919 case AS_protected:
920 OS << "protected";
921 break;
922 case AS_private:
923 OS << "private";
924 break;
925 }
926}
927
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000928void ASTDumper::dumpCXXCtorInitializer(const CXXCtorInitializer *Init) {
Richard Smithf7514452014-10-30 21:02:37 +0000929 dumpChild([=] {
930 OS << "CXXCtorInitializer";
931 if (Init->isAnyMemberInitializer()) {
932 OS << ' ';
933 dumpBareDeclRef(Init->getAnyMember());
934 } else if (Init->isBaseInitializer()) {
935 dumpType(QualType(Init->getBaseClass(), 0));
936 } else if (Init->isDelegatingInitializer()) {
937 dumpType(Init->getTypeSourceInfo()->getType());
938 } else {
939 llvm_unreachable("Unknown initializer type");
940 }
941 dumpStmt(Init->getInit());
942 });
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000943}
944
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000945void ASTDumper::dumpTemplateParameters(const TemplateParameterList *TPL) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000946 if (!TPL)
947 return;
948
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000949 for (TemplateParameterList::const_iterator I = TPL->begin(), E = TPL->end();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000950 I != E; ++I)
951 dumpDecl(*I);
952}
953
954void ASTDumper::dumpTemplateArgumentListInfo(
955 const TemplateArgumentListInfo &TALI) {
Richard Smithf7514452014-10-30 21:02:37 +0000956 for (unsigned i = 0, e = TALI.size(); i < e; ++i)
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000957 dumpTemplateArgumentLoc(TALI[i]);
958}
959
960void ASTDumper::dumpTemplateArgumentLoc(const TemplateArgumentLoc &A) {
961 dumpTemplateArgument(A.getArgument(), A.getSourceRange());
962}
963
964void ASTDumper::dumpTemplateArgumentList(const TemplateArgumentList &TAL) {
965 for (unsigned i = 0, e = TAL.size(); i < e; ++i)
966 dumpTemplateArgument(TAL[i]);
967}
968
969void ASTDumper::dumpTemplateArgument(const TemplateArgument &A, SourceRange R) {
Richard Smithf7514452014-10-30 21:02:37 +0000970 dumpChild([=] {
971 OS << "TemplateArgument";
972 if (R.isValid())
973 dumpSourceRange(R);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000974
Richard Smithf7514452014-10-30 21:02:37 +0000975 switch (A.getKind()) {
976 case TemplateArgument::Null:
977 OS << " null";
978 break;
979 case TemplateArgument::Type:
980 OS << " type";
981 dumpType(A.getAsType());
982 break;
983 case TemplateArgument::Declaration:
984 OS << " decl";
985 dumpDeclRef(A.getAsDecl());
986 break;
987 case TemplateArgument::NullPtr:
988 OS << " nullptr";
989 break;
990 case TemplateArgument::Integral:
991 OS << " integral " << A.getAsIntegral();
992 break;
993 case TemplateArgument::Template:
994 OS << " template ";
995 A.getAsTemplate().dump(OS);
996 break;
997 case TemplateArgument::TemplateExpansion:
998 OS << " template expansion";
999 A.getAsTemplateOrTemplatePattern().dump(OS);
1000 break;
1001 case TemplateArgument::Expression:
1002 OS << " expr";
1003 dumpStmt(A.getAsExpr());
1004 break;
1005 case TemplateArgument::Pack:
1006 OS << " pack";
1007 for (TemplateArgument::pack_iterator I = A.pack_begin(), E = A.pack_end();
1008 I != E; ++I)
1009 dumpTemplateArgument(*I);
1010 break;
Richard Trieude5cc7d2013-01-31 01:44:26 +00001011 }
Richard Smithf7514452014-10-30 21:02:37 +00001012 });
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001013}
1014
Chris Lattner11e30d32007-08-30 06:17:34 +00001015//===----------------------------------------------------------------------===//
Douglas Gregor85f3f952015-07-07 03:57:15 +00001016// Objective-C Utilities
1017//===----------------------------------------------------------------------===//
1018void ASTDumper::dumpObjCTypeParamList(const ObjCTypeParamList *typeParams) {
1019 if (!typeParams)
1020 return;
1021
1022 for (auto typeParam : *typeParams) {
1023 dumpDecl(typeParam);
1024 }
1025}
1026
1027//===----------------------------------------------------------------------===//
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001028// Decl dumping methods.
Chris Lattnercbe4f772007-08-08 22:51:59 +00001029//===----------------------------------------------------------------------===//
1030
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001031void ASTDumper::dumpDecl(const Decl *D) {
Richard Smithf7514452014-10-30 21:02:37 +00001032 dumpChild([=] {
1033 if (!D) {
1034 ColorScope Color(*this, NullColor);
1035 OS << "<<<NULL>>>";
1036 return;
1037 }
Mike Stump11289f42009-09-09 15:08:12 +00001038
Richard Smithf7514452014-10-30 21:02:37 +00001039 {
1040 ColorScope Color(*this, DeclKindNameColor);
1041 OS << D->getDeclKindName() << "Decl";
1042 }
1043 dumpPointer(D);
1044 if (D->getLexicalDeclContext() != D->getDeclContext())
1045 OS << " parent " << cast<Decl>(D->getDeclContext());
1046 dumpPreviousDecl(OS, D);
1047 dumpSourceRange(D->getSourceRange());
1048 OS << ' ';
1049 dumpLocation(D->getLocation());
Richard Smith26342f92017-05-17 00:24:14 +00001050 if (D->isFromASTFile())
1051 OS << " imported";
1052 if (Module *M = D->getOwningModule())
Richard Smithf7514452014-10-30 21:02:37 +00001053 OS << " in " << M->getFullModuleName();
Richard Smitha2eb4092015-06-22 18:47:01 +00001054 if (auto *ND = dyn_cast<NamedDecl>(D))
1055 for (Module *M : D->getASTContext().getModulesWithMergedDefinition(
1056 const_cast<NamedDecl *>(ND)))
1057 dumpChild([=] { OS << "also in " << M->getFullModuleName(); });
Richard Smithf7514452014-10-30 21:02:37 +00001058 if (const NamedDecl *ND = dyn_cast<NamedDecl>(D))
1059 if (ND->isHidden())
1060 OS << " hidden";
1061 if (D->isImplicit())
1062 OS << " implicit";
1063 if (D->isUsed())
1064 OS << " used";
1065 else if (D->isThisDeclarationReferenced())
1066 OS << " referenced";
1067 if (D->isInvalidDecl())
1068 OS << " invalid";
Hans Wennborg76b00532014-12-05 22:38:57 +00001069 if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
1070 if (FD->isConstexpr())
1071 OS << " constexpr";
1072
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001073
Richard Smithf7514452014-10-30 21:02:37 +00001074 ConstDeclVisitor<ASTDumper>::Visit(D);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001075
Richard Smithf7514452014-10-30 21:02:37 +00001076 for (Decl::attr_iterator I = D->attr_begin(), E = D->attr_end(); I != E;
1077 ++I)
1078 dumpAttr(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001079
Richard Smithf7514452014-10-30 21:02:37 +00001080 if (const FullComment *Comment =
1081 D->getASTContext().getLocalCommentForDeclUncached(D))
1082 dumpFullComment(Comment);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001083
Richard Smithf7514452014-10-30 21:02:37 +00001084 // Decls within functions are visited by the body.
1085 if (!isa<FunctionDecl>(*D) && !isa<ObjCMethodDecl>(*D) &&
1086 hasNodes(dyn_cast<DeclContext>(D)))
1087 dumpDeclContext(cast<DeclContext>(D));
1088 });
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001089}
1090
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001091void ASTDumper::VisitLabelDecl(const LabelDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001092 dumpName(D);
1093}
1094
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001095void ASTDumper::VisitTypedefDecl(const TypedefDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001096 dumpName(D);
1097 dumpType(D->getUnderlyingType());
1098 if (D->isModulePrivate())
1099 OS << " __module_private__";
Richard Smithba3a4f92016-01-12 21:59:26 +00001100 dumpTypeAsChild(D->getUnderlyingType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001101}
1102
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001103void ASTDumper::VisitEnumDecl(const EnumDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001104 if (D->isScoped()) {
1105 if (D->isScopedUsingClassTag())
1106 OS << " class";
1107 else
1108 OS << " struct";
1109 }
1110 dumpName(D);
1111 if (D->isModulePrivate())
1112 OS << " __module_private__";
1113 if (D->isFixed())
1114 dumpType(D->getIntegerType());
1115}
1116
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001117void ASTDumper::VisitRecordDecl(const RecordDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001118 OS << ' ' << D->getKindName();
1119 dumpName(D);
1120 if (D->isModulePrivate())
1121 OS << " __module_private__";
Richard Smith99bc1b92013-08-30 05:32:29 +00001122 if (D->isCompleteDefinition())
1123 OS << " definition";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001124}
1125
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001126void ASTDumper::VisitEnumConstantDecl(const EnumConstantDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001127 dumpName(D);
1128 dumpType(D->getType());
Richard Smithf7514452014-10-30 21:02:37 +00001129 if (const Expr *Init = D->getInitExpr())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001130 dumpStmt(Init);
1131}
1132
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001133void ASTDumper::VisitIndirectFieldDecl(const IndirectFieldDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001134 dumpName(D);
1135 dumpType(D->getType());
Richard Smithdcc2c452014-03-17 23:00:06 +00001136
Richard Smith8aa49222014-03-18 00:35:12 +00001137 for (auto *Child : D->chain())
Richard Smithf7514452014-10-30 21:02:37 +00001138 dumpDeclRef(Child);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001139}
1140
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001141void ASTDumper::VisitFunctionDecl(const FunctionDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001142 dumpName(D);
1143 dumpType(D->getType());
1144
Rafael Espindola6ae7e502013-04-03 19:27:57 +00001145 StorageClass SC = D->getStorageClass();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001146 if (SC != SC_None)
1147 OS << ' ' << VarDecl::getStorageClassSpecifierString(SC);
1148 if (D->isInlineSpecified())
1149 OS << " inline";
1150 if (D->isVirtualAsWritten())
1151 OS << " virtual";
1152 if (D->isModulePrivate())
1153 OS << " __module_private__";
1154
1155 if (D->isPure())
1156 OS << " pure";
Richard Smith5a2e6b92016-11-21 23:43:54 +00001157 if (D->isDefaulted()) {
1158 OS << " default";
1159 if (D->isDeleted())
1160 OS << "_delete";
1161 }
1162 if (D->isDeletedAsWritten())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001163 OS << " delete";
Richard Smith5a2e6b92016-11-21 23:43:54 +00001164 if (D->isTrivial())
1165 OS << " trivial";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001166
Richard Smithadaa0152013-05-17 02:09:46 +00001167 if (const FunctionProtoType *FPT = D->getType()->getAs<FunctionProtoType>()) {
1168 FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo();
Richard Smith8acb4282014-07-31 21:57:55 +00001169 switch (EPI.ExceptionSpec.Type) {
Richard Smithadaa0152013-05-17 02:09:46 +00001170 default: break;
1171 case EST_Unevaluated:
Richard Smith8acb4282014-07-31 21:57:55 +00001172 OS << " noexcept-unevaluated " << EPI.ExceptionSpec.SourceDecl;
Richard Smithadaa0152013-05-17 02:09:46 +00001173 break;
1174 case EST_Uninstantiated:
Richard Smith8acb4282014-07-31 21:57:55 +00001175 OS << " noexcept-uninstantiated " << EPI.ExceptionSpec.SourceTemplate;
Richard Smithadaa0152013-05-17 02:09:46 +00001176 break;
1177 }
1178 }
1179
Richard Smithf7514452014-10-30 21:02:37 +00001180 if (const FunctionTemplateSpecializationInfo *FTSI =
1181 D->getTemplateSpecializationInfo())
Richard Trieude5cc7d2013-01-31 01:44:26 +00001182 dumpTemplateArgumentList(*FTSI->TemplateArguments);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001183
Richard Smith8a639892015-01-24 01:07:20 +00001184 if (!D->param_begin() && D->getNumParams())
1185 dumpChild([=] { OS << "<<NULL params x " << D->getNumParams() << ">>"; });
1186 else
David Majnemera3debed2016-06-24 05:33:44 +00001187 for (const ParmVarDecl *Parameter : D->parameters())
1188 dumpDecl(Parameter);
Richard Smithf7514452014-10-30 21:02:37 +00001189
1190 if (const CXXConstructorDecl *C = dyn_cast<CXXConstructorDecl>(D))
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001191 for (CXXConstructorDecl::init_const_iterator I = C->init_begin(),
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001192 E = C->init_end();
Richard Smithf7514452014-10-30 21:02:37 +00001193 I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001194 dumpCXXCtorInitializer(*I);
1195
Lenar Safin9ae21552017-07-29 20:42:58 +00001196 if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(D)) {
Lang Hames19e07e12017-06-20 21:06:00 +00001197 if (MD->size_overridden_methods() != 0) {
Aaron Ballman8c208282017-12-21 21:42:42 +00001198 auto dumpOverride = [=](const CXXMethodDecl *D) {
1199 SplitQualType T_split = D->getType().split();
1200 OS << D << " " << D->getParent()->getName()
1201 << "::" << D->getNameAsString() << " '"
1202 << QualType::getAsString(T_split, PrintPolicy) << "'";
1203 };
Lang Hames19e07e12017-06-20 21:06:00 +00001204
1205 dumpChild([=] {
Benjamin Krameracfa3392017-12-17 23:52:45 +00001206 auto Overrides = MD->overridden_methods();
Lang Hames19e07e12017-06-20 21:06:00 +00001207 OS << "Overrides: [ ";
Benjamin Krameracfa3392017-12-17 23:52:45 +00001208 dumpOverride(*Overrides.begin());
Lang Hames19e07e12017-06-20 21:06:00 +00001209 for (const auto *Override :
Benjamin Krameracfa3392017-12-17 23:52:45 +00001210 llvm::make_range(Overrides.begin() + 1, Overrides.end())) {
Lenar Safin9ae21552017-07-29 20:42:58 +00001211 OS << ", ";
Lang Hames19e07e12017-06-20 21:06:00 +00001212 dumpOverride(Override);
Lenar Safin9ae21552017-07-29 20:42:58 +00001213 }
Lang Hames19e07e12017-06-20 21:06:00 +00001214 OS << " ]";
1215 });
1216 }
Lenar Safin9ae21552017-07-29 20:42:58 +00001217 }
Lang Hames19e07e12017-06-20 21:06:00 +00001218
Richard Smithf7514452014-10-30 21:02:37 +00001219 if (D->doesThisDeclarationHaveABody())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001220 dumpStmt(D->getBody());
1221}
1222
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001223void ASTDumper::VisitFieldDecl(const FieldDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001224 dumpName(D);
1225 dumpType(D->getType());
1226 if (D->isMutable())
1227 OS << " mutable";
1228 if (D->isModulePrivate())
1229 OS << " __module_private__";
Richard Trieude5cc7d2013-01-31 01:44:26 +00001230
Richard Smithf7514452014-10-30 21:02:37 +00001231 if (D->isBitField())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001232 dumpStmt(D->getBitWidth());
Richard Smithf7514452014-10-30 21:02:37 +00001233 if (Expr *Init = D->getInClassInitializer())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001234 dumpStmt(Init);
1235}
1236
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001237void ASTDumper::VisitVarDecl(const VarDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001238 dumpName(D);
1239 dumpType(D->getType());
Rafael Espindola6ae7e502013-04-03 19:27:57 +00001240 StorageClass SC = D->getStorageClass();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001241 if (SC != SC_None)
1242 OS << ' ' << VarDecl::getStorageClassSpecifierString(SC);
Richard Smithfd3834f2013-04-13 02:43:54 +00001243 switch (D->getTLSKind()) {
1244 case VarDecl::TLS_None: break;
1245 case VarDecl::TLS_Static: OS << " tls"; break;
1246 case VarDecl::TLS_Dynamic: OS << " tls_dynamic"; break;
1247 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001248 if (D->isModulePrivate())
1249 OS << " __module_private__";
1250 if (D->isNRVOVariable())
1251 OS << " nrvo";
Richard Smith62f19e72016-06-25 00:15:56 +00001252 if (D->isInline())
1253 OS << " inline";
1254 if (D->isConstexpr())
1255 OS << " constexpr";
Richard Trieude5cc7d2013-01-31 01:44:26 +00001256 if (D->hasInit()) {
Richard Smithd9967cc2014-07-10 22:54:03 +00001257 switch (D->getInitStyle()) {
1258 case VarDecl::CInit: OS << " cinit"; break;
1259 case VarDecl::CallInit: OS << " callinit"; break;
1260 case VarDecl::ListInit: OS << " listinit"; break;
1261 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001262 dumpStmt(D->getInit());
Richard Trieude5cc7d2013-01-31 01:44:26 +00001263 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001264}
1265
Richard Smithbdb84f32016-07-22 23:36:59 +00001266void ASTDumper::VisitDecompositionDecl(const DecompositionDecl *D) {
1267 VisitVarDecl(D);
1268 for (auto *B : D->bindings())
1269 dumpDecl(B);
1270}
1271
Richard Smith7873de02016-08-11 22:25:46 +00001272void ASTDumper::VisitBindingDecl(const BindingDecl *D) {
1273 dumpName(D);
1274 dumpType(D->getType());
1275 if (auto *E = D->getBinding())
1276 dumpStmt(E);
1277}
1278
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001279void ASTDumper::VisitFileScopeAsmDecl(const FileScopeAsmDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001280 dumpStmt(D->getAsmString());
1281}
1282
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001283void ASTDumper::VisitImportDecl(const ImportDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001284 OS << ' ' << D->getImportedModule()->getFullModuleName();
1285}
1286
Nico Weber66220292016-03-02 17:28:48 +00001287void ASTDumper::VisitPragmaCommentDecl(const PragmaCommentDecl *D) {
1288 OS << ' ';
1289 switch (D->getCommentKind()) {
1290 case PCK_Unknown: llvm_unreachable("unexpected pragma comment kind");
1291 case PCK_Compiler: OS << "compiler"; break;
1292 case PCK_ExeStr: OS << "exestr"; break;
1293 case PCK_Lib: OS << "lib"; break;
1294 case PCK_Linker: OS << "linker"; break;
1295 case PCK_User: OS << "user"; break;
1296 }
1297 StringRef Arg = D->getArg();
1298 if (!Arg.empty())
1299 OS << " \"" << Arg << "\"";
1300}
1301
Nico Webercbbaeb12016-03-02 19:28:54 +00001302void ASTDumper::VisitPragmaDetectMismatchDecl(
1303 const PragmaDetectMismatchDecl *D) {
1304 OS << " \"" << D->getName() << "\" \"" << D->getValue() << "\"";
1305}
1306
Alexey Bataev958b9e72016-03-31 09:30:50 +00001307void ASTDumper::VisitCapturedDecl(const CapturedDecl *D) {
1308 dumpStmt(D->getBody());
1309}
1310
1311//===----------------------------------------------------------------------===//
1312// OpenMP Declarations
1313//===----------------------------------------------------------------------===//
1314
1315void ASTDumper::VisitOMPThreadPrivateDecl(const OMPThreadPrivateDecl *D) {
1316 for (auto *E : D->varlists())
1317 dumpStmt(E);
1318}
1319
1320void ASTDumper::VisitOMPDeclareReductionDecl(const OMPDeclareReductionDecl *D) {
1321 dumpName(D);
1322 dumpType(D->getType());
1323 OS << " combiner";
1324 dumpStmt(D->getCombiner());
1325 if (auto *Initializer = D->getInitializer()) {
1326 OS << " initializer";
Alexey Bataev070f43a2017-09-06 14:49:58 +00001327 switch (D->getInitializerKind()) {
1328 case OMPDeclareReductionDecl::DirectInit:
1329 OS << " omp_priv = ";
1330 break;
1331 case OMPDeclareReductionDecl::CopyInit:
1332 OS << " omp_priv ()";
1333 break;
1334 case OMPDeclareReductionDecl::CallInit:
1335 break;
1336 }
Alexey Bataev958b9e72016-03-31 09:30:50 +00001337 dumpStmt(Initializer);
1338 }
1339}
1340
1341void ASTDumper::VisitOMPCapturedExprDecl(const OMPCapturedExprDecl *D) {
1342 dumpName(D);
1343 dumpType(D->getType());
1344 dumpStmt(D->getInit());
1345}
Nico Webercbbaeb12016-03-02 19:28:54 +00001346
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001347//===----------------------------------------------------------------------===//
1348// C++ Declarations
1349//===----------------------------------------------------------------------===//
1350
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001351void ASTDumper::VisitNamespaceDecl(const NamespaceDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001352 dumpName(D);
1353 if (D->isInline())
1354 OS << " inline";
1355 if (!D->isOriginalNamespace())
1356 dumpDeclRef(D->getOriginalNamespace(), "original");
1357}
1358
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001359void ASTDumper::VisitUsingDirectiveDecl(const UsingDirectiveDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001360 OS << ' ';
1361 dumpBareDeclRef(D->getNominatedNamespace());
1362}
1363
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001364void ASTDumper::VisitNamespaceAliasDecl(const NamespaceAliasDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001365 dumpName(D);
1366 dumpDeclRef(D->getAliasedNamespace());
1367}
1368
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001369void ASTDumper::VisitTypeAliasDecl(const TypeAliasDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001370 dumpName(D);
1371 dumpType(D->getUnderlyingType());
Richard Smithba3a4f92016-01-12 21:59:26 +00001372 dumpTypeAsChild(D->getUnderlyingType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001373}
1374
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001375void ASTDumper::VisitTypeAliasTemplateDecl(const TypeAliasTemplateDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001376 dumpName(D);
1377 dumpTemplateParameters(D->getTemplateParameters());
1378 dumpDecl(D->getTemplatedDecl());
1379}
1380
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001381void ASTDumper::VisitCXXRecordDecl(const CXXRecordDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001382 VisitRecordDecl(D);
1383 if (!D->isCompleteDefinition())
1384 return;
1385
Richard Smithdfc4bff2017-09-22 00:11:15 +00001386 dumpChild([=] {
1387 {
1388 ColorScope Color(*this, DeclKindNameColor);
1389 OS << "DefinitionData";
1390 }
1391#define FLAG(fn, name) if (D->fn()) OS << " " #name;
1392 FLAG(isParsingBaseSpecifiers, parsing_base_specifiers);
1393
1394 FLAG(isGenericLambda, generic);
1395 FLAG(isLambda, lambda);
1396
1397 FLAG(canPassInRegisters, pass_in_registers);
1398 FLAG(isEmpty, empty);
1399 FLAG(isAggregate, aggregate);
1400 FLAG(isStandardLayout, standard_layout);
1401 FLAG(isTriviallyCopyable, trivially_copyable);
1402 FLAG(isPOD, pod);
1403 FLAG(isTrivial, trivial);
1404 FLAG(isPolymorphic, polymorphic);
1405 FLAG(isAbstract, abstract);
1406 FLAG(isLiteral, literal);
1407
1408 FLAG(hasUserDeclaredConstructor, has_user_declared_ctor);
1409 FLAG(hasConstexprNonCopyMoveConstructor, has_constexpr_non_copy_move_ctor);
1410 FLAG(hasMutableFields, has_mutable_fields);
1411 FLAG(hasVariantMembers, has_variant_members);
1412 FLAG(allowConstDefaultInit, can_const_default_init);
1413
1414 dumpChild([=] {
1415 {
1416 ColorScope Color(*this, DeclKindNameColor);
1417 OS << "DefaultConstructor";
1418 }
1419 FLAG(hasDefaultConstructor, exists);
1420 FLAG(hasTrivialDefaultConstructor, trivial);
1421 FLAG(hasNonTrivialDefaultConstructor, non_trivial);
1422 FLAG(hasUserProvidedDefaultConstructor, user_provided);
1423 FLAG(hasConstexprDefaultConstructor, constexpr);
1424 FLAG(needsImplicitDefaultConstructor, needs_implicit);
1425 FLAG(defaultedDefaultConstructorIsConstexpr, defaulted_is_constexpr);
1426 });
1427
1428 dumpChild([=] {
1429 {
1430 ColorScope Color(*this, DeclKindNameColor);
1431 OS << "CopyConstructor";
1432 }
1433 FLAG(hasSimpleCopyConstructor, simple);
1434 FLAG(hasTrivialCopyConstructor, trivial);
1435 FLAG(hasNonTrivialCopyConstructor, non_trivial);
1436 FLAG(hasUserDeclaredCopyConstructor, user_declared);
1437 FLAG(hasCopyConstructorWithConstParam, has_const_param);
1438 FLAG(needsImplicitCopyConstructor, needs_implicit);
1439 FLAG(needsOverloadResolutionForCopyConstructor,
1440 needs_overload_resolution);
1441 if (!D->needsOverloadResolutionForCopyConstructor())
1442 FLAG(defaultedCopyConstructorIsDeleted, defaulted_is_deleted);
1443 FLAG(implicitCopyConstructorHasConstParam, implicit_has_const_param);
1444 });
1445
1446 dumpChild([=] {
1447 {
1448 ColorScope Color(*this, DeclKindNameColor);
1449 OS << "MoveConstructor";
1450 }
1451 FLAG(hasMoveConstructor, exists);
1452 FLAG(hasSimpleMoveConstructor, simple);
1453 FLAG(hasTrivialMoveConstructor, trivial);
1454 FLAG(hasNonTrivialMoveConstructor, non_trivial);
1455 FLAG(hasUserDeclaredMoveConstructor, user_declared);
1456 FLAG(needsImplicitMoveConstructor, needs_implicit);
1457 FLAG(needsOverloadResolutionForMoveConstructor,
1458 needs_overload_resolution);
1459 if (!D->needsOverloadResolutionForMoveConstructor())
1460 FLAG(defaultedMoveConstructorIsDeleted, defaulted_is_deleted);
1461 });
1462
1463 dumpChild([=] {
1464 {
1465 ColorScope Color(*this, DeclKindNameColor);
1466 OS << "CopyAssignment";
1467 }
1468 FLAG(hasTrivialCopyAssignment, trivial);
1469 FLAG(hasNonTrivialCopyAssignment, non_trivial);
1470 FLAG(hasCopyAssignmentWithConstParam, has_const_param);
1471 FLAG(hasUserDeclaredCopyAssignment, user_declared);
1472 FLAG(needsImplicitCopyAssignment, needs_implicit);
1473 FLAG(needsOverloadResolutionForCopyAssignment, needs_overload_resolution);
1474 FLAG(implicitCopyAssignmentHasConstParam, implicit_has_const_param);
1475 });
1476
1477 dumpChild([=] {
1478 {
1479 ColorScope Color(*this, DeclKindNameColor);
1480 OS << "MoveAssignment";
1481 }
1482 FLAG(hasMoveAssignment, exists);
1483 FLAG(hasSimpleMoveAssignment, simple);
1484 FLAG(hasTrivialMoveAssignment, trivial);
1485 FLAG(hasNonTrivialMoveAssignment, non_trivial);
1486 FLAG(hasUserDeclaredMoveAssignment, user_declared);
1487 FLAG(needsImplicitMoveAssignment, needs_implicit);
1488 FLAG(needsOverloadResolutionForMoveAssignment, needs_overload_resolution);
1489 });
1490
1491 dumpChild([=] {
1492 {
1493 ColorScope Color(*this, DeclKindNameColor);
1494 OS << "Destructor";
1495 }
1496 FLAG(hasSimpleDestructor, simple);
1497 FLAG(hasIrrelevantDestructor, irrelevant);
1498 FLAG(hasTrivialDestructor, trivial);
1499 FLAG(hasNonTrivialDestructor, non_trivial);
1500 FLAG(hasUserDeclaredDestructor, user_declared);
1501 FLAG(needsImplicitDestructor, needs_implicit);
1502 FLAG(needsOverloadResolutionForDestructor, needs_overload_resolution);
1503 if (!D->needsOverloadResolutionForDestructor())
1504 FLAG(defaultedDestructorIsDeleted, defaulted_is_deleted);
1505 });
1506 });
1507
Aaron Ballman574705e2014-03-13 15:41:46 +00001508 for (const auto &I : D->bases()) {
Richard Smithf7514452014-10-30 21:02:37 +00001509 dumpChild([=] {
1510 if (I.isVirtual())
1511 OS << "virtual ";
1512 dumpAccessSpecifier(I.getAccessSpecifier());
1513 dumpType(I.getType());
1514 if (I.isPackExpansion())
1515 OS << "...";
1516 });
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001517 }
1518}
1519
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001520void ASTDumper::VisitStaticAssertDecl(const StaticAssertDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001521 dumpStmt(D->getAssertExpr());
1522 dumpStmt(D->getMessage());
1523}
1524
Richard Smithcbdf7332014-03-18 02:07:28 +00001525template<typename SpecializationDecl>
Richard Smithf7514452014-10-30 21:02:37 +00001526void ASTDumper::VisitTemplateDeclSpecialization(const SpecializationDecl *D,
Richard Smithcbdf7332014-03-18 02:07:28 +00001527 bool DumpExplicitInst,
1528 bool DumpRefOnly) {
1529 bool DumpedAny = false;
1530 for (auto *RedeclWithBadType : D->redecls()) {
1531 // FIXME: The redecls() range sometimes has elements of a less-specific
1532 // type. (In particular, ClassTemplateSpecializationDecl::redecls() gives
1533 // us TagDecls, and should give CXXRecordDecls).
1534 auto *Redecl = dyn_cast<SpecializationDecl>(RedeclWithBadType);
1535 if (!Redecl) {
1536 // Found the injected-class-name for a class template. This will be dumped
1537 // as part of its surrounding class so we don't need to dump it here.
1538 assert(isa<CXXRecordDecl>(RedeclWithBadType) &&
1539 "expected an injected-class-name");
1540 continue;
1541 }
1542
1543 switch (Redecl->getTemplateSpecializationKind()) {
1544 case TSK_ExplicitInstantiationDeclaration:
1545 case TSK_ExplicitInstantiationDefinition:
1546 if (!DumpExplicitInst)
1547 break;
Adrian Prantlf3b3ccd2017-12-19 22:06:11 +00001548 LLVM_FALLTHROUGH;
Richard Smithcbdf7332014-03-18 02:07:28 +00001549 case TSK_Undeclared:
1550 case TSK_ImplicitInstantiation:
Richard Smithf7514452014-10-30 21:02:37 +00001551 if (DumpRefOnly)
1552 dumpDeclRef(Redecl);
1553 else
1554 dumpDecl(Redecl);
Richard Smithcbdf7332014-03-18 02:07:28 +00001555 DumpedAny = true;
1556 break;
1557 case TSK_ExplicitSpecialization:
1558 break;
1559 }
1560 }
1561
1562 // Ensure we dump at least one decl for each specialization.
1563 if (!DumpedAny)
Richard Smithf7514452014-10-30 21:02:37 +00001564 dumpDeclRef(D);
Richard Smithcbdf7332014-03-18 02:07:28 +00001565}
1566
Richard Smith20ade552014-03-17 23:34:53 +00001567template<typename TemplateDecl>
1568void ASTDumper::VisitTemplateDecl(const TemplateDecl *D,
1569 bool DumpExplicitInst) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001570 dumpName(D);
1571 dumpTemplateParameters(D->getTemplateParameters());
Richard Smithdcc2c452014-03-17 23:00:06 +00001572
Richard Smithf7514452014-10-30 21:02:37 +00001573 dumpDecl(D->getTemplatedDecl());
Richard Smithdcc2c452014-03-17 23:00:06 +00001574
Richard Smithcbdf7332014-03-18 02:07:28 +00001575 for (auto *Child : D->specializations())
Richard Smithf7514452014-10-30 21:02:37 +00001576 VisitTemplateDeclSpecialization(Child, DumpExplicitInst,
Richard Smithcbdf7332014-03-18 02:07:28 +00001577 !D->isCanonicalDecl());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001578}
1579
Richard Smith20ade552014-03-17 23:34:53 +00001580void ASTDumper::VisitFunctionTemplateDecl(const FunctionTemplateDecl *D) {
1581 // FIXME: We don't add a declaration of a function template specialization
1582 // to its context when it's explicitly instantiated, so dump explicit
1583 // instantiations when we dump the template itself.
1584 VisitTemplateDecl(D, true);
1585}
1586
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001587void ASTDumper::VisitClassTemplateDecl(const ClassTemplateDecl *D) {
Richard Smith20ade552014-03-17 23:34:53 +00001588 VisitTemplateDecl(D, false);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001589}
1590
1591void ASTDumper::VisitClassTemplateSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001592 const ClassTemplateSpecializationDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001593 VisitCXXRecordDecl(D);
1594 dumpTemplateArgumentList(D->getTemplateArgs());
1595}
1596
1597void ASTDumper::VisitClassTemplatePartialSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001598 const ClassTemplatePartialSpecializationDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001599 VisitClassTemplateSpecializationDecl(D);
1600 dumpTemplateParameters(D->getTemplateParameters());
1601}
1602
1603void ASTDumper::VisitClassScopeFunctionSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001604 const ClassScopeFunctionSpecializationDecl *D) {
Richard Smithc660c8f2018-03-16 13:36:56 +00001605 dumpDecl(D->getSpecialization());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001606 if (D->hasExplicitTemplateArgs())
1607 dumpTemplateArgumentListInfo(D->templateArgs());
1608}
1609
Richard Smithd25789a2013-09-18 01:36:02 +00001610void ASTDumper::VisitVarTemplateDecl(const VarTemplateDecl *D) {
Richard Smith20ade552014-03-17 23:34:53 +00001611 VisitTemplateDecl(D, false);
Richard Smithd25789a2013-09-18 01:36:02 +00001612}
1613
David Majnemerd9b1a4f2015-11-04 03:40:30 +00001614void ASTDumper::VisitBuiltinTemplateDecl(const BuiltinTemplateDecl *D) {
1615 dumpName(D);
1616 dumpTemplateParameters(D->getTemplateParameters());
1617}
1618
Richard Smithd25789a2013-09-18 01:36:02 +00001619void ASTDumper::VisitVarTemplateSpecializationDecl(
1620 const VarTemplateSpecializationDecl *D) {
1621 dumpTemplateArgumentList(D->getTemplateArgs());
1622 VisitVarDecl(D);
1623}
1624
1625void ASTDumper::VisitVarTemplatePartialSpecializationDecl(
1626 const VarTemplatePartialSpecializationDecl *D) {
1627 dumpTemplateParameters(D->getTemplateParameters());
1628 VisitVarTemplateSpecializationDecl(D);
1629}
1630
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001631void ASTDumper::VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001632 if (D->wasDeclaredWithTypename())
1633 OS << " typename";
1634 else
1635 OS << " class";
Richard Smith1832a022017-02-21 02:04:03 +00001636 OS << " depth " << D->getDepth() << " index " << D->getIndex();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001637 if (D->isParameterPack())
1638 OS << " ...";
1639 dumpName(D);
Richard Smithf7514452014-10-30 21:02:37 +00001640 if (D->hasDefaultArgument())
Richard Smithecf74ff2014-03-23 20:50:39 +00001641 dumpTemplateArgument(D->getDefaultArgument());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001642}
1643
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001644void ASTDumper::VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001645 dumpType(D->getType());
Richard Smith1832a022017-02-21 02:04:03 +00001646 OS << " depth " << D->getDepth() << " index " << D->getIndex();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001647 if (D->isParameterPack())
1648 OS << " ...";
1649 dumpName(D);
Richard Smithf7514452014-10-30 21:02:37 +00001650 if (D->hasDefaultArgument())
Richard Smithecf74ff2014-03-23 20:50:39 +00001651 dumpTemplateArgument(D->getDefaultArgument());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001652}
1653
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001654void ASTDumper::VisitTemplateTemplateParmDecl(
1655 const TemplateTemplateParmDecl *D) {
Richard Smith1832a022017-02-21 02:04:03 +00001656 OS << " depth " << D->getDepth() << " index " << D->getIndex();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001657 if (D->isParameterPack())
1658 OS << " ...";
1659 dumpName(D);
1660 dumpTemplateParameters(D->getTemplateParameters());
Richard Smithf7514452014-10-30 21:02:37 +00001661 if (D->hasDefaultArgument())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001662 dumpTemplateArgumentLoc(D->getDefaultArgument());
1663}
1664
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001665void ASTDumper::VisitUsingDecl(const UsingDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001666 OS << ' ';
Dawn Perchikddd03bf2015-12-05 22:37:55 +00001667 if (D->getQualifier())
1668 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001669 OS << D->getNameAsString();
1670}
1671
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001672void ASTDumper::VisitUnresolvedUsingTypenameDecl(
1673 const UnresolvedUsingTypenameDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001674 OS << ' ';
Dawn Perchikddd03bf2015-12-05 22:37:55 +00001675 if (D->getQualifier())
1676 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001677 OS << D->getNameAsString();
1678}
1679
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001680void ASTDumper::VisitUnresolvedUsingValueDecl(const UnresolvedUsingValueDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001681 OS << ' ';
Dawn Perchikddd03bf2015-12-05 22:37:55 +00001682 if (D->getQualifier())
1683 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001684 OS << D->getNameAsString();
1685 dumpType(D->getType());
1686}
1687
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001688void ASTDumper::VisitUsingShadowDecl(const UsingShadowDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001689 OS << ' ';
1690 dumpBareDeclRef(D->getTargetDecl());
Richard Smithba3a4f92016-01-12 21:59:26 +00001691 if (auto *TD = dyn_cast<TypeDecl>(D->getUnderlyingDecl()))
1692 dumpTypeAsChild(TD->getTypeForDecl());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001693}
1694
Richard Smith5179eb72016-06-28 19:03:57 +00001695void ASTDumper::VisitConstructorUsingShadowDecl(
1696 const ConstructorUsingShadowDecl *D) {
1697 if (D->constructsVirtualBase())
1698 OS << " virtual";
1699
1700 dumpChild([=] {
1701 OS << "target ";
1702 dumpBareDeclRef(D->getTargetDecl());
1703 });
1704
1705 dumpChild([=] {
1706 OS << "nominated ";
1707 dumpBareDeclRef(D->getNominatedBaseClass());
1708 OS << ' ';
1709 dumpBareDeclRef(D->getNominatedBaseClassShadowDecl());
1710 });
1711
1712 dumpChild([=] {
1713 OS << "constructed ";
1714 dumpBareDeclRef(D->getConstructedBaseClass());
1715 OS << ' ';
1716 dumpBareDeclRef(D->getConstructedBaseClassShadowDecl());
1717 });
1718}
1719
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001720void ASTDumper::VisitLinkageSpecDecl(const LinkageSpecDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001721 switch (D->getLanguage()) {
1722 case LinkageSpecDecl::lang_c: OS << " C"; break;
1723 case LinkageSpecDecl::lang_cxx: OS << " C++"; break;
1724 }
1725}
1726
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001727void ASTDumper::VisitAccessSpecDecl(const AccessSpecDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001728 OS << ' ';
1729 dumpAccessSpecifier(D->getAccess());
1730}
1731
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001732void ASTDumper::VisitFriendDecl(const FriendDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001733 if (TypeSourceInfo *T = D->getFriendType())
1734 dumpType(T->getType());
1735 else
1736 dumpDecl(D->getFriendDecl());
1737}
1738
1739//===----------------------------------------------------------------------===//
1740// Obj-C Declarations
1741//===----------------------------------------------------------------------===//
1742
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001743void ASTDumper::VisitObjCIvarDecl(const ObjCIvarDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001744 dumpName(D);
1745 dumpType(D->getType());
1746 if (D->getSynthesize())
1747 OS << " synthesize";
1748
1749 switch (D->getAccessControl()) {
1750 case ObjCIvarDecl::None:
1751 OS << " none";
1752 break;
1753 case ObjCIvarDecl::Private:
1754 OS << " private";
1755 break;
1756 case ObjCIvarDecl::Protected:
1757 OS << " protected";
1758 break;
1759 case ObjCIvarDecl::Public:
1760 OS << " public";
1761 break;
1762 case ObjCIvarDecl::Package:
1763 OS << " package";
1764 break;
1765 }
1766}
1767
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001768void ASTDumper::VisitObjCMethodDecl(const ObjCMethodDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001769 if (D->isInstanceMethod())
1770 OS << " -";
1771 else
1772 OS << " +";
1773 dumpName(D);
Alp Toker314cc812014-01-25 16:55:45 +00001774 dumpType(D->getReturnType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001775
Richard Trieude5cc7d2013-01-31 01:44:26 +00001776 if (D->isThisDeclarationADefinition()) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001777 dumpDeclContext(D);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001778 } else {
David Majnemera3debed2016-06-24 05:33:44 +00001779 for (const ParmVarDecl *Parameter : D->parameters())
1780 dumpDecl(Parameter);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001781 }
1782
Richard Smithf7514452014-10-30 21:02:37 +00001783 if (D->isVariadic())
1784 dumpChild([=] { OS << "..."; });
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001785
Richard Smithf7514452014-10-30 21:02:37 +00001786 if (D->hasBody())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001787 dumpStmt(D->getBody());
1788}
1789
Douglas Gregor85f3f952015-07-07 03:57:15 +00001790void ASTDumper::VisitObjCTypeParamDecl(const ObjCTypeParamDecl *D) {
1791 dumpName(D);
Douglas Gregor1ac1b632015-07-07 03:58:54 +00001792 switch (D->getVariance()) {
1793 case ObjCTypeParamVariance::Invariant:
1794 break;
1795
1796 case ObjCTypeParamVariance::Covariant:
1797 OS << " covariant";
1798 break;
1799
1800 case ObjCTypeParamVariance::Contravariant:
1801 OS << " contravariant";
1802 break;
1803 }
1804
Douglas Gregor85f3f952015-07-07 03:57:15 +00001805 if (D->hasExplicitBound())
1806 OS << " bounded";
1807 dumpType(D->getUnderlyingType());
1808}
1809
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001810void ASTDumper::VisitObjCCategoryDecl(const ObjCCategoryDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001811 dumpName(D);
1812 dumpDeclRef(D->getClassInterface());
Douglas Gregor85f3f952015-07-07 03:57:15 +00001813 dumpObjCTypeParamList(D->getTypeParamList());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001814 dumpDeclRef(D->getImplementation());
1815 for (ObjCCategoryDecl::protocol_iterator I = D->protocol_begin(),
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001816 E = D->protocol_end();
Richard Smithf7514452014-10-30 21:02:37 +00001817 I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001818 dumpDeclRef(*I);
1819}
1820
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001821void ASTDumper::VisitObjCCategoryImplDecl(const ObjCCategoryImplDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001822 dumpName(D);
1823 dumpDeclRef(D->getClassInterface());
1824 dumpDeclRef(D->getCategoryDecl());
1825}
1826
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001827void ASTDumper::VisitObjCProtocolDecl(const ObjCProtocolDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001828 dumpName(D);
Richard Smithdcc2c452014-03-17 23:00:06 +00001829
Richard Smith7fcb35f2014-03-18 02:37:59 +00001830 for (auto *Child : D->protocols())
Richard Smithf7514452014-10-30 21:02:37 +00001831 dumpDeclRef(Child);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001832}
1833
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001834void ASTDumper::VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001835 dumpName(D);
Douglas Gregor85f3f952015-07-07 03:57:15 +00001836 dumpObjCTypeParamList(D->getTypeParamListAsWritten());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001837 dumpDeclRef(D->getSuperClass(), "super");
Richard Smithdcc2c452014-03-17 23:00:06 +00001838
Richard Smithf7514452014-10-30 21:02:37 +00001839 dumpDeclRef(D->getImplementation());
Richard Smith7fcb35f2014-03-18 02:37:59 +00001840 for (auto *Child : D->protocols())
Richard Smithf7514452014-10-30 21:02:37 +00001841 dumpDeclRef(Child);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001842}
1843
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001844void ASTDumper::VisitObjCImplementationDecl(const ObjCImplementationDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001845 dumpName(D);
1846 dumpDeclRef(D->getSuperClass(), "super");
1847 dumpDeclRef(D->getClassInterface());
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001848 for (ObjCImplementationDecl::init_const_iterator I = D->init_begin(),
1849 E = D->init_end();
Richard Smithf7514452014-10-30 21:02:37 +00001850 I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001851 dumpCXXCtorInitializer(*I);
1852}
1853
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001854void ASTDumper::VisitObjCCompatibleAliasDecl(const ObjCCompatibleAliasDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001855 dumpName(D);
1856 dumpDeclRef(D->getClassInterface());
1857}
1858
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001859void ASTDumper::VisitObjCPropertyDecl(const ObjCPropertyDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001860 dumpName(D);
1861 dumpType(D->getType());
1862
1863 if (D->getPropertyImplementation() == ObjCPropertyDecl::Required)
1864 OS << " required";
1865 else if (D->getPropertyImplementation() == ObjCPropertyDecl::Optional)
1866 OS << " optional";
1867
1868 ObjCPropertyDecl::PropertyAttributeKind Attrs = D->getPropertyAttributes();
1869 if (Attrs != ObjCPropertyDecl::OBJC_PR_noattr) {
1870 if (Attrs & ObjCPropertyDecl::OBJC_PR_readonly)
1871 OS << " readonly";
1872 if (Attrs & ObjCPropertyDecl::OBJC_PR_assign)
1873 OS << " assign";
1874 if (Attrs & ObjCPropertyDecl::OBJC_PR_readwrite)
1875 OS << " readwrite";
1876 if (Attrs & ObjCPropertyDecl::OBJC_PR_retain)
1877 OS << " retain";
1878 if (Attrs & ObjCPropertyDecl::OBJC_PR_copy)
1879 OS << " copy";
1880 if (Attrs & ObjCPropertyDecl::OBJC_PR_nonatomic)
1881 OS << " nonatomic";
1882 if (Attrs & ObjCPropertyDecl::OBJC_PR_atomic)
1883 OS << " atomic";
1884 if (Attrs & ObjCPropertyDecl::OBJC_PR_weak)
1885 OS << " weak";
1886 if (Attrs & ObjCPropertyDecl::OBJC_PR_strong)
1887 OS << " strong";
1888 if (Attrs & ObjCPropertyDecl::OBJC_PR_unsafe_unretained)
1889 OS << " unsafe_unretained";
Manman Ren387ff7f2016-01-26 18:52:43 +00001890 if (Attrs & ObjCPropertyDecl::OBJC_PR_class)
1891 OS << " class";
Richard Smithf7514452014-10-30 21:02:37 +00001892 if (Attrs & ObjCPropertyDecl::OBJC_PR_getter)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001893 dumpDeclRef(D->getGetterMethodDecl(), "getter");
Richard Smithf7514452014-10-30 21:02:37 +00001894 if (Attrs & ObjCPropertyDecl::OBJC_PR_setter)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001895 dumpDeclRef(D->getSetterMethodDecl(), "setter");
1896 }
1897}
1898
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001899void ASTDumper::VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001900 dumpName(D->getPropertyDecl());
1901 if (D->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize)
1902 OS << " synthesize";
1903 else
1904 OS << " dynamic";
1905 dumpDeclRef(D->getPropertyDecl());
1906 dumpDeclRef(D->getPropertyIvarDecl());
1907}
1908
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001909void ASTDumper::VisitBlockDecl(const BlockDecl *D) {
David Majnemer59f77922016-06-24 04:05:48 +00001910 for (auto I : D->parameters())
Aaron Ballmanb2b8b1d2014-03-07 16:09:59 +00001911 dumpDecl(I);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001912
Richard Smithf7514452014-10-30 21:02:37 +00001913 if (D->isVariadic())
1914 dumpChild([=]{ OS << "..."; });
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001915
Richard Smithf7514452014-10-30 21:02:37 +00001916 if (D->capturesCXXThis())
1917 dumpChild([=]{ OS << "capture this"; });
1918
Aaron Ballman9371dd22014-03-14 18:34:04 +00001919 for (const auto &I : D->captures()) {
Richard Smithf7514452014-10-30 21:02:37 +00001920 dumpChild([=] {
1921 OS << "capture";
1922 if (I.isByRef())
1923 OS << " byref";
1924 if (I.isNested())
1925 OS << " nested";
1926 if (I.getVariable()) {
1927 OS << ' ';
1928 dumpBareDeclRef(I.getVariable());
1929 }
1930 if (I.hasCopyExpr())
1931 dumpStmt(I.getCopyExpr());
1932 });
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001933 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001934 dumpStmt(D->getBody());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001935}
1936
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001937//===----------------------------------------------------------------------===//
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001938// Stmt dumping methods.
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001939//===----------------------------------------------------------------------===//
1940
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001941void ASTDumper::dumpStmt(const Stmt *S) {
Richard Smithf7514452014-10-30 21:02:37 +00001942 dumpChild([=] {
1943 if (!S) {
1944 ColorScope Color(*this, NullColor);
1945 OS << "<<<NULL>>>";
1946 return;
1947 }
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001948
Richard Smith01ccebf2018-01-05 21:31:07 +00001949 // Some statements have custom mechanisms for dumping their children.
Richard Smithf7514452014-10-30 21:02:37 +00001950 if (const DeclStmt *DS = dyn_cast<DeclStmt>(S)) {
1951 VisitDeclStmt(DS);
1952 return;
1953 }
Richard Smith01ccebf2018-01-05 21:31:07 +00001954 if (const GenericSelectionExpr *GSE = dyn_cast<GenericSelectionExpr>(S)) {
1955 VisitGenericSelectionExpr(GSE);
1956 return;
1957 }
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001958
Richard Smithf7514452014-10-30 21:02:37 +00001959 ConstStmtVisitor<ASTDumper>::Visit(S);
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001960
Benjamin Kramer642f1732015-07-02 21:03:14 +00001961 for (const Stmt *SubStmt : S->children())
1962 dumpStmt(SubStmt);
Richard Smithf7514452014-10-30 21:02:37 +00001963 });
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001964}
1965
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001966void ASTDumper::VisitStmt(const Stmt *Node) {
Richard Trieud215b8d2013-01-26 01:31:20 +00001967 {
1968 ColorScope Color(*this, StmtColor);
1969 OS << Node->getStmtClassName();
1970 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001971 dumpPointer(Node);
1972 dumpSourceRange(Node->getSourceRange());
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001973}
1974
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001975void ASTDumper::VisitDeclStmt(const DeclStmt *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001976 VisitStmt(Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001977 for (DeclStmt::const_decl_iterator I = Node->decl_begin(),
1978 E = Node->decl_end();
Richard Smithf7514452014-10-30 21:02:37 +00001979 I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001980 dumpDecl(*I);
Ted Kremenek433a4922007-12-12 06:59:42 +00001981}
1982
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001983void ASTDumper::VisitAttributedStmt(const AttributedStmt *Node) {
Alexander Kornienko5bc364e2013-01-07 17:53:08 +00001984 VisitStmt(Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001985 for (ArrayRef<const Attr *>::iterator I = Node->getAttrs().begin(),
1986 E = Node->getAttrs().end();
Richard Smithf7514452014-10-30 21:02:37 +00001987 I != E; ++I)
Alexander Kornienko5bc364e2013-01-07 17:53:08 +00001988 dumpAttr(*I);
1989}
1990
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001991void ASTDumper::VisitLabelStmt(const LabelStmt *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001992 VisitStmt(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001993 OS << " '" << Node->getName() << "'";
Chris Lattnercbe4f772007-08-08 22:51:59 +00001994}
1995
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001996void ASTDumper::VisitGotoStmt(const GotoStmt *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001997 VisitStmt(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001998 OS << " '" << Node->getLabel()->getName() << "'";
1999 dumpPointer(Node->getLabel());
Chris Lattnercbe4f772007-08-08 22:51:59 +00002000}
2001
Pavel Labath1ef83422013-09-04 14:35:00 +00002002void ASTDumper::VisitCXXCatchStmt(const CXXCatchStmt *Node) {
2003 VisitStmt(Node);
2004 dumpDecl(Node->getExceptionDecl());
2005}
2006
Alexey Bataev958b9e72016-03-31 09:30:50 +00002007void ASTDumper::VisitCapturedStmt(const CapturedStmt *Node) {
2008 VisitStmt(Node);
2009 dumpDecl(Node->getCapturedDecl());
2010}
2011
2012//===----------------------------------------------------------------------===//
2013// OpenMP dumping methods.
2014//===----------------------------------------------------------------------===//
2015
2016void ASTDumper::VisitOMPExecutableDirective(
2017 const OMPExecutableDirective *Node) {
2018 VisitStmt(Node);
2019 for (auto *C : Node->clauses()) {
2020 dumpChild([=] {
2021 if (!C) {
2022 ColorScope Color(*this, NullColor);
2023 OS << "<<<NULL>>> OMPClause";
2024 return;
2025 }
2026 {
2027 ColorScope Color(*this, AttrColor);
2028 StringRef ClauseName(getOpenMPClauseName(C->getClauseKind()));
2029 OS << "OMP" << ClauseName.substr(/*Start=*/0, /*N=*/1).upper()
2030 << ClauseName.drop_front() << "Clause";
2031 }
2032 dumpPointer(C);
2033 dumpSourceRange(SourceRange(C->getLocStart(), C->getLocEnd()));
2034 if (C->isImplicit())
2035 OS << " <implicit>";
2036 for (auto *S : C->children())
2037 dumpStmt(S);
2038 });
2039 }
2040}
2041
Chris Lattnercbe4f772007-08-08 22:51:59 +00002042//===----------------------------------------------------------------------===//
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002043// Expr dumping methods.
Chris Lattnercbe4f772007-08-08 22:51:59 +00002044//===----------------------------------------------------------------------===//
2045
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002046void ASTDumper::VisitExpr(const Expr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002047 VisitStmt(Node);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002048 dumpType(Node->getType());
2049
Richard Trieud215b8d2013-01-26 01:31:20 +00002050 {
2051 ColorScope Color(*this, ValueKindColor);
2052 switch (Node->getValueKind()) {
2053 case VK_RValue:
2054 break;
2055 case VK_LValue:
2056 OS << " lvalue";
2057 break;
2058 case VK_XValue:
2059 OS << " xvalue";
2060 break;
2061 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002062 }
2063
Richard Trieud215b8d2013-01-26 01:31:20 +00002064 {
2065 ColorScope Color(*this, ObjectKindColor);
2066 switch (Node->getObjectKind()) {
2067 case OK_Ordinary:
2068 break;
2069 case OK_BitField:
2070 OS << " bitfield";
2071 break;
2072 case OK_ObjCProperty:
2073 OS << " objcproperty";
2074 break;
2075 case OK_ObjCSubscript:
2076 OS << " objcsubscript";
2077 break;
2078 case OK_VectorComponent:
2079 OS << " vectorcomponent";
2080 break;
2081 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002082 }
Chris Lattnercbe4f772007-08-08 22:51:59 +00002083}
2084
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002085static void dumpBasePath(raw_ostream &OS, const CastExpr *Node) {
John McCallcf142162010-08-07 06:22:56 +00002086 if (Node->path_empty())
Anders Carlssona70cff62010-04-24 19:06:50 +00002087 return;
2088
2089 OS << " (";
2090 bool First = true;
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002091 for (CastExpr::path_const_iterator I = Node->path_begin(),
2092 E = Node->path_end();
2093 I != E; ++I) {
Anders Carlssona70cff62010-04-24 19:06:50 +00002094 const CXXBaseSpecifier *Base = *I;
2095 if (!First)
2096 OS << " -> ";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002097
Anders Carlssona70cff62010-04-24 19:06:50 +00002098 const CXXRecordDecl *RD =
2099 cast<CXXRecordDecl>(Base->getType()->getAs<RecordType>()->getDecl());
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002100
Anders Carlssona70cff62010-04-24 19:06:50 +00002101 if (Base->isVirtual())
2102 OS << "virtual ";
2103 OS << RD->getName();
2104 First = false;
2105 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002106
Anders Carlssona70cff62010-04-24 19:06:50 +00002107 OS << ')';
2108}
2109
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002110void ASTDumper::VisitCastExpr(const CastExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002111 VisitExpr(Node);
Richard Trieud215b8d2013-01-26 01:31:20 +00002112 OS << " <";
2113 {
2114 ColorScope Color(*this, CastColor);
2115 OS << Node->getCastKindName();
2116 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002117 dumpBasePath(OS, Node);
Anders Carlssona70cff62010-04-24 19:06:50 +00002118 OS << ">";
Anders Carlssond7923c62009-08-22 23:33:40 +00002119}
2120
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002121void ASTDumper::VisitDeclRefExpr(const DeclRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002122 VisitExpr(Node);
Ted Kremenek5f64ca82007-09-10 17:32:55 +00002123
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002124 OS << " ";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002125 dumpBareDeclRef(Node->getDecl());
Chandler Carruth8d26bb02011-05-01 23:48:14 +00002126 if (Node->getDecl() != Node->getFoundDecl()) {
2127 OS << " (";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002128 dumpBareDeclRef(Node->getFoundDecl());
Chandler Carruth8d26bb02011-05-01 23:48:14 +00002129 OS << ")";
2130 }
John McCall351762c2011-02-07 10:33:21 +00002131}
2132
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002133void ASTDumper::VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002134 VisitExpr(Node);
John McCall76d09942009-12-11 21:50:11 +00002135 OS << " (";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002136 if (!Node->requiresADL())
2137 OS << "no ";
Benjamin Kramerb11416d2010-04-17 09:33:03 +00002138 OS << "ADL) = '" << Node->getName() << '\'';
John McCall76d09942009-12-11 21:50:11 +00002139
2140 UnresolvedLookupExpr::decls_iterator
2141 I = Node->decls_begin(), E = Node->decls_end();
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002142 if (I == E)
2143 OS << " empty";
John McCall76d09942009-12-11 21:50:11 +00002144 for (; I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002145 dumpPointer(*I);
John McCall76d09942009-12-11 21:50:11 +00002146}
2147
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002148void ASTDumper::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002149 VisitExpr(Node);
Steve Naroff5d5efca2008-03-12 13:19:12 +00002150
Richard Trieud215b8d2013-01-26 01:31:20 +00002151 {
2152 ColorScope Color(*this, DeclKindNameColor);
2153 OS << " " << Node->getDecl()->getDeclKindName() << "Decl";
2154 }
2155 OS << "='" << *Node->getDecl() << "'";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002156 dumpPointer(Node->getDecl());
Steve Naroffb3424a92008-05-23 22:01:24 +00002157 if (Node->isFreeIvar())
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002158 OS << " isFreeIvar";
Steve Naroff5d5efca2008-03-12 13:19:12 +00002159}
2160
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002161void ASTDumper::VisitPredefinedExpr(const PredefinedExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002162 VisitExpr(Node);
Alexey Bataevec474782014-10-09 08:45:04 +00002163 OS << " " << PredefinedExpr::getIdentTypeName(Node->getIdentType());
Chris Lattnercbe4f772007-08-08 22:51:59 +00002164}
2165
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002166void ASTDumper::VisitCharacterLiteral(const CharacterLiteral *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002167 VisitExpr(Node);
Richard Trieud215b8d2013-01-26 01:31:20 +00002168 ColorScope Color(*this, ValueColor);
Richard Trieu364ee422011-11-03 23:56:23 +00002169 OS << " " << Node->getValue();
Chris Lattnercbe4f772007-08-08 22:51:59 +00002170}
2171
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002172void ASTDumper::VisitIntegerLiteral(const IntegerLiteral *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002173 VisitExpr(Node);
Chris Lattnercbe4f772007-08-08 22:51:59 +00002174
2175 bool isSigned = Node->getType()->isSignedIntegerType();
Richard Trieud215b8d2013-01-26 01:31:20 +00002176 ColorScope Color(*this, ValueColor);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002177 OS << " " << Node->getValue().toString(10, isSigned);
Chris Lattnercbe4f772007-08-08 22:51:59 +00002178}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002179
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002180void ASTDumper::VisitFloatingLiteral(const FloatingLiteral *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002181 VisitExpr(Node);
Richard Trieud215b8d2013-01-26 01:31:20 +00002182 ColorScope Color(*this, ValueColor);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002183 OS << " " << Node->getValueAsApproximateDouble();
Chris Lattnercbe4f772007-08-08 22:51:59 +00002184}
Chris Lattner1c20a172007-08-26 03:42:43 +00002185
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002186void ASTDumper::VisitStringLiteral(const StringLiteral *Str) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002187 VisitExpr(Str);
Richard Trieud215b8d2013-01-26 01:31:20 +00002188 ColorScope Color(*this, ValueColor);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002189 OS << " ";
Richard Trieudc355912012-06-13 20:25:24 +00002190 Str->outputString(OS);
Chris Lattnercbe4f772007-08-08 22:51:59 +00002191}
Chris Lattner84ca3762007-08-30 01:00:35 +00002192
Richard Smithf0514962014-06-03 08:24:28 +00002193void ASTDumper::VisitInitListExpr(const InitListExpr *ILE) {
2194 VisitExpr(ILE);
2195 if (auto *Filler = ILE->getArrayFiller()) {
Richard Smithf7514452014-10-30 21:02:37 +00002196 dumpChild([=] {
2197 OS << "array filler";
2198 dumpStmt(Filler);
2199 });
Richard Smithf0514962014-06-03 08:24:28 +00002200 }
2201 if (auto *Field = ILE->getInitializedFieldInUnion()) {
2202 OS << " field ";
2203 dumpBareDeclRef(Field);
2204 }
2205}
2206
Richard Smith410306b2016-12-12 02:53:20 +00002207void ASTDumper::VisitArrayInitLoopExpr(const ArrayInitLoopExpr *E) {
2208 VisitExpr(E);
2209}
2210
2211void ASTDumper::VisitArrayInitIndexExpr(const ArrayInitIndexExpr *E) {
2212 VisitExpr(E);
2213}
2214
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002215void ASTDumper::VisitUnaryOperator(const UnaryOperator *Node) {
Aaron Ballmana5038552018-01-09 13:07:03 +00002216 VisitExpr(Node);
2217 OS << " " << (Node->isPostfix() ? "postfix" : "prefix")
2218 << " '" << UnaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
2219 if (!Node->canOverflow())
2220 OS << " cannot overflow";
2221}
2222
2223void ASTDumper::VisitUnaryExprOrTypeTraitExpr(
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002224 const UnaryExprOrTypeTraitExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002225 VisitExpr(Node);
Peter Collingbournee190dee2011-03-11 19:24:49 +00002226 switch(Node->getKind()) {
2227 case UETT_SizeOf:
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002228 OS << " sizeof";
Peter Collingbournee190dee2011-03-11 19:24:49 +00002229 break;
2230 case UETT_AlignOf:
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002231 OS << " alignof";
Peter Collingbournee190dee2011-03-11 19:24:49 +00002232 break;
2233 case UETT_VecStep:
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002234 OS << " vec_step";
Peter Collingbournee190dee2011-03-11 19:24:49 +00002235 break;
Alexey Bataev00396512015-07-02 03:40:19 +00002236 case UETT_OpenMPRequiredSimdAlign:
2237 OS << " __builtin_omp_required_simd_align";
2238 break;
Peter Collingbournee190dee2011-03-11 19:24:49 +00002239 }
Sebastian Redl6f282892008-11-11 17:56:53 +00002240 if (Node->isArgumentType())
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002241 dumpType(Node->getArgumentType());
Chris Lattnercbe4f772007-08-08 22:51:59 +00002242}
Chris Lattnerdb3b3ff2007-08-09 17:35:30 +00002243
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002244void ASTDumper::VisitMemberExpr(const MemberExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002245 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002246 OS << " " << (Node->isArrow() ? "->" : ".") << *Node->getMemberDecl();
2247 dumpPointer(Node->getMemberDecl());
Chris Lattnercbe4f772007-08-08 22:51:59 +00002248}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002249
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002250void ASTDumper::VisitExtVectorElementExpr(const ExtVectorElementExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002251 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002252 OS << " " << Node->getAccessor().getNameStart();
Chris Lattnercbe4f772007-08-08 22:51:59 +00002253}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002254
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002255void ASTDumper::VisitBinaryOperator(const BinaryOperator *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002256 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002257 OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
Chris Lattner86928112007-08-25 02:00:02 +00002258}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002259
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002260void ASTDumper::VisitCompoundAssignOperator(
2261 const CompoundAssignOperator *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002262 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002263 OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode())
2264 << "' ComputeLHSTy=";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002265 dumpBareType(Node->getComputationLHSType());
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002266 OS << " ComputeResultTy=";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002267 dumpBareType(Node->getComputationResultType());
Chris Lattnercbe4f772007-08-08 22:51:59 +00002268}
Chris Lattnercbe4f772007-08-08 22:51:59 +00002269
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002270void ASTDumper::VisitBlockExpr(const BlockExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002271 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002272 dumpDecl(Node->getBlockDecl());
John McCall351762c2011-02-07 10:33:21 +00002273}
2274
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002275void ASTDumper::VisitOpaqueValueExpr(const OpaqueValueExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002276 VisitExpr(Node);
John McCallfe96e0b2011-11-06 09:01:30 +00002277
Richard Smithf7514452014-10-30 21:02:37 +00002278 if (Expr *Source = Node->getSourceExpr())
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002279 dumpStmt(Source);
John McCallfe96e0b2011-11-06 09:01:30 +00002280}
2281
Richard Smith01ccebf2018-01-05 21:31:07 +00002282void ASTDumper::VisitGenericSelectionExpr(const GenericSelectionExpr *E) {
2283 VisitExpr(E);
2284 if (E->isResultDependent())
2285 OS << " result_dependent";
2286 dumpStmt(E->getControllingExpr());
2287 dumpTypeAsChild(E->getControllingExpr()->getType()); // FIXME: remove
2288
2289 for (unsigned I = 0, N = E->getNumAssocs(); I != N; ++I) {
2290 dumpChild([=] {
2291 if (const TypeSourceInfo *TSI = E->getAssocTypeSourceInfo(I)) {
2292 OS << "case ";
2293 dumpType(TSI->getType());
2294 } else {
2295 OS << "default";
2296 }
2297
2298 if (!E->isResultDependent() && E->getResultIndex() == I)
2299 OS << " selected";
2300
2301 if (const TypeSourceInfo *TSI = E->getAssocTypeSourceInfo(I))
2302 dumpTypeAsChild(TSI->getType());
2303 dumpStmt(E->getAssocExpr(I));
2304 });
2305 }
2306}
2307
Chris Lattnercbe4f772007-08-08 22:51:59 +00002308// GNU extensions.
2309
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002310void ASTDumper::VisitAddrLabelExpr(const AddrLabelExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002311 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002312 OS << " " << Node->getLabel()->getName();
2313 dumpPointer(Node->getLabel());
Chris Lattnercbe4f772007-08-08 22:51:59 +00002314}
2315
Chris Lattner8f184b12007-08-09 18:03:18 +00002316//===----------------------------------------------------------------------===//
2317// C++ Expressions
2318//===----------------------------------------------------------------------===//
Chris Lattnercbe4f772007-08-08 22:51:59 +00002319
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002320void ASTDumper::VisitCXXNamedCastExpr(const CXXNamedCastExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002321 VisitExpr(Node);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002322 OS << " " << Node->getCastName()
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002323 << "<" << Node->getTypeAsWritten().getAsString() << ">"
Anders Carlssona70cff62010-04-24 19:06:50 +00002324 << " <" << Node->getCastKindName();
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002325 dumpBasePath(OS, Node);
Anders Carlssona70cff62010-04-24 19:06:50 +00002326 OS << ">";
Chris Lattnercbe4f772007-08-08 22:51:59 +00002327}
2328
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002329void ASTDumper::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002330 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002331 OS << " " << (Node->getValue() ? "true" : "false");
Chris Lattnercbe4f772007-08-08 22:51:59 +00002332}
2333
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002334void ASTDumper::VisitCXXThisExpr(const CXXThisExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002335 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002336 OS << " this";
Douglas Gregor8ea1f532008-11-04 14:56:14 +00002337}
2338
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002339void ASTDumper::VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002340 VisitExpr(Node);
Eli Friedman29538892011-09-02 17:38:59 +00002341 OS << " functional cast to " << Node->getTypeAsWritten().getAsString()
2342 << " <" << Node->getCastKindName() << ">";
Douglas Gregore200adc2008-10-27 19:41:14 +00002343}
2344
Richard Smith39eca9b2017-08-23 22:12:08 +00002345void ASTDumper::VisitCXXUnresolvedConstructExpr(
2346 const CXXUnresolvedConstructExpr *Node) {
2347 VisitExpr(Node);
2348 dumpType(Node->getTypeAsWritten());
2349 if (Node->isListInitialization())
2350 OS << " list";
2351}
2352
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002353void ASTDumper::VisitCXXConstructExpr(const CXXConstructExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002354 VisitExpr(Node);
John McCalleba90cd2010-02-02 19:03:45 +00002355 CXXConstructorDecl *Ctor = Node->getConstructor();
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002356 dumpType(Ctor->getType());
Anders Carlsson073846832009-08-12 00:21:52 +00002357 if (Node->isElidable())
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002358 OS << " elidable";
Richard Smith39eca9b2017-08-23 22:12:08 +00002359 if (Node->isListInitialization())
2360 OS << " list";
2361 if (Node->isStdInitListInitialization())
2362 OS << " std::initializer_list";
John McCall85370042010-08-07 06:38:55 +00002363 if (Node->requiresZeroInitialization())
2364 OS << " zeroing";
Anders Carlsson073846832009-08-12 00:21:52 +00002365}
2366
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002367void ASTDumper::VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002368 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002369 OS << " ";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002370 dumpCXXTemporary(Node->getTemporary());
Anders Carlsson073846832009-08-12 00:21:52 +00002371}
2372
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002373void ASTDumper::VisitCXXNewExpr(const CXXNewExpr *Node) {
2374 VisitExpr(Node);
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002375 if (Node->isGlobalNew())
Reid Kleckner461c0c62015-03-19 18:47:47 +00002376 OS << " global";
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002377 if (Node->isArray())
Reid Kleckner461c0c62015-03-19 18:47:47 +00002378 OS << " array";
2379 if (Node->getOperatorNew()) {
2380 OS << ' ';
2381 dumpBareDeclRef(Node->getOperatorNew());
2382 }
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002383 // We could dump the deallocation function used in case of error, but it's
2384 // usually not that interesting.
2385}
2386
2387void ASTDumper::VisitCXXDeleteExpr(const CXXDeleteExpr *Node) {
2388 VisitExpr(Node);
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002389 if (Node->isGlobalDelete())
Reid Kleckner461c0c62015-03-19 18:47:47 +00002390 OS << " global";
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002391 if (Node->isArrayForm())
Reid Kleckner461c0c62015-03-19 18:47:47 +00002392 OS << " array";
2393 if (Node->getOperatorDelete()) {
2394 OS << ' ';
2395 dumpBareDeclRef(Node->getOperatorDelete());
2396 }
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002397}
2398
Richard Smithe6c01442013-06-05 00:46:14 +00002399void
2400ASTDumper::VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *Node) {
2401 VisitExpr(Node);
2402 if (const ValueDecl *VD = Node->getExtendingDecl()) {
2403 OS << " extended by ";
2404 dumpBareDeclRef(VD);
2405 }
2406}
2407
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002408void ASTDumper::VisitExprWithCleanups(const ExprWithCleanups *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002409 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002410 for (unsigned i = 0, e = Node->getNumObjects(); i != e; ++i)
2411 dumpDeclRef(Node->getObject(i), "cleanup");
Anders Carlsson073846832009-08-12 00:21:52 +00002412}
2413
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002414void ASTDumper::dumpCXXTemporary(const CXXTemporary *Temporary) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002415 OS << "(CXXTemporary";
2416 dumpPointer(Temporary);
2417 OS << ")";
Anders Carlsson073846832009-08-12 00:21:52 +00002418}
2419
Serge Pavlov6b926032015-02-16 19:58:41 +00002420void ASTDumper::VisitSizeOfPackExpr(const SizeOfPackExpr *Node) {
2421 VisitExpr(Node);
2422 dumpPointer(Node->getPack());
2423 dumpName(Node->getPack());
Richard Smithd784e682015-09-23 21:41:42 +00002424 if (Node->isPartiallySubstituted())
2425 for (const auto &A : Node->getPartialArguments())
2426 dumpTemplateArgument(A);
Serge Pavlov6b926032015-02-16 19:58:41 +00002427}
2428
Alex Lorenzddbe0f52016-11-09 14:02:18 +00002429void ASTDumper::VisitCXXDependentScopeMemberExpr(
2430 const CXXDependentScopeMemberExpr *Node) {
2431 VisitExpr(Node);
2432 OS << " " << (Node->isArrow() ? "->" : ".") << Node->getMember();
2433}
Serge Pavlov6b926032015-02-16 19:58:41 +00002434
Anders Carlsson76f4a902007-08-21 17:43:55 +00002435//===----------------------------------------------------------------------===//
2436// Obj-C Expressions
2437//===----------------------------------------------------------------------===//
2438
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002439void ASTDumper::VisitObjCMessageExpr(const ObjCMessageExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002440 VisitExpr(Node);
Aaron Ballmanb190f972014-01-03 17:59:55 +00002441 OS << " selector=";
2442 Node->getSelector().print(OS);
Douglas Gregor9a129192010-04-21 00:45:42 +00002443 switch (Node->getReceiverKind()) {
2444 case ObjCMessageExpr::Instance:
2445 break;
2446
2447 case ObjCMessageExpr::Class:
2448 OS << " class=";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002449 dumpBareType(Node->getClassReceiver());
Douglas Gregor9a129192010-04-21 00:45:42 +00002450 break;
2451
2452 case ObjCMessageExpr::SuperInstance:
2453 OS << " super (instance)";
2454 break;
2455
2456 case ObjCMessageExpr::SuperClass:
2457 OS << " super (class)";
2458 break;
2459 }
Ted Kremenek36748da2008-02-29 22:04:05 +00002460}
2461
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002462void ASTDumper::VisitObjCBoxedExpr(const ObjCBoxedExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002463 VisitExpr(Node);
Richard Trieu4b259c82016-06-09 22:03:04 +00002464 if (auto *BoxingMethod = Node->getBoxingMethod()) {
2465 OS << " selector=";
2466 BoxingMethod->getSelector().print(OS);
2467 }
Argyrios Kyrtzidis9dd40892012-05-10 20:02:31 +00002468}
2469
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002470void ASTDumper::VisitObjCAtCatchStmt(const ObjCAtCatchStmt *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002471 VisitStmt(Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002472 if (const VarDecl *CatchParam = Node->getCatchParamDecl())
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002473 dumpDecl(CatchParam);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002474 else
Douglas Gregor96c79492010-04-23 22:50:49 +00002475 OS << " catch all";
Douglas Gregor96c79492010-04-23 22:50:49 +00002476}
2477
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002478void ASTDumper::VisitObjCEncodeExpr(const ObjCEncodeExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002479 VisitExpr(Node);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002480 dumpType(Node->getEncodedType());
Anders Carlssonc5a81eb2007-08-22 15:14:15 +00002481}
2482
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002483void ASTDumper::VisitObjCSelectorExpr(const ObjCSelectorExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002484 VisitExpr(Node);
Mike Stump11289f42009-09-09 15:08:12 +00002485
Aaron Ballmanb190f972014-01-03 17:59:55 +00002486 OS << " ";
2487 Node->getSelector().print(OS);
Fariborz Jahanian4bef4622007-10-16 20:40:23 +00002488}
2489
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002490void ASTDumper::VisitObjCProtocolExpr(const ObjCProtocolExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002491 VisitExpr(Node);
Mike Stump11289f42009-09-09 15:08:12 +00002492
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002493 OS << ' ' << *Node->getProtocol();
Fariborz Jahaniana32aaef2007-10-17 16:58:11 +00002494}
Daniel Dunbar4b8c6db2008-08-30 05:35:15 +00002495
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002496void ASTDumper::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002497 VisitExpr(Node);
John McCallb7bd14f2010-12-02 01:19:52 +00002498 if (Node->isImplicitProperty()) {
Fariborz Jahanian0f0b3022010-12-22 19:46:35 +00002499 OS << " Kind=MethodRef Getter=\"";
2500 if (Node->getImplicitPropertyGetter())
Aaron Ballmanb190f972014-01-03 17:59:55 +00002501 Node->getImplicitPropertyGetter()->getSelector().print(OS);
Fariborz Jahanian0f0b3022010-12-22 19:46:35 +00002502 else
2503 OS << "(null)";
2504
2505 OS << "\" Setter=\"";
John McCallb7bd14f2010-12-02 01:19:52 +00002506 if (ObjCMethodDecl *Setter = Node->getImplicitPropertySetter())
Aaron Ballmanb190f972014-01-03 17:59:55 +00002507 Setter->getSelector().print(OS);
John McCallb7bd14f2010-12-02 01:19:52 +00002508 else
2509 OS << "(null)";
2510 OS << "\"";
2511 } else {
Benjamin Kramerb89514a2011-10-14 18:45:37 +00002512 OS << " Kind=PropertyRef Property=\"" << *Node->getExplicitProperty() <<'"';
John McCallb7bd14f2010-12-02 01:19:52 +00002513 }
Fariborz Jahanian8a1810f2008-11-22 18:39:36 +00002514
Fariborz Jahanian681c0752010-10-14 16:04:05 +00002515 if (Node->isSuperReceiver())
2516 OS << " super";
Argyrios Kyrtzidisab468b02012-03-30 00:19:18 +00002517
2518 OS << " Messaging=";
2519 if (Node->isMessagingGetter() && Node->isMessagingSetter())
2520 OS << "Getter&Setter";
2521 else if (Node->isMessagingGetter())
2522 OS << "Getter";
2523 else if (Node->isMessagingSetter())
2524 OS << "Setter";
Douglas Gregor8ea1f532008-11-04 14:56:14 +00002525}
2526
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002527void ASTDumper::VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002528 VisitExpr(Node);
Ted Kremeneke65b0862012-03-06 20:05:56 +00002529 if (Node->isArraySubscriptRefExpr())
2530 OS << " Kind=ArraySubscript GetterForArray=\"";
2531 else
2532 OS << " Kind=DictionarySubscript GetterForDictionary=\"";
2533 if (Node->getAtIndexMethodDecl())
Aaron Ballmanb190f972014-01-03 17:59:55 +00002534 Node->getAtIndexMethodDecl()->getSelector().print(OS);
Ted Kremeneke65b0862012-03-06 20:05:56 +00002535 else
2536 OS << "(null)";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002537
Ted Kremeneke65b0862012-03-06 20:05:56 +00002538 if (Node->isArraySubscriptRefExpr())
2539 OS << "\" SetterForArray=\"";
2540 else
2541 OS << "\" SetterForDictionary=\"";
2542 if (Node->setAtIndexMethodDecl())
Aaron Ballmanb190f972014-01-03 17:59:55 +00002543 Node->setAtIndexMethodDecl()->getSelector().print(OS);
Ted Kremeneke65b0862012-03-06 20:05:56 +00002544 else
2545 OS << "(null)";
2546}
2547
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002548void ASTDumper::VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002549 VisitExpr(Node);
Ted Kremeneke65b0862012-03-06 20:05:56 +00002550 OS << " " << (Node->getValue() ? "__objc_yes" : "__objc_no");
2551}
2552
Chris Lattnercbe4f772007-08-08 22:51:59 +00002553//===----------------------------------------------------------------------===//
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002554// Comments
2555//===----------------------------------------------------------------------===//
2556
2557const char *ASTDumper::getCommandName(unsigned CommandID) {
2558 if (Traits)
2559 return Traits->getCommandInfo(CommandID)->Name;
2560 const CommandInfo *Info = CommandTraits::getBuiltinCommandInfo(CommandID);
2561 if (Info)
2562 return Info->Name;
2563 return "<not a builtin command>";
2564}
2565
2566void ASTDumper::dumpFullComment(const FullComment *C) {
2567 if (!C)
2568 return;
2569
2570 FC = C;
2571 dumpComment(C);
Craig Topper36250ad2014-05-12 05:36:57 +00002572 FC = nullptr;
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002573}
2574
2575void ASTDumper::dumpComment(const Comment *C) {
Richard Smithf7514452014-10-30 21:02:37 +00002576 dumpChild([=] {
2577 if (!C) {
2578 ColorScope Color(*this, NullColor);
2579 OS << "<<<NULL>>>";
2580 return;
2581 }
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002582
Richard Smithf7514452014-10-30 21:02:37 +00002583 {
2584 ColorScope Color(*this, CommentColor);
2585 OS << C->getCommentKindName();
2586 }
2587 dumpPointer(C);
2588 dumpSourceRange(C->getSourceRange());
2589 ConstCommentVisitor<ASTDumper>::visit(C);
2590 for (Comment::child_iterator I = C->child_begin(), E = C->child_end();
2591 I != E; ++I)
2592 dumpComment(*I);
2593 });
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002594}
2595
2596void ASTDumper::visitTextComment(const TextComment *C) {
2597 OS << " Text=\"" << C->getText() << "\"";
2598}
2599
2600void ASTDumper::visitInlineCommandComment(const InlineCommandComment *C) {
2601 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\"";
2602 switch (C->getRenderKind()) {
2603 case InlineCommandComment::RenderNormal:
2604 OS << " RenderNormal";
2605 break;
2606 case InlineCommandComment::RenderBold:
2607 OS << " RenderBold";
2608 break;
2609 case InlineCommandComment::RenderMonospaced:
2610 OS << " RenderMonospaced";
2611 break;
2612 case InlineCommandComment::RenderEmphasized:
2613 OS << " RenderEmphasized";
2614 break;
2615 }
2616
2617 for (unsigned i = 0, e = C->getNumArgs(); i != e; ++i)
2618 OS << " Arg[" << i << "]=\"" << C->getArgText(i) << "\"";
2619}
2620
2621void ASTDumper::visitHTMLStartTagComment(const HTMLStartTagComment *C) {
2622 OS << " Name=\"" << C->getTagName() << "\"";
2623 if (C->getNumAttrs() != 0) {
2624 OS << " Attrs: ";
2625 for (unsigned i = 0, e = C->getNumAttrs(); i != e; ++i) {
2626 const HTMLStartTagComment::Attribute &Attr = C->getAttr(i);
2627 OS << " \"" << Attr.Name << "=\"" << Attr.Value << "\"";
2628 }
2629 }
2630 if (C->isSelfClosing())
2631 OS << " SelfClosing";
2632}
2633
2634void ASTDumper::visitHTMLEndTagComment(const HTMLEndTagComment *C) {
2635 OS << " Name=\"" << C->getTagName() << "\"";
2636}
2637
2638void ASTDumper::visitBlockCommandComment(const BlockCommandComment *C) {
2639 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\"";
2640 for (unsigned i = 0, e = C->getNumArgs(); i != e; ++i)
2641 OS << " Arg[" << i << "]=\"" << C->getArgText(i) << "\"";
2642}
2643
2644void ASTDumper::visitParamCommandComment(const ParamCommandComment *C) {
2645 OS << " " << ParamCommandComment::getDirectionAsString(C->getDirection());
2646
2647 if (C->isDirectionExplicit())
2648 OS << " explicitly";
2649 else
2650 OS << " implicitly";
2651
2652 if (C->hasParamName()) {
2653 if (C->isParamIndexValid())
2654 OS << " Param=\"" << C->getParamName(FC) << "\"";
2655 else
2656 OS << " Param=\"" << C->getParamNameAsWritten() << "\"";
2657 }
2658
Dmitri Gribenkodbff5c72014-03-19 14:03:47 +00002659 if (C->isParamIndexValid() && !C->isVarArgParam())
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002660 OS << " ParamIndex=" << C->getParamIndex();
2661}
2662
2663void ASTDumper::visitTParamCommandComment(const TParamCommandComment *C) {
2664 if (C->hasParamName()) {
2665 if (C->isPositionValid())
2666 OS << " Param=\"" << C->getParamName(FC) << "\"";
2667 else
2668 OS << " Param=\"" << C->getParamNameAsWritten() << "\"";
2669 }
2670
2671 if (C->isPositionValid()) {
2672 OS << " Position=<";
2673 for (unsigned i = 0, e = C->getDepth(); i != e; ++i) {
2674 OS << C->getIndex(i);
2675 if (i != e - 1)
2676 OS << ", ";
2677 }
2678 OS << ">";
2679 }
2680}
2681
2682void ASTDumper::visitVerbatimBlockComment(const VerbatimBlockComment *C) {
2683 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\""
2684 " CloseName=\"" << C->getCloseName() << "\"";
2685}
2686
2687void ASTDumper::visitVerbatimBlockLineComment(
2688 const VerbatimBlockLineComment *C) {
2689 OS << " Text=\"" << C->getText() << "\"";
2690}
2691
2692void ASTDumper::visitVerbatimLineComment(const VerbatimLineComment *C) {
2693 OS << " Text=\"" << C->getText() << "\"";
2694}
2695
2696//===----------------------------------------------------------------------===//
Richard Smithd5e7ff82014-10-31 01:17:45 +00002697// Type method implementations
2698//===----------------------------------------------------------------------===//
2699
2700void QualType::dump(const char *msg) const {
2701 if (msg)
2702 llvm::errs() << msg << ": ";
2703 dump();
2704}
2705
Richard Smith14d04842016-11-02 23:57:18 +00002706LLVM_DUMP_METHOD void QualType::dump() const { dump(llvm::errs()); }
2707
2708LLVM_DUMP_METHOD void QualType::dump(llvm::raw_ostream &OS) const {
2709 ASTDumper Dumper(OS, nullptr, nullptr);
Richard Smithd5e7ff82014-10-31 01:17:45 +00002710 Dumper.dumpTypeAsChild(*this);
2711}
2712
Richard Smith14d04842016-11-02 23:57:18 +00002713LLVM_DUMP_METHOD void Type::dump() const { dump(llvm::errs()); }
2714
2715LLVM_DUMP_METHOD void Type::dump(llvm::raw_ostream &OS) const {
2716 QualType(this, 0).dump(OS);
2717}
Richard Smithd5e7ff82014-10-31 01:17:45 +00002718
2719//===----------------------------------------------------------------------===//
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002720// Decl method implementations
2721//===----------------------------------------------------------------------===//
2722
Alp Tokeref6b0072014-01-04 13:47:14 +00002723LLVM_DUMP_METHOD void Decl::dump() const { dump(llvm::errs()); }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002724
Richard Smith3a36ac12017-03-09 22:00:01 +00002725LLVM_DUMP_METHOD void Decl::dump(raw_ostream &OS, bool Deserialize) const {
Aaron Ballman8c208282017-12-21 21:42:42 +00002726 const ASTContext &Ctx = getASTContext();
2727 const SourceManager &SM = Ctx.getSourceManager();
2728 ASTDumper P(OS, &Ctx.getCommentCommandTraits(), &SM,
2729 SM.getDiagnostics().getShowColors(), Ctx.getPrintingPolicy());
Richard Smith3a36ac12017-03-09 22:00:01 +00002730 P.setDeserialize(Deserialize);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002731 P.dumpDecl(this);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002732}
2733
Alp Tokeref6b0072014-01-04 13:47:14 +00002734LLVM_DUMP_METHOD void Decl::dumpColor() const {
Aaron Ballman8c208282017-12-21 21:42:42 +00002735 const ASTContext &Ctx = getASTContext();
2736 ASTDumper P(llvm::errs(), &Ctx.getCommentCommandTraits(),
2737 &Ctx.getSourceManager(), /*ShowColors*/ true,
2738 Ctx.getPrintingPolicy());
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002739 P.dumpDecl(this);
Richard Trieud215b8d2013-01-26 01:31:20 +00002740}
Richard Smith33937e72013-06-22 21:49:40 +00002741
Alp Tokeref6b0072014-01-04 13:47:14 +00002742LLVM_DUMP_METHOD void DeclContext::dumpLookups() const {
Richard Smith6ea05822013-06-24 01:45:33 +00002743 dumpLookups(llvm::errs());
2744}
2745
Richard Smith35f986d2014-08-11 22:11:07 +00002746LLVM_DUMP_METHOD void DeclContext::dumpLookups(raw_ostream &OS,
Richard Smith3a36ac12017-03-09 22:00:01 +00002747 bool DumpDecls,
2748 bool Deserialize) const {
Richard Smith33937e72013-06-22 21:49:40 +00002749 const DeclContext *DC = this;
2750 while (!DC->isTranslationUnit())
2751 DC = DC->getParent();
2752 ASTContext &Ctx = cast<TranslationUnitDecl>(DC)->getASTContext();
Aaron Ballman8c208282017-12-21 21:42:42 +00002753 const SourceManager &SM = Ctx.getSourceManager();
2754 ASTDumper P(OS, &Ctx.getCommentCommandTraits(), &Ctx.getSourceManager(),
2755 SM.getDiagnostics().getShowColors(), Ctx.getPrintingPolicy());
Richard Smith3a36ac12017-03-09 22:00:01 +00002756 P.setDeserialize(Deserialize);
Richard Smith35f986d2014-08-11 22:11:07 +00002757 P.dumpLookups(this, DumpDecls);
Richard Smith33937e72013-06-22 21:49:40 +00002758}
2759
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002760//===----------------------------------------------------------------------===//
Chris Lattnercbe4f772007-08-08 22:51:59 +00002761// Stmt method implementations
2762//===----------------------------------------------------------------------===//
2763
Alp Tokeref6b0072014-01-04 13:47:14 +00002764LLVM_DUMP_METHOD void Stmt::dump(SourceManager &SM) const {
Argyrios Kyrtzidisc049f752010-08-09 10:54:31 +00002765 dump(llvm::errs(), SM);
2766}
2767
Alp Tokeref6b0072014-01-04 13:47:14 +00002768LLVM_DUMP_METHOD void Stmt::dump(raw_ostream &OS, SourceManager &SM) const {
Craig Topper36250ad2014-05-12 05:36:57 +00002769 ASTDumper P(OS, nullptr, &SM);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002770 P.dumpStmt(this);
Chris Lattner779d5d92007-08-30 00:40:08 +00002771}
2772
Faisal Vali2da8ed92015-03-22 13:35:56 +00002773LLVM_DUMP_METHOD void Stmt::dump(raw_ostream &OS) const {
2774 ASTDumper P(OS, nullptr, nullptr);
2775 P.dumpStmt(this);
2776}
2777
Alp Tokeref6b0072014-01-04 13:47:14 +00002778LLVM_DUMP_METHOD void Stmt::dump() const {
Craig Topper36250ad2014-05-12 05:36:57 +00002779 ASTDumper P(llvm::errs(), nullptr, nullptr);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002780 P.dumpStmt(this);
Chris Lattnercbe4f772007-08-08 22:51:59 +00002781}
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002782
Alp Tokeref6b0072014-01-04 13:47:14 +00002783LLVM_DUMP_METHOD void Stmt::dumpColor() const {
Craig Topper36250ad2014-05-12 05:36:57 +00002784 ASTDumper P(llvm::errs(), nullptr, nullptr, /*ShowColors*/true);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002785 P.dumpStmt(this);
Richard Trieud215b8d2013-01-26 01:31:20 +00002786}
2787
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002788//===----------------------------------------------------------------------===//
2789// Comment method implementations
2790//===----------------------------------------------------------------------===//
2791
Craig Topper36250ad2014-05-12 05:36:57 +00002792LLVM_DUMP_METHOD void Comment::dump() const {
2793 dump(llvm::errs(), nullptr, nullptr);
2794}
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002795
Alp Tokeref6b0072014-01-04 13:47:14 +00002796LLVM_DUMP_METHOD void Comment::dump(const ASTContext &Context) const {
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002797 dump(llvm::errs(), &Context.getCommentCommandTraits(),
2798 &Context.getSourceManager());
2799}
2800
Alexander Kornienko00911f12013-01-15 12:20:21 +00002801void Comment::dump(raw_ostream &OS, const CommandTraits *Traits,
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002802 const SourceManager *SM) const {
2803 const FullComment *FC = dyn_cast<FullComment>(this);
2804 ASTDumper D(OS, Traits, SM);
2805 D.dumpFullComment(FC);
2806}
Richard Trieud215b8d2013-01-26 01:31:20 +00002807
Alp Tokeref6b0072014-01-04 13:47:14 +00002808LLVM_DUMP_METHOD void Comment::dumpColor() const {
Richard Trieud215b8d2013-01-26 01:31:20 +00002809 const FullComment *FC = dyn_cast<FullComment>(this);
Craig Topper36250ad2014-05-12 05:36:57 +00002810 ASTDumper D(llvm::errs(), nullptr, nullptr, /*ShowColors*/true);
Richard Trieud215b8d2013-01-26 01:31:20 +00002811 D.dumpFullComment(FC);
2812}