[cfe-commits] r41670 - in /cfe/trunk: AST/StmtDumper.cpp Sema/SemaStmt.cpp include/clang/AST/Stmt.h

Steve Naroff snaroff at apple.com
Sat Sep 1 14:08:39 PDT 2007


Author: snaroff
Date: Sat Sep  1 16:08:38 2007
New Revision: 41670

URL: http://llvm.org/viewvc/llvm-project?rev=41670&view=rev
Log:

Finish converting SwitchStmt AST to source ranges.
Move DumpSourceRange() to DumpStmt().

Now -parse-ast-dump will display source range info for all stmts/exprs.

One day we should implement the source range protocol for Decls.

Modified:
    cfe/trunk/AST/StmtDumper.cpp
    cfe/trunk/Sema/SemaStmt.cpp
    cfe/trunk/include/clang/AST/Stmt.h

Modified: cfe/trunk/AST/StmtDumper.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/StmtDumper.cpp?rev=41670&r1=41669&r2=41670&view=diff

==============================================================================
--- cfe/trunk/AST/StmtDumper.cpp (original)
+++ cfe/trunk/AST/StmtDumper.cpp Sat Sep  1 16:08:38 2007
@@ -78,7 +78,7 @@
         fprintf(F, "  ");
     }
     
-    void DumpType(QualType T) const {
+    void DumpType(QualType T) {
       fprintf(F, "'%s'", T.getAsString().c_str());
 
       // If the type is directly a typedef, strip off typedefness to give at
@@ -86,22 +86,18 @@
       if (TypedefType *TDT = dyn_cast<TypedefType>(T))
         fprintf(F, ":'%s'", TDT->LookThroughTypedefs().getAsString().c_str());
     }
-    
-    void DumpStmt(const Stmt *Node) const {
+    void DumpStmt(const Stmt *Node) {
       Indent();
       fprintf(F, "(%s %p", Node->getStmtClassName(), (void*)Node);
+      DumpSourceRange(Node);
     }
-    
-    void DumpExpr(Expr *Node) {
+    void DumpExpr(const Expr *Node) {
       DumpStmt(Node);
       fprintf(F, " ");
       DumpType(Node->getType());
-      DumpSourceRange(Node);
     }
-    
-    void DumpSourceRange(Expr *Node);
+    void DumpSourceRange(const Stmt *Node);
     void DumpLocation(SourceLocation Loc);
-
     
     // Stmts.
     void VisitStmt(Stmt *Node);
@@ -158,7 +154,7 @@
   }
 }
 
-void StmtDumper::DumpSourceRange(Expr *Node) {
+void StmtDumper::DumpSourceRange(const Stmt *Node) {
   // Can't translate locations if a SourceManager isn't available.
   if (SM == 0) return;
   

Modified: cfe/trunk/Sema/SemaStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaStmt.cpp?rev=41670&r1=41669&r2=41670&view=diff

==============================================================================
--- cfe/trunk/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/Sema/SemaStmt.cpp Sat Sep  1 16:08:38 2007
@@ -260,7 +260,7 @@
   SwitchStmt *SS = SwitchStack.back();
   assert(SS == (SwitchStmt*)Switch && "switch stack missing push/pop!");
     
-  SS->setBody(BodyStmt);
+  SS->setBody(BodyStmt, SwitchLoc);
   SwitchStack.pop_back(); 
 
   Expr *CondExpr = SS->getCond();

Modified: cfe/trunk/include/clang/AST/Stmt.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Stmt.h?rev=41670&r1=41669&r2=41670&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Stmt.h (original)
+++ cfe/trunk/include/clang/AST/Stmt.h Sat Sep  1 16:08:38 2007
@@ -375,6 +375,7 @@
   Stmt* SubExprs[END_EXPR];  
   // This points to a linked list of case and default statements.
   SwitchCase *FirstCase;
+  SourceLocation SwitchLoc;
 public:
   SwitchStmt(Expr *cond) : Stmt(SwitchStmtClass), FirstCase(0) {
       SubExprs[COND] = reinterpret_cast<Stmt*>(cond);
@@ -389,17 +390,19 @@
   Stmt *getBody() { return SubExprs[BODY]; }
   SwitchCase *getSwitchCaseList() { return FirstCase; }
 
-  void setBody(Stmt *S) { SubExprs[BODY] = S; }  
-  
+  void setBody(Stmt *S, SourceLocation SL) { 
+    SubExprs[BODY] = S; 
+    SwitchLoc = SL;
+  }  
   void addSwitchCase(SwitchCase *SC) {
     if (FirstCase)
       SC->setNextSwitchCase(FirstCase);
 
     FirstCase = SC;
   }
-  
-  virtual SourceRange getSourceRange() const { return SourceRange(); }
-
+  virtual SourceRange getSourceRange() const { 
+    return SourceRange(SwitchLoc, SubExprs[BODY]->getLocEnd()); 
+  }
   static bool classof(const Stmt *T) { 
     return T->getStmtClass() == SwitchStmtClass; 
   }





More information about the cfe-commits mailing list