]> granicus.if.org Git - clang/commitdiff
Refactor: Simplify boolean conditional return statements in lib/ARCMigrate
authorAlexander Kornienko <alexfh@google.com>
Fri, 6 Nov 2015 01:26:37 +0000 (01:26 +0000)
committerAlexander Kornienko <alexfh@google.com>
Fri, 6 Nov 2015 01:26:37 +0000 (01:26 +0000)
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

lib/ARCMigrate/ObjCMT.cpp
lib/ARCMigrate/TransEmptyStatementsAndDealloc.cpp
lib/ARCMigrate/TransGCAttrs.cpp
lib/ARCMigrate/TransRetainReleaseDealloc.cpp
lib/ARCMigrate/Transforms.cpp

index 04fa7bfb944306566caa1368d553967680f12bc5..7e84994d39c4604e128931320a202333d1800804 100644 (file)
@@ -214,25 +214,15 @@ namespace {
   // FIXME. This duplicates one in RewriteObjCFoundationAPI.cpp
   bool subscriptOperatorNeedsParens(const Expr *FullExpr) {
     const Expr* Expr = FullExpr->IgnoreImpCasts();
-    if (isa<ArraySubscriptExpr>(Expr) ||
-        isa<CallExpr>(Expr) ||
-        isa<DeclRefExpr>(Expr) ||
-        isa<CXXNamedCastExpr>(Expr) ||
-        isa<CXXConstructExpr>(Expr) ||
-        isa<CXXThisExpr>(Expr) ||
-        isa<CXXTypeidExpr>(Expr) ||
-        isa<CXXUnresolvedConstructExpr>(Expr) ||
-        isa<ObjCMessageExpr>(Expr) ||
-        isa<ObjCPropertyRefExpr>(Expr) ||
-        isa<ObjCProtocolExpr>(Expr) ||
-        isa<MemberExpr>(Expr) ||
-        isa<ObjCIvarRefExpr>(Expr) ||
-        isa<ParenExpr>(FullExpr) ||
-        isa<ParenListExpr>(Expr) ||
-        isa<SizeOfPackExpr>(Expr))
-      return false;
-    
-    return true;
+    return !(isa<ArraySubscriptExpr>(Expr) || isa<CallExpr>(Expr) ||
+             isa<DeclRefExpr>(Expr) || isa<CXXNamedCastExpr>(Expr) ||
+             isa<CXXConstructExpr>(Expr) || isa<CXXThisExpr>(Expr) ||
+             isa<CXXTypeidExpr>(Expr) ||
+             isa<CXXUnresolvedConstructExpr>(Expr) ||
+             isa<ObjCMessageExpr>(Expr) || isa<ObjCPropertyRefExpr>(Expr) ||
+             isa<ObjCProtocolExpr>(Expr) || isa<MemberExpr>(Expr) ||
+             isa<ObjCIvarRefExpr>(Expr) || isa<ParenExpr>(FullExpr) ||
+             isa<ParenListExpr>(Expr) || isa<SizeOfPackExpr>(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,
index 9689f40760cda18143b40b0f789687630af10e6c..d45d5d60b78ab46cb4b04cd367d653ca333eeafc 100644 (file)
@@ -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())
index 10fce19b6f19f344696a316098459f01f6446b52..2ae6b78a463488870d740f81b7cf11644ace137d 100644 (file)
@@ -152,9 +152,7 @@ public:
         return ID->getImplementation() != nullptr;
       if (ObjCCategoryDecl *CD = dyn_cast<ObjCCategoryDecl>(ContD))
         return CD->getImplementation() != nullptr;
-      if (isa<ObjCImplDecl>(ContD))
-        return true;
-      return false;
+      return isa<ObjCImplDecl>(ContD);
     }
     return false;
   }
index fbbd0bf641b1235b9ff0a879632273b9f145840e..f81133f3aad3702c86ffed412493640fc9d180ed 100644 (file)
@@ -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<BinaryOperator>(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<DeclStmt>(S)) {
index f3d8d8e7545688a3d5d6f3115e38723290b7d492..3fd36ff310f3d155dde0dcd86ecaf5efbcb747ef 100644 (file)
@@ -113,10 +113,7 @@ bool trans::isPlusOne(const Expr *E) {
   while (implCE && implCE->getCastKind() ==  CK_BitCast)
     implCE = dyn_cast<ImplicitCastExpr>(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