__typeof__ is a GNU extension
authorMichael Beck <beck@ipd.info.uni-karlsruhe.de>
Sat, 17 Nov 2007 11:28:53 +0000 (11:28 +0000)
committerMichael Beck <beck@ipd.info.uni-karlsruhe.de>
Sat, 17 Nov 2007 11:28:53 +0000 (11:28 +0000)
[r18437]

adt/array.h
ast2firm.c
parser.c

index 3fc8c86..0c076d0 100644 (file)
  * @return A pointer to the flexible array (can be used as a pointer to the
  *         first element of this array).
  */
-#define CLONE_ARR_F(arr)                       \
+#ifdef __GNUC__
+#define CLONE_ARR_F(type, arr)                 \
   NEW_ARR_F (__typeof__(arr[0]), ARR_LEN ((arr)))
+#else
+#define CLONE_ARR_F(type, arr)                 \
+       NEW_ARR_F (type, ARR_LEN ((arr)))
+#endif
 
 /**
  * Duplicates an array and returns the new flexible one.
  * @return A pointer to the flexible array (can be used as a pointer to the
  *         first element of this array).
  */
-#define DUP_ARR_F(arr)                                                 \
+#ifdef __GNUC__
+#define DUP_ARR_F(type, arr)                                                   \
   memcpy (CLONE_ARR_F (__typeof__(arr[0]), (arr)), (arr), sizeof(__typeof__(arr[0])) * ARR_LEN((arr)))
+#else
+#define DUP_ARR_F(type, arr)                                                   \
+       memcpy (CLONE_ARR_F (type, (arr)), (arr), sizeof(type) * ARR_LEN((arr)))
+#endif
 
 /**
  * Delete a flexible array.
  */
 #define NEW_ARR_D(type, obstack, nelts)                                        \
   (  nelts                                                             \
-   ? (type *)_new_arr_d ((obstack), (nelts), sizeof(type) * (nelts))   \
+   ? (type *)_new_arr_d((obstack), (nelts), sizeof(type) * (nelts))    \
    : (type *)arr_mt_descr.v.elts)
 
 /**
  * @return A pointer to the dynamic array (can be used as a pointer to the
  *         first element of this array).
  */
-#define CLONE_ARR_D(obstack, arr)              \
-  NEW_ARR_D (__typeof__(arr[0]), (obstack), ARR_LEN ((arr)))
+#ifdef __GNUC__
+#define CLONE_ARR_D(type, obstack, arr)                \
+  NEW_ARR_D(__typeof__(arr[0]), (obstack), ARR_LEN((arr)))
+#else
+#define CLONE_ARR_D(type, obstack, arr)                \
+       NEW_ARR_D(type, (obstack), ARR_LEN((arr)))
+#endif
 
 /**
  * Duplicates an array and returns the new dynamic one.
  * @return A pointer to the dynamic array (can be used as a pointer to the
  *         first element of this array).
  */
-#define DUP_ARR_D(obstack, arr)                                                        \
-  memcpy (CLONE_ARR_D (__typeof__(arr[0]), (obstack), (arr)), (arr), sizeof(__typeof__(arr[0])) * ARR_LEN ((arr)))
+#ifdef __GNUC__
+#define DUP_ARR_D(type, obstack, arr)                                                  \
+  memcpy(CLONE_ARR_D(__typeof__(arr[0]), (obstack), (arr)), (arr), sizeof(__typeof__(arr[0])) * ARR_LEN((arr)))
+#else
+#define DUP_ARR_D(type, obstack, arr)                                                  \
+       memcpy(CLONE_ARR_D(type, (obstack), (arr)), (arr), sizeof(type) * ARR_LEN((arr)))
+#endif
 
 /**
  * Create an automatic array which will be deleted at return from function.
  * Creates a new automatic array with the same number of elements as a
  * given one.
  *
+ * @param type     The element type of the 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
  *
  * @return A pointer to the dynamic array (can be used as a pointer to the
  *         first element of this array).
  */
-#define CLONE_ARR_A(var, arr)          \
-  NEW_ARR_A (__typeof__(arr[0]), (var), ARR_LEN ((arr)))
+#ifdef __GNUC__
+#define CLONE_ARR_A(type, var, arr)            \
+  NEW_ARR_A(__typeof__(arr[0]), (var), ARR_LEN((arr)))
+#else
+#define CLONE_ARR_A(type, var, arr)            \
+       NEW_ARR_A(type, (var), ARR_LEN((arr)))
+#endif
 
 /**
  * Duplicates an array and returns a new automatic one.
  * @return A pointer to the dynamic array (can be used as a pointer to the
  *         first element of this array).
  */
-#define DUP_ARR_A(var, arr)                                    \
+#ifdef __GNUC__
+#define DUP_ARR_A(type, var, arr)                                      \
   do { CLONE_ARR_A(__typeof__(arr[0]), (var), (arr));                                  \
-       memcpy ((var), (arr), sizeof (__typeof__(arr[0])) * ARR_LEN ((arr))); } \
+       memcpy((var), (arr), sizeof(__typeof__(arr[0])) * ARR_LEN((arr))); }    \
+  while (0)
+#else
+#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
 
 /**
  * Declare an initialized (zero'ed) array of fixed size.
  * 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(arr, n)                                     \
-  ((arr) = _arr_resize ((arr), (n), sizeof(__typeof__(arr[0]))))
+#ifdef __GNUC__
+#define ARR_RESIZE(type, arr, n)                                       \
+  ((arr) = _arr_resize((arr), (n), sizeof(__typeof__(arr[0]))))
+#else
+#define ARR_RESIZE(type, arr, n)                                       \
+       ((arr) = _arr_resize((arr), (n), sizeof(type)))
+#endif
 
 /**
  * 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(arr, n)                                     \
+#ifdef __GNUC__
+#define ARR_SETLEN(type, arr, n)                                       \
   ((arr) = _arr_setlen ((arr), (n), sizeof(__typeof__(arr[0])) * (n)))
+#else
+#define ARR_SETLEN(type, arr, n)                                       \
+  ((arr) = _arr_setlen ((arr), (n), sizeof(type) * (n)))
+#endif
 
 /** Set a length smaller than the current length of the array.  Do not
  *  resize. len must be <= ARR_LEN(arr). */
 /**
  * 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(arr, delta)                 \
-  ARR_RESIZE ((arr), ARR_LEN ((arr)) + (delta))
+#define ARR_EXTEND(type, arr, delta)                   \
+  ARR_RESIZE(type, (arr), ARR_LEN((arr)) + (delta))
 
 /**
  * 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(arr, n)                                               \
-  ((n) >= ARR_LEN ((arr)) ? ARR_RESIZE ((arr), (n)+1) : (arr))
+#define ARR_EXTO(type, arr, n)                                         \
+  ((n) >= ARR_LEN((arr)) ? ARR_RESIZE(type, (arr), (n)+1) : (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(arr, elt)                                     \
-  (ARR_EXTEND ((arr), 1), (arr)[ARR_LEN ((arr))-1] = (elt))
+#define ARR_APP1(type, arr, elt)                                       \
+  (ARR_EXTEND(type, (arr), 1), (arr)[ARR_LEN((arr))-1] = (elt))
 
 
 #ifdef NDEBUG
index a33ce29..a499c02 100644 (file)
@@ -1883,7 +1883,7 @@ static ir_node *get_label_block(declaration_t *label)
        label->declaration_type = DECLARATION_TYPE_LABEL_BLOCK;
        label->v.block          = block;
 
-       ARR_APP1(imature_blocks, block);
+       ARR_APP1(ir_node *, imature_blocks, block);
 
        return block;
 }
index 78bc75a..77a7036 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -443,7 +443,7 @@ static declaration_t *stack_push(stack_entry_t **stack_ptr,
        entry.symbol          = symbol;
        entry.old_declaration = symbol->declaration;
        entry.namespace       = namespace;
-       ARR_APP1(*stack_ptr, entry);
+       ARR_APP1(stack_entry_t, *stack_ptr, entry);
 
        /* replace/add declaration into declaration list of the symbol */
        if(symbol->declaration == NULL) {
@@ -501,7 +501,7 @@ static void stack_pop_to(stack_entry_t **stack_ptr, size_t new_top)
 
                declaration_t *old_declaration = entry->old_declaration;
                symbol_t      *symbol          = entry->symbol;
-               namespace_t    namespace       = entry->namespace;
+               namespace_t    namespace       = (namespace_t)entry->namespace;
 
                /* replace/remove declaration */
                declaration_t *declaration = symbol->declaration;