[cfe-commits] r72609 - in /cfe/trunk: include/clang/AST/Stmt.h lib/AST/DeclPrinter.cpp lib/AST/StmtPrinter.cpp
Eli Friedman
eli.friedman at gmail.com
Fri May 29 22:03:24 PDT 2009
Author: efriedma
Date: Sat May 30 00:03:24 2009
New Revision: 72609
URL: http://llvm.org/viewvc/llvm-project?rev=72609&view=rev
Log:
Add a Stmt::printPretty overload which takes an ASTContext; start
transitioning callers over to pass one in.
Modified:
cfe/trunk/include/clang/AST/Stmt.h
cfe/trunk/lib/AST/DeclPrinter.cpp
cfe/trunk/lib/AST/StmtPrinter.cpp
Modified: cfe/trunk/include/clang/AST/Stmt.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Stmt.h?rev=72609&r1=72608&r2=72609&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Stmt.h (original)
+++ cfe/trunk/include/clang/AST/Stmt.h Sat May 30 00:03:24 2009
@@ -186,8 +186,14 @@
/// 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;
Modified: cfe/trunk/lib/AST/DeclPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclPrinter.cpp?rev=72609&r1=72608&r2=72609&view=diff
==============================================================================
--- cfe/trunk/lib/AST/DeclPrinter.cpp (original)
+++ cfe/trunk/lib/AST/DeclPrinter.cpp Sat May 30 00:03:24 2009
@@ -172,6 +172,11 @@
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
@@ -274,7 +279,7 @@
Out << D->getNameAsString();
if (Expr *Init = D->getInitExpr()) {
Out << " = ";
- Init->printPretty(Out, 0, Policy, Indentation);
+ Init->printPretty(Out, Context, 0, Policy, Indentation);
}
}
@@ -347,7 +352,7 @@
} else
Out << ' ';
- D->getBody(Context)->printPretty(Out, 0, Policy, Indentation);
+ D->getBody(Context)->printPretty(Out, Context, 0, Policy, Indentation);
Out << '\n';
}
}
@@ -362,7 +367,7 @@
if (D->isBitField()) {
Out << " : ";
- D->getBitWidth()->printPretty(Out, 0, Policy, Indentation);
+ D->getBitWidth()->printPretty(Out, Context, 0, Policy, Indentation);
}
}
@@ -384,7 +389,7 @@
Out << "(";
else
Out << " = ";
- D->getInit()->printPretty(Out, 0, Policy, Indentation);
+ D->getInit()->printPretty(Out, Context, 0, Policy, Indentation);
if (D->hasCXXDirectInitializer())
Out << ")";
}
@@ -396,7 +401,7 @@
void DeclPrinter::VisitFileScopeAsmDecl(FileScopeAsmDecl *D) {
Out << "__asm (";
- D->getAsmString()->printPretty(Out, 0, Policy, Indentation);
+ D->getAsmString()->printPretty(Out, Context, 0, Policy, Indentation);
Out << ")";
}
@@ -475,7 +480,7 @@
if (OMD->getBody()) {
Out << ' ';
- OMD->getBody()->printPretty(Out, 0, Policy);
+ OMD->getBody()->printPretty(Out, Context, 0, Policy);
Out << '\n';
}
}
Modified: cfe/trunk/lib/AST/StmtPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/StmtPrinter.cpp?rev=72609&r1=72608&r2=72609&view=diff
==============================================================================
--- cfe/trunk/lib/AST/StmtPrinter.cpp (original)
+++ cfe/trunk/lib/AST/StmtPrinter.cpp Sat May 30 00:03:24 2009
@@ -28,15 +28,17 @@
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);
@@ -112,7 +114,7 @@
}
void StmtPrinter::PrintRawDecl(Decl *D) {
- D->print(OS, *(ASTContext*)0, Policy, IndentLevel);
+ D->print(OS, Context, Policy, IndentLevel);
}
void StmtPrinter::PrintRawDeclStmt(DeclStmt *S) {
@@ -121,7 +123,7 @@
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);
}
@@ -1203,11 +1205,12 @@
// 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) {
@@ -1220,7 +1223,7 @@
return;
}
- StmtPrinter P(OS, Helper, Policy, Indentation);
+ StmtPrinter P(OS, Context, Helper, Policy, Indentation);
P.Visit(const_cast<Stmt*>(this));
}
More information about the cfe-commits
mailing list