https://github.com/mizvekov updated
https://github.com/llvm/llvm-project/pull/93766
>From 774fa391d3ba427adf81919c361dd4f01e72d6a1 Mon Sep 17 00:00:00 2001
From: Matheus Izvekov
Date: Thu, 30 May 2024 01:24:53 -0300
Subject: [PATCH] [clang] text ast-dumper: dump TemplateName for TST and DTST
Implement AST text dumping of the TemplateName for
TemplateSpecializationType and VisitDeducedTemplateSpecializationType.
---
clang/include/clang/AST/TemplateName.h| 4 ++
clang/include/clang/AST/TextNodeDumper.h | 3 +-
clang/lib/AST/TextNodeDumper.cpp | 43
clang/test/AST/ast-dump-ctad-alias.cpp| 6 ++-
clang/test/AST/ast-dump-template-decls.cpp| 14 --
clang/test/AST/ast-dump-template-name.cpp | 6 +++
clang/test/AST/ast-dump-using-template.cpp| 18 +--
clang/test/Import/builtin-template/test.cpp | 11 +---
.../aggregate-deduction-candidate.cpp | 4 +-
clang/test/SemaTemplate/deduction-guide.cpp | 22
clang/test/SemaTemplate/make_integer_seq.cpp | 50 +--
clang/test/SemaTemplate/type_pack_element.cpp | 34 +
12 files changed, 149 insertions(+), 66 deletions(-)
diff --git a/clang/include/clang/AST/TemplateName.h
b/clang/include/clang/AST/TemplateName.h
index 876be463c71d0..7aedc086ab7d0 100644
--- a/clang/include/clang/AST/TemplateName.h
+++ b/clang/include/clang/AST/TemplateName.h
@@ -360,6 +360,10 @@ class TemplateName {
static TemplateName getFromVoidPointer(void *Ptr) {
return TemplateName(Ptr);
}
+
+ /// Structural equality.
+ bool operator==(TemplateName Other) const { return Storage == Other.Storage;
}
+ bool operator!=(TemplateName Other) const { return !operator==(Other); }
};
/// Insertion operator for diagnostics. This allows sending TemplateName's
diff --git a/clang/include/clang/AST/TextNodeDumper.h
b/clang/include/clang/AST/TextNodeDumper.h
index 63fa16c9ec47c..caa33abd99e47 100644
--- a/clang/include/clang/AST/TextNodeDumper.h
+++ b/clang/include/clang/AST/TextNodeDumper.h
@@ -214,7 +214,8 @@ class TextNodeDumper
void dumpNestedNameSpecifier(const NestedNameSpecifier *NNS);
void dumpConceptReference(const ConceptReference *R);
void dumpTemplateArgument(const TemplateArgument &TA);
- void dumpTemplateName(TemplateName TN);
+ void dumpBareTemplateName(TemplateName TN);
+ void dumpTemplateName(TemplateName TN, StringRef Label = {});
void dumpDeclRef(const Decl *D, StringRef Label = {});
diff --git a/clang/lib/AST/TextNodeDumper.cpp b/clang/lib/AST/TextNodeDumper.cpp
index a0eedc71ea220..0e0e0a86f5cfc 100644
--- a/clang/lib/AST/TextNodeDumper.cpp
+++ b/clang/lib/AST/TextNodeDumper.cpp
@@ -1126,7 +1126,32 @@ void TextNodeDumper::VisitIntegralTemplateArgument(const
TemplateArgument &TA) {
dumpTemplateArgument(TA);
}
-void TextNodeDumper::dumpTemplateName(TemplateName TN) {
+void TextNodeDumper::dumpTemplateName(TemplateName TN, StringRef Label) {
+ AddChild(Label, [=] {
+{
+ llvm::SmallString<128> Str;
+ {
+llvm::raw_svector_ostream SS(Str);
+TN.print(SS, PrintPolicy);
+ }
+ OS << " '" << Str << "'";
+
+ if (TemplateName CanonTN = Context->getCanonicalTemplateName(TN);
+ CanonTN != TN) {
+llvm::SmallString<128> CanonStr;
+{
+ llvm::raw_svector_ostream SS(CanonStr);
+ CanonTN.print(SS, PrintPolicy);
+}
+if (CanonStr != Str)
+ OS << ":'" << CanonStr << "'";
+ }
+}
+dumpBareTemplateName(TN);
+ });
+}
+
+void TextNodeDumper::dumpBareTemplateName(TemplateName TN) {
switch (TN.getKind()) {
case TemplateName::Template:
AddChild([=] { Visit(TN.getAsTemplateDecl()); });
@@ -1143,7 +1168,7 @@ void TextNodeDumper::dumpTemplateName(TemplateName TN) {
if (QTN->hasTemplateKeyword())
OS << " keyword";
dumpNestedNameSpecifier(QTN->getQualifier());
-dumpTemplateName(QTN->getUnderlyingTemplate());
+dumpBareTemplateName(QTN->getUnderlyingTemplate());
return;
}
case TemplateName::DependentTemplate: {
@@ -1162,7 +1187,7 @@ void TextNodeDumper::dumpTemplateName(TemplateName TN) {
if (const TemplateTemplateParmDecl *P = STS->getParameter())
AddChild("parameter", [=] { Visit(P); });
dumpDeclRef(STS->getAssociatedDecl(), "associated");
-AddChild("replacement", [=] { dumpTemplateName(STS->getReplacement()); });
+dumpTemplateName(STS->getReplacement(), "replacement");
return;
}
// FIXME: Implement these.
@@ -1182,14 +1207,14 @@ void TextNodeDumper::dumpTemplateName(TemplateName TN) {
void TextNodeDumper::VisitTemplateTemplateArgument(const TemplateArgument &TA)
{
OS << " template";
dumpTemplateArgument(TA);
- dumpTemplateName(TA.getAsTemplate());
+ dumpBareTemplateName(TA.getAsTemplate());
}
void TextNodeDumper::VisitTemplateExpansionTemplateArgument(
const TemplateArgument &TA) {
OS << " template expansion";
dumpTemplateArgu