blob: 05d8da298cd2c13dd58025ad982bff7edb49e373 [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 Smithf7514452014-10-30 21:02:37 +0000105 /// Indicates whether we're at the top level.
106 bool TopLevel;
Richard Trieude5cc7d2013-01-31 01:44:26 +0000107
Richard Smithf7514452014-10-30 21:02:37 +0000108 /// Indicates if we're handling the first child after entering a new depth.
109 bool FirstChild;
110
111 /// Prefix for currently-being-dumped entity.
112 std::string Prefix;
Richard Trieude5cc7d2013-01-31 01:44:26 +0000113
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000114 /// Keep track of the last location we print out so that we can
115 /// print out deltas from then on out.
Chris Lattner11e30d32007-08-30 06:17:34 +0000116 const char *LastLocFilename;
117 unsigned LastLocLine;
Douglas Gregor7de59662009-05-29 20:38:28 +0000118
Alexander Kornienkoebc17b52013-01-14 14:07:11 +0000119 /// The \c FullComment parent of the comment being dumped.
120 const FullComment *FC;
121
Richard Trieud215b8d2013-01-26 01:31:20 +0000122 bool ShowColors;
123
Richard Smithf7514452014-10-30 21:02:37 +0000124 /// Dump a child of the current node.
125 template<typename Fn> void dumpChild(Fn doDumpChild) {
126 // If we're at the top level, there's nothing interesting to do; just
127 // run the dumper.
128 if (TopLevel) {
129 TopLevel = false;
130 doDumpChild();
131 while (!Pending.empty()) {
132 Pending.back()(true);
133 Pending.pop_back();
134 }
135 Prefix.clear();
136 OS << "\n";
137 TopLevel = true;
138 return;
Manuel Klimek874030e2012-11-07 00:33:12 +0000139 }
Richard Smithf7514452014-10-30 21:02:37 +0000140
141 const FullComment *OrigFC = FC;
142 auto dumpWithIndent = [this, doDumpChild, OrigFC](bool isLastChild) {
143 // Print out the appropriate tree structure and work out the prefix for
144 // children of this node. For instance:
145 //
146 // A Prefix = ""
147 // |-B Prefix = "| "
148 // | `-C Prefix = "| "
149 // `-D Prefix = " "
150 // |-E Prefix = " | "
151 // `-F Prefix = " "
152 // G Prefix = ""
153 //
154 // Note that the first level gets no prefix.
155 {
156 OS << '\n';
157 ColorScope Color(*this, IndentColor);
158 OS << Prefix << (isLastChild ? '`' : '|') << '-';
NAKAMURA Takumic73e4022014-10-31 00:30:37 +0000159 this->Prefix.push_back(isLastChild ? ' ' : '|');
160 this->Prefix.push_back(' ');
Richard Smithf7514452014-10-30 21:02:37 +0000161 }
162
163 FirstChild = true;
164 unsigned Depth = Pending.size();
165
166 FC = OrigFC;
167 doDumpChild();
168
169 // If any children are left, they're the last at their nesting level.
170 // Dump those ones out now.
171 while (Depth < Pending.size()) {
172 Pending.back()(true);
NAKAMURA Takumic73e4022014-10-31 00:30:37 +0000173 this->Pending.pop_back();
Richard Smithf7514452014-10-30 21:02:37 +0000174 }
175
176 // Restore the old prefix.
NAKAMURA Takumic73e4022014-10-31 00:30:37 +0000177 this->Prefix.resize(Prefix.size() - 2);
Richard Smithf7514452014-10-30 21:02:37 +0000178 };
179
180 if (FirstChild) {
181 Pending.push_back(std::move(dumpWithIndent));
182 } else {
183 Pending.back()(false);
184 Pending.back() = std::move(dumpWithIndent);
Manuel Klimek874030e2012-11-07 00:33:12 +0000185 }
Richard Smithf7514452014-10-30 21:02:37 +0000186 FirstChild = false;
187 }
Manuel Klimek874030e2012-11-07 00:33:12 +0000188
Richard Trieud215b8d2013-01-26 01:31:20 +0000189 class ColorScope {
190 ASTDumper &Dumper;
191 public:
192 ColorScope(ASTDumper &Dumper, TerminalColor Color)
193 : Dumper(Dumper) {
194 if (Dumper.ShowColors)
195 Dumper.OS.changeColor(Color.Color, Color.Bold);
196 }
197 ~ColorScope() {
198 if (Dumper.ShowColors)
199 Dumper.OS.resetColor();
200 }
201 };
202
Chris Lattnercbe4f772007-08-08 22:51:59 +0000203 public:
Alexander Kornienkoebc17b52013-01-14 14:07:11 +0000204 ASTDumper(raw_ostream &OS, const CommandTraits *Traits,
205 const SourceManager *SM)
Richard Smithf7514452014-10-30 21:02:37 +0000206 : OS(OS), Traits(Traits), SM(SM), TopLevel(true), FirstChild(true),
Craig Topper36250ad2014-05-12 05:36:57 +0000207 LastLocFilename(""), LastLocLine(~0U), FC(nullptr),
Richard Trieud215b8d2013-01-26 01:31:20 +0000208 ShowColors(SM && SM->getDiagnostics().getShowColors()) { }
209
210 ASTDumper(raw_ostream &OS, const CommandTraits *Traits,
211 const SourceManager *SM, bool ShowColors)
Richard Smithf7514452014-10-30 21:02:37 +0000212 : OS(OS), Traits(Traits), SM(SM), TopLevel(true), FirstChild(true),
Richard Smith56d12152013-01-31 02:04:38 +0000213 LastLocFilename(""), LastLocLine(~0U),
Richard Trieude5cc7d2013-01-31 01:44:26 +0000214 ShowColors(ShowColors) { }
Mike Stump11289f42009-09-09 15:08:12 +0000215
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000216 void dumpDecl(const Decl *D);
217 void dumpStmt(const Stmt *S);
Alexander Kornienkoebc17b52013-01-14 14:07:11 +0000218 void dumpFullComment(const FullComment *C);
Mike Stump11289f42009-09-09 15:08:12 +0000219
Richard Trieude5cc7d2013-01-31 01:44:26 +0000220 // Utilities
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000221 void dumpPointer(const void *Ptr);
222 void dumpSourceRange(SourceRange R);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000223 void dumpLocation(SourceLocation Loc);
Richard Smithd5e7ff82014-10-31 01:17:45 +0000224 void dumpBareType(QualType T, bool Desugar = true);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000225 void dumpType(QualType T);
Richard Smithd5e7ff82014-10-31 01:17:45 +0000226 void dumpTypeAsChild(QualType T);
227 void dumpTypeAsChild(const Type *T);
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000228 void dumpBareDeclRef(const Decl *Node);
Craig Topper36250ad2014-05-12 05:36:57 +0000229 void dumpDeclRef(const Decl *Node, const char *Label = nullptr);
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000230 void dumpName(const NamedDecl *D);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000231 bool hasNodes(const DeclContext *DC);
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000232 void dumpDeclContext(const DeclContext *DC);
Richard Smith35f986d2014-08-11 22:11:07 +0000233 void dumpLookups(const DeclContext *DC, bool DumpDecls);
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000234 void dumpAttr(const Attr *A);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000235
236 // C++ Utilities
237 void dumpAccessSpecifier(AccessSpecifier AS);
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000238 void dumpCXXCtorInitializer(const CXXCtorInitializer *Init);
239 void dumpTemplateParameters(const TemplateParameterList *TPL);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000240 void dumpTemplateArgumentListInfo(const TemplateArgumentListInfo &TALI);
241 void dumpTemplateArgumentLoc(const TemplateArgumentLoc &A);
242 void dumpTemplateArgumentList(const TemplateArgumentList &TAL);
243 void dumpTemplateArgument(const TemplateArgument &A,
244 SourceRange R = SourceRange());
245
Douglas Gregor85f3f952015-07-07 03:57:15 +0000246 // Objective-C utilities.
247 void dumpObjCTypeParamList(const ObjCTypeParamList *typeParams);
248
Richard Smithd5e7ff82014-10-31 01:17:45 +0000249 // Types
250 void VisitComplexType(const ComplexType *T) {
251 dumpTypeAsChild(T->getElementType());
252 }
253 void VisitPointerType(const PointerType *T) {
254 dumpTypeAsChild(T->getPointeeType());
255 }
256 void VisitBlockPointerType(const BlockPointerType *T) {
257 dumpTypeAsChild(T->getPointeeType());
258 }
259 void VisitReferenceType(const ReferenceType *T) {
260 dumpTypeAsChild(T->getPointeeType());
261 }
262 void VisitRValueReferenceType(const ReferenceType *T) {
263 if (T->isSpelledAsLValue())
264 OS << " written as lvalue reference";
265 VisitReferenceType(T);
266 }
267 void VisitMemberPointerType(const MemberPointerType *T) {
268 dumpTypeAsChild(T->getClass());
269 dumpTypeAsChild(T->getPointeeType());
270 }
271 void VisitArrayType(const ArrayType *T) {
272 switch (T->getSizeModifier()) {
273 case ArrayType::Normal: break;
274 case ArrayType::Static: OS << " static"; break;
275 case ArrayType::Star: OS << " *"; break;
276 }
277 OS << " " << T->getIndexTypeQualifiers().getAsString();
278 dumpTypeAsChild(T->getElementType());
279 }
280 void VisitConstantArrayType(const ConstantArrayType *T) {
281 OS << " " << T->getSize();
282 VisitArrayType(T);
283 }
284 void VisitVariableArrayType(const VariableArrayType *T) {
285 OS << " ";
286 dumpSourceRange(T->getBracketsRange());
287 VisitArrayType(T);
288 dumpStmt(T->getSizeExpr());
289 }
290 void VisitDependentSizedArrayType(const DependentSizedArrayType *T) {
291 VisitArrayType(T);
292 OS << " ";
293 dumpSourceRange(T->getBracketsRange());
294 dumpStmt(T->getSizeExpr());
295 }
296 void VisitDependentSizedExtVectorType(
297 const DependentSizedExtVectorType *T) {
298 OS << " ";
299 dumpLocation(T->getAttributeLoc());
300 dumpTypeAsChild(T->getElementType());
301 dumpStmt(T->getSizeExpr());
302 }
303 void VisitVectorType(const VectorType *T) {
304 switch (T->getVectorKind()) {
305 case VectorType::GenericVector: break;
306 case VectorType::AltiVecVector: OS << " altivec"; break;
307 case VectorType::AltiVecPixel: OS << " altivec pixel"; break;
308 case VectorType::AltiVecBool: OS << " altivec bool"; break;
309 case VectorType::NeonVector: OS << " neon"; break;
310 case VectorType::NeonPolyVector: OS << " neon poly"; break;
311 }
312 OS << " " << T->getNumElements();
313 dumpTypeAsChild(T->getElementType());
314 }
315 void VisitFunctionType(const FunctionType *T) {
316 auto EI = T->getExtInfo();
317 if (EI.getNoReturn()) OS << " noreturn";
318 if (EI.getProducesResult()) OS << " produces_result";
319 if (EI.getHasRegParm()) OS << " regparm " << EI.getRegParm();
320 OS << " " << FunctionType::getNameForCallConv(EI.getCC());
321 dumpTypeAsChild(T->getReturnType());
322 }
323 void VisitFunctionProtoType(const FunctionProtoType *T) {
324 auto EPI = T->getExtProtoInfo();
325 if (EPI.HasTrailingReturn) OS << " trailing_return";
326 if (T->isConst()) OS << " const";
327 if (T->isVolatile()) OS << " volatile";
328 if (T->isRestrict()) OS << " restrict";
329 switch (EPI.RefQualifier) {
330 case RQ_None: break;
331 case RQ_LValue: OS << " &"; break;
332 case RQ_RValue: OS << " &&"; break;
333 }
334 // FIXME: Exception specification.
335 // FIXME: Consumed parameters.
336 VisitFunctionType(T);
337 for (QualType PT : T->getParamTypes())
338 dumpTypeAsChild(PT);
339 if (EPI.Variadic)
340 dumpChild([=] { OS << "..."; });
341 }
342 void VisitUnresolvedUsingType(const UnresolvedUsingType *T) {
343 dumpDeclRef(T->getDecl());
344 }
345 void VisitTypedefType(const TypedefType *T) {
346 dumpDeclRef(T->getDecl());
347 }
348 void VisitTypeOfExprType(const TypeOfExprType *T) {
349 dumpStmt(T->getUnderlyingExpr());
350 }
351 void VisitDecltypeType(const DecltypeType *T) {
352 dumpStmt(T->getUnderlyingExpr());
353 }
354 void VisitUnaryTransformType(const UnaryTransformType *T) {
355 switch (T->getUTTKind()) {
356 case UnaryTransformType::EnumUnderlyingType:
357 OS << " underlying_type";
358 break;
359 }
360 dumpTypeAsChild(T->getBaseType());
361 }
362 void VisitTagType(const TagType *T) {
363 dumpDeclRef(T->getDecl());
364 }
365 void VisitAttributedType(const AttributedType *T) {
366 // FIXME: AttrKind
367 dumpTypeAsChild(T->getModifiedType());
368 }
369 void VisitTemplateTypeParmType(const TemplateTypeParmType *T) {
370 OS << " depth " << T->getDepth() << " index " << T->getIndex();
371 if (T->isParameterPack()) OS << " pack";
372 dumpDeclRef(T->getDecl());
373 }
374 void VisitSubstTemplateTypeParmType(const SubstTemplateTypeParmType *T) {
375 dumpTypeAsChild(T->getReplacedParameter());
376 }
377 void VisitSubstTemplateTypeParmPackType(
378 const SubstTemplateTypeParmPackType *T) {
379 dumpTypeAsChild(T->getReplacedParameter());
380 dumpTemplateArgument(T->getArgumentPack());
381 }
382 void VisitAutoType(const AutoType *T) {
383 if (T->isDecltypeAuto()) OS << " decltype(auto)";
384 if (!T->isDeduced())
385 OS << " undeduced";
386 }
387 void VisitTemplateSpecializationType(const TemplateSpecializationType *T) {
388 if (T->isTypeAlias()) OS << " alias";
389 OS << " "; T->getTemplateName().dump(OS);
390 for (auto &Arg : *T)
391 dumpTemplateArgument(Arg);
392 if (T->isTypeAlias())
393 dumpTypeAsChild(T->getAliasedType());
394 }
395 void VisitInjectedClassNameType(const InjectedClassNameType *T) {
396 dumpDeclRef(T->getDecl());
397 }
398 void VisitObjCInterfaceType(const ObjCInterfaceType *T) {
399 dumpDeclRef(T->getDecl());
400 }
401 void VisitObjCObjectPointerType(const ObjCObjectPointerType *T) {
402 dumpTypeAsChild(T->getPointeeType());
403 }
404 void VisitAtomicType(const AtomicType *T) {
405 dumpTypeAsChild(T->getValueType());
406 }
Xiuli Pan2d12e652016-05-03 05:37:07 +0000407 void VisitPipeType(const PipeType *T) {
408 dumpTypeAsChild(T->getElementType());
409 }
Richard Smithd5e7ff82014-10-31 01:17:45 +0000410 void VisitAdjustedType(const AdjustedType *T) {
411 dumpTypeAsChild(T->getOriginalType());
412 }
413 void VisitPackExpansionType(const PackExpansionType *T) {
414 if (auto N = T->getNumExpansions()) OS << " expansions " << *N;
415 if (!T->isSugared())
416 dumpTypeAsChild(T->getPattern());
417 }
418 // FIXME: ElaboratedType, DependentNameType,
419 // DependentTemplateSpecializationType, ObjCObjectType
420
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000421 // Decls
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000422 void VisitLabelDecl(const LabelDecl *D);
423 void VisitTypedefDecl(const TypedefDecl *D);
424 void VisitEnumDecl(const EnumDecl *D);
425 void VisitRecordDecl(const RecordDecl *D);
426 void VisitEnumConstantDecl(const EnumConstantDecl *D);
427 void VisitIndirectFieldDecl(const IndirectFieldDecl *D);
428 void VisitFunctionDecl(const FunctionDecl *D);
429 void VisitFieldDecl(const FieldDecl *D);
430 void VisitVarDecl(const VarDecl *D);
431 void VisitFileScopeAsmDecl(const FileScopeAsmDecl *D);
432 void VisitImportDecl(const ImportDecl *D);
Nico Weber66220292016-03-02 17:28:48 +0000433 void VisitPragmaCommentDecl(const PragmaCommentDecl *D);
Nico Webercbbaeb12016-03-02 19:28:54 +0000434 void VisitPragmaDetectMismatchDecl(const PragmaDetectMismatchDecl *D);
Alexey Bataev958b9e72016-03-31 09:30:50 +0000435 void VisitCapturedDecl(const CapturedDecl *D);
436
437 // OpenMP decls
438 void VisitOMPThreadPrivateDecl(const OMPThreadPrivateDecl *D);
439 void VisitOMPDeclareReductionDecl(const OMPDeclareReductionDecl *D);
440 void VisitOMPCapturedExprDecl(const OMPCapturedExprDecl *D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000441
442 // C++ Decls
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000443 void VisitNamespaceDecl(const NamespaceDecl *D);
444 void VisitUsingDirectiveDecl(const UsingDirectiveDecl *D);
445 void VisitNamespaceAliasDecl(const NamespaceAliasDecl *D);
446 void VisitTypeAliasDecl(const TypeAliasDecl *D);
447 void VisitTypeAliasTemplateDecl(const TypeAliasTemplateDecl *D);
448 void VisitCXXRecordDecl(const CXXRecordDecl *D);
449 void VisitStaticAssertDecl(const StaticAssertDecl *D);
Richard Smithcbdf7332014-03-18 02:07:28 +0000450 template<typename SpecializationDecl>
Richard Smithf7514452014-10-30 21:02:37 +0000451 void VisitTemplateDeclSpecialization(const SpecializationDecl *D,
Richard Smithcbdf7332014-03-18 02:07:28 +0000452 bool DumpExplicitInst,
453 bool DumpRefOnly);
Richard Smith20ade552014-03-17 23:34:53 +0000454 template<typename TemplateDecl>
455 void VisitTemplateDecl(const TemplateDecl *D, bool DumpExplicitInst);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000456 void VisitFunctionTemplateDecl(const FunctionTemplateDecl *D);
457 void VisitClassTemplateDecl(const ClassTemplateDecl *D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000458 void VisitClassTemplateSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000459 const ClassTemplateSpecializationDecl *D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000460 void VisitClassTemplatePartialSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000461 const ClassTemplatePartialSpecializationDecl *D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000462 void VisitClassScopeFunctionSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000463 const ClassScopeFunctionSpecializationDecl *D);
David Majnemerd9b1a4f2015-11-04 03:40:30 +0000464 void VisitBuiltinTemplateDecl(const BuiltinTemplateDecl *D);
Richard Smithd25789a2013-09-18 01:36:02 +0000465 void VisitVarTemplateDecl(const VarTemplateDecl *D);
466 void VisitVarTemplateSpecializationDecl(
467 const VarTemplateSpecializationDecl *D);
468 void VisitVarTemplatePartialSpecializationDecl(
469 const VarTemplatePartialSpecializationDecl *D);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000470 void VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D);
471 void VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D);
472 void VisitTemplateTemplateParmDecl(const TemplateTemplateParmDecl *D);
473 void VisitUsingDecl(const UsingDecl *D);
474 void VisitUnresolvedUsingTypenameDecl(const UnresolvedUsingTypenameDecl *D);
475 void VisitUnresolvedUsingValueDecl(const UnresolvedUsingValueDecl *D);
476 void VisitUsingShadowDecl(const UsingShadowDecl *D);
477 void VisitLinkageSpecDecl(const LinkageSpecDecl *D);
478 void VisitAccessSpecDecl(const AccessSpecDecl *D);
479 void VisitFriendDecl(const FriendDecl *D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000480
481 // ObjC Decls
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000482 void VisitObjCIvarDecl(const ObjCIvarDecl *D);
483 void VisitObjCMethodDecl(const ObjCMethodDecl *D);
Douglas Gregor85f3f952015-07-07 03:57:15 +0000484 void VisitObjCTypeParamDecl(const ObjCTypeParamDecl *D);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000485 void VisitObjCCategoryDecl(const ObjCCategoryDecl *D);
486 void VisitObjCCategoryImplDecl(const ObjCCategoryImplDecl *D);
487 void VisitObjCProtocolDecl(const ObjCProtocolDecl *D);
488 void VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D);
489 void VisitObjCImplementationDecl(const ObjCImplementationDecl *D);
490 void VisitObjCCompatibleAliasDecl(const ObjCCompatibleAliasDecl *D);
491 void VisitObjCPropertyDecl(const ObjCPropertyDecl *D);
492 void VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D);
493 void VisitBlockDecl(const BlockDecl *D);
Mike Stump11289f42009-09-09 15:08:12 +0000494
Chris Lattner84ca3762007-08-30 01:00:35 +0000495 // Stmts.
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000496 void VisitStmt(const Stmt *Node);
497 void VisitDeclStmt(const DeclStmt *Node);
498 void VisitAttributedStmt(const AttributedStmt *Node);
499 void VisitLabelStmt(const LabelStmt *Node);
500 void VisitGotoStmt(const GotoStmt *Node);
Pavel Labath1ef83422013-09-04 14:35:00 +0000501 void VisitCXXCatchStmt(const CXXCatchStmt *Node);
Alexey Bataev958b9e72016-03-31 09:30:50 +0000502 void VisitCapturedStmt(const CapturedStmt *Node);
503
504 // OpenMP
505 void VisitOMPExecutableDirective(const OMPExecutableDirective *Node);
Mike Stump11289f42009-09-09 15:08:12 +0000506
Chris Lattner84ca3762007-08-30 01:00:35 +0000507 // Exprs
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000508 void VisitExpr(const Expr *Node);
509 void VisitCastExpr(const CastExpr *Node);
510 void VisitDeclRefExpr(const DeclRefExpr *Node);
511 void VisitPredefinedExpr(const PredefinedExpr *Node);
512 void VisitCharacterLiteral(const CharacterLiteral *Node);
513 void VisitIntegerLiteral(const IntegerLiteral *Node);
514 void VisitFloatingLiteral(const FloatingLiteral *Node);
515 void VisitStringLiteral(const StringLiteral *Str);
Richard Smithf0514962014-06-03 08:24:28 +0000516 void VisitInitListExpr(const InitListExpr *ILE);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000517 void VisitUnaryOperator(const UnaryOperator *Node);
518 void VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *Node);
519 void VisitMemberExpr(const MemberExpr *Node);
520 void VisitExtVectorElementExpr(const ExtVectorElementExpr *Node);
521 void VisitBinaryOperator(const BinaryOperator *Node);
522 void VisitCompoundAssignOperator(const CompoundAssignOperator *Node);
523 void VisitAddrLabelExpr(const AddrLabelExpr *Node);
524 void VisitBlockExpr(const BlockExpr *Node);
525 void VisitOpaqueValueExpr(const OpaqueValueExpr *Node);
Chris Lattner84ca3762007-08-30 01:00:35 +0000526
527 // C++
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000528 void VisitCXXNamedCastExpr(const CXXNamedCastExpr *Node);
529 void VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *Node);
530 void VisitCXXThisExpr(const CXXThisExpr *Node);
531 void VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *Node);
532 void VisitCXXConstructExpr(const CXXConstructExpr *Node);
533 void VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *Node);
Reid Kleckner5c682bc2015-03-19 18:09:25 +0000534 void VisitCXXNewExpr(const CXXNewExpr *Node);
535 void VisitCXXDeleteExpr(const CXXDeleteExpr *Node);
Richard Smithe6c01442013-06-05 00:46:14 +0000536 void VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000537 void VisitExprWithCleanups(const ExprWithCleanups *Node);
538 void VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *Node);
539 void dumpCXXTemporary(const CXXTemporary *Temporary);
Faisal Vali2b391ab2013-09-26 19:54:12 +0000540 void VisitLambdaExpr(const LambdaExpr *Node) {
541 VisitExpr(Node);
542 dumpDecl(Node->getLambdaClass());
543 }
Serge Pavlov6b926032015-02-16 19:58:41 +0000544 void VisitSizeOfPackExpr(const SizeOfPackExpr *Node);
Mike Stump11289f42009-09-09 15:08:12 +0000545
Chris Lattner84ca3762007-08-30 01:00:35 +0000546 // ObjC
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000547 void VisitObjCAtCatchStmt(const ObjCAtCatchStmt *Node);
548 void VisitObjCEncodeExpr(const ObjCEncodeExpr *Node);
549 void VisitObjCMessageExpr(const ObjCMessageExpr *Node);
550 void VisitObjCBoxedExpr(const ObjCBoxedExpr *Node);
551 void VisitObjCSelectorExpr(const ObjCSelectorExpr *Node);
552 void VisitObjCProtocolExpr(const ObjCProtocolExpr *Node);
553 void VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *Node);
554 void VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *Node);
555 void VisitObjCIvarRefExpr(const ObjCIvarRefExpr *Node);
556 void VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *Node);
Alexander Kornienkoebc17b52013-01-14 14:07:11 +0000557
558 // Comments.
559 const char *getCommandName(unsigned CommandID);
560 void dumpComment(const Comment *C);
561
562 // Inline comments.
563 void visitTextComment(const TextComment *C);
564 void visitInlineCommandComment(const InlineCommandComment *C);
565 void visitHTMLStartTagComment(const HTMLStartTagComment *C);
566 void visitHTMLEndTagComment(const HTMLEndTagComment *C);
567
568 // Block comments.
569 void visitBlockCommandComment(const BlockCommandComment *C);
570 void visitParamCommandComment(const ParamCommandComment *C);
571 void visitTParamCommandComment(const TParamCommandComment *C);
572 void visitVerbatimBlockComment(const VerbatimBlockComment *C);
573 void visitVerbatimBlockLineComment(const VerbatimBlockLineComment *C);
574 void visitVerbatimLineComment(const VerbatimLineComment *C);
Chris Lattnercbe4f772007-08-08 22:51:59 +0000575 };
Alexander Kornienkoab9db512015-06-22 23:07:51 +0000576}
Chris Lattnercbe4f772007-08-08 22:51:59 +0000577
578//===----------------------------------------------------------------------===//
Chris Lattner11e30d32007-08-30 06:17:34 +0000579// Utilities
580//===----------------------------------------------------------------------===//
581
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000582void ASTDumper::dumpPointer(const void *Ptr) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000583 ColorScope Color(*this, AddressColor);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000584 OS << ' ' << Ptr;
585}
586
Alexander Kornienko18ec81b2012-12-13 13:59:55 +0000587void ASTDumper::dumpLocation(SourceLocation Loc) {
Alex McCarthye14ddef2014-05-02 20:24:11 +0000588 if (!SM)
589 return;
590
Richard Trieud215b8d2013-01-26 01:31:20 +0000591 ColorScope Color(*this, LocationColor);
Chris Lattner53e384f2009-01-16 07:00:02 +0000592 SourceLocation SpellingLoc = SM->getSpellingLoc(Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000593
Chris Lattner11e30d32007-08-30 06:17:34 +0000594 // The general format we print out is filename:line:col, but we drop pieces
595 // that haven't changed since the last loc printed.
Chris Lattnerf1ca7d32009-01-27 07:57:44 +0000596 PresumedLoc PLoc = SM->getPresumedLoc(SpellingLoc);
597
Douglas Gregor453b0122010-11-12 07:15:47 +0000598 if (PLoc.isInvalid()) {
599 OS << "<invalid sloc>";
600 return;
601 }
602
Chris Lattnerf1ca7d32009-01-27 07:57:44 +0000603 if (strcmp(PLoc.getFilename(), LastLocFilename) != 0) {
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000604 OS << PLoc.getFilename() << ':' << PLoc.getLine()
605 << ':' << PLoc.getColumn();
Chris Lattnerf1ca7d32009-01-27 07:57:44 +0000606 LastLocFilename = PLoc.getFilename();
607 LastLocLine = PLoc.getLine();
608 } else if (PLoc.getLine() != LastLocLine) {
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000609 OS << "line" << ':' << PLoc.getLine()
610 << ':' << PLoc.getColumn();
Chris Lattnerf1ca7d32009-01-27 07:57:44 +0000611 LastLocLine = PLoc.getLine();
Chris Lattner11e30d32007-08-30 06:17:34 +0000612 } else {
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000613 OS << "col" << ':' << PLoc.getColumn();
Chris Lattner11e30d32007-08-30 06:17:34 +0000614 }
615}
616
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000617void ASTDumper::dumpSourceRange(SourceRange R) {
Chris Lattner11e30d32007-08-30 06:17:34 +0000618 // Can't translate locations if a SourceManager isn't available.
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000619 if (!SM)
620 return;
Mike Stump11289f42009-09-09 15:08:12 +0000621
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000622 OS << " <";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000623 dumpLocation(R.getBegin());
Chris Lattnera7c19fe2007-10-16 22:36:42 +0000624 if (R.getBegin() != R.getEnd()) {
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000625 OS << ", ";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000626 dumpLocation(R.getEnd());
Chris Lattner11e30d32007-08-30 06:17:34 +0000627 }
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000628 OS << ">";
Mike Stump11289f42009-09-09 15:08:12 +0000629
Chris Lattner11e30d32007-08-30 06:17:34 +0000630 // <t2.c:123:421[blah], t2.c:412:321>
631
632}
633
Richard Smithd5e7ff82014-10-31 01:17:45 +0000634void ASTDumper::dumpBareType(QualType T, bool Desugar) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000635 ColorScope Color(*this, TypeColor);
Richard Smithd5e7ff82014-10-31 01:17:45 +0000636
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000637 SplitQualType T_split = T.split();
638 OS << "'" << QualType::getAsString(T_split) << "'";
639
Richard Smithd5e7ff82014-10-31 01:17:45 +0000640 if (Desugar && !T.isNull()) {
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000641 // If the type is sugared, also dump a (shallow) desugared type.
642 SplitQualType D_split = T.getSplitDesugaredType();
643 if (T_split != D_split)
644 OS << ":'" << QualType::getAsString(D_split) << "'";
645 }
646}
647
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000648void ASTDumper::dumpType(QualType T) {
649 OS << ' ';
650 dumpBareType(T);
651}
652
Richard Smithd5e7ff82014-10-31 01:17:45 +0000653void ASTDumper::dumpTypeAsChild(QualType T) {
654 SplitQualType SQT = T.split();
655 if (!SQT.Quals.hasQualifiers())
656 return dumpTypeAsChild(SQT.Ty);
657
658 dumpChild([=] {
659 OS << "QualType";
660 dumpPointer(T.getAsOpaquePtr());
661 OS << " ";
662 dumpBareType(T, false);
663 OS << " " << T.split().Quals.getAsString();
664 dumpTypeAsChild(T.split().Ty);
665 });
666}
667
668void ASTDumper::dumpTypeAsChild(const Type *T) {
669 dumpChild([=] {
670 if (!T) {
671 ColorScope Color(*this, NullColor);
672 OS << "<<<NULL>>>";
673 return;
674 }
Serge Pavlova6adc9e2015-12-28 17:19:12 +0000675 if (const LocInfoType *LIT = llvm::dyn_cast<LocInfoType>(T)) {
676 {
677 ColorScope Color(*this, TypeColor);
678 OS << "LocInfo Type";
679 }
680 dumpPointer(T);
681 dumpTypeAsChild(LIT->getTypeSourceInfo()->getType());
682 return;
683 }
Richard Smithd5e7ff82014-10-31 01:17:45 +0000684
685 {
686 ColorScope Color(*this, TypeColor);
687 OS << T->getTypeClassName() << "Type";
688 }
689 dumpPointer(T);
690 OS << " ";
691 dumpBareType(QualType(T, 0), false);
692
693 QualType SingleStepDesugar =
694 T->getLocallyUnqualifiedSingleStepDesugaredType();
695 if (SingleStepDesugar != QualType(T, 0))
696 OS << " sugar";
697 if (T->isDependentType())
698 OS << " dependent";
699 else if (T->isInstantiationDependentType())
700 OS << " instantiation_dependent";
701 if (T->isVariablyModifiedType())
702 OS << " variably_modified";
703 if (T->containsUnexpandedParameterPack())
704 OS << " contains_unexpanded_pack";
705 if (T->isFromAST())
706 OS << " imported";
707
708 TypeVisitor<ASTDumper>::Visit(T);
709
710 if (SingleStepDesugar != QualType(T, 0))
711 dumpTypeAsChild(SingleStepDesugar);
712 });
713}
714
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000715void ASTDumper::dumpBareDeclRef(const Decl *D) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000716 {
717 ColorScope Color(*this, DeclKindNameColor);
718 OS << D->getDeclKindName();
719 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000720 dumpPointer(D);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000721
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000722 if (const NamedDecl *ND = dyn_cast<NamedDecl>(D)) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000723 ColorScope Color(*this, DeclNameColor);
David Blaikied4da8722013-05-14 21:04:00 +0000724 OS << " '" << ND->getDeclName() << '\'';
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000725 }
726
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000727 if (const ValueDecl *VD = dyn_cast<ValueDecl>(D))
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000728 dumpType(VD->getType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000729}
730
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000731void ASTDumper::dumpDeclRef(const Decl *D, const char *Label) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000732 if (!D)
733 return;
734
Richard Smithf7514452014-10-30 21:02:37 +0000735 dumpChild([=]{
736 if (Label)
737 OS << Label << ' ';
738 dumpBareDeclRef(D);
739 });
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000740}
741
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000742void ASTDumper::dumpName(const NamedDecl *ND) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000743 if (ND->getDeclName()) {
744 ColorScope Color(*this, DeclNameColor);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000745 OS << ' ' << ND->getNameAsString();
Richard Trieud215b8d2013-01-26 01:31:20 +0000746 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000747}
748
Richard Trieude5cc7d2013-01-31 01:44:26 +0000749bool ASTDumper::hasNodes(const DeclContext *DC) {
750 if (!DC)
751 return false;
752
Richard Smith1d209d02013-05-23 01:49:11 +0000753 return DC->hasExternalLexicalStorage() ||
754 DC->noload_decls_begin() != DC->noload_decls_end();
Richard Trieude5cc7d2013-01-31 01:44:26 +0000755}
756
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000757void ASTDumper::dumpDeclContext(const DeclContext *DC) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000758 if (!DC)
759 return;
Richard Smithdcc2c452014-03-17 23:00:06 +0000760
Richard Smithdcc2c452014-03-17 23:00:06 +0000761 for (auto *D : DC->noload_decls())
Richard Smithf7514452014-10-30 21:02:37 +0000762 dumpDecl(D);
Richard Smithdcc2c452014-03-17 23:00:06 +0000763
764 if (DC->hasExternalLexicalStorage()) {
Richard Smithf7514452014-10-30 21:02:37 +0000765 dumpChild([=]{
766 ColorScope Color(*this, UndeserializedColor);
767 OS << "<undeserialized declarations>";
768 });
Richard Smith1d209d02013-05-23 01:49:11 +0000769 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000770}
771
Richard Smith35f986d2014-08-11 22:11:07 +0000772void ASTDumper::dumpLookups(const DeclContext *DC, bool DumpDecls) {
Richard Smithf7514452014-10-30 21:02:37 +0000773 dumpChild([=] {
774 OS << "StoredDeclsMap ";
775 dumpBareDeclRef(cast<Decl>(DC));
Richard Smith33937e72013-06-22 21:49:40 +0000776
Richard Smithf7514452014-10-30 21:02:37 +0000777 const DeclContext *Primary = DC->getPrimaryContext();
778 if (Primary != DC) {
779 OS << " primary";
780 dumpPointer(cast<Decl>(Primary));
Richard Smith33937e72013-06-22 21:49:40 +0000781 }
782
Richard Smithf7514452014-10-30 21:02:37 +0000783 bool HasUndeserializedLookups = Primary->hasExternalVisibleStorage();
Richard Smith35f986d2014-08-11 22:11:07 +0000784
Richard Smithf7514452014-10-30 21:02:37 +0000785 DeclContext::all_lookups_iterator I = Primary->noload_lookups_begin(),
786 E = Primary->noload_lookups_end();
787 while (I != E) {
788 DeclarationName Name = I.getLookupName();
789 DeclContextLookupResult R = *I++;
Richard Smith35f986d2014-08-11 22:11:07 +0000790
Richard Smithf7514452014-10-30 21:02:37 +0000791 dumpChild([=] {
792 OS << "DeclarationName ";
793 {
794 ColorScope Color(*this, DeclNameColor);
795 OS << '\'' << Name << '\'';
796 }
Richard Smith35f986d2014-08-11 22:11:07 +0000797
Richard Smithf7514452014-10-30 21:02:37 +0000798 for (DeclContextLookupResult::iterator RI = R.begin(), RE = R.end();
799 RI != RE; ++RI) {
800 dumpChild([=] {
801 dumpBareDeclRef(*RI);
802
803 if ((*RI)->isHidden())
804 OS << " hidden";
805
806 // If requested, dump the redecl chain for this lookup.
807 if (DumpDecls) {
808 // Dump earliest decl first.
809 std::function<void(Decl *)> DumpWithPrev = [&](Decl *D) {
810 if (Decl *Prev = D->getPreviousDecl())
811 DumpWithPrev(Prev);
812 dumpDecl(D);
813 };
814 DumpWithPrev(*RI);
815 }
816 });
817 }
818 });
Richard Smith33937e72013-06-22 21:49:40 +0000819 }
Richard Smith33937e72013-06-22 21:49:40 +0000820
Richard Smithf7514452014-10-30 21:02:37 +0000821 if (HasUndeserializedLookups) {
822 dumpChild([=] {
823 ColorScope Color(*this, UndeserializedColor);
824 OS << "<undeserialized lookups>";
825 });
826 }
827 });
Richard Smith33937e72013-06-22 21:49:40 +0000828}
829
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000830void ASTDumper::dumpAttr(const Attr *A) {
Richard Smithf7514452014-10-30 21:02:37 +0000831 dumpChild([=] {
832 {
833 ColorScope Color(*this, AttrColor);
Aaron Ballman36a53502014-01-16 13:03:14 +0000834
Richard Smithf7514452014-10-30 21:02:37 +0000835 switch (A->getKind()) {
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000836#define ATTR(X) case attr::X: OS << #X; break;
837#include "clang/Basic/AttrList.inc"
Richard Smithf7514452014-10-30 21:02:37 +0000838 }
839 OS << "Attr";
Richard Trieud215b8d2013-01-26 01:31:20 +0000840 }
Richard Smithf7514452014-10-30 21:02:37 +0000841 dumpPointer(A);
842 dumpSourceRange(A->getRange());
843 if (A->isInherited())
844 OS << " Inherited";
845 if (A->isImplicit())
846 OS << " Implicit";
Hans Wennborgb0a8b4a2014-05-31 04:05:57 +0000847#include "clang/AST/AttrDump.inc"
Richard Smithf7514452014-10-30 21:02:37 +0000848 });
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000849}
850
Richard Smith71bec062013-10-15 21:58:30 +0000851static void dumpPreviousDeclImpl(raw_ostream &OS, ...) {}
852
853template<typename T>
854static void dumpPreviousDeclImpl(raw_ostream &OS, const Mergeable<T> *D) {
Rafael Espindola8db352d2013-10-17 15:37:26 +0000855 const T *First = D->getFirstDecl();
Richard Smith71bec062013-10-15 21:58:30 +0000856 if (First != D)
857 OS << " first " << First;
Richard Smithf5f43542013-02-07 01:35:44 +0000858}
859
860template<typename T>
Richard Smith71bec062013-10-15 21:58:30 +0000861static void dumpPreviousDeclImpl(raw_ostream &OS, const Redeclarable<T> *D) {
862 const T *Prev = D->getPreviousDecl();
863 if (Prev)
864 OS << " prev " << Prev;
Richard Smithf5f43542013-02-07 01:35:44 +0000865}
866
Richard Smith71bec062013-10-15 21:58:30 +0000867/// Dump the previous declaration in the redeclaration chain for a declaration,
868/// if any.
869static void dumpPreviousDecl(raw_ostream &OS, const Decl *D) {
Richard Smithf5f43542013-02-07 01:35:44 +0000870 switch (D->getKind()) {
871#define DECL(DERIVED, BASE) \
872 case Decl::DERIVED: \
Richard Smith71bec062013-10-15 21:58:30 +0000873 return dumpPreviousDeclImpl(OS, cast<DERIVED##Decl>(D));
Richard Smithf5f43542013-02-07 01:35:44 +0000874#define ABSTRACT_DECL(DECL)
875#include "clang/AST/DeclNodes.inc"
876 }
877 llvm_unreachable("Decl that isn't part of DeclNodes.inc!");
878}
879
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000880//===----------------------------------------------------------------------===//
881// C++ Utilities
882//===----------------------------------------------------------------------===//
883
884void ASTDumper::dumpAccessSpecifier(AccessSpecifier AS) {
885 switch (AS) {
886 case AS_none:
887 break;
888 case AS_public:
889 OS << "public";
890 break;
891 case AS_protected:
892 OS << "protected";
893 break;
894 case AS_private:
895 OS << "private";
896 break;
897 }
898}
899
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000900void ASTDumper::dumpCXXCtorInitializer(const CXXCtorInitializer *Init) {
Richard Smithf7514452014-10-30 21:02:37 +0000901 dumpChild([=] {
902 OS << "CXXCtorInitializer";
903 if (Init->isAnyMemberInitializer()) {
904 OS << ' ';
905 dumpBareDeclRef(Init->getAnyMember());
906 } else if (Init->isBaseInitializer()) {
907 dumpType(QualType(Init->getBaseClass(), 0));
908 } else if (Init->isDelegatingInitializer()) {
909 dumpType(Init->getTypeSourceInfo()->getType());
910 } else {
911 llvm_unreachable("Unknown initializer type");
912 }
913 dumpStmt(Init->getInit());
914 });
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000915}
916
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000917void ASTDumper::dumpTemplateParameters(const TemplateParameterList *TPL) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000918 if (!TPL)
919 return;
920
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000921 for (TemplateParameterList::const_iterator I = TPL->begin(), E = TPL->end();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000922 I != E; ++I)
923 dumpDecl(*I);
924}
925
926void ASTDumper::dumpTemplateArgumentListInfo(
927 const TemplateArgumentListInfo &TALI) {
Richard Smithf7514452014-10-30 21:02:37 +0000928 for (unsigned i = 0, e = TALI.size(); i < e; ++i)
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000929 dumpTemplateArgumentLoc(TALI[i]);
930}
931
932void ASTDumper::dumpTemplateArgumentLoc(const TemplateArgumentLoc &A) {
933 dumpTemplateArgument(A.getArgument(), A.getSourceRange());
934}
935
936void ASTDumper::dumpTemplateArgumentList(const TemplateArgumentList &TAL) {
937 for (unsigned i = 0, e = TAL.size(); i < e; ++i)
938 dumpTemplateArgument(TAL[i]);
939}
940
941void ASTDumper::dumpTemplateArgument(const TemplateArgument &A, SourceRange R) {
Richard Smithf7514452014-10-30 21:02:37 +0000942 dumpChild([=] {
943 OS << "TemplateArgument";
944 if (R.isValid())
945 dumpSourceRange(R);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000946
Richard Smithf7514452014-10-30 21:02:37 +0000947 switch (A.getKind()) {
948 case TemplateArgument::Null:
949 OS << " null";
950 break;
951 case TemplateArgument::Type:
952 OS << " type";
953 dumpType(A.getAsType());
954 break;
955 case TemplateArgument::Declaration:
956 OS << " decl";
957 dumpDeclRef(A.getAsDecl());
958 break;
959 case TemplateArgument::NullPtr:
960 OS << " nullptr";
961 break;
962 case TemplateArgument::Integral:
963 OS << " integral " << A.getAsIntegral();
964 break;
965 case TemplateArgument::Template:
966 OS << " template ";
967 A.getAsTemplate().dump(OS);
968 break;
969 case TemplateArgument::TemplateExpansion:
970 OS << " template expansion";
971 A.getAsTemplateOrTemplatePattern().dump(OS);
972 break;
973 case TemplateArgument::Expression:
974 OS << " expr";
975 dumpStmt(A.getAsExpr());
976 break;
977 case TemplateArgument::Pack:
978 OS << " pack";
979 for (TemplateArgument::pack_iterator I = A.pack_begin(), E = A.pack_end();
980 I != E; ++I)
981 dumpTemplateArgument(*I);
982 break;
Richard Trieude5cc7d2013-01-31 01:44:26 +0000983 }
Richard Smithf7514452014-10-30 21:02:37 +0000984 });
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000985}
986
Chris Lattner11e30d32007-08-30 06:17:34 +0000987//===----------------------------------------------------------------------===//
Douglas Gregor85f3f952015-07-07 03:57:15 +0000988// Objective-C Utilities
989//===----------------------------------------------------------------------===//
990void ASTDumper::dumpObjCTypeParamList(const ObjCTypeParamList *typeParams) {
991 if (!typeParams)
992 return;
993
994 for (auto typeParam : *typeParams) {
995 dumpDecl(typeParam);
996 }
997}
998
999//===----------------------------------------------------------------------===//
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001000// Decl dumping methods.
Chris Lattnercbe4f772007-08-08 22:51:59 +00001001//===----------------------------------------------------------------------===//
1002
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001003void ASTDumper::dumpDecl(const Decl *D) {
Richard Smithf7514452014-10-30 21:02:37 +00001004 dumpChild([=] {
1005 if (!D) {
1006 ColorScope Color(*this, NullColor);
1007 OS << "<<<NULL>>>";
1008 return;
1009 }
Mike Stump11289f42009-09-09 15:08:12 +00001010
Richard Smithf7514452014-10-30 21:02:37 +00001011 {
1012 ColorScope Color(*this, DeclKindNameColor);
1013 OS << D->getDeclKindName() << "Decl";
1014 }
1015 dumpPointer(D);
1016 if (D->getLexicalDeclContext() != D->getDeclContext())
1017 OS << " parent " << cast<Decl>(D->getDeclContext());
1018 dumpPreviousDecl(OS, D);
1019 dumpSourceRange(D->getSourceRange());
1020 OS << ' ';
1021 dumpLocation(D->getLocation());
Richard Smith42413142015-05-15 20:05:43 +00001022 if (Module *M = D->getImportedOwningModule())
Richard Smithf7514452014-10-30 21:02:37 +00001023 OS << " in " << M->getFullModuleName();
Richard Smith42413142015-05-15 20:05:43 +00001024 else if (Module *M = D->getLocalOwningModule())
1025 OS << " in (local) " << M->getFullModuleName();
Richard Smitha2eb4092015-06-22 18:47:01 +00001026 if (auto *ND = dyn_cast<NamedDecl>(D))
1027 for (Module *M : D->getASTContext().getModulesWithMergedDefinition(
1028 const_cast<NamedDecl *>(ND)))
1029 dumpChild([=] { OS << "also in " << M->getFullModuleName(); });
Richard Smithf7514452014-10-30 21:02:37 +00001030 if (const NamedDecl *ND = dyn_cast<NamedDecl>(D))
1031 if (ND->isHidden())
1032 OS << " hidden";
1033 if (D->isImplicit())
1034 OS << " implicit";
1035 if (D->isUsed())
1036 OS << " used";
1037 else if (D->isThisDeclarationReferenced())
1038 OS << " referenced";
1039 if (D->isInvalidDecl())
1040 OS << " invalid";
Hans Wennborg76b00532014-12-05 22:38:57 +00001041 if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
1042 if (FD->isConstexpr())
1043 OS << " constexpr";
1044
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001045
Richard Smithf7514452014-10-30 21:02:37 +00001046 ConstDeclVisitor<ASTDumper>::Visit(D);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001047
Richard Smithf7514452014-10-30 21:02:37 +00001048 for (Decl::attr_iterator I = D->attr_begin(), E = D->attr_end(); I != E;
1049 ++I)
1050 dumpAttr(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001051
Richard Smithf7514452014-10-30 21:02:37 +00001052 if (const FullComment *Comment =
1053 D->getASTContext().getLocalCommentForDeclUncached(D))
1054 dumpFullComment(Comment);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001055
Richard Smithf7514452014-10-30 21:02:37 +00001056 // Decls within functions are visited by the body.
1057 if (!isa<FunctionDecl>(*D) && !isa<ObjCMethodDecl>(*D) &&
1058 hasNodes(dyn_cast<DeclContext>(D)))
1059 dumpDeclContext(cast<DeclContext>(D));
1060 });
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001061}
1062
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001063void ASTDumper::VisitLabelDecl(const LabelDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001064 dumpName(D);
1065}
1066
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001067void ASTDumper::VisitTypedefDecl(const TypedefDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001068 dumpName(D);
1069 dumpType(D->getUnderlyingType());
1070 if (D->isModulePrivate())
1071 OS << " __module_private__";
Richard Smithba3a4f92016-01-12 21:59:26 +00001072 dumpTypeAsChild(D->getUnderlyingType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001073}
1074
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001075void ASTDumper::VisitEnumDecl(const EnumDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001076 if (D->isScoped()) {
1077 if (D->isScopedUsingClassTag())
1078 OS << " class";
1079 else
1080 OS << " struct";
1081 }
1082 dumpName(D);
1083 if (D->isModulePrivate())
1084 OS << " __module_private__";
1085 if (D->isFixed())
1086 dumpType(D->getIntegerType());
1087}
1088
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001089void ASTDumper::VisitRecordDecl(const RecordDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001090 OS << ' ' << D->getKindName();
1091 dumpName(D);
1092 if (D->isModulePrivate())
1093 OS << " __module_private__";
Richard Smith99bc1b92013-08-30 05:32:29 +00001094 if (D->isCompleteDefinition())
1095 OS << " definition";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001096}
1097
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001098void ASTDumper::VisitEnumConstantDecl(const EnumConstantDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001099 dumpName(D);
1100 dumpType(D->getType());
Richard Smithf7514452014-10-30 21:02:37 +00001101 if (const Expr *Init = D->getInitExpr())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001102 dumpStmt(Init);
1103}
1104
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001105void ASTDumper::VisitIndirectFieldDecl(const IndirectFieldDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001106 dumpName(D);
1107 dumpType(D->getType());
Richard Smithdcc2c452014-03-17 23:00:06 +00001108
Richard Smith8aa49222014-03-18 00:35:12 +00001109 for (auto *Child : D->chain())
Richard Smithf7514452014-10-30 21:02:37 +00001110 dumpDeclRef(Child);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001111}
1112
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001113void ASTDumper::VisitFunctionDecl(const FunctionDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001114 dumpName(D);
1115 dumpType(D->getType());
1116
Rafael Espindola6ae7e502013-04-03 19:27:57 +00001117 StorageClass SC = D->getStorageClass();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001118 if (SC != SC_None)
1119 OS << ' ' << VarDecl::getStorageClassSpecifierString(SC);
1120 if (D->isInlineSpecified())
1121 OS << " inline";
1122 if (D->isVirtualAsWritten())
1123 OS << " virtual";
1124 if (D->isModulePrivate())
1125 OS << " __module_private__";
1126
1127 if (D->isPure())
1128 OS << " pure";
1129 else if (D->isDeletedAsWritten())
1130 OS << " delete";
1131
Richard Smithadaa0152013-05-17 02:09:46 +00001132 if (const FunctionProtoType *FPT = D->getType()->getAs<FunctionProtoType>()) {
1133 FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo();
Richard Smith8acb4282014-07-31 21:57:55 +00001134 switch (EPI.ExceptionSpec.Type) {
Richard Smithadaa0152013-05-17 02:09:46 +00001135 default: break;
1136 case EST_Unevaluated:
Richard Smith8acb4282014-07-31 21:57:55 +00001137 OS << " noexcept-unevaluated " << EPI.ExceptionSpec.SourceDecl;
Richard Smithadaa0152013-05-17 02:09:46 +00001138 break;
1139 case EST_Uninstantiated:
Richard Smith8acb4282014-07-31 21:57:55 +00001140 OS << " noexcept-uninstantiated " << EPI.ExceptionSpec.SourceTemplate;
Richard Smithadaa0152013-05-17 02:09:46 +00001141 break;
1142 }
1143 }
1144
Richard Smithf7514452014-10-30 21:02:37 +00001145 if (const FunctionTemplateSpecializationInfo *FTSI =
1146 D->getTemplateSpecializationInfo())
Richard Trieude5cc7d2013-01-31 01:44:26 +00001147 dumpTemplateArgumentList(*FTSI->TemplateArguments);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001148
Dmitri Gribenkof8579502013-01-12 19:30:44 +00001149 for (ArrayRef<NamedDecl *>::iterator
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001150 I = D->getDeclsInPrototypeScope().begin(),
Richard Smithf7514452014-10-30 21:02:37 +00001151 E = D->getDeclsInPrototypeScope().end(); I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001152 dumpDecl(*I);
1153
Richard Smith8a639892015-01-24 01:07:20 +00001154 if (!D->param_begin() && D->getNumParams())
1155 dumpChild([=] { OS << "<<NULL params x " << D->getNumParams() << ">>"; });
1156 else
1157 for (FunctionDecl::param_const_iterator I = D->param_begin(),
1158 E = D->param_end();
1159 I != E; ++I)
1160 dumpDecl(*I);
Richard Smithf7514452014-10-30 21:02:37 +00001161
1162 if (const CXXConstructorDecl *C = dyn_cast<CXXConstructorDecl>(D))
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001163 for (CXXConstructorDecl::init_const_iterator I = C->init_begin(),
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001164 E = C->init_end();
Richard Smithf7514452014-10-30 21:02:37 +00001165 I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001166 dumpCXXCtorInitializer(*I);
1167
Richard Smithf7514452014-10-30 21:02:37 +00001168 if (D->doesThisDeclarationHaveABody())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001169 dumpStmt(D->getBody());
1170}
1171
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001172void ASTDumper::VisitFieldDecl(const FieldDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001173 dumpName(D);
1174 dumpType(D->getType());
1175 if (D->isMutable())
1176 OS << " mutable";
1177 if (D->isModulePrivate())
1178 OS << " __module_private__";
Richard Trieude5cc7d2013-01-31 01:44:26 +00001179
Richard Smithf7514452014-10-30 21:02:37 +00001180 if (D->isBitField())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001181 dumpStmt(D->getBitWidth());
Richard Smithf7514452014-10-30 21:02:37 +00001182 if (Expr *Init = D->getInClassInitializer())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001183 dumpStmt(Init);
1184}
1185
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001186void ASTDumper::VisitVarDecl(const VarDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001187 dumpName(D);
1188 dumpType(D->getType());
Rafael Espindola6ae7e502013-04-03 19:27:57 +00001189 StorageClass SC = D->getStorageClass();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001190 if (SC != SC_None)
1191 OS << ' ' << VarDecl::getStorageClassSpecifierString(SC);
Richard Smithfd3834f2013-04-13 02:43:54 +00001192 switch (D->getTLSKind()) {
1193 case VarDecl::TLS_None: break;
1194 case VarDecl::TLS_Static: OS << " tls"; break;
1195 case VarDecl::TLS_Dynamic: OS << " tls_dynamic"; break;
1196 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001197 if (D->isModulePrivate())
1198 OS << " __module_private__";
1199 if (D->isNRVOVariable())
1200 OS << " nrvo";
Richard Trieude5cc7d2013-01-31 01:44:26 +00001201 if (D->hasInit()) {
Richard Smithd9967cc2014-07-10 22:54:03 +00001202 switch (D->getInitStyle()) {
1203 case VarDecl::CInit: OS << " cinit"; break;
1204 case VarDecl::CallInit: OS << " callinit"; break;
1205 case VarDecl::ListInit: OS << " listinit"; break;
1206 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001207 dumpStmt(D->getInit());
Richard Trieude5cc7d2013-01-31 01:44:26 +00001208 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001209}
1210
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001211void ASTDumper::VisitFileScopeAsmDecl(const FileScopeAsmDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001212 dumpStmt(D->getAsmString());
1213}
1214
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001215void ASTDumper::VisitImportDecl(const ImportDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001216 OS << ' ' << D->getImportedModule()->getFullModuleName();
1217}
1218
Nico Weber66220292016-03-02 17:28:48 +00001219void ASTDumper::VisitPragmaCommentDecl(const PragmaCommentDecl *D) {
1220 OS << ' ';
1221 switch (D->getCommentKind()) {
1222 case PCK_Unknown: llvm_unreachable("unexpected pragma comment kind");
1223 case PCK_Compiler: OS << "compiler"; break;
1224 case PCK_ExeStr: OS << "exestr"; break;
1225 case PCK_Lib: OS << "lib"; break;
1226 case PCK_Linker: OS << "linker"; break;
1227 case PCK_User: OS << "user"; break;
1228 }
1229 StringRef Arg = D->getArg();
1230 if (!Arg.empty())
1231 OS << " \"" << Arg << "\"";
1232}
1233
Nico Webercbbaeb12016-03-02 19:28:54 +00001234void ASTDumper::VisitPragmaDetectMismatchDecl(
1235 const PragmaDetectMismatchDecl *D) {
1236 OS << " \"" << D->getName() << "\" \"" << D->getValue() << "\"";
1237}
1238
Alexey Bataev958b9e72016-03-31 09:30:50 +00001239void ASTDumper::VisitCapturedDecl(const CapturedDecl *D) {
1240 dumpStmt(D->getBody());
1241}
1242
1243//===----------------------------------------------------------------------===//
1244// OpenMP Declarations
1245//===----------------------------------------------------------------------===//
1246
1247void ASTDumper::VisitOMPThreadPrivateDecl(const OMPThreadPrivateDecl *D) {
1248 for (auto *E : D->varlists())
1249 dumpStmt(E);
1250}
1251
1252void ASTDumper::VisitOMPDeclareReductionDecl(const OMPDeclareReductionDecl *D) {
1253 dumpName(D);
1254 dumpType(D->getType());
1255 OS << " combiner";
1256 dumpStmt(D->getCombiner());
1257 if (auto *Initializer = D->getInitializer()) {
1258 OS << " initializer";
1259 dumpStmt(Initializer);
1260 }
1261}
1262
1263void ASTDumper::VisitOMPCapturedExprDecl(const OMPCapturedExprDecl *D) {
1264 dumpName(D);
1265 dumpType(D->getType());
1266 dumpStmt(D->getInit());
1267}
Nico Webercbbaeb12016-03-02 19:28:54 +00001268
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001269//===----------------------------------------------------------------------===//
1270// C++ Declarations
1271//===----------------------------------------------------------------------===//
1272
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001273void ASTDumper::VisitNamespaceDecl(const NamespaceDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001274 dumpName(D);
1275 if (D->isInline())
1276 OS << " inline";
1277 if (!D->isOriginalNamespace())
1278 dumpDeclRef(D->getOriginalNamespace(), "original");
1279}
1280
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001281void ASTDumper::VisitUsingDirectiveDecl(const UsingDirectiveDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001282 OS << ' ';
1283 dumpBareDeclRef(D->getNominatedNamespace());
1284}
1285
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001286void ASTDumper::VisitNamespaceAliasDecl(const NamespaceAliasDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001287 dumpName(D);
1288 dumpDeclRef(D->getAliasedNamespace());
1289}
1290
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001291void ASTDumper::VisitTypeAliasDecl(const TypeAliasDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001292 dumpName(D);
1293 dumpType(D->getUnderlyingType());
Richard Smithba3a4f92016-01-12 21:59:26 +00001294 dumpTypeAsChild(D->getUnderlyingType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001295}
1296
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001297void ASTDumper::VisitTypeAliasTemplateDecl(const TypeAliasTemplateDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001298 dumpName(D);
1299 dumpTemplateParameters(D->getTemplateParameters());
1300 dumpDecl(D->getTemplatedDecl());
1301}
1302
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001303void ASTDumper::VisitCXXRecordDecl(const CXXRecordDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001304 VisitRecordDecl(D);
1305 if (!D->isCompleteDefinition())
1306 return;
1307
Aaron Ballman574705e2014-03-13 15:41:46 +00001308 for (const auto &I : D->bases()) {
Richard Smithf7514452014-10-30 21:02:37 +00001309 dumpChild([=] {
1310 if (I.isVirtual())
1311 OS << "virtual ";
1312 dumpAccessSpecifier(I.getAccessSpecifier());
1313 dumpType(I.getType());
1314 if (I.isPackExpansion())
1315 OS << "...";
1316 });
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001317 }
1318}
1319
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001320void ASTDumper::VisitStaticAssertDecl(const StaticAssertDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001321 dumpStmt(D->getAssertExpr());
1322 dumpStmt(D->getMessage());
1323}
1324
Richard Smithcbdf7332014-03-18 02:07:28 +00001325template<typename SpecializationDecl>
Richard Smithf7514452014-10-30 21:02:37 +00001326void ASTDumper::VisitTemplateDeclSpecialization(const SpecializationDecl *D,
Richard Smithcbdf7332014-03-18 02:07:28 +00001327 bool DumpExplicitInst,
1328 bool DumpRefOnly) {
1329 bool DumpedAny = false;
1330 for (auto *RedeclWithBadType : D->redecls()) {
1331 // FIXME: The redecls() range sometimes has elements of a less-specific
1332 // type. (In particular, ClassTemplateSpecializationDecl::redecls() gives
1333 // us TagDecls, and should give CXXRecordDecls).
1334 auto *Redecl = dyn_cast<SpecializationDecl>(RedeclWithBadType);
1335 if (!Redecl) {
1336 // Found the injected-class-name for a class template. This will be dumped
1337 // as part of its surrounding class so we don't need to dump it here.
1338 assert(isa<CXXRecordDecl>(RedeclWithBadType) &&
1339 "expected an injected-class-name");
1340 continue;
1341 }
1342
1343 switch (Redecl->getTemplateSpecializationKind()) {
1344 case TSK_ExplicitInstantiationDeclaration:
1345 case TSK_ExplicitInstantiationDefinition:
1346 if (!DumpExplicitInst)
1347 break;
1348 // Fall through.
1349 case TSK_Undeclared:
1350 case TSK_ImplicitInstantiation:
Richard Smithf7514452014-10-30 21:02:37 +00001351 if (DumpRefOnly)
1352 dumpDeclRef(Redecl);
1353 else
1354 dumpDecl(Redecl);
Richard Smithcbdf7332014-03-18 02:07:28 +00001355 DumpedAny = true;
1356 break;
1357 case TSK_ExplicitSpecialization:
1358 break;
1359 }
1360 }
1361
1362 // Ensure we dump at least one decl for each specialization.
1363 if (!DumpedAny)
Richard Smithf7514452014-10-30 21:02:37 +00001364 dumpDeclRef(D);
Richard Smithcbdf7332014-03-18 02:07:28 +00001365}
1366
Richard Smith20ade552014-03-17 23:34:53 +00001367template<typename TemplateDecl>
1368void ASTDumper::VisitTemplateDecl(const TemplateDecl *D,
1369 bool DumpExplicitInst) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001370 dumpName(D);
1371 dumpTemplateParameters(D->getTemplateParameters());
Richard Smithdcc2c452014-03-17 23:00:06 +00001372
Richard Smithf7514452014-10-30 21:02:37 +00001373 dumpDecl(D->getTemplatedDecl());
Richard Smithdcc2c452014-03-17 23:00:06 +00001374
Richard Smithcbdf7332014-03-18 02:07:28 +00001375 for (auto *Child : D->specializations())
Richard Smithf7514452014-10-30 21:02:37 +00001376 VisitTemplateDeclSpecialization(Child, DumpExplicitInst,
Richard Smithcbdf7332014-03-18 02:07:28 +00001377 !D->isCanonicalDecl());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001378}
1379
Richard Smith20ade552014-03-17 23:34:53 +00001380void ASTDumper::VisitFunctionTemplateDecl(const FunctionTemplateDecl *D) {
1381 // FIXME: We don't add a declaration of a function template specialization
1382 // to its context when it's explicitly instantiated, so dump explicit
1383 // instantiations when we dump the template itself.
1384 VisitTemplateDecl(D, true);
1385}
1386
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001387void ASTDumper::VisitClassTemplateDecl(const ClassTemplateDecl *D) {
Richard Smith20ade552014-03-17 23:34:53 +00001388 VisitTemplateDecl(D, false);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001389}
1390
1391void ASTDumper::VisitClassTemplateSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001392 const ClassTemplateSpecializationDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001393 VisitCXXRecordDecl(D);
1394 dumpTemplateArgumentList(D->getTemplateArgs());
1395}
1396
1397void ASTDumper::VisitClassTemplatePartialSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001398 const ClassTemplatePartialSpecializationDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001399 VisitClassTemplateSpecializationDecl(D);
1400 dumpTemplateParameters(D->getTemplateParameters());
1401}
1402
1403void ASTDumper::VisitClassScopeFunctionSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001404 const ClassScopeFunctionSpecializationDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001405 dumpDeclRef(D->getSpecialization());
1406 if (D->hasExplicitTemplateArgs())
1407 dumpTemplateArgumentListInfo(D->templateArgs());
1408}
1409
Richard Smithd25789a2013-09-18 01:36:02 +00001410void ASTDumper::VisitVarTemplateDecl(const VarTemplateDecl *D) {
Richard Smith20ade552014-03-17 23:34:53 +00001411 VisitTemplateDecl(D, false);
Richard Smithd25789a2013-09-18 01:36:02 +00001412}
1413
David Majnemerd9b1a4f2015-11-04 03:40:30 +00001414void ASTDumper::VisitBuiltinTemplateDecl(const BuiltinTemplateDecl *D) {
1415 dumpName(D);
1416 dumpTemplateParameters(D->getTemplateParameters());
1417}
1418
Richard Smithd25789a2013-09-18 01:36:02 +00001419void ASTDumper::VisitVarTemplateSpecializationDecl(
1420 const VarTemplateSpecializationDecl *D) {
1421 dumpTemplateArgumentList(D->getTemplateArgs());
1422 VisitVarDecl(D);
1423}
1424
1425void ASTDumper::VisitVarTemplatePartialSpecializationDecl(
1426 const VarTemplatePartialSpecializationDecl *D) {
1427 dumpTemplateParameters(D->getTemplateParameters());
1428 VisitVarTemplateSpecializationDecl(D);
1429}
1430
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001431void ASTDumper::VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001432 if (D->wasDeclaredWithTypename())
1433 OS << " typename";
1434 else
1435 OS << " class";
1436 if (D->isParameterPack())
1437 OS << " ...";
1438 dumpName(D);
Richard Smithf7514452014-10-30 21:02:37 +00001439 if (D->hasDefaultArgument())
Richard Smithecf74ff2014-03-23 20:50:39 +00001440 dumpTemplateArgument(D->getDefaultArgument());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001441}
1442
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001443void ASTDumper::VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001444 dumpType(D->getType());
1445 if (D->isParameterPack())
1446 OS << " ...";
1447 dumpName(D);
Richard Smithf7514452014-10-30 21:02:37 +00001448 if (D->hasDefaultArgument())
Richard Smithecf74ff2014-03-23 20:50:39 +00001449 dumpTemplateArgument(D->getDefaultArgument());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001450}
1451
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001452void ASTDumper::VisitTemplateTemplateParmDecl(
1453 const TemplateTemplateParmDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001454 if (D->isParameterPack())
1455 OS << " ...";
1456 dumpName(D);
1457 dumpTemplateParameters(D->getTemplateParameters());
Richard Smithf7514452014-10-30 21:02:37 +00001458 if (D->hasDefaultArgument())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001459 dumpTemplateArgumentLoc(D->getDefaultArgument());
1460}
1461
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001462void ASTDumper::VisitUsingDecl(const UsingDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001463 OS << ' ';
Dawn Perchikddd03bf2015-12-05 22:37:55 +00001464 if (D->getQualifier())
1465 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001466 OS << D->getNameAsString();
1467}
1468
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001469void ASTDumper::VisitUnresolvedUsingTypenameDecl(
1470 const UnresolvedUsingTypenameDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001471 OS << ' ';
Dawn Perchikddd03bf2015-12-05 22:37:55 +00001472 if (D->getQualifier())
1473 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001474 OS << D->getNameAsString();
1475}
1476
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001477void ASTDumper::VisitUnresolvedUsingValueDecl(const UnresolvedUsingValueDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001478 OS << ' ';
Dawn Perchikddd03bf2015-12-05 22:37:55 +00001479 if (D->getQualifier())
1480 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001481 OS << D->getNameAsString();
1482 dumpType(D->getType());
1483}
1484
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001485void ASTDumper::VisitUsingShadowDecl(const UsingShadowDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001486 OS << ' ';
1487 dumpBareDeclRef(D->getTargetDecl());
Richard Smithba3a4f92016-01-12 21:59:26 +00001488 if (auto *TD = dyn_cast<TypeDecl>(D->getUnderlyingDecl()))
1489 dumpTypeAsChild(TD->getTypeForDecl());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001490}
1491
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001492void ASTDumper::VisitLinkageSpecDecl(const LinkageSpecDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001493 switch (D->getLanguage()) {
1494 case LinkageSpecDecl::lang_c: OS << " C"; break;
1495 case LinkageSpecDecl::lang_cxx: OS << " C++"; break;
1496 }
1497}
1498
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001499void ASTDumper::VisitAccessSpecDecl(const AccessSpecDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001500 OS << ' ';
1501 dumpAccessSpecifier(D->getAccess());
1502}
1503
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001504void ASTDumper::VisitFriendDecl(const FriendDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001505 if (TypeSourceInfo *T = D->getFriendType())
1506 dumpType(T->getType());
1507 else
1508 dumpDecl(D->getFriendDecl());
1509}
1510
1511//===----------------------------------------------------------------------===//
1512// Obj-C Declarations
1513//===----------------------------------------------------------------------===//
1514
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001515void ASTDumper::VisitObjCIvarDecl(const ObjCIvarDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001516 dumpName(D);
1517 dumpType(D->getType());
1518 if (D->getSynthesize())
1519 OS << " synthesize";
1520
1521 switch (D->getAccessControl()) {
1522 case ObjCIvarDecl::None:
1523 OS << " none";
1524 break;
1525 case ObjCIvarDecl::Private:
1526 OS << " private";
1527 break;
1528 case ObjCIvarDecl::Protected:
1529 OS << " protected";
1530 break;
1531 case ObjCIvarDecl::Public:
1532 OS << " public";
1533 break;
1534 case ObjCIvarDecl::Package:
1535 OS << " package";
1536 break;
1537 }
1538}
1539
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001540void ASTDumper::VisitObjCMethodDecl(const ObjCMethodDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001541 if (D->isInstanceMethod())
1542 OS << " -";
1543 else
1544 OS << " +";
1545 dumpName(D);
Alp Toker314cc812014-01-25 16:55:45 +00001546 dumpType(D->getReturnType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001547
Richard Trieude5cc7d2013-01-31 01:44:26 +00001548 if (D->isThisDeclarationADefinition()) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001549 dumpDeclContext(D);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001550 } else {
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001551 for (ObjCMethodDecl::param_const_iterator I = D->param_begin(),
1552 E = D->param_end();
Richard Smithf7514452014-10-30 21:02:37 +00001553 I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001554 dumpDecl(*I);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001555 }
1556
Richard Smithf7514452014-10-30 21:02:37 +00001557 if (D->isVariadic())
1558 dumpChild([=] { OS << "..."; });
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001559
Richard Smithf7514452014-10-30 21:02:37 +00001560 if (D->hasBody())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001561 dumpStmt(D->getBody());
1562}
1563
Douglas Gregor85f3f952015-07-07 03:57:15 +00001564void ASTDumper::VisitObjCTypeParamDecl(const ObjCTypeParamDecl *D) {
1565 dumpName(D);
Douglas Gregor1ac1b632015-07-07 03:58:54 +00001566 switch (D->getVariance()) {
1567 case ObjCTypeParamVariance::Invariant:
1568 break;
1569
1570 case ObjCTypeParamVariance::Covariant:
1571 OS << " covariant";
1572 break;
1573
1574 case ObjCTypeParamVariance::Contravariant:
1575 OS << " contravariant";
1576 break;
1577 }
1578
Douglas Gregor85f3f952015-07-07 03:57:15 +00001579 if (D->hasExplicitBound())
1580 OS << " bounded";
1581 dumpType(D->getUnderlyingType());
1582}
1583
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001584void ASTDumper::VisitObjCCategoryDecl(const ObjCCategoryDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001585 dumpName(D);
1586 dumpDeclRef(D->getClassInterface());
Douglas Gregor85f3f952015-07-07 03:57:15 +00001587 dumpObjCTypeParamList(D->getTypeParamList());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001588 dumpDeclRef(D->getImplementation());
1589 for (ObjCCategoryDecl::protocol_iterator I = D->protocol_begin(),
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001590 E = D->protocol_end();
Richard Smithf7514452014-10-30 21:02:37 +00001591 I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001592 dumpDeclRef(*I);
1593}
1594
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001595void ASTDumper::VisitObjCCategoryImplDecl(const ObjCCategoryImplDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001596 dumpName(D);
1597 dumpDeclRef(D->getClassInterface());
1598 dumpDeclRef(D->getCategoryDecl());
1599}
1600
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001601void ASTDumper::VisitObjCProtocolDecl(const ObjCProtocolDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001602 dumpName(D);
Richard Smithdcc2c452014-03-17 23:00:06 +00001603
Richard Smith7fcb35f2014-03-18 02:37:59 +00001604 for (auto *Child : D->protocols())
Richard Smithf7514452014-10-30 21:02:37 +00001605 dumpDeclRef(Child);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001606}
1607
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001608void ASTDumper::VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001609 dumpName(D);
Douglas Gregor85f3f952015-07-07 03:57:15 +00001610 dumpObjCTypeParamList(D->getTypeParamListAsWritten());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001611 dumpDeclRef(D->getSuperClass(), "super");
Richard Smithdcc2c452014-03-17 23:00:06 +00001612
Richard Smithf7514452014-10-30 21:02:37 +00001613 dumpDeclRef(D->getImplementation());
Richard Smith7fcb35f2014-03-18 02:37:59 +00001614 for (auto *Child : D->protocols())
Richard Smithf7514452014-10-30 21:02:37 +00001615 dumpDeclRef(Child);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001616}
1617
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001618void ASTDumper::VisitObjCImplementationDecl(const ObjCImplementationDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001619 dumpName(D);
1620 dumpDeclRef(D->getSuperClass(), "super");
1621 dumpDeclRef(D->getClassInterface());
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001622 for (ObjCImplementationDecl::init_const_iterator I = D->init_begin(),
1623 E = D->init_end();
Richard Smithf7514452014-10-30 21:02:37 +00001624 I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001625 dumpCXXCtorInitializer(*I);
1626}
1627
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001628void ASTDumper::VisitObjCCompatibleAliasDecl(const ObjCCompatibleAliasDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001629 dumpName(D);
1630 dumpDeclRef(D->getClassInterface());
1631}
1632
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001633void ASTDumper::VisitObjCPropertyDecl(const ObjCPropertyDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001634 dumpName(D);
1635 dumpType(D->getType());
1636
1637 if (D->getPropertyImplementation() == ObjCPropertyDecl::Required)
1638 OS << " required";
1639 else if (D->getPropertyImplementation() == ObjCPropertyDecl::Optional)
1640 OS << " optional";
1641
1642 ObjCPropertyDecl::PropertyAttributeKind Attrs = D->getPropertyAttributes();
1643 if (Attrs != ObjCPropertyDecl::OBJC_PR_noattr) {
1644 if (Attrs & ObjCPropertyDecl::OBJC_PR_readonly)
1645 OS << " readonly";
1646 if (Attrs & ObjCPropertyDecl::OBJC_PR_assign)
1647 OS << " assign";
1648 if (Attrs & ObjCPropertyDecl::OBJC_PR_readwrite)
1649 OS << " readwrite";
1650 if (Attrs & ObjCPropertyDecl::OBJC_PR_retain)
1651 OS << " retain";
1652 if (Attrs & ObjCPropertyDecl::OBJC_PR_copy)
1653 OS << " copy";
1654 if (Attrs & ObjCPropertyDecl::OBJC_PR_nonatomic)
1655 OS << " nonatomic";
1656 if (Attrs & ObjCPropertyDecl::OBJC_PR_atomic)
1657 OS << " atomic";
1658 if (Attrs & ObjCPropertyDecl::OBJC_PR_weak)
1659 OS << " weak";
1660 if (Attrs & ObjCPropertyDecl::OBJC_PR_strong)
1661 OS << " strong";
1662 if (Attrs & ObjCPropertyDecl::OBJC_PR_unsafe_unretained)
1663 OS << " unsafe_unretained";
Manman Ren387ff7f2016-01-26 18:52:43 +00001664 if (Attrs & ObjCPropertyDecl::OBJC_PR_class)
1665 OS << " class";
Richard Smithf7514452014-10-30 21:02:37 +00001666 if (Attrs & ObjCPropertyDecl::OBJC_PR_getter)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001667 dumpDeclRef(D->getGetterMethodDecl(), "getter");
Richard Smithf7514452014-10-30 21:02:37 +00001668 if (Attrs & ObjCPropertyDecl::OBJC_PR_setter)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001669 dumpDeclRef(D->getSetterMethodDecl(), "setter");
1670 }
1671}
1672
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001673void ASTDumper::VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001674 dumpName(D->getPropertyDecl());
1675 if (D->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize)
1676 OS << " synthesize";
1677 else
1678 OS << " dynamic";
1679 dumpDeclRef(D->getPropertyDecl());
1680 dumpDeclRef(D->getPropertyIvarDecl());
1681}
1682
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001683void ASTDumper::VisitBlockDecl(const BlockDecl *D) {
Aaron Ballmanb2b8b1d2014-03-07 16:09:59 +00001684 for (auto I : D->params())
1685 dumpDecl(I);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001686
Richard Smithf7514452014-10-30 21:02:37 +00001687 if (D->isVariadic())
1688 dumpChild([=]{ OS << "..."; });
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001689
Richard Smithf7514452014-10-30 21:02:37 +00001690 if (D->capturesCXXThis())
1691 dumpChild([=]{ OS << "capture this"; });
1692
Aaron Ballman9371dd22014-03-14 18:34:04 +00001693 for (const auto &I : D->captures()) {
Richard Smithf7514452014-10-30 21:02:37 +00001694 dumpChild([=] {
1695 OS << "capture";
1696 if (I.isByRef())
1697 OS << " byref";
1698 if (I.isNested())
1699 OS << " nested";
1700 if (I.getVariable()) {
1701 OS << ' ';
1702 dumpBareDeclRef(I.getVariable());
1703 }
1704 if (I.hasCopyExpr())
1705 dumpStmt(I.getCopyExpr());
1706 });
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001707 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001708 dumpStmt(D->getBody());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001709}
1710
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001711//===----------------------------------------------------------------------===//
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001712// Stmt dumping methods.
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001713//===----------------------------------------------------------------------===//
1714
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001715void ASTDumper::dumpStmt(const Stmt *S) {
Richard Smithf7514452014-10-30 21:02:37 +00001716 dumpChild([=] {
1717 if (!S) {
1718 ColorScope Color(*this, NullColor);
1719 OS << "<<<NULL>>>";
1720 return;
1721 }
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001722
Richard Smithf7514452014-10-30 21:02:37 +00001723 if (const DeclStmt *DS = dyn_cast<DeclStmt>(S)) {
1724 VisitDeclStmt(DS);
1725 return;
1726 }
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001727
Richard Smithf7514452014-10-30 21:02:37 +00001728 ConstStmtVisitor<ASTDumper>::Visit(S);
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001729
Benjamin Kramer642f1732015-07-02 21:03:14 +00001730 for (const Stmt *SubStmt : S->children())
1731 dumpStmt(SubStmt);
Richard Smithf7514452014-10-30 21:02:37 +00001732 });
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001733}
1734
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001735void ASTDumper::VisitStmt(const Stmt *Node) {
Richard Trieud215b8d2013-01-26 01:31:20 +00001736 {
1737 ColorScope Color(*this, StmtColor);
1738 OS << Node->getStmtClassName();
1739 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001740 dumpPointer(Node);
1741 dumpSourceRange(Node->getSourceRange());
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001742}
1743
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001744void ASTDumper::VisitDeclStmt(const DeclStmt *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001745 VisitStmt(Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001746 for (DeclStmt::const_decl_iterator I = Node->decl_begin(),
1747 E = Node->decl_end();
Richard Smithf7514452014-10-30 21:02:37 +00001748 I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001749 dumpDecl(*I);
Ted Kremenek433a4922007-12-12 06:59:42 +00001750}
1751
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001752void ASTDumper::VisitAttributedStmt(const AttributedStmt *Node) {
Alexander Kornienko5bc364e2013-01-07 17:53:08 +00001753 VisitStmt(Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001754 for (ArrayRef<const Attr *>::iterator I = Node->getAttrs().begin(),
1755 E = Node->getAttrs().end();
Richard Smithf7514452014-10-30 21:02:37 +00001756 I != E; ++I)
Alexander Kornienko5bc364e2013-01-07 17:53:08 +00001757 dumpAttr(*I);
1758}
1759
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001760void ASTDumper::VisitLabelStmt(const LabelStmt *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001761 VisitStmt(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001762 OS << " '" << Node->getName() << "'";
Chris Lattnercbe4f772007-08-08 22:51:59 +00001763}
1764
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001765void ASTDumper::VisitGotoStmt(const GotoStmt *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001766 VisitStmt(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001767 OS << " '" << Node->getLabel()->getName() << "'";
1768 dumpPointer(Node->getLabel());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001769}
1770
Pavel Labath1ef83422013-09-04 14:35:00 +00001771void ASTDumper::VisitCXXCatchStmt(const CXXCatchStmt *Node) {
1772 VisitStmt(Node);
1773 dumpDecl(Node->getExceptionDecl());
1774}
1775
Alexey Bataev958b9e72016-03-31 09:30:50 +00001776void ASTDumper::VisitCapturedStmt(const CapturedStmt *Node) {
1777 VisitStmt(Node);
1778 dumpDecl(Node->getCapturedDecl());
1779}
1780
1781//===----------------------------------------------------------------------===//
1782// OpenMP dumping methods.
1783//===----------------------------------------------------------------------===//
1784
1785void ASTDumper::VisitOMPExecutableDirective(
1786 const OMPExecutableDirective *Node) {
1787 VisitStmt(Node);
1788 for (auto *C : Node->clauses()) {
1789 dumpChild([=] {
1790 if (!C) {
1791 ColorScope Color(*this, NullColor);
1792 OS << "<<<NULL>>> OMPClause";
1793 return;
1794 }
1795 {
1796 ColorScope Color(*this, AttrColor);
1797 StringRef ClauseName(getOpenMPClauseName(C->getClauseKind()));
1798 OS << "OMP" << ClauseName.substr(/*Start=*/0, /*N=*/1).upper()
1799 << ClauseName.drop_front() << "Clause";
1800 }
1801 dumpPointer(C);
1802 dumpSourceRange(SourceRange(C->getLocStart(), C->getLocEnd()));
1803 if (C->isImplicit())
1804 OS << " <implicit>";
1805 for (auto *S : C->children())
1806 dumpStmt(S);
1807 });
1808 }
1809}
1810
Chris Lattnercbe4f772007-08-08 22:51:59 +00001811//===----------------------------------------------------------------------===//
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001812// Expr dumping methods.
Chris Lattnercbe4f772007-08-08 22:51:59 +00001813//===----------------------------------------------------------------------===//
1814
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001815void ASTDumper::VisitExpr(const Expr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001816 VisitStmt(Node);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001817 dumpType(Node->getType());
1818
Richard Trieud215b8d2013-01-26 01:31:20 +00001819 {
1820 ColorScope Color(*this, ValueKindColor);
1821 switch (Node->getValueKind()) {
1822 case VK_RValue:
1823 break;
1824 case VK_LValue:
1825 OS << " lvalue";
1826 break;
1827 case VK_XValue:
1828 OS << " xvalue";
1829 break;
1830 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001831 }
1832
Richard Trieud215b8d2013-01-26 01:31:20 +00001833 {
1834 ColorScope Color(*this, ObjectKindColor);
1835 switch (Node->getObjectKind()) {
1836 case OK_Ordinary:
1837 break;
1838 case OK_BitField:
1839 OS << " bitfield";
1840 break;
1841 case OK_ObjCProperty:
1842 OS << " objcproperty";
1843 break;
1844 case OK_ObjCSubscript:
1845 OS << " objcsubscript";
1846 break;
1847 case OK_VectorComponent:
1848 OS << " vectorcomponent";
1849 break;
1850 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001851 }
Chris Lattnercbe4f772007-08-08 22:51:59 +00001852}
1853
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001854static void dumpBasePath(raw_ostream &OS, const CastExpr *Node) {
John McCallcf142162010-08-07 06:22:56 +00001855 if (Node->path_empty())
Anders Carlssona70cff62010-04-24 19:06:50 +00001856 return;
1857
1858 OS << " (";
1859 bool First = true;
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001860 for (CastExpr::path_const_iterator I = Node->path_begin(),
1861 E = Node->path_end();
1862 I != E; ++I) {
Anders Carlssona70cff62010-04-24 19:06:50 +00001863 const CXXBaseSpecifier *Base = *I;
1864 if (!First)
1865 OS << " -> ";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001866
Anders Carlssona70cff62010-04-24 19:06:50 +00001867 const CXXRecordDecl *RD =
1868 cast<CXXRecordDecl>(Base->getType()->getAs<RecordType>()->getDecl());
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001869
Anders Carlssona70cff62010-04-24 19:06:50 +00001870 if (Base->isVirtual())
1871 OS << "virtual ";
1872 OS << RD->getName();
1873 First = false;
1874 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001875
Anders Carlssona70cff62010-04-24 19:06:50 +00001876 OS << ')';
1877}
1878
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001879void ASTDumper::VisitCastExpr(const CastExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001880 VisitExpr(Node);
Richard Trieud215b8d2013-01-26 01:31:20 +00001881 OS << " <";
1882 {
1883 ColorScope Color(*this, CastColor);
1884 OS << Node->getCastKindName();
1885 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001886 dumpBasePath(OS, Node);
Anders Carlssona70cff62010-04-24 19:06:50 +00001887 OS << ">";
Anders Carlssond7923c62009-08-22 23:33:40 +00001888}
1889
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001890void ASTDumper::VisitDeclRefExpr(const DeclRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001891 VisitExpr(Node);
Ted Kremenek5f64ca82007-09-10 17:32:55 +00001892
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001893 OS << " ";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001894 dumpBareDeclRef(Node->getDecl());
Chandler Carruth8d26bb02011-05-01 23:48:14 +00001895 if (Node->getDecl() != Node->getFoundDecl()) {
1896 OS << " (";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001897 dumpBareDeclRef(Node->getFoundDecl());
Chandler Carruth8d26bb02011-05-01 23:48:14 +00001898 OS << ")";
1899 }
John McCall351762c2011-02-07 10:33:21 +00001900}
1901
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001902void ASTDumper::VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001903 VisitExpr(Node);
John McCall76d09942009-12-11 21:50:11 +00001904 OS << " (";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001905 if (!Node->requiresADL())
1906 OS << "no ";
Benjamin Kramerb11416d2010-04-17 09:33:03 +00001907 OS << "ADL) = '" << Node->getName() << '\'';
John McCall76d09942009-12-11 21:50:11 +00001908
1909 UnresolvedLookupExpr::decls_iterator
1910 I = Node->decls_begin(), E = Node->decls_end();
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001911 if (I == E)
1912 OS << " empty";
John McCall76d09942009-12-11 21:50:11 +00001913 for (; I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001914 dumpPointer(*I);
John McCall76d09942009-12-11 21:50:11 +00001915}
1916
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001917void ASTDumper::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001918 VisitExpr(Node);
Steve Naroff5d5efca2008-03-12 13:19:12 +00001919
Richard Trieud215b8d2013-01-26 01:31:20 +00001920 {
1921 ColorScope Color(*this, DeclKindNameColor);
1922 OS << " " << Node->getDecl()->getDeclKindName() << "Decl";
1923 }
1924 OS << "='" << *Node->getDecl() << "'";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001925 dumpPointer(Node->getDecl());
Steve Naroffb3424a92008-05-23 22:01:24 +00001926 if (Node->isFreeIvar())
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001927 OS << " isFreeIvar";
Steve Naroff5d5efca2008-03-12 13:19:12 +00001928}
1929
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001930void ASTDumper::VisitPredefinedExpr(const PredefinedExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001931 VisitExpr(Node);
Alexey Bataevec474782014-10-09 08:45:04 +00001932 OS << " " << PredefinedExpr::getIdentTypeName(Node->getIdentType());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001933}
1934
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001935void ASTDumper::VisitCharacterLiteral(const CharacterLiteral *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001936 VisitExpr(Node);
Richard Trieud215b8d2013-01-26 01:31:20 +00001937 ColorScope Color(*this, ValueColor);
Richard Trieu364ee422011-11-03 23:56:23 +00001938 OS << " " << Node->getValue();
Chris Lattnercbe4f772007-08-08 22:51:59 +00001939}
1940
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001941void ASTDumper::VisitIntegerLiteral(const IntegerLiteral *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001942 VisitExpr(Node);
Chris Lattnercbe4f772007-08-08 22:51:59 +00001943
1944 bool isSigned = Node->getType()->isSignedIntegerType();
Richard Trieud215b8d2013-01-26 01:31:20 +00001945 ColorScope Color(*this, ValueColor);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001946 OS << " " << Node->getValue().toString(10, isSigned);
Chris Lattnercbe4f772007-08-08 22:51:59 +00001947}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001948
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001949void ASTDumper::VisitFloatingLiteral(const FloatingLiteral *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001950 VisitExpr(Node);
Richard Trieud215b8d2013-01-26 01:31:20 +00001951 ColorScope Color(*this, ValueColor);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001952 OS << " " << Node->getValueAsApproximateDouble();
Chris Lattnercbe4f772007-08-08 22:51:59 +00001953}
Chris Lattner1c20a172007-08-26 03:42:43 +00001954
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001955void ASTDumper::VisitStringLiteral(const StringLiteral *Str) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001956 VisitExpr(Str);
Richard Trieud215b8d2013-01-26 01:31:20 +00001957 ColorScope Color(*this, ValueColor);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001958 OS << " ";
Richard Trieudc355912012-06-13 20:25:24 +00001959 Str->outputString(OS);
Chris Lattnercbe4f772007-08-08 22:51:59 +00001960}
Chris Lattner84ca3762007-08-30 01:00:35 +00001961
Richard Smithf0514962014-06-03 08:24:28 +00001962void ASTDumper::VisitInitListExpr(const InitListExpr *ILE) {
1963 VisitExpr(ILE);
1964 if (auto *Filler = ILE->getArrayFiller()) {
Richard Smithf7514452014-10-30 21:02:37 +00001965 dumpChild([=] {
1966 OS << "array filler";
1967 dumpStmt(Filler);
1968 });
Richard Smithf0514962014-06-03 08:24:28 +00001969 }
1970 if (auto *Field = ILE->getInitializedFieldInUnion()) {
1971 OS << " field ";
1972 dumpBareDeclRef(Field);
1973 }
1974}
1975
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001976void ASTDumper::VisitUnaryOperator(const UnaryOperator *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001977 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001978 OS << " " << (Node->isPostfix() ? "postfix" : "prefix")
1979 << " '" << UnaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
Chris Lattnercbe4f772007-08-08 22:51:59 +00001980}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001981
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001982void ASTDumper::VisitUnaryExprOrTypeTraitExpr(
1983 const UnaryExprOrTypeTraitExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001984 VisitExpr(Node);
Peter Collingbournee190dee2011-03-11 19:24:49 +00001985 switch(Node->getKind()) {
1986 case UETT_SizeOf:
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001987 OS << " sizeof";
Peter Collingbournee190dee2011-03-11 19:24:49 +00001988 break;
1989 case UETT_AlignOf:
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001990 OS << " alignof";
Peter Collingbournee190dee2011-03-11 19:24:49 +00001991 break;
1992 case UETT_VecStep:
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001993 OS << " vec_step";
Peter Collingbournee190dee2011-03-11 19:24:49 +00001994 break;
Alexey Bataev00396512015-07-02 03:40:19 +00001995 case UETT_OpenMPRequiredSimdAlign:
1996 OS << " __builtin_omp_required_simd_align";
1997 break;
Peter Collingbournee190dee2011-03-11 19:24:49 +00001998 }
Sebastian Redl6f282892008-11-11 17:56:53 +00001999 if (Node->isArgumentType())
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002000 dumpType(Node->getArgumentType());
Chris Lattnercbe4f772007-08-08 22:51:59 +00002001}
Chris Lattnerdb3b3ff2007-08-09 17:35:30 +00002002
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002003void ASTDumper::VisitMemberExpr(const MemberExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002004 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002005 OS << " " << (Node->isArrow() ? "->" : ".") << *Node->getMemberDecl();
2006 dumpPointer(Node->getMemberDecl());
Chris Lattnercbe4f772007-08-08 22:51:59 +00002007}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002008
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002009void ASTDumper::VisitExtVectorElementExpr(const ExtVectorElementExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002010 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002011 OS << " " << Node->getAccessor().getNameStart();
Chris Lattnercbe4f772007-08-08 22:51:59 +00002012}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002013
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002014void ASTDumper::VisitBinaryOperator(const BinaryOperator *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002015 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002016 OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
Chris Lattner86928112007-08-25 02:00:02 +00002017}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002018
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002019void ASTDumper::VisitCompoundAssignOperator(
2020 const CompoundAssignOperator *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002021 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002022 OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode())
2023 << "' ComputeLHSTy=";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002024 dumpBareType(Node->getComputationLHSType());
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002025 OS << " ComputeResultTy=";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002026 dumpBareType(Node->getComputationResultType());
Chris Lattnercbe4f772007-08-08 22:51:59 +00002027}
Chris Lattnercbe4f772007-08-08 22:51:59 +00002028
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002029void ASTDumper::VisitBlockExpr(const BlockExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002030 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002031 dumpDecl(Node->getBlockDecl());
John McCall351762c2011-02-07 10:33:21 +00002032}
2033
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002034void ASTDumper::VisitOpaqueValueExpr(const OpaqueValueExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002035 VisitExpr(Node);
John McCallfe96e0b2011-11-06 09:01:30 +00002036
Richard Smithf7514452014-10-30 21:02:37 +00002037 if (Expr *Source = Node->getSourceExpr())
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002038 dumpStmt(Source);
John McCallfe96e0b2011-11-06 09:01:30 +00002039}
2040
Chris Lattnercbe4f772007-08-08 22:51:59 +00002041// GNU extensions.
2042
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002043void ASTDumper::VisitAddrLabelExpr(const AddrLabelExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002044 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002045 OS << " " << Node->getLabel()->getName();
2046 dumpPointer(Node->getLabel());
Chris Lattnercbe4f772007-08-08 22:51:59 +00002047}
2048
Chris Lattner8f184b12007-08-09 18:03:18 +00002049//===----------------------------------------------------------------------===//
2050// C++ Expressions
2051//===----------------------------------------------------------------------===//
Chris Lattnercbe4f772007-08-08 22:51:59 +00002052
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002053void ASTDumper::VisitCXXNamedCastExpr(const CXXNamedCastExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002054 VisitExpr(Node);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002055 OS << " " << Node->getCastName()
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002056 << "<" << Node->getTypeAsWritten().getAsString() << ">"
Anders Carlssona70cff62010-04-24 19:06:50 +00002057 << " <" << Node->getCastKindName();
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002058 dumpBasePath(OS, Node);
Anders Carlssona70cff62010-04-24 19:06:50 +00002059 OS << ">";
Chris Lattnercbe4f772007-08-08 22:51:59 +00002060}
2061
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002062void ASTDumper::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002063 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002064 OS << " " << (Node->getValue() ? "true" : "false");
Chris Lattnercbe4f772007-08-08 22:51:59 +00002065}
2066
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002067void ASTDumper::VisitCXXThisExpr(const CXXThisExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002068 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002069 OS << " this";
Douglas Gregor8ea1f532008-11-04 14:56:14 +00002070}
2071
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002072void ASTDumper::VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002073 VisitExpr(Node);
Eli Friedman29538892011-09-02 17:38:59 +00002074 OS << " functional cast to " << Node->getTypeAsWritten().getAsString()
2075 << " <" << Node->getCastKindName() << ">";
Douglas Gregore200adc2008-10-27 19:41:14 +00002076}
2077
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002078void ASTDumper::VisitCXXConstructExpr(const CXXConstructExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002079 VisitExpr(Node);
John McCalleba90cd2010-02-02 19:03:45 +00002080 CXXConstructorDecl *Ctor = Node->getConstructor();
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002081 dumpType(Ctor->getType());
Anders Carlsson073846832009-08-12 00:21:52 +00002082 if (Node->isElidable())
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002083 OS << " elidable";
John McCall85370042010-08-07 06:38:55 +00002084 if (Node->requiresZeroInitialization())
2085 OS << " zeroing";
Anders Carlsson073846832009-08-12 00:21:52 +00002086}
2087
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002088void ASTDumper::VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002089 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002090 OS << " ";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002091 dumpCXXTemporary(Node->getTemporary());
Anders Carlsson073846832009-08-12 00:21:52 +00002092}
2093
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002094void ASTDumper::VisitCXXNewExpr(const CXXNewExpr *Node) {
2095 VisitExpr(Node);
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002096 if (Node->isGlobalNew())
Reid Kleckner461c0c62015-03-19 18:47:47 +00002097 OS << " global";
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002098 if (Node->isArray())
Reid Kleckner461c0c62015-03-19 18:47:47 +00002099 OS << " array";
2100 if (Node->getOperatorNew()) {
2101 OS << ' ';
2102 dumpBareDeclRef(Node->getOperatorNew());
2103 }
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002104 // We could dump the deallocation function used in case of error, but it's
2105 // usually not that interesting.
2106}
2107
2108void ASTDumper::VisitCXXDeleteExpr(const CXXDeleteExpr *Node) {
2109 VisitExpr(Node);
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002110 if (Node->isGlobalDelete())
Reid Kleckner461c0c62015-03-19 18:47:47 +00002111 OS << " global";
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002112 if (Node->isArrayForm())
Reid Kleckner461c0c62015-03-19 18:47:47 +00002113 OS << " array";
2114 if (Node->getOperatorDelete()) {
2115 OS << ' ';
2116 dumpBareDeclRef(Node->getOperatorDelete());
2117 }
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002118}
2119
Richard Smithe6c01442013-06-05 00:46:14 +00002120void
2121ASTDumper::VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *Node) {
2122 VisitExpr(Node);
2123 if (const ValueDecl *VD = Node->getExtendingDecl()) {
2124 OS << " extended by ";
2125 dumpBareDeclRef(VD);
2126 }
2127}
2128
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002129void ASTDumper::VisitExprWithCleanups(const ExprWithCleanups *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002130 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002131 for (unsigned i = 0, e = Node->getNumObjects(); i != e; ++i)
2132 dumpDeclRef(Node->getObject(i), "cleanup");
Anders Carlsson073846832009-08-12 00:21:52 +00002133}
2134
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002135void ASTDumper::dumpCXXTemporary(const CXXTemporary *Temporary) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002136 OS << "(CXXTemporary";
2137 dumpPointer(Temporary);
2138 OS << ")";
Anders Carlsson073846832009-08-12 00:21:52 +00002139}
2140
Serge Pavlov6b926032015-02-16 19:58:41 +00002141void ASTDumper::VisitSizeOfPackExpr(const SizeOfPackExpr *Node) {
2142 VisitExpr(Node);
2143 dumpPointer(Node->getPack());
2144 dumpName(Node->getPack());
Richard Smithd784e682015-09-23 21:41:42 +00002145 if (Node->isPartiallySubstituted())
2146 for (const auto &A : Node->getPartialArguments())
2147 dumpTemplateArgument(A);
Serge Pavlov6b926032015-02-16 19:58:41 +00002148}
2149
2150
Anders Carlsson76f4a902007-08-21 17:43:55 +00002151//===----------------------------------------------------------------------===//
2152// Obj-C Expressions
2153//===----------------------------------------------------------------------===//
2154
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002155void ASTDumper::VisitObjCMessageExpr(const ObjCMessageExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002156 VisitExpr(Node);
Aaron Ballmanb190f972014-01-03 17:59:55 +00002157 OS << " selector=";
2158 Node->getSelector().print(OS);
Douglas Gregor9a129192010-04-21 00:45:42 +00002159 switch (Node->getReceiverKind()) {
2160 case ObjCMessageExpr::Instance:
2161 break;
2162
2163 case ObjCMessageExpr::Class:
2164 OS << " class=";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002165 dumpBareType(Node->getClassReceiver());
Douglas Gregor9a129192010-04-21 00:45:42 +00002166 break;
2167
2168 case ObjCMessageExpr::SuperInstance:
2169 OS << " super (instance)";
2170 break;
2171
2172 case ObjCMessageExpr::SuperClass:
2173 OS << " super (class)";
2174 break;
2175 }
Ted Kremenek36748da2008-02-29 22:04:05 +00002176}
2177
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002178void ASTDumper::VisitObjCBoxedExpr(const ObjCBoxedExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002179 VisitExpr(Node);
Aaron Ballmanb190f972014-01-03 17:59:55 +00002180 OS << " selector=";
2181 Node->getBoxingMethod()->getSelector().print(OS);
Argyrios Kyrtzidis9dd40892012-05-10 20:02:31 +00002182}
2183
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002184void ASTDumper::VisitObjCAtCatchStmt(const ObjCAtCatchStmt *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002185 VisitStmt(Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002186 if (const VarDecl *CatchParam = Node->getCatchParamDecl())
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002187 dumpDecl(CatchParam);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002188 else
Douglas Gregor96c79492010-04-23 22:50:49 +00002189 OS << " catch all";
Douglas Gregor96c79492010-04-23 22:50:49 +00002190}
2191
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002192void ASTDumper::VisitObjCEncodeExpr(const ObjCEncodeExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002193 VisitExpr(Node);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002194 dumpType(Node->getEncodedType());
Anders Carlssonc5a81eb2007-08-22 15:14:15 +00002195}
2196
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002197void ASTDumper::VisitObjCSelectorExpr(const ObjCSelectorExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002198 VisitExpr(Node);
Mike Stump11289f42009-09-09 15:08:12 +00002199
Aaron Ballmanb190f972014-01-03 17:59:55 +00002200 OS << " ";
2201 Node->getSelector().print(OS);
Fariborz Jahanian4bef4622007-10-16 20:40:23 +00002202}
2203
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002204void ASTDumper::VisitObjCProtocolExpr(const ObjCProtocolExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002205 VisitExpr(Node);
Mike Stump11289f42009-09-09 15:08:12 +00002206
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002207 OS << ' ' << *Node->getProtocol();
Fariborz Jahaniana32aaef2007-10-17 16:58:11 +00002208}
Daniel Dunbar4b8c6db2008-08-30 05:35:15 +00002209
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002210void ASTDumper::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002211 VisitExpr(Node);
John McCallb7bd14f2010-12-02 01:19:52 +00002212 if (Node->isImplicitProperty()) {
Fariborz Jahanian0f0b3022010-12-22 19:46:35 +00002213 OS << " Kind=MethodRef Getter=\"";
2214 if (Node->getImplicitPropertyGetter())
Aaron Ballmanb190f972014-01-03 17:59:55 +00002215 Node->getImplicitPropertyGetter()->getSelector().print(OS);
Fariborz Jahanian0f0b3022010-12-22 19:46:35 +00002216 else
2217 OS << "(null)";
2218
2219 OS << "\" Setter=\"";
John McCallb7bd14f2010-12-02 01:19:52 +00002220 if (ObjCMethodDecl *Setter = Node->getImplicitPropertySetter())
Aaron Ballmanb190f972014-01-03 17:59:55 +00002221 Setter->getSelector().print(OS);
John McCallb7bd14f2010-12-02 01:19:52 +00002222 else
2223 OS << "(null)";
2224 OS << "\"";
2225 } else {
Benjamin Kramerb89514a2011-10-14 18:45:37 +00002226 OS << " Kind=PropertyRef Property=\"" << *Node->getExplicitProperty() <<'"';
John McCallb7bd14f2010-12-02 01:19:52 +00002227 }
Fariborz Jahanian8a1810f2008-11-22 18:39:36 +00002228
Fariborz Jahanian681c0752010-10-14 16:04:05 +00002229 if (Node->isSuperReceiver())
2230 OS << " super";
Argyrios Kyrtzidisab468b02012-03-30 00:19:18 +00002231
2232 OS << " Messaging=";
2233 if (Node->isMessagingGetter() && Node->isMessagingSetter())
2234 OS << "Getter&Setter";
2235 else if (Node->isMessagingGetter())
2236 OS << "Getter";
2237 else if (Node->isMessagingSetter())
2238 OS << "Setter";
Douglas Gregor8ea1f532008-11-04 14:56:14 +00002239}
2240
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002241void ASTDumper::VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002242 VisitExpr(Node);
Ted Kremeneke65b0862012-03-06 20:05:56 +00002243 if (Node->isArraySubscriptRefExpr())
2244 OS << " Kind=ArraySubscript GetterForArray=\"";
2245 else
2246 OS << " Kind=DictionarySubscript GetterForDictionary=\"";
2247 if (Node->getAtIndexMethodDecl())
Aaron Ballmanb190f972014-01-03 17:59:55 +00002248 Node->getAtIndexMethodDecl()->getSelector().print(OS);
Ted Kremeneke65b0862012-03-06 20:05:56 +00002249 else
2250 OS << "(null)";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002251
Ted Kremeneke65b0862012-03-06 20:05:56 +00002252 if (Node->isArraySubscriptRefExpr())
2253 OS << "\" SetterForArray=\"";
2254 else
2255 OS << "\" SetterForDictionary=\"";
2256 if (Node->setAtIndexMethodDecl())
Aaron Ballmanb190f972014-01-03 17:59:55 +00002257 Node->setAtIndexMethodDecl()->getSelector().print(OS);
Ted Kremeneke65b0862012-03-06 20:05:56 +00002258 else
2259 OS << "(null)";
2260}
2261
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002262void ASTDumper::VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002263 VisitExpr(Node);
Ted Kremeneke65b0862012-03-06 20:05:56 +00002264 OS << " " << (Node->getValue() ? "__objc_yes" : "__objc_no");
2265}
2266
Chris Lattnercbe4f772007-08-08 22:51:59 +00002267//===----------------------------------------------------------------------===//
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002268// Comments
2269//===----------------------------------------------------------------------===//
2270
2271const char *ASTDumper::getCommandName(unsigned CommandID) {
2272 if (Traits)
2273 return Traits->getCommandInfo(CommandID)->Name;
2274 const CommandInfo *Info = CommandTraits::getBuiltinCommandInfo(CommandID);
2275 if (Info)
2276 return Info->Name;
2277 return "<not a builtin command>";
2278}
2279
2280void ASTDumper::dumpFullComment(const FullComment *C) {
2281 if (!C)
2282 return;
2283
2284 FC = C;
2285 dumpComment(C);
Craig Topper36250ad2014-05-12 05:36:57 +00002286 FC = nullptr;
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002287}
2288
2289void ASTDumper::dumpComment(const Comment *C) {
Richard Smithf7514452014-10-30 21:02:37 +00002290 dumpChild([=] {
2291 if (!C) {
2292 ColorScope Color(*this, NullColor);
2293 OS << "<<<NULL>>>";
2294 return;
2295 }
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002296
Richard Smithf7514452014-10-30 21:02:37 +00002297 {
2298 ColorScope Color(*this, CommentColor);
2299 OS << C->getCommentKindName();
2300 }
2301 dumpPointer(C);
2302 dumpSourceRange(C->getSourceRange());
2303 ConstCommentVisitor<ASTDumper>::visit(C);
2304 for (Comment::child_iterator I = C->child_begin(), E = C->child_end();
2305 I != E; ++I)
2306 dumpComment(*I);
2307 });
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002308}
2309
2310void ASTDumper::visitTextComment(const TextComment *C) {
2311 OS << " Text=\"" << C->getText() << "\"";
2312}
2313
2314void ASTDumper::visitInlineCommandComment(const InlineCommandComment *C) {
2315 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\"";
2316 switch (C->getRenderKind()) {
2317 case InlineCommandComment::RenderNormal:
2318 OS << " RenderNormal";
2319 break;
2320 case InlineCommandComment::RenderBold:
2321 OS << " RenderBold";
2322 break;
2323 case InlineCommandComment::RenderMonospaced:
2324 OS << " RenderMonospaced";
2325 break;
2326 case InlineCommandComment::RenderEmphasized:
2327 OS << " RenderEmphasized";
2328 break;
2329 }
2330
2331 for (unsigned i = 0, e = C->getNumArgs(); i != e; ++i)
2332 OS << " Arg[" << i << "]=\"" << C->getArgText(i) << "\"";
2333}
2334
2335void ASTDumper::visitHTMLStartTagComment(const HTMLStartTagComment *C) {
2336 OS << " Name=\"" << C->getTagName() << "\"";
2337 if (C->getNumAttrs() != 0) {
2338 OS << " Attrs: ";
2339 for (unsigned i = 0, e = C->getNumAttrs(); i != e; ++i) {
2340 const HTMLStartTagComment::Attribute &Attr = C->getAttr(i);
2341 OS << " \"" << Attr.Name << "=\"" << Attr.Value << "\"";
2342 }
2343 }
2344 if (C->isSelfClosing())
2345 OS << " SelfClosing";
2346}
2347
2348void ASTDumper::visitHTMLEndTagComment(const HTMLEndTagComment *C) {
2349 OS << " Name=\"" << C->getTagName() << "\"";
2350}
2351
2352void ASTDumper::visitBlockCommandComment(const BlockCommandComment *C) {
2353 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\"";
2354 for (unsigned i = 0, e = C->getNumArgs(); i != e; ++i)
2355 OS << " Arg[" << i << "]=\"" << C->getArgText(i) << "\"";
2356}
2357
2358void ASTDumper::visitParamCommandComment(const ParamCommandComment *C) {
2359 OS << " " << ParamCommandComment::getDirectionAsString(C->getDirection());
2360
2361 if (C->isDirectionExplicit())
2362 OS << " explicitly";
2363 else
2364 OS << " implicitly";
2365
2366 if (C->hasParamName()) {
2367 if (C->isParamIndexValid())
2368 OS << " Param=\"" << C->getParamName(FC) << "\"";
2369 else
2370 OS << " Param=\"" << C->getParamNameAsWritten() << "\"";
2371 }
2372
Dmitri Gribenkodbff5c72014-03-19 14:03:47 +00002373 if (C->isParamIndexValid() && !C->isVarArgParam())
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002374 OS << " ParamIndex=" << C->getParamIndex();
2375}
2376
2377void ASTDumper::visitTParamCommandComment(const TParamCommandComment *C) {
2378 if (C->hasParamName()) {
2379 if (C->isPositionValid())
2380 OS << " Param=\"" << C->getParamName(FC) << "\"";
2381 else
2382 OS << " Param=\"" << C->getParamNameAsWritten() << "\"";
2383 }
2384
2385 if (C->isPositionValid()) {
2386 OS << " Position=<";
2387 for (unsigned i = 0, e = C->getDepth(); i != e; ++i) {
2388 OS << C->getIndex(i);
2389 if (i != e - 1)
2390 OS << ", ";
2391 }
2392 OS << ">";
2393 }
2394}
2395
2396void ASTDumper::visitVerbatimBlockComment(const VerbatimBlockComment *C) {
2397 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\""
2398 " CloseName=\"" << C->getCloseName() << "\"";
2399}
2400
2401void ASTDumper::visitVerbatimBlockLineComment(
2402 const VerbatimBlockLineComment *C) {
2403 OS << " Text=\"" << C->getText() << "\"";
2404}
2405
2406void ASTDumper::visitVerbatimLineComment(const VerbatimLineComment *C) {
2407 OS << " Text=\"" << C->getText() << "\"";
2408}
2409
2410//===----------------------------------------------------------------------===//
Richard Smithd5e7ff82014-10-31 01:17:45 +00002411// Type method implementations
2412//===----------------------------------------------------------------------===//
2413
2414void QualType::dump(const char *msg) const {
2415 if (msg)
2416 llvm::errs() << msg << ": ";
2417 dump();
2418}
2419
2420LLVM_DUMP_METHOD void QualType::dump() const {
2421 ASTDumper Dumper(llvm::errs(), nullptr, nullptr);
2422 Dumper.dumpTypeAsChild(*this);
2423}
2424
2425LLVM_DUMP_METHOD void Type::dump() const { QualType(this, 0).dump(); }
2426
2427//===----------------------------------------------------------------------===//
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002428// Decl method implementations
2429//===----------------------------------------------------------------------===//
2430
Alp Tokeref6b0072014-01-04 13:47:14 +00002431LLVM_DUMP_METHOD void Decl::dump() const { dump(llvm::errs()); }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002432
Alp Tokeref6b0072014-01-04 13:47:14 +00002433LLVM_DUMP_METHOD void Decl::dump(raw_ostream &OS) const {
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002434 ASTDumper P(OS, &getASTContext().getCommentCommandTraits(),
2435 &getASTContext().getSourceManager());
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002436 P.dumpDecl(this);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002437}
2438
Alp Tokeref6b0072014-01-04 13:47:14 +00002439LLVM_DUMP_METHOD void Decl::dumpColor() const {
Richard Trieud215b8d2013-01-26 01:31:20 +00002440 ASTDumper P(llvm::errs(), &getASTContext().getCommentCommandTraits(),
2441 &getASTContext().getSourceManager(), /*ShowColors*/true);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002442 P.dumpDecl(this);
Richard Trieud215b8d2013-01-26 01:31:20 +00002443}
Richard Smith33937e72013-06-22 21:49:40 +00002444
Alp Tokeref6b0072014-01-04 13:47:14 +00002445LLVM_DUMP_METHOD void DeclContext::dumpLookups() const {
Richard Smith6ea05822013-06-24 01:45:33 +00002446 dumpLookups(llvm::errs());
2447}
2448
Richard Smith35f986d2014-08-11 22:11:07 +00002449LLVM_DUMP_METHOD void DeclContext::dumpLookups(raw_ostream &OS,
2450 bool DumpDecls) const {
Richard Smith33937e72013-06-22 21:49:40 +00002451 const DeclContext *DC = this;
2452 while (!DC->isTranslationUnit())
2453 DC = DC->getParent();
2454 ASTContext &Ctx = cast<TranslationUnitDecl>(DC)->getASTContext();
Richard Smith6ea05822013-06-24 01:45:33 +00002455 ASTDumper P(OS, &Ctx.getCommentCommandTraits(), &Ctx.getSourceManager());
Richard Smith35f986d2014-08-11 22:11:07 +00002456 P.dumpLookups(this, DumpDecls);
Richard Smith33937e72013-06-22 21:49:40 +00002457}
2458
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002459//===----------------------------------------------------------------------===//
Chris Lattnercbe4f772007-08-08 22:51:59 +00002460// Stmt method implementations
2461//===----------------------------------------------------------------------===//
2462
Alp Tokeref6b0072014-01-04 13:47:14 +00002463LLVM_DUMP_METHOD void Stmt::dump(SourceManager &SM) const {
Argyrios Kyrtzidisc049f752010-08-09 10:54:31 +00002464 dump(llvm::errs(), SM);
2465}
2466
Alp Tokeref6b0072014-01-04 13:47:14 +00002467LLVM_DUMP_METHOD void Stmt::dump(raw_ostream &OS, SourceManager &SM) const {
Craig Topper36250ad2014-05-12 05:36:57 +00002468 ASTDumper P(OS, nullptr, &SM);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002469 P.dumpStmt(this);
Chris Lattner779d5d92007-08-30 00:40:08 +00002470}
2471
Faisal Vali2da8ed92015-03-22 13:35:56 +00002472LLVM_DUMP_METHOD void Stmt::dump(raw_ostream &OS) const {
2473 ASTDumper P(OS, nullptr, nullptr);
2474 P.dumpStmt(this);
2475}
2476
Alp Tokeref6b0072014-01-04 13:47:14 +00002477LLVM_DUMP_METHOD void Stmt::dump() const {
Craig Topper36250ad2014-05-12 05:36:57 +00002478 ASTDumper P(llvm::errs(), nullptr, nullptr);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002479 P.dumpStmt(this);
Chris Lattnercbe4f772007-08-08 22:51:59 +00002480}
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002481
Alp Tokeref6b0072014-01-04 13:47:14 +00002482LLVM_DUMP_METHOD void Stmt::dumpColor() const {
Craig Topper36250ad2014-05-12 05:36:57 +00002483 ASTDumper P(llvm::errs(), nullptr, nullptr, /*ShowColors*/true);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002484 P.dumpStmt(this);
Richard Trieud215b8d2013-01-26 01:31:20 +00002485}
2486
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002487//===----------------------------------------------------------------------===//
2488// Comment method implementations
2489//===----------------------------------------------------------------------===//
2490
Craig Topper36250ad2014-05-12 05:36:57 +00002491LLVM_DUMP_METHOD void Comment::dump() const {
2492 dump(llvm::errs(), nullptr, nullptr);
2493}
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002494
Alp Tokeref6b0072014-01-04 13:47:14 +00002495LLVM_DUMP_METHOD void Comment::dump(const ASTContext &Context) const {
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002496 dump(llvm::errs(), &Context.getCommentCommandTraits(),
2497 &Context.getSourceManager());
2498}
2499
Alexander Kornienko00911f12013-01-15 12:20:21 +00002500void Comment::dump(raw_ostream &OS, const CommandTraits *Traits,
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002501 const SourceManager *SM) const {
2502 const FullComment *FC = dyn_cast<FullComment>(this);
2503 ASTDumper D(OS, Traits, SM);
2504 D.dumpFullComment(FC);
2505}
Richard Trieud215b8d2013-01-26 01:31:20 +00002506
Alp Tokeref6b0072014-01-04 13:47:14 +00002507LLVM_DUMP_METHOD void Comment::dumpColor() const {
Richard Trieud215b8d2013-01-26 01:31:20 +00002508 const FullComment *FC = dyn_cast<FullComment>(this);
Craig Topper36250ad2014-05-12 05:36:57 +00002509 ASTDumper D(llvm::errs(), nullptr, nullptr, /*ShowColors*/true);
Richard Trieud215b8d2013-01-26 01:31:20 +00002510 D.dumpFullComment(FC);
2511}