1 //===--- TextNodeDumper.cpp - Printing of AST nodes -----------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // This file implements AST dumping of components of individual AST nodes. 10 // 11 //===----------------------------------------------------------------------===// 12 13 #include "clang/AST/TextNodeDumper.h" 14 #include "clang/AST/APValue.h" 15 #include "clang/AST/DeclFriend.h" 16 #include "clang/AST/DeclOpenMP.h" 17 #include "clang/AST/DeclTemplate.h" 18 #include "clang/AST/LocInfoType.h" 19 #include "clang/AST/Type.h" 20 #include "clang/Basic/Module.h" 21 #include "clang/Basic/SourceManager.h" 22 #include "clang/Basic/Specifiers.h" 23 #include "clang/Basic/TypeTraits.h" 24 25 #include <algorithm> 26 #include <utility> 27 28 using namespace clang; 29 30 static void dumpPreviousDeclImpl(raw_ostream &OS, ...) {} 31 32 template <typename T> 33 static void dumpPreviousDeclImpl(raw_ostream &OS, const Mergeable<T> *D) { 34 const T *First = D->getFirstDecl(); 35 if (First != D) 36 OS << " first " << First; 37 } 38 39 template <typename T> 40 static void dumpPreviousDeclImpl(raw_ostream &OS, const Redeclarable<T> *D) { 41 const T *Prev = D->getPreviousDecl(); 42 if (Prev) 43 OS << " prev " << Prev; 44 } 45 46 /// Dump the previous declaration in the redeclaration chain for a declaration, 47 /// if any. 48 static void dumpPreviousDecl(raw_ostream &OS, const Decl *D) { 49 switch (D->getKind()) { 50 #define DECL(DERIVED, BASE) \ 51 case Decl::DERIVED: \ 52 return dumpPreviousDeclImpl(OS, cast<DERIVED##Decl>(D)); 53 #define ABSTRACT_DECL(DECL) 54 #include "clang/AST/DeclNodes.inc" 55 } 56 llvm_unreachable("Decl that isn't part of DeclNodes.inc!"); 57 } 58 59 TextNodeDumper::TextNodeDumper(raw_ostream &OS, const ASTContext &Context, 60 bool ShowColors) 61 : TextTreeStructure(OS, ShowColors), OS(OS), ShowColors(ShowColors), 62 Context(&Context), SM(&Context.getSourceManager()), 63 PrintPolicy(Context.getPrintingPolicy()), 64 Traits(&Context.getCommentCommandTraits()) {} 65 66 TextNodeDumper::TextNodeDumper(raw_ostream &OS, bool ShowColors) 67 : TextTreeStructure(OS, ShowColors), OS(OS), ShowColors(ShowColors) {} 68 69 void TextNodeDumper::Visit(const comments::Comment *C, 70 const comments::FullComment *FC) { 71 if (!C) { 72 ColorScope Color(OS, ShowColors, NullColor); 73 OS << "<<<NULL>>>"; 74 return; 75 } 76 77 { 78 ColorScope Color(OS, ShowColors, CommentColor); 79 OS << C->getCommentKindName(); 80 } 81 dumpPointer(C); 82 dumpSourceRange(C->getSourceRange()); 83 84 ConstCommentVisitor<TextNodeDumper, void, 85 const comments::FullComment *>::visit(C, FC); 86 } 87 88 void TextNodeDumper::Visit(const Attr *A) { 89 { 90 ColorScope Color(OS, ShowColors, AttrColor); 91 92 switch (A->getKind()) { 93 #define ATTR(X) \ 94 case attr::X: \ 95 OS << #X; \ 96 break; 97 #include "clang/Basic/AttrList.inc" 98 } 99 OS << "Attr"; 100 } 101 dumpPointer(A); 102 dumpSourceRange(A->getRange()); 103 if (A->isInherited()) 104 OS << " Inherited"; 105 if (A->isImplicit()) 106 OS << " Implicit"; 107 108 ConstAttrVisitor<TextNodeDumper>::Visit(A); 109 } 110 111 void TextNodeDumper::Visit(const TemplateArgument &TA, SourceRange R, 112 const Decl *From, StringRef Label) { 113 OS << "TemplateArgument"; 114 if (R.isValid()) 115 dumpSourceRange(R); 116 117 if (From) 118 dumpDeclRef(From, Label); 119 120 ConstTemplateArgumentVisitor<TextNodeDumper>::Visit(TA); 121 } 122 123 void TextNodeDumper::Visit(const Stmt *Node) { 124 if (!Node) { 125 ColorScope Color(OS, ShowColors, NullColor); 126 OS << "<<<NULL>>>"; 127 return; 128 } 129 { 130 ColorScope Color(OS, ShowColors, StmtColor); 131 OS << Node->getStmtClassName(); 132 } 133 dumpPointer(Node); 134 dumpSourceRange(Node->getSourceRange()); 135 136 if (const auto *E = dyn_cast<Expr>(Node)) { 137 dumpType(E->getType()); 138 139 if (E->containsErrors()) { 140 ColorScope Color(OS, ShowColors, ErrorsColor); 141 OS << " contains-errors"; 142 } 143 144 { 145 ColorScope Color(OS, ShowColors, ValueKindColor); 146 switch (E->getValueKind()) { 147 case VK_RValue: 148 break; 149 case VK_LValue: 150 OS << " lvalue"; 151 break; 152 case VK_XValue: 153 OS << " xvalue"; 154 break; 155 } 156 } 157 158 { 159 ColorScope Color(OS, ShowColors, ObjectKindColor); 160 switch (E->getObjectKind()) { 161 case OK_Ordinary: 162 break; 163 case OK_BitField: 164 OS << " bitfield"; 165 break; 166 case OK_ObjCProperty: 167 OS << " objcproperty"; 168 break; 169 case OK_ObjCSubscript: 170 OS << " objcsubscript"; 171 break; 172 case OK_VectorComponent: 173 OS << " vectorcomponent"; 174 break; 175 case OK_MatrixComponent: 176 OS << " matrixcomponent"; 177 break; 178 } 179 } 180 } 181 182 ConstStmtVisitor<TextNodeDumper>::Visit(Node); 183 } 184 185 void TextNodeDumper::Visit(const Type *T) { 186 if (!T) { 187 ColorScope Color(OS, ShowColors, NullColor); 188 OS << "<<<NULL>>>"; 189 return; 190 } 191 if (isa<LocInfoType>(T)) { 192 { 193 ColorScope Color(OS, ShowColors, TypeColor); 194 OS << "LocInfo Type"; 195 } 196 dumpPointer(T); 197 return; 198 } 199 200 { 201 ColorScope Color(OS, ShowColors, TypeColor); 202 OS << T->getTypeClassName() << "Type"; 203 } 204 dumpPointer(T); 205 OS << " "; 206 dumpBareType(QualType(T, 0), false); 207 208 QualType SingleStepDesugar = 209 T->getLocallyUnqualifiedSingleStepDesugaredType(); 210 if (SingleStepDesugar != QualType(T, 0)) 211 OS << " sugar"; 212 213 if (T->containsErrors()) { 214 ColorScope Color(OS, ShowColors, ErrorsColor); 215 OS << " contains-errors"; 216 } 217 218 if (T->isDependentType()) 219 OS << " dependent"; 220 else if (T->isInstantiationDependentType()) 221 OS << " instantiation_dependent"; 222 223 if (T->isVariablyModifiedType()) 224 OS << " variably_modified"; 225 if (T->containsUnexpandedParameterPack()) 226 OS << " contains_unexpanded_pack"; 227 if (T->isFromAST()) 228 OS << " imported"; 229 230 TypeVisitor<TextNodeDumper>::Visit(T); 231 } 232 233 void TextNodeDumper::Visit(QualType T) { 234 OS << "QualType"; 235 dumpPointer(T.getAsOpaquePtr()); 236 OS << " "; 237 dumpBareType(T, false); 238 OS << " " << T.split().Quals.getAsString(); 239 } 240 241 void TextNodeDumper::Visit(const Decl *D) { 242 if (!D) { 243 ColorScope Color(OS, ShowColors, NullColor); 244 OS << "<<<NULL>>>"; 245 return; 246 } 247 248 { 249 ColorScope Color(OS, ShowColors, DeclKindNameColor); 250 OS << D->getDeclKindName() << "Decl"; 251 } 252 dumpPointer(D); 253 if (D->getLexicalDeclContext() != D->getDeclContext()) 254 OS << " parent " << cast<Decl>(D->getDeclContext()); 255 dumpPreviousDecl(OS, D); 256 dumpSourceRange(D->getSourceRange()); 257 OS << ' '; 258 dumpLocation(D->getLocation()); 259 if (D->isFromASTFile()) 260 OS << " imported"; 261 if (Module *M = D->getOwningModule()) 262 OS << " in " << M->getFullModuleName(); 263 if (auto *ND = dyn_cast<NamedDecl>(D)) 264 for (Module *M : D->getASTContext().getModulesWithMergedDefinition( 265 const_cast<NamedDecl *>(ND))) 266 AddChild([=] { OS << "also in " << M->getFullModuleName(); }); 267 if (const NamedDecl *ND = dyn_cast<NamedDecl>(D)) 268 if (!ND->isUnconditionallyVisible()) 269 OS << " hidden"; 270 if (D->isImplicit()) 271 OS << " implicit"; 272 273 if (D->isUsed()) 274 OS << " used"; 275 else if (D->isThisDeclarationReferenced()) 276 OS << " referenced"; 277 278 if (D->isInvalidDecl()) 279 OS << " invalid"; 280 if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { 281 if (FD->isConstexprSpecified()) 282 OS << " constexpr"; 283 if (FD->isConsteval()) 284 OS << " consteval"; 285 } 286 287 if (!isa<FunctionDecl>(*D)) { 288 const auto *MD = dyn_cast<ObjCMethodDecl>(D); 289 if (!MD || !MD->isThisDeclarationADefinition()) { 290 const auto *DC = dyn_cast<DeclContext>(D); 291 if (DC && DC->hasExternalLexicalStorage()) { 292 ColorScope Color(OS, ShowColors, UndeserializedColor); 293 OS << " <undeserialized declarations>"; 294 } 295 } 296 } 297 298 ConstDeclVisitor<TextNodeDumper>::Visit(D); 299 } 300 301 void TextNodeDumper::Visit(const CXXCtorInitializer *Init) { 302 OS << "CXXCtorInitializer"; 303 if (Init->isAnyMemberInitializer()) { 304 OS << ' '; 305 dumpBareDeclRef(Init->getAnyMember()); 306 } else if (Init->isBaseInitializer()) { 307 dumpType(QualType(Init->getBaseClass(), 0)); 308 } else if (Init->isDelegatingInitializer()) { 309 dumpType(Init->getTypeSourceInfo()->getType()); 310 } else { 311 llvm_unreachable("Unknown initializer type"); 312 } 313 } 314 315 void TextNodeDumper::Visit(const BlockDecl::Capture &C) { 316 OS << "capture"; 317 if (C.isByRef()) 318 OS << " byref"; 319 if (C.isNested()) 320 OS << " nested"; 321 if (C.getVariable()) { 322 OS << ' '; 323 dumpBareDeclRef(C.getVariable()); 324 } 325 } 326 327 void TextNodeDumper::Visit(const OMPClause *C) { 328 if (!C) { 329 ColorScope Color(OS, ShowColors, NullColor); 330 OS << "<<<NULL>>> OMPClause"; 331 return; 332 } 333 { 334 ColorScope Color(OS, ShowColors, AttrColor); 335 StringRef ClauseName(llvm::omp::getOpenMPClauseName(C->getClauseKind())); 336 OS << "OMP" << ClauseName.substr(/*Start=*/0, /*N=*/1).upper() 337 << ClauseName.drop_front() << "Clause"; 338 } 339 dumpPointer(C); 340 dumpSourceRange(SourceRange(C->getBeginLoc(), C->getEndLoc())); 341 if (C->isImplicit()) 342 OS << " <implicit>"; 343 } 344 345 void TextNodeDumper::Visit(const GenericSelectionExpr::ConstAssociation &A) { 346 const TypeSourceInfo *TSI = A.getTypeSourceInfo(); 347 if (TSI) { 348 OS << "case "; 349 dumpType(TSI->getType()); 350 } else { 351 OS << "default"; 352 } 353 354 if (A.isSelected()) 355 OS << " selected"; 356 } 357 358 static double GetApproxValue(const llvm::APFloat &F) { 359 llvm::APFloat V = F; 360 bool ignored; 361 V.convert(llvm::APFloat::IEEEdouble(), llvm::APFloat::rmNearestTiesToEven, 362 &ignored); 363 return V.convertToDouble(); 364 } 365 366 /// True if the \p APValue \p Value can be folded onto the current line. 367 static bool isSimpleAPValue(const APValue &Value) { 368 switch (Value.getKind()) { 369 case APValue::None: 370 case APValue::Indeterminate: 371 case APValue::Int: 372 case APValue::Float: 373 case APValue::FixedPoint: 374 case APValue::ComplexInt: 375 case APValue::ComplexFloat: 376 case APValue::LValue: 377 case APValue::MemberPointer: 378 case APValue::AddrLabelDiff: 379 return true; 380 case APValue::Vector: 381 case APValue::Array: 382 case APValue::Struct: 383 return false; 384 case APValue::Union: 385 return isSimpleAPValue(Value.getUnionValue()); 386 } 387 llvm_unreachable("unexpected APValue kind!"); 388 } 389 390 /// Dump the children of the \p APValue \p Value. 391 /// 392 /// \param[in] Value The \p APValue to visit 393 /// \param[in] Ty The \p QualType passed to \p Visit 394 /// 395 /// \param[in] IdxToChildFun A function mapping an \p APValue and an index 396 /// to one of the child of the \p APValue 397 /// 398 /// \param[in] NumChildren \p IdxToChildFun will be called on \p Value with 399 /// the indices in the range \p [0,NumChildren( 400 /// 401 /// \param[in] LabelSingular The label to use on a line with a single child 402 /// \param[in] LabelPlurial The label to use on a line with multiple children 403 void TextNodeDumper::dumpAPValueChildren( 404 const APValue &Value, QualType Ty, 405 const APValue &(*IdxToChildFun)(const APValue &, unsigned), 406 unsigned NumChildren, StringRef LabelSingular, StringRef LabelPlurial) { 407 // To save some vertical space we print up to MaxChildrenPerLine APValues 408 // considered to be simple (by isSimpleAPValue) on a single line. 409 constexpr unsigned MaxChildrenPerLine = 4; 410 unsigned I = 0; 411 while (I < NumChildren) { 412 unsigned J = I; 413 while (J < NumChildren) { 414 if (isSimpleAPValue(IdxToChildFun(Value, J)) && 415 (J - I < MaxChildrenPerLine)) { 416 ++J; 417 continue; 418 } 419 break; 420 } 421 422 J = std::max(I + 1, J); 423 424 // Print [I,J) on a single line. 425 AddChild(J - I > 1 ? LabelPlurial : LabelSingular, [=]() { 426 for (unsigned X = I; X < J; ++X) { 427 Visit(IdxToChildFun(Value, X), Ty); 428 if (X + 1 != J) 429 OS << ", "; 430 } 431 }); 432 I = J; 433 } 434 } 435 436 void TextNodeDumper::Visit(const APValue &Value, QualType Ty) { 437 ColorScope Color(OS, ShowColors, ValueKindColor); 438 switch (Value.getKind()) { 439 case APValue::None: 440 OS << "None"; 441 return; 442 case APValue::Indeterminate: 443 OS << "Indeterminate"; 444 return; 445 case APValue::Int: 446 OS << "Int "; 447 { 448 ColorScope Color(OS, ShowColors, ValueColor); 449 OS << Value.getInt(); 450 } 451 return; 452 case APValue::Float: 453 OS << "Float "; 454 { 455 ColorScope Color(OS, ShowColors, ValueColor); 456 OS << GetApproxValue(Value.getFloat()); 457 } 458 return; 459 case APValue::FixedPoint: 460 OS << "FixedPoint "; 461 { 462 ColorScope Color(OS, ShowColors, ValueColor); 463 OS << Value.getFixedPoint(); 464 } 465 return; 466 case APValue::Vector: { 467 unsigned VectorLength = Value.getVectorLength(); 468 OS << "Vector length=" << VectorLength; 469 470 dumpAPValueChildren( 471 Value, Ty, 472 [](const APValue &Value, unsigned Index) -> const APValue & { 473 return Value.getVectorElt(Index); 474 }, 475 VectorLength, "element", "elements"); 476 return; 477 } 478 case APValue::ComplexInt: 479 OS << "ComplexInt "; 480 { 481 ColorScope Color(OS, ShowColors, ValueColor); 482 OS << Value.getComplexIntReal() << " + " << Value.getComplexIntImag() 483 << 'i'; 484 } 485 return; 486 case APValue::ComplexFloat: 487 OS << "ComplexFloat "; 488 { 489 ColorScope Color(OS, ShowColors, ValueColor); 490 OS << GetApproxValue(Value.getComplexFloatReal()) << " + " 491 << GetApproxValue(Value.getComplexFloatImag()) << 'i'; 492 } 493 return; 494 case APValue::LValue: 495 (void)Context; 496 OS << "LValue <todo>"; 497 return; 498 case APValue::Array: { 499 unsigned ArraySize = Value.getArraySize(); 500 unsigned NumInitializedElements = Value.getArrayInitializedElts(); 501 OS << "Array size=" << ArraySize; 502 503 dumpAPValueChildren( 504 Value, Ty, 505 [](const APValue &Value, unsigned Index) -> const APValue & { 506 return Value.getArrayInitializedElt(Index); 507 }, 508 NumInitializedElements, "element", "elements"); 509 510 if (Value.hasArrayFiller()) { 511 AddChild("filler", [=] { 512 { 513 ColorScope Color(OS, ShowColors, ValueColor); 514 OS << ArraySize - NumInitializedElements << " x "; 515 } 516 Visit(Value.getArrayFiller(), Ty); 517 }); 518 } 519 520 return; 521 } 522 case APValue::Struct: { 523 OS << "Struct"; 524 525 dumpAPValueChildren( 526 Value, Ty, 527 [](const APValue &Value, unsigned Index) -> const APValue & { 528 return Value.getStructBase(Index); 529 }, 530 Value.getStructNumBases(), "base", "bases"); 531 532 dumpAPValueChildren( 533 Value, Ty, 534 [](const APValue &Value, unsigned Index) -> const APValue & { 535 return Value.getStructField(Index); 536 }, 537 Value.getStructNumFields(), "field", "fields"); 538 539 return; 540 } 541 case APValue::Union: { 542 OS << "Union"; 543 { 544 ColorScope Color(OS, ShowColors, ValueColor); 545 if (const FieldDecl *FD = Value.getUnionField()) 546 OS << " ." << *cast<NamedDecl>(FD); 547 } 548 // If the union value is considered to be simple, fold it into the 549 // current line to save some vertical space. 550 const APValue &UnionValue = Value.getUnionValue(); 551 if (isSimpleAPValue(UnionValue)) { 552 OS << ' '; 553 Visit(UnionValue, Ty); 554 } else { 555 AddChild([=] { Visit(UnionValue, Ty); }); 556 } 557 558 return; 559 } 560 case APValue::MemberPointer: 561 OS << "MemberPointer <todo>"; 562 return; 563 case APValue::AddrLabelDiff: 564 OS << "AddrLabelDiff <todo>"; 565 return; 566 } 567 llvm_unreachable("Unknown APValue kind!"); 568 } 569 570 void TextNodeDumper::dumpPointer(const void *Ptr) { 571 ColorScope Color(OS, ShowColors, AddressColor); 572 OS << ' ' << Ptr; 573 } 574 575 void TextNodeDumper::dumpLocation(SourceLocation Loc) { 576 if (!SM) 577 return; 578 579 ColorScope Color(OS, ShowColors, LocationColor); 580 SourceLocation SpellingLoc = SM->getSpellingLoc(Loc); 581 582 // The general format we print out is filename:line:col, but we drop pieces 583 // that haven't changed since the last loc printed. 584 PresumedLoc PLoc = SM->getPresumedLoc(SpellingLoc); 585 586 if (PLoc.isInvalid()) { 587 OS << "<invalid sloc>"; 588 return; 589 } 590 591 if (strcmp(PLoc.getFilename(), LastLocFilename) != 0) { 592 OS << PLoc.getFilename() << ':' << PLoc.getLine() << ':' 593 << PLoc.getColumn(); 594 LastLocFilename = PLoc.getFilename(); 595 LastLocLine = PLoc.getLine(); 596 } else if (PLoc.getLine() != LastLocLine) { 597 OS << "line" << ':' << PLoc.getLine() << ':' << PLoc.getColumn(); 598 LastLocLine = PLoc.getLine(); 599 } else { 600 OS << "col" << ':' << PLoc.getColumn(); 601 } 602 } 603 604 void TextNodeDumper::dumpSourceRange(SourceRange R) { 605 // Can't translate locations if a SourceManager isn't available. 606 if (!SM) 607 return; 608 609 OS << " <"; 610 dumpLocation(R.getBegin()); 611 if (R.getBegin() != R.getEnd()) { 612 OS << ", "; 613 dumpLocation(R.getEnd()); 614 } 615 OS << ">"; 616 617 // <t2.c:123:421[blah], t2.c:412:321> 618 } 619 620 void TextNodeDumper::dumpBareType(QualType T, bool Desugar) { 621 ColorScope Color(OS, ShowColors, TypeColor); 622 623 SplitQualType T_split = T.split(); 624 OS << "'" << QualType::getAsString(T_split, PrintPolicy) << "'"; 625 626 if (Desugar && !T.isNull()) { 627 // If the type is sugared, also dump a (shallow) desugared type. 628 SplitQualType D_split = T.getSplitDesugaredType(); 629 if (T_split != D_split) 630 OS << ":'" << QualType::getAsString(D_split, PrintPolicy) << "'"; 631 } 632 } 633 634 void TextNodeDumper::dumpType(QualType T) { 635 OS << ' '; 636 dumpBareType(T); 637 } 638 639 void TextNodeDumper::dumpBareDeclRef(const Decl *D) { 640 if (!D) { 641 ColorScope Color(OS, ShowColors, NullColor); 642 OS << "<<<NULL>>>"; 643 return; 644 } 645 646 { 647 ColorScope Color(OS, ShowColors, DeclKindNameColor); 648 OS << D->getDeclKindName(); 649 } 650 dumpPointer(D); 651 652 if (const NamedDecl *ND = dyn_cast<NamedDecl>(D)) { 653 ColorScope Color(OS, ShowColors, DeclNameColor); 654 OS << " '" << ND->getDeclName() << '\''; 655 } 656 657 if (const ValueDecl *VD = dyn_cast<ValueDecl>(D)) 658 dumpType(VD->getType()); 659 } 660 661 void TextNodeDumper::dumpName(const NamedDecl *ND) { 662 if (ND->getDeclName()) { 663 ColorScope Color(OS, ShowColors, DeclNameColor); 664 OS << ' ' << ND->getDeclName(); 665 } 666 } 667 668 void TextNodeDumper::dumpAccessSpecifier(AccessSpecifier AS) { 669 const auto AccessSpelling = getAccessSpelling(AS); 670 if (AccessSpelling.empty()) 671 return; 672 OS << AccessSpelling; 673 } 674 675 void TextNodeDumper::dumpCleanupObject( 676 const ExprWithCleanups::CleanupObject &C) { 677 if (auto *BD = C.dyn_cast<BlockDecl *>()) 678 dumpDeclRef(BD, "cleanup"); 679 else if (auto *CLE = C.dyn_cast<CompoundLiteralExpr *>()) 680 AddChild([=] { 681 OS << "cleanup "; 682 { 683 ColorScope Color(OS, ShowColors, StmtColor); 684 OS << CLE->getStmtClassName(); 685 } 686 dumpPointer(CLE); 687 }); 688 else 689 llvm_unreachable("unexpected cleanup type"); 690 } 691 692 void TextNodeDumper::dumpDeclRef(const Decl *D, StringRef Label) { 693 if (!D) 694 return; 695 696 AddChild([=] { 697 if (!Label.empty()) 698 OS << Label << ' '; 699 dumpBareDeclRef(D); 700 }); 701 } 702 703 const char *TextNodeDumper::getCommandName(unsigned CommandID) { 704 if (Traits) 705 return Traits->getCommandInfo(CommandID)->Name; 706 const comments::CommandInfo *Info = 707 comments::CommandTraits::getBuiltinCommandInfo(CommandID); 708 if (Info) 709 return Info->Name; 710 return "<not a builtin command>"; 711 } 712 713 void TextNodeDumper::printFPOptions(FPOptionsOverride FPO) { 714 #define OPTION(NAME, TYPE, WIDTH, PREVIOUS) \ 715 if (FPO.has##NAME##Override()) \ 716 OS << " " #NAME "=" << FPO.get##NAME##Override(); 717 #include "clang/Basic/FPOptions.def" 718 } 719 720 void TextNodeDumper::visitTextComment(const comments::TextComment *C, 721 const comments::FullComment *) { 722 OS << " Text=\"" << C->getText() << "\""; 723 } 724 725 void TextNodeDumper::visitInlineCommandComment( 726 const comments::InlineCommandComment *C, const comments::FullComment *) { 727 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\""; 728 switch (C->getRenderKind()) { 729 case comments::InlineCommandComment::RenderNormal: 730 OS << " RenderNormal"; 731 break; 732 case comments::InlineCommandComment::RenderBold: 733 OS << " RenderBold"; 734 break; 735 case comments::InlineCommandComment::RenderMonospaced: 736 OS << " RenderMonospaced"; 737 break; 738 case comments::InlineCommandComment::RenderEmphasized: 739 OS << " RenderEmphasized"; 740 break; 741 case comments::InlineCommandComment::RenderAnchor: 742 OS << " RenderAnchor"; 743 break; 744 } 745 746 for (unsigned i = 0, e = C->getNumArgs(); i != e; ++i) 747 OS << " Arg[" << i << "]=\"" << C->getArgText(i) << "\""; 748 } 749 750 void TextNodeDumper::visitHTMLStartTagComment( 751 const comments::HTMLStartTagComment *C, const comments::FullComment *) { 752 OS << " Name=\"" << C->getTagName() << "\""; 753 if (C->getNumAttrs() != 0) { 754 OS << " Attrs: "; 755 for (unsigned i = 0, e = C->getNumAttrs(); i != e; ++i) { 756 const comments::HTMLStartTagComment::Attribute &Attr = C->getAttr(i); 757 OS << " \"" << Attr.Name << "=\"" << Attr.Value << "\""; 758 } 759 } 760 if (C->isSelfClosing()) 761 OS << " SelfClosing"; 762 } 763 764 void TextNodeDumper::visitHTMLEndTagComment( 765 const comments::HTMLEndTagComment *C, const comments::FullComment *) { 766 OS << " Name=\"" << C->getTagName() << "\""; 767 } 768 769 void TextNodeDumper::visitBlockCommandComment( 770 const comments::BlockCommandComment *C, const comments::FullComment *) { 771 OS << " Name=\"" << getCommandName(C->getCommandID()) << "\""; 772 for (unsigned i = 0, e = C->getNumArgs(); i != e; ++i) 773 OS << " Arg[" << i << "]=\"" << C->getArgText(i) << "\""; 774 } 775 776 void TextNodeDumper::visitParamCommandComment( 777 const comments::ParamCommandComment *C, const comments::FullComment *FC) { 778 OS << " " 779 << comments::ParamCommandComment::getDirectionAsString(C->getDirection()); 780 781 if (C->isDirectionExplicit()) 782 OS << " explicitly"; 783 else 784 OS << " implicitly"; 785 786 if (C->hasParamName()) { 787 if (C->isParamIndexValid()) 788 OS << " Param=\"" << C->getParamName(FC) << "\""; 789 else 790 OS << " Param=\"" << C->getParamNameAsWritten() << "\""; 791 } 792 793 if (C->isParamIndexValid() && !C->isVarArgParam()) 794 OS << " ParamIndex=" << C->getParamIndex(); 795 } 796 797 void TextNodeDumper::visitTParamCommandComment( 798 const comments::TParamCommandComment *C, const comments::FullComment *FC) { 799 if (C->hasParamName()) { 800 if (C->isPositionValid()) 801 OS << " Param=\"" << C->getParamName(FC) << "\""; 802 else 803 OS << " Param=\"" << C->getParamNameAsWritten() << "\""; 804 } 805 806 if (C->isPositionValid()) { 807 OS << " Position=<"; 808 for (unsigned i = 0, e = C->getDepth(); i != e; ++i) { 809 OS << C->getIndex(i); 810 if (i != e - 1) 811 OS << ", "; 812 } 813 OS << ">"; 814 } 815 } 816 817 void TextNodeDumper::visitVerbatimBlockComment( 818 const comments::VerbatimBlockComment *C, const comments::FullComment *) { 819 OS << " Name=\"" << getCommandName(C->getCommandID()) 820 << "\"" 821 " CloseName=\"" 822 << C->getCloseName() << "\""; 823 } 824 825 void TextNodeDumper::visitVerbatimBlockLineComment( 826 const comments::VerbatimBlockLineComment *C, 827 const comments::FullComment *) { 828 OS << " Text=\"" << C->getText() << "\""; 829 } 830 831 void TextNodeDumper::visitVerbatimLineComment( 832 const comments::VerbatimLineComment *C, const comments::FullComment *) { 833 OS << " Text=\"" << C->getText() << "\""; 834 } 835 836 void TextNodeDumper::VisitNullTemplateArgument(const TemplateArgument &) { 837 OS << " null"; 838 } 839 840 void TextNodeDumper::VisitTypeTemplateArgument(const TemplateArgument &TA) { 841 OS << " type"; 842 dumpType(TA.getAsType()); 843 } 844 845 void TextNodeDumper::VisitDeclarationTemplateArgument( 846 const TemplateArgument &TA) { 847 OS << " decl"; 848 dumpDeclRef(TA.getAsDecl()); 849 } 850 851 void TextNodeDumper::VisitNullPtrTemplateArgument(const TemplateArgument &) { 852 OS << " nullptr"; 853 } 854 855 void TextNodeDumper::VisitIntegralTemplateArgument(const TemplateArgument &TA) { 856 OS << " integral " << TA.getAsIntegral(); 857 } 858 859 void TextNodeDumper::VisitTemplateTemplateArgument(const TemplateArgument &TA) { 860 OS << " template "; 861 TA.getAsTemplate().dump(OS); 862 } 863 864 void TextNodeDumper::VisitTemplateExpansionTemplateArgument( 865 const TemplateArgument &TA) { 866 OS << " template expansion "; 867 TA.getAsTemplateOrTemplatePattern().dump(OS); 868 } 869 870 void TextNodeDumper::VisitExpressionTemplateArgument(const TemplateArgument &) { 871 OS << " expr"; 872 } 873 874 void TextNodeDumper::VisitPackTemplateArgument(const TemplateArgument &) { 875 OS << " pack"; 876 } 877 878 static void dumpBasePath(raw_ostream &OS, const CastExpr *Node) { 879 if (Node->path_empty()) 880 return; 881 882 OS << " ("; 883 bool First = true; 884 for (CastExpr::path_const_iterator I = Node->path_begin(), 885 E = Node->path_end(); 886 I != E; ++I) { 887 const CXXBaseSpecifier *Base = *I; 888 if (!First) 889 OS << " -> "; 890 891 const auto *RD = 892 cast<CXXRecordDecl>(Base->getType()->castAs<RecordType>()->getDecl()); 893 894 if (Base->isVirtual()) 895 OS << "virtual "; 896 OS << RD->getName(); 897 First = false; 898 } 899 900 OS << ')'; 901 } 902 903 void TextNodeDumper::VisitIfStmt(const IfStmt *Node) { 904 if (Node->hasInitStorage()) 905 OS << " has_init"; 906 if (Node->hasVarStorage()) 907 OS << " has_var"; 908 if (Node->hasElseStorage()) 909 OS << " has_else"; 910 } 911 912 void TextNodeDumper::VisitSwitchStmt(const SwitchStmt *Node) { 913 if (Node->hasInitStorage()) 914 OS << " has_init"; 915 if (Node->hasVarStorage()) 916 OS << " has_var"; 917 } 918 919 void TextNodeDumper::VisitWhileStmt(const WhileStmt *Node) { 920 if (Node->hasVarStorage()) 921 OS << " has_var"; 922 } 923 924 void TextNodeDumper::VisitLabelStmt(const LabelStmt *Node) { 925 OS << " '" << Node->getName() << "'"; 926 } 927 928 void TextNodeDumper::VisitGotoStmt(const GotoStmt *Node) { 929 OS << " '" << Node->getLabel()->getName() << "'"; 930 dumpPointer(Node->getLabel()); 931 } 932 933 void TextNodeDumper::VisitCaseStmt(const CaseStmt *Node) { 934 if (Node->caseStmtIsGNURange()) 935 OS << " gnu_range"; 936 } 937 938 void TextNodeDumper::VisitConstantExpr(const ConstantExpr *Node) { 939 if (Node->hasAPValueResult()) 940 AddChild("value", 941 [=] { Visit(Node->getAPValueResult(), Node->getType()); }); 942 } 943 944 void TextNodeDumper::VisitCallExpr(const CallExpr *Node) { 945 if (Node->usesADL()) 946 OS << " adl"; 947 if (Node->hasStoredFPFeatures()) 948 printFPOptions(Node->getFPFeatures()); 949 } 950 951 void TextNodeDumper::VisitCXXOperatorCallExpr(const CXXOperatorCallExpr *Node) { 952 const char *OperatorSpelling = clang::getOperatorSpelling(Node->getOperator()); 953 if (OperatorSpelling) 954 OS << " '" << OperatorSpelling << "'"; 955 956 VisitCallExpr(Node); 957 } 958 959 void TextNodeDumper::VisitCastExpr(const CastExpr *Node) { 960 OS << " <"; 961 { 962 ColorScope Color(OS, ShowColors, CastColor); 963 OS << Node->getCastKindName(); 964 } 965 dumpBasePath(OS, Node); 966 OS << ">"; 967 if (Node->hasStoredFPFeatures()) 968 printFPOptions(Node->getFPFeatures()); 969 } 970 971 void TextNodeDumper::VisitImplicitCastExpr(const ImplicitCastExpr *Node) { 972 VisitCastExpr(Node); 973 if (Node->isPartOfExplicitCast()) 974 OS << " part_of_explicit_cast"; 975 } 976 977 void TextNodeDumper::VisitDeclRefExpr(const DeclRefExpr *Node) { 978 OS << " "; 979 dumpBareDeclRef(Node->getDecl()); 980 if (Node->getDecl() != Node->getFoundDecl()) { 981 OS << " ("; 982 dumpBareDeclRef(Node->getFoundDecl()); 983 OS << ")"; 984 } 985 switch (Node->isNonOdrUse()) { 986 case NOUR_None: break; 987 case NOUR_Unevaluated: OS << " non_odr_use_unevaluated"; break; 988 case NOUR_Constant: OS << " non_odr_use_constant"; break; 989 case NOUR_Discarded: OS << " non_odr_use_discarded"; break; 990 } 991 } 992 993 void TextNodeDumper::VisitUnresolvedLookupExpr( 994 const UnresolvedLookupExpr *Node) { 995 OS << " ("; 996 if (!Node->requiresADL()) 997 OS << "no "; 998 OS << "ADL) = '" << Node->getName() << '\''; 999 1000 UnresolvedLookupExpr::decls_iterator I = Node->decls_begin(), 1001 E = Node->decls_end(); 1002 if (I == E) 1003 OS << " empty"; 1004 for (; I != E; ++I) 1005 dumpPointer(*I); 1006 } 1007 1008 void TextNodeDumper::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *Node) { 1009 { 1010 ColorScope Color(OS, ShowColors, DeclKindNameColor); 1011 OS << " " << Node->getDecl()->getDeclKindName() << "Decl"; 1012 } 1013 OS << "='" << *Node->getDecl() << "'"; 1014 dumpPointer(Node->getDecl()); 1015 if (Node->isFreeIvar()) 1016 OS << " isFreeIvar"; 1017 } 1018 1019 void TextNodeDumper::VisitPredefinedExpr(const PredefinedExpr *Node) { 1020 OS << " " << PredefinedExpr::getIdentKindName(Node->getIdentKind()); 1021 } 1022 1023 void TextNodeDumper::VisitCharacterLiteral(const CharacterLiteral *Node) { 1024 ColorScope Color(OS, ShowColors, ValueColor); 1025 OS << " " << Node->getValue(); 1026 } 1027 1028 void TextNodeDumper::VisitIntegerLiteral(const IntegerLiteral *Node) { 1029 bool isSigned = Node->getType()->isSignedIntegerType(); 1030 ColorScope Color(OS, ShowColors, ValueColor); 1031 OS << " " << Node->getValue().toString(10, isSigned); 1032 } 1033 1034 void TextNodeDumper::VisitFixedPointLiteral(const FixedPointLiteral *Node) { 1035 ColorScope Color(OS, ShowColors, ValueColor); 1036 OS << " " << Node->getValueAsString(/*Radix=*/10); 1037 } 1038 1039 void TextNodeDumper::VisitFloatingLiteral(const FloatingLiteral *Node) { 1040 ColorScope Color(OS, ShowColors, ValueColor); 1041 OS << " " << Node->getValueAsApproximateDouble(); 1042 } 1043 1044 void TextNodeDumper::VisitStringLiteral(const StringLiteral *Str) { 1045 ColorScope Color(OS, ShowColors, ValueColor); 1046 OS << " "; 1047 Str->outputString(OS); 1048 } 1049 1050 void TextNodeDumper::VisitInitListExpr(const InitListExpr *ILE) { 1051 if (auto *Field = ILE->getInitializedFieldInUnion()) { 1052 OS << " field "; 1053 dumpBareDeclRef(Field); 1054 } 1055 } 1056 1057 void TextNodeDumper::VisitGenericSelectionExpr(const GenericSelectionExpr *E) { 1058 if (E->isResultDependent()) 1059 OS << " result_dependent"; 1060 } 1061 1062 void TextNodeDumper::VisitUnaryOperator(const UnaryOperator *Node) { 1063 OS << " " << (Node->isPostfix() ? "postfix" : "prefix") << " '" 1064 << UnaryOperator::getOpcodeStr(Node->getOpcode()) << "'"; 1065 if (!Node->canOverflow()) 1066 OS << " cannot overflow"; 1067 if (Node->hasStoredFPFeatures()) 1068 printFPOptions(Node->getStoredFPFeatures()); 1069 } 1070 1071 void TextNodeDumper::VisitUnaryExprOrTypeTraitExpr( 1072 const UnaryExprOrTypeTraitExpr *Node) { 1073 OS << " " << getTraitSpelling(Node->getKind()); 1074 1075 if (Node->isArgumentType()) 1076 dumpType(Node->getArgumentType()); 1077 } 1078 1079 void TextNodeDumper::VisitMemberExpr(const MemberExpr *Node) { 1080 OS << " " << (Node->isArrow() ? "->" : ".") << *Node->getMemberDecl(); 1081 dumpPointer(Node->getMemberDecl()); 1082 switch (Node->isNonOdrUse()) { 1083 case NOUR_None: break; 1084 case NOUR_Unevaluated: OS << " non_odr_use_unevaluated"; break; 1085 case NOUR_Constant: OS << " non_odr_use_constant"; break; 1086 case NOUR_Discarded: OS << " non_odr_use_discarded"; break; 1087 } 1088 } 1089 1090 void TextNodeDumper::VisitExtVectorElementExpr( 1091 const ExtVectorElementExpr *Node) { 1092 OS << " " << Node->getAccessor().getNameStart(); 1093 } 1094 1095 void TextNodeDumper::VisitBinaryOperator(const BinaryOperator *Node) { 1096 OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode()) << "'"; 1097 if (Node->hasStoredFPFeatures()) 1098 printFPOptions(Node->getStoredFPFeatures()); 1099 } 1100 1101 void TextNodeDumper::VisitCompoundAssignOperator( 1102 const CompoundAssignOperator *Node) { 1103 OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode()) 1104 << "' ComputeLHSTy="; 1105 dumpBareType(Node->getComputationLHSType()); 1106 OS << " ComputeResultTy="; 1107 dumpBareType(Node->getComputationResultType()); 1108 if (Node->hasStoredFPFeatures()) 1109 printFPOptions(Node->getStoredFPFeatures()); 1110 } 1111 1112 void TextNodeDumper::VisitAddrLabelExpr(const AddrLabelExpr *Node) { 1113 OS << " " << Node->getLabel()->getName(); 1114 dumpPointer(Node->getLabel()); 1115 } 1116 1117 void TextNodeDumper::VisitCXXNamedCastExpr(const CXXNamedCastExpr *Node) { 1118 OS << " " << Node->getCastName() << "<" 1119 << Node->getTypeAsWritten().getAsString() << ">" 1120 << " <" << Node->getCastKindName(); 1121 dumpBasePath(OS, Node); 1122 OS << ">"; 1123 } 1124 1125 void TextNodeDumper::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *Node) { 1126 OS << " " << (Node->getValue() ? "true" : "false"); 1127 } 1128 1129 void TextNodeDumper::VisitCXXThisExpr(const CXXThisExpr *Node) { 1130 if (Node->isImplicit()) 1131 OS << " implicit"; 1132 OS << " this"; 1133 } 1134 1135 void TextNodeDumper::VisitCXXFunctionalCastExpr( 1136 const CXXFunctionalCastExpr *Node) { 1137 OS << " functional cast to " << Node->getTypeAsWritten().getAsString() << " <" 1138 << Node->getCastKindName() << ">"; 1139 if (Node->hasStoredFPFeatures()) 1140 printFPOptions(Node->getFPFeatures()); 1141 } 1142 1143 void TextNodeDumper::VisitCXXStaticCastExpr(const CXXStaticCastExpr *Node) { 1144 VisitCXXNamedCastExpr(Node); 1145 if (Node->hasStoredFPFeatures()) 1146 printFPOptions(Node->getFPFeatures()); 1147 } 1148 1149 void TextNodeDumper::VisitCXXUnresolvedConstructExpr( 1150 const CXXUnresolvedConstructExpr *Node) { 1151 dumpType(Node->getTypeAsWritten()); 1152 if (Node->isListInitialization()) 1153 OS << " list"; 1154 } 1155 1156 void TextNodeDumper::VisitCXXConstructExpr(const CXXConstructExpr *Node) { 1157 CXXConstructorDecl *Ctor = Node->getConstructor(); 1158 dumpType(Ctor->getType()); 1159 if (Node->isElidable()) 1160 OS << " elidable"; 1161 if (Node->isListInitialization()) 1162 OS << " list"; 1163 if (Node->isStdInitListInitialization()) 1164 OS << " std::initializer_list"; 1165 if (Node->requiresZeroInitialization()) 1166 OS << " zeroing"; 1167 } 1168 1169 void TextNodeDumper::VisitCXXBindTemporaryExpr( 1170 const CXXBindTemporaryExpr *Node) { 1171 OS << " (CXXTemporary"; 1172 dumpPointer(Node); 1173 OS << ")"; 1174 } 1175 1176 void TextNodeDumper::VisitCXXNewExpr(const CXXNewExpr *Node) { 1177 if (Node->isGlobalNew()) 1178 OS << " global"; 1179 if (Node->isArray()) 1180 OS << " array"; 1181 if (Node->getOperatorNew()) { 1182 OS << ' '; 1183 dumpBareDeclRef(Node->getOperatorNew()); 1184 } 1185 // We could dump the deallocation function used in case of error, but it's 1186 // usually not that interesting. 1187 } 1188 1189 void TextNodeDumper::VisitCXXDeleteExpr(const CXXDeleteExpr *Node) { 1190 if (Node->isGlobalDelete()) 1191 OS << " global"; 1192 if (Node->isArrayForm()) 1193 OS << " array"; 1194 if (Node->getOperatorDelete()) { 1195 OS << ' '; 1196 dumpBareDeclRef(Node->getOperatorDelete()); 1197 } 1198 } 1199 1200 void TextNodeDumper::VisitTypeTraitExpr(const TypeTraitExpr *Node) { 1201 OS << " " << getTraitSpelling(Node->getTrait()); 1202 } 1203 1204 void TextNodeDumper::VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr *Node) { 1205 OS << " " << getTraitSpelling(Node->getTrait()); 1206 } 1207 1208 void TextNodeDumper::VisitExpressionTraitExpr(const ExpressionTraitExpr *Node) { 1209 OS << " " << getTraitSpelling(Node->getTrait()); 1210 } 1211 1212 void TextNodeDumper::VisitMaterializeTemporaryExpr( 1213 const MaterializeTemporaryExpr *Node) { 1214 if (const ValueDecl *VD = Node->getExtendingDecl()) { 1215 OS << " extended by "; 1216 dumpBareDeclRef(VD); 1217 } 1218 } 1219 1220 void TextNodeDumper::VisitExprWithCleanups(const ExprWithCleanups *Node) { 1221 for (unsigned i = 0, e = Node->getNumObjects(); i != e; ++i) 1222 dumpCleanupObject(Node->getObject(i)); 1223 } 1224 1225 void TextNodeDumper::VisitSizeOfPackExpr(const SizeOfPackExpr *Node) { 1226 dumpPointer(Node->getPack()); 1227 dumpName(Node->getPack()); 1228 } 1229 1230 void TextNodeDumper::VisitCXXDependentScopeMemberExpr( 1231 const CXXDependentScopeMemberExpr *Node) { 1232 OS << " " << (Node->isArrow() ? "->" : ".") << Node->getMember(); 1233 } 1234 1235 void TextNodeDumper::VisitObjCMessageExpr(const ObjCMessageExpr *Node) { 1236 OS << " selector="; 1237 Node->getSelector().print(OS); 1238 switch (Node->getReceiverKind()) { 1239 case ObjCMessageExpr::Instance: 1240 break; 1241 1242 case ObjCMessageExpr::Class: 1243 OS << " class="; 1244 dumpBareType(Node->getClassReceiver()); 1245 break; 1246 1247 case ObjCMessageExpr::SuperInstance: 1248 OS << " super (instance)"; 1249 break; 1250 1251 case ObjCMessageExpr::SuperClass: 1252 OS << " super (class)"; 1253 break; 1254 } 1255 } 1256 1257 void TextNodeDumper::VisitObjCBoxedExpr(const ObjCBoxedExpr *Node) { 1258 if (auto *BoxingMethod = Node->getBoxingMethod()) { 1259 OS << " selector="; 1260 BoxingMethod->getSelector().print(OS); 1261 } 1262 } 1263 1264 void TextNodeDumper::VisitObjCAtCatchStmt(const ObjCAtCatchStmt *Node) { 1265 if (!Node->getCatchParamDecl()) 1266 OS << " catch all"; 1267 } 1268 1269 void TextNodeDumper::VisitObjCEncodeExpr(const ObjCEncodeExpr *Node) { 1270 dumpType(Node->getEncodedType()); 1271 } 1272 1273 void TextNodeDumper::VisitObjCSelectorExpr(const ObjCSelectorExpr *Node) { 1274 OS << " "; 1275 Node->getSelector().print(OS); 1276 } 1277 1278 void TextNodeDumper::VisitObjCProtocolExpr(const ObjCProtocolExpr *Node) { 1279 OS << ' ' << *Node->getProtocol(); 1280 } 1281 1282 void TextNodeDumper::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *Node) { 1283 if (Node->isImplicitProperty()) { 1284 OS << " Kind=MethodRef Getter=\""; 1285 if (Node->getImplicitPropertyGetter()) 1286 Node->getImplicitPropertyGetter()->getSelector().print(OS); 1287 else 1288 OS << "(null)"; 1289 1290 OS << "\" Setter=\""; 1291 if (ObjCMethodDecl *Setter = Node->getImplicitPropertySetter()) 1292 Setter->getSelector().print(OS); 1293 else 1294 OS << "(null)"; 1295 OS << "\""; 1296 } else { 1297 OS << " Kind=PropertyRef Property=\"" << *Node->getExplicitProperty() 1298 << '"'; 1299 } 1300 1301 if (Node->isSuperReceiver()) 1302 OS << " super"; 1303 1304 OS << " Messaging="; 1305 if (Node->isMessagingGetter() && Node->isMessagingSetter()) 1306 OS << "Getter&Setter"; 1307 else if (Node->isMessagingGetter()) 1308 OS << "Getter"; 1309 else if (Node->isMessagingSetter()) 1310 OS << "Setter"; 1311 } 1312 1313 void TextNodeDumper::VisitObjCSubscriptRefExpr( 1314 const ObjCSubscriptRefExpr *Node) { 1315 if (Node->isArraySubscriptRefExpr()) 1316 OS << " Kind=ArraySubscript GetterForArray=\""; 1317 else 1318 OS << " Kind=DictionarySubscript GetterForDictionary=\""; 1319 if (Node->getAtIndexMethodDecl()) 1320 Node->getAtIndexMethodDecl()->getSelector().print(OS); 1321 else 1322 OS << "(null)"; 1323 1324 if (Node->isArraySubscriptRefExpr()) 1325 OS << "\" SetterForArray=\""; 1326 else 1327 OS << "\" SetterForDictionary=\""; 1328 if (Node->setAtIndexMethodDecl()) 1329 Node->setAtIndexMethodDecl()->getSelector().print(OS); 1330 else 1331 OS << "(null)"; 1332 } 1333 1334 void TextNodeDumper::VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *Node) { 1335 OS << " " << (Node->getValue() ? "__objc_yes" : "__objc_no"); 1336 } 1337 1338 void TextNodeDumper::VisitOMPIteratorExpr(const OMPIteratorExpr *Node) { 1339 OS << " "; 1340 for (unsigned I = 0, E = Node->numOfIterators(); I < E; ++I) { 1341 Visit(Node->getIteratorDecl(I)); 1342 OS << " = "; 1343 const OMPIteratorExpr::IteratorRange Range = Node->getIteratorRange(I); 1344 OS << " begin "; 1345 Visit(Range.Begin); 1346 OS << " end "; 1347 Visit(Range.End); 1348 if (Range.Step) { 1349 OS << " step "; 1350 Visit(Range.Step); 1351 } 1352 } 1353 } 1354 1355 void TextNodeDumper::VisitConceptSpecializationExpr( 1356 const ConceptSpecializationExpr *Node) { 1357 OS << " "; 1358 dumpBareDeclRef(Node->getFoundDecl()); 1359 } 1360 1361 void TextNodeDumper::VisitRValueReferenceType(const ReferenceType *T) { 1362 if (T->isSpelledAsLValue()) 1363 OS << " written as lvalue reference"; 1364 } 1365 1366 void TextNodeDumper::VisitArrayType(const ArrayType *T) { 1367 switch (T->getSizeModifier()) { 1368 case ArrayType::Normal: 1369 break; 1370 case ArrayType::Static: 1371 OS << " static"; 1372 break; 1373 case ArrayType::Star: 1374 OS << " *"; 1375 break; 1376 } 1377 OS << " " << T->getIndexTypeQualifiers().getAsString(); 1378 } 1379 1380 void TextNodeDumper::VisitConstantArrayType(const ConstantArrayType *T) { 1381 OS << " " << T->getSize(); 1382 VisitArrayType(T); 1383 } 1384 1385 void TextNodeDumper::VisitVariableArrayType(const VariableArrayType *T) { 1386 OS << " "; 1387 dumpSourceRange(T->getBracketsRange()); 1388 VisitArrayType(T); 1389 } 1390 1391 void TextNodeDumper::VisitDependentSizedArrayType( 1392 const DependentSizedArrayType *T) { 1393 VisitArrayType(T); 1394 OS << " "; 1395 dumpSourceRange(T->getBracketsRange()); 1396 } 1397 1398 void TextNodeDumper::VisitDependentSizedExtVectorType( 1399 const DependentSizedExtVectorType *T) { 1400 OS << " "; 1401 dumpLocation(T->getAttributeLoc()); 1402 } 1403 1404 void TextNodeDumper::VisitVectorType(const VectorType *T) { 1405 switch (T->getVectorKind()) { 1406 case VectorType::GenericVector: 1407 break; 1408 case VectorType::AltiVecVector: 1409 OS << " altivec"; 1410 break; 1411 case VectorType::AltiVecPixel: 1412 OS << " altivec pixel"; 1413 break; 1414 case VectorType::AltiVecBool: 1415 OS << " altivec bool"; 1416 break; 1417 case VectorType::NeonVector: 1418 OS << " neon"; 1419 break; 1420 case VectorType::NeonPolyVector: 1421 OS << " neon poly"; 1422 break; 1423 case VectorType::SveFixedLengthDataVector: 1424 OS << " fixed-length sve data vector"; 1425 break; 1426 case VectorType::SveFixedLengthPredicateVector: 1427 OS << " fixed-length sve predicate vector"; 1428 break; 1429 } 1430 OS << " " << T->getNumElements(); 1431 } 1432 1433 void TextNodeDumper::VisitFunctionType(const FunctionType *T) { 1434 auto EI = T->getExtInfo(); 1435 if (EI.getNoReturn()) 1436 OS << " noreturn"; 1437 if (EI.getProducesResult()) 1438 OS << " produces_result"; 1439 if (EI.getHasRegParm()) 1440 OS << " regparm " << EI.getRegParm(); 1441 OS << " " << FunctionType::getNameForCallConv(EI.getCC()); 1442 } 1443 1444 void TextNodeDumper::VisitFunctionProtoType(const FunctionProtoType *T) { 1445 auto EPI = T->getExtProtoInfo(); 1446 if (EPI.HasTrailingReturn) 1447 OS << " trailing_return"; 1448 if (T->isConst()) 1449 OS << " const"; 1450 if (T->isVolatile()) 1451 OS << " volatile"; 1452 if (T->isRestrict()) 1453 OS << " restrict"; 1454 if (T->getExtProtoInfo().Variadic) 1455 OS << " variadic"; 1456 switch (EPI.RefQualifier) { 1457 case RQ_None: 1458 break; 1459 case RQ_LValue: 1460 OS << " &"; 1461 break; 1462 case RQ_RValue: 1463 OS << " &&"; 1464 break; 1465 } 1466 // FIXME: Exception specification. 1467 // FIXME: Consumed parameters. 1468 VisitFunctionType(T); 1469 } 1470 1471 void TextNodeDumper::VisitUnresolvedUsingType(const UnresolvedUsingType *T) { 1472 dumpDeclRef(T->getDecl()); 1473 } 1474 1475 void TextNodeDumper::VisitTypedefType(const TypedefType *T) { 1476 dumpDeclRef(T->getDecl()); 1477 } 1478 1479 void TextNodeDumper::VisitUnaryTransformType(const UnaryTransformType *T) { 1480 switch (T->getUTTKind()) { 1481 case UnaryTransformType::EnumUnderlyingType: 1482 OS << " underlying_type"; 1483 break; 1484 } 1485 } 1486 1487 void TextNodeDumper::VisitTagType(const TagType *T) { 1488 dumpDeclRef(T->getDecl()); 1489 } 1490 1491 void TextNodeDumper::VisitTemplateTypeParmType(const TemplateTypeParmType *T) { 1492 OS << " depth " << T->getDepth() << " index " << T->getIndex(); 1493 if (T->isParameterPack()) 1494 OS << " pack"; 1495 dumpDeclRef(T->getDecl()); 1496 } 1497 1498 void TextNodeDumper::VisitAutoType(const AutoType *T) { 1499 if (T->isDecltypeAuto()) 1500 OS << " decltype(auto)"; 1501 if (!T->isDeduced()) 1502 OS << " undeduced"; 1503 if (T->isConstrained()) { 1504 dumpDeclRef(T->getTypeConstraintConcept()); 1505 for (const auto &Arg : T->getTypeConstraintArguments()) 1506 VisitTemplateArgument(Arg); 1507 } 1508 } 1509 1510 void TextNodeDumper::VisitTemplateSpecializationType( 1511 const TemplateSpecializationType *T) { 1512 if (T->isTypeAlias()) 1513 OS << " alias"; 1514 OS << " "; 1515 T->getTemplateName().dump(OS); 1516 } 1517 1518 void TextNodeDumper::VisitInjectedClassNameType( 1519 const InjectedClassNameType *T) { 1520 dumpDeclRef(T->getDecl()); 1521 } 1522 1523 void TextNodeDumper::VisitObjCInterfaceType(const ObjCInterfaceType *T) { 1524 dumpDeclRef(T->getDecl()); 1525 } 1526 1527 void TextNodeDumper::VisitPackExpansionType(const PackExpansionType *T) { 1528 if (auto N = T->getNumExpansions()) 1529 OS << " expansions " << *N; 1530 } 1531 1532 void TextNodeDumper::VisitLabelDecl(const LabelDecl *D) { dumpName(D); } 1533 1534 void TextNodeDumper::VisitTypedefDecl(const TypedefDecl *D) { 1535 dumpName(D); 1536 dumpType(D->getUnderlyingType()); 1537 if (D->isModulePrivate()) 1538 OS << " __module_private__"; 1539 } 1540 1541 void TextNodeDumper::VisitEnumDecl(const EnumDecl *D) { 1542 if (D->isScoped()) { 1543 if (D->isScopedUsingClassTag()) 1544 OS << " class"; 1545 else 1546 OS << " struct"; 1547 } 1548 dumpName(D); 1549 if (D->isModulePrivate()) 1550 OS << " __module_private__"; 1551 if (D->isFixed()) 1552 dumpType(D->getIntegerType()); 1553 } 1554 1555 void TextNodeDumper::VisitRecordDecl(const RecordDecl *D) { 1556 OS << ' ' << D->getKindName(); 1557 dumpName(D); 1558 if (D->isModulePrivate()) 1559 OS << " __module_private__"; 1560 if (D->isCompleteDefinition()) 1561 OS << " definition"; 1562 } 1563 1564 void TextNodeDumper::VisitEnumConstantDecl(const EnumConstantDecl *D) { 1565 dumpName(D); 1566 dumpType(D->getType()); 1567 } 1568 1569 void TextNodeDumper::VisitIndirectFieldDecl(const IndirectFieldDecl *D) { 1570 dumpName(D); 1571 dumpType(D->getType()); 1572 1573 for (const auto *Child : D->chain()) 1574 dumpDeclRef(Child); 1575 } 1576 1577 void TextNodeDumper::VisitFunctionDecl(const FunctionDecl *D) { 1578 dumpName(D); 1579 dumpType(D->getType()); 1580 1581 StorageClass SC = D->getStorageClass(); 1582 if (SC != SC_None) 1583 OS << ' ' << VarDecl::getStorageClassSpecifierString(SC); 1584 if (D->isInlineSpecified()) 1585 OS << " inline"; 1586 if (D->isVirtualAsWritten()) 1587 OS << " virtual"; 1588 if (D->isModulePrivate()) 1589 OS << " __module_private__"; 1590 1591 if (D->isPure()) 1592 OS << " pure"; 1593 if (D->isDefaulted()) { 1594 OS << " default"; 1595 if (D->isDeleted()) 1596 OS << "_delete"; 1597 } 1598 if (D->isDeletedAsWritten()) 1599 OS << " delete"; 1600 if (D->isTrivial()) 1601 OS << " trivial"; 1602 1603 if (const auto *FPT = D->getType()->getAs<FunctionProtoType>()) { 1604 FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo(); 1605 switch (EPI.ExceptionSpec.Type) { 1606 default: 1607 break; 1608 case EST_Unevaluated: 1609 OS << " noexcept-unevaluated " << EPI.ExceptionSpec.SourceDecl; 1610 break; 1611 case EST_Uninstantiated: 1612 OS << " noexcept-uninstantiated " << EPI.ExceptionSpec.SourceTemplate; 1613 break; 1614 } 1615 } 1616 1617 if (const auto *MD = dyn_cast<CXXMethodDecl>(D)) { 1618 if (MD->size_overridden_methods() != 0) { 1619 auto dumpOverride = [=](const CXXMethodDecl *D) { 1620 SplitQualType T_split = D->getType().split(); 1621 OS << D << " " << D->getParent()->getName() << "::" << D->getDeclName() 1622 << " '" << QualType::getAsString(T_split, PrintPolicy) << "'"; 1623 }; 1624 1625 AddChild([=] { 1626 auto Overrides = MD->overridden_methods(); 1627 OS << "Overrides: [ "; 1628 dumpOverride(*Overrides.begin()); 1629 for (const auto *Override : 1630 llvm::make_range(Overrides.begin() + 1, Overrides.end())) { 1631 OS << ", "; 1632 dumpOverride(Override); 1633 } 1634 OS << " ]"; 1635 }); 1636 } 1637 } 1638 1639 // Since NumParams comes from the FunctionProtoType of the FunctionDecl and 1640 // the Params are set later, it is possible for a dump during debugging to 1641 // encounter a FunctionDecl that has been created but hasn't been assigned 1642 // ParmVarDecls yet. 1643 if (!D->param_empty() && !D->param_begin()) 1644 OS << " <<<NULL params x " << D->getNumParams() << ">>>"; 1645 } 1646 1647 void TextNodeDumper::VisitLifetimeExtendedTemporaryDecl( 1648 const LifetimeExtendedTemporaryDecl *D) { 1649 OS << " extended by "; 1650 dumpBareDeclRef(D->getExtendingDecl()); 1651 OS << " mangling "; 1652 { 1653 ColorScope Color(OS, ShowColors, ValueColor); 1654 OS << D->getManglingNumber(); 1655 } 1656 } 1657 1658 void TextNodeDumper::VisitFieldDecl(const FieldDecl *D) { 1659 dumpName(D); 1660 dumpType(D->getType()); 1661 if (D->isMutable()) 1662 OS << " mutable"; 1663 if (D->isModulePrivate()) 1664 OS << " __module_private__"; 1665 } 1666 1667 void TextNodeDumper::VisitVarDecl(const VarDecl *D) { 1668 dumpName(D); 1669 dumpType(D->getType()); 1670 StorageClass SC = D->getStorageClass(); 1671 if (SC != SC_None) 1672 OS << ' ' << VarDecl::getStorageClassSpecifierString(SC); 1673 switch (D->getTLSKind()) { 1674 case VarDecl::TLS_None: 1675 break; 1676 case VarDecl::TLS_Static: 1677 OS << " tls"; 1678 break; 1679 case VarDecl::TLS_Dynamic: 1680 OS << " tls_dynamic"; 1681 break; 1682 } 1683 if (D->isModulePrivate()) 1684 OS << " __module_private__"; 1685 if (D->isNRVOVariable()) 1686 OS << " nrvo"; 1687 if (D->isInline()) 1688 OS << " inline"; 1689 if (D->isConstexpr()) 1690 OS << " constexpr"; 1691 if (D->hasInit()) { 1692 switch (D->getInitStyle()) { 1693 case VarDecl::CInit: 1694 OS << " cinit"; 1695 break; 1696 case VarDecl::CallInit: 1697 OS << " callinit"; 1698 break; 1699 case VarDecl::ListInit: 1700 OS << " listinit"; 1701 break; 1702 } 1703 } 1704 if (D->needsDestruction(D->getASTContext())) 1705 OS << " destroyed"; 1706 if (D->isParameterPack()) 1707 OS << " pack"; 1708 1709 if (D->hasInit()) { 1710 const Expr *E = D->getInit(); 1711 // Only dump the value of constexpr VarDecls for now. 1712 if (E && !E->isValueDependent() && D->isConstexpr()) { 1713 const APValue *Value = D->evaluateValue(); 1714 if (Value) 1715 AddChild("value", [=] { Visit(*Value, E->getType()); }); 1716 } 1717 } 1718 } 1719 1720 void TextNodeDumper::VisitBindingDecl(const BindingDecl *D) { 1721 dumpName(D); 1722 dumpType(D->getType()); 1723 } 1724 1725 void TextNodeDumper::VisitCapturedDecl(const CapturedDecl *D) { 1726 if (D->isNothrow()) 1727 OS << " nothrow"; 1728 } 1729 1730 void TextNodeDumper::VisitImportDecl(const ImportDecl *D) { 1731 OS << ' ' << D->getImportedModule()->getFullModuleName(); 1732 1733 for (Decl *InitD : 1734 D->getASTContext().getModuleInitializers(D->getImportedModule())) 1735 dumpDeclRef(InitD, "initializer"); 1736 } 1737 1738 void TextNodeDumper::VisitPragmaCommentDecl(const PragmaCommentDecl *D) { 1739 OS << ' '; 1740 switch (D->getCommentKind()) { 1741 case PCK_Unknown: 1742 llvm_unreachable("unexpected pragma comment kind"); 1743 case PCK_Compiler: 1744 OS << "compiler"; 1745 break; 1746 case PCK_ExeStr: 1747 OS << "exestr"; 1748 break; 1749 case PCK_Lib: 1750 OS << "lib"; 1751 break; 1752 case PCK_Linker: 1753 OS << "linker"; 1754 break; 1755 case PCK_User: 1756 OS << "user"; 1757 break; 1758 } 1759 StringRef Arg = D->getArg(); 1760 if (!Arg.empty()) 1761 OS << " \"" << Arg << "\""; 1762 } 1763 1764 void TextNodeDumper::VisitPragmaDetectMismatchDecl( 1765 const PragmaDetectMismatchDecl *D) { 1766 OS << " \"" << D->getName() << "\" \"" << D->getValue() << "\""; 1767 } 1768 1769 void TextNodeDumper::VisitOMPExecutableDirective( 1770 const OMPExecutableDirective *D) { 1771 if (D->isStandaloneDirective()) 1772 OS << " openmp_standalone_directive"; 1773 } 1774 1775 void TextNodeDumper::VisitOMPDeclareReductionDecl( 1776 const OMPDeclareReductionDecl *D) { 1777 dumpName(D); 1778 dumpType(D->getType()); 1779 OS << " combiner"; 1780 dumpPointer(D->getCombiner()); 1781 if (const auto *Initializer = D->getInitializer()) { 1782 OS << " initializer"; 1783 dumpPointer(Initializer); 1784 switch (D->getInitializerKind()) { 1785 case OMPDeclareReductionDecl::DirectInit: 1786 OS << " omp_priv = "; 1787 break; 1788 case OMPDeclareReductionDecl::CopyInit: 1789 OS << " omp_priv ()"; 1790 break; 1791 case OMPDeclareReductionDecl::CallInit: 1792 break; 1793 } 1794 } 1795 } 1796 1797 void TextNodeDumper::VisitOMPRequiresDecl(const OMPRequiresDecl *D) { 1798 for (const auto *C : D->clauselists()) { 1799 AddChild([=] { 1800 if (!C) { 1801 ColorScope Color(OS, ShowColors, NullColor); 1802 OS << "<<<NULL>>> OMPClause"; 1803 return; 1804 } 1805 { 1806 ColorScope Color(OS, ShowColors, AttrColor); 1807 StringRef ClauseName( 1808 llvm::omp::getOpenMPClauseName(C->getClauseKind())); 1809 OS << "OMP" << ClauseName.substr(/*Start=*/0, /*N=*/1).upper() 1810 << ClauseName.drop_front() << "Clause"; 1811 } 1812 dumpPointer(C); 1813 dumpSourceRange(SourceRange(C->getBeginLoc(), C->getEndLoc())); 1814 }); 1815 } 1816 } 1817 1818 void TextNodeDumper::VisitOMPCapturedExprDecl(const OMPCapturedExprDecl *D) { 1819 dumpName(D); 1820 dumpType(D->getType()); 1821 } 1822 1823 void TextNodeDumper::VisitNamespaceDecl(const NamespaceDecl *D) { 1824 dumpName(D); 1825 if (D->isInline()) 1826 OS << " inline"; 1827 if (!D->isOriginalNamespace()) 1828 dumpDeclRef(D->getOriginalNamespace(), "original"); 1829 } 1830 1831 void TextNodeDumper::VisitUsingDirectiveDecl(const UsingDirectiveDecl *D) { 1832 OS << ' '; 1833 dumpBareDeclRef(D->getNominatedNamespace()); 1834 } 1835 1836 void TextNodeDumper::VisitNamespaceAliasDecl(const NamespaceAliasDecl *D) { 1837 dumpName(D); 1838 dumpDeclRef(D->getAliasedNamespace()); 1839 } 1840 1841 void TextNodeDumper::VisitTypeAliasDecl(const TypeAliasDecl *D) { 1842 dumpName(D); 1843 dumpType(D->getUnderlyingType()); 1844 } 1845 1846 void TextNodeDumper::VisitTypeAliasTemplateDecl( 1847 const TypeAliasTemplateDecl *D) { 1848 dumpName(D); 1849 } 1850 1851 void TextNodeDumper::VisitCXXRecordDecl(const CXXRecordDecl *D) { 1852 VisitRecordDecl(D); 1853 if (!D->isCompleteDefinition()) 1854 return; 1855 1856 AddChild([=] { 1857 { 1858 ColorScope Color(OS, ShowColors, DeclKindNameColor); 1859 OS << "DefinitionData"; 1860 } 1861 #define FLAG(fn, name) \ 1862 if (D->fn()) \ 1863 OS << " " #name; 1864 FLAG(isParsingBaseSpecifiers, parsing_base_specifiers); 1865 1866 FLAG(isGenericLambda, generic); 1867 FLAG(isLambda, lambda); 1868 1869 FLAG(isAnonymousStructOrUnion, is_anonymous); 1870 FLAG(canPassInRegisters, pass_in_registers); 1871 FLAG(isEmpty, empty); 1872 FLAG(isAggregate, aggregate); 1873 FLAG(isStandardLayout, standard_layout); 1874 FLAG(isTriviallyCopyable, trivially_copyable); 1875 FLAG(isPOD, pod); 1876 FLAG(isTrivial, trivial); 1877 FLAG(isPolymorphic, polymorphic); 1878 FLAG(isAbstract, abstract); 1879 FLAG(isLiteral, literal); 1880 1881 FLAG(hasUserDeclaredConstructor, has_user_declared_ctor); 1882 FLAG(hasConstexprNonCopyMoveConstructor, has_constexpr_non_copy_move_ctor); 1883 FLAG(hasMutableFields, has_mutable_fields); 1884 FLAG(hasVariantMembers, has_variant_members); 1885 FLAG(allowConstDefaultInit, can_const_default_init); 1886 1887 AddChild([=] { 1888 { 1889 ColorScope Color(OS, ShowColors, DeclKindNameColor); 1890 OS << "DefaultConstructor"; 1891 } 1892 FLAG(hasDefaultConstructor, exists); 1893 FLAG(hasTrivialDefaultConstructor, trivial); 1894 FLAG(hasNonTrivialDefaultConstructor, non_trivial); 1895 FLAG(hasUserProvidedDefaultConstructor, user_provided); 1896 FLAG(hasConstexprDefaultConstructor, constexpr); 1897 FLAG(needsImplicitDefaultConstructor, needs_implicit); 1898 FLAG(defaultedDefaultConstructorIsConstexpr, defaulted_is_constexpr); 1899 }); 1900 1901 AddChild([=] { 1902 { 1903 ColorScope Color(OS, ShowColors, DeclKindNameColor); 1904 OS << "CopyConstructor"; 1905 } 1906 FLAG(hasSimpleCopyConstructor, simple); 1907 FLAG(hasTrivialCopyConstructor, trivial); 1908 FLAG(hasNonTrivialCopyConstructor, non_trivial); 1909 FLAG(hasUserDeclaredCopyConstructor, user_declared); 1910 FLAG(hasCopyConstructorWithConstParam, has_const_param); 1911 FLAG(needsImplicitCopyConstructor, needs_implicit); 1912 FLAG(needsOverloadResolutionForCopyConstructor, 1913 needs_overload_resolution); 1914 if (!D->needsOverloadResolutionForCopyConstructor()) 1915 FLAG(defaultedCopyConstructorIsDeleted, defaulted_is_deleted); 1916 FLAG(implicitCopyConstructorHasConstParam, implicit_has_const_param); 1917 }); 1918 1919 AddChild([=] { 1920 { 1921 ColorScope Color(OS, ShowColors, DeclKindNameColor); 1922 OS << "MoveConstructor"; 1923 } 1924 FLAG(hasMoveConstructor, exists); 1925 FLAG(hasSimpleMoveConstructor, simple); 1926 FLAG(hasTrivialMoveConstructor, trivial); 1927 FLAG(hasNonTrivialMoveConstructor, non_trivial); 1928 FLAG(hasUserDeclaredMoveConstructor, user_declared); 1929 FLAG(needsImplicitMoveConstructor, needs_implicit); 1930 FLAG(needsOverloadResolutionForMoveConstructor, 1931 needs_overload_resolution); 1932 if (!D->needsOverloadResolutionForMoveConstructor()) 1933 FLAG(defaultedMoveConstructorIsDeleted, defaulted_is_deleted); 1934 }); 1935 1936 AddChild([=] { 1937 { 1938 ColorScope Color(OS, ShowColors, DeclKindNameColor); 1939 OS << "CopyAssignment"; 1940 } 1941 FLAG(hasSimpleCopyAssignment, simple); 1942 FLAG(hasTrivialCopyAssignment, trivial); 1943 FLAG(hasNonTrivialCopyAssignment, non_trivial); 1944 FLAG(hasCopyAssignmentWithConstParam, has_const_param); 1945 FLAG(hasUserDeclaredCopyAssignment, user_declared); 1946 FLAG(needsImplicitCopyAssignment, needs_implicit); 1947 FLAG(needsOverloadResolutionForCopyAssignment, needs_overload_resolution); 1948 FLAG(implicitCopyAssignmentHasConstParam, implicit_has_const_param); 1949 }); 1950 1951 AddChild([=] { 1952 { 1953 ColorScope Color(OS, ShowColors, DeclKindNameColor); 1954 OS << "MoveAssignment"; 1955 } 1956 FLAG(hasMoveAssignment, exists); 1957 FLAG(hasSimpleMoveAssignment, simple); 1958 FLAG(hasTrivialMoveAssignment, trivial); 1959 FLAG(hasNonTrivialMoveAssignment, non_trivial); 1960 FLAG(hasUserDeclaredMoveAssignment, user_declared); 1961 FLAG(needsImplicitMoveAssignment, needs_implicit); 1962 FLAG(needsOverloadResolutionForMoveAssignment, needs_overload_resolution); 1963 }); 1964 1965 AddChild([=] { 1966 { 1967 ColorScope Color(OS, ShowColors, DeclKindNameColor); 1968 OS << "Destructor"; 1969 } 1970 FLAG(hasSimpleDestructor, simple); 1971 FLAG(hasIrrelevantDestructor, irrelevant); 1972 FLAG(hasTrivialDestructor, trivial); 1973 FLAG(hasNonTrivialDestructor, non_trivial); 1974 FLAG(hasUserDeclaredDestructor, user_declared); 1975 FLAG(hasConstexprDestructor, constexpr); 1976 FLAG(needsImplicitDestructor, needs_implicit); 1977 FLAG(needsOverloadResolutionForDestructor, needs_overload_resolution); 1978 if (!D->needsOverloadResolutionForDestructor()) 1979 FLAG(defaultedDestructorIsDeleted, defaulted_is_deleted); 1980 }); 1981 }); 1982 1983 for (const auto &I : D->bases()) { 1984 AddChild([=] { 1985 if (I.isVirtual()) 1986 OS << "virtual "; 1987 dumpAccessSpecifier(I.getAccessSpecifier()); 1988 dumpType(I.getType()); 1989 if (I.isPackExpansion()) 1990 OS << "..."; 1991 }); 1992 } 1993 } 1994 1995 void TextNodeDumper::VisitFunctionTemplateDecl(const FunctionTemplateDecl *D) { 1996 dumpName(D); 1997 } 1998 1999 void TextNodeDumper::VisitClassTemplateDecl(const ClassTemplateDecl *D) { 2000 dumpName(D); 2001 } 2002 2003 void TextNodeDumper::VisitVarTemplateDecl(const VarTemplateDecl *D) { 2004 dumpName(D); 2005 } 2006 2007 void TextNodeDumper::VisitBuiltinTemplateDecl(const BuiltinTemplateDecl *D) { 2008 dumpName(D); 2009 } 2010 2011 void TextNodeDumper::VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D) { 2012 if (const auto *TC = D->getTypeConstraint()) { 2013 OS << " "; 2014 dumpBareDeclRef(TC->getNamedConcept()); 2015 if (TC->getNamedConcept() != TC->getFoundDecl()) { 2016 OS << " ("; 2017 dumpBareDeclRef(TC->getFoundDecl()); 2018 OS << ")"; 2019 } 2020 } else if (D->wasDeclaredWithTypename()) 2021 OS << " typename"; 2022 else 2023 OS << " class"; 2024 OS << " depth " << D->getDepth() << " index " << D->getIndex(); 2025 if (D->isParameterPack()) 2026 OS << " ..."; 2027 dumpName(D); 2028 } 2029 2030 void TextNodeDumper::VisitNonTypeTemplateParmDecl( 2031 const NonTypeTemplateParmDecl *D) { 2032 dumpType(D->getType()); 2033 OS << " depth " << D->getDepth() << " index " << D->getIndex(); 2034 if (D->isParameterPack()) 2035 OS << " ..."; 2036 dumpName(D); 2037 } 2038 2039 void TextNodeDumper::VisitTemplateTemplateParmDecl( 2040 const TemplateTemplateParmDecl *D) { 2041 OS << " depth " << D->getDepth() << " index " << D->getIndex(); 2042 if (D->isParameterPack()) 2043 OS << " ..."; 2044 dumpName(D); 2045 } 2046 2047 void TextNodeDumper::VisitUsingDecl(const UsingDecl *D) { 2048 OS << ' '; 2049 if (D->getQualifier()) 2050 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy()); 2051 OS << D->getDeclName(); 2052 } 2053 2054 void TextNodeDumper::VisitUnresolvedUsingTypenameDecl( 2055 const UnresolvedUsingTypenameDecl *D) { 2056 OS << ' '; 2057 if (D->getQualifier()) 2058 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy()); 2059 OS << D->getDeclName(); 2060 } 2061 2062 void TextNodeDumper::VisitUnresolvedUsingValueDecl( 2063 const UnresolvedUsingValueDecl *D) { 2064 OS << ' '; 2065 if (D->getQualifier()) 2066 D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy()); 2067 OS << D->getDeclName(); 2068 dumpType(D->getType()); 2069 } 2070 2071 void TextNodeDumper::VisitUsingShadowDecl(const UsingShadowDecl *D) { 2072 OS << ' '; 2073 dumpBareDeclRef(D->getTargetDecl()); 2074 } 2075 2076 void TextNodeDumper::VisitConstructorUsingShadowDecl( 2077 const ConstructorUsingShadowDecl *D) { 2078 if (D->constructsVirtualBase()) 2079 OS << " virtual"; 2080 2081 AddChild([=] { 2082 OS << "target "; 2083 dumpBareDeclRef(D->getTargetDecl()); 2084 }); 2085 2086 AddChild([=] { 2087 OS << "nominated "; 2088 dumpBareDeclRef(D->getNominatedBaseClass()); 2089 OS << ' '; 2090 dumpBareDeclRef(D->getNominatedBaseClassShadowDecl()); 2091 }); 2092 2093 AddChild([=] { 2094 OS << "constructed "; 2095 dumpBareDeclRef(D->getConstructedBaseClass()); 2096 OS << ' '; 2097 dumpBareDeclRef(D->getConstructedBaseClassShadowDecl()); 2098 }); 2099 } 2100 2101 void TextNodeDumper::VisitLinkageSpecDecl(const LinkageSpecDecl *D) { 2102 switch (D->getLanguage()) { 2103 case LinkageSpecDecl::lang_c: 2104 OS << " C"; 2105 break; 2106 case LinkageSpecDecl::lang_cxx: 2107 OS << " C++"; 2108 break; 2109 } 2110 } 2111 2112 void TextNodeDumper::VisitAccessSpecDecl(const AccessSpecDecl *D) { 2113 OS << ' '; 2114 dumpAccessSpecifier(D->getAccess()); 2115 } 2116 2117 void TextNodeDumper::VisitFriendDecl(const FriendDecl *D) { 2118 if (TypeSourceInfo *T = D->getFriendType()) 2119 dumpType(T->getType()); 2120 } 2121 2122 void TextNodeDumper::VisitObjCIvarDecl(const ObjCIvarDecl *D) { 2123 dumpName(D); 2124 dumpType(D->getType()); 2125 if (D->getSynthesize()) 2126 OS << " synthesize"; 2127 2128 switch (D->getAccessControl()) { 2129 case ObjCIvarDecl::None: 2130 OS << " none"; 2131 break; 2132 case ObjCIvarDecl::Private: 2133 OS << " private"; 2134 break; 2135 case ObjCIvarDecl::Protected: 2136 OS << " protected"; 2137 break; 2138 case ObjCIvarDecl::Public: 2139 OS << " public"; 2140 break; 2141 case ObjCIvarDecl::Package: 2142 OS << " package"; 2143 break; 2144 } 2145 } 2146 2147 void TextNodeDumper::VisitObjCMethodDecl(const ObjCMethodDecl *D) { 2148 if (D->isInstanceMethod()) 2149 OS << " -"; 2150 else 2151 OS << " +"; 2152 dumpName(D); 2153 dumpType(D->getReturnType()); 2154 2155 if (D->isVariadic()) 2156 OS << " variadic"; 2157 } 2158 2159 void TextNodeDumper::VisitObjCTypeParamDecl(const ObjCTypeParamDecl *D) { 2160 dumpName(D); 2161 switch (D->getVariance()) { 2162 case ObjCTypeParamVariance::Invariant: 2163 break; 2164 2165 case ObjCTypeParamVariance::Covariant: 2166 OS << " covariant"; 2167 break; 2168 2169 case ObjCTypeParamVariance::Contravariant: 2170 OS << " contravariant"; 2171 break; 2172 } 2173 2174 if (D->hasExplicitBound()) 2175 OS << " bounded"; 2176 dumpType(D->getUnderlyingType()); 2177 } 2178 2179 void TextNodeDumper::VisitObjCCategoryDecl(const ObjCCategoryDecl *D) { 2180 dumpName(D); 2181 dumpDeclRef(D->getClassInterface()); 2182 dumpDeclRef(D->getImplementation()); 2183 for (const auto *P : D->protocols()) 2184 dumpDeclRef(P); 2185 } 2186 2187 void TextNodeDumper::VisitObjCCategoryImplDecl(const ObjCCategoryImplDecl *D) { 2188 dumpName(D); 2189 dumpDeclRef(D->getClassInterface()); 2190 dumpDeclRef(D->getCategoryDecl()); 2191 } 2192 2193 void TextNodeDumper::VisitObjCProtocolDecl(const ObjCProtocolDecl *D) { 2194 dumpName(D); 2195 2196 for (const auto *Child : D->protocols()) 2197 dumpDeclRef(Child); 2198 } 2199 2200 void TextNodeDumper::VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D) { 2201 dumpName(D); 2202 dumpDeclRef(D->getSuperClass(), "super"); 2203 2204 dumpDeclRef(D->getImplementation()); 2205 for (const auto *Child : D->protocols()) 2206 dumpDeclRef(Child); 2207 } 2208 2209 void TextNodeDumper::VisitObjCImplementationDecl( 2210 const ObjCImplementationDecl *D) { 2211 dumpName(D); 2212 dumpDeclRef(D->getSuperClass(), "super"); 2213 dumpDeclRef(D->getClassInterface()); 2214 } 2215 2216 void TextNodeDumper::VisitObjCCompatibleAliasDecl( 2217 const ObjCCompatibleAliasDecl *D) { 2218 dumpName(D); 2219 dumpDeclRef(D->getClassInterface()); 2220 } 2221 2222 void TextNodeDumper::VisitObjCPropertyDecl(const ObjCPropertyDecl *D) { 2223 dumpName(D); 2224 dumpType(D->getType()); 2225 2226 if (D->getPropertyImplementation() == ObjCPropertyDecl::Required) 2227 OS << " required"; 2228 else if (D->getPropertyImplementation() == ObjCPropertyDecl::Optional) 2229 OS << " optional"; 2230 2231 ObjCPropertyAttribute::Kind Attrs = D->getPropertyAttributes(); 2232 if (Attrs != ObjCPropertyAttribute::kind_noattr) { 2233 if (Attrs & ObjCPropertyAttribute::kind_readonly) 2234 OS << " readonly"; 2235 if (Attrs & ObjCPropertyAttribute::kind_assign) 2236 OS << " assign"; 2237 if (Attrs & ObjCPropertyAttribute::kind_readwrite) 2238 OS << " readwrite"; 2239 if (Attrs & ObjCPropertyAttribute::kind_retain) 2240 OS << " retain"; 2241 if (Attrs & ObjCPropertyAttribute::kind_copy) 2242 OS << " copy"; 2243 if (Attrs & ObjCPropertyAttribute::kind_nonatomic) 2244 OS << " nonatomic"; 2245 if (Attrs & ObjCPropertyAttribute::kind_atomic) 2246 OS << " atomic"; 2247 if (Attrs & ObjCPropertyAttribute::kind_weak) 2248 OS << " weak"; 2249 if (Attrs & ObjCPropertyAttribute::kind_strong) 2250 OS << " strong"; 2251 if (Attrs & ObjCPropertyAttribute::kind_unsafe_unretained) 2252 OS << " unsafe_unretained"; 2253 if (Attrs & ObjCPropertyAttribute::kind_class) 2254 OS << " class"; 2255 if (Attrs & ObjCPropertyAttribute::kind_direct) 2256 OS << " direct"; 2257 if (Attrs & ObjCPropertyAttribute::kind_getter) 2258 dumpDeclRef(D->getGetterMethodDecl(), "getter"); 2259 if (Attrs & ObjCPropertyAttribute::kind_setter) 2260 dumpDeclRef(D->getSetterMethodDecl(), "setter"); 2261 } 2262 } 2263 2264 void TextNodeDumper::VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D) { 2265 dumpName(D->getPropertyDecl()); 2266 if (D->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize) 2267 OS << " synthesize"; 2268 else 2269 OS << " dynamic"; 2270 dumpDeclRef(D->getPropertyDecl()); 2271 dumpDeclRef(D->getPropertyIvarDecl()); 2272 } 2273 2274 void TextNodeDumper::VisitBlockDecl(const BlockDecl *D) { 2275 if (D->isVariadic()) 2276 OS << " variadic"; 2277 2278 if (D->capturesCXXThis()) 2279 OS << " captures_this"; 2280 } 2281 2282 void TextNodeDumper::VisitConceptDecl(const ConceptDecl *D) { 2283 dumpName(D); 2284 } 2285