diff options
author | Sebastian Redl <sebastian.redl@getdesigned.at> | 2009-03-15 17:47:39 +0000 |
---|---|---|
committer | Sebastian Redl <sebastian.redl@getdesigned.at> | 2009-03-15 17:47:39 +0000 |
commit | f53597fb16142bdb4a66901f8c0b768db4f2a548 (patch) | |
tree | b1d6b9bccdbcf7c2eccac31709a90eee515a1342 /lib | |
parent | 3e287c2a53e88d583fa2e0cafc33dbb49772db05 (diff) |
Convert a bunch of actions to smart pointers, and also bring PrintParserCallbacks a bit more in line with reality.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67029 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Parse/MinimalAction.cpp | 2 | ||||
-rw-r--r-- | lib/Parse/ParseCXXInlineMethods.cpp | 2 | ||||
-rw-r--r-- | lib/Parse/ParseDecl.cpp | 4 | ||||
-rw-r--r-- | lib/Parse/ParseExpr.cpp | 14 | ||||
-rw-r--r-- | lib/Parse/ParseExprCXX.cpp | 37 | ||||
-rw-r--r-- | lib/Sema/Sema.h | 142 | ||||
-rw-r--r-- | lib/Sema/SemaDeclCXX.cpp | 23 | ||||
-rw-r--r-- | lib/Sema/SemaExpr.cpp | 130 | ||||
-rw-r--r-- | lib/Sema/SemaExprCXX.cpp | 198 | ||||
-rw-r--r-- | lib/Sema/SemaNamedCast.cpp | 25 | ||||
-rw-r--r-- | lib/Sema/SemaTemplateInstantiate.cpp | 22 |
11 files changed, 314 insertions, 285 deletions
diff --git a/lib/Parse/MinimalAction.cpp b/lib/Parse/MinimalAction.cpp index 41ad36c83e..fbda832836 100644 --- a/lib/Parse/MinimalAction.cpp +++ b/lib/Parse/MinimalAction.cpp @@ -19,7 +19,7 @@ #include "llvm/Support/raw_ostream.h" using namespace clang; -/// Out-of-line virtual destructor to provide home for Action class. +/// Out-of-line virtual destructor to provide home for ActionBase class. ActionBase::~ActionBase() {} /// Out-of-line virtual destructor to provide home for Action class. diff --git a/lib/Parse/ParseCXXInlineMethods.cpp b/lib/Parse/ParseCXXInlineMethods.cpp index cc61f0f6fd..3ed9802026 100644 --- a/lib/Parse/ParseCXXInlineMethods.cpp +++ b/lib/Parse/ParseCXXInlineMethods.cpp @@ -98,7 +98,7 @@ void Parser::ParseLexedMethodDeclarations() { Actions.ActOnParamDefaultArgumentError(LM.DefaultArgs[I].Param); else Actions.ActOnParamDefaultArgument(LM.DefaultArgs[I].Param, EqualLoc, - DefArgResult.release()); + move(DefArgResult)); delete Toks; LM.DefaultArgs[I].Toks = 0; } diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp index 56a1decb59..aa96db540a 100644 --- a/lib/Parse/ParseDecl.cpp +++ b/lib/Parse/ParseDecl.cpp @@ -346,7 +346,7 @@ ParseInitDeclaratorListAfterFirstDeclarator(Declarator &D) { assert(!Exprs.empty() && Exprs.size()-1 == CommaLocs.size() && "Unexpected number of commas!"); Actions.AddCXXDirectInitializerToDecl(LastDeclInGroup, LParenLoc, - Exprs.take(), Exprs.size(), + move_arg(Exprs), &CommaLocs[0], RParenLoc); } } else { @@ -2184,7 +2184,7 @@ void Parser::ParseFunctionDeclarator(SourceLocation LParenLoc, Declarator &D, } else { // Inform the actions module about the default argument Actions.ActOnParamDefaultArgument(Param, EqualLoc, - DefArgResult.release()); + move(DefArgResult)); } } } diff --git a/lib/Parse/ParseExpr.cpp b/lib/Parse/ParseExpr.cpp index 000cb9d606..f2892c1367 100644 --- a/lib/Parse/ParseExpr.cpp +++ b/lib/Parse/ParseExpr.cpp @@ -625,7 +625,7 @@ Parser::OwningExprResult Parser::ParseCastExpression(bool isUnaryExpression, case tok::kw___builtin_types_compatible_p: return ParseBuiltinPrimaryExpression(); case tok::kw___null: - return Owned(Actions.ActOnGNUNullExpr(ConsumeToken())); + return Actions.ActOnGNUNullExpr(ConsumeToken()); break; case tok::plusplus: // unary-expression: '++' unary-expression case tok::minusminus: { // unary-expression: '--' unary-expression @@ -995,8 +995,7 @@ Parser::OwningExprResult Parser::ParseBuiltinPrimaryExpression() { if (Ty.isInvalid()) Res = ExprError(); else - Res = Actions.ActOnVAArg(StartLoc, Expr.release(), Ty.get(), - ConsumeParen()); + Res = Actions.ActOnVAArg(StartLoc, move(Expr), Ty.get(), ConsumeParen()); break; } case tok::kw___builtin_offsetof: { @@ -1092,8 +1091,8 @@ Parser::OwningExprResult Parser::ParseBuiltinPrimaryExpression() { Diag(Tok, diag::err_expected_rparen); return ExprError(); } - Res = Actions.ActOnChooseExpr(StartLoc, Cond.release(), Expr1.release(), - Expr2.release(), ConsumeParen()); + Res = Actions.ActOnChooseExpr(StartLoc, move(Cond), move(Expr1), + move(Expr2), ConsumeParen()); break; } case tok::kw___builtin_types_compatible_p: @@ -1151,8 +1150,7 @@ 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.release(), Tok.getLocation()); + Result = Actions.ActOnStmtExpr(OpenLoc, move(Stmt), Tok.getLocation()); } else if (ExprType >= CompoundLiteral && isTypeIdInParens()) { // Otherwise, this is a compound literal expression or cast expression. @@ -1344,7 +1342,7 @@ Parser::OwningExprResult Parser::ParseBlockLiteralExpression() { if (Tok.is(tok::l_brace)) { OwningStmtResult Stmt(ParseCompoundStatementBody()); if (!Stmt.isInvalid()) { - Result = Actions.ActOnBlockStmtExpr(CaretLoc, Stmt.release(), CurScope); + Result = Actions.ActOnBlockStmtExpr(CaretLoc, move(Stmt), CurScope); } else { Actions.ActOnBlockError(CaretLoc, CurScope); } diff --git a/lib/Parse/ParseExprCXX.cpp b/lib/Parse/ParseExprCXX.cpp index 50e6657ad8..e1b5db9c44 100644 --- a/lib/Parse/ParseExprCXX.cpp +++ b/lib/Parse/ParseExprCXX.cpp @@ -328,9 +328,9 @@ Parser::OwningExprResult Parser::ParseCXXCasts() { if (!Result.isInvalid() && !CastTy.isInvalid()) Result = Actions.ActOnCXXNamedCast(OpLoc, Kind, - LAngleBracketLoc, CastTy.get(), + LAngleBracketLoc, CastTy.get(), RAngleBracketLoc, - LParenLoc, Result.release(), RParenLoc); + LParenLoc, move(Result), RParenLoc); return move(Result); } @@ -390,7 +390,7 @@ Parser::OwningExprResult Parser::ParseCXXTypeid() { /// 'false' Parser::OwningExprResult Parser::ParseCXXBoolLiteral() { tok::TokenKind Kind = Tok.getKind(); - return Owned(Actions.ActOnCXXBoolLiteral(ConsumeToken(), Kind)); + return Actions.ActOnCXXBoolLiteral(ConsumeToken(), Kind); } /// ParseThrowExpression - This handles the C++ throw expression. @@ -411,12 +411,12 @@ Parser::OwningExprResult Parser::ParseThrowExpression() { case tok::r_brace: case tok::colon: case tok::comma: - return Owned(Actions.ActOnCXXThrow(ThrowLoc)); + return Actions.ActOnCXXThrow(ThrowLoc, ExprArg(Actions)); default: OwningExprResult Expr(ParseAssignmentExpression()); if (Expr.isInvalid()) return move(Expr); - return Owned(Actions.ActOnCXXThrow(ThrowLoc, Expr.release())); + return Actions.ActOnCXXThrow(ThrowLoc, move(Expr)); } } @@ -428,7 +428,7 @@ Parser::OwningExprResult Parser::ParseThrowExpression() { Parser::OwningExprResult Parser::ParseCXXThis() { assert(Tok.is(tok::kw_this) && "Not 'this'!"); SourceLocation ThisLoc = ConsumeToken(); - return Owned(Actions.ActOnCXXThis(ThisLoc)); + return Actions.ActOnCXXThis(ThisLoc); } /// ParseCXXTypeConstructExpression - Parse construction of a specified type. @@ -463,10 +463,9 @@ Parser::ParseCXXTypeConstructExpression(const DeclSpec &DS) { assert((Exprs.size() == 0 || Exprs.size()-1 == CommaLocs.size())&& "Unexpected number of commas!"); - return Owned(Actions.ActOnCXXTypeConstructExpr(DS.getSourceRange(), TypeRep, - LParenLoc, - Exprs.take(), Exprs.size(), - &CommaLocs[0], RParenLoc)); + return Actions.ActOnCXXTypeConstructExpr(DS.getSourceRange(), TypeRep, + LParenLoc, move_arg(Exprs), + &CommaLocs[0], RParenLoc); } /// ParseCXXCondition - if/switch/while/for condition expression. @@ -518,9 +517,9 @@ Parser::OwningExprResult Parser::ParseCXXCondition() { if (AssignExpr.isInvalid()) return ExprError(); - return Owned(Actions.ActOnCXXConditionDeclarationExpr(CurScope, StartLoc, - DeclaratorInfo,EqualLoc, - AssignExpr.release())); + return Actions.ActOnCXXConditionDeclarationExpr(CurScope, StartLoc, + DeclaratorInfo,EqualLoc, + move(AssignExpr)); } /// ParseCXXSimpleTypeSpecifier - [C++ 7.1.5.2] Simple type specifiers. @@ -883,11 +882,10 @@ Parser::ParseCXXNewExpression(bool UseGlobal, SourceLocation Start) { } } - return Owned(Actions.ActOnCXXNew(Start, UseGlobal, PlacementLParen, - PlacementArgs.take(), PlacementArgs.size(), - PlacementRParen, ParenTypeId, DeclaratorInfo, - ConstructorLParen, ConstructorArgs.take(), - ConstructorArgs.size(), ConstructorRParen)); + return Actions.ActOnCXXNew(Start, UseGlobal, PlacementLParen, + move_arg(PlacementArgs), PlacementRParen, + ParenTypeId, DeclaratorInfo, ConstructorLParen, + move_arg(ConstructorArgs), ConstructorRParen); } /// ParseDirectNewDeclarator - Parses a direct-new-declarator. Intended to be @@ -977,8 +975,7 @@ Parser::ParseCXXDeleteExpression(bool UseGlobal, SourceLocation Start) { if (Operand.isInvalid()) return move(Operand); - return Owned(Actions.ActOnCXXDelete(Start, UseGlobal, ArrayDelete, - Operand.release())); + return Actions.ActOnCXXDelete(Start, UseGlobal, ArrayDelete, move(Operand)); } static UnaryTypeTrait UnaryTypeTraitFromTokKind(tok::TokenKind kind) diff --git a/lib/Sema/Sema.h b/lib/Sema/Sema.h index 54b3d197fa..6647945364 100644 --- a/lib/Sema/Sema.h +++ b/lib/Sema/Sema.h @@ -326,9 +326,9 @@ public: bool IsFunctionDefinition, bool& InvalidDecl, bool &Redeclaration); virtual DeclTy *ActOnParamDeclarator(Scope *S, Declarator &D); - virtual void ActOnParamDefaultArgument(DeclTy *param, + virtual void ActOnParamDefaultArgument(DeclTy *param, SourceLocation EqualLoc, - ExprTy *defarg); + ExprArg defarg); virtual void ActOnParamUnparsedDefaultArgument(DeclTy *param, SourceLocation EqualLoc); virtual void ActOnParamDefaultArgumentError(DeclTy *param); @@ -1266,63 +1266,65 @@ public: ExprArg RHS); /// ActOnAddrLabel - Parse the GNU address of label extension: "&&foo". - virtual ExprResult ActOnAddrLabel(SourceLocation OpLoc, SourceLocation LabLoc, - IdentifierInfo *LabelII); - - virtual ExprResult ActOnStmtExpr(SourceLocation LPLoc, StmtTy *SubStmt, - SourceLocation RPLoc); // "({..})" + virtual OwningExprResult ActOnAddrLabel(SourceLocation OpLoc, + SourceLocation LabLoc, + IdentifierInfo *LabelII); + + virtual OwningExprResult ActOnStmtExpr(SourceLocation LPLoc, StmtArg SubStmt, + SourceLocation RPLoc); // "({..})" /// __builtin_offsetof(type, a.b[123][456].c) - virtual ExprResult ActOnBuiltinOffsetOf(Scope *S, - SourceLocation BuiltinLoc, - SourceLocation TypeLoc, TypeTy *Arg1, - OffsetOfComponent *CompPtr, - unsigned NumComponents, - SourceLocation RParenLoc); - + virtual OwningExprResult ActOnBuiltinOffsetOf(Scope *S, + SourceLocation BuiltinLoc, + SourceLocation TypeLoc, + TypeTy *Arg1, + OffsetOfComponent *CompPtr, + unsigned NumComponents, + SourceLocation RParenLoc); + // __builtin_types_compatible_p(type1, type2) - virtual ExprResult ActOnTypesCompatibleExpr(SourceLocation BuiltinLoc, - TypeTy *arg1, TypeTy *arg2, - SourceLocation RPLoc); - + virtual OwningExprResult ActOnTypesCompatibleExpr(SourceLocation BuiltinLoc, + TypeTy *arg1, TypeTy *arg2, + SourceLocation RPLoc); + // __builtin_choose_expr(constExpr, expr1, expr2) - virtual ExprResult ActOnChooseExpr(SourceLocation BuiltinLoc, - ExprTy *cond, ExprTy *expr1, ExprTy *expr2, - SourceLocation RPLoc); - + virtual OwningExprResult ActOnChooseExpr(SourceLocation BuiltinLoc, + ExprArg cond, ExprArg expr1, + ExprArg expr2, SourceLocation RPLoc); + // __builtin_va_arg(expr, type) - virtual ExprResult ActOnVAArg(SourceLocation BuiltinLoc, - ExprTy *expr, TypeTy *type, - SourceLocation RPLoc); + virtual OwningExprResult ActOnVAArg(SourceLocation BuiltinLoc, + ExprArg expr, TypeTy *type, + SourceLocation RPLoc); // __null - virtual ExprResult ActOnGNUNullExpr(SourceLocation TokenLoc); + virtual OwningExprResult ActOnGNUNullExpr(SourceLocation TokenLoc); //===------------------------- "Block" Extension ------------------------===// /// ActOnBlockStart - This callback is invoked when a block literal is /// started. virtual void ActOnBlockStart(SourceLocation CaretLoc, Scope *CurScope); - + /// ActOnBlockArguments - This callback allows processing of block arguments. /// If there are no arguments, this is still invoked. virtual void ActOnBlockArguments(Declarator &ParamInfo, Scope *CurScope); - + /// ActOnBlockError - If there is an error parsing a block, this callback /// is invoked to pop the information about the block from the action impl. virtual void ActOnBlockError(SourceLocation CaretLoc, Scope *CurScope); - + /// ActOnBlockStmtExpr - This is called when the body of a block statement /// literal was successfully completed. ^(int x){...} - virtual ExprResult ActOnBlockStmtExpr(SourceLocation CaretLoc, StmtTy *Body, - Scope *CurScope); + virtual OwningExprResult ActOnBlockStmtExpr(SourceLocation CaretLoc, + StmtArg Body, Scope *CurScope); //===---------------------------- C++ Features --------------------------===// // Act on C++ namespaces virtual DeclTy *ActOnStartNamespaceDef(Scope *S, SourceLocation IdentLoc, - IdentifierInfo *Ident, - SourceLocation LBrace); + IdentifierInfo *Ident, + SourceLocation LBrace); virtual void ActOnFinishNamespaceDef(DeclTy *Dcl, SourceLocation RBrace); virtual DeclTy *ActOnUsingDirective(Scope *CurScope, @@ -1340,7 +1342,7 @@ public: /// e.g: "int x(1);" virtual void AddCXXDirectInitializerToDecl(DeclTy *Dcl, SourceLocation LParenLoc, - ExprTy **Exprs, unsigned NumExprs, + MultiExprArg Exprs, SourceLocation *CommaLocs, SourceLocation RParenLoc); @@ -1360,49 +1362,52 @@ public: InitializationKind Kind); /// ActOnCXXNamedCast - Parse {dynamic,static,reinterpret,const}_cast's. - virtual ExprResult ActOnCXXNamedCast(SourceLocation OpLoc, tok::TokenKind Kind, - SourceLocation LAngleBracketLoc, TypeTy *Ty, - SourceLocation RAngleBracketLoc, - SourceLocation LParenLoc, ExprTy *E, - SourceLocation RParenLoc); + virtual OwningExprResult ActOnCXXNamedCast(SourceLocation OpLoc, + tok::TokenKind Kind, + SourceLocation LAngleBracketLoc, + TypeTy *Ty, + SourceLocation RAngleBracketLoc, + SourceLocation LParenLoc, + ExprArg E, + SourceLocation RParenLoc); - /// ActOnCXXTypeidOfType - Parse typeid( type-id ). - virtual ExprResult ActOnCXXTypeid(SourceLocation OpLoc, - SourceLocation LParenLoc, bool isType, - void *TyOrExpr, SourceLocation RParenLoc); + /// ActOnCXXTypeid - Parse typeid( something ). + virtual OwningExprResult ActOnCXXTypeid(SourceLocation OpLoc, + SourceLocation LParenLoc, bool isType, + void *TyOrExpr, + SourceLocation RParenLoc); //// ActOnCXXThis - Parse 'this' pointer. - virtual ExprResult ActOnCXXThis(SourceLocation ThisLoc); + virtual OwningExprResult ActOnCXXThis(SourceLocation ThisLoc); /// ActOnCXXBoolLiteral - Parse {true,false} literals. - virtual ExprResult ActOnCXXBoolLiteral(SourceLocation OpLoc, - tok::TokenKind Kind); - + virtual OwningExprResult ActOnCXXBoolLiteral(SourceLocation OpLoc, + tok::TokenKind Kind); + //// ActOnCXXThrow - Parse throw expressions. - virtual ExprResult ActOnCXXThrow(SourceLocation OpLoc, - ExprTy *expr); + virtual OwningExprResult ActOnCXXThrow(SourceLocation OpLoc, + ExprArg expr); /// ActOnCXXTypeConstructExpr - Parse construction of a specified type. /// Can be interpreted either as function-style casting ("int(x)") /// or class type construction ("ClassType(x,y,z)") /// or creation of a value-initialized type ("int()"). - virtual ExprResult ActOnCXXTypeConstructExpr(SourceRange TypeRange, - TypeTy *TypeRep, - SourceLocation LParenLoc, - ExprTy **Exprs, - unsigned NumExprs, - SourceLocation *CommaLocs, - SourceLocation RParenLoc); + virtual OwningExprResult ActOnCXXTypeConstructExpr(SourceRange TypeRange, + TypeTy *TypeRep, + SourceLocation LParenLoc, + MultiExprArg Exprs, + SourceLocation *CommaLocs, + SourceLocation RParenLoc); /// ActOnCXXNew - Parsed a C++ 'new' expression. - virtual ExprResult ActOnCXXNew(SourceLocation StartLoc, bool UseGlobal, - SourceLocation PlacementLParen, - ExprTy **PlacementArgs, unsigned NumPlaceArgs, - SourceLocation PlacementRParen, - bool ParenTypeId, Declarator &D, - SourceLocation ConstructorLParen, - ExprTy **ConstructorArgs, unsigned NumConsArgs, - SourceLocation ConstructorRParen); + virtual OwningExprResult ActOnCXXNew(SourceLocation StartLoc, bool UseGlobal, + SourceLocation PlacementLParen, + MultiExprArg PlacementArgs, + SourceLocation PlacementRParen, + bool ParenTypeId, Declarator &D, + SourceLocation ConstructorLParen, + MultiExprArg ConstructorArgs, + SourceLocation ConstructorRParen); bool CheckAllocatedType(QualType AllocType, const Declarator &D); bool FindAllocationFunctions(SourceLocation StartLoc, SourceRange Range, bool UseGlobal, QualType AllocType, bool IsArray, @@ -1418,17 +1423,18 @@ public: QualType Argument); /// ActOnCXXDelete - Parsed a C++ 'delete' expression - virtual ExprResult ActOnCXXDelete(SourceLocation StartLoc, bool UseGlobal, - bool ArrayForm, ExprTy *Operand); + virtual OwningExprResult ActOnCXXDelete(SourceLocation StartLoc, + bool UseGlobal, bool ArrayForm, + ExprArg Operand); /// ActOnCXXConditionDeclarationExpr - Parsed a condition declaration of a /// C++ if/switch/while/for statement. /// e.g: "if (int x = f()) {...}" - virtual ExprResult ActOnCXXConditionDeclarationExpr(Scope *S, + virtual OwningExprResult ActOnCXXConditionDeclarationExpr(Scope *S, SourceLocation StartLoc, Declarator &D, SourceLocation EqualLoc, - ExprTy *AssignExprVal); + ExprArg AssignExprVal); /// ActOnUnaryTypeTrait - Parsed one of the unary type trait support /// pseudo-functions. diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index 0123fe0af2..177eee2a53 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -105,9 +105,9 @@ namespace { /// to the parameter declaration. void Sema::ActOnParamDefaultArgument(DeclTy *param, SourceLocation EqualLoc, - ExprTy *defarg) { + ExprArg defarg) { ParmVarDecl *Param = (ParmVarDecl *)param; - ExprOwningPtr<Expr> DefaultArg(this, (Expr *)defarg); + ExprOwningPtr<Expr> DefaultArg(this, (Expr *)defarg.release()); QualType ParamType = Param->getType(); // Default arguments are only permitted in C++ @@ -1448,17 +1448,16 @@ void Sema::PushUsingDirective(Scope *S, UsingDirectiveDecl *UDir) { /// ActOnDeclarator, when a C++ direct initializer is present. /// e.g: "int x(1);" void Sema::AddCXXDirectInitializerToDecl(DeclTy *Dcl, SourceLocation LParenLoc, - ExprTy **ExprTys, unsigned NumExprs, + MultiExprArg Exprs, SourceLocation *CommaLocs, SourceLocation RParenLoc) { - assert(NumExprs != 0 && ExprTys && "missing expressions"); + unsigned NumExprs = Exprs.size(); + assert(NumExprs != 0 && Exprs.get() && "missing expressions"); Decl *RealDecl = static_cast<Decl *>(Dcl); // If there is no declaration, there was an error parsing it. Just ignore // the initializer. if (RealDecl == 0) { - for (unsigned i = 0; i != NumExprs; ++i) - static_cast<Expr *>(ExprTys[i])->Destroy(Context); return; } @@ -1489,16 +1488,17 @@ void Sema::AddCXXDirectInitializerToDecl(DeclTy *Dcl, SourceLocation LParenLoc, if (VDecl->getType()->isRecordType()) { CXXConstructorDecl *Constructor - = PerformInitializationByConstructor(DeclInitType, - (Expr **)ExprTys, NumExprs, + = PerformInitializationByConstructor(DeclInitType, + (Expr **)Exprs.get(), NumExprs, VDecl->getLocation(), SourceRange(VDecl->getLocation(), RParenLoc), VDecl->getDeclName(), IK_Direct); - if (!Constructor) { + if (!Constructor) RealDecl->setInvalidDecl(); - } + else + Exprs.release(); // Let clients know that initialization was done with a direct // initializer. @@ -1521,7 +1521,8 @@ void Sema::AddCXXDirectInitializerToDecl(DeclTy *Dcl, SourceLocation LParenLoc, assert(NumExprs == 1 && "Expected 1 expression"); // Set the init expression, handles conversions. - AddInitializerToDecl(Dcl, ExprArg(*this, ExprTys[0]), /*DirectInit=*/true); + AddInitializerToDecl(Dcl, ExprArg(*this, Exprs.release()[0]), + /*DirectInit=*/true); } /// PerformInitializationByConstructor - Perform initialization by diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index c3ae4f7f67..0893bc7fb3 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -4152,9 +4152,9 @@ Action::OwningExprResult Sema::ActOnUnaryOp(Scope *S, SourceLocation OpLoc, } /// ActOnAddrLabel - Parse the GNU address of label extension: "&&foo". -Sema::ExprResult Sema::ActOnAddrLabel(SourceLocation OpLoc, - SourceLocation LabLoc, - IdentifierInfo *LabelII) { +Sema::OwningExprResult Sema::ActOnAddrLabel(SourceLocation OpLoc, + SourceLocation LabLoc, + IdentifierInfo *LabelII) { // Look up the record for this label identifier. LabelStmt *&LabelDecl = CurBlock ? CurBlock->LabelMap[LabelII] : LabelMap[LabelII]; @@ -4165,19 +4165,20 @@ Sema::ExprResult Sema::ActOnAddrLabel(SourceLocation OpLoc, LabelDecl = new (Context) LabelStmt(LabLoc, LabelII, 0); // Create the AST node. The address of a label always has type 'void*'. - return new (Context) AddrLabelExpr(OpLoc, LabLoc, LabelDecl, - Context.getPointerType(Context.VoidTy)); + return Owned(new (Context) AddrLabelExpr(OpLoc, LabLoc, LabelDecl, + Context.getPointerType(Context.VoidTy))); } -Sema::ExprResult Sema::ActOnStmtExpr(SourceLocation LPLoc, StmtTy *substmt, - SourceLocation RPLoc) { // "({..})" - Stmt *SubStmt = static_cast<Stmt*>(substmt); +Sema::OwningExprResult +Sema::ActOnStmtExpr(SourceLocation LPLoc, StmtArg substmt, + SourceLocation RPLoc) { // "({..})" + Stmt *SubStmt = static_cast<Stmt*>(substmt.get()); assert(SubStmt && isa<CompoundStmt>(SubStmt) && "Invalid action invocation!"); CompoundStmt *Compound = cast<CompoundStmt>(SubStmt); bool isFileScope = getCurFunctionOrMethodDecl() == 0; if (isFileScope) { - return Diag(LPLoc, diag::err_stmtexpr_file_scope); + return ExprError(Diag(LPLoc, diag::err_stmtexpr_file_scope)); } // FIXME: there are a variety of strange constraints to enforce here, for @@ -4201,16 +4202,19 @@ Sema::ExprResult Sema::ActOnStmtExpr(SourceLocation LPLoc, StmtTy *substmt, Ty = LastExpr->getType(); } - return new (Context) StmtExpr(Compound, Ty, LPLoc, RPLoc); + substmt.release(); + return Owned(new (Context) StmtExpr(Compound, Ty, LPLoc, RPLoc)); } -Sema::ExprResult Sema::ActOnBuiltinOffsetOf(Scope *S, - SourceLocation BuiltinLoc, - SourceLocation TypeLoc, - TypeTy *argty, - OffsetOfComponent *CompPtr, - unsigned NumComponents, - SourceLocation RPLoc) { +Sema::OwningExprResult Sema::ActOnBuiltinOffsetOf(Scope *S, + SourceLocation BuiltinLoc, + SourceLocation TypeLoc, + TypeTy *argty, + OffsetOfComponent *CompPtr, + unsigned NumComponents, + SourceLocation RPLoc) { + // FIXME: This function leaks all expressions in the offset components on + // error. QualType ArgTy = QualType::getFromOpaquePtr(argty); assert(!ArgTy.isNull() && "Missing type argument!"); @@ -4220,7 +4224,7 @@ Sema::ExprResult Sema::ActOnBuiltinOffsetOf(Scope *S, // one is known to be a field designator. Verify that the ArgTy represents // a struct/union/class. if (!Dependent && !ArgTy->isRecordType()) - return Diag(TypeLoc, diag::err_offsetof_record_type) << ArgTy; + return ExprError(Diag(TypeLoc, diag::err_offsetof_record_type) << ArgTy); // FIXME: Does the type need to be complete? @@ -4228,7 +4232,7 @@ Sema::ExprResult Sema::ActOnBuiltinOffsetOf(Scope *S, // the offsetof designators. QualType ArgTyPtr = Context.getPointerType(ArgTy); Expr* Res = new (Context) ImplicitValueInitExpr(ArgTyPtr); - Res = new (Context) UnaryOperator(Res, UnaryOperator::Deref, + Res = new (Context) UnaryOperator(Res, UnaryOperator::Deref, ArgTy, SourceLocation()); // offsetof with non-identifier designators (e.g. "offsetof(x, a.b[c])") are a @@ -4249,8 +4253,8 @@ Sema::ExprResult Sema::ActOnBuiltinOffsetOf(Scope *S, const ArrayType *AT = Context.getAsArrayType(Res->getType()); if (!AT) { Res->Destroy(Context); - return Diag(OC.LocEnd, diag::err_offsetof_array_type) - << Res->getType(); + return ExprError(Diag(OC.LocEnd, diag::err_offsetof_array_type) + << Res->getType()); } // FIXME: C++: Verify that operator[] isn't overloaded. @@ -4261,9 +4265,11 @@ Sema::ExprResult Sema::ActOnBuiltinOffsetOf(Scope *S, // C99 6.5.2.1p1 Expr *Idx = static_cast<Expr*>(OC.U.E); + // FIXME: Leaks Res if (!Idx->isTypeDependent() && !Idx->getType()->isIntegerType()) - return Diag(Idx->getLocStart(), diag::err_typecheck_subscript) - << Idx->getSourceRange(); + return ExprError(Diag(Idx->getLocStart(), + diag::err_typecheck_subscript) + << Idx->getSourceRange()); Res = new (Context) ArraySubscriptExpr(Res, Idx, AT->getElementType(), OC.LocEnd); @@ -4273,8 +4279,8 @@ Sema::ExprResult Sema::ActOnBuiltinOffsetOf(Scope *S, const RecordType *RC = Res->getType()->getAsRecordType(); if (!RC) { Res->Destroy(Context); - return Diag(OC.LocEnd, diag::err_offsetof_record_type) - << Res->getType(); + return ExprError(Diag(OC.LocEnd, diag::err_offsetof_record_type) + << Res->getType()); } // Get the decl corresponding to this. @@ -4283,9 +4289,10 @@ Sema::ExprResult Sema::ActOnBuiltinOffsetOf(Scope *S, = dyn_cast_or_null<FieldDecl>(LookupQualifiedName(RD, OC.U.IdentInfo, LookupMemberName) .getAsDecl()); + // FIXME: Leaks Res if (!MemberDecl) - return Diag(BuiltinLoc, diag::err_typecheck_no_member) - << OC.U.IdentInfo << SourceRange(OC.LocStart, OC.LocEnd); + return ExprError(Diag(BuiltinLoc, diag::err_typecheck_no_member) + << OC.U.IdentInfo << SourceRange(OC.LocStart, OC.LocEnd)); // FIXME: C++: Verify that MemberDecl isn't a static field. // FIXME: Verify that MemberDecl isn't a bitfield. @@ -4296,29 +4303,30 @@ Sema::ExprResult Sema::ActOnBuiltinOffsetOf(Scope *S, } } - return new (Context) UnaryOperator(Res, UnaryOperator::OffsetOf, - Context.getSizeType(), BuiltinLoc); + return Owned(new (Context) UnaryOperator(Res, UnaryOperator::OffsetOf, + Context.getSizeType(), BuiltinLoc)); } -Sema::ExprResult Sema::ActOnTypesCompatibleExpr(SourceLocation BuiltinLoc, - TypeTy *arg1, TypeTy *arg2, - SourceLocation RPLoc) { +Sema::OwningExprResult Sema::ActOnTypesCompatibleExpr(SourceLocation BuiltinLoc, + TypeTy *arg1,TypeTy *arg2, + SourceLocation RPLoc) { QualType argT1 = QualType::getFromOpaquePtr(arg1); QualType argT2 = QualType::getFromOpaquePtr(arg2); assert((!argT1.isNull() && !argT2.isNull()) && "Missing type argument(s)"); - return new (Context) TypesCompatibleExpr(Context.IntTy, BuiltinLoc, argT1, - argT2, RPLoc); + return Owned(new (Context) TypesCompatibleExpr(Context.IntTy, BuiltinLoc, + argT1, argT2, RPLoc)); } -Sema::ExprResult Sema::ActOnChooseExpr(SourceLocation BuiltinLoc, ExprTy *cond, - ExprTy *expr1, ExprTy *expr2, - SourceLocation RPLoc) { - Expr *CondExpr = static_cast<Expr*>(cond); - Expr *LHSExpr = static_cast<Expr*>(expr1); - Expr *RHSExpr = static_cast<Expr*>(expr2); +Sema::OwningExprResult Sema::ActOnChooseExpr(SourceLocation BuiltinLoc, + ExprArg cond, + ExprArg expr1, ExprArg expr2, + SourceLocation RPLoc) { + Expr *CondExpr = static_cast<Expr*>(cond.get()); + Expr *LHSExpr = static_cast<Expr*>(expr1.get()); + Expr *RHSExpr = static_cast<Expr*>(expr2.get()); assert((CondExpr && LHSExpr && RHSExpr) && "Missing type argument(s)"); @@ -4330,15 +4338,17 @@ Sema::ExprResult Sema::ActOnChooseExpr(SourceLocation BuiltinLoc, ExprTy *cond, llvm::APSInt condEval(32); SourceLocation ExpLoc; if (!CondExpr->isIntegerConstantExpr(condEval, Context, &ExpLoc)) - return Diag(ExpLoc, diag::err_typecheck_choose_expr_requires_constant) - << CondExpr->getSourceRange(); + return ExprError(Diag(ExpLoc, + diag::err_typecheck_choose_expr_requires_constant) + << CondExpr->getSourceRange()); // If the condition is > zero, then the AST type is the same as the LSHExpr. resType = condEval.getZExtValue() ? LHSExpr->getType() : RHSExpr->getType(); } - return new (Context) ChooseExpr(BuiltinLoc, CondExpr, LHSExpr, RHSExpr, - resType, RPLoc); + cond.release(); expr1.release(); expr2.release(); + return Owned(new (Context) ChooseExpr(BuiltinLoc, CondExpr, LHSExpr, RHSExpr, + resType, RPLoc)); } //===----------------------------------------------------------------------===// @@ -4440,11 +4450,10 @@ 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::ExprResult Sema::ActOnBlockStmtExpr(SourceLocation CaretLoc, StmtTy *body, - Scope *CurScope) { +Sema::OwningExprResult Sema::ActOnBlockStmtExpr(SourceLocation CaretLoc, + StmtArg body, Scope *CurScope) { // Ensure that CurBlock is deleted. llvm::OwningPtr<BlockSemaInfo> BSI(CurBlock); - ExprO |