/*
- * Copyright (C) 1995-2011 University of Karlsruhe. All right reserved.
- *
* This file is part of libFirm.
- *
- * This file may be distributed and/or modified under the terms of the
- * GNU General Public License version 2 as published by the Free Software
- * Foundation and appearing in the file LICENSE.GPL included in the
- * packaging of this file.
- *
- * Licensees holding valid libFirm Professional Edition licenses may use
- * this file in accordance with the libFirm Commercial License.
- * Agreement provided with the Software.
- *
- * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
- * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE.
+ * Copyright (C) 2012 University of Karlsruhe.
*/
/**
* @file
* @brief Dynamic and flexible arrays for C.
* @author Markus Armbruster, Michael Beck, Matthias Braun, Sebastian Hack
- * @version $Id$
*/
#ifndef FIRM_ADT_ARRAY_H
#define FIRM_ADT_ARRAY_H
#include <stddef.h>
#include "obst.h"
-#include "fourcc.h"
-#include "xmalloc.h"
#include "../begin.h"
+/**
+ * @ingroup adt
+ * @defgroup array Arrays
+ * @{
+ */
+
/**
* Creates a flexible array.
*
#define NEW_ARR_F(type, nelts) \
((type *)ir_new_arr_f((nelts), sizeof(type) * (nelts)))
+/**
+ * Create a flexible array and null its contents.
+ */
+#define NEW_ARR_FZ(type, nelts) \
+ ((type*)memset(NEW_ARR_F(type, (nelts)), 0, sizeof(type) * (nelts)))
+
/**
* Creates a new flexible array with the same number of elements as a
* given one.
? (type *)ir_new_arr_d((obstack), (nelts), sizeof(type) * (nelts)) \
: (type *)arr_mt_descr.elts)
+/**
+ * Create a dynamic array on an obstack and null its contents.
+ */
+#define NEW_ARR_DZ(type, obstack, nelts) \
+ ((type*)memset(NEW_ARR_D(type, (obstack), (nelts)), 0, sizeof(type) * (nelts)))
+
/**
* Creates a new dynamic array with the same number of elements as a
* given one.
* @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))
+ do { \
+ if ((n) >= ARR_LEN(arr)) { ARR_RESIZE(type, arr, (n)+1); } \
+ } while(0)
/**
* Append one element to a flexible array.
# define ARR_VRFY(arr) ((void)0)
# define ARR_IDX_VRFY(arr, idx) ((void)0)
#else
+/** Check array for consistency */
# define ARR_VRFY(arr) ir_verify_arr(arr)
+/** Check if index is within array bounds */
# define ARR_IDX_VRFY(arr, idx) \
assert((0 <= (idx)) && ((idx) < ARR_LEN((arr))))
#endif
+/** @cond PRIVATE */
+
/** A type that has most constrained alignment. */
typedef union {
long double d;
long l;
} aligned_type;
-
/**
* The array descriptor header type.
*/
typedef struct {
int magic; /**< array magic. */
- size_t eltsize; /**< size of array elements. */
- union {
- struct obstack *obstack; /**< for obstack array: the obstack. */
- size_t allocated; /**< number of allocated elements. */
- } u;
+ size_t allocated; /**< number of allocated elements. */
size_t nelts; /**< current length of the array. */
aligned_type elts[1]; /**< start of the array data. */
} ir_arr_descr;
ARR_DESCR(arr)->nelts = new_len;
}
+/** @endcond */
+
+/** @} */
+
#include "../end.h"
#endif