Skip to content

Commit 0d2eae4

Browse files
Michael137DhruvSrivastavaX
authored andcommitted
[clang][Frontend] Add overload to ASTPrinter that doesn't own output stream (llvm#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.
1 parent 3d91949 commit 0d2eae4

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

clang/include/clang/Frontend/ASTConsumers.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ CreateASTDumper(std::unique_ptr<raw_ostream> OS, StringRef FilterString,
3535
bool DumpDecls, bool Deserialize, bool DumpLookups,
3636
bool DumpDeclTypes, ASTDumpOutputFormat Format);
3737

38+
std::unique_ptr<ASTConsumer>
39+
CreateASTDumper(raw_ostream &OS, StringRef FilterString, bool DumpDecls,
40+
bool Deserialize, bool DumpLookups, bool DumpDeclTypes,
41+
ASTDumpOutputFormat Format);
42+
3843
// AST Decl node lister: prints qualified names of all filterable AST Decl
3944
// nodes.
4045
std::unique_ptr<ASTConsumer> CreateASTDeclNodeLister();

clang/lib/Frontend/ASTConsumers.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ namespace {
3838
OutputKind(K), OutputFormat(Format), FilterString(FilterString),
3939
DumpLookups(DumpLookups), DumpDeclTypes(DumpDeclTypes) {}
4040

41+
ASTPrinter(raw_ostream &Out, Kind K, ASTDumpOutputFormat Format,
42+
StringRef FilterString, bool DumpLookups = false,
43+
bool DumpDeclTypes = false)
44+
: Out(Out), OwnedOut(nullptr), OutputKind(K), OutputFormat(Format),
45+
FilterString(FilterString), DumpLookups(DumpLookups),
46+
DumpDeclTypes(DumpDeclTypes) {}
47+
4148
void HandleTranslationUnit(ASTContext &Context) override {
4249
TranslationUnitDecl *D = Context.getTranslationUnitDecl();
4350

@@ -173,6 +180,19 @@ clang::CreateASTDumper(std::unique_ptr<raw_ostream> Out, StringRef FilterString,
173180
Format, FilterString, DumpLookups, DumpDeclTypes);
174181
}
175182

183+
std::unique_ptr<ASTConsumer>
184+
clang::CreateASTDumper(raw_ostream &Out, StringRef FilterString, bool DumpDecls,
185+
bool Deserialize, bool DumpLookups, bool DumpDeclTypes,
186+
ASTDumpOutputFormat Format) {
187+
assert((DumpDecls || Deserialize || DumpLookups) && "nothing to dump");
188+
return std::make_unique<ASTPrinter>(Out,
189+
Deserialize ? ASTPrinter::DumpFull
190+
: DumpDecls ? ASTPrinter::Dump
191+
: ASTPrinter::None,
192+
Format, FilterString, DumpLookups,
193+
DumpDeclTypes);
194+
}
195+
176196
std::unique_ptr<ASTConsumer> clang::CreateASTDeclNodeLister() {
177197
return std::make_unique<ASTDeclNodeLister>(nullptr);
178198
}

0 commit comments

Comments
 (0)