add_method (tree type, tree method)
{
int using;
- size_t len;
- size_t slot;
+ unsigned slot;
tree overload;
int template_conv_p;
VEC(tree) *method_vec;
bool complete_p;
+ bool insert_p = false;
+ tree current_fns;
if (method == error_mark_node)
return;
CLASSTYPE_METHOD_VEC (type) = method_vec;
}
- len = VEC_length (tree, method_vec);
-
/* Constructors and destructors go in special slots. */
if (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (method))
slot = CLASSTYPE_CONSTRUCTOR_SLOT;
}
else
{
- bool insert_p = true;
bool conv_p = DECL_CONV_FN_P (method);
tree m;
+ insert_p = true;
/* See if we already have an entry with this name. */
for (slot = CLASSTYPE_FIRST_CONVERSION_SLOT;
- (m = VEC_iterate (tree, method_vec, slot));
+ VEC_iterate (tree, method_vec, slot, m);
++slot)
{
m = OVL_CURRENT (m);
&& DECL_NAME (m) > DECL_NAME (method))
break;
}
-
- /* If we need a new slot, make room. */
- if (insert_p)
- {
- /* We expect to add few methods in the COMPLETE_P case, so
- just make room for one more method. */
- if (complete_p)
- VEC_reserve (tree, method_vec, 1);
- if (slot == len)
- VEC_safe_push (tree, method_vec, NULL_TREE);
- else
- VEC_safe_insert (tree, method_vec, slot, NULL_TREE);
- len++;
- /* Inserting a new slot may have caused the vector to be
- reallocated. */
- CLASSTYPE_METHOD_VEC (type) = method_vec;
- }
}
-
+ current_fns = insert_p ? NULL_TREE : VEC_index (tree, method_vec, slot);
+
if (processing_template_decl)
/* TYPE is a template class. Don't issue any errors now; wait
until instantiation time to complain. */
tree fns;
/* Check to see if we've already got this method. */
- for (fns = VEC_index (tree, method_vec, slot);
- fns;
- fns = OVL_NEXT (fns))
+ for (fns = current_fns; fns; fns = OVL_NEXT (fns))
{
tree fn = OVL_CURRENT (fns);
tree parms1;
}
/* Add the new binding. */
- overload = build_overload (method, VEC_index (tree, method_vec, slot));
- if (!DECL_CONSTRUCTOR_P (method)
- && !DECL_DESTRUCTOR_P (method)
- && !complete_p)
+ overload = build_overload (method, current_fns);
+
+ if (slot >= CLASSTYPE_FIRST_CONVERSION_SLOT && !complete_p)
push_class_level_binding (DECL_NAME (method), overload);
- /* Actually insert the new method. */
- VEC_replace (tree, method_vec, slot, overload);
+ if (insert_p)
+ {
+ /* We only expect to add few methods in the COMPLETE_P case, so
+ just make room for one more method in that case. */
+ if (VEC_reserve (tree, method_vec, complete_p ? 1 : -1))
+ CLASSTYPE_METHOD_VEC (type) = method_vec;
+ if (slot == VEC_length (tree, method_vec))
+ VEC_quick_push (tree, method_vec, overload);
+ else
+ VEC_quick_insert (tree, method_vec, slot, overload);
+ }
+ else
+ /* Replace the current slot. */
+ VEC_replace (tree, method_vec, slot, overload);
}
/* Subroutines of finish_struct. */
determine_primary_base (tree t)
{
unsigned i, n_baseclasses = BINFO_N_BASE_BINFOS (TYPE_BINFO (t));
- tree type_binfo;
+ tree type_binfo = TYPE_BINFO (t);
tree vbase_binfo;
+ VEC(tree) *vbases;
/* If there are no baseclasses, there is certainly no primary base. */
if (n_baseclasses == 0)
/* Find the indirect primary bases - those virtual bases which are primary
bases of something else in this hierarchy. */
- for (i = 0; (vbase_binfo = VEC_iterate
- (tree, CLASSTYPE_VBASECLASSES (t), i)); i++)
+ for (vbases = CLASSTYPE_VBASECLASSES (t), i = 0;
+ VEC_iterate (tree, vbases, i, vbase_binfo); i++)
{
unsigned j;
for (j = 0; j != n_baseclasses; ++j)
{
unsigned k;
+ VEC (tree) *base_vbases;
tree base_vbase_binfo;
tree basetype = BINFO_TYPE (BINFO_BASE_BINFO (TYPE_BINFO (t), j));
- for (k = 0; (base_vbase_binfo = VEC_iterate
- (tree, CLASSTYPE_VBASECLASSES (basetype), k)); k++)
+ for (base_vbases = CLASSTYPE_VBASECLASSES (basetype), k = 0;
+ VEC_iterate (tree, base_vbases, k, base_vbase_binfo); k++)
{
if (BINFO_PRIMARY_P (base_vbase_binfo)
&& same_type_p (BINFO_TYPE (base_vbase_binfo),
/* The type conversion ops have to live at the front of the vec, so we
can't sort them. */
for (slot = CLASSTYPE_FIRST_CONVERSION_SLOT;
- (fn = VEC_iterate (tree, method_vec, slot));
+ VEC_iterate (tree, method_vec, slot, fn);
++slot)
if (!DECL_CONV_FN_P (OVL_CURRENT (fn)))
break;
/* The type conversion ops have to live at the front of the vec, so we
can't sort them. */
- for (slot = 2;
- (fn_fields = VEC_iterate (tree, method_vec, slot));
+ for (slot = CLASSTYPE_FIRST_CONVERSION_SLOT;
+ VEC_iterate (tree, method_vec, slot, fn_fields);
++slot)
if (!DECL_CONV_FN_P (OVL_CURRENT (fn_fields)))
break;
/* We go through each separately named virtual function. */
for (i = CLASSTYPE_FIRST_CONVERSION_SLOT;
- (fns = VEC_iterate (tree, method_vec, i));
+ VEC_iterate (tree, method_vec, i, fns);
++i)
{
tree fn;
if (abi_version_at_least (2) && CLASSTYPE_VBASECLASSES (type))
{
unsigned ix;
+ VEC (tree) *vbases;
/* Iterate through the virtual base classes of TYPE. In G++
3.2, we included virtual bases in the direct base class
correct offsets for virtual bases are only known when
working with the most derived type. */
if (vbases_p)
- for (ix = 0; (binfo = VEC_iterate
- (tree, CLASSTYPE_VBASECLASSES (type), ix)); ix++)
+ for (vbases = CLASSTYPE_VBASECLASSES (type), ix = 0;
+ VEC_iterate (tree, vbases, ix, binfo); ix++)
{
r = walk_subobject_offsets (binfo,
f,
end_of_class (tree t, int include_virtuals_p)
{
tree result = size_zero_node;
+ VEC (tree) *vbases;
tree binfo;
+ tree base_binfo;
tree offset;
int i;
/* G++ 3.2 did not check indirect virtual bases. */
if (abi_version_at_least (2) && include_virtuals_p)
- for (i = 0; (binfo = VEC_iterate
- (tree, CLASSTYPE_VBASECLASSES (t), i)); i++)
+ for (vbases = CLASSTYPE_VBASECLASSES (t), i = 0;
+ VEC_iterate (tree, vbases, i, base_binfo); i++)
{
- offset = end_of_base (binfo);
+ offset = end_of_base (base_binfo);
if (INT_CST_LT_UNSIGNED (result, offset))
result = offset;
}
warn_about_ambiguous_bases (tree t)
{
int i;
+ VEC (tree) *vbases;
tree basetype;
tree binfo;
/* Check direct bases. */
- for (i = 0; i < BINFO_N_BASE_BINFOS (TYPE_BINFO (t)); ++i)
+ for (i = 0;
+ i < BINFO_N_BASE_BINFOS (TYPE_BINFO (t)); ++i)
{
basetype = BINFO_TYPE (BINFO_BASE_BINFO (TYPE_BINFO (t), i));
/* Check for ambiguous virtual bases. */
if (extra_warnings)
- for (i = 0; (binfo = VEC_iterate
- (tree, CLASSTYPE_VBASECLASSES (t), i)); i++)
+ for (vbases = CLASSTYPE_VBASECLASSES (t), i = 0;
+ VEC_iterate (tree, vbases, i, binfo); i++)
{
basetype = BINFO_TYPE (binfo);
vtbl_init_data vid;
unsigned ix;
tree vbinfo;
-
+ VEC (tree) *vbases;
+
/* Initialize VID. */
memset (&vid, 0, sizeof (vid));
vid.binfo = binfo;
/* Clear BINFO_VTABLE_PATH_MARKED; it's set by
build_vbase_offset_vtbl_entries. */
- for (ix = 0; (vbinfo = VEC_iterate
- (tree, CLASSTYPE_VBASECLASSES (t), ix)); ix++)
+ for (vbases = CLASSTYPE_VBASECLASSES (t), ix = 0;
+ VEC_iterate (tree, vbases, ix, vbinfo); ix++)
BINFO_VTABLE_PATH_MARKED (vbinfo) = 0;
/* If the target requires padding between data entries, add that now. */
objects pointed to must be long lived, but when dealing with a
vector of objects, the source objects need not be.
+ There are both 'index' and 'iterate' accessors. The iterator
+ returns a boolean iteration condition and updates the iteration
+ variable passed by reference. Because the iterator will be
+ inlined, the address-of can be optimized away.
+
The vectors are implemented using the trailing array idiom, thus
they are not resizeable without changing the address of the vector
object itself. This means you cannot have variables or fields of
element ordering 'ordered_remove', and one which does not
'unordered_remove'. The latter function copies the end element
into the removed slot, rather than invoke a memmove operation.
+
+ If you need to directly manipulate a vector, then the 'address'
+ accessor will return the address of the start of the vector. Also
+ the 'space' predicate will tell you whether there is spare capacity
+ in the vector. You will not normally need to use these two functions.
Vector types are defined using a DEF_VEC_x(TYPEDEF) macro, and
variables of vector type are declared using a VEC(TYPEDEF)
if (VEC_length(tree,s->v)) { we have some contents }
VEC_safe_push(tree,s->v,decl); // append some decl onto the end
- for (ix = 0; (t = VEC_iterate(tree,s->v,ix)); ix++)
+ for (ix = 0; VEC_iterate(tree,s->v,ix,t); ix++)
{ do something with t }
*/
Return the number of active elements in V. V can be NULL, in which
case zero is returned. */
-#define VEC_length(TDEF,V) (VEC_OP(TDEF,length)(V))
+
+#define VEC_length(TDEF,V) (VEC_OP(TDEF,length)(V))
/* Get the final element of the vector.
T VEC_T_last(VEC(T) *v); // Pointer
T *VEC_T_last(VEC(T) *v); // Object
Return the final element. If V is empty, abort. */
-#define VEC_last(TDEF,V) (VEC_OP(TDEF,last)(V))
+
+#define VEC_last(TDEF,V) (VEC_OP(TDEF,last)(V VEC_CHECK_INFO))
/* Index into vector
T VEC_T_index(VEC(T) *v, size_t ix); // Pointer
Return the IX'th element. If IX is outside the domain of V,
abort. */
-#define VEC_index(TDEF,V,I) (VEC_OP(TDEF,index)(V,I))
+
+#define VEC_index(TDEF,V,I) (VEC_OP(TDEF,index)(V,I VEC_CHECK_INFO))
/* Iterate over vector
- T VEC_T_index(VEC(T) *v, size_t ix); // Pointer
- T *VEC_T_index(VEC(T) *v, size_t ix); // Object
+ int VEC_T_index(VEC(T) *v, size_t ix, T &ptr); // Pointer
+ int VEC_T_index(VEC(T) *v, size_t ix, T *&ptr); // Object
- Return the IX'th element or NULL. Use this to iterate over the
- elements of a vector as follows,
+ Return iteration condition and update PTR to point to the IX'th
+ element. At the end of iteration, sets PTR to NULL. Use this to
+ iterate over the elements of a vector as follows,
- for (ix = 0; (ptr = VEC_iterate(T,v,ix)); ix++)
+ for (ix = 0; VEC_iterate(T,v,ix,ptr); ix++)
continue; */
-#define VEC_iterate(TDEF,V,I) (VEC_OP(TDEF,iterate)(V,I))
+
+#define VEC_iterate(TDEF,V,I,P) (VEC_OP(TDEF,iterate)(V,I,&(P)))
/* Allocate new vector.
VEC(T) *VEC_T_alloc(int reserve);
Allocate a new vector with space for RESERVE objects. If RESERVE
is <= 0, a default number of slots are created. */
-#define VEC_alloc(TDEF,A) (VEC_OP(TDEF,alloc)(A MEM_STAT_INFO))
+
+#define VEC_alloc(TDEF,A) (VEC_OP(TDEF,alloc)(A MEM_STAT_INFO))
/* Use these to determine the required size and initialization of a
vector embedded within another structure (as the final member).
void VEC_T_embedded_init(VEC(T) *v, int reserve);
These allow the caller to perform the memory allocation. */
-#define VEC_embedded_size(TDEF,A) (VEC_OP(TDEF,embedded_size)(A))
-#define VEC_embedded_init(TDEF,O,A) (VEC_OP(TDEF,embedded_init)(O,A))
+
+#define VEC_embedded_size(TDEF,A) (VEC_OP(TDEF,embedded_size)(A))
+#define VEC_embedded_init(TDEF,O,A) (VEC_OP(TDEF,embedded_init)(O,A))
+
+/* Determine if a vector has additional capacity.
+
+ int VEC_T_space (VEC(T) *v,int reserve)
+
+ If V has space for RESERVE additional entries, return non-zero. If
+ RESERVE is < 0, ensure there is at least one space slot. You
+ usually only need to use this if you are doing your own vector
+ reallocation, for instance on an embedded vector. This returns
+ non-zero in exactly the same circumstances that VEC_T_reserve
+ will. */
+
+#define VEC_space(TDEF,V,R) (VEC_OP(TDEF,space)(V,R))
/* Reserve space.
int VEC_T_reserve(VEC(T) *&v, int reserve);
perform the usual exponential headroom increase. Note this can
cause V to be reallocated. Returns non-zero iff reallocation
actually occurred. */
+
#define VEC_reserve(TDEF,V,R) (VEC_OP(TDEF,reserve)(&(V),R MEM_STAT_INFO))
/* Push object with no reallocation
filled in. For object vectors, the new value can be NULL, in which
case NO initialization is performed. Aborts if there is
insufficient space in the vector. */
-#define VEC_quick_push(TDEF,V,O) (VEC_OP(TDEF,quick_push)(V,O))
+
+#define VEC_quick_push(TDEF,V,O) \
+ (VEC_OP(TDEF,quick_push)(V,O VEC_CHECK_INFO))
/* Push object with reallocation
T *VEC_T_safe_push (VEC(T) *&v, T obj); // Pointer
Push a new element onto the end, returns a pointer to the slot
filled in. For object vectors, the new value can be NULL, in which
case NO initialization is performed. Reallocates V, if needed. */
-#define VEC_safe_push(TDEF,V,O) (VEC_OP(TDEF,safe_push)(&(V),O MEM_STAT_INFO))
+
+#define VEC_safe_push(TDEF,V,O) \
+ (VEC_OP(TDEF,safe_push)(&(V),O VEC_CHECK_INFO MEM_STAT_INFO))
/* Pop element off end
T VEC_T_pop (VEC(T) *v); // Pointer
Pop the last element off the end. Returns the element popped, for
pointer vectors. */
-#define VEC_pop(TDEF,V) (VEC_OP(TDEF,pop)(V))
+
+#define VEC_pop(TDEF,V) (VEC_OP(TDEF,pop)(V VEC_CHECK_INFO))
/* Truncate to specific length
void VEC_T_truncate (VEC(T) *v, size_t len);
Set the length as specified. This is an O(1) operation. */
-#define VEC_truncate(TDEF,V,I) (VEC_OP(TDEF,truncate)(V,I))
+
+#define VEC_truncate(TDEF,V,I) \
+ (VEC_OP(TDEF,truncate)(V,I VEC_CHECK_INFO))
/* Replace element
T VEC_T_replace (VEC(T) *v, size_t ix, T val); // Pointer
pointer to the new value. For object vectors the new value can be
NULL, in which case no overwriting of the slot is actually
performed. */
-#define VEC_replace(TDEF,V,I,O) (VEC_OP(TDEF,replace)(V,I,O))
+
+#define VEC_replace(TDEF,V,I,O) \
+ (VEC_OP(TDEF,replace)(V,I,O VEC_CHECK_INFO))
/* Insert object with no reallocation
T *VEC_T_quick_insert (VEC(T) *v, size_t ix, T val); // Pointer
to the slot created. For vectors of object, the new value can be
NULL, in which case no initialization of the inserted slot takes
place. Aborts if there is insufficient space. */
-#define VEC_quick_insert(TDEF,V,I,O) (VEC_OP(TDEF,quick_insert)(V,I,O))
+
+#define VEC_quick_insert(TDEF,V,I,O) \
+ (VEC_OP(TDEF,quick_insert)(V,I,O VEC_CHECK_INFO))
/* Insert object with reallocation
T *VEC_T_safe_insert (VEC(T) *&v, size_t ix, T val); // Pointer
to the slot created. For vectors of object, the new value can be
NULL, in which case no initialization of the inserted slot takes
place. Reallocate V, if necessary. */
-#define VEC_safe_insert(TDEF,V,I,O) (VEC_OP(TDEF,safe_insert)(&(V),I,O MEM_STAT_INFO))
+
+#define VEC_safe_insert(TDEF,V,I,O) \
+ (VEC_OP(TDEF,safe_insert)(&(V),I,O VEC_CHECK_INFO MEM_STAT_INFO))
/* Remove element retaining order
T VEC_T_ordered_remove (VEC(T) *v, size_t ix); // Pointer
Remove an element from the IXth position of V. Ordering of
remaining elements is preserverd. For pointer vectors returns the
removed object. This is an O(N) operation due to a memmove. */
-#define VEC_ordered_remove(TDEF,V,I) (VEC_OP(TDEF,ordered_remove)(V,I))
+
+#define VEC_ordered_remove(TDEF,V,I) \
+ (VEC_OP(TDEF,ordered_remove)(V,I VEC_CHECK_INFO))
/* Remove element destroying order
T VEC_T_unordered_remove (VEC(T) *v, size_t ix); // Pointer
Remove an element from the IXth position of V. Ordering of
remaining elements is destroyed. For pointer vectors returns the
removed object. This is an O(1) operation. */
-#define VEC_unordered_remove(TDEF,V,I) (VEC_OP(TDEF,unordered_remove)(V,I))
+
+#define VEC_unordered_remove(TDEF,V,I) \
+ (VEC_OP(TDEF,unordered_remove)(V,I VEC_CHECK_INFO))
/* Get the address of the array of elements
T *VEC_T_address (VEC(T) v)
If you need to directly manipulate the array (for instance, you
want to feed it to qsort), use this accessor. */
+
#define VEC_address(TDEF,V) (VEC_OP(TDEF,address)(V))
#if !IN_GENGTYPE
extern void *vec_o_reserve (void *, int, size_t, size_t MEM_STAT_DECL);
#if ENABLE_CHECKING
-extern void vec_assert_fail (const char *, const char *,
- const char *, unsigned int, const char *)
- ATTRIBUTE_NORETURN;
-#define VEC_ASSERT_FAIL(OP,VEC) \
- vec_assert_fail (OP,#VEC,__FILE__,__LINE__,__FUNCTION__)
+#define VEC_CHECK_INFO ,__FILE__,__LINE__,__FUNCTION__
+#define VEC_CHECK_DECL ,const char *file_,unsigned line_,const char *function_
+#define VEC_CHECK_PASS ,file_,line_,function_
#define VEC_ASSERT(EXPR,OP,TDEF) \
(void)((EXPR) ? 0 : (VEC_ASSERT_FAIL(OP,VEC(TDEF)), 0))
+
+extern void vec_assert_fail (const char *, const char * VEC_CHECK_DECL)
+ ATTRIBUTE_NORETURN;
+#define VEC_ASSERT_FAIL(OP,VEC) vec_assert_fail (OP,#VEC VEC_CHECK_PASS)
#else
+#define VEC_CHECK_INFO
+#define VEC_CHECK_DECL
+#define VEC_CHECK_PASS
#define VEC_ASSERT(EXPR,OP,TYPE) (void)(EXPR)
#endif
} \
\
static inline TDEF VEC_OP (TDEF,last) \
- (const VEC (TDEF) *vec_) \
+ (const VEC (TDEF) *vec_ VEC_CHECK_DECL) \
{ \
VEC_ASSERT (vec_ && vec_->num, "last", TDEF); \
\
} \
\
static inline TDEF VEC_OP (TDEF,index) \
- (const VEC (TDEF) *vec_, size_t ix_) \
+ (const VEC (TDEF) *vec_, size_t ix_ VEC_CHECK_DECL) \
{ \
VEC_ASSERT (vec_ && ix_ < vec_->num, "index", TDEF); \
\
return vec_->vec[ix_]; \
} \
\
-static inline TDEF VEC_OP (TDEF,iterate) \
- (const VEC (TDEF) *vec_, size_t ix_) \
+static inline int VEC_OP (TDEF,iterate) \
+ (const VEC (TDEF) *vec_, size_t ix_, TDEF *ptr) \
{ \
- return vec_ && ix_ < vec_->num ? vec_->vec[ix_] : NULL; \
+ if (vec_ && ix_ < vec_->num) \
+ { \
+ *ptr = vec_->vec[ix_]; \
+ return 1; \
+ } \
+ else \
+ { \
+ *ptr = 0; \
+ return 0; \
+ } \
} \
\
static inline VEC (TDEF) *VEC_OP (TDEF,alloc) \
vec_->alloc = alloc_; \
} \
\
+static inline int VEC_OP (TDEF,space) \
+ (VEC (TDEF) *vec_, int alloc_) \
+{ \
+ return vec_ ? ((vec_)->alloc - (vec_)->num \
+ < (size_t)(alloc_ < 0 ? 1 : alloc_)) : alloc_ != 0; \
+} \
+ \
static inline int VEC_OP (TDEF,reserve) \
(VEC (TDEF) **vec_, int alloc_ MEM_STAT_DECL) \
{ \
- int extend = !*vec_ || ((*vec_)->alloc - (*vec_)->num \
- < (size_t)(alloc_ < 0 ? 1 : alloc_)); \
+ int extend = VEC_OP (TDEF,space) (*vec_, alloc_); \
\
if (extend) \
*vec_ = vec_p_reserve (*vec_, alloc_ PASS_MEM_STAT); \
} \
\
static inline TDEF *VEC_OP (TDEF,quick_push) \
- (VEC (TDEF) *vec_, TDEF obj_) \
+ (VEC (TDEF) *vec_, TDEF obj_ VEC_CHECK_DECL) \
{ \
TDEF *slot_; \
\
} \
\
static inline TDEF *VEC_OP (TDEF,safe_push) \
- (VEC (TDEF) **vec_, TDEF obj_ MEM_STAT_DECL) \
+ (VEC (TDEF) **vec_, TDEF obj_ VEC_CHECK_DECL MEM_STAT_DECL) \
{ \
VEC_OP (TDEF,reserve) (vec_, -1 PASS_MEM_STAT); \
\
- return VEC_OP (TDEF,quick_push) (*vec_, obj_); \
+ return VEC_OP (TDEF,quick_push) (*vec_, obj_ VEC_CHECK_PASS); \
} \
\
static inline TDEF VEC_OP (TDEF,pop) \
- (VEC (TDEF) *vec_) \
+ (VEC (TDEF) *vec_ VEC_CHECK_DECL) \
{ \
TDEF obj_; \
\
} \
\
static inline void VEC_OP (TDEF,truncate) \
- (VEC (TDEF) *vec_, size_t size_) \
+ (VEC (TDEF) *vec_, size_t size_ VEC_CHECK_DECL) \
{ \
VEC_ASSERT (vec_ ? vec_->num >= size_ : !size_, "truncate", TDEF); \
if (vec_) \
} \
\
static inline TDEF VEC_OP (TDEF,replace) \
- (VEC (TDEF) *vec_, size_t ix_, TDEF obj_) \
+ (VEC (TDEF) *vec_, size_t ix_, TDEF obj_ VEC_CHECK_DECL) \
{ \
TDEF old_obj_; \
\
} \
\
static inline TDEF *VEC_OP (TDEF,quick_insert) \
- (VEC (TDEF) *vec_, size_t ix_, TDEF obj_) \
+ (VEC (TDEF) *vec_, size_t ix_, TDEF obj_ VEC_CHECK_DECL) \
{ \
TDEF *slot_; \
\
} \
\
static inline TDEF *VEC_OP (TDEF,safe_insert) \
- (VEC (TDEF) **vec_, size_t ix_, TDEF obj_ MEM_STAT_DECL) \
+ (VEC (TDEF) **vec_, size_t ix_, TDEF obj_ VEC_CHECK_DECL MEM_STAT_DECL) \
{ \
VEC_OP (TDEF,reserve) (vec_, -1 PASS_MEM_STAT); \
\
- return VEC_OP (TDEF,quick_insert) (*vec_, ix_, obj_); \
+ return VEC_OP (TDEF,quick_insert) (*vec_, ix_, obj_ VEC_CHECK_PASS); \
} \
\
static inline TDEF VEC_OP (TDEF,ordered_remove) \
- (VEC (TDEF) *vec_, size_t ix_) \
+ (VEC (TDEF) *vec_, size_t ix_ VEC_CHECK_DECL) \
{ \
TDEF *slot_; \
TDEF obj_; \
} \
\
static inline TDEF VEC_OP (TDEF,unordered_remove) \
- (VEC (TDEF) *vec_, size_t ix_) \
+ (VEC (TDEF) *vec_, size_t ix_ VEC_CHECK_DECL) \
{ \
TDEF *slot_; \
TDEF obj_; \
} \
\
static inline TDEF *VEC_OP (TDEF,last) \
- (VEC (TDEF) *vec_) \
+ (VEC (TDEF) *vec_ VEC_CHECK_DECL) \
{ \
VEC_ASSERT (vec_ && vec_->num, "last", TDEF); \
\
} \
\
static inline TDEF *VEC_OP (TDEF,index) \
- (VEC (TDEF) *vec_, size_t ix_) \
+ (VEC (TDEF) *vec_, size_t ix_ VEC_CHECK_DECL) \
{ \
VEC_ASSERT (vec_ && ix_ < vec_->num, "index", TDEF); \
\
return &vec_->vec[ix_]; \
} \
\
-static inline TDEF *VEC_OP (TDEF,iterate) \
- (VEC (TDEF) *vec_, size_t ix_) \
+static inline int VEC_OP (TDEF,iterate) \
+ (VEC (TDEF) *vec_, size_t ix_, TDEF **ptr) \
{ \
- return vec_ && ix_ < vec_->num ? &vec_->vec[ix_] : NULL; \
+ if (vec_ && ix_ < vec_->num) \
+ { \
+ *ptr = &vec_->vec[ix_]; \
+ return 1; \
+ } \
+ else \
+ { \
+ *ptr = 0; \
+ return 0; \
+ } \
} \
\
static inline VEC (TDEF) *VEC_OP (TDEF,alloc) \
vec_->alloc = alloc_; \
} \
\
+static inline int VEC_OP (TDEF,space) \
+ (VEC (TDEF) *vec_, int alloc_) \
+{ \
+ return vec_ ? ((vec_)->alloc - (vec_)->num \
+ < (size_t)(alloc_ < 0 ? 1 : alloc_)) : alloc_ != 0; \
+} \
+ \
static inline int VEC_OP (TDEF,reserve) \
(VEC (TDEF) **vec_, int alloc_ MEM_STAT_DECL) \
{ \
- int extend = !*vec_ || ((*vec_)->alloc - (*vec_)->num \
- < (size_t)(alloc_ < 0 ? 1 : alloc_)); \
+ int extend = VEC_OP (TDEF,space) (*vec_, alloc_); \
\
if (extend) \
*vec_ = vec_o_reserve (*vec_, alloc_, \
} \
\
static inline TDEF *VEC_OP (TDEF,quick_push) \
- (VEC (TDEF) *vec_, const TDEF *obj_) \
+ (VEC (TDEF) *vec_, const TDEF *obj_ VEC_CHECK_DECL) \
{ \
TDEF *slot_; \
\
} \
\
static inline TDEF *VEC_OP (TDEF,safe_push) \
- (VEC (TDEF) **vec_, const TDEF *obj_ MEM_STAT_DECL) \
+ (VEC (TDEF) **vec_, const TDEF *obj_ VEC_CHECK_DECL MEM_STAT_DECL) \
{ \
VEC_OP (TDEF,reserve) (vec_, -1 PASS_MEM_STAT); \
\
- return VEC_OP (TDEF,quick_push) (*vec_, obj_); \
+ return VEC_OP (TDEF,quick_push) (*vec_, obj_ VEC_CHECK_PASS); \
} \
\
static inline void VEC_OP (TDEF,pop) \
- (VEC (TDEF) *vec_) \
+ (VEC (TDEF) *vec_ VEC_CHECK_DECL) \
{ \
VEC_ASSERT (vec_->num, "pop", TDEF); \
--vec_->num; \
} \
\
static inline void VEC_OP (TDEF,truncate) \
- (VEC (TDEF) *vec_, size_t size_) \
+ (VEC (TDEF) *vec_, size_t size_ VEC_CHECK_DECL) \
{ \
VEC_ASSERT (vec_ ? vec_->num >= size_ : !size_, "truncate", TDEF); \
if (vec_) \
} \
\
static inline TDEF *VEC_OP (TDEF,replace) \
- (VEC (TDEF) *vec_, size_t ix_, const TDEF *obj_) \
+ (VEC (TDEF) *vec_, size_t ix_, const TDEF *obj_ VEC_CHECK_DECL) \
{ \
TDEF *slot_; \
\
} \
\
static inline TDEF *VEC_OP (TDEF,quick_insert) \
- (VEC (TDEF) *vec_, size_t ix_, const TDEF *obj_) \
+ (VEC (TDEF) *vec_, size_t ix_, const TDEF *obj_ VEC_CHECK_DECL) \
{ \
TDEF *slot_; \
\
} \
\
static inline TDEF *VEC_OP (TDEF,safe_insert) \
- (VEC (TDEF) **vec_, size_t ix_, const TDEF *obj_ MEM_STAT_DECL) \
+ (VEC (TDEF) **vec_, size_t ix_, const TDEF *obj_ VEC_CHECK_DECL MEM_STAT_DECL) \
{ \
VEC_OP (TDEF,reserve) (vec_, -1 PASS_MEM_STAT); \
\
- return VEC_OP (TDEF,quick_insert) (*vec_, ix_, obj_); \
+ return VEC_OP (TDEF,quick_insert) (*vec_, ix_, obj_ VEC_CHECK_PASS); \
} \
\
static inline void VEC_OP (TDEF,ordered_remove) \
- (VEC (TDEF) *vec_, size_t ix_) \
+ (VEC (TDEF) *vec_, size_t ix_ VEC_CHECK_DECL) \
{ \
TDEF *slot_; \
\
} \
\
static inline void VEC_OP (TDEF,unordered_remove) \
- (VEC (TDEF) *vec_, size_t ix_) \
+ (VEC (TDEF) *vec_, size_t ix_ VEC_CHECK_DECL) \
{ \
VEC_ASSERT (ix_ < vec_->num, "remove", TDEF); \
vec_->vec[ix_] = vec_->vec[--vec_->num]; \