36 #define VEC_GC_ENABLED 0
38 #define VEC_GC_ENABLED 1
39 #endif // GENERATOR_FILE
55 #endif // VEC_GC_ENABLED
228 template <
typename,
typename,
typename>
friend struct vec;
240 template<
typename,
typename,
typename>
struct vec;
292 if (GATHER_STATISTICS && v)
293 v->m_vecpfx.release_overhead ();
296 unsigned nelem = v ? v->length () : 0;
298 v->embedded_init (alloc, nelem);
300 if (GATHER_STATISTICS)
301 v->m_vecpfx.register_overhead (size FINAL_PASS_MEM_STAT);
314 if (GATHER_STATISTICS)
315 v->m_vecpfx.release_overhead ();
332 template<
typename T,
typename A>
336 template<
typename T,
typename A>
343 template<
typename T,
typename A>
358 template<
typename T,
typename A>
380 size_t elt_size =
sizeof (
T);
381 alloc = (size - vec_offset) / elt_size;
384 size = vec_offset + alloc * elt_size;
386 unsigned nelem = v ? v->
length () : 0;
414 typename L =
typename A::default_layout>
415 struct GTY((user))
vec
425 template <
typename T,
typename A,
typename L>
457 template<
typename T,
typename A>
461 unsigned allocated (
void)
const {
return m_vecpfx.m_alloc; }
462 unsigned length (
void)
const {
return m_vecpfx.m_num; }
463 bool is_empty (
void)
const {
return m_vecpfx.m_num == 0; }
464 T *address (
void) {
return m_vecdata; }
465 const T *address (
void)
const {
return m_vecdata; }
466 const T &operator[] (
unsigned)
const;
467 T &operator[] (
unsigned);
469 bool space (
unsigned)
const;
470 bool iterate (
unsigned,
T *)
const;
471 bool iterate (
unsigned,
T **)
const;
472 vec *
copy (ALONE_CXX_MEM_STAT_INFO)
const;
474 void splice (
vec *src);
475 T *quick_push (
const T &);
477 void truncate (
unsigned);
478 void quick_insert (
unsigned,
const T &);
479 void ordered_remove (
unsigned);
480 void unordered_remove (
unsigned);
481 void block_remove (
unsigned,
unsigned);
482 void qsort (
int (*) (
const void *,
const void *));
483 unsigned lower_bound (
T,
bool (*)(
const T &,
const T &))
const;
484 static size_t embedded_size (
unsigned);
485 void embedded_init (
unsigned,
unsigned = 0);
486 void quick_grow (
unsigned len);
487 void quick_grow_cleared (
unsigned len);
490 template <
typename,
typename,
typename>
friend struct vec;
519 template<
typename T,
typename A>
523 return v ? v->
space (nelems) : nelems == 0;
528 template<
typename T,
typename A>
532 return v ? v->
length () : 0;
537 template<
typename T,
typename A>
541 return v ? v->
address () : NULL;
546 template<
typename T,
typename A>
556 template<
typename T,
typename A>
567 template<
typename T,
typename A>
579 template<
typename T,
typename A>
590 template<
typename T,
typename A>
599 template<
typename T,
typename A>
604 gcc_checking_assert (
len >= oldlen);
611 template<
typename T,
typename A>
622 template<
typename T,
typename A>
635 template<
typename T,
typename A>
651 template<
typename T,
typename A>
662 template<
typename T,
typename A>
673 template<
typename T,
typename A>
683 template<
typename T,
typename A>
687 return src ? src->
copy () : NULL;
692 template<
typename T,
typename A>
710 template<
typename T,
typename A>
714 gcc_checking_assert (ix < m_vecpfx.m_num);
715 return m_vecdata[ix];
718 template<
typename T,
typename A>
722 gcc_checking_assert (ix < m_vecpfx.m_num);
723 return m_vecdata[ix];
729 template<
typename T,
typename A>
733 gcc_checking_assert (m_vecpfx.m_num > 0);
734 return (*
this)[m_vecpfx.m_num - 1];
744 template<
typename T,
typename A>
748 return m_vecpfx.m_alloc - m_vecpfx.m_num >= nelems;
759 template<
typename T,
typename A>
763 if (ix < m_vecpfx.m_num)
765 *ptr = m_vecdata[ix];
785 template<
typename T,
typename A>
789 if (ix < m_vecpfx.m_num)
791 *ptr = CONST_CAST (
T *, &m_vecdata[ix]);
804 template<
typename T,
typename A>
809 unsigned len = length ();
823 template<
typename T,
typename A>
827 unsigned len = src.
length ();
830 gcc_checking_assert (space (len));
831 memcpy (address () + length (), src.
address (), len *
sizeof (
T));
832 m_vecpfx.m_num +=
len;
836 template<
typename T,
typename A>
849 template<
typename T,
typename A>
853 gcc_checking_assert (space (1));
854 T *
slot = &m_vecdata[m_vecpfx.m_num++];
862 template<
typename T,
typename A>
866 gcc_checking_assert (length () > 0);
867 return m_vecdata[--m_vecpfx.m_num];
874 template<
typename T,
typename A>
878 gcc_checking_assert (length () >= size);
879 m_vecpfx.m_num = size;
886 template<
typename T,
typename A>
890 gcc_checking_assert (length () < allocated ());
891 gcc_checking_assert (ix <= length ());
892 T *
slot = &m_vecdata[ix];
893 memmove (slot + 1, slot, (m_vecpfx.m_num++ - ix) * sizeof (
T));
902 template<
typename T,
typename A>
906 gcc_checking_assert (ix < length ());
907 T *slot = &m_vecdata[ix];
908 memmove (slot, slot + 1, (--m_vecpfx.m_num - ix) * sizeof (
T));
915 template<
typename T,
typename A>
919 gcc_checking_assert (ix < length ());
920 m_vecdata[ix] = m_vecdata[--m_vecpfx.m_num];
927 template<
typename T,
typename A>
931 gcc_checking_assert (ix + len <= length ());
932 T *slot = &m_vecdata[ix];
934 memmove (slot, slot + len, (m_vecpfx.m_num - ix) * sizeof (
T));
941 template<
typename T,
typename A>
945 ::qsort (address (), length (),
sizeof (
T), cmp);
954 template<
typename T,
typename A>
959 unsigned int len = length ();
960 unsigned int half, middle;
961 unsigned int first = 0;
967 T middle_elem = (*this)[middle];
968 if (lessthan (middle_elem, obj))
972 len = len - half - 1;
993 template<
typename T,
typename A>
998 return offsetof (vec_embedded, m_vecdata) + alloc *
sizeof (
T);
1005 template<
typename T,
typename A>
1009 m_vecpfx.m_alloc = alloc;
1010 m_vecpfx.m_has_auto_buf = 0;
1011 m_vecpfx.m_num = num;
1018 template<
typename T,
typename A>
1022 gcc_checking_assert (length () <= len && len <= m_vecpfx.m_alloc);
1023 m_vecpfx.m_num =
len;
1030 template<
typename T,
typename A>
1034 unsigned oldlen = length ();
1036 memset (&(address ()[oldlen]), 0,
sizeof (
T) * (len - oldlen));
1042 template<
typename T>
1047 for (
unsigned i = 0; i < v->length (); i++)
1051 template<
typename T>
1062 template<
typename T,
typename A>
1067 for (
unsigned i = 0; i < v->
length (); i++)
1068 gt_pch_nx ((*v)[i]);
1071 template<
typename T,
typename A>
1075 for (
unsigned i = 0; i < v->length (); i++)
1076 op (&((*v)[i]), cookie);
1079 template<
typename T,
typename A>
1084 for (
unsigned i = 0; i < v->
length (); i++)
1117 template<
typename T>
1123 void create (
unsigned nelems CXX_MEM_STAT_INFO);
1124 void release (
void);
1127 bool exists (
void)
const
1128 {
return m_vec != NULL; }
1131 {
return m_vec ? m_vec->is_empty () :
true; }
1133 unsigned length (
void)
const
1134 {
return m_vec ? m_vec->length () : 0; }
1137 {
return m_vec ? m_vec->m_vecdata : NULL; }
1139 const T *address (
void)
const
1140 {
return m_vec ? m_vec->m_vecdata : NULL; }
1142 const T &operator[] (
unsigned ix)
const
1143 {
return (*m_vec)[ix]; }
1145 bool operator!=(
const vec &other)
const
1146 {
return !(*
this == other); }
1148 bool operator==(
const vec &other)
const
1149 {
return address () == other.address (); }
1151 T &operator[] (
unsigned ix)
1152 {
return (*m_vec)[ix]; }
1155 {
return m_vec->last (); }
1157 bool space (
int nelems)
const
1158 {
return m_vec ? m_vec->space (nelems) : nelems == 0; }
1160 bool iterate (
unsigned ix,
T *p)
const;
1161 bool iterate (
unsigned ix,
T **p)
const;
1162 vec copy (ALONE_CXX_MEM_STAT_INFO)
const;
1163 bool reserve (
unsigned,
bool =
false CXX_MEM_STAT_INFO);
1164 bool reserve_exact (
unsigned CXX_MEM_STAT_INFO);
1165 void splice (
vec &);
1166 void safe_splice (
vec & CXX_MEM_STAT_INFO);
1167 T *quick_push (
const T &);
1168 T *safe_push (
const T &CXX_MEM_STAT_INFO);
1170 void truncate (
unsigned);
1171 void safe_grow (
unsigned CXX_MEM_STAT_INFO);
1172 void safe_grow_cleared (
unsigned CXX_MEM_STAT_INFO);
1173 void quick_grow (
unsigned);
1174 void quick_grow_cleared (
unsigned);
1175 void quick_insert (
unsigned,
const T &);
1176 void safe_insert (
unsigned,
const T & CXX_MEM_STAT_INFO);
1177 void ordered_remove (
unsigned);
1178 void unordered_remove (
unsigned);
1179 void block_remove (
unsigned,
unsigned);
1180 void qsort (
int (*) (
const void *,
const void *));
1181 unsigned lower_bound (
T,
bool (*)(
const T &,
const T &))
const;
1183 bool using_auto_storage ()
const;
1194 template<
typename T,
size_t N>
1223 template<
typename T>
1228 v->create (nelems PASS_MEM_STAT);
1234 template<
typename T>
1245 template<
typename T>
1265 template<
typename T>
1270 return m_vec->iterate (ix, ptr);
1288 template<
typename T>
1293 return m_vec->iterate (ix, ptr);
1303 #define FOR_EACH_VEC_ELT(V, I, P) \
1304 for (I = 0; (V).iterate ((I), &(P)); ++(I))
1306 #define FOR_EACH_VEC_SAFE_ELT(V, I, P) \
1307 for (I = 0; vec_safe_iterate ((V), (I), &(P)); ++(I))
1310 #define FOR_EACH_VEC_ELT_FROM(V, I, P, FROM) \
1311 for (I = (FROM); (V).iterate ((I), &(P)); ++(I))
1314 #define FOR_EACH_VEC_ELT_REVERSE(V, I, P) \
1315 for (I = (V).length () - 1; \
1316 (V).iterate ((I), &(P)); \
1319 #define FOR_EACH_VEC_SAFE_ELT_REVERSE(V, I, P) \
1320 for (I = vec_safe_length (V) - 1; \
1321 vec_safe_iterate ((V), (I), &(P)); \
1327 template<
typename T>
1333 new_vec.
m_vec = m_vec->copy ();
1347 template<
typename T>
1351 if (!nelems || space (nelems))
1358 unsigned int oldsize = 0;
1359 bool handle_auto_vec = m_vec && using_auto_storage ();
1360 if (handle_auto_vec)
1363 oldsize = oldvec->length ();
1368 if (handle_auto_vec)
1370 memcpy (m_vec->address (), oldvec->address (),
sizeof (
T) * oldsize);
1371 m_vec->m_vecpfx.m_num = oldsize;
1383 template<
typename T>
1387 return reserve (nelems,
true PASS_MEM_STAT);
1396 template<
typename T>
1402 reserve_exact (nelems PASS_MEM_STAT);
1408 template<
typename T>
1415 if (using_auto_storage ())
1429 template<
typename T>
1443 template<
typename T>
1450 reserve_exact (src.
length ());
1460 template<
typename T>
1464 return m_vec->quick_push (obj);
1472 template<
typename T>
1476 reserve (1,
false PASS_MEM_STAT);
1477 return quick_push (obj);
1483 template<
typename T>
1487 return m_vec->pop ();
1494 template<
typename T>
1499 m_vec->truncate (size);
1501 gcc_checking_assert (size == 0);
1509 template<
typename T>
1513 unsigned oldlen = length ();
1514 gcc_checking_assert (oldlen <= len);
1515 reserve_exact (len - oldlen PASS_MEM_STAT);
1516 m_vec->quick_grow (len);
1524 template<
typename T>
1528 unsigned oldlen = length ();
1529 safe_grow (len PASS_MEM_STAT);
1530 memset (&(address ()[oldlen]), 0,
sizeof (
T) * (len - oldlen));
1537 template<
typename T>
1541 gcc_checking_assert (m_vec);
1542 m_vec->quick_grow (len);
1550 template<
typename T>
1554 gcc_checking_assert (m_vec);
1555 m_vec->quick_grow_cleared (len);
1562 template<
typename T>
1566 m_vec->quick_insert (ix, obj);
1573 template<
typename T>
1577 reserve (1,
false PASS_MEM_STAT);
1578 quick_insert (ix, obj);
1586 template<
typename T>
1590 m_vec->ordered_remove (ix);
1597 template<
typename T>
1601 m_vec->unordered_remove (ix);
1608 template<
typename T>
1612 m_vec->block_remove (ix, len);
1619 template<
typename T>
1633 template<
typename T>
1636 bool (*lessthan)(
const T &,
const T &))
1639 return m_vec ? m_vec->lower_bound (obj, lessthan) : 0;
1642 template<
typename T>
1646 if (!m_vec->m_vecpfx.m_has_auto_buf)
1654 #if (GCC_VERSION >= 3000)
1655 # pragma GCC poison m_vec m_vecpfx m_vecdata