[PPL-devel] [GIT] ppl/ppl(master): Let bitwise operators be applied to unsigned integer types.

Enea Zaffanella zaffanella at cs.unipr.it
Mon Feb 20 17:32:18 CET 2012


Module: ppl/ppl
Branch: master
Commit: 803576355bab1ffbad948d7d5a75be21121765dc
URL:    http://www.cs.unipr.it/git/gitweb.cgi?p=ppl/ppl.git;a=commit;h=803576355bab1ffbad948d7d5a75be21121765dc

Author: Enea Zaffanella <zaffanella at cs.unipr.it>
Date:   Mon Feb 20 16:55:20 2012 +0100

Let bitwise operators be applied to unsigned integer types.
Detected by ECLAIR service utypflag.

---

 src/Rounding_Dir.defs.hh    |   15 +++++++++------
 src/Rounding_Dir.inlines.hh |   42 +++++++++++++++++++++++++++++-------------
 2 files changed, 38 insertions(+), 19 deletions(-)

diff --git a/src/Rounding_Dir.defs.hh b/src/Rounding_Dir.defs.hh
index e1d9a1d..15c7d63 100644
--- a/src/Rounding_Dir.defs.hh
+++ b/src/Rounding_Dir.defs.hh
@@ -35,17 +35,17 @@ enum Rounding_Dir {
   /*! \hideinitializer
     Round toward \f$-\infty\f$.
   */
-  ROUND_DOWN = 0,
+  ROUND_DOWN = 0U,
 
   /*! \hideinitializer
     Round toward \f$+\infty\f$.
   */
-  ROUND_UP = 1,
+  ROUND_UP = 1U,
 
   /*! \hideinitializer
     Rounding is delegated to lower level. Result info is evaluated lazily.
   */
-  ROUND_IGNORE = 6,
+  ROUND_IGNORE = 6U,
   ROUND_NATIVE = ROUND_IGNORE,
 
   /*! \hideinitializer
@@ -53,22 +53,25 @@ enum Rounding_Dir {
     result is exact and representable in the destination type.
     Result info is evaluated lazily.
   */
-  ROUND_NOT_NEEDED = 7,
+  ROUND_NOT_NEEDED = 7U,
 
   ROUND_DIRECT = ROUND_UP,
   ROUND_INVERSE = ROUND_DOWN,
 
-  ROUND_DIR_MASK = 7,
+  ROUND_DIR_MASK = 7U,
 
   /*! \hideinitializer
     The client code is willing to pay an extra price to know the exact
     relation between the exact result and the computed one.
    */
-  ROUND_STRICT_RELATION = 8,
+  ROUND_STRICT_RELATION = 8U,
 
   ROUND_CHECK = ROUND_DIRECT | ROUND_STRICT_RELATION
 };
 
+Rounding_Dir operator&(Rounding_Dir x, Rounding_Dir y);
+Rounding_Dir operator|(Rounding_Dir x, Rounding_Dir y);
+
 /*! \brief
   Returns the inverse rounding mode of \p dir,
   <CODE>ROUND_IGNORE</CODE> being the inverse of itself.
diff --git a/src/Rounding_Dir.inlines.hh b/src/Rounding_Dir.inlines.hh
index af2de1c..12b9823 100644
--- a/src/Rounding_Dir.inlines.hh
+++ b/src/Rounding_Dir.inlines.hh
@@ -28,53 +28,77 @@ site: http://bugseng.com/products/ppl/ . */
 
 namespace Parma_Polyhedra_Library {
 
+/*! \relates Parma_Polyhedra_Library::Rounding_Dir */
+inline Rounding_Dir
+operator&(Rounding_Dir x, Rounding_Dir y) {
+  unsigned res = static_cast<unsigned>(x) & static_cast<unsigned>(y);
+  return static_cast<Rounding_Dir>(res);
+}
+
+/*! \relates Parma_Polyhedra_Library::Rounding_Dir */
+inline Rounding_Dir
+operator|(Rounding_Dir x, Rounding_Dir y) {
+  unsigned res = static_cast<unsigned>(x) | static_cast<unsigned>(y);
+  return static_cast<Rounding_Dir>(res);
+}
+
+/*! \relates Parma_Polyhedra_Library::Rounding_Dir */
 inline Rounding_Dir
 round_dir(Rounding_Dir dir) {
-  return static_cast<Rounding_Dir>(dir & ROUND_DIR_MASK);
+  return dir & ROUND_DIR_MASK;
 }
 
+/*! \relates Parma_Polyhedra_Library::Rounding_Dir */
 inline bool
 round_down(Rounding_Dir dir) {
   return round_dir(dir) == ROUND_DOWN;
 }
 
+/*! \relates Parma_Polyhedra_Library::Rounding_Dir */
 inline bool
 round_up(Rounding_Dir dir) {
   return round_dir(dir) == ROUND_UP;
 }
 
+/*! \relates Parma_Polyhedra_Library::Rounding_Dir */
 inline bool
 round_ignore(Rounding_Dir dir) {
   return round_dir(dir) == ROUND_IGNORE;
 }
 
+/*! \relates Parma_Polyhedra_Library::Rounding_Dir */
 inline bool
 round_not_needed(Rounding_Dir dir) {
   return round_dir(dir) == ROUND_NOT_NEEDED;
 }
 
+/*! \relates Parma_Polyhedra_Library::Rounding_Dir */
 inline bool
 round_not_requested(Rounding_Dir dir) {
   return round_dir(dir) == ROUND_IGNORE || round_dir(dir) == ROUND_NOT_NEEDED;
 }
 
+/*! \relates Parma_Polyhedra_Library::Rounding_Dir */
 inline bool
 round_direct(Rounding_Dir dir) {
   return round_dir(dir) == ROUND_DIRECT;
 }
 
+/*! \relates Parma_Polyhedra_Library::Rounding_Dir */
 inline bool
 round_inverse(Rounding_Dir dir) {
   return round_dir(dir) == ROUND_INVERSE;
 }
 
+/*! \relates Parma_Polyhedra_Library::Rounding_Dir */
 inline bool
 round_strict_relation(Rounding_Dir dir) {
-  return (dir & ROUND_STRICT_RELATION) != 0;
+  return (dir & ROUND_STRICT_RELATION) == ROUND_STRICT_RELATION;
 }
 
 #if PPL_CAN_CONTROL_FPU
 
+/*! \relates Parma_Polyhedra_Library::Rounding_Dir */
 inline fpu_rounding_direction_type
 round_fpu_dir(Rounding_Dir dir) {
   switch (round_dir(dir)) {
@@ -99,25 +123,17 @@ round_fpu_dir(Rounding_Dir dir) {
 /*! \relates Parma_Polyhedra_Library::Rounding_Dir */
 inline Rounding_Dir
 inverse(Rounding_Dir dir) {
-  Rounding_Dir d = round_dir(dir);
-  switch (d) {
+  switch (round_dir(dir)) {
   case ROUND_UP:
-    d = ROUND_DOWN;
-    break;
+    return ROUND_DOWN | (dir & ROUND_STRICT_RELATION);
   case ROUND_DOWN:
-    d = ROUND_UP;
-    break;
+    return ROUND_UP | (dir & ROUND_STRICT_RELATION);
   case ROUND_IGNORE:
     return dir;
   default:
     PPL_UNREACHABLE;
     return dir;
   }
-  return static_cast<Rounding_Dir>((dir & ~ROUND_DIR_MASK) | d);
-}
-
-inline Rounding_Dir operator|(Rounding_Dir x, Rounding_Dir y) {
-  return static_cast<Rounding_Dir>((unsigned)x | (unsigned)y);
 }
 
 } // namespace Parma_Polyhedra_Library




More information about the PPL-devel mailing list