[clang] [clang] ast-dump: print all pointers with color (PR #174954)
Luís Marques via cfe-commits
cfe-commits at lists.llvm.org
Thu Jan 8 04:04:47 PST 2026
https://github.com/luismarques updated https://github.com/llvm/llvm-project/pull/174954
>From 77cf085526f62f2f3181b92fdd15226aa926ad2b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Lu=C3=ADs=20Marques?= <luismarques at lowrisc.org>
Date: Tue, 6 Jan 2026 14:46:23 +0000
Subject: [PATCH] [clang] ast-dump: print all pointers with color
Some pointers were being directly printed to the raw_ostream instance,
instead of using the dumpPointer method. Because of that inconsistency,
those directly printed pointers would not be appropriately colored. This
patch ensures more uniform use of dumpPointer, and thus that (hopefully)
all pointers are appropriately colored.
---
clang/lib/AST/TextNodeDumper.cpp | 38 ++++++++++++++++++++------------
1 file changed, 24 insertions(+), 14 deletions(-)
diff --git a/clang/lib/AST/TextNodeDumper.cpp b/clang/lib/AST/TextNodeDumper.cpp
index 7bc0404db1bee..40a0bb17eb085 100644
--- a/clang/lib/AST/TextNodeDumper.cpp
+++ b/clang/lib/AST/TextNodeDumper.cpp
@@ -31,29 +31,36 @@
using namespace clang;
-static void dumpPreviousDeclImpl(raw_ostream &OS, ...) {}
+static void dumpPreviousDeclImpl(TextNodeDumper &TND, raw_ostream &OS, ...) {}
template <typename T>
-static void dumpPreviousDeclImpl(raw_ostream &OS, const Mergeable<T> *D) {
+static void dumpPreviousDeclImpl(TextNodeDumper &TND, raw_ostream &OS,
+ const Mergeable<T> *D) {
const T *First = D->getFirstDecl();
- if (First != D)
- OS << " first " << First;
+ if (First != D) {
+ OS << " first";
+ TND.dumpPointer(First);
+ }
}
template <typename T>
-static void dumpPreviousDeclImpl(raw_ostream &OS, const Redeclarable<T> *D) {
+static void dumpPreviousDeclImpl(TextNodeDumper &TND, raw_ostream &OS,
+ const Redeclarable<T> *D) {
const T *Prev = D->getPreviousDecl();
- if (Prev)
- OS << " prev " << Prev;
+ if (Prev) {
+ OS << " prev";
+ TND.dumpPointer(Prev);
+ }
}
/// Dump the previous declaration in the redeclaration chain for a declaration,
/// if any.
-static void dumpPreviousDecl(raw_ostream &OS, const Decl *D) {
+static void dumpPreviousDecl(TextNodeDumper &TND, raw_ostream &OS,
+ const Decl *D) {
switch (D->getKind()) {
#define DECL(DERIVED, BASE) \
case Decl::DERIVED: \
- return dumpPreviousDeclImpl(OS, cast<DERIVED##Decl>(D));
+ return dumpPreviousDeclImpl(TND, OS, cast<DERIVED##Decl>(D));
#define ABSTRACT_DECL(DECL)
#include "clang/AST/DeclNodes.inc"
}
@@ -275,9 +282,11 @@ void TextNodeDumper::Visit(const Decl *D) {
OS << D->getDeclKindName() << "Decl";
}
dumpPointer(D);
- if (D->getLexicalDeclContext() != D->getDeclContext())
- OS << " parent " << cast<Decl>(D->getDeclContext());
- dumpPreviousDecl(OS, D);
+ if (D->getLexicalDeclContext() != D->getDeclContext()) {
+ OS << " parent";
+ dumpPointer(cast<Decl>(D->getDeclContext()));
+ }
+ dumpPreviousDecl(*this, OS, D);
dumpSourceRange(D->getSourceRange());
OS << ' ';
dumpLocation(D->getLocation());
@@ -2355,13 +2364,14 @@ void TextNodeDumper::VisitFunctionDecl(const FunctionDecl *D) {
if (MD->size_overridden_methods() != 0) {
auto dumpOverride = [=](const CXXMethodDecl *D) {
SplitQualType T_split = D->getType().split();
- OS << D << " " << D->getParent()->getName() << "::" << D->getDeclName()
+ dumpPointer(D);
+ OS << " " << D->getParent()->getName() << "::" << D->getDeclName()
<< " '" << QualType::getAsString(T_split, PrintPolicy) << "'";
};
AddChild([=] {
auto Overrides = MD->overridden_methods();
- OS << "Overrides: [ ";
+ OS << "Overrides: [";
dumpOverride(*Overrides.begin());
for (const auto *Override : llvm::drop_begin(Overrides)) {
OS << ", ";
More information about the cfe-commits
mailing list