blob: 78f8a9e328a688c068b10cc0c6b3841bdbafa674 [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);
Mike Stump11289f42009-09-09 15:08:12 +000087
Richard Trieude5cc7d2013-01-31 01:44:26 +000088 // Utilities
Stephen Kellyd8744a72018-12-05 21:12:39 +000089 void dumpType(QualType T) { NodeDumper.dumpType(T); }
Richard Smithd5e7ff82014-10-31 01:17:45 +000090 void dumpTypeAsChild(QualType T);
91 void dumpTypeAsChild(const Type *T);
Craig Topper36250ad2014-05-12 05:36:57 +000092 void dumpDeclRef(const Decl *Node, const char *Label = nullptr);
Stephen Kellyd8744a72018-12-05 21:12:39 +000093 void dumpBareDeclRef(const Decl *Node) { NodeDumper.dumpBareDeclRef(Node); }
Richard Trieude5cc7d2013-01-31 01:44:26 +000094 bool hasNodes(const DeclContext *DC);
Alexander Kornienko787f4c32012-12-20 11:08:38 +000095 void dumpDeclContext(const DeclContext *DC);
Richard Smith35f986d2014-08-11 22:11:07 +000096 void dumpLookups(const DeclContext *DC, bool DumpDecls);
Alexander Kornienko5bc364e2013-01-07 17:53:08 +000097 void dumpAttr(const Attr *A);
Alexander Kornienko90ff6072012-12-20 02:09:13 +000098
99 // C++ Utilities
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000100 void dumpCXXCtorInitializer(const CXXCtorInitializer *Init);
101 void dumpTemplateParameters(const TemplateParameterList *TPL);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000102 void dumpTemplateArgumentListInfo(const TemplateArgumentListInfo &TALI);
103 void dumpTemplateArgumentLoc(const TemplateArgumentLoc &A);
104 void dumpTemplateArgumentList(const TemplateArgumentList &TAL);
105 void dumpTemplateArgument(const TemplateArgument &A,
106 SourceRange R = SourceRange());
107
Douglas Gregor85f3f952015-07-07 03:57:15 +0000108 // Objective-C utilities.
109 void dumpObjCTypeParamList(const ObjCTypeParamList *typeParams);
110
Richard Smithd5e7ff82014-10-31 01:17:45 +0000111 // Types
112 void VisitComplexType(const ComplexType *T) {
113 dumpTypeAsChild(T->getElementType());
114 }
115 void VisitPointerType(const PointerType *T) {
116 dumpTypeAsChild(T->getPointeeType());
117 }
118 void VisitBlockPointerType(const BlockPointerType *T) {
119 dumpTypeAsChild(T->getPointeeType());
120 }
121 void VisitReferenceType(const ReferenceType *T) {
122 dumpTypeAsChild(T->getPointeeType());
123 }
124 void VisitRValueReferenceType(const ReferenceType *T) {
125 if (T->isSpelledAsLValue())
126 OS << " written as lvalue reference";
127 VisitReferenceType(T);
128 }
129 void VisitMemberPointerType(const MemberPointerType *T) {
130 dumpTypeAsChild(T->getClass());
131 dumpTypeAsChild(T->getPointeeType());
132 }
133 void VisitArrayType(const ArrayType *T) {
134 switch (T->getSizeModifier()) {
135 case ArrayType::Normal: break;
136 case ArrayType::Static: OS << " static"; break;
137 case ArrayType::Star: OS << " *"; break;
138 }
139 OS << " " << T->getIndexTypeQualifiers().getAsString();
140 dumpTypeAsChild(T->getElementType());
141 }
142 void VisitConstantArrayType(const ConstantArrayType *T) {
143 OS << " " << T->getSize();
144 VisitArrayType(T);
145 }
146 void VisitVariableArrayType(const VariableArrayType *T) {
147 OS << " ";
Stephen Kellyd8744a72018-12-05 21:12:39 +0000148 NodeDumper.dumpSourceRange(T->getBracketsRange());
Richard Smithd5e7ff82014-10-31 01:17:45 +0000149 VisitArrayType(T);
150 dumpStmt(T->getSizeExpr());
151 }
152 void VisitDependentSizedArrayType(const DependentSizedArrayType *T) {
Stephen Kellyec42aa02018-12-05 20:34:07 +0000153 switch (T->getSizeModifier()) {
154 case ArrayType::Normal: break;
155 case ArrayType::Static: OS << " static"; break;
156 case ArrayType::Star: OS << " *"; break;
157 }
158 OS << " " << T->getIndexTypeQualifiers().getAsString();
Richard Smithd5e7ff82014-10-31 01:17:45 +0000159 OS << " ";
Stephen Kellyd8744a72018-12-05 21:12:39 +0000160 NodeDumper.dumpSourceRange(T->getBracketsRange());
Stephen Kellyec42aa02018-12-05 20:34:07 +0000161 dumpTypeAsChild(T->getElementType());
Richard Smithd5e7ff82014-10-31 01:17:45 +0000162 dumpStmt(T->getSizeExpr());
163 }
164 void VisitDependentSizedExtVectorType(
165 const DependentSizedExtVectorType *T) {
166 OS << " ";
Stephen Kellyd8744a72018-12-05 21:12:39 +0000167 NodeDumper.dumpLocation(T->getAttributeLoc());
Richard Smithd5e7ff82014-10-31 01:17:45 +0000168 dumpTypeAsChild(T->getElementType());
169 dumpStmt(T->getSizeExpr());
170 }
171 void VisitVectorType(const VectorType *T) {
172 switch (T->getVectorKind()) {
173 case VectorType::GenericVector: break;
174 case VectorType::AltiVecVector: OS << " altivec"; break;
175 case VectorType::AltiVecPixel: OS << " altivec pixel"; break;
176 case VectorType::AltiVecBool: OS << " altivec bool"; break;
177 case VectorType::NeonVector: OS << " neon"; break;
178 case VectorType::NeonPolyVector: OS << " neon poly"; break;
179 }
180 OS << " " << T->getNumElements();
181 dumpTypeAsChild(T->getElementType());
182 }
183 void VisitFunctionType(const FunctionType *T) {
184 auto EI = T->getExtInfo();
185 if (EI.getNoReturn()) OS << " noreturn";
186 if (EI.getProducesResult()) OS << " produces_result";
187 if (EI.getHasRegParm()) OS << " regparm " << EI.getRegParm();
188 OS << " " << FunctionType::getNameForCallConv(EI.getCC());
189 dumpTypeAsChild(T->getReturnType());
190 }
191 void VisitFunctionProtoType(const FunctionProtoType *T) {
192 auto EPI = T->getExtProtoInfo();
193 if (EPI.HasTrailingReturn) OS << " trailing_return";
194 if (T->isConst()) OS << " const";
195 if (T->isVolatile()) OS << " volatile";
196 if (T->isRestrict()) OS << " restrict";
197 switch (EPI.RefQualifier) {
198 case RQ_None: break;
199 case RQ_LValue: OS << " &"; break;
200 case RQ_RValue: OS << " &&"; break;
201 }
202 // FIXME: Exception specification.
203 // FIXME: Consumed parameters.
204 VisitFunctionType(T);
205 for (QualType PT : T->getParamTypes())
206 dumpTypeAsChild(PT);
207 if (EPI.Variadic)
208 dumpChild([=] { OS << "..."; });
209 }
210 void VisitUnresolvedUsingType(const UnresolvedUsingType *T) {
211 dumpDeclRef(T->getDecl());
212 }
213 void VisitTypedefType(const TypedefType *T) {
214 dumpDeclRef(T->getDecl());
215 }
216 void VisitTypeOfExprType(const TypeOfExprType *T) {
217 dumpStmt(T->getUnderlyingExpr());
218 }
219 void VisitDecltypeType(const DecltypeType *T) {
220 dumpStmt(T->getUnderlyingExpr());
221 }
222 void VisitUnaryTransformType(const UnaryTransformType *T) {
223 switch (T->getUTTKind()) {
224 case UnaryTransformType::EnumUnderlyingType:
225 OS << " underlying_type";
226 break;
227 }
228 dumpTypeAsChild(T->getBaseType());
229 }
230 void VisitTagType(const TagType *T) {
231 dumpDeclRef(T->getDecl());
232 }
233 void VisitAttributedType(const AttributedType *T) {
234 // FIXME: AttrKind
235 dumpTypeAsChild(T->getModifiedType());
236 }
237 void VisitTemplateTypeParmType(const TemplateTypeParmType *T) {
238 OS << " depth " << T->getDepth() << " index " << T->getIndex();
239 if (T->isParameterPack()) OS << " pack";
240 dumpDeclRef(T->getDecl());
241 }
242 void VisitSubstTemplateTypeParmType(const SubstTemplateTypeParmType *T) {
243 dumpTypeAsChild(T->getReplacedParameter());
244 }
245 void VisitSubstTemplateTypeParmPackType(
246 const SubstTemplateTypeParmPackType *T) {
247 dumpTypeAsChild(T->getReplacedParameter());
248 dumpTemplateArgument(T->getArgumentPack());
249 }
250 void VisitAutoType(const AutoType *T) {
251 if (T->isDecltypeAuto()) OS << " decltype(auto)";
252 if (!T->isDeduced())
253 OS << " undeduced";
254 }
255 void VisitTemplateSpecializationType(const TemplateSpecializationType *T) {
256 if (T->isTypeAlias()) OS << " alias";
257 OS << " "; T->getTemplateName().dump(OS);
258 for (auto &Arg : *T)
259 dumpTemplateArgument(Arg);
260 if (T->isTypeAlias())
261 dumpTypeAsChild(T->getAliasedType());
262 }
263 void VisitInjectedClassNameType(const InjectedClassNameType *T) {
264 dumpDeclRef(T->getDecl());
265 }
266 void VisitObjCInterfaceType(const ObjCInterfaceType *T) {
267 dumpDeclRef(T->getDecl());
268 }
269 void VisitObjCObjectPointerType(const ObjCObjectPointerType *T) {
270 dumpTypeAsChild(T->getPointeeType());
271 }
272 void VisitAtomicType(const AtomicType *T) {
273 dumpTypeAsChild(T->getValueType());
274 }
Xiuli Pan2d12e652016-05-03 05:37:07 +0000275 void VisitPipeType(const PipeType *T) {
276 dumpTypeAsChild(T->getElementType());
277 }
Richard Smithd5e7ff82014-10-31 01:17:45 +0000278 void VisitAdjustedType(const AdjustedType *T) {
279 dumpTypeAsChild(T->getOriginalType());
280 }
281 void VisitPackExpansionType(const PackExpansionType *T) {
282 if (auto N = T->getNumExpansions()) OS << " expansions " << *N;
283 if (!T->isSugared())
284 dumpTypeAsChild(T->getPattern());
285 }
286 // FIXME: ElaboratedType, DependentNameType,
287 // DependentTemplateSpecializationType, ObjCObjectType
288
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000289 // Decls
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000290 void VisitLabelDecl(const LabelDecl *D);
291 void VisitTypedefDecl(const TypedefDecl *D);
292 void VisitEnumDecl(const EnumDecl *D);
293 void VisitRecordDecl(const RecordDecl *D);
294 void VisitEnumConstantDecl(const EnumConstantDecl *D);
295 void VisitIndirectFieldDecl(const IndirectFieldDecl *D);
296 void VisitFunctionDecl(const FunctionDecl *D);
297 void VisitFieldDecl(const FieldDecl *D);
298 void VisitVarDecl(const VarDecl *D);
Richard Smithbdb84f32016-07-22 23:36:59 +0000299 void VisitDecompositionDecl(const DecompositionDecl *D);
Richard Smith7873de02016-08-11 22:25:46 +0000300 void VisitBindingDecl(const BindingDecl *D);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000301 void VisitFileScopeAsmDecl(const FileScopeAsmDecl *D);
302 void VisitImportDecl(const ImportDecl *D);
Nico Weber66220292016-03-02 17:28:48 +0000303 void VisitPragmaCommentDecl(const PragmaCommentDecl *D);
Nico Webercbbaeb12016-03-02 19:28:54 +0000304 void VisitPragmaDetectMismatchDecl(const PragmaDetectMismatchDecl *D);
Alexey Bataev958b9e72016-03-31 09:30:50 +0000305 void VisitCapturedDecl(const CapturedDecl *D);
306
307 // OpenMP decls
308 void VisitOMPThreadPrivateDecl(const OMPThreadPrivateDecl *D);
309 void VisitOMPDeclareReductionDecl(const OMPDeclareReductionDecl *D);
Kelvin Li1408f912018-09-26 04:28:39 +0000310 void VisitOMPRequiresDecl(const OMPRequiresDecl *D);
Alexey Bataev958b9e72016-03-31 09:30:50 +0000311 void VisitOMPCapturedExprDecl(const OMPCapturedExprDecl *D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000312
313 // C++ Decls
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000314 void VisitNamespaceDecl(const NamespaceDecl *D);
315 void VisitUsingDirectiveDecl(const UsingDirectiveDecl *D);
316 void VisitNamespaceAliasDecl(const NamespaceAliasDecl *D);
317 void VisitTypeAliasDecl(const TypeAliasDecl *D);
318 void VisitTypeAliasTemplateDecl(const TypeAliasTemplateDecl *D);
319 void VisitCXXRecordDecl(const CXXRecordDecl *D);
320 void VisitStaticAssertDecl(const StaticAssertDecl *D);
Richard Smithcbdf7332014-03-18 02:07:28 +0000321 template<typename SpecializationDecl>
Richard Smithf7514452014-10-30 21:02:37 +0000322 void VisitTemplateDeclSpecialization(const SpecializationDecl *D,
Richard Smithcbdf7332014-03-18 02:07:28 +0000323 bool DumpExplicitInst,
324 bool DumpRefOnly);
Richard Smith20ade552014-03-17 23:34:53 +0000325 template<typename TemplateDecl>
326 void VisitTemplateDecl(const TemplateDecl *D, bool DumpExplicitInst);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000327 void VisitFunctionTemplateDecl(const FunctionTemplateDecl *D);
328 void VisitClassTemplateDecl(const ClassTemplateDecl *D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000329 void VisitClassTemplateSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000330 const ClassTemplateSpecializationDecl *D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000331 void VisitClassTemplatePartialSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000332 const ClassTemplatePartialSpecializationDecl *D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000333 void VisitClassScopeFunctionSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000334 const ClassScopeFunctionSpecializationDecl *D);
David Majnemerd9b1a4f2015-11-04 03:40:30 +0000335 void VisitBuiltinTemplateDecl(const BuiltinTemplateDecl *D);
Richard Smithd25789a2013-09-18 01:36:02 +0000336 void VisitVarTemplateDecl(const VarTemplateDecl *D);
337 void VisitVarTemplateSpecializationDecl(
338 const VarTemplateSpecializationDecl *D);
339 void VisitVarTemplatePartialSpecializationDecl(
340 const VarTemplatePartialSpecializationDecl *D);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000341 void VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D);
342 void VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D);
343 void VisitTemplateTemplateParmDecl(const TemplateTemplateParmDecl *D);
344 void VisitUsingDecl(const UsingDecl *D);
345 void VisitUnresolvedUsingTypenameDecl(const UnresolvedUsingTypenameDecl *D);
346 void VisitUnresolvedUsingValueDecl(const UnresolvedUsingValueDecl *D);
347 void VisitUsingShadowDecl(const UsingShadowDecl *D);
Richard Smith5179eb72016-06-28 19:03:57 +0000348 void VisitConstructorUsingShadowDecl(const ConstructorUsingShadowDecl *D);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000349 void VisitLinkageSpecDecl(const LinkageSpecDecl *D);
350 void VisitAccessSpecDecl(const AccessSpecDecl *D);
351 void VisitFriendDecl(const FriendDecl *D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000352
353 // ObjC Decls
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000354 void VisitObjCIvarDecl(const ObjCIvarDecl *D);
355 void VisitObjCMethodDecl(const ObjCMethodDecl *D);
Douglas Gregor85f3f952015-07-07 03:57:15 +0000356 void VisitObjCTypeParamDecl(const ObjCTypeParamDecl *D);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000357 void VisitObjCCategoryDecl(const ObjCCategoryDecl *D);
358 void VisitObjCCategoryImplDecl(const ObjCCategoryImplDecl *D);
359 void VisitObjCProtocolDecl(const ObjCProtocolDecl *D);
360 void VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D);
361 void VisitObjCImplementationDecl(const ObjCImplementationDecl *D);
362 void VisitObjCCompatibleAliasDecl(const ObjCCompatibleAliasDecl *D);
363 void VisitObjCPropertyDecl(const ObjCPropertyDecl *D);
364 void VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D);
365 void VisitBlockDecl(const BlockDecl *D);
Mike Stump11289f42009-09-09 15:08:12 +0000366
Chris Lattner84ca3762007-08-30 01:00:35 +0000367 // Stmts.
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000368 void VisitDeclStmt(const DeclStmt *Node);
369 void VisitAttributedStmt(const AttributedStmt *Node);
Bruno Riccib1cc94b2018-10-27 21:12:20 +0000370 void VisitIfStmt(const IfStmt *Node);
Bruno Riccie2806f82018-10-29 16:12:37 +0000371 void VisitSwitchStmt(const SwitchStmt *Node);
Bruno Riccibacf7512018-10-30 13:42:41 +0000372 void VisitWhileStmt(const WhileStmt *Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000373 void VisitLabelStmt(const LabelStmt *Node);
374 void VisitGotoStmt(const GotoStmt *Node);
Pavel Labath1ef83422013-09-04 14:35:00 +0000375 void VisitCXXCatchStmt(const CXXCatchStmt *Node);
Bruno Ricci5b30571752018-10-28 12:30:53 +0000376 void VisitCaseStmt(const CaseStmt *Node);
Alexey Bataev958b9e72016-03-31 09:30:50 +0000377 void VisitCapturedStmt(const CapturedStmt *Node);
378
379 // OpenMP
380 void VisitOMPExecutableDirective(const OMPExecutableDirective *Node);
Mike Stump11289f42009-09-09 15:08:12 +0000381
Chris Lattner84ca3762007-08-30 01:00:35 +0000382 // Exprs
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000383 void VisitCastExpr(const CastExpr *Node);
Roman Lebedev12216f12018-07-27 07:27:14 +0000384 void VisitImplicitCastExpr(const ImplicitCastExpr *Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000385 void VisitDeclRefExpr(const DeclRefExpr *Node);
386 void VisitPredefinedExpr(const PredefinedExpr *Node);
387 void VisitCharacterLiteral(const CharacterLiteral *Node);
388 void VisitIntegerLiteral(const IntegerLiteral *Node);
Leonard Chandb01c3a2018-06-20 17:19:40 +0000389 void VisitFixedPointLiteral(const FixedPointLiteral *Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000390 void VisitFloatingLiteral(const FloatingLiteral *Node);
391 void VisitStringLiteral(const StringLiteral *Str);
Richard Smithf0514962014-06-03 08:24:28 +0000392 void VisitInitListExpr(const InitListExpr *ILE);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000393 void VisitUnaryOperator(const UnaryOperator *Node);
394 void VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *Node);
395 void VisitMemberExpr(const MemberExpr *Node);
396 void VisitExtVectorElementExpr(const ExtVectorElementExpr *Node);
397 void VisitBinaryOperator(const BinaryOperator *Node);
398 void VisitCompoundAssignOperator(const CompoundAssignOperator *Node);
399 void VisitAddrLabelExpr(const AddrLabelExpr *Node);
400 void VisitBlockExpr(const BlockExpr *Node);
401 void VisitOpaqueValueExpr(const OpaqueValueExpr *Node);
Richard Smith01ccebf2018-01-05 21:31:07 +0000402 void VisitGenericSelectionExpr(const GenericSelectionExpr *E);
Chris Lattner84ca3762007-08-30 01:00:35 +0000403
404 // C++
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000405 void VisitCXXNamedCastExpr(const CXXNamedCastExpr *Node);
406 void VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *Node);
407 void VisitCXXThisExpr(const CXXThisExpr *Node);
408 void VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *Node);
Richard Smith39eca9b2017-08-23 22:12:08 +0000409 void VisitCXXUnresolvedConstructExpr(const CXXUnresolvedConstructExpr *Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000410 void VisitCXXConstructExpr(const CXXConstructExpr *Node);
411 void VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *Node);
Reid Kleckner5c682bc2015-03-19 18:09:25 +0000412 void VisitCXXNewExpr(const CXXNewExpr *Node);
413 void VisitCXXDeleteExpr(const CXXDeleteExpr *Node);
Richard Smithe6c01442013-06-05 00:46:14 +0000414 void VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *Node);
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000415 void VisitExprWithCleanups(const ExprWithCleanups *Node);
416 void VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *Node);
Faisal Vali2b391ab2013-09-26 19:54:12 +0000417 void VisitLambdaExpr(const LambdaExpr *Node) {
Faisal Vali2b391ab2013-09-26 19:54:12 +0000418 dumpDecl(Node->getLambdaClass());
419 }
Serge Pavlov6b926032015-02-16 19:58:41 +0000420 void VisitSizeOfPackExpr(const SizeOfPackExpr *Node);
Alex Lorenzddbe0f52016-11-09 14:02:18 +0000421 void
422 VisitCXXDependentScopeMemberExpr(const CXXDependentScopeMemberExpr *Node);
Mike Stump11289f42009-09-09 15:08:12 +0000423
Chris Lattner84ca3762007-08-30 01:00:35 +0000424 // ObjC
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000425 void VisitObjCAtCatchStmt(const ObjCAtCatchStmt *Node);
426 void VisitObjCEncodeExpr(const ObjCEncodeExpr *Node);
427 void VisitObjCMessageExpr(const ObjCMessageExpr *Node);
428 void VisitObjCBoxedExpr(const ObjCBoxedExpr *Node);
429 void VisitObjCSelectorExpr(const ObjCSelectorExpr *Node);
430 void VisitObjCProtocolExpr(const ObjCProtocolExpr *Node);
431 void VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *Node);
432 void VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *Node);
433 void VisitObjCIvarRefExpr(const ObjCIvarRefExpr *Node);
434 void VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *Node);
Alexander Kornienkoebc17b52013-01-14 14:07:11 +0000435
436 // Comments.
437 const char *getCommandName(unsigned CommandID);
Stephen Kellycdbfb302018-12-02 17:30:40 +0000438 void dumpComment(const Comment *C, const FullComment *FC);
Alexander Kornienkoebc17b52013-01-14 14:07:11 +0000439
440 // Inline comments.
Stephen Kellycdbfb302018-12-02 17:30:40 +0000441 void visitTextComment(const TextComment *C, const FullComment *FC);
442 void visitInlineCommandComment(const InlineCommandComment *C,
443 const FullComment *FC);
444 void visitHTMLStartTagComment(const HTMLStartTagComment *C,
445 const FullComment *FC);
446 void visitHTMLEndTagComment(const HTMLEndTagComment *C,
447 const FullComment *FC);
Alexander Kornienkoebc17b52013-01-14 14:07:11 +0000448
449 // Block comments.
Stephen Kellycdbfb302018-12-02 17:30:40 +0000450 void visitBlockCommandComment(const BlockCommandComment *C,
451 const FullComment *FC);
452 void visitParamCommandComment(const ParamCommandComment *C,
453 const FullComment *FC);
454 void visitTParamCommandComment(const TParamCommandComment *C,
455 const FullComment *FC);
456 void visitVerbatimBlockComment(const VerbatimBlockComment *C,
457 const FullComment *FC);
458 void visitVerbatimBlockLineComment(const VerbatimBlockLineComment *C,
459 const FullComment *FC);
460 void visitVerbatimLineComment(const VerbatimLineComment *C,
461 const FullComment *FC);
Chris Lattnercbe4f772007-08-08 22:51:59 +0000462 };
Alexander Kornienkoab9db512015-06-22 23:07:51 +0000463}
Chris Lattnercbe4f772007-08-08 22:51:59 +0000464
465//===----------------------------------------------------------------------===//
Chris Lattner11e30d32007-08-30 06:17:34 +0000466// Utilities
467//===----------------------------------------------------------------------===//
468
Richard Smithd5e7ff82014-10-31 01:17:45 +0000469void ASTDumper::dumpTypeAsChild(QualType T) {
470 SplitQualType SQT = T.split();
471 if (!SQT.Quals.hasQualifiers())
472 return dumpTypeAsChild(SQT.Ty);
473
474 dumpChild([=] {
475 OS << "QualType";
Stephen Kellyd8744a72018-12-05 21:12:39 +0000476 NodeDumper.dumpPointer(T.getAsOpaquePtr());
Richard Smithd5e7ff82014-10-31 01:17:45 +0000477 OS << " ";
Stephen Kellyd8744a72018-12-05 21:12:39 +0000478 NodeDumper.dumpBareType(T, false);
Richard Smithd5e7ff82014-10-31 01:17:45 +0000479 OS << " " << T.split().Quals.getAsString();
480 dumpTypeAsChild(T.split().Ty);
481 });
482}
483
484void ASTDumper::dumpTypeAsChild(const Type *T) {
485 dumpChild([=] {
486 if (!T) {
Stephen Kelly27e948c2018-11-29 19:30:37 +0000487 ColorScope Color(OS, ShowColors, NullColor);
Richard Smithd5e7ff82014-10-31 01:17:45 +0000488 OS << "<<<NULL>>>";
489 return;
490 }
Serge Pavlova6adc9e2015-12-28 17:19:12 +0000491 if (const LocInfoType *LIT = llvm::dyn_cast<LocInfoType>(T)) {
492 {
Stephen Kelly27e948c2018-11-29 19:30:37 +0000493 ColorScope Color(OS, ShowColors, TypeColor);
Serge Pavlova6adc9e2015-12-28 17:19:12 +0000494 OS << "LocInfo Type";
495 }
Stephen Kellyd8744a72018-12-05 21:12:39 +0000496 NodeDumper.dumpPointer(T);
Serge Pavlova6adc9e2015-12-28 17:19:12 +0000497 dumpTypeAsChild(LIT->getTypeSourceInfo()->getType());
498 return;
499 }
Richard Smithd5e7ff82014-10-31 01:17:45 +0000500
501 {
Stephen Kelly27e948c2018-11-29 19:30:37 +0000502 ColorScope Color(OS, ShowColors, TypeColor);
Richard Smithd5e7ff82014-10-31 01:17:45 +0000503 OS << T->getTypeClassName() << "Type";
504 }
Stephen Kellyd8744a72018-12-05 21:12:39 +0000505 NodeDumper.dumpPointer(T);
Richard Smithd5e7ff82014-10-31 01:17:45 +0000506 OS << " ";
Stephen Kellyd8744a72018-12-05 21:12:39 +0000507 NodeDumper.dumpBareType(QualType(T, 0), false);
Richard Smithd5e7ff82014-10-31 01:17:45 +0000508
509 QualType SingleStepDesugar =
510 T->getLocallyUnqualifiedSingleStepDesugaredType();
511 if (SingleStepDesugar != QualType(T, 0))
512 OS << " sugar";
513 if (T->isDependentType())
514 OS << " dependent";
515 else if (T->isInstantiationDependentType())
516 OS << " instantiation_dependent";
517 if (T->isVariablyModifiedType())
518 OS << " variably_modified";
519 if (T->containsUnexpandedParameterPack())
520 OS << " contains_unexpanded_pack";
521 if (T->isFromAST())
522 OS << " imported";
523
524 TypeVisitor<ASTDumper>::Visit(T);
525
526 if (SingleStepDesugar != QualType(T, 0))
527 dumpTypeAsChild(SingleStepDesugar);
528 });
529}
530
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000531void ASTDumper::dumpDeclRef(const Decl *D, const char *Label) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000532 if (!D)
533 return;
534
Richard Smithf7514452014-10-30 21:02:37 +0000535 dumpChild([=]{
536 if (Label)
537 OS << Label << ' ';
538 dumpBareDeclRef(D);
539 });
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000540}
541
Richard Trieude5cc7d2013-01-31 01:44:26 +0000542bool ASTDumper::hasNodes(const DeclContext *DC) {
543 if (!DC)
544 return false;
545
Richard Smith1d209d02013-05-23 01:49:11 +0000546 return DC->hasExternalLexicalStorage() ||
Richard Smith3a36ac12017-03-09 22:00:01 +0000547 (Deserialize ? DC->decls_begin() != DC->decls_end()
548 : DC->noload_decls_begin() != DC->noload_decls_end());
Richard Trieude5cc7d2013-01-31 01:44:26 +0000549}
550
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000551void ASTDumper::dumpDeclContext(const DeclContext *DC) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000552 if (!DC)
553 return;
Richard Smithdcc2c452014-03-17 23:00:06 +0000554
Richard Smith3a36ac12017-03-09 22:00:01 +0000555 for (auto *D : (Deserialize ? DC->decls() : DC->noload_decls()))
Richard Smithf7514452014-10-30 21:02:37 +0000556 dumpDecl(D);
Richard Smithdcc2c452014-03-17 23:00:06 +0000557
558 if (DC->hasExternalLexicalStorage()) {
Stephen Kelly27e948c2018-11-29 19:30:37 +0000559 dumpChild([=] {
560 ColorScope Color(OS, ShowColors, UndeserializedColor);
Richard Smithf7514452014-10-30 21:02:37 +0000561 OS << "<undeserialized declarations>";
562 });
Richard Smith1d209d02013-05-23 01:49:11 +0000563 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000564}
565
Richard Smith35f986d2014-08-11 22:11:07 +0000566void ASTDumper::dumpLookups(const DeclContext *DC, bool DumpDecls) {
Richard Smithf7514452014-10-30 21:02:37 +0000567 dumpChild([=] {
568 OS << "StoredDeclsMap ";
Stephen Kellyd8744a72018-12-05 21:12:39 +0000569 NodeDumper.dumpBareDeclRef(cast<Decl>(DC));
Richard Smith33937e72013-06-22 21:49:40 +0000570
Richard Smithf7514452014-10-30 21:02:37 +0000571 const DeclContext *Primary = DC->getPrimaryContext();
572 if (Primary != DC) {
573 OS << " primary";
Stephen Kellyd8744a72018-12-05 21:12:39 +0000574 NodeDumper.dumpPointer(cast<Decl>(Primary));
Richard Smith33937e72013-06-22 21:49:40 +0000575 }
576
Richard Smithf7514452014-10-30 21:02:37 +0000577 bool HasUndeserializedLookups = Primary->hasExternalVisibleStorage();
Richard Smith35f986d2014-08-11 22:11:07 +0000578
Sam McCall091b1ef2018-01-16 12:33:46 +0000579 auto Range = Deserialize
580 ? Primary->lookups()
581 : Primary->noload_lookups(/*PreserveInternalState=*/true);
582 for (auto I = Range.begin(), E = Range.end(); I != E; ++I) {
Richard Smithf7514452014-10-30 21:02:37 +0000583 DeclarationName Name = I.getLookupName();
Richard Smith3a36ac12017-03-09 22:00:01 +0000584 DeclContextLookupResult R = *I;
Richard Smith35f986d2014-08-11 22:11:07 +0000585
Richard Smithf7514452014-10-30 21:02:37 +0000586 dumpChild([=] {
587 OS << "DeclarationName ";
588 {
Stephen Kelly27e948c2018-11-29 19:30:37 +0000589 ColorScope Color(OS, ShowColors, DeclNameColor);
Richard Smithf7514452014-10-30 21:02:37 +0000590 OS << '\'' << Name << '\'';
591 }
Richard Smith35f986d2014-08-11 22:11:07 +0000592
Richard Smithf7514452014-10-30 21:02:37 +0000593 for (DeclContextLookupResult::iterator RI = R.begin(), RE = R.end();
594 RI != RE; ++RI) {
595 dumpChild([=] {
Stephen Kellyd8744a72018-12-05 21:12:39 +0000596 NodeDumper.dumpBareDeclRef(*RI);
Richard Smithf7514452014-10-30 21:02:37 +0000597
598 if ((*RI)->isHidden())
599 OS << " hidden";
600
601 // If requested, dump the redecl chain for this lookup.
602 if (DumpDecls) {
603 // Dump earliest decl first.
604 std::function<void(Decl *)> DumpWithPrev = [&](Decl *D) {
605 if (Decl *Prev = D->getPreviousDecl())
606 DumpWithPrev(Prev);
607 dumpDecl(D);
608 };
609 DumpWithPrev(*RI);
610 }
611 });
612 }
613 });
Richard Smith33937e72013-06-22 21:49:40 +0000614 }
Richard Smith33937e72013-06-22 21:49:40 +0000615
Richard Smithf7514452014-10-30 21:02:37 +0000616 if (HasUndeserializedLookups) {
617 dumpChild([=] {
Stephen Kelly27e948c2018-11-29 19:30:37 +0000618 ColorScope Color(OS, ShowColors, UndeserializedColor);
Richard Smithf7514452014-10-30 21:02:37 +0000619 OS << "<undeserialized lookups>";
620 });
621 }
622 });
Richard Smith33937e72013-06-22 21:49:40 +0000623}
624
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000625void ASTDumper::dumpAttr(const Attr *A) {
Richard Smithf7514452014-10-30 21:02:37 +0000626 dumpChild([=] {
627 {
Stephen Kelly27e948c2018-11-29 19:30:37 +0000628 ColorScope Color(OS, ShowColors, AttrColor);
Aaron Ballman36a53502014-01-16 13:03:14 +0000629
Richard Smithf7514452014-10-30 21:02:37 +0000630 switch (A->getKind()) {
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000631#define ATTR(X) case attr::X: OS << #X; break;
632#include "clang/Basic/AttrList.inc"
Richard Smithf7514452014-10-30 21:02:37 +0000633 }
634 OS << "Attr";
Richard Trieud215b8d2013-01-26 01:31:20 +0000635 }
Stephen Kellyd8744a72018-12-05 21:12:39 +0000636 NodeDumper.dumpPointer(A);
637 NodeDumper.dumpSourceRange(A->getRange());
Richard Smithf7514452014-10-30 21:02:37 +0000638 if (A->isInherited())
639 OS << " Inherited";
640 if (A->isImplicit())
641 OS << " Implicit";
Hans Wennborgb0a8b4a2014-05-31 04:05:57 +0000642#include "clang/AST/AttrDump.inc"
Richard Smithf7514452014-10-30 21:02:37 +0000643 });
Alexander Kornienko5bc364e2013-01-07 17:53:08 +0000644}
645
Richard Smith71bec062013-10-15 21:58:30 +0000646static void dumpPreviousDeclImpl(raw_ostream &OS, ...) {}
647
648template<typename T>
649static void dumpPreviousDeclImpl(raw_ostream &OS, const Mergeable<T> *D) {
Rafael Espindola8db352d2013-10-17 15:37:26 +0000650 const T *First = D->getFirstDecl();
Richard Smith71bec062013-10-15 21:58:30 +0000651 if (First != D)
652 OS << " first " << First;
Richard Smithf5f43542013-02-07 01:35:44 +0000653}
654
655template<typename T>
Richard Smith71bec062013-10-15 21:58:30 +0000656static void dumpPreviousDeclImpl(raw_ostream &OS, const Redeclarable<T> *D) {
657 const T *Prev = D->getPreviousDecl();
658 if (Prev)
659 OS << " prev " << Prev;
Richard Smithf5f43542013-02-07 01:35:44 +0000660}
661
Richard Smith71bec062013-10-15 21:58:30 +0000662/// Dump the previous declaration in the redeclaration chain for a declaration,
663/// if any.
664static void dumpPreviousDecl(raw_ostream &OS, const Decl *D) {
Richard Smithf5f43542013-02-07 01:35:44 +0000665 switch (D->getKind()) {
666#define DECL(DERIVED, BASE) \
667 case Decl::DERIVED: \
Richard Smith71bec062013-10-15 21:58:30 +0000668 return dumpPreviousDeclImpl(OS, cast<DERIVED##Decl>(D));
Richard Smithf5f43542013-02-07 01:35:44 +0000669#define ABSTRACT_DECL(DECL)
670#include "clang/AST/DeclNodes.inc"
671 }
672 llvm_unreachable("Decl that isn't part of DeclNodes.inc!");
673}
674
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000675//===----------------------------------------------------------------------===//
676// C++ Utilities
677//===----------------------------------------------------------------------===//
678
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000679void ASTDumper::dumpCXXCtorInitializer(const CXXCtorInitializer *Init) {
Richard Smithf7514452014-10-30 21:02:37 +0000680 dumpChild([=] {
681 OS << "CXXCtorInitializer";
682 if (Init->isAnyMemberInitializer()) {
683 OS << ' ';
Stephen Kellyd8744a72018-12-05 21:12:39 +0000684 NodeDumper.dumpBareDeclRef(Init->getAnyMember());
Richard Smithf7514452014-10-30 21:02:37 +0000685 } else if (Init->isBaseInitializer()) {
Stephen Kellyd8744a72018-12-05 21:12:39 +0000686 NodeDumper.dumpType(QualType(Init->getBaseClass(), 0));
Richard Smithf7514452014-10-30 21:02:37 +0000687 } else if (Init->isDelegatingInitializer()) {
Stephen Kellyd8744a72018-12-05 21:12:39 +0000688 NodeDumper.dumpType(Init->getTypeSourceInfo()->getType());
Richard Smithf7514452014-10-30 21:02:37 +0000689 } else {
690 llvm_unreachable("Unknown initializer type");
691 }
692 dumpStmt(Init->getInit());
693 });
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000694}
695
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000696void ASTDumper::dumpTemplateParameters(const TemplateParameterList *TPL) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000697 if (!TPL)
698 return;
699
Alexander Kornienko787f4c32012-12-20 11:08:38 +0000700 for (TemplateParameterList::const_iterator I = TPL->begin(), E = TPL->end();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000701 I != E; ++I)
702 dumpDecl(*I);
703}
704
705void ASTDumper::dumpTemplateArgumentListInfo(
706 const TemplateArgumentListInfo &TALI) {
Richard Smithf7514452014-10-30 21:02:37 +0000707 for (unsigned i = 0, e = TALI.size(); i < e; ++i)
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000708 dumpTemplateArgumentLoc(TALI[i]);
709}
710
711void ASTDumper::dumpTemplateArgumentLoc(const TemplateArgumentLoc &A) {
712 dumpTemplateArgument(A.getArgument(), A.getSourceRange());
713}
714
715void ASTDumper::dumpTemplateArgumentList(const TemplateArgumentList &TAL) {
716 for (unsigned i = 0, e = TAL.size(); i < e; ++i)
717 dumpTemplateArgument(TAL[i]);
718}
719
720void ASTDumper::dumpTemplateArgument(const TemplateArgument &A, SourceRange R) {
Richard Smithf7514452014-10-30 21:02:37 +0000721 dumpChild([=] {
722 OS << "TemplateArgument";
723 if (R.isValid())
Stephen Kellyd8744a72018-12-05 21:12:39 +0000724 NodeDumper.dumpSourceRange(R);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000725
Richard Smithf7514452014-10-30 21:02:37 +0000726 switch (A.getKind()) {
727 case TemplateArgument::Null:
728 OS << " null";
729 break;
730 case TemplateArgument::Type:
731 OS << " type";
Stephen Kellyd8744a72018-12-05 21:12:39 +0000732 NodeDumper.dumpType(A.getAsType());
Richard Smithf7514452014-10-30 21:02:37 +0000733 break;
734 case TemplateArgument::Declaration:
735 OS << " decl";
736 dumpDeclRef(A.getAsDecl());
737 break;
738 case TemplateArgument::NullPtr:
739 OS << " nullptr";
740 break;
741 case TemplateArgument::Integral:
742 OS << " integral " << A.getAsIntegral();
743 break;
744 case TemplateArgument::Template:
745 OS << " template ";
746 A.getAsTemplate().dump(OS);
747 break;
748 case TemplateArgument::TemplateExpansion:
Richard Trieu59c289f2018-08-21 22:55:26 +0000749 OS << " template expansion ";
Richard Smithf7514452014-10-30 21:02:37 +0000750 A.getAsTemplateOrTemplatePattern().dump(OS);
751 break;
752 case TemplateArgument::Expression:
753 OS << " expr";
754 dumpStmt(A.getAsExpr());
755 break;
756 case TemplateArgument::Pack:
757 OS << " pack";
758 for (TemplateArgument::pack_iterator I = A.pack_begin(), E = A.pack_end();
759 I != E; ++I)
760 dumpTemplateArgument(*I);
761 break;
Richard Trieude5cc7d2013-01-31 01:44:26 +0000762 }
Richard Smithf7514452014-10-30 21:02:37 +0000763 });
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000764}
765
Chris Lattner11e30d32007-08-30 06:17:34 +0000766//===----------------------------------------------------------------------===//
Douglas Gregor85f3f952015-07-07 03:57:15 +0000767// Objective-C Utilities
768//===----------------------------------------------------------------------===//
769void ASTDumper::dumpObjCTypeParamList(const ObjCTypeParamList *typeParams) {
770 if (!typeParams)
771 return;
772
773 for (auto typeParam : *typeParams) {
774 dumpDecl(typeParam);
775 }
776}
777
778//===----------------------------------------------------------------------===//
Alexander Kornienko61c93bd2012-12-11 15:28:09 +0000779// Decl dumping methods.
Chris Lattnercbe4f772007-08-08 22:51:59 +0000780//===----------------------------------------------------------------------===//
781
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000782void ASTDumper::dumpDecl(const Decl *D) {
Richard Smithf7514452014-10-30 21:02:37 +0000783 dumpChild([=] {
784 if (!D) {
Stephen Kelly27e948c2018-11-29 19:30:37 +0000785 ColorScope Color(OS, ShowColors, NullColor);
Richard Smithf7514452014-10-30 21:02:37 +0000786 OS << "<<<NULL>>>";
787 return;
788 }
Mike Stump11289f42009-09-09 15:08:12 +0000789
Richard Smithf7514452014-10-30 21:02:37 +0000790 {
Stephen Kelly27e948c2018-11-29 19:30:37 +0000791 ColorScope Color(OS, ShowColors, DeclKindNameColor);
Richard Smithf7514452014-10-30 21:02:37 +0000792 OS << D->getDeclKindName() << "Decl";
793 }
Stephen Kellyd8744a72018-12-05 21:12:39 +0000794 NodeDumper.dumpPointer(D);
Richard Smithf7514452014-10-30 21:02:37 +0000795 if (D->getLexicalDeclContext() != D->getDeclContext())
796 OS << " parent " << cast<Decl>(D->getDeclContext());
797 dumpPreviousDecl(OS, D);
Stephen Kellyd8744a72018-12-05 21:12:39 +0000798 NodeDumper.dumpSourceRange(D->getSourceRange());
Richard Smithf7514452014-10-30 21:02:37 +0000799 OS << ' ';
Stephen Kellyd8744a72018-12-05 21:12:39 +0000800 NodeDumper.dumpLocation(D->getLocation());
Richard Smith26342f92017-05-17 00:24:14 +0000801 if (D->isFromASTFile())
802 OS << " imported";
803 if (Module *M = D->getOwningModule())
Richard Smithf7514452014-10-30 21:02:37 +0000804 OS << " in " << M->getFullModuleName();
Richard Smitha2eb4092015-06-22 18:47:01 +0000805 if (auto *ND = dyn_cast<NamedDecl>(D))
806 for (Module *M : D->getASTContext().getModulesWithMergedDefinition(
807 const_cast<NamedDecl *>(ND)))
808 dumpChild([=] { OS << "also in " << M->getFullModuleName(); });
Richard Smithf7514452014-10-30 21:02:37 +0000809 if (const NamedDecl *ND = dyn_cast<NamedDecl>(D))
810 if (ND->isHidden())
811 OS << " hidden";
812 if (D->isImplicit())
813 OS << " implicit";
814 if (D->isUsed())
815 OS << " used";
816 else if (D->isThisDeclarationReferenced())
817 OS << " referenced";
818 if (D->isInvalidDecl())
819 OS << " invalid";
Hans Wennborg76b00532014-12-05 22:38:57 +0000820 if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
821 if (FD->isConstexpr())
822 OS << " constexpr";
823
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000824
Richard Smithf7514452014-10-30 21:02:37 +0000825 ConstDeclVisitor<ASTDumper>::Visit(D);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000826
Richard Smithf7514452014-10-30 21:02:37 +0000827 for (Decl::attr_iterator I = D->attr_begin(), E = D->attr_end(); I != E;
828 ++I)
829 dumpAttr(*I);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000830
Richard Smithf7514452014-10-30 21:02:37 +0000831 if (const FullComment *Comment =
832 D->getASTContext().getLocalCommentForDeclUncached(D))
Stephen Kelly570b2972018-12-09 13:18:55 +0000833 dumpComment(Comment, Comment);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000834
Richard Smithf7514452014-10-30 21:02:37 +0000835 // Decls within functions are visited by the body.
836 if (!isa<FunctionDecl>(*D) && !isa<ObjCMethodDecl>(*D) &&
837 hasNodes(dyn_cast<DeclContext>(D)))
838 dumpDeclContext(cast<DeclContext>(D));
839 });
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000840}
841
Stephen Kellyd8744a72018-12-05 21:12:39 +0000842void ASTDumper::VisitLabelDecl(const LabelDecl *D) { NodeDumper.dumpName(D); }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000843
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000844void ASTDumper::VisitTypedefDecl(const TypedefDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +0000845 NodeDumper.dumpName(D);
846 NodeDumper.dumpType(D->getUnderlyingType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000847 if (D->isModulePrivate())
848 OS << " __module_private__";
Richard Smithba3a4f92016-01-12 21:59:26 +0000849 dumpTypeAsChild(D->getUnderlyingType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000850}
851
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000852void ASTDumper::VisitEnumDecl(const EnumDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000853 if (D->isScoped()) {
854 if (D->isScopedUsingClassTag())
855 OS << " class";
856 else
857 OS << " struct";
858 }
Stephen Kellyd8744a72018-12-05 21:12:39 +0000859 NodeDumper.dumpName(D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000860 if (D->isModulePrivate())
861 OS << " __module_private__";
862 if (D->isFixed())
Stephen Kellyd8744a72018-12-05 21:12:39 +0000863 NodeDumper.dumpType(D->getIntegerType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000864}
865
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000866void ASTDumper::VisitRecordDecl(const RecordDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000867 OS << ' ' << D->getKindName();
Stephen Kellyd8744a72018-12-05 21:12:39 +0000868 NodeDumper.dumpName(D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000869 if (D->isModulePrivate())
870 OS << " __module_private__";
Richard Smith99bc1b92013-08-30 05:32:29 +0000871 if (D->isCompleteDefinition())
872 OS << " definition";
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000873}
874
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000875void ASTDumper::VisitEnumConstantDecl(const EnumConstantDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +0000876 NodeDumper.dumpName(D);
877 NodeDumper.dumpType(D->getType());
Richard Smithf7514452014-10-30 21:02:37 +0000878 if (const Expr *Init = D->getInitExpr())
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000879 dumpStmt(Init);
880}
881
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000882void ASTDumper::VisitIndirectFieldDecl(const IndirectFieldDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +0000883 NodeDumper.dumpName(D);
884 NodeDumper.dumpType(D->getType());
Richard Smithdcc2c452014-03-17 23:00:06 +0000885
Richard Smith8aa49222014-03-18 00:35:12 +0000886 for (auto *Child : D->chain())
Richard Smithf7514452014-10-30 21:02:37 +0000887 dumpDeclRef(Child);
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000888}
889
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000890void ASTDumper::VisitFunctionDecl(const FunctionDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +0000891 NodeDumper.dumpName(D);
892 NodeDumper.dumpType(D->getType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000893
Rafael Espindola6ae7e502013-04-03 19:27:57 +0000894 StorageClass SC = D->getStorageClass();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000895 if (SC != SC_None)
896 OS << ' ' << VarDecl::getStorageClassSpecifierString(SC);
897 if (D->isInlineSpecified())
898 OS << " inline";
899 if (D->isVirtualAsWritten())
900 OS << " virtual";
901 if (D->isModulePrivate())
902 OS << " __module_private__";
903
904 if (D->isPure())
905 OS << " pure";
Richard Smith5a2e6b92016-11-21 23:43:54 +0000906 if (D->isDefaulted()) {
907 OS << " default";
908 if (D->isDeleted())
909 OS << "_delete";
910 }
911 if (D->isDeletedAsWritten())
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000912 OS << " delete";
Richard Smith5a2e6b92016-11-21 23:43:54 +0000913 if (D->isTrivial())
914 OS << " trivial";
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000915
Richard Smithadaa0152013-05-17 02:09:46 +0000916 if (const FunctionProtoType *FPT = D->getType()->getAs<FunctionProtoType>()) {
917 FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo();
Richard Smith8acb4282014-07-31 21:57:55 +0000918 switch (EPI.ExceptionSpec.Type) {
Richard Smithadaa0152013-05-17 02:09:46 +0000919 default: break;
920 case EST_Unevaluated:
Richard Smith8acb4282014-07-31 21:57:55 +0000921 OS << " noexcept-unevaluated " << EPI.ExceptionSpec.SourceDecl;
Richard Smithadaa0152013-05-17 02:09:46 +0000922 break;
923 case EST_Uninstantiated:
Richard Smith8acb4282014-07-31 21:57:55 +0000924 OS << " noexcept-uninstantiated " << EPI.ExceptionSpec.SourceTemplate;
Richard Smithadaa0152013-05-17 02:09:46 +0000925 break;
926 }
927 }
928
Richard Smithf7514452014-10-30 21:02:37 +0000929 if (const FunctionTemplateSpecializationInfo *FTSI =
930 D->getTemplateSpecializationInfo())
Richard Trieude5cc7d2013-01-31 01:44:26 +0000931 dumpTemplateArgumentList(*FTSI->TemplateArguments);
Richard Trieude5cc7d2013-01-31 01:44:26 +0000932
Richard Smith8a639892015-01-24 01:07:20 +0000933 if (!D->param_begin() && D->getNumParams())
934 dumpChild([=] { OS << "<<NULL params x " << D->getNumParams() << ">>"; });
935 else
David Majnemera3debed2016-06-24 05:33:44 +0000936 for (const ParmVarDecl *Parameter : D->parameters())
937 dumpDecl(Parameter);
Richard Smithf7514452014-10-30 21:02:37 +0000938
939 if (const CXXConstructorDecl *C = dyn_cast<CXXConstructorDecl>(D))
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000940 for (CXXConstructorDecl::init_const_iterator I = C->init_begin(),
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000941 E = C->init_end();
Richard Smithf7514452014-10-30 21:02:37 +0000942 I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000943 dumpCXXCtorInitializer(*I);
944
Lenar Safin9ae21552017-07-29 20:42:58 +0000945 if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(D)) {
Lang Hames19e07e12017-06-20 21:06:00 +0000946 if (MD->size_overridden_methods() != 0) {
Aaron Ballman8c208282017-12-21 21:42:42 +0000947 auto dumpOverride = [=](const CXXMethodDecl *D) {
948 SplitQualType T_split = D->getType().split();
949 OS << D << " " << D->getParent()->getName()
950 << "::" << D->getNameAsString() << " '"
951 << QualType::getAsString(T_split, PrintPolicy) << "'";
952 };
Lang Hames19e07e12017-06-20 21:06:00 +0000953
954 dumpChild([=] {
Benjamin Krameracfa3392017-12-17 23:52:45 +0000955 auto Overrides = MD->overridden_methods();
Lang Hames19e07e12017-06-20 21:06:00 +0000956 OS << "Overrides: [ ";
Benjamin Krameracfa3392017-12-17 23:52:45 +0000957 dumpOverride(*Overrides.begin());
Lang Hames19e07e12017-06-20 21:06:00 +0000958 for (const auto *Override :
Benjamin Krameracfa3392017-12-17 23:52:45 +0000959 llvm::make_range(Overrides.begin() + 1, Overrides.end())) {
Lenar Safin9ae21552017-07-29 20:42:58 +0000960 OS << ", ";
Lang Hames19e07e12017-06-20 21:06:00 +0000961 dumpOverride(Override);
Lenar Safin9ae21552017-07-29 20:42:58 +0000962 }
Lang Hames19e07e12017-06-20 21:06:00 +0000963 OS << " ]";
964 });
965 }
Lenar Safin9ae21552017-07-29 20:42:58 +0000966 }
Lang Hames19e07e12017-06-20 21:06:00 +0000967
Richard Smithf7514452014-10-30 21:02:37 +0000968 if (D->doesThisDeclarationHaveABody())
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000969 dumpStmt(D->getBody());
970}
971
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000972void ASTDumper::VisitFieldDecl(const FieldDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +0000973 NodeDumper.dumpName(D);
974 NodeDumper.dumpType(D->getType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000975 if (D->isMutable())
976 OS << " mutable";
977 if (D->isModulePrivate())
978 OS << " __module_private__";
Richard Trieude5cc7d2013-01-31 01:44:26 +0000979
Richard Smithf7514452014-10-30 21:02:37 +0000980 if (D->isBitField())
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000981 dumpStmt(D->getBitWidth());
Richard Smithf7514452014-10-30 21:02:37 +0000982 if (Expr *Init = D->getInClassInitializer())
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000983 dumpStmt(Init);
984}
985
Alexander Kornienko540bacb2013-02-01 12:35:51 +0000986void ASTDumper::VisitVarDecl(const VarDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +0000987 NodeDumper.dumpName(D);
988 NodeDumper.dumpType(D->getType());
Rafael Espindola6ae7e502013-04-03 19:27:57 +0000989 StorageClass SC = D->getStorageClass();
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000990 if (SC != SC_None)
991 OS << ' ' << VarDecl::getStorageClassSpecifierString(SC);
Richard Smithfd3834f2013-04-13 02:43:54 +0000992 switch (D->getTLSKind()) {
993 case VarDecl::TLS_None: break;
994 case VarDecl::TLS_Static: OS << " tls"; break;
995 case VarDecl::TLS_Dynamic: OS << " tls_dynamic"; break;
996 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +0000997 if (D->isModulePrivate())
998 OS << " __module_private__";
999 if (D->isNRVOVariable())
1000 OS << " nrvo";
Richard Smith62f19e72016-06-25 00:15:56 +00001001 if (D->isInline())
1002 OS << " inline";
1003 if (D->isConstexpr())
1004 OS << " constexpr";
Richard Trieude5cc7d2013-01-31 01:44:26 +00001005 if (D->hasInit()) {
Richard Smithd9967cc2014-07-10 22:54:03 +00001006 switch (D->getInitStyle()) {
1007 case VarDecl::CInit: OS << " cinit"; break;
1008 case VarDecl::CallInit: OS << " callinit"; break;
1009 case VarDecl::ListInit: OS << " listinit"; break;
1010 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001011 dumpStmt(D->getInit());
Richard Trieude5cc7d2013-01-31 01:44:26 +00001012 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001013}
1014
Richard Smithbdb84f32016-07-22 23:36:59 +00001015void ASTDumper::VisitDecompositionDecl(const DecompositionDecl *D) {
1016 VisitVarDecl(D);
1017 for (auto *B : D->bindings())
1018 dumpDecl(B);
1019}
1020
Richard Smith7873de02016-08-11 22:25:46 +00001021void ASTDumper::VisitBindingDecl(const BindingDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +00001022 NodeDumper.dumpName(D);
1023 NodeDumper.dumpType(D->getType());
Richard Smith7873de02016-08-11 22:25:46 +00001024 if (auto *E = D->getBinding())
1025 dumpStmt(E);
1026}
1027
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001028void ASTDumper::VisitFileScopeAsmDecl(const FileScopeAsmDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001029 dumpStmt(D->getAsmString());
1030}
1031
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001032void ASTDumper::VisitImportDecl(const ImportDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001033 OS << ' ' << D->getImportedModule()->getFullModuleName();
1034}
1035
Nico Weber66220292016-03-02 17:28:48 +00001036void ASTDumper::VisitPragmaCommentDecl(const PragmaCommentDecl *D) {
1037 OS << ' ';
1038 switch (D->getCommentKind()) {
1039 case PCK_Unknown: llvm_unreachable("unexpected pragma comment kind");
1040 case PCK_Compiler: OS << "compiler"; break;
1041 case PCK_ExeStr: OS << "exestr"; break;
1042 case PCK_Lib: OS << "lib"; break;
1043 case PCK_Linker: OS << "linker"; break;
1044 case PCK_User: OS << "user"; break;
1045 }
1046 StringRef Arg = D->getArg();
1047 if (!Arg.empty())
1048 OS << " \"" << Arg << "\"";
1049}
1050
Nico Webercbbaeb12016-03-02 19:28:54 +00001051void ASTDumper::VisitPragmaDetectMismatchDecl(
1052 const PragmaDetectMismatchDecl *D) {
1053 OS << " \"" << D->getName() << "\" \"" << D->getValue() << "\"";
1054}
1055
Alexey Bataev958b9e72016-03-31 09:30:50 +00001056void ASTDumper::VisitCapturedDecl(const CapturedDecl *D) {
1057 dumpStmt(D->getBody());
1058}
1059
1060//===----------------------------------------------------------------------===//
1061// OpenMP Declarations
1062//===----------------------------------------------------------------------===//
1063
1064void ASTDumper::VisitOMPThreadPrivateDecl(const OMPThreadPrivateDecl *D) {
1065 for (auto *E : D->varlists())
1066 dumpStmt(E);
1067}
1068
1069void ASTDumper::VisitOMPDeclareReductionDecl(const OMPDeclareReductionDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +00001070 NodeDumper.dumpName(D);
1071 NodeDumper.dumpType(D->getType());
Alexey Bataev958b9e72016-03-31 09:30:50 +00001072 OS << " combiner";
1073 dumpStmt(D->getCombiner());
1074 if (auto *Initializer = D->getInitializer()) {
1075 OS << " initializer";
Alexey Bataev070f43a2017-09-06 14:49:58 +00001076 switch (D->getInitializerKind()) {
1077 case OMPDeclareReductionDecl::DirectInit:
1078 OS << " omp_priv = ";
1079 break;
1080 case OMPDeclareReductionDecl::CopyInit:
1081 OS << " omp_priv ()";
1082 break;
1083 case OMPDeclareReductionDecl::CallInit:
1084 break;
1085 }
Alexey Bataev958b9e72016-03-31 09:30:50 +00001086 dumpStmt(Initializer);
1087 }
1088}
1089
Kelvin Li1408f912018-09-26 04:28:39 +00001090void ASTDumper::VisitOMPRequiresDecl(const OMPRequiresDecl *D) {
1091 for (auto *C : D->clauselists()) {
1092 dumpChild([=] {
1093 if (!C) {
Stephen Kelly27e948c2018-11-29 19:30:37 +00001094 ColorScope Color(OS, ShowColors, NullColor);
Kelvin Li1408f912018-09-26 04:28:39 +00001095 OS << "<<<NULL>>> OMPClause";
1096 return;
1097 }
1098 {
Stephen Kelly27e948c2018-11-29 19:30:37 +00001099 ColorScope Color(OS, ShowColors, AttrColor);
Kelvin Li1408f912018-09-26 04:28:39 +00001100 StringRef ClauseName(getOpenMPClauseName(C->getClauseKind()));
1101 OS << "OMP" << ClauseName.substr(/*Start=*/0, /*N=*/1).upper()
1102 << ClauseName.drop_front() << "Clause";
1103 }
Stephen Kellyd8744a72018-12-05 21:12:39 +00001104 NodeDumper.dumpPointer(C);
1105 NodeDumper.dumpSourceRange(SourceRange(C->getBeginLoc(), C->getEndLoc()));
Kelvin Li1408f912018-09-26 04:28:39 +00001106 });
1107 }
1108}
1109
Alexey Bataev958b9e72016-03-31 09:30:50 +00001110void ASTDumper::VisitOMPCapturedExprDecl(const OMPCapturedExprDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +00001111 NodeDumper.dumpName(D);
1112 NodeDumper.dumpType(D->getType());
Alexey Bataev958b9e72016-03-31 09:30:50 +00001113 dumpStmt(D->getInit());
1114}
Nico Webercbbaeb12016-03-02 19:28:54 +00001115
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001116//===----------------------------------------------------------------------===//
1117// C++ Declarations
1118//===----------------------------------------------------------------------===//
1119
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001120void ASTDumper::VisitNamespaceDecl(const NamespaceDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +00001121 NodeDumper.dumpName(D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001122 if (D->isInline())
1123 OS << " inline";
1124 if (!D->isOriginalNamespace())
1125 dumpDeclRef(D->getOriginalNamespace(), "original");
1126}
1127
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001128void ASTDumper::VisitUsingDirectiveDecl(const UsingDirectiveDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001129 OS << ' ';
Stephen Kellyd8744a72018-12-05 21:12:39 +00001130 NodeDumper.dumpBareDeclRef(D->getNominatedNamespace());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001131}
1132
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001133void ASTDumper::VisitNamespaceAliasDecl(const NamespaceAliasDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +00001134 NodeDumper.dumpName(D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001135 dumpDeclRef(D->getAliasedNamespace());
1136}
1137
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001138void ASTDumper::VisitTypeAliasDecl(const TypeAliasDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +00001139 NodeDumper.dumpName(D);
1140 NodeDumper.dumpType(D->getUnderlyingType());
Richard Smithba3a4f92016-01-12 21:59:26 +00001141 dumpTypeAsChild(D->getUnderlyingType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001142}
1143
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001144void ASTDumper::VisitTypeAliasTemplateDecl(const TypeAliasTemplateDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +00001145 NodeDumper.dumpName(D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001146 dumpTemplateParameters(D->getTemplateParameters());
1147 dumpDecl(D->getTemplatedDecl());
1148}
1149
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001150void ASTDumper::VisitCXXRecordDecl(const CXXRecordDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001151 VisitRecordDecl(D);
1152 if (!D->isCompleteDefinition())
1153 return;
1154
Richard Smithdfc4bff2017-09-22 00:11:15 +00001155 dumpChild([=] {
1156 {
Stephen Kelly27e948c2018-11-29 19:30:37 +00001157 ColorScope Color(OS, ShowColors, DeclKindNameColor);
Richard Smithdfc4bff2017-09-22 00:11:15 +00001158 OS << "DefinitionData";
1159 }
1160#define FLAG(fn, name) if (D->fn()) OS << " " #name;
1161 FLAG(isParsingBaseSpecifiers, parsing_base_specifiers);
1162
1163 FLAG(isGenericLambda, generic);
1164 FLAG(isLambda, lambda);
1165
1166 FLAG(canPassInRegisters, pass_in_registers);
1167 FLAG(isEmpty, empty);
1168 FLAG(isAggregate, aggregate);
1169 FLAG(isStandardLayout, standard_layout);
1170 FLAG(isTriviallyCopyable, trivially_copyable);
1171 FLAG(isPOD, pod);
1172 FLAG(isTrivial, trivial);
1173 FLAG(isPolymorphic, polymorphic);
1174 FLAG(isAbstract, abstract);
1175 FLAG(isLiteral, literal);
1176
1177 FLAG(hasUserDeclaredConstructor, has_user_declared_ctor);
1178 FLAG(hasConstexprNonCopyMoveConstructor, has_constexpr_non_copy_move_ctor);
1179 FLAG(hasMutableFields, has_mutable_fields);
1180 FLAG(hasVariantMembers, has_variant_members);
1181 FLAG(allowConstDefaultInit, can_const_default_init);
1182
1183 dumpChild([=] {
1184 {
Stephen Kelly27e948c2018-11-29 19:30:37 +00001185 ColorScope Color(OS, ShowColors, DeclKindNameColor);
Richard Smithdfc4bff2017-09-22 00:11:15 +00001186 OS << "DefaultConstructor";
1187 }
1188 FLAG(hasDefaultConstructor, exists);
1189 FLAG(hasTrivialDefaultConstructor, trivial);
1190 FLAG(hasNonTrivialDefaultConstructor, non_trivial);
1191 FLAG(hasUserProvidedDefaultConstructor, user_provided);
1192 FLAG(hasConstexprDefaultConstructor, constexpr);
1193 FLAG(needsImplicitDefaultConstructor, needs_implicit);
1194 FLAG(defaultedDefaultConstructorIsConstexpr, defaulted_is_constexpr);
1195 });
1196
1197 dumpChild([=] {
1198 {
Stephen Kelly27e948c2018-11-29 19:30:37 +00001199 ColorScope Color(OS, ShowColors, DeclKindNameColor);
Richard Smithdfc4bff2017-09-22 00:11:15 +00001200 OS << "CopyConstructor";
1201 }
1202 FLAG(hasSimpleCopyConstructor, simple);
1203 FLAG(hasTrivialCopyConstructor, trivial);
1204 FLAG(hasNonTrivialCopyConstructor, non_trivial);
1205 FLAG(hasUserDeclaredCopyConstructor, user_declared);
1206 FLAG(hasCopyConstructorWithConstParam, has_const_param);
1207 FLAG(needsImplicitCopyConstructor, needs_implicit);
1208 FLAG(needsOverloadResolutionForCopyConstructor,
1209 needs_overload_resolution);
1210 if (!D->needsOverloadResolutionForCopyConstructor())
1211 FLAG(defaultedCopyConstructorIsDeleted, defaulted_is_deleted);
1212 FLAG(implicitCopyConstructorHasConstParam, implicit_has_const_param);
1213 });
1214
1215 dumpChild([=] {
1216 {
Stephen Kelly27e948c2018-11-29 19:30:37 +00001217 ColorScope Color(OS, ShowColors, DeclKindNameColor);
Richard Smithdfc4bff2017-09-22 00:11:15 +00001218 OS << "MoveConstructor";
1219 }
1220 FLAG(hasMoveConstructor, exists);
1221 FLAG(hasSimpleMoveConstructor, simple);
1222 FLAG(hasTrivialMoveConstructor, trivial);
1223 FLAG(hasNonTrivialMoveConstructor, non_trivial);
1224 FLAG(hasUserDeclaredMoveConstructor, user_declared);
1225 FLAG(needsImplicitMoveConstructor, needs_implicit);
1226 FLAG(needsOverloadResolutionForMoveConstructor,
1227 needs_overload_resolution);
1228 if (!D->needsOverloadResolutionForMoveConstructor())
1229 FLAG(defaultedMoveConstructorIsDeleted, defaulted_is_deleted);
1230 });
1231
1232 dumpChild([=] {
1233 {
Stephen Kelly27e948c2018-11-29 19:30:37 +00001234 ColorScope Color(OS, ShowColors, DeclKindNameColor);
Richard Smithdfc4bff2017-09-22 00:11:15 +00001235 OS << "CopyAssignment";
1236 }
1237 FLAG(hasTrivialCopyAssignment, trivial);
1238 FLAG(hasNonTrivialCopyAssignment, non_trivial);
1239 FLAG(hasCopyAssignmentWithConstParam, has_const_param);
1240 FLAG(hasUserDeclaredCopyAssignment, user_declared);
1241 FLAG(needsImplicitCopyAssignment, needs_implicit);
1242 FLAG(needsOverloadResolutionForCopyAssignment, needs_overload_resolution);
1243 FLAG(implicitCopyAssignmentHasConstParam, implicit_has_const_param);
1244 });
1245
1246 dumpChild([=] {
1247 {
Stephen Kelly27e948c2018-11-29 19:30:37 +00001248 ColorScope Color(OS, ShowColors, DeclKindNameColor);
Richard Smithdfc4bff2017-09-22 00:11:15 +00001249 OS << "MoveAssignment";
1250 }
1251 FLAG(hasMoveAssignment, exists);
1252 FLAG(hasSimpleMoveAssignment, simple);
1253 FLAG(hasTrivialMoveAssignment, trivial);
1254 FLAG(hasNonTrivialMoveAssignment, non_trivial);
1255 FLAG(hasUserDeclaredMoveAssignment, user_declared);
1256 FLAG(needsImplicitMoveAssignment, needs_implicit);
1257 FLAG(needsOverloadResolutionForMoveAssignment, needs_overload_resolution);
1258 });
1259
1260 dumpChild([=] {
1261 {
Stephen Kelly27e948c2018-11-29 19:30:37 +00001262 ColorScope Color(OS, ShowColors, DeclKindNameColor);
Richard Smithdfc4bff2017-09-22 00:11:15 +00001263 OS << "Destructor";
1264 }
1265 FLAG(hasSimpleDestructor, simple);
1266 FLAG(hasIrrelevantDestructor, irrelevant);
1267 FLAG(hasTrivialDestructor, trivial);
1268 FLAG(hasNonTrivialDestructor, non_trivial);
1269 FLAG(hasUserDeclaredDestructor, user_declared);
1270 FLAG(needsImplicitDestructor, needs_implicit);
1271 FLAG(needsOverloadResolutionForDestructor, needs_overload_resolution);
1272 if (!D->needsOverloadResolutionForDestructor())
1273 FLAG(defaultedDestructorIsDeleted, defaulted_is_deleted);
1274 });
1275 });
1276
Aaron Ballman574705e2014-03-13 15:41:46 +00001277 for (const auto &I : D->bases()) {
Richard Smithf7514452014-10-30 21:02:37 +00001278 dumpChild([=] {
1279 if (I.isVirtual())
1280 OS << "virtual ";
Stephen Kellyd8744a72018-12-05 21:12:39 +00001281 NodeDumper.dumpAccessSpecifier(I.getAccessSpecifier());
1282 NodeDumper.dumpType(I.getType());
Richard Smithf7514452014-10-30 21:02:37 +00001283 if (I.isPackExpansion())
1284 OS << "...";
1285 });
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001286 }
1287}
1288
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001289void ASTDumper::VisitStaticAssertDecl(const StaticAssertDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001290 dumpStmt(D->getAssertExpr());
1291 dumpStmt(D->getMessage());
1292}
1293
Richard Smithcbdf7332014-03-18 02:07:28 +00001294template<typename SpecializationDecl>
Richard Smithf7514452014-10-30 21:02:37 +00001295void ASTDumper::VisitTemplateDeclSpecialization(const SpecializationDecl *D,
Richard Smithcbdf7332014-03-18 02:07:28 +00001296 bool DumpExplicitInst,
1297 bool DumpRefOnly) {
1298 bool DumpedAny = false;
1299 for (auto *RedeclWithBadType : D->redecls()) {
1300 // FIXME: The redecls() range sometimes has elements of a less-specific
1301 // type. (In particular, ClassTemplateSpecializationDecl::redecls() gives
1302 // us TagDecls, and should give CXXRecordDecls).
1303 auto *Redecl = dyn_cast<SpecializationDecl>(RedeclWithBadType);
1304 if (!Redecl) {
1305 // Found the injected-class-name for a class template. This will be dumped
1306 // as part of its surrounding class so we don't need to dump it here.
1307 assert(isa<CXXRecordDecl>(RedeclWithBadType) &&
1308 "expected an injected-class-name");
1309 continue;
1310 }
1311
1312 switch (Redecl->getTemplateSpecializationKind()) {
1313 case TSK_ExplicitInstantiationDeclaration:
1314 case TSK_ExplicitInstantiationDefinition:
1315 if (!DumpExplicitInst)
1316 break;
Adrian Prantlf3b3ccd2017-12-19 22:06:11 +00001317 LLVM_FALLTHROUGH;
Richard Smithcbdf7332014-03-18 02:07:28 +00001318 case TSK_Undeclared:
1319 case TSK_ImplicitInstantiation:
Richard Smithf7514452014-10-30 21:02:37 +00001320 if (DumpRefOnly)
1321 dumpDeclRef(Redecl);
1322 else
1323 dumpDecl(Redecl);
Richard Smithcbdf7332014-03-18 02:07:28 +00001324 DumpedAny = true;
1325 break;
1326 case TSK_ExplicitSpecialization:
1327 break;
1328 }
1329 }
1330
1331 // Ensure we dump at least one decl for each specialization.
1332 if (!DumpedAny)
Richard Smithf7514452014-10-30 21:02:37 +00001333 dumpDeclRef(D);
Richard Smithcbdf7332014-03-18 02:07:28 +00001334}
1335
Richard Smith20ade552014-03-17 23:34:53 +00001336template<typename TemplateDecl>
1337void ASTDumper::VisitTemplateDecl(const TemplateDecl *D,
1338 bool DumpExplicitInst) {
Stephen Kellyd8744a72018-12-05 21:12:39 +00001339 NodeDumper.dumpName(D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001340 dumpTemplateParameters(D->getTemplateParameters());
Richard Smithdcc2c452014-03-17 23:00:06 +00001341
Richard Smithf7514452014-10-30 21:02:37 +00001342 dumpDecl(D->getTemplatedDecl());
Richard Smithdcc2c452014-03-17 23:00:06 +00001343
Richard Smithcbdf7332014-03-18 02:07:28 +00001344 for (auto *Child : D->specializations())
Richard Smithf7514452014-10-30 21:02:37 +00001345 VisitTemplateDeclSpecialization(Child, DumpExplicitInst,
Richard Smithcbdf7332014-03-18 02:07:28 +00001346 !D->isCanonicalDecl());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001347}
1348
Richard Smith20ade552014-03-17 23:34:53 +00001349void ASTDumper::VisitFunctionTemplateDecl(const FunctionTemplateDecl *D) {
1350 // FIXME: We don't add a declaration of a function template specialization
1351 // to its context when it's explicitly instantiated, so dump explicit
1352 // instantiations when we dump the template itself.
1353 VisitTemplateDecl(D, true);
1354}
1355
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001356void ASTDumper::VisitClassTemplateDecl(const ClassTemplateDecl *D) {
Richard Smith20ade552014-03-17 23:34:53 +00001357 VisitTemplateDecl(D, false);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001358}
1359
1360void ASTDumper::VisitClassTemplateSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001361 const ClassTemplateSpecializationDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001362 VisitCXXRecordDecl(D);
1363 dumpTemplateArgumentList(D->getTemplateArgs());
1364}
1365
1366void ASTDumper::VisitClassTemplatePartialSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001367 const ClassTemplatePartialSpecializationDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001368 VisitClassTemplateSpecializationDecl(D);
1369 dumpTemplateParameters(D->getTemplateParameters());
1370}
1371
1372void ASTDumper::VisitClassScopeFunctionSpecializationDecl(
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001373 const ClassScopeFunctionSpecializationDecl *D) {
Richard Smithc660c8f2018-03-16 13:36:56 +00001374 dumpDecl(D->getSpecialization());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001375 if (D->hasExplicitTemplateArgs())
1376 dumpTemplateArgumentListInfo(D->templateArgs());
1377}
1378
Richard Smithd25789a2013-09-18 01:36:02 +00001379void ASTDumper::VisitVarTemplateDecl(const VarTemplateDecl *D) {
Richard Smith20ade552014-03-17 23:34:53 +00001380 VisitTemplateDecl(D, false);
Richard Smithd25789a2013-09-18 01:36:02 +00001381}
1382
David Majnemerd9b1a4f2015-11-04 03:40:30 +00001383void ASTDumper::VisitBuiltinTemplateDecl(const BuiltinTemplateDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +00001384 NodeDumper.dumpName(D);
David Majnemerd9b1a4f2015-11-04 03:40:30 +00001385 dumpTemplateParameters(D->getTemplateParameters());
1386}
1387
Richard Smithd25789a2013-09-18 01:36:02 +00001388void ASTDumper::VisitVarTemplateSpecializationDecl(
1389 const VarTemplateSpecializationDecl *D) {
1390 dumpTemplateArgumentList(D->getTemplateArgs());
1391 VisitVarDecl(D);
1392}
1393
1394void ASTDumper::VisitVarTemplatePartialSpecializationDecl(
1395 const VarTemplatePartialSpecializationDecl *D) {
1396 dumpTemplateParameters(D->getTemplateParameters());
1397 VisitVarTemplateSpecializationDecl(D);
1398}
1399
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001400void ASTDumper::VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001401 if (D->wasDeclaredWithTypename())
1402 OS << " typename";
1403 else
1404 OS << " class";
Richard Smith1832a022017-02-21 02:04:03 +00001405 OS << " depth " << D->getDepth() << " index " << D->getIndex();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001406 if (D->isParameterPack())
1407 OS << " ...";
Stephen Kellyd8744a72018-12-05 21:12:39 +00001408 NodeDumper.dumpName(D);
Richard Smithf7514452014-10-30 21:02:37 +00001409 if (D->hasDefaultArgument())
Richard Smithecf74ff2014-03-23 20:50:39 +00001410 dumpTemplateArgument(D->getDefaultArgument());
Richard Smithc4577662018-09-12 02:13:47 +00001411 if (auto *From = D->getDefaultArgStorage().getInheritedFrom())
1412 dumpDeclRef(From, D->defaultArgumentWasInherited() ? "inherited from"
1413 : "previous");
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001414}
1415
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001416void ASTDumper::VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +00001417 NodeDumper.dumpType(D->getType());
Richard Smith1832a022017-02-21 02:04:03 +00001418 OS << " depth " << D->getDepth() << " index " << D->getIndex();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001419 if (D->isParameterPack())
1420 OS << " ...";
Stephen Kellyd8744a72018-12-05 21:12:39 +00001421 NodeDumper.dumpName(D);
Richard Smithf7514452014-10-30 21:02:37 +00001422 if (D->hasDefaultArgument())
Richard Smithecf74ff2014-03-23 20:50:39 +00001423 dumpTemplateArgument(D->getDefaultArgument());
Richard Smithc4577662018-09-12 02:13:47 +00001424 if (auto *From = D->getDefaultArgStorage().getInheritedFrom())
1425 dumpDeclRef(From, D->defaultArgumentWasInherited() ? "inherited from"
1426 : "previous");
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001427}
1428
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001429void ASTDumper::VisitTemplateTemplateParmDecl(
1430 const TemplateTemplateParmDecl *D) {
Richard Smith1832a022017-02-21 02:04:03 +00001431 OS << " depth " << D->getDepth() << " index " << D->getIndex();
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001432 if (D->isParameterPack())
1433 OS << " ...";
Stephen Kellyd8744a72018-12-05 21:12:39 +00001434 NodeDumper.dumpName(D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001435 dumpTemplateParameters(D->getTemplateParameters());
Richard Smithf7514452014-10-30 21:02:37 +00001436 if (D->hasDefaultArgument())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001437 dumpTemplateArgumentLoc(D->getDefaultArgument());
Richard Smithc4577662018-09-12 02:13:47 +00001438 if (auto *From = D->getDefaultArgStorage().getInheritedFrom())
1439 dumpDeclRef(From, D->defaultArgumentWasInherited() ? "inherited from"
1440 : "previous");
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001441}
1442
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001443void ASTDumper::VisitUsingDecl(const UsingDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001444 OS << ' ';
Dawn Perchikddd03bf2015-12-05 22:37:55 +00001445 if (D->getQualifier())
1446 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001447 OS << D->getNameAsString();
1448}
1449
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001450void ASTDumper::VisitUnresolvedUsingTypenameDecl(
1451 const UnresolvedUsingTypenameDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001452 OS << ' ';
Dawn Perchikddd03bf2015-12-05 22:37:55 +00001453 if (D->getQualifier())
1454 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001455 OS << D->getNameAsString();
1456}
1457
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001458void ASTDumper::VisitUnresolvedUsingValueDecl(const UnresolvedUsingValueDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001459 OS << ' ';
Dawn Perchikddd03bf2015-12-05 22:37:55 +00001460 if (D->getQualifier())
1461 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001462 OS << D->getNameAsString();
Stephen Kellyd8744a72018-12-05 21:12:39 +00001463 NodeDumper.dumpType(D->getType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001464}
1465
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001466void ASTDumper::VisitUsingShadowDecl(const UsingShadowDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001467 OS << ' ';
Stephen Kellyd8744a72018-12-05 21:12:39 +00001468 NodeDumper.dumpBareDeclRef(D->getTargetDecl());
Richard Smithba3a4f92016-01-12 21:59:26 +00001469 if (auto *TD = dyn_cast<TypeDecl>(D->getUnderlyingDecl()))
1470 dumpTypeAsChild(TD->getTypeForDecl());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001471}
1472
Richard Smith5179eb72016-06-28 19:03:57 +00001473void ASTDumper::VisitConstructorUsingShadowDecl(
1474 const ConstructorUsingShadowDecl *D) {
1475 if (D->constructsVirtualBase())
1476 OS << " virtual";
1477
1478 dumpChild([=] {
1479 OS << "target ";
Stephen Kellyd8744a72018-12-05 21:12:39 +00001480 NodeDumper.dumpBareDeclRef(D->getTargetDecl());
Richard Smith5179eb72016-06-28 19:03:57 +00001481 });
1482
1483 dumpChild([=] {
1484 OS << "nominated ";
Stephen Kellyd8744a72018-12-05 21:12:39 +00001485 NodeDumper.dumpBareDeclRef(D->getNominatedBaseClass());
Richard Smith5179eb72016-06-28 19:03:57 +00001486 OS << ' ';
Stephen Kellyd8744a72018-12-05 21:12:39 +00001487 NodeDumper.dumpBareDeclRef(D->getNominatedBaseClassShadowDecl());
Richard Smith5179eb72016-06-28 19:03:57 +00001488 });
1489
1490 dumpChild([=] {
1491 OS << "constructed ";
Stephen Kellyd8744a72018-12-05 21:12:39 +00001492 NodeDumper.dumpBareDeclRef(D->getConstructedBaseClass());
Richard Smith5179eb72016-06-28 19:03:57 +00001493 OS << ' ';
Stephen Kellyd8744a72018-12-05 21:12:39 +00001494 NodeDumper.dumpBareDeclRef(D->getConstructedBaseClassShadowDecl());
Richard Smith5179eb72016-06-28 19:03:57 +00001495 });
1496}
1497
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001498void ASTDumper::VisitLinkageSpecDecl(const LinkageSpecDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001499 switch (D->getLanguage()) {
1500 case LinkageSpecDecl::lang_c: OS << " C"; break;
1501 case LinkageSpecDecl::lang_cxx: OS << " C++"; break;
1502 }
1503}
1504
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001505void ASTDumper::VisitAccessSpecDecl(const AccessSpecDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001506 OS << ' ';
Stephen Kellyd8744a72018-12-05 21:12:39 +00001507 NodeDumper.dumpAccessSpecifier(D->getAccess());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001508}
1509
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001510void ASTDumper::VisitFriendDecl(const FriendDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001511 if (TypeSourceInfo *T = D->getFriendType())
Stephen Kellyd8744a72018-12-05 21:12:39 +00001512 NodeDumper.dumpType(T->getType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001513 else
1514 dumpDecl(D->getFriendDecl());
1515}
1516
1517//===----------------------------------------------------------------------===//
1518// Obj-C Declarations
1519//===----------------------------------------------------------------------===//
1520
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001521void ASTDumper::VisitObjCIvarDecl(const ObjCIvarDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +00001522 NodeDumper.dumpName(D);
1523 NodeDumper.dumpType(D->getType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001524 if (D->getSynthesize())
1525 OS << " synthesize";
1526
1527 switch (D->getAccessControl()) {
1528 case ObjCIvarDecl::None:
1529 OS << " none";
1530 break;
1531 case ObjCIvarDecl::Private:
1532 OS << " private";
1533 break;
1534 case ObjCIvarDecl::Protected:
1535 OS << " protected";
1536 break;
1537 case ObjCIvarDecl::Public:
1538 OS << " public";
1539 break;
1540 case ObjCIvarDecl::Package:
1541 OS << " package";
1542 break;
1543 }
1544}
1545
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001546void ASTDumper::VisitObjCMethodDecl(const ObjCMethodDecl *D) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001547 if (D->isInstanceMethod())
1548 OS << " -";
1549 else
1550 OS << " +";
Stephen Kellyd8744a72018-12-05 21:12:39 +00001551 NodeDumper.dumpName(D);
1552 NodeDumper.dumpType(D->getReturnType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001553
Richard Trieude5cc7d2013-01-31 01:44:26 +00001554 if (D->isThisDeclarationADefinition()) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001555 dumpDeclContext(D);
Richard Trieude5cc7d2013-01-31 01:44:26 +00001556 } else {
David Majnemera3debed2016-06-24 05:33:44 +00001557 for (const ParmVarDecl *Parameter : D->parameters())
1558 dumpDecl(Parameter);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001559 }
1560
Richard Smithf7514452014-10-30 21:02:37 +00001561 if (D->isVariadic())
1562 dumpChild([=] { OS << "..."; });
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001563
Richard Smithf7514452014-10-30 21:02:37 +00001564 if (D->hasBody())
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001565 dumpStmt(D->getBody());
1566}
1567
Douglas Gregor85f3f952015-07-07 03:57:15 +00001568void ASTDumper::VisitObjCTypeParamDecl(const ObjCTypeParamDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +00001569 NodeDumper.dumpName(D);
Douglas Gregor1ac1b632015-07-07 03:58:54 +00001570 switch (D->getVariance()) {
1571 case ObjCTypeParamVariance::Invariant:
1572 break;
1573
1574 case ObjCTypeParamVariance::Covariant:
1575 OS << " covariant";
1576 break;
1577
1578 case ObjCTypeParamVariance::Contravariant:
1579 OS << " contravariant";
1580 break;
1581 }
1582
Douglas Gregor85f3f952015-07-07 03:57:15 +00001583 if (D->hasExplicitBound())
1584 OS << " bounded";
Stephen Kellyd8744a72018-12-05 21:12:39 +00001585 NodeDumper.dumpType(D->getUnderlyingType());
Douglas Gregor85f3f952015-07-07 03:57:15 +00001586}
1587
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001588void ASTDumper::VisitObjCCategoryDecl(const ObjCCategoryDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +00001589 NodeDumper.dumpName(D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001590 dumpDeclRef(D->getClassInterface());
Douglas Gregor85f3f952015-07-07 03:57:15 +00001591 dumpObjCTypeParamList(D->getTypeParamList());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001592 dumpDeclRef(D->getImplementation());
1593 for (ObjCCategoryDecl::protocol_iterator I = D->protocol_begin(),
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001594 E = D->protocol_end();
Richard Smithf7514452014-10-30 21:02:37 +00001595 I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001596 dumpDeclRef(*I);
1597}
1598
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001599void ASTDumper::VisitObjCCategoryImplDecl(const ObjCCategoryImplDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +00001600 NodeDumper.dumpName(D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001601 dumpDeclRef(D->getClassInterface());
1602 dumpDeclRef(D->getCategoryDecl());
1603}
1604
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001605void ASTDumper::VisitObjCProtocolDecl(const ObjCProtocolDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +00001606 NodeDumper.dumpName(D);
Richard Smithdcc2c452014-03-17 23:00:06 +00001607
Richard Smith7fcb35f2014-03-18 02:37:59 +00001608 for (auto *Child : D->protocols())
Richard Smithf7514452014-10-30 21:02:37 +00001609 dumpDeclRef(Child);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001610}
1611
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001612void ASTDumper::VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +00001613 NodeDumper.dumpName(D);
Douglas Gregor85f3f952015-07-07 03:57:15 +00001614 dumpObjCTypeParamList(D->getTypeParamListAsWritten());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001615 dumpDeclRef(D->getSuperClass(), "super");
Richard Smithdcc2c452014-03-17 23:00:06 +00001616
Richard Smithf7514452014-10-30 21:02:37 +00001617 dumpDeclRef(D->getImplementation());
Richard Smith7fcb35f2014-03-18 02:37:59 +00001618 for (auto *Child : D->protocols())
Richard Smithf7514452014-10-30 21:02:37 +00001619 dumpDeclRef(Child);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001620}
1621
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001622void ASTDumper::VisitObjCImplementationDecl(const ObjCImplementationDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +00001623 NodeDumper.dumpName(D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001624 dumpDeclRef(D->getSuperClass(), "super");
1625 dumpDeclRef(D->getClassInterface());
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001626 for (ObjCImplementationDecl::init_const_iterator I = D->init_begin(),
1627 E = D->init_end();
Richard Smithf7514452014-10-30 21:02:37 +00001628 I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001629 dumpCXXCtorInitializer(*I);
1630}
1631
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001632void ASTDumper::VisitObjCCompatibleAliasDecl(const ObjCCompatibleAliasDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +00001633 NodeDumper.dumpName(D);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001634 dumpDeclRef(D->getClassInterface());
1635}
1636
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001637void ASTDumper::VisitObjCPropertyDecl(const ObjCPropertyDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +00001638 NodeDumper.dumpName(D);
1639 NodeDumper.dumpType(D->getType());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001640
1641 if (D->getPropertyImplementation() == ObjCPropertyDecl::Required)
1642 OS << " required";
1643 else if (D->getPropertyImplementation() == ObjCPropertyDecl::Optional)
1644 OS << " optional";
1645
1646 ObjCPropertyDecl::PropertyAttributeKind Attrs = D->getPropertyAttributes();
1647 if (Attrs != ObjCPropertyDecl::OBJC_PR_noattr) {
1648 if (Attrs & ObjCPropertyDecl::OBJC_PR_readonly)
1649 OS << " readonly";
1650 if (Attrs & ObjCPropertyDecl::OBJC_PR_assign)
1651 OS << " assign";
1652 if (Attrs & ObjCPropertyDecl::OBJC_PR_readwrite)
1653 OS << " readwrite";
1654 if (Attrs & ObjCPropertyDecl::OBJC_PR_retain)
1655 OS << " retain";
1656 if (Attrs & ObjCPropertyDecl::OBJC_PR_copy)
1657 OS << " copy";
1658 if (Attrs & ObjCPropertyDecl::OBJC_PR_nonatomic)
1659 OS << " nonatomic";
1660 if (Attrs & ObjCPropertyDecl::OBJC_PR_atomic)
1661 OS << " atomic";
1662 if (Attrs & ObjCPropertyDecl::OBJC_PR_weak)
1663 OS << " weak";
1664 if (Attrs & ObjCPropertyDecl::OBJC_PR_strong)
1665 OS << " strong";
1666 if (Attrs & ObjCPropertyDecl::OBJC_PR_unsafe_unretained)
1667 OS << " unsafe_unretained";
Manman Ren387ff7f2016-01-26 18:52:43 +00001668 if (Attrs & ObjCPropertyDecl::OBJC_PR_class)
1669 OS << " class";
Richard Smithf7514452014-10-30 21:02:37 +00001670 if (Attrs & ObjCPropertyDecl::OBJC_PR_getter)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001671 dumpDeclRef(D->getGetterMethodDecl(), "getter");
Richard Smithf7514452014-10-30 21:02:37 +00001672 if (Attrs & ObjCPropertyDecl::OBJC_PR_setter)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001673 dumpDeclRef(D->getSetterMethodDecl(), "setter");
1674 }
1675}
1676
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001677void ASTDumper::VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D) {
Stephen Kellyd8744a72018-12-05 21:12:39 +00001678 NodeDumper.dumpName(D->getPropertyDecl());
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001679 if (D->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize)
1680 OS << " synthesize";
1681 else
1682 OS << " dynamic";
1683 dumpDeclRef(D->getPropertyDecl());
1684 dumpDeclRef(D->getPropertyIvarDecl());
1685}
1686
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001687void ASTDumper::VisitBlockDecl(const BlockDecl *D) {
David Majnemer59f77922016-06-24 04:05:48 +00001688 for (auto I : D->parameters())
Aaron Ballmanb2b8b1d2014-03-07 16:09:59 +00001689 dumpDecl(I);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001690
Richard Smithf7514452014-10-30 21:02:37 +00001691 if (D->isVariadic())
1692 dumpChild([=]{ OS << "..."; });
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001693
Richard Smithf7514452014-10-30 21:02:37 +00001694 if (D->capturesCXXThis())
1695 dumpChild([=]{ OS << "capture this"; });
1696
Aaron Ballman9371dd22014-03-14 18:34:04 +00001697 for (const auto &I : D->captures()) {
Richard Smithf7514452014-10-30 21:02:37 +00001698 dumpChild([=] {
1699 OS << "capture";
1700 if (I.isByRef())
1701 OS << " byref";
1702 if (I.isNested())
1703 OS << " nested";
1704 if (I.getVariable()) {
1705 OS << ' ';
Stephen Kellyd8744a72018-12-05 21:12:39 +00001706 NodeDumper.dumpBareDeclRef(I.getVariable());
Richard Smithf7514452014-10-30 21:02:37 +00001707 }
1708 if (I.hasCopyExpr())
1709 dumpStmt(I.getCopyExpr());
1710 });
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001711 }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001712 dumpStmt(D->getBody());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001713}
1714
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001715//===----------------------------------------------------------------------===//
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001716// Stmt dumping methods.
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001717//===----------------------------------------------------------------------===//
1718
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001719void ASTDumper::dumpStmt(const Stmt *S) {
Richard Smithf7514452014-10-30 21:02:37 +00001720 dumpChild([=] {
1721 if (!S) {
Stephen Kelly27e948c2018-11-29 19:30:37 +00001722 ColorScope Color(OS, ShowColors, NullColor);
Richard Smithf7514452014-10-30 21:02:37 +00001723 OS << "<<<NULL>>>";
1724 return;
1725 }
Stephen Kellyb9d6a5e2018-12-06 23:33:27 +00001726 {
1727 ColorScope Color(OS, ShowColors, StmtColor);
1728 OS << S->getStmtClassName();
1729 }
1730 NodeDumper.dumpPointer(S);
1731 NodeDumper.dumpSourceRange(S->getSourceRange());
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001732
Stephen Kelly50e82872018-12-06 23:33:33 +00001733 if (const auto *E = dyn_cast<Expr>(S)) {
1734 NodeDumper.dumpType(E->getType());
1735
1736 {
1737 ColorScope Color(OS, ShowColors, ValueKindColor);
1738 switch (E->getValueKind()) {
1739 case VK_RValue:
1740 break;
1741 case VK_LValue:
1742 OS << " lvalue";
1743 break;
1744 case VK_XValue:
1745 OS << " xvalue";
1746 break;
1747 }
1748 }
1749
1750 {
1751 ColorScope Color(OS, ShowColors, ObjectKindColor);
1752 switch (E->getObjectKind()) {
1753 case OK_Ordinary:
1754 break;
1755 case OK_BitField:
1756 OS << " bitfield";
1757 break;
1758 case OK_ObjCProperty:
1759 OS << " objcproperty";
1760 break;
1761 case OK_ObjCSubscript:
1762 OS << " objcsubscript";
1763 break;
1764 case OK_VectorComponent:
1765 OS << " vectorcomponent";
1766 break;
1767 }
1768 }
1769 }
1770
Richard Smithf7514452014-10-30 21:02:37 +00001771 ConstStmtVisitor<ASTDumper>::Visit(S);
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001772
Stephen Kelly91f9c9c2018-12-03 21:05:52 +00001773 // Some statements have custom mechanisms for dumping their children.
1774 if (isa<DeclStmt>(S) || isa<GenericSelectionExpr>(S)) {
1775 return;
1776 }
1777
Benjamin Kramer642f1732015-07-02 21:03:14 +00001778 for (const Stmt *SubStmt : S->children())
1779 dumpStmt(SubStmt);
Richard Smithf7514452014-10-30 21:02:37 +00001780 });
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00001781}
1782
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001783void ASTDumper::VisitDeclStmt(const DeclStmt *Node) {
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001784 for (DeclStmt::const_decl_iterator I = Node->decl_begin(),
1785 E = Node->decl_end();
Richard Smithf7514452014-10-30 21:02:37 +00001786 I != E; ++I)
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001787 dumpDecl(*I);
Ted Kremenek433a4922007-12-12 06:59:42 +00001788}
1789
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001790void ASTDumper::VisitAttributedStmt(const AttributedStmt *Node) {
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001791 for (ArrayRef<const Attr *>::iterator I = Node->getAttrs().begin(),
1792 E = Node->getAttrs().end();
Richard Smithf7514452014-10-30 21:02:37 +00001793 I != E; ++I)
Alexander Kornienko5bc364e2013-01-07 17:53:08 +00001794 dumpAttr(*I);
1795}
1796
Bruno Riccib1cc94b2018-10-27 21:12:20 +00001797void ASTDumper::VisitIfStmt(const IfStmt *Node) {
Bruno Riccib1cc94b2018-10-27 21:12:20 +00001798 if (Node->hasInitStorage())
1799 OS << " has_init";
1800 if (Node->hasVarStorage())
1801 OS << " has_var";
1802 if (Node->hasElseStorage())
1803 OS << " has_else";
1804}
1805
Bruno Riccie2806f82018-10-29 16:12:37 +00001806void ASTDumper::VisitSwitchStmt(const SwitchStmt *Node) {
Bruno Riccie2806f82018-10-29 16:12:37 +00001807 if (Node->hasInitStorage())
1808 OS << " has_init";
1809 if (Node->hasVarStorage())
1810 OS << " has_var";
1811}
1812
Bruno Riccibacf7512018-10-30 13:42:41 +00001813void ASTDumper::VisitWhileStmt(const WhileStmt *Node) {
Bruno Riccibacf7512018-10-30 13:42:41 +00001814 if (Node->hasVarStorage())
1815 OS << " has_var";
1816}
1817
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001818void ASTDumper::VisitLabelStmt(const LabelStmt *Node) {
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001819 OS << " '" << Node->getName() << "'";
Chris Lattnercbe4f772007-08-08 22:51:59 +00001820}
1821
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001822void ASTDumper::VisitGotoStmt(const GotoStmt *Node) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00001823 OS << " '" << Node->getLabel()->getName() << "'";
Stephen Kellyd8744a72018-12-05 21:12:39 +00001824 NodeDumper.dumpPointer(Node->getLabel());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001825}
1826
Pavel Labath1ef83422013-09-04 14:35:00 +00001827void ASTDumper::VisitCXXCatchStmt(const CXXCatchStmt *Node) {
Pavel Labath1ef83422013-09-04 14:35:00 +00001828 dumpDecl(Node->getExceptionDecl());
1829}
1830
Bruno Ricci5b30571752018-10-28 12:30:53 +00001831void ASTDumper::VisitCaseStmt(const CaseStmt *Node) {
Bruno Ricci5b30571752018-10-28 12:30:53 +00001832 if (Node->caseStmtIsGNURange())
1833 OS << " gnu_range";
1834}
1835
Alexey Bataev958b9e72016-03-31 09:30:50 +00001836void ASTDumper::VisitCapturedStmt(const CapturedStmt *Node) {
Alexey Bataev958b9e72016-03-31 09:30:50 +00001837 dumpDecl(Node->getCapturedDecl());
1838}
1839
1840//===----------------------------------------------------------------------===//
1841// OpenMP dumping methods.
1842//===----------------------------------------------------------------------===//
1843
1844void ASTDumper::VisitOMPExecutableDirective(
1845 const OMPExecutableDirective *Node) {
Alexey Bataev958b9e72016-03-31 09:30:50 +00001846 for (auto *C : Node->clauses()) {
1847 dumpChild([=] {
1848 if (!C) {
Stephen Kelly27e948c2018-11-29 19:30:37 +00001849 ColorScope Color(OS, ShowColors, NullColor);
Alexey Bataev958b9e72016-03-31 09:30:50 +00001850 OS << "<<<NULL>>> OMPClause";
1851 return;
1852 }
1853 {
Stephen Kelly27e948c2018-11-29 19:30:37 +00001854 ColorScope Color(OS, ShowColors, AttrColor);
Alexey Bataev958b9e72016-03-31 09:30:50 +00001855 StringRef ClauseName(getOpenMPClauseName(C->getClauseKind()));
1856 OS << "OMP" << ClauseName.substr(/*Start=*/0, /*N=*/1).upper()
1857 << ClauseName.drop_front() << "Clause";
1858 }
Stephen Kellyd8744a72018-12-05 21:12:39 +00001859 NodeDumper.dumpPointer(C);
1860 NodeDumper.dumpSourceRange(SourceRange(C->getBeginLoc(), C->getEndLoc()));
Alexey Bataev958b9e72016-03-31 09:30:50 +00001861 if (C->isImplicit())
1862 OS << " <implicit>";
1863 for (auto *S : C->children())
1864 dumpStmt(S);
1865 });
1866 }
1867}
1868
Chris Lattnercbe4f772007-08-08 22:51:59 +00001869//===----------------------------------------------------------------------===//
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001870// Expr dumping methods.
Chris Lattnercbe4f772007-08-08 22:51:59 +00001871//===----------------------------------------------------------------------===//
1872
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001873static void dumpBasePath(raw_ostream &OS, const CastExpr *Node) {
John McCallcf142162010-08-07 06:22:56 +00001874 if (Node->path_empty())
Anders Carlssona70cff62010-04-24 19:06:50 +00001875 return;
1876
1877 OS << " (";
1878 bool First = true;
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001879 for (CastExpr::path_const_iterator I = Node->path_begin(),
1880 E = Node->path_end();
1881 I != E; ++I) {
Anders Carlssona70cff62010-04-24 19:06:50 +00001882 const CXXBaseSpecifier *Base = *I;
1883 if (!First)
1884 OS << " -> ";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001885
Anders Carlssona70cff62010-04-24 19:06:50 +00001886 const CXXRecordDecl *RD =
1887 cast<CXXRecordDecl>(Base->getType()->getAs<RecordType>()->getDecl());
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001888
Anders Carlssona70cff62010-04-24 19:06:50 +00001889 if (Base->isVirtual())
1890 OS << "virtual ";
1891 OS << RD->getName();
1892 First = false;
1893 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001894
Anders Carlssona70cff62010-04-24 19:06:50 +00001895 OS << ')';
1896}
1897
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001898void ASTDumper::VisitCastExpr(const CastExpr *Node) {
Richard Trieud215b8d2013-01-26 01:31:20 +00001899 OS << " <";
1900 {
Stephen Kelly27e948c2018-11-29 19:30:37 +00001901 ColorScope Color(OS, ShowColors, CastColor);
Richard Trieud215b8d2013-01-26 01:31:20 +00001902 OS << Node->getCastKindName();
1903 }
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001904 dumpBasePath(OS, Node);
Anders Carlssona70cff62010-04-24 19:06:50 +00001905 OS << ">";
Roman Lebedev12216f12018-07-27 07:27:14 +00001906}
Roman Lebedevd55661d2018-07-24 08:16:50 +00001907
Roman Lebedev12216f12018-07-27 07:27:14 +00001908void ASTDumper::VisitImplicitCastExpr(const ImplicitCastExpr *Node) {
1909 VisitCastExpr(Node);
1910 if (Node->isPartOfExplicitCast())
Roman Lebedevd55661d2018-07-24 08:16:50 +00001911 OS << " part_of_explicit_cast";
Anders Carlssond7923c62009-08-22 23:33:40 +00001912}
1913
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001914void ASTDumper::VisitDeclRefExpr(const DeclRefExpr *Node) {
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001915 OS << " ";
Stephen Kellyd8744a72018-12-05 21:12:39 +00001916 NodeDumper.dumpBareDeclRef(Node->getDecl());
Chandler Carruth8d26bb02011-05-01 23:48:14 +00001917 if (Node->getDecl() != Node->getFoundDecl()) {
1918 OS << " (";
Stephen Kellyd8744a72018-12-05 21:12:39 +00001919 NodeDumper.dumpBareDeclRef(Node->getFoundDecl());
Chandler Carruth8d26bb02011-05-01 23:48:14 +00001920 OS << ")";
1921 }
John McCall351762c2011-02-07 10:33:21 +00001922}
1923
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001924void ASTDumper::VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *Node) {
John McCall76d09942009-12-11 21:50:11 +00001925 OS << " (";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001926 if (!Node->requiresADL())
1927 OS << "no ";
Benjamin Kramerb11416d2010-04-17 09:33:03 +00001928 OS << "ADL) = '" << Node->getName() << '\'';
John McCall76d09942009-12-11 21:50:11 +00001929
1930 UnresolvedLookupExpr::decls_iterator
1931 I = Node->decls_begin(), E = Node->decls_end();
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001932 if (I == E)
1933 OS << " empty";
John McCall76d09942009-12-11 21:50:11 +00001934 for (; I != E; ++I)
Stephen Kellyd8744a72018-12-05 21:12:39 +00001935 NodeDumper.dumpPointer(*I);
John McCall76d09942009-12-11 21:50:11 +00001936}
1937
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001938void ASTDumper::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *Node) {
Richard Trieud215b8d2013-01-26 01:31:20 +00001939 {
Stephen Kelly27e948c2018-11-29 19:30:37 +00001940 ColorScope Color(OS, ShowColors, DeclKindNameColor);
Richard Trieud215b8d2013-01-26 01:31:20 +00001941 OS << " " << Node->getDecl()->getDeclKindName() << "Decl";
1942 }
1943 OS << "='" << *Node->getDecl() << "'";
Stephen Kellyd8744a72018-12-05 21:12:39 +00001944 NodeDumper.dumpPointer(Node->getDecl());
Steve Naroffb3424a92008-05-23 22:01:24 +00001945 if (Node->isFreeIvar())
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001946 OS << " isFreeIvar";
Steve Naroff5d5efca2008-03-12 13:19:12 +00001947}
1948
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001949void ASTDumper::VisitPredefinedExpr(const PredefinedExpr *Node) {
Bruno Ricci17ff0262018-10-27 19:21:19 +00001950 OS << " " << PredefinedExpr::getIdentKindName(Node->getIdentKind());
Chris Lattnercbe4f772007-08-08 22:51:59 +00001951}
1952
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001953void ASTDumper::VisitCharacterLiteral(const CharacterLiteral *Node) {
Stephen Kelly27e948c2018-11-29 19:30:37 +00001954 ColorScope Color(OS, ShowColors, ValueColor);
Richard Trieu364ee422011-11-03 23:56:23 +00001955 OS << " " << Node->getValue();
Chris Lattnercbe4f772007-08-08 22:51:59 +00001956}
1957
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001958void ASTDumper::VisitIntegerLiteral(const IntegerLiteral *Node) {
Chris Lattnercbe4f772007-08-08 22:51:59 +00001959 bool isSigned = Node->getType()->isSignedIntegerType();
Stephen Kelly27e948c2018-11-29 19:30:37 +00001960 ColorScope Color(OS, ShowColors, ValueColor);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001961 OS << " " << Node->getValue().toString(10, isSigned);
Chris Lattnercbe4f772007-08-08 22:51:59 +00001962}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00001963
Leonard Chandb01c3a2018-06-20 17:19:40 +00001964void ASTDumper::VisitFixedPointLiteral(const FixedPointLiteral *Node) {
Stephen Kelly27e948c2018-11-29 19:30:37 +00001965 ColorScope Color(OS, ShowColors, ValueColor);
Leonard Chandb01c3a2018-06-20 17:19:40 +00001966 OS << " " << Node->getValueAsString(/*Radix=*/10);
1967}
1968
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001969void ASTDumper::VisitFloatingLiteral(const FloatingLiteral *Node) {
Stephen Kelly27e948c2018-11-29 19:30:37 +00001970 ColorScope Color(OS, ShowColors, ValueColor);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001971 OS << " " << Node->getValueAsApproximateDouble();
Chris Lattnercbe4f772007-08-08 22:51:59 +00001972}
Chris Lattner1c20a172007-08-26 03:42:43 +00001973
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001974void ASTDumper::VisitStringLiteral(const StringLiteral *Str) {
Stephen Kelly27e948c2018-11-29 19:30:37 +00001975 ColorScope Color(OS, ShowColors, ValueColor);
Daniel Dunbar34a96c82009-12-03 09:13:13 +00001976 OS << " ";
Richard Trieudc355912012-06-13 20:25:24 +00001977 Str->outputString(OS);
Chris Lattnercbe4f772007-08-08 22:51:59 +00001978}
Chris Lattner84ca3762007-08-30 01:00:35 +00001979
Richard Smithf0514962014-06-03 08:24:28 +00001980void ASTDumper::VisitInitListExpr(const InitListExpr *ILE) {
Stephen Kelly7ec37b22018-12-09 13:15:18 +00001981 if (auto *Field = ILE->getInitializedFieldInUnion()) {
1982 OS << " field ";
1983 NodeDumper.dumpBareDeclRef(Field);
1984 }
Richard Smithf0514962014-06-03 08:24:28 +00001985 if (auto *Filler = ILE->getArrayFiller()) {
Richard Smithf7514452014-10-30 21:02:37 +00001986 dumpChild([=] {
1987 OS << "array filler";
1988 dumpStmt(Filler);
1989 });
Richard Smithf0514962014-06-03 08:24:28 +00001990 }
Richard Smithf0514962014-06-03 08:24:28 +00001991}
1992
Alexander Kornienko540bacb2013-02-01 12:35:51 +00001993void ASTDumper::VisitUnaryOperator(const UnaryOperator *Node) {
Malcolm Parsonsfab36802018-04-16 08:31:08 +00001994 OS << " " << (Node->isPostfix() ? "postfix" : "prefix")
1995 << " '" << UnaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
1996 if (!Node->canOverflow())
1997 OS << " cannot overflow";
1998}
1999
2000void ASTDumper::VisitUnaryExprOrTypeTraitExpr(
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002001 const UnaryExprOrTypeTraitExpr *Node) {
Peter Collingbournee190dee2011-03-11 19:24:49 +00002002 switch(Node->getKind()) {
2003 case UETT_SizeOf:
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002004 OS << " sizeof";
Peter Collingbournee190dee2011-03-11 19:24:49 +00002005 break;
2006 case UETT_AlignOf:
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002007 OS << " alignof";
Peter Collingbournee190dee2011-03-11 19:24:49 +00002008 break;
2009 case UETT_VecStep:
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002010 OS << " vec_step";
Peter Collingbournee190dee2011-03-11 19:24:49 +00002011 break;
Alexey Bataev00396512015-07-02 03:40:19 +00002012 case UETT_OpenMPRequiredSimdAlign:
2013 OS << " __builtin_omp_required_simd_align";
2014 break;
Richard Smith6822bd72018-10-26 19:26:45 +00002015 case UETT_PreferredAlignOf:
2016 OS << " __alignof";
2017 break;
Peter Collingbournee190dee2011-03-11 19:24:49 +00002018 }
Sebastian Redl6f282892008-11-11 17:56:53 +00002019 if (Node->isArgumentType())
Stephen Kellyd8744a72018-12-05 21:12:39 +00002020 NodeDumper.dumpType(Node->getArgumentType());
Chris Lattnercbe4f772007-08-08 22:51:59 +00002021}
Chris Lattnerdb3b3ff2007-08-09 17:35:30 +00002022
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002023void ASTDumper::VisitMemberExpr(const MemberExpr *Node) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002024 OS << " " << (Node->isArrow() ? "->" : ".") << *Node->getMemberDecl();
Stephen Kellyd8744a72018-12-05 21:12:39 +00002025 NodeDumper.dumpPointer(Node->getMemberDecl());
Chris Lattnercbe4f772007-08-08 22:51:59 +00002026}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002027
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002028void ASTDumper::VisitExtVectorElementExpr(const ExtVectorElementExpr *Node) {
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002029 OS << " " << Node->getAccessor().getNameStart();
Chris Lattnercbe4f772007-08-08 22:51:59 +00002030}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002031
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002032void ASTDumper::VisitBinaryOperator(const BinaryOperator *Node) {
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002033 OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
Chris Lattner86928112007-08-25 02:00:02 +00002034}
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002035
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002036void ASTDumper::VisitCompoundAssignOperator(
2037 const CompoundAssignOperator *Node) {
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002038 OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode())
2039 << "' ComputeLHSTy=";
Stephen Kellyd8744a72018-12-05 21:12:39 +00002040 NodeDumper.dumpBareType(Node->getComputationLHSType());
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002041 OS << " ComputeResultTy=";
Stephen Kellyd8744a72018-12-05 21:12:39 +00002042 NodeDumper.dumpBareType(Node->getComputationResultType());
Chris Lattnercbe4f772007-08-08 22:51:59 +00002043}
Chris Lattnercbe4f772007-08-08 22:51:59 +00002044
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002045void ASTDumper::VisitBlockExpr(const BlockExpr *Node) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002046 dumpDecl(Node->getBlockDecl());
John McCall351762c2011-02-07 10:33:21 +00002047}
2048
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002049void ASTDumper::VisitOpaqueValueExpr(const OpaqueValueExpr *Node) {
Richard Smithf7514452014-10-30 21:02:37 +00002050 if (Expr *Source = Node->getSourceExpr())
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002051 dumpStmt(Source);
John McCallfe96e0b2011-11-06 09:01:30 +00002052}
2053
Richard Smith01ccebf2018-01-05 21:31:07 +00002054void ASTDumper::VisitGenericSelectionExpr(const GenericSelectionExpr *E) {
Richard Smith01ccebf2018-01-05 21:31:07 +00002055 if (E->isResultDependent())
2056 OS << " result_dependent";
2057 dumpStmt(E->getControllingExpr());
2058 dumpTypeAsChild(E->getControllingExpr()->getType()); // FIXME: remove
2059
2060 for (unsigned I = 0, N = E->getNumAssocs(); I != N; ++I) {
2061 dumpChild([=] {
2062 if (const TypeSourceInfo *TSI = E->getAssocTypeSourceInfo(I)) {
2063 OS << "case ";
Stephen Kellyd8744a72018-12-05 21:12:39 +00002064 NodeDumper.dumpType(TSI->getType());
Richard Smith01ccebf2018-01-05 21:31:07 +00002065 } else {
2066 OS << "default";
2067 }
2068
2069 if (!E->isResultDependent() && E->getResultIndex() == I)
2070 OS << " selected";
2071
2072 if (const TypeSourceInfo *TSI = E->getAssocTypeSourceInfo(I))
2073 dumpTypeAsChild(TSI->getType());
2074 dumpStmt(E->getAssocExpr(I));
2075 });
2076 }
2077}
2078
Chris Lattnercbe4f772007-08-08 22:51:59 +00002079// GNU extensions.
2080
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002081void ASTDumper::VisitAddrLabelExpr(const AddrLabelExpr *Node) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002082 OS << " " << Node->getLabel()->getName();
Stephen Kellyd8744a72018-12-05 21:12:39 +00002083 NodeDumper.dumpPointer(Node->getLabel());
Chris Lattnercbe4f772007-08-08 22:51:59 +00002084}
2085
Chris Lattner8f184b12007-08-09 18:03:18 +00002086//===----------------------------------------------------------------------===//
2087// C++ Expressions
2088//===----------------------------------------------------------------------===//
Chris Lattnercbe4f772007-08-08 22:51:59 +00002089
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002090void ASTDumper::VisitCXXNamedCastExpr(const CXXNamedCastExpr *Node) {
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002091 OS << " " << Node->getCastName()
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002092 << "<" << Node->getTypeAsWritten().getAsString() << ">"
Anders Carlssona70cff62010-04-24 19:06:50 +00002093 << " <" << Node->getCastKindName();
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002094 dumpBasePath(OS, Node);
Anders Carlssona70cff62010-04-24 19:06:50 +00002095 OS << ">";
Chris Lattnercbe4f772007-08-08 22:51:59 +00002096}
2097
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002098void ASTDumper::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *Node) {
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002099 OS << " " << (Node->getValue() ? "true" : "false");
Chris Lattnercbe4f772007-08-08 22:51:59 +00002100}
2101
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002102void ASTDumper::VisitCXXThisExpr(const CXXThisExpr *Node) {
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002103 OS << " this";
Douglas Gregor8ea1f532008-11-04 14:56:14 +00002104}
2105
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002106void ASTDumper::VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *Node) {
Eli Friedman29538892011-09-02 17:38:59 +00002107 OS << " functional cast to " << Node->getTypeAsWritten().getAsString()
2108 << " <" << Node->getCastKindName() << ">";
Douglas Gregore200adc2008-10-27 19:41:14 +00002109}
2110
Richard Smith39eca9b2017-08-23 22:12:08 +00002111void ASTDumper::VisitCXXUnresolvedConstructExpr(
2112 const CXXUnresolvedConstructExpr *Node) {
Stephen Kellyd8744a72018-12-05 21:12:39 +00002113 NodeDumper.dumpType(Node->getTypeAsWritten());
Richard Smith39eca9b2017-08-23 22:12:08 +00002114 if (Node->isListInitialization())
2115 OS << " list";
2116}
2117
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002118void ASTDumper::VisitCXXConstructExpr(const CXXConstructExpr *Node) {
John McCalleba90cd2010-02-02 19:03:45 +00002119 CXXConstructorDecl *Ctor = Node->getConstructor();
Stephen Kellyd8744a72018-12-05 21:12:39 +00002120 NodeDumper.dumpType(Ctor->getType());
Anders Carlsson073846832009-08-12 00:21:52 +00002121 if (Node->isElidable())
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002122 OS << " elidable";
Richard Smith39eca9b2017-08-23 22:12:08 +00002123 if (Node->isListInitialization())
2124 OS << " list";
2125 if (Node->isStdInitListInitialization())
2126 OS << " std::initializer_list";
John McCall85370042010-08-07 06:38:55 +00002127 if (Node->requiresZeroInitialization())
2128 OS << " zeroing";
Anders Carlsson073846832009-08-12 00:21:52 +00002129}
2130
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002131void ASTDumper::VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *Node) {
Daniel Dunbar34a96c82009-12-03 09:13:13 +00002132 OS << " ";
Stephen Kellyd8744a72018-12-05 21:12:39 +00002133 NodeDumper.dumpCXXTemporary(Node->getTemporary());
Anders Carlsson073846832009-08-12 00:21:52 +00002134}
2135
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002136void ASTDumper::VisitCXXNewExpr(const CXXNewExpr *Node) {
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002137 if (Node->isGlobalNew())
Reid Kleckner461c0c62015-03-19 18:47:47 +00002138 OS << " global";
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002139 if (Node->isArray())
Reid Kleckner461c0c62015-03-19 18:47:47 +00002140 OS << " array";
2141 if (Node->getOperatorNew()) {
2142 OS << ' ';
Stephen Kellyd8744a72018-12-05 21:12:39 +00002143 NodeDumper.dumpBareDeclRef(Node->getOperatorNew());
Reid Kleckner461c0c62015-03-19 18:47:47 +00002144 }
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002145 // We could dump the deallocation function used in case of error, but it's
2146 // usually not that interesting.
2147}
2148
2149void ASTDumper::VisitCXXDeleteExpr(const CXXDeleteExpr *Node) {
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002150 if (Node->isGlobalDelete())
Reid Kleckner461c0c62015-03-19 18:47:47 +00002151 OS << " global";
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002152 if (Node->isArrayForm())
Reid Kleckner461c0c62015-03-19 18:47:47 +00002153 OS << " array";
2154 if (Node->getOperatorDelete()) {
2155 OS << ' ';
Stephen Kellyd8744a72018-12-05 21:12:39 +00002156 NodeDumper.dumpBareDeclRef(Node->getOperatorDelete());
Reid Kleckner461c0c62015-03-19 18:47:47 +00002157 }
Reid Kleckner5c682bc2015-03-19 18:09:25 +00002158}
2159
Richard Smithe6c01442013-06-05 00:46:14 +00002160void
2161ASTDumper::VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *Node) {
Richard Smithe6c01442013-06-05 00:46:14 +00002162 if (const ValueDecl *VD = Node->getExtendingDecl()) {
2163 OS << " extended by ";
Stephen Kellyd8744a72018-12-05 21:12:39 +00002164 NodeDumper.dumpBareDeclRef(VD);
Richard Smithe6c01442013-06-05 00:46:14 +00002165 }
2166}
2167
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002168void ASTDumper::VisitExprWithCleanups(const ExprWithCleanups *Node) {
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002169 for (unsigned i = 0, e = Node->getNumObjects(); i != e; ++i)
2170 dumpDeclRef(Node->getObject(i), "cleanup");
Anders Carlsson073846832009-08-12 00:21:52 +00002171}
2172
Serge Pavlov6b926032015-02-16 19:58:41 +00002173void ASTDumper::VisitSizeOfPackExpr(const SizeOfPackExpr *Node) {
Stephen Kellyd8744a72018-12-05 21:12:39 +00002174 NodeDumper.dumpPointer(Node->getPack());
2175 NodeDumper.dumpName(Node->getPack());
Richard Smithd784e682015-09-23 21:41:42 +00002176 if (Node->isPartiallySubstituted())
2177 for (const auto &A : Node->getPartialArguments())
2178 dumpTemplateArgument(A);
Serge Pavlov6b926032015-02-16 19:58:41 +00002179}
2180
Alex Lorenzddbe0f52016-11-09 14:02:18 +00002181void ASTDumper::VisitCXXDependentScopeMemberExpr(
2182 const CXXDependentScopeMemberExpr *Node) {
Alex Lorenzddbe0f52016-11-09 14:02:18 +00002183 OS << " " << (Node->isArrow() ? "->" : ".") << Node->getMember();
2184}
Serge Pavlov6b926032015-02-16 19:58:41 +00002185
Anders Carlsson76f4a902007-08-21 17:43:55 +00002186//===----------------------------------------------------------------------===//
2187// Obj-C Expressions
2188//===----------------------------------------------------------------------===//
2189
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002190void ASTDumper::VisitObjCMessageExpr(const ObjCMessageExpr *Node) {
Aaron Ballmanb190f972014-01-03 17:59:55 +00002191 OS << " selector=";
2192 Node->getSelector().print(OS);
Douglas Gregor9a129192010-04-21 00:45:42 +00002193 switch (Node->getReceiverKind()) {
2194 case ObjCMessageExpr::Instance:
2195 break;
2196
2197 case ObjCMessageExpr::Class:
2198 OS << " class=";
Stephen Kellyd8744a72018-12-05 21:12:39 +00002199 NodeDumper.dumpBareType(Node->getClassReceiver());
Douglas Gregor9a129192010-04-21 00:45:42 +00002200 break;
2201
2202 case ObjCMessageExpr::SuperInstance:
2203 OS << " super (instance)";
2204 break;
2205
2206 case ObjCMessageExpr::SuperClass:
2207 OS << " super (class)";
2208 break;
2209 }
Ted Kremenek36748da2008-02-29 22:04:05 +00002210}
2211
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002212void ASTDumper::VisitObjCBoxedExpr(const ObjCBoxedExpr *Node) {
Richard Trieu4b259c82016-06-09 22:03:04 +00002213 if (auto *BoxingMethod = Node->getBoxingMethod()) {
2214 OS << " selector=";
2215 BoxingMethod->getSelector().print(OS);
2216 }
Argyrios Kyrtzidis9dd40892012-05-10 20:02:31 +00002217}
2218
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002219void ASTDumper::VisitObjCAtCatchStmt(const ObjCAtCatchStmt *Node) {
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002220 if (const VarDecl *CatchParam = Node->getCatchParamDecl())
Alexander Kornienko7bd0f9b2012-12-11 15:20:44 +00002221 dumpDecl(CatchParam);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002222 else
Douglas Gregor96c79492010-04-23 22:50:49 +00002223 OS << " catch all";
Douglas Gregor96c79492010-04-23 22:50:49 +00002224}
2225
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002226void ASTDumper::VisitObjCEncodeExpr(const ObjCEncodeExpr *Node) {
Stephen Kellyd8744a72018-12-05 21:12:39 +00002227 NodeDumper.dumpType(Node->getEncodedType());
Anders Carlssonc5a81eb2007-08-22 15:14:15 +00002228}
2229
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002230void ASTDumper::VisitObjCSelectorExpr(const ObjCSelectorExpr *Node) {
Aaron Ballmanb190f972014-01-03 17:59:55 +00002231 OS << " ";
2232 Node->getSelector().print(OS);
Fariborz Jahanian4bef4622007-10-16 20:40:23 +00002233}
2234
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002235void ASTDumper::VisitObjCProtocolExpr(const ObjCProtocolExpr *Node) {
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002236 OS << ' ' << *Node->getProtocol();
Fariborz Jahaniana32aaef2007-10-17 16:58:11 +00002237}
Daniel Dunbar4b8c6db2008-08-30 05:35:15 +00002238
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002239void ASTDumper::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *Node) {
John McCallb7bd14f2010-12-02 01:19:52 +00002240 if (Node->isImplicitProperty()) {
Fariborz Jahanian0f0b3022010-12-22 19:46:35 +00002241 OS << " Kind=MethodRef Getter=\"";
2242 if (Node->getImplicitPropertyGetter())
Aaron Ballmanb190f972014-01-03 17:59:55 +00002243 Node->getImplicitPropertyGetter()->getSelector().print(OS);
Fariborz Jahanian0f0b3022010-12-22 19:46:35 +00002244 else
2245 OS << "(null)";
2246
2247 OS << "\" Setter=\"";
John McCallb7bd14f2010-12-02 01:19:52 +00002248 if (ObjCMethodDecl *Setter = Node->getImplicitPropertySetter())
Aaron Ballmanb190f972014-01-03 17:59:55 +00002249 Setter->getSelector().print(OS);
John McCallb7bd14f2010-12-02 01:19:52 +00002250 else
2251 OS << "(null)";
2252 OS << "\"";
2253 } else {
Benjamin Kramerb89514a2011-10-14 18:45:37 +00002254 OS << " Kind=PropertyRef Property=\"" << *Node->getExplicitProperty() <<'"';
John McCallb7bd14f2010-12-02 01:19:52 +00002255 }
Fariborz Jahanian8a1810f2008-11-22 18:39:36 +00002256
Fariborz Jahanian681c0752010-10-14 16:04:05 +00002257 if (Node->isSuperReceiver())
2258 OS << " super";
Argyrios Kyrtzidisab468b02012-03-30 00:19:18 +00002259
2260 OS << " Messaging=";
2261 if (Node->isMessagingGetter() && Node->isMessagingSetter())
2262 OS << "Getter&Setter";
2263 else if (Node->isMessagingGetter())
2264 OS << "Getter";
2265 else if (Node->isMessagingSetter())
2266 OS << "Setter";
Douglas Gregor8ea1f532008-11-04 14:56:14 +00002267}
2268
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002269void ASTDumper::VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *Node) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00002270 if (Node->isArraySubscriptRefExpr())
2271 OS << " Kind=ArraySubscript GetterForArray=\"";
2272 else
2273 OS << " Kind=DictionarySubscript GetterForDictionary=\"";
2274 if (Node->getAtIndexMethodDecl())
Aaron Ballmanb190f972014-01-03 17:59:55 +00002275 Node->getAtIndexMethodDecl()->getSelector().print(OS);
Ted Kremeneke65b0862012-03-06 20:05:56 +00002276 else
2277 OS << "(null)";
Alexander Kornienko61c93bd2012-12-11 15:28:09 +00002278
Ted Kremeneke65b0862012-03-06 20:05:56 +00002279 if (Node->isArraySubscriptRefExpr())
2280 OS << "\" SetterForArray=\"";
2281 else
2282 OS << "\" SetterForDictionary=\"";
2283 if (Node->setAtIndexMethodDecl())
Aaron Ballmanb190f972014-01-03 17:59:55 +00002284 Node->setAtIndexMethodDecl()->getSelector().print(OS);
Ted Kremeneke65b0862012-03-06 20:05:56 +00002285 else
2286 OS << "(null)";
2287}
2288
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002289void ASTDumper::VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *Node) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00002290 OS << " " << (Node->getValue() ? "__objc_yes" : "__objc_no");
2291}
2292
Chris Lattnercbe4f772007-08-08 22:51:59 +00002293//===----------------------------------------------------------------------===//
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002294// Comments
2295//===----------------------------------------------------------------------===//
2296
2297const char *ASTDumper::getCommandName(unsigned CommandID) {
2298 if (Traits)
2299 return Traits->getCommandInfo(CommandID)->Name;
2300 const CommandInfo *Info = CommandTraits::getBuiltinCommandInfo(CommandID);
2301 if (Info)
2302 return Info->Name;
2303 return "<not a builtin command>";
2304}
2305
Stephen Kellycdbfb302018-12-02 17:30:40 +00002306void ASTDumper::dumpComment(const Comment *C, const FullComment *FC) {
Richard Smithf7514452014-10-30 21:02:37 +00002307 dumpChild([=] {
2308 if (!C) {
Stephen Kelly27e948c2018-11-29 19:30:37 +00002309 ColorScope Color(OS, ShowColors, NullColor);
Richard Smithf7514452014-10-30 21:02:37 +00002310 OS << "<<<NULL>>>";
2311 return;
2312 }
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002313
Richard Smithf7514452014-10-30 21:02:37 +00002314 {
Stephen Kelly27e948c2018-11-29 19:30:37 +00002315 ColorScope Color(OS, ShowColors, CommentColor);
Richard Smithf7514452014-10-30 21:02:37 +00002316 OS << C->getCommentKindName();
2317 }
Stephen Kellyd8744a72018-12-05 21:12:39 +00002318 NodeDumper.dumpPointer(C);
2319 NodeDumper.dumpSourceRange(C->getSourceRange());
Stephen Kellycdbfb302018-12-02 17:30:40 +00002320 ConstCommentVisitor<ASTDumper, void, const FullComment *>::visit(C, FC);
Richard Smithf7514452014-10-30 21:02:37 +00002321 for (Comment::child_iterator I = C->child_begin(), E = C->child_end();
2322 I != E; ++I)
Stephen Kellycdbfb302018-12-02 17:30:40 +00002323 dumpComment(*I, FC);
Richard Smithf7514452014-10-30 21:02:37 +00002324 });
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002325}
2326
Stephen Kellycdbfb302018-12-02 17:30:40 +00002327void ASTDumper::visitTextComment(const TextComment *C, const FullComment *) {
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002328 OS << " Text=\"" << C->getText() << "\"";
2329}
2330
Stephen Kellycdbfb302018-12-02 17:30:40 +00002331void ASTDumper::visitInlineCommandComment(const InlineCommandComment *C,
2332 const FullComment *) {
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002333 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\"";
2334 switch (C->getRenderKind()) {
2335 case InlineCommandComment::RenderNormal:
2336 OS << " RenderNormal";
2337 break;
2338 case InlineCommandComment::RenderBold:
2339 OS << " RenderBold";
2340 break;
2341 case InlineCommandComment::RenderMonospaced:
2342 OS << " RenderMonospaced";
2343 break;
2344 case InlineCommandComment::RenderEmphasized:
2345 OS << " RenderEmphasized";
2346 break;
2347 }
2348
2349 for (unsigned i = 0, e = C->getNumArgs(); i != e; ++i)
2350 OS << " Arg[" << i << "]=\"" << C->getArgText(i) << "\"";
2351}
2352
Stephen Kellycdbfb302018-12-02 17:30:40 +00002353void ASTDumper::visitHTMLStartTagComment(const HTMLStartTagComment *C,
2354 const FullComment *) {
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002355 OS << " Name=\"" << C->getTagName() << "\"";
2356 if (C->getNumAttrs() != 0) {
2357 OS << " Attrs: ";
2358 for (unsigned i = 0, e = C->getNumAttrs(); i != e; ++i) {
2359 const HTMLStartTagComment::Attribute &Attr = C->getAttr(i);
2360 OS << " \"" << Attr.Name << "=\"" << Attr.Value << "\"";
2361 }
2362 }
2363 if (C->isSelfClosing())
2364 OS << " SelfClosing";
2365}
2366
Stephen Kellycdbfb302018-12-02 17:30:40 +00002367void ASTDumper::visitHTMLEndTagComment(const HTMLEndTagComment *C,
2368 const FullComment *) {
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002369 OS << " Name=\"" << C->getTagName() << "\"";
2370}
2371
Stephen Kellycdbfb302018-12-02 17:30:40 +00002372void ASTDumper::visitBlockCommandComment(const BlockCommandComment *C,
2373 const FullComment *) {
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002374 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\"";
2375 for (unsigned i = 0, e = C->getNumArgs(); i != e; ++i)
2376 OS << " Arg[" << i << "]=\"" << C->getArgText(i) << "\"";
2377}
2378
Stephen Kellycdbfb302018-12-02 17:30:40 +00002379void ASTDumper::visitParamCommandComment(const ParamCommandComment *C,
2380 const FullComment *FC) {
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002381 OS << " " << ParamCommandComment::getDirectionAsString(C->getDirection());
2382
2383 if (C->isDirectionExplicit())
2384 OS << " explicitly";
2385 else
2386 OS << " implicitly";
2387
2388 if (C->hasParamName()) {
2389 if (C->isParamIndexValid())
2390 OS << " Param=\"" << C->getParamName(FC) << "\"";
2391 else
2392 OS << " Param=\"" << C->getParamNameAsWritten() << "\"";
2393 }
2394
Dmitri Gribenkodbff5c72014-03-19 14:03:47 +00002395 if (C->isParamIndexValid() && !C->isVarArgParam())
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002396 OS << " ParamIndex=" << C->getParamIndex();
2397}
2398
Stephen Kellycdbfb302018-12-02 17:30:40 +00002399void ASTDumper::visitTParamCommandComment(const TParamCommandComment *C,
2400 const FullComment *FC) {
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002401 if (C->hasParamName()) {
2402 if (C->isPositionValid())
2403 OS << " Param=\"" << C->getParamName(FC) << "\"";
2404 else
2405 OS << " Param=\"" << C->getParamNameAsWritten() << "\"";
2406 }
2407
2408 if (C->isPositionValid()) {
2409 OS << " Position=<";
2410 for (unsigned i = 0, e = C->getDepth(); i != e; ++i) {
2411 OS << C->getIndex(i);
2412 if (i != e - 1)
2413 OS << ", ";
2414 }
2415 OS << ">";
2416 }
2417}
2418
Stephen Kellycdbfb302018-12-02 17:30:40 +00002419void ASTDumper::visitVerbatimBlockComment(const VerbatimBlockComment *C,
2420 const FullComment *) {
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002421 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\""
2422 " CloseName=\"" << C->getCloseName() << "\"";
2423}
2424
Stephen Kellycdbfb302018-12-02 17:30:40 +00002425void ASTDumper::visitVerbatimBlockLineComment(const VerbatimBlockLineComment *C,
2426 const FullComment *) {
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002427 OS << " Text=\"" << C->getText() << "\"";
2428}
2429
Stephen Kellycdbfb302018-12-02 17:30:40 +00002430void ASTDumper::visitVerbatimLineComment(const VerbatimLineComment *C,
2431 const FullComment *) {
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002432 OS << " Text=\"" << C->getText() << "\"";
2433}
2434
2435//===----------------------------------------------------------------------===//
Richard Smithd5e7ff82014-10-31 01:17:45 +00002436// Type method implementations
2437//===----------------------------------------------------------------------===//
2438
2439void QualType::dump(const char *msg) const {
2440 if (msg)
2441 llvm::errs() << msg << ": ";
2442 dump();
2443}
2444
Richard Smith14d04842016-11-02 23:57:18 +00002445LLVM_DUMP_METHOD void QualType::dump() const { dump(llvm::errs()); }
2446
2447LLVM_DUMP_METHOD void QualType::dump(llvm::raw_ostream &OS) const {
2448 ASTDumper Dumper(OS, nullptr, nullptr);
Richard Smithd5e7ff82014-10-31 01:17:45 +00002449 Dumper.dumpTypeAsChild(*this);
2450}
2451
Richard Smith14d04842016-11-02 23:57:18 +00002452LLVM_DUMP_METHOD void Type::dump() const { dump(llvm::errs()); }
2453
2454LLVM_DUMP_METHOD void Type::dump(llvm::raw_ostream &OS) const {
2455 QualType(this, 0).dump(OS);
2456}
Richard Smithd5e7ff82014-10-31 01:17:45 +00002457
2458//===----------------------------------------------------------------------===//
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002459// Decl method implementations
2460//===----------------------------------------------------------------------===//
2461
Alp Tokeref6b0072014-01-04 13:47:14 +00002462LLVM_DUMP_METHOD void Decl::dump() const { dump(llvm::errs()); }
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002463
Richard Smith3a36ac12017-03-09 22:00:01 +00002464LLVM_DUMP_METHOD void Decl::dump(raw_ostream &OS, bool Deserialize) const {
Aaron Ballman8c208282017-12-21 21:42:42 +00002465 const ASTContext &Ctx = getASTContext();
2466 const SourceManager &SM = Ctx.getSourceManager();
2467 ASTDumper P(OS, &Ctx.getCommentCommandTraits(), &SM,
2468 SM.getDiagnostics().getShowColors(), Ctx.getPrintingPolicy());
Richard Smith3a36ac12017-03-09 22:00:01 +00002469 P.setDeserialize(Deserialize);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002470 P.dumpDecl(this);
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002471}
2472
Alp Tokeref6b0072014-01-04 13:47:14 +00002473LLVM_DUMP_METHOD void Decl::dumpColor() const {
Aaron Ballman8c208282017-12-21 21:42:42 +00002474 const ASTContext &Ctx = getASTContext();
2475 ASTDumper P(llvm::errs(), &Ctx.getCommentCommandTraits(),
2476 &Ctx.getSourceManager(), /*ShowColors*/ true,
2477 Ctx.getPrintingPolicy());
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002478 P.dumpDecl(this);
Richard Trieud215b8d2013-01-26 01:31:20 +00002479}
Richard Smith33937e72013-06-22 21:49:40 +00002480
Alp Tokeref6b0072014-01-04 13:47:14 +00002481LLVM_DUMP_METHOD void DeclContext::dumpLookups() const {
Richard Smith6ea05822013-06-24 01:45:33 +00002482 dumpLookups(llvm::errs());
2483}
2484
Richard Smith35f986d2014-08-11 22:11:07 +00002485LLVM_DUMP_METHOD void DeclContext::dumpLookups(raw_ostream &OS,
Richard Smith3a36ac12017-03-09 22:00:01 +00002486 bool DumpDecls,
2487 bool Deserialize) const {
Richard Smith33937e72013-06-22 21:49:40 +00002488 const DeclContext *DC = this;
2489 while (!DC->isTranslationUnit())
2490 DC = DC->getParent();
2491 ASTContext &Ctx = cast<TranslationUnitDecl>(DC)->getASTContext();
Aaron Ballman8c208282017-12-21 21:42:42 +00002492 const SourceManager &SM = Ctx.getSourceManager();
2493 ASTDumper P(OS, &Ctx.getCommentCommandTraits(), &Ctx.getSourceManager(),
2494 SM.getDiagnostics().getShowColors(), Ctx.getPrintingPolicy());
Richard Smith3a36ac12017-03-09 22:00:01 +00002495 P.setDeserialize(Deserialize);
Richard Smith35f986d2014-08-11 22:11:07 +00002496 P.dumpLookups(this, DumpDecls);
Richard Smith33937e72013-06-22 21:49:40 +00002497}
2498
Alexander Kornienko90ff6072012-12-20 02:09:13 +00002499//===----------------------------------------------------------------------===//
Chris Lattnercbe4f772007-08-08 22:51:59 +00002500// Stmt method implementations
2501//===----------------------------------------------------------------------===//
2502
Alp Tokeref6b0072014-01-04 13:47:14 +00002503LLVM_DUMP_METHOD void Stmt::dump(SourceManager &SM) const {
Argyrios Kyrtzidisc049f752010-08-09 10:54:31 +00002504 dump(llvm::errs(), SM);
2505}
2506
Alp Tokeref6b0072014-01-04 13:47:14 +00002507LLVM_DUMP_METHOD void Stmt::dump(raw_ostream &OS, SourceManager &SM) const {
Craig Topper36250ad2014-05-12 05:36:57 +00002508 ASTDumper P(OS, nullptr, &SM);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002509 P.dumpStmt(this);
Chris Lattner779d5d92007-08-30 00:40:08 +00002510}
2511
Faisal Vali2da8ed92015-03-22 13:35:56 +00002512LLVM_DUMP_METHOD void Stmt::dump(raw_ostream &OS) const {
2513 ASTDumper P(OS, nullptr, nullptr);
2514 P.dumpStmt(this);
2515}
2516
Alp Tokeref6b0072014-01-04 13:47:14 +00002517LLVM_DUMP_METHOD void Stmt::dump() const {
Craig Topper36250ad2014-05-12 05:36:57 +00002518 ASTDumper P(llvm::errs(), nullptr, nullptr);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002519 P.dumpStmt(this);
Chris Lattnercbe4f772007-08-08 22:51:59 +00002520}
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002521
Alp Tokeref6b0072014-01-04 13:47:14 +00002522LLVM_DUMP_METHOD void Stmt::dumpColor() const {
Craig Topper36250ad2014-05-12 05:36:57 +00002523 ASTDumper P(llvm::errs(), nullptr, nullptr, /*ShowColors*/true);
Alexander Kornienko540bacb2013-02-01 12:35:51 +00002524 P.dumpStmt(this);
Richard Trieud215b8d2013-01-26 01:31:20 +00002525}
2526
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002527//===----------------------------------------------------------------------===//
2528// Comment method implementations
2529//===----------------------------------------------------------------------===//
2530
Craig Topper36250ad2014-05-12 05:36:57 +00002531LLVM_DUMP_METHOD void Comment::dump() const {
2532 dump(llvm::errs(), nullptr, nullptr);
2533}
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002534
Alp Tokeref6b0072014-01-04 13:47:14 +00002535LLVM_DUMP_METHOD void Comment::dump(const ASTContext &Context) const {
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002536 dump(llvm::errs(), &Context.getCommentCommandTraits(),
2537 &Context.getSourceManager());
2538}
2539
Alexander Kornienko00911f12013-01-15 12:20:21 +00002540void Comment::dump(raw_ostream &OS, const CommandTraits *Traits,
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002541 const SourceManager *SM) const {
2542 const FullComment *FC = dyn_cast<FullComment>(this);
Stephen Kelly570b2972018-12-09 13:18:55 +00002543 if (!FC)
2544 return;
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002545 ASTDumper D(OS, Traits, SM);
Stephen Kelly570b2972018-12-09 13:18:55 +00002546 D.dumpComment(FC, FC);
Alexander Kornienkoebc17b52013-01-14 14:07:11 +00002547}
Richard Trieud215b8d2013-01-26 01:31:20 +00002548
Alp Tokeref6b0072014-01-04 13:47:14 +00002549LLVM_DUMP_METHOD void Comment::dumpColor() const {
Richard Trieud215b8d2013-01-26 01:31:20 +00002550 const FullComment *FC = dyn_cast<FullComment>(this);
Stephen Kelly570b2972018-12-09 13:18:55 +00002551 if (!FC)
2552 return;
Craig Topper36250ad2014-05-12 05:36:57 +00002553 ASTDumper D(llvm::errs(), nullptr, nullptr, /*ShowColors*/true);
Stephen Kelly570b2972018-12-09 13:18:55 +00002554 D.dumpComment(FC, FC);
Richard Trieud215b8d2013-01-26 01:31:20 +00002555}