[PPL-devel] [GIT] ppl/ppl(master): Dense_Row, Sparse_Row, Linear_Row: modify the flags' getter and setter methods, to follow strict aliasing rules.
Marco Poletti
poletti.marco at gmail.com
Sun Dec 26 22:56:37 CET 2010
Module: ppl/ppl
Branch: master
Commit: 242769b816b4723acf08fca18d8a3ad8059b5db8
URL: http://www.cs.unipr.it/git/gitweb.cgi?p=ppl/ppl.git;a=commit;h=242769b816b4723acf08fca18d8a3ad8059b5db8
Author: Marco Poletti <poletti.marco at gmail.com>
Date: Sun Dec 26 22:57:26 2010 +0100
Dense_Row, Sparse_Row, Linear_Row: modify the flags' getter and setter methods, to follow strict aliasing rules.
---
src/Constraint.inlines.hh | 6 +++---
src/Dense_Matrix.cc | 2 +-
src/Dense_Row.cc | 2 +-
src/Dense_Row.defs.hh | 8 ++++----
src/Dense_Row.inlines.hh | 8 ++++----
src/Generator.inlines.hh | 6 +++---
src/Linear_Row.cc | 8 +++++++-
src/Linear_Row.defs.hh | 11 +++++++----
src/Linear_Row.inlines.hh | 31 ++++++++++++++++++++++---------
src/Sparse_Matrix.cc | 6 +++---
src/Sparse_Row.cc | 2 +-
src/Sparse_Row.defs.hh | 8 ++++----
src/Sparse_Row.inlines.hh | 8 ++++----
13 files changed, 64 insertions(+), 42 deletions(-)
diff --git a/src/Constraint.inlines.hh b/src/Constraint.inlines.hh
index e474e75..edfbbb4 100644
--- a/src/Constraint.inlines.hh
+++ b/src/Constraint.inlines.hh
@@ -31,9 +31,9 @@ inline
Constraint::Constraint(Linear_Expression& e, Type type, Topology topology) {
PPL_ASSERT(type != STRICT_INEQUALITY || topology == NOT_NECESSARILY_CLOSED);
Linear_Row::swap(e);
- flags() = Flags(topology, (type == EQUALITY
- ? LINE_OR_EQUALITY
- : RAY_OR_POINT_OR_INEQUALITY));
+ set_flags(Flags(topology, (type == EQUALITY
+ ? LINE_OR_EQUALITY
+ : RAY_OR_POINT_OR_INEQUALITY)));
}
inline
diff --git a/src/Dense_Matrix.cc b/src/Dense_Matrix.cc
index 3ed35ad..455c8b6 100644
--- a/src/Dense_Matrix.cc
+++ b/src/Dense_Matrix.cc
@@ -44,7 +44,7 @@ PPL::Dense_Matrix::Dense_Matrix(const dimension_type n_rows,
PPL_ASSERT(n_rows <= max_num_rows());
// Construct in direct order: will destroy in reverse order.
for (dimension_type i = 0; i < n_rows; ++i) {
- rows[i].flags() = row_flags;
+ rows[i].set_flags(row_flags);
rows[i].resize(n_columns, row_capacity);
}
PPL_ASSERT(OK());
diff --git a/src/Dense_Row.cc b/src/Dense_Row.cc
index 36efcbb..dddc104 100644
--- a/src/Dense_Row.cc
+++ b/src/Dense_Row.cc
@@ -333,7 +333,7 @@ PPL::Dense_Row::ascii_load(std::istream& s) {
return false;
if (!(s >> str) || str != "f")
return false;
- return flags().ascii_load(s);
+ return flags_.ascii_load(s);
}
PPL::memory_size_type
diff --git a/src/Dense_Row.defs.hh b/src/Dense_Row.defs.hh
index daa343d..adc2ea8 100644
--- a/src/Dense_Row.defs.hh
+++ b/src/Dense_Row.defs.hh
@@ -126,11 +126,11 @@ public:
*/
void shrink(dimension_type new_size);
- //! Returns a const reference to the flags of \p *this.
- const Flags& flags() const;
+ //! Returns the flags of \p *this.
+ const Flags flags() const;
- //! Returns a non-const reference to the flags of \p *this.
- Flags& flags();
+ //! Sets \p f as the flags of \p *this.
+ void set_flags(Flags f);
//! Returns the size() of the largest possible Dense_Row.
static dimension_type max_size();
diff --git a/src/Dense_Row.inlines.hh b/src/Dense_Row.inlines.hh
index 0dce645..284e9ae 100644
--- a/src/Dense_Row.inlines.hh
+++ b/src/Dense_Row.inlines.hh
@@ -44,14 +44,14 @@ Dense_Row::size() const {
return size_;
}
-inline const Row_Flags&
+inline const Dense_Row::Flags
Dense_Row::flags() const {
return flags_;
}
-inline Row_Flags&
-Dense_Row::flags() {
- return flags_;
+inline void
+Dense_Row::set_flags(Dense_Row::Flags f) {
+ flags_ = f;
}
inline dimension_type
diff --git a/src/Generator.inlines.hh b/src/Generator.inlines.hh
index 06ddb40..99f673f 100644
--- a/src/Generator.inlines.hh
+++ b/src/Generator.inlines.hh
@@ -29,9 +29,9 @@ inline
Generator::Generator(Linear_Expression& e, Type type, Topology topology) {
PPL_ASSERT(type != CLOSURE_POINT || topology == NOT_NECESSARILY_CLOSED);
Linear_Row::swap(e);
- flags() = Flags(topology, (type == LINE
- ? LINE_OR_EQUALITY
- : RAY_OR_POINT_OR_INEQUALITY));
+ set_flags(Flags(topology, (type == LINE
+ ? LINE_OR_EQUALITY
+ : RAY_OR_POINT_OR_INEQUALITY)));
}
inline
diff --git a/src/Linear_Row.cc b/src/Linear_Row.cc
index f55ef65..87231a8 100644
--- a/src/Linear_Row.cc
+++ b/src/Linear_Row.cc
@@ -222,7 +222,13 @@ PPL::Linear_Row::ascii_load(std::istream& s) {
return false;
if (!(s >> str) || str != "f")
return false;
- return flags().ascii_load(s);
+
+ Flags f;
+ if (!f.ascii_load(s))
+ return false;
+ set_flags(f);
+
+ return true;
}
bool
diff --git a/src/Linear_Row.defs.hh b/src/Linear_Row.defs.hh
index 264c640..6103889 100644
--- a/src/Linear_Row.defs.hh
+++ b/src/Linear_Row.defs.hh
@@ -186,6 +186,9 @@ public:
private:
//! Builds the type from a bit-mask.
explicit Flags(base_type mask);
+
+ //! Constructor from a Dense_Row::Flags object.
+ explicit Flags(Dense_Row::Flags flags);
//! \name The bits that are currently in use
//@{
@@ -238,11 +241,11 @@ public:
//! \name Flags inspection methods
//@{
- //! Returns a const reference to the flags of \p *this.
- const Flags& flags() const;
+ //! Returns the flags of \p *this.
+ const Flags flags() const;
- //! Returns a non-const reference to the flags of \p *this.
- Flags& flags();
+ //! Sets \p f as the flags of \p *this.
+ void set_flags(Flags f);
//! Returns the topological kind of \p *this.
Topology topology() const;
diff --git a/src/Linear_Row.inlines.hh b/src/Linear_Row.inlines.hh
index 563af89..f0357e3 100644
--- a/src/Linear_Row.inlines.hh
+++ b/src/Linear_Row.inlines.hh
@@ -36,6 +36,11 @@ Linear_Row::Flags::Flags()
}
inline
+Linear_Row::Flags::Flags(Dense_Row::Flags f)
+: Dense_Row::Flags(f) {
+}
+
+inline
Linear_Row::Flags::Flags(const Topology t)
: Dense_Row::Flags(t << nnc_bit) {
#ifndef NDEBUG
@@ -124,14 +129,14 @@ Linear_Row::Flags::operator!=(const Flags& y) const {
return !operator==(y);
}
-inline const Linear_Row::Flags&
+inline const Linear_Row::Flags
Linear_Row::flags() const {
- return static_cast<const Flags&>(Dense_Row::flags());
+ return Flags(Dense_Row::flags());
}
-inline Linear_Row::Flags&
-Linear_Row::flags() {
- return static_cast<Flags&>(Dense_Row::flags());
+inline void
+Linear_Row::set_flags(Flags f) {
+ Dense_Row::set_flags(f);
}
inline bool
@@ -208,22 +213,30 @@ Linear_Row::topology() const {
inline void
Linear_Row::set_is_line_or_equality() {
- flags().set_is_line_or_equality();
+ Flags f = flags();
+ f.set_is_line_or_equality();
+ set_flags(f);
}
inline void
Linear_Row::set_is_ray_or_point_or_inequality() {
- flags().set_is_ray_or_point_or_inequality();
+ Flags f = flags();
+ f.set_is_ray_or_point_or_inequality();
+ set_flags(f);
}
inline void
Linear_Row::set_necessarily_closed() {
- flags().set_necessarily_closed();
+ Flags f = flags();
+ f.set_necessarily_closed();
+ set_flags(f);
}
inline void
Linear_Row::set_not_necessarily_closed() {
- flags().set_not_necessarily_closed();
+ Flags f = flags();
+ f.set_not_necessarily_closed();
+ set_flags(f);
}
inline Coefficient_traits::const_reference
diff --git a/src/Sparse_Matrix.cc b/src/Sparse_Matrix.cc
index 339e500..1be6aa2 100644
--- a/src/Sparse_Matrix.cc
+++ b/src/Sparse_Matrix.cc
@@ -29,7 +29,7 @@ namespace PPL = Parma_Polyhedra_Library;
PPL::Sparse_Matrix::Sparse_Matrix(dimension_type n, Flags row_flags)
: rows(n), num_columns_(n) {
for (dimension_type i = 0; i < rows.size(); ++i) {
- rows[i].flags() = row_flags;
+ rows[i].set_flags(row_flags);
rows[i].resize(num_columns_);
}
PPL_ASSERT(OK());
@@ -40,7 +40,7 @@ PPL::Sparse_Matrix::Sparse_Matrix(dimension_type num_rows,
Flags row_flags)
: rows(num_rows), num_columns_(num_columns) {
for (dimension_type i = 0; i < rows.size(); ++i) {
- rows[i].flags() = row_flags;
+ rows[i].set_flags(row_flags);
rows[i].resize(num_columns_);
}
PPL_ASSERT(OK());
@@ -54,7 +54,7 @@ PPL::Sparse_Matrix::resize(dimension_type num_rows,
rows.resize(num_rows);
if (old_num_rows < num_rows) {
for (dimension_type i = old_num_rows; i < num_rows; ++i) {
- rows[i].flags() = row_flags;
+ rows[i].set_flags(row_flags);
rows[i].resize(num_columns);
}
if (num_columns_ != num_columns) {
diff --git a/src/Sparse_Row.cc b/src/Sparse_Row.cc
index 7a7a078..fe8ed66 100644
--- a/src/Sparse_Row.cc
+++ b/src/Sparse_Row.cc
@@ -105,7 +105,7 @@ PPL::Sparse_Row::operator=(const PPL::Dense_Row& row) {
Sparse_Row_from_Dense_Row_helper_function(row));
std::swap(tree, tmp_tree);
size_ = row.size();
- flags() = row.flags();
+ flags_ = row.flags();
PPL_ASSERT(OK());
return *this;
diff --git a/src/Sparse_Row.defs.hh b/src/Sparse_Row.defs.hh
index 264f569..7b1c8b3 100644
--- a/src/Sparse_Row.defs.hh
+++ b/src/Sparse_Row.defs.hh
@@ -266,11 +266,11 @@ public:
//! Returns the size() of the largest possible Sparse_Row.
static dimension_type max_size();
- //! Returns the flags associated with this row.
- const Flags& flags() const;
+ //! Returns the flags of \p *this.
+ const Flags flags() const;
- //! Returns a reference to the flags associated with this row.
- Flags& flags();
+ //! Sets \p f as the flags of \p *this.
+ void set_flags(Flags f);
//! Resets all the elements of this row.
/*!
diff --git a/src/Sparse_Row.inlines.hh b/src/Sparse_Row.inlines.hh
index 1d67b02..a101fc3 100644
--- a/src/Sparse_Row.inlines.hh
+++ b/src/Sparse_Row.inlines.hh
@@ -145,14 +145,14 @@ Sparse_Row::max_size() {
return CO_Tree::max_size();
}
-inline const Sparse_Row::Flags&
+inline const Sparse_Row::Flags
Sparse_Row::flags() const {
return flags_;
}
-inline Sparse_Row::Flags&
-Sparse_Row::flags() {
- return flags_;
+inline void
+Sparse_Row::set_flags(Sparse_Row::Flags f) {
+ flags_ = f;
}
inline void
More information about the PPL-devel
mailing list