[cfe-commits] r61456 - in /cfe/trunk: Driver/PrintParserCallbacks.cpp include/clang/Parse/Action.h lib/Parse/ParseStmt.cpp lib/Sema/Sema.h lib/Sema/SemaStmt.cpp

Sebastian Redl sebastian.redl at getdesigned.at
Sun Dec 28 08:13:44 PST 2008


Author: cornedbee
Date: Sun Dec 28 10:13:43 2008
New Revision: 61456

URL: http://llvm.org/viewvc/llvm-project?rev=61456&view=rev
Log:
Convert a two more statement actions to smart pointers.

Modified:
    cfe/trunk/Driver/PrintParserCallbacks.cpp
    cfe/trunk/include/clang/Parse/Action.h
    cfe/trunk/lib/Parse/ParseStmt.cpp
    cfe/trunk/lib/Sema/Sema.h
    cfe/trunk/lib/Sema/SemaStmt.cpp

Modified: cfe/trunk/Driver/PrintParserCallbacks.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/PrintParserCallbacks.cpp?rev=61456&r1=61455&r2=61456&view=diff

==============================================================================
--- cfe/trunk/Driver/PrintParserCallbacks.cpp (original)
+++ cfe/trunk/Driver/PrintParserCallbacks.cpp Sun Dec 28 10:13:43 2008
@@ -269,17 +269,20 @@
   
     /// ActOnCaseStmt - Note that this handles the GNU 'case 1 ... 4' extension,
     /// which can specify an RHS value.
-    virtual StmtResult ActOnCaseStmt(SourceLocation CaseLoc, ExprTy *LHSVal,
-                                     SourceLocation DotDotDotLoc, ExprTy *RHSVal,
-                                     SourceLocation ColonLoc, StmtTy *SubStmt) {
+    virtual OwningStmtResult ActOnCaseStmt(SourceLocation CaseLoc,
+                                           ExprArg LHSVal,
+                                           SourceLocation DotDotDotLoc,
+                                           ExprArg RHSVal,
+                                           SourceLocation ColonLoc,
+                                           StmtArg SubStmt) {
       llvm::cout << __FUNCTION__ << "\n";
-      return 0;
+      return StmtEmpty();
     }
-    virtual StmtResult ActOnDefaultStmt(SourceLocation DefaultLoc,
-                                        SourceLocation ColonLoc, StmtTy *SubStmt,
-                                        Scope *CurScope){
+    virtual OwningStmtResult ActOnDefaultStmt(SourceLocation DefaultLoc,
+                                              SourceLocation ColonLoc,
+                                              StmtArg SubStmt, Scope *CurScope){
       llvm::cout << __FUNCTION__ << "\n";
-      return 0;
+      return StmtEmpty();
     }
   
     virtual StmtResult ActOnLabelStmt(SourceLocation IdentLoc, IdentifierInfo *II,

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

==============================================================================
--- cfe/trunk/include/clang/Parse/Action.h (original)
+++ cfe/trunk/include/clang/Parse/Action.h Sun Dec 28 10:13:43 2008
@@ -366,15 +366,15 @@
 
   /// ActOnCaseStmt - Note that this handles the GNU 'case 1 ... 4' extension,
   /// which can specify an RHS value.
-  virtual StmtResult ActOnCaseStmt(SourceLocation CaseLoc, ExprTy *LHSVal,
-                                   SourceLocation DotDotDotLoc, ExprTy *RHSVal,
-                                   SourceLocation ColonLoc, StmtTy *SubStmt) {
-    return 0;
+  virtual OwningStmtResult ActOnCaseStmt(SourceLocation CaseLoc, ExprArg LHSVal,
+                                    SourceLocation DotDotDotLoc, ExprArg RHSVal,
+                                    SourceLocation ColonLoc, StmtArg SubStmt) {
+    return StmtEmpty();
   }
-  virtual StmtResult ActOnDefaultStmt(SourceLocation DefaultLoc,
-                                      SourceLocation ColonLoc, StmtTy *SubStmt,
-                                      Scope *CurScope){
-    return 0;
+  virtual OwningStmtResult ActOnDefaultStmt(SourceLocation DefaultLoc,
+                                            SourceLocation ColonLoc,
+                                            StmtArg SubStmt, Scope *CurScope){
+    return StmtEmpty();
   }
   
   virtual StmtResult ActOnLabelStmt(SourceLocation IdentLoc, IdentifierInfo *II,

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

==============================================================================
--- cfe/trunk/lib/Parse/ParseStmt.cpp (original)
+++ cfe/trunk/lib/Parse/ParseStmt.cpp Sun Dec 28 10:13:43 2008
@@ -271,9 +271,9 @@
   if (SubStmt.isInvalid())
     SubStmt = Actions.ActOnNullStmt(ColonLoc);
 
-  return Owned(Actions.ActOnCaseStmt(CaseLoc, LHS.release(), DotDotDotLoc,
-                                     RHS.release(), ColonLoc,
-                                     SubStmt.release()));
+  return Actions.ActOnCaseStmt(CaseLoc, move_convert(LHS), DotDotDotLoc,
+                               move_convert(RHS), ColonLoc,
+                               move_convert(SubStmt));
 }
 
 /// ParseDefaultStatement
@@ -303,8 +303,8 @@
   if (SubStmt.isInvalid())
     return StmtError();
 
-  return Owned(Actions.ActOnDefaultStmt(DefaultLoc, ColonLoc,
-                                        SubStmt.release(), CurScope));
+  return Actions.ActOnDefaultStmt(DefaultLoc, ColonLoc,
+                                  move_convert(SubStmt), CurScope);
 }
 
 

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

==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Sun Dec 28 10:13:43 2008
@@ -567,12 +567,12 @@
                                              bool isStmtExpr);
   virtual OwningStmtResult ActOnDeclStmt(DeclTy *Decl, SourceLocation StartLoc,
                                          SourceLocation EndLoc);
-  virtual StmtResult ActOnCaseStmt(SourceLocation CaseLoc, ExprTy *LHSVal,
-                                   SourceLocation DotDotDotLoc, ExprTy *RHSVal,
-                                   SourceLocation ColonLoc, StmtTy *SubStmt);
-  virtual StmtResult ActOnDefaultStmt(SourceLocation DefaultLoc,
-                                      SourceLocation ColonLoc, StmtTy *SubStmt,
-                                      Scope *CurScope);
+  virtual OwningStmtResult ActOnCaseStmt(SourceLocation CaseLoc, ExprArg LHSVal,
+                                    SourceLocation DotDotDotLoc, ExprArg RHSVal,
+                                    SourceLocation ColonLoc, StmtArg SubStmt);
+  virtual OwningStmtResult ActOnDefaultStmt(SourceLocation DefaultLoc,
+                                            SourceLocation ColonLoc,
+                                            StmtArg SubStmt, Scope *CurScope);
   virtual StmtResult ActOnLabelStmt(SourceLocation IdentLoc, IdentifierInfo *II,
                                     SourceLocation ColonLoc, StmtTy *SubStmt);
   virtual StmtResult ActOnIfStmt(SourceLocation IfLoc, ExprTy *CondVal,

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmt.cpp Sun Dec 28 10:13:43 2008
@@ -119,49 +119,54 @@
   return Owned(new CompoundStmt(Elts, NumElts, L, R));
 }
 
-Action::StmtResult
-Sema::ActOnCaseStmt(SourceLocation CaseLoc, ExprTy *lhsval,
-                    SourceLocation DotDotDotLoc, ExprTy *rhsval,
-                    SourceLocation ColonLoc, StmtTy *subStmt) {
-  Stmt *SubStmt = static_cast<Stmt*>(subStmt);
-  Expr *LHSVal = ((Expr *)lhsval), *RHSVal = ((Expr *)rhsval);
-  assert((LHSVal != 0) && "missing expression in case statement");
-  
+Action::OwningStmtResult
+Sema::ActOnCaseStmt(SourceLocation CaseLoc, ExprArg lhsval,
+                    SourceLocation DotDotDotLoc, ExprArg rhsval,
+                    SourceLocation ColonLoc, StmtArg subStmt) {
+  Stmt *SubStmt = static_cast<Stmt*>(subStmt.release());
+  assert((lhsval.get() != 0) && "missing expression in case statement");
+
   // C99 6.8.4.2p3: The expression shall be an integer constant.
   // However, GCC allows any evaluatable integer expression. 
 
+  Expr *LHSVal = static_cast<Expr*>(lhsval.get());
   if (VerifyIntegerConstantExpression(LHSVal))
-    return SubStmt;
+    return Owned(SubStmt);
 
   // GCC extension: The expression shall be an integer constant.
-  
-  if (RHSVal && VerifyIntegerConstantExpression(RHSVal))
+
+  Expr *RHSVal = static_cast<Expr*>(rhsval.get());
+  if (RHSVal && VerifyIntegerConstantExpression(RHSVal)) {
     RHSVal = 0;  // Recover by just forgetting about it.
-  
+    rhsval = 0;
+  }
+
   if (SwitchStack.empty()) {
     Diag(CaseLoc, diag::err_case_not_in_switch);
-    return SubStmt;
+    return Owned(SubStmt);
   }
 
+  // Only now release the smart pointers.
+  lhsval.release();
+  rhsval.release();
   CaseStmt *CS = new CaseStmt(LHSVal, RHSVal, SubStmt, CaseLoc);
   SwitchStack.back()->addSwitchCase(CS);
-  return CS;
+  return Owned(CS);
 }
 
-Action::StmtResult
+Action::OwningStmtResult
 Sema::ActOnDefaultStmt(SourceLocation DefaultLoc, SourceLocation ColonLoc, 
-                       StmtTy *subStmt, Scope *CurScope) {
-  Stmt *SubStmt = static_cast<Stmt*>(subStmt);
-  
+                       StmtArg subStmt, Scope *CurScope) {
+  Stmt *SubStmt = static_cast<Stmt*>(subStmt.release());
+
   if (SwitchStack.empty()) {
     Diag(DefaultLoc, diag::err_default_not_in_switch);
-    return SubStmt;
+    return Owned(SubStmt);
   }
-  
+
   DefaultStmt *DS = new DefaultStmt(DefaultLoc, SubStmt);
   SwitchStack.back()->addSwitchCase(DS);
-
-  return DS;
+  return Owned(DS);
 }
 
 Action::StmtResult





More information about the cfe-commits mailing list