]> granicus.if.org Git - clang/commitdiff
Allow a SourceManager to optionally be passed into Stmt::dump
authorChris Lattner <sabre@nondot.org>
Thu, 30 Aug 2007 00:40:08 +0000 (00:40 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 30 Aug 2007 00:40:08 +0000 (00:40 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41588 91177308-0d34-0410-b5e6-96231b3b80d8

AST/StmtDumper.cpp
Driver/ASTStreamers.cpp
include/clang/AST/Stmt.h

index fc58184a1dbf4ffd02090fba80cd77c968dee16e..4a07d5149437a86d867b08fb45767e21a302a7a9 100644 (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");
 }
index 5e78e033c9b5d193bd25830665e130d2dc955c56..f77505b9ee8dfe02c02d1f47ca7d389a9761ed95 100644 (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)) {
index 20ecb860e09553aef84eca750d27984004ee33b5..8241bf65aca6c63f9bb789975c6cac55edd73882 100644 (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.