Allow a SourceManager to optionally be passed into Stmt::dump

llvm-svn: 41588
This commit is contained in:
Chris Lattner 2007-08-30 00:40:08 +00:00
parent d246b2ca5c
commit 779d5d9476
3 changed files with 25 additions and 5 deletions

View File

@ -26,6 +26,7 @@ using namespace clang;
namespace {
class VISIBILITY_HIDDEN StmtDumper : public StmtVisitor<StmtDumper> {
const SourceManager *SM;
FILE *F;
unsigned IndentLevel;
@ -34,8 +35,8 @@ namespace {
/// are left.
unsigned MaxDepth;
public:
StmtDumper(FILE *f, unsigned maxDepth)
: F(f), IndentLevel(0), MaxDepth(maxDepth) {}
StmtDumper(const SourceManager *sm, FILE *f, unsigned maxDepth)
: SM(sm), F(f), IndentLevel(0), MaxDepth(maxDepth) {}
void DumpSubTree(Stmt *S) {
// Prune the recursion if not using dump all.
@ -534,18 +535,34 @@ void StmtDumper::VisitObjCEncodeExpr(ObjCEncodeExpr *Node) {
// Stmt method implementations
//===----------------------------------------------------------------------===//
/// dump - This does a local dump of the specified AST fragment. It dumps the
/// specified node and a few nodes underneath it, but not the whole subtree.
/// This is useful in a debugger.
void Stmt::dump(const SourceManager &SM) const {
StmtDumper P(&SM, stderr, 4);
P.Visit(const_cast<Stmt*>(this));
fprintf(stderr, "\n");
}
/// dump - This does a local dump of the specified AST fragment. It dumps the
/// specified node and a few nodes underneath it, but not the whole subtree.
/// This is useful in a debugger.
void Stmt::dump() const {
StmtDumper P(stderr, 4);
StmtDumper P(0, stderr, 4);
P.Visit(const_cast<Stmt*>(this));
fprintf(stderr, "\n");
}
/// dumpAll - This does a dump of the specified AST fragment and all subtrees.
void Stmt::dumpAll(const SourceManager &SM) const {
StmtDumper P(&SM, stderr, ~0U);
P.Visit(const_cast<Stmt*>(this));
fprintf(stderr, "\n");
}
/// dumpAll - This does a dump of the specified AST fragment and all subtrees.
void Stmt::dumpAll() const {
StmtDumper P(stderr, ~0U);
StmtDumper P(0, stderr, ~0U);
P.Visit(const_cast<Stmt*>(this));
fprintf(stderr, "\n");
}

View File

@ -136,7 +136,7 @@ void clang::DumpASTs(Preprocessor &PP, unsigned MainFileID, bool Stats) {
if (FD->getBody()) {
fprintf(stderr, "\n");
FD->getBody()->dumpAll();
FD->getBody()->dumpAll(PP.getSourceManager());
fprintf(stderr, "\n");
}
} else if (TypedefDecl *TD = dyn_cast<TypedefDecl>(D)) {

View File

@ -23,6 +23,7 @@ namespace clang {
class Expr;
class Decl;
class IdentifierInfo;
class SourceManager;
class SwitchStmt;
/// Stmt - This represents one statement.
@ -57,9 +58,11 @@ public:
/// specified node and a few nodes underneath it, but not the whole subtree.
/// This is useful in a debugger.
void dump() const;
void dump(const SourceManager &SM) const;
/// dumpAll - This does a dump of the specified AST fragment and all subtrees.
void dumpAll() const;
void dumpAll(const SourceManager &SM) const;
/// dumpPretty/printPretty - These two methods do a "pretty print" of the AST
/// back to its original source language syntax.