[PPL-devel] [GIT] ppl/ppl(master): For readability, prefer infix notation for operator[ ].

Enea Zaffanella zaffanella at cs.unipr.it
Fri Sep 30 16:07:35 CEST 2011


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

Author: Enea Zaffanella <zaffanella at cs.unipr.it>
Date:   Fri Sep 30 13:50:14 2011 +0200

For readability, prefer infix notation for operator[].

---

 src/Congruence.cc             |    4 ++--
 src/Congruence.inlines.hh     |    8 +++++---
 src/Grid_Generator.cc         |   40 ++++++++++++++++++++++------------------
 src/Grid_Generator.inlines.hh |   16 +++++++++-------
 src/Grid_Generator_System.cc  |   13 +++++++------
 5 files changed, 45 insertions(+), 36 deletions(-)

diff --git a/src/Congruence.cc b/src/Congruence.cc
index ee16740..4ac23d5 100644
--- a/src/Congruence.cc
+++ b/src/Congruence.cc
@@ -185,7 +185,7 @@ PPL::Congruence::is_tautological() const {
       || (is_proper_congruence()
 	  && (inhomogeneous_term() % modulus() == 0))) {
     for (unsigned i = space_dimension(); i > 0; --i)
-      if (operator[](i) != 0)
+      if ((*this)[i] != 0)
 	return false;
     return true;
   }
@@ -199,7 +199,7 @@ PPL::Congruence::is_inconsistent() const {
 	  && ((inhomogeneous_term() % modulus()) == 0)))
     return false;
   for (unsigned i = space_dimension(); i > 0; --i)
-    if (operator[](i) != 0)
+    if ((*this)[i] != 0)
       return false;
   return true;
 }
diff --git a/src/Congruence.inlines.hh b/src/Congruence.inlines.hh
index b74261b..5c0ed32 100644
--- a/src/Congruence.inlines.hh
+++ b/src/Congruence.inlines.hh
@@ -195,7 +195,7 @@ Congruence::is_equality() const {
 inline bool
 Congruence::is_equal_at_dimension(dimension_type dim,
 				  const Congruence& cg) const {
-  return operator[](dim) * cg.modulus() == cg[dim] * modulus();
+  return (*this)[dim] * cg.modulus() == cg[dim] * modulus();
 }
 
 inline void
@@ -205,8 +205,10 @@ Congruence::set_is_equality() {
 
 inline void
 Congruence::negate(dimension_type start, dimension_type end) {
-  while (start <= end)
-    neg_assign(operator[](start++));
+  while (start <= end) {
+    neg_assign((*this)[start]);
+    ++start;
+  }
 }
 
 inline memory_size_type
diff --git a/src/Grid_Generator.cc b/src/Grid_Generator.cc
index cb7b90d..dca4980 100644
--- a/src/Grid_Generator.cc
+++ b/src/Grid_Generator.cc
@@ -112,21 +112,22 @@ PPL::Grid_Generator::grid_line(const Linear_Expression& e) {
 
 void
 PPL::Grid_Generator::coefficient_swap(Grid_Generator& y) {
+  Grid_Generator& x = *this;
   // Swap one coefficient at a time into *this.  Doing this instead of
   // swapping the entire row ensures that the row keeps the same
   // capacity.
   if (y.is_line())
-    set_is_line();
+    x.set_is_line();
   else
-    set_is_ray_or_point();
-  PPL_ASSERT(size() > 0);
+    x.set_is_ray_or_point();
+  PPL_ASSERT(x.size() > 0);
   PPL_ASSERT(y.size() > 0);
-  dimension_type sz = size() - 1;
+  dimension_type x_sz = x.size() - 1;
   dimension_type y_sz = y.size() - 1;
   // Swap parameter divisors.
-  std::swap(operator[](sz), y[y_sz]);
-  for (dimension_type j = (sz > y_sz ? y_sz : sz); j-- > 0; )
-    std::swap(operator[](j), y[j]);
+  std::swap(x[x_sz], y[y_sz]);
+  for (dimension_type j = (x_sz > y_sz ? y_sz : x_sz); j-- > 0; )
+    std::swap(x[j], y[j]);
 }
 
 void
@@ -192,8 +193,9 @@ PPL::Grid_Generator::set_is_parameter() {
     set_is_parameter_or_point();
   else if (!is_line_or_parameter()) {
     // The generator is a point.
-    Generator::operator[](size() - 1) = Generator::operator[](0);
-    Generator::operator[](0) = 0;
+    Grid_Generator& x = *this;
+    x[size() - 1] = x[0];
+    x[0] = 0;
   }
 }
 
@@ -228,11 +230,12 @@ PPL::Grid_Generator::is_equivalent_to(const Grid_Generator& y) const {
 
 bool
 PPL::Grid_Generator::is_equal_to(const Grid_Generator& y) const {
-  if (type() != y.type())
+  const Grid_Generator& x = *this;
+  if (x.type() != y.type())
     return false;
-  for (dimension_type col = (is_parameter() ? size() : size() - 1);
-       col-- > 0; )
-    if (Generator::operator[](col) != y.Generator::operator[](col))
+  for (dimension_type
+         col = x.size() - (x.is_parameter() ? 0 : 1); col-- > 0; )
+    if (x[col] != y[col])
       return false;
   return true;
 }
@@ -240,8 +243,9 @@ PPL::Grid_Generator::is_equal_to(const Grid_Generator& y) const {
 bool
 PPL::Grid_Generator::all_homogeneous_terms_are_zero() const {
   // Start at size() - 1 to avoid the extra grid generator column.
-  for (dimension_type i = size() - 1; --i > 0; )
-    if (operator[](i) != 0)
+  const Grid_Generator& gg = *this;
+  for (dimension_type i = gg.size() - 1; --i > 0; )
+    if (gg[i] != 0)
       return false;
   return true;
 }
@@ -259,7 +263,7 @@ PPL::Grid_Generator::scale_to_divisor(Coefficient_traits::const_reference d) {
     PPL_ASSERT(factor > 0);
     if (factor > 1)
       for (dimension_type col = size() - 2; col >= 1; --col)
-	Generator::operator[](col) *= factor;
+	(*this)[col] *= factor;
   }
 }
 
@@ -387,7 +391,7 @@ PPL::Grid_Generator::OK() const {
 
   switch (type()) {
   case Grid_Generator::LINE:
-    if (operator[](0) != 0) {
+    if ((*this)[0] != 0) {
 #ifndef NDEBUG
       std::cerr << "Inhomogeneous terms of lines must be zero!"
 		<< std::endl;
@@ -397,7 +401,7 @@ PPL::Grid_Generator::OK() const {
     break;
 
   case Grid_Generator::PARAMETER:
-    if (operator[](0) != 0) {
+    if ((*this)[0] != 0) {
 #ifndef NDEBUG
       std::cerr << "Inhomogeneous terms of parameters must be zero!"
 		<< std::endl;
diff --git a/src/Grid_Generator.inlines.hh b/src/Grid_Generator.inlines.hh
index 199e8a1..c1405da 100644
--- a/src/Grid_Generator.inlines.hh
+++ b/src/Grid_Generator.inlines.hh
@@ -111,9 +111,9 @@ inline void
 Grid_Generator::set_divisor(Coefficient_traits::const_reference d) {
   PPL_ASSERT(!is_line());
   if (is_line_or_parameter())
-    Generator::operator[](size() - 1) = d;
+    (*this)[size() - 1] = d;
   else
-    Generator::operator[](0) = d;
+    (*this)[0] = d;
 }
 
 inline Coefficient_traits::const_reference
@@ -121,15 +121,15 @@ Grid_Generator::divisor() const {
   if (is_line())
     throw_invalid_argument("divisor()", "*this is a line");
   if (is_line_or_parameter())
-    return Generator::operator[](size() - 1);
+    return (*this)[size() - 1];
   else
-    return Generator::operator[](0);
+    return (*this)[0];
 }
 
 inline bool
 Grid_Generator::is_equal_at_dimension(dimension_type dim,
 				      const Grid_Generator& gg) const {
-  return operator[](dim) * gg.divisor() == gg[dim] * divisor();
+  return (*this)[dim] * gg.divisor() == gg[dim] * divisor();
 }
 
 inline void
@@ -156,8 +156,10 @@ Grid_Generator::operator=(const Generator& g) {
 
 inline void
 Grid_Generator::negate(dimension_type start, dimension_type end) {
-  while (start <= end)
-    neg_assign(operator[](start++));
+  while (start <= end) {
+    neg_assign((*this)[start]);
+    ++start;
+  }
 }
 
 inline Coefficient_traits::const_reference
diff --git a/src/Grid_Generator_System.cc b/src/Grid_Generator_System.cc
index 7e42a4d..7e6bdad 100644
--- a/src/Grid_Generator_System.cc
+++ b/src/Grid_Generator_System.cc
@@ -54,7 +54,7 @@ PPL::Grid_Generator_System::recycling_insert(Grid_Generator_System& gs) {
   // of swapping each entire row.  This ensures that the added rows
   // have the same capacities as the existing rows.
   for (dimension_type i = gs_num_rows; i-- > 0; )
-    operator[](old_num_rows + i).coefficient_swap(gs[i]);
+    (*this)[old_num_rows + i].coefficient_swap(gs[i]);
 }
 
 void
@@ -78,7 +78,7 @@ PPL::Grid_Generator_System::recycling_insert(Grid_Generator& g) {
   // Swap one coefficient at a time into the newly added rows, instead
   // of swapping each entire row.  This ensures that the added rows
   // have the same capacities as the existing rows.
-  operator[](old_num_rows).coefficient_swap(g);
+  (*this)[old_num_rows].coefficient_swap(g);
 }
 
 void
@@ -206,10 +206,11 @@ PPL_OUTPUT_DEFINITIONS(Grid_Generator_System)
 
 void
 PPL::Grid_Generator_System::ascii_dump(std::ostream& s) const {
-  const dimension_type num_rows = this->num_rows();
-  s << num_rows << " x " << num_columns() << '\n';
+  const Grid_Generator_System& ggs = *this;
+  const dimension_type num_rows = ggs.num_rows();
+  s << num_rows << " x " << ggs.num_columns() << '\n';
   for (dimension_type i = 0; i < num_rows; ++i)
-    operator[](i).ascii_dump(s);
+    ggs[i].ascii_dump(s);
 }
 
 bool
@@ -320,7 +321,7 @@ PPL::Grid_Generator_System
   // Set the diagonal element of each added rows.
   dimension_type num_rows = this->num_rows();
   for (dimension_type row = num_rows - dims; row < num_rows; ++row, ++col)
-    const_cast<Coefficient&>(operator[](row)[col]) = 1;
+    const_cast<Coefficient&>((*this)[row][col]) = 1;
 }
 
 void




More information about the PPL-devel mailing list