
Module: ppl/ppl Branch: master Commit: 6bb782d283cc62200324e028c310428a4eb68b78 URL: http://www.cs.unipr.it/git/gitweb.cgi?p=ppl/ppl.git;a=commit;h=6bb782d283cc6...
Author: Enea Zaffanella zaffanella@cs.unipr.it Date: Wed Feb 22 14:02:19 2012 +0100
Added helper function Implementation::num_constraints(). When implementing it, avoid implicit conversion changing signedness. Detected by ECLAIR service utypflag.
---
src/Box.templates.hh | 4 ++-- src/Constraint_System.defs.hh | 14 ++++++++++++++ src/Constraint_System.inlines.hh | 12 ++++++++++++ src/PIP_Tree.cc | 10 +++++----- src/termination.cc | 30 +++++++++++++++--------------- 5 files changed, 48 insertions(+), 22 deletions(-)
diff --git a/src/Box.templates.hh b/src/Box.templates.hh index e20fdc4..af2e245 100644 --- a/src/Box.templates.hh +++ b/src/Box.templates.hh @@ -2712,8 +2712,8 @@ Box<ITV>
const Constraint_System::const_iterator cs_begin = cs.begin(); const Constraint_System::const_iterator cs_end = cs.end(); - const dimension_type cs_size = std::distance(cs_begin, cs_end); - const dimension_type propagation_weight = cs_size * space_dim; + const dimension_type propagation_weight + = Implementation::num_constraints(cs) * space_dim;
Sequence copy; bool changed; diff --git a/src/Constraint_System.defs.hh b/src/Constraint_System.defs.hh index 0475af8..d5dff3b 100644 --- a/src/Constraint_System.defs.hh +++ b/src/Constraint_System.defs.hh @@ -402,6 +402,20 @@ private: void add_low_level_constraints(); };
+namespace Parma_Polyhedra_Library { + +namespace Implementation { + +#ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS +//! Helper returning number of constraints in system. +#endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS) +dimension_type +num_constraints(const Constraint_System& cs); + +} // namespace Implementation + +} // namespace Parma_Polyhedra_Library + // Constraint_System.inlines.hh is not included here on purpose.
#endif // !defined(PPL_Constraint_System_defs_hh) diff --git a/src/Constraint_System.inlines.hh b/src/Constraint_System.inlines.hh index 96f6d6b..c36a612 100644 --- a/src/Constraint_System.inlines.hh +++ b/src/Constraint_System.inlines.hh @@ -215,6 +215,18 @@ swap(Constraint_System& x, Constraint_System& y) { x.m_swap(y); }
+namespace Implementation { + +#ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS +/*! \relates Parma_Polyhedra_Library::Constraint_System */ +#endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS) +inline dimension_type +num_constraints(const Constraint_System& cs) { + return static_cast<dimension_type>(std::distance(cs.begin(), cs.end())); +} + +} // namespace Implementation + } // namespace Parma_Polyhedra_Library
#endif // !defined(PPL_Constraint_System_inlines_hh) diff --git a/src/PIP_Tree.cc b/src/PIP_Tree.cc index f4b2f28..7977964 100644 --- a/src/PIP_Tree.cc +++ b/src/PIP_Tree.cc @@ -115,7 +115,7 @@ void merge_assign(Matrix& x, const Constraint_System& y, const Variables_Set& parameters) { PPL_ASSERT(parameters.size() == x.num_columns() - 1); - const dimension_type new_rows = std::distance(y.begin(), y.end()); + const dimension_type new_rows = Implementation::num_constraints(y); if (new_rows == 0) return; const dimension_type old_num_rows = x.num_rows(); @@ -1254,8 +1254,7 @@ PIP_Decision_Node::OK() const {
// Decision nodes with a false child must have exactly one constraint. if (false_child != 0) { - dimension_type dist = std::distance(constraints_.begin(), - constraints_.end()); + dimension_type dist = Implementation::num_constraints(constraints_); if (dist != 1) { #ifndef NDEBUG std::cerr << "PIP_Decision_Node with a 'false' child has " @@ -1321,7 +1320,7 @@ PIP_Decision_Node::solve(const PIP_Problem& pip,
if (has_false_child) { // Decision nodes with false child must have exactly one constraint - PPL_ASSERT(1 == std::distance(constraints_.begin(), constraints_.end())); + PPL_ASSERT(1 == Implementation::num_constraints(constraints_)); // NOTE: modify context_true in place, complementing its last constraint. Matrix& context_false = context_true; Row& last = context_false[context_false.num_rows() - 1]; @@ -2244,7 +2243,8 @@ PIP_Solution_Node::update_tableau( // Compute the column number of big parameter in tableau.t matrix. Variables_Set::const_iterator pos = parameters.find(pip.big_parameter_dimension); - big_dimension = std::distance(parameters.begin(), pos) + 1; + big_dimension = 1U + + static_cast<dimension_type>(std::distance(parameters.begin(), pos)); }
Coefficient_traits::const_reference denom = tableau.denominator(); diff --git a/src/termination.cc b/src/termination.cc index c7a59a4..db33684 100644 --- a/src/termination.cc +++ b/src/termination.cc @@ -148,7 +148,7 @@ fill_constraint_systems_MS(const Constraint_System& cs, Constraint_System& cs_out2) { PPL_ASSERT(cs.space_dimension() % 2 == 0); const dimension_type n = cs.space_dimension() / 2; - const dimension_type m = std::distance(cs.begin(), cs.end()); + const dimension_type m = num_constraints(cs);
#if PRINT_DEBUG_INFO Variable::output_function_type* p_default_output_function @@ -362,8 +362,8 @@ fill_constraint_system_PR(const Constraint_System& cs_before, PPL_ASSERT(cs_after.space_dimension() % 2 == 0); PPL_ASSERT(2*cs_before.space_dimension() == cs_after.space_dimension()); const dimension_type n = cs_before.space_dimension(); - const dimension_type r = distance(cs_before.begin(), cs_before.end()); - const dimension_type s = distance(cs_after.begin(), cs_after.end()); + const dimension_type r = num_constraints(cs_before); + const dimension_type s = num_constraints(cs_after); const dimension_type m = r + s;
// Make sure linear expressions are not reallocated multiple times. @@ -439,7 +439,7 @@ fill_constraint_system_PR_original(const Constraint_System& cs, Linear_Expression& le_out) { PPL_ASSERT(cs.space_dimension() % 2 == 0); const dimension_type n = cs.space_dimension() / 2; - const dimension_type m = distance(cs.begin(), cs.end()); + const dimension_type m = num_constraints(cs);
// Make sure linear expressions are not reallocated multiple times. if (m > 0) @@ -535,7 +535,7 @@ all_affine_ranking_functions_MS(const Constraint_System& cs, Variable::set_output_function(output_function_MS);
output_function_MS_n = n; - output_function_MS_m = std::distance(cs.begin(), cs.end()); + output_function_MS_m = num_constraints(cs);
std::cout << "*** ph1 projected ***" << std::endl; output_function_MS_which = 4; @@ -580,7 +580,7 @@ all_affine_quasi_ranking_functions_MS(const Constraint_System& cs, Variable::set_output_function(output_function_MS);
output_function_MS_n = n; - output_function_MS_m = std::distance(cs.begin(), cs.end()); + output_function_MS_m = num_constraints(cs);
std::cout << "*** ph1 projected ***" << std::endl; output_function_MS_which = 4; @@ -624,8 +624,8 @@ termination_test_PR(const Constraint_System& cs_before, = Variable::get_output_function(); Variable::set_output_function(output_function_PR);
- output_function_PR_r = distance(cs_before.begin(), cs_before.end()); - output_function_PR_s = distance(cs_after.begin(), cs_after.end()); + output_function_PR_r = num_constraints(cs_before); + output_function_PR_s = num_constraints(cs_after);
std::cout << "*** cs_mip ***" << std::endl; using namespace IO_Operators; @@ -656,8 +656,8 @@ one_affine_ranking_function_PR(const Constraint_System& cs_before, = Variable::get_output_function(); Variable::set_output_function(output_function_PR);
- output_function_PR_r = distance(cs_before.begin(), cs_before.end()); - output_function_PR_s = distance(cs_after.begin(), cs_after.end()); + output_function_PR_r = num_constraints(cs_before); + output_function_PR_s = num_constraints(cs_after);
std::cout << "*** cs_mip ***" << std::endl; using namespace IO_Operators; @@ -709,7 +709,7 @@ one_affine_ranking_function_PR_original(const Constraint_System& cs, Generator& mu) { PPL_ASSERT(cs.space_dimension() % 2 == 0); const dimension_type n = cs.space_dimension() / 2; - const dimension_type m = std::distance(cs.begin(), cs.end()); + const dimension_type m = num_constraints(cs);
Constraint_System cs_mip; Linear_Expression le_ineq; @@ -771,8 +771,8 @@ all_affine_ranking_functions_PR(const Constraint_System& cs_before, = Variable::get_output_function(); Variable::set_output_function(output_function_PR);
- output_function_PR_r = distance(cs_before.begin(), cs_before.end()); - output_function_PR_s = distance(cs_after.begin(), cs_after.end()); + output_function_PR_r = num_constraints(cs_before); + output_function_PR_s = num_constraints(cs_after);
std::cout << "*** cs_eqs ***" << std::endl; using namespace IO_Operators; @@ -784,7 +784,7 @@ all_affine_ranking_functions_PR(const Constraint_System& cs_before, NNC_Polyhedron ph(cs_eqs); ph.add_constraint(le_ineq < 0); // u_3 corresponds to space dimensions 0, ..., s - 1. - const dimension_type s = distance(cs_after.begin(), cs_after.end()); + const dimension_type s = num_constraints(cs_after); ph.remove_higher_space_dimensions(s);
#if PRINT_DEBUG_INFO @@ -856,7 +856,7 @@ all_affine_ranking_functions_PR_original(const Constraint_System& cs, NNC_Polyhedron& mu_space) { PPL_ASSERT(cs.space_dimension() % 2 == 0); const dimension_type n = cs.space_dimension() / 2; - const dimension_type m = distance(cs.begin(), cs.end()); + const dimension_type m = num_constraints(cs);
if (m == 0) { // If there are no constraints at all, we have non-termination,