Skip to content

[clang][Frontend] Add overload to ASTPrinter that doesn't own output stream #142163

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions clang/include/clang/Frontend/ASTConsumers.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
20 changes: 20 additions & 0 deletions clang/lib/Frontend/ASTConsumers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,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();

Expand Down Expand Up @@ -176,6 +183,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);
}
Expand Down
Loading