From effa8d1c97b00a3f53e972b0e61d9aade5ea1c57 Mon Sep 17 00:00:00 2001 From: Sebastian Redl Date: Wed, 10 Dec 2008 00:02:53 +0000 Subject: [PATCH] Modify the move emulation according to the excellent design of Howard Hinnant. Makes for much nicer syntax when smart pointers are used consistently. Also, start converting internal argument passing of Parser to smart pointers. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@60809 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Parse/Ownership.h | 208 ++++++++++++++++++-------------- include/clang/Parse/Parser.h | 4 +- lib/Parse/ParseDecl.cpp | 22 ++-- lib/Parse/ParseDeclCXX.cpp | 4 +- lib/Parse/ParseExpr.cpp | 146 +++++++++++----------- lib/Parse/ParseExprCXX.cpp | 27 +++-- lib/Parse/ParseInit.cpp | 13 +- lib/Parse/ParseObjc.cpp | 40 +++--- lib/Parse/ParsePragma.cpp | 2 +- lib/Parse/ParseStmt.cpp | 96 +++++++-------- lib/Parse/Parser.cpp | 20 +-- 11 files changed, 307 insertions(+), 275 deletions(-) diff --git a/include/clang/Parse/Ownership.h b/include/clang/Parse/Ownership.h index fc27605071..e2464ca8da 100644 --- a/include/clang/Parse/Ownership.h +++ b/include/clang/Parse/Ownership.h @@ -83,50 +83,49 @@ namespace clang /// the individual pointers, not the array holding them. template class ASTMultiPtr; - /// Move emulation helper for ASTOwningResult - template - class ASTResultMover - { - ASTOwningResult &Moved; + namespace moving { + /// Move emulation helper for ASTOwningResult. NEVER EVER use this class + /// directly if you don't know what you're doing. + template + class ASTResultMover + { + ASTOwningResult &Moved; - public: - ASTResultMover(ASTOwningResult &moved) : Moved(moved) {} + public: + ASTResultMover(ASTOwningResult &moved) : Moved(moved) {} - ASTOwningResult * operator ->() { return &Moved; } + ASTOwningResult * operator ->() { return &Moved; } + }; - // For the transition phase. - operator void*(); + /// Move emulation helper for ASTOwningPtr. NEVER EVER use this class + /// directly if you don't know what you're doing. + template + class ASTPtrMover + { + ASTOwningPtr &Moved; - // For the transition phase. - operator ActionBase::ActionResult::UID>(); - }; + public: + ASTPtrMover(ASTOwningPtr &moved) : Moved(moved) {} - /// Move emulation helper for ASTOwningPtr - template - class ASTPtrMover - { - ASTOwningPtr &Moved; - - public: - ASTPtrMover(ASTOwningPtr &moved) : Moved(moved) {} + ASTOwningPtr * operator ->() { return &Moved; } + }; - ASTOwningPtr * operator ->() { return &Moved; } + /// Move emulation helper for ASTMultiPtr. NEVER EVER use this class + /// directly if you don't know what you're doing. + template + class ASTMultiMover + { + ASTMultiPtr &Moved; - operator void*(); - }; + public: + ASTMultiMover(ASTMultiPtr &moved) : Moved(moved) {} - /// Move emulation helper for ASTMultiPtr - template - class ASTMultiMover - { - ASTMultiPtr &Moved; + ASTMultiPtr * operator ->() { return &Moved; } - public: - ASTMultiMover(ASTMultiPtr &moved) : Moved(moved) {} - - /// Reset the moved object's internal structures. - void release(); - }; + /// Reset the moved object's internal structures. + void release(); + }; + } template class ASTOwningResult @@ -135,11 +134,11 @@ namespace clang void *Node; bool Invalid; - friend class ASTResultMover; + friend class moving::ASTResultMover; friend class ASTOwningPtr; - ASTOwningResult(const ASTOwningResult&); // DO NOT IMPLEMENT - ASTOwningResult& operator =(const ASTOwningResult&); // DO NOT IMPLEMENT + ASTOwningResult(ASTOwningResult&); // DO NOT IMPLEMENT + ASTOwningResult& operator =(ASTOwningResult&); // DO NOT IMPLEMENT void destroy() { if (Node) { @@ -148,12 +147,6 @@ namespace clang } } - void * take() { - if (Invalid) - return 0; - return Node; - } - public: typedef ActionBase::ActionResult::UID> DumbResult; @@ -170,13 +163,13 @@ namespace clang ASTOwningResult(ActionBase &actions, const DumbResult &res) : Actions(&actions), Node(res.Val), Invalid(res.isInvalid) {} /// Move from another owning result - ASTOwningResult(ASTResultMover mover) + ASTOwningResult(moving::ASTResultMover mover) : Actions(mover->Actions), Node(mover->take()), Invalid(mover->Invalid) {} /// Move from an owning pointer - ASTOwningResult(ASTPtrMover mover); + ASTOwningResult(moving::ASTPtrMover mover); /// Move assignment from another owning result - ASTOwningResult & operator =(ASTResultMover mover) { + ASTOwningResult & operator =(moving::ASTResultMover mover) { Actions = mover->Actions; Node = mover->take(); Invalid = mover->Invalid; @@ -184,7 +177,7 @@ namespace clang } /// Move assignment from an owning ptr - ASTOwningResult & operator =(ASTPtrMover mover); + ASTOwningResult & operator =(moving::ASTPtrMover mover); /// Assignment from a raw pointer. Takes ownership - beware! ASTOwningResult & operator =(void *raw) @@ -214,9 +207,30 @@ namespace clang /// valid and non-null. bool isUsable() const { return !Invalid && Node; } + /// Take outside ownership of the raw pointer. + void * take() { + if (Invalid) + return 0; + void *tmp = Node; + Node = 0; + return tmp; + } + + /// Alias for interface familiarity with unique_ptr. + void * release() { + return take(); + } + + /// Pass ownership to a classical ActionResult. + DumbResult result() { + if (Invalid) + return true; + return Node; + } + /// Move hook - ASTResultMover move() { - return ASTResultMover(*this); + operator moving::ASTResultMover() { + return moving::ASTResultMover(*this); } }; @@ -226,11 +240,11 @@ namespace clang ActionBase *Actions; void *Node; - friend class ASTPtrMover; + friend class moving::ASTPtrMover; friend class ASTOwningResult; - ASTOwningPtr(const ASTOwningPtr&); // DO NOT IMPLEMENT - ASTOwningPtr& operator =(const ASTOwningPtr&); // DO NOT IMPLEMENT + ASTOwningPtr(ASTOwningPtr&); // DO NOT IMPLEMENT + ASTOwningPtr& operator =(ASTOwningPtr&); // DO NOT IMPLEMENT void destroy() { if (Node) { @@ -245,20 +259,20 @@ namespace clang ASTOwningPtr(ActionBase &actions, void *node) : Actions(&actions), Node(node) {} /// Move from another owning pointer - ASTOwningPtr(ASTPtrMover mover) + ASTOwningPtr(moving::ASTPtrMover mover) : Actions(mover->Actions), Node(mover->take()) {} /// Move from an owning result - ASTOwningPtr(ASTResultMover mover); + ASTOwningPtr(moving::ASTResultMover mover); /// Move assignment from another owning pointer - ASTOwningPtr & operator =(ASTPtrMover mover) { + ASTOwningPtr & operator =(moving::ASTPtrMover mover) { Actions = mover->Actions; Node = mover->take(); return *this; } /// Move assignment from an owning result - ASTOwningPtr & operator =(ASTResultMover mover); + ASTOwningPtr & operator =(moving::ASTResultMover mover); /// Assignment from a raw pointer. Takes ownership - beware! ASTOwningPtr & operator =(void *raw) @@ -271,9 +285,21 @@ namespace clang /// Access to the raw pointer. void * get() const { return Node; } + /// Release the raw pointer. + void * take() { + void *tmp = Node; + Node = 0; + return tmp; + } + + /// Alias for interface familiarity with unique_ptr. + void * release() { + return take(); + } + /// Move hook - ASTPtrMover move() { - return ASTPtrMover(*this); + operator moving::ASTPtrMover() { + return moving::ASTPtrMover(*this); } }; @@ -284,9 +310,9 @@ namespace clang void **Nodes; unsigned Count; - friend class ASTMultiMover; + friend class moving::ASTMultiMover; - ASTMultiPtr(const ASTMultiPtr&); // DO NOT IMPLEMENT + ASTMultiPtr(ASTMultiPtr&); // DO NOT IMPLEMENT // Reference member prevents copy assignment. void destroy() { @@ -303,15 +329,14 @@ namespace clang ASTMultiPtr(ActionBase &actions, void **nodes, unsigned count) : Actions(actions), Nodes(nodes), Count(count) {} /// Move constructor - ASTMultiPtr(ASTMultiMover mover) + ASTMultiPtr(moving::ASTMultiMover mover) : Actions(mover->Actions), Nodes(mover->Nodes), Count(mover->Count) { - mover->Nodes = 0; - mover->Count = 0; + mover.release(); } /// Move assignment - ASTMultiPtr & operator =(ASTMultiMover mover) { - Actions = mover->Actions; + ASTMultiPtr & operator =(moving::ASTMultiMover mover) { + destroy(); Nodes = mover->Nodes; Count = mover->Count; mover.release(); @@ -325,45 +350,27 @@ namespace clang unsigned size() const { return Count; } /// Move hook - ASTMultiMover move() { - return ASTMultiMover(*this); + operator moving::ASTMultiMover() { + return moving::ASTMultiMover(*this); } }; // Out-of-line implementations due to definition dependencies template inline - ASTResultMover::operator void*() { - return Moved.take(); - } - - template inline - ASTResultMover::operator - ActionBase::ActionResult::UID>() - { - if(Moved.isInvalid()) - return true; - return Moved.take(); - } - - template inline - ASTPtrMover::operator void*() { - return Moved.take(); - } - - template inline - void ASTMultiMover::release() { + void moving::ASTMultiMover::release() { Moved.Nodes = 0; Moved.Count = 0; } template inline - ASTOwningResult::ASTOwningResult(ASTPtrMover mover) + ASTOwningResult::ASTOwningResult( + moving::ASTPtrMover mover) : Actions(mover->Actions), Node(mover->take()), Invalid(false) {} template inline ASTOwningResult & - ASTOwningResult::operator =(ASTPtrMover mover) { + ASTOwningResult::operator =(moving::ASTPtrMover mover) { Actions = mover->Actions; Node = mover->take(); Invalid = false; @@ -371,17 +378,34 @@ namespace clang } template inline - ASTOwningPtr::ASTOwningPtr(ASTResultMover mover) + ASTOwningPtr::ASTOwningPtr(moving::ASTResultMover mover) : Actions(mover->Actions), Node(mover->take()) { } template inline ASTOwningPtr & - ASTOwningPtr::operator =(ASTResultMover mover) { + ASTOwningPtr::operator =(moving::ASTResultMover mover) { Actions = mover->Actions; Node = mover->take(); return *this; } + + // Move overloads. + + template inline + ASTOwningResult move(ASTOwningResult &ptr) { + return ASTOwningResult(moving::ASTResultMover(ptr)); + } + + template inline + ASTOwningPtr move(ASTOwningPtr &ptr) { + return ASTOwningPtr(moving::ASTPtrMover(ptr)); + } + + template inline + ASTMultiPtr move(ASTMultiPtr &ptr) { + return ASTMultiPtr(moving::ASTMultiMover(ptr)); + } } #endif diff --git a/include/clang/Parse/Parser.h b/include/clang/Parse/Parser.h index dedad120ba..ffd70a8971 100644 --- a/include/clang/Parse/Parser.h +++ b/include/clang/Parse/Parser.h @@ -379,8 +379,8 @@ private: DeclTy *ParseDeclarationOrFunctionDefinition(); DeclTy *ParseFunctionDefinition(Declarator &D); void ParseKNRParamDeclarations(Declarator &D); - ExprResult ParseSimpleAsm(); - ExprResult ParseAsmStringLiteral(); + OwningExprResult ParseSimpleAsm(); + OwningExprResult ParseAsmStringLiteral(); // Objective-C External Declarations DeclTy *ParseObjCAtDirectives(); diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp index 242c1b3c6f..e7f4fc92ea 100644 --- a/lib/Parse/ParseDecl.cpp +++ b/lib/Parse/ParseDecl.cpp @@ -132,7 +132,7 @@ AttributeList *Parser::ParseAttributes() { SkipUntil(tok::r_paren); break; } else { - ArgExprs.push_back(ArgExpr.move()); + ArgExprs.push_back(ArgExpr.release()); } if (Tok.isNot(tok::comma)) break; @@ -164,7 +164,7 @@ AttributeList *Parser::ParseAttributes() { SkipUntil(tok::r_paren); break; } else { - ArgExprs.push_back(ArgExpr.move()); + ArgExprs.push_back(ArgExpr.release()); } if (Tok.isNot(tok::comma)) break; @@ -270,13 +270,13 @@ ParseInitDeclaratorListAfterFirstDeclarator(Declarator &D) { while (1) { // If a simple-asm-expr is present, parse it. if (Tok.is(tok::kw_asm)) { - OwningExprResult AsmLabel(Actions, ParseSimpleAsm()); + OwningExprResult AsmLabel(ParseSimpleAsm()); if (AsmLabel.isInvalid()) { SkipUntil(tok::semi); return 0; } - D.setAsmLabel(AsmLabel.move()); + D.setAsmLabel(AsmLabel.release()); } // If attributes are present, parse them. @@ -294,7 +294,7 @@ ParseInitDeclaratorListAfterFirstDeclarator(Declarator &D) { SkipUntil(tok::semi); return 0; } - Actions.AddInitializerToDecl(LastDeclInGroup, Init.move()); + Actions.AddInitializerToDecl(LastDeclInGroup, Init.release()); } else if (Tok.is(tok::l_paren)) { // Parse C++ direct initializer: '(' expression-list ')' SourceLocation LParenLoc = ConsumeParen(); @@ -846,7 +846,7 @@ ParseStructDeclaration(DeclSpec &DS, if (Res.isInvalid()) SkipUntil(tok::semi, true, true); else - DeclaratorInfo.BitfieldSize = Res.move(); + DeclaratorInfo.BitfieldSize = Res.release(); } // If attributes exist after the declarator, parse them. @@ -1087,7 +1087,7 @@ void Parser::ParseEnumBody(SourceLocation StartLoc, DeclTy *EnumDecl) { LastEnumConstDecl, IdentLoc, Ident, EqualLoc, - AssignedVal.move()); + AssignedVal.release()); EnumConstantDecls.push_back(EnumConstDecl); LastEnumConstDecl = EnumConstDecl; @@ -1802,7 +1802,7 @@ void Parser::ParseFunctionDeclarator(SourceLocation LParenLoc, Declarator &D, } else { // Inform the actions module about the default argument Actions.ActOnParamDefaultArgument(Param, EqualLoc, - DefArgResult.move()); + DefArgResult.release()); } } @@ -1973,7 +1973,7 @@ void Parser::ParseBracketDeclarator(Declarator &D) { // Remember that we parsed a pointer type, and remember the type-quals. D.AddTypeInfo(DeclaratorChunk::getArray(DS.getTypeQualifiers(), StaticLoc.isValid(), isStar, - NumElements.move(), StartLoc)); + NumElements.release(), StartLoc)); } /// [GNU] typeof-specifier: @@ -2000,7 +2000,7 @@ void Parser::ParseTypeofSpecifier(DeclSpec &DS) { const char *PrevSpec = 0; // Check for duplicate type specifiers. if (DS.SetTypeSpecType(DeclSpec::TST_typeofExpr, StartLoc, PrevSpec, - Result.move())) + Result.release())) Diag(StartLoc, diag::err_invalid_decl_spec_combination) << PrevSpec; // FIXME: Not accurate, the range gets one token more than it should. @@ -2035,7 +2035,7 @@ void Parser::ParseTypeofSpecifier(DeclSpec &DS) { const char *PrevSpec = 0; // Check for duplicate type specifiers (e.g. "int typeof(int)"). if (DS.SetTypeSpecType(DeclSpec::TST_typeofExpr, StartLoc, PrevSpec, - Result.move())) + Result.release())) Diag(StartLoc, diag::err_invalid_decl_spec_combination) << PrevSpec; } DS.SetRangeEnd(RParenLoc); diff --git a/lib/Parse/ParseDeclCXX.cpp b/lib/Parse/ParseDeclCXX.cpp index 4b92c91863..c3b94bc628 100644 --- a/lib/Parse/ParseDeclCXX.cpp +++ b/lib/Parse/ParseDeclCXX.cpp @@ -529,8 +529,8 @@ Parser::DeclTy *Parser::ParseCXXClassMemberDeclaration(AccessSpecifier AS) { // See Sema::ActOnCXXMemberDeclarator for details. LastDeclInGroup = Actions.ActOnCXXMemberDeclarator(CurScope, AS, DeclaratorInfo, - BitfieldSize.move(), - Init.move(), + BitfieldSize.release(), + Init.release(), LastDeclInGroup); // If we don't have a comma, it is either the end of the list (a ';') diff --git a/lib/Parse/ParseExpr.cpp b/lib/Parse/ParseExpr.cpp index 9a8956c274..4cf7c1e4f7 100644 --- a/lib/Parse/ParseExpr.cpp +++ b/lib/Parse/ParseExpr.cpp @@ -174,9 +174,9 @@ Parser::ExprResult Parser::ParseExpression() { return ParseThrowExpression(); OwningExprResult LHS(Actions, ParseCastExpression(false)); - if (LHS.isInvalid()) return LHS.move(); + if (LHS.isInvalid()) return LHS.result(); - return ParseRHSOfBinaryExpression(LHS.move(), prec::Comma); + return ParseRHSOfBinaryExpression(LHS.result(), prec::Comma); } /// This routine is called when the '@' is seen and consumed. @@ -186,9 +186,9 @@ Parser::ExprResult Parser::ParseExpression() { /// Parser::ExprResult Parser::ParseExpressionWithLeadingAt(SourceLocation AtLoc) { OwningExprResult LHS(Actions, ParseObjCAtExpression(AtLoc)); - if (LHS.isInvalid()) return LHS.move(); + if (LHS.isInvalid()) return LHS.result(); - return ParseRHSOfBinaryExpression(LHS.move(), prec::Comma); + return ParseRHSOfBinaryExpression(LHS.result(), prec::Comma); } /// ParseAssignmentExpression - Parse an expr that doesn't include commas. @@ -198,9 +198,9 @@ Parser::ExprResult Parser::ParseAssignmentExpression() { return ParseThrowExpression(); OwningExprResult LHS(Actions, ParseCastExpression(false)); - if (LHS.isInvalid()) return LHS.move(); + if (LHS.isInvalid()) return LHS.result(); - return ParseRHSOfBinaryExpression(LHS.move(), prec::Assignment); + return ParseRHSOfBinaryExpression(LHS.result(), prec::Assignment); } /// ParseAssignmentExprWithObjCMessageExprStart - Parse an assignment expression @@ -219,18 +219,18 @@ Parser::ParseAssignmentExprWithObjCMessageExprStart(SourceLocation LBracLoc, OwningExprResult R(Actions, ParseObjCMessageExpressionBody(LBracLoc, NameLoc, ReceiverName, ReceiverExpr)); - if (R.isInvalid()) return R.move(); - R = ParsePostfixExpressionSuffix(R.move()); - if (R.isInvalid()) return R.move(); - return ParseRHSOfBinaryExpression(R.move(), 2); + if (R.isInvalid()) return R.result(); + R = ParsePostfixExpressionSuffix(R.result()); + if (R.isInvalid()) return R.result(); + return ParseRHSOfBinaryExpression(R.result(), 2); } Parser::ExprResult Parser::ParseConstantExpression() { OwningExprResult LHS(Actions, ParseCastExpression(false)); - if (LHS.isInvalid()) return LHS.move(); + if (LHS.isInvalid()) return LHS.result(); - return ParseRHSOfBinaryExpression(LHS.move(), prec::Conditional); + return ParseRHSOfBinaryExpression(LHS.result(), prec::Conditional); } /// ParseRHSOfBinaryExpression - Parse a binary expression that starts with @@ -246,7 +246,7 @@ Parser::ParseRHSOfBinaryExpression(ExprResult LHSArg, unsigned MinPrec) { // because we are called recursively, or because the token is not a binop), // then we are done! if (NextTokPrec < MinPrec) - return LHS.move(); + return LHS.result(); // Consume the operator, saving the operator token for error reporting. Token OpToken = Tok; @@ -262,7 +262,7 @@ Parser::ParseRHSOfBinaryExpression(ExprResult LHSArg, unsigned MinPrec) { // 'logical-OR-expression' as we might expect. TernaryMiddle = ParseExpression(); if (TernaryMiddle.isInvalid()) - return TernaryMiddle.move(); + return TernaryMiddle.result(); } else { // Special case handling of "X ? Y : Z" where Y is empty: // logical-OR-expression '?' ':' conditional-expression [GNU] @@ -283,7 +283,7 @@ Parser::ParseRHSOfBinaryExpression(ExprResult LHSArg, unsigned MinPrec) { // Parse another leaf here for the RHS of the operator. OwningExprResult RHS(Actions, ParseCastExpression(false)); if (RHS.isInvalid()) - return RHS.move(); + return RHS.result(); // Remember the precedence of this operator and get the precedence of the // operator immediately to the right of the RHS. @@ -303,9 +303,9 @@ Parser::ParseRHSOfBinaryExpression(ExprResult LHSArg, unsigned 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(RHS.move(), ThisPrec + !isRightAssoc); + RHS = ParseRHSOfBinaryExpression(RHS.result(), ThisPrec + !isRightAssoc); if (RHS.isInvalid()) - return RHS.move(); + return RHS.result(); NextTokPrec = getBinOpPrecedence(Tok.getKind()); } @@ -314,12 +314,13 @@ Parser::ParseRHSOfBinaryExpression(ExprResult LHSArg, unsigned MinPrec) { if (!LHS.isInvalid()) { // Combine the LHS and RHS into the LHS (e.g. build AST). if (TernaryMiddle.isInvalid()) - LHS = Actions.ActOnBinOp(CurScope, OpToken.getLocation(), - OpToken.getKind(), LHS.move(), RHS.move()); + LHS = Actions.ActOnBinOp(CurScope, OpToken.getLocation(), + OpToken.getKind(), LHS.release(), + RHS.release()); else LHS = Actions.ActOnConditionalOp(OpToken.getLocation(), ColonLoc, - LHS.move(), TernaryMiddle.move(), - RHS.move()); + LHS.release(), TernaryMiddle.release(), + RHS.release()); } } } @@ -443,7 +444,7 @@ Parser::ExprResult Parser::ParseCastExpression(bool isUnaryExpression) { SourceLocation LParenLoc = Tok.getLocation(); SourceLocation RParenLoc; Res = ParseParenExpression(ParenExprType, CastTy, RParenLoc); - if (Res.isInvalid()) return Res.move(); + if (Res.isInvalid()) return Res.result(); switch (ParenExprType) { case SimpleExpr: break; // Nothing else to do. @@ -458,12 +459,13 @@ Parser::ExprResult Parser::ParseCastExpression(bool isUnaryExpression) { // TODO: For cast expression with CastTy. Res = ParseCastExpression(false); if (!Res.isInvalid()) - Res = Actions.ActOnCastExpr(LParenLoc, CastTy, RParenLoc, Res.move()); - return Res.move(); + Res = Actions.ActOnCastExpr(LParenLoc, CastTy, RParenLoc, + Res.release()); + return Res.result(); } // These can be followed by postfix-expr pieces. - return ParsePostfixExpressionSuffix(Res.move()); + return ParsePostfixExpressionSuffix(Res.result()); } // primary-expression @@ -475,7 +477,7 @@ Parser::ExprResult Parser::ParseCastExpression(bool isUnaryExpression) { ConsumeToken(); // These can be followed by postfix-expr pieces. - return ParsePostfixExpressionSuffix(Res.move()); + return ParsePostfixExpressionSuffix(Res.result()); case tok::kw_true: case tok::kw_false: @@ -493,26 +495,26 @@ Parser::ExprResult Parser::ParseCastExpression(bool isUnaryExpression) { SourceLocation L = ConsumeToken(); Res = Actions.ActOnIdentifierExpr(CurScope, L, II, Tok.is(tok::l_paren)); // These can be followed by postfix-expr pieces. - return ParsePostfixExpressionSuffix(Res.move()); + return ParsePostfixExpressionSuffix(Res.result()); } case tok::char_constant: // constant: character-constant Res = Actions.ActOnCharacterConstant(Tok); ConsumeToken(); // These can be followed by postfix-expr pieces. - return ParsePostfixExpressionSuffix(Res.move()); + return ParsePostfixExpressionSuffix(Res.result()); 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(Res.move()); + return ParsePostfixExpressionSuffix(Res.result()); case tok::string_literal: // primary-expression: string-literal case tok::wide_string_literal: Res = ParseStringLiteralExpression(); - if (Res.isInvalid()) return Res.move(); + if (Res.isInvalid()) return Res.result(); // This can be followed by postfix-expr pieces (e.g. "foo"[1]). - return ParsePostfixExpressionSuffix(Res.move()); + return ParsePostfixExpressionSuffix(Res.result()); case tok::kw___builtin_va_arg: case tok::kw___builtin_offsetof: case tok::kw___builtin_choose_expr: @@ -527,8 +529,8 @@ Parser::ExprResult Parser::ParseCastExpression(bool isUnaryExpression) { SourceLocation SavedLoc = ConsumeToken(); Res = ParseCastExpression(true); if (!Res.isInvalid()) - Res = Actions.ActOnUnaryOp(CurScope, SavedLoc, SavedKind, Res.move()); - return Res.move(); + Res = Actions.ActOnUnaryOp(CurScope, SavedLoc, SavedKind, Res.release()); + return Res.result(); } case tok::amp: // unary-expression: '&' cast-expression case tok::star: // unary-expression: '*' cast-expression @@ -541,8 +543,8 @@ Parser::ExprResult Parser::ParseCastExpression(bool isUnaryExpression) { SourceLocation SavedLoc = ConsumeToken(); Res = ParseCastExpression(false); if (!Res.isInvalid()) - Res = Actions.ActOnUnaryOp(CurScope, SavedLoc, SavedKind, Res.move()); - return Res.move(); + Res = Actions.ActOnUnaryOp(CurScope, SavedLoc, SavedKind, Res.release()); + return Res.result(); } case tok::kw___extension__:{//unary-expression:'__extension__' cast-expr [GNU] @@ -551,8 +553,8 @@ Parser::ExprResult Parser::ParseCastExpression(bool isUnaryExpression) { SourceLocation SavedLoc = ConsumeToken(); Res = ParseCastExpression(false); if (!Res.isInvalid()) - Res = Actions.ActOnUnaryOp(CurScope, SavedLoc, SavedKind, Res.move()); - return Res.move(); + Res = Actions.ActOnUnaryOp(CurScope, SavedLoc, SavedKind, Res.release()); + return Res.result(); } case tok::kw_sizeof: // unary-expression: 'sizeof' unary-expression // unary-expression: 'sizeof' '(' type-name ')' @@ -567,12 +569,12 @@ Parser::ExprResult Parser::ParseCastExpression(bool isUnaryExpression) { Diag(Tok, diag::err_expected_ident); return ExprResult(true); } - + Diag(AmpAmpLoc, diag::ext_gnu_address_of_label); Res = Actions.ActOnAddrLabel(AmpAmpLoc, Tok.getLocation(), Tok.getIdentifierInfo()); ConsumeToken(); - return Res.move(); + return Res.result(); } case tok::kw_const_cast: case tok::kw_dynamic_cast: @@ -580,15 +582,15 @@ Parser::ExprResult Parser::ParseCastExpression(bool isUnaryExpression) { case tok::kw_static_cast: Res = ParseCXXCasts(); // These can be followed by postfix-expr pieces. - return ParsePostfixExpressionSuffix(Res.move()); + return ParsePostfixExpressionSuffix(Res.result()); case tok::kw_typeid: Res = ParseCXXTypeid(); // This can be followed by postfix-expr pieces. - return ParsePostfixExpressionSuffix(Res.move()); + return ParsePostfixExpressionSuffix(Res.result()); case tok::kw_this: Res = ParseCXXThis(); // This can be followed by postfix-expr pieces. - return ParsePostfixExpressionSuffix(Res.move()); + return ParsePostfixExpressionSuffix(Res.result()); case tok::kw_char: case tok::kw_wchar_t: @@ -616,14 +618,14 @@ Parser::ExprResult Parser::ParseCastExpression(bool isUnaryExpression) { Res = ParseCXXTypeConstructExpression(DS); // This can be followed by postfix-expr pieces. - return ParsePostfixExpressionSuffix(Res.move()); + return ParsePostfixExpressionSuffix(Res.result()); } case tok::annot_cxxscope: // [C++] id-expression: qualified-id case tok::kw_operator: // [C++] id-expression: operator/conversion-function-id // template-id Res = ParseCXXIdExpression(); - return ParsePostfixExpressionSuffix(Res.move()); + return ParsePostfixExpressionSuffix(Res.result()); case tok::coloncolon: // [C++] new-expression or [C++] delete-expression // If the next token is neither 'new' nor 'delete', the :: would have been @@ -689,7 +691,7 @@ Parser::ExprResult Parser::ParsePostfixExpressionSuffix(ExprResult LHSArg) { while (1) { switch (Tok.getKind()) { default: // Not a postfix-expression suffix. - return LHS.move(); + return LHS.result(); case tok::l_square: { // postfix-expression: p-e '[' expression ']' Loc = ConsumeBracket(); OwningExprResult Idx(Actions, ParseExpression()); @@ -697,8 +699,8 @@ Parser::ExprResult Parser::ParsePostfixExpressionSuffix(ExprResult LHSArg) { SourceLocation RLoc = Tok.getLocation(); if (!LHS.isInvalid() && !Idx.isInvalid() && Tok.is(tok::r_square)) { - LHS = Actions.ActOnArraySubscriptExpr(CurScope, LHS.move(), Loc, - Idx.move(), RLoc); + LHS = Actions.ActOnArraySubscriptExpr(CurScope, LHS.release(), Loc, + Idx.release(), RLoc); } else LHS = ExprResult(true); @@ -724,7 +726,7 @@ Parser::ExprResult Parser::ParsePostfixExpressionSuffix(ExprResult LHSArg) { if (!LHS.isInvalid() && Tok.is(tok::r_paren)) { assert((ArgExprs.size() == 0 || ArgExprs.size()-1 == CommaLocs.size())&& "Unexpected number of commas!"); - LHS = Actions.ActOnCallExpr(CurScope, LHS.move(), Loc, + LHS = Actions.ActOnCallExpr(CurScope, LHS.release(), Loc, ArgExprs.take(), ArgExprs.size(), &CommaLocs[0], Tok.getLocation()); @@ -744,7 +746,7 @@ Parser::ExprResult Parser::ParsePostfixExpressionSuffix(ExprResult LHSArg) { } if (!LHS.isInvalid()) { - LHS = Actions.ActOnMemberReferenceExpr(LHS.move(), OpLoc, OpKind, + LHS = Actions.ActOnMemberReferenceExpr(LHS.release(), OpLoc, OpKind, Tok.getLocation(), *Tok.getIdentifierInfo()); } @@ -755,7 +757,7 @@ Parser::ExprResult Parser::ParsePostfixExpressionSuffix(ExprResult LHSArg) { case tok::minusminus: // postfix-expression: postfix-expression '--' if (!LHS.isInvalid()) { LHS = Actions.ActOnPostfixUnaryOp(CurScope, Tok.getLocation(), - Tok.getKind(), LHS.move()); + Tok.getKind(), LHS.release()); } ConsumeToken(); break; @@ -803,16 +805,16 @@ Parser::ExprResult Parser::ParseSizeofAlignofExpression() { // If this is a parenthesized expression, it is the start of a // unary-expression, but doesn't include any postfix pieces. Parse these // now if present. - Operand = ParsePostfixExpressionSuffix(Operand.move()); + Operand = ParsePostfixExpressionSuffix(Operand.result()); } // If we get here, the operand to the sizeof/alignof was an expresion. if (!Operand.isInvalid()) Operand = Actions.ActOnSizeOfAlignOfExpr(OpTok.getLocation(), OpTok.is(tok::kw_sizeof), - /*isType=*/false, Operand.move(), - SourceRange()); - return Operand.move(); + /*isType=*/false, + Operand.release(), SourceRange()); + return Operand.result(); } /// ParseBuiltinPrimaryExpression @@ -864,7 +866,7 @@ Parser::ExprResult Parser::ParseBuiltinPrimaryExpression() { Diag(Tok, diag::err_expected_rparen); return ExprResult(true); } - Res = Actions.ActOnVAArg(StartLoc, Expr.move(), Ty, ConsumeParen()); + Res = Actions.ActOnVAArg(StartLoc, Expr.release(), Ty, ConsumeParen()); break; } case tok::kw___builtin_offsetof: { @@ -913,9 +915,9 @@ Parser::ExprResult Parser::ParseBuiltinPrimaryExpression() { Res = ParseExpression(); if (Res.isInvalid()) { SkipUntil(tok::r_paren); - return Res.move(); + return Res.result(); } - Comps.back().U.E = Res.move(); + Comps.back().U.E = Res.release(); Comps.back().LocEnd = MatchRHSPunctuation(tok::r_square, Comps.back().LocStart); @@ -934,7 +936,7 @@ Parser::ExprResult Parser::ParseBuiltinPrimaryExpression() { OwningExprResult Cond(Actions, ParseAssignmentExpression()); if (Cond.isInvalid()) { SkipUntil(tok::r_paren); - return Cond.move(); + return Cond.result(); } if (ExpectAndConsume(tok::comma, diag::err_expected_comma, "",tok::r_paren)) return ExprResult(true); @@ -942,7 +944,7 @@ Parser::ExprResult Parser::ParseBuiltinPrimaryExpression() { OwningExprResult Expr1(Actions, ParseAssignmentExpression()); if (Expr1.isInvalid()) { SkipUntil(tok::r_paren); - return Expr1.move(); + return Expr1.result(); } if (ExpectAndConsume(tok::comma, diag::err_expected_comma, "",tok::r_paren)) return ExprResult(true); @@ -950,14 +952,14 @@ Parser::ExprResult Parser::ParseBuiltinPrimaryExpression() { OwningExprResult Expr2(Actions, ParseAssignmentExpression()); if (Expr2.isInvalid()) { SkipUntil(tok::r_paren); - return Expr2.move(); + return Expr2.result(); } if (Tok.isNot(tok::r_paren)) { Diag(Tok, diag::err_expected_rparen); return ExprResult(true); } - Res = Actions.ActOnChooseExpr(StartLoc, Cond.move(), Expr1.move(), - Expr2.move(), ConsumeParen()); + Res = Actions.ActOnChooseExpr(StartLoc, Cond.release(), Expr1.release(), + Expr2.release(), ConsumeParen()); break; } case tok::kw___builtin_overload: { @@ -973,7 +975,7 @@ Parser::ExprResult Parser::ParseBuiltinPrimaryExpression() { SkipUntil(tok::r_paren); return ExprResult(true); } else - ArgExprs.push_back(ArgExpr.move()); + ArgExprs.push_back(ArgExpr.release()); if (Tok.isNot(tok::comma)) break; @@ -1010,7 +1012,7 @@ Parser::ExprResult Parser::ParseBuiltinPrimaryExpression() { // These can be followed by postfix-expr pieces because they are // primary-expressions. - return ParsePostfixExpressionSuffix(Res.move()); + return ParsePostfixExpressionSuffix(Res.result()); } /// ParseParenExpression - This parses the unit that starts with a '(' token, @@ -1042,7 +1044,7 @@ Parser::ExprResult Parser::ParseParenExpression(ParenParseOption &ExprType, // If the substmt parsed correctly, build the AST node. if (!Stmt.isInvalid() && Tok.is(tok::r_paren)) Result = Actions.ActOnStmtExpr( - OpenLoc, Stmt.move(), Tok.getLocation()); + OpenLoc, Stmt.release(), Tok.getLocation()); } else if (ExprType >= CompoundLiteral && isTypeIdInParens()) { // Otherwise, this is a compound literal expression or cast expression. @@ -1061,7 +1063,7 @@ Parser::ExprResult Parser::ParseParenExpression(ParenParseOption &ExprType, ExprType = CompoundLiteral; if (!Result.isInvalid()) return Actions.ActOnCompoundLiteral(OpenLoc, Ty, RParenLoc, - Result.move()); + Result.release()); } else if (ExprType == CastExpr) { // Note that this doesn't parse the subsequence cast-expression, it just // returns the parsed type to the callee. @@ -1072,13 +1074,13 @@ Parser::ExprResult Parser::ParseParenExpression(ParenParseOption &ExprType, Diag(Tok, diag::err_expected_lbrace_in_compound_literal); return ExprResult(true); } - return Result.move(); + return Result.result(); } else { Result = ParseExpression(); ExprType = SimpleExpr; if (!Result.isInvalid() && Tok.is(tok::r_paren)) Result = Actions.ActOnParenExpr( - OpenLoc, Tok.getLocation(), Result.move()); + OpenLoc, Tok.getLocation(), Result.release()); } // Match the ')'. @@ -1091,7 +1093,7 @@ Parser::ExprResult Parser::ParseParenExpression(ParenParseOption &ExprType, MatchRHSPunctuation(tok::r_paren, OpenLoc); } - return Result.move(); + return Result.result(); } /// ParseStringLiteralExpression - This handles the various token types that @@ -1132,7 +1134,7 @@ bool Parser::ParseExpressionList(ExprListTy &Exprs, CommaLocsTy &CommaLocs) { if (Expr.isInvalid()) return true; - Exprs.push_back(Expr.move()); + Exprs.push_back(Expr.release()); if (Tok.isNot(tok::comma)) return false; @@ -1193,12 +1195,12 @@ Parser::ExprResult Parser::ParseBlockLiteralExpression() { if (Tok.is(tok::l_brace)) { OwningStmtResult Stmt(Actions, ParseCompoundStatementBody()); if (!Stmt.isInvalid()) { - Result = Actions.ActOnBlockStmtExpr(CaretLoc, Stmt.move(), CurScope); + Result = Actions.ActOnBlockStmtExpr(CaretLoc, Stmt.release(), CurScope); } else { Actions.ActOnBlockError(CaretLoc, CurScope); } } ExitScope(); - return Result.move(); + return Result.result(); } diff --git a/lib/Parse/ParseExprCXX.cpp b/lib/Parse/ParseExprCXX.cpp index e28ddc7485..8dd2f515dd 100644 --- a/lib/Parse/ParseExprCXX.cpp +++ b/lib/Parse/ParseExprCXX.cpp @@ -226,9 +226,9 @@ Parser::ExprResult Parser::ParseCXXCasts() { if (!Result.isInvalid()) Result = Actions.ActOnCXXNamedCast(OpLoc, Kind, LAngleBracketLoc, CastTy, RAngleBracketLoc, - LParenLoc, Result.move(), RParenLoc); + LParenLoc, Result.release(), RParenLoc); - return Result.move(); + return Result.result(); } /// ParseCXXTypeid - This handles the C++ typeid expression. @@ -272,11 +272,11 @@ Parser::ExprResult Parser::ParseCXXTypeid() { MatchRHSPunctuation(tok::r_paren, LParenLoc); Result = Actions.ActOnCXXTypeid(OpLoc, LParenLoc, /*isType=*/false, - Result.move(), RParenLoc); + Result.release(), RParenLoc); } } - return Result.move(); + return Result.result(); } /// ParseCXXBoolLiteral - This handles the C++ Boolean literals. @@ -311,8 +311,8 @@ Parser::ExprResult Parser::ParseThrowExpression() { default: OwningExprResult Expr(Actions, ParseAssignmentExpression()); - if (Expr.isInvalid()) return Expr.move(); - return Actions.ActOnCXXThrow(ThrowLoc, Expr.move()); + if (Expr.isInvalid()) return Expr.result(); + return Actions.ActOnCXXThrow(ThrowLoc, Expr.release()); } } @@ -388,12 +388,12 @@ Parser::ExprResult Parser::ParseCXXCondition() { // simple-asm-expr[opt] if (Tok.is(tok::kw_asm)) { - OwningExprResult AsmLabel(Actions, ParseSimpleAsm()); + OwningExprResult AsmLabel(ParseSimpleAsm()); if (AsmLabel.isInvalid()) { SkipUntil(tok::semi); return true; } - DeclaratorInfo.setAsmLabel(AsmLabel.move()); + DeclaratorInfo.setAsmLabel(AsmLabel.release()); } // If attributes are present, parse them. @@ -409,8 +409,8 @@ Parser::ExprResult Parser::ParseCXXCondition() { return true; return Actions.ActOnCXXConditionDeclarationExpr(CurScope, StartLoc, - DeclaratorInfo, - EqualLoc, AssignExpr.move()); + DeclaratorInfo, EqualLoc, + AssignExpr.release()); } /// ParseCXXSimpleTypeSpecifier - [C++ 7.1.5.2] Simple type specifiers. @@ -786,7 +786,7 @@ void Parser::ParseDirectNewDeclarator(Declarator &D) first = false; D.AddTypeInfo(DeclaratorChunk::getArray(0, /*static=*/false, /*star=*/false, - Size.move(), LLoc)); + Size.release(), LLoc)); if (MatchRHSPunctuation(tok::r_square, LLoc).isInvalid()) return; @@ -853,7 +853,8 @@ Parser::ExprResult Parser::ParseCXXDeleteExpression() OwningExprResult Operand(Actions, ParseCastExpression(false)); if (Operand.isInvalid()) - return Operand.move(); + return Operand.result(); - return Actions.ActOnCXXDelete(Start, UseGlobal, ArrayDelete, Operand.move()); + return Actions.ActOnCXXDelete(Start, UseGlobal, ArrayDelete, + Operand.release()); } diff --git a/lib/Parse/ParseInit.cpp b/lib/Parse/ParseInit.cpp index 39b43fa201..01d1d0b22d 100644 --- a/lib/Parse/ParseInit.cpp +++ b/lib/Parse/ParseInit.cpp @@ -146,7 +146,7 @@ ParseInitializerWithPotentialDesignator(InitListDesignations &Designations, OwningExprResult Idx(Actions, ParseAssignmentExpression()); if (Idx.isInvalid()) { SkipUntil(tok::r_square); - return Idx.move(); + return Idx.result(); } // Given an expression, we could either have a designator (if the next @@ -170,7 +170,7 @@ ParseInitializerWithPotentialDesignator(InitListDesignations &Designations, return ParseAssignmentExprWithObjCMessageExprStart(StartLoc, SourceLocation(), - 0, Idx.move()); + 0, Idx.release()); } // Create designation if we haven't already. @@ -179,7 +179,7 @@ ParseInitializerWithPotentialDesignator(InitListDesignations &Designations, // If this is a normal array designator, remember it. if (Tok.isNot(tok::ellipsis)) { - Desig->AddDesignator(Designator::getArray(Idx.move())); + Desig->AddDesignator(Designator::getArray(Idx.release())); } else { // Handle the gnu array range extension. Diag(Tok, diag::ext_gnu_array_range); @@ -188,9 +188,10 @@ ParseInitializerWithPotentialDesignator(InitListDesignations &Designations, OwningExprResult RHS(Actions, ParseConstantExpression()); if (RHS.isInvalid()) { SkipUntil(tok::r_square); - return RHS.move(); + return RHS.result(); } - Desig->AddDesignator(Designator::getArrayRange(Idx.move(), RHS.move())); + Desig->AddDesignator(Designator::getArrayRange(Idx.release(), + RHS.release())); } MatchRHSPunctuation(tok::r_square, StartLoc); @@ -280,7 +281,7 @@ Parser::ExprResult Parser::ParseBraceInitializer() { // If we couldn't parse the subelement, bail out. if (!SubElt.isInvalid()) { - InitExprs.push_back(SubElt.move()); + InitExprs.push_back(SubElt.release()); } else { InitExprsOk = false; diff --git a/lib/Parse/ParseObjc.cpp b/lib/Parse/ParseObjc.cpp index 7ca11eb3cd..c6bc386d6b 100644 --- a/lib/Parse/ParseObjc.cpp +++ b/lib/Parse/ParseObjc.cpp @@ -1185,7 +1185,7 @@ Parser::StmtResult Parser::ParseObjCThrowStmt(SourceLocation atLoc) { } } ConsumeToken(); // consume ';' - return Actions.ActOnObjCAtThrowStmt(atLoc, Res.move()); + return Actions.ActOnObjCAtThrowStmt(atLoc, Res.release()); } /// objc-synchronized-statement: @@ -1221,8 +1221,8 @@ Parser::StmtResult Parser::ParseObjCSynchronizedStmt(SourceLocation atLoc) { ExitScope(); if (SynchBody.isInvalid()) SynchBody = Actions.ActOnNullStmt(Tok.getLocation()); - return Actions.ActOnObjCAtSynchronizedStmt(atLoc, Res.move(), - SynchBody.move()); + return Actions.ActOnObjCAtSynchronizedStmt(atLoc, Res.release(), + SynchBody.release()); } /// objc-try-catch-statement: @@ -1295,7 +1295,8 @@ Parser::StmtResult Parser::ParseObjCTryStmt(SourceLocation atLoc) { if (CatchBody.isInvalid()) CatchBody = Actions.ActOnNullStmt(Tok.getLocation()); CatchStmts = Actions.ActOnObjCAtCatchStmt(AtCatchFinallyLoc, - RParenLoc, FirstPart.move(), CatchBody.move(), CatchStmts.move()); + RParenLoc, FirstPart.release(), CatchBody.release(), + CatchStmts.release()); ExitScope(); } else { Diag(AtCatchFinallyLoc, diag::err_expected_lparen_after) @@ -1317,7 +1318,7 @@ Parser::StmtResult Parser::ParseObjCTryStmt(SourceLocation atLoc) { if (FinallyBody.isInvalid()) FinallyBody = Actions.ActOnNullStmt(Tok.getLocation()); FinallyStmt = Actions.ActOnObjCAtFinallyStmt(AtCatchFinallyLoc, - FinallyBody.move()); + FinallyBody.release()); catch_or_finally_seen = true; ExitScope(); break; @@ -1327,8 +1328,9 @@ Parser::StmtResult Parser::ParseObjCTryStmt(SourceLocation atLoc) { Diag(atLoc, diag::err_missing_catch_finally); return true; } - return Actions.ActOnObjCAtTryStmt(atLoc, TryBody.move(), CatchStmts.move(), - FinallyStmt.move()); + return Actions.ActOnObjCAtTryStmt(atLoc, TryBody.release(), + CatchStmts.release(), + FinallyStmt.release()); } /// objc-method-def: objc-method-proto ';'[opt] '{' body '}' @@ -1369,7 +1371,7 @@ Parser::DeclTy *Parser::ParseObjCMethodDefinition() { ExitScope(); // TODO: Pass argument information. - Actions.ActOnFinishFunctionBody(MDecl, FnBody.move()); + Actions.ActOnFinishFunctionBody(MDecl, FnBody.release()); return MDecl; } @@ -1390,7 +1392,7 @@ Parser::StmtResult Parser::ParseObjCAtStatement(SourceLocation AtLoc) { } // Otherwise, eat the semicolon. ExpectAndConsume(tok::semi, diag::err_expected_semi_after_expr); - return Actions.ActOnExprStmt(Res.move()); + return Actions.ActOnExprStmt(Res.release()); } Parser::ExprResult Parser::ParseObjCAtExpression(SourceLocation AtLoc) { @@ -1436,11 +1438,11 @@ Parser::ExprResult Parser::ParseObjCMessageExpression() { OwningExprResult Res(Actions, ParseExpression()); if (Res.isInvalid()) { SkipUntil(tok::r_square); - return Res.move(); + return Res.result(); } return ParseObjCMessageExpressionBody(LBracLoc, SourceLocation(), - 0, Res.move()); + 0, Res.release()); } /// ParseObjCMessageExpressionBody - Having parsed "'[' objc-receiver", parse @@ -1498,11 +1500,11 @@ Parser::ParseObjCMessageExpressionBody(SourceLocation LBracLoc, // stop at the ']' when it skips to the ';'. We want it to skip beyond // the enclosing expression. SkipUntil(tok::r_square); - return Res.move(); + return Res.result(); } // We have a valid expression. - KeyExprs.push_back(Res.move()); + KeyExprs.push_back(Res.release()); // Check for another keyword selector. selIdent = ParseObjCSelector(Loc); @@ -1520,11 +1522,11 @@ Parser::ParseObjCMessageExpressionBody(SourceLocation LBracLoc, // stop at the ']' when it skips to the ';'. We want it to skip beyond // the enclosing expression. SkipUntil(tok::r_square); - return Res.move(); + return Res.result(); } // We have a valid expression. - KeyExprs.push_back(Res.move()); + KeyExprs.push_back(Res.release()); } } else if (!selIdent) { Diag(Tok, diag::err_expected_ident); // missing selector name. @@ -1564,7 +1566,7 @@ Parser::ParseObjCMessageExpressionBody(SourceLocation LBracLoc, Parser::ExprResult Parser::ParseObjCStringLiteral(SourceLocation AtLoc) { OwningExprResult Res(Actions, ParseStringLiteralExpression()); - if (Res.isInvalid()) return Res.move(); + if (Res.isInvalid()) return Res.result(); // @"foo" @"bar" is a valid concatenated string. Eat any subsequent string // expressions. At this point, we know that the only valid thing that starts @@ -1572,7 +1574,7 @@ Parser::ExprResult Parser::ParseObjCStringLiteral(SourceLocation AtLoc) { llvm::SmallVector AtLocs; ExprVector AtStrings(Actions); AtLocs.push_back(AtLoc); - AtStrings.push_back(Res.move()); + AtStrings.push_back(Res.release()); while (Tok.is(tok::at)) { AtLocs.push_back(ConsumeToken()); // eat the @. @@ -1585,9 +1587,9 @@ Parser::ExprResult Parser::ParseObjCStringLiteral(SourceLocation AtLoc) { Diag(Tok, diag::err_objc_concat_string); if (Lit.isInvalid()) - return Lit.move(); + return Lit.result(); - AtStrings.push_back(Lit.move()); + AtStrings.push_back(Lit.release()); } return Actions.ParseObjCStringLiteral(&AtLocs[0], AtStrings.take(), diff --git a/lib/Parse/ParsePragma.cpp b/lib/Parse/ParsePragma.cpp index 7a1343c355..40f0f652d9 100644 --- a/lib/Parse/ParsePragma.cpp +++ b/lib/Parse/ParsePragma.cpp @@ -100,7 +100,7 @@ void PragmaPackHandler::HandlePragma(Preprocessor &PP, Token &PackTok) { } SourceLocation RParenLoc = Tok.getLocation(); - Actions.ActOnPragmaPack(Kind, Name, Alignment.move(), PackLoc, + Actions.ActOnPragmaPack(Kind, Name, Alignment.release(), PackLoc, LParenLoc, RParenLoc); } diff --git a/lib/Parse/ParseStmt.cpp b/lib/Parse/ParseStmt.cpp index c99d8efd11..f244e4ba98 100644 --- a/lib/Parse/ParseStmt.cpp +++ b/lib/Parse/ParseStmt.cpp @@ -116,7 +116,7 @@ Parser::StmtResult Parser::ParseStatementOrDeclaration(bool OnlyStatement) { } // Otherwise, eat the semicolon. ExpectAndConsume(tok::semi, diag::err_expected_semi_after_expr); - return Actions.ActOnExprStmt(Expr.move()); + return Actions.ActOnExprStmt(Expr.release()); } case tok::kw_case: // C99 6.8.1: labeled-statement @@ -163,7 +163,7 @@ Parser::StmtResult Parser::ParseStatementOrDeclaration(bool OnlyStatement) { case tok::kw_asm: bool msAsm = false; Res = ParseAsmStatement(msAsm); - if (msAsm) return Res.move(); + if (msAsm) return Res.result(); SemiError = "asm statement"; break; } @@ -176,7 +176,7 @@ Parser::StmtResult Parser::ParseStatementOrDeclaration(bool OnlyStatement) { // Skip until we see a } or ;, but don't eat it. SkipUntil(tok::r_brace, true, true); } - return Res.move(); + return Res.result(); } /// ParseLabeledStatement - We have an identifier and a ':' after it. @@ -211,7 +211,7 @@ Parser::StmtResult Parser::ParseLabeledStatement() { return Actions.ActOnLabelStmt(IdentTok.getLocation(), IdentTok.getIdentifierInfo(), - ColonLoc, SubStmt.move()); + ColonLoc, SubStmt.release()); } /// ParseCaseStatement @@ -265,8 +265,8 @@ Parser::StmtResult Parser::ParseCaseStatement() { if (SubStmt.isInvalid()) SubStmt = Actions.ActOnNullStmt(ColonLoc); - return Actions.ActOnCaseStmt(CaseLoc, LHS.move(), DotDotDotLoc, - RHS.move(), ColonLoc, SubStmt.move()); + return Actions.ActOnCaseStmt(CaseLoc, LHS.release(), DotDotDotLoc, + RHS.release(), ColonLoc, SubStmt.release()); } /// ParseDefaultStatement @@ -297,7 +297,7 @@ Parser::StmtResult Parser::ParseDefaultStatement() { return true; return Actions.ActOnDefaultStmt(DefaultLoc, ColonLoc, - SubStmt.move(), CurScope); + SubStmt.release(), CurScope); } @@ -339,7 +339,7 @@ Parser::StmtResult Parser::ParseCompoundStatement(bool isStmtExpr) { OwningStmtResult Body(Actions, ParseCompoundStatementBody(isStmtExpr)); ExitScope(); - return Body.move(); + return Body.result(); } @@ -389,19 +389,19 @@ Parser::StmtResult Parser::ParseCompoundStatementBody(bool isStmtExpr) { // Add the __extension__ node to the AST. Res = Actions.ActOnUnaryOp(CurScope, ExtLoc, tok::kw___extension__, - Res.move()); + Res.release()); if (Res.isInvalid()) continue; // Eat the semicolon at the end of stmt and convert the expr into a // statement. ExpectAndConsume(tok::semi, diag::err_expected_semi_after_expr); - R = Actions.ActOnExprStmt(Res.move()); + R = Actions.ActOnExprStmt(Res.release()); } } if (R.isUsable()) - Stmts.push_back(R.move()); + Stmts.push_back(R.release()); } // We broke out of the while loop because we found a '}' or EOF. @@ -540,8 +540,8 @@ Parser::StmtResult Parser::ParseIfStatement() { if (ElseStmt.isInvalid()) ElseStmt = Actions.ActOnNullStmt(ElseStmtLoc); - return Actions.ActOnIfStmt(IfLoc, CondExp.move(), ThenStmt.move(), - ElseLoc, ElseStmt.move()); + return Actions.ActOnIfStmt(IfLoc, CondExp.release(), ThenStmt.release(), + ElseLoc, ElseStmt.release()); } /// ParseSwitchStatement @@ -592,7 +592,8 @@ Parser::StmtResult Parser::ParseSwitchStatement() { return true; } - OwningStmtResult Switch(Actions, Actions.ActOnStartOfSwitchStmt(Cond.move())); + OwningStmtResult Switch(Actions, + Actions.ActOnStartOfSwitchStmt(Cond.release())); // C99 6.8.4p3 - In C99, the body of the switch statement is a scope, even if // there is no compound stmt. C90 does not have this clause. We only do this @@ -621,7 +622,8 @@ Parser::StmtResult Parser::ParseSwitchStatement() { ExitScope(); - return Actions.ActOnFinishSwitchStmt(SwitchLoc, Switch.move(), Body.move()); + return Actions.ActOnFinishSwitchStmt(SwitchLoc, Switch.release(), + Body.release()); } /// ParseWhileStatement @@ -693,7 +695,7 @@ Parser::StmtResult Parser::ParseWhileStatement() { if (Cond.isInvalid() || Body.isInvalid()) return true; - return Actions.ActOnWhileStmt(WhileLoc, Cond.move(), Body.move()); + return Actions.ActOnWhileStmt(WhileLoc, Cond.release(), Body.release()); } /// ParseDoStatement @@ -754,7 +756,7 @@ Parser::StmtResult Parser::ParseDoStatement() { if (Cond.isInvalid() || Body.isInvalid()) return true; - return Actions.ActOnDoStmt(DoLoc, Body.move(), WhileLoc, Cond.move()); + return Actions.ActOnDoStmt(DoLoc, Body.release(), WhileLoc, Cond.release()); } /// ParseForStatement @@ -833,8 +835,8 @@ Parser::StmtResult Parser::ParseForStatement() { // Turn the expression into a stmt. if (!Value.isInvalid()) - FirstPart = Actions.ActOnExprStmt(Value.move()); - + FirstPart = Actions.ActOnExprStmt(Value.release()); + if (Tok.is(tok::semi)) { ConsumeToken(); } @@ -871,7 +873,7 @@ Parser::StmtResult Parser::ParseForStatement() { Value = ParseExpression(); if (!Value.isInvalid()) { // Turn the expression into a stmt. - ThirdPart = Actions.ActOnExprStmt(Value.move()); + ThirdPart = Actions.ActOnExprStmt(Value.release()); } } } @@ -903,16 +905,16 @@ Parser::StmtResult Parser::ParseForStatement() { if (Body.isInvalid()) return true; - - if (!ForEach) - return Actions.ActOnForStmt(ForLoc, LParenLoc, FirstPart.move(), - SecondPart.move(), ThirdPart.move(), RParenLoc, - Body.move()); + + if (!ForEach) + return Actions.ActOnForStmt(ForLoc, LParenLoc, FirstPart.release(), + SecondPart.release(), ThirdPart.release(), + RParenLoc, Body.release()); else return Actions.ActOnObjCForCollectionStmt(ForLoc, LParenLoc, - FirstPart.move(), - SecondPart.move(), - RParenLoc, Body.move()); + FirstPart.release(), + SecondPart.release(), + RParenLoc, Body.release()); } /// ParseGotoStatement @@ -940,13 +942,13 @@ Parser::StmtResult Parser::ParseGotoStatement() { SkipUntil(tok::semi, false, true); return true; } - Res = Actions.ActOnIndirectGotoStmt(GotoLoc, StarLoc, R.move()); + Res = Actions.ActOnIndirectGotoStmt(GotoLoc, StarLoc, R.release()); } else { Diag(Tok, diag::err_expected_ident); return true; } - return Res.move(); + return Res.result(); } /// ParseContinueStatement @@ -986,7 +988,7 @@ Parser::StmtResult Parser::ParseReturnStatement() { return true; } } - return Actions.ActOnReturnStmt(ReturnLoc, R.move()); + return Actions.ActOnReturnStmt(ReturnLoc, R.release()); } /// FuzzyParseMicrosoftAsmStatement. When -fms-extensions is enabled, this @@ -1068,7 +1070,7 @@ Parser::StmtResult Parser::ParseAsmStatement(bool &msAsm) { } Loc = ConsumeParen(); - OwningExprResult AsmString(Actions, ParseAsmStringLiteral()); + OwningExprResult AsmString(ParseAsmStringLiteral()); if (AsmString.isInvalid()) return true; @@ -1095,38 +1097,38 @@ Parser::StmtResult Parser::ParseAsmStatement(bool &msAsm) { // Parse Inputs, if present. if (ParseAsmOperandsOpt(Names, Constraints, Exprs)) return true; - + assert(Names.size() == Constraints.size() && Constraints.size() == Exprs.size() && "Input operand size mismatch!"); NumInputs = Names.size() - NumOutputs; - + // Parse the clobbers, if present. if (Tok.is(tok::colon)) { ConsumeToken(); - + // Parse the asm-string list for clobbers. while (1) { - OwningExprResult Clobber(Actions, ParseAsmStringLiteral()); + OwningExprResult Clobber(ParseAsmStringLiteral()); if (Clobber.isInvalid()) break; - - Clobbers.push_back(Clobber.move()); - + + Clobbers.push_back(Clobber.release()); + if (Tok.isNot(tok::comma)) break; ConsumeToken(); } } - + RParenLoc = MatchRHSPunctuation(tok::r_paren, Loc); } - + return Actions.ActOnAsmStmt(AsmLoc, isSimple, isVolatile, NumOutputs, NumInputs, &Names[0], Constraints.take(), - Exprs.take(), AsmString.move(), + Exprs.take(), AsmString.release(), Clobbers.size(), Clobbers.take(), RParenLoc); } @@ -1173,26 +1175,26 @@ bool Parser::ParseAsmOperandsOpt(llvm::SmallVectorImpl &Names, } else Names.push_back(std::string()); - OwningExprResult Constraint(Actions, ParseAsmStringLiteral()); + OwningExprResult Constraint(ParseAsmStringLiteral()); if (Constraint.isInvalid()) { SkipUntil(tok::r_paren); return true; } - Constraints.push_back(Constraint.move()); + Constraints.push_back(Constraint.release()); if (Tok.isNot(tok::l_paren)) { Diag(Tok, diag::err_expected_lparen_after) << "asm operand"; SkipUntil(tok::r_paren); return true; } - + // Read the parenthesized expression. OwningExprResult Res(Actions, ParseSimpleParenExpression()); if (Res.isInvalid()) { SkipUntil(tok::r_paren); return true; } - Exprs.push_back(Res.move()); + Exprs.push_back(Res.release()); // Eat the comma and continue parsing if it exists. if (Tok.isNot(tok::comma)) return false; ConsumeToken(); @@ -1215,5 +1217,5 @@ Parser::DeclTy *Parser::ParseFunctionStatementBody(DeclTy *Decl, // Leave the function body scope. ExitScope(); - return Actions.ActOnFinishFunctionBody(Decl, FnBody.move()); + return Actions.ActOnFinishFunctionBody(Decl, FnBody.release()); } diff --git a/lib/Parse/Parser.cpp b/lib/Parse/Parser.cpp index b4c12fa2ad..d040efd7ac 100644 --- a/lib/Parse/Parser.cpp +++ b/lib/Parse/Parser.cpp @@ -336,13 +336,13 @@ Parser::DeclTy *Parser::ParseExternalDeclaration() { return ParseExternalDeclaration(); } case tok::kw_asm: { - OwningExprResult Result(Actions, ParseSimpleAsm()); + OwningExprResult Result(ParseSimpleAsm()); ExpectAndConsume(tok::semi, diag::err_expected_semi_after, "top-level asm block"); if (!Result.isInvalid()) - return Actions.ActOnFileScopeAsmDecl(Tok.getLocation(), Result.move()); + return Actions.ActOnFileScopeAsmDecl(Tok.getLocation(), Result.release()); return 0; } case tok::at: @@ -666,18 +666,18 @@ void Parser::ParseKNRParamDeclarations(Declarator &D) { /// [GNU] asm-string-literal: /// string-literal /// -Parser::ExprResult Parser::ParseAsmStringLiteral() { +Parser::OwningExprResult Parser::ParseAsmStringLiteral() { if (!isTokenStringLiteral()) { Diag(Tok, diag::err_expected_string_literal); - return true; + return OwningExprResult(true); } OwningExprResult Res(Actions, ParseStringLiteralExpression()); - if (Res.isInvalid()) return true; + if (Res.isInvalid()) return move(Res); // TODO: Diagnose: wide string literal in 'asm' - return Res.move(); + return move(Res); } /// ParseSimpleAsm @@ -685,25 +685,25 @@ Parser::ExprResult Parser::ParseAsmStringLiteral() { /// [GNU] simple-asm-expr: /// 'asm' '(' asm-string-literal ')' /// -Parser::ExprResult Parser::ParseSimpleAsm() { +Parser::OwningExprResult Parser::ParseSimpleAsm() { assert(Tok.is(tok::kw_asm) && "Not an asm!"); SourceLocation Loc = ConsumeToken(); if (Tok.isNot(tok::l_paren)) { Diag(Tok, diag::err_expected_lparen_after) << "asm"; - return true; + return OwningExprResult(true); } ConsumeParen(); - OwningExprResult Result(Actions, ParseAsmStringLiteral()); + OwningExprResult Result(ParseAsmStringLiteral()); if (Result.isInvalid()) SkipUntil(tok::r_paren); else MatchRHSPunctuation(tok::r_paren, Loc); - return Result.move(); + return move(Result); } /// TryAnnotateTypeOrScopeToken - If the current token position is on a -- 2.50.1