Commit 38f2ca32 by Diego Novillo Committed by Diego Novillo

Convert vec<> into a POD.

This fixes PR 55398 by making vec<> a true POD.  I thought we could get
away with having private fields, but we can't.  We fail to pass vec<>
instances through varargs.

The patch makes every field public and mangles the field names in the
hope that no future patch will try to make use of them directly.  It's
horrible, but I could not think of anything better.

Tested with clang++ as the host compiler.

2012-11-20  Diego Novillo  <dnovillo@google.com>

    PR middle-end/55398
    * vec.h (class vec_prefix): Make every field public.
    Rename field alloc_ to alloc_PRIVATE_.
    Rename field num_ to num_PRIVATE_.
    Update all users.
    (class vec<T, A, vl_embed>): Make every field public.
    Rename field pfx_ to pfx_PRIVATE_.
    Rename field data_ to data_PRIVATE_.
    Update all users.
    (class vec<T, A, vl_ptr>): Make every field public.
    Rename field vec_ to vec_PRIVATE_.
    Update all users.

From-SVN: r193667
parent 4a397c3e
2012-11-20 Diego Novillo <dnovillo@google.com>
PR middle-end/55398
* vec.h (class vec_prefix): Make every field public.
Rename field alloc_ to alloc_PRIVATE_.
Rename field num_ to num_PRIVATE_.
Update all users.
(class vec<T, A, vl_embed>): Make every field public.
Rename field pfx_ to pfx_PRIVATE_.
Rename field data_ to data_PRIVATE_.
Update all users.
(class vec<T, A, vl_ptr>): Make every field public.
Rename field vec_ to vec_PRIVATE_.
Update all users.
2012-11-20 Kai Tietz <ktietz@redhat.com> 2012-11-20 Kai Tietz <ktietz@redhat.com>
PR target/55268 PR target/55268
...@@ -121,8 +121,8 @@ vec_descriptor (const char *name, int line, const char *function) ...@@ -121,8 +121,8 @@ vec_descriptor (const char *name, int line, const char *function)
/* Account the overhead. */ /* Account the overhead. */
void void
vec_prefix::register_overhead (size_t size, const char *name, int line, vec_prefix::register_overhead_PRIVATE_ (size_t size, const char *name, int line,
const char *function) const char *function)
{ {
struct vec_descriptor *loc = vec_descriptor (name, line, function); struct vec_descriptor *loc = vec_descriptor (name, line, function);
struct ptr_hash_entry *p = XNEW (struct ptr_hash_entry); struct ptr_hash_entry *p = XNEW (struct ptr_hash_entry);
...@@ -148,7 +148,7 @@ vec_prefix::register_overhead (size_t size, const char *name, int line, ...@@ -148,7 +148,7 @@ vec_prefix::register_overhead (size_t size, const char *name, int line,
/* Notice that the memory allocated for the vector has been freed. */ /* Notice that the memory allocated for the vector has been freed. */
void void
vec_prefix::release_overhead (void) vec_prefix::release_overhead_PRIVATE_ (void)
{ {
PTR *slot = htab_find_slot_with_hash (ptr_hash, this, PTR *slot = htab_find_slot_with_hash (ptr_hash, this,
htab_hash_pointer (this), htab_hash_pointer (this),
...@@ -165,15 +165,16 @@ vec_prefix::release_overhead (void) ...@@ -165,15 +165,16 @@ vec_prefix::release_overhead (void)
exponentially. PFX is the control data for the vector. */ exponentially. PFX is the control data for the vector. */
unsigned unsigned
vec_prefix::calculate_allocation (vec_prefix *pfx, unsigned reserve, bool exact) vec_prefix::calculate_allocation_PRIVATE_ (vec_prefix *pfx, unsigned reserve,
bool exact)
{ {
unsigned alloc = 0; unsigned alloc = 0;
unsigned num = 0; unsigned num = 0;
if (pfx) if (pfx)
{ {
alloc = pfx->alloc_; alloc = pfx->alloc_PRIVATE_;
num = pfx->num_; num = pfx->num_PRIVATE_;
} }
else if (!reserve) else if (!reserve)
/* If there's no vector, and we've not requested anything, then we /* If there's no vector, and we've not requested anything, then we
......
...@@ -216,11 +216,13 @@ extern void dump_vec_loc_statistics (void); ...@@ -216,11 +216,13 @@ extern void dump_vec_loc_statistics (void);
class vec_prefix class vec_prefix
{ {
protected: /* FIXME - These fields should be private, but we need to cater to
compilers that have stricter notions of PODness for types. */
public:
/* Memory allocation support routines in vec.c. */ /* Memory allocation support routines in vec.c. */
void register_overhead (size_t, const char *, int, const char *); void register_overhead_PRIVATE_ (size_t, const char *, int, const char *);
void release_overhead (void); void release_overhead_PRIVATE_ (void);
static unsigned calculate_allocation (vec_prefix *, unsigned, bool); static unsigned calculate_allocation_PRIVATE_ (vec_prefix *, unsigned, bool);
/* Note that vec_prefix should be a base class for vec, but we use /* Note that vec_prefix should be a base class for vec, but we use
offsetof() on vector fields of tree structures (e.g., offsetof() on vector fields of tree structures (e.g.,
...@@ -236,8 +238,8 @@ protected: ...@@ -236,8 +238,8 @@ protected:
friend struct va_heap; friend struct va_heap;
friend struct va_stack; friend struct va_stack;
unsigned alloc_; unsigned alloc_PRIVATE_;
unsigned num_; unsigned num_PRIVATE_;
}; };
template<typename, typename, typename> class vec; template<typename, typename, typename> class vec;
...@@ -285,8 +287,8 @@ inline void ...@@ -285,8 +287,8 @@ inline void
va_heap::reserve (vec<T, va_heap, vl_embed> *&v, unsigned reserve, bool exact va_heap::reserve (vec<T, va_heap, vl_embed> *&v, unsigned reserve, bool exact
MEM_STAT_DECL) MEM_STAT_DECL)
{ {
unsigned alloc = vec_prefix::calculate_allocation (v ? &v->pfx_ : 0, reserve, unsigned alloc = vec_prefix::calculate_allocation_PRIVATE_ (
exact); v ? &v->pfx_PRIVATE_ : 0, reserve, exact);
if (!alloc) if (!alloc)
{ {
release (v); release (v);
...@@ -294,7 +296,7 @@ va_heap::reserve (vec<T, va_heap, vl_embed> *&v, unsigned reserve, bool exact ...@@ -294,7 +296,7 @@ va_heap::reserve (vec<T, va_heap, vl_embed> *&v, unsigned reserve, bool exact
} }
if (GATHER_STATISTICS && v) if (GATHER_STATISTICS && v)
v->pfx_.release_overhead (); v->pfx_PRIVATE_.release_overhead_PRIVATE_ ();
size_t size = vec<T, va_heap, vl_embed>::embedded_size (alloc); size_t size = vec<T, va_heap, vl_embed>::embedded_size (alloc);
unsigned nelem = v ? v->length () : 0; unsigned nelem = v ? v->length () : 0;
...@@ -302,7 +304,7 @@ va_heap::reserve (vec<T, va_heap, vl_embed> *&v, unsigned reserve, bool exact ...@@ -302,7 +304,7 @@ va_heap::reserve (vec<T, va_heap, vl_embed> *&v, unsigned reserve, bool exact
v->embedded_init (alloc, nelem); v->embedded_init (alloc, nelem);
if (GATHER_STATISTICS) if (GATHER_STATISTICS)
v->pfx_.register_overhead (size FINAL_PASS_MEM_STAT); v->pfx_PRIVATE_.register_overhead_PRIVATE_ (size FINAL_PASS_MEM_STAT);
} }
...@@ -312,8 +314,11 @@ template<typename T> ...@@ -312,8 +314,11 @@ template<typename T>
void void
va_heap::release (vec<T, va_heap, vl_embed> *&v) va_heap::release (vec<T, va_heap, vl_embed> *&v)
{ {
if (v == NULL)
return;
if (GATHER_STATISTICS) if (GATHER_STATISTICS)
v->pfx_.release_overhead (); v->pfx_PRIVATE_.release_overhead_PRIVATE_ ();
::free (v); ::free (v);
v = NULL; v = NULL;
} }
...@@ -349,8 +354,8 @@ void ...@@ -349,8 +354,8 @@ void
va_gc::reserve (vec<T, A, vl_embed> *&v, unsigned reserve, bool exact va_gc::reserve (vec<T, A, vl_embed> *&v, unsigned reserve, bool exact
MEM_STAT_DECL) MEM_STAT_DECL)
{ {
unsigned alloc = vec_prefix::calculate_allocation (v ? &v->pfx_ : 0, reserve, unsigned alloc = vec_prefix::calculate_allocation_PRIVATE_ (
exact); v ? &v->pfx_PRIVATE_ : 0, reserve, exact);
if (!alloc) if (!alloc)
{ {
::ggc_free (v); ::ggc_free (v);
...@@ -418,9 +423,9 @@ void ...@@ -418,9 +423,9 @@ void
va_stack::alloc (vec<T, va_stack, vl_ptr> &v, unsigned nelems, va_stack::alloc (vec<T, va_stack, vl_ptr> &v, unsigned nelems,
vec<T, va_stack, vl_embed> *space) vec<T, va_stack, vl_embed> *space)
{ {
v.vec_ = space; v.vec_PRIVATE_ = space;
register_stack_vec (static_cast<void *> (v.vec_)); register_stack_vec (static_cast<void *> (v.vec_PRIVATE_));
v.vec_->embedded_init (nelems, 0); v.vec_PRIVATE_->embedded_init (nelems, 0);
} }
...@@ -447,15 +452,17 @@ va_stack::reserve (vec<T, va_stack, vl_embed> *&v, unsigned nelems, bool exact ...@@ -447,15 +452,17 @@ va_stack::reserve (vec<T, va_stack, vl_embed> *&v, unsigned nelems, bool exact
} }
/* Move VEC_ to the heap. */ /* Move VEC_ to the heap. */
nelems += v->pfx_.num_; nelems += v->pfx_PRIVATE_.num_PRIVATE_;
vec<T, va_stack, vl_embed> *oldvec = v; vec<T, va_stack, vl_embed> *oldvec = v;
v = NULL; v = NULL;
va_heap::reserve (reinterpret_cast<vec<T, va_heap, vl_embed> *&>(v), nelems, va_heap::reserve (reinterpret_cast<vec<T, va_heap, vl_embed> *&>(v), nelems,
exact); exact);
if (v && oldvec) if (v && oldvec)
{ {
v->pfx_.num_ = oldvec->length (); v->pfx_PRIVATE_.num_PRIVATE_ = oldvec->length ();
memcpy (v->data_, oldvec->data_, oldvec->length () * sizeof (T)); memcpy (v->data_PRIVATE_,
oldvec->data_PRIVATE_,
oldvec->length () * sizeof (T));
} }
} }
...@@ -467,6 +474,9 @@ template<typename T> ...@@ -467,6 +474,9 @@ template<typename T>
void void
va_stack::release (vec<T, va_stack, vl_embed> *&v) va_stack::release (vec<T, va_stack, vl_embed> *&v)
{ {
if (v == NULL)
return;
int ix = stack_vec_register_index (static_cast<void *> (v)); int ix = stack_vec_register_index (static_cast<void *> (v));
if (ix >= 0) if (ix >= 0)
{ {
...@@ -531,11 +541,11 @@ template<typename T, typename A> ...@@ -531,11 +541,11 @@ template<typename T, typename A>
class GTY((user)) vec<T, A, vl_embed> class GTY((user)) vec<T, A, vl_embed>
{ {
public: public:
unsigned allocated (void) const { return pfx_.alloc_; } unsigned allocated (void) const { return pfx_PRIVATE_.alloc_PRIVATE_; }
unsigned length (void) const { return pfx_.num_; } unsigned length (void) const { return pfx_PRIVATE_.num_PRIVATE_; }
bool is_empty (void) const { return pfx_.num_ == 0; } bool is_empty (void) const { return pfx_PRIVATE_.num_PRIVATE_ == 0; }
T *address (void) { return data_; } T *address (void) { return data_PRIVATE_; }
const T *address (void) const { return data_; } const T *address (void) const { return data_PRIVATE_; }
const T &operator[] (unsigned) const; const T &operator[] (unsigned) const;
T &operator[] (unsigned); T &operator[] (unsigned);
T &last (void); T &last (void);
...@@ -568,9 +578,10 @@ public: ...@@ -568,9 +578,10 @@ public:
friend struct va_heap; friend struct va_heap;
friend struct va_stack; friend struct va_stack;
private: /* FIXME - These fields should be private, but we need to cater to
vec_prefix pfx_; compilers that have stricter notions of PODness for types. */
T data_[1]; vec_prefix pfx_PRIVATE_;
T data_PRIVATE_[1];
}; };
...@@ -782,16 +793,16 @@ template<typename T, typename A> ...@@ -782,16 +793,16 @@ template<typename T, typename A>
inline const T & inline const T &
vec<T, A, vl_embed>::operator[] (unsigned ix) const vec<T, A, vl_embed>::operator[] (unsigned ix) const
{ {
gcc_checking_assert (ix < pfx_.num_); gcc_checking_assert (ix < pfx_PRIVATE_.num_PRIVATE_);
return data_[ix]; return data_PRIVATE_[ix];
} }
template<typename T, typename A> template<typename T, typename A>
inline T & inline T &
vec<T, A, vl_embed>::operator[] (unsigned ix) vec<T, A, vl_embed>::operator[] (unsigned ix)
{ {
gcc_checking_assert (ix < pfx_.num_); gcc_checking_assert (ix < pfx_PRIVATE_.num_PRIVATE_);
return data_[ix]; return data_PRIVATE_[ix];
} }
...@@ -801,8 +812,8 @@ template<typename T, typename A> ...@@ -801,8 +812,8 @@ template<typename T, typename A>
inline T & inline T &
vec<T, A, vl_embed>::last (void) vec<T, A, vl_embed>::last (void)
{ {
gcc_checking_assert (pfx_.num_ > 0); gcc_checking_assert (pfx_PRIVATE_.num_PRIVATE_ > 0);
return (*this)[pfx_.num_ - 1]; return (*this)[pfx_PRIVATE_.num_PRIVATE_ - 1];
} }
...@@ -816,7 +827,7 @@ template<typename T, typename A> ...@@ -816,7 +827,7 @@ template<typename T, typename A>
inline bool inline bool
vec<T, A, vl_embed>::space (unsigned nelems) const vec<T, A, vl_embed>::space (unsigned nelems) const
{ {
return pfx_.alloc_ - pfx_.num_ >= nelems; return pfx_PRIVATE_.alloc_PRIVATE_ - pfx_PRIVATE_.num_PRIVATE_ >= nelems;
} }
...@@ -831,9 +842,9 @@ template<typename T, typename A> ...@@ -831,9 +842,9 @@ template<typename T, typename A>
inline bool inline bool
vec<T, A, vl_embed>::iterate (unsigned ix, T *ptr) const vec<T, A, vl_embed>::iterate (unsigned ix, T *ptr) const
{ {
if (ix < pfx_.num_) if (ix < pfx_PRIVATE_.num_PRIVATE_)
{ {
*ptr = data_[ix]; *ptr = data_PRIVATE_[ix];
return true; return true;
} }
else else
...@@ -857,9 +868,9 @@ template<typename T, typename A> ...@@ -857,9 +868,9 @@ template<typename T, typename A>
inline bool inline bool
vec<T, A, vl_embed>::iterate (unsigned ix, T **ptr) const vec<T, A, vl_embed>::iterate (unsigned ix, T **ptr) const
{ {
if (ix < pfx_.num_) if (ix < pfx_PRIVATE_.num_PRIVATE_)
{ {
*ptr = CONST_CAST (T *, &data_[ix]); *ptr = CONST_CAST (T *, &data_PRIVATE_[ix]);
return true; return true;
} }
else else
...@@ -882,7 +893,7 @@ vec<T, A, vl_embed>::copy (ALONE_MEM_STAT_DECL) const ...@@ -882,7 +893,7 @@ vec<T, A, vl_embed>::copy (ALONE_MEM_STAT_DECL) const
{ {
vec_alloc (new_vec, len PASS_MEM_STAT); vec_alloc (new_vec, len PASS_MEM_STAT);
new_vec->embedded_init (len, len); new_vec->embedded_init (len, len);
memcpy (new_vec->address(), data_, sizeof (T) * len); memcpy (new_vec->address(), data_PRIVATE_, sizeof (T) * len);
} }
return new_vec; return new_vec;
} }
...@@ -900,7 +911,7 @@ vec<T, A, vl_embed>::splice (vec<T, A, vl_embed> &src) ...@@ -900,7 +911,7 @@ vec<T, A, vl_embed>::splice (vec<T, A, vl_embed> &src)
{ {
gcc_checking_assert (space (len)); gcc_checking_assert (space (len));
memcpy (address() + length(), src.address(), len * sizeof (T)); memcpy (address() + length(), src.address(), len * sizeof (T));
pfx_.num_ += len; pfx_PRIVATE_.num_PRIVATE_ += len;
} }
} }
...@@ -922,7 +933,7 @@ inline T * ...@@ -922,7 +933,7 @@ inline T *
vec<T, A, vl_embed>::quick_push (const T &obj) vec<T, A, vl_embed>::quick_push (const T &obj)
{ {
gcc_checking_assert (space (1)); gcc_checking_assert (space (1));
T *slot = &data_[pfx_.num_++]; T *slot = &data_PRIVATE_[pfx_PRIVATE_.num_PRIVATE_++];
*slot = obj; *slot = obj;
return slot; return slot;
} }
...@@ -935,7 +946,7 @@ inline T & ...@@ -935,7 +946,7 @@ inline T &
vec<T, A, vl_embed>::pop (void) vec<T, A, vl_embed>::pop (void)
{ {
gcc_checking_assert (length () > 0); gcc_checking_assert (length () > 0);
return data_[--pfx_.num_]; return data_PRIVATE_[--pfx_PRIVATE_.num_PRIVATE_];
} }
...@@ -947,7 +958,7 @@ inline void ...@@ -947,7 +958,7 @@ inline void
vec<T, A, vl_embed>::truncate (unsigned size) vec<T, A, vl_embed>::truncate (unsigned size)
{ {
gcc_checking_assert (length () >= size); gcc_checking_assert (length () >= size);
pfx_.num_ = size; pfx_PRIVATE_.num_PRIVATE_ = size;
} }
...@@ -960,8 +971,8 @@ vec<T, A, vl_embed>::quick_insert (unsigned ix, const T &obj) ...@@ -960,8 +971,8 @@ vec<T, A, vl_embed>::quick_insert (unsigned ix, const T &obj)
{ {
gcc_checking_assert (length () < allocated ()); gcc_checking_assert (length () < allocated ());
gcc_checking_assert (ix <= length ()); gcc_checking_assert (ix <= length ());
T *slot = &data_[ix]; T *slot = &data_PRIVATE_[ix];
memmove (slot + 1, slot, (pfx_.num_++ - ix) * sizeof (T)); memmove (slot + 1, slot, (pfx_PRIVATE_.num_PRIVATE_++ - ix) * sizeof (T));
*slot = obj; *slot = obj;
} }
...@@ -975,8 +986,8 @@ inline void ...@@ -975,8 +986,8 @@ inline void
vec<T, A, vl_embed>::ordered_remove (unsigned ix) vec<T, A, vl_embed>::ordered_remove (unsigned ix)
{ {
gcc_checking_assert (ix < length()); gcc_checking_assert (ix < length());
T *slot = &data_[ix]; T *slot = &data_PRIVATE_[ix];
memmove (slot, slot + 1, (--pfx_.num_ - ix) * sizeof (T)); memmove (slot, slot + 1, (--pfx_PRIVATE_.num_PRIVATE_ - ix) * sizeof (T));
} }
...@@ -988,7 +999,7 @@ inline void ...@@ -988,7 +999,7 @@ inline void
vec<T, A, vl_embed>::unordered_remove (unsigned ix) vec<T, A, vl_embed>::unordered_remove (unsigned ix)
{ {
gcc_checking_assert (ix < length()); gcc_checking_assert (ix < length());
data_[ix] = data_[--pfx_.num_]; data_PRIVATE_[ix] = data_PRIVATE_[--pfx_PRIVATE_.num_PRIVATE_];
} }
...@@ -1000,9 +1011,9 @@ inline void ...@@ -1000,9 +1011,9 @@ inline void
vec<T, A, vl_embed>::block_remove (unsigned ix, unsigned len) vec<T, A, vl_embed>::block_remove (unsigned ix, unsigned len)
{ {
gcc_checking_assert (ix + len <= length()); gcc_checking_assert (ix + len <= length());
T *slot = &data_[ix]; T *slot = &data_PRIVATE_[ix];
pfx_.num_ -= len; pfx_PRIVATE_.num_PRIVATE_ -= len;
memmove (slot, slot + len, (pfx_.num_ - ix) * sizeof (T)); memmove (slot, slot + len, (pfx_PRIVATE_.num_PRIVATE_ - ix) * sizeof (T));
} }
...@@ -1066,7 +1077,7 @@ inline size_t ...@@ -1066,7 +1077,7 @@ inline size_t
vec<T, A, vl_embed>::embedded_size (unsigned alloc) vec<T, A, vl_embed>::embedded_size (unsigned alloc)
{ {
typedef vec<T, A, vl_embed> vec_embedded; typedef vec<T, A, vl_embed> vec_embedded;
return offsetof (vec_embedded, data_) + alloc * sizeof (T); return offsetof (vec_embedded, data_PRIVATE_) + alloc * sizeof (T);
} }
...@@ -1077,8 +1088,8 @@ template<typename T, typename A> ...@@ -1077,8 +1088,8 @@ template<typename T, typename A>
inline void inline void
vec<T, A, vl_embed>::embedded_init (unsigned alloc, unsigned num) vec<T, A, vl_embed>::embedded_init (unsigned alloc, unsigned num)
{ {
pfx_.alloc_ = alloc; pfx_PRIVATE_.alloc_PRIVATE_ = alloc;
pfx_.num_ = num; pfx_PRIVATE_.num_PRIVATE_ = num;
} }
...@@ -1089,8 +1100,8 @@ template<typename T, typename A> ...@@ -1089,8 +1100,8 @@ template<typename T, typename A>
inline void inline void
vec<T, A, vl_embed>::quick_grow (unsigned len) vec<T, A, vl_embed>::quick_grow (unsigned len)
{ {
gcc_checking_assert (length () <= len && len <= pfx_.alloc_); gcc_checking_assert (length () <= len && len <= pfx_PRIVATE_.alloc_PRIVATE_);
pfx_.num_ = len; pfx_PRIVATE_.num_PRIVATE_ = len;
} }
...@@ -1195,22 +1206,22 @@ public: ...@@ -1195,22 +1206,22 @@ public:
/* Vector operations. */ /* Vector operations. */
bool exists (void) const bool exists (void) const
{ return vec_ != NULL; } { return vec_PRIVATE_ != NULL; }
bool is_empty (void) const bool is_empty (void) const
{ return vec_ ? vec_->is_empty() : true; } { return vec_PRIVATE_ ? vec_PRIVATE_->is_empty() : true; }
unsigned length (void) const unsigned length (void) const
{ return vec_ ? vec_->length() : 0; } { return vec_PRIVATE_ ? vec_PRIVATE_->length() : 0; }
T *address (void) T *address (void)
{ return vec_ ? vec_->data_ : NULL; } { return vec_PRIVATE_ ? vec_PRIVATE_->data_PRIVATE_ : NULL; }
const T *address (void) const const T *address (void) const
{ return vec_ ? vec_->data_ : NULL; } { return vec_PRIVATE_ ? vec_PRIVATE_->data_PRIVATE_ : NULL; }
const T &operator[] (unsigned ix) const const T &operator[] (unsigned ix) const
{ return (*vec_)[ix]; } { return (*vec_PRIVATE_)[ix]; }
bool operator!=(const vec &other) const bool operator!=(const vec &other) const
{ return !(*this == other); } { return !(*this == other); }
...@@ -1219,13 +1230,13 @@ public: ...@@ -1219,13 +1230,13 @@ public:
{ return address() == other.address(); } { return address() == other.address(); }
T &operator[] (unsigned ix) T &operator[] (unsigned ix)
{ return (*vec_)[ix]; } { return (*vec_PRIVATE_)[ix]; }
T &last (void) T &last (void)
{ return vec_->last(); } { return vec_PRIVATE_->last(); }
bool space (int nelems) const bool space (int nelems) const
{ return vec_ ? vec_->space (nelems) : nelems == 0; } { return vec_PRIVATE_ ? vec_PRIVATE_->space (nelems) : nelems == 0; }
bool iterate (unsigned ix, T *p) const; bool iterate (unsigned ix, T *p) const;
bool iterate (unsigned ix, T **p) const; bool iterate (unsigned ix, T **p) const;
...@@ -1254,8 +1265,9 @@ public: ...@@ -1254,8 +1265,9 @@ public:
friend void va_stack::alloc(vec<T1, va_stack, vl_ptr>&, unsigned, friend void va_stack::alloc(vec<T1, va_stack, vl_ptr>&, unsigned,
vec<T1, va_stack, vl_embed> *); vec<T1, va_stack, vl_embed> *);
private: /* FIXME - This field should be private, but we need to cater to
vec<T, A, vl_embed> *vec_; compilers that have stricter notions of PODness for types. */
vec<T, A, vl_embed> *vec_PRIVATE_;
}; };
...@@ -1358,8 +1370,8 @@ template<typename T, typename A> ...@@ -1358,8 +1370,8 @@ template<typename T, typename A>
inline bool inline bool
vec<T, A, vl_ptr>::iterate (unsigned ix, T *ptr) const vec<T, A, vl_ptr>::iterate (unsigned ix, T *ptr) const
{ {
if (vec_) if (vec_PRIVATE_)
return vec_->iterate (ix, ptr); return vec_PRIVATE_->iterate (ix, ptr);
else else
{ {
*ptr = 0; *ptr = 0;
...@@ -1381,8 +1393,8 @@ template<typename T, typename A> ...@@ -1381,8 +1393,8 @@ template<typename T, typename A>
inline bool inline bool
vec<T, A, vl_ptr>::iterate (unsigned ix, T **ptr) const vec<T, A, vl_ptr>::iterate (unsigned ix, T **ptr) const
{ {
if (vec_) if (vec_PRIVATE_)
return vec_->iterate (ix, ptr); return vec_PRIVATE_->iterate (ix, ptr);
else else
{ {
*ptr = 0; *ptr = 0;
...@@ -1422,7 +1434,7 @@ vec<T, A, vl_ptr>::copy (ALONE_MEM_STAT_DECL) const ...@@ -1422,7 +1434,7 @@ vec<T, A, vl_ptr>::copy (ALONE_MEM_STAT_DECL) const
{ {
vec<T, A, vl_ptr> new_vec = vec<T, A, vl_ptr>(); vec<T, A, vl_ptr> new_vec = vec<T, A, vl_ptr>();
if (length ()) if (length ())
new_vec.vec_ = vec_->copy (); new_vec.vec_PRIVATE_ = vec_PRIVATE_->copy ();
return new_vec; return new_vec;
} }
...@@ -1442,7 +1454,7 @@ vec<T, A, vl_ptr>::reserve (unsigned nelems, bool exact MEM_STAT_DECL) ...@@ -1442,7 +1454,7 @@ vec<T, A, vl_ptr>::reserve (unsigned nelems, bool exact MEM_STAT_DECL)
{ {
bool extend = nelems ? !space (nelems) : false; bool extend = nelems ? !space (nelems) : false;
if (extend) if (extend)
A::reserve (vec_, nelems, exact PASS_MEM_STAT); A::reserve (vec_PRIVATE_, nelems, exact PASS_MEM_STAT);
return extend; return extend;
} }
...@@ -1469,7 +1481,7 @@ template<typename T, typename A> ...@@ -1469,7 +1481,7 @@ template<typename T, typename A>
inline void inline void
vec<T, A, vl_ptr>::create (unsigned nelems MEM_STAT_DECL) vec<T, A, vl_ptr>::create (unsigned nelems MEM_STAT_DECL)
{ {
vec_ = NULL; vec_PRIVATE_ = NULL;
if (nelems > 0) if (nelems > 0)
reserve_exact (nelems PASS_MEM_STAT); reserve_exact (nelems PASS_MEM_STAT);
} }
...@@ -1481,8 +1493,8 @@ template<typename T, typename A> ...@@ -1481,8 +1493,8 @@ template<typename T, typename A>
inline void inline void
vec<T, A, vl_ptr>::release (void) vec<T, A, vl_ptr>::release (void)
{ {
if (vec_) if (vec_PRIVATE_)
A::release (vec_); A::release (vec_PRIVATE_);
} }
...@@ -1495,8 +1507,8 @@ template<typename T, typename A> ...@@ -1495,8 +1507,8 @@ template<typename T, typename A>
inline void inline void
vec<T, A, vl_ptr>::splice (vec<T, A, vl_ptr> &src) vec<T, A, vl_ptr>::splice (vec<T, A, vl_ptr> &src)
{ {
if (src.vec_) if (src.vec_PRIVATE_)
vec_->splice (*(src.vec_)); vec_PRIVATE_->splice (*(src.vec_PRIVATE_));
} }
...@@ -1525,7 +1537,7 @@ template<typename T, typename A> ...@@ -1525,7 +1537,7 @@ template<typename T, typename A>
inline T * inline T *
vec<T, A, vl_ptr>::quick_push (const T &obj) vec<T, A, vl_ptr>::quick_push (const T &obj)
{ {
return vec_->quick_push (obj); return vec_PRIVATE_->quick_push (obj);
} }
...@@ -1548,7 +1560,7 @@ template<typename T, typename A> ...@@ -1548,7 +1560,7 @@ template<typename T, typename A>
inline T & inline T &
vec<T, A, vl_ptr>::pop (void) vec<T, A, vl_ptr>::pop (void)
{ {
return vec_->pop (); return vec_PRIVATE_->pop ();
} }
...@@ -1559,8 +1571,8 @@ template<typename T, typename A> ...@@ -1559,8 +1571,8 @@ template<typename T, typename A>
inline void inline void
vec<T, A, vl_ptr>::truncate (unsigned size) vec<T, A, vl_ptr>::truncate (unsigned size)
{ {
if (vec_) if (vec_PRIVATE_)
vec_->truncate (size); vec_PRIVATE_->truncate (size);
else else
gcc_checking_assert (size == 0); gcc_checking_assert (size == 0);
} }
...@@ -1577,7 +1589,7 @@ vec<T, A, vl_ptr>::safe_grow (unsigned len MEM_STAT_DECL) ...@@ -1577,7 +1589,7 @@ vec<T, A, vl_ptr>::safe_grow (unsigned len MEM_STAT_DECL)
unsigned oldlen = length (); unsigned oldlen = length ();
gcc_checking_assert (oldlen <= len); gcc_checking_assert (oldlen <= len);
reserve_exact (len - oldlen PASS_MEM_STAT); reserve_exact (len - oldlen PASS_MEM_STAT);
vec_->quick_grow (len); vec_PRIVATE_->quick_grow (len);
} }
...@@ -1602,8 +1614,8 @@ template<typename T, typename A> ...@@ -1602,8 +1614,8 @@ template<typename T, typename A>
inline void inline void
vec<T, A, vl_ptr>::quick_grow (unsigned len) vec<T, A, vl_ptr>::quick_grow (unsigned len)
{ {
gcc_checking_assert (vec_); gcc_checking_assert (vec_PRIVATE_);
vec_->quick_grow (len); vec_PRIVATE_->quick_grow (len);
} }
...@@ -1615,8 +1627,8 @@ template<typename T, typename A> ...@@ -1615,8 +1627,8 @@ template<typename T, typename A>
inline void inline void
vec<T, A, vl_ptr>::quick_grow_cleared (unsigned len) vec<T, A, vl_ptr>::quick_grow_cleared (unsigned len)
{ {
gcc_checking_assert (vec_); gcc_checking_assert (vec_PRIVATE_);
vec_->quick_grow_cleared (len); vec_PRIVATE_->quick_grow_cleared (len);
} }
...@@ -1627,7 +1639,7 @@ template<typename T, typename A> ...@@ -1627,7 +1639,7 @@ template<typename T, typename A>
inline void inline void
vec<T, A, vl_ptr>::quick_insert (unsigned ix, const T &obj) vec<T, A, vl_ptr>::quick_insert (unsigned ix, const T &obj)
{ {
vec_->quick_insert (ix, obj); vec_PRIVATE_->quick_insert (ix, obj);
} }
...@@ -1651,7 +1663,7 @@ template<typename T, typename A> ...@@ -1651,7 +1663,7 @@ template<typename T, typename A>
inline void inline void
vec<T, A, vl_ptr>::ordered_remove (unsigned ix) vec<T, A, vl_ptr>::ordered_remove (unsigned ix)
{ {
vec_->ordered_remove (ix); vec_PRIVATE_->ordered_remove (ix);
} }
...@@ -1662,7 +1674,7 @@ template<typename T, typename A> ...@@ -1662,7 +1674,7 @@ template<typename T, typename A>
inline void inline void
vec<T, A, vl_ptr>::unordered_remove (unsigned ix) vec<T, A, vl_ptr>::unordered_remove (unsigned ix)
{ {
vec_->unordered_remove (ix); vec_PRIVATE_->unordered_remove (ix);
} }
...@@ -1673,7 +1685,7 @@ template<typename T, typename A> ...@@ -1673,7 +1685,7 @@ template<typename T, typename A>
inline void inline void
vec<T, A, vl_ptr>::block_remove (unsigned ix, unsigned len) vec<T, A, vl_ptr>::block_remove (unsigned ix, unsigned len)
{ {
vec_->block_remove (ix, len); vec_PRIVATE_->block_remove (ix, len);
} }
...@@ -1684,8 +1696,8 @@ template<typename T, typename A> ...@@ -1684,8 +1696,8 @@ template<typename T, typename A>
inline void inline void
vec<T, A, vl_ptr>::qsort (int (*cmp) (const void *, const void *)) vec<T, A, vl_ptr>::qsort (int (*cmp) (const void *, const void *))
{ {
if (vec_) if (vec_PRIVATE_)
vec_->qsort (cmp); vec_PRIVATE_->qsort (cmp);
} }
...@@ -1696,9 +1708,10 @@ vec<T, A, vl_ptr>::qsort (int (*cmp) (const void *, const void *)) ...@@ -1696,9 +1708,10 @@ vec<T, A, vl_ptr>::qsort (int (*cmp) (const void *, const void *))
template<typename T, typename A> template<typename T, typename A>
inline unsigned inline unsigned
vec<T, A, vl_ptr>::lower_bound (T obj, bool (*lessthan)(const T &, const T &)) const vec<T, A, vl_ptr>::lower_bound (T obj, bool (*lessthan)(const T &, const T &))
const
{ {
return vec_ ? vec_->lower_bound (obj, lessthan) : 0; return vec_PRIVATE_ ? vec_PRIVATE_->lower_bound (obj, lessthan) : 0;
} }
#endif // GCC_VEC_H #endif // GCC_VEC_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment