blob: 92cd23960898119cfaddf659d76043bdb32b4e91 [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"
Stephen Kelly0da68ba2018-12-05 20:53:14 +000016#include "clang/AST/ASTDumperUtils.h"
Alexander Kornienko5bc364e2013-01-07 17:53:08 +000017#include "clang/AST/Attr.h"
Alexander Kornienkoebc17b52013-01-14 14:07:11 +000018#include "clang/AST/CommentVisitor.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000019#include "clang/AST/DeclCXX.h"
Richard Smith33937e72013-06-22 21:49:40 +000020#include "clang/AST/DeclLookups.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000021#include "clang/AST/DeclObjC.h"
Alexey Bataev958b9e72016-03-31 09:30:50 +000022#include "clang/AST/DeclOpenMP.h"
Alexander Kornienko90ff6072012-12-20 02:09:13 +000023#include "clang/AST/DeclVisitor.h"
Benjamin Kramer31b382e2016-02-01 17:42:01 +000024#include "clang/AST/LocInfoType.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000025#include "clang/AST/StmtVisitor.h"
Stephen Kellyd8744a72018-12-05 21:12:39 +000026#include "clang/AST/TextNodeDumper.h"
Richard Smithd5e7ff82014-10-31 01:17:45 +000027#include "clang/AST/TypeVisitor.h"
David Majnemerd9b1a4f2015-11-04 03:40:30 +000028#include "clang/Basic/Builtins.h"
Alexander Kornienko90ff6072012-12-20 02:09:13 +000029#include "clang/Basic/Module.h"
Chris Lattner11e30d32007-08-30 06:17:34 +000030#include "clang/Basic/SourceManager.h"
Daniel Dunbar34a96c82009-12-03 09:13:13 +000031#include "llvm/Support/raw_ostream.h"
Chris Lattnercbe4f772007-08-08 22:51:59 +000032using namespace clang;
Alexander Kornienkoebc17b52013-01-14 14:07:11 +000033using namespace clang::comments;
Chris Lattnercbe4f772007-08-08 22:51:59 +000034
35//===----------------------------------------------------------------------===//
Alexander Kornienko18ec81b2012-12-13 13:59:55 +000036// ASTDumper Visitor
Chris Lattnercbe4f772007-08-08 22:51:59 +000037//===----------------------------------------------------------------------===//
38
39namespace {
Stephen Kelly27e948c2018-11-29 19:30:37 +000040
Alexander Kornienko90ff6072012-12-20 02:09:13 +000041 class ASTDumper
Stephen Kellycdbfb302018-12-02 17:30:40 +000042 : public ConstDeclVisitor<ASTDumper>,
43 public ConstStmtVisitor<ASTDumper>,
44 public ConstCommentVisitor<ASTDumper, void, const FullComment *>,
45 public TypeVisitor<ASTDumper> {
46
Stephen Kelly0da68ba2018-12-05 20:53:14 +000047 TextTreeStructure TreeStructure;
Stephen Kellyd8744a72018-12-05 21:12:39 +000048 TextNodeDumper NodeDumper;
Stephen Kelly0da68ba2018-12-05 20:53:14 +000049
Chris Lattner0e62c1c2011-07-23 10:55:15 +000050 raw_ostream &OS;
Mike Stump11289f42009-09-09 15:08:12 +000051
Aaron Ballman8c208282017-12-21 21:42:42 +000052 /// The policy to use for printing; can be defaulted.
53 PrintingPolicy PrintPolicy;
54
Richard Smith3a36ac12017-03-09 22:00:01 +000055 /// Indicates whether we should trigger deserialization of nodes that had
56 /// not already been loaded.
57 bool Deserialize = false;
58
Stephen Kellye66308b2018-11-29 19:30:08 +000059 const bool ShowColors;
Richard Trieud215b8d2013-01-26 01:31:20 +000060
Richard Smithf7514452014-10-30 21:02:37 +000061 /// Dump a child of the current node.
62 template<typename Fn> void dumpChild(Fn doDumpChild) {
Stephen Kelly0da68ba2018-12-05 20:53:14 +000063 TreeStructure.addChild(doDumpChild);
Richard Smithf7514452014-10-30 21:02:37 +000064 }
Manuel Klimek874030e2012-11-07 00:33:12 +000065
Chris Lattnercbe4f772007-08-08 22:51:59 +000066 public:
Alexander Kornienkoebc17b52013-01-14 14:07:11 +000067 ASTDumper(raw_ostream &OS, const CommandTraits *Traits,
68 const SourceManager *SM)
Aaron Ballman8c208282017-12-21 21:42:42 +000069 : ASTDumper(OS, Traits, SM,
70 SM && SM->getDiagnostics().getShowColors()) {}
Richard Trieud215b8d2013-01-26 01:31:20 +000071
72 ASTDumper(raw_ostream &OS, const CommandTraits *Traits,
73 const SourceManager *SM, bool ShowColors)
Aaron Ballman8c208282017-12-21 21:42:42 +000074 : ASTDumper(OS, Traits, SM, ShowColors, LangOptions()) {}
75 ASTDumper(raw_ostream &OS, const CommandTraits *Traits,
76 const SourceManager *SM, bool ShowColors,
77 const PrintingPolicy &PrintPolicy)
Stephen Kellyd8744a72018-12-05 21:12:39 +000078 : TreeStructure(OS, ShowColors),
Stephen Kellye26a88a2018-12-09 13:30:17 +000079 NodeDumper(OS, ShowColors, SM, PrintPolicy, Traits), OS(OS),
Stephen Kelly0da68ba2018-12-05 20:53:14 +000080 PrintPolicy(PrintPolicy), ShowColors(ShowColors) {}
Richard Smith3a36ac12017-03-09 22:00:01 +000081
82 void setDeserialize(bool D) { Deserialize = D; }
Mike Stump11289f42009-09-09 15:08:12 +000083
Alexander Kornienko540bacb2013-02-01 12:35:51 +000084 void dumpDecl(const Decl *D);
Stephen Kelly50a29bd2018-12-09 13:24:40 +000085 void dumpStmt(const Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +000086
Richard Trieude5cc7d2013-01-31 01:44:26 +000087 // Utilities
Stephen Kellyd8744a72018-12-05 21:12:39 +000088 void dumpType(QualType T) { NodeDumper.dumpType(T); }
Richard Smithd5e7ff82014-10-31 01:17:45 +000089 void dumpTypeAsChild(QualType T);
90 void dumpTypeAsChild(const Type *T);
Craig Topper36250ad2014-05-12 05:36:57 +000091 void dumpDeclRef(const Decl *Node, const char *Label = nullptr);
Stephen Kellyd8744a72018-12-05 21:12:39 +000092 void dumpBareDeclRef(const Decl *Node) { NodeDumper.dumpBareDeclRef(Node); }
Alexander Kornienko787f4c32012-12-20 11:08:38 +000093 void dumpDeclContext(const DeclContext *DC);
Richard Smith35f986d2014-08-11 22:11:07 +000094 void dumpLookups(const DeclContext *DC, bool DumpDecls);
Alexander Kornienko5bc364e2013-01-07 17:53:08 +000095 void dumpAttr(const Attr *A);
Alexander Kornienko90ff6072012-12-20 02:09:13 +000096
97 // C++ Utilities
Alexander Kornienko787f4c32012-12-20 11:08:38 +000098 void dumpCXXCtorInitializer(const CXXCtorInitializer *Init);
99 void dumpTemplateParameters(const TemplateParameterList *TPL);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000100 void dumpTemplateArgumentListInfo(const TemplateArgumentListInfo &TALI);
Stephen Kelly43835952018-12-10 21:03:00 +0000101 void dumpTemplateArgumentLoc(const TemplateArgumentLoc &A,
102 const Decl *From = nullptr,
Stephen Kelly1be0bea2018-12-10 21:04:04 +0000103 const char *Label = nullptr);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000104 void dumpTemplateArgumentList(const TemplateArgumentList &TAL);
105 void dumpTemplateArgument(const TemplateArgument &A,
Stephen Kelly43835952018-12-10 21:03:00 +0000106 SourceRange R = SourceRange(),
107 const Decl *From = nullptr,
Stephen Kelly1be0bea2018-12-10 21:04:04 +0000108 const char *Label = nullptr);
Stephen Kelly24136382018-12-09 13:33:30 +0000109 template <typename SpecializationDecl>
110 void dumpTemplateDeclSpecialization(const SpecializationDecl *D,
111 bool DumpExplicitInst,
112 bool DumpRefOnly);
113 template <typename TemplateDecl>
114 void dumpTemplateDecl(const TemplateDecl *D, bool DumpExplicitInst);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000115
Douglas Gregor85f3f952015-07-07 03:57:15 +0000116 // Objective-C utilities.
117 void dumpObjCTypeParamList(const ObjCTypeParamList *typeParams);
118
Richard Smithd5e7ff82014-10-31 01:17:45 +0000119 // Types
120 void VisitComplexType(const ComplexType *T) {
121 dumpTypeAsChild(T->getElementType());
122 }
123 void VisitPointerType(const PointerType *T) {
124 dumpTypeAsChild(T->getPointeeType());
125 }
126 void VisitBlockPointerType(const BlockPointerType *T) {
127 dumpTypeAsChild(T->getPointeeType());
128 }
129 void VisitReferenceType(const ReferenceType *T) {
130 dumpTypeAsChild(T->getPointeeType());
131 }
132 void VisitRValueReferenceType(const ReferenceType *T) {
133 if (T->isSpelledAsLValue())
134 OS << " written as lvalue reference";
135 VisitReferenceType(T);
136 }
137 void VisitMemberPointerType(const MemberPointerType *T) {
138 dumpTypeAsChild(T->getClass());
139 dumpTypeAsChild(T->getPointeeType());
140 }
141 void VisitArrayType(const ArrayType *T) {
142 switch (T->getSizeModifier()) {
143 case ArrayType::Normal: break;
144 case ArrayType::Static: OS << " static"; break;
145 case ArrayType::Star: OS << " *"; break;
146 }
147 OS << " " << T->getIndexTypeQualifiers().getAsString();
148 dumpTypeAsChild(T->getElementType());
149 }
150 void VisitConstantArrayType(const ConstantArrayType *T) {
151 OS << " " << T->getSize();
152 VisitArrayType(T);
153 }
154 void VisitVariableArrayType(const VariableArrayType *T) {
155 OS << " ";
Stephen Kellyd8744a72018-12-05 21:12:39 +0000156 NodeDumper.dumpSourceRange(T->getBracketsRange());
Richard Smithd5e7ff82014-10-31 01:17:45 +0000157 VisitArrayType(T);
158 dumpStmt(T->getSizeExpr());
159 }
160 void VisitDependentSizedArrayType(const DependentSizedArrayType *T) {
Stephen Kellyec42aa02018-12-05 20:34:07 +0000161 switch (T->getSizeModifier()) {
162 case ArrayType::Normal: break;
163 case ArrayType::Static: OS << " static"; break;
164 case ArrayType::Star: OS << " *"; break;
165 }
166 OS << " " << T->getIndexTypeQualifiers().getAsString();
Richard Smithd5e7ff82014-10-31 01:17:45 +0000167 OS << " ";
Stephen Kellyd8744a72018-12-05 21:12:39 +0000168 NodeDumper.dumpSourceRange(T->getBracketsRange());
Stephen Kellyec42aa02018-12-05 20:34:07 +0000169 dumpTypeAsChild(T->getElementType());
Richard Smithd5e7ff82014-10-31 01:17:45 +0000170 dumpStmt(T->getSizeExpr());
171 }
172 void VisitDependentSizedExtVectorType(
173 const DependentSizedExtVectorType *T) {
174 OS << " ";
Stephen Kellyd8744a72018-12-05 21:12:39 +0000175 NodeDumper.dumpLocation(T->getAttributeLoc());
Richard Smithd5e7ff82014-10-31 01:17:45 +0000176 dumpTypeAsChild(T->getElementType());
177 dumpStmt(T->getSizeExpr());
178 }
179 void VisitVectorType(const VectorType *T) {
180 switch (T->getVectorKind()) {
181 case VectorType::GenericVector: break;
182 case VectorType::AltiVecVector: OS << " altivec"; break;
183 case VectorType::AltiVecPixel: OS << " altivec pixel"; break;
184 case VectorType::AltiVecBool: OS << " altivec bool"; break;
185 case VectorType::NeonVector: OS << " neon"; break;
186 case VectorType::NeonPolyVector: OS << " neon poly"; break;
187 }
188 OS << " " << T->getNumElements();
189 dumpTypeAsChild(T->getElementType());
190 }
191 void VisitFunctionType(const FunctionType *T) {
192 auto EI = T->getExtInfo();
193 if (EI.getNoReturn()) OS << " noreturn";
194 if (EI.getProducesResult()) OS << " produces_result";
195 if (EI.getHasRegParm()) OS << " regparm " << EI.getRegParm();
196 OS << " " << FunctionType::getNameForCallConv(EI.getCC());
197 dumpTypeAsChild(T->getReturnType());
198 }
199 void VisitFunctionProtoType(const FunctionProtoType *T) {
200 auto EPI = T->getExtProtoInfo();
201 if (EPI.HasTrailingReturn) OS << " trailing_return";
Mikael Nilsson90646732018-12-12 15:06:16 +0000202 if (T->isConst()) OS << " const";
203 if (T->isVolatile()) OS << " volatile";
204 if (T->isRestrict()) OS << " restrict";
Richard Smithd5e7ff82014-10-31 01:17:45 +0000205 switch (EPI.RefQualifier) {
206 case RQ_None: break;
207 case RQ_LValue: OS << " &"; break;
208 case RQ_RValue: OS << " &&"; break;
209 }
210 // FIXME: Exception specification.
211 // FIXME: Consumed parameters.
212 VisitFunctionType(T);
213 for (QualType PT : T->getParamTypes())
214 dumpTypeAsChild(PT);
215 if (EPI.Variadic)
216 dumpChild([=] { OS << "..."; });
217 }
218 void VisitUnresolvedUsingType(const UnresolvedUsingType *T) {
219 dumpDeclRef(T->getDecl());
220 }
221 void VisitTypedefType(const TypedefType *T) {
222 dumpDeclRef(T->getDecl());
223 }
224 void VisitTypeOfExprType(const TypeOfExprType *T) {
225 dumpStmt(T->getUnderlyingExpr());
226 }
227 void VisitDecltypeType(const DecltypeType *T) {
228 dumpStmt(T->getUnderlyingExpr());
229 }
230 void VisitUnaryTransformType(const UnaryTransformType *T) {
231 switch (T->getUTTKind()) {
232 case UnaryTransformType::EnumUnderlyingType:
233 OS << " underlying_type";
234 break;
235 }
236 dumpTypeAsChild(T->getBaseType());
237 }
238 void VisitTagType(const TagType *T) {
239 dumpDeclRef(T->getDecl());
240 }
241 void VisitAttributedType(const AttributedType *T) {
242 // FIXME: AttrKind
243 dumpTypeAsChild(T->getModifiedType());
244 }
245 void VisitTemplateTypeParmType(const TemplateTypeParmType *T) {
246 OS << " depth " << T->getDepth() << " index " << T->getIndex();
247 if (T->isParameterPack()) OS << " pack";
248 dumpDeclRef(T->getDecl());
249 }
250 void VisitSubstTemplateTypeParmType(const SubstTemplateTypeParmType *T) {
251 dumpTypeAsChild(T->getReplacedParameter());
252 }
253 void VisitSubstTemplateTypeParmPackType(
254 const SubstTemplateTypeParmPackType *T) {
255 dumpTypeAsChild(T->getReplacedParameter());
256 dumpTemplateArgument(T->getArgumentPack());
257 }
258 void VisitAutoType(const AutoType *T) {
259 if (T->isDecltypeAuto()) OS << " decltype(auto)";
260 if (!T->isDeduced())
261 OS << " undeduced";
262 }
263 void VisitTemplateSpecializationType(const TemplateSpecializationType *T) {
264 if (T->isTypeAlias()) OS << " alias";
265 OS << " "; T->getTemplateName().dump(OS);
266 for (auto &Arg : *T)
267 dumpTemplateArgument(Arg);
268 if (T->isTypeAlias())
269 dumpTypeAsChild(T->getAliasedType());
270 }
271 void VisitInjectedClassNameType(const InjectedClassNameType *T) {
272 dumpDeclRef(T->getDecl());
273 }
274 void VisitObjCInterfaceType(const ObjCInterfaceType *T) {
275 dumpDeclRef(T->getDecl());
276 }
277 void VisitObjCObjectPointerType(const ObjCObjectPointerType *T) {
278 dumpTypeAsChild(T->getPointeeType());
279 }
280 void VisitAtomicType(const AtomicType *T) {
281 dumpTypeAsChild(T->getValueType());
282 }
Xiuli Pan2d12e652016-05-03 05:37:07 +0000283 void VisitPipeType(const PipeType *T) {
284 dumpTypeAsChild(T->getElementType());
285 }
Richard Smithd5e7ff82014-10-31 01:17:45 +0000286 void VisitAdjustedType(const AdjustedType *T) {
287 dumpTypeAsChild(T->getOriginalType());
288 }
289 void VisitPackExpansionType(const PackExpansionType *T) {
290 if (auto N = T->getNumExpansions()) OS << " expansions " << *N;
291 if (!T->isSugared())
292 dumpTypeAsChild(T->getPattern());
293 }
294 // FIXME: ElaboratedType, DependentNameType,
295 // DependentTemplateSpecializationType, ObjCObjectType
296
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000297 // Decls
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000298 void VisitLabelDecl(const LabelDecl *D);
299 void VisitTypedefDecl(const TypedefDecl *D);
300 void VisitEnumDecl(const EnumDecl *D);
301 void VisitRecordDecl(const RecordDecl *D);
302 void VisitEnumConstantDecl(const EnumConstantDecl *D);
303 void VisitIndirectFieldDecl(const IndirectFieldDecl *D);
304 void VisitFunctionDecl(const FunctionDecl *D);
305 void VisitFieldDecl(const FieldDecl *D);
306 void VisitVarDecl(const VarDecl *D);
Richard Smithbdb84f32016-07-22 23:36:59 +0000307 void VisitDecompositionDecl(const DecompositionDecl *D);
Richard Smith7873de02016-08-11 22:25:46 +0000308 void VisitBindingDecl(const BindingDecl *D);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000309 void VisitFileScopeAsmDecl(const FileScopeAsmDecl *D);
310 void VisitImportDecl(const ImportDecl *D);
Nico Weber66220292016-03-02 17:28:48 +0000311 void VisitPragmaCommentDecl(const PragmaCommentDecl *D);
Nico Webercbbaeb12016-03-02 19:28:54 +0000312 void VisitPragmaDetectMismatchDecl(const PragmaDetectMismatchDecl *D);
Alexey Bataev958b9e72016-03-31 09:30:50 +0000313 void VisitCapturedDecl(const CapturedDecl *D);
314
315 // OpenMP decls
316 void VisitOMPThreadPrivateDecl(const OMPThreadPrivateDecl *D);
317 void VisitOMPDeclareReductionDecl(const OMPDeclareReductionDecl *D);
Kelvin Li1408f912018-09-26 04:28:39 +0000318 void VisitOMPRequiresDecl(const OMPRequiresDecl *D);
Alexey Bataev958b9e72016-03-31 09:30:50 +0000319 void VisitOMPCapturedExprDecl(const OMPCapturedExprDecl *D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000320
321 // C++ Decls
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000322 void VisitNamespaceDecl(const NamespaceDecl *D);
323 void VisitUsingDirectiveDecl(const UsingDirectiveDecl *D);
324 void VisitNamespaceAliasDecl(const NamespaceAliasDecl *D);
325 void VisitTypeAliasDecl(const TypeAliasDecl *D);
326 void VisitTypeAliasTemplateDecl(const TypeAliasTemplateDecl *D);
327 void VisitCXXRecordDecl(const CXXRecordDecl *D);
328 void VisitStaticAssertDecl(const StaticAssertDecl *D);
329 void VisitFunctionTemplateDecl(const FunctionTemplateDecl *D);
330 void VisitClassTemplateDecl(const ClassTemplateDecl *D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000331 void VisitClassTemplateSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000332 const ClassTemplateSpecializationDecl *D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000333 void VisitClassTemplatePartialSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000334 const ClassTemplatePartialSpecializationDecl *D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000335 void VisitClassScopeFunctionSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000336 const ClassScopeFunctionSpecializationDecl *D);
David Majnemerd9b1a4f2015-11-04 03:40:30 +0000337 void VisitBuiltinTemplateDecl(const BuiltinTemplateDecl *D);
Richard Smithd25789a2013-09-18 01:36:02 +0000338 void VisitVarTemplateDecl(const VarTemplateDecl *D);
339 void VisitVarTemplateSpecializationDecl(
340 const VarTemplateSpecializationDecl *D);
341 void VisitVarTemplatePartialSpecializationDecl(
342 const VarTemplatePartialSpecializationDecl *D);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000343 void VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D);
344 void VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D);
345 void VisitTemplateTemplateParmDecl(const TemplateTemplateParmDecl *D);
346 void VisitUsingDecl(const UsingDecl *D);
347 void VisitUnresolvedUsingTypenameDecl(const UnresolvedUsingTypenameDecl *D);
348 void VisitUnresolvedUsingValueDecl(const UnresolvedUsingValueDecl *D);
349 void VisitUsingShadowDecl(const UsingShadowDecl *D);
Richard Smith5179eb72016-06-28 19:03:57 +0000350 void VisitConstructorUsingShadowDecl(const ConstructorUsingShadowDecl *D);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000351 void VisitLinkageSpecDecl(const LinkageSpecDecl *D);
352 void VisitAccessSpecDecl(const AccessSpecDecl *D);
353 void VisitFriendDecl(const FriendDecl *D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000354
355 // ObjC Decls
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000356 void VisitObjCIvarDecl(const ObjCIvarDecl *D);
357 void VisitObjCMethodDecl(const ObjCMethodDecl *D);
Douglas Gregor85f3f952015-07-07 03:57:15 +0000358 void VisitObjCTypeParamDecl(const ObjCTypeParamDecl *D);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000359 void VisitObjCCategoryDecl(const ObjCCategoryDecl *D);
360 void VisitObjCCategoryImplDecl(const ObjCCategoryImplDecl *D);
361 void VisitObjCProtocolDecl(const ObjCProtocolDecl *D);
362 void VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D);
363 void VisitObjCImplementationDecl(const ObjCImplementationDecl *D);
364 void VisitObjCCompatibleAliasDecl(const ObjCCompatibleAliasDecl *D);
365 void VisitObjCPropertyDecl(const ObjCPropertyDecl *D);
366 void VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D);
367 void VisitBlockDecl(const BlockDecl *D);
Mike Stump11289f42009-09-09 15:08:12 +0000368
Chris Lattner84ca3762007-08-30 01:00:35 +0000369 // Stmts.
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000370 void VisitDeclStmt(const DeclStmt *Node);
371 void VisitAttributedStmt(const AttributedStmt *Node);
Bruno Riccib1cc94b2018-10-27 21:12:20 +0000372 void VisitIfStmt(const IfStmt *Node);
Bruno Riccie2806f82018-10-29 16:12:37 +0000373 void VisitSwitchStmt(const SwitchStmt *Node);
Bruno Riccibacf7512018-10-30 13:42:41 +0000374 void VisitWhileStmt(const WhileStmt *Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000375 void VisitLabelStmt(const LabelStmt *Node);
376 void VisitGotoStmt(const GotoStmt *Node);
Pavel Labath1ef83422013-09-04 14:35:00 +0000377 void VisitCXXCatchStmt(const CXXCatchStmt *Node);
Bruno Ricci5b30571752018-10-28 12:30:53 +0000378 void VisitCaseStmt(const CaseStmt *Node);
Alexey Bataev958b9e72016-03-31 09:30:50 +0000379 void VisitCapturedStmt(const CapturedStmt *Node);
380
381 // OpenMP
382 void VisitOMPExecutableDirective(const OMPExecutableDirective *Node);
Mike Stump11289f42009-09-09 15:08:12 +0000383
Chris Lattner84ca3762007-08-30 01:00:35 +0000384 // Exprs
Eric Fiselier5cdc2cd2018-12-12 21:50:55 +0000385 void VisitCallExpr(const CallExpr *Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000386 void VisitCastExpr(const CastExpr *Node);
Roman Lebedev12216f12018-07-27 07:27:14 +0000387 void VisitImplicitCastExpr(const ImplicitCastExpr *Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000388 void VisitDeclRefExpr(const DeclRefExpr *Node);
389 void VisitPredefinedExpr(const PredefinedExpr *Node);
390 void VisitCharacterLiteral(const CharacterLiteral *Node);
391 void VisitIntegerLiteral(const IntegerLiteral *Node);
Leonard Chandb01c3a2018-06-20 17:19:40 +0000392 void VisitFixedPointLiteral(const FixedPointLiteral *Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000393 void VisitFloatingLiteral(const FloatingLiteral *Node);
394 void VisitStringLiteral(const StringLiteral *Str);
Richard Smithf0514962014-06-03 08:24:28 +0000395 void VisitInitListExpr(const InitListExpr *ILE);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000396 void VisitUnaryOperator(const UnaryOperator *Node);
397 void VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *Node);
398 void VisitMemberExpr(const MemberExpr *Node);
399 void VisitExtVectorElementExpr(const ExtVectorElementExpr *Node);
400 void VisitBinaryOperator(const BinaryOperator *Node);
401 void VisitCompoundAssignOperator(const CompoundAssignOperator *Node);
402 void VisitAddrLabelExpr(const AddrLabelExpr *Node);
403 void VisitBlockExpr(const BlockExpr *Node);
404 void VisitOpaqueValueExpr(const OpaqueValueExpr *Node);
Richard Smith01ccebf2018-01-05 21:31:07 +0000405 void VisitGenericSelectionExpr(const GenericSelectionExpr *E);
Chris Lattner84ca3762007-08-30 01:00:35 +0000406
407 // C++
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000408 void VisitCXXNamedCastExpr(const CXXNamedCastExpr *Node);
409 void VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *Node);
410 void VisitCXXThisExpr(const CXXThisExpr *Node);
411 void VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *Node);
Richard Smith39eca9b2017-08-23 22:12:08 +0000412 void VisitCXXUnresolvedConstructExpr(const CXXUnresolvedConstructExpr *Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000413 void VisitCXXConstructExpr(const CXXConstructExpr *Node);
414 void VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *Node);
Reid Kleckner5c682bc2015-03-19 18:09:25 +0000415 void VisitCXXNewExpr(const CXXNewExpr *Node);
416 void VisitCXXDeleteExpr(const CXXDeleteExpr *Node);
Richard Smithe6c01442013-06-05 00:46:14 +0000417 void VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000418 void VisitExprWithCleanups(const ExprWithCleanups *Node);
419 void VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *Node);
Faisal Vali2b391ab2013-09-26 19:54:12 +0000420 void VisitLambdaExpr(const LambdaExpr *Node) {
Faisal Vali2b391ab2013-09-26 19:54:12 +0000421 dumpDecl(Node->getLambdaClass());
422 }
Serge Pavlov6b926032015-02-16 19:58:41 +0000423 void VisitSizeOfPackExpr(const SizeOfPackExpr *Node);
Alex Lorenzddbe0f52016-11-09 14:02:18 +0000424 void
425 VisitCXXDependentScopeMemberExpr(const CXXDependentScopeMemberExpr *Node);
Mike Stump11289f42009-09-09 15:08:12 +0000426
Chris Lattner84ca3762007-08-30 01:00:35 +0000427 // ObjC
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000428 void VisitObjCAtCatchStmt(const ObjCAtCatchStmt *Node);
429 void VisitObjCEncodeExpr(const ObjCEncodeExpr *Node);
430 void VisitObjCMessageExpr(const ObjCMessageExpr *Node);
431 void VisitObjCBoxedExpr(const ObjCBoxedExpr *Node);
432 void VisitObjCSelectorExpr(const ObjCSelectorExpr *Node);
433 void VisitObjCProtocolExpr(const ObjCProtocolExpr *Node);
434 void VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *Node);
435 void VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *Node);
436 void VisitObjCIvarRefExpr(const ObjCIvarRefExpr *Node);
437 void VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *Node);
Alexander Kornienkoebc17b52013-01-14 14:07:11 +0000438
439 // Comments.
Stephen Kellycdbfb302018-12-02 17:30:40 +0000440 void dumpComment(const Comment *C, const FullComment *FC);
Chris Lattnercbe4f772007-08-08 22:51:59 +0000441 };
Alexander Kornienkoab9db512015-06-22 23:07:51 +0000442}
Chris Lattnercbe4f772007-08-08 22:51:59 +0000443
444//===----------------------------------------------------------------------===//
Chris Lattner11e30d32007-08-30 06:17:34 +0000445// Utilities
446//===----------------------------------------------------------------------===//
447
Richard Smithd5e7ff82014-10-31 01:17:45 +0000448void ASTDumper::dumpTypeAsChild(QualType T) {
449 SplitQualType SQT = T.split();
450 if (!SQT.Quals.hasQualifiers())
451 return dumpTypeAsChild(SQT.Ty);
452
453 dumpChild([=] {
454 OS << "QualType";
Stephen Kellyd8744a72018-12-05 21:12:39 +0000455 NodeDumper.dumpPointer(T.getAsOpaquePtr());
Richard Smithd5e7ff82014-10-31 01:17:45 +0000456 OS << " ";
Stephen Kellyd8744a72018-12-05 21:12:39 +0000457 NodeDumper.dumpBareType(T, false);
Richard Smithd5e7ff82014-10-31 01:17:45 +0000458 OS << " " << T.split().Quals.getAsString();
459 dumpTypeAsChild(T.split().Ty);
460 });
461}
462
463void ASTDumper::dumpTypeAsChild(const Type *T) {
464 dumpChild([=] {
465 if (!T) {
Stephen Kelly27e948c2018-11-29 19:30:37 +0000466 ColorScope Color(OS, ShowColors, NullColor);
Richard Smithd5e7ff82014-10-31 01:17:45 +0000467 OS << "<<<NULL>>>";
468 return;
469 }
Serge Pavlova6adc9e2015-12-28 17:19:12 +0000470 if (const LocInfoType *LIT = llvm::dyn_cast<LocInfoType>(T)) {
471 {
Stephen Kelly27e948c2018-11-29 19:30:37 +0000472 ColorScope Color(OS, ShowColors, TypeColor);
Serge Pavlova6adc9e2015-12-28 17:19:12 +0000473 OS << "LocInfo Type";
474 }
Stephen Kellyd8744a72018-12-05 21:12:39 +0000475 NodeDumper.dumpPointer(T);
Serge Pavlova6adc9e2015-12-28 17:19:12 +0000476 dumpTypeAsChild(LIT->getTypeSourceInfo()->getType());
477 return;
478 }
Richard Smithd5e7ff82014-10-31 01:17:45 +0000479
480 {
Stephen Kelly27e948c2018-11-29 19:30:37 +0000481 ColorScope Color(OS, ShowColors, TypeColor);
Richard Smithd5e7ff82014-10-31 01:17:45 +0000482 OS << T->getTypeClassName() << "Type";
483 }
Stephen Kellyd8744a72018-12-05 21:12:39 +0000484 NodeDumper.dumpPointer(T);
Richard Smithd5e7ff82014-10-31 01:17:45 +0000485 OS << " ";
Stephen Kellyd8744a72018-12-05 21:12:39 +0000486 NodeDumper.dumpBareType(QualType(T, 0), false);
Richard Smithd5e7ff82014-10-31 01:17:45 +0000487
488 QualType SingleStepDesugar =
489 T->getLocallyUnqualifiedSingleStepDesugaredType();
490 if (SingleStepDesugar != QualType(T, 0))
491 OS << " sugar";
492 if (T->isDependentType())
493 OS << " dependent";
494 else if (T->isInstantiationDependentType())
495 OS << " instantiation_dependent";
496 if (T->isVariablyModifiedType())
497 OS << " variably_modified";
498 if (T->containsUnexpandedParameterPack())
499 OS << " contains_unexpanded_pack";
500 if (T->isFromAST())
501 OS << " imported";
502
503 TypeVisitor<ASTDumper>::Visit(T);
504
505 if (SingleStepDesugar != QualType(T, 0))
506 dumpTypeAsChild(SingleStepDesugar);
507 });
508}
509
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000510void ASTDumper::dumpDeclRef(const Decl *D, const char *Label) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000511 if (!D)
512 return;
513
Richard Smithf7514452014-10-30 21:02:37 +0000514 dumpChild([=]{
515 if (Label)
516 OS << Label << ' ';
517 dumpBareDeclRef(D);
518 });
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000519}
520
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000521void ASTDumper::dumpDeclContext(const DeclContext *DC) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000522 if (!DC)
523 return;
Richard Smithdcc2c452014-03-17 23:00:06 +0000524
Richard Smith3a36ac12017-03-09 22:00:01 +0000525 for (auto *D : (Deserialize ? DC->decls() : DC->noload_decls()))
Richard Smithf7514452014-10-30 21:02:37 +0000526 dumpDecl(D);
Richard Smithdcc2c452014-03-17 23:00:06 +0000527
528 if (DC->hasExternalLexicalStorage()) {
Stephen Kelly27e948c2018-11-29 19:30:37 +0000529 dumpChild([=] {
530 ColorScope Color(OS, ShowColors, UndeserializedColor);
Richard Smithf7514452014-10-30 21:02:37 +0000531 OS << "<undeserialized declarations>";
532 });
Richard Smith1d209d02013-05-23 01:49:11 +0000533 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000534}
535
Richard Smith35f986d2014-08-11 22:11:07 +0000536void ASTDumper::dumpLookups(const DeclContext *DC, bool DumpDecls) {
Richard Smithf7514452014-10-30 21:02:37 +0000537 dumpChild([=] {
538 OS << "StoredDeclsMap ";
Stephen Kellyd8744a72018-12-05 21:12:39 +0000539 NodeDumper.dumpBareDeclRef(cast<Decl>(DC));
Richard Smith33937e72013-06-22 21:49:40 +0000540
Richard Smithf7514452014-10-30 21:02:37 +0000541 const DeclContext *Primary = DC->getPrimaryContext();
542 if (Primary != DC) {
543 OS << " primary";
Stephen Kellyd8744a72018-12-05 21:12:39 +0000544 NodeDumper.dumpPointer(cast<Decl>(Primary));
Richard Smith33937e72013-06-22 21:49:40 +0000545 }
546
Richard Smithf7514452014-10-30 21:02:37 +0000547 bool HasUndeserializedLookups = Primary->hasExternalVisibleStorage();
Richard Smith35f986d2014-08-11 22:11:07 +0000548
Sam McCall091b1ef2018-01-16 12:33:46 +0000549 auto Range = Deserialize
550 ? Primary->lookups()
551 : Primary->noload_lookups(/*PreserveInternalState=*/true);
552 for (auto I = Range.begin(), E = Range.end(); I != E; ++I) {
Richard Smithf7514452014-10-30 21:02:37 +0000553 DeclarationName Name = I.getLookupName();
Richard Smith3a36ac12017-03-09 22:00:01 +0000554 DeclContextLookupResult R = *I;
Richard Smith35f986d2014-08-11 22:11:07 +0000555
Richard Smithf7514452014-10-30 21:02:37 +0000556 dumpChild([=] {
557 OS << "DeclarationName ";
558 {
Stephen Kelly27e948c2018-11-29 19:30:37 +0000559 ColorScope Color(OS, ShowColors, DeclNameColor);
Richard Smithf7514452014-10-30 21:02:37 +0000560 OS << '\'' << Name << '\'';
561 }
Richard Smith35f986d2014-08-11 22:11:07 +0000562
Richard Smithf7514452014-10-30 21:02:37 +0000563 for (DeclContextLookupResult::iterator RI = R.begin(), RE = R.end();
564 RI != RE; ++RI) {
565 dumpChild([=] {
Stephen Kellyd8744a72018-12-05 21:12:39 +0000566 NodeDumper.dumpBareDeclRef(*RI);
Richard Smithf7514452014-10-30 21:02:37 +0000567
568 if ((*RI)->isHidden())
569 OS << " hidden";
570
571 // If requested, dump the redecl chain for this lookup.
572 if (DumpDecls) {
573 // Dump earliest decl first.
574 std::function<void(Decl *)> DumpWithPrev = [&](Decl *D) {
575 if (Decl *Prev = D->getPreviousDecl())
576 DumpWithPrev(Prev);
577 dumpDecl(D);
578 };
579 DumpWithPrev(*RI);
580 }
581 });
582 }
583 });
Richard Smith33937e72013-06-22 21:49:40 +0000584 }
Richard Smith33937e72013-06-22 21:49:40 +0000585
Richard Smithf7514452014-10-30 21:02:37 +0000586 if (HasUndeserializedLookups) {
587 dumpChild([=] {
Stephen Kelly27e948c2018-11-29 19:30:37 +0000588 ColorScope Color(OS, ShowColors, UndeserializedColor);
Richard Smithf7514452014-10-30 21:02:37 +0000589 OS << "<undeserialized lookups>";
590 });
591 }
592 });
Richard Smith33937e72013-06-22 21:49:40 +0000593}
594
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000595void ASTDumper::dumpAttr(const Attr *A) {
Richard Smithf7514452014-10-30 21:02:37 +0000596 dumpChild([=] {
597 {
Stephen Kelly27e948c2018-11-29 19:30:37 +0000598 ColorScope Color(OS, ShowColors, AttrColor);
Aaron Ballman36a53502014-01-16 13:03:14 +0000599
Richard Smithf7514452014-10-30 21:02:37 +0000600 switch (A->getKind()) {
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000601#define ATTR(X) case attr::X: OS << #X; break;
602#include "clang/Basic/AttrList.inc"
Richard Smithf7514452014-10-30 21:02:37 +0000603 }
604 OS << "Attr";
Richard Trieud215b8d2013-01-26 01:31:20 +0000605 }
Stephen Kellyd8744a72018-12-05 21:12:39 +0000606 NodeDumper.dumpPointer(A);
607 NodeDumper.dumpSourceRange(A->getRange());
Richard Smithf7514452014-10-30 21:02:37 +0000608 if (A->isInherited())
609 OS << " Inherited";
610 if (A->isImplicit())
611 OS << " Implicit";
Hans Wennborgb0a8b4a2014-05-31 04:05:57 +0000612#include "clang/AST/AttrDump.inc"
Richard Smithf7514452014-10-30 21:02:37 +0000613 });
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000614}
615
Richard Smith71bec062013-10-15 21:58:30 +0000616static void dumpPreviousDeclImpl(raw_ostream &OS, ...) {}
617
618template<typename T>
619static void dumpPreviousDeclImpl(raw_ostream &OS, const Mergeable<T> *D) {
Rafael Espindola8db352d2013-10-17 15:37:26 +0000620 const T *First = D->getFirstDecl();
Richard Smith71bec062013-10-15 21:58:30 +0000621 if (First != D)
622 OS << " first " << First;
Richard Smithf5f43542013-02-07 01:35:44 +0000623}
624
625template<typename T>
Richard Smith71bec062013-10-15 21:58:30 +0000626static void dumpPreviousDeclImpl(raw_ostream &OS, const Redeclarable<T> *D) {
627 const T *Prev = D->getPreviousDecl();
628 if (Prev)
629 OS << " prev " << Prev;
Richard Smithf5f43542013-02-07 01:35:44 +0000630}
631
Richard Smith71bec062013-10-15 21:58:30 +0000632/// Dump the previous declaration in the redeclaration chain for a declaration,
633/// if any.
634static void dumpPreviousDecl(raw_ostream &OS, const Decl *D) {
Richard Smithf5f43542013-02-07 01:35:44 +0000635 switch (D->getKind()) {
636#define DECL(DERIVED, BASE) \
637 case Decl::DERIVED: \
Richard Smith71bec062013-10-15 21:58:30 +0000638 return dumpPreviousDeclImpl(OS, cast<DERIVED##Decl>(D));
Richard Smithf5f43542013-02-07 01:35:44 +0000639#define ABSTRACT_DECL(DECL)
640#include "clang/AST/DeclNodes.inc"
641 }
642 llvm_unreachable("Decl that isn't part of DeclNodes.inc!");
643}
644
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000645//===----------------------------------------------------------------------===//
646// C++ Utilities
647//===----------------------------------------------------------------------===//
648
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000649void ASTDumper::dumpCXXCtorInitializer(const CXXCtorInitializer *Init) {
Richard Smithf7514452014-10-30 21:02:37 +0000650 dumpChild([=] {
651 OS << "CXXCtorInitializer";
652 if (Init->isAnyMemberInitializer()) {
653 OS << ' ';
Stephen Kellyd8744a72018-12-05 21:12:39 +0000654 NodeDumper.dumpBareDeclRef(Init->getAnyMember());
Richard Smithf7514452014-10-30 21:02:37 +0000655 } else if (Init->isBaseInitializer()) {
Stephen Kellyd8744a72018-12-05 21:12:39 +0000656 NodeDumper.dumpType(QualType(Init->getBaseClass(), 0));
Richard Smithf7514452014-10-30 21:02:37 +0000657 } else if (Init->isDelegatingInitializer()) {
Stephen Kellyd8744a72018-12-05 21:12:39 +0000658 NodeDumper.dumpType(Init->getTypeSourceInfo()->getType());
Richard Smithf7514452014-10-30 21:02:37 +0000659 } else {
660 llvm_unreachable("Unknown initializer type");
661 }
662 dumpStmt(Init->getInit());
663 });
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000664}
665
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000666void ASTDumper::dumpTemplateParameters(const TemplateParameterList *TPL) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000667 if (!TPL)
668 return;
669
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000670 for (TemplateParameterList::const_iterator I = TPL->begin(), E = TPL->end();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000671 I != E; ++I)
672 dumpDecl(*I);
673}
674
675void ASTDumper::dumpTemplateArgumentListInfo(
676 const TemplateArgumentListInfo &TALI) {
Richard Smithf7514452014-10-30 21:02:37 +0000677 for (unsigned i = 0, e = TALI.size(); i < e; ++i)
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000678 dumpTemplateArgumentLoc(TALI[i]);
679}
680
Stephen Kelly43835952018-12-10 21:03:00 +0000681void ASTDumper::dumpTemplateArgumentLoc(const TemplateArgumentLoc &A,
Stephen Kelly1be0bea2018-12-10 21:04:04 +0000682 const Decl *From, const char *Label) {
683 dumpTemplateArgument(A.getArgument(), A.getSourceRange(), From, Label);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000684}
685
686void ASTDumper::dumpTemplateArgumentList(const TemplateArgumentList &TAL) {
687 for (unsigned i = 0, e = TAL.size(); i < e; ++i)
688 dumpTemplateArgument(TAL[i]);
689}
690
Stephen Kelly43835952018-12-10 21:03:00 +0000691void ASTDumper::dumpTemplateArgument(const TemplateArgument &A, SourceRange R,
Stephen Kelly1be0bea2018-12-10 21:04:04 +0000692 const Decl *From, const char *Label) {
Richard Smithf7514452014-10-30 21:02:37 +0000693 dumpChild([=] {
694 OS << "TemplateArgument";
695 if (R.isValid())
Stephen Kellyd8744a72018-12-05 21:12:39 +0000696 NodeDumper.dumpSourceRange(R);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000697
Stephen Kelly1be0bea2018-12-10 21:04:04 +0000698 if (From)
699 dumpDeclRef(From, Label);
Stephen Kelly43835952018-12-10 21:03:00 +0000700
Richard Smithf7514452014-10-30 21:02:37 +0000701 switch (A.getKind()) {
702 case TemplateArgument::Null:
703 OS << " null";
704 break;
705 case TemplateArgument::Type:
706 OS << " type";
Stephen Kellyd8744a72018-12-05 21:12:39 +0000707 NodeDumper.dumpType(A.getAsType());
Richard Smithf7514452014-10-30 21:02:37 +0000708 break;
709 case TemplateArgument::Declaration:
710 OS << " decl";
711 dumpDeclRef(A.getAsDecl());
712 break;
713 case TemplateArgument::NullPtr:
714 OS << " nullptr";
715 break;
716 case TemplateArgument::Integral:
717 OS << " integral " << A.getAsIntegral();
718 break;
719 case TemplateArgument::Template:
720 OS << " template ";
721 A.getAsTemplate().dump(OS);
722 break;
723 case TemplateArgument::TemplateExpansion:
Richard Trieu59c289f2018-08-21 22:55:26 +0000724 OS << " template expansion ";
Richard Smithf7514452014-10-30 21:02:37 +0000725 A.getAsTemplateOrTemplatePattern().dump(OS);
726 break;
727 case TemplateArgument::Expression:
728 OS << " expr";
729 dumpStmt(A.getAsExpr());
730 break;
731 case TemplateArgument::Pack:
732 OS << " pack";
733 for (TemplateArgument::pack_iterator I = A.pack_begin(), E = A.pack_end();
734 I != E; ++I)
735 dumpTemplateArgument(*I);
736 break;
Richard Trieude5cc7d2013-01-31 01:44:26 +0000737 }
Richard Smithf7514452014-10-30 21:02:37 +0000738 });
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000739}
740
Chris Lattner11e30d32007-08-30 06:17:34 +0000741//===----------------------------------------------------------------------===//
Douglas Gregor85f3f952015-07-07 03:57:15 +0000742// Objective-C Utilities
743//===----------------------------------------------------------------------===//
744void ASTDumper::dumpObjCTypeParamList(const ObjCTypeParamList *typeParams) {
745 if (!typeParams)
746 return;
747
748 for (auto typeParam : *typeParams) {
749 dumpDecl(typeParam);
750 }
751}
752
753//===----------------------------------------------------------------------===//
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000754// Decl dumping methods.
Chris Lattnercbe4f772007-08-08 22:51:59 +0000755//===----------------------------------------------------------------------===//
756
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000757void ASTDumper::dumpDecl(const Decl *D) {
Richard Smithf7514452014-10-30 21:02:37 +0000758 dumpChild([=] {
759 if (!D) {
Stephen Kelly27e948c2018-11-29 19:30:37 +0000760 ColorScope Color(OS, ShowColors, NullColor);
Richard Smithf7514452014-10-30 21:02:37 +0000761 OS << "<<<NULL>>>";
762 return;
763 }
Mike Stump11289f42009-09-09 15:08:12 +0000764
Richard Smithf7514452014-10-30 21:02:37 +0000765 {
Stephen Kelly27e948c2018-11-29 19:30:37 +0000766 ColorScope Color(OS, ShowColors, DeclKindNameColor);
Richard Smithf7514452014-10-30 21:02:37 +0000767 OS << D->getDeclKindName() << "Decl";
768 }
Stephen Kellyd8744a72018-12-05 21:12:39 +0000769 NodeDumper.dumpPointer(D);
Richard Smithf7514452014-10-30 21:02:37 +0000770 if (D->getLexicalDeclContext() != D->getDeclContext())
771 OS << " parent " << cast<Decl>(D->getDeclContext());
772 dumpPreviousDecl(OS, D);
Stephen Kellyd8744a72018-12-05 21:12:39 +0000773 NodeDumper.dumpSourceRange(D->getSourceRange());
Richard Smithf7514452014-10-30 21:02:37 +0000774 OS << ' ';
Stephen Kellyd8744a72018-12-05 21:12:39 +0000775 NodeDumper.dumpLocation(D->getLocation());
Richard Smith26342f92017-05-17 00:24:14 +0000776 if (D->isFromASTFile())
777 OS << " imported";
778 if (Module *M = D->getOwningModule())
Richard Smithf7514452014-10-30 21:02:37 +0000779 OS << " in " << M->getFullModuleName();
Richard Smitha2eb4092015-06-22 18:47:01 +0000780 if (auto *ND = dyn_cast<NamedDecl>(D))
781 for (Module *M : D->getASTContext().getModulesWithMergedDefinition(
782 const_cast<NamedDecl *>(ND)))
783 dumpChild([=] { OS << "also in " << M->getFullModuleName(); });
Richard Smithf7514452014-10-30 21:02:37 +0000784 if (const NamedDecl *ND = dyn_cast<NamedDecl>(D))
785 if (ND->isHidden())
786 OS << " hidden";
787 if (D->isImplicit())
788 OS << " implicit";
789 if (D->isUsed())
790 OS << " used";
791 else if (D->isThisDeclarationReferenced())
792 OS << " referenced";
793 if (D->isInvalidDecl())
794 OS << " invalid";
Hans Wennborg76b00532014-12-05 22:38:57 +0000795 if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
796 if (FD->isConstexpr())
797 OS << " constexpr";
798
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000799
Richard Smithf7514452014-10-30 21:02:37 +0000800 ConstDeclVisitor<ASTDumper>::Visit(D);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000801
Richard Smithf7514452014-10-30 21:02:37 +0000802 for (Decl::attr_iterator I = D->attr_begin(), E = D->attr_end(); I != E;
803 ++I)
804 dumpAttr(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000805
Richard Smithf7514452014-10-30 21:02:37 +0000806 if (const FullComment *Comment =
807 D->getASTContext().getLocalCommentForDeclUncached(D))
Stephen Kelly570b2972018-12-09 13:18:55 +0000808 dumpComment(Comment, Comment);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000809
Richard Smithf7514452014-10-30 21:02:37 +0000810 // Decls within functions are visited by the body.
Stephen Kelly39271a12018-12-09 13:20:43 +0000811 if (!isa<FunctionDecl>(*D) && !isa<ObjCMethodDecl>(*D)) {
812 auto DC = dyn_cast<DeclContext>(D);
813 if (DC &&
814 (DC->hasExternalLexicalStorage() ||
815 (Deserialize ? DC->decls_begin() != DC->decls_end()
816 : DC->noload_decls_begin() != DC->noload_decls_end())))
817 dumpDeclContext(DC);
818 }
Richard Smithf7514452014-10-30 21:02:37 +0000819 });
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000820}
821
Stephen Kellyd8744a72018-12-05 21:12:39 +0000822void ASTDumper::VisitLabelDecl(const LabelDecl *D) { NodeDumper.dumpName(D); }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000823
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000824void ASTDumper::VisitTypedefDecl(const TypedefDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +0000825 NodeDumper.dumpName(D);
826 NodeDumper.dumpType(D->getUnderlyingType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000827 if (D->isModulePrivate())
828 OS << " __module_private__";
Richard Smithba3a4f92016-01-12 21:59:26 +0000829 dumpTypeAsChild(D->getUnderlyingType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000830}
831
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000832void ASTDumper::VisitEnumDecl(const EnumDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000833 if (D->isScoped()) {
834 if (D->isScopedUsingClassTag())
835 OS << " class";
836 else
837 OS << " struct";
838 }
Stephen Kellyd8744a72018-12-05 21:12:39 +0000839 NodeDumper.dumpName(D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000840 if (D->isModulePrivate())
841 OS << " __module_private__";
842 if (D->isFixed())
Stephen Kellyd8744a72018-12-05 21:12:39 +0000843 NodeDumper.dumpType(D->getIntegerType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000844}
845
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000846void ASTDumper::VisitRecordDecl(const RecordDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000847 OS << ' ' << D->getKindName();
Stephen Kellyd8744a72018-12-05 21:12:39 +0000848 NodeDumper.dumpName(D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000849 if (D->isModulePrivate())
850 OS << " __module_private__";
Richard Smith99bc1b92013-08-30 05:32:29 +0000851 if (D->isCompleteDefinition())
852 OS << " definition";
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000853}
854
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000855void ASTDumper::VisitEnumConstantDecl(const EnumConstantDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +0000856 NodeDumper.dumpName(D);
857 NodeDumper.dumpType(D->getType());
Richard Smithf7514452014-10-30 21:02:37 +0000858 if (const Expr *Init = D->getInitExpr())
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000859 dumpStmt(Init);
860}
861
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000862void ASTDumper::VisitIndirectFieldDecl(const IndirectFieldDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +0000863 NodeDumper.dumpName(D);
864 NodeDumper.dumpType(D->getType());
Richard Smithdcc2c452014-03-17 23:00:06 +0000865
Richard Smith8aa49222014-03-18 00:35:12 +0000866 for (auto *Child : D->chain())
Richard Smithf7514452014-10-30 21:02:37 +0000867 dumpDeclRef(Child);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000868}
869
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000870void ASTDumper::VisitFunctionDecl(const FunctionDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +0000871 NodeDumper.dumpName(D);
872 NodeDumper.dumpType(D->getType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000873
Rafael Espindola6ae7e502013-04-03 19:27:57 +0000874 StorageClass SC = D->getStorageClass();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000875 if (SC != SC_None)
876 OS << ' ' << VarDecl::getStorageClassSpecifierString(SC);
877 if (D->isInlineSpecified())
878 OS << " inline";
879 if (D->isVirtualAsWritten())
880 OS << " virtual";
881 if (D->isModulePrivate())
882 OS << " __module_private__";
883
884 if (D->isPure())
885 OS << " pure";
Richard Smith5a2e6b92016-11-21 23:43:54 +0000886 if (D->isDefaulted()) {
887 OS << " default";
888 if (D->isDeleted())
889 OS << "_delete";
890 }
891 if (D->isDeletedAsWritten())
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000892 OS << " delete";
Richard Smith5a2e6b92016-11-21 23:43:54 +0000893 if (D->isTrivial())
894 OS << " trivial";
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000895
Richard Smithadaa0152013-05-17 02:09:46 +0000896 if (const FunctionProtoType *FPT = D->getType()->getAs<FunctionProtoType>()) {
897 FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo();
Richard Smith8acb4282014-07-31 21:57:55 +0000898 switch (EPI.ExceptionSpec.Type) {
Richard Smithadaa0152013-05-17 02:09:46 +0000899 default: break;
900 case EST_Unevaluated:
Richard Smith8acb4282014-07-31 21:57:55 +0000901 OS << " noexcept-unevaluated " << EPI.ExceptionSpec.SourceDecl;
Richard Smithadaa0152013-05-17 02:09:46 +0000902 break;
903 case EST_Uninstantiated:
Richard Smith8acb4282014-07-31 21:57:55 +0000904 OS << " noexcept-uninstantiated " << EPI.ExceptionSpec.SourceTemplate;
Richard Smithadaa0152013-05-17 02:09:46 +0000905 break;
906 }
907 }
908
Richard Smithf7514452014-10-30 21:02:37 +0000909 if (const FunctionTemplateSpecializationInfo *FTSI =
910 D->getTemplateSpecializationInfo())
Richard Trieude5cc7d2013-01-31 01:44:26 +0000911 dumpTemplateArgumentList(*FTSI->TemplateArguments);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000912
Richard Smith8a639892015-01-24 01:07:20 +0000913 if (!D->param_begin() && D->getNumParams())
914 dumpChild([=] { OS << "<<NULL params x " << D->getNumParams() << ">>"; });
915 else
David Majnemera3debed2016-06-24 05:33:44 +0000916 for (const ParmVarDecl *Parameter : D->parameters())
917 dumpDecl(Parameter);
Richard Smithf7514452014-10-30 21:02:37 +0000918
919 if (const CXXConstructorDecl *C = dyn_cast<CXXConstructorDecl>(D))
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000920 for (CXXConstructorDecl::init_const_iterator I = C->init_begin(),
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000921 E = C->init_end();
Richard Smithf7514452014-10-30 21:02:37 +0000922 I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000923 dumpCXXCtorInitializer(*I);
924
Lenar Safin9ae21552017-07-29 20:42:58 +0000925 if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(D)) {
Lang Hames19e07e12017-06-20 21:06:00 +0000926 if (MD->size_overridden_methods() != 0) {
Aaron Ballman8c208282017-12-21 21:42:42 +0000927 auto dumpOverride = [=](const CXXMethodDecl *D) {
928 SplitQualType T_split = D->getType().split();
929 OS << D << " " << D->getParent()->getName()
930 << "::" << D->getNameAsString() << " '"
931 << QualType::getAsString(T_split, PrintPolicy) << "'";
932 };
Lang Hames19e07e12017-06-20 21:06:00 +0000933
934 dumpChild([=] {
Benjamin Krameracfa3392017-12-17 23:52:45 +0000935 auto Overrides = MD->overridden_methods();
Lang Hames19e07e12017-06-20 21:06:00 +0000936 OS << "Overrides: [ ";
Benjamin Krameracfa3392017-12-17 23:52:45 +0000937 dumpOverride(*Overrides.begin());
Lang Hames19e07e12017-06-20 21:06:00 +0000938 for (const auto *Override :
Benjamin Krameracfa3392017-12-17 23:52:45 +0000939 llvm::make_range(Overrides.begin() + 1, Overrides.end())) {
Lenar Safin9ae21552017-07-29 20:42:58 +0000940 OS << ", ";
Lang Hames19e07e12017-06-20 21:06:00 +0000941 dumpOverride(Override);
Lenar Safin9ae21552017-07-29 20:42:58 +0000942 }
Lang Hames19e07e12017-06-20 21:06:00 +0000943 OS << " ]";
944 });
945 }
Lenar Safin9ae21552017-07-29 20:42:58 +0000946 }
Lang Hames19e07e12017-06-20 21:06:00 +0000947
Richard Smithf7514452014-10-30 21:02:37 +0000948 if (D->doesThisDeclarationHaveABody())
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000949 dumpStmt(D->getBody());
950}
951
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000952void ASTDumper::VisitFieldDecl(const FieldDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +0000953 NodeDumper.dumpName(D);
954 NodeDumper.dumpType(D->getType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000955 if (D->isMutable())
956 OS << " mutable";
957 if (D->isModulePrivate())
958 OS << " __module_private__";
Richard Trieude5cc7d2013-01-31 01:44:26 +0000959
Richard Smithf7514452014-10-30 21:02:37 +0000960 if (D->isBitField())
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000961 dumpStmt(D->getBitWidth());
Richard Smithf7514452014-10-30 21:02:37 +0000962 if (Expr *Init = D->getInClassInitializer())
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000963 dumpStmt(Init);
964}
965
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000966void ASTDumper::VisitVarDecl(const VarDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +0000967 NodeDumper.dumpName(D);
968 NodeDumper.dumpType(D->getType());
Rafael Espindola6ae7e502013-04-03 19:27:57 +0000969 StorageClass SC = D->getStorageClass();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000970 if (SC != SC_None)
971 OS << ' ' << VarDecl::getStorageClassSpecifierString(SC);
Richard Smithfd3834f2013-04-13 02:43:54 +0000972 switch (D->getTLSKind()) {
973 case VarDecl::TLS_None: break;
974 case VarDecl::TLS_Static: OS << " tls"; break;
975 case VarDecl::TLS_Dynamic: OS << " tls_dynamic"; break;
976 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000977 if (D->isModulePrivate())
978 OS << " __module_private__";
979 if (D->isNRVOVariable())
980 OS << " nrvo";
Richard Smith62f19e72016-06-25 00:15:56 +0000981 if (D->isInline())
982 OS << " inline";
983 if (D->isConstexpr())
984 OS << " constexpr";
Richard Trieude5cc7d2013-01-31 01:44:26 +0000985 if (D->hasInit()) {
Richard Smithd9967cc2014-07-10 22:54:03 +0000986 switch (D->getInitStyle()) {
987 case VarDecl::CInit: OS << " cinit"; break;
988 case VarDecl::CallInit: OS << " callinit"; break;
989 case VarDecl::ListInit: OS << " listinit"; break;
990 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000991 dumpStmt(D->getInit());
Richard Trieude5cc7d2013-01-31 01:44:26 +0000992 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000993}
994
Richard Smithbdb84f32016-07-22 23:36:59 +0000995void ASTDumper::VisitDecompositionDecl(const DecompositionDecl *D) {
996 VisitVarDecl(D);
997 for (auto *B : D->bindings())
998 dumpDecl(B);
999}
1000
Richard Smith7873de02016-08-11 22:25:46 +00001001void ASTDumper::VisitBindingDecl(const BindingDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +00001002 NodeDumper.dumpName(D);
1003 NodeDumper.dumpType(D->getType());
Richard Smith7873de02016-08-11 22:25:46 +00001004 if (auto *E = D->getBinding())
1005 dumpStmt(E);
1006}
1007
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001008void ASTDumper::VisitFileScopeAsmDecl(const FileScopeAsmDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001009 dumpStmt(D->getAsmString());
1010}
1011
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001012void ASTDumper::VisitImportDecl(const ImportDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001013 OS << ' ' << D->getImportedModule()->getFullModuleName();
1014}
1015
Nico Weber66220292016-03-02 17:28:48 +00001016void ASTDumper::VisitPragmaCommentDecl(const PragmaCommentDecl *D) {
1017 OS << ' ';
1018 switch (D->getCommentKind()) {
1019 case PCK_Unknown: llvm_unreachable("unexpected pragma comment kind");
1020 case PCK_Compiler: OS << "compiler"; break;
1021 case PCK_ExeStr: OS << "exestr"; break;
1022 case PCK_Lib: OS << "lib"; break;
1023 case PCK_Linker: OS << "linker"; break;
1024 case PCK_User: OS << "user"; break;
1025 }
1026 StringRef Arg = D->getArg();
1027 if (!Arg.empty())
1028 OS << " \"" << Arg << "\"";
1029}
1030
Nico Webercbbaeb12016-03-02 19:28:54 +00001031void ASTDumper::VisitPragmaDetectMismatchDecl(
1032 const PragmaDetectMismatchDecl *D) {
1033 OS << " \"" << D->getName() << "\" \"" << D->getValue() << "\"";
1034}
1035
Alexey Bataev958b9e72016-03-31 09:30:50 +00001036void ASTDumper::VisitCapturedDecl(const CapturedDecl *D) {
1037 dumpStmt(D->getBody());
1038}
1039
1040//===----------------------------------------------------------------------===//
1041// OpenMP Declarations
1042//===----------------------------------------------------------------------===//
1043
1044void ASTDumper::VisitOMPThreadPrivateDecl(const OMPThreadPrivateDecl *D) {
1045 for (auto *E : D->varlists())
1046 dumpStmt(E);
1047}
1048
1049void ASTDumper::VisitOMPDeclareReductionDecl(const OMPDeclareReductionDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +00001050 NodeDumper.dumpName(D);
1051 NodeDumper.dumpType(D->getType());
Alexey Bataev958b9e72016-03-31 09:30:50 +00001052 OS << " combiner";
Stephen Kelly266dc192018-12-10 20:53:39 +00001053 NodeDumper.dumpPointer(D->getCombiner());
1054 if (const auto *Initializer = D->getInitializer()) {
Alexey Bataev958b9e72016-03-31 09:30:50 +00001055 OS << " initializer";
Stephen Kelly266dc192018-12-10 20:53:39 +00001056 NodeDumper.dumpPointer(Initializer);
Alexey Bataev070f43a2017-09-06 14:49:58 +00001057 switch (D->getInitializerKind()) {
1058 case OMPDeclareReductionDecl::DirectInit:
1059 OS << " omp_priv = ";
1060 break;
1061 case OMPDeclareReductionDecl::CopyInit:
1062 OS << " omp_priv ()";
1063 break;
1064 case OMPDeclareReductionDecl::CallInit:
1065 break;
1066 }
Alexey Bataev958b9e72016-03-31 09:30:50 +00001067 }
Stephen Kelly266dc192018-12-10 20:53:39 +00001068
1069 dumpStmt(D->getCombiner());
1070 if (const auto *Initializer = D->getInitializer())
1071 dumpStmt(Initializer);
Alexey Bataev958b9e72016-03-31 09:30:50 +00001072}
1073
Kelvin Li1408f912018-09-26 04:28:39 +00001074void ASTDumper::VisitOMPRequiresDecl(const OMPRequiresDecl *D) {
1075 for (auto *C : D->clauselists()) {
1076 dumpChild([=] {
1077 if (!C) {
Stephen Kelly27e948c2018-11-29 19:30:37 +00001078 ColorScope Color(OS, ShowColors, NullColor);
Kelvin Li1408f912018-09-26 04:28:39 +00001079 OS << "<<<NULL>>> OMPClause";
1080 return;
1081 }
1082 {
Stephen Kelly27e948c2018-11-29 19:30:37 +00001083 ColorScope Color(OS, ShowColors, AttrColor);
Kelvin Li1408f912018-09-26 04:28:39 +00001084 StringRef ClauseName(getOpenMPClauseName(C->getClauseKind()));
1085 OS << "OMP" << ClauseName.substr(/*Start=*/0, /*N=*/1).upper()
1086 << ClauseName.drop_front() << "Clause";
1087 }
Stephen Kellyd8744a72018-12-05 21:12:39 +00001088 NodeDumper.dumpPointer(C);
1089 NodeDumper.dumpSourceRange(SourceRange(C->getBeginLoc(), C->getEndLoc()));
Kelvin Li1408f912018-09-26 04:28:39 +00001090 });
1091 }
1092}
1093
Alexey Bataev958b9e72016-03-31 09:30:50 +00001094void ASTDumper::VisitOMPCapturedExprDecl(const OMPCapturedExprDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +00001095 NodeDumper.dumpName(D);
1096 NodeDumper.dumpType(D->getType());
Alexey Bataev958b9e72016-03-31 09:30:50 +00001097 dumpStmt(D->getInit());
1098}
Nico Webercbbaeb12016-03-02 19:28:54 +00001099
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001100//===----------------------------------------------------------------------===//
1101// C++ Declarations
1102//===----------------------------------------------------------------------===//
1103
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001104void ASTDumper::VisitNamespaceDecl(const NamespaceDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +00001105 NodeDumper.dumpName(D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001106 if (D->isInline())
1107 OS << " inline";
1108 if (!D->isOriginalNamespace())
1109 dumpDeclRef(D->getOriginalNamespace(), "original");
1110}
1111
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001112void ASTDumper::VisitUsingDirectiveDecl(const UsingDirectiveDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001113 OS << ' ';
Stephen Kellyd8744a72018-12-05 21:12:39 +00001114 NodeDumper.dumpBareDeclRef(D->getNominatedNamespace());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001115}
1116
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001117void ASTDumper::VisitNamespaceAliasDecl(const NamespaceAliasDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +00001118 NodeDumper.dumpName(D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001119 dumpDeclRef(D->getAliasedNamespace());
1120}
1121
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001122void ASTDumper::VisitTypeAliasDecl(const TypeAliasDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +00001123 NodeDumper.dumpName(D);
1124 NodeDumper.dumpType(D->getUnderlyingType());
Richard Smithba3a4f92016-01-12 21:59:26 +00001125 dumpTypeAsChild(D->getUnderlyingType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001126}
1127
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001128void ASTDumper::VisitTypeAliasTemplateDecl(const TypeAliasTemplateDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +00001129 NodeDumper.dumpName(D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001130 dumpTemplateParameters(D->getTemplateParameters());
1131 dumpDecl(D->getTemplatedDecl());
1132}
1133
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001134void ASTDumper::VisitCXXRecordDecl(const CXXRecordDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001135 VisitRecordDecl(D);
1136 if (!D->isCompleteDefinition())
1137 return;
1138
Richard Smithdfc4bff2017-09-22 00:11:15 +00001139 dumpChild([=] {
1140 {
Stephen Kelly27e948c2018-11-29 19:30:37 +00001141 ColorScope Color(OS, ShowColors, DeclKindNameColor);
Richard Smithdfc4bff2017-09-22 00:11:15 +00001142 OS << "DefinitionData";
1143 }
1144#define FLAG(fn, name) if (D->fn()) OS << " " #name;
1145 FLAG(isParsingBaseSpecifiers, parsing_base_specifiers);
1146
1147 FLAG(isGenericLambda, generic);
1148 FLAG(isLambda, lambda);
1149
1150 FLAG(canPassInRegisters, pass_in_registers);
1151 FLAG(isEmpty, empty);
1152 FLAG(isAggregate, aggregate);
1153 FLAG(isStandardLayout, standard_layout);
1154 FLAG(isTriviallyCopyable, trivially_copyable);
1155 FLAG(isPOD, pod);
1156 FLAG(isTrivial, trivial);
1157 FLAG(isPolymorphic, polymorphic);
1158 FLAG(isAbstract, abstract);
1159 FLAG(isLiteral, literal);
1160
1161 FLAG(hasUserDeclaredConstructor, has_user_declared_ctor);
1162 FLAG(hasConstexprNonCopyMoveConstructor, has_constexpr_non_copy_move_ctor);
1163 FLAG(hasMutableFields, has_mutable_fields);
1164 FLAG(hasVariantMembers, has_variant_members);
1165 FLAG(allowConstDefaultInit, can_const_default_init);
1166
1167 dumpChild([=] {
1168 {
Stephen Kelly27e948c2018-11-29 19:30:37 +00001169 ColorScope Color(OS, ShowColors, DeclKindNameColor);
Richard Smithdfc4bff2017-09-22 00:11:15 +00001170 OS << "DefaultConstructor";
1171 }
1172 FLAG(hasDefaultConstructor, exists);
1173 FLAG(hasTrivialDefaultConstructor, trivial);
1174 FLAG(hasNonTrivialDefaultConstructor, non_trivial);
1175 FLAG(hasUserProvidedDefaultConstructor, user_provided);
1176 FLAG(hasConstexprDefaultConstructor, constexpr);
1177 FLAG(needsImplicitDefaultConstructor, needs_implicit);
1178 FLAG(defaultedDefaultConstructorIsConstexpr, defaulted_is_constexpr);
1179 });
1180
1181 dumpChild([=] {
1182 {
Stephen Kelly27e948c2018-11-29 19:30:37 +00001183 ColorScope Color(OS, ShowColors, DeclKindNameColor);
Richard Smithdfc4bff2017-09-22 00:11:15 +00001184 OS << "CopyConstructor";
1185 }
1186 FLAG(hasSimpleCopyConstructor, simple);
1187 FLAG(hasTrivialCopyConstructor, trivial);
1188 FLAG(hasNonTrivialCopyConstructor, non_trivial);
1189 FLAG(hasUserDeclaredCopyConstructor, user_declared);
1190 FLAG(hasCopyConstructorWithConstParam, has_const_param);
1191 FLAG(needsImplicitCopyConstructor, needs_implicit);
1192 FLAG(needsOverloadResolutionForCopyConstructor,
1193 needs_overload_resolution);
1194 if (!D->needsOverloadResolutionForCopyConstructor())
1195 FLAG(defaultedCopyConstructorIsDeleted, defaulted_is_deleted);
1196 FLAG(implicitCopyConstructorHasConstParam, implicit_has_const_param);
1197 });
1198
1199 dumpChild([=] {
1200 {
Stephen Kelly27e948c2018-11-29 19:30:37 +00001201 ColorScope Color(OS, ShowColors, DeclKindNameColor);
Richard Smithdfc4bff2017-09-22 00:11:15 +00001202 OS << "MoveConstructor";
1203 }
1204 FLAG(hasMoveConstructor, exists);
1205 FLAG(hasSimpleMoveConstructor, simple);
1206 FLAG(hasTrivialMoveConstructor, trivial);
1207 FLAG(hasNonTrivialMoveConstructor, non_trivial);
1208 FLAG(hasUserDeclaredMoveConstructor, user_declared);
1209 FLAG(needsImplicitMoveConstructor, needs_implicit);
1210 FLAG(needsOverloadResolutionForMoveConstructor,
1211 needs_overload_resolution);
1212 if (!D->needsOverloadResolutionForMoveConstructor())
1213 FLAG(defaultedMoveConstructorIsDeleted, defaulted_is_deleted);
1214 });
1215
1216 dumpChild([=] {
1217 {
Stephen Kelly27e948c2018-11-29 19:30:37 +00001218 ColorScope Color(OS, ShowColors, DeclKindNameColor);
Richard Smithdfc4bff2017-09-22 00:11:15 +00001219 OS << "CopyAssignment";
1220 }
1221 FLAG(hasTrivialCopyAssignment, trivial);
1222 FLAG(hasNonTrivialCopyAssignment, non_trivial);
1223 FLAG(hasCopyAssignmentWithConstParam, has_const_param);
1224 FLAG(hasUserDeclaredCopyAssignment, user_declared);
1225 FLAG(needsImplicitCopyAssignment, needs_implicit);
1226 FLAG(needsOverloadResolutionForCopyAssignment, needs_overload_resolution);
1227 FLAG(implicitCopyAssignmentHasConstParam, implicit_has_const_param);
1228 });
1229
1230 dumpChild([=] {
1231 {
Stephen Kelly27e948c2018-11-29 19:30:37 +00001232 ColorScope Color(OS, ShowColors, DeclKindNameColor);
Richard Smithdfc4bff2017-09-22 00:11:15 +00001233 OS << "MoveAssignment";
1234 }
1235 FLAG(hasMoveAssignment, exists);
1236 FLAG(hasSimpleMoveAssignment, simple);
1237 FLAG(hasTrivialMoveAssignment, trivial);
1238 FLAG(hasNonTrivialMoveAssignment, non_trivial);
1239 FLAG(hasUserDeclaredMoveAssignment, user_declared);
1240 FLAG(needsImplicitMoveAssignment, needs_implicit);
1241 FLAG(needsOverloadResolutionForMoveAssignment, needs_overload_resolution);
1242 });
1243
1244 dumpChild([=] {
1245 {
Stephen Kelly27e948c2018-11-29 19:30:37 +00001246 ColorScope Color(OS, ShowColors, DeclKindNameColor);
Richard Smithdfc4bff2017-09-22 00:11:15 +00001247 OS << "Destructor";
1248 }
1249 FLAG(hasSimpleDestructor, simple);
1250 FLAG(hasIrrelevantDestructor, irrelevant);
1251 FLAG(hasTrivialDestructor, trivial);
1252 FLAG(hasNonTrivialDestructor, non_trivial);
1253 FLAG(hasUserDeclaredDestructor, user_declared);
1254 FLAG(needsImplicitDestructor, needs_implicit);
1255 FLAG(needsOverloadResolutionForDestructor, needs_overload_resolution);
1256 if (!D->needsOverloadResolutionForDestructor())
1257 FLAG(defaultedDestructorIsDeleted, defaulted_is_deleted);
1258 });
1259 });
1260
Aaron Ballman574705e2014-03-13 15:41:46 +00001261 for (const auto &I : D->bases()) {
Richard Smithf7514452014-10-30 21:02:37 +00001262 dumpChild([=] {
1263 if (I.isVirtual())
1264 OS << "virtual ";
Stephen Kellyd8744a72018-12-05 21:12:39 +00001265 NodeDumper.dumpAccessSpecifier(I.getAccessSpecifier());
1266 NodeDumper.dumpType(I.getType());
Richard Smithf7514452014-10-30 21:02:37 +00001267 if (I.isPackExpansion())
1268 OS << "...";
1269 });
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001270 }
1271}
1272
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001273void ASTDumper::VisitStaticAssertDecl(const StaticAssertDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001274 dumpStmt(D->getAssertExpr());
1275 dumpStmt(D->getMessage());
1276}
1277
Stephen Kelly24136382018-12-09 13:33:30 +00001278template <typename SpecializationDecl>
1279void ASTDumper::dumpTemplateDeclSpecialization(const SpecializationDecl *D,
1280 bool DumpExplicitInst,
1281 bool DumpRefOnly) {
Richard Smithcbdf7332014-03-18 02:07:28 +00001282 bool DumpedAny = false;
1283 for (auto *RedeclWithBadType : D->redecls()) {
1284 // FIXME: The redecls() range sometimes has elements of a less-specific
1285 // type. (In particular, ClassTemplateSpecializationDecl::redecls() gives
1286 // us TagDecls, and should give CXXRecordDecls).
1287 auto *Redecl = dyn_cast<SpecializationDecl>(RedeclWithBadType);
1288 if (!Redecl) {
1289 // Found the injected-class-name for a class template. This will be dumped
1290 // as part of its surrounding class so we don't need to dump it here.
1291 assert(isa<CXXRecordDecl>(RedeclWithBadType) &&
1292 "expected an injected-class-name");
1293 continue;
1294 }
1295
1296 switch (Redecl->getTemplateSpecializationKind()) {
1297 case TSK_ExplicitInstantiationDeclaration:
1298 case TSK_ExplicitInstantiationDefinition:
1299 if (!DumpExplicitInst)
1300 break;
Adrian Prantlf3b3ccd2017-12-19 22:06:11 +00001301 LLVM_FALLTHROUGH;
Richard Smithcbdf7332014-03-18 02:07:28 +00001302 case TSK_Undeclared:
1303 case TSK_ImplicitInstantiation:
Richard Smithf7514452014-10-30 21:02:37 +00001304 if (DumpRefOnly)
1305 dumpDeclRef(Redecl);
1306 else
1307 dumpDecl(Redecl);
Richard Smithcbdf7332014-03-18 02:07:28 +00001308 DumpedAny = true;
1309 break;
1310 case TSK_ExplicitSpecialization:
1311 break;
1312 }
1313 }
1314
1315 // Ensure we dump at least one decl for each specialization.
1316 if (!DumpedAny)
Richard Smithf7514452014-10-30 21:02:37 +00001317 dumpDeclRef(D);
Richard Smithcbdf7332014-03-18 02:07:28 +00001318}
1319
Stephen Kelly24136382018-12-09 13:33:30 +00001320template <typename TemplateDecl>
1321void ASTDumper::dumpTemplateDecl(const TemplateDecl *D, bool DumpExplicitInst) {
Stephen Kellyd8744a72018-12-05 21:12:39 +00001322 NodeDumper.dumpName(D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001323 dumpTemplateParameters(D->getTemplateParameters());
Richard Smithdcc2c452014-03-17 23:00:06 +00001324
Richard Smithf7514452014-10-30 21:02:37 +00001325 dumpDecl(D->getTemplatedDecl());
Richard Smithdcc2c452014-03-17 23:00:06 +00001326
Richard Smithcbdf7332014-03-18 02:07:28 +00001327 for (auto *Child : D->specializations())
Stephen Kelly24136382018-12-09 13:33:30 +00001328 dumpTemplateDeclSpecialization(Child, DumpExplicitInst,
1329 !D->isCanonicalDecl());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001330}
1331
Richard Smith20ade552014-03-17 23:34:53 +00001332void ASTDumper::VisitFunctionTemplateDecl(const FunctionTemplateDecl *D) {
1333 // FIXME: We don't add a declaration of a function template specialization
1334 // to its context when it's explicitly instantiated, so dump explicit
1335 // instantiations when we dump the template itself.
Stephen Kelly24136382018-12-09 13:33:30 +00001336 dumpTemplateDecl(D, true);
Richard Smith20ade552014-03-17 23:34:53 +00001337}
1338
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001339void ASTDumper::VisitClassTemplateDecl(const ClassTemplateDecl *D) {
Stephen Kelly24136382018-12-09 13:33:30 +00001340 dumpTemplateDecl(D, false);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001341}
1342
1343void ASTDumper::VisitClassTemplateSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001344 const ClassTemplateSpecializationDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001345 VisitCXXRecordDecl(D);
1346 dumpTemplateArgumentList(D->getTemplateArgs());
1347}
1348
1349void ASTDumper::VisitClassTemplatePartialSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001350 const ClassTemplatePartialSpecializationDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001351 VisitClassTemplateSpecializationDecl(D);
1352 dumpTemplateParameters(D->getTemplateParameters());
1353}
1354
1355void ASTDumper::VisitClassScopeFunctionSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001356 const ClassScopeFunctionSpecializationDecl *D) {
Richard Smithc660c8f2018-03-16 13:36:56 +00001357 dumpDecl(D->getSpecialization());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001358 if (D->hasExplicitTemplateArgs())
1359 dumpTemplateArgumentListInfo(D->templateArgs());
1360}
1361
Richard Smithd25789a2013-09-18 01:36:02 +00001362void ASTDumper::VisitVarTemplateDecl(const VarTemplateDecl *D) {
Stephen Kelly24136382018-12-09 13:33:30 +00001363 dumpTemplateDecl(D, false);
Richard Smithd25789a2013-09-18 01:36:02 +00001364}
1365
David Majnemerd9b1a4f2015-11-04 03:40:30 +00001366void ASTDumper::VisitBuiltinTemplateDecl(const BuiltinTemplateDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +00001367 NodeDumper.dumpName(D);
David Majnemerd9b1a4f2015-11-04 03:40:30 +00001368 dumpTemplateParameters(D->getTemplateParameters());
1369}
1370
Richard Smithd25789a2013-09-18 01:36:02 +00001371void ASTDumper::VisitVarTemplateSpecializationDecl(
1372 const VarTemplateSpecializationDecl *D) {
1373 dumpTemplateArgumentList(D->getTemplateArgs());
1374 VisitVarDecl(D);
1375}
1376
1377void ASTDumper::VisitVarTemplatePartialSpecializationDecl(
1378 const VarTemplatePartialSpecializationDecl *D) {
1379 dumpTemplateParameters(D->getTemplateParameters());
1380 VisitVarTemplateSpecializationDecl(D);
1381}
1382
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001383void ASTDumper::VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001384 if (D->wasDeclaredWithTypename())
1385 OS << " typename";
1386 else
1387 OS << " class";
Richard Smith1832a022017-02-21 02:04:03 +00001388 OS << " depth " << D->getDepth() << " index " << D->getIndex();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001389 if (D->isParameterPack())
1390 OS << " ...";
Stephen Kellyd8744a72018-12-05 21:12:39 +00001391 NodeDumper.dumpName(D);
Richard Smithf7514452014-10-30 21:02:37 +00001392 if (D->hasDefaultArgument())
Stephen Kelly43835952018-12-10 21:03:00 +00001393 dumpTemplateArgument(D->getDefaultArgument(), SourceRange(),
1394 D->getDefaultArgStorage().getInheritedFrom(),
1395 D->defaultArgumentWasInherited() ? "inherited from"
1396 : "previous");
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001397}
1398
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001399void ASTDumper::VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +00001400 NodeDumper.dumpType(D->getType());
Richard Smith1832a022017-02-21 02:04:03 +00001401 OS << " depth " << D->getDepth() << " index " << D->getIndex();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001402 if (D->isParameterPack())
1403 OS << " ...";
Stephen Kellyd8744a72018-12-05 21:12:39 +00001404 NodeDumper.dumpName(D);
Richard Smithf7514452014-10-30 21:02:37 +00001405 if (D->hasDefaultArgument())
Stephen Kelly43835952018-12-10 21:03:00 +00001406 dumpTemplateArgument(D->getDefaultArgument(), SourceRange(),
1407 D->getDefaultArgStorage().getInheritedFrom(),
1408 D->defaultArgumentWasInherited() ? "inherited from"
1409 : "previous");
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001410}
1411
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001412void ASTDumper::VisitTemplateTemplateParmDecl(
1413 const TemplateTemplateParmDecl *D) {
Richard Smith1832a022017-02-21 02:04:03 +00001414 OS << " depth " << D->getDepth() << " index " << D->getIndex();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001415 if (D->isParameterPack())
1416 OS << " ...";
Stephen Kellyd8744a72018-12-05 21:12:39 +00001417 NodeDumper.dumpName(D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001418 dumpTemplateParameters(D->getTemplateParameters());
Richard Smithf7514452014-10-30 21:02:37 +00001419 if (D->hasDefaultArgument())
Stephen Kelly43835952018-12-10 21:03:00 +00001420 dumpTemplateArgumentLoc(
1421 D->getDefaultArgument(), D->getDefaultArgStorage().getInheritedFrom(),
1422 D->defaultArgumentWasInherited() ? "inherited from" : "previous");
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001423}
1424
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001425void ASTDumper::VisitUsingDecl(const UsingDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001426 OS << ' ';
Dawn Perchikddd03bf2015-12-05 22:37:55 +00001427 if (D->getQualifier())
1428 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001429 OS << D->getNameAsString();
1430}
1431
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001432void ASTDumper::VisitUnresolvedUsingTypenameDecl(
1433 const UnresolvedUsingTypenameDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001434 OS << ' ';
Dawn Perchikddd03bf2015-12-05 22:37:55 +00001435 if (D->getQualifier())
1436 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001437 OS << D->getNameAsString();
1438}
1439
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001440void ASTDumper::VisitUnresolvedUsingValueDecl(const UnresolvedUsingValueDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001441 OS << ' ';
Dawn Perchikddd03bf2015-12-05 22:37:55 +00001442 if (D->getQualifier())
1443 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001444 OS << D->getNameAsString();
Stephen Kellyd8744a72018-12-05 21:12:39 +00001445 NodeDumper.dumpType(D->getType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001446}
1447
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001448void ASTDumper::VisitUsingShadowDecl(const UsingShadowDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001449 OS << ' ';
Stephen Kellyd8744a72018-12-05 21:12:39 +00001450 NodeDumper.dumpBareDeclRef(D->getTargetDecl());
Richard Smithba3a4f92016-01-12 21:59:26 +00001451 if (auto *TD = dyn_cast<TypeDecl>(D->getUnderlyingDecl()))
1452 dumpTypeAsChild(TD->getTypeForDecl());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001453}
1454
Richard Smith5179eb72016-06-28 19:03:57 +00001455void ASTDumper::VisitConstructorUsingShadowDecl(
1456 const ConstructorUsingShadowDecl *D) {
1457 if (D->constructsVirtualBase())
1458 OS << " virtual";
1459
1460 dumpChild([=] {
1461 OS << "target ";
Stephen Kellyd8744a72018-12-05 21:12:39 +00001462 NodeDumper.dumpBareDeclRef(D->getTargetDecl());
Richard Smith5179eb72016-06-28 19:03:57 +00001463 });
1464
1465 dumpChild([=] {
1466 OS << "nominated ";
Stephen Kellyd8744a72018-12-05 21:12:39 +00001467 NodeDumper.dumpBareDeclRef(D->getNominatedBaseClass());
Richard Smith5179eb72016-06-28 19:03:57 +00001468 OS << ' ';
Stephen Kellyd8744a72018-12-05 21:12:39 +00001469 NodeDumper.dumpBareDeclRef(D->getNominatedBaseClassShadowDecl());
Richard Smith5179eb72016-06-28 19:03:57 +00001470 });
1471
1472 dumpChild([=] {
1473 OS << "constructed ";
Stephen Kellyd8744a72018-12-05 21:12:39 +00001474 NodeDumper.dumpBareDeclRef(D->getConstructedBaseClass());
Richard Smith5179eb72016-06-28 19:03:57 +00001475 OS << ' ';
Stephen Kellyd8744a72018-12-05 21:12:39 +00001476 NodeDumper.dumpBareDeclRef(D->getConstructedBaseClassShadowDecl());
Richard Smith5179eb72016-06-28 19:03:57 +00001477 });
1478}
1479
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001480void ASTDumper::VisitLinkageSpecDecl(const LinkageSpecDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001481 switch (D->getLanguage()) {
1482 case LinkageSpecDecl::lang_c: OS << " C"; break;
1483 case LinkageSpecDecl::lang_cxx: OS << " C++"; break;
1484 }
1485}
1486
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001487void ASTDumper::VisitAccessSpecDecl(const AccessSpecDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001488 OS << ' ';
Stephen Kellyd8744a72018-12-05 21:12:39 +00001489 NodeDumper.dumpAccessSpecifier(D->getAccess());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001490}
1491
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001492void ASTDumper::VisitFriendDecl(const FriendDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001493 if (TypeSourceInfo *T = D->getFriendType())
Stephen Kellyd8744a72018-12-05 21:12:39 +00001494 NodeDumper.dumpType(T->getType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001495 else
1496 dumpDecl(D->getFriendDecl());
1497}
1498
1499//===----------------------------------------------------------------------===//
1500// Obj-C Declarations
1501//===----------------------------------------------------------------------===//
1502
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001503void ASTDumper::VisitObjCIvarDecl(const ObjCIvarDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +00001504 NodeDumper.dumpName(D);
1505 NodeDumper.dumpType(D->getType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001506 if (D->getSynthesize())
1507 OS << " synthesize";
1508
1509 switch (D->getAccessControl()) {
1510 case ObjCIvarDecl::None:
1511 OS << " none";
1512 break;
1513 case ObjCIvarDecl::Private:
1514 OS << " private";
1515 break;
1516 case ObjCIvarDecl::Protected:
1517 OS << " protected";
1518 break;
1519 case ObjCIvarDecl::Public:
1520 OS << " public";
1521 break;
1522 case ObjCIvarDecl::Package:
1523 OS << " package";
1524 break;
1525 }
1526}
1527
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001528void ASTDumper::VisitObjCMethodDecl(const ObjCMethodDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001529 if (D->isInstanceMethod())
1530 OS << " -";
1531 else
1532 OS << " +";
Stephen Kellyd8744a72018-12-05 21:12:39 +00001533 NodeDumper.dumpName(D);
1534 NodeDumper.dumpType(D->getReturnType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001535
Richard Trieude5cc7d2013-01-31 01:44:26 +00001536 if (D->isThisDeclarationADefinition()) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001537 dumpDeclContext(D);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001538 } else {
David Majnemera3debed2016-06-24 05:33:44 +00001539 for (const ParmVarDecl *Parameter : D->parameters())
1540 dumpDecl(Parameter);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001541 }
1542
Richard Smithf7514452014-10-30 21:02:37 +00001543 if (D->isVariadic())
1544 dumpChild([=] { OS << "..."; });
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001545
Richard Smithf7514452014-10-30 21:02:37 +00001546 if (D->hasBody())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001547 dumpStmt(D->getBody());
1548}
1549
Douglas Gregor85f3f952015-07-07 03:57:15 +00001550void ASTDumper::VisitObjCTypeParamDecl(const ObjCTypeParamDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +00001551 NodeDumper.dumpName(D);
Douglas Gregor1ac1b632015-07-07 03:58:54 +00001552 switch (D->getVariance()) {
1553 case ObjCTypeParamVariance::Invariant:
1554 break;
1555
1556 case ObjCTypeParamVariance::Covariant:
1557 OS << " covariant";
1558 break;
1559
1560 case ObjCTypeParamVariance::Contravariant:
1561 OS << " contravariant";
1562 break;
1563 }
1564
Douglas Gregor85f3f952015-07-07 03:57:15 +00001565 if (D->hasExplicitBound())
1566 OS << " bounded";
Stephen Kellyd8744a72018-12-05 21:12:39 +00001567 NodeDumper.dumpType(D->getUnderlyingType());
Douglas Gregor85f3f952015-07-07 03:57:15 +00001568}
1569
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001570void ASTDumper::VisitObjCCategoryDecl(const ObjCCategoryDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +00001571 NodeDumper.dumpName(D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001572 dumpDeclRef(D->getClassInterface());
Douglas Gregor85f3f952015-07-07 03:57:15 +00001573 dumpObjCTypeParamList(D->getTypeParamList());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001574 dumpDeclRef(D->getImplementation());
1575 for (ObjCCategoryDecl::protocol_iterator I = D->protocol_begin(),
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001576 E = D->protocol_end();
Richard Smithf7514452014-10-30 21:02:37 +00001577 I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001578 dumpDeclRef(*I);
1579}
1580
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001581void ASTDumper::VisitObjCCategoryImplDecl(const ObjCCategoryImplDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +00001582 NodeDumper.dumpName(D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001583 dumpDeclRef(D->getClassInterface());
1584 dumpDeclRef(D->getCategoryDecl());
1585}
1586
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001587void ASTDumper::VisitObjCProtocolDecl(const ObjCProtocolDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +00001588 NodeDumper.dumpName(D);
Richard Smithdcc2c452014-03-17 23:00:06 +00001589
Richard Smith7fcb35f2014-03-18 02:37:59 +00001590 for (auto *Child : D->protocols())
Richard Smithf7514452014-10-30 21:02:37 +00001591 dumpDeclRef(Child);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001592}
1593
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001594void ASTDumper::VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +00001595 NodeDumper.dumpName(D);
Douglas Gregor85f3f952015-07-07 03:57:15 +00001596 dumpObjCTypeParamList(D->getTypeParamListAsWritten());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001597 dumpDeclRef(D->getSuperClass(), "super");
Richard Smithdcc2c452014-03-17 23:00:06 +00001598
Richard Smithf7514452014-10-30 21:02:37 +00001599 dumpDeclRef(D->getImplementation());
Richard Smith7fcb35f2014-03-18 02:37:59 +00001600 for (auto *Child : D->protocols())
Richard Smithf7514452014-10-30 21:02:37 +00001601 dumpDeclRef(Child);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001602}
1603
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001604void ASTDumper::VisitObjCImplementationDecl(const ObjCImplementationDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +00001605 NodeDumper.dumpName(D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001606 dumpDeclRef(D->getSuperClass(), "super");
1607 dumpDeclRef(D->getClassInterface());
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001608 for (ObjCImplementationDecl::init_const_iterator I = D->init_begin(),
1609 E = D->init_end();
Richard Smithf7514452014-10-30 21:02:37 +00001610 I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001611 dumpCXXCtorInitializer(*I);
1612}
1613
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001614void ASTDumper::VisitObjCCompatibleAliasDecl(const ObjCCompatibleAliasDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +00001615 NodeDumper.dumpName(D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001616 dumpDeclRef(D->getClassInterface());
1617}
1618
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001619void ASTDumper::VisitObjCPropertyDecl(const ObjCPropertyDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +00001620 NodeDumper.dumpName(D);
1621 NodeDumper.dumpType(D->getType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001622
1623 if (D->getPropertyImplementation() == ObjCPropertyDecl::Required)
1624 OS << " required";
1625 else if (D->getPropertyImplementation() == ObjCPropertyDecl::Optional)
1626 OS << " optional";
1627
1628 ObjCPropertyDecl::PropertyAttributeKind Attrs = D->getPropertyAttributes();
1629 if (Attrs != ObjCPropertyDecl::OBJC_PR_noattr) {
1630 if (Attrs & ObjCPropertyDecl::OBJC_PR_readonly)
1631 OS << " readonly";
1632 if (Attrs & ObjCPropertyDecl::OBJC_PR_assign)
1633 OS << " assign";
1634 if (Attrs & ObjCPropertyDecl::OBJC_PR_readwrite)
1635 OS << " readwrite";
1636 if (Attrs & ObjCPropertyDecl::OBJC_PR_retain)
1637 OS << " retain";
1638 if (Attrs & ObjCPropertyDecl::OBJC_PR_copy)
1639 OS << " copy";
1640 if (Attrs & ObjCPropertyDecl::OBJC_PR_nonatomic)
1641 OS << " nonatomic";
1642 if (Attrs & ObjCPropertyDecl::OBJC_PR_atomic)
1643 OS << " atomic";
1644 if (Attrs & ObjCPropertyDecl::OBJC_PR_weak)
1645 OS << " weak";
1646 if (Attrs & ObjCPropertyDecl::OBJC_PR_strong)
1647 OS << " strong";
1648 if (Attrs & ObjCPropertyDecl::OBJC_PR_unsafe_unretained)
1649 OS << " unsafe_unretained";
Manman Ren387ff7f2016-01-26 18:52:43 +00001650 if (Attrs & ObjCPropertyDecl::OBJC_PR_class)
1651 OS << " class";
Richard Smithf7514452014-10-30 21:02:37 +00001652 if (Attrs & ObjCPropertyDecl::OBJC_PR_getter)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001653 dumpDeclRef(D->getGetterMethodDecl(), "getter");
Richard Smithf7514452014-10-30 21:02:37 +00001654 if (Attrs & ObjCPropertyDecl::OBJC_PR_setter)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001655 dumpDeclRef(D->getSetterMethodDecl(), "setter");
1656 }
1657}
1658
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001659void ASTDumper::VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +00001660 NodeDumper.dumpName(D->getPropertyDecl());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001661 if (D->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize)
1662 OS << " synthesize";
1663 else
1664 OS << " dynamic";
1665 dumpDeclRef(D->getPropertyDecl());
1666 dumpDeclRef(D->getPropertyIvarDecl());
1667}
1668
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001669void ASTDumper::VisitBlockDecl(const BlockDecl *D) {
David Majnemer59f77922016-06-24 04:05:48 +00001670 for (auto I : D->parameters())
Aaron Ballmanb2b8b1d2014-03-07 16:09:59 +00001671 dumpDecl(I);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001672
Richard Smithf7514452014-10-30 21:02:37 +00001673 if (D->isVariadic())
1674 dumpChild([=]{ OS << "..."; });
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001675
Richard Smithf7514452014-10-30 21:02:37 +00001676 if (D->capturesCXXThis())
1677 dumpChild([=]{ OS << "capture this"; });
1678
Aaron Ballman9371dd22014-03-14 18:34:04 +00001679 for (const auto &I : D->captures()) {
Richard Smithf7514452014-10-30 21:02:37 +00001680 dumpChild([=] {
1681 OS << "capture";
1682 if (I.isByRef())
1683 OS << " byref";
1684 if (I.isNested())
1685 OS << " nested";
1686 if (I.getVariable()) {
1687 OS << ' ';
Stephen Kellyd8744a72018-12-05 21:12:39 +00001688 NodeDumper.dumpBareDeclRef(I.getVariable());
Richard Smithf7514452014-10-30 21:02:37 +00001689 }
1690 if (I.hasCopyExpr())
1691 dumpStmt(I.getCopyExpr());
1692 });
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001693 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001694 dumpStmt(D->getBody());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001695}
1696
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001697//===----------------------------------------------------------------------===//
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001698// Stmt dumping methods.
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001699//===----------------------------------------------------------------------===//
1700
Stephen Kelly50a29bd2018-12-09 13:24:40 +00001701void ASTDumper::dumpStmt(const Stmt *S) {
Richard Smithf7514452014-10-30 21:02:37 +00001702 dumpChild([=] {
1703 if (!S) {
Stephen Kelly27e948c2018-11-29 19:30:37 +00001704 ColorScope Color(OS, ShowColors, NullColor);
Richard Smithf7514452014-10-30 21:02:37 +00001705 OS << "<<<NULL>>>";
1706 return;
1707 }
Stephen Kellyb9d6a5e2018-12-06 23:33:27 +00001708 {
1709 ColorScope Color(OS, ShowColors, StmtColor);
1710 OS << S->getStmtClassName();
1711 }
1712 NodeDumper.dumpPointer(S);
1713 NodeDumper.dumpSourceRange(S->getSourceRange());
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001714
Stephen Kelly50e82872018-12-06 23:33:33 +00001715 if (const auto *E = dyn_cast<Expr>(S)) {
1716 NodeDumper.dumpType(E->getType());
1717
1718 {
1719 ColorScope Color(OS, ShowColors, ValueKindColor);
1720 switch (E->getValueKind()) {
1721 case VK_RValue:
1722 break;
1723 case VK_LValue:
1724 OS << " lvalue";
1725 break;
1726 case VK_XValue:
1727 OS << " xvalue";
1728 break;
1729 }
1730 }
1731
1732 {
1733 ColorScope Color(OS, ShowColors, ObjectKindColor);
1734 switch (E->getObjectKind()) {
1735 case OK_Ordinary:
1736 break;
1737 case OK_BitField:
1738 OS << " bitfield";
1739 break;
1740 case OK_ObjCProperty:
1741 OS << " objcproperty";
1742 break;
1743 case OK_ObjCSubscript:
1744 OS << " objcsubscript";
1745 break;
1746 case OK_VectorComponent:
1747 OS << " vectorcomponent";
1748 break;
1749 }
1750 }
1751 }
1752
Richard Smithf7514452014-10-30 21:02:37 +00001753 ConstStmtVisitor<ASTDumper>::Visit(S);
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001754
Stephen Kelly91f9c9c2018-12-03 21:05:52 +00001755 // Some statements have custom mechanisms for dumping their children.
1756 if (isa<DeclStmt>(S) || isa<GenericSelectionExpr>(S)) {
1757 return;
1758 }
1759
Benjamin Kramer642f1732015-07-02 21:03:14 +00001760 for (const Stmt *SubStmt : S->children())
1761 dumpStmt(SubStmt);
Richard Smithf7514452014-10-30 21:02:37 +00001762 });
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001763}
1764
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001765void ASTDumper::VisitDeclStmt(const DeclStmt *Node) {
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001766 for (DeclStmt::const_decl_iterator I = Node->decl_begin(),
1767 E = Node->decl_end();
Richard Smithf7514452014-10-30 21:02:37 +00001768 I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001769 dumpDecl(*I);
Ted Kremenek433a4922007-12-12 06:59:42 +00001770}
1771
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001772void ASTDumper::VisitAttributedStmt(const AttributedStmt *Node) {
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001773 for (ArrayRef<const Attr *>::iterator I = Node->getAttrs().begin(),
1774 E = Node->getAttrs().end();
Richard Smithf7514452014-10-30 21:02:37 +00001775 I != E; ++I)
Alexander Kornienko5bc364e2013-01-07 17:53:08 +00001776 dumpAttr(*I);
1777}
1778
Bruno Riccib1cc94b2018-10-27 21:12:20 +00001779void ASTDumper::VisitIfStmt(const IfStmt *Node) {
Bruno Riccib1cc94b2018-10-27 21:12:20 +00001780 if (Node->hasInitStorage())
1781 OS << " has_init";
1782 if (Node->hasVarStorage())
1783 OS << " has_var";
1784 if (Node->hasElseStorage())
1785 OS << " has_else";
1786}
1787
Bruno Riccie2806f82018-10-29 16:12:37 +00001788void ASTDumper::VisitSwitchStmt(const SwitchStmt *Node) {
Bruno Riccie2806f82018-10-29 16:12:37 +00001789 if (Node->hasInitStorage())
1790 OS << " has_init";
1791 if (Node->hasVarStorage())
1792 OS << " has_var";
1793}
1794
Bruno Riccibacf7512018-10-30 13:42:41 +00001795void ASTDumper::VisitWhileStmt(const WhileStmt *Node) {
Bruno Riccibacf7512018-10-30 13:42:41 +00001796 if (Node->hasVarStorage())
1797 OS << " has_var";
1798}
1799
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001800void ASTDumper::VisitLabelStmt(const LabelStmt *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 Kornienko90ff6072012-12-20 02:09:13 +00001805 OS << " '" << Node->getLabel()->getName() << "'";
Stephen Kellyd8744a72018-12-05 21:12:39 +00001806 NodeDumper.dumpPointer(Node->getLabel());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001807}
1808
Pavel Labath1ef83422013-09-04 14:35:00 +00001809void ASTDumper::VisitCXXCatchStmt(const CXXCatchStmt *Node) {
Pavel Labath1ef83422013-09-04 14:35:00 +00001810 dumpDecl(Node->getExceptionDecl());
1811}
1812
Bruno Ricci5b30571752018-10-28 12:30:53 +00001813void ASTDumper::VisitCaseStmt(const CaseStmt *Node) {
Bruno Ricci5b30571752018-10-28 12:30:53 +00001814 if (Node->caseStmtIsGNURange())
1815 OS << " gnu_range";
1816}
1817
Alexey Bataev958b9e72016-03-31 09:30:50 +00001818void ASTDumper::VisitCapturedStmt(const CapturedStmt *Node) {
Alexey Bataev958b9e72016-03-31 09:30:50 +00001819 dumpDecl(Node->getCapturedDecl());
1820}
1821
1822//===----------------------------------------------------------------------===//
1823// OpenMP dumping methods.
1824//===----------------------------------------------------------------------===//
1825
1826void ASTDumper::VisitOMPExecutableDirective(
1827 const OMPExecutableDirective *Node) {
Alexey Bataev958b9e72016-03-31 09:30:50 +00001828 for (auto *C : Node->clauses()) {
1829 dumpChild([=] {
1830 if (!C) {
Stephen Kelly27e948c2018-11-29 19:30:37 +00001831 ColorScope Color(OS, ShowColors, NullColor);
Alexey Bataev958b9e72016-03-31 09:30:50 +00001832 OS << "<<<NULL>>> OMPClause";
1833 return;
1834 }
1835 {
Stephen Kelly27e948c2018-11-29 19:30:37 +00001836 ColorScope Color(OS, ShowColors, AttrColor);
Alexey Bataev958b9e72016-03-31 09:30:50 +00001837 StringRef ClauseName(getOpenMPClauseName(C->getClauseKind()));
1838 OS << "OMP" << ClauseName.substr(/*Start=*/0, /*N=*/1).upper()
1839 << ClauseName.drop_front() << "Clause";
1840 }
Stephen Kellyd8744a72018-12-05 21:12:39 +00001841 NodeDumper.dumpPointer(C);
1842 NodeDumper.dumpSourceRange(SourceRange(C->getBeginLoc(), C->getEndLoc()));
Alexey Bataev958b9e72016-03-31 09:30:50 +00001843 if (C->isImplicit())
1844 OS << " <implicit>";
1845 for (auto *S : C->children())
1846 dumpStmt(S);
1847 });
1848 }
1849}
1850
Chris Lattnercbe4f772007-08-08 22:51:59 +00001851//===----------------------------------------------------------------------===//
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001852// Expr dumping methods.
Chris Lattnercbe4f772007-08-08 22:51:59 +00001853//===----------------------------------------------------------------------===//
1854
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001855static void dumpBasePath(raw_ostream &OS, const CastExpr *Node) {
John McCallcf142162010-08-07 06:22:56 +00001856 if (Node->path_empty())
Anders Carlssona70cff62010-04-24 19:06:50 +00001857 return;
1858
1859 OS << " (";
1860 bool First = true;
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001861 for (CastExpr::path_const_iterator I = Node->path_begin(),
1862 E = Node->path_end();
1863 I != E; ++I) {
Anders Carlssona70cff62010-04-24 19:06:50 +00001864 const CXXBaseSpecifier *Base = *I;
1865 if (!First)
1866 OS << " -> ";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001867
Anders Carlssona70cff62010-04-24 19:06:50 +00001868 const CXXRecordDecl *RD =
1869 cast<CXXRecordDecl>(Base->getType()->getAs<RecordType>()->getDecl());
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001870
Anders Carlssona70cff62010-04-24 19:06:50 +00001871 if (Base->isVirtual())
1872 OS << "virtual ";
1873 OS << RD->getName();
1874 First = false;
1875 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001876
Anders Carlssona70cff62010-04-24 19:06:50 +00001877 OS << ')';
1878}
1879
Eric Fiselier5cdc2cd2018-12-12 21:50:55 +00001880void ASTDumper::VisitCallExpr(const CallExpr *Node) {
1881 if (Node->usesADL())
1882 OS << " adl";
1883}
1884
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001885void ASTDumper::VisitCastExpr(const CastExpr *Node) {
Richard Trieud215b8d2013-01-26 01:31:20 +00001886 OS << " <";
1887 {
Stephen Kelly27e948c2018-11-29 19:30:37 +00001888 ColorScope Color(OS, ShowColors, CastColor);
Richard Trieud215b8d2013-01-26 01:31:20 +00001889 OS << Node->getCastKindName();
1890 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001891 dumpBasePath(OS, Node);
Anders Carlssona70cff62010-04-24 19:06:50 +00001892 OS << ">";
Roman Lebedev12216f12018-07-27 07:27:14 +00001893}
Roman Lebedevd55661d2018-07-24 08:16:50 +00001894
Roman Lebedev12216f12018-07-27 07:27:14 +00001895void ASTDumper::VisitImplicitCastExpr(const ImplicitCastExpr *Node) {
1896 VisitCastExpr(Node);
1897 if (Node->isPartOfExplicitCast())
Roman Lebedevd55661d2018-07-24 08:16:50 +00001898 OS << " part_of_explicit_cast";
Anders Carlssond7923c62009-08-22 23:33:40 +00001899}
1900
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001901void ASTDumper::VisitDeclRefExpr(const DeclRefExpr *Node) {
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001902 OS << " ";
Stephen Kellyd8744a72018-12-05 21:12:39 +00001903 NodeDumper.dumpBareDeclRef(Node->getDecl());
Chandler Carruth8d26bb02011-05-01 23:48:14 +00001904 if (Node->getDecl() != Node->getFoundDecl()) {
1905 OS << " (";
Stephen Kellyd8744a72018-12-05 21:12:39 +00001906 NodeDumper.dumpBareDeclRef(Node->getFoundDecl());
Chandler Carruth8d26bb02011-05-01 23:48:14 +00001907 OS << ")";
1908 }
John McCall351762c2011-02-07 10:33:21 +00001909}
1910
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001911void ASTDumper::VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *Node) {
John McCall76d09942009-12-11 21:50:11 +00001912 OS << " (";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001913 if (!Node->requiresADL())
1914 OS << "no ";
Benjamin Kramerb11416d2010-04-17 09:33:03 +00001915 OS << "ADL) = '" << Node->getName() << '\'';
John McCall76d09942009-12-11 21:50:11 +00001916
1917 UnresolvedLookupExpr::decls_iterator
1918 I = Node->decls_begin(), E = Node->decls_end();
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001919 if (I == E)
1920 OS << " empty";
John McCall76d09942009-12-11 21:50:11 +00001921 for (; I != E; ++I)
Stephen Kellyd8744a72018-12-05 21:12:39 +00001922 NodeDumper.dumpPointer(*I);
John McCall76d09942009-12-11 21:50:11 +00001923}
1924
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001925void ASTDumper::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *Node) {
Richard Trieud215b8d2013-01-26 01:31:20 +00001926 {
Stephen Kelly27e948c2018-11-29 19:30:37 +00001927 ColorScope Color(OS, ShowColors, DeclKindNameColor);
Richard Trieud215b8d2013-01-26 01:31:20 +00001928 OS << " " << Node->getDecl()->getDeclKindName() << "Decl";
1929 }
1930 OS << "='" << *Node->getDecl() << "'";
Stephen Kellyd8744a72018-12-05 21:12:39 +00001931 NodeDumper.dumpPointer(Node->getDecl());
Steve Naroffb3424a92008-05-23 22:01:24 +00001932 if (Node->isFreeIvar())
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001933 OS << " isFreeIvar";
Steve Naroff5d5efca2008-03-12 13:19:12 +00001934}
1935
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001936void ASTDumper::VisitPredefinedExpr(const PredefinedExpr *Node) {
Bruno Ricci17ff0262018-10-27 19:21:19 +00001937 OS << " " << PredefinedExpr::getIdentKindName(Node->getIdentKind());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001938}
1939
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001940void ASTDumper::VisitCharacterLiteral(const CharacterLiteral *Node) {
Stephen Kelly27e948c2018-11-29 19:30:37 +00001941 ColorScope Color(OS, ShowColors, ValueColor);
Richard Trieu364ee422011-11-03 23:56:23 +00001942 OS << " " << Node->getValue();
Chris Lattnercbe4f772007-08-08 22:51:59 +00001943}
1944
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001945void ASTDumper::VisitIntegerLiteral(const IntegerLiteral *Node) {
Chris Lattnercbe4f772007-08-08 22:51:59 +00001946 bool isSigned = Node->getType()->isSignedIntegerType();
Stephen Kelly27e948c2018-11-29 19:30:37 +00001947 ColorScope Color(OS, ShowColors, ValueColor);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001948 OS << " " << Node->getValue().toString(10, isSigned);
Chris Lattnercbe4f772007-08-08 22:51:59 +00001949}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001950
Leonard Chandb01c3a2018-06-20 17:19:40 +00001951void ASTDumper::VisitFixedPointLiteral(const FixedPointLiteral *Node) {
Stephen Kelly27e948c2018-11-29 19:30:37 +00001952 ColorScope Color(OS, ShowColors, ValueColor);
Leonard Chandb01c3a2018-06-20 17:19:40 +00001953 OS << " " << Node->getValueAsString(/*Radix=*/10);
1954}
1955
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001956void ASTDumper::VisitFloatingLiteral(const FloatingLiteral *Node) {
Stephen Kelly27e948c2018-11-29 19:30:37 +00001957 ColorScope Color(OS, ShowColors, ValueColor);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001958 OS << " " << Node->getValueAsApproximateDouble();
Chris Lattnercbe4f772007-08-08 22:51:59 +00001959}
Chris Lattner1c20a172007-08-26 03:42:43 +00001960
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001961void ASTDumper::VisitStringLiteral(const StringLiteral *Str) {
Stephen Kelly27e948c2018-11-29 19:30:37 +00001962 ColorScope Color(OS, ShowColors, ValueColor);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001963 OS << " ";
Richard Trieudc355912012-06-13 20:25:24 +00001964 Str->outputString(OS);
Chris Lattnercbe4f772007-08-08 22:51:59 +00001965}
Chris Lattner84ca3762007-08-30 01:00:35 +00001966
Richard Smithf0514962014-06-03 08:24:28 +00001967void ASTDumper::VisitInitListExpr(const InitListExpr *ILE) {
Stephen Kelly7ec37b22018-12-09 13:15:18 +00001968 if (auto *Field = ILE->getInitializedFieldInUnion()) {
1969 OS << " field ";
1970 NodeDumper.dumpBareDeclRef(Field);
1971 }
Richard Smithf0514962014-06-03 08:24:28 +00001972 if (auto *Filler = ILE->getArrayFiller()) {
Stephen Kelly677e3ae2018-12-10 21:20:05 +00001973 dumpChild([=] {
1974 OS << "array filler";
1975 dumpStmt(Filler);
1976 });
Richard Smithf0514962014-06-03 08:24:28 +00001977 }
Richard Smithf0514962014-06-03 08:24:28 +00001978}
1979
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001980void ASTDumper::VisitUnaryOperator(const UnaryOperator *Node) {
Malcolm Parsonsfab36802018-04-16 08:31:08 +00001981 OS << " " << (Node->isPostfix() ? "postfix" : "prefix")
1982 << " '" << UnaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
1983 if (!Node->canOverflow())
1984 OS << " cannot overflow";
1985}
1986
1987void ASTDumper::VisitUnaryExprOrTypeTraitExpr(
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001988 const UnaryExprOrTypeTraitExpr *Node) {
Peter Collingbournee190dee2011-03-11 19:24:49 +00001989 switch(Node->getKind()) {
1990 case UETT_SizeOf:
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001991 OS << " sizeof";
Peter Collingbournee190dee2011-03-11 19:24:49 +00001992 break;
1993 case UETT_AlignOf:
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001994 OS << " alignof";
Peter Collingbournee190dee2011-03-11 19:24:49 +00001995 break;
1996 case UETT_VecStep:
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001997 OS << " vec_step";
Peter Collingbournee190dee2011-03-11 19:24:49 +00001998 break;
Alexey Bataev00396512015-07-02 03:40:19 +00001999 case UETT_OpenMPRequiredSimdAlign:
2000 OS << " __builtin_omp_required_simd_align";
2001 break;
Richard Smith6822bd72018-10-26 19:26:45 +00002002 case UETT_PreferredAlignOf:
2003 OS << " __alignof";
2004 break;
Peter Collingbournee190dee2011-03-11 19:24:49 +00002005 }
Sebastian Redl6f282892008-11-11 17:56:53 +00002006 if (Node->isArgumentType())
Stephen Kellyd8744a72018-12-05 21:12:39 +00002007 NodeDumper.dumpType(Node->getArgumentType());
Chris Lattnercbe4f772007-08-08 22:51:59 +00002008}
Chris Lattnerdb3b3ff2007-08-09 17:35:30 +00002009
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002010void ASTDumper::VisitMemberExpr(const MemberExpr *Node) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002011 OS << " " << (Node->isArrow() ? "->" : ".") << *Node->getMemberDecl();
Stephen Kellyd8744a72018-12-05 21:12:39 +00002012 NodeDumper.dumpPointer(Node->getMemberDecl());
Chris Lattnercbe4f772007-08-08 22:51:59 +00002013}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002014
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002015void ASTDumper::VisitExtVectorElementExpr(const ExtVectorElementExpr *Node) {
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002016 OS << " " << Node->getAccessor().getNameStart();
Chris Lattnercbe4f772007-08-08 22:51:59 +00002017}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002018
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002019void ASTDumper::VisitBinaryOperator(const BinaryOperator *Node) {
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002020 OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
Chris Lattner86928112007-08-25 02:00:02 +00002021}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002022
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002023void ASTDumper::VisitCompoundAssignOperator(
2024 const CompoundAssignOperator *Node) {
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002025 OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode())
2026 << "' ComputeLHSTy=";
Stephen Kellyd8744a72018-12-05 21:12:39 +00002027 NodeDumper.dumpBareType(Node->getComputationLHSType());
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002028 OS << " ComputeResultTy=";
Stephen Kellyd8744a72018-12-05 21:12:39 +00002029 NodeDumper.dumpBareType(Node->getComputationResultType());
Chris Lattnercbe4f772007-08-08 22:51:59 +00002030}
Chris Lattnercbe4f772007-08-08 22:51:59 +00002031
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002032void ASTDumper::VisitBlockExpr(const BlockExpr *Node) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002033 dumpDecl(Node->getBlockDecl());
John McCall351762c2011-02-07 10:33:21 +00002034}
2035
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002036void ASTDumper::VisitOpaqueValueExpr(const OpaqueValueExpr *Node) {
Richard Smithf7514452014-10-30 21:02:37 +00002037 if (Expr *Source = Node->getSourceExpr())
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002038 dumpStmt(Source);
John McCallfe96e0b2011-11-06 09:01:30 +00002039}
2040
Richard Smith01ccebf2018-01-05 21:31:07 +00002041void ASTDumper::VisitGenericSelectionExpr(const GenericSelectionExpr *E) {
Richard Smith01ccebf2018-01-05 21:31:07 +00002042 if (E->isResultDependent())
2043 OS << " result_dependent";
2044 dumpStmt(E->getControllingExpr());
2045 dumpTypeAsChild(E->getControllingExpr()->getType()); // FIXME: remove
2046
2047 for (unsigned I = 0, N = E->getNumAssocs(); I != N; ++I) {
2048 dumpChild([=] {
2049 if (const TypeSourceInfo *TSI = E->getAssocTypeSourceInfo(I)) {
2050 OS << "case ";
Stephen Kellyd8744a72018-12-05 21:12:39 +00002051 NodeDumper.dumpType(TSI->getType());
Richard Smith01ccebf2018-01-05 21:31:07 +00002052 } else {
2053 OS << "default";
2054 }
2055
2056 if (!E->isResultDependent() && E->getResultIndex() == I)
2057 OS << " selected";
2058
2059 if (const TypeSourceInfo *TSI = E->getAssocTypeSourceInfo(I))
2060 dumpTypeAsChild(TSI->getType());
2061 dumpStmt(E->getAssocExpr(I));
2062 });
2063 }
2064}
2065
Chris Lattnercbe4f772007-08-08 22:51:59 +00002066// GNU extensions.
2067
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002068void ASTDumper::VisitAddrLabelExpr(const AddrLabelExpr *Node) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002069 OS << " " << Node->getLabel()->getName();
Stephen Kellyd8744a72018-12-05 21:12:39 +00002070 NodeDumper.dumpPointer(Node->getLabel());
Chris Lattnercbe4f772007-08-08 22:51:59 +00002071}
2072
Chris Lattner8f184b12007-08-09 18:03:18 +00002073//===----------------------------------------------------------------------===//
2074// C++ Expressions
2075//===----------------------------------------------------------------------===//
Chris Lattnercbe4f772007-08-08 22:51:59 +00002076
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002077void ASTDumper::VisitCXXNamedCastExpr(const CXXNamedCastExpr *Node) {
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002078 OS << " " << Node->getCastName()
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002079 << "<" << Node->getTypeAsWritten().getAsString() << ">"
Anders Carlssona70cff62010-04-24 19:06:50 +00002080 << " <" << Node->getCastKindName();
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002081 dumpBasePath(OS, Node);
Anders Carlssona70cff62010-04-24 19:06:50 +00002082 OS << ">";
Chris Lattnercbe4f772007-08-08 22:51:59 +00002083}
2084
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002085void ASTDumper::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *Node) {
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002086 OS << " " << (Node->getValue() ? "true" : "false");
Chris Lattnercbe4f772007-08-08 22:51:59 +00002087}
2088
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002089void ASTDumper::VisitCXXThisExpr(const CXXThisExpr *Node) {
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002090 OS << " this";
Douglas Gregor8ea1f532008-11-04 14:56:14 +00002091}
2092
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002093void ASTDumper::VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *Node) {
Eli Friedman29538892011-09-02 17:38:59 +00002094 OS << " functional cast to " << Node->getTypeAsWritten().getAsString()
2095 << " <" << Node->getCastKindName() << ">";
Douglas Gregore200adc2008-10-27 19:41:14 +00002096}
2097
Richard Smith39eca9b2017-08-23 22:12:08 +00002098void ASTDumper::VisitCXXUnresolvedConstructExpr(
2099 const CXXUnresolvedConstructExpr *Node) {
Stephen Kellyd8744a72018-12-05 21:12:39 +00002100 NodeDumper.dumpType(Node->getTypeAsWritten());
Richard Smith39eca9b2017-08-23 22:12:08 +00002101 if (Node->isListInitialization())
2102 OS << " list";
2103}
2104
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002105void ASTDumper::VisitCXXConstructExpr(const CXXConstructExpr *Node) {
John McCalleba90cd2010-02-02 19:03:45 +00002106 CXXConstructorDecl *Ctor = Node->getConstructor();
Stephen Kellyd8744a72018-12-05 21:12:39 +00002107 NodeDumper.dumpType(Ctor->getType());
Anders Carlsson073846832009-08-12 00:21:52 +00002108 if (Node->isElidable())
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002109 OS << " elidable";
Richard Smith39eca9b2017-08-23 22:12:08 +00002110 if (Node->isListInitialization())
2111 OS << " list";
2112 if (Node->isStdInitListInitialization())
2113 OS << " std::initializer_list";
John McCall85370042010-08-07 06:38:55 +00002114 if (Node->requiresZeroInitialization())
2115 OS << " zeroing";
Anders Carlsson073846832009-08-12 00:21:52 +00002116}
2117
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002118void ASTDumper::VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *Node) {
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002119 OS << " ";
Stephen Kellyd8744a72018-12-05 21:12:39 +00002120 NodeDumper.dumpCXXTemporary(Node->getTemporary());
Anders Carlsson073846832009-08-12 00:21:52 +00002121}
2122
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002123void ASTDumper::VisitCXXNewExpr(const CXXNewExpr *Node) {
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002124 if (Node->isGlobalNew())
Reid Kleckner461c0c62015-03-19 18:47:47 +00002125 OS << " global";
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002126 if (Node->isArray())
Reid Kleckner461c0c62015-03-19 18:47:47 +00002127 OS << " array";
2128 if (Node->getOperatorNew()) {
2129 OS << ' ';
Stephen Kellyd8744a72018-12-05 21:12:39 +00002130 NodeDumper.dumpBareDeclRef(Node->getOperatorNew());
Reid Kleckner461c0c62015-03-19 18:47:47 +00002131 }
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002132 // We could dump the deallocation function used in case of error, but it's
2133 // usually not that interesting.
2134}
2135
2136void ASTDumper::VisitCXXDeleteExpr(const CXXDeleteExpr *Node) {
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002137 if (Node->isGlobalDelete())
Reid Kleckner461c0c62015-03-19 18:47:47 +00002138 OS << " global";
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002139 if (Node->isArrayForm())
Reid Kleckner461c0c62015-03-19 18:47:47 +00002140 OS << " array";
2141 if (Node->getOperatorDelete()) {
2142 OS << ' ';
Stephen Kellyd8744a72018-12-05 21:12:39 +00002143 NodeDumper.dumpBareDeclRef(Node->getOperatorDelete());
Reid Kleckner461c0c62015-03-19 18:47:47 +00002144 }
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002145}
2146
Richard Smithe6c01442013-06-05 00:46:14 +00002147void
2148ASTDumper::VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *Node) {
Richard Smithe6c01442013-06-05 00:46:14 +00002149 if (const ValueDecl *VD = Node->getExtendingDecl()) {
2150 OS << " extended by ";
Stephen Kellyd8744a72018-12-05 21:12:39 +00002151 NodeDumper.dumpBareDeclRef(VD);
Richard Smithe6c01442013-06-05 00:46:14 +00002152 }
2153}
2154
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002155void ASTDumper::VisitExprWithCleanups(const ExprWithCleanups *Node) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002156 for (unsigned i = 0, e = Node->getNumObjects(); i != e; ++i)
2157 dumpDeclRef(Node->getObject(i), "cleanup");
Anders Carlsson073846832009-08-12 00:21:52 +00002158}
2159
Serge Pavlov6b926032015-02-16 19:58:41 +00002160void ASTDumper::VisitSizeOfPackExpr(const SizeOfPackExpr *Node) {
Stephen Kellyd8744a72018-12-05 21:12:39 +00002161 NodeDumper.dumpPointer(Node->getPack());
2162 NodeDumper.dumpName(Node->getPack());
Richard Smithd784e682015-09-23 21:41:42 +00002163 if (Node->isPartiallySubstituted())
2164 for (const auto &A : Node->getPartialArguments())
2165 dumpTemplateArgument(A);
Serge Pavlov6b926032015-02-16 19:58:41 +00002166}
2167
Alex Lorenzddbe0f52016-11-09 14:02:18 +00002168void ASTDumper::VisitCXXDependentScopeMemberExpr(
2169 const CXXDependentScopeMemberExpr *Node) {
Alex Lorenzddbe0f52016-11-09 14:02:18 +00002170 OS << " " << (Node->isArrow() ? "->" : ".") << Node->getMember();
2171}
Serge Pavlov6b926032015-02-16 19:58:41 +00002172
Anders Carlsson76f4a902007-08-21 17:43:55 +00002173//===----------------------------------------------------------------------===//
2174// Obj-C Expressions
2175//===----------------------------------------------------------------------===//
2176
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002177void ASTDumper::VisitObjCMessageExpr(const ObjCMessageExpr *Node) {
Aaron Ballmanb190f972014-01-03 17:59:55 +00002178 OS << " selector=";
2179 Node->getSelector().print(OS);
Douglas Gregor9a129192010-04-21 00:45:42 +00002180 switch (Node->getReceiverKind()) {
2181 case ObjCMessageExpr::Instance:
2182 break;
2183
2184 case ObjCMessageExpr::Class:
2185 OS << " class=";
Stephen Kellyd8744a72018-12-05 21:12:39 +00002186 NodeDumper.dumpBareType(Node->getClassReceiver());
Douglas Gregor9a129192010-04-21 00:45:42 +00002187 break;
2188
2189 case ObjCMessageExpr::SuperInstance:
2190 OS << " super (instance)";
2191 break;
2192
2193 case ObjCMessageExpr::SuperClass:
2194 OS << " super (class)";
2195 break;
2196 }
Ted Kremenek36748da2008-02-29 22:04:05 +00002197}
2198
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002199void ASTDumper::VisitObjCBoxedExpr(const ObjCBoxedExpr *Node) {
Richard Trieu4b259c82016-06-09 22:03:04 +00002200 if (auto *BoxingMethod = Node->getBoxingMethod()) {
2201 OS << " selector=";
2202 BoxingMethod->getSelector().print(OS);
2203 }
Argyrios Kyrtzidis9dd40892012-05-10 20:02:31 +00002204}
2205
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002206void ASTDumper::VisitObjCAtCatchStmt(const ObjCAtCatchStmt *Node) {
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002207 if (const VarDecl *CatchParam = Node->getCatchParamDecl())
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002208 dumpDecl(CatchParam);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002209 else
Douglas Gregor96c79492010-04-23 22:50:49 +00002210 OS << " catch all";
Douglas Gregor96c79492010-04-23 22:50:49 +00002211}
2212
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002213void ASTDumper::VisitObjCEncodeExpr(const ObjCEncodeExpr *Node) {
Stephen Kellyd8744a72018-12-05 21:12:39 +00002214 NodeDumper.dumpType(Node->getEncodedType());
Anders Carlssonc5a81eb2007-08-22 15:14:15 +00002215}
2216
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002217void ASTDumper::VisitObjCSelectorExpr(const ObjCSelectorExpr *Node) {
Aaron Ballmanb190f972014-01-03 17:59:55 +00002218 OS << " ";
2219 Node->getSelector().print(OS);
Fariborz Jahanian4bef4622007-10-16 20:40:23 +00002220}
2221
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002222void ASTDumper::VisitObjCProtocolExpr(const ObjCProtocolExpr *Node) {
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002223 OS << ' ' << *Node->getProtocol();
Fariborz Jahaniana32aaef2007-10-17 16:58:11 +00002224}
Daniel Dunbar4b8c6db2008-08-30 05:35:15 +00002225
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002226void ASTDumper::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *Node) {
John McCallb7bd14f2010-12-02 01:19:52 +00002227 if (Node->isImplicitProperty()) {
Fariborz Jahanian0f0b3022010-12-22 19:46:35 +00002228 OS << " Kind=MethodRef Getter=\"";
2229 if (Node->getImplicitPropertyGetter())
Aaron Ballmanb190f972014-01-03 17:59:55 +00002230 Node->getImplicitPropertyGetter()->getSelector().print(OS);
Fariborz Jahanian0f0b3022010-12-22 19:46:35 +00002231 else
2232 OS << "(null)";
2233
2234 OS << "\" Setter=\"";
John McCallb7bd14f2010-12-02 01:19:52 +00002235 if (ObjCMethodDecl *Setter = Node->getImplicitPropertySetter())
Aaron Ballmanb190f972014-01-03 17:59:55 +00002236 Setter->getSelector().print(OS);
John McCallb7bd14f2010-12-02 01:19:52 +00002237 else
2238 OS << "(null)";
2239 OS << "\"";
2240 } else {
Benjamin Kramerb89514a2011-10-14 18:45:37 +00002241 OS << " Kind=PropertyRef Property=\"" << *Node->getExplicitProperty() <<'"';
John McCallb7bd14f2010-12-02 01:19:52 +00002242 }
Fariborz Jahanian8a1810f2008-11-22 18:39:36 +00002243
Fariborz Jahanian681c0752010-10-14 16:04:05 +00002244 if (Node->isSuperReceiver())
2245 OS << " super";
Argyrios Kyrtzidisab468b02012-03-30 00:19:18 +00002246
2247 OS << " Messaging=";
2248 if (Node->isMessagingGetter() && Node->isMessagingSetter())
2249 OS << "Getter&Setter";
2250 else if (Node->isMessagingGetter())
2251 OS << "Getter";
2252 else if (Node->isMessagingSetter())
2253 OS << "Setter";
Douglas Gregor8ea1f532008-11-04 14:56:14 +00002254}
2255
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002256void ASTDumper::VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *Node) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00002257 if (Node->isArraySubscriptRefExpr())
2258 OS << " Kind=ArraySubscript GetterForArray=\"";
2259 else
2260 OS << " Kind=DictionarySubscript GetterForDictionary=\"";
2261 if (Node->getAtIndexMethodDecl())
Aaron Ballmanb190f972014-01-03 17:59:55 +00002262 Node->getAtIndexMethodDecl()->getSelector().print(OS);
Ted Kremeneke65b0862012-03-06 20:05:56 +00002263 else
2264 OS << "(null)";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002265
Ted Kremeneke65b0862012-03-06 20:05:56 +00002266 if (Node->isArraySubscriptRefExpr())
2267 OS << "\" SetterForArray=\"";
2268 else
2269 OS << "\" SetterForDictionary=\"";
2270 if (Node->setAtIndexMethodDecl())
Aaron Ballmanb190f972014-01-03 17:59:55 +00002271 Node->setAtIndexMethodDecl()->getSelector().print(OS);
Ted Kremeneke65b0862012-03-06 20:05:56 +00002272 else
2273 OS << "(null)";
2274}
2275
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002276void ASTDumper::VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *Node) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00002277 OS << " " << (Node->getValue() ? "__objc_yes" : "__objc_no");
2278}
2279
Chris Lattnercbe4f772007-08-08 22:51:59 +00002280//===----------------------------------------------------------------------===//
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002281// Comments
2282//===----------------------------------------------------------------------===//
2283
Stephen Kellycdbfb302018-12-02 17:30:40 +00002284void ASTDumper::dumpComment(const Comment *C, const FullComment *FC) {
Richard Smithf7514452014-10-30 21:02:37 +00002285 dumpChild([=] {
Stephen Kellye26a88a2018-12-09 13:30:17 +00002286 NodeDumper.Visit(C, FC);
Richard Smithf7514452014-10-30 21:02:37 +00002287 if (!C) {
Richard Smithf7514452014-10-30 21:02:37 +00002288 return;
2289 }
Stephen Kellycdbfb302018-12-02 17:30:40 +00002290 ConstCommentVisitor<ASTDumper, void, const FullComment *>::visit(C, FC);
Richard Smithf7514452014-10-30 21:02:37 +00002291 for (Comment::child_iterator I = C->child_begin(), E = C->child_end();
2292 I != E; ++I)
Stephen Kellycdbfb302018-12-02 17:30:40 +00002293 dumpComment(*I, FC);
Richard Smithf7514452014-10-30 21:02:37 +00002294 });
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002295}
2296
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002297//===----------------------------------------------------------------------===//
Richard Smithd5e7ff82014-10-31 01:17:45 +00002298// Type method implementations
2299//===----------------------------------------------------------------------===//
2300
2301void QualType::dump(const char *msg) const {
2302 if (msg)
2303 llvm::errs() << msg << ": ";
2304 dump();
2305}
2306
Richard Smith14d04842016-11-02 23:57:18 +00002307LLVM_DUMP_METHOD void QualType::dump() const { dump(llvm::errs()); }
2308
2309LLVM_DUMP_METHOD void QualType::dump(llvm::raw_ostream &OS) const {
2310 ASTDumper Dumper(OS, nullptr, nullptr);
Richard Smithd5e7ff82014-10-31 01:17:45 +00002311 Dumper.dumpTypeAsChild(*this);
2312}
2313
Richard Smith14d04842016-11-02 23:57:18 +00002314LLVM_DUMP_METHOD void Type::dump() const { dump(llvm::errs()); }
2315
2316LLVM_DUMP_METHOD void Type::dump(llvm::raw_ostream &OS) const {
2317 QualType(this, 0).dump(OS);
2318}
Richard Smithd5e7ff82014-10-31 01:17:45 +00002319
2320//===----------------------------------------------------------------------===//
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002321// Decl method implementations
2322//===----------------------------------------------------------------------===//
2323
Alp Tokeref6b0072014-01-04 13:47:14 +00002324LLVM_DUMP_METHOD void Decl::dump() const { dump(llvm::errs()); }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002325
Richard Smith3a36ac12017-03-09 22:00:01 +00002326LLVM_DUMP_METHOD void Decl::dump(raw_ostream &OS, bool Deserialize) const {
Aaron Ballman8c208282017-12-21 21:42:42 +00002327 const ASTContext &Ctx = getASTContext();
2328 const SourceManager &SM = Ctx.getSourceManager();
2329 ASTDumper P(OS, &Ctx.getCommentCommandTraits(), &SM,
2330 SM.getDiagnostics().getShowColors(), Ctx.getPrintingPolicy());
Richard Smith3a36ac12017-03-09 22:00:01 +00002331 P.setDeserialize(Deserialize);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002332 P.dumpDecl(this);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002333}
2334
Alp Tokeref6b0072014-01-04 13:47:14 +00002335LLVM_DUMP_METHOD void Decl::dumpColor() const {
Aaron Ballman8c208282017-12-21 21:42:42 +00002336 const ASTContext &Ctx = getASTContext();
2337 ASTDumper P(llvm::errs(), &Ctx.getCommentCommandTraits(),
2338 &Ctx.getSourceManager(), /*ShowColors*/ true,
2339 Ctx.getPrintingPolicy());
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002340 P.dumpDecl(this);
Richard Trieud215b8d2013-01-26 01:31:20 +00002341}
Richard Smith33937e72013-06-22 21:49:40 +00002342
Alp Tokeref6b0072014-01-04 13:47:14 +00002343LLVM_DUMP_METHOD void DeclContext::dumpLookups() const {
Richard Smith6ea05822013-06-24 01:45:33 +00002344 dumpLookups(llvm::errs());
2345}
2346
Richard Smith35f986d2014-08-11 22:11:07 +00002347LLVM_DUMP_METHOD void DeclContext::dumpLookups(raw_ostream &OS,
Richard Smith3a36ac12017-03-09 22:00:01 +00002348 bool DumpDecls,
2349 bool Deserialize) const {
Richard Smith33937e72013-06-22 21:49:40 +00002350 const DeclContext *DC = this;
2351 while (!DC->isTranslationUnit())
2352 DC = DC->getParent();
2353 ASTContext &Ctx = cast<TranslationUnitDecl>(DC)->getASTContext();
Aaron Ballman8c208282017-12-21 21:42:42 +00002354 const SourceManager &SM = Ctx.getSourceManager();
2355 ASTDumper P(OS, &Ctx.getCommentCommandTraits(), &Ctx.getSourceManager(),
2356 SM.getDiagnostics().getShowColors(), Ctx.getPrintingPolicy());
Richard Smith3a36ac12017-03-09 22:00:01 +00002357 P.setDeserialize(Deserialize);
Richard Smith35f986d2014-08-11 22:11:07 +00002358 P.dumpLookups(this, DumpDecls);
Richard Smith33937e72013-06-22 21:49:40 +00002359}
2360
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002361//===----------------------------------------------------------------------===//
Chris Lattnercbe4f772007-08-08 22:51:59 +00002362// Stmt method implementations
2363//===----------------------------------------------------------------------===//
2364
Alp Tokeref6b0072014-01-04 13:47:14 +00002365LLVM_DUMP_METHOD void Stmt::dump(SourceManager &SM) const {
Argyrios Kyrtzidisc049f752010-08-09 10:54:31 +00002366 dump(llvm::errs(), SM);
2367}
2368
Alp Tokeref6b0072014-01-04 13:47:14 +00002369LLVM_DUMP_METHOD void Stmt::dump(raw_ostream &OS, SourceManager &SM) const {
Craig Topper36250ad2014-05-12 05:36:57 +00002370 ASTDumper P(OS, nullptr, &SM);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002371 P.dumpStmt(this);
Chris Lattner779d5d92007-08-30 00:40:08 +00002372}
2373
Faisal Vali2da8ed92015-03-22 13:35:56 +00002374LLVM_DUMP_METHOD void Stmt::dump(raw_ostream &OS) const {
2375 ASTDumper P(OS, nullptr, nullptr);
2376 P.dumpStmt(this);
2377}
2378
Alp Tokeref6b0072014-01-04 13:47:14 +00002379LLVM_DUMP_METHOD void Stmt::dump() const {
Craig Topper36250ad2014-05-12 05:36:57 +00002380 ASTDumper P(llvm::errs(), nullptr, nullptr);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002381 P.dumpStmt(this);
Chris Lattnercbe4f772007-08-08 22:51:59 +00002382}
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002383
Alp Tokeref6b0072014-01-04 13:47:14 +00002384LLVM_DUMP_METHOD void Stmt::dumpColor() const {
Craig Topper36250ad2014-05-12 05:36:57 +00002385 ASTDumper P(llvm::errs(), nullptr, nullptr, /*ShowColors*/true);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002386 P.dumpStmt(this);
Richard Trieud215b8d2013-01-26 01:31:20 +00002387}
2388
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002389//===----------------------------------------------------------------------===//
2390// Comment method implementations
2391//===----------------------------------------------------------------------===//
2392
Craig Topper36250ad2014-05-12 05:36:57 +00002393LLVM_DUMP_METHOD void Comment::dump() const {
2394 dump(llvm::errs(), nullptr, nullptr);
2395}
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002396
Alp Tokeref6b0072014-01-04 13:47:14 +00002397LLVM_DUMP_METHOD void Comment::dump(const ASTContext &Context) const {
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002398 dump(llvm::errs(), &Context.getCommentCommandTraits(),
2399 &Context.getSourceManager());
2400}
2401
Alexander Kornienko00911f12013-01-15 12:20:21 +00002402void Comment::dump(raw_ostream &OS, const CommandTraits *Traits,
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002403 const SourceManager *SM) const {
2404 const FullComment *FC = dyn_cast<FullComment>(this);
Stephen Kelly570b2972018-12-09 13:18:55 +00002405 if (!FC)
2406 return;
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002407 ASTDumper D(OS, Traits, SM);
Stephen Kelly570b2972018-12-09 13:18:55 +00002408 D.dumpComment(FC, FC);
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002409}
Richard Trieud215b8d2013-01-26 01:31:20 +00002410
Alp Tokeref6b0072014-01-04 13:47:14 +00002411LLVM_DUMP_METHOD void Comment::dumpColor() const {
Richard Trieud215b8d2013-01-26 01:31:20 +00002412 const FullComment *FC = dyn_cast<FullComment>(this);
Stephen Kelly570b2972018-12-09 13:18:55 +00002413 if (!FC)
2414 return;
Craig Topper36250ad2014-05-12 05:36:57 +00002415 ASTDumper D(llvm::errs(), nullptr, nullptr, /*ShowColors*/true);
Stephen Kelly570b2972018-12-09 13:18:55 +00002416 D.dumpComment(FC, FC);
Richard Trieud215b8d2013-01-26 01:31:20 +00002417}