diff options
Diffstat (limited to 'gcc/fortran/array.c')
-rw-r--r-- | gcc/fortran/array.c | 42 |
1 files changed, 40 insertions, 2 deletions
diff --git a/gcc/fortran/array.c b/gcc/fortran/array.c index 4f4f19b..dc660d4 100644 --- a/gcc/fortran/array.c +++ b/gcc/fortran/array.c @@ -1499,9 +1499,45 @@ resolve_array_list (gfc_constructor * p) return t; } +/* Resolve character array constructor. If it is a constant character array and + not specified character length, update character length to the maximum of + its element constructors' length. */ -/* Resolve all of the expressions in an array list. - TODO: String lengths. */ +static void +resolve_character_array_constructor (gfc_expr * expr) +{ + gfc_constructor * p; + int max_length; + + gcc_assert (expr->expr_type == EXPR_ARRAY); + gcc_assert (expr->ts.type == BT_CHARACTER); + + max_length = -1; + + if (expr->ts.cl == NULL || expr->ts.cl->length == NULL) + { + /* Find the maximum length of the elements. Do nothing for variable array + constructor. */ + for (p = expr->value.constructor; p; p = p->next) + if (p->expr->expr_type == EXPR_CONSTANT) + max_length = MAX (p->expr->value.character.length, max_length); + else + return; + + if (max_length != -1) + { + /* Update the character length of the array constructor. */ + if (expr->ts.cl == NULL) + expr->ts.cl = gfc_get_charlen (); + expr->ts.cl->length = gfc_int_expr (max_length); + /* Update the element constructors. */ + for (p = expr->value.constructor; p; p = p->next) + gfc_set_constant_character_len (max_length, p->expr); + } + } +} + +/* Resolve all of the expressions in an array list. */ try gfc_resolve_array_constructor (gfc_expr * expr) @@ -1511,6 +1547,8 @@ gfc_resolve_array_constructor (gfc_expr * expr) t = resolve_array_list (expr->value.constructor); if (t == SUCCESS) t = gfc_check_constructor_type (expr); + if (t == SUCCESS && expr->ts.type == BT_CHARACTER) + resolve_character_array_constructor (expr); return t; } |