string literals really have array type, revert_automatic_type_conversion should respe...
authorMatthias Braun <matze@braunis.de>
Sat, 16 Feb 2008 16:04:34 +0000 (16:04 +0000)
committerMatthias Braun <matze@braunis.de>
Sat, 16 Feb 2008 16:04:34 +0000 (16:04 +0000)
[r18880]

parser.c
type.c
type_t.h

index 306de11..6715131 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -3464,6 +3464,9 @@ static expression_t *parse_string_const(void)
                }
                if (token.type != T_WIDE_STRING_LITERAL) {
                        expression_t *const cnst = allocate_expression_zero(EXPR_STRING_LITERAL);
+                       /* note: that we use type_char_ptr here, which is already the
+                        * automatic converted type. revert_automatic_type_conversion
+                        * will construct the array type */
                        cnst->base.type    = type_char_ptr;
                        cnst->string.value = res;
                        return cnst;
@@ -3684,6 +3687,16 @@ type_t *revert_automatic_type_conversion(const expression_t *expression)
                        return type_left->pointer.points_to;
                }
 
+               case EXPR_STRING_LITERAL: {
+                       size_t size = expression->string.value.size;
+                       return make_array_type(type_char, size, TYPE_QUALIFIER_NONE);
+               }
+
+               case EXPR_WIDE_STRING_LITERAL: {
+                       size_t size = expression->wide_string.value.size;
+                       return make_array_type(type_wchar_t, size, TYPE_QUALIFIER_NONE);
+               }
+
                case EXPR_COMPOUND_LITERAL:
                        return expression->compound_literal.type;
 
diff --git a/type.c b/type.c
index 4cf3d74..efe7d0e 100644 (file)
--- a/type.c
+++ b/type.c
@@ -957,6 +957,21 @@ type_t *make_pointer_type(type_t *points_to, type_qualifiers_t qualifiers)
        return identify_new_type(type);
 }
 
+type_t *make_array_type(type_t *element_type, size_t size,
+                        type_qualifiers_t qualifiers)
+{
+       type_t *type = obstack_alloc(type_obst, sizeof(array_type_t));
+       memset(type, 0, sizeof(array_type_t));
+
+       type->kind                = TYPE_ARRAY;
+       type->base.qualifiers     = qualifiers;
+       type->array.element_type  = element_type;
+       type->array.size          = size;
+       type->array.size_constant = true;
+
+       return identify_new_type(type);
+}
+
 /**
  * Debug helper. Prints the given type to stdout.
  */
index e72dd38..a32cbec 100644 (file)
--- a/type_t.h
+++ b/type_t.h
@@ -170,6 +170,8 @@ union type_t {
 
 type_t *make_atomic_type(atomic_type_kind_t type, type_qualifiers_t qualifiers);
 type_t *make_pointer_type(type_t *points_to, type_qualifiers_t qualifiers);
+type_t *make_array_type(type_t *element_type, size_t size,
+                        type_qualifiers_t qualifiers);
 
 type_t *duplicate_type(const type_t *type);