diff options
author | nathan <nathan@138bc75d-0d04-0410-961f-82ee72b054a4> | 2004-09-08 08:08:56 +0000 |
---|---|---|
committer | nathan <nathan@138bc75d-0d04-0410-961f-82ee72b054a4> | 2004-09-08 08:08:56 +0000 |
commit | 07e8c04c5c9fd05187e0135a6c00b55daea82410 (patch) | |
tree | 82cf8d02cbdec1663fdfa61ae2f02250a8f504bc /gcc/vec.h | |
parent | 611234b4a911bea129f06d829c2077155c3ed5ae (diff) | |
download | linaro-gcc-07e8c04c5c9fd05187e0135a6c00b55daea82410.tar.gz linaro-gcc-07e8c04c5c9fd05187e0135a6c00b55daea82410.tar.bz2 linaro-gcc-07e8c04c5c9fd05187e0135a6c00b55daea82410.zip |
* vec.c (vec_p_reserve, vec_o_reserve): Rename to ...
(vec_gc_p_reserve, vec_gc_o_reserve): ... here. Clone to
(vec_heap_p_reserve, vec_heap_o_reserve): ... here, adjust.
(vec_gc_free, vec_heap_free): New.
* vec.h (DEF_VEC_GC_P, DEF_VEC_MALLOC_P): New.
(DEF_VEC_P): Add allocator argument. Adjust.
(DEF_VEC_GC_O, DEF_VEC_MALLOC_O): New.
(DEF_VEC_O): Add allocator argument. Adjust.
(VEC(free)): New.
* tree.h (tree): Define a GC'd vector.
* lamba-code.c (lambda_loop): Likewise.
* value-prof.h (histogram_value): Likewise.
* cp/cp-tree.h (tree_pair_s): Likewise.
* cp/name-lookup.h (cxx_saved_binding, cp_class_binding): Likewise.
* cp/semantics.c (deferred_access): Likewise.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@87179 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/vec.h')
-rw-r--r-- | gcc/vec.h | 68 |
1 files changed, 53 insertions, 15 deletions
diff --git a/gcc/vec.h b/gcc/vec.h index cbc5f81062a..d6fc8adfcea 100644 --- a/gcc/vec.h +++ b/gcc/vec.h @@ -78,19 +78,25 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA The 'lower_bound' function will determine where to place an item in the array using insert that will maintain sorted order. + Both garbage collected and explicitly managed vector types are + creatable. The allocation mechanism is specified when the type is + defined, and is therefore part of the type. + 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_{O,P}(TYPEDEF) macro, and - variables of vector type are declared using a VEC(TYPEDEF) - macro. The characters O and P indicate whether TYPEDEF is a pointer - (P) or object (O) type. + Vector types are defined using a DEF_VEC_{GC,MALLOC}_{O,P}(TYPEDEF) + macro, and variables of vector type are declared using a + VEC(TYPEDEF) macro. The tags GC and MALLOC specify the allocation + method -- garbage collected or explicit malloc/free calls. The + characters O and P indicate whether TYPEDEF is a pointer (P) or + object (O) type. An example of their use would be, - DEF_VEC_P(tree); // define a vector of tree pointers. This must + DEF_VEC_GC_P(tree); // define a gc'd vector of tree pointers. This must // appear at file scope. struct my_struct { @@ -158,6 +164,13 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA #define VEC_alloc(TDEF,A) (VEC_OP(TDEF,alloc)(A MEM_STAT_INFO)) +/* Free a vector. + void VEC_T_alloc(VEC(T) *&); + + Free a vector and set it to NULL. */ + +#define VEC_free(TDEF,V) (VEC_OP(TDEF,free)(&V)) + /* Use these to determine the required size and initialization of a vector embedded within another structure (as the final member). @@ -317,8 +330,12 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA #if !IN_GENGTYPE /* Reallocate an array of elements with prefix. */ -extern void *vec_p_reserve (void *, int MEM_STAT_DECL); -extern void *vec_o_reserve (void *, int, size_t, size_t MEM_STAT_DECL); +extern void *vec_gc_p_reserve (void *, int MEM_STAT_DECL); +extern void *vec_gc_o_reserve (void *, int, size_t, size_t MEM_STAT_DECL); +extern void vec_gc_free (void *); +extern void *vec_heap_p_reserve (void *, int MEM_STAT_DECL); +extern void *vec_heap_o_reserve (void *, int, size_t, size_t MEM_STAT_DECL); +extern void vec_heap_free (void *); #if ENABLE_CHECKING #define VEC_CHECK_INFO ,__FILE__,__LINE__,__FUNCTION__ @@ -359,10 +376,13 @@ typedef struct VEC (TDEF) GTY(()) \ /* Vector of pointer to object. */ #if IN_GENGTYPE -{"DEF_VEC_P", VEC_STRINGIFY (VEC_TDEF (#)) ";", NULL}, +{"DEF_VEC_GC_P", VEC_STRINGIFY (VEC_TDEF (#)) ";", NULL}, +{"DEF_VEC_MALLOC_P", "", NULL}, #else +#define DEF_VEC_GC_P(TDEF) DEF_VEC_P(TDEF,gc) +#define DEF_VEC_MALLOC_P(TDEF) DEF_VEC_P(TDEF,heap) -#define DEF_VEC_P(TDEF) \ +#define DEF_VEC_P(TDEF,a) \ VEC_TDEF (TDEF); \ \ static inline unsigned VEC_OP (TDEF,length) \ @@ -405,7 +425,14 @@ static inline int VEC_OP (TDEF,iterate) \ static inline VEC (TDEF) *VEC_OP (TDEF,alloc) \ (int alloc_ MEM_STAT_DECL) \ { \ - return (VEC (TDEF) *) vec_p_reserve (NULL, alloc_ - !alloc_ PASS_MEM_STAT);\ + return (VEC (TDEF) *) vec_##a##_p_reserve (NULL, alloc_ - !alloc_ PASS_MEM_STAT);\ +} \ + \ +static inline void VEC_OP (TDEF,free) \ + (VEC (TDEF) **vec_) \ +{ \ + vec_##a##_free (*vec_); \ + *vec_ = NULL; \ } \ \ static inline size_t VEC_OP (TDEF,embedded_size) \ @@ -434,7 +461,7 @@ static inline int VEC_OP (TDEF,reserve) \ int extend = VEC_OP (TDEF,space) (*vec_, alloc_); \ \ if (extend) \ - *vec_ = (VEC (TDEF) *) vec_p_reserve (*vec_, alloc_ PASS_MEM_STAT); \ + *vec_ = (VEC (TDEF) *) vec_##a##_p_reserve (*vec_, alloc_ PASS_MEM_STAT); \ \ return extend; \ } \ @@ -577,10 +604,14 @@ struct vec_swallow_trailing_semi /* Vector of object. */ #if IN_GENGTYPE -{"DEF_VEC_O", VEC_STRINGIFY (VEC_TDEF (#)) ";", NULL}, +{"DEF_VEC_GC_O", VEC_STRINGIFY (VEC_TDEF (#)) ";", NULL}, +{"DEF_VEC_MALLOC_O", "", NULL}, #else -#define DEF_VEC_O(TDEF) \ +#define DEF_VEC_GC_O(TDEF) DEF_VEC_O(TDEF,gc) +#define DEF_VEC_MALLOC_O(TDEF) DEF_VEC_O(TDEF,heap) + +#define DEF_VEC_O(TDEF,a) \ VEC_TDEF (TDEF); \ \ static inline unsigned VEC_OP (TDEF,length) \ @@ -623,11 +654,18 @@ static inline int VEC_OP (TDEF,iterate) \ static inline VEC (TDEF) *VEC_OP (TDEF,alloc) \ (int alloc_ MEM_STAT_DECL) \ { \ - return (VEC (TDEF) *) vec_o_reserve (NULL, alloc_ - !alloc_, \ + return (VEC (TDEF) *) vec_##a##_o_reserve (NULL, alloc_ - !alloc_, \ offsetof (VEC(TDEF),vec), sizeof (TDEF)\ PASS_MEM_STAT); \ } \ \ +static inline void VEC_OP (TDEF,free) \ + (VEC (TDEF) **vec_) \ +{ \ + vec_##a##_free (*vec_); \ + *vec_ = NULL; \ +} \ + \ static inline size_t VEC_OP (TDEF,embedded_size) \ (int alloc_) \ { \ @@ -654,7 +692,7 @@ static inline int VEC_OP (TDEF,reserve) \ int extend = VEC_OP (TDEF,space) (*vec_, alloc_); \ \ if (extend) \ - *vec_ = (VEC (TDEF) *) vec_o_reserve (*vec_, alloc_, \ + *vec_ = (VEC (TDEF) *) vec_##a##_o_reserve (*vec_, alloc_, \ offsetof (VEC(TDEF),vec), sizeof (TDEF) \ PASS_MEM_STAT); \ \ |