blob: 1a4207f51209f0ee8538800b360698a6525622ac [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);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000432 void VisitFileScopeAsmDecl(const FileScopeAsmDecl *D);
433 void VisitImportDecl(const ImportDecl *D);
Nico Weber66220292016-03-02 17:28:48 +0000434 void VisitPragmaCommentDecl(const PragmaCommentDecl *D);
Nico Webercbbaeb12016-03-02 19:28:54 +0000435 void VisitPragmaDetectMismatchDecl(const PragmaDetectMismatchDecl *D);
Alexey Bataev958b9e72016-03-31 09:30:50 +0000436 void VisitCapturedDecl(const CapturedDecl *D);
437
438 // OpenMP decls
439 void VisitOMPThreadPrivateDecl(const OMPThreadPrivateDecl *D);
440 void VisitOMPDeclareReductionDecl(const OMPDeclareReductionDecl *D);
441 void VisitOMPCapturedExprDecl(const OMPCapturedExprDecl *D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000442
443 // C++ Decls
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000444 void VisitNamespaceDecl(const NamespaceDecl *D);
445 void VisitUsingDirectiveDecl(const UsingDirectiveDecl *D);
446 void VisitNamespaceAliasDecl(const NamespaceAliasDecl *D);
447 void VisitTypeAliasDecl(const TypeAliasDecl *D);
448 void VisitTypeAliasTemplateDecl(const TypeAliasTemplateDecl *D);
449 void VisitCXXRecordDecl(const CXXRecordDecl *D);
450 void VisitStaticAssertDecl(const StaticAssertDecl *D);
Richard Smithcbdf7332014-03-18 02:07:28 +0000451 template<typename SpecializationDecl>
Richard Smithf7514452014-10-30 21:02:37 +0000452 void VisitTemplateDeclSpecialization(const SpecializationDecl *D,
Richard Smithcbdf7332014-03-18 02:07:28 +0000453 bool DumpExplicitInst,
454 bool DumpRefOnly);
Richard Smith20ade552014-03-17 23:34:53 +0000455 template<typename TemplateDecl>
456 void VisitTemplateDecl(const TemplateDecl *D, bool DumpExplicitInst);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000457 void VisitFunctionTemplateDecl(const FunctionTemplateDecl *D);
458 void VisitClassTemplateDecl(const ClassTemplateDecl *D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000459 void VisitClassTemplateSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000460 const ClassTemplateSpecializationDecl *D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000461 void VisitClassTemplatePartialSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000462 const ClassTemplatePartialSpecializationDecl *D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000463 void VisitClassScopeFunctionSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000464 const ClassScopeFunctionSpecializationDecl *D);
David Majnemerd9b1a4f2015-11-04 03:40:30 +0000465 void VisitBuiltinTemplateDecl(const BuiltinTemplateDecl *D);
Richard Smithd25789a2013-09-18 01:36:02 +0000466 void VisitVarTemplateDecl(const VarTemplateDecl *D);
467 void VisitVarTemplateSpecializationDecl(
468 const VarTemplateSpecializationDecl *D);
469 void VisitVarTemplatePartialSpecializationDecl(
470 const VarTemplatePartialSpecializationDecl *D);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000471 void VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D);
472 void VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D);
473 void VisitTemplateTemplateParmDecl(const TemplateTemplateParmDecl *D);
474 void VisitUsingDecl(const UsingDecl *D);
475 void VisitUnresolvedUsingTypenameDecl(const UnresolvedUsingTypenameDecl *D);
476 void VisitUnresolvedUsingValueDecl(const UnresolvedUsingValueDecl *D);
477 void VisitUsingShadowDecl(const UsingShadowDecl *D);
Richard Smith5179eb72016-06-28 19:03:57 +0000478 void VisitConstructorUsingShadowDecl(const ConstructorUsingShadowDecl *D);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000479 void VisitLinkageSpecDecl(const LinkageSpecDecl *D);
480 void VisitAccessSpecDecl(const AccessSpecDecl *D);
481 void VisitFriendDecl(const FriendDecl *D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000482
483 // ObjC Decls
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000484 void VisitObjCIvarDecl(const ObjCIvarDecl *D);
485 void VisitObjCMethodDecl(const ObjCMethodDecl *D);
Douglas Gregor85f3f952015-07-07 03:57:15 +0000486 void VisitObjCTypeParamDecl(const ObjCTypeParamDecl *D);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000487 void VisitObjCCategoryDecl(const ObjCCategoryDecl *D);
488 void VisitObjCCategoryImplDecl(const ObjCCategoryImplDecl *D);
489 void VisitObjCProtocolDecl(const ObjCProtocolDecl *D);
490 void VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D);
491 void VisitObjCImplementationDecl(const ObjCImplementationDecl *D);
492 void VisitObjCCompatibleAliasDecl(const ObjCCompatibleAliasDecl *D);
493 void VisitObjCPropertyDecl(const ObjCPropertyDecl *D);
494 void VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D);
495 void VisitBlockDecl(const BlockDecl *D);
Mike Stump11289f42009-09-09 15:08:12 +0000496
Chris Lattner84ca3762007-08-30 01:00:35 +0000497 // Stmts.
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000498 void VisitStmt(const Stmt *Node);
499 void VisitDeclStmt(const DeclStmt *Node);
500 void VisitAttributedStmt(const AttributedStmt *Node);
501 void VisitLabelStmt(const LabelStmt *Node);
502 void VisitGotoStmt(const GotoStmt *Node);
Pavel Labath1ef83422013-09-04 14:35:00 +0000503 void VisitCXXCatchStmt(const CXXCatchStmt *Node);
Alexey Bataev958b9e72016-03-31 09:30:50 +0000504 void VisitCapturedStmt(const CapturedStmt *Node);
505
506 // OpenMP
507 void VisitOMPExecutableDirective(const OMPExecutableDirective *Node);
Mike Stump11289f42009-09-09 15:08:12 +0000508
Chris Lattner84ca3762007-08-30 01:00:35 +0000509 // Exprs
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000510 void VisitExpr(const Expr *Node);
511 void VisitCastExpr(const CastExpr *Node);
512 void VisitDeclRefExpr(const DeclRefExpr *Node);
513 void VisitPredefinedExpr(const PredefinedExpr *Node);
514 void VisitCharacterLiteral(const CharacterLiteral *Node);
515 void VisitIntegerLiteral(const IntegerLiteral *Node);
516 void VisitFloatingLiteral(const FloatingLiteral *Node);
517 void VisitStringLiteral(const StringLiteral *Str);
Richard Smithf0514962014-06-03 08:24:28 +0000518 void VisitInitListExpr(const InitListExpr *ILE);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000519 void VisitUnaryOperator(const UnaryOperator *Node);
520 void VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *Node);
521 void VisitMemberExpr(const MemberExpr *Node);
522 void VisitExtVectorElementExpr(const ExtVectorElementExpr *Node);
523 void VisitBinaryOperator(const BinaryOperator *Node);
524 void VisitCompoundAssignOperator(const CompoundAssignOperator *Node);
525 void VisitAddrLabelExpr(const AddrLabelExpr *Node);
526 void VisitBlockExpr(const BlockExpr *Node);
527 void VisitOpaqueValueExpr(const OpaqueValueExpr *Node);
Chris Lattner84ca3762007-08-30 01:00:35 +0000528
529 // C++
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000530 void VisitCXXNamedCastExpr(const CXXNamedCastExpr *Node);
531 void VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *Node);
532 void VisitCXXThisExpr(const CXXThisExpr *Node);
533 void VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *Node);
534 void VisitCXXConstructExpr(const CXXConstructExpr *Node);
535 void VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *Node);
Reid Kleckner5c682bc2015-03-19 18:09:25 +0000536 void VisitCXXNewExpr(const CXXNewExpr *Node);
537 void VisitCXXDeleteExpr(const CXXDeleteExpr *Node);
Richard Smithe6c01442013-06-05 00:46:14 +0000538 void VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000539 void VisitExprWithCleanups(const ExprWithCleanups *Node);
540 void VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *Node);
541 void dumpCXXTemporary(const CXXTemporary *Temporary);
Faisal Vali2b391ab2013-09-26 19:54:12 +0000542 void VisitLambdaExpr(const LambdaExpr *Node) {
543 VisitExpr(Node);
544 dumpDecl(Node->getLambdaClass());
545 }
Serge Pavlov6b926032015-02-16 19:58:41 +0000546 void VisitSizeOfPackExpr(const SizeOfPackExpr *Node);
Mike Stump11289f42009-09-09 15:08:12 +0000547
Chris Lattner84ca3762007-08-30 01:00:35 +0000548 // ObjC
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000549 void VisitObjCAtCatchStmt(const ObjCAtCatchStmt *Node);
550 void VisitObjCEncodeExpr(const ObjCEncodeExpr *Node);
551 void VisitObjCMessageExpr(const ObjCMessageExpr *Node);
552 void VisitObjCBoxedExpr(const ObjCBoxedExpr *Node);
553 void VisitObjCSelectorExpr(const ObjCSelectorExpr *Node);
554 void VisitObjCProtocolExpr(const ObjCProtocolExpr *Node);
555 void VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *Node);
556 void VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *Node);
557 void VisitObjCIvarRefExpr(const ObjCIvarRefExpr *Node);
558 void VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *Node);
Alexander Kornienkoebc17b52013-01-14 14:07:11 +0000559
560 // Comments.
561 const char *getCommandName(unsigned CommandID);
562 void dumpComment(const Comment *C);
563
564 // Inline comments.
565 void visitTextComment(const TextComment *C);
566 void visitInlineCommandComment(const InlineCommandComment *C);
567 void visitHTMLStartTagComment(const HTMLStartTagComment *C);
568 void visitHTMLEndTagComment(const HTMLEndTagComment *C);
569
570 // Block comments.
571 void visitBlockCommandComment(const BlockCommandComment *C);
572 void visitParamCommandComment(const ParamCommandComment *C);
573 void visitTParamCommandComment(const TParamCommandComment *C);
574 void visitVerbatimBlockComment(const VerbatimBlockComment *C);
575 void visitVerbatimBlockLineComment(const VerbatimBlockLineComment *C);
576 void visitVerbatimLineComment(const VerbatimLineComment *C);
Chris Lattnercbe4f772007-08-08 22:51:59 +0000577 };
Alexander Kornienkoab9db512015-06-22 23:07:51 +0000578}
Chris Lattnercbe4f772007-08-08 22:51:59 +0000579
580//===----------------------------------------------------------------------===//
Chris Lattner11e30d32007-08-30 06:17:34 +0000581// Utilities
582//===----------------------------------------------------------------------===//
583
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000584void ASTDumper::dumpPointer(const void *Ptr) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000585 ColorScope Color(*this, AddressColor);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000586 OS << ' ' << Ptr;
587}
588
Alexander Kornienko18ec81b2012-12-13 13:59:55 +0000589void ASTDumper::dumpLocation(SourceLocation Loc) {
Alex McCarthye14ddef2014-05-02 20:24:11 +0000590 if (!SM)
591 return;
592
Richard Trieud215b8d2013-01-26 01:31:20 +0000593 ColorScope Color(*this, LocationColor);
Chris Lattner53e384f2009-01-16 07:00:02 +0000594 SourceLocation SpellingLoc = SM->getSpellingLoc(Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000595
Chris Lattner11e30d32007-08-30 06:17:34 +0000596 // The general format we print out is filename:line:col, but we drop pieces
597 // that haven't changed since the last loc printed.
Chris Lattnerf1ca7d32009-01-27 07:57:44 +0000598 PresumedLoc PLoc = SM->getPresumedLoc(SpellingLoc);
599
Douglas Gregor453b0122010-11-12 07:15:47 +0000600 if (PLoc.isInvalid()) {
601 OS << "<invalid sloc>";
602 return;
603 }
604
Chris Lattnerf1ca7d32009-01-27 07:57:44 +0000605 if (strcmp(PLoc.getFilename(), LastLocFilename) != 0) {
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000606 OS << PLoc.getFilename() << ':' << PLoc.getLine()
607 << ':' << PLoc.getColumn();
Chris Lattnerf1ca7d32009-01-27 07:57:44 +0000608 LastLocFilename = PLoc.getFilename();
609 LastLocLine = PLoc.getLine();
610 } else if (PLoc.getLine() != LastLocLine) {
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000611 OS << "line" << ':' << PLoc.getLine()
612 << ':' << PLoc.getColumn();
Chris Lattnerf1ca7d32009-01-27 07:57:44 +0000613 LastLocLine = PLoc.getLine();
Chris Lattner11e30d32007-08-30 06:17:34 +0000614 } else {
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000615 OS << "col" << ':' << PLoc.getColumn();
Chris Lattner11e30d32007-08-30 06:17:34 +0000616 }
617}
618
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000619void ASTDumper::dumpSourceRange(SourceRange R) {
Chris Lattner11e30d32007-08-30 06:17:34 +0000620 // Can't translate locations if a SourceManager isn't available.
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000621 if (!SM)
622 return;
Mike Stump11289f42009-09-09 15:08:12 +0000623
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000624 OS << " <";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000625 dumpLocation(R.getBegin());
Chris Lattnera7c19fe2007-10-16 22:36:42 +0000626 if (R.getBegin() != R.getEnd()) {
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000627 OS << ", ";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000628 dumpLocation(R.getEnd());
Chris Lattner11e30d32007-08-30 06:17:34 +0000629 }
Daniel Dunbar34a96c82009-12-03 09:13:13 +0000630 OS << ">";
Mike Stump11289f42009-09-09 15:08:12 +0000631
Chris Lattner11e30d32007-08-30 06:17:34 +0000632 // <t2.c:123:421[blah], t2.c:412:321>
633
634}
635
Richard Smithd5e7ff82014-10-31 01:17:45 +0000636void ASTDumper::dumpBareType(QualType T, bool Desugar) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000637 ColorScope Color(*this, TypeColor);
Richard Smithd5e7ff82014-10-31 01:17:45 +0000638
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000639 SplitQualType T_split = T.split();
640 OS << "'" << QualType::getAsString(T_split) << "'";
641
Richard Smithd5e7ff82014-10-31 01:17:45 +0000642 if (Desugar && !T.isNull()) {
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000643 // If the type is sugared, also dump a (shallow) desugared type.
644 SplitQualType D_split = T.getSplitDesugaredType();
645 if (T_split != D_split)
646 OS << ":'" << QualType::getAsString(D_split) << "'";
647 }
648}
649
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000650void ASTDumper::dumpType(QualType T) {
651 OS << ' ';
652 dumpBareType(T);
653}
654
Richard Smithd5e7ff82014-10-31 01:17:45 +0000655void ASTDumper::dumpTypeAsChild(QualType T) {
656 SplitQualType SQT = T.split();
657 if (!SQT.Quals.hasQualifiers())
658 return dumpTypeAsChild(SQT.Ty);
659
660 dumpChild([=] {
661 OS << "QualType";
662 dumpPointer(T.getAsOpaquePtr());
663 OS << " ";
664 dumpBareType(T, false);
665 OS << " " << T.split().Quals.getAsString();
666 dumpTypeAsChild(T.split().Ty);
667 });
668}
669
670void ASTDumper::dumpTypeAsChild(const Type *T) {
671 dumpChild([=] {
672 if (!T) {
673 ColorScope Color(*this, NullColor);
674 OS << "<<<NULL>>>";
675 return;
676 }
Serge Pavlova6adc9e2015-12-28 17:19:12 +0000677 if (const LocInfoType *LIT = llvm::dyn_cast<LocInfoType>(T)) {
678 {
679 ColorScope Color(*this, TypeColor);
680 OS << "LocInfo Type";
681 }
682 dumpPointer(T);
683 dumpTypeAsChild(LIT->getTypeSourceInfo()->getType());
684 return;
685 }
Richard Smithd5e7ff82014-10-31 01:17:45 +0000686
687 {
688 ColorScope Color(*this, TypeColor);
689 OS << T->getTypeClassName() << "Type";
690 }
691 dumpPointer(T);
692 OS << " ";
693 dumpBareType(QualType(T, 0), false);
694
695 QualType SingleStepDesugar =
696 T->getLocallyUnqualifiedSingleStepDesugaredType();
697 if (SingleStepDesugar != QualType(T, 0))
698 OS << " sugar";
699 if (T->isDependentType())
700 OS << " dependent";
701 else if (T->isInstantiationDependentType())
702 OS << " instantiation_dependent";
703 if (T->isVariablyModifiedType())
704 OS << " variably_modified";
705 if (T->containsUnexpandedParameterPack())
706 OS << " contains_unexpanded_pack";
707 if (T->isFromAST())
708 OS << " imported";
709
710 TypeVisitor<ASTDumper>::Visit(T);
711
712 if (SingleStepDesugar != QualType(T, 0))
713 dumpTypeAsChild(SingleStepDesugar);
714 });
715}
716
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000717void ASTDumper::dumpBareDeclRef(const Decl *D) {
Richard Smith5179eb72016-06-28 19:03:57 +0000718 if (!D) {
719 ColorScope Color(*this, NullColor);
720 OS << "<<<NULL>>>";
721 return;
722 }
723
Richard Trieud215b8d2013-01-26 01:31:20 +0000724 {
725 ColorScope Color(*this, DeclKindNameColor);
726 OS << D->getDeclKindName();
727 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000728 dumpPointer(D);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000729
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000730 if (const NamedDecl *ND = dyn_cast<NamedDecl>(D)) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000731 ColorScope Color(*this, DeclNameColor);
David Blaikied4da8722013-05-14 21:04:00 +0000732 OS << " '" << ND->getDeclName() << '\'';
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000733 }
734
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000735 if (const ValueDecl *VD = dyn_cast<ValueDecl>(D))
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000736 dumpType(VD->getType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000737}
738
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000739void ASTDumper::dumpDeclRef(const Decl *D, const char *Label) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000740 if (!D)
741 return;
742
Richard Smithf7514452014-10-30 21:02:37 +0000743 dumpChild([=]{
744 if (Label)
745 OS << Label << ' ';
746 dumpBareDeclRef(D);
747 });
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000748}
749
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000750void ASTDumper::dumpName(const NamedDecl *ND) {
Richard Trieud215b8d2013-01-26 01:31:20 +0000751 if (ND->getDeclName()) {
752 ColorScope Color(*this, DeclNameColor);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000753 OS << ' ' << ND->getNameAsString();
Richard Trieud215b8d2013-01-26 01:31:20 +0000754 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000755}
756
Richard Trieude5cc7d2013-01-31 01:44:26 +0000757bool ASTDumper::hasNodes(const DeclContext *DC) {
758 if (!DC)
759 return false;
760
Richard Smith1d209d02013-05-23 01:49:11 +0000761 return DC->hasExternalLexicalStorage() ||
762 DC->noload_decls_begin() != DC->noload_decls_end();
Richard Trieude5cc7d2013-01-31 01:44:26 +0000763}
764
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000765void ASTDumper::dumpDeclContext(const DeclContext *DC) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000766 if (!DC)
767 return;
Richard Smithdcc2c452014-03-17 23:00:06 +0000768
Richard Smithdcc2c452014-03-17 23:00:06 +0000769 for (auto *D : DC->noload_decls())
Richard Smithf7514452014-10-30 21:02:37 +0000770 dumpDecl(D);
Richard Smithdcc2c452014-03-17 23:00:06 +0000771
772 if (DC->hasExternalLexicalStorage()) {
Richard Smithf7514452014-10-30 21:02:37 +0000773 dumpChild([=]{
774 ColorScope Color(*this, UndeserializedColor);
775 OS << "<undeserialized declarations>";
776 });
Richard Smith1d209d02013-05-23 01:49:11 +0000777 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000778}
779
Richard Smith35f986d2014-08-11 22:11:07 +0000780void ASTDumper::dumpLookups(const DeclContext *DC, bool DumpDecls) {
Richard Smithf7514452014-10-30 21:02:37 +0000781 dumpChild([=] {
782 OS << "StoredDeclsMap ";
783 dumpBareDeclRef(cast<Decl>(DC));
Richard Smith33937e72013-06-22 21:49:40 +0000784
Richard Smithf7514452014-10-30 21:02:37 +0000785 const DeclContext *Primary = DC->getPrimaryContext();
786 if (Primary != DC) {
787 OS << " primary";
788 dumpPointer(cast<Decl>(Primary));
Richard Smith33937e72013-06-22 21:49:40 +0000789 }
790
Richard Smithf7514452014-10-30 21:02:37 +0000791 bool HasUndeserializedLookups = Primary->hasExternalVisibleStorage();
Richard Smith35f986d2014-08-11 22:11:07 +0000792
Richard Smithf7514452014-10-30 21:02:37 +0000793 DeclContext::all_lookups_iterator I = Primary->noload_lookups_begin(),
794 E = Primary->noload_lookups_end();
795 while (I != E) {
796 DeclarationName Name = I.getLookupName();
797 DeclContextLookupResult R = *I++;
Richard Smith35f986d2014-08-11 22:11:07 +0000798
Richard Smithf7514452014-10-30 21:02:37 +0000799 dumpChild([=] {
800 OS << "DeclarationName ";
801 {
802 ColorScope Color(*this, DeclNameColor);
803 OS << '\'' << Name << '\'';
804 }
Richard Smith35f986d2014-08-11 22:11:07 +0000805
Richard Smithf7514452014-10-30 21:02:37 +0000806 for (DeclContextLookupResult::iterator RI = R.begin(), RE = R.end();
807 RI != RE; ++RI) {
808 dumpChild([=] {
809 dumpBareDeclRef(*RI);
810
811 if ((*RI)->isHidden())
812 OS << " hidden";
813
814 // If requested, dump the redecl chain for this lookup.
815 if (DumpDecls) {
816 // Dump earliest decl first.
817 std::function<void(Decl *)> DumpWithPrev = [&](Decl *D) {
818 if (Decl *Prev = D->getPreviousDecl())
819 DumpWithPrev(Prev);
820 dumpDecl(D);
821 };
822 DumpWithPrev(*RI);
823 }
824 });
825 }
826 });
Richard Smith33937e72013-06-22 21:49:40 +0000827 }
Richard Smith33937e72013-06-22 21:49:40 +0000828
Richard Smithf7514452014-10-30 21:02:37 +0000829 if (HasUndeserializedLookups) {
830 dumpChild([=] {
831 ColorScope Color(*this, UndeserializedColor);
832 OS << "<undeserialized lookups>";
833 });
834 }
835 });
Richard Smith33937e72013-06-22 21:49:40 +0000836}
837
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000838void ASTDumper::dumpAttr(const Attr *A) {
Richard Smithf7514452014-10-30 21:02:37 +0000839 dumpChild([=] {
840 {
841 ColorScope Color(*this, AttrColor);
Aaron Ballman36a53502014-01-16 13:03:14 +0000842
Richard Smithf7514452014-10-30 21:02:37 +0000843 switch (A->getKind()) {
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000844#define ATTR(X) case attr::X: OS << #X; break;
845#include "clang/Basic/AttrList.inc"
Richard Smithf7514452014-10-30 21:02:37 +0000846 }
847 OS << "Attr";
Richard Trieud215b8d2013-01-26 01:31:20 +0000848 }
Richard Smithf7514452014-10-30 21:02:37 +0000849 dumpPointer(A);
850 dumpSourceRange(A->getRange());
851 if (A->isInherited())
852 OS << " Inherited";
853 if (A->isImplicit())
854 OS << " Implicit";
Hans Wennborgb0a8b4a2014-05-31 04:05:57 +0000855#include "clang/AST/AttrDump.inc"
Richard Smithf7514452014-10-30 21:02:37 +0000856 });
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000857}
858
Richard Smith71bec062013-10-15 21:58:30 +0000859static void dumpPreviousDeclImpl(raw_ostream &OS, ...) {}
860
861template<typename T>
862static void dumpPreviousDeclImpl(raw_ostream &OS, const Mergeable<T> *D) {
Rafael Espindola8db352d2013-10-17 15:37:26 +0000863 const T *First = D->getFirstDecl();
Richard Smith71bec062013-10-15 21:58:30 +0000864 if (First != D)
865 OS << " first " << First;
Richard Smithf5f43542013-02-07 01:35:44 +0000866}
867
868template<typename T>
Richard Smith71bec062013-10-15 21:58:30 +0000869static void dumpPreviousDeclImpl(raw_ostream &OS, const Redeclarable<T> *D) {
870 const T *Prev = D->getPreviousDecl();
871 if (Prev)
872 OS << " prev " << Prev;
Richard Smithf5f43542013-02-07 01:35:44 +0000873}
874
Richard Smith71bec062013-10-15 21:58:30 +0000875/// Dump the previous declaration in the redeclaration chain for a declaration,
876/// if any.
877static void dumpPreviousDecl(raw_ostream &OS, const Decl *D) {
Richard Smithf5f43542013-02-07 01:35:44 +0000878 switch (D->getKind()) {
879#define DECL(DERIVED, BASE) \
880 case Decl::DERIVED: \
Richard Smith71bec062013-10-15 21:58:30 +0000881 return dumpPreviousDeclImpl(OS, cast<DERIVED##Decl>(D));
Richard Smithf5f43542013-02-07 01:35:44 +0000882#define ABSTRACT_DECL(DECL)
883#include "clang/AST/DeclNodes.inc"
884 }
885 llvm_unreachable("Decl that isn't part of DeclNodes.inc!");
886}
887
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000888//===----------------------------------------------------------------------===//
889// C++ Utilities
890//===----------------------------------------------------------------------===//
891
892void ASTDumper::dumpAccessSpecifier(AccessSpecifier AS) {
893 switch (AS) {
894 case AS_none:
895 break;
896 case AS_public:
897 OS << "public";
898 break;
899 case AS_protected:
900 OS << "protected";
901 break;
902 case AS_private:
903 OS << "private";
904 break;
905 }
906}
907
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000908void ASTDumper::dumpCXXCtorInitializer(const CXXCtorInitializer *Init) {
Richard Smithf7514452014-10-30 21:02:37 +0000909 dumpChild([=] {
910 OS << "CXXCtorInitializer";
911 if (Init->isAnyMemberInitializer()) {
912 OS << ' ';
913 dumpBareDeclRef(Init->getAnyMember());
914 } else if (Init->isBaseInitializer()) {
915 dumpType(QualType(Init->getBaseClass(), 0));
916 } else if (Init->isDelegatingInitializer()) {
917 dumpType(Init->getTypeSourceInfo()->getType());
918 } else {
919 llvm_unreachable("Unknown initializer type");
920 }
921 dumpStmt(Init->getInit());
922 });
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000923}
924
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000925void ASTDumper::dumpTemplateParameters(const TemplateParameterList *TPL) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000926 if (!TPL)
927 return;
928
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000929 for (TemplateParameterList::const_iterator I = TPL->begin(), E = TPL->end();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000930 I != E; ++I)
931 dumpDecl(*I);
932}
933
934void ASTDumper::dumpTemplateArgumentListInfo(
935 const TemplateArgumentListInfo &TALI) {
Richard Smithf7514452014-10-30 21:02:37 +0000936 for (unsigned i = 0, e = TALI.size(); i < e; ++i)
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000937 dumpTemplateArgumentLoc(TALI[i]);
938}
939
940void ASTDumper::dumpTemplateArgumentLoc(const TemplateArgumentLoc &A) {
941 dumpTemplateArgument(A.getArgument(), A.getSourceRange());
942}
943
944void ASTDumper::dumpTemplateArgumentList(const TemplateArgumentList &TAL) {
945 for (unsigned i = 0, e = TAL.size(); i < e; ++i)
946 dumpTemplateArgument(TAL[i]);
947}
948
949void ASTDumper::dumpTemplateArgument(const TemplateArgument &A, SourceRange R) {
Richard Smithf7514452014-10-30 21:02:37 +0000950 dumpChild([=] {
951 OS << "TemplateArgument";
952 if (R.isValid())
953 dumpSourceRange(R);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000954
Richard Smithf7514452014-10-30 21:02:37 +0000955 switch (A.getKind()) {
956 case TemplateArgument::Null:
957 OS << " null";
958 break;
959 case TemplateArgument::Type:
960 OS << " type";
961 dumpType(A.getAsType());
962 break;
963 case TemplateArgument::Declaration:
964 OS << " decl";
965 dumpDeclRef(A.getAsDecl());
966 break;
967 case TemplateArgument::NullPtr:
968 OS << " nullptr";
969 break;
970 case TemplateArgument::Integral:
971 OS << " integral " << A.getAsIntegral();
972 break;
973 case TemplateArgument::Template:
974 OS << " template ";
975 A.getAsTemplate().dump(OS);
976 break;
977 case TemplateArgument::TemplateExpansion:
978 OS << " template expansion";
979 A.getAsTemplateOrTemplatePattern().dump(OS);
980 break;
981 case TemplateArgument::Expression:
982 OS << " expr";
983 dumpStmt(A.getAsExpr());
984 break;
985 case TemplateArgument::Pack:
986 OS << " pack";
987 for (TemplateArgument::pack_iterator I = A.pack_begin(), E = A.pack_end();
988 I != E; ++I)
989 dumpTemplateArgument(*I);
990 break;
Richard Trieude5cc7d2013-01-31 01:44:26 +0000991 }
Richard Smithf7514452014-10-30 21:02:37 +0000992 });
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000993}
994
Chris Lattner11e30d32007-08-30 06:17:34 +0000995//===----------------------------------------------------------------------===//
Douglas Gregor85f3f952015-07-07 03:57:15 +0000996// Objective-C Utilities
997//===----------------------------------------------------------------------===//
998void ASTDumper::dumpObjCTypeParamList(const ObjCTypeParamList *typeParams) {
999 if (!typeParams)
1000 return;
1001
1002 for (auto typeParam : *typeParams) {
1003 dumpDecl(typeParam);
1004 }
1005}
1006
1007//===----------------------------------------------------------------------===//
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001008// Decl dumping methods.
Chris Lattnercbe4f772007-08-08 22:51:59 +00001009//===----------------------------------------------------------------------===//
1010
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001011void ASTDumper::dumpDecl(const Decl *D) {
Richard Smithf7514452014-10-30 21:02:37 +00001012 dumpChild([=] {
1013 if (!D) {
1014 ColorScope Color(*this, NullColor);
1015 OS << "<<<NULL>>>";
1016 return;
1017 }
Mike Stump11289f42009-09-09 15:08:12 +00001018
Richard Smithf7514452014-10-30 21:02:37 +00001019 {
1020 ColorScope Color(*this, DeclKindNameColor);
1021 OS << D->getDeclKindName() << "Decl";
1022 }
1023 dumpPointer(D);
1024 if (D->getLexicalDeclContext() != D->getDeclContext())
1025 OS << " parent " << cast<Decl>(D->getDeclContext());
1026 dumpPreviousDecl(OS, D);
1027 dumpSourceRange(D->getSourceRange());
1028 OS << ' ';
1029 dumpLocation(D->getLocation());
Richard Smith42413142015-05-15 20:05:43 +00001030 if (Module *M = D->getImportedOwningModule())
Richard Smithf7514452014-10-30 21:02:37 +00001031 OS << " in " << M->getFullModuleName();
Richard Smith42413142015-05-15 20:05:43 +00001032 else if (Module *M = D->getLocalOwningModule())
1033 OS << " in (local) " << M->getFullModuleName();
Richard Smitha2eb4092015-06-22 18:47:01 +00001034 if (auto *ND = dyn_cast<NamedDecl>(D))
1035 for (Module *M : D->getASTContext().getModulesWithMergedDefinition(
1036 const_cast<NamedDecl *>(ND)))
1037 dumpChild([=] { OS << "also in " << M->getFullModuleName(); });
Richard Smithf7514452014-10-30 21:02:37 +00001038 if (const NamedDecl *ND = dyn_cast<NamedDecl>(D))
1039 if (ND->isHidden())
1040 OS << " hidden";
1041 if (D->isImplicit())
1042 OS << " implicit";
1043 if (D->isUsed())
1044 OS << " used";
1045 else if (D->isThisDeclarationReferenced())
1046 OS << " referenced";
1047 if (D->isInvalidDecl())
1048 OS << " invalid";
Hans Wennborg76b00532014-12-05 22:38:57 +00001049 if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
1050 if (FD->isConstexpr())
1051 OS << " constexpr";
1052
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001053
Richard Smithf7514452014-10-30 21:02:37 +00001054 ConstDeclVisitor<ASTDumper>::Visit(D);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001055
Richard Smithf7514452014-10-30 21:02:37 +00001056 for (Decl::attr_iterator I = D->attr_begin(), E = D->attr_end(); I != E;
1057 ++I)
1058 dumpAttr(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001059
Richard Smithf7514452014-10-30 21:02:37 +00001060 if (const FullComment *Comment =
1061 D->getASTContext().getLocalCommentForDeclUncached(D))
1062 dumpFullComment(Comment);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001063
Richard Smithf7514452014-10-30 21:02:37 +00001064 // Decls within functions are visited by the body.
1065 if (!isa<FunctionDecl>(*D) && !isa<ObjCMethodDecl>(*D) &&
1066 hasNodes(dyn_cast<DeclContext>(D)))
1067 dumpDeclContext(cast<DeclContext>(D));
1068 });
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001069}
1070
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001071void ASTDumper::VisitLabelDecl(const LabelDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001072 dumpName(D);
1073}
1074
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001075void ASTDumper::VisitTypedefDecl(const TypedefDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001076 dumpName(D);
1077 dumpType(D->getUnderlyingType());
1078 if (D->isModulePrivate())
1079 OS << " __module_private__";
Richard Smithba3a4f92016-01-12 21:59:26 +00001080 dumpTypeAsChild(D->getUnderlyingType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001081}
1082
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001083void ASTDumper::VisitEnumDecl(const EnumDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001084 if (D->isScoped()) {
1085 if (D->isScopedUsingClassTag())
1086 OS << " class";
1087 else
1088 OS << " struct";
1089 }
1090 dumpName(D);
1091 if (D->isModulePrivate())
1092 OS << " __module_private__";
1093 if (D->isFixed())
1094 dumpType(D->getIntegerType());
1095}
1096
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001097void ASTDumper::VisitRecordDecl(const RecordDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001098 OS << ' ' << D->getKindName();
1099 dumpName(D);
1100 if (D->isModulePrivate())
1101 OS << " __module_private__";
Richard Smith99bc1b92013-08-30 05:32:29 +00001102 if (D->isCompleteDefinition())
1103 OS << " definition";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001104}
1105
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001106void ASTDumper::VisitEnumConstantDecl(const EnumConstantDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001107 dumpName(D);
1108 dumpType(D->getType());
Richard Smithf7514452014-10-30 21:02:37 +00001109 if (const Expr *Init = D->getInitExpr())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001110 dumpStmt(Init);
1111}
1112
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001113void ASTDumper::VisitIndirectFieldDecl(const IndirectFieldDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001114 dumpName(D);
1115 dumpType(D->getType());
Richard Smithdcc2c452014-03-17 23:00:06 +00001116
Richard Smith8aa49222014-03-18 00:35:12 +00001117 for (auto *Child : D->chain())
Richard Smithf7514452014-10-30 21:02:37 +00001118 dumpDeclRef(Child);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001119}
1120
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001121void ASTDumper::VisitFunctionDecl(const FunctionDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001122 dumpName(D);
1123 dumpType(D->getType());
1124
Rafael Espindola6ae7e502013-04-03 19:27:57 +00001125 StorageClass SC = D->getStorageClass();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001126 if (SC != SC_None)
1127 OS << ' ' << VarDecl::getStorageClassSpecifierString(SC);
1128 if (D->isInlineSpecified())
1129 OS << " inline";
1130 if (D->isVirtualAsWritten())
1131 OS << " virtual";
1132 if (D->isModulePrivate())
1133 OS << " __module_private__";
1134
1135 if (D->isPure())
1136 OS << " pure";
1137 else if (D->isDeletedAsWritten())
1138 OS << " delete";
1139
Richard Smithadaa0152013-05-17 02:09:46 +00001140 if (const FunctionProtoType *FPT = D->getType()->getAs<FunctionProtoType>()) {
1141 FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo();
Richard Smith8acb4282014-07-31 21:57:55 +00001142 switch (EPI.ExceptionSpec.Type) {
Richard Smithadaa0152013-05-17 02:09:46 +00001143 default: break;
1144 case EST_Unevaluated:
Richard Smith8acb4282014-07-31 21:57:55 +00001145 OS << " noexcept-unevaluated " << EPI.ExceptionSpec.SourceDecl;
Richard Smithadaa0152013-05-17 02:09:46 +00001146 break;
1147 case EST_Uninstantiated:
Richard Smith8acb4282014-07-31 21:57:55 +00001148 OS << " noexcept-uninstantiated " << EPI.ExceptionSpec.SourceTemplate;
Richard Smithadaa0152013-05-17 02:09:46 +00001149 break;
1150 }
1151 }
1152
Richard Smithf7514452014-10-30 21:02:37 +00001153 if (const FunctionTemplateSpecializationInfo *FTSI =
1154 D->getTemplateSpecializationInfo())
Richard Trieude5cc7d2013-01-31 01:44:26 +00001155 dumpTemplateArgumentList(*FTSI->TemplateArguments);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001156
Dmitri Gribenkof8579502013-01-12 19:30:44 +00001157 for (ArrayRef<NamedDecl *>::iterator
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001158 I = D->getDeclsInPrototypeScope().begin(),
Richard Smithf7514452014-10-30 21:02:37 +00001159 E = D->getDeclsInPrototypeScope().end(); I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001160 dumpDecl(*I);
1161
Richard Smith8a639892015-01-24 01:07:20 +00001162 if (!D->param_begin() && D->getNumParams())
1163 dumpChild([=] { OS << "<<NULL params x " << D->getNumParams() << ">>"; });
1164 else
David Majnemera3debed2016-06-24 05:33:44 +00001165 for (const ParmVarDecl *Parameter : D->parameters())
1166 dumpDecl(Parameter);
Richard Smithf7514452014-10-30 21:02:37 +00001167
1168 if (const CXXConstructorDecl *C = dyn_cast<CXXConstructorDecl>(D))
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001169 for (CXXConstructorDecl::init_const_iterator I = C->init_begin(),
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001170 E = C->init_end();
Richard Smithf7514452014-10-30 21:02:37 +00001171 I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001172 dumpCXXCtorInitializer(*I);
1173
Richard Smithf7514452014-10-30 21:02:37 +00001174 if (D->doesThisDeclarationHaveABody())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001175 dumpStmt(D->getBody());
1176}
1177
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001178void ASTDumper::VisitFieldDecl(const FieldDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001179 dumpName(D);
1180 dumpType(D->getType());
1181 if (D->isMutable())
1182 OS << " mutable";
1183 if (D->isModulePrivate())
1184 OS << " __module_private__";
Richard Trieude5cc7d2013-01-31 01:44:26 +00001185
Richard Smithf7514452014-10-30 21:02:37 +00001186 if (D->isBitField())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001187 dumpStmt(D->getBitWidth());
Richard Smithf7514452014-10-30 21:02:37 +00001188 if (Expr *Init = D->getInClassInitializer())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001189 dumpStmt(Init);
1190}
1191
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001192void ASTDumper::VisitVarDecl(const VarDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001193 dumpName(D);
1194 dumpType(D->getType());
Rafael Espindola6ae7e502013-04-03 19:27:57 +00001195 StorageClass SC = D->getStorageClass();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001196 if (SC != SC_None)
1197 OS << ' ' << VarDecl::getStorageClassSpecifierString(SC);
Richard Smithfd3834f2013-04-13 02:43:54 +00001198 switch (D->getTLSKind()) {
1199 case VarDecl::TLS_None: break;
1200 case VarDecl::TLS_Static: OS << " tls"; break;
1201 case VarDecl::TLS_Dynamic: OS << " tls_dynamic"; break;
1202 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001203 if (D->isModulePrivate())
1204 OS << " __module_private__";
1205 if (D->isNRVOVariable())
1206 OS << " nrvo";
Richard Smith62f19e72016-06-25 00:15:56 +00001207 if (D->isInline())
1208 OS << " inline";
1209 if (D->isConstexpr())
1210 OS << " constexpr";
Richard Trieude5cc7d2013-01-31 01:44:26 +00001211 if (D->hasInit()) {
Richard Smithd9967cc2014-07-10 22:54:03 +00001212 switch (D->getInitStyle()) {
1213 case VarDecl::CInit: OS << " cinit"; break;
1214 case VarDecl::CallInit: OS << " callinit"; break;
1215 case VarDecl::ListInit: OS << " listinit"; break;
1216 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001217 dumpStmt(D->getInit());
Richard Trieude5cc7d2013-01-31 01:44:26 +00001218 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001219}
1220
Richard Smithbdb84f32016-07-22 23:36:59 +00001221void ASTDumper::VisitDecompositionDecl(const DecompositionDecl *D) {
1222 VisitVarDecl(D);
1223 for (auto *B : D->bindings())
1224 dumpDecl(B);
1225}
1226
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001227void ASTDumper::VisitFileScopeAsmDecl(const FileScopeAsmDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001228 dumpStmt(D->getAsmString());
1229}
1230
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001231void ASTDumper::VisitImportDecl(const ImportDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001232 OS << ' ' << D->getImportedModule()->getFullModuleName();
1233}
1234
Nico Weber66220292016-03-02 17:28:48 +00001235void ASTDumper::VisitPragmaCommentDecl(const PragmaCommentDecl *D) {
1236 OS << ' ';
1237 switch (D->getCommentKind()) {
1238 case PCK_Unknown: llvm_unreachable("unexpected pragma comment kind");
1239 case PCK_Compiler: OS << "compiler"; break;
1240 case PCK_ExeStr: OS << "exestr"; break;
1241 case PCK_Lib: OS << "lib"; break;
1242 case PCK_Linker: OS << "linker"; break;
1243 case PCK_User: OS << "user"; break;
1244 }
1245 StringRef Arg = D->getArg();
1246 if (!Arg.empty())
1247 OS << " \"" << Arg << "\"";
1248}
1249
Nico Webercbbaeb12016-03-02 19:28:54 +00001250void ASTDumper::VisitPragmaDetectMismatchDecl(
1251 const PragmaDetectMismatchDecl *D) {
1252 OS << " \"" << D->getName() << "\" \"" << D->getValue() << "\"";
1253}
1254
Alexey Bataev958b9e72016-03-31 09:30:50 +00001255void ASTDumper::VisitCapturedDecl(const CapturedDecl *D) {
1256 dumpStmt(D->getBody());
1257}
1258
1259//===----------------------------------------------------------------------===//
1260// OpenMP Declarations
1261//===----------------------------------------------------------------------===//
1262
1263void ASTDumper::VisitOMPThreadPrivateDecl(const OMPThreadPrivateDecl *D) {
1264 for (auto *E : D->varlists())
1265 dumpStmt(E);
1266}
1267
1268void ASTDumper::VisitOMPDeclareReductionDecl(const OMPDeclareReductionDecl *D) {
1269 dumpName(D);
1270 dumpType(D->getType());
1271 OS << " combiner";
1272 dumpStmt(D->getCombiner());
1273 if (auto *Initializer = D->getInitializer()) {
1274 OS << " initializer";
1275 dumpStmt(Initializer);
1276 }
1277}
1278
1279void ASTDumper::VisitOMPCapturedExprDecl(const OMPCapturedExprDecl *D) {
1280 dumpName(D);
1281 dumpType(D->getType());
1282 dumpStmt(D->getInit());
1283}
Nico Webercbbaeb12016-03-02 19:28:54 +00001284
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001285//===----------------------------------------------------------------------===//
1286// C++ Declarations
1287//===----------------------------------------------------------------------===//
1288
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001289void ASTDumper::VisitNamespaceDecl(const NamespaceDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001290 dumpName(D);
1291 if (D->isInline())
1292 OS << " inline";
1293 if (!D->isOriginalNamespace())
1294 dumpDeclRef(D->getOriginalNamespace(), "original");
1295}
1296
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001297void ASTDumper::VisitUsingDirectiveDecl(const UsingDirectiveDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001298 OS << ' ';
1299 dumpBareDeclRef(D->getNominatedNamespace());
1300}
1301
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001302void ASTDumper::VisitNamespaceAliasDecl(const NamespaceAliasDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001303 dumpName(D);
1304 dumpDeclRef(D->getAliasedNamespace());
1305}
1306
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001307void ASTDumper::VisitTypeAliasDecl(const TypeAliasDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001308 dumpName(D);
1309 dumpType(D->getUnderlyingType());
Richard Smithba3a4f92016-01-12 21:59:26 +00001310 dumpTypeAsChild(D->getUnderlyingType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001311}
1312
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001313void ASTDumper::VisitTypeAliasTemplateDecl(const TypeAliasTemplateDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001314 dumpName(D);
1315 dumpTemplateParameters(D->getTemplateParameters());
1316 dumpDecl(D->getTemplatedDecl());
1317}
1318
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001319void ASTDumper::VisitCXXRecordDecl(const CXXRecordDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001320 VisitRecordDecl(D);
1321 if (!D->isCompleteDefinition())
1322 return;
1323
Aaron Ballman574705e2014-03-13 15:41:46 +00001324 for (const auto &I : D->bases()) {
Richard Smithf7514452014-10-30 21:02:37 +00001325 dumpChild([=] {
1326 if (I.isVirtual())
1327 OS << "virtual ";
1328 dumpAccessSpecifier(I.getAccessSpecifier());
1329 dumpType(I.getType());
1330 if (I.isPackExpansion())
1331 OS << "...";
1332 });
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001333 }
1334}
1335
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001336void ASTDumper::VisitStaticAssertDecl(const StaticAssertDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001337 dumpStmt(D->getAssertExpr());
1338 dumpStmt(D->getMessage());
1339}
1340
Richard Smithcbdf7332014-03-18 02:07:28 +00001341template<typename SpecializationDecl>
Richard Smithf7514452014-10-30 21:02:37 +00001342void ASTDumper::VisitTemplateDeclSpecialization(const SpecializationDecl *D,
Richard Smithcbdf7332014-03-18 02:07:28 +00001343 bool DumpExplicitInst,
1344 bool DumpRefOnly) {
1345 bool DumpedAny = false;
1346 for (auto *RedeclWithBadType : D->redecls()) {
1347 // FIXME: The redecls() range sometimes has elements of a less-specific
1348 // type. (In particular, ClassTemplateSpecializationDecl::redecls() gives
1349 // us TagDecls, and should give CXXRecordDecls).
1350 auto *Redecl = dyn_cast<SpecializationDecl>(RedeclWithBadType);
1351 if (!Redecl) {
1352 // Found the injected-class-name for a class template. This will be dumped
1353 // as part of its surrounding class so we don't need to dump it here.
1354 assert(isa<CXXRecordDecl>(RedeclWithBadType) &&
1355 "expected an injected-class-name");
1356 continue;
1357 }
1358
1359 switch (Redecl->getTemplateSpecializationKind()) {
1360 case TSK_ExplicitInstantiationDeclaration:
1361 case TSK_ExplicitInstantiationDefinition:
1362 if (!DumpExplicitInst)
1363 break;
1364 // Fall through.
1365 case TSK_Undeclared:
1366 case TSK_ImplicitInstantiation:
Richard Smithf7514452014-10-30 21:02:37 +00001367 if (DumpRefOnly)
1368 dumpDeclRef(Redecl);
1369 else
1370 dumpDecl(Redecl);
Richard Smithcbdf7332014-03-18 02:07:28 +00001371 DumpedAny = true;
1372 break;
1373 case TSK_ExplicitSpecialization:
1374 break;
1375 }
1376 }
1377
1378 // Ensure we dump at least one decl for each specialization.
1379 if (!DumpedAny)
Richard Smithf7514452014-10-30 21:02:37 +00001380 dumpDeclRef(D);
Richard Smithcbdf7332014-03-18 02:07:28 +00001381}
1382
Richard Smith20ade552014-03-17 23:34:53 +00001383template<typename TemplateDecl>
1384void ASTDumper::VisitTemplateDecl(const TemplateDecl *D,
1385 bool DumpExplicitInst) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001386 dumpName(D);
1387 dumpTemplateParameters(D->getTemplateParameters());
Richard Smithdcc2c452014-03-17 23:00:06 +00001388
Richard Smithf7514452014-10-30 21:02:37 +00001389 dumpDecl(D->getTemplatedDecl());
Richard Smithdcc2c452014-03-17 23:00:06 +00001390
Richard Smithcbdf7332014-03-18 02:07:28 +00001391 for (auto *Child : D->specializations())
Richard Smithf7514452014-10-30 21:02:37 +00001392 VisitTemplateDeclSpecialization(Child, DumpExplicitInst,
Richard Smithcbdf7332014-03-18 02:07:28 +00001393 !D->isCanonicalDecl());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001394}
1395
Richard Smith20ade552014-03-17 23:34:53 +00001396void ASTDumper::VisitFunctionTemplateDecl(const FunctionTemplateDecl *D) {
1397 // FIXME: We don't add a declaration of a function template specialization
1398 // to its context when it's explicitly instantiated, so dump explicit
1399 // instantiations when we dump the template itself.
1400 VisitTemplateDecl(D, true);
1401}
1402
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001403void ASTDumper::VisitClassTemplateDecl(const ClassTemplateDecl *D) {
Richard Smith20ade552014-03-17 23:34:53 +00001404 VisitTemplateDecl(D, false);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001405}
1406
1407void ASTDumper::VisitClassTemplateSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001408 const ClassTemplateSpecializationDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001409 VisitCXXRecordDecl(D);
1410 dumpTemplateArgumentList(D->getTemplateArgs());
1411}
1412
1413void ASTDumper::VisitClassTemplatePartialSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001414 const ClassTemplatePartialSpecializationDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001415 VisitClassTemplateSpecializationDecl(D);
1416 dumpTemplateParameters(D->getTemplateParameters());
1417}
1418
1419void ASTDumper::VisitClassScopeFunctionSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001420 const ClassScopeFunctionSpecializationDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001421 dumpDeclRef(D->getSpecialization());
1422 if (D->hasExplicitTemplateArgs())
1423 dumpTemplateArgumentListInfo(D->templateArgs());
1424}
1425
Richard Smithd25789a2013-09-18 01:36:02 +00001426void ASTDumper::VisitVarTemplateDecl(const VarTemplateDecl *D) {
Richard Smith20ade552014-03-17 23:34:53 +00001427 VisitTemplateDecl(D, false);
Richard Smithd25789a2013-09-18 01:36:02 +00001428}
1429
David Majnemerd9b1a4f2015-11-04 03:40:30 +00001430void ASTDumper::VisitBuiltinTemplateDecl(const BuiltinTemplateDecl *D) {
1431 dumpName(D);
1432 dumpTemplateParameters(D->getTemplateParameters());
1433}
1434
Richard Smithd25789a2013-09-18 01:36:02 +00001435void ASTDumper::VisitVarTemplateSpecializationDecl(
1436 const VarTemplateSpecializationDecl *D) {
1437 dumpTemplateArgumentList(D->getTemplateArgs());
1438 VisitVarDecl(D);
1439}
1440
1441void ASTDumper::VisitVarTemplatePartialSpecializationDecl(
1442 const VarTemplatePartialSpecializationDecl *D) {
1443 dumpTemplateParameters(D->getTemplateParameters());
1444 VisitVarTemplateSpecializationDecl(D);
1445}
1446
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001447void ASTDumper::VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001448 if (D->wasDeclaredWithTypename())
1449 OS << " typename";
1450 else
1451 OS << " class";
1452 if (D->isParameterPack())
1453 OS << " ...";
1454 dumpName(D);
Richard Smithf7514452014-10-30 21:02:37 +00001455 if (D->hasDefaultArgument())
Richard Smithecf74ff2014-03-23 20:50:39 +00001456 dumpTemplateArgument(D->getDefaultArgument());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001457}
1458
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001459void ASTDumper::VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001460 dumpType(D->getType());
1461 if (D->isParameterPack())
1462 OS << " ...";
1463 dumpName(D);
Richard Smithf7514452014-10-30 21:02:37 +00001464 if (D->hasDefaultArgument())
Richard Smithecf74ff2014-03-23 20:50:39 +00001465 dumpTemplateArgument(D->getDefaultArgument());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001466}
1467
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001468void ASTDumper::VisitTemplateTemplateParmDecl(
1469 const TemplateTemplateParmDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001470 if (D->isParameterPack())
1471 OS << " ...";
1472 dumpName(D);
1473 dumpTemplateParameters(D->getTemplateParameters());
Richard Smithf7514452014-10-30 21:02:37 +00001474 if (D->hasDefaultArgument())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001475 dumpTemplateArgumentLoc(D->getDefaultArgument());
1476}
1477
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001478void ASTDumper::VisitUsingDecl(const UsingDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001479 OS << ' ';
Dawn Perchikddd03bf2015-12-05 22:37:55 +00001480 if (D->getQualifier())
1481 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001482 OS << D->getNameAsString();
1483}
1484
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001485void ASTDumper::VisitUnresolvedUsingTypenameDecl(
1486 const UnresolvedUsingTypenameDecl *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::VisitUnresolvedUsingValueDecl(const UnresolvedUsingValueDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001494 OS << ' ';
Dawn Perchikddd03bf2015-12-05 22:37:55 +00001495 if (D->getQualifier())
1496 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001497 OS << D->getNameAsString();
1498 dumpType(D->getType());
1499}
1500
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001501void ASTDumper::VisitUsingShadowDecl(const UsingShadowDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001502 OS << ' ';
1503 dumpBareDeclRef(D->getTargetDecl());
Richard Smithba3a4f92016-01-12 21:59:26 +00001504 if (auto *TD = dyn_cast<TypeDecl>(D->getUnderlyingDecl()))
1505 dumpTypeAsChild(TD->getTypeForDecl());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001506}
1507
Richard Smith5179eb72016-06-28 19:03:57 +00001508void ASTDumper::VisitConstructorUsingShadowDecl(
1509 const ConstructorUsingShadowDecl *D) {
1510 if (D->constructsVirtualBase())
1511 OS << " virtual";
1512
1513 dumpChild([=] {
1514 OS << "target ";
1515 dumpBareDeclRef(D->getTargetDecl());
1516 });
1517
1518 dumpChild([=] {
1519 OS << "nominated ";
1520 dumpBareDeclRef(D->getNominatedBaseClass());
1521 OS << ' ';
1522 dumpBareDeclRef(D->getNominatedBaseClassShadowDecl());
1523 });
1524
1525 dumpChild([=] {
1526 OS << "constructed ";
1527 dumpBareDeclRef(D->getConstructedBaseClass());
1528 OS << ' ';
1529 dumpBareDeclRef(D->getConstructedBaseClassShadowDecl());
1530 });
1531}
1532
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001533void ASTDumper::VisitLinkageSpecDecl(const LinkageSpecDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001534 switch (D->getLanguage()) {
1535 case LinkageSpecDecl::lang_c: OS << " C"; break;
1536 case LinkageSpecDecl::lang_cxx: OS << " C++"; break;
1537 }
1538}
1539
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001540void ASTDumper::VisitAccessSpecDecl(const AccessSpecDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001541 OS << ' ';
1542 dumpAccessSpecifier(D->getAccess());
1543}
1544
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001545void ASTDumper::VisitFriendDecl(const FriendDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001546 if (TypeSourceInfo *T = D->getFriendType())
1547 dumpType(T->getType());
1548 else
1549 dumpDecl(D->getFriendDecl());
1550}
1551
1552//===----------------------------------------------------------------------===//
1553// Obj-C Declarations
1554//===----------------------------------------------------------------------===//
1555
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001556void ASTDumper::VisitObjCIvarDecl(const ObjCIvarDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001557 dumpName(D);
1558 dumpType(D->getType());
1559 if (D->getSynthesize())
1560 OS << " synthesize";
1561
1562 switch (D->getAccessControl()) {
1563 case ObjCIvarDecl::None:
1564 OS << " none";
1565 break;
1566 case ObjCIvarDecl::Private:
1567 OS << " private";
1568 break;
1569 case ObjCIvarDecl::Protected:
1570 OS << " protected";
1571 break;
1572 case ObjCIvarDecl::Public:
1573 OS << " public";
1574 break;
1575 case ObjCIvarDecl::Package:
1576 OS << " package";
1577 break;
1578 }
1579}
1580
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001581void ASTDumper::VisitObjCMethodDecl(const ObjCMethodDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001582 if (D->isInstanceMethod())
1583 OS << " -";
1584 else
1585 OS << " +";
1586 dumpName(D);
Alp Toker314cc812014-01-25 16:55:45 +00001587 dumpType(D->getReturnType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001588
Richard Trieude5cc7d2013-01-31 01:44:26 +00001589 if (D->isThisDeclarationADefinition()) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001590 dumpDeclContext(D);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001591 } else {
David Majnemera3debed2016-06-24 05:33:44 +00001592 for (const ParmVarDecl *Parameter : D->parameters())
1593 dumpDecl(Parameter);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001594 }
1595
Richard Smithf7514452014-10-30 21:02:37 +00001596 if (D->isVariadic())
1597 dumpChild([=] { OS << "..."; });
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001598
Richard Smithf7514452014-10-30 21:02:37 +00001599 if (D->hasBody())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001600 dumpStmt(D->getBody());
1601}
1602
Douglas Gregor85f3f952015-07-07 03:57:15 +00001603void ASTDumper::VisitObjCTypeParamDecl(const ObjCTypeParamDecl *D) {
1604 dumpName(D);
Douglas Gregor1ac1b632015-07-07 03:58:54 +00001605 switch (D->getVariance()) {
1606 case ObjCTypeParamVariance::Invariant:
1607 break;
1608
1609 case ObjCTypeParamVariance::Covariant:
1610 OS << " covariant";
1611 break;
1612
1613 case ObjCTypeParamVariance::Contravariant:
1614 OS << " contravariant";
1615 break;
1616 }
1617
Douglas Gregor85f3f952015-07-07 03:57:15 +00001618 if (D->hasExplicitBound())
1619 OS << " bounded";
1620 dumpType(D->getUnderlyingType());
1621}
1622
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001623void ASTDumper::VisitObjCCategoryDecl(const ObjCCategoryDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001624 dumpName(D);
1625 dumpDeclRef(D->getClassInterface());
Douglas Gregor85f3f952015-07-07 03:57:15 +00001626 dumpObjCTypeParamList(D->getTypeParamList());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001627 dumpDeclRef(D->getImplementation());
1628 for (ObjCCategoryDecl::protocol_iterator I = D->protocol_begin(),
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001629 E = D->protocol_end();
Richard Smithf7514452014-10-30 21:02:37 +00001630 I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001631 dumpDeclRef(*I);
1632}
1633
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001634void ASTDumper::VisitObjCCategoryImplDecl(const ObjCCategoryImplDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001635 dumpName(D);
1636 dumpDeclRef(D->getClassInterface());
1637 dumpDeclRef(D->getCategoryDecl());
1638}
1639
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001640void ASTDumper::VisitObjCProtocolDecl(const ObjCProtocolDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001641 dumpName(D);
Richard Smithdcc2c452014-03-17 23:00:06 +00001642
Richard Smith7fcb35f2014-03-18 02:37:59 +00001643 for (auto *Child : D->protocols())
Richard Smithf7514452014-10-30 21:02:37 +00001644 dumpDeclRef(Child);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001645}
1646
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001647void ASTDumper::VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001648 dumpName(D);
Douglas Gregor85f3f952015-07-07 03:57:15 +00001649 dumpObjCTypeParamList(D->getTypeParamListAsWritten());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001650 dumpDeclRef(D->getSuperClass(), "super");
Richard Smithdcc2c452014-03-17 23:00:06 +00001651
Richard Smithf7514452014-10-30 21:02:37 +00001652 dumpDeclRef(D->getImplementation());
Richard Smith7fcb35f2014-03-18 02:37:59 +00001653 for (auto *Child : D->protocols())
Richard Smithf7514452014-10-30 21:02:37 +00001654 dumpDeclRef(Child);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001655}
1656
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001657void ASTDumper::VisitObjCImplementationDecl(const ObjCImplementationDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001658 dumpName(D);
1659 dumpDeclRef(D->getSuperClass(), "super");
1660 dumpDeclRef(D->getClassInterface());
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001661 for (ObjCImplementationDecl::init_const_iterator I = D->init_begin(),
1662 E = D->init_end();
Richard Smithf7514452014-10-30 21:02:37 +00001663 I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001664 dumpCXXCtorInitializer(*I);
1665}
1666
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001667void ASTDumper::VisitObjCCompatibleAliasDecl(const ObjCCompatibleAliasDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001668 dumpName(D);
1669 dumpDeclRef(D->getClassInterface());
1670}
1671
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001672void ASTDumper::VisitObjCPropertyDecl(const ObjCPropertyDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001673 dumpName(D);
1674 dumpType(D->getType());
1675
1676 if (D->getPropertyImplementation() == ObjCPropertyDecl::Required)
1677 OS << " required";
1678 else if (D->getPropertyImplementation() == ObjCPropertyDecl::Optional)
1679 OS << " optional";
1680
1681 ObjCPropertyDecl::PropertyAttributeKind Attrs = D->getPropertyAttributes();
1682 if (Attrs != ObjCPropertyDecl::OBJC_PR_noattr) {
1683 if (Attrs & ObjCPropertyDecl::OBJC_PR_readonly)
1684 OS << " readonly";
1685 if (Attrs & ObjCPropertyDecl::OBJC_PR_assign)
1686 OS << " assign";
1687 if (Attrs & ObjCPropertyDecl::OBJC_PR_readwrite)
1688 OS << " readwrite";
1689 if (Attrs & ObjCPropertyDecl::OBJC_PR_retain)
1690 OS << " retain";
1691 if (Attrs & ObjCPropertyDecl::OBJC_PR_copy)
1692 OS << " copy";
1693 if (Attrs & ObjCPropertyDecl::OBJC_PR_nonatomic)
1694 OS << " nonatomic";
1695 if (Attrs & ObjCPropertyDecl::OBJC_PR_atomic)
1696 OS << " atomic";
1697 if (Attrs & ObjCPropertyDecl::OBJC_PR_weak)
1698 OS << " weak";
1699 if (Attrs & ObjCPropertyDecl::OBJC_PR_strong)
1700 OS << " strong";
1701 if (Attrs & ObjCPropertyDecl::OBJC_PR_unsafe_unretained)
1702 OS << " unsafe_unretained";
Manman Ren387ff7f2016-01-26 18:52:43 +00001703 if (Attrs & ObjCPropertyDecl::OBJC_PR_class)
1704 OS << " class";
Richard Smithf7514452014-10-30 21:02:37 +00001705 if (Attrs & ObjCPropertyDecl::OBJC_PR_getter)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001706 dumpDeclRef(D->getGetterMethodDecl(), "getter");
Richard Smithf7514452014-10-30 21:02:37 +00001707 if (Attrs & ObjCPropertyDecl::OBJC_PR_setter)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001708 dumpDeclRef(D->getSetterMethodDecl(), "setter");
1709 }
1710}
1711
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001712void ASTDumper::VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001713 dumpName(D->getPropertyDecl());
1714 if (D->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize)
1715 OS << " synthesize";
1716 else
1717 OS << " dynamic";
1718 dumpDeclRef(D->getPropertyDecl());
1719 dumpDeclRef(D->getPropertyIvarDecl());
1720}
1721
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001722void ASTDumper::VisitBlockDecl(const BlockDecl *D) {
David Majnemer59f77922016-06-24 04:05:48 +00001723 for (auto I : D->parameters())
Aaron Ballmanb2b8b1d2014-03-07 16:09:59 +00001724 dumpDecl(I);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001725
Richard Smithf7514452014-10-30 21:02:37 +00001726 if (D->isVariadic())
1727 dumpChild([=]{ OS << "..."; });
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001728
Richard Smithf7514452014-10-30 21:02:37 +00001729 if (D->capturesCXXThis())
1730 dumpChild([=]{ OS << "capture this"; });
1731
Aaron Ballman9371dd22014-03-14 18:34:04 +00001732 for (const auto &I : D->captures()) {
Richard Smithf7514452014-10-30 21:02:37 +00001733 dumpChild([=] {
1734 OS << "capture";
1735 if (I.isByRef())
1736 OS << " byref";
1737 if (I.isNested())
1738 OS << " nested";
1739 if (I.getVariable()) {
1740 OS << ' ';
1741 dumpBareDeclRef(I.getVariable());
1742 }
1743 if (I.hasCopyExpr())
1744 dumpStmt(I.getCopyExpr());
1745 });
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001746 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001747 dumpStmt(D->getBody());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001748}
1749
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001750//===----------------------------------------------------------------------===//
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001751// Stmt dumping methods.
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001752//===----------------------------------------------------------------------===//
1753
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001754void ASTDumper::dumpStmt(const Stmt *S) {
Richard Smithf7514452014-10-30 21:02:37 +00001755 dumpChild([=] {
1756 if (!S) {
1757 ColorScope Color(*this, NullColor);
1758 OS << "<<<NULL>>>";
1759 return;
1760 }
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001761
Richard Smithf7514452014-10-30 21:02:37 +00001762 if (const DeclStmt *DS = dyn_cast<DeclStmt>(S)) {
1763 VisitDeclStmt(DS);
1764 return;
1765 }
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001766
Richard Smithf7514452014-10-30 21:02:37 +00001767 ConstStmtVisitor<ASTDumper>::Visit(S);
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001768
Benjamin Kramer642f1732015-07-02 21:03:14 +00001769 for (const Stmt *SubStmt : S->children())
1770 dumpStmt(SubStmt);
Richard Smithf7514452014-10-30 21:02:37 +00001771 });
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001772}
1773
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001774void ASTDumper::VisitStmt(const Stmt *Node) {
Richard Trieud215b8d2013-01-26 01:31:20 +00001775 {
1776 ColorScope Color(*this, StmtColor);
1777 OS << Node->getStmtClassName();
1778 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001779 dumpPointer(Node);
1780 dumpSourceRange(Node->getSourceRange());
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001781}
1782
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001783void ASTDumper::VisitDeclStmt(const DeclStmt *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001784 VisitStmt(Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001785 for (DeclStmt::const_decl_iterator I = Node->decl_begin(),
1786 E = Node->decl_end();
Richard Smithf7514452014-10-30 21:02:37 +00001787 I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001788 dumpDecl(*I);
Ted Kremenek433a4922007-12-12 06:59:42 +00001789}
1790
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001791void ASTDumper::VisitAttributedStmt(const AttributedStmt *Node) {
Alexander Kornienko5bc364e2013-01-07 17:53:08 +00001792 VisitStmt(Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001793 for (ArrayRef<const Attr *>::iterator I = Node->getAttrs().begin(),
1794 E = Node->getAttrs().end();
Richard Smithf7514452014-10-30 21:02:37 +00001795 I != E; ++I)
Alexander Kornienko5bc364e2013-01-07 17:53:08 +00001796 dumpAttr(*I);
1797}
1798
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001799void ASTDumper::VisitLabelStmt(const LabelStmt *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001800 VisitStmt(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001801 OS << " '" << Node->getName() << "'";
Chris Lattnercbe4f772007-08-08 22:51:59 +00001802}
1803
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001804void ASTDumper::VisitGotoStmt(const GotoStmt *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001805 VisitStmt(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001806 OS << " '" << Node->getLabel()->getName() << "'";
1807 dumpPointer(Node->getLabel());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001808}
1809
Pavel Labath1ef83422013-09-04 14:35:00 +00001810void ASTDumper::VisitCXXCatchStmt(const CXXCatchStmt *Node) {
1811 VisitStmt(Node);
1812 dumpDecl(Node->getExceptionDecl());
1813}
1814
Alexey Bataev958b9e72016-03-31 09:30:50 +00001815void ASTDumper::VisitCapturedStmt(const CapturedStmt *Node) {
1816 VisitStmt(Node);
1817 dumpDecl(Node->getCapturedDecl());
1818}
1819
1820//===----------------------------------------------------------------------===//
1821// OpenMP dumping methods.
1822//===----------------------------------------------------------------------===//
1823
1824void ASTDumper::VisitOMPExecutableDirective(
1825 const OMPExecutableDirective *Node) {
1826 VisitStmt(Node);
1827 for (auto *C : Node->clauses()) {
1828 dumpChild([=] {
1829 if (!C) {
1830 ColorScope Color(*this, NullColor);
1831 OS << "<<<NULL>>> OMPClause";
1832 return;
1833 }
1834 {
1835 ColorScope Color(*this, AttrColor);
1836 StringRef ClauseName(getOpenMPClauseName(C->getClauseKind()));
1837 OS << "OMP" << ClauseName.substr(/*Start=*/0, /*N=*/1).upper()
1838 << ClauseName.drop_front() << "Clause";
1839 }
1840 dumpPointer(C);
1841 dumpSourceRange(SourceRange(C->getLocStart(), C->getLocEnd()));
1842 if (C->isImplicit())
1843 OS << " <implicit>";
1844 for (auto *S : C->children())
1845 dumpStmt(S);
1846 });
1847 }
1848}
1849
Chris Lattnercbe4f772007-08-08 22:51:59 +00001850//===----------------------------------------------------------------------===//
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001851// Expr dumping methods.
Chris Lattnercbe4f772007-08-08 22:51:59 +00001852//===----------------------------------------------------------------------===//
1853
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001854void ASTDumper::VisitExpr(const Expr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001855 VisitStmt(Node);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001856 dumpType(Node->getType());
1857
Richard Trieud215b8d2013-01-26 01:31:20 +00001858 {
1859 ColorScope Color(*this, ValueKindColor);
1860 switch (Node->getValueKind()) {
1861 case VK_RValue:
1862 break;
1863 case VK_LValue:
1864 OS << " lvalue";
1865 break;
1866 case VK_XValue:
1867 OS << " xvalue";
1868 break;
1869 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001870 }
1871
Richard Trieud215b8d2013-01-26 01:31:20 +00001872 {
1873 ColorScope Color(*this, ObjectKindColor);
1874 switch (Node->getObjectKind()) {
1875 case OK_Ordinary:
1876 break;
1877 case OK_BitField:
1878 OS << " bitfield";
1879 break;
1880 case OK_ObjCProperty:
1881 OS << " objcproperty";
1882 break;
1883 case OK_ObjCSubscript:
1884 OS << " objcsubscript";
1885 break;
1886 case OK_VectorComponent:
1887 OS << " vectorcomponent";
1888 break;
1889 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001890 }
Chris Lattnercbe4f772007-08-08 22:51:59 +00001891}
1892
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001893static void dumpBasePath(raw_ostream &OS, const CastExpr *Node) {
John McCallcf142162010-08-07 06:22:56 +00001894 if (Node->path_empty())
Anders Carlssona70cff62010-04-24 19:06:50 +00001895 return;
1896
1897 OS << " (";
1898 bool First = true;
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001899 for (CastExpr::path_const_iterator I = Node->path_begin(),
1900 E = Node->path_end();
1901 I != E; ++I) {
Anders Carlssona70cff62010-04-24 19:06:50 +00001902 const CXXBaseSpecifier *Base = *I;
1903 if (!First)
1904 OS << " -> ";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001905
Anders Carlssona70cff62010-04-24 19:06:50 +00001906 const CXXRecordDecl *RD =
1907 cast<CXXRecordDecl>(Base->getType()->getAs<RecordType>()->getDecl());
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001908
Anders Carlssona70cff62010-04-24 19:06:50 +00001909 if (Base->isVirtual())
1910 OS << "virtual ";
1911 OS << RD->getName();
1912 First = false;
1913 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001914
Anders Carlssona70cff62010-04-24 19:06:50 +00001915 OS << ')';
1916}
1917
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001918void ASTDumper::VisitCastExpr(const CastExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001919 VisitExpr(Node);
Richard Trieud215b8d2013-01-26 01:31:20 +00001920 OS << " <";
1921 {
1922 ColorScope Color(*this, CastColor);
1923 OS << Node->getCastKindName();
1924 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001925 dumpBasePath(OS, Node);
Anders Carlssona70cff62010-04-24 19:06:50 +00001926 OS << ">";
Anders Carlssond7923c62009-08-22 23:33:40 +00001927}
1928
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001929void ASTDumper::VisitDeclRefExpr(const DeclRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001930 VisitExpr(Node);
Ted Kremenek5f64ca82007-09-10 17:32:55 +00001931
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001932 OS << " ";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001933 dumpBareDeclRef(Node->getDecl());
Chandler Carruth8d26bb02011-05-01 23:48:14 +00001934 if (Node->getDecl() != Node->getFoundDecl()) {
1935 OS << " (";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001936 dumpBareDeclRef(Node->getFoundDecl());
Chandler Carruth8d26bb02011-05-01 23:48:14 +00001937 OS << ")";
1938 }
John McCall351762c2011-02-07 10:33:21 +00001939}
1940
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001941void ASTDumper::VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001942 VisitExpr(Node);
John McCall76d09942009-12-11 21:50:11 +00001943 OS << " (";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001944 if (!Node->requiresADL())
1945 OS << "no ";
Benjamin Kramerb11416d2010-04-17 09:33:03 +00001946 OS << "ADL) = '" << Node->getName() << '\'';
John McCall76d09942009-12-11 21:50:11 +00001947
1948 UnresolvedLookupExpr::decls_iterator
1949 I = Node->decls_begin(), E = Node->decls_end();
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001950 if (I == E)
1951 OS << " empty";
John McCall76d09942009-12-11 21:50:11 +00001952 for (; I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001953 dumpPointer(*I);
John McCall76d09942009-12-11 21:50:11 +00001954}
1955
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001956void ASTDumper::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001957 VisitExpr(Node);
Steve Naroff5d5efca2008-03-12 13:19:12 +00001958
Richard Trieud215b8d2013-01-26 01:31:20 +00001959 {
1960 ColorScope Color(*this, DeclKindNameColor);
1961 OS << " " << Node->getDecl()->getDeclKindName() << "Decl";
1962 }
1963 OS << "='" << *Node->getDecl() << "'";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001964 dumpPointer(Node->getDecl());
Steve Naroffb3424a92008-05-23 22:01:24 +00001965 if (Node->isFreeIvar())
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001966 OS << " isFreeIvar";
Steve Naroff5d5efca2008-03-12 13:19:12 +00001967}
1968
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001969void ASTDumper::VisitPredefinedExpr(const PredefinedExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001970 VisitExpr(Node);
Alexey Bataevec474782014-10-09 08:45:04 +00001971 OS << " " << PredefinedExpr::getIdentTypeName(Node->getIdentType());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001972}
1973
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001974void ASTDumper::VisitCharacterLiteral(const CharacterLiteral *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001975 VisitExpr(Node);
Richard Trieud215b8d2013-01-26 01:31:20 +00001976 ColorScope Color(*this, ValueColor);
Richard Trieu364ee422011-11-03 23:56:23 +00001977 OS << " " << Node->getValue();
Chris Lattnercbe4f772007-08-08 22:51:59 +00001978}
1979
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001980void ASTDumper::VisitIntegerLiteral(const IntegerLiteral *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001981 VisitExpr(Node);
Chris Lattnercbe4f772007-08-08 22:51:59 +00001982
1983 bool isSigned = Node->getType()->isSignedIntegerType();
Richard Trieud215b8d2013-01-26 01:31:20 +00001984 ColorScope Color(*this, ValueColor);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001985 OS << " " << Node->getValue().toString(10, isSigned);
Chris Lattnercbe4f772007-08-08 22:51:59 +00001986}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001987
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001988void ASTDumper::VisitFloatingLiteral(const FloatingLiteral *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001989 VisitExpr(Node);
Richard Trieud215b8d2013-01-26 01:31:20 +00001990 ColorScope Color(*this, ValueColor);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001991 OS << " " << Node->getValueAsApproximateDouble();
Chris Lattnercbe4f772007-08-08 22:51:59 +00001992}
Chris Lattner1c20a172007-08-26 03:42:43 +00001993
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001994void ASTDumper::VisitStringLiteral(const StringLiteral *Str) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001995 VisitExpr(Str);
Richard Trieud215b8d2013-01-26 01:31:20 +00001996 ColorScope Color(*this, ValueColor);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001997 OS << " ";
Richard Trieudc355912012-06-13 20:25:24 +00001998 Str->outputString(OS);
Chris Lattnercbe4f772007-08-08 22:51:59 +00001999}
Chris Lattner84ca3762007-08-30 01:00:35 +00002000
Richard Smithf0514962014-06-03 08:24:28 +00002001void ASTDumper::VisitInitListExpr(const InitListExpr *ILE) {
2002 VisitExpr(ILE);
2003 if (auto *Filler = ILE->getArrayFiller()) {
Richard Smithf7514452014-10-30 21:02:37 +00002004 dumpChild([=] {
2005 OS << "array filler";
2006 dumpStmt(Filler);
2007 });
Richard Smithf0514962014-06-03 08:24:28 +00002008 }
2009 if (auto *Field = ILE->getInitializedFieldInUnion()) {
2010 OS << " field ";
2011 dumpBareDeclRef(Field);
2012 }
2013}
2014
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002015void ASTDumper::VisitUnaryOperator(const UnaryOperator *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002016 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002017 OS << " " << (Node->isPostfix() ? "postfix" : "prefix")
2018 << " '" << UnaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
Chris Lattnercbe4f772007-08-08 22:51:59 +00002019}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002020
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002021void ASTDumper::VisitUnaryExprOrTypeTraitExpr(
2022 const UnaryExprOrTypeTraitExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002023 VisitExpr(Node);
Peter Collingbournee190dee2011-03-11 19:24:49 +00002024 switch(Node->getKind()) {
2025 case UETT_SizeOf:
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002026 OS << " sizeof";
Peter Collingbournee190dee2011-03-11 19:24:49 +00002027 break;
2028 case UETT_AlignOf:
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002029 OS << " alignof";
Peter Collingbournee190dee2011-03-11 19:24:49 +00002030 break;
2031 case UETT_VecStep:
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002032 OS << " vec_step";
Peter Collingbournee190dee2011-03-11 19:24:49 +00002033 break;
Alexey Bataev00396512015-07-02 03:40:19 +00002034 case UETT_OpenMPRequiredSimdAlign:
2035 OS << " __builtin_omp_required_simd_align";
2036 break;
Peter Collingbournee190dee2011-03-11 19:24:49 +00002037 }
Sebastian Redl6f282892008-11-11 17:56:53 +00002038 if (Node->isArgumentType())
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002039 dumpType(Node->getArgumentType());
Chris Lattnercbe4f772007-08-08 22:51:59 +00002040}
Chris Lattnerdb3b3ff2007-08-09 17:35:30 +00002041
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002042void ASTDumper::VisitMemberExpr(const MemberExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002043 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002044 OS << " " << (Node->isArrow() ? "->" : ".") << *Node->getMemberDecl();
2045 dumpPointer(Node->getMemberDecl());
Chris Lattnercbe4f772007-08-08 22:51:59 +00002046}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002047
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002048void ASTDumper::VisitExtVectorElementExpr(const ExtVectorElementExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002049 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002050 OS << " " << Node->getAccessor().getNameStart();
Chris Lattnercbe4f772007-08-08 22:51:59 +00002051}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002052
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002053void ASTDumper::VisitBinaryOperator(const BinaryOperator *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002054 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002055 OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
Chris Lattner86928112007-08-25 02:00:02 +00002056}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002057
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002058void ASTDumper::VisitCompoundAssignOperator(
2059 const CompoundAssignOperator *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002060 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002061 OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode())
2062 << "' ComputeLHSTy=";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002063 dumpBareType(Node->getComputationLHSType());
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002064 OS << " ComputeResultTy=";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002065 dumpBareType(Node->getComputationResultType());
Chris Lattnercbe4f772007-08-08 22:51:59 +00002066}
Chris Lattnercbe4f772007-08-08 22:51:59 +00002067
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002068void ASTDumper::VisitBlockExpr(const BlockExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002069 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002070 dumpDecl(Node->getBlockDecl());
John McCall351762c2011-02-07 10:33:21 +00002071}
2072
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002073void ASTDumper::VisitOpaqueValueExpr(const OpaqueValueExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002074 VisitExpr(Node);
John McCallfe96e0b2011-11-06 09:01:30 +00002075
Richard Smithf7514452014-10-30 21:02:37 +00002076 if (Expr *Source = Node->getSourceExpr())
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002077 dumpStmt(Source);
John McCallfe96e0b2011-11-06 09:01:30 +00002078}
2079
Chris Lattnercbe4f772007-08-08 22:51:59 +00002080// GNU extensions.
2081
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002082void ASTDumper::VisitAddrLabelExpr(const AddrLabelExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002083 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002084 OS << " " << Node->getLabel()->getName();
2085 dumpPointer(Node->getLabel());
Chris Lattnercbe4f772007-08-08 22:51:59 +00002086}
2087
Chris Lattner8f184b12007-08-09 18:03:18 +00002088//===----------------------------------------------------------------------===//
2089// C++ Expressions
2090//===----------------------------------------------------------------------===//
Chris Lattnercbe4f772007-08-08 22:51:59 +00002091
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002092void ASTDumper::VisitCXXNamedCastExpr(const CXXNamedCastExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002093 VisitExpr(Node);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002094 OS << " " << Node->getCastName()
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002095 << "<" << Node->getTypeAsWritten().getAsString() << ">"
Anders Carlssona70cff62010-04-24 19:06:50 +00002096 << " <" << Node->getCastKindName();
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002097 dumpBasePath(OS, Node);
Anders Carlssona70cff62010-04-24 19:06:50 +00002098 OS << ">";
Chris Lattnercbe4f772007-08-08 22:51:59 +00002099}
2100
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002101void ASTDumper::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002102 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002103 OS << " " << (Node->getValue() ? "true" : "false");
Chris Lattnercbe4f772007-08-08 22:51:59 +00002104}
2105
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002106void ASTDumper::VisitCXXThisExpr(const CXXThisExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002107 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002108 OS << " this";
Douglas Gregor8ea1f532008-11-04 14:56:14 +00002109}
2110
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002111void ASTDumper::VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002112 VisitExpr(Node);
Eli Friedman29538892011-09-02 17:38:59 +00002113 OS << " functional cast to " << Node->getTypeAsWritten().getAsString()
2114 << " <" << Node->getCastKindName() << ">";
Douglas Gregore200adc2008-10-27 19:41:14 +00002115}
2116
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002117void ASTDumper::VisitCXXConstructExpr(const CXXConstructExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002118 VisitExpr(Node);
John McCalleba90cd2010-02-02 19:03:45 +00002119 CXXConstructorDecl *Ctor = Node->getConstructor();
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002120 dumpType(Ctor->getType());
Anders Carlsson073846832009-08-12 00:21:52 +00002121 if (Node->isElidable())
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002122 OS << " elidable";
John McCall85370042010-08-07 06:38:55 +00002123 if (Node->requiresZeroInitialization())
2124 OS << " zeroing";
Anders Carlsson073846832009-08-12 00:21:52 +00002125}
2126
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002127void ASTDumper::VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002128 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002129 OS << " ";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002130 dumpCXXTemporary(Node->getTemporary());
Anders Carlsson073846832009-08-12 00:21:52 +00002131}
2132
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002133void ASTDumper::VisitCXXNewExpr(const CXXNewExpr *Node) {
2134 VisitExpr(Node);
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002135 if (Node->isGlobalNew())
Reid Kleckner461c0c62015-03-19 18:47:47 +00002136 OS << " global";
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002137 if (Node->isArray())
Reid Kleckner461c0c62015-03-19 18:47:47 +00002138 OS << " array";
2139 if (Node->getOperatorNew()) {
2140 OS << ' ';
2141 dumpBareDeclRef(Node->getOperatorNew());
2142 }
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002143 // We could dump the deallocation function used in case of error, but it's
2144 // usually not that interesting.
2145}
2146
2147void ASTDumper::VisitCXXDeleteExpr(const CXXDeleteExpr *Node) {
2148 VisitExpr(Node);
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002149 if (Node->isGlobalDelete())
Reid Kleckner461c0c62015-03-19 18:47:47 +00002150 OS << " global";
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002151 if (Node->isArrayForm())
Reid Kleckner461c0c62015-03-19 18:47:47 +00002152 OS << " array";
2153 if (Node->getOperatorDelete()) {
2154 OS << ' ';
2155 dumpBareDeclRef(Node->getOperatorDelete());
2156 }
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002157}
2158
Richard Smithe6c01442013-06-05 00:46:14 +00002159void
2160ASTDumper::VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *Node) {
2161 VisitExpr(Node);
2162 if (const ValueDecl *VD = Node->getExtendingDecl()) {
2163 OS << " extended by ";
2164 dumpBareDeclRef(VD);
2165 }
2166}
2167
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002168void ASTDumper::VisitExprWithCleanups(const ExprWithCleanups *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002169 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002170 for (unsigned i = 0, e = Node->getNumObjects(); i != e; ++i)
2171 dumpDeclRef(Node->getObject(i), "cleanup");
Anders Carlsson073846832009-08-12 00:21:52 +00002172}
2173
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002174void ASTDumper::dumpCXXTemporary(const CXXTemporary *Temporary) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002175 OS << "(CXXTemporary";
2176 dumpPointer(Temporary);
2177 OS << ")";
Anders Carlsson073846832009-08-12 00:21:52 +00002178}
2179
Serge Pavlov6b926032015-02-16 19:58:41 +00002180void ASTDumper::VisitSizeOfPackExpr(const SizeOfPackExpr *Node) {
2181 VisitExpr(Node);
2182 dumpPointer(Node->getPack());
2183 dumpName(Node->getPack());
Richard Smithd784e682015-09-23 21:41:42 +00002184 if (Node->isPartiallySubstituted())
2185 for (const auto &A : Node->getPartialArguments())
2186 dumpTemplateArgument(A);
Serge Pavlov6b926032015-02-16 19:58:41 +00002187}
2188
2189
Anders Carlsson76f4a902007-08-21 17:43:55 +00002190//===----------------------------------------------------------------------===//
2191// Obj-C Expressions
2192//===----------------------------------------------------------------------===//
2193
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002194void ASTDumper::VisitObjCMessageExpr(const ObjCMessageExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002195 VisitExpr(Node);
Aaron Ballmanb190f972014-01-03 17:59:55 +00002196 OS << " selector=";
2197 Node->getSelector().print(OS);
Douglas Gregor9a129192010-04-21 00:45:42 +00002198 switch (Node->getReceiverKind()) {
2199 case ObjCMessageExpr::Instance:
2200 break;
2201
2202 case ObjCMessageExpr::Class:
2203 OS << " class=";
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002204 dumpBareType(Node->getClassReceiver());
Douglas Gregor9a129192010-04-21 00:45:42 +00002205 break;
2206
2207 case ObjCMessageExpr::SuperInstance:
2208 OS << " super (instance)";
2209 break;
2210
2211 case ObjCMessageExpr::SuperClass:
2212 OS << " super (class)";
2213 break;
2214 }
Ted Kremenek36748da2008-02-29 22:04:05 +00002215}
2216
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002217void ASTDumper::VisitObjCBoxedExpr(const ObjCBoxedExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002218 VisitExpr(Node);
Richard Trieu4b259c82016-06-09 22:03:04 +00002219 if (auto *BoxingMethod = Node->getBoxingMethod()) {
2220 OS << " selector=";
2221 BoxingMethod->getSelector().print(OS);
2222 }
Argyrios Kyrtzidis9dd40892012-05-10 20:02:31 +00002223}
2224
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002225void ASTDumper::VisitObjCAtCatchStmt(const ObjCAtCatchStmt *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002226 VisitStmt(Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002227 if (const VarDecl *CatchParam = Node->getCatchParamDecl())
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002228 dumpDecl(CatchParam);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002229 else
Douglas Gregor96c79492010-04-23 22:50:49 +00002230 OS << " catch all";
Douglas Gregor96c79492010-04-23 22:50:49 +00002231}
2232
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002233void ASTDumper::VisitObjCEncodeExpr(const ObjCEncodeExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002234 VisitExpr(Node);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002235 dumpType(Node->getEncodedType());
Anders Carlssonc5a81eb2007-08-22 15:14:15 +00002236}
2237
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002238void ASTDumper::VisitObjCSelectorExpr(const ObjCSelectorExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002239 VisitExpr(Node);
Mike Stump11289f42009-09-09 15:08:12 +00002240
Aaron Ballmanb190f972014-01-03 17:59:55 +00002241 OS << " ";
2242 Node->getSelector().print(OS);
Fariborz Jahanian4bef4622007-10-16 20:40:23 +00002243}
2244
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002245void ASTDumper::VisitObjCProtocolExpr(const ObjCProtocolExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002246 VisitExpr(Node);
Mike Stump11289f42009-09-09 15:08:12 +00002247
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002248 OS << ' ' << *Node->getProtocol();
Fariborz Jahaniana32aaef2007-10-17 16:58:11 +00002249}
Daniel Dunbar4b8c6db2008-08-30 05:35:15 +00002250
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002251void ASTDumper::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002252 VisitExpr(Node);
John McCallb7bd14f2010-12-02 01:19:52 +00002253 if (Node->isImplicitProperty()) {
Fariborz Jahanian0f0b3022010-12-22 19:46:35 +00002254 OS << " Kind=MethodRef Getter=\"";
2255 if (Node->getImplicitPropertyGetter())
Aaron Ballmanb190f972014-01-03 17:59:55 +00002256 Node->getImplicitPropertyGetter()->getSelector().print(OS);
Fariborz Jahanian0f0b3022010-12-22 19:46:35 +00002257 else
2258 OS << "(null)";
2259
2260 OS << "\" Setter=\"";
John McCallb7bd14f2010-12-02 01:19:52 +00002261 if (ObjCMethodDecl *Setter = Node->getImplicitPropertySetter())
Aaron Ballmanb190f972014-01-03 17:59:55 +00002262 Setter->getSelector().print(OS);
John McCallb7bd14f2010-12-02 01:19:52 +00002263 else
2264 OS << "(null)";
2265 OS << "\"";
2266 } else {
Benjamin Kramerb89514a2011-10-14 18:45:37 +00002267 OS << " Kind=PropertyRef Property=\"" << *Node->getExplicitProperty() <<'"';
John McCallb7bd14f2010-12-02 01:19:52 +00002268 }
Fariborz Jahanian8a1810f2008-11-22 18:39:36 +00002269
Fariborz Jahanian681c0752010-10-14 16:04:05 +00002270 if (Node->isSuperReceiver())
2271 OS << " super";
Argyrios Kyrtzidisab468b02012-03-30 00:19:18 +00002272
2273 OS << " Messaging=";
2274 if (Node->isMessagingGetter() && Node->isMessagingSetter())
2275 OS << "Getter&Setter";
2276 else if (Node->isMessagingGetter())
2277 OS << "Getter";
2278 else if (Node->isMessagingSetter())
2279 OS << "Setter";
Douglas Gregor8ea1f532008-11-04 14:56:14 +00002280}
2281
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002282void ASTDumper::VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002283 VisitExpr(Node);
Ted Kremeneke65b0862012-03-06 20:05:56 +00002284 if (Node->isArraySubscriptRefExpr())
2285 OS << " Kind=ArraySubscript GetterForArray=\"";
2286 else
2287 OS << " Kind=DictionarySubscript GetterForDictionary=\"";
2288 if (Node->getAtIndexMethodDecl())
Aaron Ballmanb190f972014-01-03 17:59:55 +00002289 Node->getAtIndexMethodDecl()->getSelector().print(OS);
Ted Kremeneke65b0862012-03-06 20:05:56 +00002290 else
2291 OS << "(null)";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002292
Ted Kremeneke65b0862012-03-06 20:05:56 +00002293 if (Node->isArraySubscriptRefExpr())
2294 OS << "\" SetterForArray=\"";
2295 else
2296 OS << "\" SetterForDictionary=\"";
2297 if (Node->setAtIndexMethodDecl())
Aaron Ballmanb190f972014-01-03 17:59:55 +00002298 Node->setAtIndexMethodDecl()->getSelector().print(OS);
Ted Kremeneke65b0862012-03-06 20:05:56 +00002299 else
2300 OS << "(null)";
2301}
2302
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002303void ASTDumper::VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002304 VisitExpr(Node);
Ted Kremeneke65b0862012-03-06 20:05:56 +00002305 OS << " " << (Node->getValue() ? "__objc_yes" : "__objc_no");
2306}
2307
Chris Lattnercbe4f772007-08-08 22:51:59 +00002308//===----------------------------------------------------------------------===//
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002309// Comments
2310//===----------------------------------------------------------------------===//
2311
2312const char *ASTDumper::getCommandName(unsigned CommandID) {
2313 if (Traits)
2314 return Traits->getCommandInfo(CommandID)->Name;
2315 const CommandInfo *Info = CommandTraits::getBuiltinCommandInfo(CommandID);
2316 if (Info)
2317 return Info->Name;
2318 return "<not a builtin command>";
2319}
2320
2321void ASTDumper::dumpFullComment(const FullComment *C) {
2322 if (!C)
2323 return;
2324
2325 FC = C;
2326 dumpComment(C);
Craig Topper36250ad2014-05-12 05:36:57 +00002327 FC = nullptr;
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002328}
2329
2330void ASTDumper::dumpComment(const Comment *C) {
Richard Smithf7514452014-10-30 21:02:37 +00002331 dumpChild([=] {
2332 if (!C) {
2333 ColorScope Color(*this, NullColor);
2334 OS << "<<<NULL>>>";
2335 return;
2336 }
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002337
Richard Smithf7514452014-10-30 21:02:37 +00002338 {
2339 ColorScope Color(*this, CommentColor);
2340 OS << C->getCommentKindName();
2341 }
2342 dumpPointer(C);
2343 dumpSourceRange(C->getSourceRange());
2344 ConstCommentVisitor<ASTDumper>::visit(C);
2345 for (Comment::child_iterator I = C->child_begin(), E = C->child_end();
2346 I != E; ++I)
2347 dumpComment(*I);
2348 });
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002349}
2350
2351void ASTDumper::visitTextComment(const TextComment *C) {
2352 OS << " Text=\"" << C->getText() << "\"";
2353}
2354
2355void ASTDumper::visitInlineCommandComment(const InlineCommandComment *C) {
2356 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\"";
2357 switch (C->getRenderKind()) {
2358 case InlineCommandComment::RenderNormal:
2359 OS << " RenderNormal";
2360 break;
2361 case InlineCommandComment::RenderBold:
2362 OS << " RenderBold";
2363 break;
2364 case InlineCommandComment::RenderMonospaced:
2365 OS << " RenderMonospaced";
2366 break;
2367 case InlineCommandComment::RenderEmphasized:
2368 OS << " RenderEmphasized";
2369 break;
2370 }
2371
2372 for (unsigned i = 0, e = C->getNumArgs(); i != e; ++i)
2373 OS << " Arg[" << i << "]=\"" << C->getArgText(i) << "\"";
2374}
2375
2376void ASTDumper::visitHTMLStartTagComment(const HTMLStartTagComment *C) {
2377 OS << " Name=\"" << C->getTagName() << "\"";
2378 if (C->getNumAttrs() != 0) {
2379 OS << " Attrs: ";
2380 for (unsigned i = 0, e = C->getNumAttrs(); i != e; ++i) {
2381 const HTMLStartTagComment::Attribute &Attr = C->getAttr(i);
2382 OS << " \"" << Attr.Name << "=\"" << Attr.Value << "\"";
2383 }
2384 }
2385 if (C->isSelfClosing())
2386 OS << " SelfClosing";
2387}
2388
2389void ASTDumper::visitHTMLEndTagComment(const HTMLEndTagComment *C) {
2390 OS << " Name=\"" << C->getTagName() << "\"";
2391}
2392
2393void ASTDumper::visitBlockCommandComment(const BlockCommandComment *C) {
2394 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\"";
2395 for (unsigned i = 0, e = C->getNumArgs(); i != e; ++i)
2396 OS << " Arg[" << i << "]=\"" << C->getArgText(i) << "\"";
2397}
2398
2399void ASTDumper::visitParamCommandComment(const ParamCommandComment *C) {
2400 OS << " " << ParamCommandComment::getDirectionAsString(C->getDirection());
2401
2402 if (C->isDirectionExplicit())
2403 OS << " explicitly";
2404 else
2405 OS << " implicitly";
2406
2407 if (C->hasParamName()) {
2408 if (C->isParamIndexValid())
2409 OS << " Param=\"" << C->getParamName(FC) << "\"";
2410 else
2411 OS << " Param=\"" << C->getParamNameAsWritten() << "\"";
2412 }
2413
Dmitri Gribenkodbff5c72014-03-19 14:03:47 +00002414 if (C->isParamIndexValid() && !C->isVarArgParam())
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002415 OS << " ParamIndex=" << C->getParamIndex();
2416}
2417
2418void ASTDumper::visitTParamCommandComment(const TParamCommandComment *C) {
2419 if (C->hasParamName()) {
2420 if (C->isPositionValid())
2421 OS << " Param=\"" << C->getParamName(FC) << "\"";
2422 else
2423 OS << " Param=\"" << C->getParamNameAsWritten() << "\"";
2424 }
2425
2426 if (C->isPositionValid()) {
2427 OS << " Position=<";
2428 for (unsigned i = 0, e = C->getDepth(); i != e; ++i) {
2429 OS << C->getIndex(i);
2430 if (i != e - 1)
2431 OS << ", ";
2432 }
2433 OS << ">";
2434 }
2435}
2436
2437void ASTDumper::visitVerbatimBlockComment(const VerbatimBlockComment *C) {
2438 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\""
2439 " CloseName=\"" << C->getCloseName() << "\"";
2440}
2441
2442void ASTDumper::visitVerbatimBlockLineComment(
2443 const VerbatimBlockLineComment *C) {
2444 OS << " Text=\"" << C->getText() << "\"";
2445}
2446
2447void ASTDumper::visitVerbatimLineComment(const VerbatimLineComment *C) {
2448 OS << " Text=\"" << C->getText() << "\"";
2449}
2450
2451//===----------------------------------------------------------------------===//
Richard Smithd5e7ff82014-10-31 01:17:45 +00002452// Type method implementations
2453//===----------------------------------------------------------------------===//
2454
2455void QualType::dump(const char *msg) const {
2456 if (msg)
2457 llvm::errs() << msg << ": ";
2458 dump();
2459}
2460
2461LLVM_DUMP_METHOD void QualType::dump() const {
2462 ASTDumper Dumper(llvm::errs(), nullptr, nullptr);
2463 Dumper.dumpTypeAsChild(*this);
2464}
2465
2466LLVM_DUMP_METHOD void Type::dump() const { QualType(this, 0).dump(); }
2467
2468//===----------------------------------------------------------------------===//
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002469// Decl method implementations
2470//===----------------------------------------------------------------------===//
2471
Alp Tokeref6b0072014-01-04 13:47:14 +00002472LLVM_DUMP_METHOD void Decl::dump() const { dump(llvm::errs()); }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002473
Alp Tokeref6b0072014-01-04 13:47:14 +00002474LLVM_DUMP_METHOD void Decl::dump(raw_ostream &OS) const {
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002475 ASTDumper P(OS, &getASTContext().getCommentCommandTraits(),
2476 &getASTContext().getSourceManager());
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002477 P.dumpDecl(this);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002478}
2479
Alp Tokeref6b0072014-01-04 13:47:14 +00002480LLVM_DUMP_METHOD void Decl::dumpColor() const {
Richard Trieud215b8d2013-01-26 01:31:20 +00002481 ASTDumper P(llvm::errs(), &getASTContext().getCommentCommandTraits(),
2482 &getASTContext().getSourceManager(), /*ShowColors*/true);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002483 P.dumpDecl(this);
Richard Trieud215b8d2013-01-26 01:31:20 +00002484}
Richard Smith33937e72013-06-22 21:49:40 +00002485
Alp Tokeref6b0072014-01-04 13:47:14 +00002486LLVM_DUMP_METHOD void DeclContext::dumpLookups() const {
Richard Smith6ea05822013-06-24 01:45:33 +00002487 dumpLookups(llvm::errs());
2488}
2489
Richard Smith35f986d2014-08-11 22:11:07 +00002490LLVM_DUMP_METHOD void DeclContext::dumpLookups(raw_ostream &OS,
2491 bool DumpDecls) const {
Richard Smith33937e72013-06-22 21:49:40 +00002492 const DeclContext *DC = this;
2493 while (!DC->isTranslationUnit())
2494 DC = DC->getParent();
2495 ASTContext &Ctx = cast<TranslationUnitDecl>(DC)->getASTContext();
Richard Smith6ea05822013-06-24 01:45:33 +00002496 ASTDumper P(OS, &Ctx.getCommentCommandTraits(), &Ctx.getSourceManager());
Richard Smith35f986d2014-08-11 22:11:07 +00002497 P.dumpLookups(this, DumpDecls);
Richard Smith33937e72013-06-22 21:49:40 +00002498}
2499
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002500//===----------------------------------------------------------------------===//
Chris Lattnercbe4f772007-08-08 22:51:59 +00002501// Stmt method implementations
2502//===----------------------------------------------------------------------===//
2503
Alp Tokeref6b0072014-01-04 13:47:14 +00002504LLVM_DUMP_METHOD void Stmt::dump(SourceManager &SM) const {
Argyrios Kyrtzidisc049f752010-08-09 10:54:31 +00002505 dump(llvm::errs(), SM);
2506}
2507
Alp Tokeref6b0072014-01-04 13:47:14 +00002508LLVM_DUMP_METHOD void Stmt::dump(raw_ostream &OS, SourceManager &SM) const {
Craig Topper36250ad2014-05-12 05:36:57 +00002509 ASTDumper P(OS, nullptr, &SM);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002510 P.dumpStmt(this);
Chris Lattner779d5d92007-08-30 00:40:08 +00002511}
2512
Faisal Vali2da8ed92015-03-22 13:35:56 +00002513LLVM_DUMP_METHOD void Stmt::dump(raw_ostream &OS) const {
2514 ASTDumper P(OS, nullptr, nullptr);
2515 P.dumpStmt(this);
2516}
2517
Alp Tokeref6b0072014-01-04 13:47:14 +00002518LLVM_DUMP_METHOD void Stmt::dump() const {
Craig Topper36250ad2014-05-12 05:36:57 +00002519 ASTDumper P(llvm::errs(), nullptr, nullptr);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002520 P.dumpStmt(this);
Chris Lattnercbe4f772007-08-08 22:51:59 +00002521}
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002522
Alp Tokeref6b0072014-01-04 13:47:14 +00002523LLVM_DUMP_METHOD void Stmt::dumpColor() const {
Craig Topper36250ad2014-05-12 05:36:57 +00002524 ASTDumper P(llvm::errs(), nullptr, nullptr, /*ShowColors*/true);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002525 P.dumpStmt(this);
Richard Trieud215b8d2013-01-26 01:31:20 +00002526}
2527
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002528//===----------------------------------------------------------------------===//
2529// Comment method implementations
2530//===----------------------------------------------------------------------===//
2531
Craig Topper36250ad2014-05-12 05:36:57 +00002532LLVM_DUMP_METHOD void Comment::dump() const {
2533 dump(llvm::errs(), nullptr, nullptr);
2534}
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002535
Alp Tokeref6b0072014-01-04 13:47:14 +00002536LLVM_DUMP_METHOD void Comment::dump(const ASTContext &Context) const {
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002537 dump(llvm::errs(), &Context.getCommentCommandTraits(),
2538 &Context.getSourceManager());
2539}
2540
Alexander Kornienko00911f12013-01-15 12:20:21 +00002541void Comment::dump(raw_ostream &OS, const CommandTraits *Traits,
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002542 const SourceManager *SM) const {
2543 const FullComment *FC = dyn_cast<FullComment>(this);
2544 ASTDumper D(OS, Traits, SM);
2545 D.dumpFullComment(FC);
2546}
Richard Trieud215b8d2013-01-26 01:31:20 +00002547
Alp Tokeref6b0072014-01-04 13:47:14 +00002548LLVM_DUMP_METHOD void Comment::dumpColor() const {
Richard Trieud215b8d2013-01-26 01:31:20 +00002549 const FullComment *FC = dyn_cast<FullComment>(this);
Craig Topper36250ad2014-05-12 05:36:57 +00002550 ASTDumper D(llvm::errs(), nullptr, nullptr, /*ShowColors*/true);
Richard Trieud215b8d2013-01-26 01:31:20 +00002551 D.dumpFullComment(FC);
2552}