X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fadt%2Farray.c;h=d84007e4282a979e4bce18b0086fe3d015398043;hb=64fe0a138b8ebab4633fb47ed7e8b20d41f41491;hp=7c05ff6721456d37f6f0101831a160520dfe7d3e;hpb=c8a000c8803aa2789a92206d888712b4577cb87a;p=libfirm diff --git a/ir/adt/array.c b/ir/adt/array.c index 7c05ff672..d84007e42 100644 --- a/ir/adt/array.c +++ b/ir/adt/array.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved. + * Copyright (C) 1995-2011 University of Karlsruhe. All right reserved. * * This file is part of libFirm. * @@ -21,7 +21,6 @@ * @file * @brief Array --- dynamic & flexible arrays. * @author Markus Armbruster - * @version $Id$ */ #include "config.h" @@ -47,7 +46,7 @@ /** * An empty dynamic array descriptor. */ -ir_arr_descr arr_mt_descr = { ARR_D_MAGIC, 0, {0}, 0, {{{0}}} }; +ir_arr_descr arr_mt_descr = { ARR_D_MAGIC, 0, { 0 }, 0, { { 0 } } }; void ir_verify_arr(const void *arr) { @@ -55,10 +54,7 @@ void ir_verify_arr(const void *arr) ir_arr_descr *descr = ARR_DESCR(arr); assert(descr->magic == ARR_D_MAGIC || descr->magic == ARR_A_MAGIC || descr->magic == ARR_F_MAGIC); - if (descr->magic == ARR_F_MAGIC) { - assert(descr->u.allocated >= descr->nelts); - } - assert(descr->nelts >= 0); + assert(descr->magic != ARR_F_MAGIC || descr->u.allocated >= descr->nelts); #else (void) arr; #endif @@ -76,17 +72,17 @@ void ir_verify_arr(const void *arr) * * @remark Helper function, use NEW_ARR_D() instead. */ -void *ir_new_arr_d(struct obstack *obstack, int nelts, size_t elts_size) +void *ir_new_arr_d(struct obstack *obstack, size_t nelts, size_t elts_size) { ir_arr_descr *dp; - assert(obstack && (nelts >= 0)); + assert(obstack); - dp = (ir_arr_descr*) obstack_alloc(obstack, ARR_ELTS_OFFS + elts_size); + dp = (ir_arr_descr*)obstack_alloc(obstack, ARR_ELTS_OFFS + elts_size); ARR_SET_DBGINF(dp, ARR_D_MAGIC, elts_size/nelts); dp->u.obstack = obstack; dp->nelts = nelts; - return dp->v.elts; + return dp->elts; } /** @@ -100,15 +96,14 @@ void *ir_new_arr_d(struct obstack *obstack, int nelts, size_t elts_size) * * @remark Helper function, use NEW_ARR_F() instead. */ -void *ir_new_arr_f(int nelts, size_t elts_size) +void *ir_new_arr_f(size_t nelts, size_t elts_size) { ir_arr_descr *newa; - assert (nelts >= 0); - newa = (ir_arr_descr*) xmalloc (ARR_ELTS_OFFS+elts_size); - ARR_SET_DBGINF (newa, ARR_F_MAGIC, nelts ? elts_size/nelts : 0); + newa = (ir_arr_descr*)xmalloc(ARR_ELTS_OFFS+elts_size); + ARR_SET_DBGINF(newa, ARR_F_MAGIC, nelts ? elts_size/nelts : 0); newa->u.allocated = newa->nelts = nelts; - return newa->v.elts; + return newa->elts; } /** @@ -122,8 +117,8 @@ void ir_del_arr_f(void *elts) { ir_arr_descr *dp = ARR_DESCR (elts); - ARR_VRFY (elts); - assert (dp->magic == ARR_F_MAGIC); + ARR_VRFY(elts); + assert(dp->magic == ARR_F_MAGIC); #ifndef NDEBUG dp->magic = 0xdeadbeef; @@ -143,18 +138,18 @@ void ir_del_arr_f(void *elts) * * @remark Helper function, use ARR_SETLEN() instead. */ -void *ir_arr_setlen (void *elts, int nelts, size_t elts_size) +void *ir_arr_setlen (void *elts, size_t nelts, size_t elts_size) { ir_arr_descr *dp = ARR_DESCR (elts); - assert ((dp->magic == ARR_F_MAGIC) && (nelts >= 0)); - ARR_VRFY (elts); - assert (!dp->eltsize || !nelts || (dp->eltsize == elts_size/nelts)); + assert(dp->magic == ARR_F_MAGIC); + ARR_VRFY(elts); + assert(!dp->eltsize || !nelts || (dp->eltsize == elts_size/nelts)); - dp = (ir_arr_descr*) xrealloc (dp, ARR_ELTS_OFFS+elts_size); + dp = (ir_arr_descr*) xrealloc(dp, ARR_ELTS_OFFS+elts_size); dp->u.allocated = dp->nelts = nelts; - return dp->v.elts; + return dp->elts; } /** @@ -170,12 +165,12 @@ void *ir_arr_setlen (void *elts, int nelts, size_t elts_size) * * @remark Helper function, use ARR_RESIZE() instead. */ -void *ir_arr_resize(void *elts, int nelts, size_t eltsize) +void *ir_arr_resize(void *elts, size_t nelts, size_t eltsize) { ir_arr_descr *dp = ARR_DESCR(elts); - int n; + size_t n; - assert((dp->magic == ARR_F_MAGIC) && (nelts >= 0)); + assert(dp->magic == ARR_F_MAGIC); ARR_VRFY(elts); assert(dp->eltsize ? dp->eltsize == eltsize : (dp->eltsize = eltsize, 1)); @@ -191,17 +186,20 @@ void *ir_arr_resize(void *elts, int nelts, size_t eltsize) } dp->nelts = nelts; - return dp->v.elts; + return dp->elts; } #ifdef DEBUG_libfirm +/* forward declarations to avoid warnings */ +size_t array_len(const void *arr); +ir_arr_descr *array_descr(const void *arr); + /** * This function returns the length of a flexible array. * Do NOT use is in code, use ARR_LEN() macro! * This function is intended to be called from a debugger. */ -int array_len(const void *arr); -int array_len(const void *arr) +size_t array_len(const void *arr) { return ARR_LEN(arr); } @@ -211,7 +209,6 @@ int array_len(const void *arr) * Do NOT use is in code!. * This function is intended to be called from a debugger. */ -ir_arr_descr *array_descr(const void *arr); ir_arr_descr *array_descr(const void *arr) { if (! arr)