[PATCH] D56643: NFC: Move Decl node handling to TextNodeDumper
This revision was automatically updated to reflect the committed changes. Closed by commit rC351175: NFC: Move Decl node handling to TextNodeDumper (authored by steveire, committed by ). Changed prior to commit: https://reviews.llvm.org/D56643?vs=181453=181740#toc Repository: rC Clang CHANGES SINCE LAST ACTION https://reviews.llvm.org/D56643/new/ https://reviews.llvm.org/D56643 Files: include/clang/AST/TextNodeDumper.h lib/AST/ASTDumper.cpp lib/AST/TextNodeDumper.cpp Index: include/clang/AST/TextNodeDumper.h === --- include/clang/AST/TextNodeDumper.h +++ include/clang/AST/TextNodeDumper.h @@ -165,6 +165,8 @@ void Visit(QualType T); + void Visit(const Decl *D); + void dumpPointer(const void *Ptr); void dumpLocation(SourceLocation Loc); void dumpSourceRange(SourceRange R); Index: lib/AST/ASTDumper.cpp === --- lib/AST/ASTDumper.cpp +++ lib/AST/ASTDumper.cpp @@ -435,35 +435,6 @@ }); } -static void dumpPreviousDeclImpl(raw_ostream , ...) {} - -template -static void dumpPreviousDeclImpl(raw_ostream , const Mergeable *D) { - const T *First = D->getFirstDecl(); - if (First != D) -OS << " first " << First; -} - -template -static void dumpPreviousDeclImpl(raw_ostream , const Redeclarable *D) { - const T *Prev = D->getPreviousDecl(); - if (Prev) -OS << " prev " << Prev; -} - -/// Dump the previous declaration in the redeclaration chain for a declaration, -/// if any. -static void dumpPreviousDecl(raw_ostream , const Decl *D) { - switch (D->getKind()) { -#define DECL(DERIVED, BASE) \ - case Decl::DERIVED: \ -return dumpPreviousDeclImpl(OS, cast(D)); -#define ABSTRACT_DECL(DECL) -#include "clang/AST/DeclNodes.inc" - } - llvm_unreachable("Decl that isn't part of DeclNodes.inc!"); -} - //===--===// // C++ Utilities //===--===// @@ -536,46 +507,9 @@ void ASTDumper::dumpDecl(const Decl *D) { dumpChild([=] { -if (!D) { - ColorScope Color(OS, ShowColors, NullColor); - OS << "<<>>"; +NodeDumper.Visit(D); +if (!D) return; -} - -{ - ColorScope Color(OS, ShowColors, DeclKindNameColor); - OS << D->getDeclKindName() << "Decl"; -} -NodeDumper.dumpPointer(D); -if (D->getLexicalDeclContext() != D->getDeclContext()) - OS << " parent " << cast(D->getDeclContext()); -dumpPreviousDecl(OS, D); -NodeDumper.dumpSourceRange(D->getSourceRange()); -OS << ' '; -NodeDumper.dumpLocation(D->getLocation()); -if (D->isFromASTFile()) - OS << " imported"; -if (Module *M = D->getOwningModule()) - OS << " in " << M->getFullModuleName(); -if (auto *ND = dyn_cast(D)) - for (Module *M : D->getASTContext().getModulesWithMergedDefinition( - const_cast(ND))) -dumpChild([=] { OS << "also in " << M->getFullModuleName(); }); -if (const NamedDecl *ND = dyn_cast(D)) - if (ND->isHidden()) -OS << " hidden"; -if (D->isImplicit()) - OS << " implicit"; -if (D->isUsed()) - OS << " used"; -else if (D->isThisDeclarationReferenced()) - OS << " referenced"; -if (D->isInvalidDecl()) - OS << " invalid"; -if (const FunctionDecl *FD = dyn_cast(D)) - if (FD->isConstexpr()) -OS << " constexpr"; - ConstDeclVisitor::Visit(D); Index: lib/AST/TextNodeDumper.cpp === --- lib/AST/TextNodeDumper.cpp +++ lib/AST/TextNodeDumper.cpp @@ -12,11 +12,42 @@ //===--===// #include "clang/AST/TextNodeDumper.h" +#include "clang/AST/DeclFriend.h" +#include "clang/AST/DeclOpenMP.h" #include "clang/AST/DeclTemplate.h" #include "clang/AST/LocInfoType.h" using namespace clang; +static void dumpPreviousDeclImpl(raw_ostream , ...) {} + +template +static void dumpPreviousDeclImpl(raw_ostream , const Mergeable *D) { + const T *First = D->getFirstDecl(); + if (First != D) +OS << " first " << First; +} + +template +static void dumpPreviousDeclImpl(raw_ostream , const Redeclarable *D) { + const T *Prev = D->getPreviousDecl(); + if (Prev) +OS << " prev " << Prev; +} + +/// Dump the previous declaration in the redeclaration chain for a declaration, +/// if any. +static void dumpPreviousDecl(raw_ostream , const Decl *D) { + switch (D->getKind()) { +#define DECL(DERIVED, BASE)\ + case Decl::DERIVED: \ +return dumpPreviousDeclImpl(OS, cast(D)); +#define ABSTRACT_DECL(DECL) +#include "clang/AST/DeclNodes.inc" + } + llvm_unreachable("Decl that isn't part of DeclNodes.inc!"); +} +
[PATCH] D56643: NFC: Move Decl node handling to TextNodeDumper
aaron.ballman accepted this revision. aaron.ballman added a comment. This revision is now accepted and ready to land. LGTM aside from some minor nits. Comment at: lib/AST/ASTDumper.cpp:518 +NodeDumper.Visit(D); if (!D) { return; Elide braces. Comment at: lib/AST/TextNodeDumper.cpp:239 +OS << " in " << M->getFullModuleName(); + if (auto *ND = dyn_cast(D)) +for (Module *M : D->getASTContext().getModulesWithMergedDefinition( `const auto *` (which helps to clarify the `const_cast<>` below.) Comment at: lib/AST/TextNodeDumper.cpp:243 + AddChild([=] { OS << "also in " << M->getFullModuleName(); }); + if (const NamedDecl *ND = dyn_cast(D)) +if (ND->isHidden()) `const auto *` Comment at: lib/AST/TextNodeDumper.cpp:248-251 + if (D->isUsed()) +OS << " used"; + else if (D->isThisDeclarationReferenced()) +OS << " referenced"; Surround these with newlines for visual clarity. Comment at: lib/AST/TextNodeDumper.cpp:254 +OS << " invalid"; + if (const FunctionDecl *FD = dyn_cast(D)) +if (FD->isConstexpr()) `const auto *` Repository: rC Clang CHANGES SINCE LAST ACTION https://reviews.llvm.org/D56643/new/ https://reviews.llvm.org/D56643 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D56643: NFC: Move Decl node handling to TextNodeDumper
steveire created this revision. steveire added a reviewer: aaron.ballman. Herald added a subscriber: cfe-commits. Repository: rC Clang https://reviews.llvm.org/D56643 Files: include/clang/AST/TextNodeDumper.h lib/AST/ASTDumper.cpp lib/AST/TextNodeDumper.cpp Index: lib/AST/TextNodeDumper.cpp === --- lib/AST/TextNodeDumper.cpp +++ lib/AST/TextNodeDumper.cpp @@ -13,11 +13,42 @@ #include "clang/AST/TextNodeDumper.h" +#include "clang/AST/DeclFriend.h" +#include "clang/AST/DeclOpenMP.h" #include "clang/AST/DeclTemplate.h" #include "clang/AST/LocInfoType.h" using namespace clang; +static void dumpPreviousDeclImpl(raw_ostream , ...) {} + +template +static void dumpPreviousDeclImpl(raw_ostream , const Mergeable *D) { + const T *First = D->getFirstDecl(); + if (First != D) +OS << " first " << First; +} + +template +static void dumpPreviousDeclImpl(raw_ostream , const Redeclarable *D) { + const T *Prev = D->getPreviousDecl(); + if (Prev) +OS << " prev " << Prev; +} + +/// Dump the previous declaration in the redeclaration chain for a declaration, +/// if any. +static void dumpPreviousDecl(raw_ostream , const Decl *D) { + switch (D->getKind()) { +#define DECL(DERIVED, BASE)\ + case Decl::DERIVED: \ +return dumpPreviousDeclImpl(OS, cast(D)); +#define ABSTRACT_DECL(DECL) +#include "clang/AST/DeclNodes.inc" + } + llvm_unreachable("Decl that isn't part of DeclNodes.inc!"); +} + TextNodeDumper::TextNodeDumper(raw_ostream , bool ShowColors, const SourceManager *SM, const PrintingPolicy , @@ -183,6 +214,48 @@ OS << " " << T.split().Quals.getAsString(); } +void TextNodeDumper::Visit(const Decl *D) { + if (!D) { +ColorScope Color(OS, ShowColors, NullColor); +OS << "<<>>"; +return; + } + + { +ColorScope Color(OS, ShowColors, DeclKindNameColor); +OS << D->getDeclKindName() << "Decl"; + } + dumpPointer(D); + if (D->getLexicalDeclContext() != D->getDeclContext()) +OS << " parent " << cast(D->getDeclContext()); + dumpPreviousDecl(OS, D); + dumpSourceRange(D->getSourceRange()); + OS << ' '; + dumpLocation(D->getLocation()); + if (D->isFromASTFile()) +OS << " imported"; + if (Module *M = D->getOwningModule()) +OS << " in " << M->getFullModuleName(); + if (auto *ND = dyn_cast(D)) +for (Module *M : D->getASTContext().getModulesWithMergedDefinition( + const_cast(ND))) + AddChild([=] { OS << "also in " << M->getFullModuleName(); }); + if (const NamedDecl *ND = dyn_cast(D)) +if (ND->isHidden()) + OS << " hidden"; + if (D->isImplicit()) +OS << " implicit"; + if (D->isUsed()) +OS << " used"; + else if (D->isThisDeclarationReferenced()) +OS << " referenced"; + if (D->isInvalidDecl()) +OS << " invalid"; + if (const FunctionDecl *FD = dyn_cast(D)) +if (FD->isConstexpr()) + OS << " constexpr"; +} + void TextNodeDumper::dumpPointer(const void *Ptr) { ColorScope Color(OS, ShowColors, AddressColor); OS << ' ' << Ptr; Index: lib/AST/ASTDumper.cpp === --- lib/AST/ASTDumper.cpp +++ lib/AST/ASTDumper.cpp @@ -442,35 +442,6 @@ }); } -static void dumpPreviousDeclImpl(raw_ostream , ...) {} - -template -static void dumpPreviousDeclImpl(raw_ostream , const Mergeable *D) { - const T *First = D->getFirstDecl(); - if (First != D) -OS << " first " << First; -} - -template -static void dumpPreviousDeclImpl(raw_ostream , const Redeclarable *D) { - const T *Prev = D->getPreviousDecl(); - if (Prev) -OS << " prev " << Prev; -} - -/// Dump the previous declaration in the redeclaration chain for a declaration, -/// if any. -static void dumpPreviousDecl(raw_ostream , const Decl *D) { - switch (D->getKind()) { -#define DECL(DERIVED, BASE) \ - case Decl::DERIVED: \ -return dumpPreviousDeclImpl(OS, cast(D)); -#define ABSTRACT_DECL(DECL) -#include "clang/AST/DeclNodes.inc" - } - llvm_unreachable("Decl that isn't part of DeclNodes.inc!"); -} - //===--===// // C++ Utilities //===--===// @@ -543,47 +514,11 @@ void ASTDumper::dumpDecl(const Decl *D) { dumpChild([=] { +NodeDumper.Visit(D); if (!D) { - ColorScope Color(OS, ShowColors, NullColor); - OS << "<<>>"; return; } -{ - ColorScope Color(OS, ShowColors, DeclKindNameColor); - OS << D->getDeclKindName() << "Decl"; -} -NodeDumper.dumpPointer(D); -if (D->getLexicalDeclContext() != D->getDeclContext()) - OS << " parent " << cast(D->getDeclContext()); -dumpPreviousDecl(OS, D); -NodeDumper.dumpSourceRange(D->getSourceRange()); -