Replace more release+static_cast with takeAs.

llvm-svn: 70567
This commit is contained in:
Anders Carlsson 2009-05-01 19:49:17 +00:00
parent 3cbc85985a
commit b781bcdc30
7 changed files with 25 additions and 28 deletions

View File

@ -719,8 +719,7 @@ Sema::ActOnDeclarationNameExpr(Scope *S, SourceLocation Loc,
OwningExprResult SelfExpr = ActOnIdentifierExpr(S, Loc, II, false); OwningExprResult SelfExpr = ActOnIdentifierExpr(S, Loc, II, false);
return Owned(new (Context) return Owned(new (Context)
ObjCIvarRefExpr(IV, IV->getType(), Loc, ObjCIvarRefExpr(IV, IV->getType(), Loc,
static_cast<Expr*>(SelfExpr.release()), SelfExpr.takeAs<Expr>(), true, true));
true, true));
} }
} }
} }
@ -1221,7 +1220,7 @@ Action::OwningExprResult Sema::ActOnNumericConstant(const Token &Tok) {
Action::OwningExprResult Sema::ActOnParenExpr(SourceLocation L, Action::OwningExprResult Sema::ActOnParenExpr(SourceLocation L,
SourceLocation R, ExprArg Val) { SourceLocation R, ExprArg Val) {
Expr *E = (Expr *)Val.release(); Expr *E = Val.takeAs<Expr>();
assert((E != 0) && "ActOnParenExpr() missing expr"); assert((E != 0) && "ActOnParenExpr() missing expr");
return Owned(new (Context) ParenExpr(L, R, E)); return Owned(new (Context) ParenExpr(L, R, E));
} }
@ -4423,7 +4422,7 @@ Action::OwningExprResult Sema::ActOnBinOp(Scope *S, SourceLocation TokLoc,
tok::TokenKind Kind, tok::TokenKind Kind,
ExprArg LHS, ExprArg RHS) { ExprArg LHS, ExprArg RHS) {
BinaryOperator::Opcode Opc = ConvertTokenKindToBinaryOpcode(Kind); BinaryOperator::Opcode Opc = ConvertTokenKindToBinaryOpcode(Kind);
Expr *lhs = (Expr *)LHS.release(), *rhs = (Expr*)RHS.release(); Expr *lhs = LHS.takeAs<Expr>(), *rhs = RHS.takeAs<Expr>();
assert((lhs != 0) && "ActOnBinOp(): missing left expression"); assert((lhs != 0) && "ActOnBinOp(): missing left expression");
assert((rhs != 0) && "ActOnBinOp(): missing right expression"); assert((rhs != 0) && "ActOnBinOp(): missing right expression");
@ -4926,7 +4925,7 @@ Sema::OwningExprResult Sema::ActOnBlockStmtExpr(SourceLocation CaretLoc,
DiagnoseInvalidJumps(static_cast<CompoundStmt*>(body.get())); DiagnoseInvalidJumps(static_cast<CompoundStmt*>(body.get()));
CurFunctionNeedsScopeChecking = BSI->SavedFunctionNeedsScopeChecking; CurFunctionNeedsScopeChecking = BSI->SavedFunctionNeedsScopeChecking;
BSI->TheDecl->setBody(static_cast<CompoundStmt*>(body.release())); BSI->TheDecl->setBody(body.takeAs<CompoundStmt>());
return Owned(new (Context) BlockExpr(BSI->TheDecl, BlockTy, return Owned(new (Context) BlockExpr(BSI->TheDecl, BlockTy,
BSI->hasBlockDeclRefExprs)); BSI->hasBlockDeclRefExprs));
} }

View File

@ -1691,8 +1691,7 @@ Sema::OwningExprResult Sema::ActOnDesignatedInitializer(Designation &Desig,
DesignatedInitExpr *DIE DesignatedInitExpr *DIE
= DesignatedInitExpr::Create(Context, &Designators[0], Designators.size(), = DesignatedInitExpr::Create(Context, &Designators[0], Designators.size(),
&InitExpressions[0], InitExpressions.size(), &InitExpressions[0], InitExpressions.size(),
Loc, GNUSyntax, Loc, GNUSyntax, Init.takeAs<Expr>());
static_cast<Expr *>(Init.release()));
return Owned(DIE); return Owned(DIE);
} }

View File

@ -63,7 +63,7 @@ Sema::ActOnCXXNamedCast(SourceLocation OpLoc, tok::TokenKind Kind,
SourceLocation RAngleBracketLoc, SourceLocation RAngleBracketLoc,
SourceLocation LParenLoc, ExprArg E, SourceLocation LParenLoc, ExprArg E,
SourceLocation RParenLoc) { SourceLocation RParenLoc) {
Expr *Ex = (Expr*)E.release(); Expr *Ex = E.takeAs<Expr>();
QualType DestType = QualType::getFromOpaquePtr(Ty); QualType DestType = QualType::getFromOpaquePtr(Ty);
SourceRange OpRange(OpLoc, RParenLoc); SourceRange OpRange(OpLoc, RParenLoc);
SourceRange DestRange(LAngleBracketLoc, RAngleBracketLoc); SourceRange DestRange(LAngleBracketLoc, RAngleBracketLoc);

View File

@ -180,7 +180,7 @@ Action::OwningStmtResult
Sema::ActOnIfStmt(SourceLocation IfLoc, ExprArg CondVal, Sema::ActOnIfStmt(SourceLocation IfLoc, ExprArg CondVal,
StmtArg ThenVal, SourceLocation ElseLoc, StmtArg ThenVal, SourceLocation ElseLoc,
StmtArg ElseVal) { StmtArg ElseVal) {
Expr *condExpr = (Expr *)CondVal.release(); Expr *condExpr = CondVal.takeAs<Expr>();
assert(condExpr && "ActOnIfStmt(): missing expression"); 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) return StmtError(Diag(IfLoc, diag::err_typecheck_statement_requires_scalar)
<< condType << condExpr->getSourceRange()); << condType << condExpr->getSourceRange());
Stmt *thenStmt = (Stmt *)ThenVal.release(); Stmt *thenStmt = ThenVal.takeAs<Stmt>();
// Warn if the if block has a null body without an else value. // Warn if the if block has a null body without an else value.
// this helps prevent bugs due to typos, such as // this helps prevent bugs due to typos, such as
@ -209,7 +209,7 @@ Sema::ActOnIfStmt(SourceLocation IfLoc, ExprArg CondVal,
CondVal.release(); CondVal.release();
return Owned(new (Context) IfStmt(IfLoc, condExpr, thenStmt, return Owned(new (Context) IfStmt(IfLoc, condExpr, thenStmt,
(Stmt*)ElseVal.release())); ElseVal.takeAs<Stmt>()));
} }
Action::OwningStmtResult Action::OwningStmtResult
@ -324,7 +324,7 @@ static bool CmpCaseVals(const std::pair<llvm::APSInt, CaseStmt*>& lhs,
Action::OwningStmtResult Action::OwningStmtResult
Sema::ActOnFinishSwitchStmt(SourceLocation SwitchLoc, StmtArg Switch, Sema::ActOnFinishSwitchStmt(SourceLocation SwitchLoc, StmtArg Switch,
StmtArg Body) { StmtArg Body) {
Stmt *BodyStmt = (Stmt*)Body.release(); Stmt *BodyStmt = Body.takeAs<Stmt>();
SwitchStmt *SS = getSwitchStack().back(); SwitchStmt *SS = getSwitchStack().back();
assert(SS == (SwitchStmt*)Switch.get() && "switch stack missing push/pop!"); assert(SS == (SwitchStmt*)Switch.get() && "switch stack missing push/pop!");
@ -514,7 +514,7 @@ Sema::ActOnFinishSwitchStmt(SourceLocation SwitchLoc, StmtArg Switch,
Action::OwningStmtResult Action::OwningStmtResult
Sema::ActOnWhileStmt(SourceLocation WhileLoc, ExprArg Cond, StmtArg Body) { Sema::ActOnWhileStmt(SourceLocation WhileLoc, ExprArg Cond, StmtArg Body) {
Expr *condExpr = (Expr *)Cond.release(); Expr *condExpr = Cond.takeAs<Expr>();
assert(condExpr && "ActOnWhileStmt(): missing expression"); assert(condExpr && "ActOnWhileStmt(): missing expression");
DefaultFunctionArrayConversion(condExpr); DefaultFunctionArrayConversion(condExpr);
@ -530,14 +530,14 @@ Sema::ActOnWhileStmt(SourceLocation WhileLoc, ExprArg Cond, StmtArg Body) {
<< condType << condExpr->getSourceRange()); << condType << condExpr->getSourceRange());
Cond.release(); Cond.release();
return Owned(new (Context) WhileStmt(condExpr, (Stmt*)Body.release(), return Owned(new (Context) WhileStmt(condExpr, Body.takeAs<Stmt>(),
WhileLoc)); WhileLoc));
} }
Action::OwningStmtResult Action::OwningStmtResult
Sema::ActOnDoStmt(SourceLocation DoLoc, StmtArg Body, Sema::ActOnDoStmt(SourceLocation DoLoc, StmtArg Body,
SourceLocation WhileLoc, ExprArg Cond) { SourceLocation WhileLoc, ExprArg Cond) {
Expr *condExpr = (Expr *)Cond.release(); Expr *condExpr = Cond.takeAs<Expr>();
assert(condExpr && "ActOnDoStmt(): missing expression"); assert(condExpr && "ActOnDoStmt(): missing expression");
DefaultFunctionArrayConversion(condExpr); DefaultFunctionArrayConversion(condExpr);
@ -552,7 +552,7 @@ Sema::ActOnDoStmt(SourceLocation DoLoc, StmtArg Body,
<< condType << condExpr->getSourceRange()); << condType << condExpr->getSourceRange());
Cond.release(); Cond.release();
return Owned(new (Context) DoStmt((Stmt*)Body.release(), condExpr, DoLoc)); return Owned(new (Context) DoStmt(Body.takeAs<Stmt>(), condExpr, DoLoc));
} }
Action::OwningStmtResult Action::OwningStmtResult
@ -1069,7 +1069,7 @@ Sema::ActOnObjCAtCatchStmt(SourceLocation AtLoc,
} }
ObjCAtCatchStmt *CS = new (Context) ObjCAtCatchStmt(AtLoc, RParen, ObjCAtCatchStmt *CS = new (Context) ObjCAtCatchStmt(AtLoc, RParen,
PVD, static_cast<Stmt*>(Body.release()), CatchList); PVD, Body.takeAs<Stmt>(), CatchList);
return Owned(CatchList ? CatchList : CS); return Owned(CatchList ? CatchList : CS);
} }
@ -1083,10 +1083,9 @@ Action::OwningStmtResult
Sema::ActOnObjCAtTryStmt(SourceLocation AtLoc, Sema::ActOnObjCAtTryStmt(SourceLocation AtLoc,
StmtArg Try, StmtArg Catch, StmtArg Finally) { StmtArg Try, StmtArg Catch, StmtArg Finally) {
CurFunctionNeedsScopeChecking = true; CurFunctionNeedsScopeChecking = true;
return Owned(new (Context) ObjCAtTryStmt(AtLoc, return Owned(new (Context) ObjCAtTryStmt(AtLoc, Try.takeAs<Stmt>(),
static_cast<Stmt*>(Try.release()), Catch.takeAs<Stmt>(),
static_cast<Stmt*>(Catch.release()), Finally.takeAs<Stmt>()));
static_cast<Stmt*>(Finally.release())));
} }
Action::OwningStmtResult Action::OwningStmtResult
@ -1127,9 +1126,9 @@ Sema::ActOnObjCAtSynchronizedStmt(SourceLocation AtLoc, ExprArg SynchExpr,
<< SyncExpr->getType() << SyncExpr->getSourceRange()); << SyncExpr->getType() << SyncExpr->getSourceRange());
} }
return Owned(new (Context) ObjCAtSynchronizedStmt(AtLoc, return Owned(new (Context) ObjCAtSynchronizedStmt(AtLoc,
static_cast<Stmt*>(SynchExpr.release()), SynchExpr.takeAs<Stmt>(),
static_cast<Stmt*>(SynchBody.release()))); SynchBody.takeAs<Stmt>()));
} }
/// ActOnCXXCatchBlock - Takes an exception declaration and a handler block /// 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. // There's nothing to test that ActOnExceptionDecl didn't already test.
return Owned(new (Context) CXXCatchStmt(CatchLoc, return Owned(new (Context) CXXCatchStmt(CatchLoc,
cast_or_null<VarDecl>(ExDecl.getAs<Decl>()), cast_or_null<VarDecl>(ExDecl.getAs<Decl>()),
static_cast<Stmt*>(HandlerBlock.release()))); HandlerBlock.takeAs<Stmt>()));
} }
/// ActOnCXXTryBlock - Takes a try compound-statement and a number of /// ActOnCXXTryBlock - Takes a try compound-statement and a number of

View File

@ -302,7 +302,7 @@ void Sema::ActOnNonTypeTemplateParameterDefault(DeclPtrTy TemplateParamD,
return; return;
} }
TemplateParm->setDefaultArgument(static_cast<Expr *>(DefaultE.release())); TemplateParm->setDefaultArgument(DefaultE.takeAs<Expr>());
} }

View File

@ -303,7 +303,7 @@ InstantiateDependentSizedArrayType(const DependentSizedArrayType *T,
return QualType(); return QualType();
return SemaRef.BuildArrayType(ElementType, T->getSizeModifier(), return SemaRef.BuildArrayType(ElementType, T->getSizeModifier(),
(Expr *)InstantiatedArraySize.release(), InstantiatedArraySize.takeAs<Expr>(),
T->getIndexTypeQualifier(), Loc, Entity); T->getIndexTypeQualifier(), Loc, Entity);
} }

View File

@ -171,7 +171,7 @@ Decl *TemplateDeclInstantiator::VisitFieldDecl(FieldDecl *D) {
Invalid = true; Invalid = true;
BitWidth = 0; BitWidth = 0;
} else } else
BitWidth = (Expr *)InstantiatedBitWidth.release(); BitWidth = InstantiatedBitWidth.takeAs<Expr>();
} }
FieldDecl *Field = SemaRef.CheckFieldDecl(D->getDeclName(), T, FieldDecl *Field = SemaRef.CheckFieldDecl(D->getDeclName(), T,