[cfe-commits] r39157 - in /cfe/cfe/trunk: AST/Sema.cpp AST/Sema.h AST/SemaStmt.cpp Parse/ParseStmt.cpp Sema/Sema.cpp Sema/Sema.h Sema/SemaStmt.cpp include/clang/Parse/Action.h

sabre at cs.uiuc.edu sabre at cs.uiuc.edu
Wed Jul 11 09:40:07 PDT 2007


Author: sabre
Date: Wed Jul 11 11:40:06 2007
New Revision: 39157

URL: http://llvm.org/viewvc/llvm-project?rev=39157&view=rev
Log:
move semantic analysis of break/continue out of the parser into the sema class.

Modified:
    cfe/cfe/trunk/AST/Sema.cpp
    cfe/cfe/trunk/AST/Sema.h
    cfe/cfe/trunk/AST/SemaStmt.cpp
    cfe/cfe/trunk/Parse/ParseStmt.cpp
    cfe/cfe/trunk/Sema/Sema.cpp
    cfe/cfe/trunk/Sema/Sema.h
    cfe/cfe/trunk/Sema/SemaStmt.cpp
    cfe/cfe/trunk/include/clang/Parse/Action.h

Modified: cfe/cfe/trunk/AST/Sema.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/Sema.cpp?rev=39157&r1=39156&r2=39157&view=diff

==============================================================================
--- cfe/cfe/trunk/AST/Sema.cpp (original)
+++ cfe/cfe/trunk/AST/Sema.cpp Wed Jul 11 11:40:06 2007
@@ -23,6 +23,15 @@
 using namespace clang;
 
 //===----------------------------------------------------------------------===//
+// Helper functions.
+//===----------------------------------------------------------------------===//
+
+void Sema::Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg) {
+  PP.Diag(Loc, DiagID, Msg);
+}
+
+
+//===----------------------------------------------------------------------===//
 // Symbol table tracking callbacks.
 //===----------------------------------------------------------------------===//
 

Modified: cfe/cfe/trunk/AST/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/Sema.h?rev=39157&r1=39156&r2=39157&view=diff

==============================================================================
--- cfe/cfe/trunk/AST/Sema.h (original)
+++ cfe/cfe/trunk/AST/Sema.h Wed Jul 11 11:40:06 2007
@@ -17,6 +17,7 @@
 
 #include "clang/Parse/Action.h"
 #include <vector>
+#include <string>
 
 namespace llvm {
 namespace clang {
@@ -36,6 +37,9 @@
   Sema(Preprocessor &pp, std::vector<Decl*> &prevInGroup)
     : PP(pp), LastInGroupList(prevInGroup) {}
   
+  void Diag(SourceLocation Loc, unsigned DiagID,
+            const std::string &Msg = std::string());
+  
   //===--------------------------------------------------------------------===//
   // Symbol table tracking callbacks.
   //
@@ -81,8 +85,9 @@
   virtual StmtResult ParseIndirectGotoStmt(SourceLocation GotoLoc,
                                            SourceLocation StarLoc,
                                            ExprTy *DestExp);
-  virtual StmtResult ParseContinueStmt(SourceLocation ContinueLoc);
-  virtual StmtResult ParseBreakStmt(SourceLocation GotoLoc);
+  virtual StmtResult ParseContinueStmt(SourceLocation ContinueLoc,
+                                       Scope *CurScope);
+  virtual StmtResult ParseBreakStmt(SourceLocation GotoLoc, Scope *CurScope);
   
   virtual StmtResult ParseReturnStmt(SourceLocation ReturnLoc,
                                      ExprTy *RetValExp);

Modified: cfe/cfe/trunk/AST/SemaStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/SemaStmt.cpp?rev=39157&r1=39156&r2=39157&view=diff

==============================================================================
--- cfe/cfe/trunk/AST/SemaStmt.cpp (original)
+++ cfe/cfe/trunk/AST/SemaStmt.cpp Wed Jul 11 11:40:06 2007
@@ -13,6 +13,8 @@
 
 #include "Sema.h"
 #include "clang/AST/Stmt.h"
+#include "clang/Parse/Scope.h"
+#include "clang/Basic/Diagnostic.h"
 using namespace llvm;
 using namespace clang;
 
@@ -89,12 +91,28 @@
 }
 
 Action::StmtResult 
-Sema::ParseContinueStmt(SourceLocation ContinueLoc) {
+Sema::ParseContinueStmt(SourceLocation ContinueLoc, Scope *CurScope) {
+  Scope *S = CurScope->getContinueParent();
+  if (!S) {
+    // C99 6.8.6.2p1: A break shall appear only in or as a loop body.
+    Diag(ContinueLoc, diag::err_continue_not_in_loop);
+    return true;
+  }
+  
+  // FIXME: Remember that this continue goes with this loop.
   return new ContinueStmt();
 }
 
 Action::StmtResult 
-Sema::ParseBreakStmt(SourceLocation GotoLoc) {
+Sema::ParseBreakStmt(SourceLocation BreakLoc, Scope *CurScope) {
+  Scope *S = CurScope->getBreakParent();
+  if (!S) {
+    // C99 6.8.6.3p1: A break shall appear only in or as a switch/loop body.
+    Diag(BreakLoc, diag::err_break_not_in_loop_or_switch);
+    return true;
+  }
+  
+  // FIXME: Remember that this break goes with this loop/switch.
   return new BreakStmt();
 }
 

Modified: cfe/cfe/trunk/Parse/ParseStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Parse/ParseStmt.cpp?rev=39157&r1=39156&r2=39157&view=diff

==============================================================================
--- cfe/cfe/trunk/Parse/ParseStmt.cpp (original)
+++ cfe/cfe/trunk/Parse/ParseStmt.cpp Wed Jul 11 11:40:06 2007
@@ -660,17 +660,7 @@
 ///
 Parser::StmtResult Parser::ParseContinueStatement() {
   SourceLocation ContinueLoc = ConsumeToken();  // eat the 'continue'.
-  
-  Scope *S = CurScope->getContinueParent();
-  if (!S) {
-    // C99 6.8.6.2p1: A break shall appear only in or as a loop body.
-    Diag(ContinueLoc, diag::err_continue_not_in_loop);
-    return true;
-  }
-  
-  // FIXME: Remember that this continue goes with this loop.
-  
-  return Actions.ParseContinueStmt(ContinueLoc);
+  return Actions.ParseContinueStmt(ContinueLoc, CurScope);
 }
 
 /// ParseBreakStatement
@@ -681,16 +671,7 @@
 ///
 Parser::StmtResult Parser::ParseBreakStatement() {
   SourceLocation BreakLoc = ConsumeToken();  // eat the 'break'.
-
-  Scope *S = CurScope->getBreakParent();
-  if (!S) {
-    // C99 6.8.6.3p1: A break shall appear only in or as a switch/loop body.
-    Diag(BreakLoc, diag::err_break_not_in_loop_or_switch);
-    return true;
-  }
-  
-  // FIXME: Remember that this break goes with this loop/switch.
-  return Actions.ParseBreakStmt(BreakLoc);
+  return Actions.ParseBreakStmt(BreakLoc, CurScope);
 }
 
 /// ParseReturnStatement

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

==============================================================================
--- cfe/cfe/trunk/Sema/Sema.cpp (original)
+++ cfe/cfe/trunk/Sema/Sema.cpp Wed Jul 11 11:40:06 2007
@@ -23,6 +23,15 @@
 using namespace clang;
 
 //===----------------------------------------------------------------------===//
+// Helper functions.
+//===----------------------------------------------------------------------===//
+
+void Sema::Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg) {
+  PP.Diag(Loc, DiagID, Msg);
+}
+
+
+//===----------------------------------------------------------------------===//
 // Symbol table tracking callbacks.
 //===----------------------------------------------------------------------===//
 

Modified: cfe/cfe/trunk/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Sema/Sema.h?rev=39157&r1=39156&r2=39157&view=diff

==============================================================================
--- cfe/cfe/trunk/Sema/Sema.h (original)
+++ cfe/cfe/trunk/Sema/Sema.h Wed Jul 11 11:40:06 2007
@@ -17,6 +17,7 @@
 
 #include "clang/Parse/Action.h"
 #include <vector>
+#include <string>
 
 namespace llvm {
 namespace clang {
@@ -36,6 +37,9 @@
   Sema(Preprocessor &pp, std::vector<Decl*> &prevInGroup)
     : PP(pp), LastInGroupList(prevInGroup) {}
   
+  void Diag(SourceLocation Loc, unsigned DiagID,
+            const std::string &Msg = std::string());
+  
   //===--------------------------------------------------------------------===//
   // Symbol table tracking callbacks.
   //
@@ -81,8 +85,9 @@
   virtual StmtResult ParseIndirectGotoStmt(SourceLocation GotoLoc,
                                            SourceLocation StarLoc,
                                            ExprTy *DestExp);
-  virtual StmtResult ParseContinueStmt(SourceLocation ContinueLoc);
-  virtual StmtResult ParseBreakStmt(SourceLocation GotoLoc);
+  virtual StmtResult ParseContinueStmt(SourceLocation ContinueLoc,
+                                       Scope *CurScope);
+  virtual StmtResult ParseBreakStmt(SourceLocation GotoLoc, Scope *CurScope);
   
   virtual StmtResult ParseReturnStmt(SourceLocation ReturnLoc,
                                      ExprTy *RetValExp);

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

==============================================================================
--- cfe/cfe/trunk/Sema/SemaStmt.cpp (original)
+++ cfe/cfe/trunk/Sema/SemaStmt.cpp Wed Jul 11 11:40:06 2007
@@ -13,6 +13,8 @@
 
 #include "Sema.h"
 #include "clang/AST/Stmt.h"
+#include "clang/Parse/Scope.h"
+#include "clang/Basic/Diagnostic.h"
 using namespace llvm;
 using namespace clang;
 
@@ -89,12 +91,28 @@
 }
 
 Action::StmtResult 
-Sema::ParseContinueStmt(SourceLocation ContinueLoc) {
+Sema::ParseContinueStmt(SourceLocation ContinueLoc, Scope *CurScope) {
+  Scope *S = CurScope->getContinueParent();
+  if (!S) {
+    // C99 6.8.6.2p1: A break shall appear only in or as a loop body.
+    Diag(ContinueLoc, diag::err_continue_not_in_loop);
+    return true;
+  }
+  
+  // FIXME: Remember that this continue goes with this loop.
   return new ContinueStmt();
 }
 
 Action::StmtResult 
-Sema::ParseBreakStmt(SourceLocation GotoLoc) {
+Sema::ParseBreakStmt(SourceLocation BreakLoc, Scope *CurScope) {
+  Scope *S = CurScope->getBreakParent();
+  if (!S) {
+    // C99 6.8.6.3p1: A break shall appear only in or as a switch/loop body.
+    Diag(BreakLoc, diag::err_break_not_in_loop_or_switch);
+    return true;
+  }
+  
+  // FIXME: Remember that this break goes with this loop/switch.
   return new BreakStmt();
 }
 

Modified: cfe/cfe/trunk/include/clang/Parse/Action.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/Parse/Action.h?rev=39157&r1=39156&r2=39157&view=diff

==============================================================================
--- cfe/cfe/trunk/include/clang/Parse/Action.h (original)
+++ cfe/cfe/trunk/include/clang/Parse/Action.h Wed Jul 11 11:40:06 2007
@@ -181,14 +181,15 @@
                                            ExprTy *DestExp) {
     return 0;
   }
-  virtual StmtResult ParseContinueStmt(SourceLocation ContinueLoc) {
+  virtual StmtResult ParseContinueStmt(SourceLocation ContinueLoc,
+                                       Scope *CurScope) {
     return 0;
   }
-  virtual StmtResult ParseBreakStmt(SourceLocation GotoLoc) {
+  virtual StmtResult ParseBreakStmt(SourceLocation GotoLoc, Scope *CurScope) {
     return 0;
   }
   virtual StmtResult ParseReturnStmt(SourceLocation ReturnLoc,
-                                           ExprTy *RetValExp) {
+                                     ExprTy *RetValExp) {
     return 0;
   }
   





More information about the cfe-commits mailing list