[cfe-commits] r62380 - 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
Fri Jan 16 15:28:07 PST 2009


Author: cornedbee
Date: Fri Jan 16 17:28:06 2009
New Revision: 62380

URL: http://llvm.org/viewvc/llvm-project?rev=62380&view=rev
Log:
Convert some more statement actions to smart pointers.
Fix a type error; parser wanted to pass the third part of a for-statement as a statement; should be expression.

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=62380&r1=62379&r2=62380&view=diff

==============================================================================
--- cfe/trunk/Driver/PrintParserCallbacks.cpp (original)
+++ cfe/trunk/Driver/PrintParserCallbacks.cpp Fri Jan 16 17:28:06 2009
@@ -312,29 +312,31 @@
       return StmtEmpty();
     }
 
-    virtual StmtResult ActOnWhileStmt(SourceLocation WhileLoc, ExprTy *Cond,
-                                      StmtTy *Body) {
+    virtual OwningStmtResult ActOnWhileStmt(SourceLocation WhileLoc,
+                                            ExprArg Cond, StmtArg Body) {
       llvm::cout << __FUNCTION__ << "\n";
-      return 0;
+      return StmtEmpty();
     }
-    virtual StmtResult ActOnDoStmt(SourceLocation DoLoc, StmtTy *Body,
-                                   SourceLocation WhileLoc, ExprTy *Cond) {
+    virtual OwningStmtResult ActOnDoStmt(SourceLocation DoLoc, StmtArg Body,
+                                         SourceLocation WhileLoc, ExprArg Cond){
       llvm::cout << __FUNCTION__ << "\n";
-      return 0;
+      return StmtEmpty();
     }
-    virtual StmtResult ActOnForStmt(SourceLocation ForLoc, 
-                                    SourceLocation LParenLoc, 
-                                    StmtTy *First, ExprTy *Second, ExprTy *Third,
-                                    SourceLocation RParenLoc, StmtTy *Body) {
+    virtual OwningStmtResult ActOnForStmt(SourceLocation ForLoc,
+                                        SourceLocation LParenLoc,
+                                        StmtArg First, ExprArg Second,
+                                        ExprArg Third, SourceLocation RParenLoc,
+                                        StmtArg Body) {
       llvm::cout << __FUNCTION__ << "\n";
-      return 0;
+      return StmtEmpty();
     }
-    virtual StmtResult ActOnObjCForCollectionStmt(SourceLocation ForColLoc, 
-                                                  SourceLocation LParenLoc, 
-                                                  StmtTy *First, ExprTy *Second,
-                                                  SourceLocation RParenLoc, StmtTy *Body) {
+    virtual OwningStmtResult ActOnObjCForCollectionStmt(
+                                       SourceLocation ForColLoc,
+                                       SourceLocation LParenLoc,
+                                       StmtArg First, ExprArg Second,
+                                       SourceLocation RParenLoc, StmtArg Body) {
       llvm::cout << __FUNCTION__ << "\n";
-      return 0;
+      return StmtEmpty();
     }
     virtual StmtResult ActOnGotoStmt(SourceLocation GotoLoc,
                                      SourceLocation LabelLoc,

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

==============================================================================
--- cfe/trunk/include/clang/Parse/Action.h (original)
+++ cfe/trunk/include/clang/Parse/Action.h Fri Jan 16 17:28:06 2009
@@ -416,25 +416,26 @@
     return StmtEmpty();
   }
 
-  virtual StmtResult ActOnWhileStmt(SourceLocation WhileLoc, ExprTy *Cond,
-                                    StmtTy *Body) {
-    return 0;
+  virtual OwningStmtResult ActOnWhileStmt(SourceLocation WhileLoc, ExprArg Cond,
+                                          StmtArg Body) {
+    return StmtEmpty();
   }
-  virtual StmtResult ActOnDoStmt(SourceLocation DoLoc, StmtTy *Body,
-                                 SourceLocation WhileLoc, ExprTy *Cond) {
-    return 0;
+  virtual OwningStmtResult ActOnDoStmt(SourceLocation DoLoc, StmtArg Body,
+                                       SourceLocation WhileLoc, ExprArg Cond) {
+    return StmtEmpty();
   }
-  virtual StmtResult ActOnForStmt(SourceLocation ForLoc, 
-                                  SourceLocation LParenLoc, 
-                                  StmtTy *First, ExprTy *Second, ExprTy *Third,
-                                  SourceLocation RParenLoc, StmtTy *Body) {
-    return 0;
+  virtual OwningStmtResult ActOnForStmt(SourceLocation ForLoc,
+                                        SourceLocation LParenLoc,
+                                        StmtArg First, ExprArg Second,
+                                        ExprArg Third, SourceLocation RParenLoc,
+                                        StmtArg Body) {
+    return StmtEmpty();
   }
-  virtual StmtResult ActOnObjCForCollectionStmt(SourceLocation ForColLoc, 
-                                  SourceLocation LParenLoc, 
-                                  StmtTy *First, ExprTy *Second,
-                                  SourceLocation RParenLoc, StmtTy *Body) {
-    return 0;
+  virtual OwningStmtResult ActOnObjCForCollectionStmt(SourceLocation ForColLoc,
+                                       SourceLocation LParenLoc,
+                                       StmtArg First, ExprArg Second,
+                                       SourceLocation RParenLoc, StmtArg Body) {
+    return StmtEmpty();
   }
   virtual StmtResult ActOnGotoStmt(SourceLocation GotoLoc,
                                    SourceLocation LabelLoc,

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

==============================================================================
--- cfe/trunk/lib/Parse/ParseStmt.cpp (original)
+++ cfe/trunk/lib/Parse/ParseStmt.cpp Fri Jan 16 17:28:06 2009
@@ -722,7 +722,8 @@
   if (Cond.isInvalid() || Body.isInvalid())
     return StmtError();
 
-  return Owned(Actions.ActOnWhileStmt(WhileLoc, Cond.release(),Body.release()));
+  return Actions.ActOnWhileStmt(WhileLoc, move_convert(Cond),
+                                move_convert(Body));
 }
 
 /// ParseDoStatement
@@ -786,8 +787,8 @@
   if (Cond.isInvalid() || Body.isInvalid())
     return StmtError();
 
-  return Owned(Actions.ActOnDoStmt(DoLoc, Body.release(), WhileLoc,
-                                   Cond.release()));
+  return Actions.ActOnDoStmt(DoLoc, move_convert(Body), WhileLoc,
+                             move_convert(Cond));
 }
 
 /// ParseForStatement
@@ -843,8 +844,8 @@
   OwningExprResult Value(Actions);
 
   bool ForEach = false;
-  OwningStmtResult FirstPart(Actions), ThirdPart(Actions);
-  OwningExprResult SecondPart(Actions);
+  OwningStmtResult FirstPart(Actions);
+  OwningExprResult SecondPart(Actions), ThirdPart(Actions);
 
   // Parse the first part of the for specifier.
   if (Tok.is(tok::semi)) {  // for (;
@@ -903,11 +904,7 @@
     if (Tok.is(tok::r_paren)) {  // for (...;...;)
       // no third part.
     } else {
-      Value = ParseExpression();
-      if (!Value.isInvalid()) {
-        // Turn the expression into a stmt.
-        ThirdPart = Actions.ActOnExprStmt(move_convert(Value));
-      }
+      ThirdPart = ParseExpression();
     }
   }
   // Match the ')'.
@@ -940,14 +937,14 @@
     return StmtError();
 
   if (!ForEach)
-    return Owned(Actions.ActOnForStmt(ForLoc, LParenLoc, FirstPart.release(),
-                                      SecondPart.release(), ThirdPart.release(),
-                                      RParenLoc, Body.release()));
+    return Actions.ActOnForStmt(ForLoc, LParenLoc, move_convert(FirstPart),
+                              move_convert(SecondPart), move_convert(ThirdPart),
+                              RParenLoc, move_convert(Body));
   else
-    return Owned(Actions.ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
-                                                    FirstPart.release(),
-                                                    SecondPart.release(),
-                                                    RParenLoc, Body.release()));
+    return Actions.ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
+                                              move_convert(FirstPart),
+                                              move_convert(SecondPart),
+                                              RParenLoc, move_convert(Body));
 }
 
 /// ParseGotoStatement

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

==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Fri Jan 16 17:28:06 2009
@@ -873,19 +873,20 @@
   virtual OwningStmtResult ActOnStartOfSwitchStmt(ExprArg Cond);
   virtual OwningStmtResult ActOnFinishSwitchStmt(SourceLocation SwitchLoc,
                                                  StmtArg Switch, StmtArg Body);
-  virtual StmtResult ActOnWhileStmt(SourceLocation WhileLoc, ExprTy *Cond,
-                                    StmtTy *Body);
-  virtual StmtResult ActOnDoStmt(SourceLocation DoLoc, StmtTy *Body,
-                                 SourceLocation WhileLoc, ExprTy *Cond);
-  
-  virtual StmtResult ActOnForStmt(SourceLocation ForLoc, 
-                                  SourceLocation LParenLoc, 
-                                  StmtTy *First, ExprTy *Second, ExprTy *Third,
-                                  SourceLocation RParenLoc, StmtTy *Body);
-  virtual StmtResult ActOnObjCForCollectionStmt(SourceLocation ForColLoc, 
-                                  SourceLocation LParenLoc, 
-                                  StmtTy *First, ExprTy *Second,
-                                  SourceLocation RParenLoc, StmtTy *Body);
+  virtual OwningStmtResult ActOnWhileStmt(SourceLocation WhileLoc, ExprArg Cond,
+                                          StmtArg Body);
+  virtual OwningStmtResult ActOnDoStmt(SourceLocation DoLoc, StmtArg Body,
+                                       SourceLocation WhileLoc, ExprArg Cond);
+
+  virtual OwningStmtResult ActOnForStmt(SourceLocation ForLoc,
+                                        SourceLocation LParenLoc,
+                                        StmtArg First, ExprArg Second,
+                                        ExprArg Third, SourceLocation RParenLoc,
+                                        StmtArg Body);
+  virtual OwningStmtResult ActOnObjCForCollectionStmt(SourceLocation ForColLoc,
+                                       SourceLocation LParenLoc,
+                                       StmtArg First, ExprArg Second,
+                                       SourceLocation RParenLoc, StmtArg Body);
   
   virtual StmtResult ActOnGotoStmt(SourceLocation GotoLoc,
                                    SourceLocation LabelLoc,

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmt.cpp Fri Jan 16 17:28:06 2009
@@ -532,52 +532,57 @@
   return Owned(SS);
 }
 
-Action::StmtResult
-Sema::ActOnWhileStmt(SourceLocation WhileLoc, ExprTy *Cond, StmtTy *Body) {
-  Expr *condExpr = (Expr *)Cond;
+Action::OwningStmtResult
+Sema::ActOnWhileStmt(SourceLocation WhileLoc, ExprArg Cond, StmtArg Body) {
+  Expr *condExpr = (Expr *)Cond.release();
   assert(condExpr && "ActOnWhileStmt(): missing expression");
-  
+
   DefaultFunctionArrayConversion(condExpr);
+  Cond = condExpr;
   QualType condType = condExpr->getType();
-  
+
   if (getLangOptions().CPlusPlus) {
     if (CheckCXXBooleanCondition(condExpr)) // C++ 6.4p4
-      return true;
+      return StmtError();
   } else if (!condType->isScalarType()) // C99 6.8.5p2
-    return Diag(WhileLoc, diag::err_typecheck_statement_requires_scalar)
-      << condType << condExpr->getSourceRange();
+    return StmtError(Diag(WhileLoc,
+      diag::err_typecheck_statement_requires_scalar)
+      << condType << condExpr->getSourceRange());
 
-  return new WhileStmt(condExpr, (Stmt*)Body, WhileLoc);
+  Cond.release();
+  return Owned(new WhileStmt(condExpr, (Stmt*)Body.release(), WhileLoc));
 }
 
-Action::StmtResult
-Sema::ActOnDoStmt(SourceLocation DoLoc, StmtTy *Body,
-                  SourceLocation WhileLoc, ExprTy *Cond) {
-  Expr *condExpr = (Expr *)Cond;
+Action::OwningStmtResult
+Sema::ActOnDoStmt(SourceLocation DoLoc, StmtArg Body,
+                  SourceLocation WhileLoc, ExprArg Cond) {
+  Expr *condExpr = (Expr *)Cond.release();
   assert(condExpr && "ActOnDoStmt(): missing expression");
-  
+
   DefaultFunctionArrayConversion(condExpr);
+  Cond = condExpr;
   QualType condType = condExpr->getType();
-  
+
   if (getLangOptions().CPlusPlus) {
     if (CheckCXXBooleanCondition(condExpr)) // C++ 6.4p4
-      return true;
+      return StmtError();
   } else if (!condType->isScalarType()) // C99 6.8.5p2
-    return Diag(DoLoc, diag::err_typecheck_statement_requires_scalar)
-      << condType << condExpr->getSourceRange();
+    return StmtError(Diag(DoLoc, diag::err_typecheck_statement_requires_scalar)
+      << condType << condExpr->getSourceRange());
 
-  return new DoStmt((Stmt*)Body, condExpr, DoLoc);
+  Cond.release();
+  return Owned(new DoStmt((Stmt*)Body.release(), condExpr, DoLoc));
 }
 
-Action::StmtResult 
-Sema::ActOnForStmt(SourceLocation ForLoc, SourceLocation LParenLoc, 
-                   StmtTy *first, ExprTy *second, ExprTy *third,
-                   SourceLocation RParenLoc, StmtTy *body) {
-  Stmt *First  = static_cast<Stmt*>(first);
-  Expr *Second = static_cast<Expr*>(second);
-  Expr *Third  = static_cast<Expr*>(third);
-  Stmt *Body  = static_cast<Stmt*>(body);
-  
+Action::OwningStmtResult
+Sema::ActOnForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
+                   StmtArg first, ExprArg second, ExprArg third,
+                   SourceLocation RParenLoc, StmtArg body) {
+  Stmt *First  = static_cast<Stmt*>(first.get());
+  Expr *Second = static_cast<Expr*>(second.get());
+  Expr *Third  = static_cast<Expr*>(third.get());
+  Stmt *Body  = static_cast<Stmt*>(body.get());
+
   if (!getLangOptions().CPlusPlus) {
     if (DeclStmt *DS = dyn_cast_or_null<DeclStmt>(First)) {
       // C99 6.8.5p3: The declaration part of a 'for' statement shall only
@@ -597,32 +602,37 @@
   if (Second) {
     DefaultFunctionArrayConversion(Second);
     QualType SecondType = Second->getType();
-    
+
     if (getLangOptions().CPlusPlus) {
       if (CheckCXXBooleanCondition(Second)) // C++ 6.4p4
-        return true;
+        return StmtError();
     } else if (!SecondType->isScalarType()) // C99 6.8.5p2
-      return Diag(ForLoc, diag::err_typecheck_statement_requires_scalar)
-        << SecondType << Second->getSourceRange();
-  }
-  return new ForStmt(First, Second, Third, Body, ForLoc);
+      return StmtError(Diag(ForLoc,
+                            diag::err_typecheck_statement_requires_scalar)
+        << SecondType << Second->getSourceRange());
+  }
+  first.release();
+  second.release();
+  third.release();
+  body.release();
+  return Owned(new ForStmt(First, Second, Third, Body, ForLoc));
 }
 
-Action::StmtResult 
-Sema::ActOnObjCForCollectionStmt(SourceLocation ForLoc, 
-                                 SourceLocation LParenLoc, 
-                                 StmtTy *first, ExprTy *second,
-                                 SourceLocation RParenLoc, StmtTy *body) {
-  Stmt *First  = static_cast<Stmt*>(first);
-  Expr *Second = static_cast<Expr*>(second);
-  Stmt *Body  = static_cast<Stmt*>(body);
+Action::OwningStmtResult
+Sema::ActOnObjCForCollectionStmt(SourceLocation ForLoc,
+                                 SourceLocation LParenLoc,
+                                 StmtArg first, ExprArg second,
+                                 SourceLocation RParenLoc, StmtArg body) {
+  Stmt *First  = static_cast<Stmt*>(first.get());
+  Expr *Second = static_cast<Expr*>(second.get());
+  Stmt *Body  = static_cast<Stmt*>(body.get());
   if (First) {
     QualType FirstType;
     if (DeclStmt *DS = dyn_cast<DeclStmt>(First)) {
       if (!DS->hasSolitaryDecl())
-        return Diag((*DS->decl_begin())->getLocation(),
-                    diag::err_toomany_element_decls);
-      
+        return StmtError(Diag((*DS->decl_begin())->getLocation(),
+                         diag::err_toomany_element_decls));
+
       ScopedDecl *D = DS->getSolitaryDecl();
       FirstType = cast<ValueDecl>(D)->getType();
       // C99 6.8.5p3: The declaration part of a 'for' statement shall only
@@ -630,15 +640,17 @@
       // 'register'.
       VarDecl *VD = cast<VarDecl>(D);
       if (VD->isBlockVarDecl() && !VD->hasLocalStorage())
-        return Diag(VD->getLocation(), diag::err_non_variable_decl_in_for);
+        return StmtError(Diag(VD->getLocation(),
+                              diag::err_non_variable_decl_in_for));
     } else {
       Expr::isLvalueResult lval = cast<Expr>(First)->isLvalue(Context);
-      
+
       if (lval != Expr::LV_Valid)
-        return Diag(First->getLocStart(), diag::err_selector_element_not_lvalue)
-          << First->getSourceRange();
+        return StmtError(Diag(First->getLocStart(),
+                   diag::err_selector_element_not_lvalue)
+          << First->getSourceRange());
 
-      FirstType = static_cast<Expr*>(first)->getType();        
+      FirstType = static_cast<Expr*>(First)->getType();        
     }
     if (!Context.isObjCObjectPointerType(FirstType))
         Diag(ForLoc, diag::err_selector_element_type)
@@ -651,7 +663,11 @@
       Diag(ForLoc, diag::err_collection_expr_type)
         << SecondType << Second->getSourceRange();
   }
-  return new ObjCForCollectionStmt(First, Second, Body, ForLoc, RParenLoc);
+  first.release();
+  second.release();
+  body.release();
+  return Owned(new ObjCForCollectionStmt(First, Second, Body,
+                                         ForLoc, RParenLoc));
 }
 
 Action::StmtResult 





More information about the cfe-commits mailing list