Skip to content

Commit 3f6fe4e

Browse files
authored
[clang] NFCI: improve TemplateArgument and TemplateName dump methods (#94905)
These will work as AST Text node dumpers, as usual, instead of AST printers. Note that for now, the TemplateName dumper is using the TemplateArgument dumper through an implicit conversion. This can be fixed in a later pass.
1 parent 97cfe54 commit 3f6fe4e

File tree

5 files changed

+36
-22
lines changed

5 files changed

+36
-22
lines changed

clang/include/clang/AST/TemplateBase.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ class TemplateArgument {
459459
bool IncludeType) const;
460460

461461
/// Debugging aid that dumps the template argument.
462-
void dump(raw_ostream &Out) const;
462+
void dump(raw_ostream &Out, const ASTContext &Context) const;
463463

464464
/// Debugging aid that dumps the template argument to standard error.
465465
void dump() const;

clang/include/clang/AST/TemplateName.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ class TemplateName {
340340
Qualified Qual = Qualified::AsWritten) const;
341341

342342
/// Debugging aid that dumps the template name.
343-
void dump(raw_ostream &OS) const;
343+
void dump(raw_ostream &OS, const ASTContext &Context) const;
344344

345345
/// Debugging aid that dumps the template name to standard
346346
/// error.

clang/lib/AST/ASTDumper.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,3 +360,37 @@ LLVM_DUMP_METHOD void ConceptReference::dump(raw_ostream &OS) const {
360360
ASTDumper P(OS, Ctx, Ctx.getDiagnostics().getShowColors());
361361
P.Visit(this);
362362
}
363+
364+
//===----------------------------------------------------------------------===//
365+
// TemplateName method implementations
366+
//===----------------------------------------------------------------------===//
367+
368+
// FIXME: These are actually using the TemplateArgument dumper, through
369+
// an implicit conversion. The dump will claim this is a template argument,
370+
// which is misleading.
371+
372+
LLVM_DUMP_METHOD void TemplateName::dump() const {
373+
ASTDumper Dumper(llvm::errs(), /*ShowColors=*/false);
374+
Dumper.Visit(*this);
375+
}
376+
377+
LLVM_DUMP_METHOD void TemplateName::dump(llvm::raw_ostream &OS,
378+
const ASTContext &Context) const {
379+
ASTDumper Dumper(OS, Context, Context.getDiagnostics().getShowColors());
380+
Dumper.Visit(*this);
381+
}
382+
383+
//===----------------------------------------------------------------------===//
384+
// TemplateArgument method implementations
385+
//===----------------------------------------------------------------------===//
386+
387+
LLVM_DUMP_METHOD void TemplateArgument::dump() const {
388+
ASTDumper Dumper(llvm::errs(), /*ShowColors=*/false);
389+
Dumper.Visit(*this);
390+
}
391+
392+
LLVM_DUMP_METHOD void TemplateArgument::dump(llvm::raw_ostream &OS,
393+
const ASTContext &Context) const {
394+
ASTDumper Dumper(OS, Context, Context.getDiagnostics().getShowColors());
395+
Dumper.Visit(*this);
396+
}

clang/lib/AST/TemplateBase.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -577,15 +577,6 @@ void TemplateArgument::print(const PrintingPolicy &Policy, raw_ostream &Out,
577577
}
578578
}
579579

580-
void TemplateArgument::dump(raw_ostream &Out) const {
581-
LangOptions LO; // FIXME! see also TemplateName::dump().
582-
LO.CPlusPlus = true;
583-
LO.Bool = true;
584-
print(PrintingPolicy(LO), Out, /*IncludeType*/ true);
585-
}
586-
587-
LLVM_DUMP_METHOD void TemplateArgument::dump() const { dump(llvm::errs()); }
588-
589580
//===----------------------------------------------------------------------===//
590581
// TemplateArgumentLoc Implementation
591582
//===----------------------------------------------------------------------===//

clang/lib/AST/TemplateName.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -360,14 +360,3 @@ const StreamingDiagnostic &clang::operator<<(const StreamingDiagnostic &DB,
360360
OS.flush();
361361
return DB << NameStr;
362362
}
363-
364-
void TemplateName::dump(raw_ostream &OS) const {
365-
LangOptions LO; // FIXME!
366-
LO.CPlusPlus = true;
367-
LO.Bool = true;
368-
print(OS, PrintingPolicy(LO));
369-
}
370-
371-
LLVM_DUMP_METHOD void TemplateName::dump() const {
372-
dump(llvm::errs());
373-
}

0 commit comments

Comments
 (0)