Author: Michael Buch Date: 2025-06-02T10:19:24+01:00 New Revision: 41d634397823d01c20db783cf18c9b0c2c41fbf4
URL: https://github.com/llvm/llvm-project/commit/41d634397823d01c20db783cf18c9b0c2c41fbf4 DIFF: https://github.com/llvm/llvm-project/commit/41d634397823d01c20db783cf18c9b0c2c41fbf4.diff LOG: [clang][Frontend] Add overload to ASTPrinter that doesn't own output stream (#142163) We're planning on using the ASTPrinter in LLDB for AST dumping. But it currently takes the output stream via `unique_ptr`. In LLDB we don't have the output stream available in this form and instead it would be convenient if we could just pass a reference to the stream. This patch adds that overload. Added: Modified: clang/include/clang/Frontend/ASTConsumers.h clang/lib/Frontend/ASTConsumers.cpp Removed: ################################################################################ diff --git a/clang/include/clang/Frontend/ASTConsumers.h b/clang/include/clang/Frontend/ASTConsumers.h index 0e068bf5cccb5..890701b6ff188 100644 --- a/clang/include/clang/Frontend/ASTConsumers.h +++ b/clang/include/clang/Frontend/ASTConsumers.h @@ -35,6 +35,11 @@ CreateASTDumper(std::unique_ptr<raw_ostream> OS, StringRef FilterString, bool DumpDecls, bool Deserialize, bool DumpLookups, bool DumpDeclTypes, ASTDumpOutputFormat Format); +std::unique_ptr<ASTConsumer> +CreateASTDumper(raw_ostream &OS, StringRef FilterString, bool DumpDecls, + bool Deserialize, bool DumpLookups, bool DumpDeclTypes, + ASTDumpOutputFormat Format); + // AST Decl node lister: prints qualified names of all filterable AST Decl // nodes. std::unique_ptr<ASTConsumer> CreateASTDeclNodeLister(); diff --git a/clang/lib/Frontend/ASTConsumers.cpp b/clang/lib/Frontend/ASTConsumers.cpp index a5ec6961fbf0e..ab8a35a189250 100644 --- a/clang/lib/Frontend/ASTConsumers.cpp +++ b/clang/lib/Frontend/ASTConsumers.cpp @@ -38,6 +38,13 @@ namespace { OutputKind(K), OutputFormat(Format), FilterString(FilterString), DumpLookups(DumpLookups), DumpDeclTypes(DumpDeclTypes) {} + ASTPrinter(raw_ostream &Out, Kind K, ASTDumpOutputFormat Format, + StringRef FilterString, bool DumpLookups = false, + bool DumpDeclTypes = false) + : Out(Out), OwnedOut(nullptr), OutputKind(K), OutputFormat(Format), + FilterString(FilterString), DumpLookups(DumpLookups), + DumpDeclTypes(DumpDeclTypes) {} + void HandleTranslationUnit(ASTContext &Context) override { TranslationUnitDecl *D = Context.getTranslationUnitDecl(); @@ -173,6 +180,19 @@ clang::CreateASTDumper(std::unique_ptr<raw_ostream> Out, StringRef FilterString, Format, FilterString, DumpLookups, DumpDeclTypes); } +std::unique_ptr<ASTConsumer> +clang::CreateASTDumper(raw_ostream &Out, StringRef FilterString, bool DumpDecls, + bool Deserialize, bool DumpLookups, bool DumpDeclTypes, + ASTDumpOutputFormat Format) { + assert((DumpDecls || Deserialize || DumpLookups) && "nothing to dump"); + return std::make_unique<ASTPrinter>(Out, + Deserialize ? ASTPrinter::DumpFull + : DumpDecls ? ASTPrinter::Dump + : ASTPrinter::None, + Format, FilterString, DumpLookups, + DumpDeclTypes); +} + std::unique_ptr<ASTConsumer> clang::CreateASTDeclNodeLister() { return std::make_unique<ASTDeclNodeLister>(nullptr); } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits