OSDN Git Service

remove gfc_chainon_list
[pf3gnuchains/gcc-fork.git] / gcc / vec.h
index 8cb9c58..bc55592 100644 (file)
--- a/gcc/vec.h
+++ b/gcc/vec.h
@@ -22,6 +22,8 @@ along with GCC; see the file COPYING3.  If not see
 #ifndef GCC_VEC_H
 #define GCC_VEC_H
 
+#include "statistics.h"                /* For MEM_STAT_DECL.  */
+
 /* The macros here implement a set of templated vector types and
    associated interfaces.  These templates are implemented with
    macros, as we're not in C++ land.  The interface functions are
@@ -188,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);
 
@@ -257,6 +271,32 @@ along with GCC; see the file COPYING3.  If not see
 #define VEC_reserve_exact(T,A,V,R)     \
        (VEC_OP(T,A,reserve_exact)(&(V),R VEC_CHECK_INFO MEM_STAT_INFO))
 
+/* Copy elements with no reallocation
+   void VEC_T_splice (VEC(T) *dst, VEC(T) *src); // Integer
+   void VEC_T_splice (VEC(T) *dst, VEC(T) *src); // Pointer
+   void VEC_T_splice (VEC(T) *dst, VEC(T) *src); // Object
+
+   Copy the elements in SRC to the end of DST as if by memcpy.  DST and
+   SRC need not be allocated with the same mechanism, although they most
+   often will be.  DST is assumed to have sufficient headroom
+   available.  */
+
+#define VEC_splice(T,DST,SRC)                  \
+  (VEC_OP(T,base,splice)(VEC_BASE(DST), VEC_BASE(SRC) VEC_CHECK_INFO))
+
+/* Copy elements with reallocation
+   void VEC_T_safe_splice (VEC(T,A) *&dst, VEC(T) *src); // Integer
+   void VEC_T_safe_splice (VEC(T,A) *&dst, VEC(T) *src); // Pointer
+   void VEC_T_safe_splice (VEC(T,A) *&dst, VEC(T) *src); // Object
+
+   Copy the elements in SRC to the end of DST as if by memcpy.  DST and
+   SRC need not be allocated with the same mechanism, although they most
+   often will be.  DST need not have sufficient headroom and will be
+   reallocated if needed.  */
+
+#define VEC_safe_splice(T,A,DST,SRC)                                   \
+  (VEC_OP(T,A,safe_splice)(&(DST), VEC_BASE(SRC) VEC_CHECK_INFO MEM_STAT_INFO))
+  
 /* Push object with no reallocation
    T *VEC_T_quick_push (VEC(T) *v, T obj); // Integer
    T *VEC_T_quick_push (VEC(T) *v, T obj); // Pointer
@@ -389,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))
@@ -402,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
@@ -434,7 +480,8 @@ extern void dump_vec_loc_statistics (void);
 #ifdef GATHER_STATISTICS
 void vec_heap_free (void *);
 #else
-#define vec_heap_free(V) free (V)
+/* Avoid problems with frontends that #define free(x).  */
+#define vec_heap_free(V) (free) (V)
 #endif
 
 #if ENABLE_CHECKING
@@ -586,6 +633,19 @@ static inline int VEC_OP (T,base,space)                                      \
   return vec_ ? vec_->alloc - vec_->num >= (unsigned)alloc_ : !alloc_;   \
 }                                                                        \
                                                                          \
+static inline void VEC_OP(T,base,splice)                                 \
+     (VEC(T,base) *dst_, VEC(T,base) *src_ VEC_CHECK_DECL)               \
+{                                                                        \
+  if (src_)                                                              \
+    {                                                                    \
+      unsigned len_ = src_->num;                                         \
+      VEC_ASSERT (dst_->num + len_ <= dst_->alloc, "splice", T, base);   \
+                                                                         \
+      memcpy (&dst_->vec[dst_->num], &src_->vec[0], len_ * sizeof (T));          \
+      dst_->num += len_;                                                 \
+    }                                                                    \
+}                                                                        \
+                                                                         \
 static inline T *VEC_OP (T,base,quick_push)                              \
      (VEC(T,base) *vec_, T obj_ VEC_CHECK_DECL)                                  \
 {                                                                        \
@@ -793,6 +853,19 @@ static inline void VEC_OP (T,A,safe_grow_cleared)                    \
          sizeof (T) * (size_ - oldsize));                                \
 }                                                                        \
                                                                          \
+static inline void VEC_OP(T,A,safe_splice)                               \
+     (VEC(T,A) **dst_, VEC(T,base) *src_ VEC_CHECK_DECL MEM_STAT_DECL)   \
+{                                                                        \
+  if (src_)                                                              \
+    {                                                                    \
+      VEC_OP (T,A,reserve_exact) (dst_, src_->num                        \
+                                 VEC_CHECK_PASS MEM_STAT_INFO);          \
+                                                                         \
+      VEC_OP (T,base,splice) (VEC_BASE (*dst_), src_                     \
+                             VEC_CHECK_PASS);                            \
+    }                                                                    \
+}                                                                        \
+                                                                         \
 static inline T *VEC_OP (T,A,safe_push)                                          \
      (VEC(T,A) **vec_, T obj_ VEC_CHECK_DECL MEM_STAT_DECL)              \
 {                                                                        \
@@ -878,6 +951,19 @@ static inline int VEC_OP (T,base,space)                                      \
   return vec_ ? vec_->alloc - vec_->num >= (unsigned)alloc_ : !alloc_;   \
 }                                                                        \
                                                                          \
+static inline void VEC_OP(T,base,splice)                                 \
+     (VEC(T,base) *dst_, VEC(T,base) *src_ VEC_CHECK_DECL)               \
+{                                                                        \
+  if (src_)                                                              \
+    {                                                                    \
+      unsigned len_ = src_->num;                                         \
+      VEC_ASSERT (dst_->num + len_ <= dst_->alloc, "splice", T, base);   \
+                                                                         \
+      memcpy (&dst_->vec[dst_->num], &src_->vec[0], len_ * sizeof (T));          \
+      dst_->num += len_;                                                 \
+    }                                                                    \
+}                                                                        \
+                                                                         \
 static inline T *VEC_OP (T,base,quick_push)                              \
      (VEC(T,base) *vec_, const T *obj_ VEC_CHECK_DECL)                   \
 {                                                                        \
@@ -1081,6 +1167,19 @@ static inline void VEC_OP (T,A,safe_grow_cleared)                          \
          sizeof (T) * (size_ - oldsize));                                \
 }                                                                        \
                                                                          \
+static inline void VEC_OP(T,A,safe_splice)                               \
+     (VEC(T,A) **dst_, VEC(T,base) *src_ VEC_CHECK_DECL MEM_STAT_DECL)   \
+{                                                                        \
+  if (src_)                                                              \
+    {                                                                    \
+      VEC_OP (T,A,reserve_exact) (dst_, src_->num                        \
+                                 VEC_CHECK_PASS MEM_STAT_INFO);          \
+                                                                         \
+      VEC_OP (T,base,splice) (VEC_BASE (*dst_), src_                     \
+                             VEC_CHECK_PASS);                            \
+    }                                                                    \
+}                                                                        \
+                                                                         \
 static inline T *VEC_OP (T,A,safe_push)                                          \
      (VEC(T,A) **vec_, const T *obj_ VEC_CHECK_DECL MEM_STAT_DECL)       \
 {                                                                        \
@@ -1185,6 +1284,19 @@ static inline void VEC_OP (T,A,safe_grow_cleared)                          \
          sizeof (T) * (size_ - oldsize));                                \
 }                                                                        \
                                                                          \
+static inline void VEC_OP(T,A,safe_splice)                               \
+     (VEC(T,A) **dst_, VEC(T,base) *src_ VEC_CHECK_DECL MEM_STAT_DECL)   \
+{                                                                        \
+  if (src_)                                                              \
+    {                                                                    \
+      VEC_OP (T,A,reserve_exact) (dst_, src_->num                        \
+                                 VEC_CHECK_PASS MEM_STAT_INFO);          \
+                                                                         \
+      VEC_OP (T,base,splice) (VEC_BASE (*dst_), src_                     \
+                             VEC_CHECK_PASS);                            \
+    }                                                                    \
+}                                                                        \
+                                                                         \
 static inline T *VEC_OP (T,A,safe_push)                                          \
      (VEC(T,A) **vec_, const T obj_ VEC_CHECK_DECL MEM_STAT_DECL)        \
 {                                                                        \