1 //===--- ASTDumper.cpp - Dumping implementation for ASTs ------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the AST dump methods, which dump out the
11 // AST in a form that exposes type details and other fields.
13 //===----------------------------------------------------------------------===//
15 #include "clang/AST/ASTContext.h"
16 #include "clang/AST/Attr.h"
17 #include "clang/AST/CommentVisitor.h"
18 #include "clang/AST/DeclCXX.h"
19 #include "clang/AST/DeclLookups.h"
20 #include "clang/AST/DeclObjC.h"
21 #include "clang/AST/DeclOpenMP.h"
22 #include "clang/AST/DeclVisitor.h"
23 #include "clang/AST/LocInfoType.h"
24 #include "clang/AST/StmtVisitor.h"
25 #include "clang/AST/TypeVisitor.h"
26 #include "clang/Basic/Builtins.h"
27 #include "clang/Basic/Module.h"
28 #include "clang/Basic/SourceManager.h"
29 #include "llvm/Support/raw_ostream.h"
30 using namespace clang;
31 using namespace clang::comments;
33 //===----------------------------------------------------------------------===//
35 //===----------------------------------------------------------------------===//
38 // Colors used for various parts of the AST dump
39 // Do not use bold yellow for any text. It is hard to read on white screens.
41 struct TerminalColor {
42 raw_ostream::Colors Color;
48 // Bold Green - DeclKindNameColor, UndeserializedColor
49 // Yellow - AddressColor, LocationColor
50 // Blue - CommentColor, NullColor, IndentColor
51 // Bold Blue - AttrColor
52 // Bold Magenta - StmtColor
53 // Cyan - ValueKindColor, ObjectKindColor
54 // Bold Cyan - ValueColor, DeclNameColor
56 // Decl kind names (VarDecl, FunctionDecl, etc)
57 static const TerminalColor DeclKindNameColor = { raw_ostream::GREEN, true };
58 // Attr names (CleanupAttr, GuardedByAttr, etc)
59 static const TerminalColor AttrColor = { raw_ostream::BLUE, true };
60 // Statement names (DeclStmt, ImplicitCastExpr, etc)
61 static const TerminalColor StmtColor = { raw_ostream::MAGENTA, true };
62 // Comment names (FullComment, ParagraphComment, TextComment, etc)
63 static const TerminalColor CommentColor = { raw_ostream::BLUE, false };
65 // Type names (int, float, etc, plus user defined types)
66 static const TerminalColor TypeColor = { raw_ostream::GREEN, false };
69 static const TerminalColor AddressColor = { raw_ostream::YELLOW, false };
71 static const TerminalColor LocationColor = { raw_ostream::YELLOW, false };
74 static const TerminalColor ValueKindColor = { raw_ostream::CYAN, false };
75 // bitfield/objcproperty/objcsubscript/vectorcomponent
76 static const TerminalColor ObjectKindColor = { raw_ostream::CYAN, false };
79 static const TerminalColor NullColor = { raw_ostream::BLUE, false };
81 // Undeserialized entities
82 static const TerminalColor UndeserializedColor = { raw_ostream::GREEN, true };
84 // CastKind from CastExpr's
85 static const TerminalColor CastColor = { raw_ostream::RED, false };
87 // Value of the statement
88 static const TerminalColor ValueColor = { raw_ostream::CYAN, true };
90 static const TerminalColor DeclNameColor = { raw_ostream::CYAN, true };
92 // Indents ( `, -. | )
93 static const TerminalColor IndentColor = { raw_ostream::BLUE, false };
96 : public ConstDeclVisitor<ASTDumper>, public ConstStmtVisitor<ASTDumper>,
97 public ConstCommentVisitor<ASTDumper>, public TypeVisitor<ASTDumper> {
99 const CommandTraits *Traits;
100 const SourceManager *SM;
102 /// Pending[i] is an action to dump an entity at level i.
103 llvm::SmallVector<std::function<void(bool isLastChild)>, 32> Pending;
105 /// Indicates whether we should trigger deserialization of nodes that had
106 /// not already been loaded.
107 bool Deserialize = false;
109 /// Indicates whether we're at the top level.
110 bool TopLevel = true;
112 /// Indicates if we're handling the first child after entering a new depth.
113 bool FirstChild = true;
115 /// Prefix for currently-being-dumped entity.
118 /// Keep track of the last location we print out so that we can
119 /// print out deltas from then on out.
120 const char *LastLocFilename = "";
121 unsigned LastLocLine = ~0U;
123 /// The \c FullComment parent of the comment being dumped.
124 const FullComment *FC = nullptr;
128 /// Dump a child of the current node.
129 template<typename Fn> void dumpChild(Fn doDumpChild) {
130 // If we're at the top level, there's nothing interesting to do; just
135 while (!Pending.empty()) {
136 Pending.back()(true);
145 const FullComment *OrigFC = FC;
146 auto dumpWithIndent = [this, doDumpChild, OrigFC](bool isLastChild) {
147 // Print out the appropriate tree structure and work out the prefix for
148 // children of this node. For instance:
152 // | `-C Prefix = "| "
154 // |-E Prefix = " | "
158 // Note that the first level gets no prefix.
161 ColorScope Color(*this, IndentColor);
162 OS << Prefix << (isLastChild ? '`' : '|') << '-';
163 this->Prefix.push_back(isLastChild ? ' ' : '|');
164 this->Prefix.push_back(' ');
168 unsigned Depth = Pending.size();
173 // If any children are left, they're the last at their nesting level.
174 // Dump those ones out now.
175 while (Depth < Pending.size()) {
176 Pending.back()(true);
177 this->Pending.pop_back();
180 // Restore the old prefix.
181 this->Prefix.resize(Prefix.size() - 2);
185 Pending.push_back(std::move(dumpWithIndent));
187 Pending.back()(false);
188 Pending.back() = std::move(dumpWithIndent);
196 ColorScope(ASTDumper &Dumper, TerminalColor Color)
198 if (Dumper.ShowColors)
199 Dumper.OS.changeColor(Color.Color, Color.Bold);
202 if (Dumper.ShowColors)
203 Dumper.OS.resetColor();
208 ASTDumper(raw_ostream &OS, const CommandTraits *Traits,
209 const SourceManager *SM)
210 : OS(OS), Traits(Traits), SM(SM),
211 ShowColors(SM && SM->getDiagnostics().getShowColors()) { }
213 ASTDumper(raw_ostream &OS, const CommandTraits *Traits,
214 const SourceManager *SM, bool ShowColors)
215 : OS(OS), Traits(Traits), SM(SM), ShowColors(ShowColors) {}
217 void setDeserialize(bool D) { Deserialize = D; }
219 void dumpDecl(const Decl *D);
220 void dumpStmt(const Stmt *S);
221 void dumpFullComment(const FullComment *C);
224 void dumpPointer(const void *Ptr);
225 void dumpSourceRange(SourceRange R);
226 void dumpLocation(SourceLocation Loc);
227 void dumpBareType(QualType T, bool Desugar = true);
228 void dumpType(QualType T);
229 void dumpTypeAsChild(QualType T);
230 void dumpTypeAsChild(const Type *T);
231 void dumpBareDeclRef(const Decl *Node);
232 void dumpDeclRef(const Decl *Node, const char *Label = nullptr);
233 void dumpName(const NamedDecl *D);
234 bool hasNodes(const DeclContext *DC);
235 void dumpDeclContext(const DeclContext *DC);
236 void dumpLookups(const DeclContext *DC, bool DumpDecls);
237 void dumpAttr(const Attr *A);
240 void dumpAccessSpecifier(AccessSpecifier AS);
241 void dumpCXXCtorInitializer(const CXXCtorInitializer *Init);
242 void dumpTemplateParameters(const TemplateParameterList *TPL);
243 void dumpTemplateArgumentListInfo(const TemplateArgumentListInfo &TALI);
244 void dumpTemplateArgumentLoc(const TemplateArgumentLoc &A);
245 void dumpTemplateArgumentList(const TemplateArgumentList &TAL);
246 void dumpTemplateArgument(const TemplateArgument &A,
247 SourceRange R = SourceRange());
249 // Objective-C utilities.
250 void dumpObjCTypeParamList(const ObjCTypeParamList *typeParams);
253 void VisitComplexType(const ComplexType *T) {
254 dumpTypeAsChild(T->getElementType());
256 void VisitPointerType(const PointerType *T) {
257 dumpTypeAsChild(T->getPointeeType());
259 void VisitBlockPointerType(const BlockPointerType *T) {
260 dumpTypeAsChild(T->getPointeeType());
262 void VisitReferenceType(const ReferenceType *T) {
263 dumpTypeAsChild(T->getPointeeType());
265 void VisitRValueReferenceType(const ReferenceType *T) {
266 if (T->isSpelledAsLValue())
267 OS << " written as lvalue reference";
268 VisitReferenceType(T);
270 void VisitMemberPointerType(const MemberPointerType *T) {
271 dumpTypeAsChild(T->getClass());
272 dumpTypeAsChild(T->getPointeeType());
274 void VisitArrayType(const ArrayType *T) {
275 switch (T->getSizeModifier()) {
276 case ArrayType::Normal: break;
277 case ArrayType::Static: OS << " static"; break;
278 case ArrayType::Star: OS << " *"; break;
280 OS << " " << T->getIndexTypeQualifiers().getAsString();
281 dumpTypeAsChild(T->getElementType());
283 void VisitConstantArrayType(const ConstantArrayType *T) {
284 OS << " " << T->getSize();
287 void VisitVariableArrayType(const VariableArrayType *T) {
289 dumpSourceRange(T->getBracketsRange());
291 dumpStmt(T->getSizeExpr());
293 void VisitDependentSizedArrayType(const DependentSizedArrayType *T) {
296 dumpSourceRange(T->getBracketsRange());
297 dumpStmt(T->getSizeExpr());
299 void VisitDependentSizedExtVectorType(
300 const DependentSizedExtVectorType *T) {
302 dumpLocation(T->getAttributeLoc());
303 dumpTypeAsChild(T->getElementType());
304 dumpStmt(T->getSizeExpr());
306 void VisitVectorType(const VectorType *T) {
307 switch (T->getVectorKind()) {
308 case VectorType::GenericVector: break;
309 case VectorType::AltiVecVector: OS << " altivec"; break;
310 case VectorType::AltiVecPixel: OS << " altivec pixel"; break;
311 case VectorType::AltiVecBool: OS << " altivec bool"; break;
312 case VectorType::NeonVector: OS << " neon"; break;
313 case VectorType::NeonPolyVector: OS << " neon poly"; break;
315 OS << " " << T->getNumElements();
316 dumpTypeAsChild(T->getElementType());
318 void VisitFunctionType(const FunctionType *T) {
319 auto EI = T->getExtInfo();
320 if (EI.getNoReturn()) OS << " noreturn";
321 if (EI.getProducesResult()) OS << " produces_result";
322 if (EI.getHasRegParm()) OS << " regparm " << EI.getRegParm();
323 OS << " " << FunctionType::getNameForCallConv(EI.getCC());
324 dumpTypeAsChild(T->getReturnType());
326 void VisitFunctionProtoType(const FunctionProtoType *T) {
327 auto EPI = T->getExtProtoInfo();
328 if (EPI.HasTrailingReturn) OS << " trailing_return";
329 if (T->isConst()) OS << " const";
330 if (T->isVolatile()) OS << " volatile";
331 if (T->isRestrict()) OS << " restrict";
332 switch (EPI.RefQualifier) {
334 case RQ_LValue: OS << " &"; break;
335 case RQ_RValue: OS << " &&"; break;
337 // FIXME: Exception specification.
338 // FIXME: Consumed parameters.
339 VisitFunctionType(T);
340 for (QualType PT : T->getParamTypes())
343 dumpChild([=] { OS << "..."; });
345 void VisitUnresolvedUsingType(const UnresolvedUsingType *T) {
346 dumpDeclRef(T->getDecl());
348 void VisitTypedefType(const TypedefType *T) {
349 dumpDeclRef(T->getDecl());
351 void VisitTypeOfExprType(const TypeOfExprType *T) {
352 dumpStmt(T->getUnderlyingExpr());
354 void VisitDecltypeType(const DecltypeType *T) {
355 dumpStmt(T->getUnderlyingExpr());
357 void VisitUnaryTransformType(const UnaryTransformType *T) {
358 switch (T->getUTTKind()) {
359 case UnaryTransformType::EnumUnderlyingType:
360 OS << " underlying_type";
363 dumpTypeAsChild(T->getBaseType());
365 void VisitTagType(const TagType *T) {
366 dumpDeclRef(T->getDecl());
368 void VisitAttributedType(const AttributedType *T) {
370 dumpTypeAsChild(T->getModifiedType());
372 void VisitTemplateTypeParmType(const TemplateTypeParmType *T) {
373 OS << " depth " << T->getDepth() << " index " << T->getIndex();
374 if (T->isParameterPack()) OS << " pack";
375 dumpDeclRef(T->getDecl());
377 void VisitSubstTemplateTypeParmType(const SubstTemplateTypeParmType *T) {
378 dumpTypeAsChild(T->getReplacedParameter());
380 void VisitSubstTemplateTypeParmPackType(
381 const SubstTemplateTypeParmPackType *T) {
382 dumpTypeAsChild(T->getReplacedParameter());
383 dumpTemplateArgument(T->getArgumentPack());
385 void VisitAutoType(const AutoType *T) {
386 if (T->isDecltypeAuto()) OS << " decltype(auto)";
390 void VisitTemplateSpecializationType(const TemplateSpecializationType *T) {
391 if (T->isTypeAlias()) OS << " alias";
392 OS << " "; T->getTemplateName().dump(OS);
394 dumpTemplateArgument(Arg);
395 if (T->isTypeAlias())
396 dumpTypeAsChild(T->getAliasedType());
398 void VisitInjectedClassNameType(const InjectedClassNameType *T) {
399 dumpDeclRef(T->getDecl());
401 void VisitObjCInterfaceType(const ObjCInterfaceType *T) {
402 dumpDeclRef(T->getDecl());
404 void VisitObjCObjectPointerType(const ObjCObjectPointerType *T) {
405 dumpTypeAsChild(T->getPointeeType());
407 void VisitAtomicType(const AtomicType *T) {
408 dumpTypeAsChild(T->getValueType());
410 void VisitPipeType(const PipeType *T) {
411 dumpTypeAsChild(T->getElementType());
413 void VisitAdjustedType(const AdjustedType *T) {
414 dumpTypeAsChild(T->getOriginalType());
416 void VisitPackExpansionType(const PackExpansionType *T) {
417 if (auto N = T->getNumExpansions()) OS << " expansions " << *N;
419 dumpTypeAsChild(T->getPattern());
421 // FIXME: ElaboratedType, DependentNameType,
422 // DependentTemplateSpecializationType, ObjCObjectType
425 void VisitLabelDecl(const LabelDecl *D);
426 void VisitTypedefDecl(const TypedefDecl *D);
427 void VisitEnumDecl(const EnumDecl *D);
428 void VisitRecordDecl(const RecordDecl *D);
429 void VisitEnumConstantDecl(const EnumConstantDecl *D);
430 void VisitIndirectFieldDecl(const IndirectFieldDecl *D);
431 void VisitFunctionDecl(const FunctionDecl *D);
432 void VisitFieldDecl(const FieldDecl *D);
433 void VisitVarDecl(const VarDecl *D);
434 void VisitDecompositionDecl(const DecompositionDecl *D);
435 void VisitBindingDecl(const BindingDecl *D);
436 void VisitFileScopeAsmDecl(const FileScopeAsmDecl *D);
437 void VisitImportDecl(const ImportDecl *D);
438 void VisitPragmaCommentDecl(const PragmaCommentDecl *D);
439 void VisitPragmaDetectMismatchDecl(const PragmaDetectMismatchDecl *D);
440 void VisitCapturedDecl(const CapturedDecl *D);
443 void VisitOMPThreadPrivateDecl(const OMPThreadPrivateDecl *D);
444 void VisitOMPDeclareReductionDecl(const OMPDeclareReductionDecl *D);
445 void VisitOMPCapturedExprDecl(const OMPCapturedExprDecl *D);
448 void VisitNamespaceDecl(const NamespaceDecl *D);
449 void VisitUsingDirectiveDecl(const UsingDirectiveDecl *D);
450 void VisitNamespaceAliasDecl(const NamespaceAliasDecl *D);
451 void VisitTypeAliasDecl(const TypeAliasDecl *D);
452 void VisitTypeAliasTemplateDecl(const TypeAliasTemplateDecl *D);
453 void VisitCXXRecordDecl(const CXXRecordDecl *D);
454 void VisitStaticAssertDecl(const StaticAssertDecl *D);
455 template<typename SpecializationDecl>
456 void VisitTemplateDeclSpecialization(const SpecializationDecl *D,
457 bool DumpExplicitInst,
459 template<typename TemplateDecl>
460 void VisitTemplateDecl(const TemplateDecl *D, bool DumpExplicitInst);
461 void VisitFunctionTemplateDecl(const FunctionTemplateDecl *D);
462 void VisitClassTemplateDecl(const ClassTemplateDecl *D);
463 void VisitClassTemplateSpecializationDecl(
464 const ClassTemplateSpecializationDecl *D);
465 void VisitClassTemplatePartialSpecializationDecl(
466 const ClassTemplatePartialSpecializationDecl *D);
467 void VisitClassScopeFunctionSpecializationDecl(
468 const ClassScopeFunctionSpecializationDecl *D);
469 void VisitBuiltinTemplateDecl(const BuiltinTemplateDecl *D);
470 void VisitVarTemplateDecl(const VarTemplateDecl *D);
471 void VisitVarTemplateSpecializationDecl(
472 const VarTemplateSpecializationDecl *D);
473 void VisitVarTemplatePartialSpecializationDecl(
474 const VarTemplatePartialSpecializationDecl *D);
475 void VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D);
476 void VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D);
477 void VisitTemplateTemplateParmDecl(const TemplateTemplateParmDecl *D);
478 void VisitUsingDecl(const UsingDecl *D);
479 void VisitUnresolvedUsingTypenameDecl(const UnresolvedUsingTypenameDecl *D);
480 void VisitUnresolvedUsingValueDecl(const UnresolvedUsingValueDecl *D);
481 void VisitUsingShadowDecl(const UsingShadowDecl *D);
482 void VisitConstructorUsingShadowDecl(const ConstructorUsingShadowDecl *D);
483 void VisitLinkageSpecDecl(const LinkageSpecDecl *D);
484 void VisitAccessSpecDecl(const AccessSpecDecl *D);
485 void VisitFriendDecl(const FriendDecl *D);
488 void VisitObjCIvarDecl(const ObjCIvarDecl *D);
489 void VisitObjCMethodDecl(const ObjCMethodDecl *D);
490 void VisitObjCTypeParamDecl(const ObjCTypeParamDecl *D);
491 void VisitObjCCategoryDecl(const ObjCCategoryDecl *D);
492 void VisitObjCCategoryImplDecl(const ObjCCategoryImplDecl *D);
493 void VisitObjCProtocolDecl(const ObjCProtocolDecl *D);
494 void VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D);
495 void VisitObjCImplementationDecl(const ObjCImplementationDecl *D);
496 void VisitObjCCompatibleAliasDecl(const ObjCCompatibleAliasDecl *D);
497 void VisitObjCPropertyDecl(const ObjCPropertyDecl *D);
498 void VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D);
499 void VisitBlockDecl(const BlockDecl *D);
502 void VisitStmt(const Stmt *Node);
503 void VisitDeclStmt(const DeclStmt *Node);
504 void VisitAttributedStmt(const AttributedStmt *Node);
505 void VisitLabelStmt(const LabelStmt *Node);
506 void VisitGotoStmt(const GotoStmt *Node);
507 void VisitCXXCatchStmt(const CXXCatchStmt *Node);
508 void VisitCapturedStmt(const CapturedStmt *Node);
511 void VisitOMPExecutableDirective(const OMPExecutableDirective *Node);
514 void VisitExpr(const Expr *Node);
515 void VisitCastExpr(const CastExpr *Node);
516 void VisitDeclRefExpr(const DeclRefExpr *Node);
517 void VisitPredefinedExpr(const PredefinedExpr *Node);
518 void VisitCharacterLiteral(const CharacterLiteral *Node);
519 void VisitIntegerLiteral(const IntegerLiteral *Node);
520 void VisitFloatingLiteral(const FloatingLiteral *Node);
521 void VisitStringLiteral(const StringLiteral *Str);
522 void VisitInitListExpr(const InitListExpr *ILE);
523 void VisitArrayInitLoopExpr(const ArrayInitLoopExpr *ILE);
524 void VisitArrayInitIndexExpr(const ArrayInitIndexExpr *ILE);
525 void VisitUnaryOperator(const UnaryOperator *Node);
526 void VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *Node);
527 void VisitMemberExpr(const MemberExpr *Node);
528 void VisitExtVectorElementExpr(const ExtVectorElementExpr *Node);
529 void VisitBinaryOperator(const BinaryOperator *Node);
530 void VisitCompoundAssignOperator(const CompoundAssignOperator *Node);
531 void VisitAddrLabelExpr(const AddrLabelExpr *Node);
532 void VisitBlockExpr(const BlockExpr *Node);
533 void VisitOpaqueValueExpr(const OpaqueValueExpr *Node);
536 void VisitCXXNamedCastExpr(const CXXNamedCastExpr *Node);
537 void VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *Node);
538 void VisitCXXThisExpr(const CXXThisExpr *Node);
539 void VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *Node);
540 void VisitCXXUnresolvedConstructExpr(const CXXUnresolvedConstructExpr *Node);
541 void VisitCXXConstructExpr(const CXXConstructExpr *Node);
542 void VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *Node);
543 void VisitCXXNewExpr(const CXXNewExpr *Node);
544 void VisitCXXDeleteExpr(const CXXDeleteExpr *Node);
545 void VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *Node);
546 void VisitExprWithCleanups(const ExprWithCleanups *Node);
547 void VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *Node);
548 void dumpCXXTemporary(const CXXTemporary *Temporary);
549 void VisitLambdaExpr(const LambdaExpr *Node) {
551 dumpDecl(Node->getLambdaClass());
553 void VisitSizeOfPackExpr(const SizeOfPackExpr *Node);
555 VisitCXXDependentScopeMemberExpr(const CXXDependentScopeMemberExpr *Node);
558 void VisitObjCAtCatchStmt(const ObjCAtCatchStmt *Node);
559 void VisitObjCEncodeExpr(const ObjCEncodeExpr *Node);
560 void VisitObjCMessageExpr(const ObjCMessageExpr *Node);
561 void VisitObjCBoxedExpr(const ObjCBoxedExpr *Node);
562 void VisitObjCSelectorExpr(const ObjCSelectorExpr *Node);
563 void VisitObjCProtocolExpr(const ObjCProtocolExpr *Node);
564 void VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *Node);
565 void VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *Node);
566 void VisitObjCIvarRefExpr(const ObjCIvarRefExpr *Node);
567 void VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *Node);
570 const char *getCommandName(unsigned CommandID);
571 void dumpComment(const Comment *C);
574 void visitTextComment(const TextComment *C);
575 void visitInlineCommandComment(const InlineCommandComment *C);
576 void visitHTMLStartTagComment(const HTMLStartTagComment *C);
577 void visitHTMLEndTagComment(const HTMLEndTagComment *C);
580 void visitBlockCommandComment(const BlockCommandComment *C);
581 void visitParamCommandComment(const ParamCommandComment *C);
582 void visitTParamCommandComment(const TParamCommandComment *C);
583 void visitVerbatimBlockComment(const VerbatimBlockComment *C);
584 void visitVerbatimBlockLineComment(const VerbatimBlockLineComment *C);
585 void visitVerbatimLineComment(const VerbatimLineComment *C);
589 //===----------------------------------------------------------------------===//
591 //===----------------------------------------------------------------------===//
593 void ASTDumper::dumpPointer(const void *Ptr) {
594 ColorScope Color(*this, AddressColor);
598 void ASTDumper::dumpLocation(SourceLocation Loc) {
602 ColorScope Color(*this, LocationColor);
603 SourceLocation SpellingLoc = SM->getSpellingLoc(Loc);
605 // The general format we print out is filename:line:col, but we drop pieces
606 // that haven't changed since the last loc printed.
607 PresumedLoc PLoc = SM->getPresumedLoc(SpellingLoc);
609 if (PLoc.isInvalid()) {
610 OS << "<invalid sloc>";
614 if (strcmp(PLoc.getFilename(), LastLocFilename) != 0) {
615 OS << PLoc.getFilename() << ':' << PLoc.getLine()
616 << ':' << PLoc.getColumn();
617 LastLocFilename = PLoc.getFilename();
618 LastLocLine = PLoc.getLine();
619 } else if (PLoc.getLine() != LastLocLine) {
620 OS << "line" << ':' << PLoc.getLine()
621 << ':' << PLoc.getColumn();
622 LastLocLine = PLoc.getLine();
624 OS << "col" << ':' << PLoc.getColumn();
628 void ASTDumper::dumpSourceRange(SourceRange R) {
629 // Can't translate locations if a SourceManager isn't available.
634 dumpLocation(R.getBegin());
635 if (R.getBegin() != R.getEnd()) {
637 dumpLocation(R.getEnd());
641 // <t2.c:123:421[blah], t2.c:412:321>
645 void ASTDumper::dumpBareType(QualType T, bool Desugar) {
646 ColorScope Color(*this, TypeColor);
648 SplitQualType T_split = T.split();
649 OS << "'" << QualType::getAsString(T_split) << "'";
651 if (Desugar && !T.isNull()) {
652 // If the type is sugared, also dump a (shallow) desugared type.
653 SplitQualType D_split = T.getSplitDesugaredType();
654 if (T_split != D_split)
655 OS << ":'" << QualType::getAsString(D_split) << "'";
659 void ASTDumper::dumpType(QualType T) {
664 void ASTDumper::dumpTypeAsChild(QualType T) {
665 SplitQualType SQT = T.split();
666 if (!SQT.Quals.hasQualifiers())
667 return dumpTypeAsChild(SQT.Ty);
671 dumpPointer(T.getAsOpaquePtr());
673 dumpBareType(T, false);
674 OS << " " << T.split().Quals.getAsString();
675 dumpTypeAsChild(T.split().Ty);
679 void ASTDumper::dumpTypeAsChild(const Type *T) {
682 ColorScope Color(*this, NullColor);
686 if (const LocInfoType *LIT = llvm::dyn_cast<LocInfoType>(T)) {
688 ColorScope Color(*this, TypeColor);
689 OS << "LocInfo Type";
692 dumpTypeAsChild(LIT->getTypeSourceInfo()->getType());
697 ColorScope Color(*this, TypeColor);
698 OS << T->getTypeClassName() << "Type";
702 dumpBareType(QualType(T, 0), false);
704 QualType SingleStepDesugar =
705 T->getLocallyUnqualifiedSingleStepDesugaredType();
706 if (SingleStepDesugar != QualType(T, 0))
708 if (T->isDependentType())
710 else if (T->isInstantiationDependentType())
711 OS << " instantiation_dependent";
712 if (T->isVariablyModifiedType())
713 OS << " variably_modified";
714 if (T->containsUnexpandedParameterPack())
715 OS << " contains_unexpanded_pack";
719 TypeVisitor<ASTDumper>::Visit(T);
721 if (SingleStepDesugar != QualType(T, 0))
722 dumpTypeAsChild(SingleStepDesugar);
726 void ASTDumper::dumpBareDeclRef(const Decl *D) {
728 ColorScope Color(*this, NullColor);
734 ColorScope Color(*this, DeclKindNameColor);
735 OS << D->getDeclKindName();
739 if (const NamedDecl *ND = dyn_cast<NamedDecl>(D)) {
740 ColorScope Color(*this, DeclNameColor);
741 OS << " '" << ND->getDeclName() << '\'';
744 if (const ValueDecl *VD = dyn_cast<ValueDecl>(D))
745 dumpType(VD->getType());
748 void ASTDumper::dumpDeclRef(const Decl *D, const char *Label) {
759 void ASTDumper::dumpName(const NamedDecl *ND) {
760 if (ND->getDeclName()) {
761 ColorScope Color(*this, DeclNameColor);
762 OS << ' ' << ND->getNameAsString();
766 bool ASTDumper::hasNodes(const DeclContext *DC) {
770 return DC->hasExternalLexicalStorage() ||
771 (Deserialize ? DC->decls_begin() != DC->decls_end()
772 : DC->noload_decls_begin() != DC->noload_decls_end());
775 void ASTDumper::dumpDeclContext(const DeclContext *DC) {
779 for (auto *D : (Deserialize ? DC->decls() : DC->noload_decls()))
782 if (DC->hasExternalLexicalStorage()) {
784 ColorScope Color(*this, UndeserializedColor);
785 OS << "<undeserialized declarations>";
790 void ASTDumper::dumpLookups(const DeclContext *DC, bool DumpDecls) {
792 OS << "StoredDeclsMap ";
793 dumpBareDeclRef(cast<Decl>(DC));
795 const DeclContext *Primary = DC->getPrimaryContext();
798 dumpPointer(cast<Decl>(Primary));
801 bool HasUndeserializedLookups = Primary->hasExternalVisibleStorage();
803 for (auto I = Deserialize ? Primary->lookups_begin()
804 : Primary->noload_lookups_begin(),
805 E = Deserialize ? Primary->lookups_end()
806 : Primary->noload_lookups_end();
808 DeclarationName Name = I.getLookupName();
809 DeclContextLookupResult R = *I;
812 OS << "DeclarationName ";
814 ColorScope Color(*this, DeclNameColor);
815 OS << '\'' << Name << '\'';
818 for (DeclContextLookupResult::iterator RI = R.begin(), RE = R.end();
821 dumpBareDeclRef(*RI);
823 if ((*RI)->isHidden())
826 // If requested, dump the redecl chain for this lookup.
828 // Dump earliest decl first.
829 std::function<void(Decl *)> DumpWithPrev = [&](Decl *D) {
830 if (Decl *Prev = D->getPreviousDecl())
841 if (HasUndeserializedLookups) {
843 ColorScope Color(*this, UndeserializedColor);
844 OS << "<undeserialized lookups>";
850 void ASTDumper::dumpAttr(const Attr *A) {
853 ColorScope Color(*this, AttrColor);
855 switch (A->getKind()) {
856 #define ATTR(X) case attr::X: OS << #X; break;
857 #include "clang/Basic/AttrList.inc"
862 dumpSourceRange(A->getRange());
863 if (A->isInherited())
867 #include "clang/AST/AttrDump.inc"
871 static void dumpPreviousDeclImpl(raw_ostream &OS, ...) {}
874 static void dumpPreviousDeclImpl(raw_ostream &OS, const Mergeable<T> *D) {
875 const T *First = D->getFirstDecl();
877 OS << " first " << First;
881 static void dumpPreviousDeclImpl(raw_ostream &OS, const Redeclarable<T> *D) {
882 const T *Prev = D->getPreviousDecl();
884 OS << " prev " << Prev;
887 /// Dump the previous declaration in the redeclaration chain for a declaration,
889 static void dumpPreviousDecl(raw_ostream &OS, const Decl *D) {
890 switch (D->getKind()) {
891 #define DECL(DERIVED, BASE) \
892 case Decl::DERIVED: \
893 return dumpPreviousDeclImpl(OS, cast<DERIVED##Decl>(D));
894 #define ABSTRACT_DECL(DECL)
895 #include "clang/AST/DeclNodes.inc"
897 llvm_unreachable("Decl that isn't part of DeclNodes.inc!");
900 //===----------------------------------------------------------------------===//
902 //===----------------------------------------------------------------------===//
904 void ASTDumper::dumpAccessSpecifier(AccessSpecifier AS) {
920 void ASTDumper::dumpCXXCtorInitializer(const CXXCtorInitializer *Init) {
922 OS << "CXXCtorInitializer";
923 if (Init->isAnyMemberInitializer()) {
925 dumpBareDeclRef(Init->getAnyMember());
926 } else if (Init->isBaseInitializer()) {
927 dumpType(QualType(Init->getBaseClass(), 0));
928 } else if (Init->isDelegatingInitializer()) {
929 dumpType(Init->getTypeSourceInfo()->getType());
931 llvm_unreachable("Unknown initializer type");
933 dumpStmt(Init->getInit());
937 void ASTDumper::dumpTemplateParameters(const TemplateParameterList *TPL) {
941 for (TemplateParameterList::const_iterator I = TPL->begin(), E = TPL->end();
946 void ASTDumper::dumpTemplateArgumentListInfo(
947 const TemplateArgumentListInfo &TALI) {
948 for (unsigned i = 0, e = TALI.size(); i < e; ++i)
949 dumpTemplateArgumentLoc(TALI[i]);
952 void ASTDumper::dumpTemplateArgumentLoc(const TemplateArgumentLoc &A) {
953 dumpTemplateArgument(A.getArgument(), A.getSourceRange());
956 void ASTDumper::dumpTemplateArgumentList(const TemplateArgumentList &TAL) {
957 for (unsigned i = 0, e = TAL.size(); i < e; ++i)
958 dumpTemplateArgument(TAL[i]);
961 void ASTDumper::dumpTemplateArgument(const TemplateArgument &A, SourceRange R) {
963 OS << "TemplateArgument";
967 switch (A.getKind()) {
968 case TemplateArgument::Null:
971 case TemplateArgument::Type:
973 dumpType(A.getAsType());
975 case TemplateArgument::Declaration:
977 dumpDeclRef(A.getAsDecl());
979 case TemplateArgument::NullPtr:
982 case TemplateArgument::Integral:
983 OS << " integral " << A.getAsIntegral();
985 case TemplateArgument::Template:
987 A.getAsTemplate().dump(OS);
989 case TemplateArgument::TemplateExpansion:
990 OS << " template expansion";
991 A.getAsTemplateOrTemplatePattern().dump(OS);
993 case TemplateArgument::Expression:
995 dumpStmt(A.getAsExpr());
997 case TemplateArgument::Pack:
999 for (TemplateArgument::pack_iterator I = A.pack_begin(), E = A.pack_end();
1001 dumpTemplateArgument(*I);
1007 //===----------------------------------------------------------------------===//
1008 // Objective-C Utilities
1009 //===----------------------------------------------------------------------===//
1010 void ASTDumper::dumpObjCTypeParamList(const ObjCTypeParamList *typeParams) {
1014 for (auto typeParam : *typeParams) {
1015 dumpDecl(typeParam);
1019 //===----------------------------------------------------------------------===//
1020 // Decl dumping methods.
1021 //===----------------------------------------------------------------------===//
1023 void ASTDumper::dumpDecl(const Decl *D) {
1026 ColorScope Color(*this, NullColor);
1032 ColorScope Color(*this, DeclKindNameColor);
1033 OS << D->getDeclKindName() << "Decl";
1036 if (D->getLexicalDeclContext() != D->getDeclContext())
1037 OS << " parent " << cast<Decl>(D->getDeclContext());
1038 dumpPreviousDecl(OS, D);
1039 dumpSourceRange(D->getSourceRange());
1041 dumpLocation(D->getLocation());
1042 if (D->isFromASTFile())
1044 if (Module *M = D->getOwningModule())
1045 OS << " in " << M->getFullModuleName();
1046 if (auto *ND = dyn_cast<NamedDecl>(D))
1047 for (Module *M : D->getASTContext().getModulesWithMergedDefinition(
1048 const_cast<NamedDecl *>(ND)))
1049 dumpChild([=] { OS << "also in " << M->getFullModuleName(); });
1050 if (const NamedDecl *ND = dyn_cast<NamedDecl>(D))
1053 if (D->isImplicit())
1057 else if (D->isThisDeclarationReferenced())
1058 OS << " referenced";
1059 if (D->isInvalidDecl())
1061 if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
1062 if (FD->isConstexpr())
1066 ConstDeclVisitor<ASTDumper>::Visit(D);
1068 for (Decl::attr_iterator I = D->attr_begin(), E = D->attr_end(); I != E;
1072 if (const FullComment *Comment =
1073 D->getASTContext().getLocalCommentForDeclUncached(D))
1074 dumpFullComment(Comment);
1076 // Decls within functions are visited by the body.
1077 if (!isa<FunctionDecl>(*D) && !isa<ObjCMethodDecl>(*D) &&
1078 hasNodes(dyn_cast<DeclContext>(D)))
1079 dumpDeclContext(cast<DeclContext>(D));
1083 void ASTDumper::VisitLabelDecl(const LabelDecl *D) {
1087 void ASTDumper::VisitTypedefDecl(const TypedefDecl *D) {
1089 dumpType(D->getUnderlyingType());
1090 if (D->isModulePrivate())
1091 OS << " __module_private__";
1092 dumpTypeAsChild(D->getUnderlyingType());
1095 void ASTDumper::VisitEnumDecl(const EnumDecl *D) {
1096 if (D->isScoped()) {
1097 if (D->isScopedUsingClassTag())
1103 if (D->isModulePrivate())
1104 OS << " __module_private__";
1106 dumpType(D->getIntegerType());
1109 void ASTDumper::VisitRecordDecl(const RecordDecl *D) {
1110 OS << ' ' << D->getKindName();
1112 if (D->isModulePrivate())
1113 OS << " __module_private__";
1114 if (D->isCompleteDefinition())
1115 OS << " definition";
1118 void ASTDumper::VisitEnumConstantDecl(const EnumConstantDecl *D) {
1120 dumpType(D->getType());
1121 if (const Expr *Init = D->getInitExpr())
1125 void ASTDumper::VisitIndirectFieldDecl(const IndirectFieldDecl *D) {
1127 dumpType(D->getType());
1129 for (auto *Child : D->chain())
1133 void ASTDumper::VisitFunctionDecl(const FunctionDecl *D) {
1135 dumpType(D->getType());
1137 StorageClass SC = D->getStorageClass();
1139 OS << ' ' << VarDecl::getStorageClassSpecifierString(SC);
1140 if (D->isInlineSpecified())
1142 if (D->isVirtualAsWritten())
1144 if (D->isModulePrivate())
1145 OS << " __module_private__";
1149 if (D->isDefaulted()) {
1154 if (D->isDeletedAsWritten())
1159 if (const FunctionProtoType *FPT = D->getType()->getAs<FunctionProtoType>()) {
1160 FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo();
1161 switch (EPI.ExceptionSpec.Type) {
1163 case EST_Unevaluated:
1164 OS << " noexcept-unevaluated " << EPI.ExceptionSpec.SourceDecl;
1166 case EST_Uninstantiated:
1167 OS << " noexcept-uninstantiated " << EPI.ExceptionSpec.SourceTemplate;
1172 if (const FunctionTemplateSpecializationInfo *FTSI =
1173 D->getTemplateSpecializationInfo())
1174 dumpTemplateArgumentList(*FTSI->TemplateArguments);
1176 if (!D->param_begin() && D->getNumParams())
1177 dumpChild([=] { OS << "<<NULL params x " << D->getNumParams() << ">>"; });
1179 for (const ParmVarDecl *Parameter : D->parameters())
1180 dumpDecl(Parameter);
1182 if (const CXXConstructorDecl *C = dyn_cast<CXXConstructorDecl>(D))
1183 for (CXXConstructorDecl::init_const_iterator I = C->init_begin(),
1186 dumpCXXCtorInitializer(*I);
1188 if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(D)) {
1189 if (MD->size_overridden_methods() != 0) {
1191 [=](const CXXMethodDecl *D) {
1192 SplitQualType T_split = D->getType().split();
1193 OS << D << " " << D->getParent()->getName() << "::"
1194 << D->getNameAsString() << " '" << QualType::getAsString(T_split) << "'";
1198 auto Overrides = MD->overridden_methods();
1199 OS << "Overrides: [ ";
1200 dumpOverride(*Overrides.begin());
1201 for (const auto *Override :
1202 llvm::make_range(Overrides.begin() + 1, Overrides.end())) {
1204 dumpOverride(Override);
1211 if (D->doesThisDeclarationHaveABody())
1212 dumpStmt(D->getBody());
1215 void ASTDumper::VisitFieldDecl(const FieldDecl *D) {
1217 dumpType(D->getType());
1220 if (D->isModulePrivate())
1221 OS << " __module_private__";
1223 if (D->isBitField())
1224 dumpStmt(D->getBitWidth());
1225 if (Expr *Init = D->getInClassInitializer())
1229 void ASTDumper::VisitVarDecl(const VarDecl *D) {
1231 dumpType(D->getType());
1232 StorageClass SC = D->getStorageClass();
1234 OS << ' ' << VarDecl::getStorageClassSpecifierString(SC);
1235 switch (D->getTLSKind()) {
1236 case VarDecl::TLS_None: break;
1237 case VarDecl::TLS_Static: OS << " tls"; break;
1238 case VarDecl::TLS_Dynamic: OS << " tls_dynamic"; break;
1240 if (D->isModulePrivate())
1241 OS << " __module_private__";
1242 if (D->isNRVOVariable())
1246 if (D->isConstexpr())
1249 switch (D->getInitStyle()) {
1250 case VarDecl::CInit: OS << " cinit"; break;
1251 case VarDecl::CallInit: OS << " callinit"; break;
1252 case VarDecl::ListInit: OS << " listinit"; break;
1254 dumpStmt(D->getInit());
1258 void ASTDumper::VisitDecompositionDecl(const DecompositionDecl *D) {
1260 for (auto *B : D->bindings())
1264 void ASTDumper::VisitBindingDecl(const BindingDecl *D) {
1266 dumpType(D->getType());
1267 if (auto *E = D->getBinding())
1271 void ASTDumper::VisitFileScopeAsmDecl(const FileScopeAsmDecl *D) {
1272 dumpStmt(D->getAsmString());
1275 void ASTDumper::VisitImportDecl(const ImportDecl *D) {
1276 OS << ' ' << D->getImportedModule()->getFullModuleName();
1279 void ASTDumper::VisitPragmaCommentDecl(const PragmaCommentDecl *D) {
1281 switch (D->getCommentKind()) {
1282 case PCK_Unknown: llvm_unreachable("unexpected pragma comment kind");
1283 case PCK_Compiler: OS << "compiler"; break;
1284 case PCK_ExeStr: OS << "exestr"; break;
1285 case PCK_Lib: OS << "lib"; break;
1286 case PCK_Linker: OS << "linker"; break;
1287 case PCK_User: OS << "user"; break;
1289 StringRef Arg = D->getArg();
1291 OS << " \"" << Arg << "\"";
1294 void ASTDumper::VisitPragmaDetectMismatchDecl(
1295 const PragmaDetectMismatchDecl *D) {
1296 OS << " \"" << D->getName() << "\" \"" << D->getValue() << "\"";
1299 void ASTDumper::VisitCapturedDecl(const CapturedDecl *D) {
1300 dumpStmt(D->getBody());
1303 //===----------------------------------------------------------------------===//
1304 // OpenMP Declarations
1305 //===----------------------------------------------------------------------===//
1307 void ASTDumper::VisitOMPThreadPrivateDecl(const OMPThreadPrivateDecl *D) {
1308 for (auto *E : D->varlists())
1312 void ASTDumper::VisitOMPDeclareReductionDecl(const OMPDeclareReductionDecl *D) {
1314 dumpType(D->getType());
1316 dumpStmt(D->getCombiner());
1317 if (auto *Initializer = D->getInitializer()) {
1318 OS << " initializer";
1319 switch (D->getInitializerKind()) {
1320 case OMPDeclareReductionDecl::DirectInit:
1321 OS << " omp_priv = ";
1323 case OMPDeclareReductionDecl::CopyInit:
1324 OS << " omp_priv ()";
1326 case OMPDeclareReductionDecl::CallInit:
1329 dumpStmt(Initializer);
1333 void ASTDumper::VisitOMPCapturedExprDecl(const OMPCapturedExprDecl *D) {
1335 dumpType(D->getType());
1336 dumpStmt(D->getInit());
1339 //===----------------------------------------------------------------------===//
1341 //===----------------------------------------------------------------------===//
1343 void ASTDumper::VisitNamespaceDecl(const NamespaceDecl *D) {
1347 if (!D->isOriginalNamespace())
1348 dumpDeclRef(D->getOriginalNamespace(), "original");
1351 void ASTDumper::VisitUsingDirectiveDecl(const UsingDirectiveDecl *D) {
1353 dumpBareDeclRef(D->getNominatedNamespace());
1356 void ASTDumper::VisitNamespaceAliasDecl(const NamespaceAliasDecl *D) {
1358 dumpDeclRef(D->getAliasedNamespace());
1361 void ASTDumper::VisitTypeAliasDecl(const TypeAliasDecl *D) {
1363 dumpType(D->getUnderlyingType());
1364 dumpTypeAsChild(D->getUnderlyingType());
1367 void ASTDumper::VisitTypeAliasTemplateDecl(const TypeAliasTemplateDecl *D) {
1369 dumpTemplateParameters(D->getTemplateParameters());
1370 dumpDecl(D->getTemplatedDecl());
1373 void ASTDumper::VisitCXXRecordDecl(const CXXRecordDecl *D) {
1375 if (!D->isCompleteDefinition())
1380 ColorScope Color(*this, DeclKindNameColor);
1381 OS << "DefinitionData";
1383 #define FLAG(fn, name) if (D->fn()) OS << " " #name;
1384 FLAG(isParsingBaseSpecifiers, parsing_base_specifiers);
1386 FLAG(isGenericLambda, generic);
1387 FLAG(isLambda, lambda);
1389 FLAG(canPassInRegisters, pass_in_registers);
1390 FLAG(isEmpty, empty);
1391 FLAG(isAggregate, aggregate);
1392 FLAG(isStandardLayout, standard_layout);
1393 FLAG(isTriviallyCopyable, trivially_copyable);
1395 FLAG(isTrivial, trivial);
1396 FLAG(isPolymorphic, polymorphic);
1397 FLAG(isAbstract, abstract);
1398 FLAG(isLiteral, literal);
1400 FLAG(hasUserDeclaredConstructor, has_user_declared_ctor);
1401 FLAG(hasConstexprNonCopyMoveConstructor, has_constexpr_non_copy_move_ctor);
1402 FLAG(hasMutableFields, has_mutable_fields);
1403 FLAG(hasVariantMembers, has_variant_members);
1404 FLAG(allowConstDefaultInit, can_const_default_init);
1408 ColorScope Color(*this, DeclKindNameColor);
1409 OS << "DefaultConstructor";
1411 FLAG(hasDefaultConstructor, exists);
1412 FLAG(hasTrivialDefaultConstructor, trivial);
1413 FLAG(hasNonTrivialDefaultConstructor, non_trivial);
1414 FLAG(hasUserProvidedDefaultConstructor, user_provided);
1415 FLAG(hasConstexprDefaultConstructor, constexpr);
1416 FLAG(needsImplicitDefaultConstructor, needs_implicit);
1417 FLAG(defaultedDefaultConstructorIsConstexpr, defaulted_is_constexpr);
1422 ColorScope Color(*this, DeclKindNameColor);
1423 OS << "CopyConstructor";
1425 FLAG(hasSimpleCopyConstructor, simple);
1426 FLAG(hasTrivialCopyConstructor, trivial);
1427 FLAG(hasNonTrivialCopyConstructor, non_trivial);
1428 FLAG(hasUserDeclaredCopyConstructor, user_declared);
1429 FLAG(hasCopyConstructorWithConstParam, has_const_param);
1430 FLAG(needsImplicitCopyConstructor, needs_implicit);
1431 FLAG(needsOverloadResolutionForCopyConstructor,
1432 needs_overload_resolution);
1433 if (!D->needsOverloadResolutionForCopyConstructor())
1434 FLAG(defaultedCopyConstructorIsDeleted, defaulted_is_deleted);
1435 FLAG(implicitCopyConstructorHasConstParam, implicit_has_const_param);
1440 ColorScope Color(*this, DeclKindNameColor);
1441 OS << "MoveConstructor";
1443 FLAG(hasMoveConstructor, exists);
1444 FLAG(hasSimpleMoveConstructor, simple);
1445 FLAG(hasTrivialMoveConstructor, trivial);
1446 FLAG(hasNonTrivialMoveConstructor, non_trivial);
1447 FLAG(hasUserDeclaredMoveConstructor, user_declared);
1448 FLAG(needsImplicitMoveConstructor, needs_implicit);
1449 FLAG(needsOverloadResolutionForMoveConstructor,
1450 needs_overload_resolution);
1451 if (!D->needsOverloadResolutionForMoveConstructor())
1452 FLAG(defaultedMoveConstructorIsDeleted, defaulted_is_deleted);
1457 ColorScope Color(*this, DeclKindNameColor);
1458 OS << "CopyAssignment";
1460 FLAG(hasTrivialCopyAssignment, trivial);
1461 FLAG(hasNonTrivialCopyAssignment, non_trivial);
1462 FLAG(hasCopyAssignmentWithConstParam, has_const_param);
1463 FLAG(hasUserDeclaredCopyAssignment, user_declared);
1464 FLAG(needsImplicitCopyAssignment, needs_implicit);
1465 FLAG(needsOverloadResolutionForCopyAssignment, needs_overload_resolution);
1466 FLAG(implicitCopyAssignmentHasConstParam, implicit_has_const_param);
1471 ColorScope Color(*this, DeclKindNameColor);
1472 OS << "MoveAssignment";
1474 FLAG(hasMoveAssignment, exists);
1475 FLAG(hasSimpleMoveAssignment, simple);
1476 FLAG(hasTrivialMoveAssignment, trivial);
1477 FLAG(hasNonTrivialMoveAssignment, non_trivial);
1478 FLAG(hasUserDeclaredMoveAssignment, user_declared);
1479 FLAG(needsImplicitMoveAssignment, needs_implicit);
1480 FLAG(needsOverloadResolutionForMoveAssignment, needs_overload_resolution);
1485 ColorScope Color(*this, DeclKindNameColor);
1488 FLAG(hasSimpleDestructor, simple);
1489 FLAG(hasIrrelevantDestructor, irrelevant);
1490 FLAG(hasTrivialDestructor, trivial);
1491 FLAG(hasNonTrivialDestructor, non_trivial);
1492 FLAG(hasUserDeclaredDestructor, user_declared);
1493 FLAG(needsImplicitDestructor, needs_implicit);
1494 FLAG(needsOverloadResolutionForDestructor, needs_overload_resolution);
1495 if (!D->needsOverloadResolutionForDestructor())
1496 FLAG(defaultedDestructorIsDeleted, defaulted_is_deleted);
1500 for (const auto &I : D->bases()) {
1504 dumpAccessSpecifier(I.getAccessSpecifier());
1505 dumpType(I.getType());
1506 if (I.isPackExpansion())
1512 void ASTDumper::VisitStaticAssertDecl(const StaticAssertDecl *D) {
1513 dumpStmt(D->getAssertExpr());
1514 dumpStmt(D->getMessage());
1517 template<typename SpecializationDecl>
1518 void ASTDumper::VisitTemplateDeclSpecialization(const SpecializationDecl *D,
1519 bool DumpExplicitInst,
1521 bool DumpedAny = false;
1522 for (auto *RedeclWithBadType : D->redecls()) {
1523 // FIXME: The redecls() range sometimes has elements of a less-specific
1524 // type. (In particular, ClassTemplateSpecializationDecl::redecls() gives
1525 // us TagDecls, and should give CXXRecordDecls).
1526 auto *Redecl = dyn_cast<SpecializationDecl>(RedeclWithBadType);
1528 // Found the injected-class-name for a class template. This will be dumped
1529 // as part of its surrounding class so we don't need to dump it here.
1530 assert(isa<CXXRecordDecl>(RedeclWithBadType) &&
1531 "expected an injected-class-name");
1535 switch (Redecl->getTemplateSpecializationKind()) {
1536 case TSK_ExplicitInstantiationDeclaration:
1537 case TSK_ExplicitInstantiationDefinition:
1538 if (!DumpExplicitInst)
1541 case TSK_Undeclared:
1542 case TSK_ImplicitInstantiation:
1544 dumpDeclRef(Redecl);
1549 case TSK_ExplicitSpecialization:
1554 // Ensure we dump at least one decl for each specialization.
1559 template<typename TemplateDecl>
1560 void ASTDumper::VisitTemplateDecl(const TemplateDecl *D,
1561 bool DumpExplicitInst) {
1563 dumpTemplateParameters(D->getTemplateParameters());
1565 dumpDecl(D->getTemplatedDecl());
1567 for (auto *Child : D->specializations())
1568 VisitTemplateDeclSpecialization(Child, DumpExplicitInst,
1569 !D->isCanonicalDecl());
1572 void ASTDumper::VisitFunctionTemplateDecl(const FunctionTemplateDecl *D) {
1573 // FIXME: We don't add a declaration of a function template specialization
1574 // to its context when it's explicitly instantiated, so dump explicit
1575 // instantiations when we dump the template itself.
1576 VisitTemplateDecl(D, true);
1579 void ASTDumper::VisitClassTemplateDecl(const ClassTemplateDecl *D) {
1580 VisitTemplateDecl(D, false);
1583 void ASTDumper::VisitClassTemplateSpecializationDecl(
1584 const ClassTemplateSpecializationDecl *D) {
1585 VisitCXXRecordDecl(D);
1586 dumpTemplateArgumentList(D->getTemplateArgs());
1589 void ASTDumper::VisitClassTemplatePartialSpecializationDecl(
1590 const ClassTemplatePartialSpecializationDecl *D) {
1591 VisitClassTemplateSpecializationDecl(D);
1592 dumpTemplateParameters(D->getTemplateParameters());
1595 void ASTDumper::VisitClassScopeFunctionSpecializationDecl(
1596 const ClassScopeFunctionSpecializationDecl *D) {
1597 dumpDeclRef(D->getSpecialization());
1598 if (D->hasExplicitTemplateArgs())
1599 dumpTemplateArgumentListInfo(D->templateArgs());
1602 void ASTDumper::VisitVarTemplateDecl(const VarTemplateDecl *D) {
1603 VisitTemplateDecl(D, false);
1606 void ASTDumper::VisitBuiltinTemplateDecl(const BuiltinTemplateDecl *D) {
1608 dumpTemplateParameters(D->getTemplateParameters());
1611 void ASTDumper::VisitVarTemplateSpecializationDecl(
1612 const VarTemplateSpecializationDecl *D) {
1613 dumpTemplateArgumentList(D->getTemplateArgs());
1617 void ASTDumper::VisitVarTemplatePartialSpecializationDecl(
1618 const VarTemplatePartialSpecializationDecl *D) {
1619 dumpTemplateParameters(D->getTemplateParameters());
1620 VisitVarTemplateSpecializationDecl(D);
1623 void ASTDumper::VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D) {
1624 if (D->wasDeclaredWithTypename())
1628 OS << " depth " << D->getDepth() << " index " << D->getIndex();
1629 if (D->isParameterPack())
1632 if (D->hasDefaultArgument())
1633 dumpTemplateArgument(D->getDefaultArgument());
1636 void ASTDumper::VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D) {
1637 dumpType(D->getType());
1638 OS << " depth " << D->getDepth() << " index " << D->getIndex();
1639 if (D->isParameterPack())
1642 if (D->hasDefaultArgument())
1643 dumpTemplateArgument(D->getDefaultArgument());
1646 void ASTDumper::VisitTemplateTemplateParmDecl(
1647 const TemplateTemplateParmDecl *D) {
1648 OS << " depth " << D->getDepth() << " index " << D->getIndex();
1649 if (D->isParameterPack())
1652 dumpTemplateParameters(D->getTemplateParameters());
1653 if (D->hasDefaultArgument())
1654 dumpTemplateArgumentLoc(D->getDefaultArgument());
1657 void ASTDumper::VisitUsingDecl(const UsingDecl *D) {
1659 if (D->getQualifier())
1660 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
1661 OS << D->getNameAsString();
1664 void ASTDumper::VisitUnresolvedUsingTypenameDecl(
1665 const UnresolvedUsingTypenameDecl *D) {
1667 if (D->getQualifier())
1668 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
1669 OS << D->getNameAsString();
1672 void ASTDumper::VisitUnresolvedUsingValueDecl(const UnresolvedUsingValueDecl *D) {
1674 if (D->getQualifier())
1675 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy());
1676 OS << D->getNameAsString();
1677 dumpType(D->getType());
1680 void ASTDumper::VisitUsingShadowDecl(const UsingShadowDecl *D) {
1682 dumpBareDeclRef(D->getTargetDecl());
1683 if (auto *TD = dyn_cast<TypeDecl>(D->getUnderlyingDecl()))
1684 dumpTypeAsChild(TD->getTypeForDecl());
1687 void ASTDumper::VisitConstructorUsingShadowDecl(
1688 const ConstructorUsingShadowDecl *D) {
1689 if (D->constructsVirtualBase())
1694 dumpBareDeclRef(D->getTargetDecl());
1699 dumpBareDeclRef(D->getNominatedBaseClass());
1701 dumpBareDeclRef(D->getNominatedBaseClassShadowDecl());
1705 OS << "constructed ";
1706 dumpBareDeclRef(D->getConstructedBaseClass());
1708 dumpBareDeclRef(D->getConstructedBaseClassShadowDecl());
1712 void ASTDumper::VisitLinkageSpecDecl(const LinkageSpecDecl *D) {
1713 switch (D->getLanguage()) {
1714 case LinkageSpecDecl::lang_c: OS << " C"; break;
1715 case LinkageSpecDecl::lang_cxx: OS << " C++"; break;
1719 void ASTDumper::VisitAccessSpecDecl(const AccessSpecDecl *D) {
1721 dumpAccessSpecifier(D->getAccess());
1724 void ASTDumper::VisitFriendDecl(const FriendDecl *D) {
1725 if (TypeSourceInfo *T = D->getFriendType())
1726 dumpType(T->getType());
1728 dumpDecl(D->getFriendDecl());
1731 //===----------------------------------------------------------------------===//
1732 // Obj-C Declarations
1733 //===----------------------------------------------------------------------===//
1735 void ASTDumper::VisitObjCIvarDecl(const ObjCIvarDecl *D) {
1737 dumpType(D->getType());
1738 if (D->getSynthesize())
1739 OS << " synthesize";
1741 switch (D->getAccessControl()) {
1742 case ObjCIvarDecl::None:
1745 case ObjCIvarDecl::Private:
1748 case ObjCIvarDecl::Protected:
1751 case ObjCIvarDecl::Public:
1754 case ObjCIvarDecl::Package:
1760 void ASTDumper::VisitObjCMethodDecl(const ObjCMethodDecl *D) {
1761 if (D->isInstanceMethod())
1766 dumpType(D->getReturnType());
1768 if (D->isThisDeclarationADefinition()) {
1771 for (const ParmVarDecl *Parameter : D->parameters())
1772 dumpDecl(Parameter);
1775 if (D->isVariadic())
1776 dumpChild([=] { OS << "..."; });
1779 dumpStmt(D->getBody());
1782 void ASTDumper::VisitObjCTypeParamDecl(const ObjCTypeParamDecl *D) {
1784 switch (D->getVariance()) {
1785 case ObjCTypeParamVariance::Invariant:
1788 case ObjCTypeParamVariance::Covariant:
1792 case ObjCTypeParamVariance::Contravariant:
1793 OS << " contravariant";
1797 if (D->hasExplicitBound())
1799 dumpType(D->getUnderlyingType());
1802 void ASTDumper::VisitObjCCategoryDecl(const ObjCCategoryDecl *D) {
1804 dumpDeclRef(D->getClassInterface());
1805 dumpObjCTypeParamList(D->getTypeParamList());
1806 dumpDeclRef(D->getImplementation());
1807 for (ObjCCategoryDecl::protocol_iterator I = D->protocol_begin(),
1808 E = D->protocol_end();
1813 void ASTDumper::VisitObjCCategoryImplDecl(const ObjCCategoryImplDecl *D) {
1815 dumpDeclRef(D->getClassInterface());
1816 dumpDeclRef(D->getCategoryDecl());
1819 void ASTDumper::VisitObjCProtocolDecl(const ObjCProtocolDecl *D) {
1822 for (auto *Child : D->protocols())
1826 void ASTDumper::VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D) {
1828 dumpObjCTypeParamList(D->getTypeParamListAsWritten());
1829 dumpDeclRef(D->getSuperClass(), "super");
1831 dumpDeclRef(D->getImplementation());
1832 for (auto *Child : D->protocols())
1836 void ASTDumper::VisitObjCImplementationDecl(const ObjCImplementationDecl *D) {
1838 dumpDeclRef(D->getSuperClass(), "super");
1839 dumpDeclRef(D->getClassInterface());
1840 for (ObjCImplementationDecl::init_const_iterator I = D->init_begin(),
1843 dumpCXXCtorInitializer(*I);
1846 void ASTDumper::VisitObjCCompatibleAliasDecl(const ObjCCompatibleAliasDecl *D) {
1848 dumpDeclRef(D->getClassInterface());
1851 void ASTDumper::VisitObjCPropertyDecl(const ObjCPropertyDecl *D) {
1853 dumpType(D->getType());
1855 if (D->getPropertyImplementation() == ObjCPropertyDecl::Required)
1857 else if (D->getPropertyImplementation() == ObjCPropertyDecl::Optional)
1860 ObjCPropertyDecl::PropertyAttributeKind Attrs = D->getPropertyAttributes();
1861 if (Attrs != ObjCPropertyDecl::OBJC_PR_noattr) {
1862 if (Attrs & ObjCPropertyDecl::OBJC_PR_readonly)
1864 if (Attrs & ObjCPropertyDecl::OBJC_PR_assign)
1866 if (Attrs & ObjCPropertyDecl::OBJC_PR_readwrite)
1868 if (Attrs & ObjCPropertyDecl::OBJC_PR_retain)
1870 if (Attrs & ObjCPropertyDecl::OBJC_PR_copy)
1872 if (Attrs & ObjCPropertyDecl::OBJC_PR_nonatomic)
1874 if (Attrs & ObjCPropertyDecl::OBJC_PR_atomic)
1876 if (Attrs & ObjCPropertyDecl::OBJC_PR_weak)
1878 if (Attrs & ObjCPropertyDecl::OBJC_PR_strong)
1880 if (Attrs & ObjCPropertyDecl::OBJC_PR_unsafe_unretained)
1881 OS << " unsafe_unretained";
1882 if (Attrs & ObjCPropertyDecl::OBJC_PR_class)
1884 if (Attrs & ObjCPropertyDecl::OBJC_PR_getter)
1885 dumpDeclRef(D->getGetterMethodDecl(), "getter");
1886 if (Attrs & ObjCPropertyDecl::OBJC_PR_setter)
1887 dumpDeclRef(D->getSetterMethodDecl(), "setter");
1891 void ASTDumper::VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D) {
1892 dumpName(D->getPropertyDecl());
1893 if (D->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize)
1894 OS << " synthesize";
1897 dumpDeclRef(D->getPropertyDecl());
1898 dumpDeclRef(D->getPropertyIvarDecl());
1901 void ASTDumper::VisitBlockDecl(const BlockDecl *D) {
1902 for (auto I : D->parameters())
1905 if (D->isVariadic())
1906 dumpChild([=]{ OS << "..."; });
1908 if (D->capturesCXXThis())
1909 dumpChild([=]{ OS << "capture this"; });
1911 for (const auto &I : D->captures()) {
1918 if (I.getVariable()) {
1920 dumpBareDeclRef(I.getVariable());
1922 if (I.hasCopyExpr())
1923 dumpStmt(I.getCopyExpr());
1926 dumpStmt(D->getBody());
1929 //===----------------------------------------------------------------------===//
1930 // Stmt dumping methods.
1931 //===----------------------------------------------------------------------===//
1933 void ASTDumper::dumpStmt(const Stmt *S) {
1936 ColorScope Color(*this, NullColor);
1941 if (const DeclStmt *DS = dyn_cast<DeclStmt>(S)) {
1946 ConstStmtVisitor<ASTDumper>::Visit(S);
1948 for (const Stmt *SubStmt : S->children())
1953 void ASTDumper::VisitStmt(const Stmt *Node) {
1955 ColorScope Color(*this, StmtColor);
1956 OS << Node->getStmtClassName();
1959 dumpSourceRange(Node->getSourceRange());
1962 void ASTDumper::VisitDeclStmt(const DeclStmt *Node) {
1964 for (DeclStmt::const_decl_iterator I = Node->decl_begin(),
1965 E = Node->decl_end();
1970 void ASTDumper::VisitAttributedStmt(const AttributedStmt *Node) {
1972 for (ArrayRef<const Attr *>::iterator I = Node->getAttrs().begin(),
1973 E = Node->getAttrs().end();
1978 void ASTDumper::VisitLabelStmt(const LabelStmt *Node) {
1980 OS << " '" << Node->getName() << "'";
1983 void ASTDumper::VisitGotoStmt(const GotoStmt *Node) {
1985 OS << " '" << Node->getLabel()->getName() << "'";
1986 dumpPointer(Node->getLabel());
1989 void ASTDumper::VisitCXXCatchStmt(const CXXCatchStmt *Node) {
1991 dumpDecl(Node->getExceptionDecl());
1994 void ASTDumper::VisitCapturedStmt(const CapturedStmt *Node) {
1996 dumpDecl(Node->getCapturedDecl());
1999 //===----------------------------------------------------------------------===//
2000 // OpenMP dumping methods.
2001 //===----------------------------------------------------------------------===//
2003 void ASTDumper::VisitOMPExecutableDirective(
2004 const OMPExecutableDirective *Node) {
2006 for (auto *C : Node->clauses()) {
2009 ColorScope Color(*this, NullColor);
2010 OS << "<<<NULL>>> OMPClause";
2014 ColorScope Color(*this, AttrColor);
2015 StringRef ClauseName(getOpenMPClauseName(C->getClauseKind()));
2016 OS << "OMP" << ClauseName.substr(/*Start=*/0, /*N=*/1).upper()
2017 << ClauseName.drop_front() << "Clause";
2020 dumpSourceRange(SourceRange(C->getLocStart(), C->getLocEnd()));
2021 if (C->isImplicit())
2022 OS << " <implicit>";
2023 for (auto *S : C->children())
2029 //===----------------------------------------------------------------------===//
2030 // Expr dumping methods.
2031 //===----------------------------------------------------------------------===//
2033 void ASTDumper::VisitExpr(const Expr *Node) {
2035 dumpType(Node->getType());
2038 ColorScope Color(*this, ValueKindColor);
2039 switch (Node->getValueKind()) {
2052 ColorScope Color(*this, ObjectKindColor);
2053 switch (Node->getObjectKind()) {
2059 case OK_ObjCProperty:
2060 OS << " objcproperty";
2062 case OK_ObjCSubscript:
2063 OS << " objcsubscript";
2065 case OK_VectorComponent:
2066 OS << " vectorcomponent";
2072 static void dumpBasePath(raw_ostream &OS, const CastExpr *Node) {
2073 if (Node->path_empty())
2078 for (CastExpr::path_const_iterator I = Node->path_begin(),
2079 E = Node->path_end();
2081 const CXXBaseSpecifier *Base = *I;
2085 const CXXRecordDecl *RD =
2086 cast<CXXRecordDecl>(Base->getType()->getAs<RecordType>()->getDecl());
2088 if (Base->isVirtual())
2090 OS << RD->getName();
2097 void ASTDumper::VisitCastExpr(const CastExpr *Node) {
2101 ColorScope Color(*this, CastColor);
2102 OS << Node->getCastKindName();
2104 dumpBasePath(OS, Node);
2108 void ASTDumper::VisitDeclRefExpr(const DeclRefExpr *Node) {
2112 dumpBareDeclRef(Node->getDecl());
2113 if (Node->getDecl() != Node->getFoundDecl()) {
2115 dumpBareDeclRef(Node->getFoundDecl());
2120 void ASTDumper::VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *Node) {
2123 if (!Node->requiresADL())
2125 OS << "ADL) = '" << Node->getName() << '\'';
2127 UnresolvedLookupExpr::decls_iterator
2128 I = Node->decls_begin(), E = Node->decls_end();
2135 void ASTDumper::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *Node) {
2139 ColorScope Color(*this, DeclKindNameColor);
2140 OS << " " << Node->getDecl()->getDeclKindName() << "Decl";
2142 OS << "='" << *Node->getDecl() << "'";
2143 dumpPointer(Node->getDecl());
2144 if (Node->isFreeIvar())
2145 OS << " isFreeIvar";
2148 void ASTDumper::VisitPredefinedExpr(const PredefinedExpr *Node) {
2150 OS << " " << PredefinedExpr::getIdentTypeName(Node->getIdentType());
2153 void ASTDumper::VisitCharacterLiteral(const CharacterLiteral *Node) {
2155 ColorScope Color(*this, ValueColor);
2156 OS << " " << Node->getValue();
2159 void ASTDumper::VisitIntegerLiteral(const IntegerLiteral *Node) {
2162 bool isSigned = Node->getType()->isSignedIntegerType();
2163 ColorScope Color(*this, ValueColor);
2164 OS << " " << Node->getValue().toString(10, isSigned);
2167 void ASTDumper::VisitFloatingLiteral(const FloatingLiteral *Node) {
2169 ColorScope Color(*this, ValueColor);
2170 OS << " " << Node->getValueAsApproximateDouble();
2173 void ASTDumper::VisitStringLiteral(const StringLiteral *Str) {
2175 ColorScope Color(*this, ValueColor);
2177 Str->outputString(OS);
2180 void ASTDumper::VisitInitListExpr(const InitListExpr *ILE) {
2182 if (auto *Filler = ILE->getArrayFiller()) {
2184 OS << "array filler";
2188 if (auto *Field = ILE->getInitializedFieldInUnion()) {
2190 dumpBareDeclRef(Field);
2194 void ASTDumper::VisitArrayInitLoopExpr(const ArrayInitLoopExpr *E) {
2198 void ASTDumper::VisitArrayInitIndexExpr(const ArrayInitIndexExpr *E) {
2202 void ASTDumper::VisitUnaryOperator(const UnaryOperator *Node) {
2204 OS << " " << (Node->isPostfix() ? "postfix" : "prefix")
2205 << " '" << UnaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
2208 void ASTDumper::VisitUnaryExprOrTypeTraitExpr(
2209 const UnaryExprOrTypeTraitExpr *Node) {
2211 switch(Node->getKind()) {
2221 case UETT_OpenMPRequiredSimdAlign:
2222 OS << " __builtin_omp_required_simd_align";
2225 if (Node->isArgumentType())
2226 dumpType(Node->getArgumentType());
2229 void ASTDumper::VisitMemberExpr(const MemberExpr *Node) {
2231 OS << " " << (Node->isArrow() ? "->" : ".") << *Node->getMemberDecl();
2232 dumpPointer(Node->getMemberDecl());
2235 void ASTDumper::VisitExtVectorElementExpr(const ExtVectorElementExpr *Node) {
2237 OS << " " << Node->getAccessor().getNameStart();
2240 void ASTDumper::VisitBinaryOperator(const BinaryOperator *Node) {
2242 OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
2245 void ASTDumper::VisitCompoundAssignOperator(
2246 const CompoundAssignOperator *Node) {
2248 OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode())
2249 << "' ComputeLHSTy=";
2250 dumpBareType(Node->getComputationLHSType());
2251 OS << " ComputeResultTy=";
2252 dumpBareType(Node->getComputationResultType());
2255 void ASTDumper::VisitBlockExpr(const BlockExpr *Node) {
2257 dumpDecl(Node->getBlockDecl());
2260 void ASTDumper::VisitOpaqueValueExpr(const OpaqueValueExpr *Node) {
2263 if (Expr *Source = Node->getSourceExpr())
2269 void ASTDumper::VisitAddrLabelExpr(const AddrLabelExpr *Node) {
2271 OS << " " << Node->getLabel()->getName();
2272 dumpPointer(Node->getLabel());
2275 //===----------------------------------------------------------------------===//
2277 //===----------------------------------------------------------------------===//
2279 void ASTDumper::VisitCXXNamedCastExpr(const CXXNamedCastExpr *Node) {
2281 OS << " " << Node->getCastName()
2282 << "<" << Node->getTypeAsWritten().getAsString() << ">"
2283 << " <" << Node->getCastKindName();
2284 dumpBasePath(OS, Node);
2288 void ASTDumper::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *Node) {
2290 OS << " " << (Node->getValue() ? "true" : "false");
2293 void ASTDumper::VisitCXXThisExpr(const CXXThisExpr *Node) {
2298 void ASTDumper::VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *Node) {
2300 OS << " functional cast to " << Node->getTypeAsWritten().getAsString()
2301 << " <" << Node->getCastKindName() << ">";
2304 void ASTDumper::VisitCXXUnresolvedConstructExpr(
2305 const CXXUnresolvedConstructExpr *Node) {
2307 dumpType(Node->getTypeAsWritten());
2308 if (Node->isListInitialization())
2312 void ASTDumper::VisitCXXConstructExpr(const CXXConstructExpr *Node) {
2314 CXXConstructorDecl *Ctor = Node->getConstructor();
2315 dumpType(Ctor->getType());
2316 if (Node->isElidable())
2318 if (Node->isListInitialization())
2320 if (Node->isStdInitListInitialization())
2321 OS << " std::initializer_list";
2322 if (Node->requiresZeroInitialization())
2326 void ASTDumper::VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *Node) {
2329 dumpCXXTemporary(Node->getTemporary());
2332 void ASTDumper::VisitCXXNewExpr(const CXXNewExpr *Node) {
2334 if (Node->isGlobalNew())
2336 if (Node->isArray())
2338 if (Node->getOperatorNew()) {
2340 dumpBareDeclRef(Node->getOperatorNew());
2342 // We could dump the deallocation function used in case of error, but it's
2343 // usually not that interesting.
2346 void ASTDumper::VisitCXXDeleteExpr(const CXXDeleteExpr *Node) {
2348 if (Node->isGlobalDelete())
2350 if (Node->isArrayForm())
2352 if (Node->getOperatorDelete()) {
2354 dumpBareDeclRef(Node->getOperatorDelete());
2359 ASTDumper::VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *Node) {
2361 if (const ValueDecl *VD = Node->getExtendingDecl()) {
2362 OS << " extended by ";
2363 dumpBareDeclRef(VD);
2367 void ASTDumper::VisitExprWithCleanups(const ExprWithCleanups *Node) {
2369 for (unsigned i = 0, e = Node->getNumObjects(); i != e; ++i)
2370 dumpDeclRef(Node->getObject(i), "cleanup");
2373 void ASTDumper::dumpCXXTemporary(const CXXTemporary *Temporary) {
2374 OS << "(CXXTemporary";
2375 dumpPointer(Temporary);
2379 void ASTDumper::VisitSizeOfPackExpr(const SizeOfPackExpr *Node) {
2381 dumpPointer(Node->getPack());
2382 dumpName(Node->getPack());
2383 if (Node->isPartiallySubstituted())
2384 for (const auto &A : Node->getPartialArguments())
2385 dumpTemplateArgument(A);
2388 void ASTDumper::VisitCXXDependentScopeMemberExpr(
2389 const CXXDependentScopeMemberExpr *Node) {
2391 OS << " " << (Node->isArrow() ? "->" : ".") << Node->getMember();
2394 //===----------------------------------------------------------------------===//
2395 // Obj-C Expressions
2396 //===----------------------------------------------------------------------===//
2398 void ASTDumper::VisitObjCMessageExpr(const ObjCMessageExpr *Node) {
2401 Node->getSelector().print(OS);
2402 switch (Node->getReceiverKind()) {
2403 case ObjCMessageExpr::Instance:
2406 case ObjCMessageExpr::Class:
2408 dumpBareType(Node->getClassReceiver());
2411 case ObjCMessageExpr::SuperInstance:
2412 OS << " super (instance)";
2415 case ObjCMessageExpr::SuperClass:
2416 OS << " super (class)";
2421 void ASTDumper::VisitObjCBoxedExpr(const ObjCBoxedExpr *Node) {
2423 if (auto *BoxingMethod = Node->getBoxingMethod()) {
2425 BoxingMethod->getSelector().print(OS);
2429 void ASTDumper::VisitObjCAtCatchStmt(const ObjCAtCatchStmt *Node) {
2431 if (const VarDecl *CatchParam = Node->getCatchParamDecl())
2432 dumpDecl(CatchParam);
2437 void ASTDumper::VisitObjCEncodeExpr(const ObjCEncodeExpr *Node) {
2439 dumpType(Node->getEncodedType());
2442 void ASTDumper::VisitObjCSelectorExpr(const ObjCSelectorExpr *Node) {
2446 Node->getSelector().print(OS);
2449 void ASTDumper::VisitObjCProtocolExpr(const ObjCProtocolExpr *Node) {
2452 OS << ' ' << *Node->getProtocol();
2455 void ASTDumper::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *Node) {
2457 if (Node->isImplicitProperty()) {
2458 OS << " Kind=MethodRef Getter=\"";
2459 if (Node->getImplicitPropertyGetter())
2460 Node->getImplicitPropertyGetter()->getSelector().print(OS);
2464 OS << "\" Setter=\"";
2465 if (ObjCMethodDecl *Setter = Node->getImplicitPropertySetter())
2466 Setter->getSelector().print(OS);
2471 OS << " Kind=PropertyRef Property=\"" << *Node->getExplicitProperty() <<'"';
2474 if (Node->isSuperReceiver())
2477 OS << " Messaging=";
2478 if (Node->isMessagingGetter() && Node->isMessagingSetter())
2479 OS << "Getter&Setter";
2480 else if (Node->isMessagingGetter())
2482 else if (Node->isMessagingSetter())
2486 void ASTDumper::VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *Node) {
2488 if (Node->isArraySubscriptRefExpr())
2489 OS << " Kind=ArraySubscript GetterForArray=\"";
2491 OS << " Kind=DictionarySubscript GetterForDictionary=\"";
2492 if (Node->getAtIndexMethodDecl())
2493 Node->getAtIndexMethodDecl()->getSelector().print(OS);
2497 if (Node->isArraySubscriptRefExpr())
2498 OS << "\" SetterForArray=\"";
2500 OS << "\" SetterForDictionary=\"";
2501 if (Node->setAtIndexMethodDecl())
2502 Node->setAtIndexMethodDecl()->getSelector().print(OS);
2507 void ASTDumper::VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *Node) {
2509 OS << " " << (Node->getValue() ? "__objc_yes" : "__objc_no");
2512 //===----------------------------------------------------------------------===//
2514 //===----------------------------------------------------------------------===//
2516 const char *ASTDumper::getCommandName(unsigned CommandID) {
2518 return Traits->getCommandInfo(CommandID)->Name;
2519 const CommandInfo *Info = CommandTraits::getBuiltinCommandInfo(CommandID);
2522 return "<not a builtin command>";
2525 void ASTDumper::dumpFullComment(const FullComment *C) {
2534 void ASTDumper::dumpComment(const Comment *C) {
2537 ColorScope Color(*this, NullColor);
2543 ColorScope Color(*this, CommentColor);
2544 OS << C->getCommentKindName();
2547 dumpSourceRange(C->getSourceRange());
2548 ConstCommentVisitor<ASTDumper>::visit(C);
2549 for (Comment::child_iterator I = C->child_begin(), E = C->child_end();
2555 void ASTDumper::visitTextComment(const TextComment *C) {
2556 OS << " Text=\"" << C->getText() << "\"";
2559 void ASTDumper::visitInlineCommandComment(const InlineCommandComment *C) {
2560 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\"";
2561 switch (C->getRenderKind()) {
2562 case InlineCommandComment::RenderNormal:
2563 OS << " RenderNormal";
2565 case InlineCommandComment::RenderBold:
2566 OS << " RenderBold";
2568 case InlineCommandComment::RenderMonospaced:
2569 OS << " RenderMonospaced";
2571 case InlineCommandComment::RenderEmphasized:
2572 OS << " RenderEmphasized";
2576 for (unsigned i = 0, e = C->getNumArgs(); i != e; ++i)
2577 OS << " Arg[" << i << "]=\"" << C->getArgText(i) << "\"";
2580 void ASTDumper::visitHTMLStartTagComment(const HTMLStartTagComment *C) {
2581 OS << " Name=\"" << C->getTagName() << "\"";
2582 if (C->getNumAttrs() != 0) {
2584 for (unsigned i = 0, e = C->getNumAttrs(); i != e; ++i) {
2585 const HTMLStartTagComment::Attribute &Attr = C->getAttr(i);
2586 OS << " \"" << Attr.Name << "=\"" << Attr.Value << "\"";
2589 if (C->isSelfClosing())
2590 OS << " SelfClosing";
2593 void ASTDumper::visitHTMLEndTagComment(const HTMLEndTagComment *C) {
2594 OS << " Name=\"" << C->getTagName() << "\"";
2597 void ASTDumper::visitBlockCommandComment(const BlockCommandComment *C) {
2598 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\"";
2599 for (unsigned i = 0, e = C->getNumArgs(); i != e; ++i)
2600 OS << " Arg[" << i << "]=\"" << C->getArgText(i) << "\"";
2603 void ASTDumper::visitParamCommandComment(const ParamCommandComment *C) {
2604 OS << " " << ParamCommandComment::getDirectionAsString(C->getDirection());
2606 if (C->isDirectionExplicit())
2607 OS << " explicitly";
2609 OS << " implicitly";
2611 if (C->hasParamName()) {
2612 if (C->isParamIndexValid())
2613 OS << " Param=\"" << C->getParamName(FC) << "\"";
2615 OS << " Param=\"" << C->getParamNameAsWritten() << "\"";
2618 if (C->isParamIndexValid() && !C->isVarArgParam())
2619 OS << " ParamIndex=" << C->getParamIndex();
2622 void ASTDumper::visitTParamCommandComment(const TParamCommandComment *C) {
2623 if (C->hasParamName()) {
2624 if (C->isPositionValid())
2625 OS << " Param=\"" << C->getParamName(FC) << "\"";
2627 OS << " Param=\"" << C->getParamNameAsWritten() << "\"";
2630 if (C->isPositionValid()) {
2631 OS << " Position=<";
2632 for (unsigned i = 0, e = C->getDepth(); i != e; ++i) {
2633 OS << C->getIndex(i);
2641 void ASTDumper::visitVerbatimBlockComment(const VerbatimBlockComment *C) {
2642 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\""
2643 " CloseName=\"" << C->getCloseName() << "\"";
2646 void ASTDumper::visitVerbatimBlockLineComment(
2647 const VerbatimBlockLineComment *C) {
2648 OS << " Text=\"" << C->getText() << "\"";
2651 void ASTDumper::visitVerbatimLineComment(const VerbatimLineComment *C) {
2652 OS << " Text=\"" << C->getText() << "\"";
2655 //===----------------------------------------------------------------------===//
2656 // Type method implementations
2657 //===----------------------------------------------------------------------===//
2659 void QualType::dump(const char *msg) const {
2661 llvm::errs() << msg << ": ";
2665 LLVM_DUMP_METHOD void QualType::dump() const { dump(llvm::errs()); }
2667 LLVM_DUMP_METHOD void QualType::dump(llvm::raw_ostream &OS) const {
2668 ASTDumper Dumper(OS, nullptr, nullptr);
2669 Dumper.dumpTypeAsChild(*this);
2672 LLVM_DUMP_METHOD void Type::dump() const { dump(llvm::errs()); }
2674 LLVM_DUMP_METHOD void Type::dump(llvm::raw_ostream &OS) const {
2675 QualType(this, 0).dump(OS);
2678 //===----------------------------------------------------------------------===//
2679 // Decl method implementations
2680 //===----------------------------------------------------------------------===//
2682 LLVM_DUMP_METHOD void Decl::dump() const { dump(llvm::errs()); }
2684 LLVM_DUMP_METHOD void Decl::dump(raw_ostream &OS, bool Deserialize) const {
2685 ASTDumper P(OS, &getASTContext().getCommentCommandTraits(),
2686 &getASTContext().getSourceManager());
2687 P.setDeserialize(Deserialize);
2691 LLVM_DUMP_METHOD void Decl::dumpColor() const {
2692 ASTDumper P(llvm::errs(), &getASTContext().getCommentCommandTraits(),
2693 &getASTContext().getSourceManager(), /*ShowColors*/true);
2697 LLVM_DUMP_METHOD void DeclContext::dumpLookups() const {
2698 dumpLookups(llvm::errs());
2701 LLVM_DUMP_METHOD void DeclContext::dumpLookups(raw_ostream &OS,
2703 bool Deserialize) const {
2704 const DeclContext *DC = this;
2705 while (!DC->isTranslationUnit())
2706 DC = DC->getParent();
2707 ASTContext &Ctx = cast<TranslationUnitDecl>(DC)->getASTContext();
2708 ASTDumper P(OS, &Ctx.getCommentCommandTraits(), &Ctx.getSourceManager());
2709 P.setDeserialize(Deserialize);
2710 P.dumpLookups(this, DumpDecls);
2713 //===----------------------------------------------------------------------===//
2714 // Stmt method implementations
2715 //===----------------------------------------------------------------------===//
2717 LLVM_DUMP_METHOD void Stmt::dump(SourceManager &SM) const {
2718 dump(llvm::errs(), SM);
2721 LLVM_DUMP_METHOD void Stmt::dump(raw_ostream &OS, SourceManager &SM) const {
2722 ASTDumper P(OS, nullptr, &SM);
2726 LLVM_DUMP_METHOD void Stmt::dump(raw_ostream &OS) const {
2727 ASTDumper P(OS, nullptr, nullptr);
2731 LLVM_DUMP_METHOD void Stmt::dump() const {
2732 ASTDumper P(llvm::errs(), nullptr, nullptr);
2736 LLVM_DUMP_METHOD void Stmt::dumpColor() const {
2737 ASTDumper P(llvm::errs(), nullptr, nullptr, /*ShowColors*/true);
2741 //===----------------------------------------------------------------------===//
2742 // Comment method implementations
2743 //===----------------------------------------------------------------------===//
2745 LLVM_DUMP_METHOD void Comment::dump() const {
2746 dump(llvm::errs(), nullptr, nullptr);
2749 LLVM_DUMP_METHOD void Comment::dump(const ASTContext &Context) const {
2750 dump(llvm::errs(), &Context.getCommentCommandTraits(),
2751 &Context.getSourceManager());
2754 void Comment::dump(raw_ostream &OS, const CommandTraits *Traits,
2755 const SourceManager *SM) const {
2756 const FullComment *FC = dyn_cast<FullComment>(this);
2757 ASTDumper D(OS, Traits, SM);
2758 D.dumpFullComment(FC);
2761 LLVM_DUMP_METHOD void Comment::dumpColor() const {
2762 const FullComment *FC = dyn_cast<FullComment>(this);
2763 ASTDumper D(llvm::errs(), nullptr, nullptr, /*ShowColors*/true);
2764 D.dumpFullComment(FC);