From: Anders Carlsson Date: Fri, 1 May 2009 19:30:39 +0000 (+0000) Subject: Replace a bunch of static_cast + release with takeAs. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f1b1d59a3f0650ab97b04235a14ae4549ca1c656;p=clang Replace a bunch of static_cast + release with takeAs. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@70566 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index de509246ba..af27229b92 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -2485,7 +2485,7 @@ void Sema::AddInitializerToDecl(DeclPtrTy dcl, ExprArg init, bool DirectInit) { // Take ownership of the expression, now that we're sure we have somewhere // to put it. - Expr *Init = static_cast(init.release()); + Expr *Init = init.takeAs(); assert(Init && "missing initializer"); // Get the decls type and save a reference for later, since @@ -4274,7 +4274,7 @@ void Sema::ActOnEnumBody(SourceLocation EnumLoc, DeclPtrTy EnumDeclX, Sema::DeclPtrTy Sema::ActOnFileScopeAsmDecl(SourceLocation Loc, ExprArg expr) { - StringLiteral *AsmString = cast((Expr*)expr.release()); + StringLiteral *AsmString = cast(expr.takeAs()); return DeclPtrTy::make(FileScopeAsmDecl::Create(Context, CurContext, Loc, AsmString)); diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index 54c887e303..cc633e738d 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -108,7 +108,7 @@ void Sema::ActOnParamDefaultArgument(DeclPtrTy param, SourceLocation EqualLoc, ExprArg defarg) { ParmVarDecl *Param = cast(param.getAs()); - ExprOwningPtr DefaultArg(this, (Expr *)defarg.release()); + ExprOwningPtr DefaultArg(this, defarg.takeAs()); QualType ParamType = Param->getType(); // Default arguments are only permitted in C++ diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 66b4c9c6b2..5c0c33b298 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -1852,7 +1852,7 @@ Sema::ActOnMemberReferenceExpr(Scope *S, ExprArg Base, SourceLocation OpLoc, tok::TokenKind OpKind, SourceLocation MemberLoc, IdentifierInfo &Member, DeclPtrTy ObjCImpDecl) { - Expr *BaseExpr = static_cast(Base.release()); + Expr *BaseExpr = Base.takeAs(); assert(BaseExpr && "no record expression"); // Perform default conversions. @@ -2322,7 +2322,7 @@ Sema::ActOnCallExpr(Scope *S, ExprArg fn, SourceLocation LParenLoc, MultiExprArg args, SourceLocation *CommaLocs, SourceLocation RParenLoc) { unsigned NumArgs = args.size(); - Expr *Fn = static_cast(fn.release()); + Expr *Fn = fn.takeAs(); Expr **Args = reinterpret_cast(args.release()); assert(Fn && "no function call expression"); FunctionDecl *FDecl = NULL; @@ -2643,7 +2643,7 @@ Sema::ActOnCastExpr(SourceLocation LParenLoc, TypeTy *Ty, assert((Ty != 0) && (Op.get() != 0) && "ActOnCastExpr(): missing type or expr"); - Expr *castExpr = static_cast(Op.release()); + Expr *castExpr = Op.takeAs(); QualType castType = QualType::getFromOpaquePtr(Ty); if (CheckCastTypes(SourceRange(LParenLoc, RParenLoc), castType, castExpr)) @@ -4715,8 +4715,8 @@ Sema::OwningExprResult Sema::ActOnBuiltinOffsetOf(Scope *S, // FIXME: C++: Verify that MemberDecl isn't a static field. // FIXME: Verify that MemberDecl isn't a bitfield. if (cast(MemberDecl->getDeclContext())->isAnonymousStructOrUnion()) { - Res = static_cast(BuildAnonymousStructUnionMemberReference( - SourceLocation(), MemberDecl, Res, SourceLocation()).release()); + Res = BuildAnonymousStructUnionMemberReference( + SourceLocation(), MemberDecl, Res, SourceLocation()).takeAs(); } else { // MemberDecl->getType() doesn't get the right qualifiers, but it // doesn't matter here. diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp index fff7a44bc4..d7fd5f054d 100644 --- a/lib/Sema/SemaStmt.cpp +++ b/lib/Sema/SemaStmt.cpp @@ -22,7 +22,7 @@ using namespace clang; Sema::OwningStmtResult Sema::ActOnExprStmt(ExprArg expr) { - Expr *E = static_cast(expr.release()); + Expr *E = expr.takeAs(); assert(E && "ActOnExprStmt(): missing expression"); // C99 6.8.3p2: The expression in an expression statement is evaluated as a @@ -129,14 +129,14 @@ Sema::ActOnCaseStmt(SourceLocation CaseLoc, ExprArg lhsval, /// ActOnCaseStmtBody - This installs a statement as the body of a case. void Sema::ActOnCaseStmtBody(StmtTy *caseStmt, StmtArg subStmt) { CaseStmt *CS = static_cast(caseStmt); - Stmt *SubStmt = static_cast(subStmt.release()); + Stmt *SubStmt = subStmt.takeAs(); CS->setSubStmt(SubStmt); } Action::OwningStmtResult Sema::ActOnDefaultStmt(SourceLocation DefaultLoc, SourceLocation ColonLoc, StmtArg subStmt, Scope *CurScope) { - Stmt *SubStmt = static_cast(subStmt.release()); + Stmt *SubStmt = subStmt.takeAs(); if (getSwitchStack().empty()) { Diag(DefaultLoc, diag::err_default_not_in_switch); @@ -151,7 +151,7 @@ Sema::ActOnDefaultStmt(SourceLocation DefaultLoc, SourceLocation ColonLoc, Action::OwningStmtResult Sema::ActOnLabelStmt(SourceLocation IdentLoc, IdentifierInfo *II, SourceLocation ColonLoc, StmtArg subStmt) { - Stmt *SubStmt = static_cast(subStmt.release()); + Stmt *SubStmt = subStmt.takeAs(); // Look up the record for this label identifier. LabelStmt *&LabelDecl = getLabelMap()[II]; @@ -214,7 +214,7 @@ Sema::ActOnIfStmt(SourceLocation IfLoc, ExprArg CondVal, Action::OwningStmtResult Sema::ActOnStartOfSwitchStmt(ExprArg cond) { - Expr *Cond = static_cast(cond.release()); + Expr *Cond = cond.takeAs(); if (getLangOptions().CPlusPlus) { // C++ 6.4.2.p2: @@ -788,7 +788,7 @@ static bool IsReturnCopyElidable(ASTContext &Ctx, QualType RetType, Action::OwningStmtResult Sema::ActOnReturnStmt(SourceLocation ReturnLoc, ExprArg rex) { - Expr *RetValExp = static_cast(rex.release()); + Expr *RetValExp = rex.takeAs(); if (CurBlock) return ActOnBlockReturnStmt(ReturnLoc, RetValExp); @@ -1051,7 +1051,7 @@ Action::OwningStmtResult Sema::ActOnObjCAtCatchStmt(SourceLocation AtLoc, SourceLocation RParen, DeclPtrTy Parm, StmtArg Body, StmtArg catchList) { - Stmt *CatchList = static_cast(catchList.release()); + Stmt *CatchList = catchList.takeAs(); ParmVarDecl *PVD = cast_or_null(Parm.getAs()); // PVD == 0 implies @catch(...). @@ -1091,7 +1091,7 @@ Sema::ActOnObjCAtTryStmt(SourceLocation AtLoc, Action::OwningStmtResult Sema::ActOnObjCAtThrowStmt(SourceLocation AtLoc, ExprArg expr,Scope *CurScope) { - Expr *ThrowExpr = static_cast(expr.release()); + Expr *ThrowExpr = expr.takeAs(); if (!ThrowExpr) { // @throw without an expression designates a rethrow (which much occur // in the context of an @catch clause). diff --git a/lib/Sema/SemaTemplateInstantiate.cpp b/lib/Sema/SemaTemplateInstantiate.cpp index bd385d355b..1378682919 100644 --- a/lib/Sema/SemaTemplateInstantiate.cpp +++ b/lib/Sema/SemaTemplateInstantiate.cpp @@ -465,7 +465,7 @@ InstantiateTemplateSpecializationType( NumTemplateArgs); if (E.isInvalid()) return QualType(); - InstantiatedTemplateArgs.push_back((Expr *)E.release()); + InstantiatedTemplateArgs.push_back(E.takeAs()); break; } }