blob: c7b15dda9d8328d9d7b8ec1359756be51959e627 [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;
Alexander Kornienkoebc17b52013-01-14 14:07:11 +000051 const CommandTraits *Traits;
Mike Stump11289f42009-09-09 15:08:12 +000052
Aaron Ballman8c208282017-12-21 21:42:42 +000053 /// The policy to use for printing; can be defaulted.
54 PrintingPolicy PrintPolicy;
55
Richard Smith3a36ac12017-03-09 22:00:01 +000056 /// Indicates whether we should trigger deserialization of nodes that had
57 /// not already been loaded.
58 bool Deserialize = false;
59
Stephen Kellye66308b2018-11-29 19:30:08 +000060 const bool ShowColors;
Richard Trieud215b8d2013-01-26 01:31:20 +000061
Richard Smithf7514452014-10-30 21:02:37 +000062 /// Dump a child of the current node.
63 template<typename Fn> void dumpChild(Fn doDumpChild) {
Stephen Kelly0da68ba2018-12-05 20:53:14 +000064 TreeStructure.addChild(doDumpChild);
Richard Smithf7514452014-10-30 21:02:37 +000065 }
Manuel Klimek874030e2012-11-07 00:33:12 +000066
Chris Lattnercbe4f772007-08-08 22:51:59 +000067 public:
Alexander Kornienkoebc17b52013-01-14 14:07:11 +000068 ASTDumper(raw_ostream &OS, const CommandTraits *Traits,
69 const SourceManager *SM)
Aaron Ballman8c208282017-12-21 21:42:42 +000070 : ASTDumper(OS, Traits, SM,
71 SM && SM->getDiagnostics().getShowColors()) {}
Richard Trieud215b8d2013-01-26 01:31:20 +000072
73 ASTDumper(raw_ostream &OS, const CommandTraits *Traits,
74 const SourceManager *SM, bool ShowColors)
Aaron Ballman8c208282017-12-21 21:42:42 +000075 : ASTDumper(OS, Traits, SM, ShowColors, LangOptions()) {}
76 ASTDumper(raw_ostream &OS, const CommandTraits *Traits,
77 const SourceManager *SM, bool ShowColors,
78 const PrintingPolicy &PrintPolicy)
Stephen Kellyd8744a72018-12-05 21:12:39 +000079 : TreeStructure(OS, ShowColors),
80 NodeDumper(OS, ShowColors, SM, PrintPolicy), OS(OS), Traits(Traits),
Stephen Kelly0da68ba2018-12-05 20:53:14 +000081 PrintPolicy(PrintPolicy), ShowColors(ShowColors) {}
Richard Smith3a36ac12017-03-09 22:00:01 +000082
83 void setDeserialize(bool D) { Deserialize = D; }
Mike Stump11289f42009-09-09 15:08:12 +000084
Alexander Kornienko540bacb2013-02-01 12:35:51 +000085 void dumpDecl(const Decl *D);
86 void dumpStmt(const Stmt *S);
Alexander Kornienkoebc17b52013-01-14 14:07:11 +000087 void dumpFullComment(const FullComment *C);
Mike Stump11289f42009-09-09 15:08:12 +000088
Richard Trieude5cc7d2013-01-31 01:44:26 +000089 // Utilities
Stephen Kellyd8744a72018-12-05 21:12:39 +000090 void dumpType(QualType T) { NodeDumper.dumpType(T); }
Richard Smithd5e7ff82014-10-31 01:17:45 +000091 void dumpTypeAsChild(QualType T);
92 void dumpTypeAsChild(const Type *T);
Craig Topper36250ad2014-05-12 05:36:57 +000093 void dumpDeclRef(const Decl *Node, const char *Label = nullptr);
Stephen Kellyd8744a72018-12-05 21:12:39 +000094 void dumpBareDeclRef(const Decl *Node) { NodeDumper.dumpBareDeclRef(Node); }
Richard Trieude5cc7d2013-01-31 01:44:26 +000095 bool hasNodes(const DeclContext *DC);
Alexander Kornienko787f4c32012-12-20 11:08:38 +000096 void dumpDeclContext(const DeclContext *DC);
Richard Smith35f986d2014-08-11 22:11:07 +000097 void dumpLookups(const DeclContext *DC, bool DumpDecls);
Alexander Kornienko5bc364e2013-01-07 17:53:08 +000098 void dumpAttr(const Attr *A);
Alexander Kornienko90ff6072012-12-20 02:09:13 +000099
100 // C++ Utilities
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000101 void dumpCXXCtorInitializer(const CXXCtorInitializer *Init);
102 void dumpTemplateParameters(const TemplateParameterList *TPL);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000103 void dumpTemplateArgumentListInfo(const TemplateArgumentListInfo &TALI);
104 void dumpTemplateArgumentLoc(const TemplateArgumentLoc &A);
105 void dumpTemplateArgumentList(const TemplateArgumentList &TAL);
106 void dumpTemplateArgument(const TemplateArgument &A,
107 SourceRange R = SourceRange());
108
Douglas Gregor85f3f952015-07-07 03:57:15 +0000109 // Objective-C utilities.
110 void dumpObjCTypeParamList(const ObjCTypeParamList *typeParams);
111
Richard Smithd5e7ff82014-10-31 01:17:45 +0000112 // Types
113 void VisitComplexType(const ComplexType *T) {
114 dumpTypeAsChild(T->getElementType());
115 }
116 void VisitPointerType(const PointerType *T) {
117 dumpTypeAsChild(T->getPointeeType());
118 }
119 void VisitBlockPointerType(const BlockPointerType *T) {
120 dumpTypeAsChild(T->getPointeeType());
121 }
122 void VisitReferenceType(const ReferenceType *T) {
123 dumpTypeAsChild(T->getPointeeType());
124 }
125 void VisitRValueReferenceType(const ReferenceType *T) {
126 if (T->isSpelledAsLValue())
127 OS << " written as lvalue reference";
128 VisitReferenceType(T);
129 }
130 void VisitMemberPointerType(const MemberPointerType *T) {
131 dumpTypeAsChild(T->getClass());
132 dumpTypeAsChild(T->getPointeeType());
133 }
134 void VisitArrayType(const ArrayType *T) {
135 switch (T->getSizeModifier()) {
136 case ArrayType::Normal: break;
137 case ArrayType::Static: OS << " static"; break;
138 case ArrayType::Star: OS << " *"; break;
139 }
140 OS << " " << T->getIndexTypeQualifiers().getAsString();
141 dumpTypeAsChild(T->getElementType());
142 }
143 void VisitConstantArrayType(const ConstantArrayType *T) {
144 OS << " " << T->getSize();
145 VisitArrayType(T);
146 }
147 void VisitVariableArrayType(const VariableArrayType *T) {
148 OS << " ";
Stephen Kellyd8744a72018-12-05 21:12:39 +0000149 NodeDumper.dumpSourceRange(T->getBracketsRange());
Richard Smithd5e7ff82014-10-31 01:17:45 +0000150 VisitArrayType(T);
151 dumpStmt(T->getSizeExpr());
152 }
153 void VisitDependentSizedArrayType(const DependentSizedArrayType *T) {
Stephen Kellyec42aa02018-12-05 20:34:07 +0000154 switch (T->getSizeModifier()) {
155 case ArrayType::Normal: break;
156 case ArrayType::Static: OS << " static"; break;
157 case ArrayType::Star: OS << " *"; break;
158 }
159 OS << " " << T->getIndexTypeQualifiers().getAsString();
Richard Smithd5e7ff82014-10-31 01:17:45 +0000160 OS << " ";
Stephen Kellyd8744a72018-12-05 21:12:39 +0000161 NodeDumper.dumpSourceRange(T->getBracketsRange());
Stephen Kellyec42aa02018-12-05 20:34:07 +0000162 dumpTypeAsChild(T->getElementType());
Richard Smithd5e7ff82014-10-31 01:17:45 +0000163 dumpStmt(T->getSizeExpr());
164 }
165 void VisitDependentSizedExtVectorType(
166 const DependentSizedExtVectorType *T) {
167 OS << " ";
Stephen Kellyd8744a72018-12-05 21:12:39 +0000168 NodeDumper.dumpLocation(T->getAttributeLoc());
Richard Smithd5e7ff82014-10-31 01:17:45 +0000169 dumpTypeAsChild(T->getElementType());
170 dumpStmt(T->getSizeExpr());
171 }
172 void VisitVectorType(const VectorType *T) {
173 switch (T->getVectorKind()) {
174 case VectorType::GenericVector: break;
175 case VectorType::AltiVecVector: OS << " altivec"; break;
176 case VectorType::AltiVecPixel: OS << " altivec pixel"; break;
177 case VectorType::AltiVecBool: OS << " altivec bool"; break;
178 case VectorType::NeonVector: OS << " neon"; break;
179 case VectorType::NeonPolyVector: OS << " neon poly"; break;
180 }
181 OS << " " << T->getNumElements();
182 dumpTypeAsChild(T->getElementType());
183 }
184 void VisitFunctionType(const FunctionType *T) {
185 auto EI = T->getExtInfo();
186 if (EI.getNoReturn()) OS << " noreturn";
187 if (EI.getProducesResult()) OS << " produces_result";
188 if (EI.getHasRegParm()) OS << " regparm " << EI.getRegParm();
189 OS << " " << FunctionType::getNameForCallConv(EI.getCC());
190 dumpTypeAsChild(T->getReturnType());
191 }
192 void VisitFunctionProtoType(const FunctionProtoType *T) {
193 auto EPI = T->getExtProtoInfo();
194 if (EPI.HasTrailingReturn) OS << " trailing_return";
195 if (T->isConst()) OS << " const";
196 if (T->isVolatile()) OS << " volatile";
197 if (T->isRestrict()) OS << " restrict";
198 switch (EPI.RefQualifier) {
199 case RQ_None: break;
200 case RQ_LValue: OS << " &"; break;
201 case RQ_RValue: OS << " &&"; break;
202 }
203 // FIXME: Exception specification.
204 // FIXME: Consumed parameters.
205 VisitFunctionType(T);
206 for (QualType PT : T->getParamTypes())
207 dumpTypeAsChild(PT);
208 if (EPI.Variadic)
209 dumpChild([=] { OS << "..."; });
210 }
211 void VisitUnresolvedUsingType(const UnresolvedUsingType *T) {
212 dumpDeclRef(T->getDecl());
213 }
214 void VisitTypedefType(const TypedefType *T) {
215 dumpDeclRef(T->getDecl());
216 }
217 void VisitTypeOfExprType(const TypeOfExprType *T) {
218 dumpStmt(T->getUnderlyingExpr());
219 }
220 void VisitDecltypeType(const DecltypeType *T) {
221 dumpStmt(T->getUnderlyingExpr());
222 }
223 void VisitUnaryTransformType(const UnaryTransformType *T) {
224 switch (T->getUTTKind()) {
225 case UnaryTransformType::EnumUnderlyingType:
226 OS << " underlying_type";
227 break;
228 }
229 dumpTypeAsChild(T->getBaseType());
230 }
231 void VisitTagType(const TagType *T) {
232 dumpDeclRef(T->getDecl());
233 }
234 void VisitAttributedType(const AttributedType *T) {
235 // FIXME: AttrKind
236 dumpTypeAsChild(T->getModifiedType());
237 }
238 void VisitTemplateTypeParmType(const TemplateTypeParmType *T) {
239 OS << " depth " << T->getDepth() << " index " << T->getIndex();
240 if (T->isParameterPack()) OS << " pack";
241 dumpDeclRef(T->getDecl());
242 }
243 void VisitSubstTemplateTypeParmType(const SubstTemplateTypeParmType *T) {
244 dumpTypeAsChild(T->getReplacedParameter());
245 }
246 void VisitSubstTemplateTypeParmPackType(
247 const SubstTemplateTypeParmPackType *T) {
248 dumpTypeAsChild(T->getReplacedParameter());
249 dumpTemplateArgument(T->getArgumentPack());
250 }
251 void VisitAutoType(const AutoType *T) {
252 if (T->isDecltypeAuto()) OS << " decltype(auto)";
253 if (!T->isDeduced())
254 OS << " undeduced";
255 }
256 void VisitTemplateSpecializationType(const TemplateSpecializationType *T) {
257 if (T->isTypeAlias()) OS << " alias";
258 OS << " "; T->getTemplateName().dump(OS);
259 for (auto &Arg : *T)
260 dumpTemplateArgument(Arg);
261 if (T->isTypeAlias())
262 dumpTypeAsChild(T->getAliasedType());
263 }
264 void VisitInjectedClassNameType(const InjectedClassNameType *T) {
265 dumpDeclRef(T->getDecl());
266 }
267 void VisitObjCInterfaceType(const ObjCInterfaceType *T) {
268 dumpDeclRef(T->getDecl());
269 }
270 void VisitObjCObjectPointerType(const ObjCObjectPointerType *T) {
271 dumpTypeAsChild(T->getPointeeType());
272 }
273 void VisitAtomicType(const AtomicType *T) {
274 dumpTypeAsChild(T->getValueType());
275 }
Xiuli Pan2d12e652016-05-03 05:37:07 +0000276 void VisitPipeType(const PipeType *T) {
277 dumpTypeAsChild(T->getElementType());
278 }
Richard Smithd5e7ff82014-10-31 01:17:45 +0000279 void VisitAdjustedType(const AdjustedType *T) {
280 dumpTypeAsChild(T->getOriginalType());
281 }
282 void VisitPackExpansionType(const PackExpansionType *T) {
283 if (auto N = T->getNumExpansions()) OS << " expansions " << *N;
284 if (!T->isSugared())
285 dumpTypeAsChild(T->getPattern());
286 }
287 // FIXME: ElaboratedType, DependentNameType,
288 // DependentTemplateSpecializationType, ObjCObjectType
289
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000290 // Decls
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000291 void VisitLabelDecl(const LabelDecl *D);
292 void VisitTypedefDecl(const TypedefDecl *D);
293 void VisitEnumDecl(const EnumDecl *D);
294 void VisitRecordDecl(const RecordDecl *D);
295 void VisitEnumConstantDecl(const EnumConstantDecl *D);
296 void VisitIndirectFieldDecl(const IndirectFieldDecl *D);
297 void VisitFunctionDecl(const FunctionDecl *D);
298 void VisitFieldDecl(const FieldDecl *D);
299 void VisitVarDecl(const VarDecl *D);
Richard Smithbdb84f32016-07-22 23:36:59 +0000300 void VisitDecompositionDecl(const DecompositionDecl *D);
Richard Smith7873de02016-08-11 22:25:46 +0000301 void VisitBindingDecl(const BindingDecl *D);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000302 void VisitFileScopeAsmDecl(const FileScopeAsmDecl *D);
303 void VisitImportDecl(const ImportDecl *D);
Nico Weber66220292016-03-02 17:28:48 +0000304 void VisitPragmaCommentDecl(const PragmaCommentDecl *D);
Nico Webercbbaeb12016-03-02 19:28:54 +0000305 void VisitPragmaDetectMismatchDecl(const PragmaDetectMismatchDecl *D);
Alexey Bataev958b9e72016-03-31 09:30:50 +0000306 void VisitCapturedDecl(const CapturedDecl *D);
307
308 // OpenMP decls
309 void VisitOMPThreadPrivateDecl(const OMPThreadPrivateDecl *D);
310 void VisitOMPDeclareReductionDecl(const OMPDeclareReductionDecl *D);
Kelvin Li1408f912018-09-26 04:28:39 +0000311 void VisitOMPRequiresDecl(const OMPRequiresDecl *D);
Alexey Bataev958b9e72016-03-31 09:30:50 +0000312 void VisitOMPCapturedExprDecl(const OMPCapturedExprDecl *D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000313
314 // C++ Decls
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000315 void VisitNamespaceDecl(const NamespaceDecl *D);
316 void VisitUsingDirectiveDecl(const UsingDirectiveDecl *D);
317 void VisitNamespaceAliasDecl(const NamespaceAliasDecl *D);
318 void VisitTypeAliasDecl(const TypeAliasDecl *D);
319 void VisitTypeAliasTemplateDecl(const TypeAliasTemplateDecl *D);
320 void VisitCXXRecordDecl(const CXXRecordDecl *D);
321 void VisitStaticAssertDecl(const StaticAssertDecl *D);
Richard Smithcbdf7332014-03-18 02:07:28 +0000322 template<typename SpecializationDecl>
Richard Smithf7514452014-10-30 21:02:37 +0000323 void VisitTemplateDeclSpecialization(const SpecializationDecl *D,
Richard Smithcbdf7332014-03-18 02:07:28 +0000324 bool DumpExplicitInst,
325 bool DumpRefOnly);
Richard Smith20ade552014-03-17 23:34:53 +0000326 template<typename TemplateDecl>
327 void VisitTemplateDecl(const TemplateDecl *D, bool DumpExplicitInst);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000328 void VisitFunctionTemplateDecl(const FunctionTemplateDecl *D);
329 void VisitClassTemplateDecl(const ClassTemplateDecl *D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000330 void VisitClassTemplateSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000331 const ClassTemplateSpecializationDecl *D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000332 void VisitClassTemplatePartialSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000333 const ClassTemplatePartialSpecializationDecl *D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000334 void VisitClassScopeFunctionSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000335 const ClassScopeFunctionSpecializationDecl *D);
David Majnemerd9b1a4f2015-11-04 03:40:30 +0000336 void VisitBuiltinTemplateDecl(const BuiltinTemplateDecl *D);
Richard Smithd25789a2013-09-18 01:36:02 +0000337 void VisitVarTemplateDecl(const VarTemplateDecl *D);
338 void VisitVarTemplateSpecializationDecl(
339 const VarTemplateSpecializationDecl *D);
340 void VisitVarTemplatePartialSpecializationDecl(
341 const VarTemplatePartialSpecializationDecl *D);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000342 void VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D);
343 void VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D);
344 void VisitTemplateTemplateParmDecl(const TemplateTemplateParmDecl *D);
345 void VisitUsingDecl(const UsingDecl *D);
346 void VisitUnresolvedUsingTypenameDecl(const UnresolvedUsingTypenameDecl *D);
347 void VisitUnresolvedUsingValueDecl(const UnresolvedUsingValueDecl *D);
348 void VisitUsingShadowDecl(const UsingShadowDecl *D);
Richard Smith5179eb72016-06-28 19:03:57 +0000349 void VisitConstructorUsingShadowDecl(const ConstructorUsingShadowDecl *D);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000350 void VisitLinkageSpecDecl(const LinkageSpecDecl *D);
351 void VisitAccessSpecDecl(const AccessSpecDecl *D);
352 void VisitFriendDecl(const FriendDecl *D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000353
354 // ObjC Decls
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000355 void VisitObjCIvarDecl(const ObjCIvarDecl *D);
356 void VisitObjCMethodDecl(const ObjCMethodDecl *D);
Douglas Gregor85f3f952015-07-07 03:57:15 +0000357 void VisitObjCTypeParamDecl(const ObjCTypeParamDecl *D);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000358 void VisitObjCCategoryDecl(const ObjCCategoryDecl *D);
359 void VisitObjCCategoryImplDecl(const ObjCCategoryImplDecl *D);
360 void VisitObjCProtocolDecl(const ObjCProtocolDecl *D);
361 void VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D);
362 void VisitObjCImplementationDecl(const ObjCImplementationDecl *D);
363 void VisitObjCCompatibleAliasDecl(const ObjCCompatibleAliasDecl *D);
364 void VisitObjCPropertyDecl(const ObjCPropertyDecl *D);
365 void VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D);
366 void VisitBlockDecl(const BlockDecl *D);
Mike Stump11289f42009-09-09 15:08:12 +0000367
Chris Lattner84ca3762007-08-30 01:00:35 +0000368 // Stmts.
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000369 void VisitDeclStmt(const DeclStmt *Node);
370 void VisitAttributedStmt(const AttributedStmt *Node);
Bruno Riccib1cc94b2018-10-27 21:12:20 +0000371 void VisitIfStmt(const IfStmt *Node);
Bruno Riccie2806f82018-10-29 16:12:37 +0000372 void VisitSwitchStmt(const SwitchStmt *Node);
Bruno Riccibacf7512018-10-30 13:42:41 +0000373 void VisitWhileStmt(const WhileStmt *Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000374 void VisitLabelStmt(const LabelStmt *Node);
375 void VisitGotoStmt(const GotoStmt *Node);
Pavel Labath1ef83422013-09-04 14:35:00 +0000376 void VisitCXXCatchStmt(const CXXCatchStmt *Node);
Bruno Ricci5b30571752018-10-28 12:30:53 +0000377 void VisitCaseStmt(const CaseStmt *Node);
Alexey Bataev958b9e72016-03-31 09:30:50 +0000378 void VisitCapturedStmt(const CapturedStmt *Node);
379
380 // OpenMP
381 void VisitOMPExecutableDirective(const OMPExecutableDirective *Node);
Mike Stump11289f42009-09-09 15:08:12 +0000382
Chris Lattner84ca3762007-08-30 01:00:35 +0000383 // Exprs
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000384 void VisitExpr(const Expr *Node);
385 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) {
420 VisitExpr(Node);
421 dumpDecl(Node->getLambdaClass());
422 }
Serge Pavlov6b926032015-02-16 19:58:41 +0000423 void VisitSizeOfPackExpr(const SizeOfPackExpr *Node);
Alex Lorenzddbe0f52016-11-09 14:02:18 +0000424 void
425 VisitCXXDependentScopeMemberExpr(const CXXDependentScopeMemberExpr *Node);
Mike Stump11289f42009-09-09 15:08:12 +0000426
Chris Lattner84ca3762007-08-30 01:00:35 +0000427 // ObjC
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000428 void VisitObjCAtCatchStmt(const ObjCAtCatchStmt *Node);
429 void VisitObjCEncodeExpr(const ObjCEncodeExpr *Node);
430 void VisitObjCMessageExpr(const ObjCMessageExpr *Node);
431 void VisitObjCBoxedExpr(const ObjCBoxedExpr *Node);
432 void VisitObjCSelectorExpr(const ObjCSelectorExpr *Node);
433 void VisitObjCProtocolExpr(const ObjCProtocolExpr *Node);
434 void VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *Node);
435 void VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *Node);
436 void VisitObjCIvarRefExpr(const ObjCIvarRefExpr *Node);
437 void VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *Node);
Alexander Kornienkoebc17b52013-01-14 14:07:11 +0000438
439 // Comments.
440 const char *getCommandName(unsigned CommandID);
Stephen Kellycdbfb302018-12-02 17:30:40 +0000441 void dumpComment(const Comment *C, const FullComment *FC);
Alexander Kornienkoebc17b52013-01-14 14:07:11 +0000442
443 // Inline comments.
Stephen Kellycdbfb302018-12-02 17:30:40 +0000444 void visitTextComment(const TextComment *C, const FullComment *FC);
445 void visitInlineCommandComment(const InlineCommandComment *C,
446 const FullComment *FC);
447 void visitHTMLStartTagComment(const HTMLStartTagComment *C,
448 const FullComment *FC);
449 void visitHTMLEndTagComment(const HTMLEndTagComment *C,
450 const FullComment *FC);
Alexander Kornienkoebc17b52013-01-14 14:07:11 +0000451
452 // Block comments.
Stephen Kellycdbfb302018-12-02 17:30:40 +0000453 void visitBlockCommandComment(const BlockCommandComment *C,
454 const FullComment *FC);
455 void visitParamCommandComment(const ParamCommandComment *C,
456 const FullComment *FC);
457 void visitTParamCommandComment(const TParamCommandComment *C,
458 const FullComment *FC);
459 void visitVerbatimBlockComment(const VerbatimBlockComment *C,
460 const FullComment *FC);
461 void visitVerbatimBlockLineComment(const VerbatimBlockLineComment *C,
462 const FullComment *FC);
463 void visitVerbatimLineComment(const VerbatimLineComment *C,
464 const FullComment *FC);
Chris Lattnercbe4f772007-08-08 22:51:59 +0000465 };
Alexander Kornienkoab9db512015-06-22 23:07:51 +0000466}
Chris Lattnercbe4f772007-08-08 22:51:59 +0000467
468//===----------------------------------------------------------------------===//
Chris Lattner11e30d32007-08-30 06:17:34 +0000469// Utilities
470//===----------------------------------------------------------------------===//
471
Richard Smithd5e7ff82014-10-31 01:17:45 +0000472void ASTDumper::dumpTypeAsChild(QualType T) {
473 SplitQualType SQT = T.split();
474 if (!SQT.Quals.hasQualifiers())
475 return dumpTypeAsChild(SQT.Ty);
476
477 dumpChild([=] {
478 OS << "QualType";
Stephen Kellyd8744a72018-12-05 21:12:39 +0000479 NodeDumper.dumpPointer(T.getAsOpaquePtr());
Richard Smithd5e7ff82014-10-31 01:17:45 +0000480 OS << " ";
Stephen Kellyd8744a72018-12-05 21:12:39 +0000481 NodeDumper.dumpBareType(T, false);
Richard Smithd5e7ff82014-10-31 01:17:45 +0000482 OS << " " << T.split().Quals.getAsString();
483 dumpTypeAsChild(T.split().Ty);
484 });
485}
486
487void ASTDumper::dumpTypeAsChild(const Type *T) {
488 dumpChild([=] {
489 if (!T) {
Stephen Kelly27e948c2018-11-29 19:30:37 +0000490 ColorScope Color(OS, ShowColors, NullColor);
Richard Smithd5e7ff82014-10-31 01:17:45 +0000491 OS << "<<<NULL>>>";
492 return;
493 }
Serge Pavlova6adc9e2015-12-28 17:19:12 +0000494 if (const LocInfoType *LIT = llvm::dyn_cast<LocInfoType>(T)) {
495 {
Stephen Kelly27e948c2018-11-29 19:30:37 +0000496 ColorScope Color(OS, ShowColors, TypeColor);
Serge Pavlova6adc9e2015-12-28 17:19:12 +0000497 OS << "LocInfo Type";
498 }
Stephen Kellyd8744a72018-12-05 21:12:39 +0000499 NodeDumper.dumpPointer(T);
Serge Pavlova6adc9e2015-12-28 17:19:12 +0000500 dumpTypeAsChild(LIT->getTypeSourceInfo()->getType());
501 return;
502 }
Richard Smithd5e7ff82014-10-31 01:17:45 +0000503
504 {
Stephen Kelly27e948c2018-11-29 19:30:37 +0000505 ColorScope Color(OS, ShowColors, TypeColor);
Richard Smithd5e7ff82014-10-31 01:17:45 +0000506 OS << T->getTypeClassName() << "Type";
507 }
Stephen Kellyd8744a72018-12-05 21:12:39 +0000508 NodeDumper.dumpPointer(T);
Richard Smithd5e7ff82014-10-31 01:17:45 +0000509 OS << " ";
Stephen Kellyd8744a72018-12-05 21:12:39 +0000510 NodeDumper.dumpBareType(QualType(T, 0), false);
Richard Smithd5e7ff82014-10-31 01:17:45 +0000511
512 QualType SingleStepDesugar =
513 T->getLocallyUnqualifiedSingleStepDesugaredType();
514 if (SingleStepDesugar != QualType(T, 0))
515 OS << " sugar";
516 if (T->isDependentType())
517 OS << " dependent";
518 else if (T->isInstantiationDependentType())
519 OS << " instantiation_dependent";
520 if (T->isVariablyModifiedType())
521 OS << " variably_modified";
522 if (T->containsUnexpandedParameterPack())
523 OS << " contains_unexpanded_pack";
524 if (T->isFromAST())
525 OS << " imported";
526
527 TypeVisitor<ASTDumper>::Visit(T);
528
529 if (SingleStepDesugar != QualType(T, 0))
530 dumpTypeAsChild(SingleStepDesugar);
531 });
532}
533
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000534void ASTDumper::dumpDeclRef(const Decl *D, const char *Label) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000535 if (!D)
536 return;
537
Richard Smithf7514452014-10-30 21:02:37 +0000538 dumpChild([=]{
539 if (Label)
540 OS << Label << ' ';
541 dumpBareDeclRef(D);
542 });
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000543}
544
Richard Trieude5cc7d2013-01-31 01:44:26 +0000545bool ASTDumper::hasNodes(const DeclContext *DC) {
546 if (!DC)
547 return false;
548
Richard Smith1d209d02013-05-23 01:49:11 +0000549 return DC->hasExternalLexicalStorage() ||
Richard Smith3a36ac12017-03-09 22:00:01 +0000550 (Deserialize ? DC->decls_begin() != DC->decls_end()
551 : DC->noload_decls_begin() != DC->noload_decls_end());
Richard Trieude5cc7d2013-01-31 01:44:26 +0000552}
553
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000554void ASTDumper::dumpDeclContext(const DeclContext *DC) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000555 if (!DC)
556 return;
Richard Smithdcc2c452014-03-17 23:00:06 +0000557
Richard Smith3a36ac12017-03-09 22:00:01 +0000558 for (auto *D : (Deserialize ? DC->decls() : DC->noload_decls()))
Richard Smithf7514452014-10-30 21:02:37 +0000559 dumpDecl(D);
Richard Smithdcc2c452014-03-17 23:00:06 +0000560
561 if (DC->hasExternalLexicalStorage()) {
Stephen Kelly27e948c2018-11-29 19:30:37 +0000562 dumpChild([=] {
563 ColorScope Color(OS, ShowColors, UndeserializedColor);
Richard Smithf7514452014-10-30 21:02:37 +0000564 OS << "<undeserialized declarations>";
565 });
Richard Smith1d209d02013-05-23 01:49:11 +0000566 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000567}
568
Richard Smith35f986d2014-08-11 22:11:07 +0000569void ASTDumper::dumpLookups(const DeclContext *DC, bool DumpDecls) {
Richard Smithf7514452014-10-30 21:02:37 +0000570 dumpChild([=] {
571 OS << "StoredDeclsMap ";
Stephen Kellyd8744a72018-12-05 21:12:39 +0000572 NodeDumper.dumpBareDeclRef(cast<Decl>(DC));
Richard Smith33937e72013-06-22 21:49:40 +0000573
Richard Smithf7514452014-10-30 21:02:37 +0000574 const DeclContext *Primary = DC->getPrimaryContext();
575 if (Primary != DC) {
576 OS << " primary";
Stephen Kellyd8744a72018-12-05 21:12:39 +0000577 NodeDumper.dumpPointer(cast<Decl>(Primary));
Richard Smith33937e72013-06-22 21:49:40 +0000578 }
579
Richard Smithf7514452014-10-30 21:02:37 +0000580 bool HasUndeserializedLookups = Primary->hasExternalVisibleStorage();
Richard Smith35f986d2014-08-11 22:11:07 +0000581
Sam McCall091b1ef2018-01-16 12:33:46 +0000582 auto Range = Deserialize
583 ? Primary->lookups()
584 : Primary->noload_lookups(/*PreserveInternalState=*/true);
585 for (auto I = Range.begin(), E = Range.end(); I != E; ++I) {
Richard Smithf7514452014-10-30 21:02:37 +0000586 DeclarationName Name = I.getLookupName();
Richard Smith3a36ac12017-03-09 22:00:01 +0000587 DeclContextLookupResult R = *I;
Richard Smith35f986d2014-08-11 22:11:07 +0000588
Richard Smithf7514452014-10-30 21:02:37 +0000589 dumpChild([=] {
590 OS << "DeclarationName ";
591 {
Stephen Kelly27e948c2018-11-29 19:30:37 +0000592 ColorScope Color(OS, ShowColors, DeclNameColor);
Richard Smithf7514452014-10-30 21:02:37 +0000593 OS << '\'' << Name << '\'';
594 }
Richard Smith35f986d2014-08-11 22:11:07 +0000595
Richard Smithf7514452014-10-30 21:02:37 +0000596 for (DeclContextLookupResult::iterator RI = R.begin(), RE = R.end();
597 RI != RE; ++RI) {
598 dumpChild([=] {
Stephen Kellyd8744a72018-12-05 21:12:39 +0000599 NodeDumper.dumpBareDeclRef(*RI);
Richard Smithf7514452014-10-30 21:02:37 +0000600
601 if ((*RI)->isHidden())
602 OS << " hidden";
603
604 // If requested, dump the redecl chain for this lookup.
605 if (DumpDecls) {
606 // Dump earliest decl first.
607 std::function<void(Decl *)> DumpWithPrev = [&](Decl *D) {
608 if (Decl *Prev = D->getPreviousDecl())
609 DumpWithPrev(Prev);
610 dumpDecl(D);
611 };
612 DumpWithPrev(*RI);
613 }
614 });
615 }
616 });
Richard Smith33937e72013-06-22 21:49:40 +0000617 }
Richard Smith33937e72013-06-22 21:49:40 +0000618
Richard Smithf7514452014-10-30 21:02:37 +0000619 if (HasUndeserializedLookups) {
620 dumpChild([=] {
Stephen Kelly27e948c2018-11-29 19:30:37 +0000621 ColorScope Color(OS, ShowColors, UndeserializedColor);
Richard Smithf7514452014-10-30 21:02:37 +0000622 OS << "<undeserialized lookups>";
623 });
624 }
625 });
Richard Smith33937e72013-06-22 21:49:40 +0000626}
627
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000628void ASTDumper::dumpAttr(const Attr *A) {
Richard Smithf7514452014-10-30 21:02:37 +0000629 dumpChild([=] {
630 {
Stephen Kelly27e948c2018-11-29 19:30:37 +0000631 ColorScope Color(OS, ShowColors, AttrColor);
Aaron Ballman36a53502014-01-16 13:03:14 +0000632
Richard Smithf7514452014-10-30 21:02:37 +0000633 switch (A->getKind()) {
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000634#define ATTR(X) case attr::X: OS << #X; break;
635#include "clang/Basic/AttrList.inc"
Richard Smithf7514452014-10-30 21:02:37 +0000636 }
637 OS << "Attr";
Richard Trieud215b8d2013-01-26 01:31:20 +0000638 }
Stephen Kellyd8744a72018-12-05 21:12:39 +0000639 NodeDumper.dumpPointer(A);
640 NodeDumper.dumpSourceRange(A->getRange());
Richard Smithf7514452014-10-30 21:02:37 +0000641 if (A->isInherited())
642 OS << " Inherited";
643 if (A->isImplicit())
644 OS << " Implicit";
Hans Wennborgb0a8b4a2014-05-31 04:05:57 +0000645#include "clang/AST/AttrDump.inc"
Richard Smithf7514452014-10-30 21:02:37 +0000646 });
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000647}
648
Richard Smith71bec062013-10-15 21:58:30 +0000649static void dumpPreviousDeclImpl(raw_ostream &OS, ...) {}
650
651template<typename T>
652static void dumpPreviousDeclImpl(raw_ostream &OS, const Mergeable<T> *D) {
Rafael Espindola8db352d2013-10-17 15:37:26 +0000653 const T *First = D->getFirstDecl();
Richard Smith71bec062013-10-15 21:58:30 +0000654 if (First != D)
655 OS << " first " << First;
Richard Smithf5f43542013-02-07 01:35:44 +0000656}
657
658template<typename T>
Richard Smith71bec062013-10-15 21:58:30 +0000659static void dumpPreviousDeclImpl(raw_ostream &OS, const Redeclarable<T> *D) {
660 const T *Prev = D->getPreviousDecl();
661 if (Prev)
662 OS << " prev " << Prev;
Richard Smithf5f43542013-02-07 01:35:44 +0000663}
664
Richard Smith71bec062013-10-15 21:58:30 +0000665/// Dump the previous declaration in the redeclaration chain for a declaration,
666/// if any.
667static void dumpPreviousDecl(raw_ostream &OS, const Decl *D) {
Richard Smithf5f43542013-02-07 01:35:44 +0000668 switch (D->getKind()) {
669#define DECL(DERIVED, BASE) \
670 case Decl::DERIVED: \
Richard Smith71bec062013-10-15 21:58:30 +0000671 return dumpPreviousDeclImpl(OS, cast<DERIVED##Decl>(D));
Richard Smithf5f43542013-02-07 01:35:44 +0000672#define ABSTRACT_DECL(DECL)
673#include "clang/AST/DeclNodes.inc"
674 }
675 llvm_unreachable("Decl that isn't part of DeclNodes.inc!");
676}
677
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000678//===----------------------------------------------------------------------===//
679// C++ Utilities
680//===----------------------------------------------------------------------===//
681
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000682void ASTDumper::dumpCXXCtorInitializer(const CXXCtorInitializer *Init) {
Richard Smithf7514452014-10-30 21:02:37 +0000683 dumpChild([=] {
684 OS << "CXXCtorInitializer";
685 if (Init->isAnyMemberInitializer()) {
686 OS << ' ';
Stephen Kellyd8744a72018-12-05 21:12:39 +0000687 NodeDumper.dumpBareDeclRef(Init->getAnyMember());
Richard Smithf7514452014-10-30 21:02:37 +0000688 } else if (Init->isBaseInitializer()) {
Stephen Kellyd8744a72018-12-05 21:12:39 +0000689 NodeDumper.dumpType(QualType(Init->getBaseClass(), 0));
Richard Smithf7514452014-10-30 21:02:37 +0000690 } else if (Init->isDelegatingInitializer()) {
Stephen Kellyd8744a72018-12-05 21:12:39 +0000691 NodeDumper.dumpType(Init->getTypeSourceInfo()->getType());
Richard Smithf7514452014-10-30 21:02:37 +0000692 } else {
693 llvm_unreachable("Unknown initializer type");
694 }
695 dumpStmt(Init->getInit());
696 });
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000697}
698
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000699void ASTDumper::dumpTemplateParameters(const TemplateParameterList *TPL) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000700 if (!TPL)
701 return;
702
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000703 for (TemplateParameterList::const_iterator I = TPL->begin(), E = TPL->end();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000704 I != E; ++I)
705 dumpDecl(*I);
706}
707
708void ASTDumper::dumpTemplateArgumentListInfo(
709 const TemplateArgumentListInfo &TALI) {
Richard Smithf7514452014-10-30 21:02:37 +0000710 for (unsigned i = 0, e = TALI.size(); i < e; ++i)
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000711 dumpTemplateArgumentLoc(TALI[i]);
712}
713
714void ASTDumper::dumpTemplateArgumentLoc(const TemplateArgumentLoc &A) {
715 dumpTemplateArgument(A.getArgument(), A.getSourceRange());
716}
717
718void ASTDumper::dumpTemplateArgumentList(const TemplateArgumentList &TAL) {
719 for (unsigned i = 0, e = TAL.size(); i < e; ++i)
720 dumpTemplateArgument(TAL[i]);
721}
722
723void ASTDumper::dumpTemplateArgument(const TemplateArgument &A, SourceRange R) {
Richard Smithf7514452014-10-30 21:02:37 +0000724 dumpChild([=] {
725 OS << "TemplateArgument";
726 if (R.isValid())
Stephen Kellyd8744a72018-12-05 21:12:39 +0000727 NodeDumper.dumpSourceRange(R);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000728
Richard Smithf7514452014-10-30 21:02:37 +0000729 switch (A.getKind()) {
730 case TemplateArgument::Null:
731 OS << " null";
732 break;
733 case TemplateArgument::Type:
734 OS << " type";
Stephen Kellyd8744a72018-12-05 21:12:39 +0000735 NodeDumper.dumpType(A.getAsType());
Richard Smithf7514452014-10-30 21:02:37 +0000736 break;
737 case TemplateArgument::Declaration:
738 OS << " decl";
739 dumpDeclRef(A.getAsDecl());
740 break;
741 case TemplateArgument::NullPtr:
742 OS << " nullptr";
743 break;
744 case TemplateArgument::Integral:
745 OS << " integral " << A.getAsIntegral();
746 break;
747 case TemplateArgument::Template:
748 OS << " template ";
749 A.getAsTemplate().dump(OS);
750 break;
751 case TemplateArgument::TemplateExpansion:
Richard Trieu59c289f2018-08-21 22:55:26 +0000752 OS << " template expansion ";
Richard Smithf7514452014-10-30 21:02:37 +0000753 A.getAsTemplateOrTemplatePattern().dump(OS);
754 break;
755 case TemplateArgument::Expression:
756 OS << " expr";
757 dumpStmt(A.getAsExpr());
758 break;
759 case TemplateArgument::Pack:
760 OS << " pack";
761 for (TemplateArgument::pack_iterator I = A.pack_begin(), E = A.pack_end();
762 I != E; ++I)
763 dumpTemplateArgument(*I);
764 break;
Richard Trieude5cc7d2013-01-31 01:44:26 +0000765 }
Richard Smithf7514452014-10-30 21:02:37 +0000766 });
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000767}
768
Chris Lattner11e30d32007-08-30 06:17:34 +0000769//===----------------------------------------------------------------------===//
Douglas Gregor85f3f952015-07-07 03:57:15 +0000770// Objective-C Utilities
771//===----------------------------------------------------------------------===//
772void ASTDumper::dumpObjCTypeParamList(const ObjCTypeParamList *typeParams) {
773 if (!typeParams)
774 return;
775
776 for (auto typeParam : *typeParams) {
777 dumpDecl(typeParam);
778 }
779}
780
781//===----------------------------------------------------------------------===//
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000782// Decl dumping methods.
Chris Lattnercbe4f772007-08-08 22:51:59 +0000783//===----------------------------------------------------------------------===//
784
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000785void ASTDumper::dumpDecl(const Decl *D) {
Richard Smithf7514452014-10-30 21:02:37 +0000786 dumpChild([=] {
787 if (!D) {
Stephen Kelly27e948c2018-11-29 19:30:37 +0000788 ColorScope Color(OS, ShowColors, NullColor);
Richard Smithf7514452014-10-30 21:02:37 +0000789 OS << "<<<NULL>>>";
790 return;
791 }
Mike Stump11289f42009-09-09 15:08:12 +0000792
Richard Smithf7514452014-10-30 21:02:37 +0000793 {
Stephen Kelly27e948c2018-11-29 19:30:37 +0000794 ColorScope Color(OS, ShowColors, DeclKindNameColor);
Richard Smithf7514452014-10-30 21:02:37 +0000795 OS << D->getDeclKindName() << "Decl";
796 }
Stephen Kellyd8744a72018-12-05 21:12:39 +0000797 NodeDumper.dumpPointer(D);
Richard Smithf7514452014-10-30 21:02:37 +0000798 if (D->getLexicalDeclContext() != D->getDeclContext())
799 OS << " parent " << cast<Decl>(D->getDeclContext());
800 dumpPreviousDecl(OS, D);
Stephen Kellyd8744a72018-12-05 21:12:39 +0000801 NodeDumper.dumpSourceRange(D->getSourceRange());
Richard Smithf7514452014-10-30 21:02:37 +0000802 OS << ' ';
Stephen Kellyd8744a72018-12-05 21:12:39 +0000803 NodeDumper.dumpLocation(D->getLocation());
Richard Smith26342f92017-05-17 00:24:14 +0000804 if (D->isFromASTFile())
805 OS << " imported";
806 if (Module *M = D->getOwningModule())
Richard Smithf7514452014-10-30 21:02:37 +0000807 OS << " in " << M->getFullModuleName();
Richard Smitha2eb4092015-06-22 18:47:01 +0000808 if (auto *ND = dyn_cast<NamedDecl>(D))
809 for (Module *M : D->getASTContext().getModulesWithMergedDefinition(
810 const_cast<NamedDecl *>(ND)))
811 dumpChild([=] { OS << "also in " << M->getFullModuleName(); });
Richard Smithf7514452014-10-30 21:02:37 +0000812 if (const NamedDecl *ND = dyn_cast<NamedDecl>(D))
813 if (ND->isHidden())
814 OS << " hidden";
815 if (D->isImplicit())
816 OS << " implicit";
817 if (D->isUsed())
818 OS << " used";
819 else if (D->isThisDeclarationReferenced())
820 OS << " referenced";
821 if (D->isInvalidDecl())
822 OS << " invalid";
Hans Wennborg76b00532014-12-05 22:38:57 +0000823 if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
824 if (FD->isConstexpr())
825 OS << " constexpr";
826
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000827
Richard Smithf7514452014-10-30 21:02:37 +0000828 ConstDeclVisitor<ASTDumper>::Visit(D);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000829
Richard Smithf7514452014-10-30 21:02:37 +0000830 for (Decl::attr_iterator I = D->attr_begin(), E = D->attr_end(); I != E;
831 ++I)
832 dumpAttr(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000833
Richard Smithf7514452014-10-30 21:02:37 +0000834 if (const FullComment *Comment =
835 D->getASTContext().getLocalCommentForDeclUncached(D))
836 dumpFullComment(Comment);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000837
Richard Smithf7514452014-10-30 21:02:37 +0000838 // Decls within functions are visited by the body.
839 if (!isa<FunctionDecl>(*D) && !isa<ObjCMethodDecl>(*D) &&
840 hasNodes(dyn_cast<DeclContext>(D)))
841 dumpDeclContext(cast<DeclContext>(D));
842 });
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000843}
844
Stephen Kellyd8744a72018-12-05 21:12:39 +0000845void ASTDumper::VisitLabelDecl(const LabelDecl *D) { NodeDumper.dumpName(D); }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000846
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000847void ASTDumper::VisitTypedefDecl(const TypedefDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +0000848 NodeDumper.dumpName(D);
849 NodeDumper.dumpType(D->getUnderlyingType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000850 if (D->isModulePrivate())
851 OS << " __module_private__";
Richard Smithba3a4f92016-01-12 21:59:26 +0000852 dumpTypeAsChild(D->getUnderlyingType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000853}
854
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000855void ASTDumper::VisitEnumDecl(const EnumDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000856 if (D->isScoped()) {
857 if (D->isScopedUsingClassTag())
858 OS << " class";
859 else
860 OS << " struct";
861 }
Stephen Kellyd8744a72018-12-05 21:12:39 +0000862 NodeDumper.dumpName(D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000863 if (D->isModulePrivate())
864 OS << " __module_private__";
865 if (D->isFixed())
Stephen Kellyd8744a72018-12-05 21:12:39 +0000866 NodeDumper.dumpType(D->getIntegerType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000867}
868
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000869void ASTDumper::VisitRecordDecl(const RecordDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000870 OS << ' ' << D->getKindName();
Stephen Kellyd8744a72018-12-05 21:12:39 +0000871 NodeDumper.dumpName(D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000872 if (D->isModulePrivate())
873 OS << " __module_private__";
Richard Smith99bc1b92013-08-30 05:32:29 +0000874 if (D->isCompleteDefinition())
875 OS << " definition";
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000876}
877
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000878void ASTDumper::VisitEnumConstantDecl(const EnumConstantDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +0000879 NodeDumper.dumpName(D);
880 NodeDumper.dumpType(D->getType());
Richard Smithf7514452014-10-30 21:02:37 +0000881 if (const Expr *Init = D->getInitExpr())
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000882 dumpStmt(Init);
883}
884
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000885void ASTDumper::VisitIndirectFieldDecl(const IndirectFieldDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +0000886 NodeDumper.dumpName(D);
887 NodeDumper.dumpType(D->getType());
Richard Smithdcc2c452014-03-17 23:00:06 +0000888
Richard Smith8aa49222014-03-18 00:35:12 +0000889 for (auto *Child : D->chain())
Richard Smithf7514452014-10-30 21:02:37 +0000890 dumpDeclRef(Child);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000891}
892
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000893void ASTDumper::VisitFunctionDecl(const FunctionDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +0000894 NodeDumper.dumpName(D);
895 NodeDumper.dumpType(D->getType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000896
Rafael Espindola6ae7e502013-04-03 19:27:57 +0000897 StorageClass SC = D->getStorageClass();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000898 if (SC != SC_None)
899 OS << ' ' << VarDecl::getStorageClassSpecifierString(SC);
900 if (D->isInlineSpecified())
901 OS << " inline";
902 if (D->isVirtualAsWritten())
903 OS << " virtual";
904 if (D->isModulePrivate())
905 OS << " __module_private__";
906
907 if (D->isPure())
908 OS << " pure";
Richard Smith5a2e6b92016-11-21 23:43:54 +0000909 if (D->isDefaulted()) {
910 OS << " default";
911 if (D->isDeleted())
912 OS << "_delete";
913 }
914 if (D->isDeletedAsWritten())
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000915 OS << " delete";
Richard Smith5a2e6b92016-11-21 23:43:54 +0000916 if (D->isTrivial())
917 OS << " trivial";
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000918
Richard Smithadaa0152013-05-17 02:09:46 +0000919 if (const FunctionProtoType *FPT = D->getType()->getAs<FunctionProtoType>()) {
920 FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo();
Richard Smith8acb4282014-07-31 21:57:55 +0000921 switch (EPI.ExceptionSpec.Type) {
Richard Smithadaa0152013-05-17 02:09:46 +0000922 default: break;
923 case EST_Unevaluated:
Richard Smith8acb4282014-07-31 21:57:55 +0000924 OS << " noexcept-unevaluated " << EPI.ExceptionSpec.SourceDecl;
Richard Smithadaa0152013-05-17 02:09:46 +0000925 break;
926 case EST_Uninstantiated:
Richard Smith8acb4282014-07-31 21:57:55 +0000927 OS << " noexcept-uninstantiated " << EPI.ExceptionSpec.SourceTemplate;
Richard Smithadaa0152013-05-17 02:09:46 +0000928 break;
929 }
930 }
931
Richard Smithf7514452014-10-30 21:02:37 +0000932 if (const FunctionTemplateSpecializationInfo *FTSI =
933 D->getTemplateSpecializationInfo())
Richard Trieude5cc7d2013-01-31 01:44:26 +0000934 dumpTemplateArgumentList(*FTSI->TemplateArguments);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000935
Richard Smith8a639892015-01-24 01:07:20 +0000936 if (!D->param_begin() && D->getNumParams())
937 dumpChild([=] { OS << "<<NULL params x " << D->getNumParams() << ">>"; });
938 else
David Majnemera3debed2016-06-24 05:33:44 +0000939 for (const ParmVarDecl *Parameter : D->parameters())
940 dumpDecl(Parameter);
Richard Smithf7514452014-10-30 21:02:37 +0000941
942 if (const CXXConstructorDecl *C = dyn_cast<CXXConstructorDecl>(D))
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000943 for (CXXConstructorDecl::init_const_iterator I = C->init_begin(),
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000944 E = C->init_end();
Richard Smithf7514452014-10-30 21:02:37 +0000945 I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000946 dumpCXXCtorInitializer(*I);
947
Lenar Safin9ae21552017-07-29 20:42:58 +0000948 if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(D)) {
Lang Hames19e07e12017-06-20 21:06:00 +0000949 if (MD->size_overridden_methods() != 0) {
Aaron Ballman8c208282017-12-21 21:42:42 +0000950 auto dumpOverride = [=](const CXXMethodDecl *D) {
951 SplitQualType T_split = D->getType().split();
952 OS << D << " " << D->getParent()->getName()
953 << "::" << D->getNameAsString() << " '"
954 << QualType::getAsString(T_split, PrintPolicy) << "'";
955 };
Lang Hames19e07e12017-06-20 21:06:00 +0000956
957 dumpChild([=] {
Benjamin Krameracfa3392017-12-17 23:52:45 +0000958 auto Overrides = MD->overridden_methods();
Lang Hames19e07e12017-06-20 21:06:00 +0000959 OS << "Overrides: [ ";
Benjamin Krameracfa3392017-12-17 23:52:45 +0000960 dumpOverride(*Overrides.begin());
Lang Hames19e07e12017-06-20 21:06:00 +0000961 for (const auto *Override :
Benjamin Krameracfa3392017-12-17 23:52:45 +0000962 llvm::make_range(Overrides.begin() + 1, Overrides.end())) {
Lenar Safin9ae21552017-07-29 20:42:58 +0000963 OS << ", ";
Lang Hames19e07e12017-06-20 21:06:00 +0000964 dumpOverride(Override);
Lenar Safin9ae21552017-07-29 20:42:58 +0000965 }
Lang Hames19e07e12017-06-20 21:06:00 +0000966 OS << " ]";
967 });
968 }
Lenar Safin9ae21552017-07-29 20:42:58 +0000969 }
Lang Hames19e07e12017-06-20 21:06:00 +0000970
Richard Smithf7514452014-10-30 21:02:37 +0000971 if (D->doesThisDeclarationHaveABody())
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000972 dumpStmt(D->getBody());
973}
974
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000975void ASTDumper::VisitFieldDecl(const FieldDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +0000976 NodeDumper.dumpName(D);
977 NodeDumper.dumpType(D->getType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000978 if (D->isMutable())
979 OS << " mutable";
980 if (D->isModulePrivate())
981 OS << " __module_private__";
Richard Trieude5cc7d2013-01-31 01:44:26 +0000982
Richard Smithf7514452014-10-30 21:02:37 +0000983 if (D->isBitField())
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000984 dumpStmt(D->getBitWidth());
Richard Smithf7514452014-10-30 21:02:37 +0000985 if (Expr *Init = D->getInClassInitializer())
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000986 dumpStmt(Init);
987}
988
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000989void ASTDumper::VisitVarDecl(const VarDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +0000990 NodeDumper.dumpName(D);
991 NodeDumper.dumpType(D->getType());
Rafael Espindola6ae7e502013-04-03 19:27:57 +0000992 StorageClass SC = D->getStorageClass();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000993 if (SC != SC_None)
994 OS << ' ' << VarDecl::getStorageClassSpecifierString(SC);
Richard Smithfd3834f2013-04-13 02:43:54 +0000995 switch (D->getTLSKind()) {
996 case VarDecl::TLS_None: break;
997 case VarDecl::TLS_Static: OS << " tls"; break;
998 case VarDecl::TLS_Dynamic: OS << " tls_dynamic"; break;
999 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001000 if (D->isModulePrivate())
1001 OS << " __module_private__";
1002 if (D->isNRVOVariable())
1003 OS << " nrvo";
Richard Smith62f19e72016-06-25 00:15:56 +00001004 if (D->isInline())
1005 OS << " inline";
1006 if (D->isConstexpr())
1007 OS << " constexpr";
Richard Trieude5cc7d2013-01-31 01:44:26 +00001008 if (D->hasInit()) {
Richard Smithd9967cc2014-07-10 22:54:03 +00001009 switch (D->getInitStyle()) {
1010 case VarDecl::CInit: OS << " cinit"; break;
1011 case VarDecl::CallInit: OS << " callinit"; break;
1012 case VarDecl::ListInit: OS << " listinit"; break;
1013 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001014 dumpStmt(D->getInit());
Richard Trieude5cc7d2013-01-31 01:44:26 +00001015 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001016}
1017
Richard Smithbdb84f32016-07-22 23:36:59 +00001018void ASTDumper::VisitDecompositionDecl(const DecompositionDecl *D) {
1019 VisitVarDecl(D);
1020 for (auto *B : D->bindings())
1021 dumpDecl(B);
1022}
1023
Richard Smith7873de02016-08-11 22:25:46 +00001024void ASTDumper::VisitBindingDecl(const BindingDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +00001025 NodeDumper.dumpName(D);
1026 NodeDumper.dumpType(D->getType());
Richard Smith7873de02016-08-11 22:25:46 +00001027 if (auto *E = D->getBinding())
1028 dumpStmt(E);
1029}
1030
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001031void ASTDumper::VisitFileScopeAsmDecl(const FileScopeAsmDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001032 dumpStmt(D->getAsmString());
1033}
1034
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001035void ASTDumper::VisitImportDecl(const ImportDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001036 OS << ' ' << D->getImportedModule()->getFullModuleName();
1037}
1038
Nico Weber66220292016-03-02 17:28:48 +00001039void ASTDumper::VisitPragmaCommentDecl(const PragmaCommentDecl *D) {
1040 OS << ' ';
1041 switch (D->getCommentKind()) {
1042 case PCK_Unknown: llvm_unreachable("unexpected pragma comment kind");
1043 case PCK_Compiler: OS << "compiler"; break;
1044 case PCK_ExeStr: OS << "exestr"; break;
1045 case PCK_Lib: OS << "lib"; break;
1046 case PCK_Linker: OS << "linker"; break;
1047 case PCK_User: OS << "user"; break;
1048 }
1049 StringRef Arg = D->getArg();
1050 if (!Arg.empty())
1051 OS << " \"" << Arg << "\"";
1052}
1053
Nico Webercbbaeb12016-03-02 19:28:54 +00001054void ASTDumper::VisitPragmaDetectMismatchDecl(
1055 const PragmaDetectMismatchDecl *D) {
1056 OS << " \"" << D->getName() << "\" \"" << D->getValue() << "\"";
1057}
1058
Alexey Bataev958b9e72016-03-31 09:30:50 +00001059void ASTDumper::VisitCapturedDecl(const CapturedDecl *D) {
1060 dumpStmt(D->getBody());
1061}
1062
1063//===----------------------------------------------------------------------===//
1064// OpenMP Declarations
1065//===----------------------------------------------------------------------===//
1066
1067void ASTDumper::VisitOMPThreadPrivateDecl(const OMPThreadPrivateDecl *D) {
1068 for (auto *E : D->varlists())
1069 dumpStmt(E);
1070}
1071
1072void ASTDumper::VisitOMPDeclareReductionDecl(const OMPDeclareReductionDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +00001073 NodeDumper.dumpName(D);
1074 NodeDumper.dumpType(D->getType());
Alexey Bataev958b9e72016-03-31 09:30:50 +00001075 OS << " combiner";
1076 dumpStmt(D->getCombiner());
1077 if (auto *Initializer = D->getInitializer()) {
1078 OS << " initializer";
Alexey Bataev070f43a2017-09-06 14:49:58 +00001079 switch (D->getInitializerKind()) {
1080 case OMPDeclareReductionDecl::DirectInit:
1081 OS << " omp_priv = ";
1082 break;
1083 case OMPDeclareReductionDecl::CopyInit:
1084 OS << " omp_priv ()";
1085 break;
1086 case OMPDeclareReductionDecl::CallInit:
1087 break;
1088 }
Alexey Bataev958b9e72016-03-31 09:30:50 +00001089 dumpStmt(Initializer);
1090 }
1091}
1092
Kelvin Li1408f912018-09-26 04:28:39 +00001093void ASTDumper::VisitOMPRequiresDecl(const OMPRequiresDecl *D) {
1094 for (auto *C : D->clauselists()) {
1095 dumpChild([=] {
1096 if (!C) {
Stephen Kelly27e948c2018-11-29 19:30:37 +00001097 ColorScope Color(OS, ShowColors, NullColor);
Kelvin Li1408f912018-09-26 04:28:39 +00001098 OS << "<<<NULL>>> OMPClause";
1099 return;
1100 }
1101 {
Stephen Kelly27e948c2018-11-29 19:30:37 +00001102 ColorScope Color(OS, ShowColors, AttrColor);
Kelvin Li1408f912018-09-26 04:28:39 +00001103 StringRef ClauseName(getOpenMPClauseName(C->getClauseKind()));
1104 OS << "OMP" << ClauseName.substr(/*Start=*/0, /*N=*/1).upper()
1105 << ClauseName.drop_front() << "Clause";
1106 }
Stephen Kellyd8744a72018-12-05 21:12:39 +00001107 NodeDumper.dumpPointer(C);
1108 NodeDumper.dumpSourceRange(SourceRange(C->getBeginLoc(), C->getEndLoc()));
Kelvin Li1408f912018-09-26 04:28:39 +00001109 });
1110 }
1111}
1112
Alexey Bataev958b9e72016-03-31 09:30:50 +00001113void ASTDumper::VisitOMPCapturedExprDecl(const OMPCapturedExprDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +00001114 NodeDumper.dumpName(D);
1115 NodeDumper.dumpType(D->getType());
Alexey Bataev958b9e72016-03-31 09:30:50 +00001116 dumpStmt(D->getInit());
1117}
Nico Webercbbaeb12016-03-02 19:28:54 +00001118
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001119//===----------------------------------------------------------------------===//
1120// C++ Declarations
1121//===----------------------------------------------------------------------===//
1122
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001123void ASTDumper::VisitNamespaceDecl(const NamespaceDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +00001124 NodeDumper.dumpName(D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001125 if (D->isInline())
1126 OS << " inline";
1127 if (!D->isOriginalNamespace())
1128 dumpDeclRef(D->getOriginalNamespace(), "original");
1129}
1130
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001131void ASTDumper::VisitUsingDirectiveDecl(const UsingDirectiveDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001132 OS << ' ';
Stephen Kellyd8744a72018-12-05 21:12:39 +00001133 NodeDumper.dumpBareDeclRef(D->getNominatedNamespace());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001134}
1135
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001136void ASTDumper::VisitNamespaceAliasDecl(const NamespaceAliasDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +00001137 NodeDumper.dumpName(D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001138 dumpDeclRef(D->getAliasedNamespace());
1139}
1140
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001141void ASTDumper::VisitTypeAliasDecl(const TypeAliasDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +00001142 NodeDumper.dumpName(D);
1143 NodeDumper.dumpType(D->getUnderlyingType());
Richard Smithba3a4f92016-01-12 21:59:26 +00001144 dumpTypeAsChild(D->getUnderlyingType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001145}
1146
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001147void ASTDumper::VisitTypeAliasTemplateDecl(const TypeAliasTemplateDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +00001148 NodeDumper.dumpName(D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001149 dumpTemplateParameters(D->getTemplateParameters());
1150 dumpDecl(D->getTemplatedDecl());
1151}
1152
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001153void ASTDumper::VisitCXXRecordDecl(const CXXRecordDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001154 VisitRecordDecl(D);
1155 if (!D->isCompleteDefinition())
1156 return;
1157
Richard Smithdfc4bff2017-09-22 00:11:15 +00001158 dumpChild([=] {
1159 {
Stephen Kelly27e948c2018-11-29 19:30:37 +00001160 ColorScope Color(OS, ShowColors, DeclKindNameColor);
Richard Smithdfc4bff2017-09-22 00:11:15 +00001161 OS << "DefinitionData";
1162 }
1163#define FLAG(fn, name) if (D->fn()) OS << " " #name;
1164 FLAG(isParsingBaseSpecifiers, parsing_base_specifiers);
1165
1166 FLAG(isGenericLambda, generic);
1167 FLAG(isLambda, lambda);
1168
1169 FLAG(canPassInRegisters, pass_in_registers);
1170 FLAG(isEmpty, empty);
1171 FLAG(isAggregate, aggregate);
1172 FLAG(isStandardLayout, standard_layout);
1173 FLAG(isTriviallyCopyable, trivially_copyable);
1174 FLAG(isPOD, pod);
1175 FLAG(isTrivial, trivial);
1176 FLAG(isPolymorphic, polymorphic);
1177 FLAG(isAbstract, abstract);
1178 FLAG(isLiteral, literal);
1179
1180 FLAG(hasUserDeclaredConstructor, has_user_declared_ctor);
1181 FLAG(hasConstexprNonCopyMoveConstructor, has_constexpr_non_copy_move_ctor);
1182 FLAG(hasMutableFields, has_mutable_fields);
1183 FLAG(hasVariantMembers, has_variant_members);
1184 FLAG(allowConstDefaultInit, can_const_default_init);
1185
1186 dumpChild([=] {
1187 {
Stephen Kelly27e948c2018-11-29 19:30:37 +00001188 ColorScope Color(OS, ShowColors, DeclKindNameColor);
Richard Smithdfc4bff2017-09-22 00:11:15 +00001189 OS << "DefaultConstructor";
1190 }
1191 FLAG(hasDefaultConstructor, exists);
1192 FLAG(hasTrivialDefaultConstructor, trivial);
1193 FLAG(hasNonTrivialDefaultConstructor, non_trivial);
1194 FLAG(hasUserProvidedDefaultConstructor, user_provided);
1195 FLAG(hasConstexprDefaultConstructor, constexpr);
1196 FLAG(needsImplicitDefaultConstructor, needs_implicit);
1197 FLAG(defaultedDefaultConstructorIsConstexpr, defaulted_is_constexpr);
1198 });
1199
1200 dumpChild([=] {
1201 {
Stephen Kelly27e948c2018-11-29 19:30:37 +00001202 ColorScope Color(OS, ShowColors, DeclKindNameColor);
Richard Smithdfc4bff2017-09-22 00:11:15 +00001203 OS << "CopyConstructor";
1204 }
1205 FLAG(hasSimpleCopyConstructor, simple);
1206 FLAG(hasTrivialCopyConstructor, trivial);
1207 FLAG(hasNonTrivialCopyConstructor, non_trivial);
1208 FLAG(hasUserDeclaredCopyConstructor, user_declared);
1209 FLAG(hasCopyConstructorWithConstParam, has_const_param);
1210 FLAG(needsImplicitCopyConstructor, needs_implicit);
1211 FLAG(needsOverloadResolutionForCopyConstructor,
1212 needs_overload_resolution);
1213 if (!D->needsOverloadResolutionForCopyConstructor())
1214 FLAG(defaultedCopyConstructorIsDeleted, defaulted_is_deleted);
1215 FLAG(implicitCopyConstructorHasConstParam, implicit_has_const_param);
1216 });
1217
1218 dumpChild([=] {
1219 {
Stephen Kelly27e948c2018-11-29 19:30:37 +00001220 ColorScope Color(OS, ShowColors, DeclKindNameColor);
Richard Smithdfc4bff2017-09-22 00:11:15 +00001221 OS << "MoveConstructor";
1222 }
1223 FLAG(hasMoveConstructor, exists);
1224 FLAG(hasSimpleMoveConstructor, simple);
1225 FLAG(hasTrivialMoveConstructor, trivial);
1226 FLAG(hasNonTrivialMoveConstructor, non_trivial);
1227 FLAG(hasUserDeclaredMoveConstructor, user_declared);
1228 FLAG(needsImplicitMoveConstructor, needs_implicit);
1229 FLAG(needsOverloadResolutionForMoveConstructor,
1230 needs_overload_resolution);
1231 if (!D->needsOverloadResolutionForMoveConstructor())
1232 FLAG(defaultedMoveConstructorIsDeleted, defaulted_is_deleted);
1233 });
1234
1235 dumpChild([=] {
1236 {
Stephen Kelly27e948c2018-11-29 19:30:37 +00001237 ColorScope Color(OS, ShowColors, DeclKindNameColor);
Richard Smithdfc4bff2017-09-22 00:11:15 +00001238 OS << "CopyAssignment";
1239 }
1240 FLAG(hasTrivialCopyAssignment, trivial);
1241 FLAG(hasNonTrivialCopyAssignment, non_trivial);
1242 FLAG(hasCopyAssignmentWithConstParam, has_const_param);
1243 FLAG(hasUserDeclaredCopyAssignment, user_declared);
1244 FLAG(needsImplicitCopyAssignment, needs_implicit);
1245 FLAG(needsOverloadResolutionForCopyAssignment, needs_overload_resolution);
1246 FLAG(implicitCopyAssignmentHasConstParam, implicit_has_const_param);
1247 });
1248
1249 dumpChild([=] {
1250 {
Stephen Kelly27e948c2018-11-29 19:30:37 +00001251 ColorScope Color(OS, ShowColors, DeclKindNameColor);
Richard Smithdfc4bff2017-09-22 00:11:15 +00001252 OS << "MoveAssignment";
1253 }
1254 FLAG(hasMoveAssignment, exists);
1255 FLAG(hasSimpleMoveAssignment, simple);
1256 FLAG(hasTrivialMoveAssignment, trivial);
1257 FLAG(hasNonTrivialMoveAssignment, non_trivial);
1258 FLAG(hasUserDeclaredMoveAssignment, user_declared);
1259 FLAG(needsImplicitMoveAssignment, needs_implicit);
1260 FLAG(needsOverloadResolutionForMoveAssignment, needs_overload_resolution);
1261 });
1262
1263 dumpChild([=] {
1264 {
Stephen Kelly27e948c2018-11-29 19:30:37 +00001265 ColorScope Color(OS, ShowColors, DeclKindNameColor);
Richard Smithdfc4bff2017-09-22 00:11:15 +00001266 OS << "Destructor";
1267 }
1268 FLAG(hasSimpleDestructor, simple);
1269 FLAG(hasIrrelevantDestructor, irrelevant);
1270 FLAG(hasTrivialDestructor, trivial);
1271 FLAG(hasNonTrivialDestructor, non_trivial);
1272 FLAG(hasUserDeclaredDestructor, user_declared);
1273 FLAG(needsImplicitDestructor, needs_implicit);
1274 FLAG(needsOverloadResolutionForDestructor, needs_overload_resolution);
1275 if (!D->needsOverloadResolutionForDestructor())
1276 FLAG(defaultedDestructorIsDeleted, defaulted_is_deleted);
1277 });
1278 });
1279
Aaron Ballman574705e2014-03-13 15:41:46 +00001280 for (const auto &I : D->bases()) {
Richard Smithf7514452014-10-30 21:02:37 +00001281 dumpChild([=] {
1282 if (I.isVirtual())
1283 OS << "virtual ";
Stephen Kellyd8744a72018-12-05 21:12:39 +00001284 NodeDumper.dumpAccessSpecifier(I.getAccessSpecifier());
1285 NodeDumper.dumpType(I.getType());
Richard Smithf7514452014-10-30 21:02:37 +00001286 if (I.isPackExpansion())
1287 OS << "...";
1288 });
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001289 }
1290}
1291
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001292void ASTDumper::VisitStaticAssertDecl(const StaticAssertDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001293 dumpStmt(D->getAssertExpr());
1294 dumpStmt(D->getMessage());
1295}
1296
Richard Smithcbdf7332014-03-18 02:07:28 +00001297template<typename SpecializationDecl>
Richard Smithf7514452014-10-30 21:02:37 +00001298void ASTDumper::VisitTemplateDeclSpecialization(const SpecializationDecl *D,
Richard Smithcbdf7332014-03-18 02:07:28 +00001299 bool DumpExplicitInst,
1300 bool DumpRefOnly) {
1301 bool DumpedAny = false;
1302 for (auto *RedeclWithBadType : D->redecls()) {
1303 // FIXME: The redecls() range sometimes has elements of a less-specific
1304 // type. (In particular, ClassTemplateSpecializationDecl::redecls() gives
1305 // us TagDecls, and should give CXXRecordDecls).
1306 auto *Redecl = dyn_cast<SpecializationDecl>(RedeclWithBadType);
1307 if (!Redecl) {
1308 // Found the injected-class-name for a class template. This will be dumped
1309 // as part of its surrounding class so we don't need to dump it here.
1310 assert(isa<CXXRecordDecl>(RedeclWithBadType) &&
1311 "expected an injected-class-name");
1312 continue;
1313 }
1314
1315 switch (Redecl->getTemplateSpecializationKind()) {
1316 case TSK_ExplicitInstantiationDeclaration:
1317 case TSK_ExplicitInstantiationDefinition:
1318 if (!DumpExplicitInst)
1319 break;
Adrian Prantlf3b3ccd2017-12-19 22:06:11 +00001320 LLVM_FALLTHROUGH;
Richard Smithcbdf7332014-03-18 02:07:28 +00001321 case TSK_Undeclared:
1322 case TSK_ImplicitInstantiation:
Richard Smithf7514452014-10-30 21:02:37 +00001323 if (DumpRefOnly)
1324 dumpDeclRef(Redecl);
1325 else
1326 dumpDecl(Redecl);
Richard Smithcbdf7332014-03-18 02:07:28 +00001327 DumpedAny = true;
1328 break;
1329 case TSK_ExplicitSpecialization:
1330 break;
1331 }
1332 }
1333
1334 // Ensure we dump at least one decl for each specialization.
1335 if (!DumpedAny)
Richard Smithf7514452014-10-30 21:02:37 +00001336 dumpDeclRef(D);
Richard Smithcbdf7332014-03-18 02:07:28 +00001337}
1338
Richard Smith20ade552014-03-17 23:34:53 +00001339template<typename TemplateDecl>
1340void ASTDumper::VisitTemplateDecl(const TemplateDecl *D,
1341 bool DumpExplicitInst) {
Stephen Kellyd8744a72018-12-05 21:12:39 +00001342 NodeDumper.dumpName(D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001343 dumpTemplateParameters(D->getTemplateParameters());
Richard Smithdcc2c452014-03-17 23:00:06 +00001344
Richard Smithf7514452014-10-30 21:02:37 +00001345 dumpDecl(D->getTemplatedDecl());
Richard Smithdcc2c452014-03-17 23:00:06 +00001346
Richard Smithcbdf7332014-03-18 02:07:28 +00001347 for (auto *Child : D->specializations())
Richard Smithf7514452014-10-30 21:02:37 +00001348 VisitTemplateDeclSpecialization(Child, DumpExplicitInst,
Richard Smithcbdf7332014-03-18 02:07:28 +00001349 !D->isCanonicalDecl());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001350}
1351
Richard Smith20ade552014-03-17 23:34:53 +00001352void ASTDumper::VisitFunctionTemplateDecl(const FunctionTemplateDecl *D) {
1353 // FIXME: We don't add a declaration of a function template specialization
1354 // to its context when it's explicitly instantiated, so dump explicit
1355 // instantiations when we dump the template itself.
1356 VisitTemplateDecl(D, true);
1357}
1358
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001359void ASTDumper::VisitClassTemplateDecl(const ClassTemplateDecl *D) {
Richard Smith20ade552014-03-17 23:34:53 +00001360 VisitTemplateDecl(D, false);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001361}
1362
1363void ASTDumper::VisitClassTemplateSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001364 const ClassTemplateSpecializationDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001365 VisitCXXRecordDecl(D);
1366 dumpTemplateArgumentList(D->getTemplateArgs());
1367}
1368
1369void ASTDumper::VisitClassTemplatePartialSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001370 const ClassTemplatePartialSpecializationDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001371 VisitClassTemplateSpecializationDecl(D);
1372 dumpTemplateParameters(D->getTemplateParameters());
1373}
1374
1375void ASTDumper::VisitClassScopeFunctionSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001376 const ClassScopeFunctionSpecializationDecl *D) {
Richard Smithc660c8f2018-03-16 13:36:56 +00001377 dumpDecl(D->getSpecialization());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001378 if (D->hasExplicitTemplateArgs())
1379 dumpTemplateArgumentListInfo(D->templateArgs());
1380}
1381
Richard Smithd25789a2013-09-18 01:36:02 +00001382void ASTDumper::VisitVarTemplateDecl(const VarTemplateDecl *D) {
Richard Smith20ade552014-03-17 23:34:53 +00001383 VisitTemplateDecl(D, false);
Richard Smithd25789a2013-09-18 01:36:02 +00001384}
1385
David Majnemerd9b1a4f2015-11-04 03:40:30 +00001386void ASTDumper::VisitBuiltinTemplateDecl(const BuiltinTemplateDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +00001387 NodeDumper.dumpName(D);
David Majnemerd9b1a4f2015-11-04 03:40:30 +00001388 dumpTemplateParameters(D->getTemplateParameters());
1389}
1390
Richard Smithd25789a2013-09-18 01:36:02 +00001391void ASTDumper::VisitVarTemplateSpecializationDecl(
1392 const VarTemplateSpecializationDecl *D) {
1393 dumpTemplateArgumentList(D->getTemplateArgs());
1394 VisitVarDecl(D);
1395}
1396
1397void ASTDumper::VisitVarTemplatePartialSpecializationDecl(
1398 const VarTemplatePartialSpecializationDecl *D) {
1399 dumpTemplateParameters(D->getTemplateParameters());
1400 VisitVarTemplateSpecializationDecl(D);
1401}
1402
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001403void ASTDumper::VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001404 if (D->wasDeclaredWithTypename())
1405 OS << " typename";
1406 else
1407 OS << " class";
Richard Smith1832a022017-02-21 02:04:03 +00001408 OS << " depth " << D->getDepth() << " index " << D->getIndex();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001409 if (D->isParameterPack())
1410 OS << " ...";
Stephen Kellyd8744a72018-12-05 21:12:39 +00001411 NodeDumper.dumpName(D);
Richard Smithf7514452014-10-30 21:02:37 +00001412 if (D->hasDefaultArgument())
Richard Smithecf74ff2014-03-23 20:50:39 +00001413 dumpTemplateArgument(D->getDefaultArgument());
Richard Smithc4577662018-09-12 02:13:47 +00001414 if (auto *From = D->getDefaultArgStorage().getInheritedFrom())
1415 dumpDeclRef(From, D->defaultArgumentWasInherited() ? "inherited from"
1416 : "previous");
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001417}
1418
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001419void ASTDumper::VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +00001420 NodeDumper.dumpType(D->getType());
Richard Smith1832a022017-02-21 02:04:03 +00001421 OS << " depth " << D->getDepth() << " index " << D->getIndex();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001422 if (D->isParameterPack())
1423 OS << " ...";
Stephen Kellyd8744a72018-12-05 21:12:39 +00001424 NodeDumper.dumpName(D);
Richard Smithf7514452014-10-30 21:02:37 +00001425 if (D->hasDefaultArgument())
Richard Smithecf74ff2014-03-23 20:50:39 +00001426 dumpTemplateArgument(D->getDefaultArgument());
Richard Smithc4577662018-09-12 02:13:47 +00001427 if (auto *From = D->getDefaultArgStorage().getInheritedFrom())
1428 dumpDeclRef(From, D->defaultArgumentWasInherited() ? "inherited from"
1429 : "previous");
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001430}
1431
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001432void ASTDumper::VisitTemplateTemplateParmDecl(
1433 const TemplateTemplateParmDecl *D) {
Richard Smith1832a022017-02-21 02:04:03 +00001434 OS << " depth " << D->getDepth() << " index " << D->getIndex();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001435 if (D->isParameterPack())
1436 OS << " ...";
Stephen Kellyd8744a72018-12-05 21:12:39 +00001437 NodeDumper.dumpName(D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001438 dumpTemplateParameters(D->getTemplateParameters());
Richard Smithf7514452014-10-30 21:02:37 +00001439 if (D->hasDefaultArgument())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001440 dumpTemplateArgumentLoc(D->getDefaultArgument());
Richard Smithc4577662018-09-12 02:13:47 +00001441 if (auto *From = D->getDefaultArgStorage().getInheritedFrom())
1442 dumpDeclRef(From, D->defaultArgumentWasInherited() ? "inherited from"
1443 : "previous");
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001444}
1445
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001446void ASTDumper::VisitUsingDecl(const UsingDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001447 OS << ' ';
Dawn Perchikddd03bf2015-12-05 22:37:55 +00001448 if (D->getQualifier())
1449 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001450 OS << D->getNameAsString();
1451}
1452
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001453void ASTDumper::VisitUnresolvedUsingTypenameDecl(
1454 const UnresolvedUsingTypenameDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001455 OS << ' ';
Dawn Perchikddd03bf2015-12-05 22:37:55 +00001456 if (D->getQualifier())
1457 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001458 OS << D->getNameAsString();
1459}
1460
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001461void ASTDumper::VisitUnresolvedUsingValueDecl(const UnresolvedUsingValueDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001462 OS << ' ';
Dawn Perchikddd03bf2015-12-05 22:37:55 +00001463 if (D->getQualifier())
1464 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001465 OS << D->getNameAsString();
Stephen Kellyd8744a72018-12-05 21:12:39 +00001466 NodeDumper.dumpType(D->getType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001467}
1468
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001469void ASTDumper::VisitUsingShadowDecl(const UsingShadowDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001470 OS << ' ';
Stephen Kellyd8744a72018-12-05 21:12:39 +00001471 NodeDumper.dumpBareDeclRef(D->getTargetDecl());
Richard Smithba3a4f92016-01-12 21:59:26 +00001472 if (auto *TD = dyn_cast<TypeDecl>(D->getUnderlyingDecl()))
1473 dumpTypeAsChild(TD->getTypeForDecl());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001474}
1475
Richard Smith5179eb72016-06-28 19:03:57 +00001476void ASTDumper::VisitConstructorUsingShadowDecl(
1477 const ConstructorUsingShadowDecl *D) {
1478 if (D->constructsVirtualBase())
1479 OS << " virtual";
1480
1481 dumpChild([=] {
1482 OS << "target ";
Stephen Kellyd8744a72018-12-05 21:12:39 +00001483 NodeDumper.dumpBareDeclRef(D->getTargetDecl());
Richard Smith5179eb72016-06-28 19:03:57 +00001484 });
1485
1486 dumpChild([=] {
1487 OS << "nominated ";
Stephen Kellyd8744a72018-12-05 21:12:39 +00001488 NodeDumper.dumpBareDeclRef(D->getNominatedBaseClass());
Richard Smith5179eb72016-06-28 19:03:57 +00001489 OS << ' ';
Stephen Kellyd8744a72018-12-05 21:12:39 +00001490 NodeDumper.dumpBareDeclRef(D->getNominatedBaseClassShadowDecl());
Richard Smith5179eb72016-06-28 19:03:57 +00001491 });
1492
1493 dumpChild([=] {
1494 OS << "constructed ";
Stephen Kellyd8744a72018-12-05 21:12:39 +00001495 NodeDumper.dumpBareDeclRef(D->getConstructedBaseClass());
Richard Smith5179eb72016-06-28 19:03:57 +00001496 OS << ' ';
Stephen Kellyd8744a72018-12-05 21:12:39 +00001497 NodeDumper.dumpBareDeclRef(D->getConstructedBaseClassShadowDecl());
Richard Smith5179eb72016-06-28 19:03:57 +00001498 });
1499}
1500
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001501void ASTDumper::VisitLinkageSpecDecl(const LinkageSpecDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001502 switch (D->getLanguage()) {
1503 case LinkageSpecDecl::lang_c: OS << " C"; break;
1504 case LinkageSpecDecl::lang_cxx: OS << " C++"; break;
1505 }
1506}
1507
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001508void ASTDumper::VisitAccessSpecDecl(const AccessSpecDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001509 OS << ' ';
Stephen Kellyd8744a72018-12-05 21:12:39 +00001510 NodeDumper.dumpAccessSpecifier(D->getAccess());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001511}
1512
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001513void ASTDumper::VisitFriendDecl(const FriendDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001514 if (TypeSourceInfo *T = D->getFriendType())
Stephen Kellyd8744a72018-12-05 21:12:39 +00001515 NodeDumper.dumpType(T->getType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001516 else
1517 dumpDecl(D->getFriendDecl());
1518}
1519
1520//===----------------------------------------------------------------------===//
1521// Obj-C Declarations
1522//===----------------------------------------------------------------------===//
1523
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001524void ASTDumper::VisitObjCIvarDecl(const ObjCIvarDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +00001525 NodeDumper.dumpName(D);
1526 NodeDumper.dumpType(D->getType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001527 if (D->getSynthesize())
1528 OS << " synthesize";
1529
1530 switch (D->getAccessControl()) {
1531 case ObjCIvarDecl::None:
1532 OS << " none";
1533 break;
1534 case ObjCIvarDecl::Private:
1535 OS << " private";
1536 break;
1537 case ObjCIvarDecl::Protected:
1538 OS << " protected";
1539 break;
1540 case ObjCIvarDecl::Public:
1541 OS << " public";
1542 break;
1543 case ObjCIvarDecl::Package:
1544 OS << " package";
1545 break;
1546 }
1547}
1548
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001549void ASTDumper::VisitObjCMethodDecl(const ObjCMethodDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001550 if (D->isInstanceMethod())
1551 OS << " -";
1552 else
1553 OS << " +";
Stephen Kellyd8744a72018-12-05 21:12:39 +00001554 NodeDumper.dumpName(D);
1555 NodeDumper.dumpType(D->getReturnType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001556
Richard Trieude5cc7d2013-01-31 01:44:26 +00001557 if (D->isThisDeclarationADefinition()) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001558 dumpDeclContext(D);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001559 } else {
David Majnemera3debed2016-06-24 05:33:44 +00001560 for (const ParmVarDecl *Parameter : D->parameters())
1561 dumpDecl(Parameter);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001562 }
1563
Richard Smithf7514452014-10-30 21:02:37 +00001564 if (D->isVariadic())
1565 dumpChild([=] { OS << "..."; });
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001566
Richard Smithf7514452014-10-30 21:02:37 +00001567 if (D->hasBody())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001568 dumpStmt(D->getBody());
1569}
1570
Douglas Gregor85f3f952015-07-07 03:57:15 +00001571void ASTDumper::VisitObjCTypeParamDecl(const ObjCTypeParamDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +00001572 NodeDumper.dumpName(D);
Douglas Gregor1ac1b632015-07-07 03:58:54 +00001573 switch (D->getVariance()) {
1574 case ObjCTypeParamVariance::Invariant:
1575 break;
1576
1577 case ObjCTypeParamVariance::Covariant:
1578 OS << " covariant";
1579 break;
1580
1581 case ObjCTypeParamVariance::Contravariant:
1582 OS << " contravariant";
1583 break;
1584 }
1585
Douglas Gregor85f3f952015-07-07 03:57:15 +00001586 if (D->hasExplicitBound())
1587 OS << " bounded";
Stephen Kellyd8744a72018-12-05 21:12:39 +00001588 NodeDumper.dumpType(D->getUnderlyingType());
Douglas Gregor85f3f952015-07-07 03:57:15 +00001589}
1590
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001591void ASTDumper::VisitObjCCategoryDecl(const ObjCCategoryDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +00001592 NodeDumper.dumpName(D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001593 dumpDeclRef(D->getClassInterface());
Douglas Gregor85f3f952015-07-07 03:57:15 +00001594 dumpObjCTypeParamList(D->getTypeParamList());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001595 dumpDeclRef(D->getImplementation());
1596 for (ObjCCategoryDecl::protocol_iterator I = D->protocol_begin(),
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001597 E = D->protocol_end();
Richard Smithf7514452014-10-30 21:02:37 +00001598 I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001599 dumpDeclRef(*I);
1600}
1601
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001602void ASTDumper::VisitObjCCategoryImplDecl(const ObjCCategoryImplDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +00001603 NodeDumper.dumpName(D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001604 dumpDeclRef(D->getClassInterface());
1605 dumpDeclRef(D->getCategoryDecl());
1606}
1607
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001608void ASTDumper::VisitObjCProtocolDecl(const ObjCProtocolDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +00001609 NodeDumper.dumpName(D);
Richard Smithdcc2c452014-03-17 23:00:06 +00001610
Richard Smith7fcb35f2014-03-18 02:37:59 +00001611 for (auto *Child : D->protocols())
Richard Smithf7514452014-10-30 21:02:37 +00001612 dumpDeclRef(Child);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001613}
1614
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001615void ASTDumper::VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +00001616 NodeDumper.dumpName(D);
Douglas Gregor85f3f952015-07-07 03:57:15 +00001617 dumpObjCTypeParamList(D->getTypeParamListAsWritten());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001618 dumpDeclRef(D->getSuperClass(), "super");
Richard Smithdcc2c452014-03-17 23:00:06 +00001619
Richard Smithf7514452014-10-30 21:02:37 +00001620 dumpDeclRef(D->getImplementation());
Richard Smith7fcb35f2014-03-18 02:37:59 +00001621 for (auto *Child : D->protocols())
Richard Smithf7514452014-10-30 21:02:37 +00001622 dumpDeclRef(Child);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001623}
1624
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001625void ASTDumper::VisitObjCImplementationDecl(const ObjCImplementationDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +00001626 NodeDumper.dumpName(D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001627 dumpDeclRef(D->getSuperClass(), "super");
1628 dumpDeclRef(D->getClassInterface());
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001629 for (ObjCImplementationDecl::init_const_iterator I = D->init_begin(),
1630 E = D->init_end();
Richard Smithf7514452014-10-30 21:02:37 +00001631 I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001632 dumpCXXCtorInitializer(*I);
1633}
1634
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001635void ASTDumper::VisitObjCCompatibleAliasDecl(const ObjCCompatibleAliasDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +00001636 NodeDumper.dumpName(D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001637 dumpDeclRef(D->getClassInterface());
1638}
1639
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001640void ASTDumper::VisitObjCPropertyDecl(const ObjCPropertyDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +00001641 NodeDumper.dumpName(D);
1642 NodeDumper.dumpType(D->getType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001643
1644 if (D->getPropertyImplementation() == ObjCPropertyDecl::Required)
1645 OS << " required";
1646 else if (D->getPropertyImplementation() == ObjCPropertyDecl::Optional)
1647 OS << " optional";
1648
1649 ObjCPropertyDecl::PropertyAttributeKind Attrs = D->getPropertyAttributes();
1650 if (Attrs != ObjCPropertyDecl::OBJC_PR_noattr) {
1651 if (Attrs & ObjCPropertyDecl::OBJC_PR_readonly)
1652 OS << " readonly";
1653 if (Attrs & ObjCPropertyDecl::OBJC_PR_assign)
1654 OS << " assign";
1655 if (Attrs & ObjCPropertyDecl::OBJC_PR_readwrite)
1656 OS << " readwrite";
1657 if (Attrs & ObjCPropertyDecl::OBJC_PR_retain)
1658 OS << " retain";
1659 if (Attrs & ObjCPropertyDecl::OBJC_PR_copy)
1660 OS << " copy";
1661 if (Attrs & ObjCPropertyDecl::OBJC_PR_nonatomic)
1662 OS << " nonatomic";
1663 if (Attrs & ObjCPropertyDecl::OBJC_PR_atomic)
1664 OS << " atomic";
1665 if (Attrs & ObjCPropertyDecl::OBJC_PR_weak)
1666 OS << " weak";
1667 if (Attrs & ObjCPropertyDecl::OBJC_PR_strong)
1668 OS << " strong";
1669 if (Attrs & ObjCPropertyDecl::OBJC_PR_unsafe_unretained)
1670 OS << " unsafe_unretained";
Manman Ren387ff7f2016-01-26 18:52:43 +00001671 if (Attrs & ObjCPropertyDecl::OBJC_PR_class)
1672 OS << " class";
Richard Smithf7514452014-10-30 21:02:37 +00001673 if (Attrs & ObjCPropertyDecl::OBJC_PR_getter)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001674 dumpDeclRef(D->getGetterMethodDecl(), "getter");
Richard Smithf7514452014-10-30 21:02:37 +00001675 if (Attrs & ObjCPropertyDecl::OBJC_PR_setter)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001676 dumpDeclRef(D->getSetterMethodDecl(), "setter");
1677 }
1678}
1679
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001680void ASTDumper::VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +00001681 NodeDumper.dumpName(D->getPropertyDecl());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001682 if (D->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize)
1683 OS << " synthesize";
1684 else
1685 OS << " dynamic";
1686 dumpDeclRef(D->getPropertyDecl());
1687 dumpDeclRef(D->getPropertyIvarDecl());
1688}
1689
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001690void ASTDumper::VisitBlockDecl(const BlockDecl *D) {
David Majnemer59f77922016-06-24 04:05:48 +00001691 for (auto I : D->parameters())
Aaron Ballmanb2b8b1d2014-03-07 16:09:59 +00001692 dumpDecl(I);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001693
Richard Smithf7514452014-10-30 21:02:37 +00001694 if (D->isVariadic())
1695 dumpChild([=]{ OS << "..."; });
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001696
Richard Smithf7514452014-10-30 21:02:37 +00001697 if (D->capturesCXXThis())
1698 dumpChild([=]{ OS << "capture this"; });
1699
Aaron Ballman9371dd22014-03-14 18:34:04 +00001700 for (const auto &I : D->captures()) {
Richard Smithf7514452014-10-30 21:02:37 +00001701 dumpChild([=] {
1702 OS << "capture";
1703 if (I.isByRef())
1704 OS << " byref";
1705 if (I.isNested())
1706 OS << " nested";
1707 if (I.getVariable()) {
1708 OS << ' ';
Stephen Kellyd8744a72018-12-05 21:12:39 +00001709 NodeDumper.dumpBareDeclRef(I.getVariable());
Richard Smithf7514452014-10-30 21:02:37 +00001710 }
1711 if (I.hasCopyExpr())
1712 dumpStmt(I.getCopyExpr());
1713 });
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001714 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001715 dumpStmt(D->getBody());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001716}
1717
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001718//===----------------------------------------------------------------------===//
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001719// Stmt dumping methods.
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001720//===----------------------------------------------------------------------===//
1721
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001722void ASTDumper::dumpStmt(const Stmt *S) {
Richard Smithf7514452014-10-30 21:02:37 +00001723 dumpChild([=] {
1724 if (!S) {
Stephen Kelly27e948c2018-11-29 19:30:37 +00001725 ColorScope Color(OS, ShowColors, NullColor);
Richard Smithf7514452014-10-30 21:02:37 +00001726 OS << "<<<NULL>>>";
1727 return;
1728 }
Stephen Kellyb9d6a5e2018-12-06 23:33:27 +00001729 {
1730 ColorScope Color(OS, ShowColors, StmtColor);
1731 OS << S->getStmtClassName();
1732 }
1733 NodeDumper.dumpPointer(S);
1734 NodeDumper.dumpSourceRange(S->getSourceRange());
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001735
Richard Smithf7514452014-10-30 21:02:37 +00001736 ConstStmtVisitor<ASTDumper>::Visit(S);
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001737
Stephen Kelly91f9c9c2018-12-03 21:05:52 +00001738 // Some statements have custom mechanisms for dumping their children.
1739 if (isa<DeclStmt>(S) || isa<GenericSelectionExpr>(S)) {
1740 return;
1741 }
1742
Benjamin Kramer642f1732015-07-02 21:03:14 +00001743 for (const Stmt *SubStmt : S->children())
1744 dumpStmt(SubStmt);
Richard Smithf7514452014-10-30 21:02:37 +00001745 });
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001746}
1747
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001748void ASTDumper::VisitDeclStmt(const DeclStmt *Node) {
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001749 for (DeclStmt::const_decl_iterator I = Node->decl_begin(),
1750 E = Node->decl_end();
Richard Smithf7514452014-10-30 21:02:37 +00001751 I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001752 dumpDecl(*I);
Ted Kremenek433a4922007-12-12 06:59:42 +00001753}
1754
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001755void ASTDumper::VisitAttributedStmt(const AttributedStmt *Node) {
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001756 for (ArrayRef<const Attr *>::iterator I = Node->getAttrs().begin(),
1757 E = Node->getAttrs().end();
Richard Smithf7514452014-10-30 21:02:37 +00001758 I != E; ++I)
Alexander Kornienko5bc364e2013-01-07 17:53:08 +00001759 dumpAttr(*I);
1760}
1761
Bruno Riccib1cc94b2018-10-27 21:12:20 +00001762void ASTDumper::VisitIfStmt(const IfStmt *Node) {
Bruno Riccib1cc94b2018-10-27 21:12:20 +00001763 if (Node->hasInitStorage())
1764 OS << " has_init";
1765 if (Node->hasVarStorage())
1766 OS << " has_var";
1767 if (Node->hasElseStorage())
1768 OS << " has_else";
1769}
1770
Bruno Riccie2806f82018-10-29 16:12:37 +00001771void ASTDumper::VisitSwitchStmt(const SwitchStmt *Node) {
Bruno Riccie2806f82018-10-29 16:12:37 +00001772 if (Node->hasInitStorage())
1773 OS << " has_init";
1774 if (Node->hasVarStorage())
1775 OS << " has_var";
1776}
1777
Bruno Riccibacf7512018-10-30 13:42:41 +00001778void ASTDumper::VisitWhileStmt(const WhileStmt *Node) {
Bruno Riccibacf7512018-10-30 13:42:41 +00001779 if (Node->hasVarStorage())
1780 OS << " has_var";
1781}
1782
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001783void ASTDumper::VisitLabelStmt(const LabelStmt *Node) {
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001784 OS << " '" << Node->getName() << "'";
Chris Lattnercbe4f772007-08-08 22:51:59 +00001785}
1786
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001787void ASTDumper::VisitGotoStmt(const GotoStmt *Node) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001788 OS << " '" << Node->getLabel()->getName() << "'";
Stephen Kellyd8744a72018-12-05 21:12:39 +00001789 NodeDumper.dumpPointer(Node->getLabel());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001790}
1791
Pavel Labath1ef83422013-09-04 14:35:00 +00001792void ASTDumper::VisitCXXCatchStmt(const CXXCatchStmt *Node) {
Pavel Labath1ef83422013-09-04 14:35:00 +00001793 dumpDecl(Node->getExceptionDecl());
1794}
1795
Bruno Ricci5b30571752018-10-28 12:30:53 +00001796void ASTDumper::VisitCaseStmt(const CaseStmt *Node) {
Bruno Ricci5b30571752018-10-28 12:30:53 +00001797 if (Node->caseStmtIsGNURange())
1798 OS << " gnu_range";
1799}
1800
Alexey Bataev958b9e72016-03-31 09:30:50 +00001801void ASTDumper::VisitCapturedStmt(const CapturedStmt *Node) {
Alexey Bataev958b9e72016-03-31 09:30:50 +00001802 dumpDecl(Node->getCapturedDecl());
1803}
1804
1805//===----------------------------------------------------------------------===//
1806// OpenMP dumping methods.
1807//===----------------------------------------------------------------------===//
1808
1809void ASTDumper::VisitOMPExecutableDirective(
1810 const OMPExecutableDirective *Node) {
Alexey Bataev958b9e72016-03-31 09:30:50 +00001811 for (auto *C : Node->clauses()) {
1812 dumpChild([=] {
1813 if (!C) {
Stephen Kelly27e948c2018-11-29 19:30:37 +00001814 ColorScope Color(OS, ShowColors, NullColor);
Alexey Bataev958b9e72016-03-31 09:30:50 +00001815 OS << "<<<NULL>>> OMPClause";
1816 return;
1817 }
1818 {
Stephen Kelly27e948c2018-11-29 19:30:37 +00001819 ColorScope Color(OS, ShowColors, AttrColor);
Alexey Bataev958b9e72016-03-31 09:30:50 +00001820 StringRef ClauseName(getOpenMPClauseName(C->getClauseKind()));
1821 OS << "OMP" << ClauseName.substr(/*Start=*/0, /*N=*/1).upper()
1822 << ClauseName.drop_front() << "Clause";
1823 }
Stephen Kellyd8744a72018-12-05 21:12:39 +00001824 NodeDumper.dumpPointer(C);
1825 NodeDumper.dumpSourceRange(SourceRange(C->getBeginLoc(), C->getEndLoc()));
Alexey Bataev958b9e72016-03-31 09:30:50 +00001826 if (C->isImplicit())
1827 OS << " <implicit>";
1828 for (auto *S : C->children())
1829 dumpStmt(S);
1830 });
1831 }
1832}
1833
Chris Lattnercbe4f772007-08-08 22:51:59 +00001834//===----------------------------------------------------------------------===//
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001835// Expr dumping methods.
Chris Lattnercbe4f772007-08-08 22:51:59 +00001836//===----------------------------------------------------------------------===//
1837
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001838void ASTDumper::VisitExpr(const Expr *Node) {
Stephen Kellyd8744a72018-12-05 21:12:39 +00001839 NodeDumper.dumpType(Node->getType());
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001840
Richard Trieud215b8d2013-01-26 01:31:20 +00001841 {
Stephen Kelly27e948c2018-11-29 19:30:37 +00001842 ColorScope Color(OS, ShowColors, ValueKindColor);
Richard Trieud215b8d2013-01-26 01:31:20 +00001843 switch (Node->getValueKind()) {
1844 case VK_RValue:
1845 break;
1846 case VK_LValue:
1847 OS << " lvalue";
1848 break;
1849 case VK_XValue:
1850 OS << " xvalue";
1851 break;
1852 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001853 }
1854
Richard Trieud215b8d2013-01-26 01:31:20 +00001855 {
Stephen Kelly27e948c2018-11-29 19:30:37 +00001856 ColorScope Color(OS, ShowColors, ObjectKindColor);
Richard Trieud215b8d2013-01-26 01:31:20 +00001857 switch (Node->getObjectKind()) {
1858 case OK_Ordinary:
1859 break;
1860 case OK_BitField:
1861 OS << " bitfield";
1862 break;
1863 case OK_ObjCProperty:
1864 OS << " objcproperty";
1865 break;
1866 case OK_ObjCSubscript:
1867 OS << " objcsubscript";
1868 break;
1869 case OK_VectorComponent:
1870 OS << " vectorcomponent";
1871 break;
1872 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001873 }
Chris Lattnercbe4f772007-08-08 22:51:59 +00001874}
1875
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001876static void dumpBasePath(raw_ostream &OS, const CastExpr *Node) {
John McCallcf142162010-08-07 06:22:56 +00001877 if (Node->path_empty())
Anders Carlssona70cff62010-04-24 19:06:50 +00001878 return;
1879
1880 OS << " (";
1881 bool First = true;
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001882 for (CastExpr::path_const_iterator I = Node->path_begin(),
1883 E = Node->path_end();
1884 I != E; ++I) {
Anders Carlssona70cff62010-04-24 19:06:50 +00001885 const CXXBaseSpecifier *Base = *I;
1886 if (!First)
1887 OS << " -> ";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001888
Anders Carlssona70cff62010-04-24 19:06:50 +00001889 const CXXRecordDecl *RD =
1890 cast<CXXRecordDecl>(Base->getType()->getAs<RecordType>()->getDecl());
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001891
Anders Carlssona70cff62010-04-24 19:06:50 +00001892 if (Base->isVirtual())
1893 OS << "virtual ";
1894 OS << RD->getName();
1895 First = false;
1896 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001897
Anders Carlssona70cff62010-04-24 19:06:50 +00001898 OS << ')';
1899}
1900
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001901void ASTDumper::VisitCastExpr(const CastExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001902 VisitExpr(Node);
Richard Trieud215b8d2013-01-26 01:31:20 +00001903 OS << " <";
1904 {
Stephen Kelly27e948c2018-11-29 19:30:37 +00001905 ColorScope Color(OS, ShowColors, CastColor);
Richard Trieud215b8d2013-01-26 01:31:20 +00001906 OS << Node->getCastKindName();
1907 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001908 dumpBasePath(OS, Node);
Anders Carlssona70cff62010-04-24 19:06:50 +00001909 OS << ">";
Roman Lebedev12216f12018-07-27 07:27:14 +00001910}
Roman Lebedevd55661d2018-07-24 08:16:50 +00001911
Roman Lebedev12216f12018-07-27 07:27:14 +00001912void ASTDumper::VisitImplicitCastExpr(const ImplicitCastExpr *Node) {
1913 VisitCastExpr(Node);
1914 if (Node->isPartOfExplicitCast())
Roman Lebedevd55661d2018-07-24 08:16:50 +00001915 OS << " part_of_explicit_cast";
Anders Carlssond7923c62009-08-22 23:33:40 +00001916}
1917
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001918void ASTDumper::VisitDeclRefExpr(const DeclRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001919 VisitExpr(Node);
Ted Kremenek5f64ca82007-09-10 17:32:55 +00001920
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001921 OS << " ";
Stephen Kellyd8744a72018-12-05 21:12:39 +00001922 NodeDumper.dumpBareDeclRef(Node->getDecl());
Chandler Carruth8d26bb02011-05-01 23:48:14 +00001923 if (Node->getDecl() != Node->getFoundDecl()) {
1924 OS << " (";
Stephen Kellyd8744a72018-12-05 21:12:39 +00001925 NodeDumper.dumpBareDeclRef(Node->getFoundDecl());
Chandler Carruth8d26bb02011-05-01 23:48:14 +00001926 OS << ")";
1927 }
John McCall351762c2011-02-07 10:33:21 +00001928}
1929
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001930void ASTDumper::VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001931 VisitExpr(Node);
John McCall76d09942009-12-11 21:50:11 +00001932 OS << " (";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001933 if (!Node->requiresADL())
1934 OS << "no ";
Benjamin Kramerb11416d2010-04-17 09:33:03 +00001935 OS << "ADL) = '" << Node->getName() << '\'';
John McCall76d09942009-12-11 21:50:11 +00001936
1937 UnresolvedLookupExpr::decls_iterator
1938 I = Node->decls_begin(), E = Node->decls_end();
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001939 if (I == E)
1940 OS << " empty";
John McCall76d09942009-12-11 21:50:11 +00001941 for (; I != E; ++I)
Stephen Kellyd8744a72018-12-05 21:12:39 +00001942 NodeDumper.dumpPointer(*I);
John McCall76d09942009-12-11 21:50:11 +00001943}
1944
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001945void ASTDumper::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001946 VisitExpr(Node);
Steve Naroff5d5efca2008-03-12 13:19:12 +00001947
Richard Trieud215b8d2013-01-26 01:31:20 +00001948 {
Stephen Kelly27e948c2018-11-29 19:30:37 +00001949 ColorScope Color(OS, ShowColors, DeclKindNameColor);
Richard Trieud215b8d2013-01-26 01:31:20 +00001950 OS << " " << Node->getDecl()->getDeclKindName() << "Decl";
1951 }
1952 OS << "='" << *Node->getDecl() << "'";
Stephen Kellyd8744a72018-12-05 21:12:39 +00001953 NodeDumper.dumpPointer(Node->getDecl());
Steve Naroffb3424a92008-05-23 22:01:24 +00001954 if (Node->isFreeIvar())
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001955 OS << " isFreeIvar";
Steve Naroff5d5efca2008-03-12 13:19:12 +00001956}
1957
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001958void ASTDumper::VisitPredefinedExpr(const PredefinedExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001959 VisitExpr(Node);
Bruno Ricci17ff0262018-10-27 19:21:19 +00001960 OS << " " << PredefinedExpr::getIdentKindName(Node->getIdentKind());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001961}
1962
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001963void ASTDumper::VisitCharacterLiteral(const CharacterLiteral *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001964 VisitExpr(Node);
Stephen Kelly27e948c2018-11-29 19:30:37 +00001965 ColorScope Color(OS, ShowColors, ValueColor);
Richard Trieu364ee422011-11-03 23:56:23 +00001966 OS << " " << Node->getValue();
Chris Lattnercbe4f772007-08-08 22:51:59 +00001967}
1968
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001969void ASTDumper::VisitIntegerLiteral(const IntegerLiteral *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001970 VisitExpr(Node);
Chris Lattnercbe4f772007-08-08 22:51:59 +00001971
1972 bool isSigned = Node->getType()->isSignedIntegerType();
Stephen Kelly27e948c2018-11-29 19:30:37 +00001973 ColorScope Color(OS, ShowColors, ValueColor);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001974 OS << " " << Node->getValue().toString(10, isSigned);
Chris Lattnercbe4f772007-08-08 22:51:59 +00001975}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001976
Leonard Chandb01c3a2018-06-20 17:19:40 +00001977void ASTDumper::VisitFixedPointLiteral(const FixedPointLiteral *Node) {
1978 VisitExpr(Node);
1979
Stephen Kelly27e948c2018-11-29 19:30:37 +00001980 ColorScope Color(OS, ShowColors, ValueColor);
Leonard Chandb01c3a2018-06-20 17:19:40 +00001981 OS << " " << Node->getValueAsString(/*Radix=*/10);
1982}
1983
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001984void ASTDumper::VisitFloatingLiteral(const FloatingLiteral *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001985 VisitExpr(Node);
Stephen Kelly27e948c2018-11-29 19:30:37 +00001986 ColorScope Color(OS, ShowColors, ValueColor);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001987 OS << " " << Node->getValueAsApproximateDouble();
Chris Lattnercbe4f772007-08-08 22:51:59 +00001988}
Chris Lattner1c20a172007-08-26 03:42:43 +00001989
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001990void ASTDumper::VisitStringLiteral(const StringLiteral *Str) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001991 VisitExpr(Str);
Stephen Kelly27e948c2018-11-29 19:30:37 +00001992 ColorScope Color(OS, ShowColors, ValueColor);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001993 OS << " ";
Richard Trieudc355912012-06-13 20:25:24 +00001994 Str->outputString(OS);
Chris Lattnercbe4f772007-08-08 22:51:59 +00001995}
Chris Lattner84ca3762007-08-30 01:00:35 +00001996
Richard Smithf0514962014-06-03 08:24:28 +00001997void ASTDumper::VisitInitListExpr(const InitListExpr *ILE) {
1998 VisitExpr(ILE);
1999 if (auto *Filler = ILE->getArrayFiller()) {
Richard Smithf7514452014-10-30 21:02:37 +00002000 dumpChild([=] {
2001 OS << "array filler";
2002 dumpStmt(Filler);
2003 });
Richard Smithf0514962014-06-03 08:24:28 +00002004 }
2005 if (auto *Field = ILE->getInitializedFieldInUnion()) {
2006 OS << " field ";
Stephen Kellyd8744a72018-12-05 21:12:39 +00002007 NodeDumper.dumpBareDeclRef(Field);
Richard Smithf0514962014-06-03 08:24:28 +00002008 }
2009}
2010
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002011void ASTDumper::VisitUnaryOperator(const UnaryOperator *Node) {
Malcolm Parsonsfab36802018-04-16 08:31:08 +00002012 VisitExpr(Node);
2013 OS << " " << (Node->isPostfix() ? "postfix" : "prefix")
2014 << " '" << UnaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
2015 if (!Node->canOverflow())
2016 OS << " cannot overflow";
2017}
2018
2019void ASTDumper::VisitUnaryExprOrTypeTraitExpr(
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002020 const UnaryExprOrTypeTraitExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002021 VisitExpr(Node);
Peter Collingbournee190dee2011-03-11 19:24:49 +00002022 switch(Node->getKind()) {
2023 case UETT_SizeOf:
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002024 OS << " sizeof";
Peter Collingbournee190dee2011-03-11 19:24:49 +00002025 break;
2026 case UETT_AlignOf:
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002027 OS << " alignof";
Peter Collingbournee190dee2011-03-11 19:24:49 +00002028 break;
2029 case UETT_VecStep:
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002030 OS << " vec_step";
Peter Collingbournee190dee2011-03-11 19:24:49 +00002031 break;
Alexey Bataev00396512015-07-02 03:40:19 +00002032 case UETT_OpenMPRequiredSimdAlign:
2033 OS << " __builtin_omp_required_simd_align";
2034 break;
Richard Smith6822bd72018-10-26 19:26:45 +00002035 case UETT_PreferredAlignOf:
2036 OS << " __alignof";
2037 break;
Peter Collingbournee190dee2011-03-11 19:24:49 +00002038 }
Sebastian Redl6f282892008-11-11 17:56:53 +00002039 if (Node->isArgumentType())
Stephen Kellyd8744a72018-12-05 21:12:39 +00002040 NodeDumper.dumpType(Node->getArgumentType());
Chris Lattnercbe4f772007-08-08 22:51:59 +00002041}
Chris Lattnerdb3b3ff2007-08-09 17:35:30 +00002042
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002043void ASTDumper::VisitMemberExpr(const MemberExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002044 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002045 OS << " " << (Node->isArrow() ? "->" : ".") << *Node->getMemberDecl();
Stephen Kellyd8744a72018-12-05 21:12:39 +00002046 NodeDumper.dumpPointer(Node->getMemberDecl());
Chris Lattnercbe4f772007-08-08 22:51:59 +00002047}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002048
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002049void ASTDumper::VisitExtVectorElementExpr(const ExtVectorElementExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002050 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002051 OS << " " << Node->getAccessor().getNameStart();
Chris Lattnercbe4f772007-08-08 22:51:59 +00002052}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002053
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002054void ASTDumper::VisitBinaryOperator(const BinaryOperator *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002055 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002056 OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
Chris Lattner86928112007-08-25 02:00:02 +00002057}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002058
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002059void ASTDumper::VisitCompoundAssignOperator(
2060 const CompoundAssignOperator *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002061 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002062 OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode())
2063 << "' ComputeLHSTy=";
Stephen Kellyd8744a72018-12-05 21:12:39 +00002064 NodeDumper.dumpBareType(Node->getComputationLHSType());
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002065 OS << " ComputeResultTy=";
Stephen Kellyd8744a72018-12-05 21:12:39 +00002066 NodeDumper.dumpBareType(Node->getComputationResultType());
Chris Lattnercbe4f772007-08-08 22:51:59 +00002067}
Chris Lattnercbe4f772007-08-08 22:51:59 +00002068
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002069void ASTDumper::VisitBlockExpr(const BlockExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002070 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002071 dumpDecl(Node->getBlockDecl());
John McCall351762c2011-02-07 10:33:21 +00002072}
2073
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002074void ASTDumper::VisitOpaqueValueExpr(const OpaqueValueExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002075 VisitExpr(Node);
John McCallfe96e0b2011-11-06 09:01:30 +00002076
Richard Smithf7514452014-10-30 21:02:37 +00002077 if (Expr *Source = Node->getSourceExpr())
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002078 dumpStmt(Source);
John McCallfe96e0b2011-11-06 09:01:30 +00002079}
2080
Richard Smith01ccebf2018-01-05 21:31:07 +00002081void ASTDumper::VisitGenericSelectionExpr(const GenericSelectionExpr *E) {
2082 VisitExpr(E);
2083 if (E->isResultDependent())
2084 OS << " result_dependent";
2085 dumpStmt(E->getControllingExpr());
2086 dumpTypeAsChild(E->getControllingExpr()->getType()); // FIXME: remove
2087
2088 for (unsigned I = 0, N = E->getNumAssocs(); I != N; ++I) {
2089 dumpChild([=] {
2090 if (const TypeSourceInfo *TSI = E->getAssocTypeSourceInfo(I)) {
2091 OS << "case ";
Stephen Kellyd8744a72018-12-05 21:12:39 +00002092 NodeDumper.dumpType(TSI->getType());
Richard Smith01ccebf2018-01-05 21:31:07 +00002093 } else {
2094 OS << "default";
2095 }
2096
2097 if (!E->isResultDependent() && E->getResultIndex() == I)
2098 OS << " selected";
2099
2100 if (const TypeSourceInfo *TSI = E->getAssocTypeSourceInfo(I))
2101 dumpTypeAsChild(TSI->getType());
2102 dumpStmt(E->getAssocExpr(I));
2103 });
2104 }
2105}
2106
Chris Lattnercbe4f772007-08-08 22:51:59 +00002107// GNU extensions.
2108
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002109void ASTDumper::VisitAddrLabelExpr(const AddrLabelExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002110 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002111 OS << " " << Node->getLabel()->getName();
Stephen Kellyd8744a72018-12-05 21:12:39 +00002112 NodeDumper.dumpPointer(Node->getLabel());
Chris Lattnercbe4f772007-08-08 22:51:59 +00002113}
2114
Chris Lattner8f184b12007-08-09 18:03:18 +00002115//===----------------------------------------------------------------------===//
2116// C++ Expressions
2117//===----------------------------------------------------------------------===//
Chris Lattnercbe4f772007-08-08 22:51:59 +00002118
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002119void ASTDumper::VisitCXXNamedCastExpr(const CXXNamedCastExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002120 VisitExpr(Node);
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002121 OS << " " << Node->getCastName()
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002122 << "<" << Node->getTypeAsWritten().getAsString() << ">"
Anders Carlssona70cff62010-04-24 19:06:50 +00002123 << " <" << Node->getCastKindName();
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002124 dumpBasePath(OS, Node);
Anders Carlssona70cff62010-04-24 19:06:50 +00002125 OS << ">";
Chris Lattnercbe4f772007-08-08 22:51:59 +00002126}
2127
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002128void ASTDumper::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002129 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002130 OS << " " << (Node->getValue() ? "true" : "false");
Chris Lattnercbe4f772007-08-08 22:51:59 +00002131}
2132
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002133void ASTDumper::VisitCXXThisExpr(const CXXThisExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002134 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002135 OS << " this";
Douglas Gregor8ea1f532008-11-04 14:56:14 +00002136}
2137
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002138void ASTDumper::VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002139 VisitExpr(Node);
Eli Friedman29538892011-09-02 17:38:59 +00002140 OS << " functional cast to " << Node->getTypeAsWritten().getAsString()
2141 << " <" << Node->getCastKindName() << ">";
Douglas Gregore200adc2008-10-27 19:41:14 +00002142}
2143
Richard Smith39eca9b2017-08-23 22:12:08 +00002144void ASTDumper::VisitCXXUnresolvedConstructExpr(
2145 const CXXUnresolvedConstructExpr *Node) {
2146 VisitExpr(Node);
Stephen Kellyd8744a72018-12-05 21:12:39 +00002147 NodeDumper.dumpType(Node->getTypeAsWritten());
Richard Smith39eca9b2017-08-23 22:12:08 +00002148 if (Node->isListInitialization())
2149 OS << " list";
2150}
2151
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002152void ASTDumper::VisitCXXConstructExpr(const CXXConstructExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002153 VisitExpr(Node);
John McCalleba90cd2010-02-02 19:03:45 +00002154 CXXConstructorDecl *Ctor = Node->getConstructor();
Stephen Kellyd8744a72018-12-05 21:12:39 +00002155 NodeDumper.dumpType(Ctor->getType());
Anders Carlsson073846832009-08-12 00:21:52 +00002156 if (Node->isElidable())
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002157 OS << " elidable";
Richard Smith39eca9b2017-08-23 22:12:08 +00002158 if (Node->isListInitialization())
2159 OS << " list";
2160 if (Node->isStdInitListInitialization())
2161 OS << " std::initializer_list";
John McCall85370042010-08-07 06:38:55 +00002162 if (Node->requiresZeroInitialization())
2163 OS << " zeroing";
Anders Carlsson073846832009-08-12 00:21:52 +00002164}
2165
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002166void ASTDumper::VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002167 VisitExpr(Node);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002168 OS << " ";
Stephen Kellyd8744a72018-12-05 21:12:39 +00002169 NodeDumper.dumpCXXTemporary(Node->getTemporary());
Anders Carlsson073846832009-08-12 00:21:52 +00002170}
2171
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002172void ASTDumper::VisitCXXNewExpr(const CXXNewExpr *Node) {
2173 VisitExpr(Node);
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002174 if (Node->isGlobalNew())
Reid Kleckner461c0c62015-03-19 18:47:47 +00002175 OS << " global";
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002176 if (Node->isArray())
Reid Kleckner461c0c62015-03-19 18:47:47 +00002177 OS << " array";
2178 if (Node->getOperatorNew()) {
2179 OS << ' ';
Stephen Kellyd8744a72018-12-05 21:12:39 +00002180 NodeDumper.dumpBareDeclRef(Node->getOperatorNew());
Reid Kleckner461c0c62015-03-19 18:47:47 +00002181 }
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002182 // We could dump the deallocation function used in case of error, but it's
2183 // usually not that interesting.
2184}
2185
2186void ASTDumper::VisitCXXDeleteExpr(const CXXDeleteExpr *Node) {
2187 VisitExpr(Node);
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002188 if (Node->isGlobalDelete())
Reid Kleckner461c0c62015-03-19 18:47:47 +00002189 OS << " global";
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002190 if (Node->isArrayForm())
Reid Kleckner461c0c62015-03-19 18:47:47 +00002191 OS << " array";
2192 if (Node->getOperatorDelete()) {
2193 OS << ' ';
Stephen Kellyd8744a72018-12-05 21:12:39 +00002194 NodeDumper.dumpBareDeclRef(Node->getOperatorDelete());
Reid Kleckner461c0c62015-03-19 18:47:47 +00002195 }
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002196}
2197
Richard Smithe6c01442013-06-05 00:46:14 +00002198void
2199ASTDumper::VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *Node) {
2200 VisitExpr(Node);
2201 if (const ValueDecl *VD = Node->getExtendingDecl()) {
2202 OS << " extended by ";
Stephen Kellyd8744a72018-12-05 21:12:39 +00002203 NodeDumper.dumpBareDeclRef(VD);
Richard Smithe6c01442013-06-05 00:46:14 +00002204 }
2205}
2206
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002207void ASTDumper::VisitExprWithCleanups(const ExprWithCleanups *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002208 VisitExpr(Node);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002209 for (unsigned i = 0, e = Node->getNumObjects(); i != e; ++i)
2210 dumpDeclRef(Node->getObject(i), "cleanup");
Anders Carlsson073846832009-08-12 00:21:52 +00002211}
2212
Serge Pavlov6b926032015-02-16 19:58:41 +00002213void ASTDumper::VisitSizeOfPackExpr(const SizeOfPackExpr *Node) {
2214 VisitExpr(Node);
Stephen Kellyd8744a72018-12-05 21:12:39 +00002215 NodeDumper.dumpPointer(Node->getPack());
2216 NodeDumper.dumpName(Node->getPack());
Richard Smithd784e682015-09-23 21:41:42 +00002217 if (Node->isPartiallySubstituted())
2218 for (const auto &A : Node->getPartialArguments())
2219 dumpTemplateArgument(A);
Serge Pavlov6b926032015-02-16 19:58:41 +00002220}
2221
Alex Lorenzddbe0f52016-11-09 14:02:18 +00002222void ASTDumper::VisitCXXDependentScopeMemberExpr(
2223 const CXXDependentScopeMemberExpr *Node) {
2224 VisitExpr(Node);
2225 OS << " " << (Node->isArrow() ? "->" : ".") << Node->getMember();
2226}
Serge Pavlov6b926032015-02-16 19:58:41 +00002227
Anders Carlsson76f4a902007-08-21 17:43:55 +00002228//===----------------------------------------------------------------------===//
2229// Obj-C Expressions
2230//===----------------------------------------------------------------------===//
2231
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002232void ASTDumper::VisitObjCMessageExpr(const ObjCMessageExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002233 VisitExpr(Node);
Aaron Ballmanb190f972014-01-03 17:59:55 +00002234 OS << " selector=";
2235 Node->getSelector().print(OS);
Douglas Gregor9a129192010-04-21 00:45:42 +00002236 switch (Node->getReceiverKind()) {
2237 case ObjCMessageExpr::Instance:
2238 break;
2239
2240 case ObjCMessageExpr::Class:
2241 OS << " class=";
Stephen Kellyd8744a72018-12-05 21:12:39 +00002242 NodeDumper.dumpBareType(Node->getClassReceiver());
Douglas Gregor9a129192010-04-21 00:45:42 +00002243 break;
2244
2245 case ObjCMessageExpr::SuperInstance:
2246 OS << " super (instance)";
2247 break;
2248
2249 case ObjCMessageExpr::SuperClass:
2250 OS << " super (class)";
2251 break;
2252 }
Ted Kremenek36748da2008-02-29 22:04:05 +00002253}
2254
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002255void ASTDumper::VisitObjCBoxedExpr(const ObjCBoxedExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002256 VisitExpr(Node);
Richard Trieu4b259c82016-06-09 22:03:04 +00002257 if (auto *BoxingMethod = Node->getBoxingMethod()) {
2258 OS << " selector=";
2259 BoxingMethod->getSelector().print(OS);
2260 }
Argyrios Kyrtzidis9dd40892012-05-10 20:02:31 +00002261}
2262
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002263void ASTDumper::VisitObjCAtCatchStmt(const ObjCAtCatchStmt *Node) {
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002264 if (const VarDecl *CatchParam = Node->getCatchParamDecl())
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002265 dumpDecl(CatchParam);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002266 else
Douglas Gregor96c79492010-04-23 22:50:49 +00002267 OS << " catch all";
Douglas Gregor96c79492010-04-23 22:50:49 +00002268}
2269
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002270void ASTDumper::VisitObjCEncodeExpr(const ObjCEncodeExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002271 VisitExpr(Node);
Stephen Kellyd8744a72018-12-05 21:12:39 +00002272 NodeDumper.dumpType(Node->getEncodedType());
Anders Carlssonc5a81eb2007-08-22 15:14:15 +00002273}
2274
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002275void ASTDumper::VisitObjCSelectorExpr(const ObjCSelectorExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002276 VisitExpr(Node);
Mike Stump11289f42009-09-09 15:08:12 +00002277
Aaron Ballmanb190f972014-01-03 17:59:55 +00002278 OS << " ";
2279 Node->getSelector().print(OS);
Fariborz Jahanian4bef4622007-10-16 20:40:23 +00002280}
2281
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002282void ASTDumper::VisitObjCProtocolExpr(const ObjCProtocolExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002283 VisitExpr(Node);
Mike Stump11289f42009-09-09 15:08:12 +00002284
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002285 OS << ' ' << *Node->getProtocol();
Fariborz Jahaniana32aaef2007-10-17 16:58:11 +00002286}
Daniel Dunbar4b8c6db2008-08-30 05:35:15 +00002287
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002288void ASTDumper::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002289 VisitExpr(Node);
John McCallb7bd14f2010-12-02 01:19:52 +00002290 if (Node->isImplicitProperty()) {
Fariborz Jahanian0f0b3022010-12-22 19:46:35 +00002291 OS << " Kind=MethodRef Getter=\"";
2292 if (Node->getImplicitPropertyGetter())
Aaron Ballmanb190f972014-01-03 17:59:55 +00002293 Node->getImplicitPropertyGetter()->getSelector().print(OS);
Fariborz Jahanian0f0b3022010-12-22 19:46:35 +00002294 else
2295 OS << "(null)";
2296
2297 OS << "\" Setter=\"";
John McCallb7bd14f2010-12-02 01:19:52 +00002298 if (ObjCMethodDecl *Setter = Node->getImplicitPropertySetter())
Aaron Ballmanb190f972014-01-03 17:59:55 +00002299 Setter->getSelector().print(OS);
John McCallb7bd14f2010-12-02 01:19:52 +00002300 else
2301 OS << "(null)";
2302 OS << "\"";
2303 } else {
Benjamin Kramerb89514a2011-10-14 18:45:37 +00002304 OS << " Kind=PropertyRef Property=\"" << *Node->getExplicitProperty() <<'"';
John McCallb7bd14f2010-12-02 01:19:52 +00002305 }
Fariborz Jahanian8a1810f2008-11-22 18:39:36 +00002306
Fariborz Jahanian681c0752010-10-14 16:04:05 +00002307 if (Node->isSuperReceiver())
2308 OS << " super";
Argyrios Kyrtzidisab468b02012-03-30 00:19:18 +00002309
2310 OS << " Messaging=";
2311 if (Node->isMessagingGetter() && Node->isMessagingSetter())
2312 OS << "Getter&Setter";
2313 else if (Node->isMessagingGetter())
2314 OS << "Getter";
2315 else if (Node->isMessagingSetter())
2316 OS << "Setter";
Douglas Gregor8ea1f532008-11-04 14:56:14 +00002317}
2318
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002319void ASTDumper::VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002320 VisitExpr(Node);
Ted Kremeneke65b0862012-03-06 20:05:56 +00002321 if (Node->isArraySubscriptRefExpr())
2322 OS << " Kind=ArraySubscript GetterForArray=\"";
2323 else
2324 OS << " Kind=DictionarySubscript GetterForDictionary=\"";
2325 if (Node->getAtIndexMethodDecl())
Aaron Ballmanb190f972014-01-03 17:59:55 +00002326 Node->getAtIndexMethodDecl()->getSelector().print(OS);
Ted Kremeneke65b0862012-03-06 20:05:56 +00002327 else
2328 OS << "(null)";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002329
Ted Kremeneke65b0862012-03-06 20:05:56 +00002330 if (Node->isArraySubscriptRefExpr())
2331 OS << "\" SetterForArray=\"";
2332 else
2333 OS << "\" SetterForDictionary=\"";
2334 if (Node->setAtIndexMethodDecl())
Aaron Ballmanb190f972014-01-03 17:59:55 +00002335 Node->setAtIndexMethodDecl()->getSelector().print(OS);
Ted Kremeneke65b0862012-03-06 20:05:56 +00002336 else
2337 OS << "(null)";
2338}
2339
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002340void ASTDumper::VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *Node) {
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002341 VisitExpr(Node);
Ted Kremeneke65b0862012-03-06 20:05:56 +00002342 OS << " " << (Node->getValue() ? "__objc_yes" : "__objc_no");
2343}
2344
Chris Lattnercbe4f772007-08-08 22:51:59 +00002345//===----------------------------------------------------------------------===//
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002346// Comments
2347//===----------------------------------------------------------------------===//
2348
2349const char *ASTDumper::getCommandName(unsigned CommandID) {
2350 if (Traits)
2351 return Traits->getCommandInfo(CommandID)->Name;
2352 const CommandInfo *Info = CommandTraits::getBuiltinCommandInfo(CommandID);
2353 if (Info)
2354 return Info->Name;
2355 return "<not a builtin command>";
2356}
2357
2358void ASTDumper::dumpFullComment(const FullComment *C) {
2359 if (!C)
2360 return;
Stephen Kellycdbfb302018-12-02 17:30:40 +00002361 dumpComment(C, C);
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002362}
2363
Stephen Kellycdbfb302018-12-02 17:30:40 +00002364void ASTDumper::dumpComment(const Comment *C, const FullComment *FC) {
Richard Smithf7514452014-10-30 21:02:37 +00002365 dumpChild([=] {
2366 if (!C) {
Stephen Kelly27e948c2018-11-29 19:30:37 +00002367 ColorScope Color(OS, ShowColors, NullColor);
Richard Smithf7514452014-10-30 21:02:37 +00002368 OS << "<<<NULL>>>";
2369 return;
2370 }
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002371
Richard Smithf7514452014-10-30 21:02:37 +00002372 {
Stephen Kelly27e948c2018-11-29 19:30:37 +00002373 ColorScope Color(OS, ShowColors, CommentColor);
Richard Smithf7514452014-10-30 21:02:37 +00002374 OS << C->getCommentKindName();
2375 }
Stephen Kellyd8744a72018-12-05 21:12:39 +00002376 NodeDumper.dumpPointer(C);
2377 NodeDumper.dumpSourceRange(C->getSourceRange());
Stephen Kellycdbfb302018-12-02 17:30:40 +00002378 ConstCommentVisitor<ASTDumper, void, const FullComment *>::visit(C, FC);
Richard Smithf7514452014-10-30 21:02:37 +00002379 for (Comment::child_iterator I = C->child_begin(), E = C->child_end();
2380 I != E; ++I)
Stephen Kellycdbfb302018-12-02 17:30:40 +00002381 dumpComment(*I, FC);
Richard Smithf7514452014-10-30 21:02:37 +00002382 });
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002383}
2384
Stephen Kellycdbfb302018-12-02 17:30:40 +00002385void ASTDumper::visitTextComment(const TextComment *C, const FullComment *) {
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002386 OS << " Text=\"" << C->getText() << "\"";
2387}
2388
Stephen Kellycdbfb302018-12-02 17:30:40 +00002389void ASTDumper::visitInlineCommandComment(const InlineCommandComment *C,
2390 const FullComment *) {
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002391 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\"";
2392 switch (C->getRenderKind()) {
2393 case InlineCommandComment::RenderNormal:
2394 OS << " RenderNormal";
2395 break;
2396 case InlineCommandComment::RenderBold:
2397 OS << " RenderBold";
2398 break;
2399 case InlineCommandComment::RenderMonospaced:
2400 OS << " RenderMonospaced";
2401 break;
2402 case InlineCommandComment::RenderEmphasized:
2403 OS << " RenderEmphasized";
2404 break;
2405 }
2406
2407 for (unsigned i = 0, e = C->getNumArgs(); i != e; ++i)
2408 OS << " Arg[" << i << "]=\"" << C->getArgText(i) << "\"";
2409}
2410
Stephen Kellycdbfb302018-12-02 17:30:40 +00002411void ASTDumper::visitHTMLStartTagComment(const HTMLStartTagComment *C,
2412 const FullComment *) {
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002413 OS << " Name=\"" << C->getTagName() << "\"";
2414 if (C->getNumAttrs() != 0) {
2415 OS << " Attrs: ";
2416 for (unsigned i = 0, e = C->getNumAttrs(); i != e; ++i) {
2417 const HTMLStartTagComment::Attribute &Attr = C->getAttr(i);
2418 OS << " \"" << Attr.Name << "=\"" << Attr.Value << "\"";
2419 }
2420 }
2421 if (C->isSelfClosing())
2422 OS << " SelfClosing";
2423}
2424
Stephen Kellycdbfb302018-12-02 17:30:40 +00002425void ASTDumper::visitHTMLEndTagComment(const HTMLEndTagComment *C,
2426 const FullComment *) {
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002427 OS << " Name=\"" << C->getTagName() << "\"";
2428}
2429
Stephen Kellycdbfb302018-12-02 17:30:40 +00002430void ASTDumper::visitBlockCommandComment(const BlockCommandComment *C,
2431 const FullComment *) {
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002432 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\"";
2433 for (unsigned i = 0, e = C->getNumArgs(); i != e; ++i)
2434 OS << " Arg[" << i << "]=\"" << C->getArgText(i) << "\"";
2435}
2436
Stephen Kellycdbfb302018-12-02 17:30:40 +00002437void ASTDumper::visitParamCommandComment(const ParamCommandComment *C,
2438 const FullComment *FC) {
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002439 OS << " " << ParamCommandComment::getDirectionAsString(C->getDirection());
2440
2441 if (C->isDirectionExplicit())
2442 OS << " explicitly";
2443 else
2444 OS << " implicitly";
2445
2446 if (C->hasParamName()) {
2447 if (C->isParamIndexValid())
2448 OS << " Param=\"" << C->getParamName(FC) << "\"";
2449 else
2450 OS << " Param=\"" << C->getParamNameAsWritten() << "\"";
2451 }
2452
Dmitri Gribenkodbff5c72014-03-19 14:03:47 +00002453 if (C->isParamIndexValid() && !C->isVarArgParam())
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002454 OS << " ParamIndex=" << C->getParamIndex();
2455}
2456
Stephen Kellycdbfb302018-12-02 17:30:40 +00002457void ASTDumper::visitTParamCommandComment(const TParamCommandComment *C,
2458 const FullComment *FC) {
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002459 if (C->hasParamName()) {
2460 if (C->isPositionValid())
2461 OS << " Param=\"" << C->getParamName(FC) << "\"";
2462 else
2463 OS << " Param=\"" << C->getParamNameAsWritten() << "\"";
2464 }
2465
2466 if (C->isPositionValid()) {
2467 OS << " Position=<";
2468 for (unsigned i = 0, e = C->getDepth(); i != e; ++i) {
2469 OS << C->getIndex(i);
2470 if (i != e - 1)
2471 OS << ", ";
2472 }
2473 OS << ">";
2474 }
2475}
2476
Stephen Kellycdbfb302018-12-02 17:30:40 +00002477void ASTDumper::visitVerbatimBlockComment(const VerbatimBlockComment *C,
2478 const FullComment *) {
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002479 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\""
2480 " CloseName=\"" << C->getCloseName() << "\"";
2481}
2482
Stephen Kellycdbfb302018-12-02 17:30:40 +00002483void ASTDumper::visitVerbatimBlockLineComment(const VerbatimBlockLineComment *C,
2484 const FullComment *) {
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002485 OS << " Text=\"" << C->getText() << "\"";
2486}
2487
Stephen Kellycdbfb302018-12-02 17:30:40 +00002488void ASTDumper::visitVerbatimLineComment(const VerbatimLineComment *C,
2489 const FullComment *) {
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002490 OS << " Text=\"" << C->getText() << "\"";
2491}
2492
2493//===----------------------------------------------------------------------===//
Richard Smithd5e7ff82014-10-31 01:17:45 +00002494// Type method implementations
2495//===----------------------------------------------------------------------===//
2496
2497void QualType::dump(const char *msg) const {
2498 if (msg)
2499 llvm::errs() << msg << ": ";
2500 dump();
2501}
2502
Richard Smith14d04842016-11-02 23:57:18 +00002503LLVM_DUMP_METHOD void QualType::dump() const { dump(llvm::errs()); }
2504
2505LLVM_DUMP_METHOD void QualType::dump(llvm::raw_ostream &OS) const {
2506 ASTDumper Dumper(OS, nullptr, nullptr);
Richard Smithd5e7ff82014-10-31 01:17:45 +00002507 Dumper.dumpTypeAsChild(*this);
2508}
2509
Richard Smith14d04842016-11-02 23:57:18 +00002510LLVM_DUMP_METHOD void Type::dump() const { dump(llvm::errs()); }
2511
2512LLVM_DUMP_METHOD void Type::dump(llvm::raw_ostream &OS) const {
2513 QualType(this, 0).dump(OS);
2514}
Richard Smithd5e7ff82014-10-31 01:17:45 +00002515
2516//===----------------------------------------------------------------------===//
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002517// Decl method implementations
2518//===----------------------------------------------------------------------===//
2519
Alp Tokeref6b0072014-01-04 13:47:14 +00002520LLVM_DUMP_METHOD void Decl::dump() const { dump(llvm::errs()); }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002521
Richard Smith3a36ac12017-03-09 22:00:01 +00002522LLVM_DUMP_METHOD void Decl::dump(raw_ostream &OS, bool Deserialize) const {
Aaron Ballman8c208282017-12-21 21:42:42 +00002523 const ASTContext &Ctx = getASTContext();
2524 const SourceManager &SM = Ctx.getSourceManager();
2525 ASTDumper P(OS, &Ctx.getCommentCommandTraits(), &SM,
2526 SM.getDiagnostics().getShowColors(), Ctx.getPrintingPolicy());
Richard Smith3a36ac12017-03-09 22:00:01 +00002527 P.setDeserialize(Deserialize);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002528 P.dumpDecl(this);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002529}
2530
Alp Tokeref6b0072014-01-04 13:47:14 +00002531LLVM_DUMP_METHOD void Decl::dumpColor() const {
Aaron Ballman8c208282017-12-21 21:42:42 +00002532 const ASTContext &Ctx = getASTContext();
2533 ASTDumper P(llvm::errs(), &Ctx.getCommentCommandTraits(),
2534 &Ctx.getSourceManager(), /*ShowColors*/ true,
2535 Ctx.getPrintingPolicy());
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002536 P.dumpDecl(this);
Richard Trieud215b8d2013-01-26 01:31:20 +00002537}
Richard Smith33937e72013-06-22 21:49:40 +00002538
Alp Tokeref6b0072014-01-04 13:47:14 +00002539LLVM_DUMP_METHOD void DeclContext::dumpLookups() const {
Richard Smith6ea05822013-06-24 01:45:33 +00002540 dumpLookups(llvm::errs());
2541}
2542
Richard Smith35f986d2014-08-11 22:11:07 +00002543LLVM_DUMP_METHOD void DeclContext::dumpLookups(raw_ostream &OS,
Richard Smith3a36ac12017-03-09 22:00:01 +00002544 bool DumpDecls,
2545 bool Deserialize) const {
Richard Smith33937e72013-06-22 21:49:40 +00002546 const DeclContext *DC = this;
2547 while (!DC->isTranslationUnit())
2548 DC = DC->getParent();
2549 ASTContext &Ctx = cast<TranslationUnitDecl>(DC)->getASTContext();
Aaron Ballman8c208282017-12-21 21:42:42 +00002550 const SourceManager &SM = Ctx.getSourceManager();
2551 ASTDumper P(OS, &Ctx.getCommentCommandTraits(), &Ctx.getSourceManager(),
2552 SM.getDiagnostics().getShowColors(), Ctx.getPrintingPolicy());
Richard Smith3a36ac12017-03-09 22:00:01 +00002553 P.setDeserialize(Deserialize);
Richard Smith35f986d2014-08-11 22:11:07 +00002554 P.dumpLookups(this, DumpDecls);
Richard Smith33937e72013-06-22 21:49:40 +00002555}
2556
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002557//===----------------------------------------------------------------------===//
Chris Lattnercbe4f772007-08-08 22:51:59 +00002558// Stmt method implementations
2559//===----------------------------------------------------------------------===//
2560
Alp Tokeref6b0072014-01-04 13:47:14 +00002561LLVM_DUMP_METHOD void Stmt::dump(SourceManager &SM) const {
Argyrios Kyrtzidisc049f752010-08-09 10:54:31 +00002562 dump(llvm::errs(), SM);
2563}
2564
Alp Tokeref6b0072014-01-04 13:47:14 +00002565LLVM_DUMP_METHOD void Stmt::dump(raw_ostream &OS, SourceManager &SM) const {
Craig Topper36250ad2014-05-12 05:36:57 +00002566 ASTDumper P(OS, nullptr, &SM);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002567 P.dumpStmt(this);
Chris Lattner779d5d92007-08-30 00:40:08 +00002568}
2569
Faisal Vali2da8ed92015-03-22 13:35:56 +00002570LLVM_DUMP_METHOD void Stmt::dump(raw_ostream &OS) const {
2571 ASTDumper P(OS, nullptr, nullptr);
2572 P.dumpStmt(this);
2573}
2574
Alp Tokeref6b0072014-01-04 13:47:14 +00002575LLVM_DUMP_METHOD void Stmt::dump() const {
Craig Topper36250ad2014-05-12 05:36:57 +00002576 ASTDumper P(llvm::errs(), nullptr, nullptr);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002577 P.dumpStmt(this);
Chris Lattnercbe4f772007-08-08 22:51:59 +00002578}
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002579
Alp Tokeref6b0072014-01-04 13:47:14 +00002580LLVM_DUMP_METHOD void Stmt::dumpColor() const {
Craig Topper36250ad2014-05-12 05:36:57 +00002581 ASTDumper P(llvm::errs(), nullptr, nullptr, /*ShowColors*/true);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002582 P.dumpStmt(this);
Richard Trieud215b8d2013-01-26 01:31:20 +00002583}
2584
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002585//===----------------------------------------------------------------------===//
2586// Comment method implementations
2587//===----------------------------------------------------------------------===//
2588
Craig Topper36250ad2014-05-12 05:36:57 +00002589LLVM_DUMP_METHOD void Comment::dump() const {
2590 dump(llvm::errs(), nullptr, nullptr);
2591}
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002592
Alp Tokeref6b0072014-01-04 13:47:14 +00002593LLVM_DUMP_METHOD void Comment::dump(const ASTContext &Context) const {
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002594 dump(llvm::errs(), &Context.getCommentCommandTraits(),
2595 &Context.getSourceManager());
2596}
2597
Alexander Kornienko00911f12013-01-15 12:20:21 +00002598void Comment::dump(raw_ostream &OS, const CommandTraits *Traits,
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002599 const SourceManager *SM) const {
2600 const FullComment *FC = dyn_cast<FullComment>(this);
2601 ASTDumper D(OS, Traits, SM);
2602 D.dumpFullComment(FC);
2603}
Richard Trieud215b8d2013-01-26 01:31:20 +00002604
Alp Tokeref6b0072014-01-04 13:47:14 +00002605LLVM_DUMP_METHOD void Comment::dumpColor() const {
Richard Trieud215b8d2013-01-26 01:31:20 +00002606 const FullComment *FC = dyn_cast<FullComment>(this);
Craig Topper36250ad2014-05-12 05:36:57 +00002607 ASTDumper D(llvm::errs(), nullptr, nullptr, /*ShowColors*/true);
Richard Trieud215b8d2013-01-26 01:31:20 +00002608 D.dumpFullComment(FC);
2609}