/*
- * Copyright (C) 1995-2008 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 Array --- dynamic & flexible arrays.
- * @version $Id: array.c 17964 2008-03-05 09:48:51Z matze $
*/
#ifndef FIRM_ADT_ARRAY_T_H
#define FIRM_ADT_ARRAY_T_H
#include "array.h"
+#include "fourcc.h"
-#define ARR_D_MAGIC FOURCC('A','R','R','D')
-#define ARR_A_MAGIC FOURCC('A','R','R','A')
-#define ARR_F_MAGIC FOURCC('A','R','R','F')
+#define ARR_D_MAGIC FOURCC('A','R','R','D')
+#define ARR_A_MAGIC FOURCC('A','R','R','A')
+#define ARR_F_MAGIC FOURCC('A','R','R','F')
#ifdef NDEBUG
-# define ARR_SET_DBGINF(descr, co, es)
+# define ARR_SET_DBGINF(descr, co)
#else
-# define ARR_SET_DBGINF(descr, co, es) \
- ( (descr)->magic = (co), (descr)->eltsize = (es) )
+# define ARR_SET_DBGINF(descr, co) \
+ ((descr)->magic = (co))
#endif
/**
* 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); \
- assert(nelts >= 0); \
- (var) = (type *)((ir_arr_descr *)alloca(ARR_ELTS_OFFS + sizeof(type) * nelts))->v.elts; \
- ARR_SET_DBGINF(ARR_DESCR ((var)), ARR_A_MAGIC, sizeof (type)); \
- (void)(ARR_DESCR((var))->nelts = nelts); \
+#define NEW_ARR_A(type, var, n) \
+ do { \
+ size_t nelts = (n); \
+ (var) = (type *)((ir_arr_descr *)alloca(ARR_ELTS_OFFS + sizeof(type) * nelts))->elts; \
+ ARR_SET_DBGINF(ARR_DESCR ((var)), ARR_A_MAGIC); \
+ (void)(ARR_DESCR((var))->nelts = nelts); \
} while (0)
/**
* @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) \
+#define CLONE_ARR_A(type, var, arr) \
NEW_ARR_A(type, (var), ARR_LEN((arr)))
/**
* @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))); } \
+#define DUP_ARR_A(type, var, arr) \
+ do { CLONE_ARR_A(type, (var), (arr)); \
+ memcpy((var), (arr), sizeof (type) * ARR_LEN((arr))); } \
while (0)
#endif