blob: b92df75520f59d61f306acb12e78d4ff8b19ea40 [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
Richard Smithf7514452014-10-30 21:02:37 +0000102 /// Pending[i] is an action to dump an entity at level i.
103 llvm::SmallVector<std::function<void(bool isLastChild)>, 32> Pending;
Richard Trieude5cc7d2013-01-31 01:44:26 +0000104
Richard Smith3a36ac12017-03-09 22:00:01 +0000105 /// Indicates whether we should trigger deserialization of nodes that had
106 /// not already been loaded.
107 bool Deserialize = false;
108
Richard Smithf7514452014-10-30 21:02:37 +0000109 /// Indicates whether we're at the top level.
Richard Smith3a36ac12017-03-09 22:00:01 +0000110 bool TopLevel = true;
Richard Trieude5cc7d2013-01-31 01:44:26 +0000111
Richard Smithf7514452014-10-30 21:02:37 +0000112 /// Indicates if we're handling the first child after entering a new depth.
Richard Smith3a36ac12017-03-09 22:00:01 +0000113 bool FirstChild = true;
Richard Smithf7514452014-10-30 21:02:37 +0000114
115 /// Prefix for currently-being-dumped entity.
116 std::string Prefix;
Richard Trieude5cc7d2013-01-31 01:44:26 +0000117
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000118 /// Keep track of the last location we print out so that we can
119 /// print out deltas from then on out.
Richard Smith3a36ac12017-03-09 22:00:01 +0000120 const char *LastLocFilename = "";
121 unsigned LastLocLine = ~0U;
Douglas Gregor7de59662009-05-29 20:38:28 +0000122
Alexander Kornienkoebc17b52013-01-14 14:07:11 +0000123 /// The \c FullComment parent of the comment being dumped.
Richard Smith3a36ac12017-03-09 22:00:01 +0000124 const FullComment *FC = nullptr;
Alexander Kornienkoebc17b52013-01-14 14:07:11 +0000125
Richard Trieud215b8d2013-01-26 01:31:20 +0000126 bool ShowColors;
127
Richard Smithf7514452014-10-30 21:02:37 +0000128 /// Dump a child of the current node.
129 template<typename Fn> void dumpChild(Fn doDumpChild) {
130 // If we're at the top level, there's nothing interesting to do; just
131 // run the dumper.
132 if (TopLevel) {
133 TopLevel = false;
134 doDumpChild();
135 while (!Pending.empty()) {
136 Pending.back()(true);
137 Pending.pop_back();
138 }
139 Prefix.clear();
140 OS << "\n";
141 TopLevel = true;
142 return;
Manuel Klimek874030e2012-11-07 00:33:12 +0000143 }
Richard Smithf7514452014-10-30 21:02:37 +0000144
145 const FullComment *OrigFC = FC;
146 auto dumpWithIndent = [this, doDumpChild, OrigFC](bool isLastChild) {
147 // Print out the appropriate tree structure and work out the prefix for
148 // children of this node. For instance:
149 //
150 // A Prefix = ""
151 // |-B Prefix = "| "
152 // | `-C Prefix = "| "
153 // `-D Prefix = " "
154 // |-E Prefix = " | "
155 // `-F Prefix = " "
156 // G Prefix = ""
157 //
158 // Note that the first level gets no prefix.
159 {
160 OS << '\n';
161 ColorScope Color(*this, IndentColor);
162 OS << Prefix << (isLastChild ? '`' : '|') << '-';
NAKAMURA Takumic73e4022014-10-31 00:30:37 +0000163 this->Prefix.push_back(isLastChild ? ' ' : '|');
164 this->Prefix.push_back(' ');
Richard Smithf7514452014-10-30 21:02:37 +0000165 }
166
167 FirstChild = true;
168 unsigned Depth = Pending.size();
169
170 FC = OrigFC;
171 doDumpChild();
172
173 // If any children are left, they're the last at their nesting level.
174 // Dump those ones out now.
175 while (Depth < Pending.size()) {
176 Pending.back()(true);
NAKAMURA Takumic73e4022014-10-31 00:30:37 +0000177 this->Pending.pop_back();
Richard Smithf7514452014-10-30 21:02:37 +0000178 }
179
180 // Restore the old prefix.
NAKAMURA Takumic73e4022014-10-31 00:30:37 +0000181 this->Prefix.resize(Prefix.size() - 2);
Richard Smithf7514452014-10-30 21:02:37 +0000182 };
183
184 if (FirstChild) {
185 Pending.push_back(std::move(dumpWithIndent));
186 } else {
187 Pending.back()(false);
188 Pending.back() = std::move(dumpWithIndent);
Manuel Klimek874030e2012-11-07 00:33:12 +0000189 }
Richard Smithf7514452014-10-30 21:02:37 +0000190 FirstChild = false;
191 }
Manuel Klimek874030e2012-11-07 00:33:12 +0000192
Richard Trieud215b8d2013-01-26 01:31:20 +0000193 class ColorScope {
194 ASTDumper &Dumper;
195 public:
196 ColorScope(ASTDumper &Dumper, TerminalColor Color)
197 : Dumper(Dumper) {
198 if (Dumper.ShowColors)
199 Dumper.OS.changeColor(Color.Color, Color.Bold);
200 }
201 ~ColorScope() {
202 if (Dumper.ShowColors)
203 Dumper.OS.resetColor();
204 }
205 };
206
Chris Lattnercbe4f772007-08-08 22:51:59 +0000207 public:
Alexander Kornienkoebc17b52013-01-14 14:07:11 +0000208 ASTDumper(raw_ostream &OS, const CommandTraits *Traits,
209 const SourceManager *SM)
Richard Smith3a36ac12017-03-09 22:00:01 +0000210 : OS(OS), Traits(Traits), SM(SM),
Richard Trieud215b8d2013-01-26 01:31:20 +0000211 ShowColors(SM && SM->getDiagnostics().getShowColors()) { }
212
213 ASTDumper(raw_ostream &OS, const CommandTraits *Traits,
214 const SourceManager *SM, bool ShowColors)
Richard Smith3a36ac12017-03-09 22:00:01 +0000215 : OS(OS), Traits(Traits), SM(SM), ShowColors(ShowColors) {}
216
217 void setDeserialize(bool D) { Deserialize = D; }
Mike Stump11289f42009-09-09 15:08:12 +0000218
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000219 void dumpDecl(const Decl *D);
220 void dumpStmt(const Stmt *S);
Alexander Kornienkoebc17b52013-01-14 14:07:11 +0000221 void dumpFullComment(const FullComment *C);
Mike Stump11289f42009-09-09 15:08:12 +0000222
Richard Trieude5cc7d2013-01-31 01:44:26 +0000223 // Utilities
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000224 void dumpPointer(const void *Ptr);
225 void dumpSourceRange(SourceRange R);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000226 void dumpLocation(SourceLocation Loc);
Richard Smithd5e7ff82014-10-31 01:17:45 +0000227 void dumpBareType(QualType T, bool Desugar = true);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000228 void dumpType(QualType T);
Richard Smithd5e7ff82014-10-31 01:17:45 +0000229 void dumpTypeAsChild(QualType T);
230 void dumpTypeAsChild(const Type *T);
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000231 void dumpBareDeclRef(const Decl *Node);
Craig Topper36250ad2014-05-12 05:36:57 +0000232 void dumpDeclRef(const Decl *Node, const char *Label = nullptr);
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000233 void dumpName(const NamedDecl *D);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000234 bool hasNodes(const DeclContext *DC);
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000235 void dumpDeclContext(const DeclContext *DC);
Richard Smith35f986d2014-08-11 22:11:07 +0000236 void dumpLookups(const DeclContext *DC, bool DumpDecls);
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000237 void dumpAttr(const Attr *A);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000238
239 // C++ Utilities
240 void dumpAccessSpecifier(AccessSpecifier AS);
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000241 void dumpCXXCtorInitializer(const CXXCtorInitializer *Init);
242 void dumpTemplateParameters(const TemplateParameterList *TPL);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000243 void dumpTemplateArgumentListInfo(const TemplateArgumentListInfo &TALI);
244 void dumpTemplateArgumentLoc(const TemplateArgumentLoc &A);
245 void dumpTemplateArgumentList(const TemplateArgumentList &TAL);
246 void dumpTemplateArgument(const TemplateArgument &A,
247 SourceRange R = SourceRange());
248
Douglas Gregor85f3f952015-07-07 03:57:15 +0000249 // Objective-C utilities.
250 void dumpObjCTypeParamList(const ObjCTypeParamList *typeParams);
251
Richard Smithd5e7ff82014-10-31 01:17:45 +0000252 // Types
253 void VisitComplexType(const ComplexType *T) {
254 dumpTypeAsChild(T->getElementType());
255 }
256 void VisitPointerType(const PointerType *T) {
257 dumpTypeAsChild(T->getPointeeType());
258 }
259 void VisitBlockPointerType(const BlockPointerType *T) {
260 dumpTypeAsChild(T->getPointeeType());
261 }
262 void VisitReferenceType(const ReferenceType *T) {
263 dumpTypeAsChild(T->getPointeeType());
264 }
265 void VisitRValueReferenceType(const ReferenceType *T) {
266 if (T->isSpelledAsLValue())
267 OS << " written as lvalue reference";
268 VisitReferenceType(T);
269 }
270 void VisitMemberPointerType(const MemberPointerType *T) {
271 dumpTypeAsChild(T->getClass());
272 dumpTypeAsChild(T->getPointeeType());
273 }
274 void VisitArrayType(const ArrayType *T) {
275 switch (T->getSizeModifier()) {
276 case ArrayType::Normal: break;
277 case ArrayType::Static: OS << " static"; break;
278 case ArrayType::Star: OS << " *"; break;
279 }
280 OS << " " << T->getIndexTypeQualifiers().getAsString();
281 dumpTypeAsChild(T->getElementType());
282 }
283 void VisitConstantArrayType(const ConstantArrayType *T) {
284 OS << " " << T->getSize();
285 VisitArrayType(T);
286 }
287 void VisitVariableArrayType(const VariableArrayType *T) {
288 OS << " ";
289 dumpSourceRange(T->getBracketsRange());
290 VisitArrayType(T);
291 dumpStmt(T->getSizeExpr());
292 }
293 void VisitDependentSizedArrayType(const DependentSizedArrayType *T) {
294 VisitArrayType(T);
295 OS << " ";
296 dumpSourceRange(T->getBracketsRange());
297 dumpStmt(T->getSizeExpr());
298 }
299 void VisitDependentSizedExtVectorType(
300 const DependentSizedExtVectorType *T) {
301 OS << " ";
302 dumpLocation(T->getAttributeLoc());
303 dumpTypeAsChild(T->getElementType());
304 dumpStmt(T->getSizeExpr());
305 }
306 void VisitVectorType(const VectorType *T) {
307 switch (T->getVectorKind()) {
308 case VectorType::GenericVector: break;
309 case VectorType::AltiVecVector: OS << " altivec"; break;
310 case VectorType::AltiVecPixel: OS << " altivec pixel"; break;
311 case VectorType::AltiVecBool: OS << " altivec bool"; break;
312 case VectorType::NeonVector: OS << " neon"; break;
313 case VectorType::NeonPolyVector: OS << " neon poly"; break;
314 }
315 OS << " " << T->getNumElements();
316 dumpTypeAsChild(T->getElementType());
317 }
318 void VisitFunctionType(const FunctionType *T) {
319 auto EI = T->getExtInfo();
320 if (EI.getNoReturn()) OS << " noreturn";
321 if (EI.getProducesResult()) OS << " produces_result";
322 if (EI.getHasRegParm()) OS << " regparm " << EI.getRegParm();
323 OS << " " << FunctionType::getNameForCallConv(EI.getCC());
324 dumpTypeAsChild(T->getReturnType());
325 }
326 void VisitFunctionProtoType(const FunctionProtoType *T) {
327 auto EPI = T->getExtProtoInfo();
328 if (EPI.HasTrailingReturn) OS << " trailing_return";
329 if (T->isConst()) OS << " const";
330 if (T->isVolatile()) OS << " volatile";
331 if (T->isRestrict()) OS << " restrict";
332 switch (EPI.RefQualifier) {
333 case RQ_None: break;
334 case RQ_LValue: OS << " &"; break;
335 case RQ_RValue: OS << " &&"; break;
336 }
337 // FIXME: Exception specification.
338 // FIXME: Consumed parameters.
339 VisitFunctionType(T);
340 for (QualType PT : T->getParamTypes())
341 dumpTypeAsChild(PT);
342 if (EPI.Variadic)
343 dumpChild([=] { OS << "..."; });
344 }
345 void VisitUnresolvedUsingType(const UnresolvedUsingType *T) {
346 dumpDeclRef(T->getDecl());
347 }
348 void VisitTypedefType(const TypedefType *T) {
349 dumpDeclRef(T->getDecl());
350 }
351 void VisitTypeOfExprType(const TypeOfExprType *T) {
352 dumpStmt(T->getUnderlyingExpr());
353 }
354 void VisitDecltypeType(const DecltypeType *T) {
355 dumpStmt(T->getUnderlyingExpr());
356 }
357 void VisitUnaryTransformType(const UnaryTransformType *T) {
358 switch (T->getUTTKind()) {
359 case UnaryTransformType::EnumUnderlyingType:
360 OS << " underlying_type";
361 break;
362 }
363 dumpTypeAsChild(T->getBaseType());
364 }
365 void VisitTagType(const TagType *T) {
366 dumpDeclRef(T->getDecl());
367 }
368 void VisitAttributedType(const AttributedType *T) {
369 // FIXME: AttrKind
370 dumpTypeAsChild(T->getModifiedType());
371 }
372 void VisitTemplateTypeParmType(const TemplateTypeParmType *T) {
373 OS << " depth " << T->getDepth() << " index " << T->getIndex();
374 if (T->isParameterPack()) OS << " pack";
375 dumpDeclRef(T->getDecl());
376 }
377 void VisitSubstTemplateTypeParmType(const SubstTemplateTypeParmType *T) {
378 dumpTypeAsChild(T->getReplacedParameter());
379 }
380 void VisitSubstTemplateTypeParmPackType(
381 const SubstTemplateTypeParmPackType *T) {
382 dumpTypeAsChild(T->getReplacedParameter());
383 dumpTemplateArgument(T->getArgumentPack());
384 }
385 void VisitAutoType(const AutoType *T) {
386 if (T->isDecltypeAuto()) OS << " decltype(auto)";
387 if (!T->isDeduced())
388 OS << " undeduced";
389 }
390 void VisitTemplateSpecializationType(const TemplateSpecializationType *T) {
391 if (T->isTypeAlias()) OS << " alias";
392 OS << " "; T->getTemplateName().dump(OS);
393 for (auto &Arg : *T)
394 dumpTemplateArgument(Arg);
395 if (T->isTypeAlias())
396 dumpTypeAsChild(T->getAliasedType());
397 }
398 void VisitInjectedClassNameType(const InjectedClassNameType *T) {
399 dumpDeclRef(T->getDecl());
400 }
401 void VisitObjCInterfaceType(const ObjCInterfaceType *T) {
402 dumpDeclRef(T->getDecl());
403 }
404 void VisitObjCObjectPointerType(const ObjCObjectPointerType *T) {
405 dumpTypeAsChild(T->getPointeeType());
406 }
407 void VisitAtomicType(const AtomicType *T) {
408 dumpTypeAsChild(T->getValueType());
409 }
Xiuli Pan2d12e652016-05-03 05:37:07 +0000410 void VisitPipeType(const PipeType *T) {
411 dumpTypeAsChild(T->getElementType());
412 }
Richard Smithd5e7ff82014-10-31 01:17:45 +0000413 void VisitAdjustedType(const AdjustedType *T) {
414 dumpTypeAsChild(T->getOriginalType());
415 }
416 void VisitPackExpansionType(const PackExpansionType *T) {
417 if (auto N = T->getNumExpansions()) OS << " expansions " << *N;
418 if (!T->isSugared())
419 dumpTypeAsChild(T->getPattern());
420 }
421 // FIXME: ElaboratedType, DependentNameType,
422 // DependentTemplateSpecializationType, ObjCObjectType
423
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000424 // Decls
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000425 void VisitLabelDecl(const LabelDecl *D);
426 void VisitTypedefDecl(const TypedefDecl *D);
427 void VisitEnumDecl(const EnumDecl *D);
428 void VisitRecordDecl(const RecordDecl *D);
429 void VisitEnumConstantDecl(const EnumConstantDecl *D);
430 void VisitIndirectFieldDecl(const IndirectFieldDecl *D);
431 void VisitFunctionDecl(const FunctionDecl *D);
432 void VisitFieldDecl(const FieldDecl *D);
433 void VisitVarDecl(const VarDecl *D);
Richard Smithbdb84f32016-07-22 23:36:59 +0000434 void VisitDecompositionDecl(const DecompositionDecl *D);
Richard Smith7873de02016-08-11 22:25:46 +0000435 void VisitBindingDecl(const BindingDecl *D);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000436 void VisitFileScopeAsmDecl(const FileScopeAsmDecl *D);
437 void VisitImportDecl(const ImportDecl *D);
Nico Weber66220292016-03-02 17:28:48 +0000438 void VisitPragmaCommentDecl(const PragmaCommentDecl *D);
Nico Webercbbaeb12016-03-02 19:28:54 +0000439 void VisitPragmaDetectMismatchDecl(const PragmaDetectMismatchDecl *D);
Alexey Bataev958b9e72016-03-31 09:30:50 +0000440 void VisitCapturedDecl(const CapturedDecl *D);
441
442 // OpenMP decls
443 void VisitOMPThreadPrivateDecl(const OMPThreadPrivateDecl *D);
444 void VisitOMPDeclareReductionDecl(const OMPDeclareReductionDecl *D);
445 void VisitOMPCapturedExprDecl(const OMPCapturedExprDecl *D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000446
447 // C++ Decls
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000448 void VisitNamespaceDecl(const NamespaceDecl *D);
449 void VisitUsingDirectiveDecl(const UsingDirectiveDecl *D);
450 void VisitNamespaceAliasDecl(const NamespaceAliasDecl *D);
451 void VisitTypeAliasDecl(const TypeAliasDecl *D);
452 void VisitTypeAliasTemplateDecl(const TypeAliasTemplateDecl *D);
453 void VisitCXXRecordDecl(const CXXRecordDecl *D);
454 void VisitStaticAssertDecl(const StaticAssertDecl *D);
Richard Smithcbdf7332014-03-18 02:07:28 +0000455 template<typename SpecializationDecl>
Richard Smithf7514452014-10-30 21:02:37 +0000456 void VisitTemplateDeclSpecialization(const SpecializationDecl *D,
Richard Smithcbdf7332014-03-18 02:07:28 +0000457 bool DumpExplicitInst,
458 bool DumpRefOnly);
Richard Smith20ade552014-03-17 23:34:53 +0000459 template<typename TemplateDecl>
460 void VisitTemplateDecl(const TemplateDecl *D, bool DumpExplicitInst);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000461 void VisitFunctionTemplateDecl(const FunctionTemplateDecl *D);
462 void VisitClassTemplateDecl(const ClassTemplateDecl *D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000463 void VisitClassTemplateSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000464 const ClassTemplateSpecializationDecl *D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000465 void VisitClassTemplatePartialSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000466 const ClassTemplatePartialSpecializationDecl *D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000467 void VisitClassScopeFunctionSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000468 const ClassScopeFunctionSpecializationDecl *D);
David Majnemerd9b1a4f2015-11-04 03:40:30 +0000469 void VisitBuiltinTemplateDecl(const BuiltinTemplateDecl *D);
Richard Smithd25789a2013-09-18 01:36:02 +0000470 void VisitVarTemplateDecl(const VarTemplateDecl *D);
471 void VisitVarTemplateSpecializationDecl(
472 const VarTemplateSpecializationDecl *D);
473 void VisitVarTemplatePartialSpecializationDecl(
474 const VarTemplatePartialSpecializationDecl *D);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000475 void VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D);
476 void VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D);
477 void VisitTemplateTemplateParmDecl(const TemplateTemplateParmDecl *D);
478 void VisitUsingDecl(const UsingDecl *D);
479 void VisitUnresolvedUsingTypenameDecl(const UnresolvedUsingTypenameDecl *D);
480 void VisitUnresolvedUsingValueDecl(const UnresolvedUsingValueDecl *D);
481 void VisitUsingShadowDecl(const UsingShadowDecl *D);
Richard Smith5179eb72016-06-28 19:03:57 +0000482 void VisitConstructorUsingShadowDecl(const ConstructorUsingShadowDecl *D);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000483 void VisitLinkageSpecDecl(const LinkageSpecDecl *D);
484 void VisitAccessSpecDecl(const AccessSpecDecl *D);
485 void VisitFriendDecl(const FriendDecl *D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000486
487 // ObjC Decls
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000488 void VisitObjCIvarDecl(const ObjCIvarDecl *D);
489 void VisitObjCMethodDecl(const ObjCMethodDecl *D);
Douglas Gregor85f3f952015-07-07 03:57:15 +0000490 void VisitObjCTypeParamDecl(const ObjCTypeParamDecl *D);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000491 void VisitObjCCategoryDecl(const ObjCCategoryDecl *D);
492 void VisitObjCCategoryImplDecl(const ObjCCategoryImplDecl *D);
493 void VisitObjCProtocolDecl(const ObjCProtocolDecl *D);
494 void VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D);
495 void VisitObjCImplementationDecl(const ObjCImplementationDecl *D);
496 void VisitObjCCompatibleAliasDecl(const ObjCCompatibleAliasDecl *D);
497 void VisitObjCPropertyDecl(const ObjCPropertyDecl *D);
498 void VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D);
499 void VisitBlockDecl(const BlockDecl *D);
Mike Stump11289f42009-09-09 15:08:12 +0000500
Chris Lattner84ca3762007-08-30 01:00:35 +0000501 // Stmts.
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000502 void VisitStmt(const Stmt *Node);
503 void VisitDeclStmt(const DeclStmt *Node);
504 void VisitAttributedStmt(const AttributedStmt *Node);
505 void VisitLabelStmt(const LabelStmt *Node);
506 void VisitGotoStmt(const GotoStmt *Node);
Pavel Labath1ef83422013-09-04 14:35:00 +0000507 void VisitCXXCatchStmt(const CXXCatchStmt *Node);
Alexey Bataev958b9e72016-03-31 09:30:50 +0000508 void VisitCapturedStmt(const CapturedStmt *Node);
509
510 // OpenMP
511 void VisitOMPExecutableDirective(const OMPExecutableDirective *Node);
Mike Stump11289f42009-09-09 15:08:12 +0000512
Chris Lattner84ca3762007-08-30 01:00:35 +0000513 // Exprs
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000514 void VisitExpr(const Expr *Node);
515 void VisitCastExpr(const CastExpr *Node);
516 void VisitDeclRefExpr(const DeclRefExpr *Node);
517 void VisitPredefinedExpr(const PredefinedExpr *Node);
518 void VisitCharacterLiteral(const CharacterLiteral *Node);
519 void VisitIntegerLiteral(const IntegerLiteral *Node);
520 void VisitFloatingLiteral(const FloatingLiteral *Node);
521 void VisitStringLiteral(const StringLiteral *Str);
Richard Smithf0514962014-06-03 08:24:28 +0000522 void VisitInitListExpr(const InitListExpr *ILE);
Richard Smith410306b2016-12-12 02:53:20 +0000523 void VisitArrayInitLoopExpr(const ArrayInitLoopExpr *ILE);
524 void VisitArrayInitIndexExpr(const ArrayInitIndexExpr *ILE);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000525 void VisitUnaryOperator(const UnaryOperator *Node);
526 void VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *Node);
527 void VisitMemberExpr(const MemberExpr *Node);
528 void VisitExtVectorElementExpr(const ExtVectorElementExpr *Node);
529 void VisitBinaryOperator(const BinaryOperator *Node);
530 void VisitCompoundAssignOperator(const CompoundAssignOperator *Node);
531 void VisitAddrLabelExpr(const AddrLabelExpr *Node);
532 void VisitBlockExpr(const BlockExpr *Node);
533 void VisitOpaqueValueExpr(const OpaqueValueExpr *Node);
Chris Lattner84ca3762007-08-30 01:00:35 +0000534
535 // C++
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000536 void VisitCXXNamedCastExpr(const CXXNamedCastExpr *Node);
537 void VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *Node);
538 void VisitCXXThisExpr(const CXXThisExpr *Node);
539 void VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *Node);
540 void VisitCXXConstructExpr(const CXXConstructExpr *Node);
541 void VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *Node);
Reid Kleckner5c682bc2015-03-19 18:09:25 +0000542 void VisitCXXNewExpr(const CXXNewExpr *Node);
543 void VisitCXXDeleteExpr(const CXXDeleteExpr *Node);
Richard Smithe6c01442013-06-05 00:46:14 +0000544 void VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000545 void VisitExprWithCleanups(const ExprWithCleanups *Node);
546 void VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *Node);
547 void dumpCXXTemporary(const CXXTemporary *Temporary);
Faisal Vali2b391ab2013-09-26 19:54:12 +0000548 void VisitLambdaExpr(const LambdaExpr *Node) {
549 VisitExpr(Node);
550 dumpDecl(Node->getLambdaClass());
551 }
Serge Pavlov6b926032015-02-16 19:58:41 +0000552 void VisitSizeOfPackExpr(const SizeOfPackExpr *Node);
Alex Lorenzddbe0f52016-11-09 14:02:18 +0000553 void
554 VisitCXXDependentScopeMemberExpr(const CXXDependentScopeMemberExpr *Node);
Mike Stump11289f42009-09-09 15:08:12 +0000555
Chris Lattner84ca3762007-08-30 01:00:35 +0000556 // ObjC
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000557 void VisitObjCAtCatchStmt(const ObjCAtCatchStmt *Node);
558 void VisitObjCEncodeExpr(const ObjCEncodeExpr *Node);
559 void VisitObjCMessageExpr(const ObjCMessageExpr *Node);
560 void VisitObjCBoxedExpr(const ObjCBoxedExpr *Node);
561 void VisitObjCSelectorExpr(const ObjCSelectorExpr *Node);
562 void VisitObjCProtocolExpr(const ObjCProtocolExpr *Node);
563 void VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *Node);
564 void VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *Node);
565 void VisitObjCIvarRefExpr(const ObjCIvarRefExpr *Node);
566 void VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *Node);
Alexander Kornienkoebc17b52013-01-14 14:07:11 +0000567
568 // Comments.
569 const char *getCommandName(unsigned CommandID);
570 void dumpComment(const Comment *C);
571
572 // Inline comments.
573 void visitTextComment(const TextComment *C);
574 void visitInlineCommandComment(const InlineCommandComment *C);
575 void visitHTMLStartTagComment(const HTMLStartTagComment *C);
576 void visitHTMLEndTagComment(const HTMLEndTagComment *C);
577
578 // Block comments.
579 void visitBlockCommandComment(const BlockCommandComment *C);
580 void visitParamCommandComment(const ParamCommandComment *C);
581 void visitTParamCommandComment(const TParamCommandComment *C);
582 void visitVerbatimBlockComment(const VerbatimBlockComment *C);
583 void visitVerbatimBlockLineComment(const VerbatimBlockLineComment *C);
584 void visitVerbatimLineComment(const VerbatimLineComment *C);
Chris Lattnercbe4f772007-08-08 22:51:59 +0000585 };
Alexander Kornienkoab9db512015-06-22 23:07:51 +0000586}
Chris Lattnercbe4f772007-08-08 22:51:59 +0000587
588//===----------------------------------------------------------------------===//
Chris Lattner11e30d32007-08-30 06:17:34 +0000589// Utilities
590//===----------------------------------------------------------------------===//
591
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000592void ASTDumper::dumpPointer(const void *Ptr) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000593 ColorScope Color(*this, AddressColor);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000594 OS << ' ' << Ptr;
595}
596
Alexander Kornienko18ec81b2012-12-13 13:59:55 +0000597void ASTDumper::dumpLocation(SourceLocation Loc) {
Alex McCarthye14ddef2014-05-02 20:24:11 +0000598 if (!SM)
599 return;
600
Richard Trieud215b8d2013-01-26 01:31:20 +0000601 ColorScope Color(*this, LocationColor);
Chris Lattner53e384f2009-01-16 07:00:02 +0000602 SourceLocation SpellingLoc = SM->getSpellingLoc(Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000603
Chris Lattner11e30d32007-08-30 06:17:34 +0000604 // The general format we print out is filename:line:col, but we drop pieces
605 // that haven't changed since the last loc printed.
Chris Lattnerf1ca7d32009-01-27 07:57:44 +0000606 PresumedLoc PLoc = SM->getPresumedLoc(SpellingLoc);
607
Douglas Gregor453b0122010-11-12 07:15:47 +0000608 if (PLoc.isInvalid()) {
609 OS << "<invalid sloc>";
610 return;
611 }
612
Chris Lattnerf1ca7d32009-01-27 07:57:44 +0000613 if (strcmp(PLoc.getFilename(), LastLocFilename) != 0) {
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000614 OS << PLoc.getFilename() << ':' << PLoc.getLine()
615 << ':' << PLoc.getColumn();
Chris Lattnerf1ca7d32009-01-27 07:57:44 +0000616 LastLocFilename = PLoc.getFilename();
617 LastLocLine = PLoc.getLine();
618 } else if (PLoc.getLine() != LastLocLine) {
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000619 OS << "line" << ':' << PLoc.getLine()
620 << ':' << PLoc.getColumn();
Chris Lattnerf1ca7d32009-01-27 07:57:44 +0000621 LastLocLine = PLoc.getLine();
Chris Lattner11e30d32007-08-30 06:17:34 +0000622 } else {
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000623 OS << "col" << ':' << PLoc.getColumn();
Chris Lattner11e30d32007-08-30 06:17:34 +0000624 }
625}
626
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000627void ASTDumper::dumpSourceRange(SourceRange R) {
Chris Lattner11e30d32007-08-30 06:17:34 +0000628 // Can't translate locations if a SourceManager isn't available.
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000629 if (!SM)
630 return;
Mike Stump11289f42009-09-09 15:08:12 +0000631
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000632 OS << " <";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000633 dumpLocation(R.getBegin());
Chris Lattnera7c19fe2007-10-16 22:36:42 +0000634 if (R.getBegin() != R.getEnd()) {
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000635 OS << ", ";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000636 dumpLocation(R.getEnd());
Chris Lattner11e30d32007-08-30 06:17:34 +0000637 }
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000638 OS << ">";
Mike Stump11289f42009-09-09 15:08:12 +0000639
Chris Lattner11e30d32007-08-30 06:17:34 +0000640 // <t2.c:123:421[blah], t2.c:412:321>
641
642}
643
Richard Smithd5e7ff82014-10-31 01:17:45 +0000644void ASTDumper::dumpBareType(QualType T, bool Desugar) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000645 ColorScope Color(*this, TypeColor);
Richard Smithd5e7ff82014-10-31 01:17:45 +0000646
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000647 SplitQualType T_split = T.split();
648 OS << "'" << QualType::getAsString(T_split) << "'";
649
Richard Smithd5e7ff82014-10-31 01:17:45 +0000650 if (Desugar && !T.isNull()) {
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000651 // If the type is sugared, also dump a (shallow) desugared type.
652 SplitQualType D_split = T.getSplitDesugaredType();
653 if (T_split != D_split)
654 OS << ":'" << QualType::getAsString(D_split) << "'";
655 }
656}
657
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000658void ASTDumper::dumpType(QualType T) {
659 OS << ' ';
660 dumpBareType(T);
661}
662
Richard Smithd5e7ff82014-10-31 01:17:45 +0000663void ASTDumper::dumpTypeAsChild(QualType T) {
664 SplitQualType SQT = T.split();
665 if (!SQT.Quals.hasQualifiers())
666 return dumpTypeAsChild(SQT.Ty);
667
668 dumpChild([=] {
669 OS << "QualType";
670 dumpPointer(T.getAsOpaquePtr());
671 OS << " ";
672 dumpBareType(T, false);
673 OS << " " << T.split().Quals.getAsString();
674 dumpTypeAsChild(T.split().Ty);
675 });
676}
677
678void ASTDumper::dumpTypeAsChild(const Type *T) {
679 dumpChild([=] {
680 if (!T) {
681 ColorScope Color(*this, NullColor);
682 OS << "<<<NULL>>>";
683 return;
684 }
Serge Pavlova6adc9e2015-12-28 17:19:12 +0000685 if (const LocInfoType *LIT = llvm::dyn_cast<LocInfoType>(T)) {
686 {
687 ColorScope Color(*this, TypeColor);
688 OS << "LocInfo Type";
689 }
690 dumpPointer(T);
691 dumpTypeAsChild(LIT->getTypeSourceInfo()->getType());
692 return;
693 }
Richard Smithd5e7ff82014-10-31 01:17:45 +0000694
695 {
696 ColorScope Color(*this, TypeColor);
697 OS << T->getTypeClassName() << "Type";
698 }
699 dumpPointer(T);
700 OS << " ";
701 dumpBareType(QualType(T, 0), false);
702
703 QualType SingleStepDesugar =
704 T->getLocallyUnqualifiedSingleStepDesugaredType();
705 if (SingleStepDesugar != QualType(T, 0))
706 OS << " sugar";
707 if (T->isDependentType())
708 OS << " dependent";
709 else if (T->isInstantiationDependentType())
710 OS << " instantiation_dependent";
711 if (T->isVariablyModifiedType())
712 OS << " variably_modified";
713 if (T->containsUnexpandedParameterPack())
714 OS << " contains_unexpanded_pack";
715 if (T->isFromAST())
716 OS << " imported";
717
718 TypeVisitor<ASTDumper>::Visit(T);
719
720 if (SingleStepDesugar != QualType(T, 0))
721 dumpTypeAsChild(SingleStepDesugar);
722 });
723}
724
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000725void ASTDumper::dumpBareDeclRef(const Decl *D) {
Richard Smith5179eb72016-06-28 19:03:57 +0000726 if (!D) {
727 ColorScope Color(*this, NullColor);
728 OS << "<<<NULL>>>";
729 return;
730 }
731
Richard Trieud215b8d2013-01-26 01:31:20 +0000732 {
733 ColorScope Color(*this, DeclKindNameColor);
734 OS << D->getDeclKindName();
735 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000736 dumpPointer(D);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000737
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000738 if (const NamedDecl *ND = dyn_cast<NamedDecl>(D)) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000739 ColorScope Color(*this, DeclNameColor);
David Blaikied4da8722013-05-14 21:04:00 +0000740 OS << " '" << ND->getDeclName() << '\'';
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000741 }
742
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000743 if (const ValueDecl *VD = dyn_cast<ValueDecl>(D))
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000744 dumpType(VD->getType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000745}
746
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000747void ASTDumper::dumpDeclRef(const Decl *D, const char *Label) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000748 if (!D)
749 return;
750
Richard Smithf7514452014-10-30 21:02:37 +0000751 dumpChild([=]{
752 if (Label)
753 OS << Label << ' ';
754 dumpBareDeclRef(D);
755 });
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000756}
757
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000758void ASTDumper::dumpName(const NamedDecl *ND) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000759 if (ND->getDeclName()) {
760 ColorScope Color(*this, DeclNameColor);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000761 OS << ' ' << ND->getNameAsString();
Richard Trieud215b8d2013-01-26 01:31:20 +0000762 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000763}
764
Richard Trieude5cc7d2013-01-31 01:44:26 +0000765bool ASTDumper::hasNodes(const DeclContext *DC) {
766 if (!DC)
767 return false;
768
Richard Smith1d209d02013-05-23 01:49:11 +0000769 return DC->hasExternalLexicalStorage() ||
Richard Smith3a36ac12017-03-09 22:00:01 +0000770 (Deserialize ? DC->decls_begin() != DC->decls_end()
771 : DC->noload_decls_begin() != DC->noload_decls_end());
Richard Trieude5cc7d2013-01-31 01:44:26 +0000772}
773
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000774void ASTDumper::dumpDeclContext(const DeclContext *DC) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000775 if (!DC)
776 return;
Richard Smithdcc2c452014-03-17 23:00:06 +0000777
Richard Smith3a36ac12017-03-09 22:00:01 +0000778 for (auto *D : (Deserialize ? DC->decls() : DC->noload_decls()))
Richard Smithf7514452014-10-30 21:02:37 +0000779 dumpDecl(D);
Richard Smithdcc2c452014-03-17 23:00:06 +0000780
781 if (DC->hasExternalLexicalStorage()) {
Richard Smithf7514452014-10-30 21:02:37 +0000782 dumpChild([=]{
783 ColorScope Color(*this, UndeserializedColor);
784 OS << "<undeserialized declarations>";
785 });
Richard Smith1d209d02013-05-23 01:49:11 +0000786 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000787}
788
Richard Smith35f986d2014-08-11 22:11:07 +0000789void ASTDumper::dumpLookups(const DeclContext *DC, bool DumpDecls) {
Richard Smithf7514452014-10-30 21:02:37 +0000790 dumpChild([=] {
791 OS << "StoredDeclsMap ";
792 dumpBareDeclRef(cast<Decl>(DC));
Richard Smith33937e72013-06-22 21:49:40 +0000793
Richard Smithf7514452014-10-30 21:02:37 +0000794 const DeclContext *Primary = DC->getPrimaryContext();
795 if (Primary != DC) {
796 OS << " primary";
797 dumpPointer(cast<Decl>(Primary));
Richard Smith33937e72013-06-22 21:49:40 +0000798 }
799
Richard Smithf7514452014-10-30 21:02:37 +0000800 bool HasUndeserializedLookups = Primary->hasExternalVisibleStorage();
Richard Smith35f986d2014-08-11 22:11:07 +0000801
Richard Smith3a36ac12017-03-09 22:00:01 +0000802 for (auto I = Deserialize ? Primary->lookups_begin()
803 : Primary->noload_lookups_begin(),
804 E = Deserialize ? Primary->lookups_end()
805 : Primary->noload_lookups_end();
806 I != E; ++I) {
Richard Smithf7514452014-10-30 21:02:37 +0000807 DeclarationName Name = I.getLookupName();
Richard Smith3a36ac12017-03-09 22:00:01 +0000808 DeclContextLookupResult R = *I;
Richard Smith35f986d2014-08-11 22:11:07 +0000809
Richard Smithf7514452014-10-30 21:02:37 +0000810 dumpChild([=] {
811 OS << "DeclarationName ";
812 {
813 ColorScope Color(*this, DeclNameColor);
814 OS << '\'' << Name << '\'';
815 }
Richard Smith35f986d2014-08-11 22:11:07 +0000816
Richard Smithf7514452014-10-30 21:02:37 +0000817 for (DeclContextLookupResult::iterator RI = R.begin(), RE = R.end();
818 RI != RE; ++RI) {
819 dumpChild([=] {
820 dumpBareDeclRef(*RI);
821
822 if ((*RI)->isHidden())
823 OS << " hidden";
824
825 // If requested, dump the redecl chain for this lookup.
826 if (DumpDecls) {
827 // Dump earliest decl first.
828 std::function<void(Decl *)> DumpWithPrev = [&](Decl *D) {
829 if (Decl *Prev = D->getPreviousDecl())
830 DumpWithPrev(Prev);
831 dumpDecl(D);
832 };
833 DumpWithPrev(*RI);
834 }
835 });
836 }
837 });
Richard Smith33937e72013-06-22 21:49:40 +0000838 }
Richard Smith33937e72013-06-22 21:49:40 +0000839
Richard Smithf7514452014-10-30 21:02:37 +0000840 if (HasUndeserializedLookups) {
841 dumpChild([=] {
842 ColorScope Color(*this, UndeserializedColor);
843 OS << "<undeserialized lookups>";
844 });
845 }
846 });
Richard Smith33937e72013-06-22 21:49:40 +0000847}
848
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000849void ASTDumper::dumpAttr(const Attr *A) {
Richard Smithf7514452014-10-30 21:02:37 +0000850 dumpChild([=] {
851 {
852 ColorScope Color(*this, AttrColor);
Aaron Ballman36a53502014-01-16 13:03:14 +0000853
Richard Smithf7514452014-10-30 21:02:37 +0000854 switch (A->getKind()) {
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000855#define ATTR(X) case attr::X: OS << #X; break;
856#include "clang/Basic/AttrList.inc"
Richard Smithf7514452014-10-30 21:02:37 +0000857 }
858 OS << "Attr";
Richard Trieud215b8d2013-01-26 01:31:20 +0000859 }
Richard Smithf7514452014-10-30 21:02:37 +0000860 dumpPointer(A);
861 dumpSourceRange(A->getRange());
862 if (A->isInherited())
863 OS << " Inherited";
864 if (A->isImplicit())
865 OS << " Implicit";
Hans Wennborgb0a8b4a2014-05-31 04:05:57 +0000866#include "clang/AST/AttrDump.inc"
Richard Smithf7514452014-10-30 21:02:37 +0000867 });
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000868}
869
Richard Smith71bec062013-10-15 21:58:30 +0000870static void dumpPreviousDeclImpl(raw_ostream &OS, ...) {}
871
872template<typename T>
873static void dumpPreviousDeclImpl(raw_ostream &OS, const Mergeable<T> *D) {
Rafael Espindola8db352d2013-10-17 15:37:26 +0000874 const T *First = D->getFirstDecl();
Richard Smith71bec062013-10-15 21:58:30 +0000875 if (First != D)
876 OS << " first " << First;
Richard Smithf5f43542013-02-07 01:35:44 +0000877}
878
879template<typename T>
Richard Smith71bec062013-10-15 21:58:30 +0000880static void dumpPreviousDeclImpl(raw_ostream &OS, const Redeclarable<T> *D) {
881 const T *Prev = D->getPreviousDecl();
882 if (Prev)
883 OS << " prev " << Prev;
Richard Smithf5f43542013-02-07 01:35:44 +0000884}
885
Richard Smith71bec062013-10-15 21:58:30 +0000886/// Dump the previous declaration in the redeclaration chain for a declaration,
887/// if any.
888static void dumpPreviousDecl(raw_ostream &OS, const Decl *D) {
Richard Smithf5f43542013-02-07 01:35:44 +0000889 switch (D->getKind()) {
890#define DECL(DERIVED, BASE) \
891 case Decl::DERIVED: \
Richard Smith71bec062013-10-15 21:58:30 +0000892 return dumpPreviousDeclImpl(OS, cast<DERIVED##Decl>(D));
Richard Smithf5f43542013-02-07 01:35:44 +0000893#define ABSTRACT_DECL(DECL)
894#include "clang/AST/DeclNodes.inc"
895 }
896 llvm_unreachable("Decl that isn't part of DeclNodes.inc!");
897}
898
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000899//===----------------------------------------------------------------------===//
900// C++ Utilities
901//===----------------------------------------------------------------------===//
902
903void ASTDumper::dumpAccessSpecifier(AccessSpecifier AS) {
904 switch (AS) {
905 case AS_none:
906 break;
907 case AS_public:
908 OS << "public";
909 break;
910 case AS_protected:
911 OS << "protected";
912 break;
913 case AS_private:
914 OS << "private";
915 break;
916 }
917}
918
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000919void ASTDumper::dumpCXXCtorInitializer(const CXXCtorInitializer *Init) {
Richard Smithf7514452014-10-30 21:02:37 +0000920 dumpChild([=] {
921 OS << "CXXCtorInitializer";
922 if (Init->isAnyMemberInitializer()) {
923 OS << ' ';
924 dumpBareDeclRef(Init->getAnyMember());
925 } else if (Init->isBaseInitializer()) {
926 dumpType(QualType(Init->getBaseClass(), 0));
927 } else if (Init->isDelegatingInitializer()) {
928 dumpType(Init->getTypeSourceInfo()->getType());
929 } else {
930 llvm_unreachable("Unknown initializer type");
931 }
932 dumpStmt(Init->getInit());
933 });
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000934}
935
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000936void ASTDumper::dumpTemplateParameters(const TemplateParameterList *TPL) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000937 if (!TPL)
938 return;
939
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000940 for (TemplateParameterList::const_iterator I = TPL->begin(), E = TPL->end();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000941 I != E; ++I)
942 dumpDecl(*I);
943}
944
945void ASTDumper::dumpTemplateArgumentListInfo(
946 const TemplateArgumentListInfo &TALI) {
Richard Smithf7514452014-10-30 21:02:37 +0000947 for (unsigned i = 0, e = TALI.size(); i < e; ++i)
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000948 dumpTemplateArgumentLoc(TALI[i]);
949}
950
951void ASTDumper::dumpTemplateArgumentLoc(const TemplateArgumentLoc &A) {
952 dumpTemplateArgument(A.getArgument(), A.getSourceRange());
953}
954
955void ASTDumper::dumpTemplateArgumentList(const TemplateArgumentList &TAL) {
956 for (unsigned i = 0, e = TAL.size(); i < e; ++i)
957 dumpTemplateArgument(TAL[i]);
958}
959
960void ASTDumper::dumpTemplateArgument(const TemplateArgument &A, SourceRange R) {
Richard Smithf7514452014-10-30 21:02:37 +0000961 dumpChild([=] {
962 OS << "TemplateArgument";
963 if (R.isValid())
964 dumpSourceRange(R);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000965
Richard Smithf7514452014-10-30 21:02:37 +0000966 switch (A.getKind()) {
967 case TemplateArgument::Null:
968 OS << " null";
969 break;
970 case TemplateArgument::Type:
971 OS << " type";
972 dumpType(A.getAsType());
973 break;
974 case TemplateArgument::Declaration:
975 OS << " decl";
976 dumpDeclRef(A.getAsDecl());
977 break;
978 case TemplateArgument::NullPtr:
979 OS << " nullptr";
980 break;
981 case TemplateArgument::Integral:
982 OS << " integral " << A.getAsIntegral();
983 break;
984 case TemplateArgument::Template:
985 OS << " template ";
986 A.getAsTemplate().dump(OS);
987 break;
988 case TemplateArgument::TemplateExpansion:
989 OS << " template expansion";
990 A.getAsTemplateOrTemplatePattern().dump(OS);
991 break;
992 case TemplateArgument::Expression:
993 OS << " expr";
994 dumpStmt(A.getAsExpr());
995 break;
996 case TemplateArgument::Pack:
997 OS << " pack";
998 for (TemplateArgument::pack_iterator I = A.pack_begin(), E = A.pack_end();
999 I != E; ++I)
1000 dumpTemplateArgument(*I);
1001 break;
Richard Trieude5cc7d2013-01-31 01:44:26 +00001002 }
Richard Smithf7514452014-10-30 21:02:37 +00001003 });
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001004}
1005
Chris Lattner11e30d32007-08-30 06:17:34 +00001006//===----------------------------------------------------------------------===//
Douglas Gregor85f3f952015-07-07 03:57:15 +00001007// Objective-C Utilities
1008//===----------------------------------------------------------------------===//
1009void ASTDumper::dumpObjCTypeParamList(const ObjCTypeParamList *typeParams) {
1010 if (!typeParams)
1011 return;
1012
1013 for (auto typeParam : *typeParams) {
1014 dumpDecl(typeParam);
1015 }
1016}
1017
1018//===----------------------------------------------------------------------===//
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001019// Decl dumping methods.
Chris Lattnercbe4f772007-08-08 22:51:59 +00001020//===----------------------------------------------------------------------===//
1021
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001022void ASTDumper::dumpDecl(const Decl *D) {
Richard Smithf7514452014-10-30 21:02:37 +00001023 dumpChild([=] {
1024 if (!D) {
1025 ColorScope Color(*this, NullColor);
1026 OS << "<<<NULL>>>";
1027 return;
1028 }
Mike Stump11289f42009-09-09 15:08:12 +00001029
Richard Smithf7514452014-10-30 21:02:37 +00001030 {
1031 ColorScope Color(*this, DeclKindNameColor);
1032 OS << D->getDeclKindName() << "Decl";
1033 }
1034 dumpPointer(D);
1035 if (D->getLexicalDeclContext() != D->getDeclContext())
1036 OS << " parent " << cast<Decl>(D->getDeclContext());
1037 dumpPreviousDecl(OS, D);
1038 dumpSourceRange(D->getSourceRange());
1039 OS << ' ';
1040 dumpLocation(D->getLocation());
Richard Smith26342f92017-05-17 00:24:14 +00001041 if (D->isFromASTFile())
1042 OS << " imported";
1043 if (Module *M = D->getOwningModule())
Richard Smithf7514452014-10-30 21:02:37 +00001044 OS << " in " << M->getFullModuleName();
Richard Smitha2eb4092015-06-22 18:47:01 +00001045 if (auto *ND = dyn_cast<NamedDecl>(D))
1046 for (Module *M : D->getASTContext().getModulesWithMergedDefinition(
1047 const_cast<NamedDecl *>(ND)))
1048 dumpChild([=] { OS << "also in " << M->getFullModuleName(); });
Richard Smithf7514452014-10-30 21:02:37 +00001049 if (const NamedDecl *ND = dyn_cast<NamedDecl>(D))
1050 if (ND->isHidden())
1051 OS << " hidden";
1052 if (D->isImplicit())
1053 OS << " implicit";
1054 if (D->isUsed())
1055 OS << " used";
1056 else if (D->isThisDeclarationReferenced())
1057 OS << " referenced";
1058 if (D->isInvalidDecl())
1059 OS << " invalid";
Hans Wennborg76b00532014-12-05 22:38:57 +00001060 if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
1061 if (FD->isConstexpr())
1062 OS << " constexpr";
1063
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001064
Richard Smithf7514452014-10-30 21:02:37 +00001065 ConstDeclVisitor<ASTDumper>::Visit(D);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001066
Richard Smithf7514452014-10-30 21:02:37 +00001067 for (Decl::attr_iterator I = D->attr_begin(), E = D->attr_end(); I != E;
1068 ++I)
1069 dumpAttr(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001070
Richard Smithf7514452014-10-30 21:02:37 +00001071 if (const FullComment *Comment =
1072 D->getASTContext().getLocalCommentForDeclUncached(D))
1073 dumpFullComment(Comment);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001074
Richard Smithf7514452014-10-30 21:02:37 +00001075 // Decls within functions are visited by the body.
1076 if (!isa<FunctionDecl>(*D) && !isa<ObjCMethodDecl>(*D) &&
1077 hasNodes(dyn_cast<DeclContext>(D)))
1078 dumpDeclContext(cast<DeclContext>(D));
1079 });
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001080}
1081
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001082void ASTDumper::VisitLabelDecl(const LabelDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001083 dumpName(D);
1084}
1085
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001086void ASTDumper::VisitTypedefDecl(const TypedefDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001087 dumpName(D);
1088 dumpType(D->getUnderlyingType());
1089 if (D->isModulePrivate())
1090 OS << " __module_private__";
Richard Smithba3a4f92016-01-12 21:59:26 +00001091 dumpTypeAsChild(D->getUnderlyingType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001092}
1093
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001094void ASTDumper::VisitEnumDecl(const EnumDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001095 if (D->isScoped()) {
1096 if (D->isScopedUsingClassTag())
1097 OS << " class";
1098 else
1099 OS << " struct";
1100 }
1101 dumpName(D);
1102 if (D->isModulePrivate())
1103 OS << " __module_private__";
1104 if (D->isFixed())
1105 dumpType(D->getIntegerType());
1106}
1107
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001108void ASTDumper::VisitRecordDecl(const RecordDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001109 OS << ' ' << D->getKindName();
1110 dumpName(D);
1111 if (D->isModulePrivate())
1112 OS << " __module_private__";
Richard Smith99bc1b92013-08-30 05:32:29 +00001113 if (D->isCompleteDefinition())
1114 OS << " definition";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001115}
1116
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001117void ASTDumper::VisitEnumConstantDecl(const EnumConstantDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001118 dumpName(D);
1119 dumpType(D->getType());
Richard Smithf7514452014-10-30 21:02:37 +00001120 if (const Expr *Init = D->getInitExpr())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001121 dumpStmt(Init);
1122}
1123
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001124void ASTDumper::VisitIndirectFieldDecl(const IndirectFieldDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001125 dumpName(D);
1126 dumpType(D->getType());
Richard Smithdcc2c452014-03-17 23:00:06 +00001127
Richard Smith8aa49222014-03-18 00:35:12 +00001128 for (auto *Child : D->chain())
Richard Smithf7514452014-10-30 21:02:37 +00001129 dumpDeclRef(Child);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001130}
1131
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001132void ASTDumper::VisitFunctionDecl(const FunctionDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001133 dumpName(D);
1134 dumpType(D->getType());
1135
Rafael Espindola6ae7e502013-04-03 19:27:57 +00001136 StorageClass SC = D->getStorageClass();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001137 if (SC != SC_None)
1138 OS << ' ' << VarDecl::getStorageClassSpecifierString(SC);
1139 if (D->isInlineSpecified())
1140 OS << " inline";
1141 if (D->isVirtualAsWritten())
1142 OS << " virtual";
1143 if (D->isModulePrivate())
1144 OS << " __module_private__";
1145
1146 if (D->isPure())
1147 OS << " pure";
Richard Smith5a2e6b92016-11-21 23:43:54 +00001148 if (D->isDefaulted()) {
1149 OS << " default";
1150 if (D->isDeleted())
1151 OS << "_delete";
1152 }
1153 if (D->isDeletedAsWritten())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001154 OS << " delete";
Richard Smith5a2e6b92016-11-21 23:43:54 +00001155 if (D->isTrivial())
1156 OS << " trivial";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001157
Richard Smithadaa0152013-05-17 02:09:46 +00001158 if (const FunctionProtoType *FPT = D->getType()->getAs<FunctionProtoType>()) {
1159 FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo();
Richard Smith8acb4282014-07-31 21:57:55 +00001160 switch (EPI.ExceptionSpec.Type) {
Richard Smithadaa0152013-05-17 02:09:46 +00001161 default: break;
1162 case EST_Unevaluated:
Richard Smith8acb4282014-07-31 21:57:55 +00001163 OS << " noexcept-unevaluated " << EPI.ExceptionSpec.SourceDecl;
Richard Smithadaa0152013-05-17 02:09:46 +00001164 break;
1165 case EST_Uninstantiated:
Richard Smith8acb4282014-07-31 21:57:55 +00001166 OS << " noexcept-uninstantiated " << EPI.ExceptionSpec.SourceTemplate;
Richard Smithadaa0152013-05-17 02:09:46 +00001167 break;
1168 }
1169 }
1170
Richard Smithf7514452014-10-30 21:02:37 +00001171 if (const FunctionTemplateSpecializationInfo *FTSI =
1172 D->getTemplateSpecializationInfo())
Richard Trieude5cc7d2013-01-31 01:44:26 +00001173 dumpTemplateArgumentList(*FTSI->TemplateArguments);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001174
Richard Smith8a639892015-01-24 01:07:20 +00001175 if (!D->param_begin() && D->getNumParams())
1176 dumpChild([=] { OS << "<<NULL params x " << D->getNumParams() << ">>"; });
1177 else
David Majnemera3debed2016-06-24 05:33:44 +00001178 for (const ParmVarDecl *Parameter : D->parameters())
1179 dumpDecl(Parameter);
Richard Smithf7514452014-10-30 21:02:37 +00001180
1181 if (const CXXConstructorDecl *C = dyn_cast<CXXConstructorDecl>(D))
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001182 for (CXXConstructorDecl::init_const_iterator I = C->init_begin(),
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001183 E = C->init_end();
Richard Smithf7514452014-10-30 21:02:37 +00001184 I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001185 dumpCXXCtorInitializer(*I);
1186
Lenar Safin9ae21552017-07-29 20:42:58 +00001187 if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(D)) {
Lang Hames19e07e12017-06-20 21:06:00 +00001188 if (MD->size_overridden_methods() != 0) {
1189 auto dumpOverride =
1190 [=](const CXXMethodDecl *D) {
1191 SplitQualType T_split = D->getType().split();
Lang Hames971add52017-07-13 21:08:29 +00001192 OS << D << " " << D->getParent()->getName() << "::"
1193 << D->getNameAsString() << " '" << QualType::getAsString(T_split) << "'";
Lang Hames19e07e12017-06-20 21:06:00 +00001194 };
1195
1196 dumpChild([=] {
1197 auto FirstOverrideItr = MD->begin_overridden_methods();
1198 OS << "Overrides: [ ";
1199 dumpOverride(*FirstOverrideItr);
1200 for (const auto *Override :
1201 llvm::make_range(FirstOverrideItr + 1,
Lenar Safin9ae21552017-07-29 20:42:58 +00001202 MD->end_overridden_methods())) {
1203 OS << ", ";
Lang Hames19e07e12017-06-20 21:06:00 +00001204 dumpOverride(Override);
Lenar Safin9ae21552017-07-29 20:42:58 +00001205 }
Lang Hames19e07e12017-06-20 21:06:00 +00001206 OS << " ]";
1207 });
1208 }
Lenar Safin9ae21552017-07-29 20:42:58 +00001209 }
Lang Hames19e07e12017-06-20 21:06:00 +00001210
Richard Smithf7514452014-10-30 21:02:37 +00001211 if (D->doesThisDeclarationHaveABody())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001212 dumpStmt(D->getBody());
1213}
1214
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001215void ASTDumper::VisitFieldDecl(const FieldDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001216 dumpName(D);
1217 dumpType(D->getType());
1218 if (D->isMutable())
1219 OS << " mutable";
1220 if (D->isModulePrivate())
1221 OS << " __module_private__";
Richard Trieude5cc7d2013-01-31 01:44:26 +00001222
Richard Smithf7514452014-10-30 21:02:37 +00001223 if (D->isBitField())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001224 dumpStmt(D->getBitWidth());
Richard Smithf7514452014-10-30 21:02:37 +00001225 if (Expr *Init = D->getInClassInitializer())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001226 dumpStmt(Init);
1227}
1228
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001229void ASTDumper::VisitVarDecl(const VarDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001230 dumpName(D);
1231 dumpType(D->getType());
Rafael Espindola6ae7e502013-04-03 19:27:57 +00001232 StorageClass SC = D->getStorageClass();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001233 if (SC != SC_None)
1234 OS << ' ' << VarDecl::getStorageClassSpecifierString(SC);
Richard Smithfd3834f2013-04-13 02:43:54 +00001235 switch (D->getTLSKind()) {
1236 case VarDecl::TLS_None: break;
1237 case VarDecl::TLS_Static: OS << " tls"; break;
1238 case VarDecl::TLS_Dynamic: OS << " tls_dynamic"; break;
1239 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001240 if (D->isModulePrivate())
1241 OS << " __module_private__";
1242 if (D->isNRVOVariable())
1243 OS << " nrvo";
Richard Smith62f19e72016-06-25 00:15:56 +00001244 if (D->isInline())
1245 OS << " inline";
1246 if (D->isConstexpr())
1247 OS << " constexpr";
Richard Trieude5cc7d2013-01-31 01:44:26 +00001248 if (D->hasInit()) {
Richard Smithd9967cc2014-07-10 22:54:03 +00001249 switch (D->getInitStyle()) {
1250 case VarDecl::CInit: OS << " cinit"; break;
1251 case VarDecl::CallInit: OS << " callinit"; break;
1252 case VarDecl::ListInit: OS << " listinit"; break;
1253 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001254 dumpStmt(D->getInit());
Richard Trieude5cc7d2013-01-31 01:44:26 +00001255 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001256}
1257
Richard Smithbdb84f32016-07-22 23:36:59 +00001258void ASTDumper::VisitDecompositionDecl(const DecompositionDecl *D) {
1259 VisitVarDecl(D);
1260 for (auto *B : D->bindings())
1261 dumpDecl(B);
1262}
1263
Richard Smith7873de02016-08-11 22:25:46 +00001264void ASTDumper::VisitBindingDecl(const BindingDecl *D) {
1265 dumpName(D);
1266 dumpType(D->getType());
1267 if (auto *E = D->getBinding())
1268 dumpStmt(E);
1269}
1270
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001271void ASTDumper::VisitFileScopeAsmDecl(const FileScopeAsmDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001272 dumpStmt(D->getAsmString());
1273}
1274
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001275void ASTDumper::VisitImportDecl(const ImportDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001276 OS << ' ' << D->getImportedModule()->getFullModuleName();
1277}
1278
Nico Weber66220292016-03-02 17:28:48 +00001279void ASTDumper::VisitPragmaCommentDecl(const PragmaCommentDecl *D) {
1280 OS << ' ';
1281 switch (D->getCommentKind()) {
1282 case PCK_Unknown: llvm_unreachable("unexpected pragma comment kind");
1283 case PCK_Compiler: OS << "compiler"; break;
1284 case PCK_ExeStr: OS << "exestr"; break;
1285 case PCK_Lib: OS << "lib"; break;
1286 case PCK_Linker: OS << "linker"; break;
1287 case PCK_User: OS << "user"; break;
1288 }
1289 StringRef Arg = D->getArg();
1290 if (!Arg.empty())
1291 OS << " \"" << Arg << "\"";
1292}
1293
Nico Webercbbaeb12016-03-02 19:28:54 +00001294void ASTDumper::VisitPragmaDetectMismatchDecl(
1295 const PragmaDetectMismatchDecl *D) {
1296 OS << " \"" << D->getName() << "\" \"" << D->getValue() << "\"";
1297}
1298
Alexey Bataev958b9e72016-03-31 09:30:50 +00001299void ASTDumper::VisitCapturedDecl(const CapturedDecl *D) {
1300 dumpStmt(D->getBody());
1301}
1302
1303//===----------------------------------------------------------------------===//
1304// OpenMP Declarations
1305//===----------------------------------------------------------------------===//
1306
1307void ASTDumper::VisitOMPThreadPrivateDecl(const OMPThreadPrivateDecl *D) {
1308 for (auto *E : D->varlists())
1309 dumpStmt(E);
1310}
1311
1312void ASTDumper::VisitOMPDeclareReductionDecl(const OMPDeclareReductionDecl *D) {
1313 dumpName(D);
1314 dumpType(D->getType());
1315 OS << " combiner";
1316 dumpStmt(D->getCombiner());
1317 if (auto *Initializer = D->getInitializer()) {
1318 OS << " initializer";
1319 dumpStmt(Initializer);
1320 }
1321}
1322
1323void ASTDumper::VisitOMPCapturedExprDecl(const OMPCapturedExprDecl *D) {
1324 dumpName(D);
1325 dumpType(D->getType());
1326 dumpStmt(D->getInit());
1327}
Nico Webercbbaeb12016-03-02 19:28:54 +00001328
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001329//===----------------------------------------------------------------------===//
1330// C++ Declarations
1331//===----------------------------------------------------------------------===//
1332
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001333void ASTDumper::VisitNamespaceDecl(const NamespaceDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001334 dumpName(D);
1335 if (D->isInline())
1336 OS << " inline";
1337 if (!D->isOriginalNamespace())
1338 dumpDeclRef(D->getOriginalNamespace(), "original");
1339}
1340
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001341void ASTDumper::VisitUsingDirectiveDecl(const UsingDirectiveDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001342 OS << ' ';
1343 dumpBareDeclRef(D->getNominatedNamespace());
1344}
1345
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001346void ASTDumper::VisitNamespaceAliasDecl(const NamespaceAliasDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001347 dumpName(D);
1348 dumpDeclRef(D->getAliasedNamespace());
1349}
1350
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001351void ASTDumper::VisitTypeAliasDecl(const TypeAliasDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001352 dumpName(D);
1353 dumpType(D->getUnderlyingType());
Richard Smithba3a4f92016-01-12 21:59:26 +00001354 dumpTypeAsChild(D->getUnderlyingType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001355}
1356
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001357void ASTDumper::VisitTypeAliasTemplateDecl(const TypeAliasTemplateDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001358 dumpName(D);
1359 dumpTemplateParameters(D->getTemplateParameters());
1360 dumpDecl(D->getTemplatedDecl());
1361}
1362
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001363void ASTDumper::VisitCXXRecordDecl(const CXXRecordDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001364 VisitRecordDecl(D);
1365 if (!D->isCompleteDefinition())
1366 return;
1367
Aaron Ballman574705e2014-03-13 15:41:46 +00001368 for (const auto &I : D->bases()) {
Richard Smithf7514452014-10-30 21:02:37 +00001369 dumpChild([=] {
1370 if (I.isVirtual())
1371 OS << "virtual ";
1372 dumpAccessSpecifier(I.getAccessSpecifier());
1373 dumpType(I.getType());
1374 if (I.isPackExpansion())
1375 OS << "...";
1376 });
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001377 }
1378}
1379
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001380void ASTDumper::VisitStaticAssertDecl(const StaticAssertDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001381 dumpStmt(D->getAssertExpr());
1382 dumpStmt(D->getMessage());
1383}
1384
Richard Smithcbdf7332014-03-18 02:07:28 +00001385template<typename SpecializationDecl>
Richard Smithf7514452014-10-30 21:02:37 +00001386void ASTDumper::VisitTemplateDeclSpecialization(const SpecializationDecl *D,
Richard Smithcbdf7332014-03-18 02:07:28 +00001387 bool DumpExplicitInst,
1388 bool DumpRefOnly) {
1389 bool DumpedAny = false;
1390 for (auto *RedeclWithBadType : D->redecls()) {
1391 // FIXME: The redecls() range sometimes has elements of a less-specific
1392 // type. (In particular, ClassTemplateSpecializationDecl::redecls() gives
1393 // us TagDecls, and should give CXXRecordDecls).
1394 auto *Redecl = dyn_cast<SpecializationDecl>(RedeclWithBadType);
1395 if (!Redecl) {
1396 // Found the injected-class-name for a class template. This will be dumped
1397 // as part of its surrounding class so we don't need to dump it here.
1398 assert(isa<CXXRecordDecl>(RedeclWithBadType) &&
1399 "expected an injected-class-name");
1400 continue;
1401 }
1402
1403 switch (Redecl->getTemplateSpecializationKind()) {
1404 case TSK_ExplicitInstantiationDeclaration:
1405 case TSK_ExplicitInstantiationDefinition:
1406 if (!DumpExplicitInst)
1407 break;
1408 // Fall through.
1409 case TSK_Undeclared:
1410 case TSK_ImplicitInstantiation:
Richard Smithf7514452014-10-30 21:02:37 +00001411 if (DumpRefOnly)
1412 dumpDeclRef(Redecl);
1413 else
1414 dumpDecl(Redecl);
Richard Smithcbdf7332014-03-18 02:07:28 +00001415 DumpedAny = true;
1416 break;
1417 case TSK_ExplicitSpecialization:
1418 break;
1419 }
1420 }
1421
1422 // Ensure we dump at least one decl for each specialization.
1423 if (!DumpedAny)
Richard Smithf7514452014-10-30 21:02:37 +00001424 dumpDeclRef(D);
Richard Smithcbdf7332014-03-18 02:07:28 +00001425}
1426
Richard Smith20ade552014-03-17 23:34:53 +00001427template<typename TemplateDecl>
1428void ASTDumper::VisitTemplateDecl(const TemplateDecl *D,
1429 bool DumpExplicitInst) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001430 dumpName(D);
1431 dumpTemplateParameters(D->getTemplateParameters());
Richard Smithdcc2c452014-03-17 23:00:06 +00001432
Richard Smithf7514452014-10-30 21:02:37 +00001433 dumpDecl(D->getTemplatedDecl());
Richard Smithdcc2c452014-03-17 23:00:06 +00001434
Richard Smithcbdf7332014-03-18 02:07:28 +00001435 for (auto *Child : D->specializations())
Richard Smithf7514452014-10-30 21:02:37 +00001436 VisitTemplateDeclSpecialization(Child, DumpExplicitInst,
Richard Smithcbdf7332014-03-18 02:07:28 +00001437 !D->isCanonicalDecl());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001438}
1439
Richard Smith20ade552014-03-17 23:34:53 +00001440void ASTDumper::VisitFunctionTemplateDecl(const FunctionTemplateDecl *D) {
1441 // FIXME: We don't add a declaration of a function template specialization
1442 // to its context when it's explicitly instantiated, so dump explicit
1443 // instantiations when we dump the template itself.
1444 VisitTemplateDecl(D, true);
1445}
1446
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001447void ASTDumper::VisitClassTemplateDecl(const ClassTemplateDecl *D) {
Richard Smith20ade552014-03-17 23:34:53 +00001448 VisitTemplateDecl(D, false);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001449}
1450
1451void ASTDumper::VisitClassTemplateSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001452 const ClassTemplateSpecializationDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001453 VisitCXXRecordDecl(D);
1454 dumpTemplateArgumentList(D->getTemplateArgs());
1455}
1456
1457void ASTDumper::VisitClassTemplatePartialSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001458 const ClassTemplatePartialSpecializationDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001459 VisitClassTemplateSpecializationDecl(D);
1460 dumpTemplateParameters(D->getTemplateParameters());
1461}
1462
1463void ASTDumper::VisitClassScopeFunctionSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001464 const ClassScopeFunctionSpecializationDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001465 dumpDeclRef(D->getSpecialization());
1466 if (D->hasExplicitTemplateArgs())
1467 dumpTemplateArgumentListInfo(D->templateArgs());
1468}
1469
Richard Smithd25789a2013-09-18 01:36:02 +00001470void ASTDumper::VisitVarTemplateDecl(const VarTemplateDecl *D) {
Richard Smith20ade552014-03-17 23:34:53 +00001471 VisitTemplateDecl(D, false);
Richard Smithd25789a2013-09-18 01:36:02 +00001472}
1473
David Majnemerd9b1a4f2015-11-04 03:40:30 +00001474void ASTDumper::VisitBuiltinTemplateDecl(const BuiltinTemplateDecl *D) {
1475 dumpName(D);
1476 dumpTemplateParameters(D->getTemplateParameters());
1477}
1478
Richard Smithd25789a2013-09-18 01:36:02 +00001479void ASTDumper::VisitVarTemplateSpecializationDecl(
1480 const VarTemplateSpecializationDecl *D) {
1481 dumpTemplateArgumentList(D->getTemplateArgs());
1482 VisitVarDecl(D);
1483}
1484
1485void ASTDumper::VisitVarTemplatePartialSpecializationDecl(
1486 const VarTemplatePartialSpecializationDecl *D) {
1487 dumpTemplateParameters(D->getTemplateParameters());
1488 VisitVarTemplateSpecializationDecl(D);
1489}
1490
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001491void ASTDumper::VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001492 if (D->wasDeclaredWithTypename())
1493 OS << " typename";
1494 else
1495 OS << " class";
Richard Smith1832a022017-02-21 02:04:03 +00001496 OS << " depth " << D->getDepth() << " index " << D->getIndex();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001497 if (D->isParameterPack())
1498 OS << " ...";
1499 dumpName(D);
Richard Smithf7514452014-10-30 21:02:37 +00001500 if (D->hasDefaultArgument())
Richard Smithecf74ff2014-03-23 20:50:39 +00001501 dumpTemplateArgument(D->getDefaultArgument());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001502}
1503
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001504void ASTDumper::VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001505 dumpType(D->getType());
Richard Smith1832a022017-02-21 02:04:03 +00001506 OS << " depth " << D->getDepth() << " index " << D->getIndex();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001507 if (D->isParameterPack())
1508 OS << " ...";
1509 dumpName(D);
Richard Smithf7514452014-10-30 21:02:37 +00001510 if (D->hasDefaultArgument())
Richard Smithecf74ff2014-03-23 20:50:39 +00001511 dumpTemplateArgument(D->getDefaultArgument());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001512}
1513
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001514void ASTDumper::VisitTemplateTemplateParmDecl(
1515 const TemplateTemplateParmDecl *D) {
Richard Smith1832a022017-02-21 02:04:03 +00001516 OS << " depth " << D->getDepth() << " index " << D->getIndex();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001517 if (D->isParameterPack())
1518 OS << " ...";
1519 dumpName(D);
1520 dumpTemplateParameters(D->getTemplateParameters());
Richard Smithf7514452014-10-30 21:02:37 +00001521 if (D->hasDefaultArgument())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001522 dumpTemplateArgumentLoc(D->getDefaultArgument());
1523}
1524
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001525void ASTDumper::VisitUsingDecl(const UsingDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001526 OS << ' ';
Dawn Perchikddd03bf2015-12-05 22:37:55 +00001527 if (D->getQualifier())
1528 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001529 OS << D->getNameAsString();
1530}
1531
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001532void ASTDumper::VisitUnresolvedUsingTypenameDecl(
1533 const UnresolvedUsingTypenameDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001534 OS << ' ';
Dawn Perchikddd03bf2015-12-05 22:37:55 +00001535 if (D->getQualifier())
1536 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001537 OS << D->getNameAsString();
1538}
1539
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001540void ASTDumper::VisitUnresolvedUsingValueDecl(const UnresolvedUsingValueDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001541 OS << ' ';
Dawn Perchikddd03bf2015-12-05 22:37:55 +00001542 if (D->getQualifier())
1543 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001544 OS << D->getNameAsString();
1545 dumpType(D->getType());
1546}
1547
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001548void ASTDumper::VisitUsingShadowDecl(const UsingShadowDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001549 OS << ' ';
1550 dumpBareDeclRef(D->getTargetDecl());
Richard Smithba3a4f92016-01-12 21:59:26 +00001551 if (auto *TD = dyn_cast<TypeDecl>(D->getUnderlyingDecl()))
1552 dumpTypeAsChild(TD->getTypeForDecl());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001553}
1554
Richard Smith5179eb72016-06-28 19:03:57 +00001555void ASTDumper::VisitConstructorUsingShadowDecl(
1556 const ConstructorUsingShadowDecl *D) {
1557 if (D->constructsVirtualBase())
1558 OS << " virtual";
1559
1560 dumpChild([=] {
1561 OS << "target ";
1562 dumpBareDeclRef(D->getTargetDecl());
1563 });
1564
1565 dumpChild([=] {
1566 OS << "nominated ";
1567 dumpBareDeclRef(D->getNominatedBaseClass());
1568 OS << ' ';
1569 dumpBareDeclRef(D->getNominatedBaseClassShadowDecl());
1570 });
1571
1572 dumpChild([=] {
1573 OS << "constructed ";
1574 dumpBareDeclRef(D->getConstructedBaseClass());
1575 OS << ' ';
1576 dumpBareDeclRef(D->getConstructedBaseClassShadowDecl());
1577 });
1578}
1579
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001580void ASTDumper::VisitLinkageSpecDecl(const LinkageSpecDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001581 switch (D->getLanguage()) {
1582 case LinkageSpecDecl::lang_c: OS << " C"; break;
1583 case LinkageSpecDecl::lang_cxx: OS << " C++"; break;
1584 }
1585}
1586
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001587void ASTDumper::VisitAccessSpecDecl(const AccessSpecDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001588 OS << ' ';
1589 dumpAccessSpecifier(D->getAccess());
1590}
1591
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001592void ASTDumper::VisitFriendDecl(const FriendDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001593 if (TypeSourceInfo *T = D->getFriendType())
1594 dumpType(T->getType());
1595 else
1596 dumpDecl(D->getFriendDecl());
1597}
1598
1599//===----------------------------------------------------------------------===//
1600// Obj-C Declarations
1601//===----------------------------------------------------------------------===//
1602
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001603void ASTDumper::VisitObjCIvarDecl(const ObjCIvarDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001604 dumpName(D);
1605 dumpType(D->getType());
1606 if (D->getSynthesize())
1607 OS << " synthesize";
1608
1609 switch (D->getAccessControl()) {
1610 case ObjCIvarDecl::None:
1611 OS << " none";
1612 break;
1613 case ObjCIvarDecl::Private:
1614 OS << " private";
1615 break;
1616 case ObjCIvarDecl::Protected:
1617 OS << " protected";
1618 break;
1619 case ObjCIvarDecl::Public:
1620 OS << " public";
1621 break;
1622 case ObjCIvarDecl::Package:
1623 OS << " package";
1624 break;
1625 }
1626}
1627
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001628void ASTDumper::VisitObjCMethodDecl(const ObjCMethodDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001629 if (D->isInstanceMethod())
1630 OS << " -";
1631 else
1632 OS << " +";
1633 dumpName(D);
Alp Toker314cc812014-01-25 16:55:45 +00001634 dumpType(D->getReturnType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001635
Richard Trieude5cc7d2013-01-31 01:44:26 +00001636 if (D->isThisDeclarationADefinition()) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001637 dumpDeclContext(D);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001638 } else {
David Majnemera3debed2016-06-24 05:33:44 +00001639 for (const ParmVarDecl *Parameter : D->parameters())
1640 dumpDecl(Parameter);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001641 }
1642
Richard Smithf7514452014-10-30 21:02:37 +00001643 if (D->isVariadic())
1644 dumpChild([=] { OS << "..."; });
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001645
Richard Smithf7514452014-10-30 21:02:37 +00001646 if (D->hasBody())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001647 dumpStmt(D->getBody());
1648}
1649
Douglas Gregor85f3f952015-07-07 03:57:15 +00001650void ASTDumper::VisitObjCTypeParamDecl(const ObjCTypeParamDecl *D) {
1651 dumpName(D);
Douglas Gregor1ac1b632015-07-07 03:58:54 +00001652 switch (D->getVariance()) {
1653 case ObjCTypeParamVariance::Invariant:
1654 break;
1655
1656 case ObjCTypeParamVariance::Covariant:
1657 OS << " covariant";
1658 break;
1659
1660 case ObjCTypeParamVariance::Contravariant:
1661 OS << " contravariant";
1662 break;
1663 }
1664
Douglas Gregor85f3f952015-07-07 03:57:15 +00001665 if (D->hasExplicitBound())
1666 OS << " bounded";
1667 dumpType(D->getUnderlyingType());
1668}
1669
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001670void ASTDumper::VisitObjCCategoryDecl(const ObjCCategoryDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001671 dumpName(D);
1672 dumpDeclRef(D->getClassInterface());
Douglas Gregor85f3f952015-07-07 03:57:15 +00001673 dumpObjCTypeParamList(D->getTypeParamList());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001674 dumpDeclRef(D->getImplementation());
1675 for (ObjCCategoryDecl::protocol_iterator I = D->protocol_begin(),
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001676 E = D->protocol_end();
Richard Smithf7514452014-10-30 21:02:37 +00001677 I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001678 dumpDeclRef(*I);
1679}
1680
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001681void ASTDumper::VisitObjCCategoryImplDecl(const ObjCCategoryImplDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001682 dumpName(D);
1683 dumpDeclRef(D->getClassInterface());
1684 dumpDeclRef(D->getCategoryDecl());
1685}
1686
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001687void ASTDumper::VisitObjCProtocolDecl(const ObjCProtocolDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001688 dumpName(D);
Richard Smithdcc2c452014-03-17 23:00:06 +00001689
Richard Smith7fcb35f2014-03-18 02:37:59 +00001690 for (auto *Child : D->protocols())
Richard Smithf7514452014-10-30 21:02:37 +00001691 dumpDeclRef(Child);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001692}
1693
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001694void ASTDumper::VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001695 dumpName(D);
Douglas Gregor85f3f952015-07-07 03:57:15 +00001696 dumpObjCTypeParamList(D->getTypeParamListAsWritten());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001697 dumpDeclRef(D->getSuperClass(), "super");
Richard Smithdcc2c452014-03-17 23:00:06 +00001698
Richard Smithf7514452014-10-30 21:02:37 +00001699 dumpDeclRef(D->getImplementation());
Richard Smith7fcb35f2014-03-18 02:37:59 +00001700 for (auto *Child : D->protocols())
Richard Smithf7514452014-10-30 21:02:37 +00001701 dumpDeclRef(Child);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001702}
1703
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001704void ASTDumper::VisitObjCImplementationDecl(const ObjCImplementationDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001705 dumpName(D);
1706 dumpDeclRef(D->getSuperClass(), "super");
1707 dumpDeclRef(D->getClassInterface());
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001708 for (ObjCImplementationDecl::init_const_iterator I = D->init_begin(),
1709 E = D->init_end();
Richard Smithf7514452014-10-30 21:02:37 +00001710 I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001711 dumpCXXCtorInitializer(*I);
1712}
1713
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001714void ASTDumper::VisitObjCCompatibleAliasDecl(const ObjCCompatibleAliasDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001715 dumpName(D);
1716 dumpDeclRef(D->getClassInterface());
1717}
1718
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001719void ASTDumper::VisitObjCPropertyDecl(const ObjCPropertyDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001720 dumpName(D);
1721 dumpType(D->getType());
1722
1723 if (D->getPropertyImplementation() == ObjCPropertyDecl::Required)
1724 OS << " required";
1725 else if (D->getPropertyImplementation() == ObjCPropertyDecl::Optional)
1726 OS << " optional";
1727
1728 ObjCPropertyDecl::PropertyAttributeKind Attrs = D->getPropertyAttributes();
1729 if (Attrs != ObjCPropertyDecl::OBJC_PR_noattr) {
1730 if (Attrs & ObjCPropertyDecl::OBJC_PR_readonly)
1731 OS << " readonly";
1732 if (Attrs & ObjCPropertyDecl::OBJC_PR_assign)
1733 OS << " assign";
1734 if (Attrs & ObjCPropertyDecl::OBJC_PR_readwrite)
1735 OS << " readwrite";
1736 if (Attrs & ObjCPropertyDecl::OBJC_PR_retain)
1737 OS << " retain";
1738 if (Attrs & ObjCPropertyDecl::OBJC_PR_copy)
1739 OS << " copy";
1740 if (Attrs & ObjCPropertyDecl::OBJC_PR_nonatomic)
1741 OS << " nonatomic";
1742 if (Attrs & ObjCPropertyDecl::OBJC_PR_atomic)
1743 OS << " atomic";
1744 if (Attrs & ObjCPropertyDecl::OBJC_PR_weak)
1745 OS << " weak";
1746 if (Attrs & ObjCPropertyDecl::OBJC_PR_strong)
1747 OS << " strong";
1748 if (Attrs & ObjCPropertyDecl::OBJC_PR_unsafe_unretained)
1749 OS << " unsafe_unretained";
Manman Ren387ff7f2016-01-26 18:52:43 +00001750 if (Attrs & ObjCPropertyDecl::OBJC_PR_class)
1751 OS << " class";
Richard Smithf7514452014-10-30 21:02:37 +00001752 if (Attrs & ObjCPropertyDecl::OBJC_PR_getter)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001753 dumpDeclRef(D->getGetterMethodDecl(), "getter");
Richard Smithf7514452014-10-30 21:02:37 +00001754 if (Attrs & ObjCPropertyDecl::OBJC_PR_setter)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001755 dumpDeclRef(D->getSetterMethodDecl(), "setter");
1756 }
1757}
1758
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001759void ASTDumper::VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001760 dumpName(D->getPropertyDecl());
1761 if (D->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize)
1762 OS << " synthesize";
1763 else
1764 OS << " dynamic";
1765 dumpDeclRef(D->getPropertyDecl());
1766 dumpDeclRef(D->getPropertyIvarDecl());
1767}
1768
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001769void ASTDumper::VisitBlockDecl(const BlockDecl *D) {
David Majnemer59f77922016-06-24 04:05:48 +00001770 for (auto I : D->parameters())
Aaron Ballmanb2b8b1d2014-03-07 16:09:59 +00001771 dumpDecl(I);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001772
Richard Smithf7514452014-10-30 21:02:37 +00001773 if (D->isVariadic())
1774 dumpChild([=]{ OS << "..."; });
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001775
Richard Smithf7514452014-10-30 21:02:37 +00001776 if (D->capturesCXXThis())
1777 dumpChild([=]{ OS << "capture this"; });
1778
Aaron Ballman9371dd22014-03-14 18:34:04 +00001779 for (const auto &I : D->captures()) {
Richard Smithf7514452014-10-30 21:02:37 +00001780 dumpChild([=] {
1781 OS << "capture";
1782 if (I.isByRef())
1783 OS << " byref";
1784 if (I.isNested())
1785 OS << " nested";
1786 if (I.getVariable()) {
1787 OS << ' ';
1788 dumpBareDeclRef(I.getVariable());
1789 }
1790 if (I.hasCopyExpr())
1791 dumpStmt(I.getCopyExpr());
1792 });
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001793 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001794 dumpStmt(D->getBody());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001795}
1796
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001797//===----------------------------------------------------------------------===//
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001798// Stmt dumping methods.
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001799//===----------------------------------------------------------------------===//
1800
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001801void ASTDumper::dumpStmt(const Stmt *S) {
Richard Smithf7514452014-10-30 21:02:37 +00001802 dumpChild([=] {
1803 if (!S) {
1804 ColorScope Color(*this, NullColor);
1805 OS << "<<<NULL>>>";
1806 return;
1807 }
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001808
Richard Smithf7514452014-10-30 21:02:37 +00001809 if (const DeclStmt *DS = dyn_cast<DeclStmt>(S)) {
1810 VisitDeclStmt(DS);
1811 return;
1812 }
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001813
Richard Smithf7514452014-10-30 21:02:37 +00001814 ConstStmtVisitor<ASTDumper>::Visit(S);
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001815
Benjamin Kramer642f1732015-07-02 21:03:14 +00001816 for (const Stmt *SubStmt : S->children())
1817 dumpStmt(SubStmt);
Richard Smithf7514452014-10-30 21:02:37 +00001818 });
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001819}
1820
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001821void ASTDumper::VisitStmt(const Stmt *Node) {
Richard Trieud215b8d2013-01-26 01:31:20 +00001822 {
1823 ColorScope Color(*this, StmtColor);
1824 OS << Node->getStmtClassName();
1825 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001826 dumpPointer(Node);
1827 dumpSourceRange(Node->getSourceRange());
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001828}
1829
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001830void ASTDumper::VisitDeclStmt(const DeclStmt *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001831 VisitStmt(Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001832 for (DeclStmt::const_decl_iterator I = Node->decl_begin(),
1833 E = Node->decl_end();
Richard Smithf7514452014-10-30 21:02:37 +00001834 I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001835 dumpDecl(*I);
Ted Kremenek433a4922007-12-12 06:59:42 +00001836}
1837
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001838void ASTDumper::VisitAttributedStmt(const AttributedStmt *Node) {
Alexander Kornienko5bc364e2013-01-07 17:53:08 +00001839 VisitStmt(Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001840 for (ArrayRef<const Attr *>::iterator I = Node->getAttrs().begin(),
1841 E = Node->getAttrs().end();
Richard Smithf7514452014-10-30 21:02:37 +00001842 I != E; ++I)
Alexander Kornienko5bc364e2013-01-07 17:53:08 +00001843 dumpAttr(*I);
1844}
1845
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001846void ASTDumper::VisitLabelStmt(const LabelStmt *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001847 VisitStmt(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001848 OS << " '" << Node->getName() << "'";
Chris Lattnercbe4f772007-08-08 22:51:59 +00001849}
1850
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001851void ASTDumper::VisitGotoStmt(const GotoStmt *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001852 VisitStmt(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001853 OS << " '" << Node->getLabel()->getName() << "'";
1854 dumpPointer(Node->getLabel());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001855}
1856
Pavel Labath1ef83422013-09-04 14:35:00 +00001857void ASTDumper::VisitCXXCatchStmt(const CXXCatchStmt *Node) {
1858 VisitStmt(Node);
1859 dumpDecl(Node->getExceptionDecl());
1860}
1861
Alexey Bataev958b9e72016-03-31 09:30:50 +00001862void ASTDumper::VisitCapturedStmt(const CapturedStmt *Node) {
1863 VisitStmt(Node);
1864 dumpDecl(Node->getCapturedDecl());
1865}
1866
1867//===----------------------------------------------------------------------===//
1868// OpenMP dumping methods.
1869//===----------------------------------------------------------------------===//
1870
1871void ASTDumper::VisitOMPExecutableDirective(
1872 const OMPExecutableDirective *Node) {
1873 VisitStmt(Node);
1874 for (auto *C : Node->clauses()) {
1875 dumpChild([=] {
1876 if (!C) {
1877 ColorScope Color(*this, NullColor);
1878 OS << "<<<NULL>>> OMPClause";
1879 return;
1880 }
1881 {
1882 ColorScope Color(*this, AttrColor);
1883 StringRef ClauseName(getOpenMPClauseName(C->getClauseKind()));
1884 OS << "OMP" << ClauseName.substr(/*Start=*/0, /*N=*/1).upper()
1885 << ClauseName.drop_front() << "Clause";
1886 }
1887 dumpPointer(C);
1888 dumpSourceRange(SourceRange(C->getLocStart(), C->getLocEnd()));
1889 if (C->isImplicit())
1890 OS << " <implicit>";
1891 for (auto *S : C->children())
1892 dumpStmt(S);
1893 });
1894 }
1895}
1896
Chris Lattnercbe4f772007-08-08 22:51:59 +00001897//===----------------------------------------------------------------------===//
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001898// Expr dumping methods.
Chris Lattnercbe4f772007-08-08 22:51:59 +00001899//===----------------------------------------------------------------------===//
1900
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001901void ASTDumper::VisitExpr(const Expr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001902 VisitStmt(Node);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001903 dumpType(Node->getType());
1904
Richard Trieud215b8d2013-01-26 01:31:20 +00001905 {
1906 ColorScope Color(*this, ValueKindColor);
1907 switch (Node->getValueKind()) {
1908 case VK_RValue:
1909 break;
1910 case VK_LValue:
1911 OS << " lvalue";
1912 break;
1913 case VK_XValue:
1914 OS << " xvalue";
1915 break;
1916 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001917 }
1918
Richard Trieud215b8d2013-01-26 01:31:20 +00001919 {
1920 ColorScope Color(*this, ObjectKindColor);
1921 switch (Node->getObjectKind()) {
1922 case OK_Ordinary:
1923 break;
1924 case OK_BitField:
1925 OS << " bitfield";
1926 break;
1927 case OK_ObjCProperty:
1928 OS << " objcproperty";
1929 break;
1930 case OK_ObjCSubscript:
1931 OS << " objcsubscript";
1932 break;
1933 case OK_VectorComponent:
1934 OS << " vectorcomponent";
1935 break;
1936 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001937 }
Chris Lattnercbe4f772007-08-08 22:51:59 +00001938}
1939
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001940static void dumpBasePath(raw_ostream &OS, const CastExpr *Node) {
John McCallcf142162010-08-07 06:22:56 +00001941 if (Node->path_empty())
Anders Carlssona70cff62010-04-24 19:06:50 +00001942 return;
1943
1944 OS << " (";
1945 bool First = true;
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001946 for (CastExpr::path_const_iterator I = Node->path_begin(),
1947 E = Node->path_end();
1948 I != E; ++I) {
Anders Carlssona70cff62010-04-24 19:06:50 +00001949 const CXXBaseSpecifier *Base = *I;
1950 if (!First)
1951 OS << " -> ";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001952
Anders Carlssona70cff62010-04-24 19:06:50 +00001953 const CXXRecordDecl *RD =
1954 cast<CXXRecordDecl>(Base->getType()->getAs<RecordType>()->getDecl());
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001955
Anders Carlssona70cff62010-04-24 19:06:50 +00001956 if (Base->isVirtual())
1957 OS << "virtual ";
1958 OS << RD->getName();
1959 First = false;
1960 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001961
Anders Carlssona70cff62010-04-24 19:06:50 +00001962 OS << ')';
1963}
1964
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001965void ASTDumper::VisitCastExpr(const CastExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001966 VisitExpr(Node);
Richard Trieud215b8d2013-01-26 01:31:20 +00001967 OS << " <";
1968 {
1969 ColorScope Color(*this, CastColor);
1970 OS << Node->getCastKindName();
1971 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001972 dumpBasePath(OS, Node);
Anders Carlssona70cff62010-04-24 19:06:50 +00001973 OS << ">";
Anders Carlssond7923c62009-08-22 23:33:40 +00001974}
1975
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001976void ASTDumper::VisitDeclRefExpr(const DeclRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001977 VisitExpr(Node);
Ted Kremenek5f64ca82007-09-10 17:32:55 +00001978
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001979 OS << " ";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001980 dumpBareDeclRef(Node->getDecl());
Chandler Carruth8d26bb02011-05-01 23:48:14 +00001981 if (Node->getDecl() != Node->getFoundDecl()) {
1982 OS << " (";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001983 dumpBareDeclRef(Node->getFoundDecl());
Chandler Carruth8d26bb02011-05-01 23:48:14 +00001984 OS << ")";
1985 }
John McCall351762c2011-02-07 10:33:21 +00001986}
1987
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001988void ASTDumper::VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001989 VisitExpr(Node);
John McCall76d09942009-12-11 21:50:11 +00001990 OS << " (";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001991 if (!Node->requiresADL())
1992 OS << "no ";
Benjamin Kramerb11416d2010-04-17 09:33:03 +00001993 OS << "ADL) = '" << Node->getName() << '\'';
John McCall76d09942009-12-11 21:50:11 +00001994
1995 UnresolvedLookupExpr::decls_iterator
1996 I = Node->decls_begin(), E = Node->decls_end();
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001997 if (I == E)
1998 OS << " empty";
John McCall76d09942009-12-11 21:50:11 +00001999 for (; I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002000 dumpPointer(*I);
John McCall76d09942009-12-11 21:50:11 +00002001}
2002
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002003void ASTDumper::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002004 VisitExpr(Node);
Steve Naroff5d5efca2008-03-12 13:19:12 +00002005
Richard Trieud215b8d2013-01-26 01:31:20 +00002006 {
2007 ColorScope Color(*this, DeclKindNameColor);
2008 OS << " " << Node->getDecl()->getDeclKindName() << "Decl";
2009 }
2010 OS << "='" << *Node->getDecl() << "'";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002011 dumpPointer(Node->getDecl());
Steve Naroffb3424a92008-05-23 22:01:24 +00002012 if (Node->isFreeIvar())
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002013 OS << " isFreeIvar";
Steve Naroff5d5efca2008-03-12 13:19:12 +00002014}
2015
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002016void ASTDumper::VisitPredefinedExpr(const PredefinedExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002017 VisitExpr(Node);
Alexey Bataevec474782014-10-09 08:45:04 +00002018 OS << " " << PredefinedExpr::getIdentTypeName(Node->getIdentType());
Chris Lattnercbe4f772007-08-08 22:51:59 +00002019}
2020
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002021void ASTDumper::VisitCharacterLiteral(const CharacterLiteral *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002022 VisitExpr(Node);
Richard Trieud215b8d2013-01-26 01:31:20 +00002023 ColorScope Color(*this, ValueColor);
Richard Trieu364ee422011-11-03 23:56:23 +00002024 OS << " " << Node->getValue();
Chris Lattnercbe4f772007-08-08 22:51:59 +00002025}
2026
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002027void ASTDumper::VisitIntegerLiteral(const IntegerLiteral *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002028 VisitExpr(Node);
Chris Lattnercbe4f772007-08-08 22:51:59 +00002029
2030 bool isSigned = Node->getType()->isSignedIntegerType();
Richard Trieud215b8d2013-01-26 01:31:20 +00002031 ColorScope Color(*this, ValueColor);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002032 OS << " " << Node->getValue().toString(10, isSigned);
Chris Lattnercbe4f772007-08-08 22:51:59 +00002033}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002034
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002035void ASTDumper::VisitFloatingLiteral(const FloatingLiteral *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002036 VisitExpr(Node);
Richard Trieud215b8d2013-01-26 01:31:20 +00002037 ColorScope Color(*this, ValueColor);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002038 OS << " " << Node->getValueAsApproximateDouble();
Chris Lattnercbe4f772007-08-08 22:51:59 +00002039}
Chris Lattner1c20a172007-08-26 03:42:43 +00002040
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002041void ASTDumper::VisitStringLiteral(const StringLiteral *Str) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002042 VisitExpr(Str);
Richard Trieud215b8d2013-01-26 01:31:20 +00002043 ColorScope Color(*this, ValueColor);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002044 OS << " ";
Richard Trieudc355912012-06-13 20:25:24 +00002045 Str->outputString(OS);
Chris Lattnercbe4f772007-08-08 22:51:59 +00002046}
Chris Lattner84ca3762007-08-30 01:00:35 +00002047
Richard Smithf0514962014-06-03 08:24:28 +00002048void ASTDumper::VisitInitListExpr(const InitListExpr *ILE) {
2049 VisitExpr(ILE);
2050 if (auto *Filler = ILE->getArrayFiller()) {
Richard Smithf7514452014-10-30 21:02:37 +00002051 dumpChild([=] {
2052 OS << "array filler";
2053 dumpStmt(Filler);
2054 });
Richard Smithf0514962014-06-03 08:24:28 +00002055 }
2056 if (auto *Field = ILE->getInitializedFieldInUnion()) {
2057 OS << " field ";
2058 dumpBareDeclRef(Field);
2059 }
2060}
2061
Richard Smith410306b2016-12-12 02:53:20 +00002062void ASTDumper::VisitArrayInitLoopExpr(const ArrayInitLoopExpr *E) {
2063 VisitExpr(E);
2064}
2065
2066void ASTDumper::VisitArrayInitIndexExpr(const ArrayInitIndexExpr *E) {
2067 VisitExpr(E);
2068}
2069
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002070void ASTDumper::VisitUnaryOperator(const UnaryOperator *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002071 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002072 OS << " " << (Node->isPostfix() ? "postfix" : "prefix")
2073 << " '" << UnaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
Chris Lattnercbe4f772007-08-08 22:51:59 +00002074}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002075
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002076void ASTDumper::VisitUnaryExprOrTypeTraitExpr(
2077 const UnaryExprOrTypeTraitExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002078 VisitExpr(Node);
Peter Collingbournee190dee2011-03-11 19:24:49 +00002079 switch(Node->getKind()) {
2080 case UETT_SizeOf:
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002081 OS << " sizeof";
Peter Collingbournee190dee2011-03-11 19:24:49 +00002082 break;
2083 case UETT_AlignOf:
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002084 OS << " alignof";
Peter Collingbournee190dee2011-03-11 19:24:49 +00002085 break;
2086 case UETT_VecStep:
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002087 OS << " vec_step";
Peter Collingbournee190dee2011-03-11 19:24:49 +00002088 break;
Alexey Bataev00396512015-07-02 03:40:19 +00002089 case UETT_OpenMPRequiredSimdAlign:
2090 OS << " __builtin_omp_required_simd_align";
2091 break;
Peter Collingbournee190dee2011-03-11 19:24:49 +00002092 }
Sebastian Redl6f282892008-11-11 17:56:53 +00002093 if (Node->isArgumentType())
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002094 dumpType(Node->getArgumentType());
Chris Lattnercbe4f772007-08-08 22:51:59 +00002095}
Chris Lattnerdb3b3ff2007-08-09 17:35:30 +00002096
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002097void ASTDumper::VisitMemberExpr(const MemberExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002098 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002099 OS << " " << (Node->isArrow() ? "->" : ".") << *Node->getMemberDecl();
2100 dumpPointer(Node->getMemberDecl());
Chris Lattnercbe4f772007-08-08 22:51:59 +00002101}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002102
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002103void ASTDumper::VisitExtVectorElementExpr(const ExtVectorElementExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002104 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002105 OS << " " << Node->getAccessor().getNameStart();
Chris Lattnercbe4f772007-08-08 22:51:59 +00002106}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002107
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002108void ASTDumper::VisitBinaryOperator(const BinaryOperator *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002109 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002110 OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
Chris Lattner86928112007-08-25 02:00:02 +00002111}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002112
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002113void ASTDumper::VisitCompoundAssignOperator(
2114 const CompoundAssignOperator *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002115 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002116 OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode())
2117 << "' ComputeLHSTy=";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002118 dumpBareType(Node->getComputationLHSType());
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002119 OS << " ComputeResultTy=";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002120 dumpBareType(Node->getComputationResultType());
Chris Lattnercbe4f772007-08-08 22:51:59 +00002121}
Chris Lattnercbe4f772007-08-08 22:51:59 +00002122
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002123void ASTDumper::VisitBlockExpr(const BlockExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002124 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002125 dumpDecl(Node->getBlockDecl());
John McCall351762c2011-02-07 10:33:21 +00002126}
2127
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002128void ASTDumper::VisitOpaqueValueExpr(const OpaqueValueExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002129 VisitExpr(Node);
John McCallfe96e0b2011-11-06 09:01:30 +00002130
Richard Smithf7514452014-10-30 21:02:37 +00002131 if (Expr *Source = Node->getSourceExpr())
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002132 dumpStmt(Source);
John McCallfe96e0b2011-11-06 09:01:30 +00002133}
2134
Chris Lattnercbe4f772007-08-08 22:51:59 +00002135// GNU extensions.
2136
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002137void ASTDumper::VisitAddrLabelExpr(const AddrLabelExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002138 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002139 OS << " " << Node->getLabel()->getName();
2140 dumpPointer(Node->getLabel());
Chris Lattnercbe4f772007-08-08 22:51:59 +00002141}
2142
Chris Lattner8f184b12007-08-09 18:03:18 +00002143//===----------------------------------------------------------------------===//
2144// C++ Expressions
2145//===----------------------------------------------------------------------===//
Chris Lattnercbe4f772007-08-08 22:51:59 +00002146
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002147void ASTDumper::VisitCXXNamedCastExpr(const CXXNamedCastExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002148 VisitExpr(Node);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002149 OS << " " << Node->getCastName()
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002150 << "<" << Node->getTypeAsWritten().getAsString() << ">"
Anders Carlssona70cff62010-04-24 19:06:50 +00002151 << " <" << Node->getCastKindName();
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002152 dumpBasePath(OS, Node);
Anders Carlssona70cff62010-04-24 19:06:50 +00002153 OS << ">";
Chris Lattnercbe4f772007-08-08 22:51:59 +00002154}
2155
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002156void ASTDumper::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002157 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002158 OS << " " << (Node->getValue() ? "true" : "false");
Chris Lattnercbe4f772007-08-08 22:51:59 +00002159}
2160
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002161void ASTDumper::VisitCXXThisExpr(const CXXThisExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002162 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002163 OS << " this";
Douglas Gregor8ea1f532008-11-04 14:56:14 +00002164}
2165
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002166void ASTDumper::VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002167 VisitExpr(Node);
Eli Friedman29538892011-09-02 17:38:59 +00002168 OS << " functional cast to " << Node->getTypeAsWritten().getAsString()
2169 << " <" << Node->getCastKindName() << ">";
Douglas Gregore200adc2008-10-27 19:41:14 +00002170}
2171
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002172void ASTDumper::VisitCXXConstructExpr(const CXXConstructExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002173 VisitExpr(Node);
John McCalleba90cd2010-02-02 19:03:45 +00002174 CXXConstructorDecl *Ctor = Node->getConstructor();
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002175 dumpType(Ctor->getType());
Anders Carlsson073846832009-08-12 00:21:52 +00002176 if (Node->isElidable())
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002177 OS << " elidable";
John McCall85370042010-08-07 06:38:55 +00002178 if (Node->requiresZeroInitialization())
2179 OS << " zeroing";
Anders Carlsson073846832009-08-12 00:21:52 +00002180}
2181
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002182void ASTDumper::VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002183 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002184 OS << " ";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002185 dumpCXXTemporary(Node->getTemporary());
Anders Carlsson073846832009-08-12 00:21:52 +00002186}
2187
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002188void ASTDumper::VisitCXXNewExpr(const CXXNewExpr *Node) {
2189 VisitExpr(Node);
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002190 if (Node->isGlobalNew())
Reid Kleckner461c0c62015-03-19 18:47:47 +00002191 OS << " global";
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002192 if (Node->isArray())
Reid Kleckner461c0c62015-03-19 18:47:47 +00002193 OS << " array";
2194 if (Node->getOperatorNew()) {
2195 OS << ' ';
2196 dumpBareDeclRef(Node->getOperatorNew());
2197 }
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002198 // We could dump the deallocation function used in case of error, but it's
2199 // usually not that interesting.
2200}
2201
2202void ASTDumper::VisitCXXDeleteExpr(const CXXDeleteExpr *Node) {
2203 VisitExpr(Node);
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002204 if (Node->isGlobalDelete())
Reid Kleckner461c0c62015-03-19 18:47:47 +00002205 OS << " global";
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002206 if (Node->isArrayForm())
Reid Kleckner461c0c62015-03-19 18:47:47 +00002207 OS << " array";
2208 if (Node->getOperatorDelete()) {
2209 OS << ' ';
2210 dumpBareDeclRef(Node->getOperatorDelete());
2211 }
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002212}
2213
Richard Smithe6c01442013-06-05 00:46:14 +00002214void
2215ASTDumper::VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *Node) {
2216 VisitExpr(Node);
2217 if (const ValueDecl *VD = Node->getExtendingDecl()) {
2218 OS << " extended by ";
2219 dumpBareDeclRef(VD);
2220 }
2221}
2222
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002223void ASTDumper::VisitExprWithCleanups(const ExprWithCleanups *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002224 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002225 for (unsigned i = 0, e = Node->getNumObjects(); i != e; ++i)
2226 dumpDeclRef(Node->getObject(i), "cleanup");
Anders Carlsson073846832009-08-12 00:21:52 +00002227}
2228
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002229void ASTDumper::dumpCXXTemporary(const CXXTemporary *Temporary) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002230 OS << "(CXXTemporary";
2231 dumpPointer(Temporary);
2232 OS << ")";
Anders Carlsson073846832009-08-12 00:21:52 +00002233}
2234
Serge Pavlov6b926032015-02-16 19:58:41 +00002235void ASTDumper::VisitSizeOfPackExpr(const SizeOfPackExpr *Node) {
2236 VisitExpr(Node);
2237 dumpPointer(Node->getPack());
2238 dumpName(Node->getPack());
Richard Smithd784e682015-09-23 21:41:42 +00002239 if (Node->isPartiallySubstituted())
2240 for (const auto &A : Node->getPartialArguments())
2241 dumpTemplateArgument(A);
Serge Pavlov6b926032015-02-16 19:58:41 +00002242}
2243
Alex Lorenzddbe0f52016-11-09 14:02:18 +00002244void ASTDumper::VisitCXXDependentScopeMemberExpr(
2245 const CXXDependentScopeMemberExpr *Node) {
2246 VisitExpr(Node);
2247 OS << " " << (Node->isArrow() ? "->" : ".") << Node->getMember();
2248}
Serge Pavlov6b926032015-02-16 19:58:41 +00002249
Anders Carlsson76f4a902007-08-21 17:43:55 +00002250//===----------------------------------------------------------------------===//
2251// Obj-C Expressions
2252//===----------------------------------------------------------------------===//
2253
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002254void ASTDumper::VisitObjCMessageExpr(const ObjCMessageExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002255 VisitExpr(Node);
Aaron Ballmanb190f972014-01-03 17:59:55 +00002256 OS << " selector=";
2257 Node->getSelector().print(OS);
Douglas Gregor9a129192010-04-21 00:45:42 +00002258 switch (Node->getReceiverKind()) {
2259 case ObjCMessageExpr::Instance:
2260 break;
2261
2262 case ObjCMessageExpr::Class:
2263 OS << " class=";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002264 dumpBareType(Node->getClassReceiver());
Douglas Gregor9a129192010-04-21 00:45:42 +00002265 break;
2266
2267 case ObjCMessageExpr::SuperInstance:
2268 OS << " super (instance)";
2269 break;
2270
2271 case ObjCMessageExpr::SuperClass:
2272 OS << " super (class)";
2273 break;
2274 }
Ted Kremenek36748da2008-02-29 22:04:05 +00002275}
2276
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002277void ASTDumper::VisitObjCBoxedExpr(const ObjCBoxedExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002278 VisitExpr(Node);
Richard Trieu4b259c82016-06-09 22:03:04 +00002279 if (auto *BoxingMethod = Node->getBoxingMethod()) {
2280 OS << " selector=";
2281 BoxingMethod->getSelector().print(OS);
2282 }
Argyrios Kyrtzidis9dd40892012-05-10 20:02:31 +00002283}
2284
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002285void ASTDumper::VisitObjCAtCatchStmt(const ObjCAtCatchStmt *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002286 VisitStmt(Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002287 if (const VarDecl *CatchParam = Node->getCatchParamDecl())
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002288 dumpDecl(CatchParam);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002289 else
Douglas Gregor96c79492010-04-23 22:50:49 +00002290 OS << " catch all";
Douglas Gregor96c79492010-04-23 22:50:49 +00002291}
2292
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002293void ASTDumper::VisitObjCEncodeExpr(const ObjCEncodeExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002294 VisitExpr(Node);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002295 dumpType(Node->getEncodedType());
Anders Carlssonc5a81eb2007-08-22 15:14:15 +00002296}
2297
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002298void ASTDumper::VisitObjCSelectorExpr(const ObjCSelectorExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002299 VisitExpr(Node);
Mike Stump11289f42009-09-09 15:08:12 +00002300
Aaron Ballmanb190f972014-01-03 17:59:55 +00002301 OS << " ";
2302 Node->getSelector().print(OS);
Fariborz Jahanian4bef4622007-10-16 20:40:23 +00002303}
2304
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002305void ASTDumper::VisitObjCProtocolExpr(const ObjCProtocolExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002306 VisitExpr(Node);
Mike Stump11289f42009-09-09 15:08:12 +00002307
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002308 OS << ' ' << *Node->getProtocol();
Fariborz Jahaniana32aaef2007-10-17 16:58:11 +00002309}
Daniel Dunbar4b8c6db2008-08-30 05:35:15 +00002310
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002311void ASTDumper::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002312 VisitExpr(Node);
John McCallb7bd14f2010-12-02 01:19:52 +00002313 if (Node->isImplicitProperty()) {
Fariborz Jahanian0f0b3022010-12-22 19:46:35 +00002314 OS << " Kind=MethodRef Getter=\"";
2315 if (Node->getImplicitPropertyGetter())
Aaron Ballmanb190f972014-01-03 17:59:55 +00002316 Node->getImplicitPropertyGetter()->getSelector().print(OS);
Fariborz Jahanian0f0b3022010-12-22 19:46:35 +00002317 else
2318 OS << "(null)";
2319
2320 OS << "\" Setter=\"";
John McCallb7bd14f2010-12-02 01:19:52 +00002321 if (ObjCMethodDecl *Setter = Node->getImplicitPropertySetter())
Aaron Ballmanb190f972014-01-03 17:59:55 +00002322 Setter->getSelector().print(OS);
John McCallb7bd14f2010-12-02 01:19:52 +00002323 else
2324 OS << "(null)";
2325 OS << "\"";
2326 } else {
Benjamin Kramerb89514a2011-10-14 18:45:37 +00002327 OS << " Kind=PropertyRef Property=\"" << *Node->getExplicitProperty() <<'"';
John McCallb7bd14f2010-12-02 01:19:52 +00002328 }
Fariborz Jahanian8a1810f2008-11-22 18:39:36 +00002329
Fariborz Jahanian681c0752010-10-14 16:04:05 +00002330 if (Node->isSuperReceiver())
2331 OS << " super";
Argyrios Kyrtzidisab468b02012-03-30 00:19:18 +00002332
2333 OS << " Messaging=";
2334 if (Node->isMessagingGetter() && Node->isMessagingSetter())
2335 OS << "Getter&Setter";
2336 else if (Node->isMessagingGetter())
2337 OS << "Getter";
2338 else if (Node->isMessagingSetter())
2339 OS << "Setter";
Douglas Gregor8ea1f532008-11-04 14:56:14 +00002340}
2341
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002342void ASTDumper::VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002343 VisitExpr(Node);
Ted Kremeneke65b0862012-03-06 20:05:56 +00002344 if (Node->isArraySubscriptRefExpr())
2345 OS << " Kind=ArraySubscript GetterForArray=\"";
2346 else
2347 OS << " Kind=DictionarySubscript GetterForDictionary=\"";
2348 if (Node->getAtIndexMethodDecl())
Aaron Ballmanb190f972014-01-03 17:59:55 +00002349 Node->getAtIndexMethodDecl()->getSelector().print(OS);
Ted Kremeneke65b0862012-03-06 20:05:56 +00002350 else
2351 OS << "(null)";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002352
Ted Kremeneke65b0862012-03-06 20:05:56 +00002353 if (Node->isArraySubscriptRefExpr())
2354 OS << "\" SetterForArray=\"";
2355 else
2356 OS << "\" SetterForDictionary=\"";
2357 if (Node->setAtIndexMethodDecl())
Aaron Ballmanb190f972014-01-03 17:59:55 +00002358 Node->setAtIndexMethodDecl()->getSelector().print(OS);
Ted Kremeneke65b0862012-03-06 20:05:56 +00002359 else
2360 OS << "(null)";
2361}
2362
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002363void ASTDumper::VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002364 VisitExpr(Node);
Ted Kremeneke65b0862012-03-06 20:05:56 +00002365 OS << " " << (Node->getValue() ? "__objc_yes" : "__objc_no");
2366}
2367
Chris Lattnercbe4f772007-08-08 22:51:59 +00002368//===----------------------------------------------------------------------===//
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002369// Comments
2370//===----------------------------------------------------------------------===//
2371
2372const char *ASTDumper::getCommandName(unsigned CommandID) {
2373 if (Traits)
2374 return Traits->getCommandInfo(CommandID)->Name;
2375 const CommandInfo *Info = CommandTraits::getBuiltinCommandInfo(CommandID);
2376 if (Info)
2377 return Info->Name;
2378 return "<not a builtin command>";
2379}
2380
2381void ASTDumper::dumpFullComment(const FullComment *C) {
2382 if (!C)
2383 return;
2384
2385 FC = C;
2386 dumpComment(C);
Craig Topper36250ad2014-05-12 05:36:57 +00002387 FC = nullptr;
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002388}
2389
2390void ASTDumper::dumpComment(const Comment *C) {
Richard Smithf7514452014-10-30 21:02:37 +00002391 dumpChild([=] {
2392 if (!C) {
2393 ColorScope Color(*this, NullColor);
2394 OS << "<<<NULL>>>";
2395 return;
2396 }
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002397
Richard Smithf7514452014-10-30 21:02:37 +00002398 {
2399 ColorScope Color(*this, CommentColor);
2400 OS << C->getCommentKindName();
2401 }
2402 dumpPointer(C);
2403 dumpSourceRange(C->getSourceRange());
2404 ConstCommentVisitor<ASTDumper>::visit(C);
2405 for (Comment::child_iterator I = C->child_begin(), E = C->child_end();
2406 I != E; ++I)
2407 dumpComment(*I);
2408 });
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002409}
2410
2411void ASTDumper::visitTextComment(const TextComment *C) {
2412 OS << " Text=\"" << C->getText() << "\"";
2413}
2414
2415void ASTDumper::visitInlineCommandComment(const InlineCommandComment *C) {
2416 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\"";
2417 switch (C->getRenderKind()) {
2418 case InlineCommandComment::RenderNormal:
2419 OS << " RenderNormal";
2420 break;
2421 case InlineCommandComment::RenderBold:
2422 OS << " RenderBold";
2423 break;
2424 case InlineCommandComment::RenderMonospaced:
2425 OS << " RenderMonospaced";
2426 break;
2427 case InlineCommandComment::RenderEmphasized:
2428 OS << " RenderEmphasized";
2429 break;
2430 }
2431
2432 for (unsigned i = 0, e = C->getNumArgs(); i != e; ++i)
2433 OS << " Arg[" << i << "]=\"" << C->getArgText(i) << "\"";
2434}
2435
2436void ASTDumper::visitHTMLStartTagComment(const HTMLStartTagComment *C) {
2437 OS << " Name=\"" << C->getTagName() << "\"";
2438 if (C->getNumAttrs() != 0) {
2439 OS << " Attrs: ";
2440 for (unsigned i = 0, e = C->getNumAttrs(); i != e; ++i) {
2441 const HTMLStartTagComment::Attribute &Attr = C->getAttr(i);
2442 OS << " \"" << Attr.Name << "=\"" << Attr.Value << "\"";
2443 }
2444 }
2445 if (C->isSelfClosing())
2446 OS << " SelfClosing";
2447}
2448
2449void ASTDumper::visitHTMLEndTagComment(const HTMLEndTagComment *C) {
2450 OS << " Name=\"" << C->getTagName() << "\"";
2451}
2452
2453void ASTDumper::visitBlockCommandComment(const BlockCommandComment *C) {
2454 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\"";
2455 for (unsigned i = 0, e = C->getNumArgs(); i != e; ++i)
2456 OS << " Arg[" << i << "]=\"" << C->getArgText(i) << "\"";
2457}
2458
2459void ASTDumper::visitParamCommandComment(const ParamCommandComment *C) {
2460 OS << " " << ParamCommandComment::getDirectionAsString(C->getDirection());
2461
2462 if (C->isDirectionExplicit())
2463 OS << " explicitly";
2464 else
2465 OS << " implicitly";
2466
2467 if (C->hasParamName()) {
2468 if (C->isParamIndexValid())
2469 OS << " Param=\"" << C->getParamName(FC) << "\"";
2470 else
2471 OS << " Param=\"" << C->getParamNameAsWritten() << "\"";
2472 }
2473
Dmitri Gribenkodbff5c72014-03-19 14:03:47 +00002474 if (C->isParamIndexValid() && !C->isVarArgParam())
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002475 OS << " ParamIndex=" << C->getParamIndex();
2476}
2477
2478void ASTDumper::visitTParamCommandComment(const TParamCommandComment *C) {
2479 if (C->hasParamName()) {
2480 if (C->isPositionValid())
2481 OS << " Param=\"" << C->getParamName(FC) << "\"";
2482 else
2483 OS << " Param=\"" << C->getParamNameAsWritten() << "\"";
2484 }
2485
2486 if (C->isPositionValid()) {
2487 OS << " Position=<";
2488 for (unsigned i = 0, e = C->getDepth(); i != e; ++i) {
2489 OS << C->getIndex(i);
2490 if (i != e - 1)
2491 OS << ", ";
2492 }
2493 OS << ">";
2494 }
2495}
2496
2497void ASTDumper::visitVerbatimBlockComment(const VerbatimBlockComment *C) {
2498 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\""
2499 " CloseName=\"" << C->getCloseName() << "\"";
2500}
2501
2502void ASTDumper::visitVerbatimBlockLineComment(
2503 const VerbatimBlockLineComment *C) {
2504 OS << " Text=\"" << C->getText() << "\"";
2505}
2506
2507void ASTDumper::visitVerbatimLineComment(const VerbatimLineComment *C) {
2508 OS << " Text=\"" << C->getText() << "\"";
2509}
2510
2511//===----------------------------------------------------------------------===//
Richard Smithd5e7ff82014-10-31 01:17:45 +00002512// Type method implementations
2513//===----------------------------------------------------------------------===//
2514
2515void QualType::dump(const char *msg) const {
2516 if (msg)
2517 llvm::errs() << msg << ": ";
2518 dump();
2519}
2520
Richard Smith14d04842016-11-02 23:57:18 +00002521LLVM_DUMP_METHOD void QualType::dump() const { dump(llvm::errs()); }
2522
2523LLVM_DUMP_METHOD void QualType::dump(llvm::raw_ostream &OS) const {
2524 ASTDumper Dumper(OS, nullptr, nullptr);
Richard Smithd5e7ff82014-10-31 01:17:45 +00002525 Dumper.dumpTypeAsChild(*this);
2526}
2527
Richard Smith14d04842016-11-02 23:57:18 +00002528LLVM_DUMP_METHOD void Type::dump() const { dump(llvm::errs()); }
2529
2530LLVM_DUMP_METHOD void Type::dump(llvm::raw_ostream &OS) const {
2531 QualType(this, 0).dump(OS);
2532}
Richard Smithd5e7ff82014-10-31 01:17:45 +00002533
2534//===----------------------------------------------------------------------===//
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002535// Decl method implementations
2536//===----------------------------------------------------------------------===//
2537
Alp Tokeref6b0072014-01-04 13:47:14 +00002538LLVM_DUMP_METHOD void Decl::dump() const { dump(llvm::errs()); }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002539
Richard Smith3a36ac12017-03-09 22:00:01 +00002540LLVM_DUMP_METHOD void Decl::dump(raw_ostream &OS, bool Deserialize) const {
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002541 ASTDumper P(OS, &getASTContext().getCommentCommandTraits(),
2542 &getASTContext().getSourceManager());
Richard Smith3a36ac12017-03-09 22:00:01 +00002543 P.setDeserialize(Deserialize);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002544 P.dumpDecl(this);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002545}
2546
Alp Tokeref6b0072014-01-04 13:47:14 +00002547LLVM_DUMP_METHOD void Decl::dumpColor() const {
Richard Trieud215b8d2013-01-26 01:31:20 +00002548 ASTDumper P(llvm::errs(), &getASTContext().getCommentCommandTraits(),
2549 &getASTContext().getSourceManager(), /*ShowColors*/true);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002550 P.dumpDecl(this);
Richard Trieud215b8d2013-01-26 01:31:20 +00002551}
Richard Smith33937e72013-06-22 21:49:40 +00002552
Alp Tokeref6b0072014-01-04 13:47:14 +00002553LLVM_DUMP_METHOD void DeclContext::dumpLookups() const {
Richard Smith6ea05822013-06-24 01:45:33 +00002554 dumpLookups(llvm::errs());
2555}
2556
Richard Smith35f986d2014-08-11 22:11:07 +00002557LLVM_DUMP_METHOD void DeclContext::dumpLookups(raw_ostream &OS,
Richard Smith3a36ac12017-03-09 22:00:01 +00002558 bool DumpDecls,
2559 bool Deserialize) const {
Richard Smith33937e72013-06-22 21:49:40 +00002560 const DeclContext *DC = this;
2561 while (!DC->isTranslationUnit())
2562 DC = DC->getParent();
2563 ASTContext &Ctx = cast<TranslationUnitDecl>(DC)->getASTContext();
Richard Smith6ea05822013-06-24 01:45:33 +00002564 ASTDumper P(OS, &Ctx.getCommentCommandTraits(), &Ctx.getSourceManager());
Richard Smith3a36ac12017-03-09 22:00:01 +00002565 P.setDeserialize(Deserialize);
Richard Smith35f986d2014-08-11 22:11:07 +00002566 P.dumpLookups(this, DumpDecls);
Richard Smith33937e72013-06-22 21:49:40 +00002567}
2568
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002569//===----------------------------------------------------------------------===//
Chris Lattnercbe4f772007-08-08 22:51:59 +00002570// Stmt method implementations
2571//===----------------------------------------------------------------------===//
2572
Alp Tokeref6b0072014-01-04 13:47:14 +00002573LLVM_DUMP_METHOD void Stmt::dump(SourceManager &SM) const {
Argyrios Kyrtzidisc049f752010-08-09 10:54:31 +00002574 dump(llvm::errs(), SM);
2575}
2576
Alp Tokeref6b0072014-01-04 13:47:14 +00002577LLVM_DUMP_METHOD void Stmt::dump(raw_ostream &OS, SourceManager &SM) const {
Craig Topper36250ad2014-05-12 05:36:57 +00002578 ASTDumper P(OS, nullptr, &SM);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002579 P.dumpStmt(this);
Chris Lattner779d5d92007-08-30 00:40:08 +00002580}
2581
Faisal Vali2da8ed92015-03-22 13:35:56 +00002582LLVM_DUMP_METHOD void Stmt::dump(raw_ostream &OS) const {
2583 ASTDumper P(OS, nullptr, nullptr);
2584 P.dumpStmt(this);
2585}
2586
Alp Tokeref6b0072014-01-04 13:47:14 +00002587LLVM_DUMP_METHOD void Stmt::dump() const {
Craig Topper36250ad2014-05-12 05:36:57 +00002588 ASTDumper P(llvm::errs(), nullptr, nullptr);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002589 P.dumpStmt(this);
Chris Lattnercbe4f772007-08-08 22:51:59 +00002590}
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002591
Alp Tokeref6b0072014-01-04 13:47:14 +00002592LLVM_DUMP_METHOD void Stmt::dumpColor() const {
Craig Topper36250ad2014-05-12 05:36:57 +00002593 ASTDumper P(llvm::errs(), nullptr, nullptr, /*ShowColors*/true);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002594 P.dumpStmt(this);
Richard Trieud215b8d2013-01-26 01:31:20 +00002595}
2596
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002597//===----------------------------------------------------------------------===//
2598// Comment method implementations
2599//===----------------------------------------------------------------------===//
2600
Craig Topper36250ad2014-05-12 05:36:57 +00002601LLVM_DUMP_METHOD void Comment::dump() const {
2602 dump(llvm::errs(), nullptr, nullptr);
2603}
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002604
Alp Tokeref6b0072014-01-04 13:47:14 +00002605LLVM_DUMP_METHOD void Comment::dump(const ASTContext &Context) const {
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002606 dump(llvm::errs(), &Context.getCommentCommandTraits(),
2607 &Context.getSourceManager());
2608}
2609
Alexander Kornienko00911f12013-01-15 12:20:21 +00002610void Comment::dump(raw_ostream &OS, const CommandTraits *Traits,
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002611 const SourceManager *SM) const {
2612 const FullComment *FC = dyn_cast<FullComment>(this);
2613 ASTDumper D(OS, Traits, SM);
2614 D.dumpFullComment(FC);
2615}
Richard Trieud215b8d2013-01-26 01:31:20 +00002616
Alp Tokeref6b0072014-01-04 13:47:14 +00002617LLVM_DUMP_METHOD void Comment::dumpColor() const {
Richard Trieud215b8d2013-01-26 01:31:20 +00002618 const FullComment *FC = dyn_cast<FullComment>(this);
Craig Topper36250ad2014-05-12 05:36:57 +00002619 ASTDumper D(llvm::errs(), nullptr, nullptr, /*ShowColors*/true);
Richard Trieud215b8d2013-01-26 01:31:20 +00002620 D.dumpFullComment(FC);
2621}