In C++ (most) character literals are of type char.
[cparser] / ast2firm.c
index 40ad71d..c0a0d98 100644 (file)
@@ -22,6 +22,7 @@
 #include <assert.h>
 #include <string.h>
 #include <stdbool.h>
+#include <limits.h>
 
 #include <libfirm/firm.h>
 #include <libfirm/adt/obst.h>
@@ -319,11 +320,10 @@ static unsigned count_parameters(const function_type_t *function_type)
  */
 static ir_type *create_atomic_type(const atomic_type_t *type)
 {
-       dbg_info           *dbgi      = get_dbg_info(&type->base.source_position);
-       atomic_type_kind_t  kind      = type->akind;
-       ir_mode            *mode      = _atomic_modes[kind];
-       ident              *id        = get_mode_ident(mode);
-       ir_type            *irtype    = new_d_type_primitive(id, mode, dbgi);
+       atomic_type_kind_t  kind   = type->akind;
+       ir_mode            *mode   = _atomic_modes[kind];
+       ident              *id     = get_mode_ident(mode);
+       ir_type            *irtype = new_type_primitive(id, mode);
 
        set_type_alignment_bytes(irtype, type->base.alignment);
 
@@ -335,13 +335,11 @@ static ir_type *create_atomic_type(const atomic_type_t *type)
  */
 static ir_type *create_complex_type(const complex_type_t *type)
 {
-       dbg_info           *dbgi      = get_dbg_info(&type->base.source_position);
-       atomic_type_kind_t  kind      = type->akind;
-       ir_mode            *mode      = _atomic_modes[kind];
-       ident              *id        = get_mode_ident(mode);
+       atomic_type_kind_t  kind = type->akind;
+       ir_mode            *mode = _atomic_modes[kind];
+       ident              *id   = get_mode_ident(mode);
 
        (void) id;
-       (void) dbgi;
 
        /* FIXME: finish the array */
        return NULL;
@@ -352,11 +350,10 @@ static ir_type *create_complex_type(const complex_type_t *type)
  */
 static ir_type *create_imaginary_type(const imaginary_type_t *type)
 {
-       dbg_info           *dbgi      = get_dbg_info(&type->base.source_position);
        atomic_type_kind_t  kind      = type->akind;
        ir_mode            *mode      = _atomic_modes[kind];
        ident              *id        = get_mode_ident(mode);
-       ir_type            *irtype    = new_d_type_primitive(id, mode, dbgi);
+       ir_type            *irtype    = new_type_primitive(id, mode);
 
        set_type_alignment_bytes(irtype, type->base.alignment);
 
@@ -385,8 +382,7 @@ static ir_type *create_method_type(const function_type_t *function_type)
        ident   *id           = id_unique("functiontype.%u");
        int      n_parameters = count_parameters(function_type);
        int      n_results    = return_type == type_void ? 0 : 1;
-       dbg_info *dbgi        = get_dbg_info(&function_type->base.source_position);
-       ir_type *irtype       = new_d_type_method(id, n_parameters, n_results, dbgi);
+       ir_type *irtype       = new_type_method(id, n_parameters, n_results);
 
        if (return_type != type_void) {
                ir_type *restype = get_ir_type(return_type);
@@ -431,7 +427,6 @@ is_cdecl:
 
        case CC_THISCALL:
                /* Hmm, leave default, not accepted by the parser yet. */
-               warningf(&function_type->base.source_position, "THISCALL calling convention not supported yet");
                break;
        }
        return irtype;
@@ -441,9 +436,8 @@ static ir_type *create_pointer_type(pointer_type_t *type)
 {
        type_t   *points_to    = type->points_to;
        ir_type  *ir_points_to = get_ir_type_incomplete(points_to);
-       dbg_info *dbgi         = get_dbg_info(&type->base.source_position);
-       ir_type  *ir_type      = new_d_type_pointer(id_unique("pointer.%u"),
-                                                   ir_points_to, mode_P_data, dbgi);
+       ir_type  *ir_type      = new_type_pointer(id_unique("pointer.%u"),
+                                                 ir_points_to, mode_P_data);
 
        return ir_type;
 }
@@ -454,8 +448,7 @@ static ir_type *create_array_type(array_type_t *type)
        ir_type *ir_element_type = get_ir_type(element_type);
 
        ident    *id      = id_unique("array.%u");
-       dbg_info *dbgi    = get_dbg_info(&type->base.source_position);
-       ir_type  *ir_type = new_d_type_array(id, 1, ir_element_type, dbgi);
+       ir_type  *ir_type = new_type_array(id, 1, ir_element_type);
 
        const int align = get_type_alignment_bytes(ir_element_type);
        set_type_alignment_bytes(ir_type, align);
@@ -608,7 +601,7 @@ static ir_type *create_compound_type(compound_type_t *type, ir_type *irtype,
                                id = id_unique("__anonymous_struct.%u");
                        }
                }
-               dbg_info *dbgi  = get_dbg_info(&type->base.source_position);
+               dbg_info *dbgi = get_dbg_info(&declaration->source_position);
 
                if (is_union) {
                        irtype = new_d_type_union(id, dbgi);
@@ -4576,18 +4569,17 @@ static void switch_statement_to_firm(switch_statement_t *statement)
                        continue;
                }
                if (l->last_case >= l->first_case)
-                       num_cases += l->last_case - l->first_case;
+                       num_cases += l->last_case - l->first_case + 1;
                if (l->last_case > def_nr)
                        def_nr = l->last_case;
        }
 
-       if (def_nr + 1 < 0) {
-               /* Bad: an overflow occurred, we cannot be sure that the
-        * maximum + 1 is a free number. Scan the values a second
-        * time to find a free number.
-        */
+       if (def_nr == INT_MAX) {
+               /* Bad: an overflow will occurr, we cannot be sure that the
+                * maximum + 1 is a free number. Scan the values a second
+                * time to find a free number.
+                */
                unsigned char *bits = xmalloc((num_cases + 7) >> 3);
-               unsigned long i;
 
                memset(bits, 0, (num_cases + 7) >> 3);
                for (case_label_statement_t *l = statement->first_case; l != NULL; l = l->next) {
@@ -4595,9 +4587,13 @@ static void switch_statement_to_firm(switch_statement_t *statement)
                                /* default case */
                                continue;
                        }
-                       for (long cns = l->first_case; cns <= l->last_case; ++cns) {
-                               if (cns >= 0 && (unsigned long)cns < num_cases)
+                       unsigned long start = l->first_case > 0 ? (unsigned long)l->first_case : 0;
+                       if (start < num_cases && l->last_case >= 0) {
+                               unsigned long end  = (unsigned long)l->last_case < num_cases ?
+                                       (unsigned long)l->last_case : num_cases - 1;
+                               for (unsigned long cns = start; cns <= end; ++cns) {
                                        bits[cns >> 3] |= (1 << (cns & 7));
+                               }
                        }
                }
                /* We look at the first num_cases constants:
@@ -4605,8 +4601,9 @@ static void switch_statement_to_firm(switch_statement_t *statement)
                 * one, or they are non densed, so we will find one free
                 * there...
                 */
+               unsigned long i;
                for (i = 0; i < num_cases; ++i)
-                       if ((bits[i >> 3] & (i & 7)) == 0)
+                       if ((bits[i >> 3] & (1 << (i & 7))) == 0)
                                break;
 
                free(bits);