[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.
This commit is contained in:
parent
8f3ccd1674
commit
41d6343978
@ -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();
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user