From: Alexander Kornienko Date: Fri, 6 Nov 2015 01:26:37 +0000 (+0000) Subject: Refactor: Simplify boolean conditional return statements in lib/ARCMigrate X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4ac74f807fe9b1b4c1b5f5b10917f269475bc449;p=clang Refactor: Simplify boolean conditional return statements in lib/ARCMigrate Patch by Richard Thomson! (+a couple of modifications to address comments) Differential revision: http://reviews.llvm.org/D10009 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@252261 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/ARCMigrate/ObjCMT.cpp b/lib/ARCMigrate/ObjCMT.cpp index 04fa7bfb94..7e84994d39 100644 --- a/lib/ARCMigrate/ObjCMT.cpp +++ b/lib/ARCMigrate/ObjCMT.cpp @@ -214,25 +214,15 @@ namespace { // FIXME. This duplicates one in RewriteObjCFoundationAPI.cpp bool subscriptOperatorNeedsParens(const Expr *FullExpr) { const Expr* Expr = FullExpr->IgnoreImpCasts(); - if (isa(Expr) || - isa(Expr) || - isa(Expr) || - isa(Expr) || - isa(Expr) || - isa(Expr) || - isa(Expr) || - isa(Expr) || - isa(Expr) || - isa(Expr) || - isa(Expr) || - isa(Expr) || - isa(Expr) || - isa(FullExpr) || - isa(Expr) || - isa(Expr)) - return false; - - return true; + return !(isa(Expr) || isa(Expr) || + isa(Expr) || isa(Expr) || + isa(Expr) || isa(Expr) || + isa(Expr) || + isa(Expr) || + isa(Expr) || isa(Expr) || + isa(Expr) || isa(Expr) || + isa(Expr) || isa(FullExpr) || + isa(Expr) || isa(Expr)); } /// \brief - Rewrite message expression for Objective-C setter and getters into @@ -665,9 +655,7 @@ ClassImplementsAllMethodsAndProperties(ASTContext &Ctx, return false; } } - if (HasAtleastOneRequiredProperty || HasAtleastOneRequiredMethod) - return true; - return false; + return HasAtleastOneRequiredProperty || HasAtleastOneRequiredMethod; } static bool rewriteToObjCInterfaceDecl(const ObjCInterfaceDecl *IDecl, diff --git a/lib/ARCMigrate/TransEmptyStatementsAndDealloc.cpp b/lib/ARCMigrate/TransEmptyStatementsAndDealloc.cpp index 9689f40760..d45d5d60b7 100644 --- a/lib/ARCMigrate/TransEmptyStatementsAndDealloc.cpp +++ b/lib/ARCMigrate/TransEmptyStatementsAndDealloc.cpp @@ -104,9 +104,7 @@ public: return false; if (!S->getThen() || !Visit(S->getThen())) return false; - if (S->getElse() && !Visit(S->getElse())) - return false; - return true; + return !S->getElse() || Visit(S->getElse()); } bool VisitWhileStmt(WhileStmt *S) { if (S->getConditionVariable()) diff --git a/lib/ARCMigrate/TransGCAttrs.cpp b/lib/ARCMigrate/TransGCAttrs.cpp index 10fce19b6f..2ae6b78a46 100644 --- a/lib/ARCMigrate/TransGCAttrs.cpp +++ b/lib/ARCMigrate/TransGCAttrs.cpp @@ -152,9 +152,7 @@ public: return ID->getImplementation() != nullptr; if (ObjCCategoryDecl *CD = dyn_cast(ContD)) return CD->getImplementation() != nullptr; - if (isa(ContD)) - return true; - return false; + return isa(ContD); } return false; } diff --git a/lib/ARCMigrate/TransRetainReleaseDealloc.cpp b/lib/ARCMigrate/TransRetainReleaseDealloc.cpp index fbbd0bf641..f81133f3aa 100644 --- a/lib/ARCMigrate/TransRetainReleaseDealloc.cpp +++ b/lib/ARCMigrate/TransRetainReleaseDealloc.cpp @@ -150,11 +150,8 @@ public: return true; } - if (!hasSideEffects(rec, Pass.Ctx)) { - if (tryRemoving(RecContainer)) - return true; - } - Pass.TA.replace(RecContainer->getSourceRange(), RecRange); + if (hasSideEffects(rec, Pass.Ctx) || !tryRemoving(RecContainer)) + Pass.TA.replace(RecContainer->getSourceRange(), RecRange); return true; } @@ -174,11 +171,8 @@ private: /// return var; /// bool isCommonUnusedAutorelease(ObjCMessageExpr *E) { - if (isPlusOneAssignBeforeOrAfterAutorelease(E)) - return true; - if (isReturnedAfterAutorelease(E)) - return true; - return false; + return isPlusOneAssignBeforeOrAfterAutorelease(E) || + isReturnedAfterAutorelease(E); } bool isReturnedAfterAutorelease(ObjCMessageExpr *E) { @@ -225,11 +219,7 @@ private: // Check for "RefD = [+1 retained object];". if (BinaryOperator *Bop = dyn_cast(S)) { - if (RefD != getReferencedDecl(Bop->getLHS())) - return false; - if (isPlusOneAssign(Bop)) - return true; - return false; + return (RefD == getReferencedDecl(Bop->getLHS())) && isPlusOneAssign(Bop); } if (DeclStmt *DS = dyn_cast(S)) { diff --git a/lib/ARCMigrate/Transforms.cpp b/lib/ARCMigrate/Transforms.cpp index f3d8d8e754..3fd36ff310 100644 --- a/lib/ARCMigrate/Transforms.cpp +++ b/lib/ARCMigrate/Transforms.cpp @@ -113,10 +113,7 @@ bool trans::isPlusOne(const Expr *E) { while (implCE && implCE->getCastKind() == CK_BitCast) implCE = dyn_cast(implCE->getSubExpr()); - if (implCE && implCE->getCastKind() == CK_ARCConsumeObject) - return true; - - return false; + return implCE && implCE->getCastKind() == CK_ARCConsumeObject; } /// \brief 'Loc' is the end of a statement range. This returns the location