[PATCH] Refactor: Simplify boolean conditional return statements in lib/Edit

Richard legalize at xmission.com
Mon May 25 13:19:39 PDT 2015


Hi akyrtzi, chapuni, bkramer,

Use clang-tidy to simplify boolean conditional return statements

http://reviews.llvm.org/D10014

Files:
  lib/Edit/RewriteObjCFoundationAPI.cpp

Index: lib/Edit/RewriteObjCFoundationAPI.cpp
===================================================================
--- lib/Edit/RewriteObjCFoundationAPI.cpp
+++ lib/Edit/RewriteObjCFoundationAPI.cpp
@@ -628,10 +628,7 @@
     if (!getNSArrayObjects(Msg->getArg(1), NS, Keys))
       return false;
 
-    if (Vals.size() != Keys.size())
-      return false;
-
-    return true;
+    return Vals.size() == Keys.size();
   }
 
   return false;
@@ -888,53 +885,30 @@
 // make it broadly available.
 static 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);
 }
+
 static bool castOperatorNeedsParens(const Expr *FullExpr) {
   const Expr* Expr = FullExpr->IgnoreImpCasts();
-  if (isa<ArraySubscriptExpr>(Expr) ||
-      isa<CallExpr>(Expr) ||
-      isa<DeclRefExpr>(Expr) ||
-      isa<CastExpr>(Expr) ||
-      isa<CXXNewExpr>(Expr) ||
-      isa<CXXConstructExpr>(Expr) ||
-      isa<CXXDeleteExpr>(Expr) ||
-      isa<CXXNoexceptExpr>(Expr) ||
-      isa<CXXPseudoDestructorExpr>(Expr) ||
-      isa<CXXScalarValueInitExpr>(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) ||
-      isa<UnaryOperator>(Expr))
-    return false;
-
-  return true;
+  return !isa<ArraySubscriptExpr>(Expr) && !isa<CallExpr>(Expr) &&
+         !isa<DeclRefExpr>(Expr) && !isa<CastExpr>(Expr) &&
+         !isa<CXXNewExpr>(Expr) && !isa<CXXConstructExpr>(Expr) &&
+         !isa<CXXDeleteExpr>(Expr) && !isa<CXXNoexceptExpr>(Expr) &&
+         !isa<CXXPseudoDestructorExpr>(Expr) &&
+         !isa<CXXScalarValueInitExpr>(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) &&
+         !isa<UnaryOperator>(Expr);
 }
 
 static void objectifyExpr(const Expr *E, Commit &commit) {

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D10014.26481.patch
Type: text/x-patch
Size: 3610 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150525/c0d72036/attachment.bin>


More information about the cfe-commits mailing list