blob: 61a38af8dc156a5692e590d05336f5af0d4cb249 [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);
Richard Smithbdb84f32016-07-22 23:36:59 +0000431 void VisitDecompositionDecl(const DecompositionDecl *D);
Richard Smith7873de02016-08-11 22:25:46 +0000432 void VisitBindingDecl(const BindingDecl *D);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000433 void VisitFileScopeAsmDecl(const FileScopeAsmDecl *D);
434 void VisitImportDecl(const ImportDecl *D);
Nico Weber66220292016-03-02 17:28:48 +0000435 void VisitPragmaCommentDecl(const PragmaCommentDecl *D);
Nico Webercbbaeb12016-03-02 19:28:54 +0000436 void VisitPragmaDetectMismatchDecl(const PragmaDetectMismatchDecl *D);
Alexey Bataev958b9e72016-03-31 09:30:50 +0000437 void VisitCapturedDecl(const CapturedDecl *D);
438
439 // OpenMP decls
440 void VisitOMPThreadPrivateDecl(const OMPThreadPrivateDecl *D);
441 void VisitOMPDeclareReductionDecl(const OMPDeclareReductionDecl *D);
442 void VisitOMPCapturedExprDecl(const OMPCapturedExprDecl *D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000443
444 // C++ Decls
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000445 void VisitNamespaceDecl(const NamespaceDecl *D);
446 void VisitUsingDirectiveDecl(const UsingDirectiveDecl *D);
447 void VisitNamespaceAliasDecl(const NamespaceAliasDecl *D);
448 void VisitTypeAliasDecl(const TypeAliasDecl *D);
449 void VisitTypeAliasTemplateDecl(const TypeAliasTemplateDecl *D);
450 void VisitCXXRecordDecl(const CXXRecordDecl *D);
451 void VisitStaticAssertDecl(const StaticAssertDecl *D);
Richard Smithcbdf7332014-03-18 02:07:28 +0000452 template<typename SpecializationDecl>
Richard Smithf7514452014-10-30 21:02:37 +0000453 void VisitTemplateDeclSpecialization(const SpecializationDecl *D,
Richard Smithcbdf7332014-03-18 02:07:28 +0000454 bool DumpExplicitInst,
455 bool DumpRefOnly);
Richard Smith20ade552014-03-17 23:34:53 +0000456 template<typename TemplateDecl>
457 void VisitTemplateDecl(const TemplateDecl *D, bool DumpExplicitInst);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000458 void VisitFunctionTemplateDecl(const FunctionTemplateDecl *D);
459 void VisitClassTemplateDecl(const ClassTemplateDecl *D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000460 void VisitClassTemplateSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000461 const ClassTemplateSpecializationDecl *D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000462 void VisitClassTemplatePartialSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000463 const ClassTemplatePartialSpecializationDecl *D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000464 void VisitClassScopeFunctionSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000465 const ClassScopeFunctionSpecializationDecl *D);
David Majnemerd9b1a4f2015-11-04 03:40:30 +0000466 void VisitBuiltinTemplateDecl(const BuiltinTemplateDecl *D);
Richard Smithd25789a2013-09-18 01:36:02 +0000467 void VisitVarTemplateDecl(const VarTemplateDecl *D);
468 void VisitVarTemplateSpecializationDecl(
469 const VarTemplateSpecializationDecl *D);
470 void VisitVarTemplatePartialSpecializationDecl(
471 const VarTemplatePartialSpecializationDecl *D);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000472 void VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D);
473 void VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D);
474 void VisitTemplateTemplateParmDecl(const TemplateTemplateParmDecl *D);
475 void VisitUsingDecl(const UsingDecl *D);
476 void VisitUnresolvedUsingTypenameDecl(const UnresolvedUsingTypenameDecl *D);
477 void VisitUnresolvedUsingValueDecl(const UnresolvedUsingValueDecl *D);
478 void VisitUsingShadowDecl(const UsingShadowDecl *D);
Richard Smith5179eb72016-06-28 19:03:57 +0000479 void VisitConstructorUsingShadowDecl(const ConstructorUsingShadowDecl *D);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000480 void VisitLinkageSpecDecl(const LinkageSpecDecl *D);
481 void VisitAccessSpecDecl(const AccessSpecDecl *D);
482 void VisitFriendDecl(const FriendDecl *D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000483
484 // ObjC Decls
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000485 void VisitObjCIvarDecl(const ObjCIvarDecl *D);
486 void VisitObjCMethodDecl(const ObjCMethodDecl *D);
Douglas Gregor85f3f952015-07-07 03:57:15 +0000487 void VisitObjCTypeParamDecl(const ObjCTypeParamDecl *D);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000488 void VisitObjCCategoryDecl(const ObjCCategoryDecl *D);
489 void VisitObjCCategoryImplDecl(const ObjCCategoryImplDecl *D);
490 void VisitObjCProtocolDecl(const ObjCProtocolDecl *D);
491 void VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D);
492 void VisitObjCImplementationDecl(const ObjCImplementationDecl *D);
493 void VisitObjCCompatibleAliasDecl(const ObjCCompatibleAliasDecl *D);
494 void VisitObjCPropertyDecl(const ObjCPropertyDecl *D);
495 void VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D);
496 void VisitBlockDecl(const BlockDecl *D);
Mike Stump11289f42009-09-09 15:08:12 +0000497
Chris Lattner84ca3762007-08-30 01:00:35 +0000498 // Stmts.
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000499 void VisitStmt(const Stmt *Node);
500 void VisitDeclStmt(const DeclStmt *Node);
501 void VisitAttributedStmt(const AttributedStmt *Node);
502 void VisitLabelStmt(const LabelStmt *Node);
503 void VisitGotoStmt(const GotoStmt *Node);
Pavel Labath1ef83422013-09-04 14:35:00 +0000504 void VisitCXXCatchStmt(const CXXCatchStmt *Node);
Alexey Bataev958b9e72016-03-31 09:30:50 +0000505 void VisitCapturedStmt(const CapturedStmt *Node);
506
507 // OpenMP
508 void VisitOMPExecutableDirective(const OMPExecutableDirective *Node);
Mike Stump11289f42009-09-09 15:08:12 +0000509
Chris Lattner84ca3762007-08-30 01:00:35 +0000510 // Exprs
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000511 void VisitExpr(const Expr *Node);
512 void VisitCastExpr(const CastExpr *Node);
513 void VisitDeclRefExpr(const DeclRefExpr *Node);
514 void VisitPredefinedExpr(const PredefinedExpr *Node);
515 void VisitCharacterLiteral(const CharacterLiteral *Node);
516 void VisitIntegerLiteral(const IntegerLiteral *Node);
517 void VisitFloatingLiteral(const FloatingLiteral *Node);
518 void VisitStringLiteral(const StringLiteral *Str);
Richard Smithf0514962014-06-03 08:24:28 +0000519 void VisitInitListExpr(const InitListExpr *ILE);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000520 void VisitUnaryOperator(const UnaryOperator *Node);
521 void VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *Node);
522 void VisitMemberExpr(const MemberExpr *Node);
523 void VisitExtVectorElementExpr(const ExtVectorElementExpr *Node);
524 void VisitBinaryOperator(const BinaryOperator *Node);
525 void VisitCompoundAssignOperator(const CompoundAssignOperator *Node);
526 void VisitAddrLabelExpr(const AddrLabelExpr *Node);
527 void VisitBlockExpr(const BlockExpr *Node);
528 void VisitOpaqueValueExpr(const OpaqueValueExpr *Node);
Chris Lattner84ca3762007-08-30 01:00:35 +0000529
530 // C++
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000531 void VisitCXXNamedCastExpr(const CXXNamedCastExpr *Node);
532 void VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *Node);
533 void VisitCXXThisExpr(const CXXThisExpr *Node);
534 void VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *Node);
535 void VisitCXXConstructExpr(const CXXConstructExpr *Node);
536 void VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *Node);
Reid Kleckner5c682bc2015-03-19 18:09:25 +0000537 void VisitCXXNewExpr(const CXXNewExpr *Node);
538 void VisitCXXDeleteExpr(const CXXDeleteExpr *Node);
Richard Smithe6c01442013-06-05 00:46:14 +0000539 void VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000540 void VisitExprWithCleanups(const ExprWithCleanups *Node);
541 void VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *Node);
542 void dumpCXXTemporary(const CXXTemporary *Temporary);
Faisal Vali2b391ab2013-09-26 19:54:12 +0000543 void VisitLambdaExpr(const LambdaExpr *Node) {
544 VisitExpr(Node);
545 dumpDecl(Node->getLambdaClass());
546 }
Serge Pavlov6b926032015-02-16 19:58:41 +0000547 void VisitSizeOfPackExpr(const SizeOfPackExpr *Node);
Mike Stump11289f42009-09-09 15:08:12 +0000548
Chris Lattner84ca3762007-08-30 01:00:35 +0000549 // ObjC
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000550 void VisitObjCAtCatchStmt(const ObjCAtCatchStmt *Node);
551 void VisitObjCEncodeExpr(const ObjCEncodeExpr *Node);
552 void VisitObjCMessageExpr(const ObjCMessageExpr *Node);
553 void VisitObjCBoxedExpr(const ObjCBoxedExpr *Node);
554 void VisitObjCSelectorExpr(const ObjCSelectorExpr *Node);
555 void VisitObjCProtocolExpr(const ObjCProtocolExpr *Node);
556 void VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *Node);
557 void VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *Node);
558 void VisitObjCIvarRefExpr(const ObjCIvarRefExpr *Node);
559 void VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *Node);
Alexander Kornienkoebc17b52013-01-14 14:07:11 +0000560
561 // Comments.
562 const char *getCommandName(unsigned CommandID);
563 void dumpComment(const Comment *C);
564
565 // Inline comments.
566 void visitTextComment(const TextComment *C);
567 void visitInlineCommandComment(const InlineCommandComment *C);
568 void visitHTMLStartTagComment(const HTMLStartTagComment *C);
569 void visitHTMLEndTagComment(const HTMLEndTagComment *C);
570
571 // Block comments.
572 void visitBlockCommandComment(const BlockCommandComment *C);
573 void visitParamCommandComment(const ParamCommandComment *C);
574 void visitTParamCommandComment(const TParamCommandComment *C);
575 void visitVerbatimBlockComment(const VerbatimBlockComment *C);
576 void visitVerbatimBlockLineComment(const VerbatimBlockLineComment *C);
577 void visitVerbatimLineComment(const VerbatimLineComment *C);
Chris Lattnercbe4f772007-08-08 22:51:59 +0000578 };
Alexander Kornienkoab9db512015-06-22 23:07:51 +0000579}
Chris Lattnercbe4f772007-08-08 22:51:59 +0000580
581//===----------------------------------------------------------------------===//
Chris Lattner11e30d32007-08-30 06:17:34 +0000582// Utilities
583//===----------------------------------------------------------------------===//
584
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000585void ASTDumper::dumpPointer(const void *Ptr) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000586 ColorScope Color(*this, AddressColor);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000587 OS << ' ' << Ptr;
588}
589
Alexander Kornienko18ec81b2012-12-13 13:59:55 +0000590void ASTDumper::dumpLocation(SourceLocation Loc) {
Alex McCarthye14ddef2014-05-02 20:24:11 +0000591 if (!SM)
592 return;
593
Richard Trieud215b8d2013-01-26 01:31:20 +0000594 ColorScope Color(*this, LocationColor);
Chris Lattner53e384f2009-01-16 07:00:02 +0000595 SourceLocation SpellingLoc = SM->getSpellingLoc(Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000596
Chris Lattner11e30d32007-08-30 06:17:34 +0000597 // The general format we print out is filename:line:col, but we drop pieces
598 // that haven't changed since the last loc printed.
Chris Lattnerf1ca7d32009-01-27 07:57:44 +0000599 PresumedLoc PLoc = SM->getPresumedLoc(SpellingLoc);
600
Douglas Gregor453b0122010-11-12 07:15:47 +0000601 if (PLoc.isInvalid()) {
602 OS << "<invalid sloc>";
603 return;
604 }
605
Chris Lattnerf1ca7d32009-01-27 07:57:44 +0000606 if (strcmp(PLoc.getFilename(), LastLocFilename) != 0) {
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000607 OS << PLoc.getFilename() << ':' << PLoc.getLine()
608 << ':' << PLoc.getColumn();
Chris Lattnerf1ca7d32009-01-27 07:57:44 +0000609 LastLocFilename = PLoc.getFilename();
610 LastLocLine = PLoc.getLine();
611 } else if (PLoc.getLine() != LastLocLine) {
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000612 OS << "line" << ':' << PLoc.getLine()
613 << ':' << PLoc.getColumn();
Chris Lattnerf1ca7d32009-01-27 07:57:44 +0000614 LastLocLine = PLoc.getLine();
Chris Lattner11e30d32007-08-30 06:17:34 +0000615 } else {
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000616 OS << "col" << ':' << PLoc.getColumn();
Chris Lattner11e30d32007-08-30 06:17:34 +0000617 }
618}
619
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000620void ASTDumper::dumpSourceRange(SourceRange R) {
Chris Lattner11e30d32007-08-30 06:17:34 +0000621 // Can't translate locations if a SourceManager isn't available.
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000622 if (!SM)
623 return;
Mike Stump11289f42009-09-09 15:08:12 +0000624
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000625 OS << " <";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000626 dumpLocation(R.getBegin());
Chris Lattnera7c19fe2007-10-16 22:36:42 +0000627 if (R.getBegin() != R.getEnd()) {
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000628 OS << ", ";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000629 dumpLocation(R.getEnd());
Chris Lattner11e30d32007-08-30 06:17:34 +0000630 }
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000631 OS << ">";
Mike Stump11289f42009-09-09 15:08:12 +0000632
Chris Lattner11e30d32007-08-30 06:17:34 +0000633 // <t2.c:123:421[blah], t2.c:412:321>
634
635}
636
Richard Smithd5e7ff82014-10-31 01:17:45 +0000637void ASTDumper::dumpBareType(QualType T, bool Desugar) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000638 ColorScope Color(*this, TypeColor);
Richard Smithd5e7ff82014-10-31 01:17:45 +0000639
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000640 SplitQualType T_split = T.split();
641 OS << "'" << QualType::getAsString(T_split) << "'";
642
Richard Smithd5e7ff82014-10-31 01:17:45 +0000643 if (Desugar && !T.isNull()) {
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000644 // If the type is sugared, also dump a (shallow) desugared type.
645 SplitQualType D_split = T.getSplitDesugaredType();
646 if (T_split != D_split)
647 OS << ":'" << QualType::getAsString(D_split) << "'";
648 }
649}
650
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000651void ASTDumper::dumpType(QualType T) {
652 OS << ' ';
653 dumpBareType(T);
654}
655
Richard Smithd5e7ff82014-10-31 01:17:45 +0000656void ASTDumper::dumpTypeAsChild(QualType T) {
657 SplitQualType SQT = T.split();
658 if (!SQT.Quals.hasQualifiers())
659 return dumpTypeAsChild(SQT.Ty);
660
661 dumpChild([=] {
662 OS << "QualType";
663 dumpPointer(T.getAsOpaquePtr());
664 OS << " ";
665 dumpBareType(T, false);
666 OS << " " << T.split().Quals.getAsString();
667 dumpTypeAsChild(T.split().Ty);
668 });
669}
670
671void ASTDumper::dumpTypeAsChild(const Type *T) {
672 dumpChild([=] {
673 if (!T) {
674 ColorScope Color(*this, NullColor);
675 OS << "<<<NULL>>>";
676 return;
677 }
Serge Pavlova6adc9e2015-12-28 17:19:12 +0000678 if (const LocInfoType *LIT = llvm::dyn_cast<LocInfoType>(T)) {
679 {
680 ColorScope Color(*this, TypeColor);
681 OS << "LocInfo Type";
682 }
683 dumpPointer(T);
684 dumpTypeAsChild(LIT->getTypeSourceInfo()->getType());
685 return;
686 }
Richard Smithd5e7ff82014-10-31 01:17:45 +0000687
688 {
689 ColorScope Color(*this, TypeColor);
690 OS << T->getTypeClassName() << "Type";
691 }
692 dumpPointer(T);
693 OS << " ";
694 dumpBareType(QualType(T, 0), false);
695
696 QualType SingleStepDesugar =
697 T->getLocallyUnqualifiedSingleStepDesugaredType();
698 if (SingleStepDesugar != QualType(T, 0))
699 OS << " sugar";
700 if (T->isDependentType())
701 OS << " dependent";
702 else if (T->isInstantiationDependentType())
703 OS << " instantiation_dependent";
704 if (T->isVariablyModifiedType())
705 OS << " variably_modified";
706 if (T->containsUnexpandedParameterPack())
707 OS << " contains_unexpanded_pack";
708 if (T->isFromAST())
709 OS << " imported";
710
711 TypeVisitor<ASTDumper>::Visit(T);
712
713 if (SingleStepDesugar != QualType(T, 0))
714 dumpTypeAsChild(SingleStepDesugar);
715 });
716}
717
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000718void ASTDumper::dumpBareDeclRef(const Decl *D) {
Richard Smith5179eb72016-06-28 19:03:57 +0000719 if (!D) {
720 ColorScope Color(*this, NullColor);
721 OS << "<<<NULL>>>";
722 return;
723 }
724
Richard Trieud215b8d2013-01-26 01:31:20 +0000725 {
726 ColorScope Color(*this, DeclKindNameColor);
727 OS << D->getDeclKindName();
728 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000729 dumpPointer(D);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000730
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000731 if (const NamedDecl *ND = dyn_cast<NamedDecl>(D)) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000732 ColorScope Color(*this, DeclNameColor);
David Blaikied4da8722013-05-14 21:04:00 +0000733 OS << " '" << ND->getDeclName() << '\'';
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000734 }
735
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000736 if (const ValueDecl *VD = dyn_cast<ValueDecl>(D))
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000737 dumpType(VD->getType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000738}
739
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000740void ASTDumper::dumpDeclRef(const Decl *D, const char *Label) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000741 if (!D)
742 return;
743
Richard Smithf7514452014-10-30 21:02:37 +0000744 dumpChild([=]{
745 if (Label)
746 OS << Label << ' ';
747 dumpBareDeclRef(D);
748 });
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000749}
750
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000751void ASTDumper::dumpName(const NamedDecl *ND) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000752 if (ND->getDeclName()) {
753 ColorScope Color(*this, DeclNameColor);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000754 OS << ' ' << ND->getNameAsString();
Richard Trieud215b8d2013-01-26 01:31:20 +0000755 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000756}
757
Richard Trieude5cc7d2013-01-31 01:44:26 +0000758bool ASTDumper::hasNodes(const DeclContext *DC) {
759 if (!DC)
760 return false;
761
Richard Smith1d209d02013-05-23 01:49:11 +0000762 return DC->hasExternalLexicalStorage() ||
763 DC->noload_decls_begin() != DC->noload_decls_end();
Richard Trieude5cc7d2013-01-31 01:44:26 +0000764}
765
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000766void ASTDumper::dumpDeclContext(const DeclContext *DC) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000767 if (!DC)
768 return;
Richard Smithdcc2c452014-03-17 23:00:06 +0000769
Richard Smithdcc2c452014-03-17 23:00:06 +0000770 for (auto *D : DC->noload_decls())
Richard Smithf7514452014-10-30 21:02:37 +0000771 dumpDecl(D);
Richard Smithdcc2c452014-03-17 23:00:06 +0000772
773 if (DC->hasExternalLexicalStorage()) {
Richard Smithf7514452014-10-30 21:02:37 +0000774 dumpChild([=]{
775 ColorScope Color(*this, UndeserializedColor);
776 OS << "<undeserialized declarations>";
777 });
Richard Smith1d209d02013-05-23 01:49:11 +0000778 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000779}
780
Richard Smith35f986d2014-08-11 22:11:07 +0000781void ASTDumper::dumpLookups(const DeclContext *DC, bool DumpDecls) {
Richard Smithf7514452014-10-30 21:02:37 +0000782 dumpChild([=] {
783 OS << "StoredDeclsMap ";
784 dumpBareDeclRef(cast<Decl>(DC));
Richard Smith33937e72013-06-22 21:49:40 +0000785
Richard Smithf7514452014-10-30 21:02:37 +0000786 const DeclContext *Primary = DC->getPrimaryContext();
787 if (Primary != DC) {
788 OS << " primary";
789 dumpPointer(cast<Decl>(Primary));
Richard Smith33937e72013-06-22 21:49:40 +0000790 }
791
Richard Smithf7514452014-10-30 21:02:37 +0000792 bool HasUndeserializedLookups = Primary->hasExternalVisibleStorage();
Richard Smith35f986d2014-08-11 22:11:07 +0000793
Richard Smithf7514452014-10-30 21:02:37 +0000794 DeclContext::all_lookups_iterator I = Primary->noload_lookups_begin(),
795 E = Primary->noload_lookups_end();
796 while (I != E) {
797 DeclarationName Name = I.getLookupName();
798 DeclContextLookupResult R = *I++;
Richard Smith35f986d2014-08-11 22:11:07 +0000799
Richard Smithf7514452014-10-30 21:02:37 +0000800 dumpChild([=] {
801 OS << "DeclarationName ";
802 {
803 ColorScope Color(*this, DeclNameColor);
804 OS << '\'' << Name << '\'';
805 }
Richard Smith35f986d2014-08-11 22:11:07 +0000806
Richard Smithf7514452014-10-30 21:02:37 +0000807 for (DeclContextLookupResult::iterator RI = R.begin(), RE = R.end();
808 RI != RE; ++RI) {
809 dumpChild([=] {
810 dumpBareDeclRef(*RI);
811
812 if ((*RI)->isHidden())
813 OS << " hidden";
814
815 // If requested, dump the redecl chain for this lookup.
816 if (DumpDecls) {
817 // Dump earliest decl first.
818 std::function<void(Decl *)> DumpWithPrev = [&](Decl *D) {
819 if (Decl *Prev = D->getPreviousDecl())
820 DumpWithPrev(Prev);
821 dumpDecl(D);
822 };
823 DumpWithPrev(*RI);
824 }
825 });
826 }
827 });
Richard Smith33937e72013-06-22 21:49:40 +0000828 }
Richard Smith33937e72013-06-22 21:49:40 +0000829
Richard Smithf7514452014-10-30 21:02:37 +0000830 if (HasUndeserializedLookups) {
831 dumpChild([=] {
832 ColorScope Color(*this, UndeserializedColor);
833 OS << "<undeserialized lookups>";
834 });
835 }
836 });
Richard Smith33937e72013-06-22 21:49:40 +0000837}
838
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000839void ASTDumper::dumpAttr(const Attr *A) {
Richard Smithf7514452014-10-30 21:02:37 +0000840 dumpChild([=] {
841 {
842 ColorScope Color(*this, AttrColor);
Aaron Ballman36a53502014-01-16 13:03:14 +0000843
Richard Smithf7514452014-10-30 21:02:37 +0000844 switch (A->getKind()) {
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000845#define ATTR(X) case attr::X: OS << #X; break;
846#include "clang/Basic/AttrList.inc"
Richard Smithf7514452014-10-30 21:02:37 +0000847 }
848 OS << "Attr";
Richard Trieud215b8d2013-01-26 01:31:20 +0000849 }
Richard Smithf7514452014-10-30 21:02:37 +0000850 dumpPointer(A);
851 dumpSourceRange(A->getRange());
852 if (A->isInherited())
853 OS << " Inherited";
854 if (A->isImplicit())
855 OS << " Implicit";
Hans Wennborgb0a8b4a2014-05-31 04:05:57 +0000856#include "clang/AST/AttrDump.inc"
Richard Smithf7514452014-10-30 21:02:37 +0000857 });
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000858}
859
Richard Smith71bec062013-10-15 21:58:30 +0000860static void dumpPreviousDeclImpl(raw_ostream &OS, ...) {}
861
862template<typename T>
863static void dumpPreviousDeclImpl(raw_ostream &OS, const Mergeable<T> *D) {
Rafael Espindola8db352d2013-10-17 15:37:26 +0000864 const T *First = D->getFirstDecl();
Richard Smith71bec062013-10-15 21:58:30 +0000865 if (First != D)
866 OS << " first " << First;
Richard Smithf5f43542013-02-07 01:35:44 +0000867}
868
869template<typename T>
Richard Smith71bec062013-10-15 21:58:30 +0000870static void dumpPreviousDeclImpl(raw_ostream &OS, const Redeclarable<T> *D) {
871 const T *Prev = D->getPreviousDecl();
872 if (Prev)
873 OS << " prev " << Prev;
Richard Smithf5f43542013-02-07 01:35:44 +0000874}
875
Richard Smith71bec062013-10-15 21:58:30 +0000876/// Dump the previous declaration in the redeclaration chain for a declaration,
877/// if any.
878static void dumpPreviousDecl(raw_ostream &OS, const Decl *D) {
Richard Smithf5f43542013-02-07 01:35:44 +0000879 switch (D->getKind()) {
880#define DECL(DERIVED, BASE) \
881 case Decl::DERIVED: \
Richard Smith71bec062013-10-15 21:58:30 +0000882 return dumpPreviousDeclImpl(OS, cast<DERIVED##Decl>(D));
Richard Smithf5f43542013-02-07 01:35:44 +0000883#define ABSTRACT_DECL(DECL)
884#include "clang/AST/DeclNodes.inc"
885 }
886 llvm_unreachable("Decl that isn't part of DeclNodes.inc!");
887}
888
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000889//===----------------------------------------------------------------------===//
890// C++ Utilities
891//===----------------------------------------------------------------------===//
892
893void ASTDumper::dumpAccessSpecifier(AccessSpecifier AS) {
894 switch (AS) {
895 case AS_none:
896 break;
897 case AS_public:
898 OS << "public";
899 break;
900 case AS_protected:
901 OS << "protected";
902 break;
903 case AS_private:
904 OS << "private";
905 break;
906 }
907}
908
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000909void ASTDumper::dumpCXXCtorInitializer(const CXXCtorInitializer *Init) {
Richard Smithf7514452014-10-30 21:02:37 +0000910 dumpChild([=] {
911 OS << "CXXCtorInitializer";
912 if (Init->isAnyMemberInitializer()) {
913 OS << ' ';
914 dumpBareDeclRef(Init->getAnyMember());
915 } else if (Init->isBaseInitializer()) {
916 dumpType(QualType(Init->getBaseClass(), 0));
917 } else if (Init->isDelegatingInitializer()) {
918 dumpType(Init->getTypeSourceInfo()->getType());
919 } else {
920 llvm_unreachable("Unknown initializer type");
921 }
922 dumpStmt(Init->getInit());
923 });
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000924}
925
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000926void ASTDumper::dumpTemplateParameters(const TemplateParameterList *TPL) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000927 if (!TPL)
928 return;
929
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000930 for (TemplateParameterList::const_iterator I = TPL->begin(), E = TPL->end();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000931 I != E; ++I)
932 dumpDecl(*I);
933}
934
935void ASTDumper::dumpTemplateArgumentListInfo(
936 const TemplateArgumentListInfo &TALI) {
Richard Smithf7514452014-10-30 21:02:37 +0000937 for (unsigned i = 0, e = TALI.size(); i < e; ++i)
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000938 dumpTemplateArgumentLoc(TALI[i]);
939}
940
941void ASTDumper::dumpTemplateArgumentLoc(const TemplateArgumentLoc &A) {
942 dumpTemplateArgument(A.getArgument(), A.getSourceRange());
943}
944
945void ASTDumper::dumpTemplateArgumentList(const TemplateArgumentList &TAL) {
946 for (unsigned i = 0, e = TAL.size(); i < e; ++i)
947 dumpTemplateArgument(TAL[i]);
948}
949
950void ASTDumper::dumpTemplateArgument(const TemplateArgument &A, SourceRange R) {
Richard Smithf7514452014-10-30 21:02:37 +0000951 dumpChild([=] {
952 OS << "TemplateArgument";
953 if (R.isValid())
954 dumpSourceRange(R);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000955
Richard Smithf7514452014-10-30 21:02:37 +0000956 switch (A.getKind()) {
957 case TemplateArgument::Null:
958 OS << " null";
959 break;
960 case TemplateArgument::Type:
961 OS << " type";
962 dumpType(A.getAsType());
963 break;
964 case TemplateArgument::Declaration:
965 OS << " decl";
966 dumpDeclRef(A.getAsDecl());
967 break;
968 case TemplateArgument::NullPtr:
969 OS << " nullptr";
970 break;
971 case TemplateArgument::Integral:
972 OS << " integral " << A.getAsIntegral();
973 break;
974 case TemplateArgument::Template:
975 OS << " template ";
976 A.getAsTemplate().dump(OS);
977 break;
978 case TemplateArgument::TemplateExpansion:
979 OS << " template expansion";
980 A.getAsTemplateOrTemplatePattern().dump(OS);
981 break;
982 case TemplateArgument::Expression:
983 OS << " expr";
984 dumpStmt(A.getAsExpr());
985 break;
986 case TemplateArgument::Pack:
987 OS << " pack";
988 for (TemplateArgument::pack_iterator I = A.pack_begin(), E = A.pack_end();
989 I != E; ++I)
990 dumpTemplateArgument(*I);
991 break;
Richard Trieude5cc7d2013-01-31 01:44:26 +0000992 }
Richard Smithf7514452014-10-30 21:02:37 +0000993 });
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000994}
995
Chris Lattner11e30d32007-08-30 06:17:34 +0000996//===----------------------------------------------------------------------===//
Douglas Gregor85f3f952015-07-07 03:57:15 +0000997// Objective-C Utilities
998//===----------------------------------------------------------------------===//
999void ASTDumper::dumpObjCTypeParamList(const ObjCTypeParamList *typeParams) {
1000 if (!typeParams)
1001 return;
1002
1003 for (auto typeParam : *typeParams) {
1004 dumpDecl(typeParam);
1005 }
1006}
1007
1008//===----------------------------------------------------------------------===//
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001009// Decl dumping methods.
Chris Lattnercbe4f772007-08-08 22:51:59 +00001010//===----------------------------------------------------------------------===//
1011
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001012void ASTDumper::dumpDecl(const Decl *D) {
Richard Smithf7514452014-10-30 21:02:37 +00001013 dumpChild([=] {
1014 if (!D) {
1015 ColorScope Color(*this, NullColor);
1016 OS << "<<<NULL>>>";
1017 return;
1018 }
Mike Stump11289f42009-09-09 15:08:12 +00001019
Richard Smithf7514452014-10-30 21:02:37 +00001020 {
1021 ColorScope Color(*this, DeclKindNameColor);
1022 OS << D->getDeclKindName() << "Decl";
1023 }
1024 dumpPointer(D);
1025 if (D->getLexicalDeclContext() != D->getDeclContext())
1026 OS << " parent " << cast<Decl>(D->getDeclContext());
1027 dumpPreviousDecl(OS, D);
1028 dumpSourceRange(D->getSourceRange());
1029 OS << ' ';
1030 dumpLocation(D->getLocation());
Richard Smith42413142015-05-15 20:05:43 +00001031 if (Module *M = D->getImportedOwningModule())
Richard Smithf7514452014-10-30 21:02:37 +00001032 OS << " in " << M->getFullModuleName();
Richard Smith42413142015-05-15 20:05:43 +00001033 else if (Module *M = D->getLocalOwningModule())
1034 OS << " in (local) " << M->getFullModuleName();
Richard Smitha2eb4092015-06-22 18:47:01 +00001035 if (auto *ND = dyn_cast<NamedDecl>(D))
1036 for (Module *M : D->getASTContext().getModulesWithMergedDefinition(
1037 const_cast<NamedDecl *>(ND)))
1038 dumpChild([=] { OS << "also in " << M->getFullModuleName(); });
Richard Smithf7514452014-10-30 21:02:37 +00001039 if (const NamedDecl *ND = dyn_cast<NamedDecl>(D))
1040 if (ND->isHidden())
1041 OS << " hidden";
1042 if (D->isImplicit())
1043 OS << " implicit";
1044 if (D->isUsed())
1045 OS << " used";
1046 else if (D->isThisDeclarationReferenced())
1047 OS << " referenced";
1048 if (D->isInvalidDecl())
1049 OS << " invalid";
Hans Wennborg76b00532014-12-05 22:38:57 +00001050 if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
1051 if (FD->isConstexpr())
1052 OS << " constexpr";
1053
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001054
Richard Smithf7514452014-10-30 21:02:37 +00001055 ConstDeclVisitor<ASTDumper>::Visit(D);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001056
Richard Smithf7514452014-10-30 21:02:37 +00001057 for (Decl::attr_iterator I = D->attr_begin(), E = D->attr_end(); I != E;
1058 ++I)
1059 dumpAttr(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001060
Richard Smithf7514452014-10-30 21:02:37 +00001061 if (const FullComment *Comment =
1062 D->getASTContext().getLocalCommentForDeclUncached(D))
1063 dumpFullComment(Comment);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001064
Richard Smithf7514452014-10-30 21:02:37 +00001065 // Decls within functions are visited by the body.
1066 if (!isa<FunctionDecl>(*D) && !isa<ObjCMethodDecl>(*D) &&
1067 hasNodes(dyn_cast<DeclContext>(D)))
1068 dumpDeclContext(cast<DeclContext>(D));
1069 });
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001070}
1071
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001072void ASTDumper::VisitLabelDecl(const LabelDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001073 dumpName(D);
1074}
1075
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001076void ASTDumper::VisitTypedefDecl(const TypedefDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001077 dumpName(D);
1078 dumpType(D->getUnderlyingType());
1079 if (D->isModulePrivate())
1080 OS << " __module_private__";
Richard Smithba3a4f92016-01-12 21:59:26 +00001081 dumpTypeAsChild(D->getUnderlyingType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001082}
1083
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001084void ASTDumper::VisitEnumDecl(const EnumDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001085 if (D->isScoped()) {
1086 if (D->isScopedUsingClassTag())
1087 OS << " class";
1088 else
1089 OS << " struct";
1090 }
1091 dumpName(D);
1092 if (D->isModulePrivate())
1093 OS << " __module_private__";
1094 if (D->isFixed())
1095 dumpType(D->getIntegerType());
1096}
1097
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001098void ASTDumper::VisitRecordDecl(const RecordDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001099 OS << ' ' << D->getKindName();
1100 dumpName(D);
1101 if (D->isModulePrivate())
1102 OS << " __module_private__";
Richard Smith99bc1b92013-08-30 05:32:29 +00001103 if (D->isCompleteDefinition())
1104 OS << " definition";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001105}
1106
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001107void ASTDumper::VisitEnumConstantDecl(const EnumConstantDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001108 dumpName(D);
1109 dumpType(D->getType());
Richard Smithf7514452014-10-30 21:02:37 +00001110 if (const Expr *Init = D->getInitExpr())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001111 dumpStmt(Init);
1112}
1113
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001114void ASTDumper::VisitIndirectFieldDecl(const IndirectFieldDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001115 dumpName(D);
1116 dumpType(D->getType());
Richard Smithdcc2c452014-03-17 23:00:06 +00001117
Richard Smith8aa49222014-03-18 00:35:12 +00001118 for (auto *Child : D->chain())
Richard Smithf7514452014-10-30 21:02:37 +00001119 dumpDeclRef(Child);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001120}
1121
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001122void ASTDumper::VisitFunctionDecl(const FunctionDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001123 dumpName(D);
1124 dumpType(D->getType());
1125
Rafael Espindola6ae7e502013-04-03 19:27:57 +00001126 StorageClass SC = D->getStorageClass();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001127 if (SC != SC_None)
1128 OS << ' ' << VarDecl::getStorageClassSpecifierString(SC);
1129 if (D->isInlineSpecified())
1130 OS << " inline";
1131 if (D->isVirtualAsWritten())
1132 OS << " virtual";
1133 if (D->isModulePrivate())
1134 OS << " __module_private__";
1135
1136 if (D->isPure())
1137 OS << " pure";
1138 else if (D->isDeletedAsWritten())
1139 OS << " delete";
1140
Richard Smithadaa0152013-05-17 02:09:46 +00001141 if (const FunctionProtoType *FPT = D->getType()->getAs<FunctionProtoType>()) {
1142 FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo();
Richard Smith8acb4282014-07-31 21:57:55 +00001143 switch (EPI.ExceptionSpec.Type) {
Richard Smithadaa0152013-05-17 02:09:46 +00001144 default: break;
1145 case EST_Unevaluated:
Richard Smith8acb4282014-07-31 21:57:55 +00001146 OS << " noexcept-unevaluated " << EPI.ExceptionSpec.SourceDecl;
Richard Smithadaa0152013-05-17 02:09:46 +00001147 break;
1148 case EST_Uninstantiated:
Richard Smith8acb4282014-07-31 21:57:55 +00001149 OS << " noexcept-uninstantiated " << EPI.ExceptionSpec.SourceTemplate;
Richard Smithadaa0152013-05-17 02:09:46 +00001150 break;
1151 }
1152 }
1153
Richard Smithf7514452014-10-30 21:02:37 +00001154 if (const FunctionTemplateSpecializationInfo *FTSI =
1155 D->getTemplateSpecializationInfo())
Richard Trieude5cc7d2013-01-31 01:44:26 +00001156 dumpTemplateArgumentList(*FTSI->TemplateArguments);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001157
Dmitri Gribenkof8579502013-01-12 19:30:44 +00001158 for (ArrayRef<NamedDecl *>::iterator
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001159 I = D->getDeclsInPrototypeScope().begin(),
Richard Smithf7514452014-10-30 21:02:37 +00001160 E = D->getDeclsInPrototypeScope().end(); I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001161 dumpDecl(*I);
1162
Richard Smith8a639892015-01-24 01:07:20 +00001163 if (!D->param_begin() && D->getNumParams())
1164 dumpChild([=] { OS << "<<NULL params x " << D->getNumParams() << ">>"; });
1165 else
David Majnemera3debed2016-06-24 05:33:44 +00001166 for (const ParmVarDecl *Parameter : D->parameters())
1167 dumpDecl(Parameter);
Richard Smithf7514452014-10-30 21:02:37 +00001168
1169 if (const CXXConstructorDecl *C = dyn_cast<CXXConstructorDecl>(D))
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001170 for (CXXConstructorDecl::init_const_iterator I = C->init_begin(),
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001171 E = C->init_end();
Richard Smithf7514452014-10-30 21:02:37 +00001172 I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001173 dumpCXXCtorInitializer(*I);
1174
Richard Smithf7514452014-10-30 21:02:37 +00001175 if (D->doesThisDeclarationHaveABody())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001176 dumpStmt(D->getBody());
1177}
1178
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001179void ASTDumper::VisitFieldDecl(const FieldDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001180 dumpName(D);
1181 dumpType(D->getType());
1182 if (D->isMutable())
1183 OS << " mutable";
1184 if (D->isModulePrivate())
1185 OS << " __module_private__";
Richard Trieude5cc7d2013-01-31 01:44:26 +00001186
Richard Smithf7514452014-10-30 21:02:37 +00001187 if (D->isBitField())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001188 dumpStmt(D->getBitWidth());
Richard Smithf7514452014-10-30 21:02:37 +00001189 if (Expr *Init = D->getInClassInitializer())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001190 dumpStmt(Init);
1191}
1192
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001193void ASTDumper::VisitVarDecl(const VarDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001194 dumpName(D);
1195 dumpType(D->getType());
Rafael Espindola6ae7e502013-04-03 19:27:57 +00001196 StorageClass SC = D->getStorageClass();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001197 if (SC != SC_None)
1198 OS << ' ' << VarDecl::getStorageClassSpecifierString(SC);
Richard Smithfd3834f2013-04-13 02:43:54 +00001199 switch (D->getTLSKind()) {
1200 case VarDecl::TLS_None: break;
1201 case VarDecl::TLS_Static: OS << " tls"; break;
1202 case VarDecl::TLS_Dynamic: OS << " tls_dynamic"; break;
1203 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001204 if (D->isModulePrivate())
1205 OS << " __module_private__";
1206 if (D->isNRVOVariable())
1207 OS << " nrvo";
Richard Smith62f19e72016-06-25 00:15:56 +00001208 if (D->isInline())
1209 OS << " inline";
1210 if (D->isConstexpr())
1211 OS << " constexpr";
Richard Trieude5cc7d2013-01-31 01:44:26 +00001212 if (D->hasInit()) {
Richard Smithd9967cc2014-07-10 22:54:03 +00001213 switch (D->getInitStyle()) {
1214 case VarDecl::CInit: OS << " cinit"; break;
1215 case VarDecl::CallInit: OS << " callinit"; break;
1216 case VarDecl::ListInit: OS << " listinit"; break;
1217 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001218 dumpStmt(D->getInit());
Richard Trieude5cc7d2013-01-31 01:44:26 +00001219 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001220}
1221
Richard Smithbdb84f32016-07-22 23:36:59 +00001222void ASTDumper::VisitDecompositionDecl(const DecompositionDecl *D) {
1223 VisitVarDecl(D);
1224 for (auto *B : D->bindings())
1225 dumpDecl(B);
1226}
1227
Richard Smith7873de02016-08-11 22:25:46 +00001228void ASTDumper::VisitBindingDecl(const BindingDecl *D) {
1229 dumpName(D);
1230 dumpType(D->getType());
1231 if (auto *E = D->getBinding())
1232 dumpStmt(E);
1233}
1234
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001235void ASTDumper::VisitFileScopeAsmDecl(const FileScopeAsmDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001236 dumpStmt(D->getAsmString());
1237}
1238
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001239void ASTDumper::VisitImportDecl(const ImportDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001240 OS << ' ' << D->getImportedModule()->getFullModuleName();
1241}
1242
Nico Weber66220292016-03-02 17:28:48 +00001243void ASTDumper::VisitPragmaCommentDecl(const PragmaCommentDecl *D) {
1244 OS << ' ';
1245 switch (D->getCommentKind()) {
1246 case PCK_Unknown: llvm_unreachable("unexpected pragma comment kind");
1247 case PCK_Compiler: OS << "compiler"; break;
1248 case PCK_ExeStr: OS << "exestr"; break;
1249 case PCK_Lib: OS << "lib"; break;
1250 case PCK_Linker: OS << "linker"; break;
1251 case PCK_User: OS << "user"; break;
1252 }
1253 StringRef Arg = D->getArg();
1254 if (!Arg.empty())
1255 OS << " \"" << Arg << "\"";
1256}
1257
Nico Webercbbaeb12016-03-02 19:28:54 +00001258void ASTDumper::VisitPragmaDetectMismatchDecl(
1259 const PragmaDetectMismatchDecl *D) {
1260 OS << " \"" << D->getName() << "\" \"" << D->getValue() << "\"";
1261}
1262
Alexey Bataev958b9e72016-03-31 09:30:50 +00001263void ASTDumper::VisitCapturedDecl(const CapturedDecl *D) {
1264 dumpStmt(D->getBody());
1265}
1266
1267//===----------------------------------------------------------------------===//
1268// OpenMP Declarations
1269//===----------------------------------------------------------------------===//
1270
1271void ASTDumper::VisitOMPThreadPrivateDecl(const OMPThreadPrivateDecl *D) {
1272 for (auto *E : D->varlists())
1273 dumpStmt(E);
1274}
1275
1276void ASTDumper::VisitOMPDeclareReductionDecl(const OMPDeclareReductionDecl *D) {
1277 dumpName(D);
1278 dumpType(D->getType());
1279 OS << " combiner";
1280 dumpStmt(D->getCombiner());
1281 if (auto *Initializer = D->getInitializer()) {
1282 OS << " initializer";
1283 dumpStmt(Initializer);
1284 }
1285}
1286
1287void ASTDumper::VisitOMPCapturedExprDecl(const OMPCapturedExprDecl *D) {
1288 dumpName(D);
1289 dumpType(D->getType());
1290 dumpStmt(D->getInit());
1291}
Nico Webercbbaeb12016-03-02 19:28:54 +00001292
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001293//===----------------------------------------------------------------------===//
1294// C++ Declarations
1295//===----------------------------------------------------------------------===//
1296
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001297void ASTDumper::VisitNamespaceDecl(const NamespaceDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001298 dumpName(D);
1299 if (D->isInline())
1300 OS << " inline";
1301 if (!D->isOriginalNamespace())
1302 dumpDeclRef(D->getOriginalNamespace(), "original");
1303}
1304
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001305void ASTDumper::VisitUsingDirectiveDecl(const UsingDirectiveDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001306 OS << ' ';
1307 dumpBareDeclRef(D->getNominatedNamespace());
1308}
1309
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001310void ASTDumper::VisitNamespaceAliasDecl(const NamespaceAliasDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001311 dumpName(D);
1312 dumpDeclRef(D->getAliasedNamespace());
1313}
1314
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001315void ASTDumper::VisitTypeAliasDecl(const TypeAliasDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001316 dumpName(D);
1317 dumpType(D->getUnderlyingType());
Richard Smithba3a4f92016-01-12 21:59:26 +00001318 dumpTypeAsChild(D->getUnderlyingType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001319}
1320
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001321void ASTDumper::VisitTypeAliasTemplateDecl(const TypeAliasTemplateDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001322 dumpName(D);
1323 dumpTemplateParameters(D->getTemplateParameters());
1324 dumpDecl(D->getTemplatedDecl());
1325}
1326
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001327void ASTDumper::VisitCXXRecordDecl(const CXXRecordDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001328 VisitRecordDecl(D);
1329 if (!D->isCompleteDefinition())
1330 return;
1331
Aaron Ballman574705e2014-03-13 15:41:46 +00001332 for (const auto &I : D->bases()) {
Richard Smithf7514452014-10-30 21:02:37 +00001333 dumpChild([=] {
1334 if (I.isVirtual())
1335 OS << "virtual ";
1336 dumpAccessSpecifier(I.getAccessSpecifier());
1337 dumpType(I.getType());
1338 if (I.isPackExpansion())
1339 OS << "...";
1340 });
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001341 }
1342}
1343
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001344void ASTDumper::VisitStaticAssertDecl(const StaticAssertDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001345 dumpStmt(D->getAssertExpr());
1346 dumpStmt(D->getMessage());
1347}
1348
Richard Smithcbdf7332014-03-18 02:07:28 +00001349template<typename SpecializationDecl>
Richard Smithf7514452014-10-30 21:02:37 +00001350void ASTDumper::VisitTemplateDeclSpecialization(const SpecializationDecl *D,
Richard Smithcbdf7332014-03-18 02:07:28 +00001351 bool DumpExplicitInst,
1352 bool DumpRefOnly) {
1353 bool DumpedAny = false;
1354 for (auto *RedeclWithBadType : D->redecls()) {
1355 // FIXME: The redecls() range sometimes has elements of a less-specific
1356 // type. (In particular, ClassTemplateSpecializationDecl::redecls() gives
1357 // us TagDecls, and should give CXXRecordDecls).
1358 auto *Redecl = dyn_cast<SpecializationDecl>(RedeclWithBadType);
1359 if (!Redecl) {
1360 // Found the injected-class-name for a class template. This will be dumped
1361 // as part of its surrounding class so we don't need to dump it here.
1362 assert(isa<CXXRecordDecl>(RedeclWithBadType) &&
1363 "expected an injected-class-name");
1364 continue;
1365 }
1366
1367 switch (Redecl->getTemplateSpecializationKind()) {
1368 case TSK_ExplicitInstantiationDeclaration:
1369 case TSK_ExplicitInstantiationDefinition:
1370 if (!DumpExplicitInst)
1371 break;
1372 // Fall through.
1373 case TSK_Undeclared:
1374 case TSK_ImplicitInstantiation:
Richard Smithf7514452014-10-30 21:02:37 +00001375 if (DumpRefOnly)
1376 dumpDeclRef(Redecl);
1377 else
1378 dumpDecl(Redecl);
Richard Smithcbdf7332014-03-18 02:07:28 +00001379 DumpedAny = true;
1380 break;
1381 case TSK_ExplicitSpecialization:
1382 break;
1383 }
1384 }
1385
1386 // Ensure we dump at least one decl for each specialization.
1387 if (!DumpedAny)
Richard Smithf7514452014-10-30 21:02:37 +00001388 dumpDeclRef(D);
Richard Smithcbdf7332014-03-18 02:07:28 +00001389}
1390
Richard Smith20ade552014-03-17 23:34:53 +00001391template<typename TemplateDecl>
1392void ASTDumper::VisitTemplateDecl(const TemplateDecl *D,
1393 bool DumpExplicitInst) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001394 dumpName(D);
1395 dumpTemplateParameters(D->getTemplateParameters());
Richard Smithdcc2c452014-03-17 23:00:06 +00001396
Richard Smithf7514452014-10-30 21:02:37 +00001397 dumpDecl(D->getTemplatedDecl());
Richard Smithdcc2c452014-03-17 23:00:06 +00001398
Richard Smithcbdf7332014-03-18 02:07:28 +00001399 for (auto *Child : D->specializations())
Richard Smithf7514452014-10-30 21:02:37 +00001400 VisitTemplateDeclSpecialization(Child, DumpExplicitInst,
Richard Smithcbdf7332014-03-18 02:07:28 +00001401 !D->isCanonicalDecl());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001402}
1403
Richard Smith20ade552014-03-17 23:34:53 +00001404void ASTDumper::VisitFunctionTemplateDecl(const FunctionTemplateDecl *D) {
1405 // FIXME: We don't add a declaration of a function template specialization
1406 // to its context when it's explicitly instantiated, so dump explicit
1407 // instantiations when we dump the template itself.
1408 VisitTemplateDecl(D, true);
1409}
1410
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001411void ASTDumper::VisitClassTemplateDecl(const ClassTemplateDecl *D) {
Richard Smith20ade552014-03-17 23:34:53 +00001412 VisitTemplateDecl(D, false);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001413}
1414
1415void ASTDumper::VisitClassTemplateSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001416 const ClassTemplateSpecializationDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001417 VisitCXXRecordDecl(D);
1418 dumpTemplateArgumentList(D->getTemplateArgs());
1419}
1420
1421void ASTDumper::VisitClassTemplatePartialSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001422 const ClassTemplatePartialSpecializationDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001423 VisitClassTemplateSpecializationDecl(D);
1424 dumpTemplateParameters(D->getTemplateParameters());
1425}
1426
1427void ASTDumper::VisitClassScopeFunctionSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001428 const ClassScopeFunctionSpecializationDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001429 dumpDeclRef(D->getSpecialization());
1430 if (D->hasExplicitTemplateArgs())
1431 dumpTemplateArgumentListInfo(D->templateArgs());
1432}
1433
Richard Smithd25789a2013-09-18 01:36:02 +00001434void ASTDumper::VisitVarTemplateDecl(const VarTemplateDecl *D) {
Richard Smith20ade552014-03-17 23:34:53 +00001435 VisitTemplateDecl(D, false);
Richard Smithd25789a2013-09-18 01:36:02 +00001436}
1437
David Majnemerd9b1a4f2015-11-04 03:40:30 +00001438void ASTDumper::VisitBuiltinTemplateDecl(const BuiltinTemplateDecl *D) {
1439 dumpName(D);
1440 dumpTemplateParameters(D->getTemplateParameters());
1441}
1442
Richard Smithd25789a2013-09-18 01:36:02 +00001443void ASTDumper::VisitVarTemplateSpecializationDecl(
1444 const VarTemplateSpecializationDecl *D) {
1445 dumpTemplateArgumentList(D->getTemplateArgs());
1446 VisitVarDecl(D);
1447}
1448
1449void ASTDumper::VisitVarTemplatePartialSpecializationDecl(
1450 const VarTemplatePartialSpecializationDecl *D) {
1451 dumpTemplateParameters(D->getTemplateParameters());
1452 VisitVarTemplateSpecializationDecl(D);
1453}
1454
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001455void ASTDumper::VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001456 if (D->wasDeclaredWithTypename())
1457 OS << " typename";
1458 else
1459 OS << " class";
1460 if (D->isParameterPack())
1461 OS << " ...";
1462 dumpName(D);
Richard Smithf7514452014-10-30 21:02:37 +00001463 if (D->hasDefaultArgument())
Richard Smithecf74ff2014-03-23 20:50:39 +00001464 dumpTemplateArgument(D->getDefaultArgument());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001465}
1466
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001467void ASTDumper::VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001468 dumpType(D->getType());
1469 if (D->isParameterPack())
1470 OS << " ...";
1471 dumpName(D);
Richard Smithf7514452014-10-30 21:02:37 +00001472 if (D->hasDefaultArgument())
Richard Smithecf74ff2014-03-23 20:50:39 +00001473 dumpTemplateArgument(D->getDefaultArgument());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001474}
1475
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001476void ASTDumper::VisitTemplateTemplateParmDecl(
1477 const TemplateTemplateParmDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001478 if (D->isParameterPack())
1479 OS << " ...";
1480 dumpName(D);
1481 dumpTemplateParameters(D->getTemplateParameters());
Richard Smithf7514452014-10-30 21:02:37 +00001482 if (D->hasDefaultArgument())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001483 dumpTemplateArgumentLoc(D->getDefaultArgument());
1484}
1485
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001486void ASTDumper::VisitUsingDecl(const UsingDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001487 OS << ' ';
Dawn Perchikddd03bf2015-12-05 22:37:55 +00001488 if (D->getQualifier())
1489 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001490 OS << D->getNameAsString();
1491}
1492
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001493void ASTDumper::VisitUnresolvedUsingTypenameDecl(
1494 const UnresolvedUsingTypenameDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001495 OS << ' ';
Dawn Perchikddd03bf2015-12-05 22:37:55 +00001496 if (D->getQualifier())
1497 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001498 OS << D->getNameAsString();
1499}
1500
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001501void ASTDumper::VisitUnresolvedUsingValueDecl(const UnresolvedUsingValueDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001502 OS << ' ';
Dawn Perchikddd03bf2015-12-05 22:37:55 +00001503 if (D->getQualifier())
1504 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001505 OS << D->getNameAsString();
1506 dumpType(D->getType());
1507}
1508
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001509void ASTDumper::VisitUsingShadowDecl(const UsingShadowDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001510 OS << ' ';
1511 dumpBareDeclRef(D->getTargetDecl());
Richard Smithba3a4f92016-01-12 21:59:26 +00001512 if (auto *TD = dyn_cast<TypeDecl>(D->getUnderlyingDecl()))
1513 dumpTypeAsChild(TD->getTypeForDecl());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001514}
1515
Richard Smith5179eb72016-06-28 19:03:57 +00001516void ASTDumper::VisitConstructorUsingShadowDecl(
1517 const ConstructorUsingShadowDecl *D) {
1518 if (D->constructsVirtualBase())
1519 OS << " virtual";
1520
1521 dumpChild([=] {
1522 OS << "target ";
1523 dumpBareDeclRef(D->getTargetDecl());
1524 });
1525
1526 dumpChild([=] {
1527 OS << "nominated ";
1528 dumpBareDeclRef(D->getNominatedBaseClass());
1529 OS << ' ';
1530 dumpBareDeclRef(D->getNominatedBaseClassShadowDecl());
1531 });
1532
1533 dumpChild([=] {
1534 OS << "constructed ";
1535 dumpBareDeclRef(D->getConstructedBaseClass());
1536 OS << ' ';
1537 dumpBareDeclRef(D->getConstructedBaseClassShadowDecl());
1538 });
1539}
1540
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001541void ASTDumper::VisitLinkageSpecDecl(const LinkageSpecDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001542 switch (D->getLanguage()) {
1543 case LinkageSpecDecl::lang_c: OS << " C"; break;
1544 case LinkageSpecDecl::lang_cxx: OS << " C++"; break;
1545 }
1546}
1547
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001548void ASTDumper::VisitAccessSpecDecl(const AccessSpecDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001549 OS << ' ';
1550 dumpAccessSpecifier(D->getAccess());
1551}
1552
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001553void ASTDumper::VisitFriendDecl(const FriendDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001554 if (TypeSourceInfo *T = D->getFriendType())
1555 dumpType(T->getType());
1556 else
1557 dumpDecl(D->getFriendDecl());
1558}
1559
1560//===----------------------------------------------------------------------===//
1561// Obj-C Declarations
1562//===----------------------------------------------------------------------===//
1563
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001564void ASTDumper::VisitObjCIvarDecl(const ObjCIvarDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001565 dumpName(D);
1566 dumpType(D->getType());
1567 if (D->getSynthesize())
1568 OS << " synthesize";
1569
1570 switch (D->getAccessControl()) {
1571 case ObjCIvarDecl::None:
1572 OS << " none";
1573 break;
1574 case ObjCIvarDecl::Private:
1575 OS << " private";
1576 break;
1577 case ObjCIvarDecl::Protected:
1578 OS << " protected";
1579 break;
1580 case ObjCIvarDecl::Public:
1581 OS << " public";
1582 break;
1583 case ObjCIvarDecl::Package:
1584 OS << " package";
1585 break;
1586 }
1587}
1588
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001589void ASTDumper::VisitObjCMethodDecl(const ObjCMethodDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001590 if (D->isInstanceMethod())
1591 OS << " -";
1592 else
1593 OS << " +";
1594 dumpName(D);
Alp Toker314cc812014-01-25 16:55:45 +00001595 dumpType(D->getReturnType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001596
Richard Trieude5cc7d2013-01-31 01:44:26 +00001597 if (D->isThisDeclarationADefinition()) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001598 dumpDeclContext(D);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001599 } else {
David Majnemera3debed2016-06-24 05:33:44 +00001600 for (const ParmVarDecl *Parameter : D->parameters())
1601 dumpDecl(Parameter);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001602 }
1603
Richard Smithf7514452014-10-30 21:02:37 +00001604 if (D->isVariadic())
1605 dumpChild([=] { OS << "..."; });
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001606
Richard Smithf7514452014-10-30 21:02:37 +00001607 if (D->hasBody())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001608 dumpStmt(D->getBody());
1609}
1610
Douglas Gregor85f3f952015-07-07 03:57:15 +00001611void ASTDumper::VisitObjCTypeParamDecl(const ObjCTypeParamDecl *D) {
1612 dumpName(D);
Douglas Gregor1ac1b632015-07-07 03:58:54 +00001613 switch (D->getVariance()) {
1614 case ObjCTypeParamVariance::Invariant:
1615 break;
1616
1617 case ObjCTypeParamVariance::Covariant:
1618 OS << " covariant";
1619 break;
1620
1621 case ObjCTypeParamVariance::Contravariant:
1622 OS << " contravariant";
1623 break;
1624 }
1625
Douglas Gregor85f3f952015-07-07 03:57:15 +00001626 if (D->hasExplicitBound())
1627 OS << " bounded";
1628 dumpType(D->getUnderlyingType());
1629}
1630
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001631void ASTDumper::VisitObjCCategoryDecl(const ObjCCategoryDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001632 dumpName(D);
1633 dumpDeclRef(D->getClassInterface());
Douglas Gregor85f3f952015-07-07 03:57:15 +00001634 dumpObjCTypeParamList(D->getTypeParamList());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001635 dumpDeclRef(D->getImplementation());
1636 for (ObjCCategoryDecl::protocol_iterator I = D->protocol_begin(),
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001637 E = D->protocol_end();
Richard Smithf7514452014-10-30 21:02:37 +00001638 I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001639 dumpDeclRef(*I);
1640}
1641
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001642void ASTDumper::VisitObjCCategoryImplDecl(const ObjCCategoryImplDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001643 dumpName(D);
1644 dumpDeclRef(D->getClassInterface());
1645 dumpDeclRef(D->getCategoryDecl());
1646}
1647
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001648void ASTDumper::VisitObjCProtocolDecl(const ObjCProtocolDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001649 dumpName(D);
Richard Smithdcc2c452014-03-17 23:00:06 +00001650
Richard Smith7fcb35f2014-03-18 02:37:59 +00001651 for (auto *Child : D->protocols())
Richard Smithf7514452014-10-30 21:02:37 +00001652 dumpDeclRef(Child);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001653}
1654
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001655void ASTDumper::VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001656 dumpName(D);
Douglas Gregor85f3f952015-07-07 03:57:15 +00001657 dumpObjCTypeParamList(D->getTypeParamListAsWritten());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001658 dumpDeclRef(D->getSuperClass(), "super");
Richard Smithdcc2c452014-03-17 23:00:06 +00001659
Richard Smithf7514452014-10-30 21:02:37 +00001660 dumpDeclRef(D->getImplementation());
Richard Smith7fcb35f2014-03-18 02:37:59 +00001661 for (auto *Child : D->protocols())
Richard Smithf7514452014-10-30 21:02:37 +00001662 dumpDeclRef(Child);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001663}
1664
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001665void ASTDumper::VisitObjCImplementationDecl(const ObjCImplementationDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001666 dumpName(D);
1667 dumpDeclRef(D->getSuperClass(), "super");
1668 dumpDeclRef(D->getClassInterface());
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001669 for (ObjCImplementationDecl::init_const_iterator I = D->init_begin(),
1670 E = D->init_end();
Richard Smithf7514452014-10-30 21:02:37 +00001671 I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001672 dumpCXXCtorInitializer(*I);
1673}
1674
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001675void ASTDumper::VisitObjCCompatibleAliasDecl(const ObjCCompatibleAliasDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001676 dumpName(D);
1677 dumpDeclRef(D->getClassInterface());
1678}
1679
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001680void ASTDumper::VisitObjCPropertyDecl(const ObjCPropertyDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001681 dumpName(D);
1682 dumpType(D->getType());
1683
1684 if (D->getPropertyImplementation() == ObjCPropertyDecl::Required)
1685 OS << " required";
1686 else if (D->getPropertyImplementation() == ObjCPropertyDecl::Optional)
1687 OS << " optional";
1688
1689 ObjCPropertyDecl::PropertyAttributeKind Attrs = D->getPropertyAttributes();
1690 if (Attrs != ObjCPropertyDecl::OBJC_PR_noattr) {
1691 if (Attrs & ObjCPropertyDecl::OBJC_PR_readonly)
1692 OS << " readonly";
1693 if (Attrs & ObjCPropertyDecl::OBJC_PR_assign)
1694 OS << " assign";
1695 if (Attrs & ObjCPropertyDecl::OBJC_PR_readwrite)
1696 OS << " readwrite";
1697 if (Attrs & ObjCPropertyDecl::OBJC_PR_retain)
1698 OS << " retain";
1699 if (Attrs & ObjCPropertyDecl::OBJC_PR_copy)
1700 OS << " copy";
1701 if (Attrs & ObjCPropertyDecl::OBJC_PR_nonatomic)
1702 OS << " nonatomic";
1703 if (Attrs & ObjCPropertyDecl::OBJC_PR_atomic)
1704 OS << " atomic";
1705 if (Attrs & ObjCPropertyDecl::OBJC_PR_weak)
1706 OS << " weak";
1707 if (Attrs & ObjCPropertyDecl::OBJC_PR_strong)
1708 OS << " strong";
1709 if (Attrs & ObjCPropertyDecl::OBJC_PR_unsafe_unretained)
1710 OS << " unsafe_unretained";
Manman Ren387ff7f2016-01-26 18:52:43 +00001711 if (Attrs & ObjCPropertyDecl::OBJC_PR_class)
1712 OS << " class";
Richard Smithf7514452014-10-30 21:02:37 +00001713 if (Attrs & ObjCPropertyDecl::OBJC_PR_getter)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001714 dumpDeclRef(D->getGetterMethodDecl(), "getter");
Richard Smithf7514452014-10-30 21:02:37 +00001715 if (Attrs & ObjCPropertyDecl::OBJC_PR_setter)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001716 dumpDeclRef(D->getSetterMethodDecl(), "setter");
1717 }
1718}
1719
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001720void ASTDumper::VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001721 dumpName(D->getPropertyDecl());
1722 if (D->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize)
1723 OS << " synthesize";
1724 else
1725 OS << " dynamic";
1726 dumpDeclRef(D->getPropertyDecl());
1727 dumpDeclRef(D->getPropertyIvarDecl());
1728}
1729
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001730void ASTDumper::VisitBlockDecl(const BlockDecl *D) {
David Majnemer59f77922016-06-24 04:05:48 +00001731 for (auto I : D->parameters())
Aaron Ballmanb2b8b1d2014-03-07 16:09:59 +00001732 dumpDecl(I);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001733
Richard Smithf7514452014-10-30 21:02:37 +00001734 if (D->isVariadic())
1735 dumpChild([=]{ OS << "..."; });
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001736
Richard Smithf7514452014-10-30 21:02:37 +00001737 if (D->capturesCXXThis())
1738 dumpChild([=]{ OS << "capture this"; });
1739
Aaron Ballman9371dd22014-03-14 18:34:04 +00001740 for (const auto &I : D->captures()) {
Richard Smithf7514452014-10-30 21:02:37 +00001741 dumpChild([=] {
1742 OS << "capture";
1743 if (I.isByRef())
1744 OS << " byref";
1745 if (I.isNested())
1746 OS << " nested";
1747 if (I.getVariable()) {
1748 OS << ' ';
1749 dumpBareDeclRef(I.getVariable());
1750 }
1751 if (I.hasCopyExpr())
1752 dumpStmt(I.getCopyExpr());
1753 });
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001754 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001755 dumpStmt(D->getBody());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001756}
1757
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001758//===----------------------------------------------------------------------===//
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001759// Stmt dumping methods.
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001760//===----------------------------------------------------------------------===//
1761
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001762void ASTDumper::dumpStmt(const Stmt *S) {
Richard Smithf7514452014-10-30 21:02:37 +00001763 dumpChild([=] {
1764 if (!S) {
1765 ColorScope Color(*this, NullColor);
1766 OS << "<<<NULL>>>";
1767 return;
1768 }
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001769
Richard Smithf7514452014-10-30 21:02:37 +00001770 if (const DeclStmt *DS = dyn_cast<DeclStmt>(S)) {
1771 VisitDeclStmt(DS);
1772 return;
1773 }
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001774
Richard Smithf7514452014-10-30 21:02:37 +00001775 ConstStmtVisitor<ASTDumper>::Visit(S);
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001776
Benjamin Kramer642f1732015-07-02 21:03:14 +00001777 for (const Stmt *SubStmt : S->children())
1778 dumpStmt(SubStmt);
Richard Smithf7514452014-10-30 21:02:37 +00001779 });
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001780}
1781
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001782void ASTDumper::VisitStmt(const Stmt *Node) {
Richard Trieud215b8d2013-01-26 01:31:20 +00001783 {
1784 ColorScope Color(*this, StmtColor);
1785 OS << Node->getStmtClassName();
1786 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001787 dumpPointer(Node);
1788 dumpSourceRange(Node->getSourceRange());
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001789}
1790
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001791void ASTDumper::VisitDeclStmt(const DeclStmt *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001792 VisitStmt(Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001793 for (DeclStmt::const_decl_iterator I = Node->decl_begin(),
1794 E = Node->decl_end();
Richard Smithf7514452014-10-30 21:02:37 +00001795 I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001796 dumpDecl(*I);
Ted Kremenek433a4922007-12-12 06:59:42 +00001797}
1798
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001799void ASTDumper::VisitAttributedStmt(const AttributedStmt *Node) {
Alexander Kornienko5bc364e2013-01-07 17:53:08 +00001800 VisitStmt(Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001801 for (ArrayRef<const Attr *>::iterator I = Node->getAttrs().begin(),
1802 E = Node->getAttrs().end();
Richard Smithf7514452014-10-30 21:02:37 +00001803 I != E; ++I)
Alexander Kornienko5bc364e2013-01-07 17:53:08 +00001804 dumpAttr(*I);
1805}
1806
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001807void ASTDumper::VisitLabelStmt(const LabelStmt *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001808 VisitStmt(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001809 OS << " '" << Node->getName() << "'";
Chris Lattnercbe4f772007-08-08 22:51:59 +00001810}
1811
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001812void ASTDumper::VisitGotoStmt(const GotoStmt *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001813 VisitStmt(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001814 OS << " '" << Node->getLabel()->getName() << "'";
1815 dumpPointer(Node->getLabel());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001816}
1817
Pavel Labath1ef83422013-09-04 14:35:00 +00001818void ASTDumper::VisitCXXCatchStmt(const CXXCatchStmt *Node) {
1819 VisitStmt(Node);
1820 dumpDecl(Node->getExceptionDecl());
1821}
1822
Alexey Bataev958b9e72016-03-31 09:30:50 +00001823void ASTDumper::VisitCapturedStmt(const CapturedStmt *Node) {
1824 VisitStmt(Node);
1825 dumpDecl(Node->getCapturedDecl());
1826}
1827
1828//===----------------------------------------------------------------------===//
1829// OpenMP dumping methods.
1830//===----------------------------------------------------------------------===//
1831
1832void ASTDumper::VisitOMPExecutableDirective(
1833 const OMPExecutableDirective *Node) {
1834 VisitStmt(Node);
1835 for (auto *C : Node->clauses()) {
1836 dumpChild([=] {
1837 if (!C) {
1838 ColorScope Color(*this, NullColor);
1839 OS << "<<<NULL>>> OMPClause";
1840 return;
1841 }
1842 {
1843 ColorScope Color(*this, AttrColor);
1844 StringRef ClauseName(getOpenMPClauseName(C->getClauseKind()));
1845 OS << "OMP" << ClauseName.substr(/*Start=*/0, /*N=*/1).upper()
1846 << ClauseName.drop_front() << "Clause";
1847 }
1848 dumpPointer(C);
1849 dumpSourceRange(SourceRange(C->getLocStart(), C->getLocEnd()));
1850 if (C->isImplicit())
1851 OS << " <implicit>";
1852 for (auto *S : C->children())
1853 dumpStmt(S);
1854 });
1855 }
1856}
1857
Chris Lattnercbe4f772007-08-08 22:51:59 +00001858//===----------------------------------------------------------------------===//
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001859// Expr dumping methods.
Chris Lattnercbe4f772007-08-08 22:51:59 +00001860//===----------------------------------------------------------------------===//
1861
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001862void ASTDumper::VisitExpr(const Expr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001863 VisitStmt(Node);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001864 dumpType(Node->getType());
1865
Richard Trieud215b8d2013-01-26 01:31:20 +00001866 {
1867 ColorScope Color(*this, ValueKindColor);
1868 switch (Node->getValueKind()) {
1869 case VK_RValue:
1870 break;
1871 case VK_LValue:
1872 OS << " lvalue";
1873 break;
1874 case VK_XValue:
1875 OS << " xvalue";
1876 break;
1877 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001878 }
1879
Richard Trieud215b8d2013-01-26 01:31:20 +00001880 {
1881 ColorScope Color(*this, ObjectKindColor);
1882 switch (Node->getObjectKind()) {
1883 case OK_Ordinary:
1884 break;
1885 case OK_BitField:
1886 OS << " bitfield";
1887 break;
1888 case OK_ObjCProperty:
1889 OS << " objcproperty";
1890 break;
1891 case OK_ObjCSubscript:
1892 OS << " objcsubscript";
1893 break;
1894 case OK_VectorComponent:
1895 OS << " vectorcomponent";
1896 break;
1897 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001898 }
Chris Lattnercbe4f772007-08-08 22:51:59 +00001899}
1900
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001901static void dumpBasePath(raw_ostream &OS, const CastExpr *Node) {
John McCallcf142162010-08-07 06:22:56 +00001902 if (Node->path_empty())
Anders Carlssona70cff62010-04-24 19:06:50 +00001903 return;
1904
1905 OS << " (";
1906 bool First = true;
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001907 for (CastExpr::path_const_iterator I = Node->path_begin(),
1908 E = Node->path_end();
1909 I != E; ++I) {
Anders Carlssona70cff62010-04-24 19:06:50 +00001910 const CXXBaseSpecifier *Base = *I;
1911 if (!First)
1912 OS << " -> ";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001913
Anders Carlssona70cff62010-04-24 19:06:50 +00001914 const CXXRecordDecl *RD =
1915 cast<CXXRecordDecl>(Base->getType()->getAs<RecordType>()->getDecl());
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001916
Anders Carlssona70cff62010-04-24 19:06:50 +00001917 if (Base->isVirtual())
1918 OS << "virtual ";
1919 OS << RD->getName();
1920 First = false;
1921 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001922
Anders Carlssona70cff62010-04-24 19:06:50 +00001923 OS << ')';
1924}
1925
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001926void ASTDumper::VisitCastExpr(const CastExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001927 VisitExpr(Node);
Richard Trieud215b8d2013-01-26 01:31:20 +00001928 OS << " <";
1929 {
1930 ColorScope Color(*this, CastColor);
1931 OS << Node->getCastKindName();
1932 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001933 dumpBasePath(OS, Node);
Anders Carlssona70cff62010-04-24 19:06:50 +00001934 OS << ">";
Anders Carlssond7923c62009-08-22 23:33:40 +00001935}
1936
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001937void ASTDumper::VisitDeclRefExpr(const DeclRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001938 VisitExpr(Node);
Ted Kremenek5f64ca82007-09-10 17:32:55 +00001939
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001940 OS << " ";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001941 dumpBareDeclRef(Node->getDecl());
Chandler Carruth8d26bb02011-05-01 23:48:14 +00001942 if (Node->getDecl() != Node->getFoundDecl()) {
1943 OS << " (";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001944 dumpBareDeclRef(Node->getFoundDecl());
Chandler Carruth8d26bb02011-05-01 23:48:14 +00001945 OS << ")";
1946 }
John McCall351762c2011-02-07 10:33:21 +00001947}
1948
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001949void ASTDumper::VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001950 VisitExpr(Node);
John McCall76d09942009-12-11 21:50:11 +00001951 OS << " (";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001952 if (!Node->requiresADL())
1953 OS << "no ";
Benjamin Kramerb11416d2010-04-17 09:33:03 +00001954 OS << "ADL) = '" << Node->getName() << '\'';
John McCall76d09942009-12-11 21:50:11 +00001955
1956 UnresolvedLookupExpr::decls_iterator
1957 I = Node->decls_begin(), E = Node->decls_end();
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001958 if (I == E)
1959 OS << " empty";
John McCall76d09942009-12-11 21:50:11 +00001960 for (; I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001961 dumpPointer(*I);
John McCall76d09942009-12-11 21:50:11 +00001962}
1963
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001964void ASTDumper::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001965 VisitExpr(Node);
Steve Naroff5d5efca2008-03-12 13:19:12 +00001966
Richard Trieud215b8d2013-01-26 01:31:20 +00001967 {
1968 ColorScope Color(*this, DeclKindNameColor);
1969 OS << " " << Node->getDecl()->getDeclKindName() << "Decl";
1970 }
1971 OS << "='" << *Node->getDecl() << "'";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001972 dumpPointer(Node->getDecl());
Steve Naroffb3424a92008-05-23 22:01:24 +00001973 if (Node->isFreeIvar())
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001974 OS << " isFreeIvar";
Steve Naroff5d5efca2008-03-12 13:19:12 +00001975}
1976
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001977void ASTDumper::VisitPredefinedExpr(const PredefinedExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001978 VisitExpr(Node);
Alexey Bataevec474782014-10-09 08:45:04 +00001979 OS << " " << PredefinedExpr::getIdentTypeName(Node->getIdentType());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001980}
1981
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001982void ASTDumper::VisitCharacterLiteral(const CharacterLiteral *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001983 VisitExpr(Node);
Richard Trieud215b8d2013-01-26 01:31:20 +00001984 ColorScope Color(*this, ValueColor);
Richard Trieu364ee422011-11-03 23:56:23 +00001985 OS << " " << Node->getValue();
Chris Lattnercbe4f772007-08-08 22:51:59 +00001986}
1987
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001988void ASTDumper::VisitIntegerLiteral(const IntegerLiteral *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001989 VisitExpr(Node);
Chris Lattnercbe4f772007-08-08 22:51:59 +00001990
1991 bool isSigned = Node->getType()->isSignedIntegerType();
Richard Trieud215b8d2013-01-26 01:31:20 +00001992 ColorScope Color(*this, ValueColor);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001993 OS << " " << Node->getValue().toString(10, isSigned);
Chris Lattnercbe4f772007-08-08 22:51:59 +00001994}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001995
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001996void ASTDumper::VisitFloatingLiteral(const FloatingLiteral *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001997 VisitExpr(Node);
Richard Trieud215b8d2013-01-26 01:31:20 +00001998 ColorScope Color(*this, ValueColor);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001999 OS << " " << Node->getValueAsApproximateDouble();
Chris Lattnercbe4f772007-08-08 22:51:59 +00002000}
Chris Lattner1c20a172007-08-26 03:42:43 +00002001
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002002void ASTDumper::VisitStringLiteral(const StringLiteral *Str) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002003 VisitExpr(Str);
Richard Trieud215b8d2013-01-26 01:31:20 +00002004 ColorScope Color(*this, ValueColor);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002005 OS << " ";
Richard Trieudc355912012-06-13 20:25:24 +00002006 Str->outputString(OS);
Chris Lattnercbe4f772007-08-08 22:51:59 +00002007}
Chris Lattner84ca3762007-08-30 01:00:35 +00002008
Richard Smithf0514962014-06-03 08:24:28 +00002009void ASTDumper::VisitInitListExpr(const InitListExpr *ILE) {
2010 VisitExpr(ILE);
2011 if (auto *Filler = ILE->getArrayFiller()) {
Richard Smithf7514452014-10-30 21:02:37 +00002012 dumpChild([=] {
2013 OS << "array filler";
2014 dumpStmt(Filler);
2015 });
Richard Smithf0514962014-06-03 08:24:28 +00002016 }
2017 if (auto *Field = ILE->getInitializedFieldInUnion()) {
2018 OS << " field ";
2019 dumpBareDeclRef(Field);
2020 }
2021}
2022
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002023void ASTDumper::VisitUnaryOperator(const UnaryOperator *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002024 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002025 OS << " " << (Node->isPostfix() ? "postfix" : "prefix")
2026 << " '" << UnaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
Chris Lattnercbe4f772007-08-08 22:51:59 +00002027}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002028
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002029void ASTDumper::VisitUnaryExprOrTypeTraitExpr(
2030 const UnaryExprOrTypeTraitExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002031 VisitExpr(Node);
Peter Collingbournee190dee2011-03-11 19:24:49 +00002032 switch(Node->getKind()) {
2033 case UETT_SizeOf:
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002034 OS << " sizeof";
Peter Collingbournee190dee2011-03-11 19:24:49 +00002035 break;
2036 case UETT_AlignOf:
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002037 OS << " alignof";
Peter Collingbournee190dee2011-03-11 19:24:49 +00002038 break;
2039 case UETT_VecStep:
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002040 OS << " vec_step";
Peter Collingbournee190dee2011-03-11 19:24:49 +00002041 break;
Alexey Bataev00396512015-07-02 03:40:19 +00002042 case UETT_OpenMPRequiredSimdAlign:
2043 OS << " __builtin_omp_required_simd_align";
2044 break;
Peter Collingbournee190dee2011-03-11 19:24:49 +00002045 }
Sebastian Redl6f282892008-11-11 17:56:53 +00002046 if (Node->isArgumentType())
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002047 dumpType(Node->getArgumentType());
Chris Lattnercbe4f772007-08-08 22:51:59 +00002048}
Chris Lattnerdb3b3ff2007-08-09 17:35:30 +00002049
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002050void ASTDumper::VisitMemberExpr(const MemberExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002051 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002052 OS << " " << (Node->isArrow() ? "->" : ".") << *Node->getMemberDecl();
2053 dumpPointer(Node->getMemberDecl());
Chris Lattnercbe4f772007-08-08 22:51:59 +00002054}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002055
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002056void ASTDumper::VisitExtVectorElementExpr(const ExtVectorElementExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002057 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002058 OS << " " << Node->getAccessor().getNameStart();
Chris Lattnercbe4f772007-08-08 22:51:59 +00002059}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002060
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002061void ASTDumper::VisitBinaryOperator(const BinaryOperator *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002062 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002063 OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
Chris Lattner86928112007-08-25 02:00:02 +00002064}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002065
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002066void ASTDumper::VisitCompoundAssignOperator(
2067 const CompoundAssignOperator *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002068 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002069 OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode())
2070 << "' ComputeLHSTy=";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002071 dumpBareType(Node->getComputationLHSType());
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002072 OS << " ComputeResultTy=";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002073 dumpBareType(Node->getComputationResultType());
Chris Lattnercbe4f772007-08-08 22:51:59 +00002074}
Chris Lattnercbe4f772007-08-08 22:51:59 +00002075
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002076void ASTDumper::VisitBlockExpr(const BlockExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002077 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002078 dumpDecl(Node->getBlockDecl());
John McCall351762c2011-02-07 10:33:21 +00002079}
2080
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002081void ASTDumper::VisitOpaqueValueExpr(const OpaqueValueExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002082 VisitExpr(Node);
John McCallfe96e0b2011-11-06 09:01:30 +00002083
Richard Smithf7514452014-10-30 21:02:37 +00002084 if (Expr *Source = Node->getSourceExpr())
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002085 dumpStmt(Source);
John McCallfe96e0b2011-11-06 09:01:30 +00002086}
2087
Chris Lattnercbe4f772007-08-08 22:51:59 +00002088// GNU extensions.
2089
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002090void ASTDumper::VisitAddrLabelExpr(const AddrLabelExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002091 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002092 OS << " " << Node->getLabel()->getName();
2093 dumpPointer(Node->getLabel());
Chris Lattnercbe4f772007-08-08 22:51:59 +00002094}
2095
Chris Lattner8f184b12007-08-09 18:03:18 +00002096//===----------------------------------------------------------------------===//
2097// C++ Expressions
2098//===----------------------------------------------------------------------===//
Chris Lattnercbe4f772007-08-08 22:51:59 +00002099
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002100void ASTDumper::VisitCXXNamedCastExpr(const CXXNamedCastExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002101 VisitExpr(Node);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002102 OS << " " << Node->getCastName()
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002103 << "<" << Node->getTypeAsWritten().getAsString() << ">"
Anders Carlssona70cff62010-04-24 19:06:50 +00002104 << " <" << Node->getCastKindName();
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002105 dumpBasePath(OS, Node);
Anders Carlssona70cff62010-04-24 19:06:50 +00002106 OS << ">";
Chris Lattnercbe4f772007-08-08 22:51:59 +00002107}
2108
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002109void ASTDumper::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002110 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002111 OS << " " << (Node->getValue() ? "true" : "false");
Chris Lattnercbe4f772007-08-08 22:51:59 +00002112}
2113
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002114void ASTDumper::VisitCXXThisExpr(const CXXThisExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002115 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002116 OS << " this";
Douglas Gregor8ea1f532008-11-04 14:56:14 +00002117}
2118
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002119void ASTDumper::VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002120 VisitExpr(Node);
Eli Friedman29538892011-09-02 17:38:59 +00002121 OS << " functional cast to " << Node->getTypeAsWritten().getAsString()
2122 << " <" << Node->getCastKindName() << ">";
Douglas Gregore200adc2008-10-27 19:41:14 +00002123}
2124
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002125void ASTDumper::VisitCXXConstructExpr(const CXXConstructExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002126 VisitExpr(Node);
John McCalleba90cd2010-02-02 19:03:45 +00002127 CXXConstructorDecl *Ctor = Node->getConstructor();
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002128 dumpType(Ctor->getType());
Anders Carlsson073846832009-08-12 00:21:52 +00002129 if (Node->isElidable())
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002130 OS << " elidable";
John McCall85370042010-08-07 06:38:55 +00002131 if (Node->requiresZeroInitialization())
2132 OS << " zeroing";
Anders Carlsson073846832009-08-12 00:21:52 +00002133}
2134
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002135void ASTDumper::VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002136 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002137 OS << " ";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002138 dumpCXXTemporary(Node->getTemporary());
Anders Carlsson073846832009-08-12 00:21:52 +00002139}
2140
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002141void ASTDumper::VisitCXXNewExpr(const CXXNewExpr *Node) {
2142 VisitExpr(Node);
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002143 if (Node->isGlobalNew())
Reid Kleckner461c0c62015-03-19 18:47:47 +00002144 OS << " global";
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002145 if (Node->isArray())
Reid Kleckner461c0c62015-03-19 18:47:47 +00002146 OS << " array";
2147 if (Node->getOperatorNew()) {
2148 OS << ' ';
2149 dumpBareDeclRef(Node->getOperatorNew());
2150 }
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002151 // We could dump the deallocation function used in case of error, but it's
2152 // usually not that interesting.
2153}
2154
2155void ASTDumper::VisitCXXDeleteExpr(const CXXDeleteExpr *Node) {
2156 VisitExpr(Node);
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002157 if (Node->isGlobalDelete())
Reid Kleckner461c0c62015-03-19 18:47:47 +00002158 OS << " global";
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002159 if (Node->isArrayForm())
Reid Kleckner461c0c62015-03-19 18:47:47 +00002160 OS << " array";
2161 if (Node->getOperatorDelete()) {
2162 OS << ' ';
2163 dumpBareDeclRef(Node->getOperatorDelete());
2164 }
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002165}
2166
Richard Smithe6c01442013-06-05 00:46:14 +00002167void
2168ASTDumper::VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *Node) {
2169 VisitExpr(Node);
2170 if (const ValueDecl *VD = Node->getExtendingDecl()) {
2171 OS << " extended by ";
2172 dumpBareDeclRef(VD);
2173 }
2174}
2175
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002176void ASTDumper::VisitExprWithCleanups(const ExprWithCleanups *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002177 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002178 for (unsigned i = 0, e = Node->getNumObjects(); i != e; ++i)
2179 dumpDeclRef(Node->getObject(i), "cleanup");
Anders Carlsson073846832009-08-12 00:21:52 +00002180}
2181
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002182void ASTDumper::dumpCXXTemporary(const CXXTemporary *Temporary) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002183 OS << "(CXXTemporary";
2184 dumpPointer(Temporary);
2185 OS << ")";
Anders Carlsson073846832009-08-12 00:21:52 +00002186}
2187
Serge Pavlov6b926032015-02-16 19:58:41 +00002188void ASTDumper::VisitSizeOfPackExpr(const SizeOfPackExpr *Node) {
2189 VisitExpr(Node);
2190 dumpPointer(Node->getPack());
2191 dumpName(Node->getPack());
Richard Smithd784e682015-09-23 21:41:42 +00002192 if (Node->isPartiallySubstituted())
2193 for (const auto &A : Node->getPartialArguments())
2194 dumpTemplateArgument(A);
Serge Pavlov6b926032015-02-16 19:58:41 +00002195}
2196
2197
Anders Carlsson76f4a902007-08-21 17:43:55 +00002198//===----------------------------------------------------------------------===//
2199// Obj-C Expressions
2200//===----------------------------------------------------------------------===//
2201
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002202void ASTDumper::VisitObjCMessageExpr(const ObjCMessageExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002203 VisitExpr(Node);
Aaron Ballmanb190f972014-01-03 17:59:55 +00002204 OS << " selector=";
2205 Node->getSelector().print(OS);
Douglas Gregor9a129192010-04-21 00:45:42 +00002206 switch (Node->getReceiverKind()) {
2207 case ObjCMessageExpr::Instance:
2208 break;
2209
2210 case ObjCMessageExpr::Class:
2211 OS << " class=";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002212 dumpBareType(Node->getClassReceiver());
Douglas Gregor9a129192010-04-21 00:45:42 +00002213 break;
2214
2215 case ObjCMessageExpr::SuperInstance:
2216 OS << " super (instance)";
2217 break;
2218
2219 case ObjCMessageExpr::SuperClass:
2220 OS << " super (class)";
2221 break;
2222 }
Ted Kremenek36748da2008-02-29 22:04:05 +00002223}
2224
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002225void ASTDumper::VisitObjCBoxedExpr(const ObjCBoxedExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002226 VisitExpr(Node);
Richard Trieu4b259c82016-06-09 22:03:04 +00002227 if (auto *BoxingMethod = Node->getBoxingMethod()) {
2228 OS << " selector=";
2229 BoxingMethod->getSelector().print(OS);
2230 }
Argyrios Kyrtzidis9dd40892012-05-10 20:02:31 +00002231}
2232
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002233void ASTDumper::VisitObjCAtCatchStmt(const ObjCAtCatchStmt *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002234 VisitStmt(Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002235 if (const VarDecl *CatchParam = Node->getCatchParamDecl())
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002236 dumpDecl(CatchParam);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002237 else
Douglas Gregor96c79492010-04-23 22:50:49 +00002238 OS << " catch all";
Douglas Gregor96c79492010-04-23 22:50:49 +00002239}
2240
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002241void ASTDumper::VisitObjCEncodeExpr(const ObjCEncodeExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002242 VisitExpr(Node);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002243 dumpType(Node->getEncodedType());
Anders Carlssonc5a81eb2007-08-22 15:14:15 +00002244}
2245
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002246void ASTDumper::VisitObjCSelectorExpr(const ObjCSelectorExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002247 VisitExpr(Node);
Mike Stump11289f42009-09-09 15:08:12 +00002248
Aaron Ballmanb190f972014-01-03 17:59:55 +00002249 OS << " ";
2250 Node->getSelector().print(OS);
Fariborz Jahanian4bef4622007-10-16 20:40:23 +00002251}
2252
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002253void ASTDumper::VisitObjCProtocolExpr(const ObjCProtocolExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002254 VisitExpr(Node);
Mike Stump11289f42009-09-09 15:08:12 +00002255
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002256 OS << ' ' << *Node->getProtocol();
Fariborz Jahaniana32aaef2007-10-17 16:58:11 +00002257}
Daniel Dunbar4b8c6db2008-08-30 05:35:15 +00002258
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002259void ASTDumper::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002260 VisitExpr(Node);
John McCallb7bd14f2010-12-02 01:19:52 +00002261 if (Node->isImplicitProperty()) {
Fariborz Jahanian0f0b3022010-12-22 19:46:35 +00002262 OS << " Kind=MethodRef Getter=\"";
2263 if (Node->getImplicitPropertyGetter())
Aaron Ballmanb190f972014-01-03 17:59:55 +00002264 Node->getImplicitPropertyGetter()->getSelector().print(OS);
Fariborz Jahanian0f0b3022010-12-22 19:46:35 +00002265 else
2266 OS << "(null)";
2267
2268 OS << "\" Setter=\"";
John McCallb7bd14f2010-12-02 01:19:52 +00002269 if (ObjCMethodDecl *Setter = Node->getImplicitPropertySetter())
Aaron Ballmanb190f972014-01-03 17:59:55 +00002270 Setter->getSelector().print(OS);
John McCallb7bd14f2010-12-02 01:19:52 +00002271 else
2272 OS << "(null)";
2273 OS << "\"";
2274 } else {
Benjamin Kramerb89514a2011-10-14 18:45:37 +00002275 OS << " Kind=PropertyRef Property=\"" << *Node->getExplicitProperty() <<'"';
John McCallb7bd14f2010-12-02 01:19:52 +00002276 }
Fariborz Jahanian8a1810f2008-11-22 18:39:36 +00002277
Fariborz Jahanian681c0752010-10-14 16:04:05 +00002278 if (Node->isSuperReceiver())
2279 OS << " super";
Argyrios Kyrtzidisab468b02012-03-30 00:19:18 +00002280
2281 OS << " Messaging=";
2282 if (Node->isMessagingGetter() && Node->isMessagingSetter())
2283 OS << "Getter&Setter";
2284 else if (Node->isMessagingGetter())
2285 OS << "Getter";
2286 else if (Node->isMessagingSetter())
2287 OS << "Setter";
Douglas Gregor8ea1f532008-11-04 14:56:14 +00002288}
2289
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002290void ASTDumper::VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002291 VisitExpr(Node);
Ted Kremeneke65b0862012-03-06 20:05:56 +00002292 if (Node->isArraySubscriptRefExpr())
2293 OS << " Kind=ArraySubscript GetterForArray=\"";
2294 else
2295 OS << " Kind=DictionarySubscript GetterForDictionary=\"";
2296 if (Node->getAtIndexMethodDecl())
Aaron Ballmanb190f972014-01-03 17:59:55 +00002297 Node->getAtIndexMethodDecl()->getSelector().print(OS);
Ted Kremeneke65b0862012-03-06 20:05:56 +00002298 else
2299 OS << "(null)";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002300
Ted Kremeneke65b0862012-03-06 20:05:56 +00002301 if (Node->isArraySubscriptRefExpr())
2302 OS << "\" SetterForArray=\"";
2303 else
2304 OS << "\" SetterForDictionary=\"";
2305 if (Node->setAtIndexMethodDecl())
Aaron Ballmanb190f972014-01-03 17:59:55 +00002306 Node->setAtIndexMethodDecl()->getSelector().print(OS);
Ted Kremeneke65b0862012-03-06 20:05:56 +00002307 else
2308 OS << "(null)";
2309}
2310
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002311void ASTDumper::VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002312 VisitExpr(Node);
Ted Kremeneke65b0862012-03-06 20:05:56 +00002313 OS << " " << (Node->getValue() ? "__objc_yes" : "__objc_no");
2314}
2315
Chris Lattnercbe4f772007-08-08 22:51:59 +00002316//===----------------------------------------------------------------------===//
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002317// Comments
2318//===----------------------------------------------------------------------===//
2319
2320const char *ASTDumper::getCommandName(unsigned CommandID) {
2321 if (Traits)
2322 return Traits->getCommandInfo(CommandID)->Name;
2323 const CommandInfo *Info = CommandTraits::getBuiltinCommandInfo(CommandID);
2324 if (Info)
2325 return Info->Name;
2326 return "<not a builtin command>";
2327}
2328
2329void ASTDumper::dumpFullComment(const FullComment *C) {
2330 if (!C)
2331 return;
2332
2333 FC = C;
2334 dumpComment(C);
Craig Topper36250ad2014-05-12 05:36:57 +00002335 FC = nullptr;
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002336}
2337
2338void ASTDumper::dumpComment(const Comment *C) {
Richard Smithf7514452014-10-30 21:02:37 +00002339 dumpChild([=] {
2340 if (!C) {
2341 ColorScope Color(*this, NullColor);
2342 OS << "<<<NULL>>>";
2343 return;
2344 }
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002345
Richard Smithf7514452014-10-30 21:02:37 +00002346 {
2347 ColorScope Color(*this, CommentColor);
2348 OS << C->getCommentKindName();
2349 }
2350 dumpPointer(C);
2351 dumpSourceRange(C->getSourceRange());
2352 ConstCommentVisitor<ASTDumper>::visit(C);
2353 for (Comment::child_iterator I = C->child_begin(), E = C->child_end();
2354 I != E; ++I)
2355 dumpComment(*I);
2356 });
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002357}
2358
2359void ASTDumper::visitTextComment(const TextComment *C) {
2360 OS << " Text=\"" << C->getText() << "\"";
2361}
2362
2363void ASTDumper::visitInlineCommandComment(const InlineCommandComment *C) {
2364 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\"";
2365 switch (C->getRenderKind()) {
2366 case InlineCommandComment::RenderNormal:
2367 OS << " RenderNormal";
2368 break;
2369 case InlineCommandComment::RenderBold:
2370 OS << " RenderBold";
2371 break;
2372 case InlineCommandComment::RenderMonospaced:
2373 OS << " RenderMonospaced";
2374 break;
2375 case InlineCommandComment::RenderEmphasized:
2376 OS << " RenderEmphasized";
2377 break;
2378 }
2379
2380 for (unsigned i = 0, e = C->getNumArgs(); i != e; ++i)
2381 OS << " Arg[" << i << "]=\"" << C->getArgText(i) << "\"";
2382}
2383
2384void ASTDumper::visitHTMLStartTagComment(const HTMLStartTagComment *C) {
2385 OS << " Name=\"" << C->getTagName() << "\"";
2386 if (C->getNumAttrs() != 0) {
2387 OS << " Attrs: ";
2388 for (unsigned i = 0, e = C->getNumAttrs(); i != e; ++i) {
2389 const HTMLStartTagComment::Attribute &Attr = C->getAttr(i);
2390 OS << " \"" << Attr.Name << "=\"" << Attr.Value << "\"";
2391 }
2392 }
2393 if (C->isSelfClosing())
2394 OS << " SelfClosing";
2395}
2396
2397void ASTDumper::visitHTMLEndTagComment(const HTMLEndTagComment *C) {
2398 OS << " Name=\"" << C->getTagName() << "\"";
2399}
2400
2401void ASTDumper::visitBlockCommandComment(const BlockCommandComment *C) {
2402 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\"";
2403 for (unsigned i = 0, e = C->getNumArgs(); i != e; ++i)
2404 OS << " Arg[" << i << "]=\"" << C->getArgText(i) << "\"";
2405}
2406
2407void ASTDumper::visitParamCommandComment(const ParamCommandComment *C) {
2408 OS << " " << ParamCommandComment::getDirectionAsString(C->getDirection());
2409
2410 if (C->isDirectionExplicit())
2411 OS << " explicitly";
2412 else
2413 OS << " implicitly";
2414
2415 if (C->hasParamName()) {
2416 if (C->isParamIndexValid())
2417 OS << " Param=\"" << C->getParamName(FC) << "\"";
2418 else
2419 OS << " Param=\"" << C->getParamNameAsWritten() << "\"";
2420 }
2421
Dmitri Gribenkodbff5c72014-03-19 14:03:47 +00002422 if (C->isParamIndexValid() && !C->isVarArgParam())
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002423 OS << " ParamIndex=" << C->getParamIndex();
2424}
2425
2426void ASTDumper::visitTParamCommandComment(const TParamCommandComment *C) {
2427 if (C->hasParamName()) {
2428 if (C->isPositionValid())
2429 OS << " Param=\"" << C->getParamName(FC) << "\"";
2430 else
2431 OS << " Param=\"" << C->getParamNameAsWritten() << "\"";
2432 }
2433
2434 if (C->isPositionValid()) {
2435 OS << " Position=<";
2436 for (unsigned i = 0, e = C->getDepth(); i != e; ++i) {
2437 OS << C->getIndex(i);
2438 if (i != e - 1)
2439 OS << ", ";
2440 }
2441 OS << ">";
2442 }
2443}
2444
2445void ASTDumper::visitVerbatimBlockComment(const VerbatimBlockComment *C) {
2446 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\""
2447 " CloseName=\"" << C->getCloseName() << "\"";
2448}
2449
2450void ASTDumper::visitVerbatimBlockLineComment(
2451 const VerbatimBlockLineComment *C) {
2452 OS << " Text=\"" << C->getText() << "\"";
2453}
2454
2455void ASTDumper::visitVerbatimLineComment(const VerbatimLineComment *C) {
2456 OS << " Text=\"" << C->getText() << "\"";
2457}
2458
2459//===----------------------------------------------------------------------===//
Richard Smithd5e7ff82014-10-31 01:17:45 +00002460// Type method implementations
2461//===----------------------------------------------------------------------===//
2462
2463void QualType::dump(const char *msg) const {
2464 if (msg)
2465 llvm::errs() << msg << ": ";
2466 dump();
2467}
2468
Richard Smith14d04842016-11-02 23:57:18 +00002469LLVM_DUMP_METHOD void QualType::dump() const { dump(llvm::errs()); }
2470
2471LLVM_DUMP_METHOD void QualType::dump(llvm::raw_ostream &OS) const {
2472 ASTDumper Dumper(OS, nullptr, nullptr);
Richard Smithd5e7ff82014-10-31 01:17:45 +00002473 Dumper.dumpTypeAsChild(*this);
2474}
2475
Richard Smith14d04842016-11-02 23:57:18 +00002476LLVM_DUMP_METHOD void Type::dump() const { dump(llvm::errs()); }
2477
2478LLVM_DUMP_METHOD void Type::dump(llvm::raw_ostream &OS) const {
2479 QualType(this, 0).dump(OS);
2480}
Richard Smithd5e7ff82014-10-31 01:17:45 +00002481
2482//===----------------------------------------------------------------------===//
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002483// Decl method implementations
2484//===----------------------------------------------------------------------===//
2485
Alp Tokeref6b0072014-01-04 13:47:14 +00002486LLVM_DUMP_METHOD void Decl::dump() const { dump(llvm::errs()); }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002487
Alp Tokeref6b0072014-01-04 13:47:14 +00002488LLVM_DUMP_METHOD void Decl::dump(raw_ostream &OS) const {
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002489 ASTDumper P(OS, &getASTContext().getCommentCommandTraits(),
2490 &getASTContext().getSourceManager());
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002491 P.dumpDecl(this);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002492}
2493
Alp Tokeref6b0072014-01-04 13:47:14 +00002494LLVM_DUMP_METHOD void Decl::dumpColor() const {
Richard Trieud215b8d2013-01-26 01:31:20 +00002495 ASTDumper P(llvm::errs(), &getASTContext().getCommentCommandTraits(),
2496 &getASTContext().getSourceManager(), /*ShowColors*/true);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002497 P.dumpDecl(this);
Richard Trieud215b8d2013-01-26 01:31:20 +00002498}
Richard Smith33937e72013-06-22 21:49:40 +00002499
Alp Tokeref6b0072014-01-04 13:47:14 +00002500LLVM_DUMP_METHOD void DeclContext::dumpLookups() const {
Richard Smith6ea05822013-06-24 01:45:33 +00002501 dumpLookups(llvm::errs());
2502}
2503
Richard Smith35f986d2014-08-11 22:11:07 +00002504LLVM_DUMP_METHOD void DeclContext::dumpLookups(raw_ostream &OS,
2505 bool DumpDecls) const {
Richard Smith33937e72013-06-22 21:49:40 +00002506 const DeclContext *DC = this;
2507 while (!DC->isTranslationUnit())
2508 DC = DC->getParent();
2509 ASTContext &Ctx = cast<TranslationUnitDecl>(DC)->getASTContext();
Richard Smith6ea05822013-06-24 01:45:33 +00002510 ASTDumper P(OS, &Ctx.getCommentCommandTraits(), &Ctx.getSourceManager());
Richard Smith35f986d2014-08-11 22:11:07 +00002511 P.dumpLookups(this, DumpDecls);
Richard Smith33937e72013-06-22 21:49:40 +00002512}
2513
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002514//===----------------------------------------------------------------------===//
Chris Lattnercbe4f772007-08-08 22:51:59 +00002515// Stmt method implementations
2516//===----------------------------------------------------------------------===//
2517
Alp Tokeref6b0072014-01-04 13:47:14 +00002518LLVM_DUMP_METHOD void Stmt::dump(SourceManager &SM) const {
Argyrios Kyrtzidisc049f752010-08-09 10:54:31 +00002519 dump(llvm::errs(), SM);
2520}
2521
Alp Tokeref6b0072014-01-04 13:47:14 +00002522LLVM_DUMP_METHOD void Stmt::dump(raw_ostream &OS, SourceManager &SM) const {
Craig Topper36250ad2014-05-12 05:36:57 +00002523 ASTDumper P(OS, nullptr, &SM);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002524 P.dumpStmt(this);
Chris Lattner779d5d92007-08-30 00:40:08 +00002525}
2526
Faisal Vali2da8ed92015-03-22 13:35:56 +00002527LLVM_DUMP_METHOD void Stmt::dump(raw_ostream &OS) const {
2528 ASTDumper P(OS, nullptr, nullptr);
2529 P.dumpStmt(this);
2530}
2531
Alp Tokeref6b0072014-01-04 13:47:14 +00002532LLVM_DUMP_METHOD void Stmt::dump() const {
Craig Topper36250ad2014-05-12 05:36:57 +00002533 ASTDumper P(llvm::errs(), nullptr, nullptr);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002534 P.dumpStmt(this);
Chris Lattnercbe4f772007-08-08 22:51:59 +00002535}
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002536
Alp Tokeref6b0072014-01-04 13:47:14 +00002537LLVM_DUMP_METHOD void Stmt::dumpColor() const {
Craig Topper36250ad2014-05-12 05:36:57 +00002538 ASTDumper P(llvm::errs(), nullptr, nullptr, /*ShowColors*/true);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002539 P.dumpStmt(this);
Richard Trieud215b8d2013-01-26 01:31:20 +00002540}
2541
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002542//===----------------------------------------------------------------------===//
2543// Comment method implementations
2544//===----------------------------------------------------------------------===//
2545
Craig Topper36250ad2014-05-12 05:36:57 +00002546LLVM_DUMP_METHOD void Comment::dump() const {
2547 dump(llvm::errs(), nullptr, nullptr);
2548}
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002549
Alp Tokeref6b0072014-01-04 13:47:14 +00002550LLVM_DUMP_METHOD void Comment::dump(const ASTContext &Context) const {
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002551 dump(llvm::errs(), &Context.getCommentCommandTraits(),
2552 &Context.getSourceManager());
2553}
2554
Alexander Kornienko00911f12013-01-15 12:20:21 +00002555void Comment::dump(raw_ostream &OS, const CommandTraits *Traits,
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002556 const SourceManager *SM) const {
2557 const FullComment *FC = dyn_cast<FullComment>(this);
2558 ASTDumper D(OS, Traits, SM);
2559 D.dumpFullComment(FC);
2560}
Richard Trieud215b8d2013-01-26 01:31:20 +00002561
Alp Tokeref6b0072014-01-04 13:47:14 +00002562LLVM_DUMP_METHOD void Comment::dumpColor() const {
Richard Trieud215b8d2013-01-26 01:31:20 +00002563 const FullComment *FC = dyn_cast<FullComment>(this);
Craig Topper36250ad2014-05-12 05:36:57 +00002564 ASTDumper D(llvm::errs(), nullptr, nullptr, /*ShowColors*/true);
Richard Trieud215b8d2013-01-26 01:31:20 +00002565 D.dumpFullComment(FC);
2566}