From 9ae2f076ca5ab1feb3ba95629099ec2319833701 Mon Sep 17 00:00:00 2001 From: John McCall Date: Mon, 23 Aug 2010 23:25:46 +0000 Subject: [PATCH] Kill off ExprArg (now just Expr*) and StmtArg (now just Stmt*). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@111863 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Parse/Parser.h | 18 +- include/clang/Sema/Action.h | 34 +- include/clang/Sema/Ownership.h | 97 ++-- include/clang/Sema/Sema.h | 18 +- lib/Parse/ParseCXXInlineMethods.cpp | 4 +- lib/Parse/ParseDecl.cpp | 4 +- lib/Parse/ParseDeclCXX.cpp | 5 +- lib/Parse/ParseExpr.cpp | 127 +++-- lib/Parse/ParseExprCXX.cpp | 19 +- lib/Parse/ParseInit.cpp | 10 +- lib/Parse/ParseObjc.cpp | 40 +- lib/Parse/ParseStmt.cpp | 74 +-- lib/Parse/ParseTemplate.cpp | 2 +- lib/Parse/Parser.cpp | 4 +- lib/Sema/SemaCXXCast.cpp | 3 +- lib/Sema/SemaDecl.cpp | 34 +- lib/Sema/SemaDeclAttr.cpp | 2 +- lib/Sema/SemaDeclCXX.cpp | 153 +++--- lib/Sema/SemaExpr.cpp | 231 ++++----- lib/Sema/SemaExprCXX.cpp | 136 ++--- lib/Sema/SemaExprObjC.cpp | 12 +- lib/Sema/SemaOverload.cpp | 136 ++--- lib/Sema/SemaStmt.cpp | 198 +++---- lib/Sema/SemaTemplate.cpp | 13 +- lib/Sema/SemaTemplateInstantiateDecl.cpp | 14 +- lib/Sema/SemaType.cpp | 16 +- lib/Sema/TreeTransform.h | 630 +++++++++++------------ 27 files changed, 881 insertions(+), 1153 deletions(-) diff --git a/include/clang/Parse/Parser.h b/include/clang/Parse/Parser.h index b5e3a4c05d..6e537989bb 100644 --- a/include/clang/Parse/Parser.h +++ b/include/clang/Parse/Parser.h @@ -158,17 +158,17 @@ public: typedef llvm::SmallVector TemplateParameterLists; - typedef Action::ExprResult ExprResult; - typedef Action::StmtResult StmtResult; - typedef Action::BaseResult BaseResult; - typedef Action::MemInitResult MemInitResult; - typedef Action::TypeResult TypeResult; + typedef clang::ExprResult ExprResult; + typedef clang::StmtResult StmtResult; + typedef clang::BaseResult BaseResult; + typedef clang::MemInitResult MemInitResult; + typedef clang::TypeResult TypeResult; - typedef Action::OwningExprResult OwningExprResult; - typedef Action::OwningStmtResult OwningStmtResult; + typedef clang::OwningExprResult OwningExprResult; + typedef clang::OwningStmtResult OwningStmtResult; - typedef Action::ExprArg ExprArg; - typedef Action::MultiStmtArg MultiStmtArg; + typedef Expr *ExprArg; + typedef ASTMultiPtr MultiStmtArg; typedef Action::FullExprArg FullExprArg; /// Adorns a ExprResult with Actions to make it an OwningExprResult diff --git a/include/clang/Sema/Action.h b/include/clang/Sema/Action.h index 542ac3b8dc..008f55d3ba 100644 --- a/include/clang/Sema/Action.h +++ b/include/clang/Sema/Action.h @@ -89,14 +89,14 @@ public: typedef clang::MemInitResult MemInitResult; /// Same, but with ownership. - typedef ASTOwningResult OwningExprResult; - typedef ASTOwningResult OwningStmtResult; + typedef clang::OwningExprResult OwningExprResult; + typedef clang::OwningStmtResult OwningStmtResult; // Note that these will replace ExprResult and StmtResult when the transition // is complete. /// Single expressions or statements as arguments. - typedef ASTOwningPtr ExprArg; - typedef ASTOwningPtr StmtArg; + typedef Expr *ExprArg; + typedef Stmt *StmtArg; /// Multiple expressions or statements as arguments. typedef ASTMultiPtr MultiExprArg; @@ -105,25 +105,21 @@ public: class FullExprArg { public: - FullExprArg(ActionBase &actions) : Expr(actions) { } + FullExprArg(ActionBase &actions) : Expr(0) { } // FIXME: The const_cast here is ugly. RValue references would make this // much nicer (or we could duplicate a bunch of the move semantics // emulation code from Ownership.h). - FullExprArg(const FullExprArg& Other) - : Expr(move(const_cast(Other).Expr)) {} - - FullExprArg &operator=(const FullExprArg& Other) { - Expr.operator=(move(const_cast(Other).Expr)); - return *this; - } + FullExprArg(const FullExprArg& Other): Expr(Other.Expr) {} OwningExprResult release() { return move(Expr); } - ExprArg* operator->() { - return &Expr; + ExprArg get() const { return Expr; } + + ExprArg operator->() { + return Expr; } private: @@ -131,15 +127,13 @@ public: // Action::FullExpr that needs access to the constructor below. friend class Action; - explicit FullExprArg(ExprArg expr) - : Expr(move(expr)) {} + explicit FullExprArg(Expr *expr) : Expr(expr) {} - ExprArg Expr; + Expr *Expr; }; - template - FullExprArg MakeFullExpr(T &Arg) { - return FullExprArg(ActOnFinishFullExpr(move(Arg))); + FullExprArg MakeFullExpr(Expr *Arg) { + return FullExprArg(ActOnFinishFullExpr(Arg).release()); } // Utilities for Action implementations to return smart results. diff --git a/include/clang/Sema/Ownership.h b/include/clang/Sema/Ownership.h index 5a70eef4f1..c56d71b73e 100644 --- a/include/clang/Sema/Ownership.h +++ b/include/clang/Sema/Ownership.h @@ -316,39 +316,6 @@ namespace clang { /// the individual pointers, not the array holding them. template class ASTMultiPtr; - /// Kept only as a type-safe wrapper for a void pointer. - template class ASTOwningPtr { - PtrTy Node; - - public: - explicit ASTOwningPtr(ActionBase &) : Node(0) {} - ASTOwningPtr(ActionBase &, PtrTy node) : Node(node) {} - - // Normal copying operators are defined implicitly. - ASTOwningPtr(const ASTOwningResult &o); - - ASTOwningPtr & operator =(PtrTy raw) { - Node = raw; - return *this; - } - - /// Access to the raw pointer. - PtrTy get() const { return Node; } - - /// Release the raw pointer. - PtrTy take() { return Node; } - - /// Take outside ownership of the raw pointer and cast it down. - template T *takeAs() { - return static_cast(Node); - } - - /// Alias for interface familiarity with unique_ptr. - PtrTy release() { - return take(); - } - }; - template class ASTOwningResult { public: typedef ActionBase::ActionResult DumbResult; @@ -359,46 +326,42 @@ namespace clang { public: explicit ASTOwningResult(bool invalid = false) : Result(invalid) { } - explicit ASTOwningResult(PtrTy node) : Result(node) { } - explicit ASTOwningResult(const DumbResult &res) : Result(res) { } + ASTOwningResult(PtrTy node) : Result(node) { } + ASTOwningResult(const DumbResult &res) : Result(res) { } // Normal copying semantics are defined implicitly. - ASTOwningResult(const ASTOwningPtr &o) : Result(o.get()) { } // These two overloads prevent void* -> bool conversions. explicit ASTOwningResult(const void *); explicit ASTOwningResult(volatile void *); - /// Assignment from a raw pointer. Takes ownership - beware! - ASTOwningResult & operator =(PtrTy raw) { + /// Assignment from a raw pointer. + ASTOwningResult &operator=(PtrTy raw) { Result = raw; return *this; } - /// Assignment from an ActionResult. Takes ownership - beware! - ASTOwningResult & operator =(const DumbResult &res) { + /// Assignment from an ActionResult. + ASTOwningResult &operator=(const DumbResult &res) { Result = res; return *this; } - /// Access to the raw pointer. - PtrTy get() const { return Result.get(); } - bool isInvalid() const { return Result.isInvalid(); } - /// Does this point to a usable AST node? To be usable, the node must be - /// valid and non-null. + /// Does this point to a usable AST node? To be usable, the node + /// must be valid and non-null. bool isUsable() const { return !Result.isInvalid() && get(); } - /// Take outside ownership of the raw pointer. - PtrTy take() { - return Result.get(); - } + /// It is forbidden to call either of these methods on an invalid + /// pointer. We should assert that, but we're not going to, + /// because it's likely to trigger it unpredictable ways on + /// invalid code. + PtrTy get() const { return Result.get(); } + PtrTy take() const { return get(); } /// Take outside ownership of the raw pointer and cast it down. template - T *takeAs() { - return static_cast(take()); - } + T *takeAs() { return static_cast(get()); } /// Alias for interface familiarity with unique_ptr. PtrTy release() { return take(); } @@ -497,18 +460,9 @@ namespace clang { return ASTMultiPtr(vec.take(), vec.size()); } - template inline - ASTOwningPtr::ASTOwningPtr(const ASTOwningResult &o) - : Node(o.get()) { } - // These versions are hopefully no-ops. template inline - ASTOwningResult& move(ASTOwningResult &ptr) { - return ptr; - } - - template inline - ASTOwningPtr& move(ASTOwningPtr &ptr) { + ASTOwningResult move(ASTOwningResult &ptr) { return ptr; } @@ -541,6 +495,25 @@ namespace clang { typedef ActionBase::ActionResult DeclResult; typedef OpaquePtr ParsedTemplateTy; + + typedef ASTOwningResult OwningExprResult; + typedef ASTOwningResult OwningStmtResult; + + inline Expr *move(Expr *E) { return E; } + inline Stmt *move(Stmt *S) { return S; } + + typedef ASTMultiPtr MultiExprArg; + typedef ASTMultiPtr MultiTemplateParamsArg; + + inline Expr *AssertSuccess(OwningExprResult R) { + assert(!R.isInvalid() && "operation was asserted to never fail!"); + return R.get(); + } + + inline Stmt *AssertSuccess(OwningStmtResult R) { + assert(!R.isInvalid() && "operation was asserted to never fail!"); + return R.get(); + } } #endif diff --git a/include/clang/Sema/Sema.h b/include/clang/Sema/Sema.h index 6ec01572b9..ba1b08b557 100644 --- a/include/clang/Sema/Sema.h +++ b/include/clang/Sema/Sema.h @@ -2107,7 +2107,7 @@ public: return GetTypeFromParser(Ty)->isVectorType(); } - OwningExprResult MaybeConvertParenListExprToParenExpr(Scope *S, ExprArg ME); + OwningExprResult MaybeConvertParenListExprToParenExpr(Scope *S, Expr *ME); OwningExprResult ActOnCastOfParenListExpr(Scope *S, SourceLocation LParenLoc, SourceLocation RParenLoc, ExprArg E, TypeSourceInfo *TInfo); @@ -4781,22 +4781,6 @@ private: void CheckImplicitConversions(Expr *E); }; -//===--------------------------------------------------------------------===// -// Typed version of Parser::ExprArg (smart pointer for wrapping Expr pointers). -template -class ExprOwningPtr : public Action::ExprArg { -public: - ExprOwningPtr(Sema *S, T *expr) : Action::ExprArg(*S, expr) {} - - void reset(T* p) { Action::ExprArg::operator=(p); } - T* get() const { return static_cast(Action::ExprArg::get()); } - T* take() { return static_cast(Action::ExprArg::take()); } - T* release() { return take(); } - - T& operator*() const { return *get(); } - T* operator->() const { return get(); } -}; - } // end namespace clang #endif diff --git a/lib/Parse/ParseCXXInlineMethods.cpp b/lib/Parse/ParseCXXInlineMethods.cpp index eeccfac8cc..06eea9cd5d 100644 --- a/lib/Parse/ParseCXXInlineMethods.cpp +++ b/lib/Parse/ParseCXXInlineMethods.cpp @@ -147,7 +147,7 @@ void Parser::ParseLexedMethodDeclarations(ParsingClass &Class) { else Diag(Tok.getLocation(), diag::err_default_arg_unparsed); Actions.ActOnParamDefaultArgument(LM.DefaultArgs[I].Param, EqualLoc, - move(DefArgResult)); + DefArgResult.take()); } assert(!PP.getSourceManager().isBeforeInTranslationUnit(origLoc, @@ -231,7 +231,7 @@ void Parser::ParseLexedMethodDefs(ParsingClass &Class) { // Error recovery. if (!Tok.is(tok::l_brace)) { - Actions.ActOnFinishFunctionBody(LM.D, Action::StmtArg(Actions)); + Actions.ActOnFinishFunctionBody(LM.D, 0); continue; } } else diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp index 8265f3701e..814f203158 100644 --- a/lib/Parse/ParseDecl.cpp +++ b/lib/Parse/ParseDecl.cpp @@ -593,7 +593,7 @@ Decl *Parser::ParseDeclarationAfterDeclarator(Declarator &D, SkipUntil(tok::comma, true, true); Actions.ActOnInitializerError(ThisDecl); } else - Actions.AddInitializerToDecl(ThisDecl, move(Init)); + Actions.AddInitializerToDecl(ThisDecl, Init.take()); } } else if (Tok.is(tok::l_paren)) { // Parse C++ direct initializer: '(' expression-list ')' @@ -3136,7 +3136,7 @@ void Parser::ParseFunctionDeclarator(SourceLocation LParenLoc, Declarator &D, } else { // Inform the actions module about the default argument Actions.ActOnParamDefaultArgument(Param, EqualLoc, - move(DefArgResult)); + DefArgResult.take()); } } } diff --git a/lib/Parse/ParseDeclCXX.cpp b/lib/Parse/ParseDeclCXX.cpp index ea42c727f6..c56a1b4e7c 100644 --- a/lib/Parse/ParseDeclCXX.cpp +++ b/lib/Parse/ParseDeclCXX.cpp @@ -413,8 +413,9 @@ Decl *Parser::ParseStaticAssertDeclaration(SourceLocation &DeclEnd){ DeclEnd = Tok.getLocation(); ExpectAndConsume(tok::semi, diag::err_expected_semi_after_static_assert); - return Actions.ActOnStaticAssertDeclaration(StaticAssertLoc, move(AssertExpr), - move(AssertMessage)); + return Actions.ActOnStaticAssertDeclaration(StaticAssertLoc, + AssertExpr.take(), + AssertMessage.take()); } /// ParseDecltypeSpecifier - Parse a C++0x decltype specifier. diff --git a/lib/Parse/ParseExpr.cpp b/lib/Parse/ParseExpr.cpp index f7b03f229e..626a7ec006 100644 --- a/lib/Parse/ParseExpr.cpp +++ b/lib/Parse/ParseExpr.cpp @@ -210,10 +210,10 @@ Parser::ParseExpressionWithLeadingExtension(SourceLocation ExtLoc) { } LHS = Actions.ActOnUnaryOp(getCurScope(), ExtLoc, tok::kw___extension__, - move(LHS)); + LHS.take()); if (LHS.isInvalid()) return move(LHS); - return ParseRHSOfBinaryExpression(move(LHS), prec::Comma); + return ParseRHSOfBinaryExpression(LHS.take(), prec::Comma); } /// ParseAssignmentExpression - Parse an expr that doesn't include commas. @@ -230,7 +230,7 @@ Parser::OwningExprResult Parser::ParseAssignmentExpression() { OwningExprResult LHS(ParseCastExpression(false)); if (LHS.isInvalid()) return move(LHS); - return ParseRHSOfBinaryExpression(move(LHS), prec::Assignment); + return ParseRHSOfBinaryExpression(LHS.take(), prec::Assignment); } /// ParseAssignmentExprWithObjCMessageExprStart - Parse an assignment expression @@ -245,14 +245,14 @@ Parser::OwningExprResult Parser::ParseAssignmentExprWithObjCMessageExprStart(SourceLocation LBracLoc, SourceLocation SuperLoc, TypeTy *ReceiverType, - ExprArg ReceiverExpr) { - OwningExprResult R(ParseObjCMessageExpressionBody(LBracLoc, SuperLoc, - ReceiverType, - move(ReceiverExpr))); + Expr *ReceiverExpr) { + OwningExprResult R + = ParseObjCMessageExpressionBody(LBracLoc, SuperLoc, + ReceiverType, ReceiverExpr); if (R.isInvalid()) return move(R); - R = ParsePostfixExpressionSuffix(move(R)); + R = ParsePostfixExpressionSuffix(R.take()); if (R.isInvalid()) return move(R); - return ParseRHSOfBinaryExpression(move(R), prec::Assignment); + return ParseRHSOfBinaryExpression(R.take(), prec::Assignment); } @@ -266,7 +266,7 @@ Parser::OwningExprResult Parser::ParseConstantExpression() { OwningExprResult LHS(ParseCastExpression(false)); if (LHS.isInvalid()) return move(LHS); - return ParseRHSOfBinaryExpression(move(LHS), prec::Conditional); + return ParseRHSOfBinaryExpression(LHS.take(), prec::Conditional); } /// ParseRHSOfBinaryExpression - Parse a binary expression that starts with @@ -384,7 +384,7 @@ Parser::ParseRHSOfBinaryExpression(OwningExprResult LHS, prec::Level MinPrec) { // is okay, to bind exactly as tightly. For example, compile A=B=C=D as // A=(B=(C=D)), where each paren is a level of recursion here. // The function takes ownership of the RHS. - RHS = ParseRHSOfBinaryExpression(move(RHS), + RHS = ParseRHSOfBinaryExpression(RHS.get(), static_cast(ThisPrec + !isRightAssoc)); if (RHS.isInvalid()) return move(RHS); @@ -407,11 +407,11 @@ Parser::ParseRHSOfBinaryExpression(OwningExprResult LHS, prec::Level MinPrec) { Actions.getExprRange(RHS.get()).getEnd())); LHS = Actions.ActOnBinOp(getCurScope(), OpToken.getLocation(), - OpToken.getKind(), move(LHS), move(RHS)); + OpToken.getKind(), LHS.take(), RHS.take()); } else LHS = Actions.ActOnConditionalOp(OpToken.getLocation(), ColonLoc, - move(LHS), move(TernaryMiddle), - move(RHS)); + LHS.take(), TernaryMiddle.take(), + RHS.take()); } } } @@ -560,9 +560,10 @@ Parser::OwningExprResult Parser::ParseCastExpression(bool isUnaryExpression, // expression, or statement expression. // // If the parsed tokens consist of a primary-expression, the cases below - // call ParsePostfixExpressionSuffix to handle the postfix expression - // suffixes. Cases that cannot be followed by postfix exprs should - // return without invoking ParsePostfixExpressionSuffix. + // break out of the switch; at the end we call ParsePostfixExpressionSuffix + // to handle the postfix expression suffixes. Cases that cannot be followed + // by postfix exprs should return without invoking + // ParsePostfixExpressionSuffix. switch (SavedKind) { case tok::l_paren: { // If this expression is limited to being a unary-expression, the parent can @@ -596,8 +597,7 @@ Parser::OwningExprResult Parser::ParseCastExpression(bool isUnaryExpression, return move(Res); } - // These can be followed by postfix-expr pieces. - return ParsePostfixExpressionSuffix(move(Res)); + break; } // primary-expression @@ -607,9 +607,7 @@ Parser::OwningExprResult Parser::ParseCastExpression(bool isUnaryExpression, Res = Actions.ActOnNumericConstant(Tok); ConsumeToken(); - - // These can be followed by postfix-expr pieces. - return ParsePostfixExpressionSuffix(move(Res)); + break; case tok::kw_true: case tok::kw_false: @@ -660,8 +658,7 @@ Parser::OwningExprResult Parser::ParseCastExpression(bool isUnaryExpression, Res = Actions.ActOnClassPropertyRefExpr(II, PropertyName, ILoc, PropertyLoc); - // These can be followed by postfix-expr pieces. - return ParsePostfixExpressionSuffix(move(Res)); + break; } // Function designators are allowed to be undeclared (C99 6.5.1p2), so we @@ -672,28 +669,22 @@ Parser::OwningExprResult Parser::ParseCastExpression(bool isUnaryExpression, Name.setIdentifier(&II, ILoc); Res = Actions.ActOnIdExpression(getCurScope(), ScopeSpec, Name, Tok.is(tok::l_paren), false); - - // These can be followed by postfix-expr pieces. - return ParsePostfixExpressionSuffix(move(Res)); + break; } case tok::char_constant: // constant: character-constant Res = Actions.ActOnCharacterConstant(Tok); ConsumeToken(); - // These can be followed by postfix-expr pieces. - return ParsePostfixExpressionSuffix(move(Res)); + break; case tok::kw___func__: // primary-expression: __func__ [C99 6.4.2.2] case tok::kw___FUNCTION__: // primary-expression: __FUNCTION__ [GNU] case tok::kw___PRETTY_FUNCTION__: // primary-expression: __P..Y_F..N__ [GNU] Res = Actions.ActOnPredefinedExpr(Tok.getLocation(), SavedKind); ConsumeToken(); - // These can be followed by postfix-expr pieces. - return ParsePostfixExpressionSuffix(move(Res)); + break; case tok::string_literal: // primary-expression: string-literal case tok::wide_string_literal: Res = ParseStringLiteralExpression(); - if (Res.isInvalid()) return move(Res); - // This can be followed by postfix-expr pieces (e.g. "foo"[1]). - return ParsePostfixExpressionSuffix(move(Res)); + break; case tok::kw___builtin_va_arg: case tok::kw___builtin_offsetof: case tok::kw___builtin_choose_expr: @@ -711,7 +702,7 @@ Parser::OwningExprResult Parser::ParseCastExpression(bool isUnaryExpression, SourceLocation SavedLoc = ConsumeToken(); Res = ParseCastExpression(!getLang().CPlusPlus); if (!Res.isInvalid()) - Res = Actions.ActOnUnaryOp(getCurScope(), SavedLoc, SavedKind, move(Res)); + Res = Actions.ActOnUnaryOp(getCurScope(), SavedLoc, SavedKind, Res.get()); return move(Res); } case tok::amp: { // unary-expression: '&' cast-expression @@ -719,7 +710,7 @@ Parser::OwningExprResult Parser::ParseCastExpression(bool isUnaryExpression, SourceLocation SavedLoc = ConsumeToken(); Res = ParseCastExpression(false, true); if (!Res.isInvalid()) - Res = Actions.ActOnUnaryOp(getCurScope(), SavedLoc, SavedKind, move(Res)); + Res = Actions.ActOnUnaryOp(getCurScope(), SavedLoc, SavedKind, Res.get()); return move(Res); } @@ -733,7 +724,7 @@ Parser::OwningExprResult Parser::ParseCastExpression(bool isUnaryExpression, SourceLocation SavedLoc = ConsumeToken(); Res = ParseCastExpression(false); if (!Res.isInvalid()) - Res = Actions.ActOnUnaryOp(getCurScope(), SavedLoc, SavedKind, move(Res)); + Res = Actions.ActOnUnaryOp(getCurScope(), SavedLoc, SavedKind, Res.get()); return move(Res); } @@ -743,7 +734,7 @@ Parser::OwningExprResult Parser::ParseCastExpression(bool isUnaryExpression, SourceLocation SavedLoc = ConsumeToken(); Res = ParseCastExpression(false); if (!Res.isInvalid()) - Res = Actions.ActOnUnaryOp(getCurScope(), SavedLoc, SavedKind, move(Res)); + Res = Actions.ActOnUnaryOp(getCurScope(), SavedLoc, SavedKind, Res.get()); return move(Res); } case tok::kw_sizeof: // unary-expression: 'sizeof' unary-expression @@ -769,16 +760,13 @@ Parser::OwningExprResult Parser::ParseCastExpression(bool isUnaryExpression, case tok::kw_reinterpret_cast: case tok::kw_static_cast: Res = ParseCXXCasts(); - // These can be followed by postfix-expr pieces. - return ParsePostfixExpressionSuffix(move(Res)); + break; case tok::kw_typeid: Res = ParseCXXTypeid(); - // This can be followed by postfix-expr pieces. - return ParsePostfixExpressionSuffix(move(Res)); + break; case tok::kw_this: Res = ParseCXXThis(); - // This can be followed by postfix-expr pieces. - return ParsePostfixExpressionSuffix(move(Res)); + break; case tok::kw_char: case tok::kw_wchar_t: @@ -817,8 +805,7 @@ Parser::OwningExprResult Parser::ParseCastExpression(bool isUnaryExpression, << DS.getSourceRange()); Res = ParseCXXTypeConstructExpression(DS); - // This can be followed by postfix-expr pieces. - return ParsePostfixExpressionSuffix(move(Res)); + break; } case tok::annot_cxxscope: { // [C++] id-expression: qualified-id @@ -848,7 +835,7 @@ Parser::OwningExprResult Parser::ParseCastExpression(bool isUnaryExpression, // Parse as an id-expression. Res = ParseCXXIdExpression(isAddressOfOperand); - return ParsePostfixExpressionSuffix(move(Res)); + break; } case tok::annot_template_id: { // [C++] template-id @@ -868,7 +855,7 @@ Parser::OwningExprResult Parser::ParseCastExpression(bool isUnaryExpression, case tok::kw_operator: // [C++] id-expression: operator/conversion-function-id Res = ParseCXXIdExpression(isAddressOfOperand); - return ParsePostfixExpressionSuffix(move(Res)); + break; case tok::coloncolon: { // ::foo::bar -> global qualified name etc. If TryAnnotateTypeOrScopeToken @@ -932,8 +919,9 @@ Parser::OwningExprResult Parser::ParseCastExpression(bool isUnaryExpression, return ExprError(); } - // unreachable. - abort(); + // These can be followed by postfix-expr pieces. + if (Res.isInvalid()) return move(Res); + return ParsePostfixExpressionSuffix(Res.get()); } /// ParsePostfixExpressionSuffix - Once the leading part of a postfix-expression @@ -980,8 +968,8 @@ Parser::ParsePostfixExpressionSuffix(OwningExprResult LHS) { SourceLocation RLoc = Tok.getLocation(); if (!LHS.isInvalid() && !Idx.isInvalid() && Tok.is(tok::r_square)) { - LHS = Actions.ActOnArraySubscriptExpr(getCurScope(), move(LHS), Loc, - move(Idx), RLoc); + LHS = Actions.ActOnArraySubscriptExpr(getCurScope(), LHS.take(), Loc, + Idx.take(), RLoc); } else LHS = ExprError(); @@ -1023,7 +1011,7 @@ Parser::ParsePostfixExpressionSuffix(OwningExprResult LHS) { if (!LHS.isInvalid()) { assert((ArgExprs.size() == 0 || ArgExprs.size()-1 == CommaLocs.size())&& "Unexpected number of commas!"); - LHS = Actions.ActOnCallExpr(getCurScope(), move(LHS), Loc, + LHS = Actions.ActOnCallExpr(getCurScope(), LHS.take(), Loc, move_arg(ArgExprs), CommaLocs.data(), Tok.getLocation()); } @@ -1042,7 +1030,7 @@ Parser::ParsePostfixExpressionSuffix(OwningExprResult LHS) { Action::TypeTy *ObjectType = 0; bool MayBePseudoDestructor = false; if (getLang().CPlusPlus && !LHS.isInvalid()) { - LHS = Actions.ActOnStartCXXMemberReference(getCurScope(), move(LHS), + LHS = Actions.ActOnStartCXXMemberReference(getCurScope(), LHS.take(), OpLoc, OpKind, ObjectType, MayBePseudoDestructor); if (LHS.isInvalid()) @@ -1062,8 +1050,8 @@ Parser::ParsePostfixExpressionSuffix(OwningExprResult LHS) { ConsumeCodeCompletionToken(); } - if (MayBePseudoDestructor) { - LHS = ParseCXXPseudoDestructor(move(LHS), OpLoc, OpKind, SS, + if (MayBePseudoDestructor && !LHS.isInvalid()) { + LHS = ParseCXXPseudoDestructor(LHS.take(), OpLoc, OpKind, SS, ObjectType); break; } @@ -1083,7 +1071,7 @@ Parser::ParsePostfixExpressionSuffix(OwningExprResult LHS) { return ExprError(); if (!LHS.isInvalid()) - LHS = Actions.ActOnMemberAccessExpr(getCurScope(), move(LHS), OpLoc, + LHS = Actions.ActOnMemberAccessExpr(getCurScope(), LHS.take(), OpLoc, OpKind, SS, Name, ObjCImpDecl, Tok.is(tok::l_paren)); break; @@ -1092,7 +1080,7 @@ Parser::ParsePostfixExpressionSuffix(OwningExprResult LHS) { case tok::minusminus: // postfix-expression: postfix-expression '--' if (!LHS.isInvalid()) { LHS = Actions.ActOnPostfixUnaryOp(getCurScope(), Tok.getLocation(), - Tok.getKind(), move(LHS)); + Tok.getKind(), LHS.take()); } ConsumeToken(); break; @@ -1179,7 +1167,7 @@ Parser::ParseExprAfterTypeofSizeofAlignof(const Token &OpTok, // sizeof/alignof or in C++. Therefore, the parenthesized expression is // the start of a unary-expression, but doesn't include any postfix // pieces. Parse these now if present. - Operand = ParsePostfixExpressionSuffix(move(Operand)); + Operand = ParsePostfixExpressionSuffix(Operand.take()); } } @@ -1276,7 +1264,7 @@ Parser::OwningExprResult Parser::ParseBuiltinPrimaryExpression() { if (Ty.isInvalid()) Res = ExprError(); else - Res = Actions.ActOnVAArg(StartLoc, move(Expr), Ty.get(), ConsumeParen()); + Res = Actions.ActOnVAArg(StartLoc, Expr.take(), Ty.get(), ConsumeParen()); break; } case tok::kw___builtin_offsetof: { @@ -1377,8 +1365,8 @@ Parser::OwningExprResult Parser::ParseBuiltinPrimaryExpression() { Diag(Tok, diag::err_expected_rparen); return ExprError(); } - Res = Actions.ActOnChooseExpr(StartLoc, move(Cond), move(Expr1), - move(Expr2), ConsumeParen()); + Res = Actions.ActOnChooseExpr(StartLoc, Cond.take(), Expr1.take(), + Expr2.take(), ConsumeParen()); break; } case tok::kw___builtin_types_compatible_p: @@ -1402,9 +1390,12 @@ Parser::OwningExprResult Parser::ParseBuiltinPrimaryExpression() { break; } + if (Res.isInvalid()) + return ExprError(); + // These can be followed by postfix-expr pieces because they are // primary-expressions. - return ParsePostfixExpressionSuffix(move(Res)); + return ParsePostfixExpressionSuffix(Res.take()); } /// ParseParenExpression - This parses the unit that starts with a '(' token, @@ -1439,7 +1430,7 @@ Parser::ParseParenExpression(ParenParseOption &ExprType, bool stopIfCastExpr, // If the substmt parsed correctly, build the AST node. if (!Stmt.isInvalid() && Tok.is(tok::r_paren)) - Result = Actions.ActOnStmtExpr(OpenLoc, move(Stmt), Tok.getLocation()); + Result = Actions.ActOnStmtExpr(OpenLoc, Stmt.take(), Tok.getLocation()); } else if (ExprType >= CompoundLiteral && isTypeIdInParens(isAmbiguousTypeId)) { @@ -1496,7 +1487,7 @@ Parser::ParseParenExpression(ParenParseOption &ExprType, bool stopIfCastExpr, Result = ParseCastExpression(false, false, CastTy); if (!Result.isInvalid()) Result = Actions.ActOnCastExpr(getCurScope(), OpenLoc, CastTy, RParenLoc, - move(Result)); + Result.take()); return move(Result); } @@ -1516,7 +1507,7 @@ Parser::ParseParenExpression(ParenParseOption &ExprType, bool stopIfCastExpr, Result = ParseExpression(); ExprType = SimpleExpr; if (!Result.isInvalid() && Tok.is(tok::r_paren)) - Result = Actions.ActOnParenExpr(OpenLoc, Tok.getLocation(), move(Result)); + Result = Actions.ActOnParenExpr(OpenLoc, Tok.getLocation(), Result.take()); } // Match the ')'. @@ -1549,7 +1540,7 @@ Parser::ParseCompoundLiteralExpression(TypeTy *Ty, Diag(LParenLoc, diag::ext_c99_compound_literal); OwningExprResult Result = ParseInitializer(); if (!Result.isInvalid() && Ty) - return Actions.ActOnCompoundLiteral(LParenLoc, Ty, RParenLoc, move(Result)); + return Actions.ActOnCompoundLiteral(LParenLoc, Ty, RParenLoc, Result.take()); return move(Result); } @@ -1734,7 +1725,7 @@ Parser::OwningExprResult Parser::ParseBlockLiteralExpression() { OwningStmtResult Stmt(ParseCompoundStatementBody()); if (!Stmt.isInvalid()) - Result = Actions.ActOnBlockStmtExpr(CaretLoc, move(Stmt), getCurScope()); + Result = Actions.ActOnBlockStmtExpr(CaretLoc, Stmt.take(), getCurScope()); else Actions.ActOnBlockError(CaretLoc, getCurScope()); return move(Result); diff --git a/lib/Parse/ParseExprCXX.cpp b/lib/Parse/ParseExprCXX.cpp index ea835470df..82c5970f12 100644 --- a/lib/Parse/ParseExprCXX.cpp +++ b/lib/Parse/ParseExprCXX.cpp @@ -484,7 +484,7 @@ Parser::OwningExprResult Parser::ParseCXXCasts() { Result = Actions.ActOnCXXNamedCast(OpLoc, Kind, LAngleBracketLoc, CastTy.get(), RAngleBracketLoc, - LParenLoc, move(Result), RParenLoc); + LParenLoc, Result.take(), RParenLoc); return move(Result); } @@ -613,7 +613,8 @@ Parser::ParseCXXPseudoDestructor(ExprArg Base, SourceLocation OpLoc, /*TemplateKWLoc*/SourceLocation())) return ExprError(); - return Actions.ActOnPseudoDestructorExpr(getCurScope(), move(Base), OpLoc, OpKind, + return Actions.ActOnPseudoDestructorExpr(getCurScope(), Base, + OpLoc, OpKind, SS, FirstTypeName, CCLoc, TildeLoc, SecondTypeName, Tok.is(tok::l_paren)); @@ -647,12 +648,12 @@ Parser::OwningExprResult Parser::ParseThrowExpression() { case tok::r_brace: case tok::colon: case tok::comma: - return Actions.ActOnCXXThrow(ThrowLoc, ExprArg(Actions)); + return Actions.ActOnCXXThrow(ThrowLoc, 0); default: OwningExprResult Expr(ParseAssignmentExpression()); if (Expr.isInvalid()) return move(Expr); - return Actions.ActOnCXXThrow(ThrowLoc, move(Expr)); + return Actions.ActOnCXXThrow(ThrowLoc, Expr.take()); } } @@ -748,7 +749,7 @@ bool Parser::ParseCXXCondition(OwningExprResult &ExprResult, // If required, convert to a boolean value. if (ConvertToBoolean) ExprResult - = Actions.ActOnBooleanCondition(getCurScope(), Loc, move(ExprResult)); + = Actions.ActOnBooleanCondition(getCurScope(), Loc, ExprResult.take()); return ExprResult.isInvalid(); } @@ -790,7 +791,7 @@ bool Parser::ParseCXXCondition(OwningExprResult &ExprResult, SourceLocation EqualLoc = ConsumeToken(); OwningExprResult AssignExpr(ParseAssignmentExpression()); if (!AssignExpr.isInvalid()) - Actions.AddInitializerToDecl(DeclResult, move(AssignExpr)); + Actions.AddInitializerToDecl(DeclResult, AssignExpr.take()); } else { // FIXME: C++0x allows a braced-init-list Diag(Tok, diag::err_expected_equal_after_declarator); @@ -1745,7 +1746,7 @@ Parser::ParseCXXDeleteExpression(bool UseGlobal, SourceLocation Start) { if (Operand.isInvalid()) return move(Operand); - return Actions.ActOnCXXDelete(Start, UseGlobal, ArrayDelete, move(Operand)); + return Actions.ActOnCXXDelete(Start, UseGlobal, ArrayDelete, Operand.take()); } static UnaryTypeTrait UnaryTypeTraitFromTokKind(tok::TokenKind kind) { @@ -1899,7 +1900,7 @@ Parser::ParseCXXAmbiguousParenExpression(ParenParseOption &ExprType, // Result is what ParseCastExpression returned earlier. if (!Result.isInvalid()) Result = Actions.ActOnCastExpr(getCurScope(), LParenLoc, CastTy, RParenLoc, - move(Result)); + Result.take()); return move(Result); } @@ -1909,7 +1910,7 @@ Parser::ParseCXXAmbiguousParenExpression(ParenParseOption &ExprType, ExprType = SimpleExpr; Result = ParseExpression(); if (!Result.isInvalid() && Tok.is(tok::r_paren)) - Result = Actions.ActOnParenExpr(LParenLoc, Tok.getLocation(), move(Result)); + Result = Actions.ActOnParenExpr(LParenLoc, Tok.getLocation(), Result.take()); // Match the ')'. if (Result.isInvalid()) { diff --git a/lib/Parse/ParseInit.cpp b/lib/Parse/ParseInit.cpp index 52b6e3c992..3be43d8eb5 100644 --- a/lib/Parse/ParseInit.cpp +++ b/lib/Parse/ParseInit.cpp @@ -150,7 +150,7 @@ Parser::OwningExprResult Parser::ParseInitializerWithPotentialDesignator() { CheckArrayDesignatorSyntax(*this, StartLoc, Desig); return ParseAssignmentExprWithObjCMessageExprStart(StartLoc, ConsumeToken(), 0, - ExprArg(Actions)); + 0); } // Parse the receiver, which is either a type or an expression. @@ -168,7 +168,7 @@ Parser::OwningExprResult Parser::ParseInitializerWithPotentialDesignator() { return ParseAssignmentExprWithObjCMessageExprStart(StartLoc, SourceLocation(), TypeOrExpr, - ExprArg(Actions)); + 0); } // If the receiver was an expression, we still don't know @@ -195,7 +195,7 @@ Parser::OwningExprResult Parser::ParseInitializerWithPotentialDesignator() { return ParseAssignmentExprWithObjCMessageExprStart(StartLoc, ConsumeToken(), 0, - ExprArg(Actions)); + 0); ConsumeToken(); // the identifier if (!ReceiverType) { SkipUntil(tok::r_square); @@ -205,7 +205,7 @@ Parser::OwningExprResult Parser::ParseInitializerWithPotentialDesignator() { return ParseAssignmentExprWithObjCMessageExprStart(StartLoc, SourceLocation(), ReceiverType, - ExprArg(Actions)); + 0); case Action::ObjCInstanceMessage: // Fall through; we'll just parse the expression and @@ -239,7 +239,7 @@ Parser::OwningExprResult Parser::ParseInitializerWithPotentialDesignator() { CheckArrayDesignatorSyntax(*this, Tok.getLocation(), Desig); return ParseAssignmentExprWithObjCMessageExprStart(StartLoc, SourceLocation(), - 0, move(Idx)); + 0, Idx.take()); } // If this is a normal array designator, remember it. diff --git a/lib/Parse/ParseObjc.cpp b/lib/Parse/ParseObjc.cpp index 822d96b7c8..df47fdfaf9 100644 --- a/lib/Parse/ParseObjc.cpp +++ b/lib/Parse/ParseObjc.cpp @@ -1470,7 +1470,7 @@ Parser::OwningStmtResult Parser::ParseObjCThrowStmt(SourceLocation atLoc) { } // consume ';' ExpectAndConsume(tok::semi, diag::err_expected_semi_after, "@throw"); - return Actions.ActOnObjCAtThrowStmt(atLoc, move(Res), getCurScope()); + return Actions.ActOnObjCAtThrowStmt(atLoc, Res.take(), getCurScope()); } /// objc-synchronized-statement: @@ -1507,7 +1507,7 @@ Parser::ParseObjCSynchronizedStmt(SourceLocation atLoc) { BodyScope.Exit(); if (SynchBody.isInvalid()) SynchBody = Actions.ActOnNullStmt(Tok.getLocation()); - return Actions.ActOnObjCAtSynchronizedStmt(atLoc, move(Res), move(SynchBody)); + return Actions.ActOnObjCAtSynchronizedStmt(atLoc, Res.take(), SynchBody.take()); } /// objc-try-catch-statement: @@ -1586,7 +1586,7 @@ Parser::OwningStmtResult Parser::ParseObjCTryStmt(SourceLocation atLoc) { OwningStmtResult Catch = Actions.ActOnObjCAtCatchStmt(AtCatchFinallyLoc, RParenLoc, FirstPart, - move(CatchBody)); + CatchBody.take()); if (!Catch.isInvalid()) CatchStmts.push_back(Catch.release()); @@ -1609,7 +1609,7 @@ Parser::OwningStmtResult Parser::ParseObjCTryStmt(SourceLocation atLoc) { if (FinallyBody.isInvalid()) FinallyBody = Actions.ActOnNullStmt(Tok.getLocation()); FinallyStmt = Actions.ActOnObjCAtFinallyStmt(AtCatchFinallyLoc, - move(FinallyBody)); + FinallyBody.take()); catch_or_finally_seen = true; break; } @@ -1619,9 +1619,9 @@ Parser::OwningStmtResult Parser::ParseObjCTryStmt(SourceLocation atLoc) { return StmtError(); } - return Actions.ActOnObjCAtTryStmt(atLoc, move(TryBody), + return Actions.ActOnObjCAtTryStmt(atLoc, TryBody.take(), move_arg(CatchStmts), - move(FinallyStmt)); + FinallyStmt.take()); } /// objc-method-def: objc-method-proto ';'[opt] '{' body '}' @@ -1671,7 +1671,7 @@ Decl *Parser::ParseObjCMethodDefinition() { MultiStmtArg(Actions), false); // TODO: Pass argument information. - Actions.ActOnFinishFunctionBody(MDecl, move(FnBody)); + Actions.ActOnFinishFunctionBody(MDecl, FnBody.take()); // Leave the function body scope. BodyScope.Exit(); @@ -1706,7 +1706,7 @@ Parser::OwningStmtResult Parser::ParseObjCAtStatement(SourceLocation AtLoc) { // Otherwise, eat the semicolon. ExpectAndConsume(tok::semi, diag::err_expected_semi_after_expr); - return Actions.ActOnExprStmt(Actions.MakeFullExpr(Res)); + return Actions.ActOnExprStmt(Actions.MakeFullExpr(Res.take())); } Parser::OwningExprResult Parser::ParseObjCAtExpression(SourceLocation AtLoc) { @@ -1797,9 +1797,9 @@ bool Parser::ParseObjCXXMessageReceiver(bool &IsExpr, void *&TypeOrExpr) { // instance method. OwningExprResult Receiver = ParseCXXTypeConstructExpression(DS); if (!Receiver.isInvalid()) - Receiver = ParsePostfixExpressionSuffix(move(Receiver)); + Receiver = ParsePostfixExpressionSuffix(Receiver.take()); if (!Receiver.isInvalid()) - Receiver = ParseRHSOfBinaryExpression(move(Receiver), prec::Comma); + Receiver = ParseRHSOfBinaryExpression(Receiver.take(), prec::Comma); if (Receiver.isInvalid()) return true; @@ -1863,7 +1863,7 @@ Parser::OwningExprResult Parser::ParseObjCMessageExpression() { if (Tok.is(tok::identifier) && Tok.getIdentifierInfo() == Ident_super && NextToken().isNot(tok::period) && getCurScope()->isInObjcMethodScope()) return ParseObjCMessageExpressionBody(LBracLoc, ConsumeToken(), 0, - ExprArg(Actions)); + 0); // Parse the receiver, which is either a type or an expression. bool IsExpr; @@ -1875,10 +1875,10 @@ Parser::OwningExprResult Parser::ParseObjCMessageExpression() { if (IsExpr) return ParseObjCMessageExpressionBody(LBracLoc, SourceLocation(), 0, - OwningExprResult(static_cast(TypeOrExpr))); + static_cast(TypeOrExpr)); return ParseObjCMessageExpressionBody(LBracLoc, SourceLocation(), - TypeOrExpr, ExprArg(Actions)); + TypeOrExpr, 0); } if (Tok.is(tok::identifier)) { @@ -1890,8 +1890,7 @@ Parser::OwningExprResult Parser::ParseObjCMessageExpression() { NextToken().is(tok::period), ReceiverType)) { case Action::ObjCSuperMessage: - return ParseObjCMessageExpressionBody(LBracLoc, ConsumeToken(), 0, - ExprArg(Actions)); + return ParseObjCMessageExpressionBody(LBracLoc, ConsumeToken(), 0, 0); case Action::ObjCClassMessage: if (!ReceiverType) { @@ -1902,8 +1901,7 @@ Parser::OwningExprResult Parser::ParseObjCMessageExpression() { ConsumeToken(); // the type name return ParseObjCMessageExpressionBody(LBracLoc, SourceLocation(), - ReceiverType, - ExprArg(Actions)); + ReceiverType, 0); case Action::ObjCInstanceMessage: // Fall through to parse an expression. @@ -1919,7 +1917,7 @@ Parser::OwningExprResult Parser::ParseObjCMessageExpression() { } return ParseObjCMessageExpressionBody(LBracLoc, SourceLocation(), 0, - move(Res)); + Res.take()); } /// \brief Parse the remainder of an Objective-C message following the @@ -1971,7 +1969,7 @@ Parser::ParseObjCMessageExpressionBody(SourceLocation LBracLoc, else if (ReceiverType) Actions.CodeCompleteObjCClassMessage(getCurScope(), ReceiverType, 0, 0); else - Actions.CodeCompleteObjCInstanceMessage(getCurScope(), ReceiverExpr.get(), + Actions.CodeCompleteObjCInstanceMessage(getCurScope(), ReceiverExpr, 0, 0); ConsumeCodeCompletionToken(); } @@ -2024,7 +2022,7 @@ Parser::ParseObjCMessageExpressionBody(SourceLocation LBracLoc, KeyIdents.data(), KeyIdents.size()); else - Actions.CodeCompleteObjCInstanceMessage(getCurScope(), ReceiverExpr.get(), + Actions.CodeCompleteObjCInstanceMessage(getCurScope(), ReceiverExpr, KeyIdents.data(), KeyIdents.size()); ConsumeCodeCompletionToken(); @@ -2093,7 +2091,7 @@ Parser::ParseObjCMessageExpressionBody(SourceLocation LBracLoc, Action::MultiExprArg(Actions, KeyExprs.take(), KeyExprs.size())); - return Actions.ActOnInstanceMessage(getCurScope(), move(ReceiverExpr), Sel, + return Actions.ActOnInstanceMessage(getCurScope(), ReceiverExpr, Sel, LBracLoc, SelectorLoc, RBracLoc, Action::MultiExprArg(Actions, KeyExprs.take(), diff --git a/lib/Parse/ParseStmt.cpp b/lib/Parse/ParseStmt.cpp index de81c7797a..fc672eb24a 100644 --- a/lib/Parse/ParseStmt.cpp +++ b/lib/Parse/ParseStmt.cpp @@ -137,7 +137,7 @@ Parser::ParseStatementOrDeclaration(bool OnlyStatement) { } // Otherwise, eat the semicolon. ExpectAndConsume(tok::semi, diag::err_expected_semi_after_expr); - return Actions.ActOnExprStmt(Actions.MakeFullExpr(Expr)); + return Actions.ActOnExprStmt(Actions.MakeFullExpr(Expr.get())); } case tok::kw_case: // C99 6.8.1: labeled-statement @@ -243,7 +243,7 @@ Parser::OwningStmtResult Parser::ParseLabeledStatement(AttributeList *Attr) { // FIXME: use attributes? return Actions.ActOnLabelStmt(IdentTok.getLocation(), IdentTok.getIdentifierInfo(), - ColonLoc, move(SubStmt)); + ColonLoc, SubStmt.get()); } /// ParseCaseStatement @@ -324,8 +324,8 @@ Parser::OwningStmtResult Parser::ParseCaseStatement(AttributeList *Attr) { SourceLocation ColonLoc = ConsumeToken(); OwningStmtResult Case = - Actions.ActOnCaseStmt(CaseLoc, move(LHS), DotDotDotLoc, - move(RHS), ColonLoc); + Actions.ActOnCaseStmt(CaseLoc, LHS.get(), DotDotDotLoc, + RHS.get(), ColonLoc); // If we had a sema error parsing this case, then just ignore it and // continue parsing the sub-stmt. @@ -340,7 +340,7 @@ Parser::OwningStmtResult Parser::ParseCaseStatement(AttributeList *Attr) { if (TopLevelCase.isInvalid()) TopLevelCase = move(Case); else - Actions.ActOnCaseStmtBody(DeepestParsedCaseStmt, move(Case)); + Actions.ActOnCaseStmtBody(DeepestParsedCaseStmt, Case.get()); DeepestParsedCaseStmt = NextDeepest; } @@ -367,7 +367,7 @@ Parser::OwningStmtResult Parser::ParseCaseStatement(AttributeList *Attr) { SubStmt = Actions.ActOnNullStmt(SourceLocation()); // Install the body into the most deeply-nested case. - Actions.ActOnCaseStmtBody(DeepestParsedCaseStmt, move(SubStmt)); + Actions.ActOnCaseStmtBody(DeepestParsedCaseStmt, SubStmt.get()); // Return the top level parsed statement tree. return move(TopLevelCase); @@ -404,7 +404,7 @@ Parser::OwningStmtResult Parser::ParseDefaultStatement(AttributeList *Attr) { return StmtError(); return Actions.ActOnDefaultStmt(DefaultLoc, ColonLoc, - move(SubStmt), getCurScope()); + SubStmt.get(), getCurScope()); } @@ -507,7 +507,7 @@ Parser::OwningStmtResult Parser::ParseCompoundStatementBody(bool isStmtExpr) { // 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(Actions.MakeFullExpr(Res)); + R = Actions.ActOnExprStmt(Actions.MakeFullExpr(Res.get())); } } @@ -554,7 +554,7 @@ bool Parser::ParseParenExprOrCondition(OwningExprResult &ExprResult, // If required, convert to a boolean value. if (!ExprResult.isInvalid() && ConvertToBoolean) ExprResult - = Actions.ActOnBooleanCondition(getCurScope(), Loc, move(ExprResult)); + = Actions.ActOnBooleanCondition(getCurScope(), Loc, ExprResult.get()); } // If the parser was confused by the condition and we don't have a ')', try to @@ -616,7 +616,7 @@ Parser::OwningStmtResult Parser::ParseIfStatement(AttributeList *Attr) { if (ParseParenExprOrCondition(CondExp, CondVar, IfLoc, true)) return StmtError(); - FullExprArg FullCondExp(Actions.MakeFullExpr(CondExp)); + FullExprArg FullCondExp(Actions.MakeFullExpr(CondExp.get())); // C99 6.8.4p3 - In C99, the body of the if statement is a scope, even if // there is no compound stmt. C90 does not have this clause. We only do this @@ -696,8 +696,8 @@ Parser::OwningStmtResult Parser::ParseIfStatement(AttributeList *Attr) { if (ElseStmt.isInvalid()) ElseStmt = Actions.ActOnNullStmt(ElseStmtLoc); - return Actions.ActOnIfStmt(IfLoc, FullCondExp, CondVar, move(ThenStmt), - ElseLoc, move(ElseStmt)); + return Actions.ActOnIfStmt(IfLoc, FullCondExp, CondVar, ThenStmt.get(), + ElseLoc, ElseStmt.get()); } /// ParseSwitchStatement @@ -743,7 +743,7 @@ Parser::OwningStmtResult Parser::ParseSwitchStatement(AttributeList *Attr) { return StmtError(); OwningStmtResult Switch - = Actions.ActOnStartOfSwitchStmt(SwitchLoc, move(Cond), CondVar); + = Actions.ActOnStartOfSwitchStmt(SwitchLoc, Cond.get(), CondVar); if (Switch.isInvalid()) { // Skip the switch body. @@ -783,7 +783,7 @@ Parser::OwningStmtResult Parser::ParseSwitchStatement(AttributeList *Attr) { // FIXME: Remove the case statement list from the Switch statement. Body = Actions.ActOnNullStmt(Tok.getLocation()); - return Actions.ActOnFinishSwitchStmt(SwitchLoc, move(Switch), move(Body)); + return Actions.ActOnFinishSwitchStmt(SwitchLoc, Switch.get(), Body.get()); } /// ParseWhileStatement @@ -832,7 +832,7 @@ Parser::OwningStmtResult Parser::ParseWhileStatement(AttributeList *Attr) { if (ParseParenExprOrCondition(Cond, CondVar, WhileLoc, true)) return StmtError(); - FullExprArg FullCond(Actions.MakeFullExpr(Cond)); + FullExprArg FullCond(Actions.MakeFullExpr(Cond.get())); // C99 6.8.5p5 - In C99, the body of the if statement is a scope, even if // there is no compound stmt. C90 does not have this clause. We only do this @@ -858,7 +858,7 @@ Parser::OwningStmtResult Parser::ParseWhileStatement(AttributeList *Attr) { if ((Cond.isInvalid() && !CondVar) || Body.isInvalid()) return StmtError(); - return Actions.ActOnWhileStmt(WhileLoc, FullCond, CondVar, move(Body)); + return Actions.ActOnWhileStmt(WhileLoc, FullCond, CondVar, Body.get()); } /// ParseDoStatement @@ -925,8 +925,8 @@ Parser::OwningStmtResult Parser::ParseDoStatement(AttributeList *Attr) { if (Cond.isInvalid() || Body.isInvalid()) return StmtError(); - return Actions.ActOnDoStmt(DoLoc, move(Body), WhileLoc, LPLoc, - move(Cond), RPLoc); + return Actions.ActOnDoStmt(DoLoc, Body.get(), WhileLoc, LPLoc, + Cond.get(), RPLoc); } /// ParseForStatement @@ -1038,7 +1038,7 @@ Parser::OwningStmtResult Parser::ParseForStatement(AttributeList *Attr) { // Turn the expression into a stmt. if (!Value.isInvalid()) - FirstPart = Actions.ActOnExprStmt(Actions.MakeFullExpr(Value)); + FirstPart = Actions.ActOnExprStmt(Actions.MakeFullExpr(Value.get())); if (Tok.is(tok::semi)) { ConsumeToken(); @@ -1056,7 +1056,7 @@ Parser::OwningStmtResult Parser::ParseForStatement(AttributeList *Attr) { } } if (!ForEach) { - assert(!SecondPart->get() && "Shouldn't have a second expression yet."); + assert(!SecondPart.get() && "Shouldn't have a second expression yet."); // Parse the second part of the for specifier. if (Tok.is(tok::semi)) { // for (...;; // no second part. @@ -1068,10 +1068,10 @@ Parser::OwningStmtResult Parser::ParseForStatement(AttributeList *Attr) { Second = ParseExpression(); if (!Second.isInvalid()) Second = Actions.ActOnBooleanCondition(getCurScope(), ForLoc, - move(Second)); + Second.get()); } SecondPartIsInvalid = Second.isInvalid(); - SecondPart = Actions.MakeFullExpr(Second); + SecondPart = Actions.MakeFullExpr(Second.get()); } if (Tok.is(tok::semi)) { @@ -1085,7 +1085,7 @@ Parser::OwningStmtResult Parser::ParseForStatement(AttributeList *Attr) { // Parse the third part of the for specifier. if (Tok.isNot(tok::r_paren)) { // for (...;...;) OwningExprResult Third = ParseExpression(); - ThirdPart = Actions.MakeFullExpr(Third); + ThirdPart = Actions.MakeFullExpr(Third.take()); } } // Match the ')'. @@ -1118,14 +1118,14 @@ Parser::OwningStmtResult Parser::ParseForStatement(AttributeList *Attr) { return StmtError(); if (!ForEach) - return Actions.ActOnForStmt(ForLoc, LParenLoc, move(FirstPart), SecondPart, - SecondVar, ThirdPart, RParenLoc, move(Body)); + return Actions.ActOnForStmt(ForLoc, LParenLoc, FirstPart.take(), SecondPart, + SecondVar, ThirdPart, RParenLoc, Body.take()); // FIXME: It isn't clear how to communicate the late destruction of // C++ temporaries used to create the collection. - return Actions.ActOnObjCForCollectionStmt(ForLoc, LParenLoc, move(FirstPart), - move(Collection), RParenLoc, - move(Body)); + return Actions.ActOnObjCForCollectionStmt(ForLoc, LParenLoc, FirstPart.take(), + Collection.take(), RParenLoc, + Body.take()); } /// ParseGotoStatement @@ -1156,7 +1156,7 @@ Parser::OwningStmtResult Parser::ParseGotoStatement(AttributeList *Attr) { SkipUntil(tok::semi, false, true); return StmtError(); } - Res = Actions.ActOnIndirectGotoStmt(GotoLoc, StarLoc, move(R)); + Res = Actions.ActOnIndirectGotoStmt(GotoLoc, StarLoc, R.take()); } else { Diag(Tok, diag::err_expected_ident); return StmtError(); @@ -1218,7 +1218,7 @@ Parser::OwningStmtResult Parser::ParseReturnStatement(AttributeList *Attr) { return StmtError(); } } - return Actions.ActOnReturnStmt(ReturnLoc, move(R)); + return Actions.ActOnReturnStmt(ReturnLoc, R.take()); } /// FuzzyParseMicrosoftAsmStatement. When -fms-extensions is enabled, this @@ -1253,7 +1253,7 @@ Parser::OwningStmtResult Parser::FuzzyParseMicrosoftAsmStatement() { ExprVector Clobbers(Actions); return Actions.ActOnAsmStmt(Tok.getLocation(), true, true, 0, 0, 0, move_arg(Constraints), move_arg(Exprs), - move(AsmString), move_arg(Clobbers), + AsmString.take(), move_arg(Clobbers), Tok.getLocation(), true); } @@ -1326,7 +1326,7 @@ Parser::OwningStmtResult Parser::ParseAsmStatement(bool &msAsm) { return Actions.ActOnAsmStmt(AsmLoc, /*isSimple*/ true, isVolatile, /*NumOutputs*/ 0, /*NumInputs*/ 0, 0, move_arg(Constraints), move_arg(Exprs), - move(AsmString), move_arg(Clobbers), + AsmString.take(), move_arg(Clobbers), RParenLoc); } @@ -1391,7 +1391,7 @@ Parser::OwningStmtResult Parser::ParseAsmStatement(bool &msAsm) { return Actions.ActOnAsmStmt(AsmLoc, false, isVolatile, NumOutputs, NumInputs, Names.data(), move_arg(Constraints), move_arg(Exprs), - move(AsmString), move_arg(Clobbers), + AsmString.take(), move_arg(Clobbers), RParenLoc); } @@ -1482,7 +1482,7 @@ Decl *Parser::ParseFunctionStatementBody(Decl *Decl) { FnBody = Actions.ActOnCompoundStmt(LBraceLoc, LBraceLoc, MultiStmtArg(Actions), false); - return Actions.ActOnFinishFunctionBody(Decl, move(FnBody)); + return Actions.ActOnFinishFunctionBody(Decl, FnBody.take()); } /// ParseFunctionTryBlock - Parse a C++ function-try-block. @@ -1510,7 +1510,7 @@ Decl *Parser::ParseFunctionTryBlock(Decl *Decl) { FnBody = Actions.ActOnCompoundStmt(LBraceLoc, LBraceLoc, MultiStmtArg(Actions), false); - return Actions.ActOnFinishFunctionBody(Decl, move(FnBody)); + return Actions.ActOnFinishFunctionBody(Decl, FnBody.take()); } /// ParseCXXTryBlock - Parse a C++ try-block. @@ -1566,7 +1566,7 @@ Parser::OwningStmtResult Parser::ParseCXXTryBlockCommon(SourceLocation TryLoc) { if (Handlers.empty()) return StmtError(); - return Actions.ActOnCXXTryBlock(TryLoc, move(TryBlock), move_arg(Handlers)); + return Actions.ActOnCXXTryBlock(TryLoc, TryBlock.take(), move_arg(Handlers)); } /// ParseCXXCatchBlock - Parse a C++ catch block, called handler in the standard @@ -1618,5 +1618,5 @@ Parser::OwningStmtResult Parser::ParseCXXCatchBlock() { if (Block.isInvalid()) return move(Block); - return Actions.ActOnCXXCatchBlock(CatchLoc, ExceptionDecl, move(Block)); + return Actions.ActOnCXXCatchBlock(CatchLoc, ExceptionDecl, Block.take()); } diff --git a/lib/Parse/ParseTemplate.cpp b/lib/Parse/ParseTemplate.cpp index 795fea789c..835b6e5a5b 100644 --- a/lib/Parse/ParseTemplate.cpp +++ b/lib/Parse/ParseTemplate.cpp @@ -620,7 +620,7 @@ Parser::ParseNonTypeTemplateParameter(unsigned Depth, unsigned Position) { // Create the parameter. return Actions.ActOnNonTypeTemplateParameter(getCurScope(), ParamDecl, Depth, Position, EqualLoc, - move(DefaultArg)); + DefaultArg.take()); } /// \brief Parses a template-id that after the template name has diff --git a/lib/Parse/Parser.cpp b/lib/Parse/Parser.cpp index fab68486df..498a7d3e7a 100644 --- a/lib/Parse/Parser.cpp +++ b/lib/Parse/Parser.cpp @@ -443,7 +443,7 @@ Parser::DeclGroupPtrTy Parser::ParseExternalDeclaration(CXX0XAttributeList Attr) if (Result.isInvalid()) return DeclGroupPtrTy(); - SingleDecl = Actions.ActOnFileScopeAsmDecl(Tok.getLocation(), move(Result)); + SingleDecl = Actions.ActOnFileScopeAsmDecl(Tok.getLocation(), Result.get()); break; } case tok::at: @@ -696,7 +696,7 @@ Decl *Parser::ParseFunctionDefinition(ParsingDeclarator &D, // Recover from error. if (!Tok.is(tok::l_brace)) { - Actions.ActOnFinishFunctionBody(Res, Action::StmtArg(Actions)); + Actions.ActOnFinishFunctionBody(Res, 0); return Res; } } else diff --git a/lib/Sema/SemaCXXCast.cpp b/lib/Sema/SemaCXXCast.cpp index a7225180ac..f1bdc7a1f5 100644 --- a/lib/Sema/SemaCXXCast.cpp +++ b/lib/Sema/SemaCXXCast.cpp @@ -135,9 +135,8 @@ Sema::ActOnCXXNamedCast(SourceLocation OpLoc, tok::TokenKind Kind, Action::OwningExprResult Sema::BuildCXXNamedCast(SourceLocation OpLoc, tok::TokenKind Kind, - TypeSourceInfo *DestTInfo, ExprArg E, + TypeSourceInfo *DestTInfo, ExprArg Ex, SourceRange AngleBrackets, SourceRange Parens) { - Expr *Ex = E.takeAs(); QualType DestType = DestTInfo->getType(); SourceRange OpRange(OpLoc, Parens.getEnd()); diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index e9a2b3cd72..b2c31916b7 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -4035,14 +4035,14 @@ bool Sema::CheckForConstantInitializer(Expr *Init, QualType DclT) { return true; } -void Sema::AddInitializerToDecl(Decl *dcl, ExprArg init) { - AddInitializerToDecl(dcl, move(init), /*DirectInit=*/false); +void Sema::AddInitializerToDecl(Decl *dcl, Expr *init) { + AddInitializerToDecl(dcl, init, /*DirectInit=*/false); } /// AddInitializerToDecl - Adds the initializer Init to the /// declaration dcl. If DirectInit is true, this is C++ direct /// initialization rather than copy initialization. -void Sema::AddInitializerToDecl(Decl *RealDecl, ExprArg init, bool DirectInit) { +void Sema::AddInitializerToDecl(Decl *RealDecl, Expr *Init, bool DirectInit) { // If there is no declaration, there was an error parsing it. Just ignore // the initializer. if (RealDecl == 0) @@ -4053,7 +4053,6 @@ void Sema::AddInitializerToDecl(Decl *RealDecl, ExprArg init, bool DirectInit) { // distinguish between a normal initializer and a pure-specifier. // Thus this grotesque test. IntegerLiteral *IL; - Expr *Init = static_cast(init.get()); if ((IL = dyn_cast(Init)) && IL->getValue() == 0 && Context.getCanonicalType(IL->getType()) == Context.IntTy) CheckPureMethod(Method, Init->getSourceRange()); @@ -4108,11 +4107,6 @@ void Sema::AddInitializerToDecl(Decl *RealDecl, ExprArg init, bool DirectInit) { if (getLangOptions().CPlusPlus && VDecl->hasLocalStorage()) setFunctionHasBranchProtectedScope(); - // Take ownership of the expression, now that we're sure we have somewhere - // to put it. - Expr *Init = init.takeAs(); - assert(Init && "missing initializer"); - // Capture the variable that is being initialized and the style of // initialization. InitializedEntity Entity = InitializedEntity::InitializeVariable(VDecl); @@ -4860,10 +4854,8 @@ Decl *Sema::ActOnFinishFunctionBody(Decl *D, StmtArg BodyArg) { return ActOnFinishFunctionBody(D, move(BodyArg), false); } -Decl *Sema::ActOnFinishFunctionBody(Decl *dcl, StmtArg BodyArg, - bool IsInstantiation) { - Stmt *Body = BodyArg.takeAs(); - +Decl *Sema::ActOnFinishFunctionBody(Decl *dcl, Stmt *Body, + bool IsInstantiation) { FunctionDecl *FD = 0; FunctionTemplateDecl *FunTmpl = dyn_cast_or_null(dcl); if (FunTmpl) @@ -6663,9 +6655,7 @@ EnumConstantDecl *Sema::CheckEnumConstant(EnumDecl *Enum, EnumConstantDecl *LastEnumConst, SourceLocation IdLoc, IdentifierInfo *Id, - ExprArg val) { - Expr *Val = (Expr *)val.get(); - + Expr *Val) { unsigned IntWidth = Context.Target.getIntWidth(); llvm::APSInt EnumVal(IntWidth); QualType EltTy; @@ -6693,11 +6683,6 @@ EnumConstantDecl *Sema::CheckEnumConstant(EnumDecl *Enum, else if (!Context.hasSameType(Val->getType(), Context.IntTy)) { // Force the type of the expression to 'int'. ImpCastExprToType(Val, Context.IntTy, CastExpr::CK_IntegralCast); - - if (Val != val.get()) { - val.release(); - val = Val; - } } } @@ -6785,7 +6770,6 @@ EnumConstantDecl *Sema::CheckEnumConstant(EnumDecl *Enum, EnumVal.setIsSigned(EltTy->isSignedIntegerType()); } - val.release(); return EnumConstantDecl::Create(Context, Enum, IdLoc, Id, EltTy, Val, EnumVal); } @@ -6832,7 +6816,7 @@ Decl *Sema::ActOnEnumConstant(Scope *S, Decl *theEnumDecl, } EnumConstantDecl *New = CheckEnumConstant(TheEnumDecl, LastEnumConst, - IdLoc, Id, Owned(Val)); + IdLoc, Id, Val); // Register this decl in the current scope stack. if (New) { @@ -7046,8 +7030,8 @@ void Sema::ActOnEnumBody(SourceLocation EnumLoc, SourceLocation LBraceLoc, NumPositiveBits, NumNegativeBits); } -Decl *Sema::ActOnFileScopeAsmDecl(SourceLocation Loc, ExprArg expr) { - StringLiteral *AsmString = cast(expr.takeAs()); +Decl *Sema::ActOnFileScopeAsmDecl(SourceLocation Loc, Expr *expr) { + StringLiteral *AsmString = cast(expr); FileScopeAsmDecl *New = FileScopeAsmDecl::Create(Context, CurContext, Loc, AsmString); diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp index 11afd14df8..3213b2ea5d 100644 --- a/lib/Sema/SemaDeclAttr.cpp +++ b/lib/Sema/SemaDeclAttr.cpp @@ -193,7 +193,7 @@ static void HandleExtVectorTypeAttr(Scope *scope, Decl *d, // Instantiate/Install the vector type, and let Sema build the type for us. // This will run the reguired checks. - QualType T = S.BuildExtVectorType(curType, S.Owned(sizeExpr), Attr.getLoc()); + QualType T = S.BuildExtVectorType(curType, sizeExpr, Attr.getLoc()); if (!T.isNull()) { // FIXME: preserve the old source info. tDecl->setTypeSourceInfo(S.Context.getTrivialTypeSourceInfo(T)); diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index 08a34a5d0f..9479fac085 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -108,7 +108,7 @@ namespace { } bool -Sema::SetParamDefaultArgument(ParmVarDecl *Param, ExprArg DefaultArg, +Sema::SetParamDefaultArgument(ParmVarDecl *Param, Expr *Arg, SourceLocation EqualLoc) { if (RequireCompleteType(Param->getLocation(), Param->getType(), diag::err_typecheck_decl_incomplete_type)) { @@ -116,8 +116,6 @@ Sema::SetParamDefaultArgument(ParmVarDecl *Param, ExprArg DefaultArg, return true; } - Expr *Arg = (Expr *)DefaultArg.get(); - // C++ [dcl.fct.default]p5 // A default argument expression is implicitly converted (clause // 4) to the parameter type. The default argument expression has @@ -139,8 +137,6 @@ Sema::SetParamDefaultArgument(ParmVarDecl *Param, ExprArg DefaultArg, // Okay: add the default argument to the parameter Param->setDefaultArg(Arg); - DefaultArg.release(); - return false; } @@ -149,15 +145,13 @@ Sema::SetParamDefaultArgument(ParmVarDecl *Param, ExprArg DefaultArg, /// to the parameter declaration. void Sema::ActOnParamDefaultArgument(Decl *param, SourceLocation EqualLoc, - ExprArg defarg) { - if (!param || !defarg.get()) + Expr *DefaultArg) { + if (!param || !DefaultArg) return; ParmVarDecl *Param = cast(param); UnparsedDefaultArgLocs.erase(Param); - ExprOwningPtr DefaultArg(this, defarg.takeAs()); - // Default arguments are only permitted in C++ if (!getLangOptions().CPlusPlus) { Diag(EqualLoc, diag::err_param_default_argument) @@ -167,13 +161,13 @@ Sema::ActOnParamDefaultArgument(Decl *param, SourceLocation EqualLoc, } // Check that the default argument is well-formed - CheckDefaultArgumentVisitor DefaultArgChecker(DefaultArg.get(), this); - if (DefaultArgChecker.Visit(DefaultArg.get())) { + CheckDefaultArgumentVisitor DefaultArgChecker(DefaultArg, this); + if (DefaultArgChecker.Visit(DefaultArg)) { Param->setInvalidDecl(); return; } - SetParamDefaultArgument(Param, move(DefaultArg), EqualLoc); + SetParamDefaultArgument(Param, DefaultArg, EqualLoc); } /// ActOnParamUnparsedDefaultArgument - We've seen a default @@ -1002,7 +996,7 @@ Sema::ActOnCXXMemberDeclarator(Scope *S, AccessSpecifier AS, Declarator &D, assert((Name || isInstField) && "No identifier for non-field ?"); if (Init) - AddInitializerToDecl(Member, ExprArg(*this, Init), false); + AddInitializerToDecl(Member, Init, false); if (Deleted) // FIXME: Source location is not very good. SetDeclDeleted(Member, D.getSourceRange().getBegin()); @@ -1294,9 +1288,9 @@ Sema::BuildMemberInitializer(FieldDecl *Member, Expr **Args, if (Member->getType()->isDependentType() || HasDependentArg) { // Can't check initialization for a member of dependent type or when // any of the arguments are type-dependent expressions. - OwningExprResult Init - = Owned(new (Context) ParenListExpr(Context, LParenLoc, Args, NumArgs, - RParenLoc)); + Expr *Init + = new (Context) ParenListExpr(Context, LParenLoc, Args, NumArgs, + RParenLoc); // Erase any temporaries within this evaluation context; we're not // going to track them in the AST, since we'll be rebuilding the @@ -1307,7 +1301,7 @@ Sema::BuildMemberInitializer(FieldDecl *Member, Expr **Args, return new (Context) CXXBaseOrMemberInitializer(Context, Member, IdLoc, LParenLoc, - Init.takeAs(), + Init, RParenLoc); } @@ -1332,7 +1326,7 @@ Sema::BuildMemberInitializer(FieldDecl *Member, Expr **Args, // C++0x [class.base.init]p7: // The initialization of each base and member constitutes a // full-expression. - MemberInit = MaybeCreateCXXExprWithTemporaries(move(MemberInit)); + MemberInit = MaybeCreateCXXExprWithTemporaries(MemberInit.get()); if (MemberInit.isInvalid()) return true; @@ -1348,18 +1342,17 @@ Sema::BuildMemberInitializer(FieldDecl *Member, Expr **Args, for (unsigned I = 0; I != NumArgs; ++I) Args[I]->Retain(); - OwningExprResult Init - = Owned(new (Context) ParenListExpr(Context, LParenLoc, Args, NumArgs, - RParenLoc)); + Expr *Init = new (Context) ParenListExpr(Context, LParenLoc, Args, NumArgs, + RParenLoc); return new (Context) CXXBaseOrMemberInitializer(Context, Member, IdLoc, LParenLoc, - Init.takeAs(), + Init, RParenLoc); } return new (Context) CXXBaseOrMemberInitializer(Context, Member, IdLoc, LParenLoc, - MemberInit.takeAs(), + MemberInit.get(), RParenLoc); } @@ -1464,7 +1457,7 @@ Sema::BuildBaseInitializer(QualType BaseType, TypeSourceInfo *BaseTInfo, // C++0x [class.base.init]p7: // The initialization of each base and member constitutes a // full-expression. - BaseInit = MaybeCreateCXXExprWithTemporaries(move(BaseInit)); + BaseInit = MaybeCreateCXXExprWithTemporaries(BaseInit.get()); if (BaseInit.isInvalid()) return true; @@ -1560,8 +1553,11 @@ BuildImplicitBaseInitializer(Sema &SemaRef, CXXConstructorDecl *Constructor, case IIK_Move: assert(false && "Unhandled initializer kind!"); } + + if (BaseInit.isInvalid()) + return true; - BaseInit = SemaRef.MaybeCreateCXXExprWithTemporaries(move(BaseInit)); + BaseInit = SemaRef.MaybeCreateCXXExprWithTemporaries(BaseInit.get()); if (BaseInit.isInvalid()) return true; @@ -1602,7 +1598,7 @@ BuildImplicitMemberInitializer(Sema &SemaRef, CXXConstructorDecl *Constructor, MemberLookup.addDecl(Field, AS_public); MemberLookup.resolveKind(); Sema::OwningExprResult CopyCtorArg - = SemaRef.BuildMemberReferenceExpr(SemaRef.Owned(MemberExprBase), + = SemaRef.BuildMemberReferenceExpr(MemberExprBase, ParamType, Loc, /*IsArrow=*/false, SS, @@ -1643,9 +1639,9 @@ BuildImplicitMemberInitializer(Sema &SemaRef, CXXConstructorDecl *Constructor, "Reference to invented variable cannot fail!"); // Subscript the array with this iteration variable. - CopyCtorArg = SemaRef.CreateBuiltinArraySubscriptExpr(move(CopyCtorArg), + CopyCtorArg = SemaRef.CreateBuiltinArraySubscriptExpr(CopyCtorArg.take(), Loc, - move(IterationVarRef), + IterationVarRef.take(), Loc); if (CopyCtorArg.isInvalid()) return true; @@ -1675,7 +1671,7 @@ BuildImplicitMemberInitializer(Sema &SemaRef, CXXConstructorDecl *Constructor, Sema::OwningExprResult MemberInit = InitSeq.Perform(SemaRef, Entities.back(), InitKind, Sema::MultiExprArg(SemaRef, &CopyCtorArgE, 1)); - MemberInit = SemaRef.MaybeCreateCXXExprWithTemporaries(move(MemberInit)); + MemberInit = SemaRef.MaybeCreateCXXExprWithTemporaries(MemberInit.get()); if (MemberInit.isInvalid()) return true; @@ -1701,14 +1697,17 @@ BuildImplicitMemberInitializer(Sema &SemaRef, CXXConstructorDecl *Constructor, Sema::OwningExprResult MemberInit = InitSeq.Perform(SemaRef, InitEntity, InitKind, Sema::MultiExprArg(SemaRef, 0, 0)); - MemberInit = SemaRef.MaybeCreateCXXExprWithTemporaries(move(MemberInit)); + if (MemberInit.isInvalid()) + return true; + + MemberInit = SemaRef.MaybeCreateCXXExprWithTemporaries(MemberInit.get()); if (MemberInit.isInvalid()) return true; CXXMemberInit = new (SemaRef.Context) CXXBaseOrMemberInitializer(SemaRef.Context, Field, Loc, Loc, - MemberInit.takeAs(), + MemberInit.get(), Loc); return false; } @@ -4541,13 +4540,10 @@ void Sema::DefineImplicitDestructor(SourceLocation CurrentLocation, /// \param Depth Internal parameter recording the depth of the recursion. /// /// \returns A statement or a loop that copies the expressions. -static Sema::OwningStmtResult +static OwningStmtResult BuildSingleCopyAssign(Sema &S, SourceLocation Loc, QualType T, - Sema::OwningExprResult To, Sema::OwningExprResult From, + Expr *To, Expr *From, bool CopyingBaseSubobject, unsigned Depth = 0) { - typedef Sema::OwningStmtResult OwningStmtResult; - typedef Sema::OwningExprResult OwningExprResult; - // C++0x [class.copy]p30: // Each subobject is assigned in the manner appropriate to its type: // @@ -4605,7 +4601,7 @@ BuildSingleCopyAssign(Sema &S, SourceLocation Loc, QualType T, // Create the reference to operator=. OwningExprResult OpEqualRef - = S.BuildMemberReferenceExpr(move(To), T, Loc, /*isArrow=*/false, SS, + = S.BuildMemberReferenceExpr(To, T, Loc, /*isArrow=*/false, SS, /*FirstQualifierInScope=*/0, OpLookup, /*TemplateArgs=*/0, /*SuppressQualifierCheck=*/true); @@ -4613,10 +4609,10 @@ BuildSingleCopyAssign(Sema &S, SourceLocation Loc, QualType T, return S.StmtError(); // Build the call to the assignment operator. - Expr *FromE = From.takeAs(); + OwningExprResult Call = S.BuildCallToMemberFunction(/*Scope=*/0, OpEqualRef.takeAs(), - Loc, &FromE, 1, 0, Loc); + Loc, &From, 1, 0, Loc); if (Call.isInvalid()) return S.StmtError(); @@ -4627,10 +4623,10 @@ BuildSingleCopyAssign(Sema &S, SourceLocation Loc, QualType T, // operator is used. const ConstantArrayType *ArrayTy = S.Context.getAsConstantArrayType(T); if (!ArrayTy) { - OwningExprResult Assignment = S.CreateBuiltinBinOp(Loc, + OwningExprResult Assignment = S.CreateBuiltinBinOp(Loc, BinaryOperator::Assign, - To.takeAs(), - From.takeAs()); + To, + From); if (Assignment.isInvalid()) return S.StmtError(); @@ -4676,40 +4672,36 @@ BuildSingleCopyAssign(Sema &S, SourceLocation Loc, QualType T, // Create the comparison against the array bound. llvm::APInt Upper = ArrayTy->getSize(); Upper.zextOrTrunc(S.Context.getTypeSize(SizeType)); - OwningExprResult Comparison - = S.Owned(new (S.Context) BinaryOperator(IterationVarRef->Retain(), + Expr *Comparison + = new (S.Context) BinaryOperator(IterationVarRef->Retain(), new (S.Context) IntegerLiteral(Upper, SizeType, Loc), - BinaryOperator::NE, S.Context.BoolTy, Loc)); + BinaryOperator::NE, S.Context.BoolTy, Loc); // Create the pre-increment of the iteration variable. - OwningExprResult Increment - = S.Owned(new (S.Context) UnaryOperator(IterationVarRef->Retain(), - UnaryOperator::PreInc, - SizeType, Loc)); + Expr *Increment + = new (S.Context) UnaryOperator(IterationVarRef->Retain(), + UnaryOperator::PreInc, + SizeType, Loc); // Subscript the "from" and "to" expressions with the iteration variable. - From = S.CreateBuiltinArraySubscriptExpr(move(From), Loc, - S.Owned(IterationVarRef->Retain()), - Loc); - To = S.CreateBuiltinArraySubscriptExpr(move(To), Loc, - S.Owned(IterationVarRef->Retain()), - Loc); - assert(!From.isInvalid() && "Builtin subscripting can't fail!"); - assert(!To.isInvalid() && "Builtin subscripting can't fail!"); + From = AssertSuccess(S.CreateBuiltinArraySubscriptExpr(From, Loc, + IterationVarRef, Loc)); + To = AssertSuccess(S.CreateBuiltinArraySubscriptExpr(To, Loc, + IterationVarRef, Loc)); // Build the copy for an individual element of the array. OwningStmtResult Copy = BuildSingleCopyAssign(S, Loc, ArrayTy->getElementType(), - move(To), move(From), + To, From, CopyingBaseSubobject, Depth+1); if (Copy.isInvalid()) return S.StmtError(); // Construct the loop that copies all elements of this array. - return S.ActOnForStmt(Loc, Loc, S.Owned(InitStmt), + return S.ActOnForStmt(Loc, Loc, InitStmt, S.MakeFullExpr(Comparison), 0, S.MakeFullExpr(Increment), - Loc, move(Copy)); + Loc, Copy.take()); } /// \brief Determine whether the given class has a copy assignment operator @@ -4978,8 +4970,7 @@ void Sema::DefineImplicitCopyAssignment(SourceLocation CurrentLocation, ImplicitCastExpr::LValue, &BasePath); // Dereference "this". - OwningExprResult To = CreateBuiltinUnaryOp(Loc, UnaryOperator::Deref, - Owned(This->Retain())); + OwningExprResult To = CreateBuiltinUnaryOp(Loc, UnaryOperator::Deref, This); // Implicitly cast "this" to the appropriately-qualified base type. Expr *ToE = To.takeAs(); @@ -4992,7 +4983,7 @@ void Sema::DefineImplicitCopyAssignment(SourceLocation CurrentLocation, // Build the copy. OwningStmtResult Copy = BuildSingleCopyAssign(*this, Loc, BaseType, - move(To), Owned(From), + To.get(), From, /*CopyingBaseSubobject=*/true); if (Copy.isInvalid()) { Diag(CurrentLocation, diag::note_member_synthesized_at) @@ -5050,12 +5041,10 @@ void Sema::DefineImplicitCopyAssignment(SourceLocation CurrentLocation, LookupMemberName); MemberLookup.addDecl(*Field); MemberLookup.resolveKind(); - OwningExprResult From = BuildMemberReferenceExpr(Owned(OtherRef->Retain()), - OtherRefType, + OwningExprResult From = BuildMemberReferenceExpr(OtherRef, OtherRefType, Loc, /*IsArrow=*/false, SS, 0, MemberLookup, 0); - OwningExprResult To = BuildMemberReferenceExpr(Owned(This->Retain()), - This->getType(), + OwningExprResult To = BuildMemberReferenceExpr(This, This->getType(), Loc, /*IsArrow=*/true, SS, 0, MemberLookup, 0); assert(!From.isInvalid() && "Implicit field reference cannot fail"); @@ -5083,8 +5072,8 @@ void Sema::DefineImplicitCopyAssignment(SourceLocation CurrentLocation, } // Take the address of the field references for "from" and "to". - From = CreateBuiltinUnaryOp(Loc, UnaryOperator::AddrOf, move(From)); - To = CreateBuiltinUnaryOp(Loc, UnaryOperator::AddrOf, move(To)); + From = CreateBuiltinUnaryOp(Loc, UnaryOperator::AddrOf, From.get()); + To = CreateBuiltinUnaryOp(Loc, UnaryOperator::AddrOf, To.get()); bool NeedsCollectableMemCpy = (BaseType->isRecordType() && @@ -5142,12 +5131,12 @@ void Sema::DefineImplicitCopyAssignment(SourceLocation CurrentLocation, OwningExprResult Call = ExprError(); if (NeedsCollectableMemCpy) Call = ActOnCallExpr(/*Scope=*/0, - Owned(CollectableMemCpyRef->Retain()), + CollectableMemCpyRef, Loc, move_arg(CallArgs), Commas.data(), Loc); else Call = ActOnCallExpr(/*Scope=*/0, - Owned(BuiltinMemCpyRef->Retain()), + BuiltinMemCpyRef, Loc, move_arg(CallArgs), Commas.data(), Loc); @@ -5158,7 +5147,7 @@ void Sema::DefineImplicitCopyAssignment(SourceLocation CurrentLocation, // Build the copy of this field. OwningStmtResult Copy = BuildSingleCopyAssign(*this, Loc, FieldType, - move(To), move(From), + To.get(), From.get(), /*CopyingBaseSubobject=*/false); if (Copy.isInvalid()) { Diag(CurrentLocation, diag::note_member_synthesized_at) @@ -5174,9 +5163,9 @@ void Sema::DefineImplicitCopyAssignment(SourceLocation CurrentLocation, if (!Invalid) { // Add a "return *this;" OwningExprResult ThisObj = CreateBuiltinUnaryOp(Loc, UnaryOperator::Deref, - Owned(This->Retain())); + This); - OwningStmtResult Return = ActOnReturnStmt(Loc, move(ThisObj)); + OwningStmtResult Return = ActOnReturnStmt(Loc, ThisObj.get()); if (Return.isInvalid()) Invalid = true; else { @@ -5570,14 +5559,14 @@ void Sema::AddCXXDirectInitializerToDecl(Decl *RealDecl, LParenLoc, RParenLoc); InitializationSequence InitSeq(*this, Entity, Kind, - (Expr**)Exprs.get(), Exprs.size()); + Exprs.get(), Exprs.size()); OwningExprResult Result = InitSeq.Perform(*this, Entity, Kind, move(Exprs)); if (Result.isInvalid()) { VDecl->setInvalidDecl(); return; } - Result = MaybeCreateCXXExprWithTemporaries(move(Result)); + Result = MaybeCreateCXXExprWithTemporaries(Result.get()); VDecl->setInit(Result.takeAs()); VDecl->setCXXDirectInitializer(true); @@ -6198,11 +6187,9 @@ Decl *Sema::ActOnExceptionDeclarator(Scope *S, Declarator &D) { } Decl *Sema::ActOnStaticAssertDeclaration(SourceLocation AssertLoc, - ExprArg assertexpr, - ExprArg assertmessageexpr) { - Expr *AssertExpr = (Expr *)assertexpr.get(); - StringLiteral *AssertMessage = - cast((Expr *)assertmessageexpr.get()); + Expr *AssertExpr, + Expr *AssertMessageExpr_) { + StringLiteral *AssertMessage = cast(AssertMessageExpr_); if (!AssertExpr->isTypeDependent() && !AssertExpr->isValueDependent()) { llvm::APSInt Value(32); @@ -6218,8 +6205,6 @@ Decl *Sema::ActOnStaticAssertDeclaration(SourceLocation AssertLoc, } } - assertexpr.release(); - assertmessageexpr.release(); Decl *Decl = StaticAssertDecl::Create(Context, CurContext, AssertLoc, AssertExpr, AssertMessage); @@ -6933,7 +6918,7 @@ void Sema::SetIvarInitializers(ObjCImplementationDecl *ObjCImplementation) { Sema::OwningExprResult MemberInit = InitSeq.Perform(*this, InitEntity, InitKind, Sema::MultiExprArg(*this, 0, 0)); - MemberInit = MaybeCreateCXXExprWithTemporaries(move(MemberInit)); + MemberInit = MaybeCreateCXXExprWithTemporaries(MemberInit.get()); // Note, MemberInit could actually come back empty if no initialization // is required (e.g., because it would call a trivial default constructor) if (!MemberInit.get() || MemberInit.isInvalid()) diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 6a62a1a12d..46e2745b21 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -1622,7 +1622,7 @@ Sema::BuildImplicitMemberExpr(const CXXScopeSpec &SS, This = new (Context) CXXThisExpr(Loc, ThisType, /*isImplicit=*/true); } - return BuildMemberReferenceExpr(ExprArg(*this, This), ThisType, + return BuildMemberReferenceExpr(This, ThisType, /*OpLoc*/ SourceLocation(), /*IsArrow*/ true, SS, @@ -1834,7 +1834,7 @@ Sema::BuildDeclarationNameExpr(const CXXScopeSpec &SS, SourceLocation(), Owned(E)); if (!Res.isInvalid()) { - Res = MaybeCreateCXXExprWithTemporaries(move(Res)); + Res = MaybeCreateCXXExprWithTemporaries(Res.get()); Expr *Init = Res.takeAs(); BDRE->setCopyConstructorExpr(Init); } @@ -2074,8 +2074,7 @@ Action::OwningExprResult Sema::ActOnNumericConstant(const Token &Tok) { } Action::OwningExprResult Sema::ActOnParenExpr(SourceLocation L, - SourceLocation R, ExprArg Val) { - Expr *E = Val.takeAs(); + SourceLocation R, Expr *E) { assert((E != 0) && "ActOnParenExpr() missing expr"); return Owned(new (Context) ParenExpr(L, R, E)); } @@ -2252,7 +2251,7 @@ QualType Sema::CheckRealImagOperand(Expr *&V, SourceLocation Loc, bool isReal) { Action::OwningExprResult Sema::ActOnPostfixUnaryOp(Scope *S, SourceLocation OpLoc, - tok::TokenKind Kind, ExprArg Input) { + tok::TokenKind Kind, Expr *Input) { UnaryOperator::Opcode Opc; switch (Kind) { default: assert(0 && "Unknown unary op!"); @@ -2260,22 +2259,21 @@ Sema::ActOnPostfixUnaryOp(Scope *S, SourceLocation OpLoc, case tok::minusminus: Opc = UnaryOperator::PostDec; break; } - return BuildUnaryOp(S, OpLoc, Opc, move(Input)); + return BuildUnaryOp(S, OpLoc, Opc, Input); } Action::OwningExprResult -Sema::ActOnArraySubscriptExpr(Scope *S, ExprArg Base, SourceLocation LLoc, - ExprArg Idx, SourceLocation RLoc) { +Sema::ActOnArraySubscriptExpr(Scope *S, Expr *Base, SourceLocation LLoc, + Expr *Idx, SourceLocation RLoc) { // Since this might be a postfix expression, get rid of ParenListExprs. - Base = MaybeConvertParenListExprToParenExpr(S, move(Base)); + OwningExprResult Result = MaybeConvertParenListExprToParenExpr(S, Base); + if (Result.isInvalid()) return ExprError(); + Base = Result.take(); - Expr *LHSExp = static_cast(Base.get()), - *RHSExp = static_cast(Idx.get()); + Expr *LHSExp = Base, *RHSExp = Idx; if (getLangOptions().CPlusPlus && (LHSExp->isTypeDependent() || RHSExp->isTypeDependent())) { - Base.release(); - Idx.release(); return Owned(new (Context) ArraySubscriptExpr(LHSExp, RHSExp, Context.DependentTy, RLoc)); } @@ -2285,18 +2283,18 @@ Sema::ActOnArraySubscriptExpr(Scope *S, ExprArg Base, SourceLocation LLoc, LHSExp->getType()->isEnumeralType() || RHSExp->getType()->isRecordType() || RHSExp->getType()->isEnumeralType())) { - return CreateOverloadedArraySubscriptExpr(LLoc, RLoc, move(Base),move(Idx)); + return CreateOverloadedArraySubscriptExpr(LLoc, RLoc, Base, Idx); } - return CreateBuiltinArraySubscriptExpr(move(Base), LLoc, move(Idx), RLoc); + return CreateBuiltinArraySubscriptExpr(Base, LLoc, Idx, RLoc); } Action::OwningExprResult -Sema::CreateBuiltinArraySubscriptExpr(ExprArg Base, SourceLocation LLoc, - ExprArg Idx, SourceLocation RLoc) { - Expr *LHSExp = static_cast(Base.get()); - Expr *RHSExp = static_cast(Idx.get()); +Sema::CreateBuiltinArraySubscriptExpr(Expr *Base, SourceLocation LLoc, + Expr *Idx, SourceLocation RLoc) { + Expr *LHSExp = Base; + Expr *RHSExp = Idx; // Perform default conversions. if (!LHSExp->getType()->getAs()) @@ -2404,8 +2402,6 @@ Sema::CreateBuiltinArraySubscriptExpr(ExprArg Base, SourceLocation LLoc, return ExprError(); } - Base.release(); - Idx.release(); return Owned(new (Context) ArraySubscriptExpr(LHSExp, RHSExp, ResultType, RLoc)); } @@ -2546,14 +2542,12 @@ static Decl *FindGetterNameDecl(const ObjCObjectPointerType *QIdTy, } Sema::OwningExprResult -Sema::ActOnDependentMemberExpr(ExprArg Base, QualType BaseType, +Sema::ActOnDependentMemberExpr(Expr *BaseExpr, QualType BaseType, bool IsArrow, SourceLocation OpLoc, const CXXScopeSpec &SS, NamedDecl *FirstQualifierInScope, const DeclarationNameInfo &NameInfo, const TemplateArgumentListInfo *TemplateArgs) { - Expr *BaseExpr = Base.takeAs(); - // Even in dependent contexts, try to diagnose base expressions with // obviously wrong types, e.g.: // @@ -2582,7 +2576,7 @@ Sema::ActOnDependentMemberExpr(ExprArg Base, QualType BaseType, // must have pointer type, and the accessed type is the pointee. return Owned(CXXDependentScopeMemberExpr::Create(Context, BaseExpr, BaseType, IsArrow, OpLoc, - static_cast(SS.getScopeRep()), + SS.getScopeRep(), SS.getRange(), FirstQualifierInScope, NameInfo, TemplateArgs)); @@ -2725,17 +2719,15 @@ LookupMemberExprInRecord(Sema &SemaRef, LookupResult &R, } Sema::OwningExprResult -Sema::BuildMemberReferenceExpr(ExprArg BaseArg, QualType BaseType, +Sema::BuildMemberReferenceExpr(Expr *Base, QualType BaseType, SourceLocation OpLoc, bool IsArrow, CXXScopeSpec &SS, NamedDecl *FirstQualifierInScope, const DeclarationNameInfo &NameInfo, const TemplateArgumentListInfo *TemplateArgs) { - Expr *Base = BaseArg.takeAs(); - if (BaseType->isDependentType() || (SS.isSet() && isDependentScopeSpecifier(SS))) - return ActOnDependentMemberExpr(ExprArg(*this, Base), BaseType, + return ActOnDependentMemberExpr(Base, BaseType, IsArrow, OpLoc, SS, FirstQualifierInScope, NameInfo, TemplateArgs); @@ -2769,20 +2761,19 @@ Sema::BuildMemberReferenceExpr(ExprArg BaseArg, QualType BaseType, BaseType = Base->getType(); } - return BuildMemberReferenceExpr(ExprArg(*this, Base), BaseType, + return BuildMemberReferenceExpr(Base, BaseType, OpLoc, IsArrow, SS, FirstQualifierInScope, R, TemplateArgs); } Sema::OwningExprResult -Sema::BuildMemberReferenceExpr(ExprArg Base, QualType BaseExprType, +Sema::BuildMemberReferenceExpr(Expr *BaseExpr, QualType BaseExprType, SourceLocation OpLoc, bool IsArrow, const CXXScopeSpec &SS, NamedDecl *FirstQualifierInScope, LookupResult &R, const TemplateArgumentListInfo *TemplateArgs, bool SuppressQualifierCheck) { - Expr *BaseExpr = Base.takeAs(); QualType BaseType = BaseExprType; if (IsArrow) { assert(BaseType->isPointerType()); @@ -2790,8 +2781,7 @@ Sema::BuildMemberReferenceExpr(ExprArg Base, QualType BaseExprType, } R.setBaseObjectType(BaseType); - NestedNameSpecifier *Qualifier = - static_cast(SS.getScopeRep()); + NestedNameSpecifier *Qualifier = SS.getScopeRep(); const DeclarationNameInfo &MemberNameInfo = R.getLookupNameInfo(); DeclarationName MemberName = MemberNameInfo.getName(); SourceLocation MemberLoc = MemberNameInfo.getLoc(); @@ -3002,7 +2992,7 @@ Sema::LookupMemberExpr(LookupResult &R, Expr *&BaseExpr, << FixItHint::CreateInsertion(Loc, "()"); OwningExprResult NewBase - = ActOnCallExpr(0, ExprArg(*this, BaseExpr), Loc, + = ActOnCallExpr(0, BaseExpr, Loc, MultiExprArg(*this, 0, 0), 0, Loc); BaseExpr = 0; if (NewBase.isInvalid()) @@ -3314,7 +3304,7 @@ Sema::LookupMemberExpr(LookupResult &R, Expr *&BaseExpr, /// \param ObjCImpDecl the current ObjC @implementation decl; /// this is an ugly hack around the fact that ObjC @implementations /// aren't properly put in the context chain -Sema::OwningExprResult Sema::ActOnMemberAccessExpr(Scope *S, ExprArg BaseArg, +Sema::OwningExprResult Sema::ActOnMemberAccessExpr(Scope *S, Expr *Base, SourceLocation OpLoc, tok::TokenKind OpKind, CXXScopeSpec &SS, @@ -3340,13 +3330,13 @@ Sema::OwningExprResult Sema::ActOnMemberAccessExpr(Scope *S, ExprArg BaseArg, static_cast(SS.getScopeRep()))); // This is a postfix expression, so get rid of ParenListExprs. - BaseArg = MaybeConvertParenListExprToParenExpr(S, move(BaseArg)); + OwningExprResult Result = MaybeConvertParenListExprToParenExpr(S, Base); + if (Result.isInvalid()) return ExprError(); + Base = Result.take(); - Expr *Base = BaseArg.takeAs(); - OwningExprResult Result; if (Base->getType()->isDependentType() || Name.isDependentName() || isDependentScopeSpecifier(SS)) { - Result = ActOnDependentMemberExpr(ExprArg(*this, Base), Base->getType(), + Result = ActOnDependentMemberExpr(Base, Base->getType(), IsArrow, OpLoc, SS, FirstQualifierInScope, NameInfo, TemplateArgs); @@ -3367,12 +3357,12 @@ Sema::OwningExprResult Sema::ActOnMemberAccessExpr(Scope *S, ExprArg BaseArg, // call now. if (!HasTrailingLParen && Id.getKind() == UnqualifiedId::IK_DestructorName) - return DiagnoseDtorReference(NameInfo.getLoc(), move(Result)); + return DiagnoseDtorReference(NameInfo.getLoc(), Result.get()); return move(Result); } - Result = BuildMemberReferenceExpr(ExprArg(*this, Base), Base->getType(), + Result = BuildMemberReferenceExpr(Base, Base->getType(), OpLoc, IsArrow, SS, FirstQualifierInScope, R, TemplateArgs); } @@ -3571,17 +3561,17 @@ bool Sema::GatherArgumentsForCall(SourceLocation CallLoc, /// This provides the location of the left/right parens and a list of comma /// locations. Action::OwningExprResult -Sema::ActOnCallExpr(Scope *S, ExprArg fn, SourceLocation LParenLoc, +Sema::ActOnCallExpr(Scope *S, Expr *Fn, SourceLocation LParenLoc, MultiExprArg args, SourceLocation *CommaLocs, SourceLocation RParenLoc) { unsigned NumArgs = args.size(); // Since this might be a postfix expression, get rid of ParenListExprs. - fn = MaybeConvertParenListExprToParenExpr(S, move(fn)); + OwningExprResult Result = MaybeConvertParenListExprToParenExpr(S, Fn); + if (Result.isInvalid()) return ExprError(); + Fn = Result.take(); - Expr *Fn = fn.takeAs(); - Expr **Args = reinterpret_cast(args.release()); - assert(Fn && "no function call expression"); + Expr **Args = args.release(); if (getLangOptions().CPlusPlus) { // If this is a pseudo-destructor expression, build the call immediately. @@ -3653,21 +3643,21 @@ Sema::ActOnCallExpr(Scope *S, ExprArg fn, SourceLocation LParenLoc, = BO->getType()->getAs()) { QualType ResultTy = FPT->getCallResultType(Context); - ExprOwningPtr - TheCall(this, new (Context) CXXMemberCallExpr(Context, BO, Args, - NumArgs, ResultTy, - RParenLoc)); + CXXMemberCallExpr *TheCall + = new (Context) CXXMemberCallExpr(Context, BO, Args, + NumArgs, ResultTy, + RParenLoc); if (CheckCallReturnType(FPT->getResultType(), BO->getRHS()->getSourceRange().getBegin(), - TheCall.get(), 0)) + TheCall, 0)) return ExprError(); - if (ConvertArgumentsForCall(&*TheCall, BO, 0, FPT, Args, NumArgs, + if (ConvertArgumentsForCall(TheCall, BO, 0, FPT, Args, NumArgs, RParenLoc)) return ExprError(); - return Owned(MaybeBindToTemporary(TheCall.release()).release()); + return MaybeBindToTemporary(TheCall); } return ExprError(Diag(Fn->getLocStart(), diag::err_typecheck_call_not_function) @@ -3712,10 +3702,10 @@ Sema::BuildResolvedCallExpr(Expr *Fn, NamedDecl *NDecl, // Make the call expr early, before semantic checks. This guarantees cleanup // of arguments and function on error. - ExprOwningPtr TheCall(this, new (Context) CallExpr(Context, Fn, - Args, NumArgs, - Context.BoolTy, - RParenLoc)); + CallExpr *TheCall = new (Context) CallExpr(Context, Fn, + Args, NumArgs, + Context.BoolTy, + RParenLoc); const FunctionType *FuncT; if (!Fn->getType()->isBlockPointerType()) { @@ -3736,7 +3726,7 @@ Sema::BuildResolvedCallExpr(Expr *Fn, NamedDecl *NDecl, // Check for a valid return type if (CheckCallReturnType(FuncT->getResultType(), - Fn->getSourceRange().getBegin(), TheCall.get(), + Fn->getSourceRange().getBegin(), TheCall, FDecl)) return ExprError(); @@ -3744,7 +3734,7 @@ Sema::BuildResolvedCallExpr(Expr *Fn, NamedDecl *NDecl, TheCall->setType(FuncT->getCallResultType(Context)); if (const FunctionProtoType *Proto = dyn_cast(FuncT)) { - if (ConvertArgumentsForCall(&*TheCall, Fn, FDecl, Proto, Args, NumArgs, + if (ConvertArgumentsForCall(TheCall, Fn, FDecl, Proto, Args, NumArgs, RParenLoc)) return ExprError(); } else { @@ -3788,22 +3778,22 @@ Sema::BuildResolvedCallExpr(Expr *Fn, NamedDecl *NDecl, // Do special checking on direct calls to functions. if (FDecl) { - if (CheckFunctionCall(FDecl, TheCall.get())) + if (CheckFunctionCall(FDecl, TheCall)) return ExprError(); if (unsigned BuiltinID = FDecl->getBuiltinID()) - return CheckBuiltinFunctionCall(BuiltinID, TheCall.take()); + return CheckBuiltinFunctionCall(BuiltinID, TheCall); } else if (NDecl) { - if (CheckBlockCall(NDecl, TheCall.get())) + if (CheckBlockCall(NDecl, TheCall)) return ExprError(); } - return MaybeBindToTemporary(TheCall.take()); + return MaybeBindToTemporary(TheCall); } Action::OwningExprResult Sema::ActOnCompoundLiteral(SourceLocation LParenLoc, TypeTy *Ty, - SourceLocation RParenLoc, ExprArg InitExpr) { + SourceLocation RParenLoc, Expr *InitExpr) { assert((Ty != 0) && "ActOnCompoundLiteral(): missing type"); // FIXME: put back this assert when initializers are worked out. //assert((InitExpr != 0) && "ActOnCompoundLiteral(): missing expression"); @@ -3813,14 +3803,13 @@ Sema::ActOnCompoundLiteral(SourceLocation LParenLoc, TypeTy *Ty, if (!TInfo) TInfo = Context.getTrivialTypeSourceInfo(literalType); - return BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc, move(InitExpr)); + return BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc, InitExpr); } Action::OwningExprResult Sema::BuildCompoundLiteralExpr(SourceLocation LParenLoc, TypeSourceInfo *TInfo, - SourceLocation RParenLoc, ExprArg InitExpr) { + SourceLocation RParenLoc, Expr *literalExpr) { QualType literalType = TInfo->getType(); - Expr *literalExpr = static_cast(InitExpr.get()); if (literalType->isArrayType()) { if (literalType->isVariableArrayType()) @@ -3844,8 +3833,7 @@ Sema::BuildCompoundLiteralExpr(SourceLocation LParenLoc, TypeSourceInfo *TInfo, &literalType); if (Result.isInvalid()) return ExprError(); - InitExpr.release(); - literalExpr = static_cast(Result.get()); + literalExpr = Result.get(); bool isFileScope = getCurFunctionOrMethodDecl() == 0; if (isFileScope) { // 6.5.2.5p3 @@ -3853,8 +3841,6 @@ Sema::BuildCompoundLiteralExpr(SourceLocation LParenLoc, TypeSourceInfo *TInfo, return ExprError(); } - Result.release(); - return Owned(new (Context) CompoundLiteralExpr(LParenLoc, TInfo, literalType, literalExpr, isFileScope)); } @@ -3863,7 +3849,7 @@ Action::OwningExprResult Sema::ActOnInitList(SourceLocation LBraceLoc, MultiExprArg initlist, SourceLocation RBraceLoc) { unsigned NumInit = initlist.size(); - Expr **InitList = reinterpret_cast(initlist.release()); + Expr **InitList = initlist.release(); // Semantic analysis for initializers is done by ActOnDeclarator() and // CheckInitializer() - it requires knowledge of the object being intialized. @@ -4062,8 +4048,8 @@ bool Sema::CheckExtVectorCast(SourceRange R, QualType DestTy, Expr *&CastExpr, Action::OwningExprResult Sema::ActOnCastExpr(Scope *S, SourceLocation LParenLoc, TypeTy *Ty, - SourceLocation RParenLoc, ExprArg Op) { - assert((Ty != 0) && (Op.get() != 0) && + SourceLocation RParenLoc, Expr *castExpr) { + assert((Ty != 0) && (castExpr != 0) && "ActOnCastExpr(): missing type or expr"); TypeSourceInfo *castTInfo; @@ -4072,26 +4058,22 @@ Sema::ActOnCastExpr(Scope *S, SourceLocation LParenLoc, TypeTy *Ty, castTInfo = Context.getTrivialTypeSourceInfo(castType); // If the Expr being casted is a ParenListExpr, handle it specially. - Expr *castExpr = (Expr *)Op.get(); if (isa(castExpr)) - return ActOnCastOfParenListExpr(S, LParenLoc, RParenLoc, move(Op), + return ActOnCastOfParenListExpr(S, LParenLoc, RParenLoc, castExpr, castTInfo); - return BuildCStyleCastExpr(LParenLoc, castTInfo, RParenLoc, move(Op)); + return BuildCStyleCastExpr(LParenLoc, castTInfo, RParenLoc, castExpr); } Action::OwningExprResult Sema::BuildCStyleCastExpr(SourceLocation LParenLoc, TypeSourceInfo *Ty, - SourceLocation RParenLoc, ExprArg Op) { - Expr *castExpr = static_cast(Op.get()); - + SourceLocation RParenLoc, Expr *castExpr) { CastExpr::CastKind Kind = CastExpr::CK_Unknown; CXXCastPath BasePath; if (CheckCastTypes(SourceRange(LParenLoc, RParenLoc), Ty->getType(), castExpr, Kind, BasePath)) return ExprError(); - Op.release(); return Owned(CStyleCastExpr::Create(Context, Ty->getType().getNonLValueExprType(Context), Kind, castExpr, &BasePath, Ty, @@ -4100,9 +4082,8 @@ Sema::BuildCStyleCastExpr(SourceLocation LParenLoc, TypeSourceInfo *Ty, /// This is not an AltiVec-style cast, so turn the ParenListExpr into a sequence /// of comma binary operators. -Action::OwningExprResult -Sema::MaybeConvertParenListExprToParenExpr(Scope *S, ExprArg EA) { - Expr *expr = EA.takeAs(); +OwningExprResult +Sema::MaybeConvertParenListExprToParenExpr(Scope *S, Expr *expr) { ParenListExpr *E = dyn_cast(expr); if (!E) return Owned(expr); @@ -4110,17 +4091,19 @@ Sema::MaybeConvertParenListExprToParenExpr(Scope *S, ExprArg EA) { OwningExprResult Result(E->getExpr(0)); for (unsigned i = 1, e = E->getNumExprs(); i != e && !Result.isInvalid(); ++i) - Result = ActOnBinOp(S, E->getExprLoc(), tok::comma, move(Result), - Owned(E->getExpr(i))); + Result = ActOnBinOp(S, E->getExprLoc(), tok::comma, Result.get(), + E->getExpr(i)); - return ActOnParenExpr(E->getLParenLoc(), E->getRParenLoc(), move(Result)); + if (Result.isInvalid()) return ExprError(); + + return ActOnParenExpr(E->getLParenLoc(), E->getRParenLoc(), Result.get()); } Action::OwningExprResult Sema::ActOnCastOfParenListExpr(Scope *S, SourceLocation LParenLoc, - SourceLocation RParenLoc, ExprArg Op, + SourceLocation RParenLoc, Expr *Op, TypeSourceInfo *TInfo) { - ParenListExpr *PE = (ParenListExpr *)Op.get(); + ParenListExpr *PE = cast(Op); QualType Ty = TInfo->getType(); bool isAltiVecLiteral = false; @@ -4148,17 +4131,17 @@ Sema::ActOnCastOfParenListExpr(Scope *S, SourceLocation LParenLoc, // FIXME: This means that pretty-printing the final AST will produce curly // braces instead of the original commas. - Op.release(); InitListExpr *E = new (Context) InitListExpr(Context, LParenLoc, &initExprs[0], initExprs.size(), RParenLoc); E->setType(Ty); - return BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc, Owned(E)); + return BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc, E); } else { // This is not an AltiVec-style cast, so turn the ParenListExpr into a // sequence of BinOp comma operators. - Op = MaybeConvertParenListExprToParenExpr(S, move(Op)); - return BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc, move(Op)); + OwningExprResult Result = MaybeConvertParenListExprToParenExpr(S, Op); + if (Result.isInvalid()) return ExprError(); + return BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc, Result.take()); } } @@ -4502,11 +4485,8 @@ QualType Sema::FindCompositeObjCPointerType(Expr *&LHS, Expr *&RHS, /// in the case of a the GNU conditional expr extension. Action::OwningExprResult Sema::ActOnConditionalOp(SourceLocation QuestionLoc, SourceLocation ColonLoc, - ExprArg Cond, ExprArg LHS, - ExprArg RHS) { - Expr *CondExpr = (Expr *) Cond.get(); - Expr *LHSExpr = (Expr *) LHS.get(), *RHSExpr = (Expr *) RHS.get(); - + Expr *CondExpr, Expr *LHSExpr, + Expr *RHSExpr) { // If this is the gnu "x ?: y" extension, analyze the types as though the LHS // was the condition. bool isLHSNull = LHSExpr == 0; @@ -4518,9 +4498,6 @@ Action::OwningExprResult Sema::ActOnConditionalOp(SourceLocation QuestionLoc, if (result.isNull()) return ExprError(); - Cond.release(); - LHS.release(); - RHS.release(); return Owned(new (Context) ConditionalOperator(CondExpr, QuestionLoc, isLHSNull ? 0 : LHSExpr, ColonLoc, RHSExpr, result)); @@ -6653,10 +6630,8 @@ static void DiagnoseBinOpPrecedence(Sema &Self, BinaryOperator::Opcode Opc, // Binary Operators. 'Tok' is the token for the operator. Action::OwningExprResult Sema::ActOnBinOp(Scope *S, SourceLocation TokLoc, tok::TokenKind Kind, - ExprArg LHS, ExprArg RHS) { + Expr *lhs, Expr *rhs) { BinaryOperator::Opcode Opc = ConvertTokenKindToBinaryOpcode(Kind); - Expr *lhs = LHS.takeAs(), *rhs = RHS.takeAs(); - assert((lhs != 0) && "ActOnBinOp(): missing left expression"); assert((rhs != 0) && "ActOnBinOp(): missing right expression"); @@ -6693,11 +6668,9 @@ Action::OwningExprResult Sema::BuildBinOp(Scope *S, SourceLocation OpLoc, Action::OwningExprResult Sema::CreateBuiltinUnaryOp(SourceLocation OpLoc, unsigned OpcIn, - ExprArg InputArg) { + Expr *Input) { UnaryOperator::Opcode Opc = static_cast(OpcIn); - // FIXME: Input is modified below, but InputArg is not updated appropriately. - Expr *Input = (Expr *)InputArg.get(); QualType resultType; switch (Opc) { case UnaryOperator::PreInc: @@ -6774,14 +6747,12 @@ Action::OwningExprResult Sema::CreateBuiltinUnaryOp(SourceLocation OpLoc, if (resultType.isNull()) return ExprError(); - InputArg.release(); return Owned(new (Context) UnaryOperator(Input, Opc, resultType, OpLoc)); } Action::OwningExprResult Sema::BuildUnaryOp(Scope *S, SourceLocation OpLoc, UnaryOperator::Opcode Opc, - ExprArg input) { - Expr *Input = (Expr*)input.get(); + Expr *Input) { if (getLangOptions().CPlusPlus && Input->getType()->isOverloadableType() && Opc != UnaryOperator::Extension) { // Find all of the overloaded operators visible from this @@ -6794,16 +6765,16 @@ Action::OwningExprResult Sema::BuildUnaryOp(Scope *S, SourceLocation OpLoc, LookupOverloadedOperatorName(OverOp, S, Input->getType(), QualType(), Functions); - return CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(input)); + return CreateOverloadedUnaryOp(OpLoc, Opc, Functions, Input); } - return CreateBuiltinUnaryOp(OpLoc, Opc, move(input)); + return CreateBuiltinUnaryOp(OpLoc, Opc, Input); } // Unary Operators. 'Tok' is the token for the operator. Action::OwningExprResult Sema::ActOnUnaryOp(Scope *S, SourceLocation OpLoc, - tok::TokenKind Op, ExprArg input) { - return BuildUnaryOp(S, OpLoc, ConvertTokenKindToUnaryOpcode(Op), move(input)); + tok::TokenKind Op, Expr *Input) { + return BuildUnaryOp(S, OpLoc, ConvertTokenKindToUnaryOpcode(Op), Input); } /// ActOnAddrLabel - Parse the GNU address of label extension: "&&foo". @@ -6824,9 +6795,8 @@ Sema::OwningExprResult Sema::ActOnAddrLabel(SourceLocation OpLoc, } Sema::OwningExprResult -Sema::ActOnStmtExpr(SourceLocation LPLoc, StmtArg substmt, +Sema::ActOnStmtExpr(SourceLocation LPLoc, Stmt *SubStmt, SourceLocation RPLoc) { // "({..})" - Stmt *SubStmt = static_cast(substmt.get()); assert(SubStmt && isa(SubStmt) && "Invalid action invocation!"); CompoundStmt *Compound = cast(SubStmt); @@ -6856,7 +6826,6 @@ Sema::ActOnStmtExpr(SourceLocation LPLoc, StmtArg substmt, // FIXME: Check that expression type is complete/non-abstract; statement // expressions are not lvalues. - substmt.release(); return Owned(new (Context) StmtExpr(Compound, Ty, LPLoc, RPLoc)); } @@ -7067,13 +7036,9 @@ Sema::BuildTypesCompatibleExpr(SourceLocation BuiltinLoc, Sema::OwningExprResult Sema::ActOnChooseExpr(SourceLocation BuiltinLoc, - ExprArg cond, - ExprArg expr1, ExprArg expr2, + Expr *CondExpr, + Expr *LHSExpr, Expr *RHSExpr, SourceLocation RPLoc) { - Expr *CondExpr = static_cast(cond.get()); - Expr *LHSExpr = static_cast(expr1.get()); - Expr *RHSExpr = static_cast(expr2.get()); - assert((CondExpr && LHSExpr && RHSExpr) && "Missing type argument(s)"); QualType resType; @@ -7096,7 +7061,6 @@ Sema::OwningExprResult Sema::ActOnChooseExpr(SourceLocation BuiltinLoc, : RHSExpr->isValueDependent(); } - cond.release(); expr1.release(); expr2.release(); return Owned(new (Context) ChooseExpr(BuiltinLoc, CondExpr, LHSExpr, RHSExpr, resType, RPLoc, resType->isDependentType(), @@ -7234,7 +7198,7 @@ void Sema::ActOnBlockError(SourceLocation CaretLoc, Scope *CurScope) { /// ActOnBlockStmtExpr - This is called when the body of a block statement /// literal was successfully completed. ^(int x){...} Sema::OwningExprResult Sema::ActOnBlockStmtExpr(SourceLocation CaretLoc, - StmtArg body, Scope *CurScope) { + Stmt *Body, Scope *CurScope) { // If blocks are disabled, emit an error. if (!LangOpts.Blocks) Diag(CaretLoc, diag::err_blocks_disable); @@ -7297,9 +7261,9 @@ Sema::OwningExprResult Sema::ActOnBlockStmtExpr(SourceLocation CaretLoc, // If needed, diagnose invalid gotos and switches in the block. if (FunctionNeedsScopeChecking() && !hasAnyErrorsInThisFunction()) - DiagnoseInvalidJumps(static_cast(body.get())); + DiagnoseInvalidJumps(cast(Body)); - BSI->TheDecl->setBody(body.takeAs()); + BSI->TheDecl->setBody(cast(Body)); bool Good = true; // Check goto/label use. @@ -7333,17 +7297,16 @@ Sema::OwningExprResult Sema::ActOnBlockStmtExpr(SourceLocation CaretLoc, } Sema::OwningExprResult Sema::ActOnVAArg(SourceLocation BuiltinLoc, - ExprArg expr, TypeTy *type, + Expr *expr, TypeTy *type, SourceLocation RPLoc) { TypeSourceInfo *TInfo; QualType T = GetTypeFromParser(type, &TInfo); - return BuildVAArgExpr(BuiltinLoc, move(expr), TInfo, RPLoc); + return BuildVAArgExpr(BuiltinLoc, expr, TInfo, RPLoc); } Sema::OwningExprResult Sema::BuildVAArgExpr(SourceLocation BuiltinLoc, - ExprArg expr, TypeSourceInfo *TInfo, + Expr *E, TypeSourceInfo *TInfo, SourceLocation RPLoc) { - Expr *E = static_cast(expr.get()); Expr *OrigExpr = E; InitBuiltinVaListType(); @@ -7375,7 +7338,6 @@ Sema::OwningExprResult Sema::BuildVAArgExpr(SourceLocation BuiltinLoc, // FIXME: Check that type is complete/non-abstract // FIXME: Warn if a non-POD type is passed in. - expr.release(); QualType T = TInfo->getType().getNonLValueExprType(Context); return Owned(new (Context) VAArgExpr(BuiltinLoc, E, TInfo, RPLoc, T)); } @@ -7909,8 +7871,7 @@ bool Sema::CheckBooleanCondition(Expr *&E, SourceLocation Loc) { } Sema::OwningExprResult Sema::ActOnBooleanCondition(Scope *S, SourceLocation Loc, - ExprArg SubExpr) { - Expr *Sub = SubExpr.takeAs(); + Expr *Sub) { if (!Sub) return ExprError(); diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp index 948a7079a2..8a3dcc9bcb 100644 --- a/lib/Sema/SemaExprCXX.cpp +++ b/lib/Sema/SemaExprCXX.cpp @@ -281,10 +281,9 @@ Sema::OwningExprResult Sema::BuildCXXTypeId(QualType TypeInfoType, /// \brief Build a C++ typeid expression with an expression operand. Sema::OwningExprResult Sema::BuildCXXTypeId(QualType TypeInfoType, SourceLocation TypeidLoc, - ExprArg Operand, + Expr *E, SourceLocation RParenLoc) { bool isUnevaluatedOperand = true; - Expr *E = static_cast(Operand.get()); if (E && !E->isTypeDependent()) { QualType T = E->getType(); if (const RecordType *RecordT = T->getAs()) { @@ -317,8 +316,6 @@ Sema::OwningExprResult Sema::BuildCXXTypeId(QualType TypeInfoType, if (!Context.hasSameType(T, UnqualT)) { T = UnqualT; ImpCastExprToType(E, UnqualT, CastExpr::CK_NoOp, CastCategory(E)); - Operand.release(); - Operand = Owned(E); } } @@ -329,7 +326,7 @@ Sema::OwningExprResult Sema::BuildCXXTypeId(QualType TypeInfoType, ExprEvalContexts.back().Context = Unevaluated; return Owned(new (Context) CXXTypeidExpr(TypeInfoType.withConst(), - Operand.takeAs(), + E, SourceRange(TypeidLoc, RParenLoc))); } @@ -364,7 +361,7 @@ Sema::ActOnCXXTypeid(SourceLocation OpLoc, SourceLocation LParenLoc, } // The operand is an expression. - return BuildCXXTypeId(TypeInfoType, OpLoc, Owned((Expr*)TyOrExpr), RParenLoc); + return BuildCXXTypeId(TypeInfoType, OpLoc, (Expr*)TyOrExpr, RParenLoc); } /// ActOnCXXBoolLiteral - Parse {true,false} literals. @@ -384,8 +381,7 @@ Sema::ActOnCXXNullPtrLiteral(SourceLocation Loc) { /// ActOnCXXThrow - Parse throw expressions. Action::OwningExprResult -Sema::ActOnCXXThrow(SourceLocation OpLoc, ExprArg E) { - Expr *Ex = E.takeAs(); +Sema::ActOnCXXThrow(SourceLocation OpLoc, Expr *Ex) { if (Ex && !Ex->isTypeDependent() && CheckCXXThrowOperand(OpLoc, Ex)) return ExprError(); return Owned(new (Context) CXXThrowExpr(Ex, Context.VoidTy, OpLoc)); @@ -643,7 +639,7 @@ Sema::ActOnCXXNew(SourceLocation StartLoc, bool UseGlobal, AllocType, D.getSourceRange().getBegin(), R, - Owned(ArraySize), + ArraySize, ConstructorLParen, move(ConstructorArgs), ConstructorRParen); @@ -658,7 +654,7 @@ Sema::BuildCXXNew(SourceLocation StartLoc, bool UseGlobal, QualType AllocType, SourceLocation TypeLoc, SourceRange TypeRange, - ExprArg ArraySizeE, + Expr *ArraySize, SourceLocation ConstructorLParen, MultiExprArg ConstructorArgs, SourceLocation ConstructorRParen) { @@ -667,12 +663,12 @@ Sema::BuildCXXNew(SourceLocation StartLoc, bool UseGlobal, // Per C++0x [expr.new]p5, the type being constructed may be a // typedef of an array type. - if (!ArraySizeE.get()) { + if (!ArraySize) { if (const ConstantArrayType *Array = Context.getAsConstantArrayType(AllocType)) { - ArraySizeE = Owned(new (Context) IntegerLiteral(Array->getSize(), - Context.getSizeType(), - TypeRange.getEnd())); + ArraySize = new (Context) IntegerLiteral(Array->getSize(), + Context.getSizeType(), + TypeRange.getEnd()); AllocType = Array->getElementType(); } } @@ -681,13 +677,12 @@ Sema::BuildCXXNew(SourceLocation StartLoc, bool UseGlobal, // C++ 5.3.4p6: "The expression in a direct-new-declarator shall have integral // or enumeration type with a non-negative value." - Expr *ArraySize = (Expr *)ArraySizeE.get(); if (ArraySize && !ArraySize->isTypeDependent()) { QualType SizeType = ArraySize->getType(); OwningExprResult ConvertedSize - = ConvertToIntegralOrEnumerationType(StartLoc, move(ArraySizeE), + = ConvertToIntegralOrEnumerationType(StartLoc, ArraySize, PDiag(diag::err_array_size_not_integral), PDiag(diag::err_array_size_incomplete_type) << ArraySize->getSourceRange(), @@ -700,8 +695,7 @@ Sema::BuildCXXNew(SourceLocation StartLoc, bool UseGlobal, if (ConvertedSize.isInvalid()) return ExprError(); - ArraySize = ConvertedSize.takeAs(); - ArraySizeE = Owned(ArraySize); + ArraySize = ConvertedSize.take(); SizeType = ArraySize->getType(); if (!SizeType->isIntegralOrEnumerationType()) return ExprError(); @@ -851,7 +845,6 @@ Sema::BuildCXXNew(SourceLocation StartLoc, bool UseGlobal, PlacementArgs.release(); ConstructorArgs.release(); - ArraySizeE.release(); // FIXME: The TypeSourceInfo should also be included in CXXNewExpr. return Owned(new (Context) CXXNewExpr(Context, UseGlobal, OperatorNew, @@ -1382,7 +1375,7 @@ bool Sema::FindDeallocationFunction(SourceLocation StartLoc, CXXRecordDecl *RD, /// @code delete [] ptr; @endcode Action::OwningExprResult Sema::ActOnCXXDelete(SourceLocation StartLoc, bool UseGlobal, - bool ArrayForm, ExprArg Operand) { + bool ArrayForm, Expr *Ex) { // C++ [expr.delete]p1: // The operand shall have a pointer type, or a class type having a single // conversion function to a pointer type. The result has type void. @@ -1391,7 +1384,6 @@ Sema::ActOnCXXDelete(SourceLocation StartLoc, bool UseGlobal, FunctionDecl *OperatorDelete = 0; - Expr *Ex = (Expr *)Operand.get(); if (!Ex->isTypeDependent()) { QualType Type = Ex->getType(); @@ -1425,11 +1417,9 @@ Sema::ActOnCXXDelete(SourceLocation StartLoc, bool UseGlobal, // We have a single conversion to a pointer-to-object type. Perform // that conversion. // TODO: don't redo the conversion calculation. - Operand.release(); if (!PerformImplicitConversion(Ex, ObjectPtrConversions.front()->getConversionType(), AA_Converting)) { - Operand = Owned(Ex); Type = Ex->getType(); } } @@ -1470,10 +1460,6 @@ Sema::ActOnCXXDelete(SourceLocation StartLoc, bool UseGlobal, ImpCastExprToType(Ex, Context.getPointerType(Context.VoidTy), CastExpr::CK_NoOp); - // Update the operand. - Operand.take(); - Operand = ExprArg(*this, Ex); - DeclarationName DeleteName = Context.DeclarationNames.getCXXOperatorName( ArrayForm ? OO_Array_Delete : OO_Delete); @@ -1505,7 +1491,6 @@ Sema::ActOnCXXDelete(SourceLocation StartLoc, bool UseGlobal, // FIXME: Check access and ambiguity of operator delete and destructor. } - Operand.release(); return Owned(new (Context) CXXDeleteExpr(Context.VoidTy, UseGlobal, ArrayForm, OperatorDelete, Ex, StartLoc)); } @@ -1586,9 +1571,7 @@ static Sema::OwningExprResult BuildCXXCastArgument(Sema &S, QualType Ty, CastExpr::CastKind Kind, CXXMethodDecl *Method, - Sema::ExprArg Arg) { - Expr *From = Arg.takeAs(); - + Expr *From) { switch (Kind) { default: assert(0 && "Unhandled cast kind!"); case CastExpr::CK_ConstructorConversion: { @@ -1674,7 +1657,7 @@ Sema::PerformImplicitConversion(Expr *&From, QualType ToType, From->getLocStart(), ToType.getNonReferenceType(), CastKind, cast(FD), - Owned(From)); + From); if (CastArg.isInvalid()) return true; @@ -2694,16 +2677,15 @@ FullExpr Sema::CreateFullExpr(Expr *SubExpr) { } Sema::OwningExprResult -Sema::ActOnStartCXXMemberReference(Scope *S, ExprArg Base, SourceLocation OpLoc, +Sema::ActOnStartCXXMemberReference(Scope *S, Expr *Base, SourceLocation OpLoc, tok::TokenKind OpKind, TypeTy *&ObjectType, bool &MayBePseudoDestructor) { // Since this might be a postfix expression, get rid of ParenListExprs. - Base = MaybeConvertParenListExprToParenExpr(S, move(Base)); - - Expr *BaseExpr = (Expr*)Base.get(); - assert(BaseExpr && "no record expansion"); + OwningExprResult Result = MaybeConvertParenListExprToParenExpr(S, Base); + if (Result.isInvalid()) return ExprError(); + Base = Result.get(); - QualType BaseType = BaseExpr->getType(); + QualType BaseType = Base->getType(); MayBePseudoDestructor = false; if (BaseType->isDependentType()) { // If we have a pointer to a dependent type and are using the -> operator, @@ -2715,7 +2697,7 @@ Sema::ActOnStartCXXMemberReference(Scope *S, ExprArg Base, SourceLocation OpLoc, ObjectType = BaseType.getAsOpaquePtr(); MayBePseudoDestructor = true; - return move(Base); + return Owned(Base); } // C++ [over.match.oper]p8: @@ -2728,13 +2710,13 @@ Sema::ActOnStartCXXMemberReference(Scope *S, ExprArg Base, SourceLocation OpLoc, CTypes.insert(Context.getCanonicalType(BaseType)); while (BaseType->isRecordType()) { - Base = BuildOverloadedArrowExpr(S, move(Base), OpLoc); - BaseExpr = (Expr*)Base.get(); - if (BaseExpr == NULL) + Result = BuildOverloadedArrowExpr(S, Base, OpLoc); + if (Result.isInvalid()) return ExprError(); - if (CXXOperatorCallExpr *OpCall = dyn_cast(BaseExpr)) + Base = Result.get(); + if (CXXOperatorCallExpr *OpCall = dyn_cast(Base)) Locations.push_back(OpCall->getDirectCallee()->getLocation()); - BaseType = BaseExpr->getType(); + BaseType = Base->getType(); CanQualType CBaseType = Context.getCanonicalType(BaseType); if (!CTypes.insert(CBaseType)) { Diag(OpLoc, diag::err_operator_arrow_circular); @@ -2761,7 +2743,7 @@ Sema::ActOnStartCXXMemberReference(Scope *S, ExprArg Base, SourceLocation OpLoc, // pseudo-destructor-name. ObjectType = 0; MayBePseudoDestructor = true; - return move(Base); + return Owned(Base); } // The object type must be complete (or dependent). @@ -2780,22 +2762,21 @@ Sema::ActOnStartCXXMemberReference(Scope *S, ExprArg Base, SourceLocation OpLoc, } Sema::OwningExprResult Sema::DiagnoseDtorReference(SourceLocation NameLoc, - ExprArg MemExpr) { - Expr *E = (Expr *) MemExpr.get(); + Expr *MemExpr) { SourceLocation ExpectedLParenLoc = PP.getLocForEndOfToken(NameLoc); - Diag(E->getLocStart(), diag::err_dtor_expr_without_call) - << isa(E) + Diag(MemExpr->getLocStart(), diag::err_dtor_expr_without_call) + << isa(MemExpr) << FixItHint::CreateInsertion(ExpectedLParenLoc, "()"); return ActOnCallExpr(/*Scope*/ 0, - move(MemExpr), + MemExpr, /*LPLoc*/ ExpectedLParenLoc, Sema::MultiExprArg(*this, 0, 0), /*CommaLocs*/ 0, /*RPLoc*/ ExpectedLParenLoc); } -Sema::OwningExprResult Sema::BuildPseudoDestructorExpr(ExprArg Base, +Sema::OwningExprResult Sema::BuildPseudoDestructorExpr(Expr *Base, SourceLocation OpLoc, tok::TokenKind OpKind, const CXXScopeSpec &SS, @@ -2810,12 +2791,11 @@ Sema::OwningExprResult Sema::BuildPseudoDestructorExpr(ExprArg Base, // The left-hand side of the dot operator shall be of scalar type. The // left-hand side of the arrow operator shall be of pointer to scalar type. // This scalar type is the object type. - Expr *BaseE = (Expr *)Base.get(); - QualType ObjectType = BaseE->getType(); + QualType ObjectType = Base->getType(); if (OpKind == tok::arrow) { if (const PointerType *Ptr = ObjectType->getAs()) { ObjectType = Ptr->getPointeeType(); - } else if (!BaseE->isTypeDependent()) { + } else if (!Base->isTypeDependent()) { // The user wrote "p->" when she probably meant "p."; fix it. Diag(OpLoc, diag::err_typecheck_member_reference_suggestion) << ObjectType << true @@ -2829,7 +2809,7 @@ Sema::OwningExprResult Sema::BuildPseudoDestructorExpr(ExprArg Base, if (!ObjectType->isDependentType() && !ObjectType->isScalarType()) { Diag(OpLoc, diag::err_pseudo_dtor_base_not_scalar) - << ObjectType << BaseE->getSourceRange(); + << ObjectType << Base->getSourceRange(); return ExprError(); } @@ -2843,7 +2823,7 @@ Sema::OwningExprResult Sema::BuildPseudoDestructorExpr(ExprArg Base, if (!DestructedType->isDependentType() && !ObjectType->isDependentType() && !Context.hasSameUnqualifiedType(DestructedType, ObjectType)) { Diag(DestructedTypeStart, diag::err_pseudo_dtor_type_mismatch) - << ObjectType << DestructedType << BaseE->getSourceRange() + << ObjectType << DestructedType << Base->getSourceRange() << DestructedTypeInfo->getTypeLoc().getLocalSourceRange(); // Recover by setting the destructed type to the object type. @@ -2868,7 +2848,7 @@ Sema::OwningExprResult Sema::BuildPseudoDestructorExpr(ExprArg Base, Diag(ScopeTypeInfo->getTypeLoc().getLocalSourceRange().getBegin(), diag::err_pseudo_dtor_type_mismatch) - << ObjectType << ScopeType << BaseE->getSourceRange() + << ObjectType << ScopeType << Base->getSourceRange() << ScopeTypeInfo->getTypeLoc().getLocalSourceRange(); ScopeType = QualType(); @@ -2876,25 +2856,22 @@ Sema::OwningExprResult Sema::BuildPseudoDestructorExpr(ExprArg Base, } } - OwningExprResult Result - = Owned(new (Context) CXXPseudoDestructorExpr(Context, - Base.takeAs(), - OpKind == tok::arrow, - OpLoc, - (NestedNameSpecifier *) SS.getScopeRep(), - SS.getRange(), - ScopeTypeInfo, - CCLoc, - TildeLoc, - Destructed)); + Expr *Result + = new (Context) CXXPseudoDestructorExpr(Context, Base, + OpKind == tok::arrow, OpLoc, + SS.getScopeRep(), SS.getRange(), + ScopeTypeInfo, + CCLoc, + TildeLoc, + Destructed); if (HasTrailingLParen) - return move(Result); + return Owned(Result); - return DiagnoseDtorReference(Destructed.getLocation(), move(Result)); + return DiagnoseDtorReference(Destructed.getLocation(), Result); } -Sema::OwningExprResult Sema::ActOnPseudoDestructorExpr(Scope *S, ExprArg Base, +Sema::OwningExprResult Sema::ActOnPseudoDestructorExpr(Scope *S, Expr *Base, SourceLocation OpLoc, tok::TokenKind OpKind, CXXScopeSpec &SS, @@ -2910,13 +2887,11 @@ Sema::OwningExprResult Sema::ActOnPseudoDestructorExpr(Scope *S, ExprArg Base, SecondTypeName.getKind() == UnqualifiedId::IK_Identifier) && "Invalid second type name in pseudo-destructor"); - Expr *BaseE = (Expr *)Base.get(); - // C++ [expr.pseudo]p2: // The left-hand side of the dot operator shall be of scalar type. The // left-hand side of the arrow operator shall be of pointer to scalar type. // This scalar type is the object type. - QualType ObjectType = BaseE->getType(); + QualType ObjectType = Base->getType(); if (OpKind == tok::arrow) { if (const PointerType *Ptr = ObjectType->getAs()) { ObjectType = Ptr->getPointeeType(); @@ -3043,7 +3018,7 @@ Sema::OwningExprResult Sema::ActOnPseudoDestructorExpr(Scope *S, ExprArg Base, FirstTypeName.StartLocation); - return BuildPseudoDestructorExpr(move(Base), OpLoc, OpKind, SS, + return BuildPseudoDestructorExpr(Base, OpLoc, OpKind, SS, ScopeTypeInfo, CCLoc, TildeLoc, Destructed, HasTrailingLParen); } @@ -3066,12 +3041,7 @@ CXXMemberCallExpr *Sema::BuildCXXMemberCallExpr(Expr *Exp, return CE; } -Sema::OwningExprResult Sema::ActOnFinishFullExpr(ExprArg Arg) { - Expr *FullExpr = Arg.takeAs(); - if (FullExpr) - FullExpr = MaybeCreateCXXExprWithTemporaries(FullExpr); - else - return ExprError(); - - return Owned(FullExpr); +Sema::OwningExprResult Sema::ActOnFinishFullExpr(Expr *FullExpr) { + if (!FullExpr) return ExprError(); + return MaybeCreateCXXExprWithTemporaries(FullExpr); } diff --git a/lib/Sema/SemaExprObjC.cpp b/lib/Sema/SemaExprObjC.cpp index 336fbf2c77..b9071e6894 100644 --- a/lib/Sema/SemaExprObjC.cpp +++ b/lib/Sema/SemaExprObjC.cpp @@ -659,7 +659,7 @@ Sema::OwningExprResult Sema::ActOnSuperMessage(Scope *S, // message to the superclass instance. QualType SuperTy = Context.getObjCInterfaceType(Super); SuperTy = Context.getObjCObjectPointerType(SuperTy); - return BuildInstanceMessage(ExprArg(*this), SuperTy, SuperLoc, + return BuildInstanceMessage(0, SuperTy, SuperLoc, Sel, /*Method=*/0, LBracLoc, RBracLoc, move(Args)); } @@ -828,7 +828,7 @@ Sema::OwningExprResult Sema::ActOnClassMessage(Scope *S, /// \param RBrac The location of the closing square bracket ']'. /// /// \param Args The message arguments. -Sema::OwningExprResult Sema::BuildInstanceMessage(ExprArg ReceiverE, +Sema::OwningExprResult Sema::BuildInstanceMessage(Expr *Receiver, QualType ReceiverType, SourceLocation SuperLoc, Selector Sel, @@ -838,7 +838,6 @@ Sema::OwningExprResult Sema::BuildInstanceMessage(ExprArg ReceiverE, MultiExprArg ArgsIn) { // If we have a receiver expression, perform appropriate promotions // and determine receiver type. - Expr *Receiver = ReceiverE.takeAs(); if (Receiver) { if (Receiver->isTypeDependent()) { // If the receiver is type-dependent, we can't type-check anything @@ -986,7 +985,7 @@ Sema::OwningExprResult Sema::BuildInstanceMessage(ExprArg ReceiverE, Receiver = ICE->getSubExpr(); ReceiverType = Receiver->getType(); } - return BuildInstanceMessage(Owned(Receiver), + return BuildInstanceMessage(Receiver, ReceiverType, SuperLoc, Sel, @@ -1034,17 +1033,16 @@ Sema::OwningExprResult Sema::BuildInstanceMessage(ExprArg ReceiverE, // ArgExprs is optional - if it is present, the number of expressions // is obtained from Sel.getNumArgs(). Sema::OwningExprResult Sema::ActOnInstanceMessage(Scope *S, - ExprArg ReceiverE, + Expr *Receiver, Selector Sel, SourceLocation LBracLoc, SourceLocation SelectorLoc, SourceLocation RBracLoc, MultiExprArg Args) { - Expr *Receiver = static_cast(ReceiverE.get()); if (!Receiver) return ExprError(); - return BuildInstanceMessage(move(ReceiverE), Receiver->getType(), + return BuildInstanceMessage(Receiver, Receiver->getType(), /*SuperLoc=*/SourceLocation(), Sel, /*Method=*/0, LBracLoc, RBracLoc, move(Args)); } diff --git a/lib/Sema/SemaOverload.cpp b/lib/Sema/SemaOverload.cpp index e50a06057a..f115a793a9 100644 --- a/lib/Sema/SemaOverload.cpp +++ b/lib/Sema/SemaOverload.cpp @@ -3192,7 +3192,7 @@ bool Sema::PerformContextuallyConvertToObjCId(Expr *&From) { /// \returns The expression, converted to an integral or enumeration type if /// successful. Sema::OwningExprResult -Sema::ConvertToIntegralOrEnumerationType(SourceLocation Loc, ExprArg FromE, +Sema::ConvertToIntegralOrEnumerationType(SourceLocation Loc, Expr *From, const PartialDiagnostic &NotIntDiag, const PartialDiagnostic &IncompleteDiag, const PartialDiagnostic &ExplicitConvDiag, @@ -3200,16 +3200,14 @@ Sema::ConvertToIntegralOrEnumerationType(SourceLocation Loc, ExprArg FromE, const PartialDiagnostic &AmbigDiag, const PartialDiagnostic &AmbigNote, const PartialDiagnostic &ConvDiag) { - Expr *From = static_cast(FromE.get()); - // We can't perform any more checking for type-dependent expressions. if (From->isTypeDependent()) - return move(FromE); + return Owned(From); // If the expression already has integral or enumeration type, we're golden. QualType T = From->getType(); if (T->isIntegralOrEnumerationType()) - return move(FromE); + return Owned(From); // FIXME: Check for missing '()' if T is a function type? @@ -3219,12 +3217,12 @@ Sema::ConvertToIntegralOrEnumerationType(SourceLocation Loc, ExprArg FromE, if (!RecordTy || !getLangOptions().CPlusPlus) { Diag(Loc, NotIntDiag) << T << From->getSourceRange(); - return move(FromE); + return Owned(From); } // We must have a complete class type. if (RequireCompleteType(Loc, T, IncompleteDiag)) - return move(FromE); + return Owned(From); // Look for a conversion to an integral or enumeration type. UnresolvedSet<4> ViableConversions; @@ -3276,8 +3274,7 @@ Sema::ConvertToIntegralOrEnumerationType(SourceLocation Loc, ExprArg FromE, return ExprError(); CheckMemberOperatorAccess(From->getExprLoc(), From, 0, Found); - From = BuildCXXMemberCallExpr(FromE.takeAs(), Found, Conversion); - FromE = Owned(From); + From = BuildCXXMemberCallExpr(From, Found, Conversion); } // We'll complain below about a non-integral condition type. @@ -3300,9 +3297,8 @@ Sema::ConvertToIntegralOrEnumerationType(SourceLocation Loc, ExprArg FromE, << T << ConvTy->isEnumeralType() << ConvTy << From->getSourceRange(); } - From = BuildCXXMemberCallExpr(FromE.takeAs(), Found, + From = BuildCXXMemberCallExpr(From, Found, cast(Found->getUnderlyingDecl())); - FromE = Owned(From); break; } @@ -3316,14 +3312,14 @@ Sema::ConvertToIntegralOrEnumerationType(SourceLocation Loc, ExprArg FromE, Diag(Conv->getLocation(), AmbigNote) << ConvTy->isEnumeralType() << ConvTy; } - return move(FromE); + return Owned(From); } if (!From->getType()->isIntegralOrEnumerationType()) Diag(Loc, NotIntDiag) << From->getType() << From->getSourceRange(); - return move(FromE); + return Owned(From); } /// AddOverloadCandidate - Adds the given function to the set of @@ -6553,7 +6549,7 @@ BuildRecoveryCallExpr(Sema &SemaRef, Scope *S, Expr *Fn, // This shouldn't cause an infinite loop because we're giving it // an expression with non-empty lookup results, which should never // end up here. - return SemaRef.ActOnCallExpr(/*Scope*/ 0, move(NewFn), LParenLoc, + return SemaRef.ActOnCallExpr(/*Scope*/ 0, NewFn.take(), LParenLoc, Sema::MultiExprArg(SemaRef, Args, NumArgs), CommaLocs, RParenLoc); } @@ -6662,9 +6658,8 @@ static bool IsOverloaded(const UnresolvedSetImpl &Functions) { Sema::OwningExprResult Sema::CreateOverloadedUnaryOp(SourceLocation OpLoc, unsigned OpcIn, const UnresolvedSetImpl &Fns, - ExprArg input) { + Expr *Input) { UnaryOperator::Opcode Opc = static_cast(OpcIn); - Expr *Input = (Expr *)input.get(); OverloadedOperatorKind Op = UnaryOperator::getOverloadedOperator(Opc); assert(Op != OO_None && "Invalid opcode for overloaded unary operator"); @@ -6687,7 +6682,7 @@ Sema::CreateOverloadedUnaryOp(SourceLocation OpLoc, unsigned OpcIn, if (Input->isTypeDependent()) { if (Fns.empty()) - return Owned(new (Context) UnaryOperator(input.takeAs(), + return Owned(new (Context) UnaryOperator(Input, Opc, Context.DependentTy, OpLoc)); @@ -6698,7 +6693,6 @@ Sema::CreateOverloadedUnaryOp(SourceLocation OpLoc, unsigned OpcIn, 0, SourceRange(), OpNameInfo, /*ADL*/ true, IsOverloaded(Fns), Fns.begin(), Fns.end()); - input.release(); return Owned(new (Context) CXXOperatorCallExpr(Context, Op, Fn, &Args[0], NumArgs, Context.DependentTy, @@ -6747,12 +6741,10 @@ Sema::CreateOverloadedUnaryOp(SourceLocation OpLoc, unsigned OpcIn, = PerformCopyInitialization(InitializedEntity::InitializeParameter( FnDecl->getParamDecl(0)), SourceLocation(), - move(input)); + Input); if (InputInit.isInvalid()) return ExprError(); - - input = move(InputInit); - Input = (Expr *)input.get(); + Input = InputInit.take(); } DiagnoseUseOfDecl(Best->FoundDecl, OpLoc); @@ -6765,17 +6757,16 @@ Sema::CreateOverloadedUnaryOp(SourceLocation OpLoc, unsigned OpcIn, SourceLocation()); UsualUnaryConversions(FnExpr); - input.release(); Args[0] = Input; - ExprOwningPtr TheCall(this, + CallExpr *TheCall = new (Context) CXXOperatorCallExpr(Context, Op, FnExpr, - Args, NumArgs, ResultTy, OpLoc)); + Args, NumArgs, ResultTy, OpLoc); - if (CheckCallReturnType(FnDecl->getResultType(), OpLoc, TheCall.get(), + if (CheckCallReturnType(FnDecl->getResultType(), OpLoc, TheCall, FnDecl)) return ExprError(); - return MaybeBindToTemporary(TheCall.release()); + return MaybeBindToTemporary(TheCall); } else { // We matched a built-in operator. Convert the arguments, then // break out so that we will build the appropriate built-in @@ -6813,8 +6804,7 @@ Sema::CreateOverloadedUnaryOp(SourceLocation OpLoc, unsigned OpcIn, // Either we found no viable overloaded operator or we matched a // built-in operator. In either case, fall through to trying to // build a built-in operation. - input.release(); - return CreateBuiltinUnaryOp(OpLoc, Opc, Owned(Input)); + return CreateBuiltinUnaryOp(OpLoc, Opc, Input); } /// \brief Create a binary operation that may resolve to an overloaded @@ -6975,16 +6965,15 @@ Sema::CreateOverloadedBinOp(SourceLocation OpLoc, OpLoc); UsualUnaryConversions(FnExpr); - ExprOwningPtr - TheCall(this, new (Context) CXXOperatorCallExpr(Context, Op, FnExpr, - Args, 2, ResultTy, - OpLoc)); + CXXOperatorCallExpr *TheCall = + new (Context) CXXOperatorCallExpr(Context, Op, FnExpr, + Args, 2, ResultTy, OpLoc); - if (CheckCallReturnType(FnDecl->getResultType(), OpLoc, TheCall.get(), + if (CheckCallReturnType(FnDecl->getResultType(), OpLoc, TheCall, FnDecl)) return ExprError(); - return MaybeBindToTemporary(TheCall.release()); + return MaybeBindToTemporary(TheCall); } else { // We matched a built-in operator. Convert the arguments, then // break out so that we will build the appropriate built-in @@ -7053,9 +7042,8 @@ Sema::CreateOverloadedBinOp(SourceLocation OpLoc, Action::OwningExprResult Sema::CreateOverloadedArraySubscriptExpr(SourceLocation LLoc, SourceLocation RLoc, - ExprArg Base, ExprArg Idx) { - Expr *Args[2] = { static_cast(Base.get()), - static_cast(Idx.get()) }; + Expr *Base, Expr *Idx) { + Expr *Args[2] = { Base, Idx }; DeclarationName OpName = Context.DeclarationNames.getCXXOperatorName(OO_Subscript); @@ -7075,8 +7063,6 @@ Sema::CreateOverloadedArraySubscriptExpr(SourceLocation LLoc, UnresolvedSetIterator()); // Can't add any actual overloads yet - Base.release(); - Idx.release(); return Owned(new (Context) CXXOperatorCallExpr(Context, OO_Subscript, Fn, Args, 2, Context.DependentTy, @@ -7135,18 +7121,16 @@ Sema::CreateOverloadedArraySubscriptExpr(SourceLocation LLoc, LLoc); UsualUnaryConversions(FnExpr); - Base.release(); - Idx.release(); - ExprOwningPtr - TheCall(this, new (Context) CXXOperatorCallExpr(Context, OO_Subscript, - FnExpr, Args, 2, - ResultTy, RLoc)); + CXXOperatorCallExpr *TheCall = + new (Context) CXXOperatorCallExpr(Context, OO_Subscript, + FnExpr, Args, 2, + ResultTy, RLoc); - if (CheckCallReturnType(FnDecl->getResultType(), LLoc, TheCall.get(), + if (CheckCallReturnType(FnDecl->getResultType(), LLoc, TheCall, FnDecl)) return ExprError(); - return MaybeBindToTemporary(TheCall.release()); + return MaybeBindToTemporary(TheCall); } else { // We matched a built-in operator. Convert the arguments, then // break out so that we will build the appropriate built-in @@ -7192,10 +7176,7 @@ Sema::CreateOverloadedArraySubscriptExpr(SourceLocation LLoc, } // We matched a built-in operator; build it. - Base.release(); - Idx.release(); - return CreateBuiltinArraySubscriptExpr(Owned(Args[0]), LLoc, - Owned(Args[1]), RLoc); + return CreateBuiltinArraySubscriptExpr(Args[0], LLoc, Args[1], RLoc); } /// BuildCallToMemberFunction - Build a call to a member @@ -7313,15 +7294,14 @@ Sema::BuildCallToMemberFunction(Scope *S, Expr *MemExprE, } assert(Method && "Member call to something that isn't a method?"); - ExprOwningPtr - TheCall(this, new (Context) CXXMemberCallExpr(Context, MemExprE, Args, - NumArgs, - Method->getCallResultType(), - RParenLoc)); + CXXMemberCallExpr *TheCall = + new (Context) CXXMemberCallExpr(Context, MemExprE, Args, NumArgs, + Method->getCallResultType(), + RParenLoc); // Check for a valid return type. if (CheckCallReturnType(Method->getResultType(), MemExpr->getMemberLoc(), - TheCall.get(), Method)) + TheCall, Method)) return ExprError(); // Convert the object argument (for a non-static member function call). @@ -7336,14 +7316,14 @@ Sema::BuildCallToMemberFunction(Scope *S, Expr *MemExprE, // Convert the rest of the arguments const FunctionProtoType *Proto = Method->getType()->getAs(); - if (ConvertArgumentsForCall(&*TheCall, MemExpr, Method, Proto, Args, NumArgs, + if (ConvertArgumentsForCall(TheCall, MemExpr, Method, Proto, Args, NumArgs, RParenLoc)) return ExprError(); - if (CheckFunctionCall(Method, TheCall.get())) + if (CheckFunctionCall(Method, TheCall)) return ExprError(); - return MaybeBindToTemporary(TheCall.release()); + return MaybeBindToTemporary(TheCall); } /// BuildCallToObjectOfClassType - Build a call to an object of class @@ -7488,7 +7468,7 @@ Sema::BuildCallToObjectOfClassType(Scope *S, Expr *Object, CXXMemberCallExpr *CE = BuildCXXMemberCallExpr(Object, Best->FoundDecl, Conv); - return ActOnCallExpr(S, ExprArg(*this, CE), LParenLoc, + return ActOnCallExpr(S, CE, LParenLoc, MultiExprArg(*this, (ExprTy**)Args, NumArgs), CommaLocs, RParenLoc).result(); } @@ -7526,13 +7506,13 @@ Sema::BuildCallToObjectOfClassType(Scope *S, Expr *Object, // Once we've built TheCall, all of the expressions are properly // owned. QualType ResultTy = Method->getCallResultType(); - ExprOwningPtr - TheCall(this, new (Context) CXXOperatorCallExpr(Context, OO_Call, NewFn, - MethodArgs, NumArgs + 1, - ResultTy, RParenLoc)); + CXXOperatorCallExpr *TheCall = + new (Context) CXXOperatorCallExpr(Context, OO_Call, NewFn, + MethodArgs, NumArgs + 1, + ResultTy, RParenLoc); delete [] MethodArgs; - if (CheckCallReturnType(Method->getResultType(), LParenLoc, TheCall.get(), + if (CheckCallReturnType(Method->getResultType(), LParenLoc, TheCall, Method)) return true; @@ -7562,7 +7542,7 @@ Sema::BuildCallToObjectOfClassType(Scope *S, Expr *Object, OwningExprResult InputInit = PerformCopyInitialization(InitializedEntity::InitializeParameter( Method->getParamDecl(i)), - SourceLocation(), Owned(Arg)); + SourceLocation(), Arg); IsError |= InputInit.isInvalid(); Arg = InputInit.takeAs(); @@ -7592,18 +7572,17 @@ Sema::BuildCallToObjectOfClassType(Scope *S, Expr *Object, if (IsError) return true; - if (CheckFunctionCall(Method, TheCall.get())) + if (CheckFunctionCall(Method, TheCall)) return true; - return MaybeBindToTemporary(TheCall.release()).result(); + return MaybeBindToTemporary(TheCall).result(); } /// BuildOverloadedArrowExpr - Build a call to an overloaded @c operator-> /// (if one exists), where @c Base is an expression of class type and /// @c Member is the name of the member we're trying to find. Sema::OwningExprResult -Sema::BuildOverloadedArrowExpr(Scope *S, ExprArg BaseIn, SourceLocation OpLoc) { - Expr *Base = static_cast(BaseIn.get()); +Sema::BuildOverloadedArrowExpr(Scope *S, Expr *Base, SourceLocation OpLoc) { assert(Base->getType()->isRecordType() && "left-hand side must have class type"); SourceLocation Loc = Base->getExprLoc(); @@ -7673,23 +7652,20 @@ Sema::BuildOverloadedArrowExpr(Scope *S, ExprArg BaseIn, SourceLocation OpLoc) { Best->FoundDecl, Method)) return ExprError(); - // No concerns about early exits now. - BaseIn.release(); - // Build the operator call. Expr *FnExpr = new (Context) DeclRefExpr(Method, Method->getType(), SourceLocation()); UsualUnaryConversions(FnExpr); QualType ResultTy = Method->getCallResultType(); - ExprOwningPtr - TheCall(this, new (Context) CXXOperatorCallExpr(Context, OO_Arrow, FnExpr, - &Base, 1, ResultTy, OpLoc)); + CXXOperatorCallExpr *TheCall = + new (Context) CXXOperatorCallExpr(Context, OO_Arrow, FnExpr, + &Base, 1, ResultTy, OpLoc); - if (CheckCallReturnType(Method->getResultType(), OpLoc, TheCall.get(), + if (CheckCallReturnType(Method->getResultType(), OpLoc, TheCall, Method)) return ExprError(); - return move(TheCall); + return Owned(TheCall); } /// FixOverloadedFunctionReference - E is an expression that refers to diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp index 5392da098f..b6e1e7c62d 100644 --- a/lib/Sema/SemaStmt.cpp +++ b/lib/Sema/SemaStmt.cpp @@ -28,7 +28,7 @@ using namespace clang; Sema::OwningStmtResult Sema::ActOnExprStmt(FullExprArg expr) { - Expr *E = expr->takeAs(); + Expr *E = expr.get(); assert(E && "ActOnExprStmt(): missing expression"); // C99 6.8.3p2: The expression in an expression statement is evaluated as a // void expression for its side effects. Conversion to void allows any @@ -171,25 +171,22 @@ Sema::ActOnCompoundStmt(SourceLocation L, SourceLocation R, } Action::OwningStmtResult -Sema::ActOnCaseStmt(SourceLocation CaseLoc, ExprArg lhsval, - SourceLocation DotDotDotLoc, ExprArg rhsval, +Sema::ActOnCaseStmt(SourceLocation CaseLoc, Expr *LHSVal, + SourceLocation DotDotDotLoc, Expr *RHSVal, SourceLocation ColonLoc) { - assert((lhsval.get() != 0) && "missing expression in case statement"); + assert((LHSVal != 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(lhsval.get()); if (!LHSVal->isTypeDependent() && !LHSVal->isValueDependent() && VerifyIntegerConstantExpression(LHSVal)) return StmtError(); // GCC extension: The expression shall be an integer constant. - Expr *RHSVal = static_cast(rhsval.get()); if (RHSVal && !RHSVal->isTypeDependent() && !RHSVal->isValueDependent() && VerifyIntegerConstantExpression(RHSVal)) { RHSVal = 0; // Recover by just forgetting about it. - rhsval = 0; } if (getSwitchStack().empty()) { @@ -197,9 +194,6 @@ Sema::ActOnCaseStmt(SourceLocation CaseLoc, ExprArg lhsval, return StmtError(); } - // Only now release the smart pointers. - lhsval.release(); - rhsval.release(); CaseStmt *CS = new (Context) CaseStmt(LHSVal, RHSVal, CaseLoc, DotDotDotLoc, ColonLoc); getSwitchStack().back()->addSwitchCase(CS); @@ -207,17 +201,14 @@ Sema::ActOnCaseStmt(SourceLocation CaseLoc, ExprArg lhsval, } /// ActOnCaseStmtBody - This installs a statement as the body of a case. -void Sema::ActOnCaseStmtBody(StmtTy *caseStmt, StmtArg subStmt) { +void Sema::ActOnCaseStmtBody(Stmt *caseStmt, Stmt *SubStmt) { CaseStmt *CS = static_cast(caseStmt); - Stmt *SubStmt = subStmt.takeAs(); CS->setSubStmt(SubStmt); } Action::OwningStmtResult Sema::ActOnDefaultStmt(SourceLocation DefaultLoc, SourceLocation ColonLoc, - StmtArg subStmt, Scope *CurScope) { - Stmt *SubStmt = subStmt.takeAs(); - + Stmt *SubStmt, Scope *CurScope) { if (getSwitchStack().empty()) { Diag(DefaultLoc, diag::err_default_not_in_switch); return Owned(SubStmt); @@ -230,8 +221,7 @@ Sema::ActOnDefaultStmt(SourceLocation DefaultLoc, SourceLocation ColonLoc, Action::OwningStmtResult Sema::ActOnLabelStmt(SourceLocation IdentLoc, IdentifierInfo *II, - SourceLocation ColonLoc, StmtArg subStmt) { - Stmt *SubStmt = subStmt.takeAs(); + SourceLocation ColonLoc, Stmt *SubStmt) { // Look up the record for this label identifier. LabelStmt *&LabelDecl = getLabelMap()[II]; @@ -258,8 +248,8 @@ Sema::ActOnLabelStmt(SourceLocation IdentLoc, IdentifierInfo *II, Action::OwningStmtResult Sema::ActOnIfStmt(SourceLocation IfLoc, FullExprArg CondVal, Decl *CondVar, - StmtArg ThenVal, SourceLocation ElseLoc, - StmtArg ElseVal) { + Stmt *thenStmt, SourceLocation ElseLoc, + Stmt *elseStmt) { OwningExprResult CondResult(CondVal.release()); VarDecl *ConditionVar = 0; @@ -273,22 +263,19 @@ Sema::ActOnIfStmt(SourceLocation IfLoc, FullExprArg CondVal, Decl *CondVar, if (!ConditionExpr) return StmtError(); - Stmt *thenStmt = ThenVal.takeAs(); DiagnoseUnusedExprResult(thenStmt); // Warn if the if block has a null body without an else value. // this helps prevent bugs due to typos, such as // if (condition); // do_stuff(); - if (!ElseVal.get()) { + if (!elseStmt) { if (NullStmt* stmt = dyn_cast(thenStmt)) Diag(stmt->getSemiLoc(), diag::warn_empty_if_body); } - Stmt *elseStmt = ElseVal.takeAs(); DiagnoseUnusedExprResult(elseStmt); - CondResult.release(); return Owned(new (Context) IfStmt(Context, IfLoc, ConditionVar, ConditionExpr, thenStmt, ElseLoc, elseStmt)); } @@ -396,57 +383,55 @@ static QualType GetTypeBeforeIntegralPromotion(const Expr* expr) { } Action::OwningStmtResult -Sema::ActOnStartOfSwitchStmt(SourceLocation SwitchLoc, ExprArg Cond, +Sema::ActOnStartOfSwitchStmt(SourceLocation SwitchLoc, Expr *Cond, Decl *CondVar) { + OwningExprResult CondResult; + VarDecl *ConditionVar = 0; if (CondVar) { ConditionVar = cast(CondVar); - OwningExprResult CondE = CheckConditionVariable(ConditionVar, SourceLocation(), false); - if (CondE.isInvalid()) + CondResult = CheckConditionVariable(ConditionVar, SourceLocation(), false); + if (CondResult.isInvalid()) return StmtError(); - Cond = move(CondE); + Cond = CondResult.release(); } - if (!Cond.get()) + if (!Cond) return StmtError(); - Expr *CondExpr = static_cast(Cond.get()); - OwningExprResult ConvertedCond - = ConvertToIntegralOrEnumerationType(SwitchLoc, move(Cond), + CondResult + = ConvertToIntegralOrEnumerationType(SwitchLoc, Cond, PDiag(diag::err_typecheck_statement_requires_integer), PDiag(diag::err_switch_incomplete_class_type) - << CondExpr->getSourceRange(), + << Cond->getSourceRange(), PDiag(diag::err_switch_explicit_conversion), PDiag(diag::note_switch_conversion), PDiag(diag::err_switch_multiple_conversions), PDiag(diag::note_switch_conversion), PDiag(0)); - if (ConvertedCond.isInvalid()) - return StmtError(); - - CondExpr = ConvertedCond.takeAs(); + if (CondResult.isInvalid()) return StmtError(); + Cond = CondResult.take(); if (!CondVar) { - CondExpr = MaybeCreateCXXExprWithTemporaries(CondExpr); - if (!CondExpr) + CondResult = MaybeCreateCXXExprWithTemporaries(Cond); + if (CondResult.isInvalid()) return StmtError(); + Cond = CondResult.take(); } setFunctionHasBranchIntoScope(); - SwitchStmt *SS = new (Context) SwitchStmt(Context, ConditionVar, CondExpr); + SwitchStmt *SS = new (Context) SwitchStmt(Context, ConditionVar, Cond); getSwitchStack().push_back(SS); return Owned(SS); } Action::OwningStmtResult -Sema::ActOnFinishSwitchStmt(SourceLocation SwitchLoc, StmtArg Switch, - StmtArg Body) { - Stmt *BodyStmt = Body.takeAs(); - - SwitchStmt *SS = getSwitchStack().back(); - assert(SS == (SwitchStmt*)Switch.get() && "switch stack missing push/pop!"); +Sema::ActOnFinishSwitchStmt(SourceLocation SwitchLoc, Stmt *Switch, + Stmt *BodyStmt) { + SwitchStmt *SS = cast(Switch); + assert(SS == getSwitchStack().back() && "switch stack missing push/pop!"); SS->setBody(BodyStmt, SwitchLoc); getSwitchStack().pop_back(); @@ -795,13 +780,12 @@ Sema::ActOnFinishSwitchStmt(SourceLocation SwitchLoc, StmtArg Switch, if (CaseListIsErroneous) return StmtError(); - Switch.release(); return Owned(SS); } Action::OwningStmtResult Sema::ActOnWhileStmt(SourceLocation WhileLoc, FullExprArg Cond, - Decl *CondVar, StmtArg Body) { + Decl *CondVar, Stmt *Body) { OwningExprResult CondResult(Cond.release()); VarDecl *ConditionVar = 0; @@ -811,49 +795,40 @@ Sema::ActOnWhileStmt(SourceLocation WhileLoc, FullExprArg Cond, if (CondResult.isInvalid()) return StmtError(); } - Expr *ConditionExpr = CondResult.takeAs(); + Expr *ConditionExpr = CondResult.take(); if (!ConditionExpr) return StmtError(); - Stmt *bodyStmt = Body.takeAs(); - DiagnoseUnusedExprResult(bodyStmt); + DiagnoseUnusedExprResult(Body); - CondResult.release(); return Owned(new (Context) WhileStmt(Context, ConditionVar, ConditionExpr, - bodyStmt, WhileLoc)); + Body, WhileLoc)); } Action::OwningStmtResult -Sema::ActOnDoStmt(SourceLocation DoLoc, StmtArg Body, +Sema::ActOnDoStmt(SourceLocation DoLoc, Stmt *Body, SourceLocation WhileLoc, SourceLocation CondLParen, - ExprArg Cond, SourceLocation CondRParen) { - Expr *condExpr = Cond.takeAs(); - assert(condExpr && "ActOnDoStmt(): missing expression"); + Expr *Cond, SourceLocation CondRParen) { + assert(Cond && "ActOnDoStmt(): missing expression"); - if (CheckBooleanCondition(condExpr, DoLoc)) { - Cond = condExpr; + if (CheckBooleanCondition(Cond, DoLoc)) return StmtError(); - } - condExpr = MaybeCreateCXXExprWithTemporaries(condExpr); - if (!condExpr) + OwningExprResult CondResult = MaybeCreateCXXExprWithTemporaries(Cond); + if (CondResult.isInvalid()) return StmtError(); + Cond = CondResult.take(); - Stmt *bodyStmt = Body.takeAs(); - DiagnoseUnusedExprResult(bodyStmt); + DiagnoseUnusedExprResult(Body); - Cond.release(); - return Owned(new (Context) DoStmt(bodyStmt, condExpr, DoLoc, - WhileLoc, CondRParen)); + return Owned(new (Context) DoStmt(Body, Cond, DoLoc, WhileLoc, CondRParen)); } Action::OwningStmtResult Sema::ActOnForStmt(SourceLocation ForLoc, SourceLocation LParenLoc, - StmtArg first, FullExprArg second, Decl *secondVar, + Stmt *First, FullExprArg second, Decl *secondVar, FullExprArg third, - SourceLocation RParenLoc, StmtArg body) { - Stmt *First = static_cast(first.get()); - + SourceLocation RParenLoc, Stmt *Body) { if (!getLangOptions().CPlusPlus) { if (DeclStmt *DS = dyn_cast_or_null(First)) { // C99 6.8.5p3: The declaration part of a 'for' statement shall only @@ -881,16 +856,13 @@ Sema::ActOnForStmt(SourceLocation ForLoc, SourceLocation LParenLoc, } Expr *Third = third.release().takeAs(); - Stmt *Body = static_cast(body.get()); DiagnoseUnusedExprResult(First); DiagnoseUnusedExprResult(Third); DiagnoseUnusedExprResult(Body); - first.release(); - body.release(); return Owned(new (Context) ForStmt(Context, First, - SecondResult.takeAs(), ConditionVar, + SecondResult.take(), ConditionVar, Third, Body, ForLoc, LParenLoc, RParenLoc)); } @@ -898,11 +870,8 @@ Sema::ActOnForStmt(SourceLocation ForLoc, SourceLocation LParenLoc, Action::OwningStmtResult Sema::ActOnObjCForCollectionStmt(SourceLocation ForLoc, SourceLocation LParenLoc, - StmtArg first, ExprArg second, - SourceLocation RParenLoc, StmtArg body) { - Stmt *First = static_cast(first.get()); - Expr *Second = static_cast(second.get()); - Stmt *Body = static_cast(body.get()); + Stmt *First, Expr *Second, + SourceLocation RParenLoc, Stmt *Body) { if (First) { QualType FirstType; if (DeclStmt *DS = dyn_cast(First)) { @@ -963,9 +932,6 @@ Sema::ActOnObjCForCollectionStmt(SourceLocation ForLoc, } } } - first.release(); - second.release(); - body.release(); return Owned(new (Context) ObjCForCollectionStmt(First, Second, Body, ForLoc, RParenLoc)); } @@ -987,9 +953,8 @@ Sema::ActOnGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc, Action::OwningStmtResult Sema::ActOnIndirectGotoStmt(SourceLocation GotoLoc, SourceLocation StarLoc, - ExprArg DestExp) { + Expr *E) { // Convert operand to void* - Expr* E = DestExp.takeAs(); if (!E->isTypeDependent()) { QualType ETy = E->getType(); QualType DestTy = Context.getPointerType(Context.VoidTy.withConst()); @@ -1153,8 +1118,7 @@ Sema::ActOnBlockReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp) { } Action::OwningStmtResult -Sema::ActOnReturnStmt(SourceLocation ReturnLoc, ExprArg rex) { - Expr *RetValExp = rex.takeAs(); +Sema::ActOnReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp) { if (getCurBlock()) return ActOnBlockReturnStmt(ReturnLoc, RetValExp); @@ -1285,15 +1249,15 @@ Sema::OwningStmtResult Sema::ActOnAsmStmt(SourceLocation AsmLoc, IdentifierInfo **Names, MultiExprArg constraints, MultiExprArg exprs, - ExprArg asmString, + Expr *asmString, MultiExprArg clobbers, SourceLocation RParenLoc, bool MSAsm) { unsigned NumClobbers = clobbers.size(); StringLiteral **Constraints = reinterpret_cast(constraints.get()); - Expr **Exprs = reinterpret_cast(exprs.get()); - StringLiteral *AsmString = cast((Expr *)asmString.get()); + Expr **Exprs = exprs.get(); + StringLiteral *AsmString = cast(asmString); StringLiteral **Clobbers = reinterpret_cast(clobbers.get()); llvm::SmallVector OutputConstraintInfos; @@ -1389,10 +1353,6 @@ Sema::OwningStmtResult Sema::ActOnAsmStmt(SourceLocation AsmLoc, diag::err_asm_unknown_register_name) << Clobber); } - constraints.release(); - exprs.release(); - asmString.release(); - clobbers.release(); AsmStmt *NS = new (Context) AsmStmt(Context, AsmLoc, IsSimple, IsVolatile, MSAsm, NumOutputs, NumInputs, Names, Constraints, Exprs, @@ -1505,35 +1465,32 @@ Sema::OwningStmtResult Sema::ActOnAsmStmt(SourceLocation AsmLoc, Action::OwningStmtResult Sema::ActOnObjCAtCatchStmt(SourceLocation AtLoc, SourceLocation RParen, Decl *Parm, - StmtArg Body) { + Stmt *Body) { VarDecl *Var = cast_or_null(Parm); if (Var && Var->isInvalidDecl()) return StmtError(); - return Owned(new (Context) ObjCAtCatchStmt(AtLoc, RParen, Var, - Body.takeAs())); + return Owned(new (Context) ObjCAtCatchStmt(AtLoc, RParen, Var, Body)); } Action::OwningStmtResult -Sema::ActOnObjCAtFinallyStmt(SourceLocation AtLoc, StmtArg Body) { - return Owned(new (Context) ObjCAtFinallyStmt(AtLoc, - static_cast(Body.release()))); +Sema::ActOnObjCAtFinallyStmt(SourceLocation AtLoc, Stmt *Body) { + return Owned(new (Context) ObjCAtFinallyStmt(AtLoc, Body)); } Action::OwningStmtResult -Sema::ActOnObjCAtTryStmt(SourceLocation AtLoc, StmtArg Try, - MultiStmtArg CatchStmts, StmtArg Finally) { +Sema::ActOnObjCAtTryStmt(SourceLocation AtLoc, Stmt *Try, + MultiStmtArg CatchStmts, Stmt *Finally) { setFunctionHasBranchProtectedScope(); unsigned NumCatchStmts = CatchStmts.size(); - return Owned(ObjCAtTryStmt::Create(Context, AtLoc, Try.takeAs(), - (Stmt **)CatchStmts.release(), + return Owned(ObjCAtTryStmt::Create(Context, AtLoc, Try, + CatchStmts.release(), NumCatchStmts, - Finally.takeAs())); + Finally)); } Sema::OwningStmtResult Sema::BuildObjCAtThrowStmt(SourceLocation AtLoc, - ExprArg ThrowE) { - Expr *Throw = static_cast(ThrowE.get()); + Expr *Throw) { if (Throw) { QualType ThrowType = Throw->getType(); // Make sure the expression type is an ObjC pointer or "void *". @@ -1546,13 +1503,13 @@ Sema::OwningStmtResult Sema::BuildObjCAtThrowStmt(SourceLocation AtLoc, } } - return Owned(new (Context) ObjCAtThrowStmt(AtLoc, ThrowE.takeAs())); + return Owned(new (Context) ObjCAtThrowStmt(AtLoc, Throw)); } Action::OwningStmtResult -Sema::ActOnObjCAtThrowStmt(SourceLocation AtLoc, ExprArg Throw, +Sema::ActOnObjCAtThrowStmt(SourceLocation AtLoc, Expr *Throw, Scope *CurScope) { - if (!Throw.get()) { + if (!Throw) { // @throw without an expression designates a rethrow (which much occur // in the context of an @catch clause). Scope *AtCatchParent = CurScope; @@ -1562,16 +1519,15 @@ Sema::ActOnObjCAtThrowStmt(SourceLocation AtLoc, ExprArg Throw, return StmtError(Diag(AtLoc, diag::error_rethrow_used_outside_catch)); } - return BuildObjCAtThrowStmt(AtLoc, move(Throw)); + return BuildObjCAtThrowStmt(AtLoc, Throw); } Action::OwningStmtResult -Sema::ActOnObjCAtSynchronizedStmt(SourceLocation AtLoc, ExprArg SynchExpr, - StmtArg SynchBody) { +Sema::ActOnObjCAtSynchronizedStmt(SourceLocation AtLoc, Expr *SyncExpr, + Stmt *SyncBody) { setFunctionHasBranchProtectedScope(); // Make sure the expression type is an ObjC pointer or "void *". - Expr *SyncExpr = static_cast(SynchExpr.get()); if (!SyncExpr->getType()->isDependentType() && !SyncExpr->getType()->isObjCObjectPointerType()) { const PointerType *PT = SyncExpr->getType()->getAs(); @@ -1580,20 +1536,18 @@ Sema::ActOnObjCAtSynchronizedStmt(SourceLocation AtLoc, ExprArg SynchExpr, << SyncExpr->getType() << SyncExpr->getSourceRange()); } - return Owned(new (Context) ObjCAtSynchronizedStmt(AtLoc, - SynchExpr.takeAs(), - SynchBody.takeAs())); + return Owned(new (Context) ObjCAtSynchronizedStmt(AtLoc, SyncExpr, SyncBody)); } /// ActOnCXXCatchBlock - Takes an exception declaration and a handler block /// and creates a proper catch handler from them. Action::OwningStmtResult Sema::ActOnCXXCatchBlock(SourceLocation CatchLoc, Decl *ExDecl, - StmtArg HandlerBlock) { + Stmt *HandlerBlock) { // There's nothing to test that ActOnExceptionDecl didn't already test. return Owned(new (Context) CXXCatchStmt(CatchLoc, cast_or_null(ExDecl), - HandlerBlock.takeAs())); + HandlerBlock)); } namespace { @@ -1632,12 +1586,12 @@ public: /// ActOnCXXTryBlock - Takes a try compound-statement and a number of /// handlers and creates a try statement from them. Action::OwningStmtResult -Sema::ActOnCXXTryBlock(SourceLocation TryLoc, StmtArg TryBlock, +Sema::ActOnCXXTryBlock(SourceLocation TryLoc, Stmt *TryBlock, MultiStmtArg RawHandlers) { unsigned NumHandlers = RawHandlers.size(); assert(NumHandlers > 0 && "The parser shouldn't call this if there are no handlers."); - Stmt **Handlers = reinterpret_cast(RawHandlers.get()); + Stmt **Handlers = RawHandlers.get(); llvm::SmallVector TypesWithHandlers; @@ -1685,8 +1639,6 @@ Sema::ActOnCXXTryBlock(SourceLocation TryLoc, StmtArg TryBlock, // Neither of these are explicitly forbidden, but every compiler detects them // and warns. - RawHandlers.release(); - return Owned(CXXTryStmt::Create(Context, TryLoc, - static_cast(TryBlock.release()), + return Owned(CXXTryStmt::Create(Context, TryLoc, TryBlock, Handlers, NumHandlers)); } diff --git a/lib/Sema/SemaTemplate.cpp b/lib/Sema/SemaTemplate.cpp index 33ef32a8e7..9445ced11c 100644 --- a/lib/Sema/SemaTemplate.cpp +++ b/lib/Sema/SemaTemplate.cpp @@ -584,7 +584,7 @@ Decl *Sema::ActOnNonTypeTemplateParameter(Scope *S, Declarator &D, unsigned Depth, unsigned Position, SourceLocation EqualLoc, - ExprArg DefaultArg) { + Expr *Default) { TypeSourceInfo *TInfo = GetTypeForDeclarator(D, S); QualType T = TInfo->getType(); @@ -622,14 +622,14 @@ Decl *Sema::ActOnNonTypeTemplateParameter(Scope *S, Declarator &D, } // Check the well-formedness of the default template argument, if provided. - if (Expr *Default = static_cast(DefaultArg.get())) { + if (Default) { TemplateArgument Converted; if (CheckTemplateArgument(Param, Param->getType(), Default, Converted)) { Param->setInvalidDecl(); return Param; } - Param->setDefaultArgument(DefaultArg.takeAs(), false); + Param->setDefaultArgument(Default, false); } return Param; @@ -3057,7 +3057,8 @@ Sema::BuildExpressionFromDeclTemplateArgument(const TemplateArgument &Arg, QualType ClassType = Context.getTypeDeclType(cast(VD->getDeclContext())); NestedNameSpecifier *Qualifier - = NestedNameSpecifier::Create(Context, 0, false, ClassType.getTypePtr()); + = NestedNameSpecifier::Create(Context, 0, false, + ClassType.getTypePtr()); CXXScopeSpec SS; SS.setScopeRep(Qualifier); OwningExprResult RefExpr = BuildDeclRefExpr(VD, @@ -3067,7 +3068,7 @@ Sema::BuildExpressionFromDeclTemplateArgument(const TemplateArgument &Arg, if (RefExpr.isInvalid()) return ExprError(); - RefExpr = CreateBuiltinUnaryOp(Loc, UnaryOperator::AddrOf, move(RefExpr)); + RefExpr = CreateBuiltinUnaryOp(Loc, UnaryOperator::AddrOf, RefExpr.get()); // We might need to perform a trailing qualification conversion, since // the element type on the parameter could be more qualified than the @@ -3108,7 +3109,7 @@ Sema::BuildExpressionFromDeclTemplateArgument(const TemplateArgument &Arg, } // Take the address of everything else - return CreateBuiltinUnaryOp(Loc, UnaryOperator::AddrOf, move(RefExpr)); + return CreateBuiltinUnaryOp(Loc, UnaryOperator::AddrOf, RefExpr.get()); } // If the non-type template parameter has reference type, qualify the diff --git a/lib/Sema/SemaTemplateInstantiateDecl.cpp b/lib/Sema/SemaTemplateInstantiateDecl.cpp index d915c53c2e..14ae73f466 100644 --- a/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -433,10 +433,8 @@ Decl *TemplateDeclInstantiator::VisitVarDecl(VarDecl *D) { CommaLocs.data(), RParenLoc); } else if (InitArgs.size() == 1) { - Expr *Init = (Expr*)(InitArgs.take()[0]); - SemaRef.AddInitializerToDecl(Var, - SemaRef.Owned(Init), - false); + Expr *Init = InitArgs.take()[0]; + SemaRef.AddInitializerToDecl(Var, Init, false); } else { assert(InitArgs.size() == 0); SemaRef.ActOnUninitializedDecl(Var, false); @@ -594,8 +592,8 @@ Decl *TemplateDeclInstantiator::VisitStaticAssertDecl(StaticAssertDecl *D) { OwningExprResult Message(D->getMessage()); D->getMessage()->Retain(); return SemaRef.ActOnStaticAssertDeclaration(D->getLocation(), - move(InstantiatedAssertExpr), - move(Message)); + InstantiatedAssertExpr.get(), + Message.get()); } Decl *TemplateDeclInstantiator::VisitEnumDecl(EnumDecl *D) { @@ -638,7 +636,7 @@ Decl *TemplateDeclInstantiator::VisitEnumDecl(EnumDecl *D) { EnumConstantDecl *EnumConst = SemaRef.CheckEnumConstant(Enum, LastEnumConst, EC->getLocation(), EC->getIdentifier(), - move(Value)); + Value.get()); if (isInvalid) { if (EnumConst) @@ -2113,7 +2111,7 @@ void Sema::InstantiateFunctionDefinition(SourceLocation PointOfInstantiation, if (Body.isInvalid()) Function->setInvalidDecl(); - ActOnFinishFunctionBody(Function, move(Body), + ActOnFinishFunctionBody(Function, Body.get(), /*IsInstantiation=*/true); PerformDependentDiagnostics(PatternDecl, TemplateArgs); diff --git a/lib/Sema/SemaType.cpp b/lib/Sema/SemaType.cpp index 81441dec93..05c87acb57 100644 --- a/lib/Sema/SemaType.cpp +++ b/lib/Sema/SemaType.cpp @@ -750,11 +750,8 @@ QualType Sema::BuildArrayType(QualType T, ArrayType::ArraySizeModifier ASM, /// \brief Build an ext-vector type. /// /// Run the required checks for the extended vector type. -QualType Sema::BuildExtVectorType(QualType T, ExprArg ArraySize, +QualType Sema::BuildExtVectorType(QualType T, Expr *ArraySize, SourceLocation AttrLoc) { - - Expr *Arg = (Expr *)ArraySize.get(); - // unlike gcc's vector_size attribute, we do not allow vectors to be defined // in conjunction with complex types (pointers, arrays, functions, etc.). if (!T->isDependentType() && @@ -763,11 +760,11 @@ QualType Sema::BuildExtVectorType(QualType T, ExprArg ArraySize, return QualType(); } - if (!Arg->isTypeDependent() && !Arg->isValueDependent()) { + if (!ArraySize->isTypeDependent() && !ArraySize->isValueDependent()) { llvm::APSInt vecSize(32); - if (!Arg->isIntegerConstantExpr(vecSize, Context)) { + if (!ArraySize->isIntegerConstantExpr(vecSize, Context)) { Diag(AttrLoc, diag::err_attribute_argument_not_int) - << "ext_vector_type" << Arg->getSourceRange(); + << "ext_vector_type" << ArraySize->getSourceRange(); return QualType(); } @@ -777,7 +774,7 @@ QualType Sema::BuildExtVectorType(QualType T, ExprArg ArraySize, if (vectorSize == 0) { Diag(AttrLoc, diag::err_attribute_zero_size) - << Arg->getSourceRange(); + << ArraySize->getSourceRange(); return QualType(); } @@ -785,8 +782,7 @@ QualType Sema::BuildExtVectorType(QualType T, ExprArg ArraySize, return Context.getExtVectorType(T, vectorSize); } - return Context.getDependentSizedExtVectorType(T, ArraySize.takeAs(), - AttrLoc); + return Context.getDependentSizedExtVectorType(T, ArraySize, AttrLoc); } /// \brief Build a function type. diff --git a/lib/Sema/TreeTransform.h b/lib/Sema/TreeTransform.h index 40358e31bc..843580bee1 100644 --- a/lib/Sema/TreeTransform.h +++ b/lib/Sema/TreeTransform.h @@ -91,8 +91,6 @@ protected: public: typedef Sema::OwningStmtResult OwningStmtResult; typedef Sema::OwningExprResult OwningExprResult; - typedef Sema::StmtArg StmtArg; - typedef Sema::ExprArg ExprArg; typedef Sema::MultiExprArg MultiExprArg; typedef Sema::MultiStmtArg MultiStmtArg; @@ -107,6 +105,9 @@ public: return static_cast(*this); } + static inline OwningExprResult Owned(Expr *E) { return E; } + static inline OwningStmtResult Owned(Stmt *S) { return S; } + /// \brief Retrieves a reference to the semantic analysis object used for /// this tree transform. Sema &getSema() const { return SemaRef; } @@ -420,7 +421,7 @@ public: /// Subclasses may override this routine to provide different behavior. QualType RebuildVariableArrayType(QualType ElementType, ArrayType::ArraySizeModifier SizeMod, - ExprArg SizeExpr, + Expr *SizeExpr, unsigned IndexTypeQuals, SourceRange BracketsRange); @@ -431,7 +432,7 @@ public: /// Subclasses may override this routine to provide different behavior. QualType RebuildDependentSizedArrayType(QualType ElementType, ArrayType::ArraySizeModifier SizeMod, - ExprArg SizeExpr, + Expr *SizeExpr, unsigned IndexTypeQuals, SourceRange BracketsRange); @@ -457,7 +458,7 @@ public: /// By default, performs semantic analysis when building the vector type. /// Subclasses may override this routine to provide different behavior. QualType RebuildDependentSizedExtVectorType(QualType ElementType, - ExprArg SizeExpr, + Expr *SizeExpr, SourceLocation AttributeLoc); /// \brief Build a new function type. @@ -496,7 +497,7 @@ public: /// /// By default, performs semantic analysis when building the typeof type. /// Subclasses may override this routine to provide different behavior. - QualType RebuildTypeOfExprType(ExprArg Underlying); + QualType RebuildTypeOfExprType(Expr *Underlying); /// \brief Build a new typeof(type) type. /// @@ -507,7 +508,7 @@ public: /// /// By default, performs semantic analysis when building the decltype type. /// Subclasses may override this routine to provide different behavior. - QualType RebuildDecltypeType(ExprArg Underlying); + QualType RebuildDecltypeType(Expr *Underlying); /// \brief Build a new template specialization type. /// @@ -712,7 +713,7 @@ public: MultiStmtArg Statements, SourceLocation RBraceLoc, bool IsStmtExpr) { - return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, move(Statements), + return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements, IsStmtExpr); } @@ -721,11 +722,11 @@ public: /// By default, performs semantic analysis to build the new statement. /// Subclasses may override this routine to provide different behavior. OwningStmtResult RebuildCaseStmt(SourceLocation CaseLoc, - ExprArg LHS, + Expr *LHS, SourceLocation EllipsisLoc, - ExprArg RHS, + Expr *RHS, SourceLocation ColonLoc) { - return getSema().ActOnCaseStmt(CaseLoc, move(LHS), EllipsisLoc, move(RHS), + return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS, ColonLoc); } @@ -733,9 +734,9 @@ public: /// /// By default, performs semantic analysis to build the new statement. /// Subclasses may override this routine to provide different behavior. - OwningStmtResult RebuildCaseStmtBody(StmtArg S, StmtArg Body) { - getSema().ActOnCaseStmtBody(S.get(), move(Body)); - return move(S); + OwningStmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) { + getSema().ActOnCaseStmtBody(S, Body); + return S; } /// \brief Build a new default statement. @@ -744,8 +745,8 @@ public: /// Subclasses may override this routine to provide different behavior. OwningStmtResult RebuildDefaultStmt(SourceLocation DefaultLoc, SourceLocation ColonLoc, - StmtArg SubStmt) { - return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, move(SubStmt), + Stmt *SubStmt) { + return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt, /*CurScope=*/0); } @@ -756,8 +757,8 @@ public: OwningStmtResult RebuildLabelStmt(SourceLocation IdentLoc, IdentifierInfo *Id, SourceLocation ColonLoc, - StmtArg SubStmt) { - return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, move(SubStmt)); + Stmt *SubStmt) { + return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, SubStmt); } /// \brief Build a new "if" statement. @@ -765,10 +766,9 @@ public: /// By default, performs semantic analysis to build the new statement. /// Subclasses may override this routine to provide different behavior. OwningStmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond, - VarDecl *CondVar, StmtArg Then, - SourceLocation ElseLoc, StmtArg Else) { - return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, - move(Then), ElseLoc, move(Else)); + VarDecl *CondVar, Stmt *Then, + SourceLocation ElseLoc, Stmt *Else) { + return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else); } /// \brief Start building a new switch statement. @@ -776,9 +776,8 @@ public: /// By default, performs semantic analysis to build the new statement. /// Subclasses may override this routine to provide different behavior. OwningStmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc, - Sema::ExprArg Cond, - VarDecl *CondVar) { - return getSema().ActOnStartOfSwitchStmt(SwitchLoc, move(Cond), + Expr *Cond, VarDecl *CondVar) { + return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond, CondVar); } @@ -787,9 +786,8 @@ public: /// By default, performs semantic analysis to build the new statement. /// Subclasses may override this routine to provide different behavior. OwningStmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc, - StmtArg Switch, StmtArg Body) { - return getSema().ActOnFinishSwitchStmt(SwitchLoc, move(Switch), - move(Body)); + Stmt *Switch, Stmt *Body) { + return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body); } /// \brief Build a new while statement. @@ -799,22 +797,21 @@ public: OwningStmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond, VarDecl *CondVar, - StmtArg Body) { - return getSema().ActOnWhileStmt(WhileLoc, Cond, - CondVar, move(Body)); + Stmt *Body) { + return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body); } /// \brief Build a new do-while statement. /// /// By default, performs semantic analysis to build the new statement. /// Subclasses may override this routine to provide different behavior. - OwningStmtResult RebuildDoStmt(SourceLocation DoLoc, StmtArg Body, + OwningStmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body, SourceLocation WhileLoc, SourceLocation LParenLoc, - ExprArg Cond, + Expr *Cond, SourceLocation RParenLoc) { - return getSema().ActOnDoStmt(DoLoc, move(Body), WhileLoc, LParenLoc, - move(Cond), RParenLoc); + return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc, + Cond, RParenLoc); } /// \brief Build a new for statement. @@ -823,12 +820,12 @@ public: /// Subclasses may override this routine to provide different behavior. OwningStmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc, - StmtArg Init, Sema::FullExprArg Cond, + Stmt *Init, Sema::FullExprArg Cond, VarDecl *CondVar, Sema::FullExprArg Inc, - SourceLocation RParenLoc, StmtArg Body) { - return getSema().ActOnForStmt(ForLoc, LParenLoc, move(Init), Cond, + SourceLocation RParenLoc, Stmt *Body) { + return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond, CondVar, - Inc, RParenLoc, move(Body)); + Inc, RParenLoc, Body); } /// \brief Build a new goto statement. @@ -847,8 +844,8 @@ public: /// Subclasses may override this routine to provide different behavior. OwningStmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc, SourceLocation StarLoc, - ExprArg Target) { - return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, move(Target)); + Expr *Target) { + return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target); } /// \brief Build a new return statement. @@ -856,9 +853,9 @@ public: /// By default, performs semantic analysis to build the new statement. /// Subclasses may override this routine to provide different behavior. OwningStmtResult RebuildReturnStmt(SourceLocation ReturnLoc, - ExprArg Result) { + Expr *Result) { - return getSema().ActOnReturnStmt(ReturnLoc, move(Result)); + return getSema().ActOnReturnStmt(ReturnLoc, Result); } /// \brief Build a new declaration statement. @@ -887,13 +884,13 @@ public: IdentifierInfo **Names, MultiExprArg Constraints, MultiExprArg Exprs, - ExprArg AsmString, + Expr *AsmString, MultiExprArg Clobbers, SourceLocation RParenLoc, bool MSAsm) { return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs, NumInputs, Names, move(Constraints), - move(Exprs), move(AsmString), move(Clobbers), + Exprs, AsmString, Clobbers, RParenLoc, MSAsm); } @@ -902,11 +899,11 @@ public: /// By default, performs semantic analysis to build the new statement. /// Subclasses may override this routine to provide different behavior. OwningStmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc, - StmtArg TryBody, + Stmt *TryBody, MultiStmtArg CatchStmts, - StmtArg Finally) { - return getSema().ActOnObjCAtTryStmt(AtLoc, move(TryBody), move(CatchStmts), - move(Finally)); + Stmt *Finally) { + return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts), + Finally); } /// \brief Rebuild an Objective-C exception declaration. @@ -927,9 +924,9 @@ public: OwningStmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc, SourceLocation RParenLoc, VarDecl *Var, - StmtArg Body) { + Stmt *Body) { return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc, - Var, move(Body)); + Var, Body); } /// \brief Build a new Objective-C @finally statement. @@ -937,8 +934,8 @@ public: /// By default, performs semantic analysis to build the new statement. /// Subclasses may override this routine to provide different behavior. OwningStmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc, - StmtArg Body) { - return getSema().ActOnObjCAtFinallyStmt(AtLoc, move(Body)); + Stmt *Body) { + return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body); } /// \brief Build a new Objective-C @throw statement. @@ -946,8 +943,8 @@ public: /// By default, performs semantic analysis to build the new statement. /// Subclasses may override this routine to provide different behavior. OwningStmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc, - ExprArg Operand) { - return getSema().BuildObjCAtThrowStmt(AtLoc, move(Operand)); + Expr *Operand) { + return getSema().BuildObjCAtThrowStmt(AtLoc, Operand); } /// \brief Build a new Objective-C @synchronized statement. @@ -955,10 +952,10 @@ public: /// By default, performs semantic analysis to build the new statement. /// Subclasses may override this routine to provide different behavior. OwningStmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc, - ExprArg Object, - StmtArg Body) { - return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, move(Object), - move(Body)); + Expr *Object, + Stmt *Body) { + return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, + Body); } /// \brief Build a new Objective-C fast enumeration statement. @@ -967,15 +964,15 @@ public: /// Subclasses may override this routine to provide different behavior. OwningStmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc, SourceLocation LParenLoc, - StmtArg Element, - ExprArg Collection, + Stmt *Element, + Expr *Collection, SourceLocation RParenLoc, - StmtArg Body) { + Stmt *Body) { return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc, - move(Element), - move(Collection), + Element, + Collection, RParenLoc, - move(Body)); + Body); } /// \brief Build a new C++ exception declaration. @@ -997,10 +994,9 @@ public: /// Subclasses may override this routine to provide different behavior. OwningStmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc, VarDecl *ExceptionDecl, - StmtArg Handler) { - return getSema().Owned( - new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl, - Handler.takeAs())); + Stmt *Handler) { + return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl, + Handler)); } /// \brief Build a new C++ try statement. @@ -1008,9 +1004,9 @@ public: /// By default, performs semantic analysis to build the new statement. /// Subclasses may override this routine to provide different behavior. OwningStmtResult RebuildCXXTryStmt(SourceLocation TryLoc, - StmtArg TryBlock, + Stmt *TryBlock, MultiStmtArg Handlers) { - return getSema().ActOnCXXTryBlock(TryLoc, move(TryBlock), move(Handlers)); + return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers)); } /// \brief Build a new expression that references a declaration. @@ -1046,16 +1042,16 @@ public: /// /// By default, performs semantic analysis to build the new expression. /// Subclasses may override this routine to provide different behavior. - OwningExprResult RebuildParenExpr(ExprArg SubExpr, SourceLocation LParen, + OwningExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen, SourceLocation RParen) { - return getSema().ActOnParenExpr(LParen, RParen, move(SubExpr)); + return getSema().ActOnParenExpr(LParen, RParen, SubExpr); } /// \brief Build a new pseudo-destructor expression. /// /// By default, performs semantic analysis to build the new expression. /// Subclasses may override this routine to provide different behavior. - OwningExprResult RebuildCXXPseudoDestructorExpr(ExprArg Base, + OwningExprResult RebuildCXXPseudoDestructorExpr(Expr *Base, SourceLocation OperatorLoc, bool isArrow, NestedNameSpecifier *Qualifier, @@ -1071,8 +1067,8 @@ public: /// Subclasses may override this routine to provide different behavior. OwningExprResult RebuildUnaryOperator(SourceLocation OpLoc, UnaryOperator::Opcode Opc, - ExprArg SubExpr) { - return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, move(SubExpr)); + Expr *SubExpr) { + return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr); } /// \brief Build a new builtin offsetof expression. @@ -1103,15 +1099,13 @@ public: /// /// By default, performs semantic analysis to build the new expression. /// Subclasses may override this routine to provide different behavior. - OwningExprResult RebuildSizeOfAlignOf(ExprArg SubExpr, SourceLocation OpLoc, + OwningExprResult RebuildSizeOfAlignOf(Expr *SubExpr, SourceLocation OpLoc, bool isSizeOf, SourceRange R) { OwningExprResult Result - = getSema().CreateSizeOfAlignOfExpr((Expr *)SubExpr.get(), - OpLoc, isSizeOf, R); + = getSema().CreateSizeOfAlignOfExpr(SubExpr, OpLoc, isSizeOf, R); if (Result.isInvalid()) return getSema().ExprError(); - SubExpr.release(); return move(Result); } @@ -1119,12 +1113,12 @@ public: /// /// By default, performs semantic analysis to build the new expression. /// Subclasses may override this routine to provide different behavior. - OwningExprResult RebuildArraySubscriptExpr(ExprArg LHS, + OwningExprResult RebuildArraySubscriptExpr(Expr *LHS, SourceLocation LBracketLoc, - ExprArg RHS, + Expr *RHS, SourceLocation RBracketLoc) { - return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, move(LHS), - LBracketLoc, move(RHS), + return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS, + LBracketLoc, RHS, RBracketLoc); } @@ -1132,11 +1126,11 @@ public: /// /// By default, performs semantic analysis to build the new expression. /// Subclasses may override this routine to provide different behavior. - OwningExprResult RebuildCallExpr(ExprArg Callee, SourceLocation LParenLoc, + OwningExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc, MultiExprArg Args, SourceLocation *CommaLocs, SourceLocation RParenLoc) { - return getSema().ActOnCallExpr(/*Scope=*/0, move(Callee), LParenLoc, + return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc, move(Args), CommaLocs, RParenLoc); } @@ -1144,7 +1138,7 @@ public: /// /// By default, performs semantic analysis to build the new expression. /// Subclasses may override this routine to provide different behavior. - OwningExprResult RebuildMemberExpr(ExprArg Base, SourceLocation OpLoc, + OwningExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc, bool isArrow, NestedNameSpecifier *Qualifier, SourceRange QualifierRange, @@ -1157,13 +1151,12 @@ public: // We have a reference to an unnamed field. assert(!Qualifier && "Can't have an unnamed field with a qualifier!"); - Expr *BaseExpr = Base.takeAs(); - if (getSema().PerformObjectMemberConversion(BaseExpr, Qualifier, + if (getSema().PerformObjectMemberConversion(Base, Qualifier, FoundDecl, Member)) return getSema().ExprError(); MemberExpr *ME = - new (getSema().Context) MemberExpr(BaseExpr, isArrow, + new (getSema().Context) MemberExpr(Base, isArrow, Member, MemberNameInfo, cast(Member)->getType()); return getSema().Owned(ME); @@ -1175,9 +1168,8 @@ public: SS.setScopeRep(Qualifier); } - Expr *BaseExpr = Base.takeAs(); - getSema().DefaultFunctionArrayConversion(BaseExpr); - QualType BaseType = BaseExpr->getType(); + getSema().DefaultFunctionArrayConversion(Base); + QualType BaseType = Base->getType(); // FIXME: this involves duplicating earlier analysis in a lot of // cases; we should avoid this when possible. @@ -1185,8 +1177,7 @@ public: R.addDecl(FoundDecl); R.resolveKind(); - return getSema().BuildMemberReferenceExpr(getSema().Owned(BaseExpr), - BaseType, OpLoc, isArrow, + return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow, SS, FirstQualifierInScope, R, ExplicitTemplateArgs); } @@ -1197,22 +1188,21 @@ public: /// Subclasses may override this routine to provide different behavior. OwningExprResult RebuildBinaryOperator(SourceLocation OpLoc, BinaryOperator::Opcode Opc, - ExprArg LHS, ExprArg RHS) { - return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, - LHS.takeAs(), RHS.takeAs()); + Expr *LHS, Expr *RHS) { + return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS); } /// \brief Build a new conditional operator expression. /// /// By default, performs semantic analysis to build the new expression. /// Subclasses may override this routine to provide different behavior. - OwningExprResult RebuildConditionalOperator(ExprArg Cond, + OwningExprResult RebuildConditionalOperator(Expr *Cond, SourceLocation QuestionLoc, - ExprArg LHS, + Expr *LHS, SourceLocation ColonLoc, - ExprArg RHS) { - return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, move(Cond), - move(LHS), move(RHS)); + Expr *RHS) { + return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond, + LHS, RHS); } /// \brief Build a new C-style cast expression. @@ -1222,9 +1212,9 @@ public: OwningExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc, TypeSourceInfo *TInfo, SourceLocation RParenLoc, - ExprArg SubExpr) { + Expr *SubExpr) { return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc, - move(SubExpr)); + SubExpr); } /// \brief Build a new compound literal expression. @@ -1234,24 +1224,23 @@ public: OwningExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc, TypeSourceInfo *TInfo, SourceLocation RParenLoc, - ExprArg Init) { + Expr *Init) { return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc, - move(Init)); + Init); } /// \brief Build a new extended vector element access expression. /// /// By default, performs semantic analysis to build the new expression. /// Subclasses may override this routine to provide different behavior. - OwningExprResult RebuildExtVectorElementExpr(ExprArg Base, + OwningExprResult RebuildExtVectorElementExpr(Expr *Base, SourceLocation OpLoc, SourceLocation AccessorLoc, IdentifierInfo &Accessor) { CXXScopeSpec SS; - QualType BaseType = ((Expr*) Base.get())->getType(); DeclarationNameInfo NameInfo(&Accessor, AccessorLoc); - return getSema().BuildMemberReferenceExpr(move(Base), BaseType, + return getSema().BuildMemberReferenceExpr(Base, Base->getType(), OpLoc, /*IsArrow*/ false, SS, /*FirstQualifierInScope*/ 0, NameInfo, @@ -1286,10 +1275,10 @@ public: MultiExprArg ArrayExprs, SourceLocation EqualOrColonLoc, bool GNUSyntax, - ExprArg Init) { + Expr *Init) { OwningExprResult Result = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax, - move(Init)); + Init); if (Result.isInvalid()) return SemaRef.ExprError(); @@ -1311,10 +1300,10 @@ public: /// By default, performs semantic analysis to build the new expression. /// Subclasses may override this routine to provide different behavior. OwningExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, - ExprArg SubExpr, TypeSourceInfo *TInfo, + Expr *SubExpr, TypeSourceInfo *TInfo, SourceLocation RParenLoc) { return getSema().BuildVAArgExpr(BuiltinLoc, - move(SubExpr), TInfo, + SubExpr, TInfo, RParenLoc); } @@ -1345,9 +1334,9 @@ public: /// By default, performs semantic analysis to build the new expression. /// Subclasses may override this routine to provide different behavior. OwningExprResult RebuildStmtExpr(SourceLocation LParenLoc, - StmtArg SubStmt, + Stmt *SubStmt, SourceLocation RParenLoc) { - return getSema().ActOnStmtExpr(LParenLoc, move(SubStmt), RParenLoc); + return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc); } /// \brief Build a new __builtin_types_compatible_p expression. @@ -1368,10 +1357,10 @@ public: /// By default, performs semantic analysis to build the new expression. /// Subclasses may override this routine to provide different behavior. OwningExprResult RebuildChooseExpr(SourceLocation BuiltinLoc, - ExprArg Cond, ExprArg LHS, ExprArg RHS, + Expr *Cond, Expr *LHS, Expr *RHS, SourceLocation RParenLoc) { return SemaRef.ActOnChooseExpr(BuiltinLoc, - move(Cond), move(LHS), move(RHS), + Cond, LHS, RHS, RParenLoc); } @@ -1385,9 +1374,9 @@ public: /// provide different behavior. OwningExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, SourceLocation OpLoc, - ExprArg Callee, - ExprArg First, - ExprArg Second); + Expr *Callee, + Expr *First, + Expr *Second); /// \brief Build a new C++ "named" cast expression, such as static_cast or /// reinterpret_cast. @@ -1401,29 +1390,29 @@ public: TypeSourceInfo *TInfo, SourceLocation RAngleLoc, SourceLocation LParenLoc, - ExprArg SubExpr, + Expr *SubExpr, SourceLocation RParenLoc) { switch (Class) { case Stmt::CXXStaticCastExprClass: return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo, RAngleLoc, LParenLoc, - move(SubExpr), RParenLoc); + SubExpr, RParenLoc); case Stmt::CXXDynamicCastExprClass: return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo, RAngleLoc, LParenLoc, - move(SubExpr), RParenLoc); + SubExpr, RParenLoc); case Stmt::CXXReinterpretCastExprClass: return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo, RAngleLoc, LParenLoc, - move(SubExpr), + SubExpr, RParenLoc); case Stmt::CXXConstCastExprClass: return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo, RAngleLoc, LParenLoc, - move(SubExpr), RParenLoc); + SubExpr, RParenLoc); default: assert(false && "Invalid C++ named cast"); @@ -1442,10 +1431,10 @@ public: TypeSourceInfo *TInfo, SourceLocation RAngleLoc, SourceLocation LParenLoc, - ExprArg SubExpr, + Expr *SubExpr, SourceLocation RParenLoc) { return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast, - TInfo, move(SubExpr), + TInfo, SubExpr, SourceRange(LAngleLoc, RAngleLoc), SourceRange(LParenLoc, RParenLoc)); } @@ -1459,10 +1448,10 @@ public: TypeSourceInfo *TInfo, SourceLocation RAngleLoc, SourceLocation LParenLoc, - ExprArg SubExpr, + Expr *SubExpr, SourceLocation RParenLoc) { return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast, - TInfo, move(SubExpr), + TInfo, SubExpr, SourceRange(LAngleLoc, RAngleLoc), SourceRange(LParenLoc, RParenLoc)); } @@ -1476,10 +1465,10 @@ public: TypeSourceInfo *TInfo, SourceLocation RAngleLoc, SourceLocation LParenLoc, - ExprArg SubExpr, + Expr *SubExpr, SourceLocation RParenLoc) { return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast, - TInfo, move(SubExpr), + TInfo, SubExpr, SourceRange(LAngleLoc, RAngleLoc), SourceRange(LParenLoc, RParenLoc)); } @@ -1493,10 +1482,10 @@ public: TypeSourceInfo *TInfo, SourceLocation RAngleLoc, SourceLocation LParenLoc, - ExprArg SubExpr, + Expr *SubExpr, SourceLocation RParenLoc) { return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast, - TInfo, move(SubExpr), + TInfo, SubExpr, SourceRange(LAngleLoc, RAngleLoc), SourceRange(LParenLoc, RParenLoc)); } @@ -1508,9 +1497,8 @@ public: OwningExprResult RebuildCXXFunctionalCastExpr(SourceRange TypeRange, TypeSourceInfo *TInfo, SourceLocation LParenLoc, - ExprArg SubExpr, + Expr *Sub, SourceLocation RParenLoc) { - Expr *Sub = SubExpr.get(); return getSema().ActOnCXXTypeConstructExpr(TypeRange, TInfo->getType().getAsOpaquePtr(), LParenLoc, @@ -1537,9 +1525,9 @@ public: /// Subclasses may override this routine to provide different behavior. OwningExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, SourceLocation TypeidLoc, - ExprArg Operand, + Expr *Operand, SourceLocation RParenLoc) { - return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, move(Operand), + return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand, RParenLoc); } @@ -1560,8 +1548,8 @@ public: /// /// By default, performs semantic analysis to build the new expression. /// Subclasses may override this routine to provide different behavior. - OwningExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, ExprArg Sub) { - return getSema().ActOnCXXThrow(ThrowLoc, move(Sub)); + OwningExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub) { + return getSema().ActOnCXXThrow(ThrowLoc, Sub); } /// \brief Build a new C++ default-argument expression. @@ -1602,7 +1590,7 @@ public: QualType AllocType, SourceLocation TypeLoc, SourceRange TypeRange, - ExprArg ArraySize, + Expr *ArraySize, SourceLocation ConstructorLParen, MultiExprArg ConstructorArgs, SourceLocation ConstructorRParen) { @@ -1614,7 +1602,7 @@ public: AllocType, TypeLoc, TypeRange, - move(ArraySize), + ArraySize, ConstructorLParen, move(ConstructorArgs), ConstructorRParen); @@ -1627,9 +1615,9 @@ public: OwningExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc, bool IsGlobalDelete, bool IsArrayForm, - ExprArg Operand) { + Expr *Operand) { return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm, - move(Operand)); + Operand); } /// \brief Build a new unary type trait expression. @@ -1738,7 +1726,7 @@ public: /// /// By default, performs semantic analysis to build the new expression. /// Subclasses may override this routine to provide different behavior. - OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE, + OwningExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE, QualType BaseType, bool IsArrow, SourceLocation OperatorLoc, @@ -1751,7 +1739,7 @@ public: SS.setRange(QualifierRange); SS.setScopeRep(Qualifier); - return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType, + return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType, OperatorLoc, IsArrow, SS, FirstQualifierInScope, MemberNameInfo, @@ -1762,7 +1750,7 @@ public: /// /// By default, performs semantic analysis to build the new expression. /// Subclasses may override this routine to provide different behavior. - OwningExprResult RebuildUnresolvedMemberExpr(ExprArg BaseE, + OwningExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType, SourceLocation OperatorLoc, bool IsArrow, @@ -1775,7 +1763,7 @@ public: SS.setRange(QualifierRange); SS.setScopeRep(Qualifier); - return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType, + return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType, OperatorLoc, IsArrow, SS, FirstQualifierInScope, R, TemplateArgs); @@ -1807,15 +1795,14 @@ public: } /// \brief Build a new Objective-C instance message. - OwningExprResult RebuildObjCMessageExpr(ExprArg Receiver, + OwningExprResult RebuildObjCMessageExpr(Expr *Receiver, Selector Sel, ObjCMethodDecl *Method, SourceLocation LBracLoc, MultiExprArg Args, SourceLocation RBracLoc) { - QualType ReceiverType = static_cast(Receiver.get())->getType(); - return SemaRef.BuildInstanceMessage(move(Receiver), - ReceiverType, + return SemaRef.BuildInstanceMessage(Receiver, + Receiver->getType(), /*SuperLoc=*/SourceLocation(), Sel, Method, LBracLoc, RBracLoc, move(Args)); @@ -1825,12 +1812,12 @@ public: /// /// By default, performs semantic analysis to build the new expression. /// Subclasses may override this routine to provide different behavior. - OwningExprResult RebuildObjCIvarRefExpr(ExprArg BaseArg, ObjCIvarDecl *Ivar, + OwningExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar, SourceLocation IvarLoc, bool IsArrow, bool IsFreeIvar) { // FIXME: We lose track of the IsFreeIvar bit. CXXScopeSpec SS; - Expr *Base = BaseArg.takeAs(); + Expr *Base = BaseArg; LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc, Sema::LookupMemberName); OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, @@ -1843,8 +1830,7 @@ public: if (Result.get()) return move(Result); - return getSema().BuildMemberReferenceExpr(getSema().Owned(Base), - Base->getType(), + return getSema().BuildMemberReferenceExpr(Base, Base->getType(), /*FIXME:*/IvarLoc, IsArrow, SS, /*FirstQualifierInScope=*/0, R, @@ -1855,11 +1841,11 @@ public: /// /// By default, performs semantic analysis to build the new expression. /// Subclasses may override this routine to provide different behavior. - OwningExprResult RebuildObjCPropertyRefExpr(ExprArg BaseArg, + OwningExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg, ObjCPropertyDecl *Property, SourceLocation PropertyLoc) { CXXScopeSpec SS; - Expr *Base = BaseArg.takeAs(); + Expr *Base = BaseArg; LookupResult R(getSema(), Property->getDeclName(), PropertyLoc, Sema::LookupMemberName); bool IsArrow = false; @@ -1872,8 +1858,7 @@ public: if (Result.get()) return move(Result); - return getSema().BuildMemberReferenceExpr(getSema().Owned(Base), - Base->getType(), + return getSema().BuildMemberReferenceExpr(Base, Base->getType(), /*FIXME:*/PropertyLoc, IsArrow, SS, /*FirstQualifierInScope=*/0, @@ -1891,24 +1876,24 @@ public: QualType T, ObjCMethodDecl *Setter, SourceLocation NameLoc, - ExprArg Base) { + Expr *Base) { // Since these expressions can only be value-dependent, we do not need to // perform semantic analysis again. - return getSema().Owned( + return Owned( new (getSema().Context) ObjCImplicitSetterGetterRefExpr(Getter, T, Setter, NameLoc, - Base.takeAs())); + Base)); } /// \brief Build a new Objective-C "isa" expression. /// /// By default, performs semantic analysis to build the new expression. /// Subclasses may override this routine to provide different behavior. - OwningExprResult RebuildObjCIsaExpr(ExprArg BaseArg, SourceLocation IsaLoc, + OwningExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc, bool IsArrow) { CXXScopeSpec SS; - Expr *Base = BaseArg.takeAs(); + Expr *Base = BaseArg; LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc, Sema::LookupMemberName); OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, @@ -1920,8 +1905,7 @@ public: if (Result.get()) return move(Result); - return getSema().BuildMemberReferenceExpr(getSema().Owned(Base), - Base->getType(), + return getSema().BuildMemberReferenceExpr(Base, Base->getType(), /*FIXME:*/IsaLoc, IsArrow, SS, /*FirstQualifierInScope=*/0, R, @@ -1992,7 +1976,7 @@ Sema::OwningStmtResult TreeTransform::TransformStmt(Stmt *S) { if (E.isInvalid()) return getSema().StmtError(); - return getSema().ActOnExprStmt(getSema().MakeFullExpr(E)); + return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take())); } } @@ -2290,12 +2274,7 @@ bool TreeTransform::TransformTemplateArgument( EnterExpressionEvaluationContext Unevaluated(getSema(), Action::Unevaluated); Sema::OwningExprResult E = getDerived().TransformExpr(SourceExpr); - if (E.isInvalid()) - SourceExpr = NULL; - else { - SourceExpr = E.takeAs(); - SourceExpr->Retain(); - } + SourceExpr = (E.isInvalid() ? 0 : E.take()); } Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr); @@ -2326,10 +2305,7 @@ bool TreeTransform::TransformTemplateArgument( Sema::OwningExprResult E = getDerived().TransformExpr(InputExpr); if (E.isInvalid()) return true; - - Expr *ETaken = E.takeAs(); - ETaken->Retain(); - Output = TemplateArgumentLoc(TemplateArgument(ETaken), ETaken); + Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take()); return false; } @@ -2706,7 +2682,7 @@ TreeTransform::TransformVariableArrayType(TypeLocBuilder &TLB, if (SizeResult.isInvalid()) return QualType(); - Expr *Size = static_cast(SizeResult.get()); + Expr *Size = SizeResult.take(); QualType Result = TL.getType(); if (getDerived().AlwaysRebuild() || @@ -2714,13 +2690,12 @@ TreeTransform::TransformVariableArrayType(TypeLocBuilder &TLB, Size != T->getSizeExpr()) { Result = getDerived().RebuildVariableArrayType(ElementType, T->getSizeModifier(), - move(SizeResult), + Size, T->getIndexTypeCVRQualifiers(), TL.getBracketsRange()); if (Result.isNull()) return QualType(); } - else SizeResult.take(); VariableArrayTypeLoc NewTL = TLB.push(Result); NewTL.setLBracketLoc(TL.getLBracketLoc()); @@ -2756,7 +2731,7 @@ TreeTransform::TransformDependentSizedArrayType(TypeLocBuilder &TLB, Size != T->getSizeExpr()) { Result = getDerived().RebuildDependentSizedArrayType(ElementType, T->getSizeModifier(), - move(SizeResult), + Size, T->getIndexTypeCVRQualifiers(), TL.getBracketsRange()); if (Result.isNull()) @@ -2798,12 +2773,11 @@ QualType TreeTransform::TransformDependentSizedExtVectorType( ElementType != T->getElementType() || Size.get() != T->getSizeExpr()) { Result = getDerived().RebuildDependentSizedExtVectorType(ElementType, - move(Size), + Size.take(), T->getAttributeLoc()); if (Result.isNull()) return QualType(); } - else Size.take(); // Result might be dependent or not. if (isa(Result)) { @@ -3052,7 +3026,7 @@ QualType TreeTransform::TransformTypeOfExprType(TypeLocBuilder &TLB, QualType Result = TL.getType(); if (getDerived().AlwaysRebuild() || E.get() != TL.getUnderlyingExpr()) { - Result = getDerived().RebuildTypeOfExprType(move(E)); + Result = getDerived().RebuildTypeOfExprType(E.get()); if (Result.isNull()) return QualType(); } @@ -3107,7 +3081,7 @@ QualType TreeTransform::TransformDecltypeType(TypeLocBuilder &TLB, QualType Result = TL.getType(); if (getDerived().AlwaysRebuild() || E.get() != T->getUnderlyingExpr()) { - Result = getDerived().RebuildDecltypeType(move(E)); + Result = getDerived().RebuildDecltypeType(E.get()); if (Result.isNull()) return QualType(); } @@ -3513,9 +3487,9 @@ TreeTransform::TransformCaseStmt(CaseStmt *S) { // Case statements are always rebuilt so that they will attached to their // transformed switch statement. OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(), - move(LHS), + LHS.get(), S->getEllipsisLoc(), - move(RHS), + RHS.get(), S->getColonLoc()); if (Case.isInvalid()) return SemaRef.StmtError(); @@ -3526,7 +3500,7 @@ TreeTransform::TransformCaseStmt(CaseStmt *S) { return SemaRef.StmtError(); // Attach the body to the case statement - return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt)); + return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get()); } template @@ -3539,7 +3513,7 @@ TreeTransform::TransformDefaultStmt(DefaultStmt *S) { // Default statements are always rebuilt return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(), - move(SubStmt)); + SubStmt.get()); } template @@ -3552,7 +3526,7 @@ TreeTransform::TransformLabelStmt(LabelStmt *S) { // FIXME: Pass the real colon location in. SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc()); return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc, - move(SubStmt)); + SubStmt.get()); } template @@ -3579,16 +3553,16 @@ TreeTransform::TransformIfStmt(IfStmt *S) { if (S->getCond()) { OwningExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(), - move(Cond)); + Cond.get()); if (CondE.isInvalid()) return getSema().StmtError(); - Cond = move(CondE); + Cond = CondE.get(); } } - Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond)); - if (!S->getConditionVariable() && S->getCond() && !FullCond->get()) + Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take())); + if (!S->getConditionVariable() && S->getCond() && !FullCond.get()) return SemaRef.StmtError(); // Transform the "then" branch. @@ -3602,15 +3576,15 @@ TreeTransform::TransformIfStmt(IfStmt *S) { return SemaRef.StmtError(); if (!getDerived().AlwaysRebuild() && - FullCond->get() == S->getCond() && + FullCond.get() == S->getCond() && ConditionVar == S->getConditionVariable() && Then.get() == S->getThen() && Else.get() == S->getElse()) return SemaRef.Owned(S->Retain()); return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar, - move(Then), - S->getElseLoc(), move(Else)); + Then.get(), + S->getElseLoc(), Else.get()); } template @@ -3636,7 +3610,7 @@ TreeTransform::TransformSwitchStmt(SwitchStmt *S) { // Rebuild the switch statement. OwningStmtResult Switch - = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), move(Cond), + = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(), ConditionVar); if (Switch.isInvalid()) return SemaRef.StmtError(); @@ -3647,8 +3621,8 @@ TreeTransform::TransformSwitchStmt(SwitchStmt *S) { return SemaRef.StmtError(); // Complete the switch statement. - return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch), - move(Body)); + return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(), + Body.get()); } template @@ -3675,15 +3649,15 @@ TreeTransform::TransformWhileStmt(WhileStmt *S) { // Convert the condition to a boolean value. OwningExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(), - move(Cond)); + Cond.get()); if (CondE.isInvalid()) return getSema().StmtError(); - Cond = move(CondE); + Cond = CondE; } } - Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond)); - if (!S->getConditionVariable() && S->getCond() && !FullCond->get()) + Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take())); + if (!S->getConditionVariable() && S->getCond() && !FullCond.get()) return SemaRef.StmtError(); // Transform the body @@ -3692,13 +3666,13 @@ TreeTransform::TransformWhileStmt(WhileStmt *S) { return SemaRef.StmtError(); if (!getDerived().AlwaysRebuild() && - FullCond->get() == S->getCond() && + FullCond.get() == S->getCond() && ConditionVar == S->getConditionVariable() && Body.get() == S->getBody()) - return SemaRef.Owned(S->Retain()); + return Owned(S); return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, - ConditionVar, move(Body)); + ConditionVar, Body.get()); } template @@ -3719,8 +3693,8 @@ TreeTransform::TransformDoStmt(DoStmt *S) { Body.get() == S->getBody()) return SemaRef.Owned(S->Retain()); - return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(), - /*FIXME:*/S->getWhileLoc(), move(Cond), + return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(), + /*FIXME:*/S->getWhileLoc(), Cond.get(), S->getRParenLoc()); } @@ -3753,16 +3727,16 @@ TreeTransform::TransformForStmt(ForStmt *S) { // Convert the condition to a boolean value. OwningExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(), - move(Cond)); + Cond.get()); if (CondE.isInvalid()) return getSema().StmtError(); - Cond = move(CondE); + Cond = CondE.get(); } } - Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond)); - if (!S->getConditionVariable() && S->getCond() && !FullCond->get()) + Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take())); + if (!S->getConditionVariable() && S->getCond() && !FullCond.get()) return SemaRef.StmtError(); // Transform the increment @@ -3770,8 +3744,8 @@ TreeTransform::TransformForStmt(ForStmt *S) { if (Inc.isInvalid()) return SemaRef.StmtError(); - Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc)); - if (S->getInc() && !FullInc->get()) + Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get())); + if (S->getInc() && !FullInc.get()) return SemaRef.StmtError(); // Transform the body @@ -3781,14 +3755,14 @@ TreeTransform::TransformForStmt(ForStmt *S) { if (!getDerived().AlwaysRebuild() && Init.get() == S->getInit() && - FullCond->get() == S->getCond() && + FullCond.get() == S->getCond() && Inc.get() == S->getInc() && Body.get() == S->getBody()) return SemaRef.Owned(S->Retain()); return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(), - move(Init), FullCond, ConditionVar, - FullInc, S->getRParenLoc(), move(Body)); + Init.get(), FullCond, ConditionVar, + FullInc, S->getRParenLoc(), Body.get()); } template @@ -3811,7 +3785,7 @@ TreeTransform::TransformIndirectGotoStmt(IndirectGotoStmt *S) { return SemaRef.Owned(S->Retain()); return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(), - move(Target)); + Target.get()); } template @@ -3835,7 +3809,7 @@ TreeTransform::TransformReturnStmt(ReturnStmt *S) { // FIXME: We always rebuild the return statement because there is no way // to tell whether the return type of the function has changed. - return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result)); + return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get()); } template @@ -3898,7 +3872,7 @@ TreeTransform::TransformAsmStmt(AsmStmt *S) { ExprsChanged |= Result.get() != OutputExpr; - Exprs.push_back(Result.takeAs()); + Exprs.push_back(Result.get()); } // Go through the inputs. @@ -3916,7 +3890,7 @@ TreeTransform::TransformAsmStmt(AsmStmt *S) { ExprsChanged |= Result.get() != InputExpr; - Exprs.push_back(Result.takeAs()); + Exprs.push_back(Result.get()); } if (!getDerived().AlwaysRebuild() && !ExprsChanged) @@ -3937,7 +3911,7 @@ TreeTransform::TransformAsmStmt(AsmStmt *S) { Names.data(), move_arg(Constraints), move_arg(Exprs), - move(AsmString), + AsmString.get(), move_arg(Clobbers), S->getRParenLoc(), S->isMSAsm()); @@ -3980,8 +3954,8 @@ TreeTransform::TransformObjCAtTryStmt(ObjCAtTryStmt *S) { return SemaRef.Owned(S->Retain()); // Build a new statement. - return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), move(TryBody), - move_arg(CatchStmts), move(Finally)); + return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(), + move_arg(CatchStmts), Finally.get()); } template @@ -4017,7 +3991,7 @@ TreeTransform::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) { return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(), S->getRParenLoc(), - Var, move(Body)); + Var, Body.get()); } template @@ -4035,7 +4009,7 @@ TreeTransform::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { // Build a new statement. return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(), - move(Body)); + Body.get()); } template @@ -4052,7 +4026,7 @@ TreeTransform::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) { Operand.get() == S->getThrowExpr()) return getSema().Owned(S->Retain()); - return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), move(Operand)); + return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get()); } template @@ -4077,7 +4051,7 @@ TreeTransform::TransformObjCAtSynchronizedStmt( // Build a new statement. return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(), - move(Object), move(Body)); + Object.get(), Body.get()); } template @@ -4109,10 +4083,10 @@ TreeTransform::TransformObjCForCollectionStmt( // Build a new statement. return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(), /*FIXME:*/S->getForLoc(), - move(Element), - move(Collection), + Element.get(), + Collection.get(), S->getRParenLoc(), - move(Body)); + Body.get()); } @@ -4153,7 +4127,7 @@ TreeTransform::TransformCXXCatchStmt(CXXCatchStmt *S) { return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, - move(Handler)); + Handler.get()); } template @@ -4183,7 +4157,7 @@ TreeTransform::TransformCXXTryStmt(CXXTryStmt *S) { !HandlerChanged) return SemaRef.Owned(S->Retain()); - return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock), + return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(), move_arg(Handlers)); } @@ -4290,7 +4264,7 @@ TreeTransform::TransformParenExpr(ParenExpr *E) { if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) return SemaRef.Owned(E->Retain()); - return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(), + return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(), E->getRParen()); } @@ -4306,7 +4280,7 @@ TreeTransform::TransformUnaryOperator(UnaryOperator *E) { return getDerived().RebuildUnaryOperator(E->getOperatorLoc(), E->getOpcode(), - move(SubExpr)); + SubExpr.get()); } template @@ -4342,7 +4316,7 @@ TreeTransform::TransformOffsetOfExpr(OffsetOfExpr *E) { ExprChanged = ExprChanged || Index.get() != FromIndex; Comp.isBrackets = true; - Comp.U.E = Index.takeAs(); // FIXME: leaked + Comp.U.E = Index.get(); break; } @@ -4408,7 +4382,7 @@ TreeTransform::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) { return SemaRef.Owned(E->Retain()); } - return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(), + return getDerived().RebuildSizeOfAlignOf(SubExpr.get(), E->getOperatorLoc(), E->isSizeOf(), E->getSourceRange()); } @@ -4430,9 +4404,9 @@ TreeTransform::TransformArraySubscriptExpr(ArraySubscriptExpr *E) { RHS.get() == E->getRHS()) return SemaRef.Owned(E->Retain()); - return getDerived().RebuildArraySubscriptExpr(move(LHS), + return getDerived().RebuildArraySubscriptExpr(LHS.get(), /*FIXME:*/E->getLHS()->getLocStart(), - move(RHS), + RHS.get(), E->getRBracketLoc()); } @@ -4458,7 +4432,7 @@ TreeTransform::TransformCallExpr(CallExpr *E) { SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd())); ArgChanged = ArgChanged || Arg.get() != E->getArg(I); - Args.push_back(Arg.takeAs()); + Args.push_back(Arg.get()); } if (!getDerived().AlwaysRebuild() && @@ -4469,7 +4443,7 @@ TreeTransform::TransformCallExpr(CallExpr *E) { // FIXME: Wrong source location information for the '('. SourceLocation FakeLParenLoc = ((Expr *)Callee.get())->getSourceRange().getBegin(); - return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc, + return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc, move_arg(Args), FakeCommaLocs.data(), E->getRParenLoc()); @@ -4542,7 +4516,7 @@ TreeTransform::TransformMemberExpr(MemberExpr *E) { // nested-name-qualifier (and therefore could do the lookup). NamedDecl *FirstQualifierInScope = 0; - return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc, + return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc, E->isArrow(), Qualifier, E->getQualifierRange(), @@ -4571,7 +4545,7 @@ TreeTransform::TransformBinaryOperator(BinaryOperator *E) { return SemaRef.Owned(E->Retain()); return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(), - move(LHS), move(RHS)); + LHS.get(), RHS.get()); } template @@ -4602,11 +4576,11 @@ TreeTransform::TransformConditionalOperator(ConditionalOperator *E) { RHS.get() == E->getRHS()) return SemaRef.Owned(E->Retain()); - return getDerived().RebuildConditionalOperator(move(Cond), + return getDerived().RebuildConditionalOperator(Cond.get(), E->getQuestionLoc(), - move(LHS), + LHS.get(), E->getColonLoc(), - move(RHS)); + RHS.get()); } template @@ -4647,7 +4621,7 @@ TreeTransform::TransformCStyleCastExpr(CStyleCastExpr *E) { return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(), NewT, E->getRParenLoc(), - move(SubExpr)); + SubExpr.get()); } template @@ -4673,7 +4647,7 @@ TreeTransform::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) { return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT, /*FIXME:*/E->getInitializer()->getLocEnd(), - move(Init)); + Init.get()); } template @@ -4690,7 +4664,7 @@ TreeTransform::TransformExtVectorElementExpr(ExtVectorElementExpr *E) { // FIXME: Bad source location SourceLocation FakeOperatorLoc = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd()); - return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc, + return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc, E->getAccessorLoc(), E->getAccessor()); } @@ -4707,7 +4681,7 @@ TreeTransform::TransformInitListExpr(InitListExpr *E) { return SemaRef.ExprError(); InitChanged = InitChanged || Init.get() != E->getInit(I); - Inits.push_back(Init.takeAs()); + Inits.push_back(Init.get()); } if (!getDerived().AlwaysRebuild() && !InitChanged) @@ -4782,7 +4756,7 @@ TreeTransform::TransformDesignatedInitExpr(DesignatedInitExpr *E) { return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs), E->getEqualOrColonLoc(), - E->usesGNUSyntax(), move(Init)); + E->usesGNUSyntax(), Init.get()); } template @@ -4820,7 +4794,7 @@ TreeTransform::TransformVAArgExpr(VAArgExpr *E) { SubExpr.get() == E->getSubExpr()) return SemaRef.Owned(E->Retain()); - return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr), + return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(), TInfo, E->getRParenLoc()); } @@ -4835,7 +4809,7 @@ TreeTransform::TransformParenListExpr(ParenListExpr *E) { return SemaRef.ExprError(); ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I); - Inits.push_back(Init.takeAs()); + Inits.push_back(Init.get()); } return getDerived().RebuildParenListExpr(E->getLParenLoc(), @@ -4868,7 +4842,7 @@ TreeTransform::TransformStmtExpr(StmtExpr *E) { return SemaRef.Owned(E->Retain()); return getDerived().RebuildStmtExpr(E->getLParenLoc(), - move(SubStmt), + SubStmt.get(), E->getRParenLoc()); } @@ -4918,7 +4892,7 @@ TreeTransform::TransformChooseExpr(ChooseExpr *E) { return SemaRef.Owned(E->Retain()); return getDerived().RebuildChooseExpr(E->getBuiltinLoc(), - move(Cond), move(LHS), move(RHS), + Cond.get(), LHS.get(), RHS.get(), E->getRParenLoc()); } @@ -4972,7 +4946,7 @@ TreeTransform::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) { Args.push_back(Arg.release()); } - return getDerived().RebuildCallExpr(move(Object), FakeLParenLoc, + return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc, move_arg(Args), FakeCommaLocs.data(), E->getLocEnd()); @@ -5019,9 +4993,9 @@ TreeTransform::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) { return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(), E->getOperatorLoc(), - move(Callee), - move(First), - move(Second)); + Callee.get(), + First.get(), + Second.get()); } template @@ -5070,7 +5044,7 @@ TreeTransform::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) { NewT, FakeRAngleLoc, FakeRAngleLoc, - move(SubExpr), + SubExpr.get(), FakeRParenLoc); } @@ -5129,7 +5103,7 @@ TreeTransform::TransformCXXFunctionalCastExpr( /*FIXME:*/SourceRange(E->getTypeBeginLoc()), NewT, /*FIXME:*/E->getSubExpr()->getLocStart(), - move(SubExpr), + SubExpr.get(), E->getRParenLoc()); } @@ -5168,7 +5142,7 @@ TreeTransform::TransformCXXTypeidExpr(CXXTypeidExpr *E) { return getDerived().RebuildCXXTypeidExpr(E->getType(), E->getLocStart(), - move(SubExpr), + SubExpr.get(), E->getLocEnd()); } @@ -5212,7 +5186,7 @@ TreeTransform::TransformCXXThrowExpr(CXXThrowExpr *E) { SubExpr.get() == E->getSubExpr()) return SemaRef.Owned(E->Retain()); - return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr)); + return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get()); } template @@ -5370,7 +5344,7 @@ TreeTransform::TransformCXXNewExpr(CXXNewExpr *E) { AllocType, /*FIXME:*/E->getLocStart(), /*FIXME:*/SourceRange(), - move(ArraySize), + ArraySize.get(), /*FIXME:*/E->getLocStart(), move_arg(ConstructorArgs), E->getLocEnd()); @@ -5406,7 +5380,7 @@ TreeTransform::TransformCXXDeleteExpr(CXXDeleteExpr *E) { return getDerived().RebuildCXXDeleteExpr(E->getLocStart(), E->isGlobalDelete(), E->isArrayForm(), - move(Operand)); + Operand.get()); } template @@ -5419,7 +5393,7 @@ TreeTransform::TransformCXXPseudoDestructorExpr( Sema::TypeTy *ObjectTypePtr = 0; bool MayBePseudoDestructor = false; - Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base), + Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(), E->getOperatorLoc(), E->isArrow()? tok::arrow : tok::period, ObjectTypePtr, @@ -5477,7 +5451,7 @@ TreeTransform::TransformCXXPseudoDestructorExpr( return SemaRef.ExprError(); } - return getDerived().RebuildCXXPseudoDestructorExpr(move(Base), + return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(), E->getOperatorLoc(), E->isArrow(), Qualifier, @@ -5674,7 +5648,7 @@ TreeTransform::TransformCXXConstructExpr(CXXConstructExpr *E) { return SemaRef.ExprError(); ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; - Args.push_back(TransArg.takeAs()); + Args.push_back(TransArg.get()); } if (!getDerived().AlwaysRebuild() && @@ -5807,7 +5781,7 @@ TreeTransform::TransformCXXUnresolvedConstructExpr( ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg; FakeCommaLocs.push_back( SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd())); - Args.push_back(TransArg.takeAs()); + Args.push_back(TransArg.get()); } if (!getDerived().AlwaysRebuild() && @@ -5842,7 +5816,7 @@ TreeTransform::TransformCXXDependentScopeMemberExpr( // Start the member reference and compute the object's type. Sema::TypeTy *ObjectTy = 0; bool MayBePseudoDestructor = false; - Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base), + Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(), E->getOperatorLoc(), E->isArrow()? tok::arrow : tok::period, ObjectTy, @@ -5892,7 +5866,7 @@ TreeTransform::TransformCXXDependentScopeMemberExpr( FirstQualifierInScope == E->getFirstQualifierFoundInScope()) return SemaRef.Owned(E->Retain()); - return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base), + return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(), BaseType, E->isArrow(), E->getOperatorLoc(), @@ -5911,7 +5885,7 @@ TreeTransform::TransformCXXDependentScopeMemberExpr( TransArgs.addArgument(Loc); } - return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base), + return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(), BaseType, E->isArrow(), E->getOperatorLoc(), @@ -6009,7 +5983,7 @@ TreeTransform::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) // nested-name-qualifier (and therefore could do the lookup). NamedDecl *FirstQualifierInScope = 0; - return getDerived().RebuildUnresolvedMemberExpr(move(Base), + return getDerived().RebuildUnresolvedMemberExpr(Base.get(), BaseType, Old->getOperatorLoc(), Old->isArrow(), @@ -6056,7 +6030,7 @@ TreeTransform::TransformObjCMessageExpr(ObjCMessageExpr *E) { return SemaRef.ExprError(); ArgChanged = ArgChanged || Arg.get() != E->getArg(I); - Args.push_back(Arg.takeAs()); + Args.push_back(Arg.get()); } if (E->getReceiverKind() == ObjCMessageExpr::Class) { @@ -6094,7 +6068,7 @@ TreeTransform::TransformObjCMessageExpr(ObjCMessageExpr *E) { return SemaRef.Owned(E->Retain()); // Build a new instance message send. - return getDerived().RebuildObjCMessageExpr(move(Receiver), + return getDerived().RebuildObjCMessageExpr(Receiver.get(), E->getSelector(), E->getMethodDecl(), E->getLeftLoc(), @@ -6129,7 +6103,7 @@ TreeTransform::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) { Base.get() == E->getBase()) return SemaRef.Owned(E->Retain()); - return getDerived().RebuildObjCIvarRefExpr(move(Base), E->getDecl(), + return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(), E->getLocation(), E->isArrow(), E->isFreeIvar()); } @@ -6149,7 +6123,7 @@ TreeTransform::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) { Base.get() == E->getBase()) return SemaRef.Owned(E->Retain()); - return getDerived().RebuildObjCPropertyRefExpr(move(Base), E->getProperty(), + return getDerived().RebuildObjCPropertyRefExpr(Base.get(), E->getProperty(), E->getLocation()); } @@ -6179,7 +6153,7 @@ TreeTransform::TransformObjCImplicitSetterGetterRefExpr( E->getType(), E->getSetterMethod(), E->getLocation(), - move(Base)); + Base.get()); } @@ -6203,7 +6177,7 @@ TreeTransform::TransformObjCIsaExpr(ObjCIsaExpr *E) { Base.get() == E->getBase()) return SemaRef.Owned(E->Retain()); - return getDerived().RebuildObjCIsaExpr(move(Base), E->getIsaMemberLoc(), + return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(), E->isArrow()); } @@ -6218,7 +6192,7 @@ TreeTransform::TransformShuffleVectorExpr(ShuffleVectorExpr *E) { return SemaRef.ExprError(); ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I); - SubExprs.push_back(SubExpr.takeAs()); + SubExprs.push_back(SubExpr.get()); } if (!getDerived().AlwaysRebuild() && @@ -6278,7 +6252,7 @@ TreeTransform::TransformBlockExpr(BlockExpr *E) { BExprFunctionType->getExtInfo()); CurBlock->FunctionType = FunctionType; - return SemaRef.ActOnBlockStmtExpr(CaretLoc, move(Body), /*Scope=*/0); + return SemaRef.ActOnBlockStmtExpr(CaretLoc, Body.get(), /*Scope=*/0); } template @@ -6399,11 +6373,11 @@ template QualType TreeTransform::RebuildVariableArrayType(QualType ElementType, ArrayType::ArraySizeModifier SizeMod, - ExprArg SizeExpr, + Expr *SizeExpr, unsigned IndexTypeQuals, SourceRange BracketsRange) { return getDerived().RebuildArrayType(ElementType, SizeMod, 0, - SizeExpr.takeAs(), + SizeExpr, IndexTypeQuals, BracketsRange); } @@ -6411,11 +6385,11 @@ template QualType TreeTransform::RebuildDependentSizedArrayType(QualType ElementType, ArrayType::ArraySizeModifier SizeMod, - ExprArg SizeExpr, + Expr *SizeExpr, unsigned IndexTypeQuals, SourceRange BracketsRange) { return getDerived().RebuildArrayType(ElementType, SizeMod, 0, - SizeExpr.takeAs(), + SizeExpr, IndexTypeQuals, BracketsRange); } @@ -6436,16 +6410,15 @@ QualType TreeTransform::RebuildExtVectorType(QualType ElementType, IntegerLiteral *VectorSize = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy, AttributeLoc); - return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize), - AttributeLoc); + return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc); } template QualType TreeTransform::RebuildDependentSizedExtVectorType(QualType ElementType, - ExprArg SizeExpr, + Expr *SizeExpr, SourceLocation AttributeLoc) { - return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc); + return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc); } template @@ -6493,8 +6466,8 @@ QualType TreeTransform::RebuildUnresolvedUsingType(Decl *D) { } template -QualType TreeTransform::RebuildTypeOfExprType(ExprArg E) { - return SemaRef.BuildTypeofExprType(E.takeAs()); +QualType TreeTransform::RebuildTypeOfExprType(Expr *E) { + return SemaRef.BuildTypeofExprType(E); } template @@ -6503,8 +6476,8 @@ QualType TreeTransform::RebuildTypeOfType(QualType Underlying) { } template -QualType TreeTransform::RebuildDecltypeType(ExprArg E) { - return SemaRef.BuildDecltypeType(E.takeAs()); +QualType TreeTransform::RebuildDecltypeType(Expr *E) { + return SemaRef.BuildDecltypeType(E); } template @@ -6616,46 +6589,42 @@ template Sema::OwningExprResult TreeTransform::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, SourceLocation OpLoc, - ExprArg Callee, - ExprArg First, - ExprArg Second) { - Expr *FirstExpr = (Expr *)First.get(); - Expr *SecondExpr = (Expr *)Second.get(); - Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts(); - bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus); + Expr *OrigCallee, + Expr *First, + Expr *Second) { + Expr *Callee = OrigCallee->IgnoreParenCasts(); + bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus); // Determine whether this should be a builtin operation. if (Op == OO_Subscript) { - if (!FirstExpr->getType()->isOverloadableType() && - !SecondExpr->getType()->isOverloadableType()) - return getSema().CreateBuiltinArraySubscriptExpr(move(First), - CalleeExpr->getLocStart(), - move(Second), OpLoc); + if (!First->getType()->isOverloadableType() && + !Second->getType()->isOverloadableType()) + return getSema().CreateBuiltinArraySubscriptExpr(First, + Callee->getLocStart(), + Second, OpLoc); } else if (Op == OO_Arrow) { // -> is never a builtin operation. - return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc); - } else if (SecondExpr == 0 || isPostIncDec) { - if (!FirstExpr->getType()->isOverloadableType()) { + return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc); + } else if (Second == 0 || isPostIncDec) { + if (!First->getType()->isOverloadableType()) { // The argument is not of overloadable type, so try to create a // built-in unary operation. UnaryOperator::Opcode Opc = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); - return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First)); + return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First); } } else { - if (!FirstExpr->getType()->isOverloadableType() && - !SecondExpr->getType()->isOverloadableType()) { + if (!First->getType()->isOverloadableType() && + !Second->getType()->isOverloadableType()) { // Neither of the arguments is an overloadable type, so try to // create a built-in binary operation. BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op); OwningExprResult Result - = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr); + = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second); if (Result.isInvalid()) return SemaRef.ExprError(); - First.release(); - Second.release(); return move(Result); } } @@ -6664,32 +6633,32 @@ TreeTransform::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, // used during overload resolution. UnresolvedSet<16> Functions; - if (UnresolvedLookupExpr *ULE = dyn_cast(CalleeExpr)) { + if (UnresolvedLookupExpr *ULE = dyn_cast(Callee)) { assert(ULE->requiresADL()); // FIXME: Do we have to check // IsAcceptableNonMemberOperatorCandidate for each of these? Functions.append(ULE->decls_begin(), ULE->decls_end()); } else { - Functions.addDecl(cast(CalleeExpr)->getDecl()); + Functions.addDecl(cast(Callee)->getDecl()); } // Add any functions found via argument-dependent lookup. - Expr *Args[2] = { FirstExpr, SecondExpr }; - unsigned NumArgs = 1 + (SecondExpr != 0); + Expr *Args[2] = { First, Second }; + unsigned NumArgs = 1 + (Second != 0); // Create the overloaded operator invocation for unary operators. if (NumArgs == 1 || isPostIncDec) { UnaryOperator::Opcode Opc = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); - return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First)); + return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First); } if (Op == OO_Subscript) - return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(), + return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(), OpLoc, - move(First), - move(Second)); + First, + Second); // Create the overloaded operator invocation for binary operators. BinaryOperator::Opcode Opc = @@ -6699,14 +6668,12 @@ TreeTransform::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, if (Result.isInvalid()) return SemaRef.ExprError(); - First.release(); - Second.release(); return move(Result); } template Sema::OwningExprResult -TreeTransform::RebuildCXXPseudoDestructorExpr(ExprArg Base, +TreeTransform::RebuildCXXPseudoDestructorExpr(Expr *Base, SourceLocation OperatorLoc, bool isArrow, NestedNameSpecifier *Qualifier, @@ -6721,15 +6688,14 @@ TreeTransform::RebuildCXXPseudoDestructorExpr(ExprArg Base, SS.setScopeRep(Qualifier); } - Expr *BaseE = (Expr *)Base.get(); - QualType BaseType = BaseE->getType(); - if (BaseE->isTypeDependent() || Destroyed.getIdentifier() || + QualType BaseType = Base->getType(); + if (Base->isTypeDependent() || Destroyed.getIdentifier() || (!isArrow && !BaseType->getAs()) || (isArrow && BaseType->getAs() && !BaseType->getAs()->getPointeeType() ->template getAs())){ // This pseudo-destructor expression is still a pseudo-destructor. - return SemaRef.BuildPseudoDestructorExpr(move(Base), OperatorLoc, + return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc, isArrow? tok::arrow : tok::period, SS, ScopeType, CCLoc, TildeLoc, Destroyed, @@ -6744,7 +6710,7 @@ TreeTransform::RebuildCXXPseudoDestructorExpr(ExprArg Base, // FIXME: the ScopeType should be tacked onto SS. - return getSema().BuildMemberReferenceExpr(move(Base), BaseType, + return getSema().BuildMemberReferenceExpr(Base, BaseType, OperatorLoc, isArrow, SS, /*FIXME: FirstQualifier*/ 0, NameInfo, -- 2.40.0