1 //===--- ASTDumper.cpp - Dumping implementation for ASTs ------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 10 // This file implements the AST dump methods, which dump out the 11 // AST in a form that exposes type details and other fields. 12 // 13 //===----------------------------------------------------------------------===// 14 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; 32 33 //===----------------------------------------------------------------------===// 34 // ASTDumper Visitor 35 //===----------------------------------------------------------------------===// 36 37 namespace { 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. 40 41 struct TerminalColor { 42 raw_ostream::Colors Color; 43 bool Bold; 44 }; 45 46 // Red - CastColor 47 // Green - TypeColor 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 55 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 }; 64 65 // Type names (int, float, etc, plus user defined types) 66 static const TerminalColor TypeColor = { raw_ostream::GREEN, false }; 67 68 // Pointer address 69 static const TerminalColor AddressColor = { raw_ostream::YELLOW, false }; 70 // Source locations 71 static const TerminalColor LocationColor = { raw_ostream::YELLOW, false }; 72 73 // lvalue/xvalue 74 static const TerminalColor ValueKindColor = { raw_ostream::CYAN, false }; 75 // bitfield/objcproperty/objcsubscript/vectorcomponent 76 static const TerminalColor ObjectKindColor = { raw_ostream::CYAN, false }; 77 78 // Null statements 79 static const TerminalColor NullColor = { raw_ostream::BLUE, false }; 80 81 // Undeserialized entities 82 static const TerminalColor UndeserializedColor = { raw_ostream::GREEN, true }; 83 84 // CastKind from CastExpr's 85 static const TerminalColor CastColor = { raw_ostream::RED, false }; 86 87 // Value of the statement 88 static const TerminalColor ValueColor = { raw_ostream::CYAN, true }; 89 // Decl names 90 static const TerminalColor DeclNameColor = { raw_ostream::CYAN, true }; 91 92 // Indents ( `, -. | ) 93 static const TerminalColor IndentColor = { raw_ostream::BLUE, false }; 94 95 class ASTDumper 96 : public ConstDeclVisitor<ASTDumper>, public ConstStmtVisitor<ASTDumper>, 97 public ConstCommentVisitor<ASTDumper>, public TypeVisitor<ASTDumper> { 98 raw_ostream &OS; 99 const CommandTraits *Traits; 100 const SourceManager *SM; 101 102 /// Pending[i] is an action to dump an entity at level i. 103 llvm::SmallVector<std::function<void(bool isLastChild)>, 32> Pending; 104 105 /// Indicates whether we're at the top level. 106 bool TopLevel; 107 108 /// Indicates if we're handling the first child after entering a new depth. 109 bool FirstChild; 110 111 /// Prefix for currently-being-dumped entity. 112 std::string Prefix; 113 114 /// Keep track of the last location we print out so that we can 115 /// print out deltas from then on out. 116 const char *LastLocFilename; 117 unsigned LastLocLine; 118 119 /// The \c FullComment parent of the comment being dumped. 120 const FullComment *FC; 121 122 bool ShowColors; 123 124 /// Dump a child of the current node. 125 template<typename Fn> void dumpChild(Fn doDumpChild) { 126 // If we're at the top level, there's nothing interesting to do; just 127 // run the dumper. 128 if (TopLevel) { 129 TopLevel = false; 130 doDumpChild(); 131 while (!Pending.empty()) { 132 Pending.back()(true); 133 Pending.pop_back(); 134 } 135 Prefix.clear(); 136 OS << "\n"; 137 TopLevel = true; 138 return; 139 } 140 141 const FullComment *OrigFC = FC; 142 auto dumpWithIndent = [this, doDumpChild, OrigFC](bool isLastChild) { 143 // Print out the appropriate tree structure and work out the prefix for 144 // children of this node. For instance: 145 // 146 // A Prefix = "" 147 // |-B Prefix = "| " 148 // | `-C Prefix = "| " 149 // `-D Prefix = " " 150 // |-E Prefix = " | " 151 // `-F Prefix = " " 152 // G Prefix = "" 153 // 154 // Note that the first level gets no prefix. 155 { 156 OS << '\n'; 157 ColorScope Color(*this, IndentColor); 158 OS << Prefix << (isLastChild ? '`' : '|') << '-'; 159 this->Prefix.push_back(isLastChild ? ' ' : '|'); 160 this->Prefix.push_back(' '); 161 } 162 163 FirstChild = true; 164 unsigned Depth = Pending.size(); 165 166 FC = OrigFC; 167 doDumpChild(); 168 169 // If any children are left, they're the last at their nesting level. 170 // Dump those ones out now. 171 while (Depth < Pending.size()) { 172 Pending.back()(true); 173 this->Pending.pop_back(); 174 } 175 176 // Restore the old prefix. 177 this->Prefix.resize(Prefix.size() - 2); 178 }; 179 180 if (FirstChild) { 181 Pending.push_back(std::move(dumpWithIndent)); 182 } else { 183 Pending.back()(false); 184 Pending.back() = std::move(dumpWithIndent); 185 } 186 FirstChild = false; 187 } 188 189 class ColorScope { 190 ASTDumper &Dumper; 191 public: 192 ColorScope(ASTDumper &Dumper, TerminalColor Color) 193 : Dumper(Dumper) { 194 if (Dumper.ShowColors) 195 Dumper.OS.changeColor(Color.Color, Color.Bold); 196 } 197 ~ColorScope() { 198 if (Dumper.ShowColors) 199 Dumper.OS.resetColor(); 200 } 201 }; 202 203 public: 204 ASTDumper(raw_ostream &OS, const CommandTraits *Traits, 205 const SourceManager *SM) 206 : OS(OS), Traits(Traits), SM(SM), TopLevel(true), FirstChild(true), 207 LastLocFilename(""), LastLocLine(~0U), FC(nullptr), 208 ShowColors(SM && SM->getDiagnostics().getShowColors()) { } 209 210 ASTDumper(raw_ostream &OS, const CommandTraits *Traits, 211 const SourceManager *SM, bool ShowColors) 212 : OS(OS), Traits(Traits), SM(SM), TopLevel(true), FirstChild(true), 213 LastLocFilename(""), LastLocLine(~0U), 214 ShowColors(ShowColors) { } 215 216 void dumpDecl(const Decl *D); 217 void dumpStmt(const Stmt *S); 218 void dumpFullComment(const FullComment *C); 219 220 // Utilities 221 void dumpPointer(const void *Ptr); 222 void dumpSourceRange(SourceRange R); 223 void dumpLocation(SourceLocation Loc); 224 void dumpBareType(QualType T, bool Desugar = true); 225 void dumpType(QualType T); 226 void dumpTypeAsChild(QualType T); 227 void dumpTypeAsChild(const Type *T); 228 void dumpBareDeclRef(const Decl *Node); 229 void dumpDeclRef(const Decl *Node, const char *Label = nullptr); 230 void dumpName(const NamedDecl *D); 231 bool hasNodes(const DeclContext *DC); 232 void dumpDeclContext(const DeclContext *DC); 233 void dumpLookups(const DeclContext *DC, bool DumpDecls); 234 void dumpAttr(const Attr *A); 235 236 // C++ Utilities 237 void dumpAccessSpecifier(AccessSpecifier AS); 238 void dumpCXXCtorInitializer(const CXXCtorInitializer *Init); 239 void dumpTemplateParameters(const TemplateParameterList *TPL); 240 void dumpTemplateArgumentListInfo(const TemplateArgumentListInfo &TALI); 241 void dumpTemplateArgumentLoc(const TemplateArgumentLoc &A); 242 void dumpTemplateArgumentList(const TemplateArgumentList &TAL); 243 void dumpTemplateArgument(const TemplateArgument &A, 244 SourceRange R = SourceRange()); 245 246 // Objective-C utilities. 247 void dumpObjCTypeParamList(const ObjCTypeParamList *typeParams); 248 249 // Types 250 void VisitComplexType(const ComplexType *T) { 251 dumpTypeAsChild(T->getElementType()); 252 } 253 void VisitPointerType(const PointerType *T) { 254 dumpTypeAsChild(T->getPointeeType()); 255 } 256 void VisitBlockPointerType(const BlockPointerType *T) { 257 dumpTypeAsChild(T->getPointeeType()); 258 } 259 void VisitReferenceType(const ReferenceType *T) { 260 dumpTypeAsChild(T->getPointeeType()); 261 } 262 void VisitRValueReferenceType(const ReferenceType *T) { 263 if (T->isSpelledAsLValue()) 264 OS << " written as lvalue reference"; 265 VisitReferenceType(T); 266 } 267 void VisitMemberPointerType(const MemberPointerType *T) { 268 dumpTypeAsChild(T->getClass()); 269 dumpTypeAsChild(T->getPointeeType()); 270 } 271 void VisitArrayType(const ArrayType *T) { 272 switch (T->getSizeModifier()) { 273 case ArrayType::Normal: break; 274 case ArrayType::Static: OS << " static"; break; 275 case ArrayType::Star: OS << " *"; break; 276 } 277 OS << " " << T->getIndexTypeQualifiers().getAsString(); 278 dumpTypeAsChild(T->getElementType()); 279 } 280 void VisitConstantArrayType(const ConstantArrayType *T) { 281 OS << " " << T->getSize(); 282 VisitArrayType(T); 283 } 284 void VisitVariableArrayType(const VariableArrayType *T) { 285 OS << " "; 286 dumpSourceRange(T->getBracketsRange()); 287 VisitArrayType(T); 288 dumpStmt(T->getSizeExpr()); 289 } 290 void VisitDependentSizedArrayType(const DependentSizedArrayType *T) { 291 VisitArrayType(T); 292 OS << " "; 293 dumpSourceRange(T->getBracketsRange()); 294 dumpStmt(T->getSizeExpr()); 295 } 296 void VisitDependentSizedExtVectorType( 297 const DependentSizedExtVectorType *T) { 298 OS << " "; 299 dumpLocation(T->getAttributeLoc()); 300 dumpTypeAsChild(T->getElementType()); 301 dumpStmt(T->getSizeExpr()); 302 } 303 void VisitVectorType(const VectorType *T) { 304 switch (T->getVectorKind()) { 305 case VectorType::GenericVector: break; 306 case VectorType::AltiVecVector: OS << " altivec"; break; 307 case VectorType::AltiVecPixel: OS << " altivec pixel"; break; 308 case VectorType::AltiVecBool: OS << " altivec bool"; break; 309 case VectorType::NeonVector: OS << " neon"; break; 310 case VectorType::NeonPolyVector: OS << " neon poly"; break; 311 } 312 OS << " " << T->getNumElements(); 313 dumpTypeAsChild(T->getElementType()); 314 } 315 void VisitFunctionType(const FunctionType *T) { 316 auto EI = T->getExtInfo(); 317 if (EI.getNoReturn()) OS << " noreturn"; 318 if (EI.getProducesResult()) OS << " produces_result"; 319 if (EI.getHasRegParm()) OS << " regparm " << EI.getRegParm(); 320 OS << " " << FunctionType::getNameForCallConv(EI.getCC()); 321 dumpTypeAsChild(T->getReturnType()); 322 } 323 void VisitFunctionProtoType(const FunctionProtoType *T) { 324 auto EPI = T->getExtProtoInfo(); 325 if (EPI.HasTrailingReturn) OS << " trailing_return"; 326 if (T->isConst()) OS << " const"; 327 if (T->isVolatile()) OS << " volatile"; 328 if (T->isRestrict()) OS << " restrict"; 329 switch (EPI.RefQualifier) { 330 case RQ_None: break; 331 case RQ_LValue: OS << " &"; break; 332 case RQ_RValue: OS << " &&"; break; 333 } 334 // FIXME: Exception specification. 335 // FIXME: Consumed parameters. 336 VisitFunctionType(T); 337 for (QualType PT : T->getParamTypes()) 338 dumpTypeAsChild(PT); 339 if (EPI.Variadic) 340 dumpChild([=] { OS << "..."; }); 341 } 342 void VisitUnresolvedUsingType(const UnresolvedUsingType *T) { 343 dumpDeclRef(T->getDecl()); 344 } 345 void VisitTypedefType(const TypedefType *T) { 346 dumpDeclRef(T->getDecl()); 347 } 348 void VisitTypeOfExprType(const TypeOfExprType *T) { 349 dumpStmt(T->getUnderlyingExpr()); 350 } 351 void VisitDecltypeType(const DecltypeType *T) { 352 dumpStmt(T->getUnderlyingExpr()); 353 } 354 void VisitUnaryTransformType(const UnaryTransformType *T) { 355 switch (T->getUTTKind()) { 356 case UnaryTransformType::EnumUnderlyingType: 357 OS << " underlying_type"; 358 break; 359 } 360 dumpTypeAsChild(T->getBaseType()); 361 } 362 void VisitTagType(const TagType *T) { 363 dumpDeclRef(T->getDecl()); 364 } 365 void VisitAttributedType(const AttributedType *T) { 366 // FIXME: AttrKind 367 dumpTypeAsChild(T->getModifiedType()); 368 } 369 void VisitTemplateTypeParmType(const TemplateTypeParmType *T) { 370 OS << " depth " << T->getDepth() << " index " << T->getIndex(); 371 if (T->isParameterPack()) OS << " pack"; 372 dumpDeclRef(T->getDecl()); 373 } 374 void VisitSubstTemplateTypeParmType(const SubstTemplateTypeParmType *T) { 375 dumpTypeAsChild(T->getReplacedParameter()); 376 } 377 void VisitSubstTemplateTypeParmPackType( 378 const SubstTemplateTypeParmPackType *T) { 379 dumpTypeAsChild(T->getReplacedParameter()); 380 dumpTemplateArgument(T->getArgumentPack()); 381 } 382 void VisitAutoType(const AutoType *T) { 383 if (T->isDecltypeAuto()) OS << " decltype(auto)"; 384 if (!T->isDeduced()) 385 OS << " undeduced"; 386 } 387 void VisitTemplateSpecializationType(const TemplateSpecializationType *T) { 388 if (T->isTypeAlias()) OS << " alias"; 389 OS << " "; T->getTemplateName().dump(OS); 390 for (auto &Arg : *T) 391 dumpTemplateArgument(Arg); 392 if (T->isTypeAlias()) 393 dumpTypeAsChild(T->getAliasedType()); 394 } 395 void VisitInjectedClassNameType(const InjectedClassNameType *T) { 396 dumpDeclRef(T->getDecl()); 397 } 398 void VisitObjCInterfaceType(const ObjCInterfaceType *T) { 399 dumpDeclRef(T->getDecl()); 400 } 401 void VisitObjCObjectPointerType(const ObjCObjectPointerType *T) { 402 dumpTypeAsChild(T->getPointeeType()); 403 } 404 void VisitAtomicType(const AtomicType *T) { 405 dumpTypeAsChild(T->getValueType()); 406 } 407 void VisitAdjustedType(const AdjustedType *T) { 408 dumpTypeAsChild(T->getOriginalType()); 409 } 410 void VisitPackExpansionType(const PackExpansionType *T) { 411 if (auto N = T->getNumExpansions()) OS << " expansions " << *N; 412 if (!T->isSugared()) 413 dumpTypeAsChild(T->getPattern()); 414 } 415 // FIXME: ElaboratedType, DependentNameType, 416 // DependentTemplateSpecializationType, ObjCObjectType 417 418 // Decls 419 void VisitLabelDecl(const LabelDecl *D); 420 void VisitTypedefDecl(const TypedefDecl *D); 421 void VisitEnumDecl(const EnumDecl *D); 422 void VisitRecordDecl(const RecordDecl *D); 423 void VisitEnumConstantDecl(const EnumConstantDecl *D); 424 void VisitIndirectFieldDecl(const IndirectFieldDecl *D); 425 void VisitFunctionDecl(const FunctionDecl *D); 426 void VisitFieldDecl(const FieldDecl *D); 427 void VisitVarDecl(const VarDecl *D); 428 void VisitFileScopeAsmDecl(const FileScopeAsmDecl *D); 429 void VisitImportDecl(const ImportDecl *D); 430 void VisitPragmaCommentDecl(const PragmaCommentDecl *D); 431 void VisitPragmaDetectMismatchDecl(const PragmaDetectMismatchDecl *D); 432 void VisitCapturedDecl(const CapturedDecl *D); 433 434 // OpenMP decls 435 void VisitOMPThreadPrivateDecl(const OMPThreadPrivateDecl *D); 436 void VisitOMPDeclareReductionDecl(const OMPDeclareReductionDecl *D); 437 void VisitOMPCapturedExprDecl(const OMPCapturedExprDecl *D); 438 439 // C++ Decls 440 void VisitNamespaceDecl(const NamespaceDecl *D); 441 void VisitUsingDirectiveDecl(const UsingDirectiveDecl *D); 442 void VisitNamespaceAliasDecl(const NamespaceAliasDecl *D); 443 void VisitTypeAliasDecl(const TypeAliasDecl *D); 444 void VisitTypeAliasTemplateDecl(const TypeAliasTemplateDecl *D); 445 void VisitCXXRecordDecl(const CXXRecordDecl *D); 446 void VisitStaticAssertDecl(const StaticAssertDecl *D); 447 template<typename SpecializationDecl> 448 void VisitTemplateDeclSpecialization(const SpecializationDecl *D, 449 bool DumpExplicitInst, 450 bool DumpRefOnly); 451 template<typename TemplateDecl> 452 void VisitTemplateDecl(const TemplateDecl *D, bool DumpExplicitInst); 453 void VisitFunctionTemplateDecl(const FunctionTemplateDecl *D); 454 void VisitClassTemplateDecl(const ClassTemplateDecl *D); 455 void VisitClassTemplateSpecializationDecl( 456 const ClassTemplateSpecializationDecl *D); 457 void VisitClassTemplatePartialSpecializationDecl( 458 const ClassTemplatePartialSpecializationDecl *D); 459 void VisitClassScopeFunctionSpecializationDecl( 460 const ClassScopeFunctionSpecializationDecl *D); 461 void VisitBuiltinTemplateDecl(const BuiltinTemplateDecl *D); 462 void VisitVarTemplateDecl(const VarTemplateDecl *D); 463 void VisitVarTemplateSpecializationDecl( 464 const VarTemplateSpecializationDecl *D); 465 void VisitVarTemplatePartialSpecializationDecl( 466 const VarTemplatePartialSpecializationDecl *D); 467 void VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D); 468 void VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D); 469 void VisitTemplateTemplateParmDecl(const TemplateTemplateParmDecl *D); 470 void VisitUsingDecl(const UsingDecl *D); 471 void VisitUnresolvedUsingTypenameDecl(const UnresolvedUsingTypenameDecl *D); 472 void VisitUnresolvedUsingValueDecl(const UnresolvedUsingValueDecl *D); 473 void VisitUsingShadowDecl(const UsingShadowDecl *D); 474 void VisitLinkageSpecDecl(const LinkageSpecDecl *D); 475 void VisitAccessSpecDecl(const AccessSpecDecl *D); 476 void VisitFriendDecl(const FriendDecl *D); 477 478 // ObjC Decls 479 void VisitObjCIvarDecl(const ObjCIvarDecl *D); 480 void VisitObjCMethodDecl(const ObjCMethodDecl *D); 481 void VisitObjCTypeParamDecl(const ObjCTypeParamDecl *D); 482 void VisitObjCCategoryDecl(const ObjCCategoryDecl *D); 483 void VisitObjCCategoryImplDecl(const ObjCCategoryImplDecl *D); 484 void VisitObjCProtocolDecl(const ObjCProtocolDecl *D); 485 void VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D); 486 void VisitObjCImplementationDecl(const ObjCImplementationDecl *D); 487 void VisitObjCCompatibleAliasDecl(const ObjCCompatibleAliasDecl *D); 488 void VisitObjCPropertyDecl(const ObjCPropertyDecl *D); 489 void VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D); 490 void VisitBlockDecl(const BlockDecl *D); 491 492 // Stmts. 493 void VisitStmt(const Stmt *Node); 494 void VisitDeclStmt(const DeclStmt *Node); 495 void VisitAttributedStmt(const AttributedStmt *Node); 496 void VisitLabelStmt(const LabelStmt *Node); 497 void VisitGotoStmt(const GotoStmt *Node); 498 void VisitCXXCatchStmt(const CXXCatchStmt *Node); 499 void VisitCapturedStmt(const CapturedStmt *Node); 500 501 // OpenMP 502 void VisitOMPExecutableDirective(const OMPExecutableDirective *Node); 503 504 // Exprs 505 void VisitExpr(const Expr *Node); 506 void VisitCastExpr(const CastExpr *Node); 507 void VisitDeclRefExpr(const DeclRefExpr *Node); 508 void VisitPredefinedExpr(const PredefinedExpr *Node); 509 void VisitCharacterLiteral(const CharacterLiteral *Node); 510 void VisitIntegerLiteral(const IntegerLiteral *Node); 511 void VisitFloatingLiteral(const FloatingLiteral *Node); 512 void VisitStringLiteral(const StringLiteral *Str); 513 void VisitInitListExpr(const InitListExpr *ILE); 514 void VisitUnaryOperator(const UnaryOperator *Node); 515 void VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *Node); 516 void VisitMemberExpr(const MemberExpr *Node); 517 void VisitExtVectorElementExpr(const ExtVectorElementExpr *Node); 518 void VisitBinaryOperator(const BinaryOperator *Node); 519 void VisitCompoundAssignOperator(const CompoundAssignOperator *Node); 520 void VisitAddrLabelExpr(const AddrLabelExpr *Node); 521 void VisitBlockExpr(const BlockExpr *Node); 522 void VisitOpaqueValueExpr(const OpaqueValueExpr *Node); 523 524 // C++ 525 void VisitCXXNamedCastExpr(const CXXNamedCastExpr *Node); 526 void VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *Node); 527 void VisitCXXThisExpr(const CXXThisExpr *Node); 528 void VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *Node); 529 void VisitCXXConstructExpr(const CXXConstructExpr *Node); 530 void VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *Node); 531 void VisitCXXNewExpr(const CXXNewExpr *Node); 532 void VisitCXXDeleteExpr(const CXXDeleteExpr *Node); 533 void VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *Node); 534 void VisitExprWithCleanups(const ExprWithCleanups *Node); 535 void VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *Node); 536 void dumpCXXTemporary(const CXXTemporary *Temporary); 537 void VisitLambdaExpr(const LambdaExpr *Node) { 538 VisitExpr(Node); 539 dumpDecl(Node->getLambdaClass()); 540 } 541 void VisitSizeOfPackExpr(const SizeOfPackExpr *Node); 542 543 // ObjC 544 void VisitObjCAtCatchStmt(const ObjCAtCatchStmt *Node); 545 void VisitObjCEncodeExpr(const ObjCEncodeExpr *Node); 546 void VisitObjCMessageExpr(const ObjCMessageExpr *Node); 547 void VisitObjCBoxedExpr(const ObjCBoxedExpr *Node); 548 void VisitObjCSelectorExpr(const ObjCSelectorExpr *Node); 549 void VisitObjCProtocolExpr(const ObjCProtocolExpr *Node); 550 void VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *Node); 551 void VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *Node); 552 void VisitObjCIvarRefExpr(const ObjCIvarRefExpr *Node); 553 void VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *Node); 554 555 // Comments. 556 const char *getCommandName(unsigned CommandID); 557 void dumpComment(const Comment *C); 558 559 // Inline comments. 560 void visitTextComment(const TextComment *C); 561 void visitInlineCommandComment(const InlineCommandComment *C); 562 void visitHTMLStartTagComment(const HTMLStartTagComment *C); 563 void visitHTMLEndTagComment(const HTMLEndTagComment *C); 564 565 // Block comments. 566 void visitBlockCommandComment(const BlockCommandComment *C); 567 void visitParamCommandComment(const ParamCommandComment *C); 568 void visitTParamCommandComment(const TParamCommandComment *C); 569 void visitVerbatimBlockComment(const VerbatimBlockComment *C); 570 void visitVerbatimBlockLineComment(const VerbatimBlockLineComment *C); 571 void visitVerbatimLineComment(const VerbatimLineComment *C); 572 }; 573 } 574 575 //===----------------------------------------------------------------------===// 576 // Utilities 577 //===----------------------------------------------------------------------===// 578 579 void ASTDumper::dumpPointer(const void *Ptr) { 580 ColorScope Color(*this, AddressColor); 581 OS << ' ' << Ptr; 582 } 583 584 void ASTDumper::dumpLocation(SourceLocation Loc) { 585 if (!SM) 586 return; 587 588 ColorScope Color(*this, LocationColor); 589 SourceLocation SpellingLoc = SM->getSpellingLoc(Loc); 590 591 // The general format we print out is filename:line:col, but we drop pieces 592 // that haven't changed since the last loc printed. 593 PresumedLoc PLoc = SM->getPresumedLoc(SpellingLoc); 594 595 if (PLoc.isInvalid()) { 596 OS << "<invalid sloc>"; 597 return; 598 } 599 600 if (strcmp(PLoc.getFilename(), LastLocFilename) != 0) { 601 OS << PLoc.getFilename() << ':' << PLoc.getLine() 602 << ':' << PLoc.getColumn(); 603 LastLocFilename = PLoc.getFilename(); 604 LastLocLine = PLoc.getLine(); 605 } else if (PLoc.getLine() != LastLocLine) { 606 OS << "line" << ':' << PLoc.getLine() 607 << ':' << PLoc.getColumn(); 608 LastLocLine = PLoc.getLine(); 609 } else { 610 OS << "col" << ':' << PLoc.getColumn(); 611 } 612 } 613 614 void ASTDumper::dumpSourceRange(SourceRange R) { 615 // Can't translate locations if a SourceManager isn't available. 616 if (!SM) 617 return; 618 619 OS << " <"; 620 dumpLocation(R.getBegin()); 621 if (R.getBegin() != R.getEnd()) { 622 OS << ", "; 623 dumpLocation(R.getEnd()); 624 } 625 OS << ">"; 626 627 // <t2.c:123:421[blah], t2.c:412:321> 628 629 } 630 631 void ASTDumper::dumpBareType(QualType T, bool Desugar) { 632 ColorScope Color(*this, TypeColor); 633 634 SplitQualType T_split = T.split(); 635 OS << "'" << QualType::getAsString(T_split) << "'"; 636 637 if (Desugar && !T.isNull()) { 638 // If the type is sugared, also dump a (shallow) desugared type. 639 SplitQualType D_split = T.getSplitDesugaredType(); 640 if (T_split != D_split) 641 OS << ":'" << QualType::getAsString(D_split) << "'"; 642 } 643 } 644 645 void ASTDumper::dumpType(QualType T) { 646 OS << ' '; 647 dumpBareType(T); 648 } 649 650 void ASTDumper::dumpTypeAsChild(QualType T) { 651 SplitQualType SQT = T.split(); 652 if (!SQT.Quals.hasQualifiers()) 653 return dumpTypeAsChild(SQT.Ty); 654 655 dumpChild([=] { 656 OS << "QualType"; 657 dumpPointer(T.getAsOpaquePtr()); 658 OS << " "; 659 dumpBareType(T, false); 660 OS << " " << T.split().Quals.getAsString(); 661 dumpTypeAsChild(T.split().Ty); 662 }); 663 } 664 665 void ASTDumper::dumpTypeAsChild(const Type *T) { 666 dumpChild([=] { 667 if (!T) { 668 ColorScope Color(*this, NullColor); 669 OS << "<<<NULL>>>"; 670 return; 671 } 672 if (const LocInfoType *LIT = llvm::dyn_cast<LocInfoType>(T)) { 673 { 674 ColorScope Color(*this, TypeColor); 675 OS << "LocInfo Type"; 676 } 677 dumpPointer(T); 678 dumpTypeAsChild(LIT->getTypeSourceInfo()->getType()); 679 return; 680 } 681 682 { 683 ColorScope Color(*this, TypeColor); 684 OS << T->getTypeClassName() << "Type"; 685 } 686 dumpPointer(T); 687 OS << " "; 688 dumpBareType(QualType(T, 0), false); 689 690 QualType SingleStepDesugar = 691 T->getLocallyUnqualifiedSingleStepDesugaredType(); 692 if (SingleStepDesugar != QualType(T, 0)) 693 OS << " sugar"; 694 if (T->isDependentType()) 695 OS << " dependent"; 696 else if (T->isInstantiationDependentType()) 697 OS << " instantiation_dependent"; 698 if (T->isVariablyModifiedType()) 699 OS << " variably_modified"; 700 if (T->containsUnexpandedParameterPack()) 701 OS << " contains_unexpanded_pack"; 702 if (T->isFromAST()) 703 OS << " imported"; 704 705 TypeVisitor<ASTDumper>::Visit(T); 706 707 if (SingleStepDesugar != QualType(T, 0)) 708 dumpTypeAsChild(SingleStepDesugar); 709 }); 710 } 711 712 void ASTDumper::dumpBareDeclRef(const Decl *D) { 713 { 714 ColorScope Color(*this, DeclKindNameColor); 715 OS << D->getDeclKindName(); 716 } 717 dumpPointer(D); 718 719 if (const NamedDecl *ND = dyn_cast<NamedDecl>(D)) { 720 ColorScope Color(*this, DeclNameColor); 721 OS << " '" << ND->getDeclName() << '\''; 722 } 723 724 if (const ValueDecl *VD = dyn_cast<ValueDecl>(D)) 725 dumpType(VD->getType()); 726 } 727 728 void ASTDumper::dumpDeclRef(const Decl *D, const char *Label) { 729 if (!D) 730 return; 731 732 dumpChild([=]{ 733 if (Label) 734 OS << Label << ' '; 735 dumpBareDeclRef(D); 736 }); 737 } 738 739 void ASTDumper::dumpName(const NamedDecl *ND) { 740 if (ND->getDeclName()) { 741 ColorScope Color(*this, DeclNameColor); 742 OS << ' ' << ND->getNameAsString(); 743 } 744 } 745 746 bool ASTDumper::hasNodes(const DeclContext *DC) { 747 if (!DC) 748 return false; 749 750 return DC->hasExternalLexicalStorage() || 751 DC->noload_decls_begin() != DC->noload_decls_end(); 752 } 753 754 void ASTDumper::dumpDeclContext(const DeclContext *DC) { 755 if (!DC) 756 return; 757 758 for (auto *D : DC->noload_decls()) 759 dumpDecl(D); 760 761 if (DC->hasExternalLexicalStorage()) { 762 dumpChild([=]{ 763 ColorScope Color(*this, UndeserializedColor); 764 OS << "<undeserialized declarations>"; 765 }); 766 } 767 } 768 769 void ASTDumper::dumpLookups(const DeclContext *DC, bool DumpDecls) { 770 dumpChild([=] { 771 OS << "StoredDeclsMap "; 772 dumpBareDeclRef(cast<Decl>(DC)); 773 774 const DeclContext *Primary = DC->getPrimaryContext(); 775 if (Primary != DC) { 776 OS << " primary"; 777 dumpPointer(cast<Decl>(Primary)); 778 } 779 780 bool HasUndeserializedLookups = Primary->hasExternalVisibleStorage(); 781 782 DeclContext::all_lookups_iterator I = Primary->noload_lookups_begin(), 783 E = Primary->noload_lookups_end(); 784 while (I != E) { 785 DeclarationName Name = I.getLookupName(); 786 DeclContextLookupResult R = *I++; 787 788 dumpChild([=] { 789 OS << "DeclarationName "; 790 { 791 ColorScope Color(*this, DeclNameColor); 792 OS << '\'' << Name << '\''; 793 } 794 795 for (DeclContextLookupResult::iterator RI = R.begin(), RE = R.end(); 796 RI != RE; ++RI) { 797 dumpChild([=] { 798 dumpBareDeclRef(*RI); 799 800 if ((*RI)->isHidden()) 801 OS << " hidden"; 802 803 // If requested, dump the redecl chain for this lookup. 804 if (DumpDecls) { 805 // Dump earliest decl first. 806 std::function<void(Decl *)> DumpWithPrev = [&](Decl *D) { 807 if (Decl *Prev = D->getPreviousDecl()) 808 DumpWithPrev(Prev); 809 dumpDecl(D); 810 }; 811 DumpWithPrev(*RI); 812 } 813 }); 814 } 815 }); 816 } 817 818 if (HasUndeserializedLookups) { 819 dumpChild([=] { 820 ColorScope Color(*this, UndeserializedColor); 821 OS << "<undeserialized lookups>"; 822 }); 823 } 824 }); 825 } 826 827 void ASTDumper::dumpAttr(const Attr *A) { 828 dumpChild([=] { 829 { 830 ColorScope Color(*this, AttrColor); 831 832 switch (A->getKind()) { 833 #define ATTR(X) case attr::X: OS << #X; break; 834 #include "clang/Basic/AttrList.inc" 835 } 836 OS << "Attr"; 837 } 838 dumpPointer(A); 839 dumpSourceRange(A->getRange()); 840 if (A->isInherited()) 841 OS << " Inherited"; 842 if (A->isImplicit()) 843 OS << " Implicit"; 844 #include "clang/AST/AttrDump.inc" 845 }); 846 } 847 848 static void dumpPreviousDeclImpl(raw_ostream &OS, ...) {} 849 850 template<typename T> 851 static void dumpPreviousDeclImpl(raw_ostream &OS, const Mergeable<T> *D) { 852 const T *First = D->getFirstDecl(); 853 if (First != D) 854 OS << " first " << First; 855 } 856 857 template<typename T> 858 static void dumpPreviousDeclImpl(raw_ostream &OS, const Redeclarable<T> *D) { 859 const T *Prev = D->getPreviousDecl(); 860 if (Prev) 861 OS << " prev " << Prev; 862 } 863 864 /// Dump the previous declaration in the redeclaration chain for a declaration, 865 /// if any. 866 static void dumpPreviousDecl(raw_ostream &OS, const Decl *D) { 867 switch (D->getKind()) { 868 #define DECL(DERIVED, BASE) \ 869 case Decl::DERIVED: \ 870 return dumpPreviousDeclImpl(OS, cast<DERIVED##Decl>(D)); 871 #define ABSTRACT_DECL(DECL) 872 #include "clang/AST/DeclNodes.inc" 873 } 874 llvm_unreachable("Decl that isn't part of DeclNodes.inc!"); 875 } 876 877 //===----------------------------------------------------------------------===// 878 // C++ Utilities 879 //===----------------------------------------------------------------------===// 880 881 void ASTDumper::dumpAccessSpecifier(AccessSpecifier AS) { 882 switch (AS) { 883 case AS_none: 884 break; 885 case AS_public: 886 OS << "public"; 887 break; 888 case AS_protected: 889 OS << "protected"; 890 break; 891 case AS_private: 892 OS << "private"; 893 break; 894 } 895 } 896 897 void ASTDumper::dumpCXXCtorInitializer(const CXXCtorInitializer *Init) { 898 dumpChild([=] { 899 OS << "CXXCtorInitializer"; 900 if (Init->isAnyMemberInitializer()) { 901 OS << ' '; 902 dumpBareDeclRef(Init->getAnyMember()); 903 } else if (Init->isBaseInitializer()) { 904 dumpType(QualType(Init->getBaseClass(), 0)); 905 } else if (Init->isDelegatingInitializer()) { 906 dumpType(Init->getTypeSourceInfo()->getType()); 907 } else { 908 llvm_unreachable("Unknown initializer type"); 909 } 910 dumpStmt(Init->getInit()); 911 }); 912 } 913 914 void ASTDumper::dumpTemplateParameters(const TemplateParameterList *TPL) { 915 if (!TPL) 916 return; 917 918 for (TemplateParameterList::const_iterator I = TPL->begin(), E = TPL->end(); 919 I != E; ++I) 920 dumpDecl(*I); 921 } 922 923 void ASTDumper::dumpTemplateArgumentListInfo( 924 const TemplateArgumentListInfo &TALI) { 925 for (unsigned i = 0, e = TALI.size(); i < e; ++i) 926 dumpTemplateArgumentLoc(TALI[i]); 927 } 928 929 void ASTDumper::dumpTemplateArgumentLoc(const TemplateArgumentLoc &A) { 930 dumpTemplateArgument(A.getArgument(), A.getSourceRange()); 931 } 932 933 void ASTDumper::dumpTemplateArgumentList(const TemplateArgumentList &TAL) { 934 for (unsigned i = 0, e = TAL.size(); i < e; ++i) 935 dumpTemplateArgument(TAL[i]); 936 } 937 938 void ASTDumper::dumpTemplateArgument(const TemplateArgument &A, SourceRange R) { 939 dumpChild([=] { 940 OS << "TemplateArgument"; 941 if (R.isValid()) 942 dumpSourceRange(R); 943 944 switch (A.getKind()) { 945 case TemplateArgument::Null: 946 OS << " null"; 947 break; 948 case TemplateArgument::Type: 949 OS << " type"; 950 dumpType(A.getAsType()); 951 break; 952 case TemplateArgument::Declaration: 953 OS << " decl"; 954 dumpDeclRef(A.getAsDecl()); 955 break; 956 case TemplateArgument::NullPtr: 957 OS << " nullptr"; 958 break; 959 case TemplateArgument::Integral: 960 OS << " integral " << A.getAsIntegral(); 961 break; 962 case TemplateArgument::Template: 963 OS << " template "; 964 A.getAsTemplate().dump(OS); 965 break; 966 case TemplateArgument::TemplateExpansion: 967 OS << " template expansion"; 968 A.getAsTemplateOrTemplatePattern().dump(OS); 969 break; 970 case TemplateArgument::Expression: 971 OS << " expr"; 972 dumpStmt(A.getAsExpr()); 973 break; 974 case TemplateArgument::Pack: 975 OS << " pack"; 976 for (TemplateArgument::pack_iterator I = A.pack_begin(), E = A.pack_end(); 977 I != E; ++I) 978 dumpTemplateArgument(*I); 979 break; 980 } 981 }); 982 } 983 984 //===----------------------------------------------------------------------===// 985 // Objective-C Utilities 986 //===----------------------------------------------------------------------===// 987 void ASTDumper::dumpObjCTypeParamList(const ObjCTypeParamList *typeParams) { 988 if (!typeParams) 989 return; 990 991 for (auto typeParam : *typeParams) { 992 dumpDecl(typeParam); 993 } 994 } 995 996 //===----------------------------------------------------------------------===// 997 // Decl dumping methods. 998 //===----------------------------------------------------------------------===// 999 1000 void ASTDumper::dumpDecl(const Decl *D) { 1001 dumpChild([=] { 1002 if (!D) { 1003 ColorScope Color(*this, NullColor); 1004 OS << "<<<NULL>>>"; 1005 return; 1006 } 1007 1008 { 1009 ColorScope Color(*this, DeclKindNameColor); 1010 OS << D->getDeclKindName() << "Decl"; 1011 } 1012 dumpPointer(D); 1013 if (D->getLexicalDeclContext() != D->getDeclContext()) 1014 OS << " parent " << cast<Decl>(D->getDeclContext()); 1015 dumpPreviousDecl(OS, D); 1016 dumpSourceRange(D->getSourceRange()); 1017 OS << ' '; 1018 dumpLocation(D->getLocation()); 1019 if (Module *M = D->getImportedOwningModule()) 1020 OS << " in " << M->getFullModuleName(); 1021 else if (Module *M = D->getLocalOwningModule()) 1022 OS << " in (local) " << M->getFullModuleName(); 1023 if (auto *ND = dyn_cast<NamedDecl>(D)) 1024 for (Module *M : D->getASTContext().getModulesWithMergedDefinition( 1025 const_cast<NamedDecl *>(ND))) 1026 dumpChild([=] { OS << "also in " << M->getFullModuleName(); }); 1027 if (const NamedDecl *ND = dyn_cast<NamedDecl>(D)) 1028 if (ND->isHidden()) 1029 OS << " hidden"; 1030 if (D->isImplicit()) 1031 OS << " implicit"; 1032 if (D->isUsed()) 1033 OS << " used"; 1034 else if (D->isThisDeclarationReferenced()) 1035 OS << " referenced"; 1036 if (D->isInvalidDecl()) 1037 OS << " invalid"; 1038 if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) 1039 if (FD->isConstexpr()) 1040 OS << " constexpr"; 1041 1042 1043 ConstDeclVisitor<ASTDumper>::Visit(D); 1044 1045 for (Decl::attr_iterator I = D->attr_begin(), E = D->attr_end(); I != E; 1046 ++I) 1047 dumpAttr(*I); 1048 1049 if (const FullComment *Comment = 1050 D->getASTContext().getLocalCommentForDeclUncached(D)) 1051 dumpFullComment(Comment); 1052 1053 // Decls within functions are visited by the body. 1054 if (!isa<FunctionDecl>(*D) && !isa<ObjCMethodDecl>(*D) && 1055 hasNodes(dyn_cast<DeclContext>(D))) 1056 dumpDeclContext(cast<DeclContext>(D)); 1057 }); 1058 } 1059 1060 void ASTDumper::VisitLabelDecl(const LabelDecl *D) { 1061 dumpName(D); 1062 } 1063 1064 void ASTDumper::VisitTypedefDecl(const TypedefDecl *D) { 1065 dumpName(D); 1066 dumpType(D->getUnderlyingType()); 1067 if (D->isModulePrivate()) 1068 OS << " __module_private__"; 1069 dumpTypeAsChild(D->getUnderlyingType()); 1070 } 1071 1072 void ASTDumper::VisitEnumDecl(const EnumDecl *D) { 1073 if (D->isScoped()) { 1074 if (D->isScopedUsingClassTag()) 1075 OS << " class"; 1076 else 1077 OS << " struct"; 1078 } 1079 dumpName(D); 1080 if (D->isModulePrivate()) 1081 OS << " __module_private__"; 1082 if (D->isFixed()) 1083 dumpType(D->getIntegerType()); 1084 } 1085 1086 void ASTDumper::VisitRecordDecl(const RecordDecl *D) { 1087 OS << ' ' << D->getKindName(); 1088 dumpName(D); 1089 if (D->isModulePrivate()) 1090 OS << " __module_private__"; 1091 if (D->isCompleteDefinition()) 1092 OS << " definition"; 1093 } 1094 1095 void ASTDumper::VisitEnumConstantDecl(const EnumConstantDecl *D) { 1096 dumpName(D); 1097 dumpType(D->getType()); 1098 if (const Expr *Init = D->getInitExpr()) 1099 dumpStmt(Init); 1100 } 1101 1102 void ASTDumper::VisitIndirectFieldDecl(const IndirectFieldDecl *D) { 1103 dumpName(D); 1104 dumpType(D->getType()); 1105 1106 for (auto *Child : D->chain()) 1107 dumpDeclRef(Child); 1108 } 1109 1110 void ASTDumper::VisitFunctionDecl(const FunctionDecl *D) { 1111 dumpName(D); 1112 dumpType(D->getType()); 1113 1114 StorageClass SC = D->getStorageClass(); 1115 if (SC != SC_None) 1116 OS << ' ' << VarDecl::getStorageClassSpecifierString(SC); 1117 if (D->isInlineSpecified()) 1118 OS << " inline"; 1119 if (D->isVirtualAsWritten()) 1120 OS << " virtual"; 1121 if (D->isModulePrivate()) 1122 OS << " __module_private__"; 1123 1124 if (D->isPure()) 1125 OS << " pure"; 1126 else if (D->isDeletedAsWritten()) 1127 OS << " delete"; 1128 1129 if (const FunctionProtoType *FPT = D->getType()->getAs<FunctionProtoType>()) { 1130 FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo(); 1131 switch (EPI.ExceptionSpec.Type) { 1132 default: break; 1133 case EST_Unevaluated: 1134 OS << " noexcept-unevaluated " << EPI.ExceptionSpec.SourceDecl; 1135 break; 1136 case EST_Uninstantiated: 1137 OS << " noexcept-uninstantiated " << EPI.ExceptionSpec.SourceTemplate; 1138 break; 1139 } 1140 } 1141 1142 if (const FunctionTemplateSpecializationInfo *FTSI = 1143 D->getTemplateSpecializationInfo()) 1144 dumpTemplateArgumentList(*FTSI->TemplateArguments); 1145 1146 for (ArrayRef<NamedDecl *>::iterator 1147 I = D->getDeclsInPrototypeScope().begin(), 1148 E = D->getDeclsInPrototypeScope().end(); I != E; ++I) 1149 dumpDecl(*I); 1150 1151 if (!D->param_begin() && D->getNumParams()) 1152 dumpChild([=] { OS << "<<NULL params x " << D->getNumParams() << ">>"; }); 1153 else 1154 for (FunctionDecl::param_const_iterator I = D->param_begin(), 1155 E = D->param_end(); 1156 I != E; ++I) 1157 dumpDecl(*I); 1158 1159 if (const CXXConstructorDecl *C = dyn_cast<CXXConstructorDecl>(D)) 1160 for (CXXConstructorDecl::init_const_iterator I = C->init_begin(), 1161 E = C->init_end(); 1162 I != E; ++I) 1163 dumpCXXCtorInitializer(*I); 1164 1165 if (D->doesThisDeclarationHaveABody()) 1166 dumpStmt(D->getBody()); 1167 } 1168 1169 void ASTDumper::VisitFieldDecl(const FieldDecl *D) { 1170 dumpName(D); 1171 dumpType(D->getType()); 1172 if (D->isMutable()) 1173 OS << " mutable"; 1174 if (D->isModulePrivate()) 1175 OS << " __module_private__"; 1176 1177 if (D->isBitField()) 1178 dumpStmt(D->getBitWidth()); 1179 if (Expr *Init = D->getInClassInitializer()) 1180 dumpStmt(Init); 1181 } 1182 1183 void ASTDumper::VisitVarDecl(const VarDecl *D) { 1184 dumpName(D); 1185 dumpType(D->getType()); 1186 StorageClass SC = D->getStorageClass(); 1187 if (SC != SC_None) 1188 OS << ' ' << VarDecl::getStorageClassSpecifierString(SC); 1189 switch (D->getTLSKind()) { 1190 case VarDecl::TLS_None: break; 1191 case VarDecl::TLS_Static: OS << " tls"; break; 1192 case VarDecl::TLS_Dynamic: OS << " tls_dynamic"; break; 1193 } 1194 if (D->isModulePrivate()) 1195 OS << " __module_private__"; 1196 if (D->isNRVOVariable()) 1197 OS << " nrvo"; 1198 if (D->hasInit()) { 1199 switch (D->getInitStyle()) { 1200 case VarDecl::CInit: OS << " cinit"; break; 1201 case VarDecl::CallInit: OS << " callinit"; break; 1202 case VarDecl::ListInit: OS << " listinit"; break; 1203 } 1204 dumpStmt(D->getInit()); 1205 } 1206 } 1207 1208 void ASTDumper::VisitFileScopeAsmDecl(const FileScopeAsmDecl *D) { 1209 dumpStmt(D->getAsmString()); 1210 } 1211 1212 void ASTDumper::VisitImportDecl(const ImportDecl *D) { 1213 OS << ' ' << D->getImportedModule()->getFullModuleName(); 1214 } 1215 1216 void ASTDumper::VisitPragmaCommentDecl(const PragmaCommentDecl *D) { 1217 OS << ' '; 1218 switch (D->getCommentKind()) { 1219 case PCK_Unknown: llvm_unreachable("unexpected pragma comment kind"); 1220 case PCK_Compiler: OS << "compiler"; break; 1221 case PCK_ExeStr: OS << "exestr"; break; 1222 case PCK_Lib: OS << "lib"; break; 1223 case PCK_Linker: OS << "linker"; break; 1224 case PCK_User: OS << "user"; break; 1225 } 1226 StringRef Arg = D->getArg(); 1227 if (!Arg.empty()) 1228 OS << " \"" << Arg << "\""; 1229 } 1230 1231 void ASTDumper::VisitPragmaDetectMismatchDecl( 1232 const PragmaDetectMismatchDecl *D) { 1233 OS << " \"" << D->getName() << "\" \"" << D->getValue() << "\""; 1234 } 1235 1236 void ASTDumper::VisitCapturedDecl(const CapturedDecl *D) { 1237 dumpStmt(D->getBody()); 1238 } 1239 1240 //===----------------------------------------------------------------------===// 1241 // OpenMP Declarations 1242 //===----------------------------------------------------------------------===// 1243 1244 void ASTDumper::VisitOMPThreadPrivateDecl(const OMPThreadPrivateDecl *D) { 1245 for (auto *E : D->varlists()) 1246 dumpStmt(E); 1247 } 1248 1249 void ASTDumper::VisitOMPDeclareReductionDecl(const OMPDeclareReductionDecl *D) { 1250 dumpName(D); 1251 dumpType(D->getType()); 1252 OS << " combiner"; 1253 dumpStmt(D->getCombiner()); 1254 if (auto *Initializer = D->getInitializer()) { 1255 OS << " initializer"; 1256 dumpStmt(Initializer); 1257 } 1258 } 1259 1260 void ASTDumper::VisitOMPCapturedExprDecl(const OMPCapturedExprDecl *D) { 1261 dumpName(D); 1262 dumpType(D->getType()); 1263 dumpStmt(D->getInit()); 1264 } 1265 1266 //===----------------------------------------------------------------------===// 1267 // C++ Declarations 1268 //===----------------------------------------------------------------------===// 1269 1270 void ASTDumper::VisitNamespaceDecl(const NamespaceDecl *D) { 1271 dumpName(D); 1272 if (D->isInline()) 1273 OS << " inline"; 1274 if (!D->isOriginalNamespace()) 1275 dumpDeclRef(D->getOriginalNamespace(), "original"); 1276 } 1277 1278 void ASTDumper::VisitUsingDirectiveDecl(const UsingDirectiveDecl *D) { 1279 OS << ' '; 1280 dumpBareDeclRef(D->getNominatedNamespace()); 1281 } 1282 1283 void ASTDumper::VisitNamespaceAliasDecl(const NamespaceAliasDecl *D) { 1284 dumpName(D); 1285 dumpDeclRef(D->getAliasedNamespace()); 1286 } 1287 1288 void ASTDumper::VisitTypeAliasDecl(const TypeAliasDecl *D) { 1289 dumpName(D); 1290 dumpType(D->getUnderlyingType()); 1291 dumpTypeAsChild(D->getUnderlyingType()); 1292 } 1293 1294 void ASTDumper::VisitTypeAliasTemplateDecl(const TypeAliasTemplateDecl *D) { 1295 dumpName(D); 1296 dumpTemplateParameters(D->getTemplateParameters()); 1297 dumpDecl(D->getTemplatedDecl()); 1298 } 1299 1300 void ASTDumper::VisitCXXRecordDecl(const CXXRecordDecl *D) { 1301 VisitRecordDecl(D); 1302 if (!D->isCompleteDefinition()) 1303 return; 1304 1305 for (const auto &I : D->bases()) { 1306 dumpChild([=] { 1307 if (I.isVirtual()) 1308 OS << "virtual "; 1309 dumpAccessSpecifier(I.getAccessSpecifier()); 1310 dumpType(I.getType()); 1311 if (I.isPackExpansion()) 1312 OS << "..."; 1313 }); 1314 } 1315 } 1316 1317 void ASTDumper::VisitStaticAssertDecl(const StaticAssertDecl *D) { 1318 dumpStmt(D->getAssertExpr()); 1319 dumpStmt(D->getMessage()); 1320 } 1321 1322 template<typename SpecializationDecl> 1323 void ASTDumper::VisitTemplateDeclSpecialization(const SpecializationDecl *D, 1324 bool DumpExplicitInst, 1325 bool DumpRefOnly) { 1326 bool DumpedAny = false; 1327 for (auto *RedeclWithBadType : D->redecls()) { 1328 // FIXME: The redecls() range sometimes has elements of a less-specific 1329 // type. (In particular, ClassTemplateSpecializationDecl::redecls() gives 1330 // us TagDecls, and should give CXXRecordDecls). 1331 auto *Redecl = dyn_cast<SpecializationDecl>(RedeclWithBadType); 1332 if (!Redecl) { 1333 // Found the injected-class-name for a class template. This will be dumped 1334 // as part of its surrounding class so we don't need to dump it here. 1335 assert(isa<CXXRecordDecl>(RedeclWithBadType) && 1336 "expected an injected-class-name"); 1337 continue; 1338 } 1339 1340 switch (Redecl->getTemplateSpecializationKind()) { 1341 case TSK_ExplicitInstantiationDeclaration: 1342 case TSK_ExplicitInstantiationDefinition: 1343 if (!DumpExplicitInst) 1344 break; 1345 // Fall through. 1346 case TSK_Undeclared: 1347 case TSK_ImplicitInstantiation: 1348 if (DumpRefOnly) 1349 dumpDeclRef(Redecl); 1350 else 1351 dumpDecl(Redecl); 1352 DumpedAny = true; 1353 break; 1354 case TSK_ExplicitSpecialization: 1355 break; 1356 } 1357 } 1358 1359 // Ensure we dump at least one decl for each specialization. 1360 if (!DumpedAny) 1361 dumpDeclRef(D); 1362 } 1363 1364 template<typename TemplateDecl> 1365 void ASTDumper::VisitTemplateDecl(const TemplateDecl *D, 1366 bool DumpExplicitInst) { 1367 dumpName(D); 1368 dumpTemplateParameters(D->getTemplateParameters()); 1369 1370 dumpDecl(D->getTemplatedDecl()); 1371 1372 for (auto *Child : D->specializations()) 1373 VisitTemplateDeclSpecialization(Child, DumpExplicitInst, 1374 !D->isCanonicalDecl()); 1375 } 1376 1377 void ASTDumper::VisitFunctionTemplateDecl(const FunctionTemplateDecl *D) { 1378 // FIXME: We don't add a declaration of a function template specialization 1379 // to its context when it's explicitly instantiated, so dump explicit 1380 // instantiations when we dump the template itself. 1381 VisitTemplateDecl(D, true); 1382 } 1383 1384 void ASTDumper::VisitClassTemplateDecl(const ClassTemplateDecl *D) { 1385 VisitTemplateDecl(D, false); 1386 } 1387 1388 void ASTDumper::VisitClassTemplateSpecializationDecl( 1389 const ClassTemplateSpecializationDecl *D) { 1390 VisitCXXRecordDecl(D); 1391 dumpTemplateArgumentList(D->getTemplateArgs()); 1392 } 1393 1394 void ASTDumper::VisitClassTemplatePartialSpecializationDecl( 1395 const ClassTemplatePartialSpecializationDecl *D) { 1396 VisitClassTemplateSpecializationDecl(D); 1397 dumpTemplateParameters(D->getTemplateParameters()); 1398 } 1399 1400 void ASTDumper::VisitClassScopeFunctionSpecializationDecl( 1401 const ClassScopeFunctionSpecializationDecl *D) { 1402 dumpDeclRef(D->getSpecialization()); 1403 if (D->hasExplicitTemplateArgs()) 1404 dumpTemplateArgumentListInfo(D->templateArgs()); 1405 } 1406 1407 void ASTDumper::VisitVarTemplateDecl(const VarTemplateDecl *D) { 1408 VisitTemplateDecl(D, false); 1409 } 1410 1411 void ASTDumper::VisitBuiltinTemplateDecl(const BuiltinTemplateDecl *D) { 1412 dumpName(D); 1413 dumpTemplateParameters(D->getTemplateParameters()); 1414 } 1415 1416 void ASTDumper::VisitVarTemplateSpecializationDecl( 1417 const VarTemplateSpecializationDecl *D) { 1418 dumpTemplateArgumentList(D->getTemplateArgs()); 1419 VisitVarDecl(D); 1420 } 1421 1422 void ASTDumper::VisitVarTemplatePartialSpecializationDecl( 1423 const VarTemplatePartialSpecializationDecl *D) { 1424 dumpTemplateParameters(D->getTemplateParameters()); 1425 VisitVarTemplateSpecializationDecl(D); 1426 } 1427 1428 void ASTDumper::VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D) { 1429 if (D->wasDeclaredWithTypename()) 1430 OS << " typename"; 1431 else 1432 OS << " class"; 1433 if (D->isParameterPack()) 1434 OS << " ..."; 1435 dumpName(D); 1436 if (D->hasDefaultArgument()) 1437 dumpTemplateArgument(D->getDefaultArgument()); 1438 } 1439 1440 void ASTDumper::VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D) { 1441 dumpType(D->getType()); 1442 if (D->isParameterPack()) 1443 OS << " ..."; 1444 dumpName(D); 1445 if (D->hasDefaultArgument()) 1446 dumpTemplateArgument(D->getDefaultArgument()); 1447 } 1448 1449 void ASTDumper::VisitTemplateTemplateParmDecl( 1450 const TemplateTemplateParmDecl *D) { 1451 if (D->isParameterPack()) 1452 OS << " ..."; 1453 dumpName(D); 1454 dumpTemplateParameters(D->getTemplateParameters()); 1455 if (D->hasDefaultArgument()) 1456 dumpTemplateArgumentLoc(D->getDefaultArgument()); 1457 } 1458 1459 void ASTDumper::VisitUsingDecl(const UsingDecl *D) { 1460 OS << ' '; 1461 if (D->getQualifier()) 1462 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy()); 1463 OS << D->getNameAsString(); 1464 } 1465 1466 void ASTDumper::VisitUnresolvedUsingTypenameDecl( 1467 const UnresolvedUsingTypenameDecl *D) { 1468 OS << ' '; 1469 if (D->getQualifier()) 1470 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy()); 1471 OS << D->getNameAsString(); 1472 } 1473 1474 void ASTDumper::VisitUnresolvedUsingValueDecl(const UnresolvedUsingValueDecl *D) { 1475 OS << ' '; 1476 if (D->getQualifier()) 1477 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy()); 1478 OS << D->getNameAsString(); 1479 dumpType(D->getType()); 1480 } 1481 1482 void ASTDumper::VisitUsingShadowDecl(const UsingShadowDecl *D) { 1483 OS << ' '; 1484 dumpBareDeclRef(D->getTargetDecl()); 1485 if (auto *TD = dyn_cast<TypeDecl>(D->getUnderlyingDecl())) 1486 dumpTypeAsChild(TD->getTypeForDecl()); 1487 } 1488 1489 void ASTDumper::VisitLinkageSpecDecl(const LinkageSpecDecl *D) { 1490 switch (D->getLanguage()) { 1491 case LinkageSpecDecl::lang_c: OS << " C"; break; 1492 case LinkageSpecDecl::lang_cxx: OS << " C++"; break; 1493 } 1494 } 1495 1496 void ASTDumper::VisitAccessSpecDecl(const AccessSpecDecl *D) { 1497 OS << ' '; 1498 dumpAccessSpecifier(D->getAccess()); 1499 } 1500 1501 void ASTDumper::VisitFriendDecl(const FriendDecl *D) { 1502 if (TypeSourceInfo *T = D->getFriendType()) 1503 dumpType(T->getType()); 1504 else 1505 dumpDecl(D->getFriendDecl()); 1506 } 1507 1508 //===----------------------------------------------------------------------===// 1509 // Obj-C Declarations 1510 //===----------------------------------------------------------------------===// 1511 1512 void ASTDumper::VisitObjCIvarDecl(const ObjCIvarDecl *D) { 1513 dumpName(D); 1514 dumpType(D->getType()); 1515 if (D->getSynthesize()) 1516 OS << " synthesize"; 1517 1518 switch (D->getAccessControl()) { 1519 case ObjCIvarDecl::None: 1520 OS << " none"; 1521 break; 1522 case ObjCIvarDecl::Private: 1523 OS << " private"; 1524 break; 1525 case ObjCIvarDecl::Protected: 1526 OS << " protected"; 1527 break; 1528 case ObjCIvarDecl::Public: 1529 OS << " public"; 1530 break; 1531 case ObjCIvarDecl::Package: 1532 OS << " package"; 1533 break; 1534 } 1535 } 1536 1537 void ASTDumper::VisitObjCMethodDecl(const ObjCMethodDecl *D) { 1538 if (D->isInstanceMethod()) 1539 OS << " -"; 1540 else 1541 OS << " +"; 1542 dumpName(D); 1543 dumpType(D->getReturnType()); 1544 1545 if (D->isThisDeclarationADefinition()) { 1546 dumpDeclContext(D); 1547 } else { 1548 for (ObjCMethodDecl::param_const_iterator I = D->param_begin(), 1549 E = D->param_end(); 1550 I != E; ++I) 1551 dumpDecl(*I); 1552 } 1553 1554 if (D->isVariadic()) 1555 dumpChild([=] { OS << "..."; }); 1556 1557 if (D->hasBody()) 1558 dumpStmt(D->getBody()); 1559 } 1560 1561 void ASTDumper::VisitObjCTypeParamDecl(const ObjCTypeParamDecl *D) { 1562 dumpName(D); 1563 switch (D->getVariance()) { 1564 case ObjCTypeParamVariance::Invariant: 1565 break; 1566 1567 case ObjCTypeParamVariance::Covariant: 1568 OS << " covariant"; 1569 break; 1570 1571 case ObjCTypeParamVariance::Contravariant: 1572 OS << " contravariant"; 1573 break; 1574 } 1575 1576 if (D->hasExplicitBound()) 1577 OS << " bounded"; 1578 dumpType(D->getUnderlyingType()); 1579 } 1580 1581 void ASTDumper::VisitObjCCategoryDecl(const ObjCCategoryDecl *D) { 1582 dumpName(D); 1583 dumpDeclRef(D->getClassInterface()); 1584 dumpObjCTypeParamList(D->getTypeParamList()); 1585 dumpDeclRef(D->getImplementation()); 1586 for (ObjCCategoryDecl::protocol_iterator I = D->protocol_begin(), 1587 E = D->protocol_end(); 1588 I != E; ++I) 1589 dumpDeclRef(*I); 1590 } 1591 1592 void ASTDumper::VisitObjCCategoryImplDecl(const ObjCCategoryImplDecl *D) { 1593 dumpName(D); 1594 dumpDeclRef(D->getClassInterface()); 1595 dumpDeclRef(D->getCategoryDecl()); 1596 } 1597 1598 void ASTDumper::VisitObjCProtocolDecl(const ObjCProtocolDecl *D) { 1599 dumpName(D); 1600 1601 for (auto *Child : D->protocols()) 1602 dumpDeclRef(Child); 1603 } 1604 1605 void ASTDumper::VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D) { 1606 dumpName(D); 1607 dumpObjCTypeParamList(D->getTypeParamListAsWritten()); 1608 dumpDeclRef(D->getSuperClass(), "super"); 1609 1610 dumpDeclRef(D->getImplementation()); 1611 for (auto *Child : D->protocols()) 1612 dumpDeclRef(Child); 1613 } 1614 1615 void ASTDumper::VisitObjCImplementationDecl(const ObjCImplementationDecl *D) { 1616 dumpName(D); 1617 dumpDeclRef(D->getSuperClass(), "super"); 1618 dumpDeclRef(D->getClassInterface()); 1619 for (ObjCImplementationDecl::init_const_iterator I = D->init_begin(), 1620 E = D->init_end(); 1621 I != E; ++I) 1622 dumpCXXCtorInitializer(*I); 1623 } 1624 1625 void ASTDumper::VisitObjCCompatibleAliasDecl(const ObjCCompatibleAliasDecl *D) { 1626 dumpName(D); 1627 dumpDeclRef(D->getClassInterface()); 1628 } 1629 1630 void ASTDumper::VisitObjCPropertyDecl(const ObjCPropertyDecl *D) { 1631 dumpName(D); 1632 dumpType(D->getType()); 1633 1634 if (D->getPropertyImplementation() == ObjCPropertyDecl::Required) 1635 OS << " required"; 1636 else if (D->getPropertyImplementation() == ObjCPropertyDecl::Optional) 1637 OS << " optional"; 1638 1639 ObjCPropertyDecl::PropertyAttributeKind Attrs = D->getPropertyAttributes(); 1640 if (Attrs != ObjCPropertyDecl::OBJC_PR_noattr) { 1641 if (Attrs & ObjCPropertyDecl::OBJC_PR_readonly) 1642 OS << " readonly"; 1643 if (Attrs & ObjCPropertyDecl::OBJC_PR_assign) 1644 OS << " assign"; 1645 if (Attrs & ObjCPropertyDecl::OBJC_PR_readwrite) 1646 OS << " readwrite"; 1647 if (Attrs & ObjCPropertyDecl::OBJC_PR_retain) 1648 OS << " retain"; 1649 if (Attrs & ObjCPropertyDecl::OBJC_PR_copy) 1650 OS << " copy"; 1651 if (Attrs & ObjCPropertyDecl::OBJC_PR_nonatomic) 1652 OS << " nonatomic"; 1653 if (Attrs & ObjCPropertyDecl::OBJC_PR_atomic) 1654 OS << " atomic"; 1655 if (Attrs & ObjCPropertyDecl::OBJC_PR_weak) 1656 OS << " weak"; 1657 if (Attrs & ObjCPropertyDecl::OBJC_PR_strong) 1658 OS << " strong"; 1659 if (Attrs & ObjCPropertyDecl::OBJC_PR_unsafe_unretained) 1660 OS << " unsafe_unretained"; 1661 if (Attrs & ObjCPropertyDecl::OBJC_PR_class) 1662 OS << " class"; 1663 if (Attrs & ObjCPropertyDecl::OBJC_PR_getter) 1664 dumpDeclRef(D->getGetterMethodDecl(), "getter"); 1665 if (Attrs & ObjCPropertyDecl::OBJC_PR_setter) 1666 dumpDeclRef(D->getSetterMethodDecl(), "setter"); 1667 } 1668 } 1669 1670 void ASTDumper::VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D) { 1671 dumpName(D->getPropertyDecl()); 1672 if (D->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize) 1673 OS << " synthesize"; 1674 else 1675 OS << " dynamic"; 1676 dumpDeclRef(D->getPropertyDecl()); 1677 dumpDeclRef(D->getPropertyIvarDecl()); 1678 } 1679 1680 void ASTDumper::VisitBlockDecl(const BlockDecl *D) { 1681 for (auto I : D->params()) 1682 dumpDecl(I); 1683 1684 if (D->isVariadic()) 1685 dumpChild([=]{ OS << "..."; }); 1686 1687 if (D->capturesCXXThis()) 1688 dumpChild([=]{ OS << "capture this"; }); 1689 1690 for (const auto &I : D->captures()) { 1691 dumpChild([=] { 1692 OS << "capture"; 1693 if (I.isByRef()) 1694 OS << " byref"; 1695 if (I.isNested()) 1696 OS << " nested"; 1697 if (I.getVariable()) { 1698 OS << ' '; 1699 dumpBareDeclRef(I.getVariable()); 1700 } 1701 if (I.hasCopyExpr()) 1702 dumpStmt(I.getCopyExpr()); 1703 }); 1704 } 1705 dumpStmt(D->getBody()); 1706 } 1707 1708 //===----------------------------------------------------------------------===// 1709 // Stmt dumping methods. 1710 //===----------------------------------------------------------------------===// 1711 1712 void ASTDumper::dumpStmt(const Stmt *S) { 1713 dumpChild([=] { 1714 if (!S) { 1715 ColorScope Color(*this, NullColor); 1716 OS << "<<<NULL>>>"; 1717 return; 1718 } 1719 1720 if (const DeclStmt *DS = dyn_cast<DeclStmt>(S)) { 1721 VisitDeclStmt(DS); 1722 return; 1723 } 1724 1725 ConstStmtVisitor<ASTDumper>::Visit(S); 1726 1727 for (const Stmt *SubStmt : S->children()) 1728 dumpStmt(SubStmt); 1729 }); 1730 } 1731 1732 void ASTDumper::VisitStmt(const Stmt *Node) { 1733 { 1734 ColorScope Color(*this, StmtColor); 1735 OS << Node->getStmtClassName(); 1736 } 1737 dumpPointer(Node); 1738 dumpSourceRange(Node->getSourceRange()); 1739 } 1740 1741 void ASTDumper::VisitDeclStmt(const DeclStmt *Node) { 1742 VisitStmt(Node); 1743 for (DeclStmt::const_decl_iterator I = Node->decl_begin(), 1744 E = Node->decl_end(); 1745 I != E; ++I) 1746 dumpDecl(*I); 1747 } 1748 1749 void ASTDumper::VisitAttributedStmt(const AttributedStmt *Node) { 1750 VisitStmt(Node); 1751 for (ArrayRef<const Attr *>::iterator I = Node->getAttrs().begin(), 1752 E = Node->getAttrs().end(); 1753 I != E; ++I) 1754 dumpAttr(*I); 1755 } 1756 1757 void ASTDumper::VisitLabelStmt(const LabelStmt *Node) { 1758 VisitStmt(Node); 1759 OS << " '" << Node->getName() << "'"; 1760 } 1761 1762 void ASTDumper::VisitGotoStmt(const GotoStmt *Node) { 1763 VisitStmt(Node); 1764 OS << " '" << Node->getLabel()->getName() << "'"; 1765 dumpPointer(Node->getLabel()); 1766 } 1767 1768 void ASTDumper::VisitCXXCatchStmt(const CXXCatchStmt *Node) { 1769 VisitStmt(Node); 1770 dumpDecl(Node->getExceptionDecl()); 1771 } 1772 1773 void ASTDumper::VisitCapturedStmt(const CapturedStmt *Node) { 1774 VisitStmt(Node); 1775 dumpDecl(Node->getCapturedDecl()); 1776 } 1777 1778 //===----------------------------------------------------------------------===// 1779 // OpenMP dumping methods. 1780 //===----------------------------------------------------------------------===// 1781 1782 void ASTDumper::VisitOMPExecutableDirective( 1783 const OMPExecutableDirective *Node) { 1784 VisitStmt(Node); 1785 for (auto *C : Node->clauses()) { 1786 dumpChild([=] { 1787 if (!C) { 1788 ColorScope Color(*this, NullColor); 1789 OS << "<<<NULL>>> OMPClause"; 1790 return; 1791 } 1792 { 1793 ColorScope Color(*this, AttrColor); 1794 StringRef ClauseName(getOpenMPClauseName(C->getClauseKind())); 1795 OS << "OMP" << ClauseName.substr(/*Start=*/0, /*N=*/1).upper() 1796 << ClauseName.drop_front() << "Clause"; 1797 } 1798 dumpPointer(C); 1799 dumpSourceRange(SourceRange(C->getLocStart(), C->getLocEnd())); 1800 if (C->isImplicit()) 1801 OS << " <implicit>"; 1802 for (auto *S : C->children()) 1803 dumpStmt(S); 1804 }); 1805 } 1806 } 1807 1808 //===----------------------------------------------------------------------===// 1809 // Expr dumping methods. 1810 //===----------------------------------------------------------------------===// 1811 1812 void ASTDumper::VisitExpr(const Expr *Node) { 1813 VisitStmt(Node); 1814 dumpType(Node->getType()); 1815 1816 { 1817 ColorScope Color(*this, ValueKindColor); 1818 switch (Node->getValueKind()) { 1819 case VK_RValue: 1820 break; 1821 case VK_LValue: 1822 OS << " lvalue"; 1823 break; 1824 case VK_XValue: 1825 OS << " xvalue"; 1826 break; 1827 } 1828 } 1829 1830 { 1831 ColorScope Color(*this, ObjectKindColor); 1832 switch (Node->getObjectKind()) { 1833 case OK_Ordinary: 1834 break; 1835 case OK_BitField: 1836 OS << " bitfield"; 1837 break; 1838 case OK_ObjCProperty: 1839 OS << " objcproperty"; 1840 break; 1841 case OK_ObjCSubscript: 1842 OS << " objcsubscript"; 1843 break; 1844 case OK_VectorComponent: 1845 OS << " vectorcomponent"; 1846 break; 1847 } 1848 } 1849 } 1850 1851 static void dumpBasePath(raw_ostream &OS, const CastExpr *Node) { 1852 if (Node->path_empty()) 1853 return; 1854 1855 OS << " ("; 1856 bool First = true; 1857 for (CastExpr::path_const_iterator I = Node->path_begin(), 1858 E = Node->path_end(); 1859 I != E; ++I) { 1860 const CXXBaseSpecifier *Base = *I; 1861 if (!First) 1862 OS << " -> "; 1863 1864 const CXXRecordDecl *RD = 1865 cast<CXXRecordDecl>(Base->getType()->getAs<RecordType>()->getDecl()); 1866 1867 if (Base->isVirtual()) 1868 OS << "virtual "; 1869 OS << RD->getName(); 1870 First = false; 1871 } 1872 1873 OS << ')'; 1874 } 1875 1876 void ASTDumper::VisitCastExpr(const CastExpr *Node) { 1877 VisitExpr(Node); 1878 OS << " <"; 1879 { 1880 ColorScope Color(*this, CastColor); 1881 OS << Node->getCastKindName(); 1882 } 1883 dumpBasePath(OS, Node); 1884 OS << ">"; 1885 } 1886 1887 void ASTDumper::VisitDeclRefExpr(const DeclRefExpr *Node) { 1888 VisitExpr(Node); 1889 1890 OS << " "; 1891 dumpBareDeclRef(Node->getDecl()); 1892 if (Node->getDecl() != Node->getFoundDecl()) { 1893 OS << " ("; 1894 dumpBareDeclRef(Node->getFoundDecl()); 1895 OS << ")"; 1896 } 1897 } 1898 1899 void ASTDumper::VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *Node) { 1900 VisitExpr(Node); 1901 OS << " ("; 1902 if (!Node->requiresADL()) 1903 OS << "no "; 1904 OS << "ADL) = '" << Node->getName() << '\''; 1905 1906 UnresolvedLookupExpr::decls_iterator 1907 I = Node->decls_begin(), E = Node->decls_end(); 1908 if (I == E) 1909 OS << " empty"; 1910 for (; I != E; ++I) 1911 dumpPointer(*I); 1912 } 1913 1914 void ASTDumper::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *Node) { 1915 VisitExpr(Node); 1916 1917 { 1918 ColorScope Color(*this, DeclKindNameColor); 1919 OS << " " << Node->getDecl()->getDeclKindName() << "Decl"; 1920 } 1921 OS << "='" << *Node->getDecl() << "'"; 1922 dumpPointer(Node->getDecl()); 1923 if (Node->isFreeIvar()) 1924 OS << " isFreeIvar"; 1925 } 1926 1927 void ASTDumper::VisitPredefinedExpr(const PredefinedExpr *Node) { 1928 VisitExpr(Node); 1929 OS << " " << PredefinedExpr::getIdentTypeName(Node->getIdentType()); 1930 } 1931 1932 void ASTDumper::VisitCharacterLiteral(const CharacterLiteral *Node) { 1933 VisitExpr(Node); 1934 ColorScope Color(*this, ValueColor); 1935 OS << " " << Node->getValue(); 1936 } 1937 1938 void ASTDumper::VisitIntegerLiteral(const IntegerLiteral *Node) { 1939 VisitExpr(Node); 1940 1941 bool isSigned = Node->getType()->isSignedIntegerType(); 1942 ColorScope Color(*this, ValueColor); 1943 OS << " " << Node->getValue().toString(10, isSigned); 1944 } 1945 1946 void ASTDumper::VisitFloatingLiteral(const FloatingLiteral *Node) { 1947 VisitExpr(Node); 1948 ColorScope Color(*this, ValueColor); 1949 OS << " " << Node->getValueAsApproximateDouble(); 1950 } 1951 1952 void ASTDumper::VisitStringLiteral(const StringLiteral *Str) { 1953 VisitExpr(Str); 1954 ColorScope Color(*this, ValueColor); 1955 OS << " "; 1956 Str->outputString(OS); 1957 } 1958 1959 void ASTDumper::VisitInitListExpr(const InitListExpr *ILE) { 1960 VisitExpr(ILE); 1961 if (auto *Filler = ILE->getArrayFiller()) { 1962 dumpChild([=] { 1963 OS << "array filler"; 1964 dumpStmt(Filler); 1965 }); 1966 } 1967 if (auto *Field = ILE->getInitializedFieldInUnion()) { 1968 OS << " field "; 1969 dumpBareDeclRef(Field); 1970 } 1971 } 1972 1973 void ASTDumper::VisitUnaryOperator(const UnaryOperator *Node) { 1974 VisitExpr(Node); 1975 OS << " " << (Node->isPostfix() ? "postfix" : "prefix") 1976 << " '" << UnaryOperator::getOpcodeStr(Node->getOpcode()) << "'"; 1977 } 1978 1979 void ASTDumper::VisitUnaryExprOrTypeTraitExpr( 1980 const UnaryExprOrTypeTraitExpr *Node) { 1981 VisitExpr(Node); 1982 switch(Node->getKind()) { 1983 case UETT_SizeOf: 1984 OS << " sizeof"; 1985 break; 1986 case UETT_AlignOf: 1987 OS << " alignof"; 1988 break; 1989 case UETT_VecStep: 1990 OS << " vec_step"; 1991 break; 1992 case UETT_OpenMPRequiredSimdAlign: 1993 OS << " __builtin_omp_required_simd_align"; 1994 break; 1995 } 1996 if (Node->isArgumentType()) 1997 dumpType(Node->getArgumentType()); 1998 } 1999 2000 void ASTDumper::VisitMemberExpr(const MemberExpr *Node) { 2001 VisitExpr(Node); 2002 OS << " " << (Node->isArrow() ? "->" : ".") << *Node->getMemberDecl(); 2003 dumpPointer(Node->getMemberDecl()); 2004 } 2005 2006 void ASTDumper::VisitExtVectorElementExpr(const ExtVectorElementExpr *Node) { 2007 VisitExpr(Node); 2008 OS << " " << Node->getAccessor().getNameStart(); 2009 } 2010 2011 void ASTDumper::VisitBinaryOperator(const BinaryOperator *Node) { 2012 VisitExpr(Node); 2013 OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode()) << "'"; 2014 } 2015 2016 void ASTDumper::VisitCompoundAssignOperator( 2017 const CompoundAssignOperator *Node) { 2018 VisitExpr(Node); 2019 OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode()) 2020 << "' ComputeLHSTy="; 2021 dumpBareType(Node->getComputationLHSType()); 2022 OS << " ComputeResultTy="; 2023 dumpBareType(Node->getComputationResultType()); 2024 } 2025 2026 void ASTDumper::VisitBlockExpr(const BlockExpr *Node) { 2027 VisitExpr(Node); 2028 dumpDecl(Node->getBlockDecl()); 2029 } 2030 2031 void ASTDumper::VisitOpaqueValueExpr(const OpaqueValueExpr *Node) { 2032 VisitExpr(Node); 2033 2034 if (Expr *Source = Node->getSourceExpr()) 2035 dumpStmt(Source); 2036 } 2037 2038 // GNU extensions. 2039 2040 void ASTDumper::VisitAddrLabelExpr(const AddrLabelExpr *Node) { 2041 VisitExpr(Node); 2042 OS << " " << Node->getLabel()->getName(); 2043 dumpPointer(Node->getLabel()); 2044 } 2045 2046 //===----------------------------------------------------------------------===// 2047 // C++ Expressions 2048 //===----------------------------------------------------------------------===// 2049 2050 void ASTDumper::VisitCXXNamedCastExpr(const CXXNamedCastExpr *Node) { 2051 VisitExpr(Node); 2052 OS << " " << Node->getCastName() 2053 << "<" << Node->getTypeAsWritten().getAsString() << ">" 2054 << " <" << Node->getCastKindName(); 2055 dumpBasePath(OS, Node); 2056 OS << ">"; 2057 } 2058 2059 void ASTDumper::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *Node) { 2060 VisitExpr(Node); 2061 OS << " " << (Node->getValue() ? "true" : "false"); 2062 } 2063 2064 void ASTDumper::VisitCXXThisExpr(const CXXThisExpr *Node) { 2065 VisitExpr(Node); 2066 OS << " this"; 2067 } 2068 2069 void ASTDumper::VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *Node) { 2070 VisitExpr(Node); 2071 OS << " functional cast to " << Node->getTypeAsWritten().getAsString() 2072 << " <" << Node->getCastKindName() << ">"; 2073 } 2074 2075 void ASTDumper::VisitCXXConstructExpr(const CXXConstructExpr *Node) { 2076 VisitExpr(Node); 2077 CXXConstructorDecl *Ctor = Node->getConstructor(); 2078 dumpType(Ctor->getType()); 2079 if (Node->isElidable()) 2080 OS << " elidable"; 2081 if (Node->requiresZeroInitialization()) 2082 OS << " zeroing"; 2083 } 2084 2085 void ASTDumper::VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *Node) { 2086 VisitExpr(Node); 2087 OS << " "; 2088 dumpCXXTemporary(Node->getTemporary()); 2089 } 2090 2091 void ASTDumper::VisitCXXNewExpr(const CXXNewExpr *Node) { 2092 VisitExpr(Node); 2093 if (Node->isGlobalNew()) 2094 OS << " global"; 2095 if (Node->isArray()) 2096 OS << " array"; 2097 if (Node->getOperatorNew()) { 2098 OS << ' '; 2099 dumpBareDeclRef(Node->getOperatorNew()); 2100 } 2101 // We could dump the deallocation function used in case of error, but it's 2102 // usually not that interesting. 2103 } 2104 2105 void ASTDumper::VisitCXXDeleteExpr(const CXXDeleteExpr *Node) { 2106 VisitExpr(Node); 2107 if (Node->isGlobalDelete()) 2108 OS << " global"; 2109 if (Node->isArrayForm()) 2110 OS << " array"; 2111 if (Node->getOperatorDelete()) { 2112 OS << ' '; 2113 dumpBareDeclRef(Node->getOperatorDelete()); 2114 } 2115 } 2116 2117 void 2118 ASTDumper::VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *Node) { 2119 VisitExpr(Node); 2120 if (const ValueDecl *VD = Node->getExtendingDecl()) { 2121 OS << " extended by "; 2122 dumpBareDeclRef(VD); 2123 } 2124 } 2125 2126 void ASTDumper::VisitExprWithCleanups(const ExprWithCleanups *Node) { 2127 VisitExpr(Node); 2128 for (unsigned i = 0, e = Node->getNumObjects(); i != e; ++i) 2129 dumpDeclRef(Node->getObject(i), "cleanup"); 2130 } 2131 2132 void ASTDumper::dumpCXXTemporary(const CXXTemporary *Temporary) { 2133 OS << "(CXXTemporary"; 2134 dumpPointer(Temporary); 2135 OS << ")"; 2136 } 2137 2138 void ASTDumper::VisitSizeOfPackExpr(const SizeOfPackExpr *Node) { 2139 VisitExpr(Node); 2140 dumpPointer(Node->getPack()); 2141 dumpName(Node->getPack()); 2142 if (Node->isPartiallySubstituted()) 2143 for (const auto &A : Node->getPartialArguments()) 2144 dumpTemplateArgument(A); 2145 } 2146 2147 2148 //===----------------------------------------------------------------------===// 2149 // Obj-C Expressions 2150 //===----------------------------------------------------------------------===// 2151 2152 void ASTDumper::VisitObjCMessageExpr(const ObjCMessageExpr *Node) { 2153 VisitExpr(Node); 2154 OS << " selector="; 2155 Node->getSelector().print(OS); 2156 switch (Node->getReceiverKind()) { 2157 case ObjCMessageExpr::Instance: 2158 break; 2159 2160 case ObjCMessageExpr::Class: 2161 OS << " class="; 2162 dumpBareType(Node->getClassReceiver()); 2163 break; 2164 2165 case ObjCMessageExpr::SuperInstance: 2166 OS << " super (instance)"; 2167 break; 2168 2169 case ObjCMessageExpr::SuperClass: 2170 OS << " super (class)"; 2171 break; 2172 } 2173 } 2174 2175 void ASTDumper::VisitObjCBoxedExpr(const ObjCBoxedExpr *Node) { 2176 VisitExpr(Node); 2177 OS << " selector="; 2178 Node->getBoxingMethod()->getSelector().print(OS); 2179 } 2180 2181 void ASTDumper::VisitObjCAtCatchStmt(const ObjCAtCatchStmt *Node) { 2182 VisitStmt(Node); 2183 if (const VarDecl *CatchParam = Node->getCatchParamDecl()) 2184 dumpDecl(CatchParam); 2185 else 2186 OS << " catch all"; 2187 } 2188 2189 void ASTDumper::VisitObjCEncodeExpr(const ObjCEncodeExpr *Node) { 2190 VisitExpr(Node); 2191 dumpType(Node->getEncodedType()); 2192 } 2193 2194 void ASTDumper::VisitObjCSelectorExpr(const ObjCSelectorExpr *Node) { 2195 VisitExpr(Node); 2196 2197 OS << " "; 2198 Node->getSelector().print(OS); 2199 } 2200 2201 void ASTDumper::VisitObjCProtocolExpr(const ObjCProtocolExpr *Node) { 2202 VisitExpr(Node); 2203 2204 OS << ' ' << *Node->getProtocol(); 2205 } 2206 2207 void ASTDumper::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *Node) { 2208 VisitExpr(Node); 2209 if (Node->isImplicitProperty()) { 2210 OS << " Kind=MethodRef Getter=\""; 2211 if (Node->getImplicitPropertyGetter()) 2212 Node->getImplicitPropertyGetter()->getSelector().print(OS); 2213 else 2214 OS << "(null)"; 2215 2216 OS << "\" Setter=\""; 2217 if (ObjCMethodDecl *Setter = Node->getImplicitPropertySetter()) 2218 Setter->getSelector().print(OS); 2219 else 2220 OS << "(null)"; 2221 OS << "\""; 2222 } else { 2223 OS << " Kind=PropertyRef Property=\"" << *Node->getExplicitProperty() <<'"'; 2224 } 2225 2226 if (Node->isSuperReceiver()) 2227 OS << " super"; 2228 2229 OS << " Messaging="; 2230 if (Node->isMessagingGetter() && Node->isMessagingSetter()) 2231 OS << "Getter&Setter"; 2232 else if (Node->isMessagingGetter()) 2233 OS << "Getter"; 2234 else if (Node->isMessagingSetter()) 2235 OS << "Setter"; 2236 } 2237 2238 void ASTDumper::VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *Node) { 2239 VisitExpr(Node); 2240 if (Node->isArraySubscriptRefExpr()) 2241 OS << " Kind=ArraySubscript GetterForArray=\""; 2242 else 2243 OS << " Kind=DictionarySubscript GetterForDictionary=\""; 2244 if (Node->getAtIndexMethodDecl()) 2245 Node->getAtIndexMethodDecl()->getSelector().print(OS); 2246 else 2247 OS << "(null)"; 2248 2249 if (Node->isArraySubscriptRefExpr()) 2250 OS << "\" SetterForArray=\""; 2251 else 2252 OS << "\" SetterForDictionary=\""; 2253 if (Node->setAtIndexMethodDecl()) 2254 Node->setAtIndexMethodDecl()->getSelector().print(OS); 2255 else 2256 OS << "(null)"; 2257 } 2258 2259 void ASTDumper::VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *Node) { 2260 VisitExpr(Node); 2261 OS << " " << (Node->getValue() ? "__objc_yes" : "__objc_no"); 2262 } 2263 2264 //===----------------------------------------------------------------------===// 2265 // Comments 2266 //===----------------------------------------------------------------------===// 2267 2268 const char *ASTDumper::getCommandName(unsigned CommandID) { 2269 if (Traits) 2270 return Traits->getCommandInfo(CommandID)->Name; 2271 const CommandInfo *Info = CommandTraits::getBuiltinCommandInfo(CommandID); 2272 if (Info) 2273 return Info->Name; 2274 return "<not a builtin command>"; 2275 } 2276 2277 void ASTDumper::dumpFullComment(const FullComment *C) { 2278 if (!C) 2279 return; 2280 2281 FC = C; 2282 dumpComment(C); 2283 FC = nullptr; 2284 } 2285 2286 void ASTDumper::dumpComment(const Comment *C) { 2287 dumpChild([=] { 2288 if (!C) { 2289 ColorScope Color(*this, NullColor); 2290 OS << "<<<NULL>>>"; 2291 return; 2292 } 2293 2294 { 2295 ColorScope Color(*this, CommentColor); 2296 OS << C->getCommentKindName(); 2297 } 2298 dumpPointer(C); 2299 dumpSourceRange(C->getSourceRange()); 2300 ConstCommentVisitor<ASTDumper>::visit(C); 2301 for (Comment::child_iterator I = C->child_begin(), E = C->child_end(); 2302 I != E; ++I) 2303 dumpComment(*I); 2304 }); 2305 } 2306 2307 void ASTDumper::visitTextComment(const TextComment *C) { 2308 OS << " Text=\"" << C->getText() << "\""; 2309 } 2310 2311 void ASTDumper::visitInlineCommandComment(const InlineCommandComment *C) { 2312 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\""; 2313 switch (C->getRenderKind()) { 2314 case InlineCommandComment::RenderNormal: 2315 OS << " RenderNormal"; 2316 break; 2317 case InlineCommandComment::RenderBold: 2318 OS << " RenderBold"; 2319 break; 2320 case InlineCommandComment::RenderMonospaced: 2321 OS << " RenderMonospaced"; 2322 break; 2323 case InlineCommandComment::RenderEmphasized: 2324 OS << " RenderEmphasized"; 2325 break; 2326 } 2327 2328 for (unsigned i = 0, e = C->getNumArgs(); i != e; ++i) 2329 OS << " Arg[" << i << "]=\"" << C->getArgText(i) << "\""; 2330 } 2331 2332 void ASTDumper::visitHTMLStartTagComment(const HTMLStartTagComment *C) { 2333 OS << " Name=\"" << C->getTagName() << "\""; 2334 if (C->getNumAttrs() != 0) { 2335 OS << " Attrs: "; 2336 for (unsigned i = 0, e = C->getNumAttrs(); i != e; ++i) { 2337 const HTMLStartTagComment::Attribute &Attr = C->getAttr(i); 2338 OS << " \"" << Attr.Name << "=\"" << Attr.Value << "\""; 2339 } 2340 } 2341 if (C->isSelfClosing()) 2342 OS << " SelfClosing"; 2343 } 2344 2345 void ASTDumper::visitHTMLEndTagComment(const HTMLEndTagComment *C) { 2346 OS << " Name=\"" << C->getTagName() << "\""; 2347 } 2348 2349 void ASTDumper::visitBlockCommandComment(const BlockCommandComment *C) { 2350 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\""; 2351 for (unsigned i = 0, e = C->getNumArgs(); i != e; ++i) 2352 OS << " Arg[" << i << "]=\"" << C->getArgText(i) << "\""; 2353 } 2354 2355 void ASTDumper::visitParamCommandComment(const ParamCommandComment *C) { 2356 OS << " " << ParamCommandComment::getDirectionAsString(C->getDirection()); 2357 2358 if (C->isDirectionExplicit()) 2359 OS << " explicitly"; 2360 else 2361 OS << " implicitly"; 2362 2363 if (C->hasParamName()) { 2364 if (C->isParamIndexValid()) 2365 OS << " Param=\"" << C->getParamName(FC) << "\""; 2366 else 2367 OS << " Param=\"" << C->getParamNameAsWritten() << "\""; 2368 } 2369 2370 if (C->isParamIndexValid() && !C->isVarArgParam()) 2371 OS << " ParamIndex=" << C->getParamIndex(); 2372 } 2373 2374 void ASTDumper::visitTParamCommandComment(const TParamCommandComment *C) { 2375 if (C->hasParamName()) { 2376 if (C->isPositionValid()) 2377 OS << " Param=\"" << C->getParamName(FC) << "\""; 2378 else 2379 OS << " Param=\"" << C->getParamNameAsWritten() << "\""; 2380 } 2381 2382 if (C->isPositionValid()) { 2383 OS << " Position=<"; 2384 for (unsigned i = 0, e = C->getDepth(); i != e; ++i) { 2385 OS << C->getIndex(i); 2386 if (i != e - 1) 2387 OS << ", "; 2388 } 2389 OS << ">"; 2390 } 2391 } 2392 2393 void ASTDumper::visitVerbatimBlockComment(const VerbatimBlockComment *C) { 2394 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\"" 2395 " CloseName=\"" << C->getCloseName() << "\""; 2396 } 2397 2398 void ASTDumper::visitVerbatimBlockLineComment( 2399 const VerbatimBlockLineComment *C) { 2400 OS << " Text=\"" << C->getText() << "\""; 2401 } 2402 2403 void ASTDumper::visitVerbatimLineComment(const VerbatimLineComment *C) { 2404 OS << " Text=\"" << C->getText() << "\""; 2405 } 2406 2407 //===----------------------------------------------------------------------===// 2408 // Type method implementations 2409 //===----------------------------------------------------------------------===// 2410 2411 void QualType::dump(const char *msg) const { 2412 if (msg) 2413 llvm::errs() << msg << ": "; 2414 dump(); 2415 } 2416 2417 LLVM_DUMP_METHOD void QualType::dump() const { 2418 ASTDumper Dumper(llvm::errs(), nullptr, nullptr); 2419 Dumper.dumpTypeAsChild(*this); 2420 } 2421 2422 LLVM_DUMP_METHOD void Type::dump() const { QualType(this, 0).dump(); } 2423 2424 //===----------------------------------------------------------------------===// 2425 // Decl method implementations 2426 //===----------------------------------------------------------------------===// 2427 2428 LLVM_DUMP_METHOD void Decl::dump() const { dump(llvm::errs()); } 2429 2430 LLVM_DUMP_METHOD void Decl::dump(raw_ostream &OS) const { 2431 ASTDumper P(OS, &getASTContext().getCommentCommandTraits(), 2432 &getASTContext().getSourceManager()); 2433 P.dumpDecl(this); 2434 } 2435 2436 LLVM_DUMP_METHOD void Decl::dumpColor() const { 2437 ASTDumper P(llvm::errs(), &getASTContext().getCommentCommandTraits(), 2438 &getASTContext().getSourceManager(), /*ShowColors*/true); 2439 P.dumpDecl(this); 2440 } 2441 2442 LLVM_DUMP_METHOD void DeclContext::dumpLookups() const { 2443 dumpLookups(llvm::errs()); 2444 } 2445 2446 LLVM_DUMP_METHOD void DeclContext::dumpLookups(raw_ostream &OS, 2447 bool DumpDecls) const { 2448 const DeclContext *DC = this; 2449 while (!DC->isTranslationUnit()) 2450 DC = DC->getParent(); 2451 ASTContext &Ctx = cast<TranslationUnitDecl>(DC)->getASTContext(); 2452 ASTDumper P(OS, &Ctx.getCommentCommandTraits(), &Ctx.getSourceManager()); 2453 P.dumpLookups(this, DumpDecls); 2454 } 2455 2456 //===----------------------------------------------------------------------===// 2457 // Stmt method implementations 2458 //===----------------------------------------------------------------------===// 2459 2460 LLVM_DUMP_METHOD void Stmt::dump(SourceManager &SM) const { 2461 dump(llvm::errs(), SM); 2462 } 2463 2464 LLVM_DUMP_METHOD void Stmt::dump(raw_ostream &OS, SourceManager &SM) const { 2465 ASTDumper P(OS, nullptr, &SM); 2466 P.dumpStmt(this); 2467 } 2468 2469 LLVM_DUMP_METHOD void Stmt::dump(raw_ostream &OS) const { 2470 ASTDumper P(OS, nullptr, nullptr); 2471 P.dumpStmt(this); 2472 } 2473 2474 LLVM_DUMP_METHOD void Stmt::dump() const { 2475 ASTDumper P(llvm::errs(), nullptr, nullptr); 2476 P.dumpStmt(this); 2477 } 2478 2479 LLVM_DUMP_METHOD void Stmt::dumpColor() const { 2480 ASTDumper P(llvm::errs(), nullptr, nullptr, /*ShowColors*/true); 2481 P.dumpStmt(this); 2482 } 2483 2484 //===----------------------------------------------------------------------===// 2485 // Comment method implementations 2486 //===----------------------------------------------------------------------===// 2487 2488 LLVM_DUMP_METHOD void Comment::dump() const { 2489 dump(llvm::errs(), nullptr, nullptr); 2490 } 2491 2492 LLVM_DUMP_METHOD void Comment::dump(const ASTContext &Context) const { 2493 dump(llvm::errs(), &Context.getCommentCommandTraits(), 2494 &Context.getSourceManager()); 2495 } 2496 2497 void Comment::dump(raw_ostream &OS, const CommandTraits *Traits, 2498 const SourceManager *SM) const { 2499 const FullComment *FC = dyn_cast<FullComment>(this); 2500 ASTDumper D(OS, Traits, SM); 2501 D.dumpFullComment(FC); 2502 } 2503 2504 LLVM_DUMP_METHOD void Comment::dumpColor() const { 2505 const FullComment *FC = dyn_cast<FullComment>(this); 2506 ASTDumper D(llvm::errs(), nullptr, nullptr, /*ShowColors*/true); 2507 D.dumpFullComment(FC); 2508 } 2509