On Mon, Sep 30, 2013 at 10:39 PM, Richard Sandiford <rdsandif...@googlemail.com> wrote: > Richard Biener <richard.guent...@gmail.com> writes: >> On Sun, Sep 29, 2013 at 11:08 AM, Richard Sandiford >> <rdsandif...@googlemail.com> wrote: >>> Michael Matz <m...@suse.de> writes: >>>>Trever Saunders <tsaund...@mozilla.com> writes: >>>>> Richard Biener <richard.guent...@gmail.com> writes: >>>>> > Btw, I've come around multiple coding-styles in the past and I >>>>> > definitely would prefer m_mode / m_count to mark members vs. mode_ and >>>>> > count_. (and s_XXX for static members IIRC). >>>>> >>>>> I'd prefer m_/s_foo for members / static things too fwiw. >>>> >>>> Me as well. It's still ugly, but not so unsymmetric as the trailing >>>> underscore. >>> >>> Well, I'm not sure how I came to be the one writing these patches, >>> but I suppose I prefer m_foo too. So how about the attached? >>> >>> The first patch has changes to the coding conventions. I added >>> some missing spaces while there. >>> >>> The second patch has the mechanical code changes. The reason for >>> yesterday's mass adding of spaces was because the second patch would >>> have been pretty inconsistent otherwise. >>> >>> Tested on x86_64-linux-gnu. >> >> Ok. > > Applied, thanks. I was only looking for private and protected members, > so I ended up missing vec. I installed the patch below as an obvious > follow-up. Tested on x86_64-linux-gnu. > > There are some other uses foo_, but many of them seem to date from before > the C++ switchover.
My usual foo_ use is for stuff like int qsort_fn (const void *ptr1_, const void *ptr2_) { const T *ptr1 = (const T *)ptr1_; ... to not need to invent another name for the void * typed parameter and keep the name association obvious. But grepping for '_ ' indeed shows a lot more, but mostly in macros. Richard. > Richard > > > gcc/ > * vec.h (vec_prefix, vec): Prefix member names with "m_". > * vec.c (vec_prefix::calculate_allocation): Update accordingly. > > Index: gcc/vec.c > =================================================================== > --- gcc/vec.c 2013-09-27 09:16:58.010299213 +0100 > +++ gcc/vec.c 2013-09-30 18:09:02.892316820 +0100 > @@ -183,8 +183,8 @@ vec_prefix::calculate_allocation (vec_pr > > if (pfx) > { > - alloc = pfx->alloc_; > - num = pfx->num_; > + alloc = pfx->m_alloc; > + num = pfx->m_num; > } > else if (!reserve) > /* If there's no vector, and we've not requested anything, then we > Index: gcc/vec.h > =================================================================== > --- gcc/vec.h 2013-09-30 18:06:22.236575959 +0100 > +++ gcc/vec.h 2013-09-30 18:06:22.305576705 +0100 > @@ -235,8 +235,8 @@ struct vec_prefix > friend struct va_heap; > friend struct va_stack; > > - unsigned alloc_; > - unsigned num_; > + unsigned m_alloc; > + unsigned m_num; > }; > > template<typename, typename, typename> struct vec; > @@ -285,7 +285,7 @@ va_heap::reserve (vec<T, va_heap, vl_emb > MEM_STAT_DECL) > { > unsigned alloc > - = vec_prefix::calculate_allocation (v ? &v->vecpfx_ : 0, reserve, exact); > + = vec_prefix::calculate_allocation (v ? &v->m_vecpfx : 0, reserve, > exact); > if (!alloc) > { > release (v); > @@ -293,7 +293,7 @@ va_heap::reserve (vec<T, va_heap, vl_emb > } > > if (GATHER_STATISTICS && v) > - v->vecpfx_.release_overhead (); > + v->m_vecpfx.release_overhead (); > > size_t size = vec<T, va_heap, vl_embed>::embedded_size (alloc); > unsigned nelem = v ? v->length () : 0; > @@ -301,7 +301,7 @@ va_heap::reserve (vec<T, va_heap, vl_emb > v->embedded_init (alloc, nelem); > > if (GATHER_STATISTICS) > - v->vecpfx_.register_overhead (size FINAL_PASS_MEM_STAT); > + v->m_vecpfx.register_overhead (size FINAL_PASS_MEM_STAT); > } > > > @@ -315,7 +315,7 @@ va_heap::release (vec<T, va_heap, vl_emb > return; > > if (GATHER_STATISTICS) > - v->vecpfx_.release_overhead (); > + v->m_vecpfx.release_overhead (); > ::free (v); > v = NULL; > } > @@ -364,7 +364,7 @@ va_gc::reserve (vec<T, A, vl_embed> *&v, > MEM_STAT_DECL) > { > unsigned alloc > - = vec_prefix::calculate_allocation (v ? &v->vecpfx_ : 0, reserve, exact); > + = vec_prefix::calculate_allocation (v ? &v->m_vecpfx : 0, reserve, > exact); > if (!alloc) > { > ::ggc_free (v); > @@ -433,9 +433,9 @@ void unregister_stack_vec (unsigned); > va_stack::alloc (vec<T, va_stack, vl_ptr> &v, unsigned nelems, > vec<T, va_stack, vl_embed> *space) > { > - v.vec_ = space; > - register_stack_vec (static_cast<void *> (v.vec_)); > - v.vec_->embedded_init (nelems, 0); > + v.m_vec = space; > + register_stack_vec (static_cast<void *> (v.m_vec)); > + v.m_vec->embedded_init (nelems, 0); > } > > > @@ -462,16 +462,16 @@ va_stack::reserve (vec<T, va_stack, vl_e > } > > /* Move VEC_ to the heap. */ > - nelems += v->vecpfx_.num_; > + nelems += v->m_vecpfx.m_num; > vec<T, va_stack, vl_embed> *oldvec = v; > v = NULL; > va_heap::reserve (reinterpret_cast<vec<T, va_heap, vl_embed> *&>(v), > nelems, > exact PASS_MEM_STAT); > if (v && oldvec) > { > - v->vecpfx_.num_ = oldvec->length (); > - memcpy (v->vecdata_, > - oldvec->vecdata_, > + v->m_vecpfx.m_num = oldvec->length (); > + memcpy (v->m_vecdata, > + oldvec->m_vecdata, > oldvec->length () * sizeof (T)); > } > } > @@ -562,11 +562,11 @@ struct vnull > struct GTY((user)) vec<T, A, vl_embed> > { > public: > - unsigned allocated (void) const { return vecpfx_.alloc_; } > - unsigned length (void) const { return vecpfx_.num_; } > - bool is_empty (void) const { return vecpfx_.num_ == 0; } > - T *address (void) { return vecdata_; } > - const T *address (void) const { return vecdata_; } > + unsigned allocated (void) const { return m_vecpfx.m_alloc; } > + unsigned length (void) const { return m_vecpfx.m_num; } > + bool is_empty (void) const { return m_vecpfx.m_num == 0; } > + T *address (void) { return m_vecdata; } > + const T *address (void) const { return m_vecdata; } > const T &operator[] (unsigned) const; > T &operator[] (unsigned); > T &last (void); > @@ -601,8 +601,8 @@ struct GTY((user)) vec<T, A, vl_embed> > > /* FIXME - These fields should be private, but we need to cater to > compilers that have stricter notions of PODness for types. */ > - vec_prefix vecpfx_; > - T vecdata_[1]; > + vec_prefix m_vecpfx; > + T m_vecdata[1]; > }; > > > @@ -816,16 +816,16 @@ vec_safe_splice (vec<T, A, vl_embed> *&d > inline const T & > vec<T, A, vl_embed>::operator[] (unsigned ix) const > { > - gcc_checking_assert (ix < vecpfx_.num_); > - return vecdata_[ix]; > + gcc_checking_assert (ix < m_vecpfx.m_num); > + return m_vecdata[ix]; > } > > template<typename T, typename A> > inline T & > vec<T, A, vl_embed>::operator[] (unsigned ix) > { > - gcc_checking_assert (ix < vecpfx_.num_); > - return vecdata_[ix]; > + gcc_checking_assert (ix < m_vecpfx.m_num); > + return m_vecdata[ix]; > } > > > @@ -835,8 +835,8 @@ vec<T, A, vl_embed>::operator[] (unsigne > inline T & > vec<T, A, vl_embed>::last (void) > { > - gcc_checking_assert (vecpfx_.num_ > 0); > - return (*this)[vecpfx_.num_ - 1]; > + gcc_checking_assert (m_vecpfx.m_num > 0); > + return (*this)[m_vecpfx.m_num - 1]; > } > > > @@ -850,7 +850,7 @@ vec<T, A, vl_embed>::last (void) > inline bool > vec<T, A, vl_embed>::space (unsigned nelems) const > { > - return vecpfx_.alloc_ - vecpfx_.num_ >= nelems; > + return m_vecpfx.m_alloc - m_vecpfx.m_num >= nelems; > } > > > @@ -865,9 +865,9 @@ vec<T, A, vl_embed>::space (unsigned nel > inline bool > vec<T, A, vl_embed>::iterate (unsigned ix, T *ptr) const > { > - if (ix < vecpfx_.num_) > + if (ix < m_vecpfx.m_num) > { > - *ptr = vecdata_[ix]; > + *ptr = m_vecdata[ix]; > return true; > } > else > @@ -891,9 +891,9 @@ vec<T, A, vl_embed>::iterate (unsigned i > inline bool > vec<T, A, vl_embed>::iterate (unsigned ix, T **ptr) const > { > - if (ix < vecpfx_.num_) > + if (ix < m_vecpfx.m_num) > { > - *ptr = CONST_CAST (T *, &vecdata_[ix]); > + *ptr = CONST_CAST (T *, &m_vecdata[ix]); > return true; > } > else > @@ -916,7 +916,7 @@ vec<T, A, vl_embed>::copy (ALONE_MEM_STA > { > vec_alloc (new_vec, len PASS_MEM_STAT); > new_vec->embedded_init (len, len); > - memcpy (new_vec->address (), vecdata_, sizeof (T) * len); > + memcpy (new_vec->address (), m_vecdata, sizeof (T) * len); > } > return new_vec; > } > @@ -934,7 +934,7 @@ vec<T, A, vl_embed>::splice (vec<T, A, v > { > gcc_checking_assert (space (len)); > memcpy (address () + length (), src.address (), len * sizeof (T)); > - vecpfx_.num_ += len; > + m_vecpfx.m_num += len; > } > } > > @@ -956,7 +956,7 @@ vec<T, A, vl_embed>::splice (vec<T, A, v > vec<T, A, vl_embed>::quick_push (const T &obj) > { > gcc_checking_assert (space (1)); > - T *slot = &vecdata_[vecpfx_.num_++]; > + T *slot = &m_vecdata[m_vecpfx.m_num++]; > *slot = obj; > return slot; > } > @@ -969,7 +969,7 @@ vec<T, A, vl_embed>::quick_push (const T > vec<T, A, vl_embed>::pop (void) > { > gcc_checking_assert (length () > 0); > - return vecdata_[--vecpfx_.num_]; > + return m_vecdata[--m_vecpfx.m_num]; > } > > > @@ -981,7 +981,7 @@ vec<T, A, vl_embed>::pop (void) > vec<T, A, vl_embed>::truncate (unsigned size) > { > gcc_checking_assert (length () >= size); > - vecpfx_.num_ = size; > + m_vecpfx.m_num = size; > } > > > @@ -994,8 +994,8 @@ vec<T, A, vl_embed>::quick_insert (unsig > { > gcc_checking_assert (length () < allocated ()); > gcc_checking_assert (ix <= length ()); > - T *slot = &vecdata_[ix]; > - memmove (slot + 1, slot, (vecpfx_.num_++ - ix) * sizeof (T)); > + T *slot = &m_vecdata[ix]; > + memmove (slot + 1, slot, (m_vecpfx.m_num++ - ix) * sizeof (T)); > *slot = obj; > } > > @@ -1009,8 +1009,8 @@ vec<T, A, vl_embed>::quick_insert (unsig > vec<T, A, vl_embed>::ordered_remove (unsigned ix) > { > gcc_checking_assert (ix < length ()); > - T *slot = &vecdata_[ix]; > - memmove (slot, slot + 1, (--vecpfx_.num_ - ix) * sizeof (T)); > + T *slot = &m_vecdata[ix]; > + memmove (slot, slot + 1, (--m_vecpfx.m_num - ix) * sizeof (T)); > } > > > @@ -1022,7 +1022,7 @@ vec<T, A, vl_embed>::ordered_remove (uns > vec<T, A, vl_embed>::unordered_remove (unsigned ix) > { > gcc_checking_assert (ix < length ()); > - vecdata_[ix] = vecdata_[--vecpfx_.num_]; > + m_vecdata[ix] = m_vecdata[--m_vecpfx.m_num]; > } > > > @@ -1034,9 +1034,9 @@ vec<T, A, vl_embed>::unordered_remove (u > vec<T, A, vl_embed>::block_remove (unsigned ix, unsigned len) > { > gcc_checking_assert (ix + len <= length ()); > - T *slot = &vecdata_[ix]; > - vecpfx_.num_ -= len; > - memmove (slot, slot + len, (vecpfx_.num_ - ix) * sizeof (T)); > + T *slot = &m_vecdata[ix]; > + m_vecpfx.m_num -= len; > + memmove (slot, slot + len, (m_vecpfx.m_num - ix) * sizeof (T)); > } > > > @@ -1100,7 +1100,7 @@ vec<T, A, vl_embed>::lower_bound (T obj, > vec<T, A, vl_embed>::embedded_size (unsigned alloc) > { > typedef vec<T, A, vl_embed> vec_embedded; > - return offsetof (vec_embedded, vecdata_) + alloc * sizeof (T); > + return offsetof (vec_embedded, m_vecdata) + alloc * sizeof (T); > } > > > @@ -1111,8 +1111,8 @@ vec<T, A, vl_embed>::embedded_size (unsi > inline void > vec<T, A, vl_embed>::embedded_init (unsigned alloc, unsigned num) > { > - vecpfx_.alloc_ = alloc; > - vecpfx_.num_ = num; > + m_vecpfx.m_alloc = alloc; > + m_vecpfx.m_num = num; > } > > > @@ -1123,8 +1123,8 @@ vec<T, A, vl_embed>::embedded_init (unsi > inline void > vec<T, A, vl_embed>::quick_grow (unsigned len) > { > - gcc_checking_assert (length () <= len && len <= vecpfx_.alloc_); > - vecpfx_.num_ = len; > + gcc_checking_assert (length () <= len && len <= m_vecpfx.m_alloc); > + m_vecpfx.m_num = len; > } > > > @@ -1229,22 +1229,22 @@ struct vec<T, A, vl_ptr> > > /* Vector operations. */ > bool exists (void) const > - { return vec_ != NULL; } > + { return m_vec != NULL; } > > bool is_empty (void) const > - { return vec_ ? vec_->is_empty () : true; } > + { return m_vec ? m_vec->is_empty () : true; } > > unsigned length (void) const > - { return vec_ ? vec_->length () : 0; } > + { return m_vec ? m_vec->length () : 0; } > > T *address (void) > - { return vec_ ? vec_->vecdata_ : NULL; } > + { return m_vec ? m_vec->m_vecdata : NULL; } > > const T *address (void) const > - { return vec_ ? vec_->vecdata_ : NULL; } > + { return m_vec ? m_vec->m_vecdata : NULL; } > > const T &operator[] (unsigned ix) const > - { return (*vec_)[ix]; } > + { return (*m_vec)[ix]; } > > bool operator!=(const vec &other) const > { return !(*this == other); } > @@ -1253,13 +1253,13 @@ struct vec<T, A, vl_ptr> > { return address () == other.address (); } > > T &operator[] (unsigned ix) > - { return (*vec_)[ix]; } > + { return (*m_vec)[ix]; } > > T &last (void) > - { return vec_->last (); } > + { return m_vec->last (); } > > bool space (int nelems) const > - { return vec_ ? vec_->space (nelems) : nelems == 0; } > + { return m_vec ? m_vec->space (nelems) : nelems == 0; } > > bool iterate (unsigned ix, T *p) const; > bool iterate (unsigned ix, T **p) const; > @@ -1290,7 +1290,7 @@ struct vec<T, A, vl_ptr> > > /* FIXME - This field should be private, but we need to cater to > compilers that have stricter notions of PODness for types. */ > - vec<T, A, vl_embed> *vec_; > + vec<T, A, vl_embed> *m_vec; > }; > > > @@ -1393,8 +1393,8 @@ #define vec_stack_alloc(T,V,N) > \ > inline bool > vec<T, A, vl_ptr>::iterate (unsigned ix, T *ptr) const > { > - if (vec_) > - return vec_->iterate (ix, ptr); > + if (m_vec) > + return m_vec->iterate (ix, ptr); > else > { > *ptr = 0; > @@ -1416,8 +1416,8 @@ vec<T, A, vl_ptr>::iterate (unsigned ix, > inline bool > vec<T, A, vl_ptr>::iterate (unsigned ix, T **ptr) const > { > - if (vec_) > - return vec_->iterate (ix, ptr); > + if (m_vec) > + return m_vec->iterate (ix, ptr); > else > { > *ptr = 0; > @@ -1457,7 +1457,7 @@ vec<T, A, vl_ptr>::copy (ALONE_MEM_STAT_ > { > vec<T, A, vl_ptr> new_vec = vNULL; > if (length ()) > - new_vec.vec_ = vec_->copy (); > + new_vec.m_vec = m_vec->copy (); > return new_vec; > } > > @@ -1477,7 +1477,7 @@ vec<T, A, vl_ptr>::reserve (unsigned nel > { > bool extend = nelems ? !space (nelems) : false; > if (extend) > - A::reserve (vec_, nelems, exact PASS_MEM_STAT); > + A::reserve (m_vec, nelems, exact PASS_MEM_STAT); > return extend; > } > > @@ -1504,7 +1504,7 @@ vec<T, A, vl_ptr>::reserve_exact (unsign > inline void > vec<T, A, vl_ptr>::create (unsigned nelems MEM_STAT_DECL) > { > - vec_ = NULL; > + m_vec = NULL; > if (nelems > 0) > reserve_exact (nelems PASS_MEM_STAT); > } > @@ -1516,8 +1516,8 @@ vec<T, A, vl_ptr>::create (unsigned nele > inline void > vec<T, A, vl_ptr>::release (void) > { > - if (vec_) > - A::release (vec_); > + if (m_vec) > + A::release (m_vec); > } > > > @@ -1530,8 +1530,8 @@ vec<T, A, vl_ptr>::release (void) > inline void > vec<T, A, vl_ptr>::splice (vec<T, A, vl_ptr> &src) > { > - if (src.vec_) > - vec_->splice (*(src.vec_)); > + if (src.m_vec) > + m_vec->splice (*(src.m_vec)); > } > > > @@ -1560,7 +1560,7 @@ vec<T, A, vl_ptr>::safe_splice (vec<T, A > inline T * > vec<T, A, vl_ptr>::quick_push (const T &obj) > { > - return vec_->quick_push (obj); > + return m_vec->quick_push (obj); > } > > > @@ -1583,7 +1583,7 @@ vec<T, A, vl_ptr>::safe_push (const T &o > inline T & > vec<T, A, vl_ptr>::pop (void) > { > - return vec_->pop (); > + return m_vec->pop (); > } > > > @@ -1594,8 +1594,8 @@ vec<T, A, vl_ptr>::pop (void) > inline void > vec<T, A, vl_ptr>::truncate (unsigned size) > { > - if (vec_) > - vec_->truncate (size); > + if (m_vec) > + m_vec->truncate (size); > else > gcc_checking_assert (size == 0); > } > @@ -1612,7 +1612,7 @@ vec<T, A, vl_ptr>::safe_grow (unsigned l > unsigned oldlen = length (); > gcc_checking_assert (oldlen <= len); > reserve_exact (len - oldlen PASS_MEM_STAT); > - vec_->quick_grow (len); > + m_vec->quick_grow (len); > } > > > @@ -1637,8 +1637,8 @@ vec<T, A, vl_ptr>::safe_grow_cleared (un > inline void > vec<T, A, vl_ptr>::quick_grow (unsigned len) > { > - gcc_checking_assert (vec_); > - vec_->quick_grow (len); > + gcc_checking_assert (m_vec); > + m_vec->quick_grow (len); > } > > > @@ -1650,8 +1650,8 @@ vec<T, A, vl_ptr>::quick_grow (unsigned > inline void > vec<T, A, vl_ptr>::quick_grow_cleared (unsigned len) > { > - gcc_checking_assert (vec_); > - vec_->quick_grow_cleared (len); > + gcc_checking_assert (m_vec); > + m_vec->quick_grow_cleared (len); > } > > > @@ -1662,7 +1662,7 @@ vec<T, A, vl_ptr>::quick_grow_cleared (u > inline void > vec<T, A, vl_ptr>::quick_insert (unsigned ix, const T &obj) > { > - vec_->quick_insert (ix, obj); > + m_vec->quick_insert (ix, obj); > } > > > @@ -1686,7 +1686,7 @@ vec<T, A, vl_ptr>::safe_insert (unsigned > inline void > vec<T, A, vl_ptr>::ordered_remove (unsigned ix) > { > - vec_->ordered_remove (ix); > + m_vec->ordered_remove (ix); > } > > > @@ -1697,7 +1697,7 @@ vec<T, A, vl_ptr>::ordered_remove (unsig > inline void > vec<T, A, vl_ptr>::unordered_remove (unsigned ix) > { > - vec_->unordered_remove (ix); > + m_vec->unordered_remove (ix); > } > > > @@ -1708,7 +1708,7 @@ vec<T, A, vl_ptr>::unordered_remove (uns > inline void > vec<T, A, vl_ptr>::block_remove (unsigned ix, unsigned len) > { > - vec_->block_remove (ix, len); > + m_vec->block_remove (ix, len); > } > > > @@ -1719,8 +1719,8 @@ vec<T, A, vl_ptr>::block_remove (unsigne > inline void > vec<T, A, vl_ptr>::qsort (int (*cmp) (const void *, const void *)) > { > - if (vec_) > - vec_->qsort (cmp); > + if (m_vec) > + m_vec->qsort (cmp); > } > > > @@ -1734,11 +1734,11 @@ vec<T, A, vl_ptr>::qsort (int (*cmp) (co > 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 m_vec ? m_vec->lower_bound (obj, lessthan) : 0; > } > > #if (GCC_VERSION >= 3000) > -# pragma GCC poison vec_ vecpfx_ vecdata_ > +# pragma GCC poison m_vec m_vecpfx m_vecdata > #endif > > #endif // GCC_VEC_H