Convert a few Stmt actions to smart pointers.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@61309 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Parse/AstGuard.h b/lib/Parse/AstGuard.h
index 5d17aa6..a65caed 100644
--- a/lib/Parse/AstGuard.h
+++ b/lib/Parse/AstGuard.h
@@ -23,7 +23,7 @@
   /// automatically freeing them on destruction unless it's been disowned.
   /// Instantiated for statements and expressions (Action::DeleteStmt and
   /// Action::DeleteExpr).
-  template <void (ActionBase::*Destroyer)(void*), unsigned N>
+  template <ASTDestroyer Destroyer, unsigned N>
   class ASTVector : public llvm::SmallVector<void*, N> {
   private:
     Action &Actions;
@@ -50,6 +50,8 @@
       Owns = false;
       return &(*this)[0];
     }
+
+    Action &getActions() const { return Actions; }
   };
 
   /// A SmallVector of statements, with stack size 32 (as that is the only one
@@ -57,6 +59,11 @@
   typedef ASTVector<&Action::DeleteStmt, 32> StmtVector;
   /// A SmallVector of expressions, with stack size 12 (the maximum used.)
   typedef ASTVector<&Action::DeleteExpr, 12> ExprVector;
+
+  template <ASTDestroyer Destroyer, unsigned N> inline
+  ASTMultiPtr<Destroyer> move_convert(ASTVector<Destroyer, N> &vec) {
+    return ASTMultiPtr<Destroyer>(vec.getActions(), vec.take(), vec.size());
+  }
 }
 
 #endif
diff --git a/lib/Parse/ParseObjc.cpp b/lib/Parse/ParseObjc.cpp
index e70d202..759de7a 100644
--- a/lib/Parse/ParseObjc.cpp
+++ b/lib/Parse/ParseObjc.cpp
@@ -1365,7 +1365,8 @@
 
   // If the function body could not be parsed, make a bogus compoundstmt.
   if (FnBody.isInvalid())
-    FnBody = Actions.ActOnCompoundStmt(BraceLoc, BraceLoc, 0, 0, false);
+    FnBody = Actions.ActOnCompoundStmt(BraceLoc, BraceLoc,
+                                       MultiStmtArg(Actions), false);
 
   // Leave the function body scope.
   BodyScope.Exit();
@@ -1392,7 +1393,7 @@
   }
   // Otherwise, eat the semicolon.
   ExpectAndConsume(tok::semi, diag::err_expected_semi_after_expr);
-  return Owned(Actions.ActOnExprStmt(Res.release()));
+  return Actions.ActOnExprStmt(move_convert(Res));
 }
 
 Parser::OwningExprResult Parser::ParseObjCAtExpression(SourceLocation AtLoc) {
diff --git a/lib/Parse/ParseStmt.cpp b/lib/Parse/ParseStmt.cpp
index d22fbb7..c605bf2 100644
--- a/lib/Parse/ParseStmt.cpp
+++ b/lib/Parse/ParseStmt.cpp
@@ -101,7 +101,7 @@
       SourceLocation DeclStart = Tok.getLocation();
       DeclTy *Decl = ParseDeclaration(Declarator::BlockContext);
       // FIXME: Pass in the right location for the end of the declstmt.
-      return Owned(Actions.ActOnDeclStmt(Decl, DeclStart, DeclStart));
+      return Actions.ActOnDeclStmt(Decl, DeclStart, DeclStart);
     } else if (Tok.is(tok::r_brace)) {
       Diag(Tok, diag::err_expected_statement);
       return StmtError();
@@ -117,7 +117,7 @@
       }
       // Otherwise, eat the semicolon.
       ExpectAndConsume(tok::semi, diag::err_expected_semi_after_expr);
-      return Owned(Actions.ActOnExprStmt(Expr.release()));
+      return Actions.ActOnExprStmt(move_convert(Expr));
     }
 
   case tok::kw_case:                // C99 6.8.1: labeled-statement
@@ -128,7 +128,7 @@
   case tok::l_brace:                // C99 6.8.2: compound-statement
     return ParseCompoundStatement();
   case tok::semi:                   // C99 6.8.3p3: expression[opt] ';'
-    return Owned(Actions.ActOnNullStmt(ConsumeToken()));
+    return Actions.ActOnNullStmt(ConsumeToken());
 
   case tok::kw_if:                  // C99 6.8.4.1: if-statement
     return ParseIfStatement();
@@ -395,7 +395,7 @@
         // Eat the semicolon at the end of stmt and convert the expr into a
         // statement.
         ExpectAndConsume(tok::semi, diag::err_expected_semi_after_expr);
-        R = Actions.ActOnExprStmt(Res.release());
+        R = Actions.ActOnExprStmt(move_convert(Res));
       }
     }
 
@@ -410,8 +410,8 @@
   }
 
   SourceLocation RBraceLoc = ConsumeBrace();
-  return Owned(Actions.ActOnCompoundStmt(LBraceLoc, RBraceLoc, Stmts.take(),
-                                         Stmts.size(), isStmtExpr));
+  return Actions.ActOnCompoundStmt(LBraceLoc, RBraceLoc, move_convert(Stmts),
+                                   isStmtExpr);
 }
 
 /// ParseParenExprOrCondition:
@@ -863,7 +863,7 @@
 
     // Turn the expression into a stmt.
     if (!Value.isInvalid())
-      FirstPart = Actions.ActOnExprStmt(Value.release());
+      FirstPart = Actions.ActOnExprStmt(move_convert(Value));
 
     if (Tok.is(tok::semi)) {
       ConsumeToken();
@@ -900,7 +900,7 @@
       Value = ParseExpression();
       if (!Value.isInvalid()) {
         // Turn the expression into a stmt.
-        ThirdPart = Actions.ActOnExprStmt(Value.release());
+        ThirdPart = Actions.ActOnExprStmt(move_convert(Value));
       }
     }
   }
@@ -1039,7 +1039,7 @@
              Tok.isNot(tok::r_brace) && Tok.isNot(tok::semi) && 
              Tok.isNot(tok::eof));
   }
-  return Owned(Actions.ActOnNullStmt(Tok.getLocation()));
+  return Actions.ActOnNullStmt(Tok.getLocation());
 }
 
 /// ParseAsmStatement - Parse a GNU extended asm statement.
@@ -1239,7 +1239,7 @@
 
   // If the function body could not be parsed, make a bogus compoundstmt.
   if (FnBody.isInvalid())
-    FnBody = Owned(Actions.ActOnCompoundStmt(L, R, 0, 0, false));
+    FnBody = Actions.ActOnCompoundStmt(L, R, MultiStmtArg(Actions), false);
 
   return Actions.ActOnFinishFunctionBody(Decl, move_convert(FnBody));
 }