From: Chris Lattner Date: Thu, 30 Aug 2007 00:40:08 +0000 (+0000) Subject: Allow a SourceManager to optionally be passed into Stmt::dump X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0c727a35718556866a978f64ac549d9798735f08;p=clang Allow a SourceManager to optionally be passed into Stmt::dump git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41588 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/AST/StmtDumper.cpp b/AST/StmtDumper.cpp index fc58184a1d..4a07d51494 100644 --- a/AST/StmtDumper.cpp +++ b/AST/StmtDumper.cpp @@ -26,6 +26,7 @@ using namespace clang; namespace { class VISIBILITY_HIDDEN StmtDumper : public StmtVisitor { + 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(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(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(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(this)); fprintf(stderr, "\n"); } diff --git a/Driver/ASTStreamers.cpp b/Driver/ASTStreamers.cpp index 5e78e033c9..f77505b9ee 100644 --- a/Driver/ASTStreamers.cpp +++ b/Driver/ASTStreamers.cpp @@ -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(D)) { diff --git a/include/clang/AST/Stmt.h b/include/clang/AST/Stmt.h index 20ecb860e0..8241bf65ac 100644 --- a/include/clang/AST/Stmt.h +++ b/include/clang/AST/Stmt.h @@ -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.