]> granicus.if.org Git - clang/commitdiff
Finish converting SwitchStmt AST to source ranges.
authorSteve Naroff <snaroff@apple.com>
Sat, 1 Sep 2007 21:08:38 +0000 (21:08 +0000)
committerSteve Naroff <snaroff@apple.com>
Sat, 1 Sep 2007 21:08:38 +0000 (21:08 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41670 91177308-0d34-0410-b5e6-96231b3b80d8

AST/StmtDumper.cpp
Sema/SemaStmt.cpp
include/clang/AST/Stmt.h

index 73aef8474275959c203465cb498cd62d80a1f25c..ea43ad72a193cba652f19be38c1657fd6460312a 100644 (file)
@@ -78,7 +78,7 @@ namespace  {
         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 @@ namespace  {
       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::DumpLocation(SourceLocation Loc) {
   }
 }
 
-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;
   
index 87d5e262985e1bdcafca522bc00ec662e6ea486b..d6c4c2d6d10e06dff984d728da44b431ffdcf04d 100644 (file)
@@ -260,7 +260,7 @@ Sema::FinishSwitchStmt(SourceLocation SwitchLoc, StmtTy *Switch, ExprTy *Body) {
   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();
index aae088a5120ac8068d30c9fad3acf09a9859f4f9..b0dca78648f98e9e25547399202082008af282b0 100644 (file)
@@ -375,6 +375,7 @@ class SwitchStmt : public Stmt {
   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 @@ public:
   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; 
   }