OSDN Git Service

PR debug/46307
[pf3gnuchains/gcc-fork.git] / gcc / vec.h
index e6c42bc..bc55592 100644 (file)
--- a/gcc/vec.h
+++ b/gcc/vec.h
@@ -190,6 +190,18 @@ along with GCC; see the file COPYING3.  If not see
 
 #define VEC_iterate(T,V,I,P)   (VEC_OP(T,base,iterate)(VEC_BASE(V),I,&(P)))
 
+/* Convenience macro for forward iteration.  */
+
+#define FOR_EACH_VEC_ELT(T, V, I, P)           \
+  for (I = 0; VEC_iterate (T, (V), (I), (P)); ++(I))
+
+/* Convenience macro for reverse iteration.  */
+
+#define FOR_EACH_VEC_ELT_REVERSE(T,V,I,P) \
+  for (I = VEC_length (T, (V)) - 1;           \
+       VEC_iterate (T, (V), (I), (P));   \
+       (I)--)
+
 /* Allocate new vector.
    VEC(T,A) *VEC_T_A_alloc(int reserve);
 
@@ -417,7 +429,7 @@ along with GCC; see the file COPYING3.  If not see
    void VEC_T_block_remove (VEC(T) *v, unsigned ix, unsigned len);
 
    Remove LEN elements starting at the IXth.  Ordering is retained.
-   This is an O(1) operation.  */
+   This is an O(N) operation due to memmove.  */
 
 #define VEC_block_remove(T,V,I,L)      \
        (VEC_OP(T,base,block_remove)(VEC_BASE(V),I,L VEC_CHECK_INFO))
@@ -430,6 +442,12 @@ along with GCC; see the file COPYING3.  If not see
 
 #define VEC_address(T,V)               (VEC_OP(T,base,address)(VEC_BASE(V)))
 
+/* Conveniently sort the contents of the vector with qsort.
+   void VEC_qsort (VEC(T) *v, int (*cmp_func)(const void *, const void *))  */
+
+#define VEC_qsort(T,V,CMP) qsort(VEC_address (T,V), VEC_length(T,V),   \
+                                sizeof (T), CMP)
+
 /* Find the first index in the vector not less than the object.
    unsigned VEC_T_lower_bound (VEC(T) *v, const T val,
                                bool (*lessthan) (const T, const T)); // Integer