[PPL-devel] [GIT] ppl/ppl(master): Reduced the scope of several variables.

Roberto Bagnara bagnara at cs.unipr.it
Wed Jan 18 11:50:52 CET 2012


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

Author: Roberto Bagnara <bagnara at cs.unipr.it>
Date:   Wed Jan 18 11:48:24 2012 +0100

Reduced the scope of several variables.
Detected by ECLAIR service minscope.

---

 demos/ppl_pips/ppl_pips.cc |    5 ++---
 src/BD_Shape.templates.hh  |   16 +++++++++-------
 src/Boundary.defs.hh       |    3 +--
 src/MIP_Problem.cc         |   14 +++++++++-----
 src/PIP_Tree.cc            |    7 ++-----
 src/Sparse_Row.cc          |    6 +++---
 src/Variables_Set.cc       |    2 +-
 src/termination.cc         |    2 +-
 src/wrap_assign.hh         |    4 ++--
 9 files changed, 30 insertions(+), 29 deletions(-)

diff --git a/demos/ppl_pips/ppl_pips.cc b/demos/ppl_pips/ppl_pips.cc
index bfa1def..5ff21b9 100644
--- a/demos/ppl_pips/ppl_pips.cc
+++ b/demos/ppl_pips/ppl_pips.cc
@@ -391,8 +391,8 @@ protected:
   bool read_comment(std::istream& in) {
     comment = "";
     int count = 1;
-    char c;
     do {
+      char c;
       if (!in.get(c))
         return false;
       if (c == '(')
@@ -635,7 +635,6 @@ process_options(int argc, char* argv[]) {
       break;
 
     char* endptr;
-    long l;
     switch (c) {
     case 0:
       break;
@@ -649,7 +648,7 @@ process_options(int argc, char* argv[]) {
     case 'R':
       {
         const int MEGA = 1024*1024;
-        l = strtol(optarg, &endptr, 10);
+        long l = strtol(optarg, &endptr, 10);
         if (*endptr || l < 0)
           fatal("a non-negative integer must follow `-R'");
         else if (static_cast<unsigned long>(l) > ULONG_MAX/MEGA)
diff --git a/src/BD_Shape.templates.hh b/src/BD_Shape.templates.hh
index 911812f..49f4fe0 100644
--- a/src/BD_Shape.templates.hh
+++ b/src/BD_Shape.templates.hh
@@ -412,12 +412,11 @@ BD_Shape<T>::add_constraint(const Constraint& c) {
   // Select the cell to be modified for the "<=" part of the constraint,
   // and set `coeff' to the absolute value of itself.
   const bool negative = (coeff < 0);
-  N& x = negative ? dbm[i][j] : dbm[j][i];
-  N& y = negative ? dbm[j][i] : dbm[i][j];
   if (negative)
     neg_assign(coeff);
 
   bool changed = false;
+  N& x = negative ? dbm[i][j] : dbm[j][i];
   // Compute the bound for `x', rounding towards plus infinity.
   PPL_DIRTY_TEMP(N, d);
   div_round_up(d, inhomo, coeff);
@@ -427,6 +426,7 @@ BD_Shape<T>::add_constraint(const Constraint& c) {
   }
 
   if (c.is_equality()) {
+    N& y = negative ? dbm[j][i] : dbm[i][j];
     // Also compute the bound for `y', rounding towards plus infinity.
     PPL_DIRTY_TEMP_COEFFICIENT(minus_c_term);
     neg_assign(minus_c_term, inhomo);
@@ -2983,14 +2983,13 @@ BD_Shape<T>::get_limiting_shape(const Constraint_System& cs,
       const N& x = negative ? dbm[i][j] : dbm[j][i];
       const N& y = negative ? dbm[j][i] : dbm[i][j];
       DB_Matrix<N>& ls_dbm = limiting_shape.dbm;
-      N& ls_x = negative ? ls_dbm[i][j] : ls_dbm[j][i];
-      N& ls_y = negative ? ls_dbm[j][i] : ls_dbm[i][j];
       if (negative)
         neg_assign(coeff);
       // Compute the bound for `x', rounding towards plus infinity.
       div_round_up(d, c.inhomogeneous_term(), coeff);
       if (x <= d) {
         if (c.is_inequality()) {
+          N& ls_x = negative ? ls_dbm[i][j] : ls_dbm[j][i];
           if (ls_x > d) {
             ls_x = d;
             changed = true;
@@ -3000,12 +2999,15 @@ BD_Shape<T>::get_limiting_shape(const Constraint_System& cs,
           // Compute the bound for `y', rounding towards plus infinity.
           neg_assign(minus_c_term, c.inhomogeneous_term());
           div_round_up(d1, minus_c_term, coeff);
-          if (y <= d1)
+          if (y <= d1) {
+            N& ls_x = negative ? ls_dbm[i][j] : ls_dbm[j][i];
+            N& ls_y = negative ? ls_dbm[j][i] : ls_dbm[i][j];
 	    if ((ls_x >= d && ls_y > d1) || (ls_x > d && ls_y >= d1)) {
 	      ls_x = d;
 	      ls_y = d1;
 	      changed = true;
             }
+          }
         }
       }
     }
@@ -4243,12 +4245,12 @@ void BD_Shape<T>
   PPL_DIRTY_TEMP(N, b_mlb);
   neg_assign_r(b_mlb, b.lower(), ROUND_NOT_NEEDED);
 
-  // true if b = [b_lb, b_ub] = [0;0].
-  bool is_b_zero = (b_mlb == 0 && b_ub == 0);
   // true if w_coeff = [1;1]
   bool is_w_coeff_one = (w_coeff == 1);
 
   if (w_id == var_id) {
+    // true if b = [b_lb, b_ub] = [0;0].
+    bool is_b_zero = (b_mlb == 0 && b_ub == 0);
     // Here `lf' is of the form: [+/-1;+/-1] * v + b.
     if (is_w_coeff_one) {
       if (is_b_zero)
diff --git a/src/Boundary.defs.hh b/src/Boundary.defs.hh
index 7b85dc0..fb24935 100644
--- a/src/Boundary.defs.hh
+++ b/src/Boundary.defs.hh
@@ -716,7 +716,6 @@ inline Result
 div_assign_z(Boundary_Type to_type, To& to, To_Info& to_info,
 	     Boundary_Type type1, const T1& x1, const Info1& info1, int x1s,
 	     Boundary_Type type2, const T2& x2, const Info2& info2, int x2s) {
-  bool shrink;
   if (x1s != 0) {
     if (x2s != 0)
       return div_assign(to_type, to, to_info,
@@ -728,7 +727,7 @@ div_assign_z(Boundary_Type to_type, To& to, To_Info& to_info,
     }
   }
   else {
-    shrink = info1.get_boundary_property(type1, OPEN)
+    bool shrink = info1.get_boundary_property(type1, OPEN)
       && !is_boundary_infinity_closed(type2, x2, info2);
     return set_zero(to_type, to, to_info, shrink);
   }
diff --git a/src/MIP_Problem.cc b/src/MIP_Problem.cc
index 07558bf..6ecfa28 100644
--- a/src/MIP_Problem.cc
+++ b/src/MIP_Problem.cc
@@ -2662,8 +2662,8 @@ PPL::MIP_Problem::ascii_load(std::istream& s) {
   if (!(s >> str) || str != ")")
     return false;
 
-  dimension_type base_value;
   for (dimension_type i = 0; i != base_size; ++i) {
+    dimension_type base_value;
     if (!(s >> base_value))
       return false;
     base.push_back(base_value);
@@ -2685,26 +2685,30 @@ PPL::MIP_Problem::ascii_load(std::istream& s) {
   if (!(s >> str) || str != ")")
     return false;
 
-  dimension_type first_value;
-  dimension_type second_value;
-  dimension_type index;
-
   // The first `mapping' index is never used, so we initialize
   // it pushing back a dummy value.
   if (tableau.num_columns() != 0)
     mapping.push_back(std::make_pair(0, 0));
 
   for (dimension_type i = 1; i < mapping_size; ++i) {
+    dimension_type index;
     if (!(s >> index))
       return false;
+
     if (!(s >> str) || str != "->")
       return false;
+
+    dimension_type first_value;
     if (!(s >> first_value))
       return false;
+
     if (!(s >> str) || str != "->")
       return false;
+
+    dimension_type second_value;
     if (!(s >> second_value))
       return false;
+
     mapping.push_back(std::make_pair(first_value, second_value));
   }
 
diff --git a/src/PIP_Tree.cc b/src/PIP_Tree.cc
index f788457..1b12491 100644
--- a/src/PIP_Tree.cc
+++ b/src/PIP_Tree.cc
@@ -735,11 +735,7 @@ compatibility_check_find_pivot(const Matrix& s,
         current_data.value = s_ij;
       } else {
         data_struct& current_data = candidates_map[j];
-
-        Coefficient_traits::const_reference value_b = s_i.get(j);
-
         PPL_ASSERT(current_data.value > 0);
-        PPL_ASSERT(value_b > 0);
 
         // Before computing and comparing the actual values, the signs are
         // compared. This speeds up the code, because the values' computation
@@ -759,9 +755,10 @@ compatibility_check_find_pivot(const Matrix& s,
           }
           // Otherwise, keep current pivot for this column.
         } else {
-
           // Sign comparison is not enough this time.
           // Do the full computation.
+          Coefficient_traits::const_reference value_b = s_i.get(j);
+          PPL_ASSERT(value_b > 0);
 
           PPL_DIRTY_TEMP_COEFFICIENT(lhs_coeff);
           lhs_coeff = current_data.cost;
diff --git a/src/Sparse_Row.cc b/src/Sparse_Row.cc
index 9a61ced..c5efd90 100644
--- a/src/Sparse_Row.cc
+++ b/src/Sparse_Row.cc
@@ -475,17 +475,17 @@ PPL::Sparse_Row::ascii_load(std::istream& s) {
   if (!(s >> size_))
     return false;
   clear();
-  dimension_type n_elements;
-  dimension_type current_key;
-  Coefficient current_data;
 
   if (!(s >> str) || str != "elements")
     return false;
 
+  dimension_type n_elements;
   if (!(s >> n_elements))
     return false;
 
+  PPL_DIRTY_TEMP_COEFFICIENT(current_data);
   for (dimension_type i = 0; i < n_elements; ++i) {
+    dimension_type current_key;
     if (!(s >> str) || str != "[")
       return false;
     if (!(s >> current_key))
diff --git a/src/Variables_Set.cc b/src/Variables_Set.cc
index d73ad15..0a0abe5 100644
--- a/src/Variables_Set.cc
+++ b/src/Variables_Set.cc
@@ -81,8 +81,8 @@ PPL::Variables_Set::ascii_load(std::istream& s) {
   if (!(s >> str) || str != ")")
     return false;
 
-  dimension_type variable_value;
   for (dimension_type i = 0; i < size; ++i) {
+    dimension_type variable_value;
     if (!(s >> variable_value))
       return false;
     insert(variable_value);
diff --git a/src/termination.cc b/src/termination.cc
index 0ac4e00..50e2710 100644
--- a/src/termination.cc
+++ b/src/termination.cc
@@ -883,13 +883,13 @@ all_affine_ranking_functions_PR_original(const Constraint_System& cs,
 #endif
 
   const Generator_System& gs_in = ph.generators();
-  Generator_System gs_out;
   Generator_System::const_iterator gs_in_it = gs_in.begin();
   Generator_System::const_iterator gs_in_end = gs_in.end();
   if (gs_in_it == gs_in_end)
     // The system is unsatisfiable.
     mu_space = NNC_Polyhedron(n + 1, EMPTY);
   else {
+    Generator_System gs_out;
     for ( ; gs_in_it != gs_in_end; ++gs_in_it) {
       const Generator& g = *gs_in_it;
       Linear_Expression le;
diff --git a/src/wrap_assign.hh b/src/wrap_assign.hh
index 7461749..a416506 100644
--- a/src/wrap_assign.hh
+++ b/src/wrap_assign.hh
@@ -168,8 +168,8 @@ wrap_assign(PSET& pointset,
   //         and  vars.space_dimension() <= pointset.space_dimension().
 
   // Dimension-compatibility check of `*cs_p', if any.
-  const dimension_type vars_space_dim = vars.space_dimension();
   if (cs_p != 0) {
+    const dimension_type vars_space_dim = vars.space_dimension();
     if (cs_p->space_dimension() > vars_space_dim) {
       std::ostringstream s;
       s << "PPL::" << class_name << "::wrap_assign(..., cs_p, ...):"
@@ -190,7 +190,7 @@ wrap_assign(PSET& pointset,
       const Constraint& c = *i;
       for (dimension_type d = cs_space_dim; d-- > 0; ) {
         PPL_ASSERT(c.coefficient(Variable(d)) == 0
-               || vars.find(d) != vars_end);
+                   || vars.find(d) != vars_end);
       }
     }
 #endif




More information about the PPL-devel mailing list