use bool flag instead of UNARY_CAST_IMPLICIT
authorMatthias Braun <matze@braunis.de>
Thu, 28 Jul 2011 12:08:13 +0000 (14:08 +0200)
committerMatthias Braun <matze@braunis.de>
Thu, 28 Jul 2011 12:08:24 +0000 (14:08 +0200)
this also fixes constexpr6.c

ast.c
ast2firm.c
ast_t.h
format_check.c
parser.c
type.c
wrappergen/write_jna.c

diff --git a/ast.c b/ast.c
index b8f2b87..4394732 100644 (file)
--- a/ast.c
+++ b/ast.c
@@ -149,7 +149,6 @@ static unsigned get_expression_precedence(expression_kind_t kind)
                [EXPR_UNARY_PREFIX_INCREMENT]            = PREC_UNARY,
                [EXPR_UNARY_PREFIX_DECREMENT]            = PREC_UNARY,
                [EXPR_UNARY_CAST]                        = PREC_UNARY,
-               [EXPR_UNARY_CAST_IMPLICIT]               = PREC_UNARY,
                [EXPR_UNARY_ASSUME]                      = PREC_PRIMARY,
                [EXPR_UNARY_DELETE]                      = PREC_UNARY,
                [EXPR_UNARY_DELETE_ARRAY]                = PREC_UNARY,
@@ -413,7 +412,6 @@ static void print_unary_expression(const unary_expression_t *unexpr)
                print_expression_prec(unexpr->value, prec);
                print_string("--");
                return;
-       case EXPR_UNARY_CAST_IMPLICIT:
        case EXPR_UNARY_CAST:
                print_string("(");
                print_type(unexpr->base.type);
@@ -672,7 +670,8 @@ static void print_statement_expression(const statement_expression_t *expression)
  */
 static void print_expression_prec(const expression_t *expression, unsigned top_prec)
 {
-       if (expression->kind == EXPR_UNARY_CAST_IMPLICIT && !print_implicit_casts) {
+       if (expression->kind == EXPR_UNARY_CAST
+           && expression->base.implicit && !print_implicit_casts) {
                expression = expression->unary.value;
        }
 
@@ -1894,8 +1893,7 @@ expression_classification_t is_constant_expression(const expression_t *expressio
        case EXPR_UNARY_NOT:
                return is_constant_expression(expression->unary.value);
 
-       case EXPR_UNARY_CAST:
-       case EXPR_UNARY_CAST_IMPLICIT: {
+       case EXPR_UNARY_CAST: {
                type_t *const type = skip_typeref(expression->base.type);
                if (is_type_scalar(type))
                        return is_constant_expression(expression->unary.value);
index 559b1c2..5e71177 100644 (file)
@@ -2593,7 +2593,6 @@ static ir_node *unary_expression_to_firm(const unary_expression_t *expression)
        case EXPR_UNARY_PREFIX_INCREMENT:
        case EXPR_UNARY_PREFIX_DECREMENT:
                return create_incdec(expression);
-       case EXPR_UNARY_CAST_IMPLICIT:
        case EXPR_UNARY_CAST: {
                ir_node *value_node = expression_to_firm(value);
                type_t  *from_type  = value->base.type;
@@ -4034,7 +4033,7 @@ static ir_initializer_t *create_ir_initializer_value(
                type_t *skipped = skip_typeref(type);
                if (skipped->kind == TYPE_BITFIELD) {
                        /* remove the bitfield cast... */
-                       assert(expr->kind == EXPR_UNARY_CAST_IMPLICIT);
+                       assert(expr->kind == EXPR_UNARY_CAST && expr->base.implicit);
                        expr = expr->unary.value;
                        type = skipped->bitfield.base_type;
                }
diff --git a/ast_t.h b/ast_t.h
index e05e633..92caf95 100644 (file)
--- a/ast_t.h
+++ b/ast_t.h
@@ -108,7 +108,6 @@ typedef enum expression_kind_t {
        EXPR_UNARY_PREFIX_INCREMENT,
        EXPR_UNARY_PREFIX_DECREMENT,
        EXPR_UNARY_CAST,
-       EXPR_UNARY_CAST_IMPLICIT, /**< compiler generated cast */
        EXPR_UNARY_ASSUME,        /**< MS __assume() */
        EXPR_UNARY_DELETE,
        EXPR_UNARY_DELETE_ARRAY,
@@ -217,7 +216,6 @@ typedef enum funcname_kind_t {
        case EXPR_UNARY_PREFIX_INCREMENT:      \
        case EXPR_UNARY_PREFIX_DECREMENT:      \
        case EXPR_UNARY_CAST:                  \
-       case EXPR_UNARY_CAST_IMPLICIT:         \
        case EXPR_UNARY_ASSUME:                \
        case EXPR_UNARY_DELETE:                \
        case EXPR_UNARY_DELETE_ARRAY:
@@ -254,6 +252,11 @@ struct expression_base_t {
 #ifndef NDEBUG
        bool                transformed : 1;     /**< Set if this expression was transformed. */
 #endif
+       bool                implicit : 1;    /**< compiler generated expression.
+                                                 Examples:
+                                                    select into anonymous structs
+                                                    implicit casts
+                                             */
 };
 
 /**
@@ -332,8 +335,6 @@ struct select_expression_t {
        expression_base_t  base;
        expression_t      *compound;
        entity_t          *compound_entry;
-       bool               implicit : 1; /**< compiler generated select
-                                             (for anonymous struct/union) */
 };
 
 struct array_access_expression_t {
index f1134e2..6fec9b7 100644 (file)
@@ -108,7 +108,7 @@ static int internal_check_printf_format(const expression_t *fmt_expr,
                                         const call_argument_t *arg,
                                         const format_spec_t *spec)
 {
-       while (fmt_expr->kind == EXPR_UNARY_CAST_IMPLICIT) {
+       while (fmt_expr->kind == EXPR_UNARY_CAST) {
                fmt_expr = fmt_expr->unary.value;
        }
 
@@ -521,7 +521,7 @@ too_few_args:
                                }
                        } else if (get_unqualified_type(arg_skip) == expected_type_skip) {
                                goto next_arg;
-                       } else if (arg->expression->kind == EXPR_UNARY_CAST_IMPLICIT) {
+                       } else if (arg->expression->kind == EXPR_UNARY_CAST) {
                                expression_t const *const expr        = arg->expression->unary.value;
                                type_t             *const unprom_type = skip_typeref(expr->base.type);
                                if (get_unqualified_type(unprom_type) == expected_type_skip) {
@@ -595,7 +595,7 @@ static void check_scanf_format(const call_argument_t *arg,
        }
 
        const expression_t *fmt_expr = arg->expression;
-       if (fmt_expr->kind == EXPR_UNARY_CAST_IMPLICIT) {
+       if (fmt_expr->kind == EXPR_UNARY_CAST) {
                fmt_expr = fmt_expr->unary.value;
        }
 
index 5ed7914..5f9f11f 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -887,23 +887,6 @@ static type_t *promote_integer(type_t *type)
        return type;
 }
 
-/**
- * Create a cast expression.
- *
- * @param expression  the expression to cast
- * @param dest_type   the destination type
- */
-static expression_t *create_cast_expression(expression_t *expression,
-                                            type_t *dest_type)
-{
-       expression_t *cast = allocate_expression_zero(EXPR_UNARY_CAST_IMPLICIT);
-
-       cast->unary.value = expression;
-       cast->base.type   = dest_type;
-
-       return cast;
-}
-
 /**
  * Check if a given expression represents a null pointer constant.
  *
@@ -912,8 +895,7 @@ static expression_t *create_cast_expression(expression_t *expression,
 static bool is_null_pointer_constant(const expression_t *expression)
 {
        /* skip void* cast */
-       if (expression->kind == EXPR_UNARY_CAST ||
-                       expression->kind == EXPR_UNARY_CAST_IMPLICIT) {
+       if (expression->kind == EXPR_UNARY_CAST) {
                type_t *const type = skip_typeref(expression->base.type);
                if (types_compatible(type, type_void_ptr))
                        expression = expression->unary.value;
@@ -943,7 +925,12 @@ static expression_t *create_implicit_cast(expression_t *expression,
        if (source_type == dest_type)
                return expression;
 
-       return create_cast_expression(expression, dest_type);
+       expression_t *cast = allocate_expression_zero(EXPR_UNARY_CAST);
+       cast->unary.value   = expression;
+       cast->base.type     = dest_type;
+       cast->base.implicit = true;
+
+       return cast;
 }
 
 typedef enum assign_error_t {
@@ -1506,7 +1493,6 @@ static void mark_vars_read(expression_t *const expr, entity_t *lhs_ent)
                case EXPR_UNARY_POSTFIX_DECREMENT:
                case EXPR_UNARY_PREFIX_INCREMENT:
                case EXPR_UNARY_PREFIX_DECREMENT:
-               case EXPR_UNARY_CAST_IMPLICIT:
                case EXPR_UNARY_ASSUME:
 unary:
                        mark_vars_read(expr->unary.value, lhs_ent);
@@ -5649,7 +5635,7 @@ static expression_t *find_create_select(const source_position_t *pos,
 
                        expression_t *sub_addr = create_select(pos, addr, qualifiers, iter);
                        sub_addr->base.source_position = *pos;
-                       sub_addr->select.implicit      = true;
+                       sub_addr->base.implicit        = true;
                        return find_create_select(pos, sub_addr, qualifiers, sub_compound,
                                                  symbol);
                }
@@ -8610,7 +8596,6 @@ static bool expression_has_effect(const expression_t *const expr)
                        return is_type_atomic(type, ATOMIC_TYPE_VOID);
                }
 
-               case EXPR_UNARY_CAST_IMPLICIT:        return true;
                case EXPR_UNARY_ASSUME:               return true;
                case EXPR_UNARY_DELETE:               return true;
                case EXPR_UNARY_DELETE_ARRAY:         return true;
diff --git a/type.c b/type.c
index 88219a4..df0b759 100644 (file)
--- a/type.c
+++ b/type.c
@@ -574,9 +574,6 @@ void print_enum_definition(const enum_t *enume)
 
                        /* skip the implicit cast */
                        expression_t *expression = entry->enum_value.value;
-                       if (expression->kind == EXPR_UNARY_CAST_IMPLICIT) {
-                               expression = expression->unary.value;
-                       }
                        print_expression(expression);
                }
                print_string(",\n");
index 1f180d2..ad3b9e6 100644 (file)
@@ -272,7 +272,7 @@ static void write_unary_expression(const unary_expression_t *expression)
        case EXPR_UNARY_NOT:
                fputc('!', out);
                break;
-       case EXPR_UNARY_CAST_IMPLICIT:
+       case EXPR_UNARY_CAST:
                write_expression(expression->value);
                return;
        default: