blob: 8137c81d0c43b77af5276ab6e9c28eef6770661a [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";
202 if (T->isConst()) OS << " const";
203 if (T->isVolatile()) OS << " volatile";
204 if (T->isRestrict()) OS << " restrict";
205 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
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000385 void VisitCastExpr(const CastExpr *Node);
Roman Lebedev12216f12018-07-27 07:27:14 +0000386 void VisitImplicitCastExpr(const ImplicitCastExpr *Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000387 void VisitDeclRefExpr(const DeclRefExpr *Node);
388 void VisitPredefinedExpr(const PredefinedExpr *Node);
389 void VisitCharacterLiteral(const CharacterLiteral *Node);
390 void VisitIntegerLiteral(const IntegerLiteral *Node);
Leonard Chandb01c3a2018-06-20 17:19:40 +0000391 void VisitFixedPointLiteral(const FixedPointLiteral *Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000392 void VisitFloatingLiteral(const FloatingLiteral *Node);
393 void VisitStringLiteral(const StringLiteral *Str);
Richard Smithf0514962014-06-03 08:24:28 +0000394 void VisitInitListExpr(const InitListExpr *ILE);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000395 void VisitUnaryOperator(const UnaryOperator *Node);
396 void VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *Node);
397 void VisitMemberExpr(const MemberExpr *Node);
398 void VisitExtVectorElementExpr(const ExtVectorElementExpr *Node);
399 void VisitBinaryOperator(const BinaryOperator *Node);
400 void VisitCompoundAssignOperator(const CompoundAssignOperator *Node);
401 void VisitAddrLabelExpr(const AddrLabelExpr *Node);
402 void VisitBlockExpr(const BlockExpr *Node);
403 void VisitOpaqueValueExpr(const OpaqueValueExpr *Node);
Richard Smith01ccebf2018-01-05 21:31:07 +0000404 void VisitGenericSelectionExpr(const GenericSelectionExpr *E);
Chris Lattner84ca3762007-08-30 01:00:35 +0000405
406 // C++
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000407 void VisitCXXNamedCastExpr(const CXXNamedCastExpr *Node);
408 void VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *Node);
409 void VisitCXXThisExpr(const CXXThisExpr *Node);
410 void VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *Node);
Richard Smith39eca9b2017-08-23 22:12:08 +0000411 void VisitCXXUnresolvedConstructExpr(const CXXUnresolvedConstructExpr *Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000412 void VisitCXXConstructExpr(const CXXConstructExpr *Node);
413 void VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *Node);
Reid Kleckner5c682bc2015-03-19 18:09:25 +0000414 void VisitCXXNewExpr(const CXXNewExpr *Node);
415 void VisitCXXDeleteExpr(const CXXDeleteExpr *Node);
Richard Smithe6c01442013-06-05 00:46:14 +0000416 void VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000417 void VisitExprWithCleanups(const ExprWithCleanups *Node);
418 void VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *Node);
Faisal Vali2b391ab2013-09-26 19:54:12 +0000419 void VisitLambdaExpr(const LambdaExpr *Node) {
Faisal Vali2b391ab2013-09-26 19:54:12 +0000420 dumpDecl(Node->getLambdaClass());
421 }
Serge Pavlov6b926032015-02-16 19:58:41 +0000422 void VisitSizeOfPackExpr(const SizeOfPackExpr *Node);
Alex Lorenzddbe0f52016-11-09 14:02:18 +0000423 void
424 VisitCXXDependentScopeMemberExpr(const CXXDependentScopeMemberExpr *Node);
Mike Stump11289f42009-09-09 15:08:12 +0000425
Chris Lattner84ca3762007-08-30 01:00:35 +0000426 // ObjC
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000427 void VisitObjCAtCatchStmt(const ObjCAtCatchStmt *Node);
428 void VisitObjCEncodeExpr(const ObjCEncodeExpr *Node);
429 void VisitObjCMessageExpr(const ObjCMessageExpr *Node);
430 void VisitObjCBoxedExpr(const ObjCBoxedExpr *Node);
431 void VisitObjCSelectorExpr(const ObjCSelectorExpr *Node);
432 void VisitObjCProtocolExpr(const ObjCProtocolExpr *Node);
433 void VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *Node);
434 void VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *Node);
435 void VisitObjCIvarRefExpr(const ObjCIvarRefExpr *Node);
436 void VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *Node);
Alexander Kornienkoebc17b52013-01-14 14:07:11 +0000437
438 // Comments.
Stephen Kellycdbfb302018-12-02 17:30:40 +0000439 void dumpComment(const Comment *C, const FullComment *FC);
Chris Lattnercbe4f772007-08-08 22:51:59 +0000440 };
Alexander Kornienkoab9db512015-06-22 23:07:51 +0000441}
Chris Lattnercbe4f772007-08-08 22:51:59 +0000442
443//===----------------------------------------------------------------------===//
Chris Lattner11e30d32007-08-30 06:17:34 +0000444// Utilities
445//===----------------------------------------------------------------------===//
446
Richard Smithd5e7ff82014-10-31 01:17:45 +0000447void ASTDumper::dumpTypeAsChild(QualType T) {
448 SplitQualType SQT = T.split();
449 if (!SQT.Quals.hasQualifiers())
450 return dumpTypeAsChild(SQT.Ty);
451
452 dumpChild([=] {
453 OS << "QualType";
Stephen Kellyd8744a72018-12-05 21:12:39 +0000454 NodeDumper.dumpPointer(T.getAsOpaquePtr());
Richard Smithd5e7ff82014-10-31 01:17:45 +0000455 OS << " ";
Stephen Kellyd8744a72018-12-05 21:12:39 +0000456 NodeDumper.dumpBareType(T, false);
Richard Smithd5e7ff82014-10-31 01:17:45 +0000457 OS << " " << T.split().Quals.getAsString();
458 dumpTypeAsChild(T.split().Ty);
459 });
460}
461
462void ASTDumper::dumpTypeAsChild(const Type *T) {
463 dumpChild([=] {
464 if (!T) {
Stephen Kelly27e948c2018-11-29 19:30:37 +0000465 ColorScope Color(OS, ShowColors, NullColor);
Richard Smithd5e7ff82014-10-31 01:17:45 +0000466 OS << "<<<NULL>>>";
467 return;
468 }
Serge Pavlova6adc9e2015-12-28 17:19:12 +0000469 if (const LocInfoType *LIT = llvm::dyn_cast<LocInfoType>(T)) {
470 {
Stephen Kelly27e948c2018-11-29 19:30:37 +0000471 ColorScope Color(OS, ShowColors, TypeColor);
Serge Pavlova6adc9e2015-12-28 17:19:12 +0000472 OS << "LocInfo Type";
473 }
Stephen Kellyd8744a72018-12-05 21:12:39 +0000474 NodeDumper.dumpPointer(T);
Serge Pavlova6adc9e2015-12-28 17:19:12 +0000475 dumpTypeAsChild(LIT->getTypeSourceInfo()->getType());
476 return;
477 }
Richard Smithd5e7ff82014-10-31 01:17:45 +0000478
479 {
Stephen Kelly27e948c2018-11-29 19:30:37 +0000480 ColorScope Color(OS, ShowColors, TypeColor);
Richard Smithd5e7ff82014-10-31 01:17:45 +0000481 OS << T->getTypeClassName() << "Type";
482 }
Stephen Kellyd8744a72018-12-05 21:12:39 +0000483 NodeDumper.dumpPointer(T);
Richard Smithd5e7ff82014-10-31 01:17:45 +0000484 OS << " ";
Stephen Kellyd8744a72018-12-05 21:12:39 +0000485 NodeDumper.dumpBareType(QualType(T, 0), false);
Richard Smithd5e7ff82014-10-31 01:17:45 +0000486
487 QualType SingleStepDesugar =
488 T->getLocallyUnqualifiedSingleStepDesugaredType();
489 if (SingleStepDesugar != QualType(T, 0))
490 OS << " sugar";
491 if (T->isDependentType())
492 OS << " dependent";
493 else if (T->isInstantiationDependentType())
494 OS << " instantiation_dependent";
495 if (T->isVariablyModifiedType())
496 OS << " variably_modified";
497 if (T->containsUnexpandedParameterPack())
498 OS << " contains_unexpanded_pack";
499 if (T->isFromAST())
500 OS << " imported";
501
502 TypeVisitor<ASTDumper>::Visit(T);
503
504 if (SingleStepDesugar != QualType(T, 0))
505 dumpTypeAsChild(SingleStepDesugar);
506 });
507}
508
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000509void ASTDumper::dumpDeclRef(const Decl *D, const char *Label) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000510 if (!D)
511 return;
512
Richard Smithf7514452014-10-30 21:02:37 +0000513 dumpChild([=]{
514 if (Label)
515 OS << Label << ' ';
516 dumpBareDeclRef(D);
517 });
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000518}
519
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000520void ASTDumper::dumpDeclContext(const DeclContext *DC) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000521 if (!DC)
522 return;
Richard Smithdcc2c452014-03-17 23:00:06 +0000523
Richard Smith3a36ac12017-03-09 22:00:01 +0000524 for (auto *D : (Deserialize ? DC->decls() : DC->noload_decls()))
Richard Smithf7514452014-10-30 21:02:37 +0000525 dumpDecl(D);
Richard Smithdcc2c452014-03-17 23:00:06 +0000526
527 if (DC->hasExternalLexicalStorage()) {
Stephen Kelly27e948c2018-11-29 19:30:37 +0000528 dumpChild([=] {
529 ColorScope Color(OS, ShowColors, UndeserializedColor);
Richard Smithf7514452014-10-30 21:02:37 +0000530 OS << "<undeserialized declarations>";
531 });
Richard Smith1d209d02013-05-23 01:49:11 +0000532 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000533}
534
Richard Smith35f986d2014-08-11 22:11:07 +0000535void ASTDumper::dumpLookups(const DeclContext *DC, bool DumpDecls) {
Richard Smithf7514452014-10-30 21:02:37 +0000536 dumpChild([=] {
537 OS << "StoredDeclsMap ";
Stephen Kellyd8744a72018-12-05 21:12:39 +0000538 NodeDumper.dumpBareDeclRef(cast<Decl>(DC));
Richard Smith33937e72013-06-22 21:49:40 +0000539
Richard Smithf7514452014-10-30 21:02:37 +0000540 const DeclContext *Primary = DC->getPrimaryContext();
541 if (Primary != DC) {
542 OS << " primary";
Stephen Kellyd8744a72018-12-05 21:12:39 +0000543 NodeDumper.dumpPointer(cast<Decl>(Primary));
Richard Smith33937e72013-06-22 21:49:40 +0000544 }
545
Richard Smithf7514452014-10-30 21:02:37 +0000546 bool HasUndeserializedLookups = Primary->hasExternalVisibleStorage();
Richard Smith35f986d2014-08-11 22:11:07 +0000547
Sam McCall091b1ef2018-01-16 12:33:46 +0000548 auto Range = Deserialize
549 ? Primary->lookups()
550 : Primary->noload_lookups(/*PreserveInternalState=*/true);
551 for (auto I = Range.begin(), E = Range.end(); I != E; ++I) {
Richard Smithf7514452014-10-30 21:02:37 +0000552 DeclarationName Name = I.getLookupName();
Richard Smith3a36ac12017-03-09 22:00:01 +0000553 DeclContextLookupResult R = *I;
Richard Smith35f986d2014-08-11 22:11:07 +0000554
Richard Smithf7514452014-10-30 21:02:37 +0000555 dumpChild([=] {
556 OS << "DeclarationName ";
557 {
Stephen Kelly27e948c2018-11-29 19:30:37 +0000558 ColorScope Color(OS, ShowColors, DeclNameColor);
Richard Smithf7514452014-10-30 21:02:37 +0000559 OS << '\'' << Name << '\'';
560 }
Richard Smith35f986d2014-08-11 22:11:07 +0000561
Richard Smithf7514452014-10-30 21:02:37 +0000562 for (DeclContextLookupResult::iterator RI = R.begin(), RE = R.end();
563 RI != RE; ++RI) {
564 dumpChild([=] {
Stephen Kellyd8744a72018-12-05 21:12:39 +0000565 NodeDumper.dumpBareDeclRef(*RI);
Richard Smithf7514452014-10-30 21:02:37 +0000566
567 if ((*RI)->isHidden())
568 OS << " hidden";
569
570 // If requested, dump the redecl chain for this lookup.
571 if (DumpDecls) {
572 // Dump earliest decl first.
573 std::function<void(Decl *)> DumpWithPrev = [&](Decl *D) {
574 if (Decl *Prev = D->getPreviousDecl())
575 DumpWithPrev(Prev);
576 dumpDecl(D);
577 };
578 DumpWithPrev(*RI);
579 }
580 });
581 }
582 });
Richard Smith33937e72013-06-22 21:49:40 +0000583 }
Richard Smith33937e72013-06-22 21:49:40 +0000584
Richard Smithf7514452014-10-30 21:02:37 +0000585 if (HasUndeserializedLookups) {
586 dumpChild([=] {
Stephen Kelly27e948c2018-11-29 19:30:37 +0000587 ColorScope Color(OS, ShowColors, UndeserializedColor);
Richard Smithf7514452014-10-30 21:02:37 +0000588 OS << "<undeserialized lookups>";
589 });
590 }
591 });
Richard Smith33937e72013-06-22 21:49:40 +0000592}
593
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000594void ASTDumper::dumpAttr(const Attr *A) {
Richard Smithf7514452014-10-30 21:02:37 +0000595 dumpChild([=] {
596 {
Stephen Kelly27e948c2018-11-29 19:30:37 +0000597 ColorScope Color(OS, ShowColors, AttrColor);
Aaron Ballman36a53502014-01-16 13:03:14 +0000598
Richard Smithf7514452014-10-30 21:02:37 +0000599 switch (A->getKind()) {
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000600#define ATTR(X) case attr::X: OS << #X; break;
601#include "clang/Basic/AttrList.inc"
Richard Smithf7514452014-10-30 21:02:37 +0000602 }
603 OS << "Attr";
Richard Trieud215b8d2013-01-26 01:31:20 +0000604 }
Stephen Kellyd8744a72018-12-05 21:12:39 +0000605 NodeDumper.dumpPointer(A);
606 NodeDumper.dumpSourceRange(A->getRange());
Richard Smithf7514452014-10-30 21:02:37 +0000607 if (A->isInherited())
608 OS << " Inherited";
609 if (A->isImplicit())
610 OS << " Implicit";
Hans Wennborgb0a8b4a2014-05-31 04:05:57 +0000611#include "clang/AST/AttrDump.inc"
Richard Smithf7514452014-10-30 21:02:37 +0000612 });
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000613}
614
Richard Smith71bec062013-10-15 21:58:30 +0000615static void dumpPreviousDeclImpl(raw_ostream &OS, ...) {}
616
617template<typename T>
618static void dumpPreviousDeclImpl(raw_ostream &OS, const Mergeable<T> *D) {
Rafael Espindola8db352d2013-10-17 15:37:26 +0000619 const T *First = D->getFirstDecl();
Richard Smith71bec062013-10-15 21:58:30 +0000620 if (First != D)
621 OS << " first " << First;
Richard Smithf5f43542013-02-07 01:35:44 +0000622}
623
624template<typename T>
Richard Smith71bec062013-10-15 21:58:30 +0000625static void dumpPreviousDeclImpl(raw_ostream &OS, const Redeclarable<T> *D) {
626 const T *Prev = D->getPreviousDecl();
627 if (Prev)
628 OS << " prev " << Prev;
Richard Smithf5f43542013-02-07 01:35:44 +0000629}
630
Richard Smith71bec062013-10-15 21:58:30 +0000631/// Dump the previous declaration in the redeclaration chain for a declaration,
632/// if any.
633static void dumpPreviousDecl(raw_ostream &OS, const Decl *D) {
Richard Smithf5f43542013-02-07 01:35:44 +0000634 switch (D->getKind()) {
635#define DECL(DERIVED, BASE) \
636 case Decl::DERIVED: \
Richard Smith71bec062013-10-15 21:58:30 +0000637 return dumpPreviousDeclImpl(OS, cast<DERIVED##Decl>(D));
Richard Smithf5f43542013-02-07 01:35:44 +0000638#define ABSTRACT_DECL(DECL)
639#include "clang/AST/DeclNodes.inc"
640 }
641 llvm_unreachable("Decl that isn't part of DeclNodes.inc!");
642}
643
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000644//===----------------------------------------------------------------------===//
645// C++ Utilities
646//===----------------------------------------------------------------------===//
647
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000648void ASTDumper::dumpCXXCtorInitializer(const CXXCtorInitializer *Init) {
Richard Smithf7514452014-10-30 21:02:37 +0000649 dumpChild([=] {
650 OS << "CXXCtorInitializer";
651 if (Init->isAnyMemberInitializer()) {
652 OS << ' ';
Stephen Kellyd8744a72018-12-05 21:12:39 +0000653 NodeDumper.dumpBareDeclRef(Init->getAnyMember());
Richard Smithf7514452014-10-30 21:02:37 +0000654 } else if (Init->isBaseInitializer()) {
Stephen Kellyd8744a72018-12-05 21:12:39 +0000655 NodeDumper.dumpType(QualType(Init->getBaseClass(), 0));
Richard Smithf7514452014-10-30 21:02:37 +0000656 } else if (Init->isDelegatingInitializer()) {
Stephen Kellyd8744a72018-12-05 21:12:39 +0000657 NodeDumper.dumpType(Init->getTypeSourceInfo()->getType());
Richard Smithf7514452014-10-30 21:02:37 +0000658 } else {
659 llvm_unreachable("Unknown initializer type");
660 }
661 dumpStmt(Init->getInit());
662 });
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000663}
664
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000665void ASTDumper::dumpTemplateParameters(const TemplateParameterList *TPL) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000666 if (!TPL)
667 return;
668
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000669 for (TemplateParameterList::const_iterator I = TPL->begin(), E = TPL->end();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000670 I != E; ++I)
671 dumpDecl(*I);
672}
673
674void ASTDumper::dumpTemplateArgumentListInfo(
675 const TemplateArgumentListInfo &TALI) {
Richard Smithf7514452014-10-30 21:02:37 +0000676 for (unsigned i = 0, e = TALI.size(); i < e; ++i)
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000677 dumpTemplateArgumentLoc(TALI[i]);
678}
679
Stephen Kelly43835952018-12-10 21:03:00 +0000680void ASTDumper::dumpTemplateArgumentLoc(const TemplateArgumentLoc &A,
Stephen Kelly1be0bea2018-12-10 21:04:04 +0000681 const Decl *From, const char *Label) {
682 dumpTemplateArgument(A.getArgument(), A.getSourceRange(), From, Label);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000683}
684
685void ASTDumper::dumpTemplateArgumentList(const TemplateArgumentList &TAL) {
686 for (unsigned i = 0, e = TAL.size(); i < e; ++i)
687 dumpTemplateArgument(TAL[i]);
688}
689
Stephen Kelly43835952018-12-10 21:03:00 +0000690void ASTDumper::dumpTemplateArgument(const TemplateArgument &A, SourceRange R,
Stephen Kelly1be0bea2018-12-10 21:04:04 +0000691 const Decl *From, const char *Label) {
Richard Smithf7514452014-10-30 21:02:37 +0000692 dumpChild([=] {
693 OS << "TemplateArgument";
694 if (R.isValid())
Stephen Kellyd8744a72018-12-05 21:12:39 +0000695 NodeDumper.dumpSourceRange(R);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000696
Stephen Kelly1be0bea2018-12-10 21:04:04 +0000697 if (From)
698 dumpDeclRef(From, Label);
Stephen Kelly43835952018-12-10 21:03:00 +0000699
Richard Smithf7514452014-10-30 21:02:37 +0000700 switch (A.getKind()) {
701 case TemplateArgument::Null:
702 OS << " null";
703 break;
704 case TemplateArgument::Type:
705 OS << " type";
Stephen Kellyd8744a72018-12-05 21:12:39 +0000706 NodeDumper.dumpType(A.getAsType());
Richard Smithf7514452014-10-30 21:02:37 +0000707 break;
708 case TemplateArgument::Declaration:
709 OS << " decl";
710 dumpDeclRef(A.getAsDecl());
711 break;
712 case TemplateArgument::NullPtr:
713 OS << " nullptr";
714 break;
715 case TemplateArgument::Integral:
716 OS << " integral " << A.getAsIntegral();
717 break;
718 case TemplateArgument::Template:
719 OS << " template ";
720 A.getAsTemplate().dump(OS);
721 break;
722 case TemplateArgument::TemplateExpansion:
Richard Trieu59c289f2018-08-21 22:55:26 +0000723 OS << " template expansion ";
Richard Smithf7514452014-10-30 21:02:37 +0000724 A.getAsTemplateOrTemplatePattern().dump(OS);
725 break;
726 case TemplateArgument::Expression:
727 OS << " expr";
728 dumpStmt(A.getAsExpr());
729 break;
730 case TemplateArgument::Pack:
731 OS << " pack";
732 for (TemplateArgument::pack_iterator I = A.pack_begin(), E = A.pack_end();
733 I != E; ++I)
734 dumpTemplateArgument(*I);
735 break;
Richard Trieude5cc7d2013-01-31 01:44:26 +0000736 }
Richard Smithf7514452014-10-30 21:02:37 +0000737 });
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000738}
739
Chris Lattner11e30d32007-08-30 06:17:34 +0000740//===----------------------------------------------------------------------===//
Douglas Gregor85f3f952015-07-07 03:57:15 +0000741// Objective-C Utilities
742//===----------------------------------------------------------------------===//
743void ASTDumper::dumpObjCTypeParamList(const ObjCTypeParamList *typeParams) {
744 if (!typeParams)
745 return;
746
747 for (auto typeParam : *typeParams) {
748 dumpDecl(typeParam);
749 }
750}
751
752//===----------------------------------------------------------------------===//
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000753// Decl dumping methods.
Chris Lattnercbe4f772007-08-08 22:51:59 +0000754//===----------------------------------------------------------------------===//
755
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000756void ASTDumper::dumpDecl(const Decl *D) {
Richard Smithf7514452014-10-30 21:02:37 +0000757 dumpChild([=] {
758 if (!D) {
Stephen Kelly27e948c2018-11-29 19:30:37 +0000759 ColorScope Color(OS, ShowColors, NullColor);
Richard Smithf7514452014-10-30 21:02:37 +0000760 OS << "<<<NULL>>>";
761 return;
762 }
Mike Stump11289f42009-09-09 15:08:12 +0000763
Richard Smithf7514452014-10-30 21:02:37 +0000764 {
Stephen Kelly27e948c2018-11-29 19:30:37 +0000765 ColorScope Color(OS, ShowColors, DeclKindNameColor);
Richard Smithf7514452014-10-30 21:02:37 +0000766 OS << D->getDeclKindName() << "Decl";
767 }
Stephen Kellyd8744a72018-12-05 21:12:39 +0000768 NodeDumper.dumpPointer(D);
Richard Smithf7514452014-10-30 21:02:37 +0000769 if (D->getLexicalDeclContext() != D->getDeclContext())
770 OS << " parent " << cast<Decl>(D->getDeclContext());
771 dumpPreviousDecl(OS, D);
Stephen Kellyd8744a72018-12-05 21:12:39 +0000772 NodeDumper.dumpSourceRange(D->getSourceRange());
Richard Smithf7514452014-10-30 21:02:37 +0000773 OS << ' ';
Stephen Kellyd8744a72018-12-05 21:12:39 +0000774 NodeDumper.dumpLocation(D->getLocation());
Richard Smith26342f92017-05-17 00:24:14 +0000775 if (D->isFromASTFile())
776 OS << " imported";
777 if (Module *M = D->getOwningModule())
Richard Smithf7514452014-10-30 21:02:37 +0000778 OS << " in " << M->getFullModuleName();
Richard Smitha2eb4092015-06-22 18:47:01 +0000779 if (auto *ND = dyn_cast<NamedDecl>(D))
780 for (Module *M : D->getASTContext().getModulesWithMergedDefinition(
781 const_cast<NamedDecl *>(ND)))
782 dumpChild([=] { OS << "also in " << M->getFullModuleName(); });
Richard Smithf7514452014-10-30 21:02:37 +0000783 if (const NamedDecl *ND = dyn_cast<NamedDecl>(D))
784 if (ND->isHidden())
785 OS << " hidden";
786 if (D->isImplicit())
787 OS << " implicit";
788 if (D->isUsed())
789 OS << " used";
790 else if (D->isThisDeclarationReferenced())
791 OS << " referenced";
792 if (D->isInvalidDecl())
793 OS << " invalid";
Hans Wennborg76b00532014-12-05 22:38:57 +0000794 if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
795 if (FD->isConstexpr())
796 OS << " constexpr";
797
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000798
Richard Smithf7514452014-10-30 21:02:37 +0000799 ConstDeclVisitor<ASTDumper>::Visit(D);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000800
Richard Smithf7514452014-10-30 21:02:37 +0000801 for (Decl::attr_iterator I = D->attr_begin(), E = D->attr_end(); I != E;
802 ++I)
803 dumpAttr(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000804
Richard Smithf7514452014-10-30 21:02:37 +0000805 if (const FullComment *Comment =
806 D->getASTContext().getLocalCommentForDeclUncached(D))
Stephen Kelly570b2972018-12-09 13:18:55 +0000807 dumpComment(Comment, Comment);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000808
Richard Smithf7514452014-10-30 21:02:37 +0000809 // Decls within functions are visited by the body.
Stephen Kelly39271a12018-12-09 13:20:43 +0000810 if (!isa<FunctionDecl>(*D) && !isa<ObjCMethodDecl>(*D)) {
811 auto DC = dyn_cast<DeclContext>(D);
812 if (DC &&
813 (DC->hasExternalLexicalStorage() ||
814 (Deserialize ? DC->decls_begin() != DC->decls_end()
815 : DC->noload_decls_begin() != DC->noload_decls_end())))
816 dumpDeclContext(DC);
817 }
Richard Smithf7514452014-10-30 21:02:37 +0000818 });
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000819}
820
Stephen Kellyd8744a72018-12-05 21:12:39 +0000821void ASTDumper::VisitLabelDecl(const LabelDecl *D) { NodeDumper.dumpName(D); }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000822
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000823void ASTDumper::VisitTypedefDecl(const TypedefDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +0000824 NodeDumper.dumpName(D);
825 NodeDumper.dumpType(D->getUnderlyingType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000826 if (D->isModulePrivate())
827 OS << " __module_private__";
Richard Smithba3a4f92016-01-12 21:59:26 +0000828 dumpTypeAsChild(D->getUnderlyingType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000829}
830
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000831void ASTDumper::VisitEnumDecl(const EnumDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000832 if (D->isScoped()) {
833 if (D->isScopedUsingClassTag())
834 OS << " class";
835 else
836 OS << " struct";
837 }
Stephen Kellyd8744a72018-12-05 21:12:39 +0000838 NodeDumper.dumpName(D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000839 if (D->isModulePrivate())
840 OS << " __module_private__";
841 if (D->isFixed())
Stephen Kellyd8744a72018-12-05 21:12:39 +0000842 NodeDumper.dumpType(D->getIntegerType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000843}
844
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000845void ASTDumper::VisitRecordDecl(const RecordDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000846 OS << ' ' << D->getKindName();
Stephen Kellyd8744a72018-12-05 21:12:39 +0000847 NodeDumper.dumpName(D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000848 if (D->isModulePrivate())
849 OS << " __module_private__";
Richard Smith99bc1b92013-08-30 05:32:29 +0000850 if (D->isCompleteDefinition())
851 OS << " definition";
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000852}
853
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000854void ASTDumper::VisitEnumConstantDecl(const EnumConstantDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +0000855 NodeDumper.dumpName(D);
856 NodeDumper.dumpType(D->getType());
Richard Smithf7514452014-10-30 21:02:37 +0000857 if (const Expr *Init = D->getInitExpr())
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000858 dumpStmt(Init);
859}
860
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000861void ASTDumper::VisitIndirectFieldDecl(const IndirectFieldDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +0000862 NodeDumper.dumpName(D);
863 NodeDumper.dumpType(D->getType());
Richard Smithdcc2c452014-03-17 23:00:06 +0000864
Richard Smith8aa49222014-03-18 00:35:12 +0000865 for (auto *Child : D->chain())
Richard Smithf7514452014-10-30 21:02:37 +0000866 dumpDeclRef(Child);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000867}
868
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000869void ASTDumper::VisitFunctionDecl(const FunctionDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +0000870 NodeDumper.dumpName(D);
871 NodeDumper.dumpType(D->getType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000872
Rafael Espindola6ae7e502013-04-03 19:27:57 +0000873 StorageClass SC = D->getStorageClass();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000874 if (SC != SC_None)
875 OS << ' ' << VarDecl::getStorageClassSpecifierString(SC);
876 if (D->isInlineSpecified())
877 OS << " inline";
878 if (D->isVirtualAsWritten())
879 OS << " virtual";
880 if (D->isModulePrivate())
881 OS << " __module_private__";
882
883 if (D->isPure())
884 OS << " pure";
Richard Smith5a2e6b92016-11-21 23:43:54 +0000885 if (D->isDefaulted()) {
886 OS << " default";
887 if (D->isDeleted())
888 OS << "_delete";
889 }
890 if (D->isDeletedAsWritten())
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000891 OS << " delete";
Richard Smith5a2e6b92016-11-21 23:43:54 +0000892 if (D->isTrivial())
893 OS << " trivial";
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000894
Richard Smithadaa0152013-05-17 02:09:46 +0000895 if (const FunctionProtoType *FPT = D->getType()->getAs<FunctionProtoType>()) {
896 FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo();
Richard Smith8acb4282014-07-31 21:57:55 +0000897 switch (EPI.ExceptionSpec.Type) {
Richard Smithadaa0152013-05-17 02:09:46 +0000898 default: break;
899 case EST_Unevaluated:
Richard Smith8acb4282014-07-31 21:57:55 +0000900 OS << " noexcept-unevaluated " << EPI.ExceptionSpec.SourceDecl;
Richard Smithadaa0152013-05-17 02:09:46 +0000901 break;
902 case EST_Uninstantiated:
Richard Smith8acb4282014-07-31 21:57:55 +0000903 OS << " noexcept-uninstantiated " << EPI.ExceptionSpec.SourceTemplate;
Richard Smithadaa0152013-05-17 02:09:46 +0000904 break;
905 }
906 }
907
Richard Smithf7514452014-10-30 21:02:37 +0000908 if (const FunctionTemplateSpecializationInfo *FTSI =
909 D->getTemplateSpecializationInfo())
Richard Trieude5cc7d2013-01-31 01:44:26 +0000910 dumpTemplateArgumentList(*FTSI->TemplateArguments);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000911
Richard Smith8a639892015-01-24 01:07:20 +0000912 if (!D->param_begin() && D->getNumParams())
913 dumpChild([=] { OS << "<<NULL params x " << D->getNumParams() << ">>"; });
914 else
David Majnemera3debed2016-06-24 05:33:44 +0000915 for (const ParmVarDecl *Parameter : D->parameters())
916 dumpDecl(Parameter);
Richard Smithf7514452014-10-30 21:02:37 +0000917
918 if (const CXXConstructorDecl *C = dyn_cast<CXXConstructorDecl>(D))
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000919 for (CXXConstructorDecl::init_const_iterator I = C->init_begin(),
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000920 E = C->init_end();
Richard Smithf7514452014-10-30 21:02:37 +0000921 I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000922 dumpCXXCtorInitializer(*I);
923
Lenar Safin9ae21552017-07-29 20:42:58 +0000924 if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(D)) {
Lang Hames19e07e12017-06-20 21:06:00 +0000925 if (MD->size_overridden_methods() != 0) {
Aaron Ballman8c208282017-12-21 21:42:42 +0000926 auto dumpOverride = [=](const CXXMethodDecl *D) {
927 SplitQualType T_split = D->getType().split();
928 OS << D << " " << D->getParent()->getName()
929 << "::" << D->getNameAsString() << " '"
930 << QualType::getAsString(T_split, PrintPolicy) << "'";
931 };
Lang Hames19e07e12017-06-20 21:06:00 +0000932
933 dumpChild([=] {
Benjamin Krameracfa3392017-12-17 23:52:45 +0000934 auto Overrides = MD->overridden_methods();
Lang Hames19e07e12017-06-20 21:06:00 +0000935 OS << "Overrides: [ ";
Benjamin Krameracfa3392017-12-17 23:52:45 +0000936 dumpOverride(*Overrides.begin());
Lang Hames19e07e12017-06-20 21:06:00 +0000937 for (const auto *Override :
Benjamin Krameracfa3392017-12-17 23:52:45 +0000938 llvm::make_range(Overrides.begin() + 1, Overrides.end())) {
Lenar Safin9ae21552017-07-29 20:42:58 +0000939 OS << ", ";
Lang Hames19e07e12017-06-20 21:06:00 +0000940 dumpOverride(Override);
Lenar Safin9ae21552017-07-29 20:42:58 +0000941 }
Lang Hames19e07e12017-06-20 21:06:00 +0000942 OS << " ]";
943 });
944 }
Lenar Safin9ae21552017-07-29 20:42:58 +0000945 }
Lang Hames19e07e12017-06-20 21:06:00 +0000946
Richard Smithf7514452014-10-30 21:02:37 +0000947 if (D->doesThisDeclarationHaveABody())
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000948 dumpStmt(D->getBody());
949}
950
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000951void ASTDumper::VisitFieldDecl(const FieldDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +0000952 NodeDumper.dumpName(D);
953 NodeDumper.dumpType(D->getType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000954 if (D->isMutable())
955 OS << " mutable";
956 if (D->isModulePrivate())
957 OS << " __module_private__";
Richard Trieude5cc7d2013-01-31 01:44:26 +0000958
Richard Smithf7514452014-10-30 21:02:37 +0000959 if (D->isBitField())
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000960 dumpStmt(D->getBitWidth());
Richard Smithf7514452014-10-30 21:02:37 +0000961 if (Expr *Init = D->getInClassInitializer())
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000962 dumpStmt(Init);
963}
964
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000965void ASTDumper::VisitVarDecl(const VarDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +0000966 NodeDumper.dumpName(D);
967 NodeDumper.dumpType(D->getType());
Rafael Espindola6ae7e502013-04-03 19:27:57 +0000968 StorageClass SC = D->getStorageClass();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000969 if (SC != SC_None)
970 OS << ' ' << VarDecl::getStorageClassSpecifierString(SC);
Richard Smithfd3834f2013-04-13 02:43:54 +0000971 switch (D->getTLSKind()) {
972 case VarDecl::TLS_None: break;
973 case VarDecl::TLS_Static: OS << " tls"; break;
974 case VarDecl::TLS_Dynamic: OS << " tls_dynamic"; break;
975 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000976 if (D->isModulePrivate())
977 OS << " __module_private__";
978 if (D->isNRVOVariable())
979 OS << " nrvo";
Richard Smith62f19e72016-06-25 00:15:56 +0000980 if (D->isInline())
981 OS << " inline";
982 if (D->isConstexpr())
983 OS << " constexpr";
Richard Trieude5cc7d2013-01-31 01:44:26 +0000984 if (D->hasInit()) {
Richard Smithd9967cc2014-07-10 22:54:03 +0000985 switch (D->getInitStyle()) {
986 case VarDecl::CInit: OS << " cinit"; break;
987 case VarDecl::CallInit: OS << " callinit"; break;
988 case VarDecl::ListInit: OS << " listinit"; break;
989 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000990 dumpStmt(D->getInit());
Richard Trieude5cc7d2013-01-31 01:44:26 +0000991 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000992}
993
Richard Smithbdb84f32016-07-22 23:36:59 +0000994void ASTDumper::VisitDecompositionDecl(const DecompositionDecl *D) {
995 VisitVarDecl(D);
996 for (auto *B : D->bindings())
997 dumpDecl(B);
998}
999
Richard Smith7873de02016-08-11 22:25:46 +00001000void ASTDumper::VisitBindingDecl(const BindingDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +00001001 NodeDumper.dumpName(D);
1002 NodeDumper.dumpType(D->getType());
Richard Smith7873de02016-08-11 22:25:46 +00001003 if (auto *E = D->getBinding())
1004 dumpStmt(E);
1005}
1006
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001007void ASTDumper::VisitFileScopeAsmDecl(const FileScopeAsmDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001008 dumpStmt(D->getAsmString());
1009}
1010
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001011void ASTDumper::VisitImportDecl(const ImportDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001012 OS << ' ' << D->getImportedModule()->getFullModuleName();
1013}
1014
Nico Weber66220292016-03-02 17:28:48 +00001015void ASTDumper::VisitPragmaCommentDecl(const PragmaCommentDecl *D) {
1016 OS << ' ';
1017 switch (D->getCommentKind()) {
1018 case PCK_Unknown: llvm_unreachable("unexpected pragma comment kind");
1019 case PCK_Compiler: OS << "compiler"; break;
1020 case PCK_ExeStr: OS << "exestr"; break;
1021 case PCK_Lib: OS << "lib"; break;
1022 case PCK_Linker: OS << "linker"; break;
1023 case PCK_User: OS << "user"; break;
1024 }
1025 StringRef Arg = D->getArg();
1026 if (!Arg.empty())
1027 OS << " \"" << Arg << "\"";
1028}
1029
Nico Webercbbaeb12016-03-02 19:28:54 +00001030void ASTDumper::VisitPragmaDetectMismatchDecl(
1031 const PragmaDetectMismatchDecl *D) {
1032 OS << " \"" << D->getName() << "\" \"" << D->getValue() << "\"";
1033}
1034
Alexey Bataev958b9e72016-03-31 09:30:50 +00001035void ASTDumper::VisitCapturedDecl(const CapturedDecl *D) {
1036 dumpStmt(D->getBody());
1037}
1038
1039//===----------------------------------------------------------------------===//
1040// OpenMP Declarations
1041//===----------------------------------------------------------------------===//
1042
1043void ASTDumper::VisitOMPThreadPrivateDecl(const OMPThreadPrivateDecl *D) {
1044 for (auto *E : D->varlists())
1045 dumpStmt(E);
1046}
1047
1048void ASTDumper::VisitOMPDeclareReductionDecl(const OMPDeclareReductionDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +00001049 NodeDumper.dumpName(D);
1050 NodeDumper.dumpType(D->getType());
Alexey Bataev958b9e72016-03-31 09:30:50 +00001051 OS << " combiner";
Stephen Kelly266dc192018-12-10 20:53:39 +00001052 NodeDumper.dumpPointer(D->getCombiner());
1053 if (const auto *Initializer = D->getInitializer()) {
Alexey Bataev958b9e72016-03-31 09:30:50 +00001054 OS << " initializer";
Stephen Kelly266dc192018-12-10 20:53:39 +00001055 NodeDumper.dumpPointer(Initializer);
Alexey Bataev070f43a2017-09-06 14:49:58 +00001056 switch (D->getInitializerKind()) {
1057 case OMPDeclareReductionDecl::DirectInit:
1058 OS << " omp_priv = ";
1059 break;
1060 case OMPDeclareReductionDecl::CopyInit:
1061 OS << " omp_priv ()";
1062 break;
1063 case OMPDeclareReductionDecl::CallInit:
1064 break;
1065 }
Alexey Bataev958b9e72016-03-31 09:30:50 +00001066 }
Stephen Kelly266dc192018-12-10 20:53:39 +00001067
1068 dumpStmt(D->getCombiner());
1069 if (const auto *Initializer = D->getInitializer())
1070 dumpStmt(Initializer);
Alexey Bataev958b9e72016-03-31 09:30:50 +00001071}
1072
Kelvin Li1408f912018-09-26 04:28:39 +00001073void ASTDumper::VisitOMPRequiresDecl(const OMPRequiresDecl *D) {
1074 for (auto *C : D->clauselists()) {
1075 dumpChild([=] {
1076 if (!C) {
Stephen Kelly27e948c2018-11-29 19:30:37 +00001077 ColorScope Color(OS, ShowColors, NullColor);
Kelvin Li1408f912018-09-26 04:28:39 +00001078 OS << "<<<NULL>>> OMPClause";
1079 return;
1080 }
1081 {
Stephen Kelly27e948c2018-11-29 19:30:37 +00001082 ColorScope Color(OS, ShowColors, AttrColor);
Kelvin Li1408f912018-09-26 04:28:39 +00001083 StringRef ClauseName(getOpenMPClauseName(C->getClauseKind()));
1084 OS << "OMP" << ClauseName.substr(/*Start=*/0, /*N=*/1).upper()
1085 << ClauseName.drop_front() << "Clause";
1086 }
Stephen Kellyd8744a72018-12-05 21:12:39 +00001087 NodeDumper.dumpPointer(C);
1088 NodeDumper.dumpSourceRange(SourceRange(C->getBeginLoc(), C->getEndLoc()));
Kelvin Li1408f912018-09-26 04:28:39 +00001089 });
1090 }
1091}
1092
Alexey Bataev958b9e72016-03-31 09:30:50 +00001093void ASTDumper::VisitOMPCapturedExprDecl(const OMPCapturedExprDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +00001094 NodeDumper.dumpName(D);
1095 NodeDumper.dumpType(D->getType());
Alexey Bataev958b9e72016-03-31 09:30:50 +00001096 dumpStmt(D->getInit());
1097}
Nico Webercbbaeb12016-03-02 19:28:54 +00001098
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001099//===----------------------------------------------------------------------===//
1100// C++ Declarations
1101//===----------------------------------------------------------------------===//
1102
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001103void ASTDumper::VisitNamespaceDecl(const NamespaceDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +00001104 NodeDumper.dumpName(D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001105 if (D->isInline())
1106 OS << " inline";
1107 if (!D->isOriginalNamespace())
1108 dumpDeclRef(D->getOriginalNamespace(), "original");
1109}
1110
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001111void ASTDumper::VisitUsingDirectiveDecl(const UsingDirectiveDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001112 OS << ' ';
Stephen Kellyd8744a72018-12-05 21:12:39 +00001113 NodeDumper.dumpBareDeclRef(D->getNominatedNamespace());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001114}
1115
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001116void ASTDumper::VisitNamespaceAliasDecl(const NamespaceAliasDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +00001117 NodeDumper.dumpName(D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001118 dumpDeclRef(D->getAliasedNamespace());
1119}
1120
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001121void ASTDumper::VisitTypeAliasDecl(const TypeAliasDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +00001122 NodeDumper.dumpName(D);
1123 NodeDumper.dumpType(D->getUnderlyingType());
Richard Smithba3a4f92016-01-12 21:59:26 +00001124 dumpTypeAsChild(D->getUnderlyingType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001125}
1126
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001127void ASTDumper::VisitTypeAliasTemplateDecl(const TypeAliasTemplateDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +00001128 NodeDumper.dumpName(D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001129 dumpTemplateParameters(D->getTemplateParameters());
1130 dumpDecl(D->getTemplatedDecl());
1131}
1132
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001133void ASTDumper::VisitCXXRecordDecl(const CXXRecordDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001134 VisitRecordDecl(D);
1135 if (!D->isCompleteDefinition())
1136 return;
1137
Richard Smithdfc4bff2017-09-22 00:11:15 +00001138 dumpChild([=] {
1139 {
Stephen Kelly27e948c2018-11-29 19:30:37 +00001140 ColorScope Color(OS, ShowColors, DeclKindNameColor);
Richard Smithdfc4bff2017-09-22 00:11:15 +00001141 OS << "DefinitionData";
1142 }
1143#define FLAG(fn, name) if (D->fn()) OS << " " #name;
1144 FLAG(isParsingBaseSpecifiers, parsing_base_specifiers);
1145
1146 FLAG(isGenericLambda, generic);
1147 FLAG(isLambda, lambda);
1148
1149 FLAG(canPassInRegisters, pass_in_registers);
1150 FLAG(isEmpty, empty);
1151 FLAG(isAggregate, aggregate);
1152 FLAG(isStandardLayout, standard_layout);
1153 FLAG(isTriviallyCopyable, trivially_copyable);
1154 FLAG(isPOD, pod);
1155 FLAG(isTrivial, trivial);
1156 FLAG(isPolymorphic, polymorphic);
1157 FLAG(isAbstract, abstract);
1158 FLAG(isLiteral, literal);
1159
1160 FLAG(hasUserDeclaredConstructor, has_user_declared_ctor);
1161 FLAG(hasConstexprNonCopyMoveConstructor, has_constexpr_non_copy_move_ctor);
1162 FLAG(hasMutableFields, has_mutable_fields);
1163 FLAG(hasVariantMembers, has_variant_members);
1164 FLAG(allowConstDefaultInit, can_const_default_init);
1165
1166 dumpChild([=] {
1167 {
Stephen Kelly27e948c2018-11-29 19:30:37 +00001168 ColorScope Color(OS, ShowColors, DeclKindNameColor);
Richard Smithdfc4bff2017-09-22 00:11:15 +00001169 OS << "DefaultConstructor";
1170 }
1171 FLAG(hasDefaultConstructor, exists);
1172 FLAG(hasTrivialDefaultConstructor, trivial);
1173 FLAG(hasNonTrivialDefaultConstructor, non_trivial);
1174 FLAG(hasUserProvidedDefaultConstructor, user_provided);
1175 FLAG(hasConstexprDefaultConstructor, constexpr);
1176 FLAG(needsImplicitDefaultConstructor, needs_implicit);
1177 FLAG(defaultedDefaultConstructorIsConstexpr, defaulted_is_constexpr);
1178 });
1179
1180 dumpChild([=] {
1181 {
Stephen Kelly27e948c2018-11-29 19:30:37 +00001182 ColorScope Color(OS, ShowColors, DeclKindNameColor);
Richard Smithdfc4bff2017-09-22 00:11:15 +00001183 OS << "CopyConstructor";
1184 }
1185 FLAG(hasSimpleCopyConstructor, simple);
1186 FLAG(hasTrivialCopyConstructor, trivial);
1187 FLAG(hasNonTrivialCopyConstructor, non_trivial);
1188 FLAG(hasUserDeclaredCopyConstructor, user_declared);
1189 FLAG(hasCopyConstructorWithConstParam, has_const_param);
1190 FLAG(needsImplicitCopyConstructor, needs_implicit);
1191 FLAG(needsOverloadResolutionForCopyConstructor,
1192 needs_overload_resolution);
1193 if (!D->needsOverloadResolutionForCopyConstructor())
1194 FLAG(defaultedCopyConstructorIsDeleted, defaulted_is_deleted);
1195 FLAG(implicitCopyConstructorHasConstParam, implicit_has_const_param);
1196 });
1197
1198 dumpChild([=] {
1199 {
Stephen Kelly27e948c2018-11-29 19:30:37 +00001200 ColorScope Color(OS, ShowColors, DeclKindNameColor);
Richard Smithdfc4bff2017-09-22 00:11:15 +00001201 OS << "MoveConstructor";
1202 }
1203 FLAG(hasMoveConstructor, exists);
1204 FLAG(hasSimpleMoveConstructor, simple);
1205 FLAG(hasTrivialMoveConstructor, trivial);
1206 FLAG(hasNonTrivialMoveConstructor, non_trivial);
1207 FLAG(hasUserDeclaredMoveConstructor, user_declared);
1208 FLAG(needsImplicitMoveConstructor, needs_implicit);
1209 FLAG(needsOverloadResolutionForMoveConstructor,
1210 needs_overload_resolution);
1211 if (!D->needsOverloadResolutionForMoveConstructor())
1212 FLAG(defaultedMoveConstructorIsDeleted, defaulted_is_deleted);
1213 });
1214
1215 dumpChild([=] {
1216 {
Stephen Kelly27e948c2018-11-29 19:30:37 +00001217 ColorScope Color(OS, ShowColors, DeclKindNameColor);
Richard Smithdfc4bff2017-09-22 00:11:15 +00001218 OS << "CopyAssignment";
1219 }
1220 FLAG(hasTrivialCopyAssignment, trivial);
1221 FLAG(hasNonTrivialCopyAssignment, non_trivial);
1222 FLAG(hasCopyAssignmentWithConstParam, has_const_param);
1223 FLAG(hasUserDeclaredCopyAssignment, user_declared);
1224 FLAG(needsImplicitCopyAssignment, needs_implicit);
1225 FLAG(needsOverloadResolutionForCopyAssignment, needs_overload_resolution);
1226 FLAG(implicitCopyAssignmentHasConstParam, implicit_has_const_param);
1227 });
1228
1229 dumpChild([=] {
1230 {
Stephen Kelly27e948c2018-11-29 19:30:37 +00001231 ColorScope Color(OS, ShowColors, DeclKindNameColor);
Richard Smithdfc4bff2017-09-22 00:11:15 +00001232 OS << "MoveAssignment";
1233 }
1234 FLAG(hasMoveAssignment, exists);
1235 FLAG(hasSimpleMoveAssignment, simple);
1236 FLAG(hasTrivialMoveAssignment, trivial);
1237 FLAG(hasNonTrivialMoveAssignment, non_trivial);
1238 FLAG(hasUserDeclaredMoveAssignment, user_declared);
1239 FLAG(needsImplicitMoveAssignment, needs_implicit);
1240 FLAG(needsOverloadResolutionForMoveAssignment, needs_overload_resolution);
1241 });
1242
1243 dumpChild([=] {
1244 {
Stephen Kelly27e948c2018-11-29 19:30:37 +00001245 ColorScope Color(OS, ShowColors, DeclKindNameColor);
Richard Smithdfc4bff2017-09-22 00:11:15 +00001246 OS << "Destructor";
1247 }
1248 FLAG(hasSimpleDestructor, simple);
1249 FLAG(hasIrrelevantDestructor, irrelevant);
1250 FLAG(hasTrivialDestructor, trivial);
1251 FLAG(hasNonTrivialDestructor, non_trivial);
1252 FLAG(hasUserDeclaredDestructor, user_declared);
1253 FLAG(needsImplicitDestructor, needs_implicit);
1254 FLAG(needsOverloadResolutionForDestructor, needs_overload_resolution);
1255 if (!D->needsOverloadResolutionForDestructor())
1256 FLAG(defaultedDestructorIsDeleted, defaulted_is_deleted);
1257 });
1258 });
1259
Aaron Ballman574705e2014-03-13 15:41:46 +00001260 for (const auto &I : D->bases()) {
Richard Smithf7514452014-10-30 21:02:37 +00001261 dumpChild([=] {
1262 if (I.isVirtual())
1263 OS << "virtual ";
Stephen Kellyd8744a72018-12-05 21:12:39 +00001264 NodeDumper.dumpAccessSpecifier(I.getAccessSpecifier());
1265 NodeDumper.dumpType(I.getType());
Richard Smithf7514452014-10-30 21:02:37 +00001266 if (I.isPackExpansion())
1267 OS << "...";
1268 });
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001269 }
1270}
1271
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001272void ASTDumper::VisitStaticAssertDecl(const StaticAssertDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001273 dumpStmt(D->getAssertExpr());
1274 dumpStmt(D->getMessage());
1275}
1276
Stephen Kelly24136382018-12-09 13:33:30 +00001277template <typename SpecializationDecl>
1278void ASTDumper::dumpTemplateDeclSpecialization(const SpecializationDecl *D,
1279 bool DumpExplicitInst,
1280 bool DumpRefOnly) {
Richard Smithcbdf7332014-03-18 02:07:28 +00001281 bool DumpedAny = false;
1282 for (auto *RedeclWithBadType : D->redecls()) {
1283 // FIXME: The redecls() range sometimes has elements of a less-specific
1284 // type. (In particular, ClassTemplateSpecializationDecl::redecls() gives
1285 // us TagDecls, and should give CXXRecordDecls).
1286 auto *Redecl = dyn_cast<SpecializationDecl>(RedeclWithBadType);
1287 if (!Redecl) {
1288 // Found the injected-class-name for a class template. This will be dumped
1289 // as part of its surrounding class so we don't need to dump it here.
1290 assert(isa<CXXRecordDecl>(RedeclWithBadType) &&
1291 "expected an injected-class-name");
1292 continue;
1293 }
1294
1295 switch (Redecl->getTemplateSpecializationKind()) {
1296 case TSK_ExplicitInstantiationDeclaration:
1297 case TSK_ExplicitInstantiationDefinition:
1298 if (!DumpExplicitInst)
1299 break;
Adrian Prantlf3b3ccd2017-12-19 22:06:11 +00001300 LLVM_FALLTHROUGH;
Richard Smithcbdf7332014-03-18 02:07:28 +00001301 case TSK_Undeclared:
1302 case TSK_ImplicitInstantiation:
Richard Smithf7514452014-10-30 21:02:37 +00001303 if (DumpRefOnly)
1304 dumpDeclRef(Redecl);
1305 else
1306 dumpDecl(Redecl);
Richard Smithcbdf7332014-03-18 02:07:28 +00001307 DumpedAny = true;
1308 break;
1309 case TSK_ExplicitSpecialization:
1310 break;
1311 }
1312 }
1313
1314 // Ensure we dump at least one decl for each specialization.
1315 if (!DumpedAny)
Richard Smithf7514452014-10-30 21:02:37 +00001316 dumpDeclRef(D);
Richard Smithcbdf7332014-03-18 02:07:28 +00001317}
1318
Stephen Kelly24136382018-12-09 13:33:30 +00001319template <typename TemplateDecl>
1320void ASTDumper::dumpTemplateDecl(const TemplateDecl *D, bool DumpExplicitInst) {
Stephen Kellyd8744a72018-12-05 21:12:39 +00001321 NodeDumper.dumpName(D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001322 dumpTemplateParameters(D->getTemplateParameters());
Richard Smithdcc2c452014-03-17 23:00:06 +00001323
Richard Smithf7514452014-10-30 21:02:37 +00001324 dumpDecl(D->getTemplatedDecl());
Richard Smithdcc2c452014-03-17 23:00:06 +00001325
Richard Smithcbdf7332014-03-18 02:07:28 +00001326 for (auto *Child : D->specializations())
Stephen Kelly24136382018-12-09 13:33:30 +00001327 dumpTemplateDeclSpecialization(Child, DumpExplicitInst,
1328 !D->isCanonicalDecl());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001329}
1330
Richard Smith20ade552014-03-17 23:34:53 +00001331void ASTDumper::VisitFunctionTemplateDecl(const FunctionTemplateDecl *D) {
1332 // FIXME: We don't add a declaration of a function template specialization
1333 // to its context when it's explicitly instantiated, so dump explicit
1334 // instantiations when we dump the template itself.
Stephen Kelly24136382018-12-09 13:33:30 +00001335 dumpTemplateDecl(D, true);
Richard Smith20ade552014-03-17 23:34:53 +00001336}
1337
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001338void ASTDumper::VisitClassTemplateDecl(const ClassTemplateDecl *D) {
Stephen Kelly24136382018-12-09 13:33:30 +00001339 dumpTemplateDecl(D, false);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001340}
1341
1342void ASTDumper::VisitClassTemplateSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001343 const ClassTemplateSpecializationDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001344 VisitCXXRecordDecl(D);
1345 dumpTemplateArgumentList(D->getTemplateArgs());
1346}
1347
1348void ASTDumper::VisitClassTemplatePartialSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001349 const ClassTemplatePartialSpecializationDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001350 VisitClassTemplateSpecializationDecl(D);
1351 dumpTemplateParameters(D->getTemplateParameters());
1352}
1353
1354void ASTDumper::VisitClassScopeFunctionSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001355 const ClassScopeFunctionSpecializationDecl *D) {
Richard Smithc660c8f2018-03-16 13:36:56 +00001356 dumpDecl(D->getSpecialization());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001357 if (D->hasExplicitTemplateArgs())
1358 dumpTemplateArgumentListInfo(D->templateArgs());
1359}
1360
Richard Smithd25789a2013-09-18 01:36:02 +00001361void ASTDumper::VisitVarTemplateDecl(const VarTemplateDecl *D) {
Stephen Kelly24136382018-12-09 13:33:30 +00001362 dumpTemplateDecl(D, false);
Richard Smithd25789a2013-09-18 01:36:02 +00001363}
1364
David Majnemerd9b1a4f2015-11-04 03:40:30 +00001365void ASTDumper::VisitBuiltinTemplateDecl(const BuiltinTemplateDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +00001366 NodeDumper.dumpName(D);
David Majnemerd9b1a4f2015-11-04 03:40:30 +00001367 dumpTemplateParameters(D->getTemplateParameters());
1368}
1369
Richard Smithd25789a2013-09-18 01:36:02 +00001370void ASTDumper::VisitVarTemplateSpecializationDecl(
1371 const VarTemplateSpecializationDecl *D) {
1372 dumpTemplateArgumentList(D->getTemplateArgs());
1373 VisitVarDecl(D);
1374}
1375
1376void ASTDumper::VisitVarTemplatePartialSpecializationDecl(
1377 const VarTemplatePartialSpecializationDecl *D) {
1378 dumpTemplateParameters(D->getTemplateParameters());
1379 VisitVarTemplateSpecializationDecl(D);
1380}
1381
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001382void ASTDumper::VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001383 if (D->wasDeclaredWithTypename())
1384 OS << " typename";
1385 else
1386 OS << " class";
Richard Smith1832a022017-02-21 02:04:03 +00001387 OS << " depth " << D->getDepth() << " index " << D->getIndex();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001388 if (D->isParameterPack())
1389 OS << " ...";
Stephen Kellyd8744a72018-12-05 21:12:39 +00001390 NodeDumper.dumpName(D);
Richard Smithf7514452014-10-30 21:02:37 +00001391 if (D->hasDefaultArgument())
Stephen Kelly43835952018-12-10 21:03:00 +00001392 dumpTemplateArgument(D->getDefaultArgument(), SourceRange(),
1393 D->getDefaultArgStorage().getInheritedFrom(),
1394 D->defaultArgumentWasInherited() ? "inherited from"
1395 : "previous");
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001396}
1397
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001398void ASTDumper::VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +00001399 NodeDumper.dumpType(D->getType());
Richard Smith1832a022017-02-21 02:04:03 +00001400 OS << " depth " << D->getDepth() << " index " << D->getIndex();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001401 if (D->isParameterPack())
1402 OS << " ...";
Stephen Kellyd8744a72018-12-05 21:12:39 +00001403 NodeDumper.dumpName(D);
Richard Smithf7514452014-10-30 21:02:37 +00001404 if (D->hasDefaultArgument())
Stephen Kelly43835952018-12-10 21:03:00 +00001405 dumpTemplateArgument(D->getDefaultArgument(), SourceRange(),
1406 D->getDefaultArgStorage().getInheritedFrom(),
1407 D->defaultArgumentWasInherited() ? "inherited from"
1408 : "previous");
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001409}
1410
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001411void ASTDumper::VisitTemplateTemplateParmDecl(
1412 const TemplateTemplateParmDecl *D) {
Richard Smith1832a022017-02-21 02:04:03 +00001413 OS << " depth " << D->getDepth() << " index " << D->getIndex();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001414 if (D->isParameterPack())
1415 OS << " ...";
Stephen Kellyd8744a72018-12-05 21:12:39 +00001416 NodeDumper.dumpName(D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001417 dumpTemplateParameters(D->getTemplateParameters());
Richard Smithf7514452014-10-30 21:02:37 +00001418 if (D->hasDefaultArgument())
Stephen Kelly43835952018-12-10 21:03:00 +00001419 dumpTemplateArgumentLoc(
1420 D->getDefaultArgument(), D->getDefaultArgStorage().getInheritedFrom(),
1421 D->defaultArgumentWasInherited() ? "inherited from" : "previous");
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001422}
1423
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001424void ASTDumper::VisitUsingDecl(const UsingDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001425 OS << ' ';
Dawn Perchikddd03bf2015-12-05 22:37:55 +00001426 if (D->getQualifier())
1427 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001428 OS << D->getNameAsString();
1429}
1430
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001431void ASTDumper::VisitUnresolvedUsingTypenameDecl(
1432 const UnresolvedUsingTypenameDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001433 OS << ' ';
Dawn Perchikddd03bf2015-12-05 22:37:55 +00001434 if (D->getQualifier())
1435 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001436 OS << D->getNameAsString();
1437}
1438
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001439void ASTDumper::VisitUnresolvedUsingValueDecl(const UnresolvedUsingValueDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001440 OS << ' ';
Dawn Perchikddd03bf2015-12-05 22:37:55 +00001441 if (D->getQualifier())
1442 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001443 OS << D->getNameAsString();
Stephen Kellyd8744a72018-12-05 21:12:39 +00001444 NodeDumper.dumpType(D->getType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001445}
1446
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001447void ASTDumper::VisitUsingShadowDecl(const UsingShadowDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001448 OS << ' ';
Stephen Kellyd8744a72018-12-05 21:12:39 +00001449 NodeDumper.dumpBareDeclRef(D->getTargetDecl());
Richard Smithba3a4f92016-01-12 21:59:26 +00001450 if (auto *TD = dyn_cast<TypeDecl>(D->getUnderlyingDecl()))
1451 dumpTypeAsChild(TD->getTypeForDecl());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001452}
1453
Richard Smith5179eb72016-06-28 19:03:57 +00001454void ASTDumper::VisitConstructorUsingShadowDecl(
1455 const ConstructorUsingShadowDecl *D) {
1456 if (D->constructsVirtualBase())
1457 OS << " virtual";
1458
1459 dumpChild([=] {
1460 OS << "target ";
Stephen Kellyd8744a72018-12-05 21:12:39 +00001461 NodeDumper.dumpBareDeclRef(D->getTargetDecl());
Richard Smith5179eb72016-06-28 19:03:57 +00001462 });
1463
1464 dumpChild([=] {
1465 OS << "nominated ";
Stephen Kellyd8744a72018-12-05 21:12:39 +00001466 NodeDumper.dumpBareDeclRef(D->getNominatedBaseClass());
Richard Smith5179eb72016-06-28 19:03:57 +00001467 OS << ' ';
Stephen Kellyd8744a72018-12-05 21:12:39 +00001468 NodeDumper.dumpBareDeclRef(D->getNominatedBaseClassShadowDecl());
Richard Smith5179eb72016-06-28 19:03:57 +00001469 });
1470
1471 dumpChild([=] {
1472 OS << "constructed ";
Stephen Kellyd8744a72018-12-05 21:12:39 +00001473 NodeDumper.dumpBareDeclRef(D->getConstructedBaseClass());
Richard Smith5179eb72016-06-28 19:03:57 +00001474 OS << ' ';
Stephen Kellyd8744a72018-12-05 21:12:39 +00001475 NodeDumper.dumpBareDeclRef(D->getConstructedBaseClassShadowDecl());
Richard Smith5179eb72016-06-28 19:03:57 +00001476 });
1477}
1478
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001479void ASTDumper::VisitLinkageSpecDecl(const LinkageSpecDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001480 switch (D->getLanguage()) {
1481 case LinkageSpecDecl::lang_c: OS << " C"; break;
1482 case LinkageSpecDecl::lang_cxx: OS << " C++"; break;
1483 }
1484}
1485
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001486void ASTDumper::VisitAccessSpecDecl(const AccessSpecDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001487 OS << ' ';
Stephen Kellyd8744a72018-12-05 21:12:39 +00001488 NodeDumper.dumpAccessSpecifier(D->getAccess());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001489}
1490
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001491void ASTDumper::VisitFriendDecl(const FriendDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001492 if (TypeSourceInfo *T = D->getFriendType())
Stephen Kellyd8744a72018-12-05 21:12:39 +00001493 NodeDumper.dumpType(T->getType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001494 else
1495 dumpDecl(D->getFriendDecl());
1496}
1497
1498//===----------------------------------------------------------------------===//
1499// Obj-C Declarations
1500//===----------------------------------------------------------------------===//
1501
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001502void ASTDumper::VisitObjCIvarDecl(const ObjCIvarDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +00001503 NodeDumper.dumpName(D);
1504 NodeDumper.dumpType(D->getType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001505 if (D->getSynthesize())
1506 OS << " synthesize";
1507
1508 switch (D->getAccessControl()) {
1509 case ObjCIvarDecl::None:
1510 OS << " none";
1511 break;
1512 case ObjCIvarDecl::Private:
1513 OS << " private";
1514 break;
1515 case ObjCIvarDecl::Protected:
1516 OS << " protected";
1517 break;
1518 case ObjCIvarDecl::Public:
1519 OS << " public";
1520 break;
1521 case ObjCIvarDecl::Package:
1522 OS << " package";
1523 break;
1524 }
1525}
1526
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001527void ASTDumper::VisitObjCMethodDecl(const ObjCMethodDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001528 if (D->isInstanceMethod())
1529 OS << " -";
1530 else
1531 OS << " +";
Stephen Kellyd8744a72018-12-05 21:12:39 +00001532 NodeDumper.dumpName(D);
1533 NodeDumper.dumpType(D->getReturnType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001534
Richard Trieude5cc7d2013-01-31 01:44:26 +00001535 if (D->isThisDeclarationADefinition()) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001536 dumpDeclContext(D);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001537 } else {
David Majnemera3debed2016-06-24 05:33:44 +00001538 for (const ParmVarDecl *Parameter : D->parameters())
1539 dumpDecl(Parameter);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001540 }
1541
Richard Smithf7514452014-10-30 21:02:37 +00001542 if (D->isVariadic())
1543 dumpChild([=] { OS << "..."; });
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001544
Richard Smithf7514452014-10-30 21:02:37 +00001545 if (D->hasBody())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001546 dumpStmt(D->getBody());
1547}
1548
Douglas Gregor85f3f952015-07-07 03:57:15 +00001549void ASTDumper::VisitObjCTypeParamDecl(const ObjCTypeParamDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +00001550 NodeDumper.dumpName(D);
Douglas Gregor1ac1b632015-07-07 03:58:54 +00001551 switch (D->getVariance()) {
1552 case ObjCTypeParamVariance::Invariant:
1553 break;
1554
1555 case ObjCTypeParamVariance::Covariant:
1556 OS << " covariant";
1557 break;
1558
1559 case ObjCTypeParamVariance::Contravariant:
1560 OS << " contravariant";
1561 break;
1562 }
1563
Douglas Gregor85f3f952015-07-07 03:57:15 +00001564 if (D->hasExplicitBound())
1565 OS << " bounded";
Stephen Kellyd8744a72018-12-05 21:12:39 +00001566 NodeDumper.dumpType(D->getUnderlyingType());
Douglas Gregor85f3f952015-07-07 03:57:15 +00001567}
1568
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001569void ASTDumper::VisitObjCCategoryDecl(const ObjCCategoryDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +00001570 NodeDumper.dumpName(D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001571 dumpDeclRef(D->getClassInterface());
Douglas Gregor85f3f952015-07-07 03:57:15 +00001572 dumpObjCTypeParamList(D->getTypeParamList());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001573 dumpDeclRef(D->getImplementation());
1574 for (ObjCCategoryDecl::protocol_iterator I = D->protocol_begin(),
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001575 E = D->protocol_end();
Richard Smithf7514452014-10-30 21:02:37 +00001576 I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001577 dumpDeclRef(*I);
1578}
1579
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001580void ASTDumper::VisitObjCCategoryImplDecl(const ObjCCategoryImplDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +00001581 NodeDumper.dumpName(D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001582 dumpDeclRef(D->getClassInterface());
1583 dumpDeclRef(D->getCategoryDecl());
1584}
1585
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001586void ASTDumper::VisitObjCProtocolDecl(const ObjCProtocolDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +00001587 NodeDumper.dumpName(D);
Richard Smithdcc2c452014-03-17 23:00:06 +00001588
Richard Smith7fcb35f2014-03-18 02:37:59 +00001589 for (auto *Child : D->protocols())
Richard Smithf7514452014-10-30 21:02:37 +00001590 dumpDeclRef(Child);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001591}
1592
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001593void ASTDumper::VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +00001594 NodeDumper.dumpName(D);
Douglas Gregor85f3f952015-07-07 03:57:15 +00001595 dumpObjCTypeParamList(D->getTypeParamListAsWritten());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001596 dumpDeclRef(D->getSuperClass(), "super");
Richard Smithdcc2c452014-03-17 23:00:06 +00001597
Richard Smithf7514452014-10-30 21:02:37 +00001598 dumpDeclRef(D->getImplementation());
Richard Smith7fcb35f2014-03-18 02:37:59 +00001599 for (auto *Child : D->protocols())
Richard Smithf7514452014-10-30 21:02:37 +00001600 dumpDeclRef(Child);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001601}
1602
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001603void ASTDumper::VisitObjCImplementationDecl(const ObjCImplementationDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +00001604 NodeDumper.dumpName(D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001605 dumpDeclRef(D->getSuperClass(), "super");
1606 dumpDeclRef(D->getClassInterface());
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001607 for (ObjCImplementationDecl::init_const_iterator I = D->init_begin(),
1608 E = D->init_end();
Richard Smithf7514452014-10-30 21:02:37 +00001609 I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001610 dumpCXXCtorInitializer(*I);
1611}
1612
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001613void ASTDumper::VisitObjCCompatibleAliasDecl(const ObjCCompatibleAliasDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +00001614 NodeDumper.dumpName(D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001615 dumpDeclRef(D->getClassInterface());
1616}
1617
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001618void ASTDumper::VisitObjCPropertyDecl(const ObjCPropertyDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +00001619 NodeDumper.dumpName(D);
1620 NodeDumper.dumpType(D->getType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001621
1622 if (D->getPropertyImplementation() == ObjCPropertyDecl::Required)
1623 OS << " required";
1624 else if (D->getPropertyImplementation() == ObjCPropertyDecl::Optional)
1625 OS << " optional";
1626
1627 ObjCPropertyDecl::PropertyAttributeKind Attrs = D->getPropertyAttributes();
1628 if (Attrs != ObjCPropertyDecl::OBJC_PR_noattr) {
1629 if (Attrs & ObjCPropertyDecl::OBJC_PR_readonly)
1630 OS << " readonly";
1631 if (Attrs & ObjCPropertyDecl::OBJC_PR_assign)
1632 OS << " assign";
1633 if (Attrs & ObjCPropertyDecl::OBJC_PR_readwrite)
1634 OS << " readwrite";
1635 if (Attrs & ObjCPropertyDecl::OBJC_PR_retain)
1636 OS << " retain";
1637 if (Attrs & ObjCPropertyDecl::OBJC_PR_copy)
1638 OS << " copy";
1639 if (Attrs & ObjCPropertyDecl::OBJC_PR_nonatomic)
1640 OS << " nonatomic";
1641 if (Attrs & ObjCPropertyDecl::OBJC_PR_atomic)
1642 OS << " atomic";
1643 if (Attrs & ObjCPropertyDecl::OBJC_PR_weak)
1644 OS << " weak";
1645 if (Attrs & ObjCPropertyDecl::OBJC_PR_strong)
1646 OS << " strong";
1647 if (Attrs & ObjCPropertyDecl::OBJC_PR_unsafe_unretained)
1648 OS << " unsafe_unretained";
Manman Ren387ff7f2016-01-26 18:52:43 +00001649 if (Attrs & ObjCPropertyDecl::OBJC_PR_class)
1650 OS << " class";
Richard Smithf7514452014-10-30 21:02:37 +00001651 if (Attrs & ObjCPropertyDecl::OBJC_PR_getter)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001652 dumpDeclRef(D->getGetterMethodDecl(), "getter");
Richard Smithf7514452014-10-30 21:02:37 +00001653 if (Attrs & ObjCPropertyDecl::OBJC_PR_setter)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001654 dumpDeclRef(D->getSetterMethodDecl(), "setter");
1655 }
1656}
1657
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001658void ASTDumper::VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +00001659 NodeDumper.dumpName(D->getPropertyDecl());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001660 if (D->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize)
1661 OS << " synthesize";
1662 else
1663 OS << " dynamic";
1664 dumpDeclRef(D->getPropertyDecl());
1665 dumpDeclRef(D->getPropertyIvarDecl());
1666}
1667
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001668void ASTDumper::VisitBlockDecl(const BlockDecl *D) {
David Majnemer59f77922016-06-24 04:05:48 +00001669 for (auto I : D->parameters())
Aaron Ballmanb2b8b1d2014-03-07 16:09:59 +00001670 dumpDecl(I);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001671
Richard Smithf7514452014-10-30 21:02:37 +00001672 if (D->isVariadic())
1673 dumpChild([=]{ OS << "..."; });
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001674
Richard Smithf7514452014-10-30 21:02:37 +00001675 if (D->capturesCXXThis())
1676 dumpChild([=]{ OS << "capture this"; });
1677
Aaron Ballman9371dd22014-03-14 18:34:04 +00001678 for (const auto &I : D->captures()) {
Richard Smithf7514452014-10-30 21:02:37 +00001679 dumpChild([=] {
1680 OS << "capture";
1681 if (I.isByRef())
1682 OS << " byref";
1683 if (I.isNested())
1684 OS << " nested";
1685 if (I.getVariable()) {
1686 OS << ' ';
Stephen Kellyd8744a72018-12-05 21:12:39 +00001687 NodeDumper.dumpBareDeclRef(I.getVariable());
Richard Smithf7514452014-10-30 21:02:37 +00001688 }
1689 if (I.hasCopyExpr())
1690 dumpStmt(I.getCopyExpr());
1691 });
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001692 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001693 dumpStmt(D->getBody());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001694}
1695
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001696//===----------------------------------------------------------------------===//
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001697// Stmt dumping methods.
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001698//===----------------------------------------------------------------------===//
1699
Stephen Kelly50a29bd2018-12-09 13:24:40 +00001700void ASTDumper::dumpStmt(const Stmt *S) {
Richard Smithf7514452014-10-30 21:02:37 +00001701 dumpChild([=] {
1702 if (!S) {
Stephen Kelly27e948c2018-11-29 19:30:37 +00001703 ColorScope Color(OS, ShowColors, NullColor);
Richard Smithf7514452014-10-30 21:02:37 +00001704 OS << "<<<NULL>>>";
1705 return;
1706 }
Stephen Kellyb9d6a5e2018-12-06 23:33:27 +00001707 {
1708 ColorScope Color(OS, ShowColors, StmtColor);
1709 OS << S->getStmtClassName();
1710 }
1711 NodeDumper.dumpPointer(S);
1712 NodeDumper.dumpSourceRange(S->getSourceRange());
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001713
Stephen Kelly50e82872018-12-06 23:33:33 +00001714 if (const auto *E = dyn_cast<Expr>(S)) {
1715 NodeDumper.dumpType(E->getType());
1716
1717 {
1718 ColorScope Color(OS, ShowColors, ValueKindColor);
1719 switch (E->getValueKind()) {
1720 case VK_RValue:
1721 break;
1722 case VK_LValue:
1723 OS << " lvalue";
1724 break;
1725 case VK_XValue:
1726 OS << " xvalue";
1727 break;
1728 }
1729 }
1730
1731 {
1732 ColorScope Color(OS, ShowColors, ObjectKindColor);
1733 switch (E->getObjectKind()) {
1734 case OK_Ordinary:
1735 break;
1736 case OK_BitField:
1737 OS << " bitfield";
1738 break;
1739 case OK_ObjCProperty:
1740 OS << " objcproperty";
1741 break;
1742 case OK_ObjCSubscript:
1743 OS << " objcsubscript";
1744 break;
1745 case OK_VectorComponent:
1746 OS << " vectorcomponent";
1747 break;
1748 }
1749 }
1750 }
1751
Richard Smithf7514452014-10-30 21:02:37 +00001752 ConstStmtVisitor<ASTDumper>::Visit(S);
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001753
Stephen Kelly91f9c9c2018-12-03 21:05:52 +00001754 // Some statements have custom mechanisms for dumping their children.
1755 if (isa<DeclStmt>(S) || isa<GenericSelectionExpr>(S)) {
1756 return;
1757 }
1758
Benjamin Kramer642f1732015-07-02 21:03:14 +00001759 for (const Stmt *SubStmt : S->children())
1760 dumpStmt(SubStmt);
Richard Smithf7514452014-10-30 21:02:37 +00001761 });
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001762}
1763
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001764void ASTDumper::VisitDeclStmt(const DeclStmt *Node) {
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001765 for (DeclStmt::const_decl_iterator I = Node->decl_begin(),
1766 E = Node->decl_end();
Richard Smithf7514452014-10-30 21:02:37 +00001767 I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001768 dumpDecl(*I);
Ted Kremenek433a4922007-12-12 06:59:42 +00001769}
1770
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001771void ASTDumper::VisitAttributedStmt(const AttributedStmt *Node) {
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001772 for (ArrayRef<const Attr *>::iterator I = Node->getAttrs().begin(),
1773 E = Node->getAttrs().end();
Richard Smithf7514452014-10-30 21:02:37 +00001774 I != E; ++I)
Alexander Kornienko5bc364e2013-01-07 17:53:08 +00001775 dumpAttr(*I);
1776}
1777
Bruno Riccib1cc94b2018-10-27 21:12:20 +00001778void ASTDumper::VisitIfStmt(const IfStmt *Node) {
Bruno Riccib1cc94b2018-10-27 21:12:20 +00001779 if (Node->hasInitStorage())
1780 OS << " has_init";
1781 if (Node->hasVarStorage())
1782 OS << " has_var";
1783 if (Node->hasElseStorage())
1784 OS << " has_else";
1785}
1786
Bruno Riccie2806f82018-10-29 16:12:37 +00001787void ASTDumper::VisitSwitchStmt(const SwitchStmt *Node) {
Bruno Riccie2806f82018-10-29 16:12:37 +00001788 if (Node->hasInitStorage())
1789 OS << " has_init";
1790 if (Node->hasVarStorage())
1791 OS << " has_var";
1792}
1793
Bruno Riccibacf7512018-10-30 13:42:41 +00001794void ASTDumper::VisitWhileStmt(const WhileStmt *Node) {
Bruno Riccibacf7512018-10-30 13:42:41 +00001795 if (Node->hasVarStorage())
1796 OS << " has_var";
1797}
1798
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001799void ASTDumper::VisitLabelStmt(const LabelStmt *Node) {
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001800 OS << " '" << Node->getName() << "'";
Chris Lattnercbe4f772007-08-08 22:51:59 +00001801}
1802
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001803void ASTDumper::VisitGotoStmt(const GotoStmt *Node) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001804 OS << " '" << Node->getLabel()->getName() << "'";
Stephen Kellyd8744a72018-12-05 21:12:39 +00001805 NodeDumper.dumpPointer(Node->getLabel());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001806}
1807
Pavel Labath1ef83422013-09-04 14:35:00 +00001808void ASTDumper::VisitCXXCatchStmt(const CXXCatchStmt *Node) {
Pavel Labath1ef83422013-09-04 14:35:00 +00001809 dumpDecl(Node->getExceptionDecl());
1810}
1811
Bruno Ricci5b30571752018-10-28 12:30:53 +00001812void ASTDumper::VisitCaseStmt(const CaseStmt *Node) {
Bruno Ricci5b30571752018-10-28 12:30:53 +00001813 if (Node->caseStmtIsGNURange())
1814 OS << " gnu_range";
1815}
1816
Alexey Bataev958b9e72016-03-31 09:30:50 +00001817void ASTDumper::VisitCapturedStmt(const CapturedStmt *Node) {
Alexey Bataev958b9e72016-03-31 09:30:50 +00001818 dumpDecl(Node->getCapturedDecl());
1819}
1820
1821//===----------------------------------------------------------------------===//
1822// OpenMP dumping methods.
1823//===----------------------------------------------------------------------===//
1824
1825void ASTDumper::VisitOMPExecutableDirective(
1826 const OMPExecutableDirective *Node) {
Alexey Bataev958b9e72016-03-31 09:30:50 +00001827 for (auto *C : Node->clauses()) {
1828 dumpChild([=] {
1829 if (!C) {
Stephen Kelly27e948c2018-11-29 19:30:37 +00001830 ColorScope Color(OS, ShowColors, NullColor);
Alexey Bataev958b9e72016-03-31 09:30:50 +00001831 OS << "<<<NULL>>> OMPClause";
1832 return;
1833 }
1834 {
Stephen Kelly27e948c2018-11-29 19:30:37 +00001835 ColorScope Color(OS, ShowColors, AttrColor);
Alexey Bataev958b9e72016-03-31 09:30:50 +00001836 StringRef ClauseName(getOpenMPClauseName(C->getClauseKind()));
1837 OS << "OMP" << ClauseName.substr(/*Start=*/0, /*N=*/1).upper()
1838 << ClauseName.drop_front() << "Clause";
1839 }
Stephen Kellyd8744a72018-12-05 21:12:39 +00001840 NodeDumper.dumpPointer(C);
1841 NodeDumper.dumpSourceRange(SourceRange(C->getBeginLoc(), C->getEndLoc()));
Alexey Bataev958b9e72016-03-31 09:30:50 +00001842 if (C->isImplicit())
1843 OS << " <implicit>";
1844 for (auto *S : C->children())
1845 dumpStmt(S);
1846 });
1847 }
1848}
1849
Chris Lattnercbe4f772007-08-08 22:51:59 +00001850//===----------------------------------------------------------------------===//
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001851// Expr dumping methods.
Chris Lattnercbe4f772007-08-08 22:51:59 +00001852//===----------------------------------------------------------------------===//
1853
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001854static void dumpBasePath(raw_ostream &OS, const CastExpr *Node) {
John McCallcf142162010-08-07 06:22:56 +00001855 if (Node->path_empty())
Anders Carlssona70cff62010-04-24 19:06:50 +00001856 return;
1857
1858 OS << " (";
1859 bool First = true;
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001860 for (CastExpr::path_const_iterator I = Node->path_begin(),
1861 E = Node->path_end();
1862 I != E; ++I) {
Anders Carlssona70cff62010-04-24 19:06:50 +00001863 const CXXBaseSpecifier *Base = *I;
1864 if (!First)
1865 OS << " -> ";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001866
Anders Carlssona70cff62010-04-24 19:06:50 +00001867 const CXXRecordDecl *RD =
1868 cast<CXXRecordDecl>(Base->getType()->getAs<RecordType>()->getDecl());
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001869
Anders Carlssona70cff62010-04-24 19:06:50 +00001870 if (Base->isVirtual())
1871 OS << "virtual ";
1872 OS << RD->getName();
1873 First = false;
1874 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001875
Anders Carlssona70cff62010-04-24 19:06:50 +00001876 OS << ')';
1877}
1878
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001879void ASTDumper::VisitCastExpr(const CastExpr *Node) {
Richard Trieud215b8d2013-01-26 01:31:20 +00001880 OS << " <";
1881 {
Stephen Kelly27e948c2018-11-29 19:30:37 +00001882 ColorScope Color(OS, ShowColors, CastColor);
Richard Trieud215b8d2013-01-26 01:31:20 +00001883 OS << Node->getCastKindName();
1884 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001885 dumpBasePath(OS, Node);
Anders Carlssona70cff62010-04-24 19:06:50 +00001886 OS << ">";
Roman Lebedev12216f12018-07-27 07:27:14 +00001887}
Roman Lebedevd55661d2018-07-24 08:16:50 +00001888
Roman Lebedev12216f12018-07-27 07:27:14 +00001889void ASTDumper::VisitImplicitCastExpr(const ImplicitCastExpr *Node) {
1890 VisitCastExpr(Node);
1891 if (Node->isPartOfExplicitCast())
Roman Lebedevd55661d2018-07-24 08:16:50 +00001892 OS << " part_of_explicit_cast";
Anders Carlssond7923c62009-08-22 23:33:40 +00001893}
1894
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001895void ASTDumper::VisitDeclRefExpr(const DeclRefExpr *Node) {
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001896 OS << " ";
Stephen Kellyd8744a72018-12-05 21:12:39 +00001897 NodeDumper.dumpBareDeclRef(Node->getDecl());
Chandler Carruth8d26bb02011-05-01 23:48:14 +00001898 if (Node->getDecl() != Node->getFoundDecl()) {
1899 OS << " (";
Stephen Kellyd8744a72018-12-05 21:12:39 +00001900 NodeDumper.dumpBareDeclRef(Node->getFoundDecl());
Chandler Carruth8d26bb02011-05-01 23:48:14 +00001901 OS << ")";
1902 }
John McCall351762c2011-02-07 10:33:21 +00001903}
1904
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001905void ASTDumper::VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *Node) {
John McCall76d09942009-12-11 21:50:11 +00001906 OS << " (";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001907 if (!Node->requiresADL())
1908 OS << "no ";
Benjamin Kramerb11416d2010-04-17 09:33:03 +00001909 OS << "ADL) = '" << Node->getName() << '\'';
John McCall76d09942009-12-11 21:50:11 +00001910
1911 UnresolvedLookupExpr::decls_iterator
1912 I = Node->decls_begin(), E = Node->decls_end();
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001913 if (I == E)
1914 OS << " empty";
John McCall76d09942009-12-11 21:50:11 +00001915 for (; I != E; ++I)
Stephen Kellyd8744a72018-12-05 21:12:39 +00001916 NodeDumper.dumpPointer(*I);
John McCall76d09942009-12-11 21:50:11 +00001917}
1918
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001919void ASTDumper::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *Node) {
Richard Trieud215b8d2013-01-26 01:31:20 +00001920 {
Stephen Kelly27e948c2018-11-29 19:30:37 +00001921 ColorScope Color(OS, ShowColors, DeclKindNameColor);
Richard Trieud215b8d2013-01-26 01:31:20 +00001922 OS << " " << Node->getDecl()->getDeclKindName() << "Decl";
1923 }
1924 OS << "='" << *Node->getDecl() << "'";
Stephen Kellyd8744a72018-12-05 21:12:39 +00001925 NodeDumper.dumpPointer(Node->getDecl());
Steve Naroffb3424a92008-05-23 22:01:24 +00001926 if (Node->isFreeIvar())
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001927 OS << " isFreeIvar";
Steve Naroff5d5efca2008-03-12 13:19:12 +00001928}
1929
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001930void ASTDumper::VisitPredefinedExpr(const PredefinedExpr *Node) {
Bruno Ricci17ff0262018-10-27 19:21:19 +00001931 OS << " " << PredefinedExpr::getIdentKindName(Node->getIdentKind());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001932}
1933
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001934void ASTDumper::VisitCharacterLiteral(const CharacterLiteral *Node) {
Stephen Kelly27e948c2018-11-29 19:30:37 +00001935 ColorScope Color(OS, ShowColors, ValueColor);
Richard Trieu364ee422011-11-03 23:56:23 +00001936 OS << " " << Node->getValue();
Chris Lattnercbe4f772007-08-08 22:51:59 +00001937}
1938
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001939void ASTDumper::VisitIntegerLiteral(const IntegerLiteral *Node) {
Chris Lattnercbe4f772007-08-08 22:51:59 +00001940 bool isSigned = Node->getType()->isSignedIntegerType();
Stephen Kelly27e948c2018-11-29 19:30:37 +00001941 ColorScope Color(OS, ShowColors, ValueColor);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001942 OS << " " << Node->getValue().toString(10, isSigned);
Chris Lattnercbe4f772007-08-08 22:51:59 +00001943}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001944
Leonard Chandb01c3a2018-06-20 17:19:40 +00001945void ASTDumper::VisitFixedPointLiteral(const FixedPointLiteral *Node) {
Stephen Kelly27e948c2018-11-29 19:30:37 +00001946 ColorScope Color(OS, ShowColors, ValueColor);
Leonard Chandb01c3a2018-06-20 17:19:40 +00001947 OS << " " << Node->getValueAsString(/*Radix=*/10);
1948}
1949
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001950void ASTDumper::VisitFloatingLiteral(const FloatingLiteral *Node) {
Stephen Kelly27e948c2018-11-29 19:30:37 +00001951 ColorScope Color(OS, ShowColors, ValueColor);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001952 OS << " " << Node->getValueAsApproximateDouble();
Chris Lattnercbe4f772007-08-08 22:51:59 +00001953}
Chris Lattner1c20a172007-08-26 03:42:43 +00001954
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001955void ASTDumper::VisitStringLiteral(const StringLiteral *Str) {
Stephen Kelly27e948c2018-11-29 19:30:37 +00001956 ColorScope Color(OS, ShowColors, ValueColor);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001957 OS << " ";
Richard Trieudc355912012-06-13 20:25:24 +00001958 Str->outputString(OS);
Chris Lattnercbe4f772007-08-08 22:51:59 +00001959}
Chris Lattner84ca3762007-08-30 01:00:35 +00001960
Richard Smithf0514962014-06-03 08:24:28 +00001961void ASTDumper::VisitInitListExpr(const InitListExpr *ILE) {
Stephen Kelly7ec37b22018-12-09 13:15:18 +00001962 if (auto *Field = ILE->getInitializedFieldInUnion()) {
1963 OS << " field ";
1964 NodeDumper.dumpBareDeclRef(Field);
1965 }
Richard Smithf0514962014-06-03 08:24:28 +00001966 if (auto *Filler = ILE->getArrayFiller()) {
Stephen Kelly677e3ae2018-12-10 21:20:05 +00001967 dumpChild([=] {
1968 OS << "array filler";
1969 dumpStmt(Filler);
1970 });
Richard Smithf0514962014-06-03 08:24:28 +00001971 }
Richard Smithf0514962014-06-03 08:24:28 +00001972}
1973
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001974void ASTDumper::VisitUnaryOperator(const UnaryOperator *Node) {
Malcolm Parsonsfab36802018-04-16 08:31:08 +00001975 OS << " " << (Node->isPostfix() ? "postfix" : "prefix")
1976 << " '" << UnaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
1977 if (!Node->canOverflow())
1978 OS << " cannot overflow";
1979}
1980
1981void ASTDumper::VisitUnaryExprOrTypeTraitExpr(
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001982 const UnaryExprOrTypeTraitExpr *Node) {
Peter Collingbournee190dee2011-03-11 19:24:49 +00001983 switch(Node->getKind()) {
1984 case UETT_SizeOf:
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001985 OS << " sizeof";
Peter Collingbournee190dee2011-03-11 19:24:49 +00001986 break;
1987 case UETT_AlignOf:
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001988 OS << " alignof";
Peter Collingbournee190dee2011-03-11 19:24:49 +00001989 break;
1990 case UETT_VecStep:
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001991 OS << " vec_step";
Peter Collingbournee190dee2011-03-11 19:24:49 +00001992 break;
Alexey Bataev00396512015-07-02 03:40:19 +00001993 case UETT_OpenMPRequiredSimdAlign:
1994 OS << " __builtin_omp_required_simd_align";
1995 break;
Richard Smith6822bd72018-10-26 19:26:45 +00001996 case UETT_PreferredAlignOf:
1997 OS << " __alignof";
1998 break;
Peter Collingbournee190dee2011-03-11 19:24:49 +00001999 }
Sebastian Redl6f282892008-11-11 17:56:53 +00002000 if (Node->isArgumentType())
Stephen Kellyd8744a72018-12-05 21:12:39 +00002001 NodeDumper.dumpType(Node->getArgumentType());
Chris Lattnercbe4f772007-08-08 22:51:59 +00002002}
Chris Lattnerdb3b3ff2007-08-09 17:35:30 +00002003
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002004void ASTDumper::VisitMemberExpr(const MemberExpr *Node) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002005 OS << " " << (Node->isArrow() ? "->" : ".") << *Node->getMemberDecl();
Stephen Kellyd8744a72018-12-05 21:12:39 +00002006 NodeDumper.dumpPointer(Node->getMemberDecl());
Chris Lattnercbe4f772007-08-08 22:51:59 +00002007}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002008
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002009void ASTDumper::VisitExtVectorElementExpr(const ExtVectorElementExpr *Node) {
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002010 OS << " " << Node->getAccessor().getNameStart();
Chris Lattnercbe4f772007-08-08 22:51:59 +00002011}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002012
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002013void ASTDumper::VisitBinaryOperator(const BinaryOperator *Node) {
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002014 OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
Chris Lattner86928112007-08-25 02:00:02 +00002015}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002016
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002017void ASTDumper::VisitCompoundAssignOperator(
2018 const CompoundAssignOperator *Node) {
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002019 OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode())
2020 << "' ComputeLHSTy=";
Stephen Kellyd8744a72018-12-05 21:12:39 +00002021 NodeDumper.dumpBareType(Node->getComputationLHSType());
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002022 OS << " ComputeResultTy=";
Stephen Kellyd8744a72018-12-05 21:12:39 +00002023 NodeDumper.dumpBareType(Node->getComputationResultType());
Chris Lattnercbe4f772007-08-08 22:51:59 +00002024}
Chris Lattnercbe4f772007-08-08 22:51:59 +00002025
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002026void ASTDumper::VisitBlockExpr(const BlockExpr *Node) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002027 dumpDecl(Node->getBlockDecl());
John McCall351762c2011-02-07 10:33:21 +00002028}
2029
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002030void ASTDumper::VisitOpaqueValueExpr(const OpaqueValueExpr *Node) {
Richard Smithf7514452014-10-30 21:02:37 +00002031 if (Expr *Source = Node->getSourceExpr())
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002032 dumpStmt(Source);
John McCallfe96e0b2011-11-06 09:01:30 +00002033}
2034
Richard Smith01ccebf2018-01-05 21:31:07 +00002035void ASTDumper::VisitGenericSelectionExpr(const GenericSelectionExpr *E) {
Richard Smith01ccebf2018-01-05 21:31:07 +00002036 if (E->isResultDependent())
2037 OS << " result_dependent";
2038 dumpStmt(E->getControllingExpr());
2039 dumpTypeAsChild(E->getControllingExpr()->getType()); // FIXME: remove
2040
2041 for (unsigned I = 0, N = E->getNumAssocs(); I != N; ++I) {
2042 dumpChild([=] {
2043 if (const TypeSourceInfo *TSI = E->getAssocTypeSourceInfo(I)) {
2044 OS << "case ";
Stephen Kellyd8744a72018-12-05 21:12:39 +00002045 NodeDumper.dumpType(TSI->getType());
Richard Smith01ccebf2018-01-05 21:31:07 +00002046 } else {
2047 OS << "default";
2048 }
2049
2050 if (!E->isResultDependent() && E->getResultIndex() == I)
2051 OS << " selected";
2052
2053 if (const TypeSourceInfo *TSI = E->getAssocTypeSourceInfo(I))
2054 dumpTypeAsChild(TSI->getType());
2055 dumpStmt(E->getAssocExpr(I));
2056 });
2057 }
2058}
2059
Chris Lattnercbe4f772007-08-08 22:51:59 +00002060// GNU extensions.
2061
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002062void ASTDumper::VisitAddrLabelExpr(const AddrLabelExpr *Node) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002063 OS << " " << Node->getLabel()->getName();
Stephen Kellyd8744a72018-12-05 21:12:39 +00002064 NodeDumper.dumpPointer(Node->getLabel());
Chris Lattnercbe4f772007-08-08 22:51:59 +00002065}
2066
Chris Lattner8f184b12007-08-09 18:03:18 +00002067//===----------------------------------------------------------------------===//
2068// C++ Expressions
2069//===----------------------------------------------------------------------===//
Chris Lattnercbe4f772007-08-08 22:51:59 +00002070
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002071void ASTDumper::VisitCXXNamedCastExpr(const CXXNamedCastExpr *Node) {
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002072 OS << " " << Node->getCastName()
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002073 << "<" << Node->getTypeAsWritten().getAsString() << ">"
Anders Carlssona70cff62010-04-24 19:06:50 +00002074 << " <" << Node->getCastKindName();
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002075 dumpBasePath(OS, Node);
Anders Carlssona70cff62010-04-24 19:06:50 +00002076 OS << ">";
Chris Lattnercbe4f772007-08-08 22:51:59 +00002077}
2078
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002079void ASTDumper::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *Node) {
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002080 OS << " " << (Node->getValue() ? "true" : "false");
Chris Lattnercbe4f772007-08-08 22:51:59 +00002081}
2082
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002083void ASTDumper::VisitCXXThisExpr(const CXXThisExpr *Node) {
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002084 OS << " this";
Douglas Gregor8ea1f532008-11-04 14:56:14 +00002085}
2086
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002087void ASTDumper::VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *Node) {
Eli Friedman29538892011-09-02 17:38:59 +00002088 OS << " functional cast to " << Node->getTypeAsWritten().getAsString()
2089 << " <" << Node->getCastKindName() << ">";
Douglas Gregore200adc2008-10-27 19:41:14 +00002090}
2091
Richard Smith39eca9b2017-08-23 22:12:08 +00002092void ASTDumper::VisitCXXUnresolvedConstructExpr(
2093 const CXXUnresolvedConstructExpr *Node) {
Stephen Kellyd8744a72018-12-05 21:12:39 +00002094 NodeDumper.dumpType(Node->getTypeAsWritten());
Richard Smith39eca9b2017-08-23 22:12:08 +00002095 if (Node->isListInitialization())
2096 OS << " list";
2097}
2098
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002099void ASTDumper::VisitCXXConstructExpr(const CXXConstructExpr *Node) {
John McCalleba90cd2010-02-02 19:03:45 +00002100 CXXConstructorDecl *Ctor = Node->getConstructor();
Stephen Kellyd8744a72018-12-05 21:12:39 +00002101 NodeDumper.dumpType(Ctor->getType());
Anders Carlsson073846832009-08-12 00:21:52 +00002102 if (Node->isElidable())
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002103 OS << " elidable";
Richard Smith39eca9b2017-08-23 22:12:08 +00002104 if (Node->isListInitialization())
2105 OS << " list";
2106 if (Node->isStdInitListInitialization())
2107 OS << " std::initializer_list";
John McCall85370042010-08-07 06:38:55 +00002108 if (Node->requiresZeroInitialization())
2109 OS << " zeroing";
Anders Carlsson073846832009-08-12 00:21:52 +00002110}
2111
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002112void ASTDumper::VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *Node) {
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002113 OS << " ";
Stephen Kellyd8744a72018-12-05 21:12:39 +00002114 NodeDumper.dumpCXXTemporary(Node->getTemporary());
Anders Carlsson073846832009-08-12 00:21:52 +00002115}
2116
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002117void ASTDumper::VisitCXXNewExpr(const CXXNewExpr *Node) {
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002118 if (Node->isGlobalNew())
Reid Kleckner461c0c62015-03-19 18:47:47 +00002119 OS << " global";
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002120 if (Node->isArray())
Reid Kleckner461c0c62015-03-19 18:47:47 +00002121 OS << " array";
2122 if (Node->getOperatorNew()) {
2123 OS << ' ';
Stephen Kellyd8744a72018-12-05 21:12:39 +00002124 NodeDumper.dumpBareDeclRef(Node->getOperatorNew());
Reid Kleckner461c0c62015-03-19 18:47:47 +00002125 }
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002126 // We could dump the deallocation function used in case of error, but it's
2127 // usually not that interesting.
2128}
2129
2130void ASTDumper::VisitCXXDeleteExpr(const CXXDeleteExpr *Node) {
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002131 if (Node->isGlobalDelete())
Reid Kleckner461c0c62015-03-19 18:47:47 +00002132 OS << " global";
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002133 if (Node->isArrayForm())
Reid Kleckner461c0c62015-03-19 18:47:47 +00002134 OS << " array";
2135 if (Node->getOperatorDelete()) {
2136 OS << ' ';
Stephen Kellyd8744a72018-12-05 21:12:39 +00002137 NodeDumper.dumpBareDeclRef(Node->getOperatorDelete());
Reid Kleckner461c0c62015-03-19 18:47:47 +00002138 }
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002139}
2140
Richard Smithe6c01442013-06-05 00:46:14 +00002141void
2142ASTDumper::VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *Node) {
Richard Smithe6c01442013-06-05 00:46:14 +00002143 if (const ValueDecl *VD = Node->getExtendingDecl()) {
2144 OS << " extended by ";
Stephen Kellyd8744a72018-12-05 21:12:39 +00002145 NodeDumper.dumpBareDeclRef(VD);
Richard Smithe6c01442013-06-05 00:46:14 +00002146 }
2147}
2148
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002149void ASTDumper::VisitExprWithCleanups(const ExprWithCleanups *Node) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002150 for (unsigned i = 0, e = Node->getNumObjects(); i != e; ++i)
2151 dumpDeclRef(Node->getObject(i), "cleanup");
Anders Carlsson073846832009-08-12 00:21:52 +00002152}
2153
Serge Pavlov6b926032015-02-16 19:58:41 +00002154void ASTDumper::VisitSizeOfPackExpr(const SizeOfPackExpr *Node) {
Stephen Kellyd8744a72018-12-05 21:12:39 +00002155 NodeDumper.dumpPointer(Node->getPack());
2156 NodeDumper.dumpName(Node->getPack());
Richard Smithd784e682015-09-23 21:41:42 +00002157 if (Node->isPartiallySubstituted())
2158 for (const auto &A : Node->getPartialArguments())
2159 dumpTemplateArgument(A);
Serge Pavlov6b926032015-02-16 19:58:41 +00002160}
2161
Alex Lorenzddbe0f52016-11-09 14:02:18 +00002162void ASTDumper::VisitCXXDependentScopeMemberExpr(
2163 const CXXDependentScopeMemberExpr *Node) {
Alex Lorenzddbe0f52016-11-09 14:02:18 +00002164 OS << " " << (Node->isArrow() ? "->" : ".") << Node->getMember();
2165}
Serge Pavlov6b926032015-02-16 19:58:41 +00002166
Anders Carlsson76f4a902007-08-21 17:43:55 +00002167//===----------------------------------------------------------------------===//
2168// Obj-C Expressions
2169//===----------------------------------------------------------------------===//
2170
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002171void ASTDumper::VisitObjCMessageExpr(const ObjCMessageExpr *Node) {
Aaron Ballmanb190f972014-01-03 17:59:55 +00002172 OS << " selector=";
2173 Node->getSelector().print(OS);
Douglas Gregor9a129192010-04-21 00:45:42 +00002174 switch (Node->getReceiverKind()) {
2175 case ObjCMessageExpr::Instance:
2176 break;
2177
2178 case ObjCMessageExpr::Class:
2179 OS << " class=";
Stephen Kellyd8744a72018-12-05 21:12:39 +00002180 NodeDumper.dumpBareType(Node->getClassReceiver());
Douglas Gregor9a129192010-04-21 00:45:42 +00002181 break;
2182
2183 case ObjCMessageExpr::SuperInstance:
2184 OS << " super (instance)";
2185 break;
2186
2187 case ObjCMessageExpr::SuperClass:
2188 OS << " super (class)";
2189 break;
2190 }
Ted Kremenek36748da2008-02-29 22:04:05 +00002191}
2192
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002193void ASTDumper::VisitObjCBoxedExpr(const ObjCBoxedExpr *Node) {
Richard Trieu4b259c82016-06-09 22:03:04 +00002194 if (auto *BoxingMethod = Node->getBoxingMethod()) {
2195 OS << " selector=";
2196 BoxingMethod->getSelector().print(OS);
2197 }
Argyrios Kyrtzidis9dd40892012-05-10 20:02:31 +00002198}
2199
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002200void ASTDumper::VisitObjCAtCatchStmt(const ObjCAtCatchStmt *Node) {
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002201 if (const VarDecl *CatchParam = Node->getCatchParamDecl())
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002202 dumpDecl(CatchParam);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002203 else
Douglas Gregor96c79492010-04-23 22:50:49 +00002204 OS << " catch all";
Douglas Gregor96c79492010-04-23 22:50:49 +00002205}
2206
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002207void ASTDumper::VisitObjCEncodeExpr(const ObjCEncodeExpr *Node) {
Stephen Kellyd8744a72018-12-05 21:12:39 +00002208 NodeDumper.dumpType(Node->getEncodedType());
Anders Carlssonc5a81eb2007-08-22 15:14:15 +00002209}
2210
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002211void ASTDumper::VisitObjCSelectorExpr(const ObjCSelectorExpr *Node) {
Aaron Ballmanb190f972014-01-03 17:59:55 +00002212 OS << " ";
2213 Node->getSelector().print(OS);
Fariborz Jahanian4bef4622007-10-16 20:40:23 +00002214}
2215
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002216void ASTDumper::VisitObjCProtocolExpr(const ObjCProtocolExpr *Node) {
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002217 OS << ' ' << *Node->getProtocol();
Fariborz Jahaniana32aaef2007-10-17 16:58:11 +00002218}
Daniel Dunbar4b8c6db2008-08-30 05:35:15 +00002219
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002220void ASTDumper::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *Node) {
John McCallb7bd14f2010-12-02 01:19:52 +00002221 if (Node->isImplicitProperty()) {
Fariborz Jahanian0f0b3022010-12-22 19:46:35 +00002222 OS << " Kind=MethodRef Getter=\"";
2223 if (Node->getImplicitPropertyGetter())
Aaron Ballmanb190f972014-01-03 17:59:55 +00002224 Node->getImplicitPropertyGetter()->getSelector().print(OS);
Fariborz Jahanian0f0b3022010-12-22 19:46:35 +00002225 else
2226 OS << "(null)";
2227
2228 OS << "\" Setter=\"";
John McCallb7bd14f2010-12-02 01:19:52 +00002229 if (ObjCMethodDecl *Setter = Node->getImplicitPropertySetter())
Aaron Ballmanb190f972014-01-03 17:59:55 +00002230 Setter->getSelector().print(OS);
John McCallb7bd14f2010-12-02 01:19:52 +00002231 else
2232 OS << "(null)";
2233 OS << "\"";
2234 } else {
Benjamin Kramerb89514a2011-10-14 18:45:37 +00002235 OS << " Kind=PropertyRef Property=\"" << *Node->getExplicitProperty() <<'"';
John McCallb7bd14f2010-12-02 01:19:52 +00002236 }
Fariborz Jahanian8a1810f2008-11-22 18:39:36 +00002237
Fariborz Jahanian681c0752010-10-14 16:04:05 +00002238 if (Node->isSuperReceiver())
2239 OS << " super";
Argyrios Kyrtzidisab468b02012-03-30 00:19:18 +00002240
2241 OS << " Messaging=";
2242 if (Node->isMessagingGetter() && Node->isMessagingSetter())
2243 OS << "Getter&Setter";
2244 else if (Node->isMessagingGetter())
2245 OS << "Getter";
2246 else if (Node->isMessagingSetter())
2247 OS << "Setter";
Douglas Gregor8ea1f532008-11-04 14:56:14 +00002248}
2249
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002250void ASTDumper::VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *Node) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00002251 if (Node->isArraySubscriptRefExpr())
2252 OS << " Kind=ArraySubscript GetterForArray=\"";
2253 else
2254 OS << " Kind=DictionarySubscript GetterForDictionary=\"";
2255 if (Node->getAtIndexMethodDecl())
Aaron Ballmanb190f972014-01-03 17:59:55 +00002256 Node->getAtIndexMethodDecl()->getSelector().print(OS);
Ted Kremeneke65b0862012-03-06 20:05:56 +00002257 else
2258 OS << "(null)";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002259
Ted Kremeneke65b0862012-03-06 20:05:56 +00002260 if (Node->isArraySubscriptRefExpr())
2261 OS << "\" SetterForArray=\"";
2262 else
2263 OS << "\" SetterForDictionary=\"";
2264 if (Node->setAtIndexMethodDecl())
Aaron Ballmanb190f972014-01-03 17:59:55 +00002265 Node->setAtIndexMethodDecl()->getSelector().print(OS);
Ted Kremeneke65b0862012-03-06 20:05:56 +00002266 else
2267 OS << "(null)";
2268}
2269
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002270void ASTDumper::VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *Node) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00002271 OS << " " << (Node->getValue() ? "__objc_yes" : "__objc_no");
2272}
2273
Chris Lattnercbe4f772007-08-08 22:51:59 +00002274//===----------------------------------------------------------------------===//
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002275// Comments
2276//===----------------------------------------------------------------------===//
2277
Stephen Kellycdbfb302018-12-02 17:30:40 +00002278void ASTDumper::dumpComment(const Comment *C, const FullComment *FC) {
Richard Smithf7514452014-10-30 21:02:37 +00002279 dumpChild([=] {
Stephen Kellye26a88a2018-12-09 13:30:17 +00002280 NodeDumper.Visit(C, FC);
Richard Smithf7514452014-10-30 21:02:37 +00002281 if (!C) {
Richard Smithf7514452014-10-30 21:02:37 +00002282 return;
2283 }
Stephen Kellycdbfb302018-12-02 17:30:40 +00002284 ConstCommentVisitor<ASTDumper, void, const FullComment *>::visit(C, FC);
Richard Smithf7514452014-10-30 21:02:37 +00002285 for (Comment::child_iterator I = C->child_begin(), E = C->child_end();
2286 I != E; ++I)
Stephen Kellycdbfb302018-12-02 17:30:40 +00002287 dumpComment(*I, FC);
Richard Smithf7514452014-10-30 21:02:37 +00002288 });
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002289}
2290
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002291//===----------------------------------------------------------------------===//
Richard Smithd5e7ff82014-10-31 01:17:45 +00002292// Type method implementations
2293//===----------------------------------------------------------------------===//
2294
2295void QualType::dump(const char *msg) const {
2296 if (msg)
2297 llvm::errs() << msg << ": ";
2298 dump();
2299}
2300
Richard Smith14d04842016-11-02 23:57:18 +00002301LLVM_DUMP_METHOD void QualType::dump() const { dump(llvm::errs()); }
2302
2303LLVM_DUMP_METHOD void QualType::dump(llvm::raw_ostream &OS) const {
2304 ASTDumper Dumper(OS, nullptr, nullptr);
Richard Smithd5e7ff82014-10-31 01:17:45 +00002305 Dumper.dumpTypeAsChild(*this);
2306}
2307
Richard Smith14d04842016-11-02 23:57:18 +00002308LLVM_DUMP_METHOD void Type::dump() const { dump(llvm::errs()); }
2309
2310LLVM_DUMP_METHOD void Type::dump(llvm::raw_ostream &OS) const {
2311 QualType(this, 0).dump(OS);
2312}
Richard Smithd5e7ff82014-10-31 01:17:45 +00002313
2314//===----------------------------------------------------------------------===//
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002315// Decl method implementations
2316//===----------------------------------------------------------------------===//
2317
Alp Tokeref6b0072014-01-04 13:47:14 +00002318LLVM_DUMP_METHOD void Decl::dump() const { dump(llvm::errs()); }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002319
Richard Smith3a36ac12017-03-09 22:00:01 +00002320LLVM_DUMP_METHOD void Decl::dump(raw_ostream &OS, bool Deserialize) const {
Aaron Ballman8c208282017-12-21 21:42:42 +00002321 const ASTContext &Ctx = getASTContext();
2322 const SourceManager &SM = Ctx.getSourceManager();
2323 ASTDumper P(OS, &Ctx.getCommentCommandTraits(), &SM,
2324 SM.getDiagnostics().getShowColors(), Ctx.getPrintingPolicy());
Richard Smith3a36ac12017-03-09 22:00:01 +00002325 P.setDeserialize(Deserialize);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002326 P.dumpDecl(this);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002327}
2328
Alp Tokeref6b0072014-01-04 13:47:14 +00002329LLVM_DUMP_METHOD void Decl::dumpColor() const {
Aaron Ballman8c208282017-12-21 21:42:42 +00002330 const ASTContext &Ctx = getASTContext();
2331 ASTDumper P(llvm::errs(), &Ctx.getCommentCommandTraits(),
2332 &Ctx.getSourceManager(), /*ShowColors*/ true,
2333 Ctx.getPrintingPolicy());
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002334 P.dumpDecl(this);
Richard Trieud215b8d2013-01-26 01:31:20 +00002335}
Richard Smith33937e72013-06-22 21:49:40 +00002336
Alp Tokeref6b0072014-01-04 13:47:14 +00002337LLVM_DUMP_METHOD void DeclContext::dumpLookups() const {
Richard Smith6ea05822013-06-24 01:45:33 +00002338 dumpLookups(llvm::errs());
2339}
2340
Richard Smith35f986d2014-08-11 22:11:07 +00002341LLVM_DUMP_METHOD void DeclContext::dumpLookups(raw_ostream &OS,
Richard Smith3a36ac12017-03-09 22:00:01 +00002342 bool DumpDecls,
2343 bool Deserialize) const {
Richard Smith33937e72013-06-22 21:49:40 +00002344 const DeclContext *DC = this;
2345 while (!DC->isTranslationUnit())
2346 DC = DC->getParent();
2347 ASTContext &Ctx = cast<TranslationUnitDecl>(DC)->getASTContext();
Aaron Ballman8c208282017-12-21 21:42:42 +00002348 const SourceManager &SM = Ctx.getSourceManager();
2349 ASTDumper P(OS, &Ctx.getCommentCommandTraits(), &Ctx.getSourceManager(),
2350 SM.getDiagnostics().getShowColors(), Ctx.getPrintingPolicy());
Richard Smith3a36ac12017-03-09 22:00:01 +00002351 P.setDeserialize(Deserialize);
Richard Smith35f986d2014-08-11 22:11:07 +00002352 P.dumpLookups(this, DumpDecls);
Richard Smith33937e72013-06-22 21:49:40 +00002353}
2354
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002355//===----------------------------------------------------------------------===//
Chris Lattnercbe4f772007-08-08 22:51:59 +00002356// Stmt method implementations
2357//===----------------------------------------------------------------------===//
2358
Alp Tokeref6b0072014-01-04 13:47:14 +00002359LLVM_DUMP_METHOD void Stmt::dump(SourceManager &SM) const {
Argyrios Kyrtzidisc049f752010-08-09 10:54:31 +00002360 dump(llvm::errs(), SM);
2361}
2362
Alp Tokeref6b0072014-01-04 13:47:14 +00002363LLVM_DUMP_METHOD void Stmt::dump(raw_ostream &OS, SourceManager &SM) const {
Craig Topper36250ad2014-05-12 05:36:57 +00002364 ASTDumper P(OS, nullptr, &SM);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002365 P.dumpStmt(this);
Chris Lattner779d5d92007-08-30 00:40:08 +00002366}
2367
Faisal Vali2da8ed92015-03-22 13:35:56 +00002368LLVM_DUMP_METHOD void Stmt::dump(raw_ostream &OS) const {
2369 ASTDumper P(OS, nullptr, nullptr);
2370 P.dumpStmt(this);
2371}
2372
Alp Tokeref6b0072014-01-04 13:47:14 +00002373LLVM_DUMP_METHOD void Stmt::dump() const {
Craig Topper36250ad2014-05-12 05:36:57 +00002374 ASTDumper P(llvm::errs(), nullptr, nullptr);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002375 P.dumpStmt(this);
Chris Lattnercbe4f772007-08-08 22:51:59 +00002376}
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002377
Alp Tokeref6b0072014-01-04 13:47:14 +00002378LLVM_DUMP_METHOD void Stmt::dumpColor() const {
Craig Topper36250ad2014-05-12 05:36:57 +00002379 ASTDumper P(llvm::errs(), nullptr, nullptr, /*ShowColors*/true);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002380 P.dumpStmt(this);
Richard Trieud215b8d2013-01-26 01:31:20 +00002381}
2382
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002383//===----------------------------------------------------------------------===//
2384// Comment method implementations
2385//===----------------------------------------------------------------------===//
2386
Craig Topper36250ad2014-05-12 05:36:57 +00002387LLVM_DUMP_METHOD void Comment::dump() const {
2388 dump(llvm::errs(), nullptr, nullptr);
2389}
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002390
Alp Tokeref6b0072014-01-04 13:47:14 +00002391LLVM_DUMP_METHOD void Comment::dump(const ASTContext &Context) const {
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002392 dump(llvm::errs(), &Context.getCommentCommandTraits(),
2393 &Context.getSourceManager());
2394}
2395
Alexander Kornienko00911f12013-01-15 12:20:21 +00002396void Comment::dump(raw_ostream &OS, const CommandTraits *Traits,
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002397 const SourceManager *SM) const {
2398 const FullComment *FC = dyn_cast<FullComment>(this);
Stephen Kelly570b2972018-12-09 13:18:55 +00002399 if (!FC)
2400 return;
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002401 ASTDumper D(OS, Traits, SM);
Stephen Kelly570b2972018-12-09 13:18:55 +00002402 D.dumpComment(FC, FC);
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002403}
Richard Trieud215b8d2013-01-26 01:31:20 +00002404
Alp Tokeref6b0072014-01-04 13:47:14 +00002405LLVM_DUMP_METHOD void Comment::dumpColor() const {
Richard Trieud215b8d2013-01-26 01:31:20 +00002406 const FullComment *FC = dyn_cast<FullComment>(this);
Stephen Kelly570b2972018-12-09 13:18:55 +00002407 if (!FC)
2408 return;
Craig Topper36250ad2014-05-12 05:36:57 +00002409 ASTDumper D(llvm::errs(), nullptr, nullptr, /*ShowColors*/true);
Stephen Kelly570b2972018-12-09 13:18:55 +00002410 D.dumpComment(FC, FC);
Richard Trieud215b8d2013-01-26 01:31:20 +00002411}