From b781bcdc3053e67769c062adc684ac0b07d3160f Mon Sep 17 00:00:00 2001 From: Anders Carlsson Date: Fri, 1 May 2009 19:49:17 +0000 Subject: [PATCH] Replace more release+static_cast with takeAs. llvm-svn: 70567 --- clang/lib/Sema/SemaExpr.cpp | 9 +++-- clang/lib/Sema/SemaInit.cpp | 3 +- clang/lib/Sema/SemaNamedCast.cpp | 2 +- clang/lib/Sema/SemaStmt.cpp | 33 +++++++++---------- clang/lib/Sema/SemaTemplate.cpp | 2 +- clang/lib/Sema/SemaTemplateInstantiate.cpp | 2 +- .../lib/Sema/SemaTemplateInstantiateDecl.cpp | 2 +- 7 files changed, 25 insertions(+), 28 deletions(-) diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 5c0c33b298c5..8e54ef77b58f 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -719,8 +719,7 @@ Sema::ActOnDeclarationNameExpr(Scope *S, SourceLocation Loc, OwningExprResult SelfExpr = ActOnIdentifierExpr(S, Loc, II, false); return Owned(new (Context) ObjCIvarRefExpr(IV, IV->getType(), Loc, - static_cast(SelfExpr.release()), - true, true)); + SelfExpr.takeAs(), true, true)); } } } @@ -1221,7 +1220,7 @@ Action::OwningExprResult Sema::ActOnNumericConstant(const Token &Tok) { Action::OwningExprResult Sema::ActOnParenExpr(SourceLocation L, SourceLocation R, ExprArg Val) { - Expr *E = (Expr *)Val.release(); + Expr *E = Val.takeAs(); assert((E != 0) && "ActOnParenExpr() missing expr"); return Owned(new (Context) ParenExpr(L, R, E)); } @@ -4423,7 +4422,7 @@ Action::OwningExprResult Sema::ActOnBinOp(Scope *S, SourceLocation TokLoc, tok::TokenKind Kind, ExprArg LHS, ExprArg RHS) { BinaryOperator::Opcode Opc = ConvertTokenKindToBinaryOpcode(Kind); - Expr *lhs = (Expr *)LHS.release(), *rhs = (Expr*)RHS.release(); + Expr *lhs = LHS.takeAs(), *rhs = RHS.takeAs(); assert((lhs != 0) && "ActOnBinOp(): missing left expression"); assert((rhs != 0) && "ActOnBinOp(): missing right expression"); @@ -4926,7 +4925,7 @@ Sema::OwningExprResult Sema::ActOnBlockStmtExpr(SourceLocation CaretLoc, DiagnoseInvalidJumps(static_cast(body.get())); CurFunctionNeedsScopeChecking = BSI->SavedFunctionNeedsScopeChecking; - BSI->TheDecl->setBody(static_cast(body.release())); + BSI->TheDecl->setBody(body.takeAs()); return Owned(new (Context) BlockExpr(BSI->TheDecl, BlockTy, BSI->hasBlockDeclRefExprs)); } diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp index a622ef3796f9..36b0e3b13506 100644 --- a/clang/lib/Sema/SemaInit.cpp +++ b/clang/lib/Sema/SemaInit.cpp @@ -1691,8 +1691,7 @@ Sema::OwningExprResult Sema::ActOnDesignatedInitializer(Designation &Desig, DesignatedInitExpr *DIE = DesignatedInitExpr::Create(Context, &Designators[0], Designators.size(), &InitExpressions[0], InitExpressions.size(), - Loc, GNUSyntax, - static_cast(Init.release())); + Loc, GNUSyntax, Init.takeAs()); return Owned(DIE); } diff --git a/clang/lib/Sema/SemaNamedCast.cpp b/clang/lib/Sema/SemaNamedCast.cpp index 8c45fe627864..f5bef4a1f2d0 100644 --- a/clang/lib/Sema/SemaNamedCast.cpp +++ b/clang/lib/Sema/SemaNamedCast.cpp @@ -63,7 +63,7 @@ Sema::ActOnCXXNamedCast(SourceLocation OpLoc, tok::TokenKind Kind, SourceLocation RAngleBracketLoc, SourceLocation LParenLoc, ExprArg E, SourceLocation RParenLoc) { - Expr *Ex = (Expr*)E.release(); + Expr *Ex = E.takeAs(); QualType DestType = QualType::getFromOpaquePtr(Ty); SourceRange OpRange(OpLoc, RParenLoc); SourceRange DestRange(LAngleBracketLoc, RAngleBracketLoc); diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp index d7fd5f054d07..243b5695c393 100644 --- a/clang/lib/Sema/SemaStmt.cpp +++ b/clang/lib/Sema/SemaStmt.cpp @@ -180,7 +180,7 @@ Action::OwningStmtResult Sema::ActOnIfStmt(SourceLocation IfLoc, ExprArg CondVal, StmtArg ThenVal, SourceLocation ElseLoc, StmtArg ElseVal) { - Expr *condExpr = (Expr *)CondVal.release(); + Expr *condExpr = CondVal.takeAs(); assert(condExpr && "ActOnIfStmt(): missing expression"); @@ -196,7 +196,7 @@ Sema::ActOnIfStmt(SourceLocation IfLoc, ExprArg CondVal, return StmtError(Diag(IfLoc, diag::err_typecheck_statement_requires_scalar) << condType << condExpr->getSourceRange()); - Stmt *thenStmt = (Stmt *)ThenVal.release(); + Stmt *thenStmt = ThenVal.takeAs(); // Warn if the if block has a null body without an else value. // this helps prevent bugs due to typos, such as @@ -209,7 +209,7 @@ Sema::ActOnIfStmt(SourceLocation IfLoc, ExprArg CondVal, CondVal.release(); return Owned(new (Context) IfStmt(IfLoc, condExpr, thenStmt, - (Stmt*)ElseVal.release())); + ElseVal.takeAs())); } Action::OwningStmtResult @@ -324,7 +324,7 @@ static bool CmpCaseVals(const std::pair& lhs, Action::OwningStmtResult Sema::ActOnFinishSwitchStmt(SourceLocation SwitchLoc, StmtArg Switch, StmtArg Body) { - Stmt *BodyStmt = (Stmt*)Body.release(); + Stmt *BodyStmt = Body.takeAs(); SwitchStmt *SS = getSwitchStack().back(); assert(SS == (SwitchStmt*)Switch.get() && "switch stack missing push/pop!"); @@ -514,7 +514,7 @@ Sema::ActOnFinishSwitchStmt(SourceLocation SwitchLoc, StmtArg Switch, Action::OwningStmtResult Sema::ActOnWhileStmt(SourceLocation WhileLoc, ExprArg Cond, StmtArg Body) { - Expr *condExpr = (Expr *)Cond.release(); + Expr *condExpr = Cond.takeAs(); assert(condExpr && "ActOnWhileStmt(): missing expression"); DefaultFunctionArrayConversion(condExpr); @@ -530,14 +530,14 @@ Sema::ActOnWhileStmt(SourceLocation WhileLoc, ExprArg Cond, StmtArg Body) { << condType << condExpr->getSourceRange()); Cond.release(); - return Owned(new (Context) WhileStmt(condExpr, (Stmt*)Body.release(), + return Owned(new (Context) WhileStmt(condExpr, Body.takeAs(), WhileLoc)); } Action::OwningStmtResult Sema::ActOnDoStmt(SourceLocation DoLoc, StmtArg Body, SourceLocation WhileLoc, ExprArg Cond) { - Expr *condExpr = (Expr *)Cond.release(); + Expr *condExpr = Cond.takeAs(); assert(condExpr && "ActOnDoStmt(): missing expression"); DefaultFunctionArrayConversion(condExpr); @@ -552,7 +552,7 @@ Sema::ActOnDoStmt(SourceLocation DoLoc, StmtArg Body, << condType << condExpr->getSourceRange()); Cond.release(); - return Owned(new (Context) DoStmt((Stmt*)Body.release(), condExpr, DoLoc)); + return Owned(new (Context) DoStmt(Body.takeAs(), condExpr, DoLoc)); } Action::OwningStmtResult @@ -1069,7 +1069,7 @@ Sema::ActOnObjCAtCatchStmt(SourceLocation AtLoc, } ObjCAtCatchStmt *CS = new (Context) ObjCAtCatchStmt(AtLoc, RParen, - PVD, static_cast(Body.release()), CatchList); + PVD, Body.takeAs(), CatchList); return Owned(CatchList ? CatchList : CS); } @@ -1083,10 +1083,9 @@ Action::OwningStmtResult Sema::ActOnObjCAtTryStmt(SourceLocation AtLoc, StmtArg Try, StmtArg Catch, StmtArg Finally) { CurFunctionNeedsScopeChecking = true; - return Owned(new (Context) ObjCAtTryStmt(AtLoc, - static_cast(Try.release()), - static_cast(Catch.release()), - static_cast(Finally.release()))); + return Owned(new (Context) ObjCAtTryStmt(AtLoc, Try.takeAs(), + Catch.takeAs(), + Finally.takeAs())); } Action::OwningStmtResult @@ -1127,9 +1126,9 @@ Sema::ActOnObjCAtSynchronizedStmt(SourceLocation AtLoc, ExprArg SynchExpr, << SyncExpr->getType() << SyncExpr->getSourceRange()); } - return Owned(new (Context) ObjCAtSynchronizedStmt(AtLoc, - static_cast(SynchExpr.release()), - static_cast(SynchBody.release()))); + return Owned(new (Context) ObjCAtSynchronizedStmt(AtLoc, + SynchExpr.takeAs(), + SynchBody.takeAs())); } /// ActOnCXXCatchBlock - Takes an exception declaration and a handler block @@ -1140,7 +1139,7 @@ Sema::ActOnCXXCatchBlock(SourceLocation CatchLoc, DeclPtrTy ExDecl, // There's nothing to test that ActOnExceptionDecl didn't already test. return Owned(new (Context) CXXCatchStmt(CatchLoc, cast_or_null(ExDecl.getAs()), - static_cast(HandlerBlock.release()))); + HandlerBlock.takeAs())); } /// ActOnCXXTryBlock - Takes a try compound-statement and a number of diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp index 6e6021ae948f..43713e11f18c 100644 --- a/clang/lib/Sema/SemaTemplate.cpp +++ b/clang/lib/Sema/SemaTemplate.cpp @@ -302,7 +302,7 @@ void Sema::ActOnNonTypeTemplateParameterDefault(DeclPtrTy TemplateParamD, return; } - TemplateParm->setDefaultArgument(static_cast(DefaultE.release())); + TemplateParm->setDefaultArgument(DefaultE.takeAs()); } diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp b/clang/lib/Sema/SemaTemplateInstantiate.cpp index 137868291997..ac8f293a8031 100644 --- a/clang/lib/Sema/SemaTemplateInstantiate.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp @@ -303,7 +303,7 @@ InstantiateDependentSizedArrayType(const DependentSizedArrayType *T, return QualType(); return SemaRef.BuildArrayType(ElementType, T->getSizeModifier(), - (Expr *)InstantiatedArraySize.release(), + InstantiatedArraySize.takeAs(), T->getIndexTypeQualifier(), Loc, Entity); } diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp index d7e81127a753..62c717b6d3df 100644 --- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -171,7 +171,7 @@ Decl *TemplateDeclInstantiator::VisitFieldDecl(FieldDecl *D) { Invalid = true; BitWidth = 0; } else - BitWidth = (Expr *)InstantiatedBitWidth.release(); + BitWidth = InstantiatedBitWidth.takeAs(); } FieldDecl *Field = SemaRef.CheckFieldDecl(D->getDeclName(), T,