libFirm 1.20
Arrays

Defines

#define NEW_ARR_F(type, nelts)   ((type *)ir_new_arr_f((nelts), sizeof(type) * (nelts)))
 Creates a flexible array.
#define CLONE_ARR_F(type, arr)   NEW_ARR_F(type, ARR_LEN((arr)))
 Creates a new flexible array with the same number of elements as a given one.
#define DUP_ARR_F(type, arr)   ((type*) memcpy(CLONE_ARR_F(type, (arr)), (arr), sizeof(type) * ARR_LEN((arr))))
 Duplicates an array and returns the new flexible one.
#define DEL_ARR_F(arr)   (ir_del_arr_f((void *)(arr)))
 Delete a flexible array.
#define NEW_ARR_D(type, obstack, nelts)
 Creates a dynamic array on an obstack.
#define CLONE_ARR_D(type, obstack, arr)   NEW_ARR_D(type, (obstack), ARR_LEN((arr)))
 Creates a new dynamic array with the same number of elements as a given one.
#define DUP_ARR_D(type, obstack, arr)   ((type*)memcpy(CLONE_ARR_D(type, (obstack), (arr)), (arr), sizeof(type) * ARR_LEN ((arr))))
 Duplicates an array and returns the new dynamic one.
#define ARR_LEN(arr)   (ARR_VRFY((arr)), ARR_DESCR((arr))->nelts)
 Returns the length of an array.
#define ARR_RESIZE(type, arr, n)   ((arr) = (type*) ir_arr_resize((void *)(arr), (n), sizeof(type)))
 Resize a flexible array, allocate more data if needed but do NOT reduce.
#define ARR_SETLEN(type, arr, n)   ((arr) = (type*) ir_arr_setlen((void *)(arr), (n), sizeof(type) * (n)))
 Resize a flexible array, always reallocate data.
#define ARR_EXTEND(type, arr, delta)   ARR_RESIZE(type, (arr), ARR_LEN((arr)) + (delta))
 Resize a flexible array by growing it by delta elements.
#define ARR_EXTO(type, arr, n)
 Resize a flexible array to hold n elements only if it is currently shorter than n.
#define ARR_APP1(type, arr, elt)   (ARR_EXTEND(type, (arr), 1), (arr)[ARR_LEN((arr))-1] = (elt))
 Append one element to a flexible array.
#define ARR_VRFY(arr)   ir_verify_arr(arr)
 Check array for consistency.
#define ARR_IDX_VRFY(arr, idx)   assert((0 <= (idx)) && ((idx) < ARR_LEN((arr))))
 Check if index is within array bounds.

Define Documentation

#define ARR_APP1 (   type,
  arr,
  elt 
)    (ARR_EXTEND(type, (arr), 1), (arr)[ARR_LEN((arr))-1] = (elt))

Append one element to a flexible array.

Parameters:
typeThe element type of the array.
arrThe array, which must be an lvalue.
eltThe new element, must be of type (type).

Definition at line 211 of file array.h.

#define ARR_EXTEND (   type,
  arr,
  delta 
)    ARR_RESIZE(type, (arr), ARR_LEN((arr)) + (delta))

Resize a flexible array by growing it by delta elements.

Parameters:
typeThe element type of the array.
arrThe array, which must be an lvalue.
deltaThe delta number of elements.
Remarks:
This macro may change arr, so update all references!

Definition at line 186 of file array.h.

#define ARR_EXTO (   type,
  arr,
 
)
Value:
do { \
        if ((n) >= ARR_LEN(arr)) { ARR_RESIZE(type, arr, (n)+1); } \
    } while(0)

Resize a flexible array to hold n elements only if it is currently shorter than n.

Parameters:
typeThe element type of the array.
arrThe array, which must be an lvalue.
nThe new size of the array.
Remarks:
This macro may change arr, so update all references!

Definition at line 199 of file array.h.

#define ARR_IDX_VRFY (   arr,
  idx 
)    assert((0 <= (idx)) && ((idx) < ARR_LEN((arr))))

Check if index is within array bounds.

Definition at line 221 of file array.h.

#define ARR_LEN (   arr)    (ARR_VRFY((arr)), ARR_DESCR((arr))->nelts)

Returns the length of an array.

Parameters:
arra flexible, dynamic, automatic or static array.

Definition at line 150 of file array.h.

#define ARR_RESIZE (   type,
  arr,
 
)    ((arr) = (type*) ir_arr_resize((void *)(arr), (n), sizeof(type)))

Resize a flexible array, allocate more data if needed but do NOT reduce.

Parameters:
typeThe element type of the array.
arrThe array, which must be an lvalue.
nThe new size of the array.
Remarks:
This macro may change arr, so update all references!

Definition at line 162 of file array.h.

#define ARR_SETLEN (   type,
  arr,
 
)    ((arr) = (type*) ir_arr_setlen((void *)(arr), (n), sizeof(type) * (n)))

Resize a flexible array, always reallocate data.

Parameters:
typeThe element type of the array.
arrThe array, which must be an lvalue.
nThe new size of the array.
Remarks:
This macro may change arr, so update all references!

Definition at line 174 of file array.h.

#define ARR_VRFY (   arr)    ir_verify_arr(arr)

Check array for consistency.

Definition at line 219 of file array.h.

#define CLONE_ARR_D (   type,
  obstack,
  arr 
)    NEW_ARR_D(type, (obstack), ARR_LEN((arr)))

Creates a new dynamic array with the same number of elements as a given one.

Parameters:
typeThe element type of the new array.
obstackAn struct obstack * were the data will be allocated
arrAn 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.

Returns:
A pointer to the dynamic array (can be used as a pointer to the first element of this array).

Definition at line 126 of file array.h.

#define CLONE_ARR_F (   type,
  arr 
)    NEW_ARR_F(type, ARR_LEN((arr)))

Creates a new flexible array with the same number of elements as a given one.

Parameters:
typeThe element type of the new array.
arrAn 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.

Returns:
A pointer to the flexible array (can be used as a pointer to the first element of this array).

Definition at line 69 of file array.h.

#define DEL_ARR_F (   arr)    (ir_del_arr_f((void *)(arr)))

Delete a flexible array.

Parameters:
arrThe flexible array.

Definition at line 92 of file array.h.

#define DUP_ARR_D (   type,
  obstack,
  arr 
)    ((type*)memcpy(CLONE_ARR_D(type, (obstack), (arr)), (arr), sizeof(type) * ARR_LEN ((arr))))

Duplicates an array and returns the new dynamic one.

Parameters:
typeThe element type of the new array.
obstackAn struct obstack * were the data will be allocated
arrAn 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.

Returns:
A pointer to the dynamic array (can be used as a pointer to the first element of this array).

Definition at line 142 of file array.h.

#define DUP_ARR_F (   type,
  arr 
)    ((type*) memcpy(CLONE_ARR_F(type, (arr)), (arr), sizeof(type) * ARR_LEN((arr))))

Duplicates an array and returns the new flexible one.

Parameters:
typeThe element type of the new array.
arrAn 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.

Returns:
A pointer to the flexible array (can be used as a pointer to the first element of this array).

Definition at line 84 of file array.h.

#define NEW_ARR_D (   type,
  obstack,
  nelts 
)
Value:
(  nelts                                                              \
   ? (type *)ir_new_arr_d((obstack), (nelts), sizeof(type) * (nelts))   \
   : (type *)arr_mt_descr.elts)

Creates a dynamic array on an obstack.

Parameters:
typeThe element type of the new array.
obstackA struct obstack * were the data will be allocated
neltsA 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.

Returns:
A pointer to the dynamic array (can be used as a pointer to the first element of this array).

Definition at line 107 of file array.h.

#define NEW_ARR_F (   type,
  nelts 
)    ((type *)ir_new_arr_f((nelts), sizeof(type) * (nelts)))

Creates a flexible array.

Parameters:
typeThe element type of the new array.
neltsa 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.

Returns:
A pointer to the flexible array (can be used as a pointer to the first element of this array).

Definition at line 53 of file array.h.