r351175 - NFC: Move Decl node handling to TextNodeDumper
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Tue Jan 15 05:06:34 PST 2019
On Tue, Jan 15, 2019 at 4:39 AM Stephen Kelly via cfe-commits
<cfe-commits at lists.llvm.org> wrote:
>
> Author: steveire
> Date: Tue Jan 15 01:35:52 2019
> New Revision: 351175
>
> URL: http://llvm.org/viewvc/llvm-project?rev=351175&view=rev
> Log:
> NFC: Move Decl node handling to TextNodeDumper
>
> Reviewers: aaron.ballman
>
> Subscribers: cfe-commits
>
> Differential Revision: https://reviews.llvm.org/D56643
>
> Modified:
> cfe/trunk/include/clang/AST/TextNodeDumper.h
> cfe/trunk/lib/AST/ASTDumper.cpp
> cfe/trunk/lib/AST/TextNodeDumper.cpp
>
> Modified: cfe/trunk/include/clang/AST/TextNodeDumper.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/TextNodeDumper.h?rev=351175&r1=351174&r2=351175&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/AST/TextNodeDumper.h (original)
> +++ cfe/trunk/include/clang/AST/TextNodeDumper.h Tue Jan 15 01:35:52 2019
> @@ -165,6 +165,8 @@ public:
>
> void Visit(QualType T);
>
> + void Visit(const Decl *D);
> +
> void dumpPointer(const void *Ptr);
> void dumpLocation(SourceLocation Loc);
> void dumpSourceRange(SourceRange R);
>
> Modified: cfe/trunk/lib/AST/ASTDumper.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTDumper.cpp?rev=351175&r1=351174&r2=351175&view=diff
> ==============================================================================
> --- cfe/trunk/lib/AST/ASTDumper.cpp (original)
> +++ cfe/trunk/lib/AST/ASTDumper.cpp Tue Jan 15 01:35:52 2019
> @@ -435,35 +435,6 @@ void ASTDumper::dumpAttr(const Attr *A)
> });
> }
>
> -static void dumpPreviousDeclImpl(raw_ostream &OS, ...) {}
> -
> -template<typename T>
> -static void dumpPreviousDeclImpl(raw_ostream &OS, const Mergeable<T> *D) {
> - const T *First = D->getFirstDecl();
> - if (First != D)
> - OS << " first " << First;
> -}
> -
> -template<typename T>
> -static void dumpPreviousDeclImpl(raw_ostream &OS, const Redeclarable<T> *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 &OS, const Decl *D) {
> - switch (D->getKind()) {
> -#define DECL(DERIVED, BASE) \
> - case Decl::DERIVED: \
> - return dumpPreviousDeclImpl(OS, cast<DERIVED##Decl>(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::dumpObjCTypeParamList(co
>
> void ASTDumper::dumpDecl(const Decl *D) {
> dumpChild([=] {
> - if (!D) {
> - ColorScope Color(OS, ShowColors, NullColor);
> - OS << "<<<NULL>>>";
> + 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<Decl>(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<NamedDecl>(D))
> - for (Module *M : D->getASTContext().getModulesWithMergedDefinition(
> - const_cast<NamedDecl *>(ND)))
> - dumpChild([=] { OS << "also in " << M->getFullModuleName(); });
> - if (const NamedDecl *ND = dyn_cast<NamedDecl>(D))
This wasn't switched over to `const auto *` as asked for in the review.
> - 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<FunctionDecl>(D))
> - if (FD->isConstexpr())
> - OS << " constexpr";
> -
>
> ConstDeclVisitor<ASTDumper>::Visit(D);
>
>
> Modified: cfe/trunk/lib/AST/TextNodeDumper.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/TextNodeDumper.cpp?rev=351175&r1=351174&r2=351175&view=diff
> ==============================================================================
> --- cfe/trunk/lib/AST/TextNodeDumper.cpp (original)
> +++ cfe/trunk/lib/AST/TextNodeDumper.cpp Tue Jan 15 01:35:52 2019
> @@ -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 &OS, ...) {}
> +
> +template <typename T>
> +static void dumpPreviousDeclImpl(raw_ostream &OS, const Mergeable<T> *D) {
> + const T *First = D->getFirstDecl();
> + if (First != D)
> + OS << " first " << First;
> +}
> +
> +template <typename T>
> +static void dumpPreviousDeclImpl(raw_ostream &OS, const Redeclarable<T> *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 &OS, const Decl *D) {
> + switch (D->getKind()) {
> +#define DECL(DERIVED, BASE) \
> + case Decl::DERIVED: \
> + return dumpPreviousDeclImpl(OS, cast<DERIVED##Decl>(D));
> +#define ABSTRACT_DECL(DECL)
> +#include "clang/AST/DeclNodes.inc"
> + }
> + llvm_unreachable("Decl that isn't part of DeclNodes.inc!");
> +}
> +
> TextNodeDumper::TextNodeDumper(raw_ostream &OS, bool ShowColors,
> const SourceManager *SM,
> const PrintingPolicy &PrintPolicy,
> @@ -183,6 +214,50 @@ void TextNodeDumper::Visit(QualType T) {
> OS << " " << T.split().Quals.getAsString();
> }
>
> +void TextNodeDumper::Visit(const Decl *D) {
> + if (!D) {
> + ColorScope Color(OS, ShowColors, NullColor);
> + OS << "<<<NULL>>>";
> + return;
> + }
> +
> + {
> + ColorScope Color(OS, ShowColors, DeclKindNameColor);
> + OS << D->getDeclKindName() << "Decl";
> + }
> + dumpPointer(D);
> + if (D->getLexicalDeclContext() != D->getDeclContext())
> + OS << " parent " << cast<Decl>(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<NamedDecl>(D))
Likewise here
> + for (Module *M : D->getASTContext().getModulesWithMergedDefinition(
> + const_cast<NamedDecl *>(ND)))
> + AddChild([=] { OS << "also in " << M->getFullModuleName(); });
> + if (const NamedDecl *ND = dyn_cast<NamedDecl>(D))
and here. Can you take care of those?
~Aaron
> + 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<FunctionDecl>(D))
> + if (FD->isConstexpr())
> + OS << " constexpr";
> +}
> +
> void TextNodeDumper::dumpPointer(const void *Ptr) {
> ColorScope Color(OS, ShowColors, AddressColor);
> OS << ' ' << Ptr;
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
More information about the cfe-commits
mailing list