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/DeclVisitor.h"
22 #include "clang/AST/StmtVisitor.h"
23 #include "clang/AST/TypeVisitor.h"
24 #include "clang/Basic/Module.h"
25 #include "clang/Basic/SourceManager.h"
26 #include "llvm/Support/raw_ostream.h"
27 using namespace clang
;
28 using namespace clang::comments
;
30 //===----------------------------------------------------------------------===//
32 //===----------------------------------------------------------------------===//
35 // Colors used for various parts of the AST dump
36 // Do not use bold yellow for any text. It is hard to read on white screens.
38 struct TerminalColor
{
39 raw_ostream::Colors Color
;
45 // Bold Green - DeclKindNameColor, UndeserializedColor
46 // Yellow - AddressColor, LocationColor
47 // Blue - CommentColor, NullColor, IndentColor
48 // Bold Blue - AttrColor
49 // Bold Magenta - StmtColor
50 // Cyan - ValueKindColor, ObjectKindColor
51 // Bold Cyan - ValueColor, DeclNameColor
53 // Decl kind names (VarDecl, FunctionDecl, etc)
54 static const TerminalColor DeclKindNameColor
= { raw_ostream::GREEN
, true };
55 // Attr names (CleanupAttr, GuardedByAttr, etc)
56 static const TerminalColor AttrColor
= { raw_ostream::BLUE
, true };
57 // Statement names (DeclStmt, ImplicitCastExpr, etc)
58 static const TerminalColor StmtColor
= { raw_ostream::MAGENTA
, true };
59 // Comment names (FullComment, ParagraphComment, TextComment, etc)
60 static const TerminalColor CommentColor
= { raw_ostream::BLUE
, false };
62 // Type names (int, float, etc, plus user defined types)
63 static const TerminalColor TypeColor
= { raw_ostream::GREEN
, false };
66 static const TerminalColor AddressColor
= { raw_ostream::YELLOW
, false };
68 static const TerminalColor LocationColor
= { raw_ostream::YELLOW
, false };
71 static const TerminalColor ValueKindColor
= { raw_ostream::CYAN
, false };
72 // bitfield/objcproperty/objcsubscript/vectorcomponent
73 static const TerminalColor ObjectKindColor
= { raw_ostream::CYAN
, false };
76 static const TerminalColor NullColor
= { raw_ostream::BLUE
, false };
78 // Undeserialized entities
79 static const TerminalColor UndeserializedColor
= { raw_ostream::GREEN
, true };
81 // CastKind from CastExpr's
82 static const TerminalColor CastColor
= { raw_ostream::RED
, false };
84 // Value of the statement
85 static const TerminalColor ValueColor
= { raw_ostream::CYAN
, true };
87 static const TerminalColor DeclNameColor
= { raw_ostream::CYAN
, true };
89 // Indents ( `, -. | )
90 static const TerminalColor IndentColor
= { raw_ostream::BLUE
, false };
93 : public ConstDeclVisitor
<ASTDumper
>, public ConstStmtVisitor
<ASTDumper
>,
94 public ConstCommentVisitor
<ASTDumper
>, public TypeVisitor
<ASTDumper
> {
96 const CommandTraits
*Traits
;
97 const SourceManager
*SM
;
99 /// Pending[i] is an action to dump an entity at level i.
100 llvm::SmallVector
<std::function
<void(bool isLastChild
)>, 32> Pending
;
102 /// Indicates whether we're at the top level.
105 /// Indicates if we're handling the first child after entering a new depth.
108 /// Prefix for currently-being-dumped entity.
111 /// Keep track of the last location we print out so that we can
112 /// print out deltas from then on out.
113 const char *LastLocFilename
;
114 unsigned LastLocLine
;
116 /// The \c FullComment parent of the comment being dumped.
117 const FullComment
*FC
;
121 /// Dump a child of the current node.
122 template<typename Fn
> void dumpChild(Fn doDumpChild
) {
123 // If we're at the top level, there's nothing interesting to do; just
128 while (!Pending
.empty()) {
129 Pending
.back()(true);
138 const FullComment
*OrigFC
= FC
;
139 auto dumpWithIndent
= [this, doDumpChild
, OrigFC
](bool isLastChild
) {
140 // Print out the appropriate tree structure and work out the prefix for
141 // children of this node. For instance:
145 // | `-C Prefix = "| "
147 // |-E Prefix = " | "
151 // Note that the first level gets no prefix.
154 ColorScope
Color(*this, IndentColor
);
155 OS
<< Prefix
<< (isLastChild
? '`' : '|') << '-';
156 this->Prefix
.push_back(isLastChild
? ' ' : '|');
157 this->Prefix
.push_back(' ');
161 unsigned Depth
= Pending
.size();
166 // If any children are left, they're the last at their nesting level.
167 // Dump those ones out now.
168 while (Depth
< Pending
.size()) {
169 Pending
.back()(true);
170 this->Pending
.pop_back();
173 // Restore the old prefix.
174 this->Prefix
.resize(Prefix
.size() - 2);
178 Pending
.push_back(std::move(dumpWithIndent
));
180 Pending
.back()(false);
181 Pending
.back() = std::move(dumpWithIndent
);
189 ColorScope(ASTDumper
&Dumper
, TerminalColor Color
)
191 if (Dumper
.ShowColors
)
192 Dumper
.OS
.changeColor(Color
.Color
, Color
.Bold
);
195 if (Dumper
.ShowColors
)
196 Dumper
.OS
.resetColor();
201 ASTDumper(raw_ostream
&OS
, const CommandTraits
*Traits
,
202 const SourceManager
*SM
)
203 : OS(OS
), Traits(Traits
), SM(SM
), TopLevel(true), FirstChild(true),
204 LastLocFilename(""), LastLocLine(~0U), FC(nullptr),
205 ShowColors(SM
&& SM
->getDiagnostics().getShowColors()) { }
207 ASTDumper(raw_ostream
&OS
, const CommandTraits
*Traits
,
208 const SourceManager
*SM
, bool ShowColors
)
209 : OS(OS
), Traits(Traits
), SM(SM
), TopLevel(true), FirstChild(true),
210 LastLocFilename(""), LastLocLine(~0U),
211 ShowColors(ShowColors
) { }
213 void dumpDecl(const Decl
*D
);
214 void dumpStmt(const Stmt
*S
);
215 void dumpFullComment(const FullComment
*C
);
218 void dumpPointer(const void *Ptr
);
219 void dumpSourceRange(SourceRange R
);
220 void dumpLocation(SourceLocation Loc
);
221 void dumpBareType(QualType T
, bool Desugar
= true);
222 void dumpType(QualType T
);
223 void dumpTypeAsChild(QualType T
);
224 void dumpTypeAsChild(const Type
*T
);
225 void dumpBareDeclRef(const Decl
*Node
);
226 void dumpDeclRef(const Decl
*Node
, const char *Label
= nullptr);
227 void dumpName(const NamedDecl
*D
);
228 bool hasNodes(const DeclContext
*DC
);
229 void dumpDeclContext(const DeclContext
*DC
);
230 void dumpLookups(const DeclContext
*DC
, bool DumpDecls
);
231 void dumpAttr(const Attr
*A
);
234 void dumpAccessSpecifier(AccessSpecifier AS
);
235 void dumpCXXCtorInitializer(const CXXCtorInitializer
*Init
);
236 void dumpTemplateParameters(const TemplateParameterList
*TPL
);
237 void dumpTemplateArgumentListInfo(const TemplateArgumentListInfo
&TALI
);
238 void dumpTemplateArgumentLoc(const TemplateArgumentLoc
&A
);
239 void dumpTemplateArgumentList(const TemplateArgumentList
&TAL
);
240 void dumpTemplateArgument(const TemplateArgument
&A
,
241 SourceRange R
= SourceRange());
244 void VisitComplexType(const ComplexType
*T
) {
245 dumpTypeAsChild(T
->getElementType());
247 void VisitPointerType(const PointerType
*T
) {
248 dumpTypeAsChild(T
->getPointeeType());
250 void VisitBlockPointerType(const BlockPointerType
*T
) {
251 dumpTypeAsChild(T
->getPointeeType());
253 void VisitReferenceType(const ReferenceType
*T
) {
254 dumpTypeAsChild(T
->getPointeeType());
256 void VisitRValueReferenceType(const ReferenceType
*T
) {
257 if (T
->isSpelledAsLValue())
258 OS
<< " written as lvalue reference";
259 VisitReferenceType(T
);
261 void VisitMemberPointerType(const MemberPointerType
*T
) {
262 dumpTypeAsChild(T
->getClass());
263 dumpTypeAsChild(T
->getPointeeType());
265 void VisitArrayType(const ArrayType
*T
) {
266 switch (T
->getSizeModifier()) {
267 case ArrayType::Normal
: break;
268 case ArrayType::Static
: OS
<< " static"; break;
269 case ArrayType::Star
: OS
<< " *"; break;
271 OS
<< " " << T
->getIndexTypeQualifiers().getAsString();
272 dumpTypeAsChild(T
->getElementType());
274 void VisitConstantArrayType(const ConstantArrayType
*T
) {
275 OS
<< " " << T
->getSize();
278 void VisitVariableArrayType(const VariableArrayType
*T
) {
280 dumpSourceRange(T
->getBracketsRange());
282 dumpStmt(T
->getSizeExpr());
284 void VisitDependentSizedArrayType(const DependentSizedArrayType
*T
) {
287 dumpSourceRange(T
->getBracketsRange());
288 dumpStmt(T
->getSizeExpr());
290 void VisitDependentSizedExtVectorType(
291 const DependentSizedExtVectorType
*T
) {
293 dumpLocation(T
->getAttributeLoc());
294 dumpTypeAsChild(T
->getElementType());
295 dumpStmt(T
->getSizeExpr());
297 void VisitVectorType(const VectorType
*T
) {
298 switch (T
->getVectorKind()) {
299 case VectorType::GenericVector
: break;
300 case VectorType::AltiVecVector
: OS
<< " altivec"; break;
301 case VectorType::AltiVecPixel
: OS
<< " altivec pixel"; break;
302 case VectorType::AltiVecBool
: OS
<< " altivec bool"; break;
303 case VectorType::NeonVector
: OS
<< " neon"; break;
304 case VectorType::NeonPolyVector
: OS
<< " neon poly"; break;
306 OS
<< " " << T
->getNumElements();
307 dumpTypeAsChild(T
->getElementType());
309 void VisitFunctionType(const FunctionType
*T
) {
310 auto EI
= T
->getExtInfo();
311 if (EI
.getNoReturn()) OS
<< " noreturn";
312 if (EI
.getProducesResult()) OS
<< " produces_result";
313 if (EI
.getHasRegParm()) OS
<< " regparm " << EI
.getRegParm();
314 OS
<< " " << FunctionType::getNameForCallConv(EI
.getCC());
315 dumpTypeAsChild(T
->getReturnType());
317 void VisitFunctionProtoType(const FunctionProtoType
*T
) {
318 auto EPI
= T
->getExtProtoInfo();
319 if (EPI
.HasTrailingReturn
) OS
<< " trailing_return";
320 if (T
->isConst()) OS
<< " const";
321 if (T
->isVolatile()) OS
<< " volatile";
322 if (T
->isRestrict()) OS
<< " restrict";
323 switch (EPI
.RefQualifier
) {
325 case RQ_LValue
: OS
<< " &"; break;
326 case RQ_RValue
: OS
<< " &&"; break;
328 // FIXME: Exception specification.
329 // FIXME: Consumed parameters.
330 VisitFunctionType(T
);
331 for (QualType PT
: T
->getParamTypes())
334 dumpChild([=] { OS
<< "..."; });
336 void VisitUnresolvedUsingType(const UnresolvedUsingType
*T
) {
337 dumpDeclRef(T
->getDecl());
339 void VisitTypedefType(const TypedefType
*T
) {
340 dumpDeclRef(T
->getDecl());
342 void VisitTypeOfExprType(const TypeOfExprType
*T
) {
343 dumpStmt(T
->getUnderlyingExpr());
345 void VisitDecltypeType(const DecltypeType
*T
) {
346 dumpStmt(T
->getUnderlyingExpr());
348 void VisitUnaryTransformType(const UnaryTransformType
*T
) {
349 switch (T
->getUTTKind()) {
350 case UnaryTransformType::EnumUnderlyingType
:
351 OS
<< " underlying_type";
354 dumpTypeAsChild(T
->getBaseType());
356 void VisitTagType(const TagType
*T
) {
357 dumpDeclRef(T
->getDecl());
359 void VisitAttributedType(const AttributedType
*T
) {
361 dumpTypeAsChild(T
->getModifiedType());
363 void VisitTemplateTypeParmType(const TemplateTypeParmType
*T
) {
364 OS
<< " depth " << T
->getDepth() << " index " << T
->getIndex();
365 if (T
->isParameterPack()) OS
<< " pack";
366 dumpDeclRef(T
->getDecl());
368 void VisitSubstTemplateTypeParmType(const SubstTemplateTypeParmType
*T
) {
369 dumpTypeAsChild(T
->getReplacedParameter());
371 void VisitSubstTemplateTypeParmPackType(
372 const SubstTemplateTypeParmPackType
*T
) {
373 dumpTypeAsChild(T
->getReplacedParameter());
374 dumpTemplateArgument(T
->getArgumentPack());
376 void VisitAutoType(const AutoType
*T
) {
377 if (T
->isDecltypeAuto()) OS
<< " decltype(auto)";
381 void VisitTemplateSpecializationType(const TemplateSpecializationType
*T
) {
382 if (T
->isTypeAlias()) OS
<< " alias";
383 OS
<< " "; T
->getTemplateName().dump(OS
);
385 dumpTemplateArgument(Arg
);
386 if (T
->isTypeAlias())
387 dumpTypeAsChild(T
->getAliasedType());
389 void VisitInjectedClassNameType(const InjectedClassNameType
*T
) {
390 dumpDeclRef(T
->getDecl());
392 void VisitObjCInterfaceType(const ObjCInterfaceType
*T
) {
393 dumpDeclRef(T
->getDecl());
395 void VisitObjCObjectPointerType(const ObjCObjectPointerType
*T
) {
396 dumpTypeAsChild(T
->getPointeeType());
398 void VisitAtomicType(const AtomicType
*T
) {
399 dumpTypeAsChild(T
->getValueType());
401 void VisitAdjustedType(const AdjustedType
*T
) {
402 dumpTypeAsChild(T
->getOriginalType());
404 void VisitPackExpansionType(const PackExpansionType
*T
) {
405 if (auto N
= T
->getNumExpansions()) OS
<< " expansions " << *N
;
407 dumpTypeAsChild(T
->getPattern());
409 // FIXME: ElaboratedType, DependentNameType,
410 // DependentTemplateSpecializationType, ObjCObjectType
413 void VisitLabelDecl(const LabelDecl
*D
);
414 void VisitTypedefDecl(const TypedefDecl
*D
);
415 void VisitEnumDecl(const EnumDecl
*D
);
416 void VisitRecordDecl(const RecordDecl
*D
);
417 void VisitEnumConstantDecl(const EnumConstantDecl
*D
);
418 void VisitIndirectFieldDecl(const IndirectFieldDecl
*D
);
419 void VisitFunctionDecl(const FunctionDecl
*D
);
420 void VisitFieldDecl(const FieldDecl
*D
);
421 void VisitVarDecl(const VarDecl
*D
);
422 void VisitFileScopeAsmDecl(const FileScopeAsmDecl
*D
);
423 void VisitImportDecl(const ImportDecl
*D
);
426 void VisitNamespaceDecl(const NamespaceDecl
*D
);
427 void VisitUsingDirectiveDecl(const UsingDirectiveDecl
*D
);
428 void VisitNamespaceAliasDecl(const NamespaceAliasDecl
*D
);
429 void VisitTypeAliasDecl(const TypeAliasDecl
*D
);
430 void VisitTypeAliasTemplateDecl(const TypeAliasTemplateDecl
*D
);
431 void VisitCXXRecordDecl(const CXXRecordDecl
*D
);
432 void VisitStaticAssertDecl(const StaticAssertDecl
*D
);
433 template<typename SpecializationDecl
>
434 void VisitTemplateDeclSpecialization(const SpecializationDecl
*D
,
435 bool DumpExplicitInst
,
437 template<typename TemplateDecl
>
438 void VisitTemplateDecl(const TemplateDecl
*D
, bool DumpExplicitInst
);
439 void VisitFunctionTemplateDecl(const FunctionTemplateDecl
*D
);
440 void VisitClassTemplateDecl(const ClassTemplateDecl
*D
);
441 void VisitClassTemplateSpecializationDecl(
442 const ClassTemplateSpecializationDecl
*D
);
443 void VisitClassTemplatePartialSpecializationDecl(
444 const ClassTemplatePartialSpecializationDecl
*D
);
445 void VisitClassScopeFunctionSpecializationDecl(
446 const ClassScopeFunctionSpecializationDecl
*D
);
447 void VisitVarTemplateDecl(const VarTemplateDecl
*D
);
448 void VisitVarTemplateSpecializationDecl(
449 const VarTemplateSpecializationDecl
*D
);
450 void VisitVarTemplatePartialSpecializationDecl(
451 const VarTemplatePartialSpecializationDecl
*D
);
452 void VisitTemplateTypeParmDecl(const TemplateTypeParmDecl
*D
);
453 void VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl
*D
);
454 void VisitTemplateTemplateParmDecl(const TemplateTemplateParmDecl
*D
);
455 void VisitUsingDecl(const UsingDecl
*D
);
456 void VisitUnresolvedUsingTypenameDecl(const UnresolvedUsingTypenameDecl
*D
);
457 void VisitUnresolvedUsingValueDecl(const UnresolvedUsingValueDecl
*D
);
458 void VisitUsingShadowDecl(const UsingShadowDecl
*D
);
459 void VisitLinkageSpecDecl(const LinkageSpecDecl
*D
);
460 void VisitAccessSpecDecl(const AccessSpecDecl
*D
);
461 void VisitFriendDecl(const FriendDecl
*D
);
464 void VisitObjCIvarDecl(const ObjCIvarDecl
*D
);
465 void VisitObjCMethodDecl(const ObjCMethodDecl
*D
);
466 void VisitObjCCategoryDecl(const ObjCCategoryDecl
*D
);
467 void VisitObjCCategoryImplDecl(const ObjCCategoryImplDecl
*D
);
468 void VisitObjCProtocolDecl(const ObjCProtocolDecl
*D
);
469 void VisitObjCInterfaceDecl(const ObjCInterfaceDecl
*D
);
470 void VisitObjCImplementationDecl(const ObjCImplementationDecl
*D
);
471 void VisitObjCCompatibleAliasDecl(const ObjCCompatibleAliasDecl
*D
);
472 void VisitObjCPropertyDecl(const ObjCPropertyDecl
*D
);
473 void VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl
*D
);
474 void VisitBlockDecl(const BlockDecl
*D
);
477 void VisitStmt(const Stmt
*Node
);
478 void VisitDeclStmt(const DeclStmt
*Node
);
479 void VisitAttributedStmt(const AttributedStmt
*Node
);
480 void VisitLabelStmt(const LabelStmt
*Node
);
481 void VisitGotoStmt(const GotoStmt
*Node
);
482 void VisitCXXCatchStmt(const CXXCatchStmt
*Node
);
485 void VisitExpr(const Expr
*Node
);
486 void VisitCastExpr(const CastExpr
*Node
);
487 void VisitDeclRefExpr(const DeclRefExpr
*Node
);
488 void VisitPredefinedExpr(const PredefinedExpr
*Node
);
489 void VisitCharacterLiteral(const CharacterLiteral
*Node
);
490 void VisitIntegerLiteral(const IntegerLiteral
*Node
);
491 void VisitFloatingLiteral(const FloatingLiteral
*Node
);
492 void VisitStringLiteral(const StringLiteral
*Str
);
493 void VisitInitListExpr(const InitListExpr
*ILE
);
494 void VisitUnaryOperator(const UnaryOperator
*Node
);
495 void VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr
*Node
);
496 void VisitMemberExpr(const MemberExpr
*Node
);
497 void VisitExtVectorElementExpr(const ExtVectorElementExpr
*Node
);
498 void VisitBinaryOperator(const BinaryOperator
*Node
);
499 void VisitCompoundAssignOperator(const CompoundAssignOperator
*Node
);
500 void VisitAddrLabelExpr(const AddrLabelExpr
*Node
);
501 void VisitBlockExpr(const BlockExpr
*Node
);
502 void VisitOpaqueValueExpr(const OpaqueValueExpr
*Node
);
505 void VisitCXXNamedCastExpr(const CXXNamedCastExpr
*Node
);
506 void VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr
*Node
);
507 void VisitCXXThisExpr(const CXXThisExpr
*Node
);
508 void VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr
*Node
);
509 void VisitCXXConstructExpr(const CXXConstructExpr
*Node
);
510 void VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr
*Node
);
511 void VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr
*Node
);
512 void VisitExprWithCleanups(const ExprWithCleanups
*Node
);
513 void VisitUnresolvedLookupExpr(const UnresolvedLookupExpr
*Node
);
514 void dumpCXXTemporary(const CXXTemporary
*Temporary
);
515 void VisitLambdaExpr(const LambdaExpr
*Node
) {
517 dumpDecl(Node
->getLambdaClass());
521 void VisitObjCAtCatchStmt(const ObjCAtCatchStmt
*Node
);
522 void VisitObjCEncodeExpr(const ObjCEncodeExpr
*Node
);
523 void VisitObjCMessageExpr(const ObjCMessageExpr
*Node
);
524 void VisitObjCBoxedExpr(const ObjCBoxedExpr
*Node
);
525 void VisitObjCSelectorExpr(const ObjCSelectorExpr
*Node
);
526 void VisitObjCProtocolExpr(const ObjCProtocolExpr
*Node
);
527 void VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr
*Node
);
528 void VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr
*Node
);
529 void VisitObjCIvarRefExpr(const ObjCIvarRefExpr
*Node
);
530 void VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr
*Node
);
533 const char *getCommandName(unsigned CommandID
);
534 void dumpComment(const Comment
*C
);
537 void visitTextComment(const TextComment
*C
);
538 void visitInlineCommandComment(const InlineCommandComment
*C
);
539 void visitHTMLStartTagComment(const HTMLStartTagComment
*C
);
540 void visitHTMLEndTagComment(const HTMLEndTagComment
*C
);
543 void visitBlockCommandComment(const BlockCommandComment
*C
);
544 void visitParamCommandComment(const ParamCommandComment
*C
);
545 void visitTParamCommandComment(const TParamCommandComment
*C
);
546 void visitVerbatimBlockComment(const VerbatimBlockComment
*C
);
547 void visitVerbatimBlockLineComment(const VerbatimBlockLineComment
*C
);
548 void visitVerbatimLineComment(const VerbatimLineComment
*C
);
552 //===----------------------------------------------------------------------===//
554 //===----------------------------------------------------------------------===//
556 void ASTDumper::dumpPointer(const void *Ptr
) {
557 ColorScope
Color(*this, AddressColor
);
561 void ASTDumper::dumpLocation(SourceLocation Loc
) {
565 ColorScope
Color(*this, LocationColor
);
566 SourceLocation SpellingLoc
= SM
->getSpellingLoc(Loc
);
568 // The general format we print out is filename:line:col, but we drop pieces
569 // that haven't changed since the last loc printed.
570 PresumedLoc PLoc
= SM
->getPresumedLoc(SpellingLoc
);
572 if (PLoc
.isInvalid()) {
573 OS
<< "<invalid sloc>";
577 if (strcmp(PLoc
.getFilename(), LastLocFilename
) != 0) {
578 OS
<< PLoc
.getFilename() << ':' << PLoc
.getLine()
579 << ':' << PLoc
.getColumn();
580 LastLocFilename
= PLoc
.getFilename();
581 LastLocLine
= PLoc
.getLine();
582 } else if (PLoc
.getLine() != LastLocLine
) {
583 OS
<< "line" << ':' << PLoc
.getLine()
584 << ':' << PLoc
.getColumn();
585 LastLocLine
= PLoc
.getLine();
587 OS
<< "col" << ':' << PLoc
.getColumn();
591 void ASTDumper::dumpSourceRange(SourceRange R
) {
592 // Can't translate locations if a SourceManager isn't available.
597 dumpLocation(R
.getBegin());
598 if (R
.getBegin() != R
.getEnd()) {
600 dumpLocation(R
.getEnd());
604 // <t2.c:123:421[blah], t2.c:412:321>
608 void ASTDumper::dumpBareType(QualType T
, bool Desugar
) {
609 ColorScope
Color(*this, TypeColor
);
611 SplitQualType T_split
= T
.split();
612 OS
<< "'" << QualType::getAsString(T_split
) << "'";
614 if (Desugar
&& !T
.isNull()) {
615 // If the type is sugared, also dump a (shallow) desugared type.
616 SplitQualType D_split
= T
.getSplitDesugaredType();
617 if (T_split
!= D_split
)
618 OS
<< ":'" << QualType::getAsString(D_split
) << "'";
622 void ASTDumper::dumpType(QualType T
) {
627 void ASTDumper::dumpTypeAsChild(QualType T
) {
628 SplitQualType SQT
= T
.split();
629 if (!SQT
.Quals
.hasQualifiers())
630 return dumpTypeAsChild(SQT
.Ty
);
634 dumpPointer(T
.getAsOpaquePtr());
636 dumpBareType(T
, false);
637 OS
<< " " << T
.split().Quals
.getAsString();
638 dumpTypeAsChild(T
.split().Ty
);
642 void ASTDumper::dumpTypeAsChild(const Type
*T
) {
645 ColorScope
Color(*this, NullColor
);
651 ColorScope
Color(*this, TypeColor
);
652 OS
<< T
->getTypeClassName() << "Type";
656 dumpBareType(QualType(T
, 0), false);
658 QualType SingleStepDesugar
=
659 T
->getLocallyUnqualifiedSingleStepDesugaredType();
660 if (SingleStepDesugar
!= QualType(T
, 0))
662 if (T
->isDependentType())
664 else if (T
->isInstantiationDependentType())
665 OS
<< " instantiation_dependent";
666 if (T
->isVariablyModifiedType())
667 OS
<< " variably_modified";
668 if (T
->containsUnexpandedParameterPack())
669 OS
<< " contains_unexpanded_pack";
673 TypeVisitor
<ASTDumper
>::Visit(T
);
675 if (SingleStepDesugar
!= QualType(T
, 0))
676 dumpTypeAsChild(SingleStepDesugar
);
680 void ASTDumper::dumpBareDeclRef(const Decl
*D
) {
682 ColorScope
Color(*this, DeclKindNameColor
);
683 OS
<< D
->getDeclKindName();
687 if (const NamedDecl
*ND
= dyn_cast
<NamedDecl
>(D
)) {
688 ColorScope
Color(*this, DeclNameColor
);
689 OS
<< " '" << ND
->getDeclName() << '\'';
692 if (const ValueDecl
*VD
= dyn_cast
<ValueDecl
>(D
))
693 dumpType(VD
->getType());
696 void ASTDumper::dumpDeclRef(const Decl
*D
, const char *Label
) {
707 void ASTDumper::dumpName(const NamedDecl
*ND
) {
708 if (ND
->getDeclName()) {
709 ColorScope
Color(*this, DeclNameColor
);
710 OS
<< ' ' << ND
->getNameAsString();
714 bool ASTDumper::hasNodes(const DeclContext
*DC
) {
718 return DC
->hasExternalLexicalStorage() ||
719 DC
->noload_decls_begin() != DC
->noload_decls_end();
722 void ASTDumper::dumpDeclContext(const DeclContext
*DC
) {
726 for (auto *D
: DC
->noload_decls())
729 if (DC
->hasExternalLexicalStorage()) {
731 ColorScope
Color(*this, UndeserializedColor
);
732 OS
<< "<undeserialized declarations>";
737 void ASTDumper::dumpLookups(const DeclContext
*DC
, bool DumpDecls
) {
739 OS
<< "StoredDeclsMap ";
740 dumpBareDeclRef(cast
<Decl
>(DC
));
742 const DeclContext
*Primary
= DC
->getPrimaryContext();
745 dumpPointer(cast
<Decl
>(Primary
));
748 bool HasUndeserializedLookups
= Primary
->hasExternalVisibleStorage();
750 DeclContext::all_lookups_iterator I
= Primary
->noload_lookups_begin(),
751 E
= Primary
->noload_lookups_end();
753 DeclarationName Name
= I
.getLookupName();
754 DeclContextLookupResult R
= *I
++;
757 OS
<< "DeclarationName ";
759 ColorScope
Color(*this, DeclNameColor
);
760 OS
<< '\'' << Name
<< '\'';
763 for (DeclContextLookupResult::iterator RI
= R
.begin(), RE
= R
.end();
766 dumpBareDeclRef(*RI
);
768 if ((*RI
)->isHidden())
771 // If requested, dump the redecl chain for this lookup.
773 // Dump earliest decl first.
774 std::function
<void(Decl
*)> DumpWithPrev
= [&](Decl
*D
) {
775 if (Decl
*Prev
= D
->getPreviousDecl())
786 if (HasUndeserializedLookups
) {
788 ColorScope
Color(*this, UndeserializedColor
);
789 OS
<< "<undeserialized lookups>";
795 void ASTDumper::dumpAttr(const Attr
*A
) {
798 ColorScope
Color(*this, AttrColor
);
800 switch (A
->getKind()) {
801 #define ATTR(X) case attr::X: OS << #X; break;
802 #include "clang/Basic/AttrList.inc"
804 llvm_unreachable("unexpected attribute kind");
809 dumpSourceRange(A
->getRange());
810 if (A
->isInherited())
814 #include "clang/AST/AttrDump.inc"
818 static void dumpPreviousDeclImpl(raw_ostream
&OS
, ...) {}
821 static void dumpPreviousDeclImpl(raw_ostream
&OS
, const Mergeable
<T
> *D
) {
822 const T
*First
= D
->getFirstDecl();
824 OS
<< " first " << First
;
828 static void dumpPreviousDeclImpl(raw_ostream
&OS
, const Redeclarable
<T
> *D
) {
829 const T
*Prev
= D
->getPreviousDecl();
831 OS
<< " prev " << Prev
;
834 /// Dump the previous declaration in the redeclaration chain for a declaration,
836 static void dumpPreviousDecl(raw_ostream
&OS
, const Decl
*D
) {
837 switch (D
->getKind()) {
838 #define DECL(DERIVED, BASE) \
839 case Decl::DERIVED: \
840 return dumpPreviousDeclImpl(OS, cast<DERIVED##Decl>(D));
841 #define ABSTRACT_DECL(DECL)
842 #include "clang/AST/DeclNodes.inc"
844 llvm_unreachable("Decl that isn't part of DeclNodes.inc!");
847 //===----------------------------------------------------------------------===//
849 //===----------------------------------------------------------------------===//
851 void ASTDumper::dumpAccessSpecifier(AccessSpecifier AS
) {
867 void ASTDumper::dumpCXXCtorInitializer(const CXXCtorInitializer
*Init
) {
869 OS
<< "CXXCtorInitializer";
870 if (Init
->isAnyMemberInitializer()) {
872 dumpBareDeclRef(Init
->getAnyMember());
873 } else if (Init
->isBaseInitializer()) {
874 dumpType(QualType(Init
->getBaseClass(), 0));
875 } else if (Init
->isDelegatingInitializer()) {
876 dumpType(Init
->getTypeSourceInfo()->getType());
878 llvm_unreachable("Unknown initializer type");
880 dumpStmt(Init
->getInit());
884 void ASTDumper::dumpTemplateParameters(const TemplateParameterList
*TPL
) {
888 for (TemplateParameterList::const_iterator I
= TPL
->begin(), E
= TPL
->end();
893 void ASTDumper::dumpTemplateArgumentListInfo(
894 const TemplateArgumentListInfo
&TALI
) {
895 for (unsigned i
= 0, e
= TALI
.size(); i
< e
; ++i
)
896 dumpTemplateArgumentLoc(TALI
[i
]);
899 void ASTDumper::dumpTemplateArgumentLoc(const TemplateArgumentLoc
&A
) {
900 dumpTemplateArgument(A
.getArgument(), A
.getSourceRange());
903 void ASTDumper::dumpTemplateArgumentList(const TemplateArgumentList
&TAL
) {
904 for (unsigned i
= 0, e
= TAL
.size(); i
< e
; ++i
)
905 dumpTemplateArgument(TAL
[i
]);
908 void ASTDumper::dumpTemplateArgument(const TemplateArgument
&A
, SourceRange R
) {
910 OS
<< "TemplateArgument";
914 switch (A
.getKind()) {
915 case TemplateArgument::Null
:
918 case TemplateArgument::Type
:
920 dumpType(A
.getAsType());
922 case TemplateArgument::Declaration
:
924 dumpDeclRef(A
.getAsDecl());
926 case TemplateArgument::NullPtr
:
929 case TemplateArgument::Integral
:
930 OS
<< " integral " << A
.getAsIntegral();
932 case TemplateArgument::Template
:
934 A
.getAsTemplate().dump(OS
);
936 case TemplateArgument::TemplateExpansion
:
937 OS
<< " template expansion";
938 A
.getAsTemplateOrTemplatePattern().dump(OS
);
940 case TemplateArgument::Expression
:
942 dumpStmt(A
.getAsExpr());
944 case TemplateArgument::Pack
:
946 for (TemplateArgument::pack_iterator I
= A
.pack_begin(), E
= A
.pack_end();
948 dumpTemplateArgument(*I
);
954 //===----------------------------------------------------------------------===//
955 // Decl dumping methods.
956 //===----------------------------------------------------------------------===//
958 void ASTDumper::dumpDecl(const Decl
*D
) {
961 ColorScope
Color(*this, NullColor
);
967 ColorScope
Color(*this, DeclKindNameColor
);
968 OS
<< D
->getDeclKindName() << "Decl";
971 if (D
->getLexicalDeclContext() != D
->getDeclContext())
972 OS
<< " parent " << cast
<Decl
>(D
->getDeclContext());
973 dumpPreviousDecl(OS
, D
);
974 dumpSourceRange(D
->getSourceRange());
976 dumpLocation(D
->getLocation());
977 if (Module
*M
= D
->getOwningModule())
978 OS
<< " in " << M
->getFullModuleName();
979 if (const NamedDecl
*ND
= dyn_cast
<NamedDecl
>(D
))
986 else if (D
->isThisDeclarationReferenced())
988 if (D
->isInvalidDecl())
990 if (const FunctionDecl
*FD
= dyn_cast
<FunctionDecl
>(D
))
991 if (FD
->isConstexpr())
995 ConstDeclVisitor
<ASTDumper
>::Visit(D
);
997 for (Decl::attr_iterator I
= D
->attr_begin(), E
= D
->attr_end(); I
!= E
;
1001 if (const FullComment
*Comment
=
1002 D
->getASTContext().getLocalCommentForDeclUncached(D
))
1003 dumpFullComment(Comment
);
1005 // Decls within functions are visited by the body.
1006 if (!isa
<FunctionDecl
>(*D
) && !isa
<ObjCMethodDecl
>(*D
) &&
1007 hasNodes(dyn_cast
<DeclContext
>(D
)))
1008 dumpDeclContext(cast
<DeclContext
>(D
));
1012 void ASTDumper::VisitLabelDecl(const LabelDecl
*D
) {
1016 void ASTDumper::VisitTypedefDecl(const TypedefDecl
*D
) {
1018 dumpType(D
->getUnderlyingType());
1019 if (D
->isModulePrivate())
1020 OS
<< " __module_private__";
1023 void ASTDumper::VisitEnumDecl(const EnumDecl
*D
) {
1024 if (D
->isScoped()) {
1025 if (D
->isScopedUsingClassTag())
1031 if (D
->isModulePrivate())
1032 OS
<< " __module_private__";
1034 dumpType(D
->getIntegerType());
1037 void ASTDumper::VisitRecordDecl(const RecordDecl
*D
) {
1038 OS
<< ' ' << D
->getKindName();
1040 if (D
->isModulePrivate())
1041 OS
<< " __module_private__";
1042 if (D
->isCompleteDefinition())
1043 OS
<< " definition";
1046 void ASTDumper::VisitEnumConstantDecl(const EnumConstantDecl
*D
) {
1048 dumpType(D
->getType());
1049 if (const Expr
*Init
= D
->getInitExpr())
1053 void ASTDumper::VisitIndirectFieldDecl(const IndirectFieldDecl
*D
) {
1055 dumpType(D
->getType());
1057 for (auto *Child
: D
->chain())
1061 void ASTDumper::VisitFunctionDecl(const FunctionDecl
*D
) {
1063 dumpType(D
->getType());
1065 StorageClass SC
= D
->getStorageClass();
1067 OS
<< ' ' << VarDecl::getStorageClassSpecifierString(SC
);
1068 if (D
->isInlineSpecified())
1070 if (D
->isVirtualAsWritten())
1072 if (D
->isModulePrivate())
1073 OS
<< " __module_private__";
1077 else if (D
->isDeletedAsWritten())
1080 if (const FunctionProtoType
*FPT
= D
->getType()->getAs
<FunctionProtoType
>()) {
1081 FunctionProtoType::ExtProtoInfo EPI
= FPT
->getExtProtoInfo();
1082 switch (EPI
.ExceptionSpec
.Type
) {
1084 case EST_Unevaluated
:
1085 OS
<< " noexcept-unevaluated " << EPI
.ExceptionSpec
.SourceDecl
;
1087 case EST_Uninstantiated
:
1088 OS
<< " noexcept-uninstantiated " << EPI
.ExceptionSpec
.SourceTemplate
;
1093 if (const FunctionTemplateSpecializationInfo
*FTSI
=
1094 D
->getTemplateSpecializationInfo())
1095 dumpTemplateArgumentList(*FTSI
->TemplateArguments
);
1097 for (ArrayRef
<NamedDecl
*>::iterator
1098 I
= D
->getDeclsInPrototypeScope().begin(),
1099 E
= D
->getDeclsInPrototypeScope().end(); I
!= E
; ++I
)
1102 for (FunctionDecl::param_const_iterator I
= D
->param_begin(),
1107 if (const CXXConstructorDecl
*C
= dyn_cast
<CXXConstructorDecl
>(D
))
1108 for (CXXConstructorDecl::init_const_iterator I
= C
->init_begin(),
1111 dumpCXXCtorInitializer(*I
);
1113 if (D
->doesThisDeclarationHaveABody())
1114 dumpStmt(D
->getBody());
1117 void ASTDumper::VisitFieldDecl(const FieldDecl
*D
) {
1119 dumpType(D
->getType());
1122 if (D
->isModulePrivate())
1123 OS
<< " __module_private__";
1125 if (D
->isBitField())
1126 dumpStmt(D
->getBitWidth());
1127 if (Expr
*Init
= D
->getInClassInitializer())
1131 void ASTDumper::VisitVarDecl(const VarDecl
*D
) {
1133 dumpType(D
->getType());
1134 StorageClass SC
= D
->getStorageClass();
1136 OS
<< ' ' << VarDecl::getStorageClassSpecifierString(SC
);
1137 switch (D
->getTLSKind()) {
1138 case VarDecl::TLS_None
: break;
1139 case VarDecl::TLS_Static
: OS
<< " tls"; break;
1140 case VarDecl::TLS_Dynamic
: OS
<< " tls_dynamic"; break;
1142 if (D
->isModulePrivate())
1143 OS
<< " __module_private__";
1144 if (D
->isNRVOVariable())
1147 switch (D
->getInitStyle()) {
1148 case VarDecl::CInit
: OS
<< " cinit"; break;
1149 case VarDecl::CallInit
: OS
<< " callinit"; break;
1150 case VarDecl::ListInit
: OS
<< " listinit"; break;
1152 dumpStmt(D
->getInit());
1156 void ASTDumper::VisitFileScopeAsmDecl(const FileScopeAsmDecl
*D
) {
1157 dumpStmt(D
->getAsmString());
1160 void ASTDumper::VisitImportDecl(const ImportDecl
*D
) {
1161 OS
<< ' ' << D
->getImportedModule()->getFullModuleName();
1164 //===----------------------------------------------------------------------===//
1166 //===----------------------------------------------------------------------===//
1168 void ASTDumper::VisitNamespaceDecl(const NamespaceDecl
*D
) {
1172 if (!D
->isOriginalNamespace())
1173 dumpDeclRef(D
->getOriginalNamespace(), "original");
1176 void ASTDumper::VisitUsingDirectiveDecl(const UsingDirectiveDecl
*D
) {
1178 dumpBareDeclRef(D
->getNominatedNamespace());
1181 void ASTDumper::VisitNamespaceAliasDecl(const NamespaceAliasDecl
*D
) {
1183 dumpDeclRef(D
->getAliasedNamespace());
1186 void ASTDumper::VisitTypeAliasDecl(const TypeAliasDecl
*D
) {
1188 dumpType(D
->getUnderlyingType());
1191 void ASTDumper::VisitTypeAliasTemplateDecl(const TypeAliasTemplateDecl
*D
) {
1193 dumpTemplateParameters(D
->getTemplateParameters());
1194 dumpDecl(D
->getTemplatedDecl());
1197 void ASTDumper::VisitCXXRecordDecl(const CXXRecordDecl
*D
) {
1199 if (!D
->isCompleteDefinition())
1202 for (const auto &I
: D
->bases()) {
1206 dumpAccessSpecifier(I
.getAccessSpecifier());
1207 dumpType(I
.getType());
1208 if (I
.isPackExpansion())
1214 void ASTDumper::VisitStaticAssertDecl(const StaticAssertDecl
*D
) {
1215 dumpStmt(D
->getAssertExpr());
1216 dumpStmt(D
->getMessage());
1219 template<typename SpecializationDecl
>
1220 void ASTDumper::VisitTemplateDeclSpecialization(const SpecializationDecl
*D
,
1221 bool DumpExplicitInst
,
1223 bool DumpedAny
= false;
1224 for (auto *RedeclWithBadType
: D
->redecls()) {
1225 // FIXME: The redecls() range sometimes has elements of a less-specific
1226 // type. (In particular, ClassTemplateSpecializationDecl::redecls() gives
1227 // us TagDecls, and should give CXXRecordDecls).
1228 auto *Redecl
= dyn_cast
<SpecializationDecl
>(RedeclWithBadType
);
1230 // Found the injected-class-name for a class template. This will be dumped
1231 // as part of its surrounding class so we don't need to dump it here.
1232 assert(isa
<CXXRecordDecl
>(RedeclWithBadType
) &&
1233 "expected an injected-class-name");
1237 switch (Redecl
->getTemplateSpecializationKind()) {
1238 case TSK_ExplicitInstantiationDeclaration
:
1239 case TSK_ExplicitInstantiationDefinition
:
1240 if (!DumpExplicitInst
)
1243 case TSK_Undeclared
:
1244 case TSK_ImplicitInstantiation
:
1246 dumpDeclRef(Redecl
);
1251 case TSK_ExplicitSpecialization
:
1256 // Ensure we dump at least one decl for each specialization.
1261 template<typename TemplateDecl
>
1262 void ASTDumper::VisitTemplateDecl(const TemplateDecl
*D
,
1263 bool DumpExplicitInst
) {
1265 dumpTemplateParameters(D
->getTemplateParameters());
1267 dumpDecl(D
->getTemplatedDecl());
1269 for (auto *Child
: D
->specializations())
1270 VisitTemplateDeclSpecialization(Child
, DumpExplicitInst
,
1271 !D
->isCanonicalDecl());
1274 void ASTDumper::VisitFunctionTemplateDecl(const FunctionTemplateDecl
*D
) {
1275 // FIXME: We don't add a declaration of a function template specialization
1276 // to its context when it's explicitly instantiated, so dump explicit
1277 // instantiations when we dump the template itself.
1278 VisitTemplateDecl(D
, true);
1281 void ASTDumper::VisitClassTemplateDecl(const ClassTemplateDecl
*D
) {
1282 VisitTemplateDecl(D
, false);
1285 void ASTDumper::VisitClassTemplateSpecializationDecl(
1286 const ClassTemplateSpecializationDecl
*D
) {
1287 VisitCXXRecordDecl(D
);
1288 dumpTemplateArgumentList(D
->getTemplateArgs());
1291 void ASTDumper::VisitClassTemplatePartialSpecializationDecl(
1292 const ClassTemplatePartialSpecializationDecl
*D
) {
1293 VisitClassTemplateSpecializationDecl(D
);
1294 dumpTemplateParameters(D
->getTemplateParameters());
1297 void ASTDumper::VisitClassScopeFunctionSpecializationDecl(
1298 const ClassScopeFunctionSpecializationDecl
*D
) {
1299 dumpDeclRef(D
->getSpecialization());
1300 if (D
->hasExplicitTemplateArgs())
1301 dumpTemplateArgumentListInfo(D
->templateArgs());
1304 void ASTDumper::VisitVarTemplateDecl(const VarTemplateDecl
*D
) {
1305 VisitTemplateDecl(D
, false);
1308 void ASTDumper::VisitVarTemplateSpecializationDecl(
1309 const VarTemplateSpecializationDecl
*D
) {
1310 dumpTemplateArgumentList(D
->getTemplateArgs());
1314 void ASTDumper::VisitVarTemplatePartialSpecializationDecl(
1315 const VarTemplatePartialSpecializationDecl
*D
) {
1316 dumpTemplateParameters(D
->getTemplateParameters());
1317 VisitVarTemplateSpecializationDecl(D
);
1320 void ASTDumper::VisitTemplateTypeParmDecl(const TemplateTypeParmDecl
*D
) {
1321 if (D
->wasDeclaredWithTypename())
1325 if (D
->isParameterPack())
1328 if (D
->hasDefaultArgument())
1329 dumpTemplateArgument(D
->getDefaultArgument());
1332 void ASTDumper::VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl
*D
) {
1333 dumpType(D
->getType());
1334 if (D
->isParameterPack())
1337 if (D
->hasDefaultArgument())
1338 dumpTemplateArgument(D
->getDefaultArgument());
1341 void ASTDumper::VisitTemplateTemplateParmDecl(
1342 const TemplateTemplateParmDecl
*D
) {
1343 if (D
->isParameterPack())
1346 dumpTemplateParameters(D
->getTemplateParameters());
1347 if (D
->hasDefaultArgument())
1348 dumpTemplateArgumentLoc(D
->getDefaultArgument());
1351 void ASTDumper::VisitUsingDecl(const UsingDecl
*D
) {
1353 D
->getQualifier()->print(OS
, D
->getASTContext().getPrintingPolicy());
1354 OS
<< D
->getNameAsString();
1357 void ASTDumper::VisitUnresolvedUsingTypenameDecl(
1358 const UnresolvedUsingTypenameDecl
*D
) {
1360 D
->getQualifier()->print(OS
, D
->getASTContext().getPrintingPolicy());
1361 OS
<< D
->getNameAsString();
1364 void ASTDumper::VisitUnresolvedUsingValueDecl(const UnresolvedUsingValueDecl
*D
) {
1366 D
->getQualifier()->print(OS
, D
->getASTContext().getPrintingPolicy());
1367 OS
<< D
->getNameAsString();
1368 dumpType(D
->getType());
1371 void ASTDumper::VisitUsingShadowDecl(const UsingShadowDecl
*D
) {
1373 dumpBareDeclRef(D
->getTargetDecl());
1376 void ASTDumper::VisitLinkageSpecDecl(const LinkageSpecDecl
*D
) {
1377 switch (D
->getLanguage()) {
1378 case LinkageSpecDecl::lang_c
: OS
<< " C"; break;
1379 case LinkageSpecDecl::lang_cxx
: OS
<< " C++"; break;
1383 void ASTDumper::VisitAccessSpecDecl(const AccessSpecDecl
*D
) {
1385 dumpAccessSpecifier(D
->getAccess());
1388 void ASTDumper::VisitFriendDecl(const FriendDecl
*D
) {
1389 if (TypeSourceInfo
*T
= D
->getFriendType())
1390 dumpType(T
->getType());
1392 dumpDecl(D
->getFriendDecl());
1395 //===----------------------------------------------------------------------===//
1396 // Obj-C Declarations
1397 //===----------------------------------------------------------------------===//
1399 void ASTDumper::VisitObjCIvarDecl(const ObjCIvarDecl
*D
) {
1401 dumpType(D
->getType());
1402 if (D
->getSynthesize())
1403 OS
<< " synthesize";
1405 switch (D
->getAccessControl()) {
1406 case ObjCIvarDecl::None
:
1409 case ObjCIvarDecl::Private
:
1412 case ObjCIvarDecl::Protected
:
1415 case ObjCIvarDecl::Public
:
1418 case ObjCIvarDecl::Package
:
1424 void ASTDumper::VisitObjCMethodDecl(const ObjCMethodDecl
*D
) {
1425 if (D
->isInstanceMethod())
1430 dumpType(D
->getReturnType());
1432 if (D
->isThisDeclarationADefinition()) {
1435 for (ObjCMethodDecl::param_const_iterator I
= D
->param_begin(),
1441 if (D
->isVariadic())
1442 dumpChild([=] { OS
<< "..."; });
1445 dumpStmt(D
->getBody());
1448 void ASTDumper::VisitObjCCategoryDecl(const ObjCCategoryDecl
*D
) {
1450 dumpDeclRef(D
->getClassInterface());
1451 dumpDeclRef(D
->getImplementation());
1452 for (ObjCCategoryDecl::protocol_iterator I
= D
->protocol_begin(),
1453 E
= D
->protocol_end();
1458 void ASTDumper::VisitObjCCategoryImplDecl(const ObjCCategoryImplDecl
*D
) {
1460 dumpDeclRef(D
->getClassInterface());
1461 dumpDeclRef(D
->getCategoryDecl());
1464 void ASTDumper::VisitObjCProtocolDecl(const ObjCProtocolDecl
*D
) {
1467 for (auto *Child
: D
->protocols())
1471 void ASTDumper::VisitObjCInterfaceDecl(const ObjCInterfaceDecl
*D
) {
1473 dumpDeclRef(D
->getSuperClass(), "super");
1475 dumpDeclRef(D
->getImplementation());
1476 for (auto *Child
: D
->protocols())
1480 void ASTDumper::VisitObjCImplementationDecl(const ObjCImplementationDecl
*D
) {
1482 dumpDeclRef(D
->getSuperClass(), "super");
1483 dumpDeclRef(D
->getClassInterface());
1484 for (ObjCImplementationDecl::init_const_iterator I
= D
->init_begin(),
1487 dumpCXXCtorInitializer(*I
);
1490 void ASTDumper::VisitObjCCompatibleAliasDecl(const ObjCCompatibleAliasDecl
*D
) {
1492 dumpDeclRef(D
->getClassInterface());
1495 void ASTDumper::VisitObjCPropertyDecl(const ObjCPropertyDecl
*D
) {
1497 dumpType(D
->getType());
1499 if (D
->getPropertyImplementation() == ObjCPropertyDecl::Required
)
1501 else if (D
->getPropertyImplementation() == ObjCPropertyDecl::Optional
)
1504 ObjCPropertyDecl::PropertyAttributeKind Attrs
= D
->getPropertyAttributes();
1505 if (Attrs
!= ObjCPropertyDecl::OBJC_PR_noattr
) {
1506 if (Attrs
& ObjCPropertyDecl::OBJC_PR_readonly
)
1508 if (Attrs
& ObjCPropertyDecl::OBJC_PR_assign
)
1510 if (Attrs
& ObjCPropertyDecl::OBJC_PR_readwrite
)
1512 if (Attrs
& ObjCPropertyDecl::OBJC_PR_retain
)
1514 if (Attrs
& ObjCPropertyDecl::OBJC_PR_copy
)
1516 if (Attrs
& ObjCPropertyDecl::OBJC_PR_nonatomic
)
1518 if (Attrs
& ObjCPropertyDecl::OBJC_PR_atomic
)
1520 if (Attrs
& ObjCPropertyDecl::OBJC_PR_weak
)
1522 if (Attrs
& ObjCPropertyDecl::OBJC_PR_strong
)
1524 if (Attrs
& ObjCPropertyDecl::OBJC_PR_unsafe_unretained
)
1525 OS
<< " unsafe_unretained";
1526 if (Attrs
& ObjCPropertyDecl::OBJC_PR_getter
)
1527 dumpDeclRef(D
->getGetterMethodDecl(), "getter");
1528 if (Attrs
& ObjCPropertyDecl::OBJC_PR_setter
)
1529 dumpDeclRef(D
->getSetterMethodDecl(), "setter");
1533 void ASTDumper::VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl
*D
) {
1534 dumpName(D
->getPropertyDecl());
1535 if (D
->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize
)
1536 OS
<< " synthesize";
1539 dumpDeclRef(D
->getPropertyDecl());
1540 dumpDeclRef(D
->getPropertyIvarDecl());
1543 void ASTDumper::VisitBlockDecl(const BlockDecl
*D
) {
1544 for (auto I
: D
->params())
1547 if (D
->isVariadic())
1548 dumpChild([=]{ OS
<< "..."; });
1550 if (D
->capturesCXXThis())
1551 dumpChild([=]{ OS
<< "capture this"; });
1553 for (const auto &I
: D
->captures()) {
1560 if (I
.getVariable()) {
1562 dumpBareDeclRef(I
.getVariable());
1564 if (I
.hasCopyExpr())
1565 dumpStmt(I
.getCopyExpr());
1568 dumpStmt(D
->getBody());
1571 //===----------------------------------------------------------------------===//
1572 // Stmt dumping methods.
1573 //===----------------------------------------------------------------------===//
1575 void ASTDumper::dumpStmt(const Stmt
*S
) {
1578 ColorScope
Color(*this, NullColor
);
1583 if (const DeclStmt
*DS
= dyn_cast
<DeclStmt
>(S
)) {
1588 ConstStmtVisitor
<ASTDumper
>::Visit(S
);
1590 for (Stmt::const_child_range CI
= S
->children(); CI
; ++CI
)
1595 void ASTDumper::VisitStmt(const Stmt
*Node
) {
1597 ColorScope
Color(*this, StmtColor
);
1598 OS
<< Node
->getStmtClassName();
1601 dumpSourceRange(Node
->getSourceRange());
1604 void ASTDumper::VisitDeclStmt(const DeclStmt
*Node
) {
1606 for (DeclStmt::const_decl_iterator I
= Node
->decl_begin(),
1607 E
= Node
->decl_end();
1612 void ASTDumper::VisitAttributedStmt(const AttributedStmt
*Node
) {
1614 for (ArrayRef
<const Attr
*>::iterator I
= Node
->getAttrs().begin(),
1615 E
= Node
->getAttrs().end();
1620 void ASTDumper::VisitLabelStmt(const LabelStmt
*Node
) {
1622 OS
<< " '" << Node
->getName() << "'";
1625 void ASTDumper::VisitGotoStmt(const GotoStmt
*Node
) {
1627 OS
<< " '" << Node
->getLabel()->getName() << "'";
1628 dumpPointer(Node
->getLabel());
1631 void ASTDumper::VisitCXXCatchStmt(const CXXCatchStmt
*Node
) {
1633 dumpDecl(Node
->getExceptionDecl());
1636 //===----------------------------------------------------------------------===//
1637 // Expr dumping methods.
1638 //===----------------------------------------------------------------------===//
1640 void ASTDumper::VisitExpr(const Expr
*Node
) {
1642 dumpType(Node
->getType());
1645 ColorScope
Color(*this, ValueKindColor
);
1646 switch (Node
->getValueKind()) {
1659 ColorScope
Color(*this, ObjectKindColor
);
1660 switch (Node
->getObjectKind()) {
1666 case OK_ObjCProperty
:
1667 OS
<< " objcproperty";
1669 case OK_ObjCSubscript
:
1670 OS
<< " objcsubscript";
1672 case OK_VectorComponent
:
1673 OS
<< " vectorcomponent";
1679 static void dumpBasePath(raw_ostream
&OS
, const CastExpr
*Node
) {
1680 if (Node
->path_empty())
1685 for (CastExpr::path_const_iterator I
= Node
->path_begin(),
1686 E
= Node
->path_end();
1688 const CXXBaseSpecifier
*Base
= *I
;
1692 const CXXRecordDecl
*RD
=
1693 cast
<CXXRecordDecl
>(Base
->getType()->getAs
<RecordType
>()->getDecl());
1695 if (Base
->isVirtual())
1697 OS
<< RD
->getName();
1704 void ASTDumper::VisitCastExpr(const CastExpr
*Node
) {
1708 ColorScope
Color(*this, CastColor
);
1709 OS
<< Node
->getCastKindName();
1711 dumpBasePath(OS
, Node
);
1715 void ASTDumper::VisitDeclRefExpr(const DeclRefExpr
*Node
) {
1719 dumpBareDeclRef(Node
->getDecl());
1720 if (Node
->getDecl() != Node
->getFoundDecl()) {
1722 dumpBareDeclRef(Node
->getFoundDecl());
1727 void ASTDumper::VisitUnresolvedLookupExpr(const UnresolvedLookupExpr
*Node
) {
1730 if (!Node
->requiresADL())
1732 OS
<< "ADL) = '" << Node
->getName() << '\'';
1734 UnresolvedLookupExpr::decls_iterator
1735 I
= Node
->decls_begin(), E
= Node
->decls_end();
1742 void ASTDumper::VisitObjCIvarRefExpr(const ObjCIvarRefExpr
*Node
) {
1746 ColorScope
Color(*this, DeclKindNameColor
);
1747 OS
<< " " << Node
->getDecl()->getDeclKindName() << "Decl";
1749 OS
<< "='" << *Node
->getDecl() << "'";
1750 dumpPointer(Node
->getDecl());
1751 if (Node
->isFreeIvar())
1752 OS
<< " isFreeIvar";
1755 void ASTDumper::VisitPredefinedExpr(const PredefinedExpr
*Node
) {
1757 OS
<< " " << PredefinedExpr::getIdentTypeName(Node
->getIdentType());
1760 void ASTDumper::VisitCharacterLiteral(const CharacterLiteral
*Node
) {
1762 ColorScope
Color(*this, ValueColor
);
1763 OS
<< " " << Node
->getValue();
1766 void ASTDumper::VisitIntegerLiteral(const IntegerLiteral
*Node
) {
1769 bool isSigned
= Node
->getType()->isSignedIntegerType();
1770 ColorScope
Color(*this, ValueColor
);
1771 OS
<< " " << Node
->getValue().toString(10, isSigned
);
1774 void ASTDumper::VisitFloatingLiteral(const FloatingLiteral
*Node
) {
1776 ColorScope
Color(*this, ValueColor
);
1777 OS
<< " " << Node
->getValueAsApproximateDouble();
1780 void ASTDumper::VisitStringLiteral(const StringLiteral
*Str
) {
1782 ColorScope
Color(*this, ValueColor
);
1784 Str
->outputString(OS
);
1787 void ASTDumper::VisitInitListExpr(const InitListExpr
*ILE
) {
1789 if (auto *Filler
= ILE
->getArrayFiller()) {
1791 OS
<< "array filler";
1795 if (auto *Field
= ILE
->getInitializedFieldInUnion()) {
1797 dumpBareDeclRef(Field
);
1801 void ASTDumper::VisitUnaryOperator(const UnaryOperator
*Node
) {
1803 OS
<< " " << (Node
->isPostfix() ? "postfix" : "prefix")
1804 << " '" << UnaryOperator::getOpcodeStr(Node
->getOpcode()) << "'";
1807 void ASTDumper::VisitUnaryExprOrTypeTraitExpr(
1808 const UnaryExprOrTypeTraitExpr
*Node
) {
1810 switch(Node
->getKind()) {
1821 if (Node
->isArgumentType())
1822 dumpType(Node
->getArgumentType());
1825 void ASTDumper::VisitMemberExpr(const MemberExpr
*Node
) {
1827 OS
<< " " << (Node
->isArrow() ? "->" : ".") << *Node
->getMemberDecl();
1828 dumpPointer(Node
->getMemberDecl());
1831 void ASTDumper::VisitExtVectorElementExpr(const ExtVectorElementExpr
*Node
) {
1833 OS
<< " " << Node
->getAccessor().getNameStart();
1836 void ASTDumper::VisitBinaryOperator(const BinaryOperator
*Node
) {
1838 OS
<< " '" << BinaryOperator::getOpcodeStr(Node
->getOpcode()) << "'";
1841 void ASTDumper::VisitCompoundAssignOperator(
1842 const CompoundAssignOperator
*Node
) {
1844 OS
<< " '" << BinaryOperator::getOpcodeStr(Node
->getOpcode())
1845 << "' ComputeLHSTy=";
1846 dumpBareType(Node
->getComputationLHSType());
1847 OS
<< " ComputeResultTy=";
1848 dumpBareType(Node
->getComputationResultType());
1851 void ASTDumper::VisitBlockExpr(const BlockExpr
*Node
) {
1853 dumpDecl(Node
->getBlockDecl());
1856 void ASTDumper::VisitOpaqueValueExpr(const OpaqueValueExpr
*Node
) {
1859 if (Expr
*Source
= Node
->getSourceExpr())
1865 void ASTDumper::VisitAddrLabelExpr(const AddrLabelExpr
*Node
) {
1867 OS
<< " " << Node
->getLabel()->getName();
1868 dumpPointer(Node
->getLabel());
1871 //===----------------------------------------------------------------------===//
1873 //===----------------------------------------------------------------------===//
1875 void ASTDumper::VisitCXXNamedCastExpr(const CXXNamedCastExpr
*Node
) {
1877 OS
<< " " << Node
->getCastName()
1878 << "<" << Node
->getTypeAsWritten().getAsString() << ">"
1879 << " <" << Node
->getCastKindName();
1880 dumpBasePath(OS
, Node
);
1884 void ASTDumper::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr
*Node
) {
1886 OS
<< " " << (Node
->getValue() ? "true" : "false");
1889 void ASTDumper::VisitCXXThisExpr(const CXXThisExpr
*Node
) {
1894 void ASTDumper::VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr
*Node
) {
1896 OS
<< " functional cast to " << Node
->getTypeAsWritten().getAsString()
1897 << " <" << Node
->getCastKindName() << ">";
1900 void ASTDumper::VisitCXXConstructExpr(const CXXConstructExpr
*Node
) {
1902 CXXConstructorDecl
*Ctor
= Node
->getConstructor();
1903 dumpType(Ctor
->getType());
1904 if (Node
->isElidable())
1906 if (Node
->requiresZeroInitialization())
1910 void ASTDumper::VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr
*Node
) {
1913 dumpCXXTemporary(Node
->getTemporary());
1917 ASTDumper::VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr
*Node
) {
1919 if (const ValueDecl
*VD
= Node
->getExtendingDecl()) {
1920 OS
<< " extended by ";
1921 dumpBareDeclRef(VD
);
1925 void ASTDumper::VisitExprWithCleanups(const ExprWithCleanups
*Node
) {
1927 for (unsigned i
= 0, e
= Node
->getNumObjects(); i
!= e
; ++i
)
1928 dumpDeclRef(Node
->getObject(i
), "cleanup");
1931 void ASTDumper::dumpCXXTemporary(const CXXTemporary
*Temporary
) {
1932 OS
<< "(CXXTemporary";
1933 dumpPointer(Temporary
);
1937 //===----------------------------------------------------------------------===//
1938 // Obj-C Expressions
1939 //===----------------------------------------------------------------------===//
1941 void ASTDumper::VisitObjCMessageExpr(const ObjCMessageExpr
*Node
) {
1944 Node
->getSelector().print(OS
);
1945 switch (Node
->getReceiverKind()) {
1946 case ObjCMessageExpr::Instance
:
1949 case ObjCMessageExpr::Class
:
1951 dumpBareType(Node
->getClassReceiver());
1954 case ObjCMessageExpr::SuperInstance
:
1955 OS
<< " super (instance)";
1958 case ObjCMessageExpr::SuperClass
:
1959 OS
<< " super (class)";
1964 void ASTDumper::VisitObjCBoxedExpr(const ObjCBoxedExpr
*Node
) {
1967 Node
->getBoxingMethod()->getSelector().print(OS
);
1970 void ASTDumper::VisitObjCAtCatchStmt(const ObjCAtCatchStmt
*Node
) {
1972 if (const VarDecl
*CatchParam
= Node
->getCatchParamDecl())
1973 dumpDecl(CatchParam
);
1978 void ASTDumper::VisitObjCEncodeExpr(const ObjCEncodeExpr
*Node
) {
1980 dumpType(Node
->getEncodedType());
1983 void ASTDumper::VisitObjCSelectorExpr(const ObjCSelectorExpr
*Node
) {
1987 Node
->getSelector().print(OS
);
1990 void ASTDumper::VisitObjCProtocolExpr(const ObjCProtocolExpr
*Node
) {
1993 OS
<< ' ' << *Node
->getProtocol();
1996 void ASTDumper::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr
*Node
) {
1998 if (Node
->isImplicitProperty()) {
1999 OS
<< " Kind=MethodRef Getter=\"";
2000 if (Node
->getImplicitPropertyGetter())
2001 Node
->getImplicitPropertyGetter()->getSelector().print(OS
);
2005 OS
<< "\" Setter=\"";
2006 if (ObjCMethodDecl
*Setter
= Node
->getImplicitPropertySetter())
2007 Setter
->getSelector().print(OS
);
2012 OS
<< " Kind=PropertyRef Property=\"" << *Node
->getExplicitProperty() <<'"';
2015 if (Node
->isSuperReceiver())
2018 OS
<< " Messaging=";
2019 if (Node
->isMessagingGetter() && Node
->isMessagingSetter())
2020 OS
<< "Getter&Setter";
2021 else if (Node
->isMessagingGetter())
2023 else if (Node
->isMessagingSetter())
2027 void ASTDumper::VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr
*Node
) {
2029 if (Node
->isArraySubscriptRefExpr())
2030 OS
<< " Kind=ArraySubscript GetterForArray=\"";
2032 OS
<< " Kind=DictionarySubscript GetterForDictionary=\"";
2033 if (Node
->getAtIndexMethodDecl())
2034 Node
->getAtIndexMethodDecl()->getSelector().print(OS
);
2038 if (Node
->isArraySubscriptRefExpr())
2039 OS
<< "\" SetterForArray=\"";
2041 OS
<< "\" SetterForDictionary=\"";
2042 if (Node
->setAtIndexMethodDecl())
2043 Node
->setAtIndexMethodDecl()->getSelector().print(OS
);
2048 void ASTDumper::VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr
*Node
) {
2050 OS
<< " " << (Node
->getValue() ? "__objc_yes" : "__objc_no");
2053 //===----------------------------------------------------------------------===//
2055 //===----------------------------------------------------------------------===//
2057 const char *ASTDumper::getCommandName(unsigned CommandID
) {
2059 return Traits
->getCommandInfo(CommandID
)->Name
;
2060 const CommandInfo
*Info
= CommandTraits::getBuiltinCommandInfo(CommandID
);
2063 return "<not a builtin command>";
2066 void ASTDumper::dumpFullComment(const FullComment
*C
) {
2075 void ASTDumper::dumpComment(const Comment
*C
) {
2078 ColorScope
Color(*this, NullColor
);
2084 ColorScope
Color(*this, CommentColor
);
2085 OS
<< C
->getCommentKindName();
2088 dumpSourceRange(C
->getSourceRange());
2089 ConstCommentVisitor
<ASTDumper
>::visit(C
);
2090 for (Comment::child_iterator I
= C
->child_begin(), E
= C
->child_end();
2096 void ASTDumper::visitTextComment(const TextComment
*C
) {
2097 OS
<< " Text=\"" << C
->getText() << "\"";
2100 void ASTDumper::visitInlineCommandComment(const InlineCommandComment
*C
) {
2101 OS
<< " Name=\"" << getCommandName(C
->getCommandID()) << "\"";
2102 switch (C
->getRenderKind()) {
2103 case InlineCommandComment::RenderNormal
:
2104 OS
<< " RenderNormal";
2106 case InlineCommandComment::RenderBold
:
2107 OS
<< " RenderBold";
2109 case InlineCommandComment::RenderMonospaced
:
2110 OS
<< " RenderMonospaced";
2112 case InlineCommandComment::RenderEmphasized
:
2113 OS
<< " RenderEmphasized";
2117 for (unsigned i
= 0, e
= C
->getNumArgs(); i
!= e
; ++i
)
2118 OS
<< " Arg[" << i
<< "]=\"" << C
->getArgText(i
) << "\"";
2121 void ASTDumper::visitHTMLStartTagComment(const HTMLStartTagComment
*C
) {
2122 OS
<< " Name=\"" << C
->getTagName() << "\"";
2123 if (C
->getNumAttrs() != 0) {
2125 for (unsigned i
= 0, e
= C
->getNumAttrs(); i
!= e
; ++i
) {
2126 const HTMLStartTagComment::Attribute
&Attr
= C
->getAttr(i
);
2127 OS
<< " \"" << Attr
.Name
<< "=\"" << Attr
.Value
<< "\"";
2130 if (C
->isSelfClosing())
2131 OS
<< " SelfClosing";
2134 void ASTDumper::visitHTMLEndTagComment(const HTMLEndTagComment
*C
) {
2135 OS
<< " Name=\"" << C
->getTagName() << "\"";
2138 void ASTDumper::visitBlockCommandComment(const BlockCommandComment
*C
) {
2139 OS
<< " Name=\"" << getCommandName(C
->getCommandID()) << "\"";
2140 for (unsigned i
= 0, e
= C
->getNumArgs(); i
!= e
; ++i
)
2141 OS
<< " Arg[" << i
<< "]=\"" << C
->getArgText(i
) << "\"";
2144 void ASTDumper::visitParamCommandComment(const ParamCommandComment
*C
) {
2145 OS
<< " " << ParamCommandComment::getDirectionAsString(C
->getDirection());
2147 if (C
->isDirectionExplicit())
2148 OS
<< " explicitly";
2150 OS
<< " implicitly";
2152 if (C
->hasParamName()) {
2153 if (C
->isParamIndexValid())
2154 OS
<< " Param=\"" << C
->getParamName(FC
) << "\"";
2156 OS
<< " Param=\"" << C
->getParamNameAsWritten() << "\"";
2159 if (C
->isParamIndexValid() && !C
->isVarArgParam())
2160 OS
<< " ParamIndex=" << C
->getParamIndex();
2163 void ASTDumper::visitTParamCommandComment(const TParamCommandComment
*C
) {
2164 if (C
->hasParamName()) {
2165 if (C
->isPositionValid())
2166 OS
<< " Param=\"" << C
->getParamName(FC
) << "\"";
2168 OS
<< " Param=\"" << C
->getParamNameAsWritten() << "\"";
2171 if (C
->isPositionValid()) {
2172 OS
<< " Position=<";
2173 for (unsigned i
= 0, e
= C
->getDepth(); i
!= e
; ++i
) {
2174 OS
<< C
->getIndex(i
);
2182 void ASTDumper::visitVerbatimBlockComment(const VerbatimBlockComment
*C
) {
2183 OS
<< " Name=\"" << getCommandName(C
->getCommandID()) << "\""
2184 " CloseName=\"" << C
->getCloseName() << "\"";
2187 void ASTDumper::visitVerbatimBlockLineComment(
2188 const VerbatimBlockLineComment
*C
) {
2189 OS
<< " Text=\"" << C
->getText() << "\"";
2192 void ASTDumper::visitVerbatimLineComment(const VerbatimLineComment
*C
) {
2193 OS
<< " Text=\"" << C
->getText() << "\"";
2196 //===----------------------------------------------------------------------===//
2197 // Type method implementations
2198 //===----------------------------------------------------------------------===//
2200 void QualType::dump(const char *msg
) const {
2202 llvm::errs() << msg
<< ": ";
2206 LLVM_DUMP_METHOD
void QualType::dump() const {
2207 ASTDumper
Dumper(llvm::errs(), nullptr, nullptr);
2208 Dumper
.dumpTypeAsChild(*this);
2211 LLVM_DUMP_METHOD
void Type::dump() const { QualType(this, 0).dump(); }
2213 //===----------------------------------------------------------------------===//
2214 // Decl method implementations
2215 //===----------------------------------------------------------------------===//
2217 LLVM_DUMP_METHOD
void Decl::dump() const { dump(llvm::errs()); }
2219 LLVM_DUMP_METHOD
void Decl::dump(raw_ostream
&OS
) const {
2220 ASTDumper
P(OS
, &getASTContext().getCommentCommandTraits(),
2221 &getASTContext().getSourceManager());
2225 LLVM_DUMP_METHOD
void Decl::dumpColor() const {
2226 ASTDumper
P(llvm::errs(), &getASTContext().getCommentCommandTraits(),
2227 &getASTContext().getSourceManager(), /*ShowColors*/true);
2231 LLVM_DUMP_METHOD
void DeclContext::dumpLookups() const {
2232 dumpLookups(llvm::errs());
2235 LLVM_DUMP_METHOD
void DeclContext::dumpLookups(raw_ostream
&OS
,
2236 bool DumpDecls
) const {
2237 const DeclContext
*DC
= this;
2238 while (!DC
->isTranslationUnit())
2239 DC
= DC
->getParent();
2240 ASTContext
&Ctx
= cast
<TranslationUnitDecl
>(DC
)->getASTContext();
2241 ASTDumper
P(OS
, &Ctx
.getCommentCommandTraits(), &Ctx
.getSourceManager());
2242 P
.dumpLookups(this, DumpDecls
);
2245 //===----------------------------------------------------------------------===//
2246 // Stmt method implementations
2247 //===----------------------------------------------------------------------===//
2249 LLVM_DUMP_METHOD
void Stmt::dump(SourceManager
&SM
) const {
2250 dump(llvm::errs(), SM
);
2253 LLVM_DUMP_METHOD
void Stmt::dump(raw_ostream
&OS
, SourceManager
&SM
) const {
2254 ASTDumper
P(OS
, nullptr, &SM
);
2258 LLVM_DUMP_METHOD
void Stmt::dump() const {
2259 ASTDumper
P(llvm::errs(), nullptr, nullptr);
2263 LLVM_DUMP_METHOD
void Stmt::dumpColor() const {
2264 ASTDumper
P(llvm::errs(), nullptr, nullptr, /*ShowColors*/true);
2268 //===----------------------------------------------------------------------===//
2269 // Comment method implementations
2270 //===----------------------------------------------------------------------===//
2272 LLVM_DUMP_METHOD
void Comment::dump() const {
2273 dump(llvm::errs(), nullptr, nullptr);
2276 LLVM_DUMP_METHOD
void Comment::dump(const ASTContext
&Context
) const {
2277 dump(llvm::errs(), &Context
.getCommentCommandTraits(),
2278 &Context
.getSourceManager());
2281 void Comment::dump(raw_ostream
&OS
, const CommandTraits
*Traits
,
2282 const SourceManager
*SM
) const {
2283 const FullComment
*FC
= dyn_cast
<FullComment
>(this);
2284 ASTDumper
D(OS
, Traits
, SM
);
2285 D
.dumpFullComment(FC
);
2288 LLVM_DUMP_METHOD
void Comment::dumpColor() const {
2289 const FullComment
*FC
= dyn_cast
<FullComment
>(this);
2290 ASTDumper
D(llvm::errs(), nullptr, nullptr, /*ShowColors*/true);
2291 D
.dumpFullComment(FC
);