From ab2620a4aef90ff7cf9419abf0a0612339864579 Mon Sep 17 00:00:00 2001 From: Michael Beck Date: Mon, 28 Jun 2004 15:33:22 +0000 Subject: [PATCH] Added doxygen comments. [r3223] --- ir/adt/array.c | 62 +++++++++++++- ir/adt/array.h | 213 +++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 256 insertions(+), 19 deletions(-) diff --git a/ir/adt/array.c b/ir/adt/array.c index b73eac2ca..c082aba7d 100644 --- a/ir/adt/array.c +++ b/ir/adt/array.c @@ -32,12 +32,27 @@ # define MIN(a,b) ((a) > (b) ? (b) : (a)) #endif +/** + * An empty dynamic array + */ _arr_descr arr_mt_descr #ifndef NDEBUG = { ARR_D_MAGIC } #endif ; +/** + * Creates a dynamic array on a obstack. + * + * @param obstack An struct obstack * were the data will be allocated + * @param nelts The number of elements + * @param elts_size The size of the array elements. + * + * @return A pointer to the dynamic array (can be used as a pointer to the + * first element of this array). + * + * @remark Helper function, use NEW_ARR_D() instead. + */ void * _new_arr_d (struct obstack *obstack, int nelts, size_t elts_size) { @@ -52,7 +67,17 @@ _new_arr_d (struct obstack *obstack, int nelts, size_t elts_size) return new->v.elts; } - +/** + * Creates a flexible array. + * + * @param nelts The number of elements + * @param elts_size The size of the array elements. + * + * @return A pointer to the flexible array (can be used as a pointer to the + * first element of this array). + * + * @remark Helper function, use NEW_ARR_F() instead. + */ void * _new_arr_f (int nelts, size_t elts_size) { @@ -65,7 +90,13 @@ _new_arr_f (int nelts, size_t elts_size) return new->v.elts; } - +/** + * Delete a flexible array. + * + * @param elts The flexible array (pointer to the first element). + * + * @remark Helper function, use DEL_ARR_F() instead. + */ void _del_arr_f (void *elts) { @@ -80,7 +111,18 @@ _del_arr_f (void *elts) free (dp); } - +/** + * Resize a flexible array, always reallocate data. + * + * @param elts The flexible array (pointer to the first element). + * @param nelts The new number of elements. + * @param elts_size The size of the array elements. + * + * @return A resized flexible array, possibly other address than + * elts. + * + * @remark Helper function, use ARR_SETLEN() instead. + */ void * _arr_setlen (void *elts, int nelts, size_t elts_size) { @@ -96,7 +138,19 @@ _arr_setlen (void *elts, int nelts, size_t elts_size) return dp->v.elts; } -\ +/** + * Resize a flexible array, allocate more data if needed but do NOT + * reduce. + * + * @param elts The flexible array (pointer to the first element). + * @param nelts The new number of elements. + * @param elts_size The size of the array elements. + * + * @return A resized flexible array, possibly other address than + * elts. + * + * @remark Helper function, use ARR_RESIZE() instead. + */ void * _arr_resize (void *elts, int nelts, size_t eltsize) { diff --git a/ir/adt/array.h b/ir/adt/array.h index 43dd9eb07..9c4d2a6bf 100644 --- a/ir/adt/array.h +++ b/ir/adt/array.h @@ -10,7 +10,9 @@ * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE. */ -/* @@@ growing a dynamic on an obstack */ +/** + * @file array.h Dynamic and flexible arrays for C. + */ #ifndef _ARRAY_H #define _ARRAY_H @@ -23,27 +25,121 @@ #include "xmalloc.h" -/* Flexible create / delete */ +/** + * Creates a flexible array. + * + * @param type The element type of the new array. + * @param nelts a size_t expression evaluating to the number of elements + * + * This macro creates a flexible array of a given type at runtime. + * The size of the array can be changed later. + * + * @return A pointer to the flexible array (can be used as a pointer to the + * first element of this array). + */ #define NEW_ARR_F(type, nelts) \ (XMALLOC_TRACE (type *)_new_arr_f ((nelts), sizeof(type) * (nelts))) + +/** + * Creates a new flxible array with the same number of elements as a + * given one. + * + * @param type The element type of the new array. + * @param arr An array from which the number of elements will be taken + * + * This macro creates a flexible array of a given type at runtime. + * The size of the array can be changed later. + * + * @return A pointer to the flexible array (can be used as a pointer to the + * first element of this array). + */ #define CLONE_ARR_F(type, arr) \ NEW_ARR_F (type, ARR_LEN ((arr))) + +/** + * Duplicates an array and returns the new flexible one. + * + * @param type The element type of the new array. + * @param arr An array from which the elements will be duplicated + * + * This macro creates a flexible array of a given type at runtime. + * The size of the array can be changed later. + * + * @return A pointer to the flexible array (can be used as a pointer to the + * first element of this array). + */ #define DUP_ARR_F(type, arr) \ memcpy (CLONE_ARR_F (type, (arr)), (arr), sizeof(type) * ARR_LEN((arr))) + +/** + * Delete a flexible array. + * + * @param arr The flexible array. + */ #define DEL_ARR_F(arr) (XMALLOC_TRACE _del_arr_f ((arr))) -/* Dynamic create on obstacks */ +/** + * Creates a dynamic array on a obstack. + * + * @param type The element type of the new array. + * @param obstack An struct obstack * were the data will be allocated + * @param nelts a size_t expression evaluating to the number of elements + * + * This macro creates a dynamic array of a given type at runtime. + * The size of the array cannot be changed later. + * + * @return A pointer to the dynamic array (can be used as a pointer to the + * first element of this array). + */ #define NEW_ARR_D(type, obstack, nelts) \ ( nelts \ ? (type *)_new_arr_d ((obstack), (nelts), sizeof(type) * (nelts)) \ : (type *)arr_mt_descr.v.elts) + +/** + * Creates a new dynamic array with the same number of elements as a + * given one. + * + * @param type The element type of the new array. + * @param obstack An struct obstack * were the data will be allocated + * @param arr An array from which the number of elements will be taken + * + * This macro creates a dynamic array of a given type at runtime. + * The size of the array cannot be changed later. + * + * @return A pointer to the dynamic array (can be used as a pointer to the + * first element of this array). + */ #define CLONE_ARR_D(type, obstack, arr) \ NEW_ARR_D (type, (obstack), ARR_LEN ((arr))) + +/** + * Duplicates an array and returns the new dynamic one. + * + * @param type The element type of the new array. + * @param obstack An struct obstack * were the data will be allocated + * @param arr An array from which the elements will be duplicated + * + * This macro creates a dynamic array of a given type at runtime. + * The size of the array cannot be changed later. + * + * @return A pointer to the dynamic array (can be used as a pointer to the + * first element of this array). + */ #define DUP_ARR_D(type, obstack, arr) \ memcpy (CLONE_ARR_D (type, (obstack), (arr)), (arr), sizeof(type) * ARR_LEN ((arr))) -/* Automatic create; delete is automatic at return from function */ -/* Quick'n'dirty! */ +/** + * Create an automatic array which will be deleted at return from function. + * Beware, the data will be allocated un the functions stack! + * + * @param type The element type of the new array. + * @param var A lvalue of type (type *) which will hold the new array. + * @param n number of elements in this array. + * + * This macro creates a dynamic array on the functions stack of a given type at runtime. + * The size of the array cannot be changed later. + */ #define NEW_ARR_A(type, var, n) \ do { \ int _nelts = (n); \ @@ -52,39 +148,120 @@ _ARR_SET_DBGINF (_ARR_DESCR ((var)), ARR_A_MAGIC, sizeof (type)); \ (void)(_ARR_DESCR ((var))->nelts = _nelts); \ } while (0) + +/** + * Creates a new automatic array with the same number of elements as a + * given one. + * + * @param type The element type of the new array. + * @param var A lvalue of type (type *) which will hold the new array. + * @param arr An array from which the elements will be duplicated + * + * This macro creates a dynamic array of a given type at runtime. + * The size of the array cannot be changed later. + * + * @return A pointer to the dynamic array (can be used as a pointer to the + * first element of this array). + */ #define CLONE_ARR_A(type, var, arr) \ NEW_ARR_A (type, (var), ARR_LEN ((arr))) +/** + * Duplicates an array and returns a new automatic one. + * + * @param type The element type of the new array. + * @param var A lvalue of type (type *) which will hold the new array. + * @param arr An array from with the number of elements will be taken + * + * This macro creates a dynamic array of a given type at runtime. + * The size of the array cannot be changed later. + * + * @return A pointer to the dynamic array (can be used as a pointer to the + * first element of this array). + */ #define DUP_ARR_A(type, var, arr) \ do { CLONE_ARR_A(type, (var), (arr)); \ memcpy ((var), (arr), sizeof (type) * ARR_LEN ((arr))); } \ while (0) -/* Declare an initialized array of fixed size */ +/** + * Declare an initialized (zero'ed) array of fixed size. + * This macro should be used at file scope only. + * + * @param type The element type of the new array. + * @param var A lvalue of type (type *) which will hold the new array. + * @param _nelts Number of elements in this new array. + */ #define DECL_ARR_S(type, var, _nelts) \ ARR_STRUCT(type, (_nelts) ? (_nelts) : 1) _##var; \ type *var = (_ARR_SET_DBGINF (&_##var, ARR_A_MAGIC, sizeof (type)), \ _##var.nelts = _nelts, \ _##var.v.elts) -/* Length */ +/** + * Returns the length of an array + * + * @param arr a flexible, dynamic, automatic or static array. + */ #define ARR_LEN(arr) (ARR_VRFY ((arr)), _ARR_DESCR((arr))->nelts) -/* Resize - Applicable to flexibles only, change arr which must be an lvalue. */ -/* resize arr to hold n elts */ +/** + * Resize a flexible array, allocate more data if needed but do NOT + * reduce. + * + * @param type The element type of the array. + * @param arr The array, which must be an lvalue. + * @param n The new size of the array. + * + * @remark This macro may change arr, so update all references! + */ #define ARR_RESIZE(type, arr, n) \ (XMALLOC_TRACE (arr) = _arr_resize ((arr), (n), sizeof(type))) -/* resize arr to hold exactly n elts */ + +/** + * Resize a flexible array, always reallocate data. + * + * @param type The element type of the array. + * @param arr The array, which must be an lvalue. + * @param n The new size of the array. + * + * @remark This macro may change arr, so update all references! + */ #define ARR_SETLEN(type, arr, n) \ (XMALLOC_TRACE (arr) = _arr_setlen ((arr), (n), sizeof(type) * (n))) -/* resize arr by delta elts */ + +/** + * Resize a flexible array by growing it by delta elements. + * + * @param type The element type of the array. + * @param arr The array, which must be an lvalue. + * @param delta The delta number of elements. + * + * @remark This macro may change arr, so update all references! + */ #define ARR_EXTEND(type, arr, delta) \ ARR_RESIZE (type, (arr), ARR_LEN ((arr)) + (delta)) -/* resize arr to hold n elts only if it is currently shorter */ + +/** + * Resize a flexible array to hold n elements only if it is currently shorter + * than n. + * + * @param type The element type of the array. + * @param arr The array, which must be an lvalue. + * @param n The new size of the array. + * + * @remark This macro may change arr, so update all references! + */ #define ARR_EXTO(type, arr, n) \ ((n) >= ARR_LEN ((arr)) ? ARR_RESIZE (type, (arr), (n)+1) : (arr)) -/* append one elt to arr */ + +/** + * Append one element to a flexible array. + * + * @param type The element type of the array. + * @param arr The array, which must be an lvalue. + * @param elt The new element, must be of type (type). + */ #define ARR_APP1(type, arr, elt) \ (ARR_EXTEND (type, (arr), 1), (arr)[ARR_LEN ((arr))-1] = (elt)) @@ -117,6 +294,9 @@ ((descr)->cookie = (co), (descr)->eltsize = (es)) #endif +/** + * Construct an array header. + */ #define ARR_STRUCT(type, _nelts) \ struct { \ _ARR_DBGINF_DECL \ @@ -131,13 +311,16 @@ } v; \ } +/** + * The array descriptor header type. + */ typedef ARR_STRUCT (aligned_type, 1) _arr_descr; extern _arr_descr arr_mt_descr; void *_new_arr_f (int, size_t); void _del_arr_f (void *); -void *_new_arr_d (struct obstack *, int, size_t); +void *_new_arr_d (struct obstack *obstack, int nelts, size_t elts_size); void *_arr_resize (void *, int, size_t); void *_arr_setlen (void *, int, size_t); -- 2.20.1