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

David Blaikie dblaikie at gmail.com
Tue May 26 12:48:12 PDT 2015


================
Comment at: lib/AST/ASTImporter.cpp:401
@@ -400,6 +400,3 @@
     return false;
-  if (Array1->getIndexTypeQualifiers() != Array2->getIndexTypeQualifiers())
-    return false;
-  
-  return true;
+  return Array1->getIndexTypeQualifiers() == Array2->getIndexTypeQualifiers();
 }
----------------
Isn't this the sort of chained conditional you/we decided not to flag/suggest changes on?

================
Comment at: lib/AST/Decl.cpp:2384
@@ -2383,5 +2383,3 @@
 
-  if (isa<CompoundStmt>(S) && cast<CompoundStmt>(S)->body_empty())
-    return true;
-  return false;
+  return isa<CompoundStmt>(S) && cast<CompoundStmt>(S)->body_empty();
 }
----------------
this should probably be:

  if (auto *CS = dyn_cast<CompoundStmt>(S))
    return CS->body_empty();
  return false;

================
Comment at: lib/AST/DeclBase.cpp:305
@@ -304,6 +304,3 @@
   // Check for used attribute.
-  if (CheckUsedAttr && hasAttr<UsedAttr>())
-    return true;
-
-  return false; 
+  return CheckUsedAttr && hasAttr<UsedAttr>(); 
 }
----------------
another possible 'chain' style return

================
Comment at: lib/AST/DeclCXX.cpp:413
@@ -412,5 +412,3 @@
   //   -- has a trivial destructor.
-  if (!hasTrivialDestructor()) return false;
-
-  return true;
+  return hasTrivialDestructor();
 }
----------------
Another chain return

================
Comment at: lib/AST/Expr.cpp:2669
@@ -2668,6 +2668,3 @@
   // - opaque values (all)
-  if (isa<OpaqueValueExpr>(E))
-    return false;
-
-  return true;
+  return !isa<OpaqueValueExpr>(E);
 }
----------------
Possible chain

================
Comment at: lib/AST/ExprConstant.cpp:207
@@ -206,5 +206,3 @@
         return true;
-      if (MostDerivedArraySize &&
-          Entries[MostDerivedPathLength - 1].ArrayIndex == MostDerivedArraySize)
-        return true;
-      return false;
+      return MostDerivedArraySize &&
+             Entries[MostDerivedPathLength - 1].ArrayIndex ==
----------------
possible chain

================
Comment at: lib/AST/ExprConstant.cpp:2220
@@ -2220,7 +2219,3 @@
       // If we modified a bit-field, truncate it to the right width.
-      if (handler.AccessKind != AK_Read &&
-          LastField && LastField->isBitField() &&
-          !truncateBitfieldValue(Info, E, *O, LastField))
-        return false;
-
-      return true;
+      return handler.AccessKind == AK_Read || !LastField ||
+             !LastField->isBitField() ||
----------------
possible chain

================
Comment at: lib/AST/ItaniumMangle.cpp:1869
@@ -1868,6 +1868,3 @@
     return true;
-  if (Ty->isBuiltinType())
-    return false;
-
-  return true;
+  return !Ty->isBuiltinType();
 }
----------------
chain

================
Comment at: lib/AST/ItaniumMangle.cpp:3728
@@ -3730,6 +3727,3 @@
 
-  if (!isCharSpecialization(TemplateArgs[1].getAsType(), "char_traits"))
-    return false;
-
-  return true;
+  return isCharSpecialization(TemplateArgs[1].getAsType(), "char_traits");
 }
----------------
chain

http://reviews.llvm.org/D10010

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/






More information about the cfe-commits mailing list