diff options
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<TemplateParameterList *, 4> 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<Stmt*> 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<Expr*> OwningExprResult; - typedef ASTOwningResult<Stmt*> 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<Expr*> ExprArg; - typedef ASTOwningPtr<Stmt*> StmtArg; + typedef Expr *ExprArg; + typedef Stmt *StmtArg; /// Multiple expressions or statements as arguments. typedef ASTMultiPtr<Expr*> 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<FullExprArg&>(Other).Expr)) {} - - FullExprArg &operator=(const FullExprArg& Other) { - Expr.operator=(move(const_cast<FullExprArg&>(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<typename T> - 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 <typename PtrTy> class ASTMultiPtr; - /// Kept only as a type-safe wrapper for a void pointer. - template <typename PtrTy> 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<PtrTy> &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<typename T> T *takeAs() { - return static_cast<T*>(Node); - } - - /// Alias for interface familiarity with unique_ptr. - PtrTy release() { - return take(); - } - }; - template <class PtrTy> class ASTOwningResult { public: typedef ActionBase::ActionResult<PtrTy> 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<PtrTy> &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<typename T> - T *takeAs() { - return static_cast<T*>(take()); - } + T *takeAs() { return static_cast<T*>(get()); } /// Alias for interface familiarity with unique_ptr. PtrTy release() { return take(); } @@ -497,18 +460,9 @@ namespace clang { return ASTMultiPtr<T>(vec.take(), vec.size()); } - template <class T> inline - ASTOwningPtr<T>::ASTOwningPtr(const ASTOwningResult<T> &o) - : Node(o.get()) { } - // These versions are hopefully no-ops. template <class T> inline - ASTOwningResult<T>& move(ASTOwningResult<T> &ptr) { - return ptr; - } - - template <class T> inline - ASTOwningPtr<T>& move(ASTOwningPtr<T> &ptr) { + ASTOwningResult<T> move(ASTOwningResult<T> &ptr) { return ptr; } @@ -541,6 +495,25 @@ namespace clang { typedef ActionBase::ActionResult<Decl*> DeclResult; typedef OpaquePtr<TemplateName> ParsedTemplateTy; + + typedef ASTOwningResult<Expr*> OwningExprResult; + typedef ASTOwningResult<Stmt*> OwningStmtResult; + + inline Expr *move(Expr *E) { return E; } + inline Stmt *move(Stmt *S) { return S; } + + typedef ASTMultiPtr<Expr*> MultiExprArg; + typedef ASTMultiPtr<TemplateParameterList*> 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 <typename T> -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<T*>(Action::ExprArg::get()); } - T* take() { return static_cast<T*>(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<prec::Level>(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); |