/// dumpPretty/printPretty - These two methods do a "pretty print" of the AST
/// back to its original source language syntax.
- void dumpPretty() const;
- void printPretty(llvm::raw_ostream &OS, PrinterHelper* = 0,
+ void dumpPretty(ASTContext& Context) const;
+ void printPretty(llvm::raw_ostream &OS, PrinterHelper *Helper = 0,
+ const PrintingPolicy &Policy = PrintingPolicy(),
+ unsigned Indentation = 0) const {
+ printPretty(OS, *(ASTContext*)0, Helper, Policy, Indentation);
+ }
+ void printPretty(llvm::raw_ostream &OS, ASTContext& Context,
+ PrinterHelper *Helper = 0,
const PrintingPolicy &Policy = PrintingPolicy(),
unsigned Indentation = 0) const;
for (DeclContext::decl_iterator D = DC->decls_begin(Context),
DEnd = DC->decls_end(Context);
D != DEnd; ++D) {
+ if (!Policy.Dump) {
+ // Skip over implicit declarations in pretty-printing mode.
+ if (D->isImplicit()) continue;
+ }
+
// The next bits of code handles stuff like "struct {int x;} a,b"; we're
// forced to merge the declarations because there's no other way to
// refer to the struct in question. This limited merging is safe without
Out << D->getNameAsString();
if (Expr *Init = D->getInitExpr()) {
Out << " = ";
- Init->printPretty(Out, 0, Policy, Indentation);
+ Init->printPretty(Out, Context, 0, Policy, Indentation);
}
}
} else
Out << ' ';
- D->getBody(Context)->printPretty(Out, 0, Policy, Indentation);
+ D->getBody(Context)->printPretty(Out, Context, 0, Policy, Indentation);
Out << '\n';
}
}
if (D->isBitField()) {
Out << " : ";
- D->getBitWidth()->printPretty(Out, 0, Policy, Indentation);
+ D->getBitWidth()->printPretty(Out, Context, 0, Policy, Indentation);
}
}
Out << "(";
else
Out << " = ";
- D->getInit()->printPretty(Out, 0, Policy, Indentation);
+ D->getInit()->printPretty(Out, Context, 0, Policy, Indentation);
if (D->hasCXXDirectInitializer())
Out << ")";
}
void DeclPrinter::VisitFileScopeAsmDecl(FileScopeAsmDecl *D) {
Out << "__asm (";
- D->getAsmString()->printPretty(Out, 0, Policy, Indentation);
+ D->getAsmString()->printPretty(Out, Context, 0, Policy, Indentation);
Out << ")";
}
if (OMD->getBody()) {
Out << ' ';
- OMD->getBody()->printPretty(Out, 0, Policy);
+ OMD->getBody()->printPretty(Out, Context, 0, Policy);
Out << '\n';
}
}
namespace {
class VISIBILITY_HIDDEN StmtPrinter : public StmtVisitor<StmtPrinter> {
llvm::raw_ostream &OS;
+ ASTContext &Context;
unsigned IndentLevel;
clang::PrinterHelper* Helper;
PrintingPolicy Policy;
public:
- StmtPrinter(llvm::raw_ostream &os, PrinterHelper* helper,
+ StmtPrinter(llvm::raw_ostream &os, ASTContext &C, PrinterHelper* helper,
const PrintingPolicy &Policy = PrintingPolicy(),
unsigned Indentation = 0)
- : OS(os), IndentLevel(Indentation), Helper(helper), Policy(Policy) {}
+ : OS(os), Context(C), IndentLevel(Indentation), Helper(helper),
+ Policy(Policy) {}
void PrintStmt(Stmt *S) {
PrintStmt(S, Policy.Indentation);
}
void StmtPrinter::PrintRawDecl(Decl *D) {
- D->print(OS, *(ASTContext*)0, Policy, IndentLevel);
+ D->print(OS, Context, Policy, IndentLevel);
}
void StmtPrinter::PrintRawDeclStmt(DeclStmt *S) {
for ( ; Begin != End; ++Begin)
Decls.push_back(*Begin);
- Decl::printGroup(Decls.data(), Decls.size(), OS, *(ASTContext*)0, Policy,
+ Decl::printGroup(Decls.data(), Decls.size(), OS, Context, Policy,
IndentLevel);
}
// Stmt method implementations
//===----------------------------------------------------------------------===//
-void Stmt::dumpPretty() const {
- printPretty(llvm::errs(), 0, PrintingPolicy());
+void Stmt::dumpPretty(ASTContext& Context) const {
+ printPretty(llvm::errs(), Context, 0, PrintingPolicy());
}
-void Stmt::printPretty(llvm::raw_ostream &OS, PrinterHelper* Helper,
+void Stmt::printPretty(llvm::raw_ostream &OS, ASTContext& Context,
+ PrinterHelper* Helper,
const PrintingPolicy &Policy,
unsigned Indentation) const {
if (this == 0) {
return;
}
- StmtPrinter P(OS, Helper, Policy, Indentation);
+ StmtPrinter P(OS, Context, Helper, Policy, Indentation);
P.Visit(const_cast<Stmt*>(this));
}