diff options
author | Giovanni Bajo <giovannibajo@libero.it> | 2005-07-20 01:19:59 +0000 |
---|---|---|
committer | Giovanni Bajo <giovannibajo@libero.it> | 2005-07-20 01:19:59 +0000 |
commit | 0991dbb37374a89269389d4918eacc7eefa7cdfd (patch) | |
tree | cee4baf52782472c6ce30e28249d2a5df154551f /gcc/varasm.c | |
parent | 71efb5c37550ef6db31122a65a792c1b5af5ae76 (diff) |
Make CONSTRUCTOR use VEC to store initializers.
* c-common.c (complete_array_type): Update to cope with VEC in
CONSTRUCTOR_ELTS.
* c-pretty-print.c (pp_c_initializer_list): Use pp_c_constructor_elts.
(pp_c_constructor_elts): New function.
* c-pretty-print.h (pp_c_constructor_elts): Declare.
* c-typeck.c (build_function_call, build_c_cast, digest_init,
struct constructor_stack, struct initializer_stack,
constructor_elements, push_init_level, pop_init_level,
add_pending_init, find_init_member, output_init_element): Update to
cope with VEC in CONSTRUCTOR_ELTS.
* coverage.c (build_fn_info_value, build_ctr_info_value,
build_gcov_info): Likewise.
* expr.c (categorize_ctor_elements_1, store_constructor,
expand_expr_real_1): Likewise.
* fold-const.c (fold_ternary): Likewise.
* gimplify.c (gimplify_init_ctor_preeval, zero_sized_field_decl,
gimplify_init_constructor, gimplify_expr): Likewise.
* tree-dump.c (dequeue_and_dump): Likewise.
* tree-inline.c (copy_tree_r): Add code to duplicate a CONSTRUCTOR
node.
* tree-pretty-print.c (dump_generic_node): Update to cope with VEC in
CONSTRUCTOR_ELTS.
* tree-sra.c (generate_element_init_1): Likewise.
* tree-ssa-ccp.c (fold_const_aggregate_ref): Likewise.
* tree-ssa-operands.c (get_expr_operands): Likewise.
* tree-vect-generic.c (expand_vector_piecewise): Likewise.
* tree-vect-transform.c (vect_get_vec_def_for_operand):
(get_initial_def_for_reduction): Likewise.
* tree-vn.c (set_value_handle, get_value_handle): CONSTURCTOR uses
value handle in annotations.
* tree.c (tree_node_kind, tree_code_size, make_node_stat,
tree_node_structure): Add support for constr_kind.
(build_vector_from_ctor, build_constructor_single,
build_constructor_from_list): New functions.
(build_constructor): Update to take a VEC instead of a TREE_LIST.
(simple_cst_equal, iterative_hash_expr, initializer_zerop, walk_tree):
Update to cope with VEC in CONSTRUCTOR_ELTS.
* tree.def (CONSTRUCTOR): Make it a tcc_exceptional node.
* tree.h (FOR_EACH_CONSTRUCTOR_VALUE, FOR_EACH_CONSTRUCTOR_ELT,
CONSTRUCTOR_APPEND_ELT): New macros.
(struct constructor_elt, struct tree_constructor): New data types.
(union tree_node): Add tree_constructor field.
* treestruct.def: Define TS_CONSTRUCTOR.
* varasm.c (const_hash_1, compare_constant, copy_constant,
compute_reloc_for_constant, output_addressed_constants,
initializer_constant_valid_p, output_constant,
array_size_for_constructor, output_constructor): Update to cope with
VEC in CONSTRUCTOR_ELTS.
* vec.h (VEC_empty, VEC_copy): New macros.
ada/
Make CONSTRUCTOR use VEC to store initializers.
* decl.c (gnat_to_gnu_entity): Update to cope with VEC in
CONSTRUCTOR_ELTS.
* trans.c (extract_values): Likewise.
* utils.c (convert, remove_conversions): Likewise.
* utils2.c (contains_save_expr_p, build_binary_op, build_unary_op,
gnat_build_constructor): Likewise.
cp/
Make CONSTRUCTOR use VEC to store initializers.
* call.c (convert_default_arg): Update call to digest_init.
* class.c (dump_class_hierarchy, dump_array): Update to cope with
VEC in CONSTRUCTOR_ELTS.
* cp-tree.h (EMPTY_CONSTRUCTOR_P): Likewise.
(finish_compound_literal, digest_init): Update declaration.
* decl.c (struct reshape_iter): New data type.
(reshape_init_array): Rename to...
(reshape_init_array_1): Update to cope with VEC in CONSTRUCTOR_ELTS.
(reshape_init): Rewrite from scratch. Split parts into...
(reshape_init_array, reshape_init_vector, reshape_init_class,
reshape_init_r): New functions.
(check_initializer): Update call to reshape_init. Remove obsolete
code.
(initialize_artificial_var, cp_complete_array_type): Update to cope
with VEC in CONSTRUCTOR_ELTS.
* decl2.c (grokfield): Update calls to digest_init.
(mark_vtable_entries): Update to cope with VEC in CONSTRUCTOR_ELTS.
* error.c (dump_expr_init_vec): New function.
(dump_expr): Use dump_expr_init_vec.
* init.c (build_zero_init, build_vec_init): Update to cope with VEC
in CONSTRUCTOR_ELTS.
(expand_default_init): Update call to digest_init.
* parser.c (cp_parser_postfix_expression): Use a VEC for the
initializers.
(cp_parser_initializer_list): Build a VEC of initializers.
* pt.c (tsubst_copy, tsubst_copy_and_build): Update to cope with VEC
in CONSTRUCTOR_ELTS.
* rtti.c (tinfo_base_init, generic_initializer, ptr_initializer,
ptm_initializer, class_initializer, get_pseudo_ti_init): Use
build_constructor_from_list instead of build_constructor.
* semantics.c (finish_compound_literal): Update call to digest_init.
* tree.c (stabilize_init): Update to cope with VEC in
CONSTRUCTOR_ELTS.
* typeck.c (build_ptrmemfunc1): Likewise.
* typeck2.c: (cxx_incomplete_type_error, split_nonconstant_init_1):
Likewise.
(store_init_value): Use build_constructor_from_list and update call
to digest_init.
(digest_init): Rewrite.
(process_init_constructor): Rewrite from scratch. Split into...
(process_init_constructor_array, picflag_from_initializer,
process_init_constructor_record, process_init_constructor_union):
New functions.
(PICFLAG_ERRONEOUS, PICFLAG_NOT_ALL_CONSTANT, PICFLAG_NOT_ALL_SIMPLE):
New macros.
(build_functional_cast): Use build_constructor_from_list instead of
build_constructor.
fortran/
Make CONSTRUCTOR use VEC to store initializers.
* trans-array.c (gfc_build_null_descriptor,
gfc_trans_array_constructor_value, gfc_conv_array_initializer):
Update to cope with VEC in CONSTRUCTOR_ELTS.
* trans-common.c (create_common): Likewise.
* trans-expr.c (gfc_conv_structure): Likewise.
* trans-stmt.c (gfc_trans_character_select): Use
build_constructor_from_list instead of build_constructor.
java/
Make CONSTRUCTOR use VEC to store initializers.
* check-init.c (check_init): Update to cope with VEC in
CONSTRUCTOR_ELTS.
* class.c (make_field_value, make_method_value, get_dispatch_table,
make_class_data, emit_symbol_table, emit_catch_table,
emit_assertion_table): Use build_constructor_from_list instead of
build_constructor.
* constants.c (build_constants_constructor): Likewise.
* java-gimplify.c (java_gimplify_new_array_init): Update to cope with
VEC in CONSTRUCTOR_ELTS.
* java-tree.h (START_RECORD_CONSTRUCTOR, PUSH_SUPER_VALUE,
PUSH_FIELD_VALUE, FINISH_RECORD_CONSTRUCTOR): Create a VEC instead
of a TREE_LIST.
* jcf-write.c (generate_bytecode_insns): Update to cope with VEC in
CONSTRUCTOR_ELTS.
* parse.y (build_new_array_init): Use build_constructor_from_list
instead of build_constructor.
(patch_new_array_init): Update to cope with VEC in
CONSTRUCTOR_ELTS.
(array_constructor_check_entry): Likewise.
objc/
Make CONSTRUCTOR use VEC to store initializers.
* objc-act.c (objc_build_constructor): Use build_constructor_from_list
instead of build_constructor.
testsuite/
Make CONSTRUCTOR use VEC to store initializers.
* g++.dg/ext/complit3.C: Check for specific error messages.
* g++.dg/init/brace2.C: Update error message.
* g++.dg/warn/Wbraces2.C: Likewise.
git-svn-id: https://gcc.gnu.org/svn/gcc/trunk@102182 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/varasm.c')
-rw-r--r-- | gcc/varasm.c | 112 |
1 files changed, 67 insertions, 45 deletions
diff --git a/gcc/varasm.c b/gcc/varasm.c index db54f986730..e4d30974ddc 100644 --- a/gcc/varasm.c +++ b/gcc/varasm.c @@ -2400,13 +2400,14 @@ const_hash_1 (const tree exp) case CONSTRUCTOR: { - tree link; + unsigned HOST_WIDE_INT idx; + tree value; hi = 5 + int_size_in_bytes (TREE_TYPE (exp)); - for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link)) - if (TREE_VALUE (link)) - hi = hi * 603 + const_hash_1 (TREE_VALUE (link)); + FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, value) + if (value) + hi = hi * 603 + const_hash_1 (value); return hi; } @@ -2517,7 +2518,8 @@ compare_constant (const tree t1, const tree t2) case CONSTRUCTOR: { - tree l1, l2; + VEC(constructor_elt, gc) *v1, *v2; + unsigned HOST_WIDE_INT idx; typecode = TREE_CODE (TREE_TYPE (t1)); if (typecode != TREE_CODE (TREE_TYPE (t2))) @@ -2540,28 +2542,34 @@ compare_constant (const tree t1, const tree t2) return 0; } - for (l1 = CONSTRUCTOR_ELTS (t1), l2 = CONSTRUCTOR_ELTS (t2); - l1 && l2; - l1 = TREE_CHAIN (l1), l2 = TREE_CHAIN (l2)) + v1 = CONSTRUCTOR_ELTS (t1); + v2 = CONSTRUCTOR_ELTS (t2); + if (VEC_length (constructor_elt, v1) + != VEC_length (constructor_elt, v2)) + return 0; + + for (idx = 0; idx < VEC_length (constructor_elt, v1); ++idx) { + constructor_elt *c1 = VEC_index (constructor_elt, v1, idx); + constructor_elt *c2 = VEC_index (constructor_elt, v2, idx); + /* Check that each value is the same... */ - if (! compare_constant (TREE_VALUE (l1), TREE_VALUE (l2))) + if (!compare_constant (c1->value, c2->value)) return 0; /* ... and that they apply to the same fields! */ if (typecode == ARRAY_TYPE) { - if (! compare_constant (TREE_PURPOSE (l1), - TREE_PURPOSE (l2))) + if (!compare_constant (c1->index, c2->index)) return 0; } else { - if (TREE_PURPOSE (l1) != TREE_PURPOSE (l2)) + if (c1->index != c2->index) return 0; } } - return l1 == NULL_TREE && l2 == NULL_TREE; + return 1; } case ADDR_EXPR: @@ -2645,13 +2653,19 @@ copy_constant (tree exp) case CONSTRUCTOR: { tree copy = copy_node (exp); - tree list = copy_list (CONSTRUCTOR_ELTS (exp)); - tree tail; - - CONSTRUCTOR_ELTS (copy) = list; - for (tail = list; tail; tail = TREE_CHAIN (tail)) - TREE_VALUE (tail) = copy_constant (TREE_VALUE (tail)); - + VEC(constructor_elt, gc) *v; + unsigned HOST_WIDE_INT idx; + tree purpose, value; + + v = VEC_alloc(constructor_elt, gc, VEC_length(constructor_elt, + CONSTRUCTOR_ELTS (exp))); + FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp), idx, purpose, value) + { + constructor_elt *ce = VEC_quick_push (constructor_elt, v, NULL); + ce->index = purpose; + ce->value = copy_constant (value); + } + CONSTRUCTOR_ELTS (copy) = v; return copy; } @@ -3476,10 +3490,12 @@ compute_reloc_for_constant (tree exp) break; case CONSTRUCTOR: - for (tem = CONSTRUCTOR_ELTS (exp); tem; tem = TREE_CHAIN (tem)) - if (TREE_VALUE (tem) != 0) - reloc |= compute_reloc_for_constant (TREE_VALUE (tem)); - + { + unsigned HOST_WIDE_INT idx; + FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, tem) + if (tem != 0) + reloc |= compute_reloc_for_constant (tem); + } break; default: @@ -3533,10 +3549,12 @@ output_addressed_constants (tree exp) break; case CONSTRUCTOR: - for (tem = CONSTRUCTOR_ELTS (exp); tem; tem = TREE_CHAIN (tem)) - if (TREE_VALUE (tem) != 0) - output_addressed_constants (TREE_VALUE (tem)); - + { + unsigned HOST_WIDE_INT idx; + FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, tem) + if (tem != 0) + output_addressed_constants (tem); + } break; default: @@ -3567,16 +3585,16 @@ initializer_constant_valid_p (tree value, tree endtype) if ((TREE_CODE (TREE_TYPE (value)) == UNION_TYPE || TREE_CODE (TREE_TYPE (value)) == RECORD_TYPE) && TREE_CONSTANT (value) - && CONSTRUCTOR_ELTS (value)) + && !VEC_empty (constructor_elt, CONSTRUCTOR_ELTS (value))) { + unsigned HOST_WIDE_INT idx; tree elt; bool absolute = true; - for (elt = CONSTRUCTOR_ELTS (value); elt; elt = TREE_CHAIN (elt)) + FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (value), idx, elt) { tree reloc; - value = TREE_VALUE (elt); - reloc = initializer_constant_valid_p (value, TREE_TYPE (value)); + reloc = initializer_constant_valid_p (elt, TREE_TYPE (elt)); if (!reloc) return NULL_TREE; if (reloc != null_pointer_node) @@ -3832,7 +3850,8 @@ output_constant (tree exp, unsigned HOST_WIDE_INT size, unsigned int align) /* Allow a constructor with no elements for any data type. This means to fill the space with zeros. */ - if (TREE_CODE (exp) == CONSTRUCTOR && CONSTRUCTOR_ELTS (exp) == 0) + if (TREE_CODE (exp) == CONSTRUCTOR + && VEC_empty (constructor_elt, CONSTRUCTOR_ELTS (exp))) { assemble_zeros (size); return; @@ -3942,6 +3961,8 @@ static unsigned HOST_WIDE_INT array_size_for_constructor (tree val) { tree max_index, i; + unsigned HOST_WIDE_INT cnt; + tree index, value; /* This code used to attempt to handle string constants that are not arrays of single-bytes, but nothing else does, so there's no point in @@ -3950,10 +3971,8 @@ array_size_for_constructor (tree val) return TREE_STRING_LENGTH (val); max_index = NULL_TREE; - for (i = CONSTRUCTOR_ELTS (val); i; i = TREE_CHAIN (i)) + FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (val), cnt, index, value) { - tree index = TREE_PURPOSE (i); - if (TREE_CODE (index) == RANGE_EXPR) index = TREE_OPERAND (index, 1); if (max_index == NULL_TREE || tree_int_cst_lt (max_index, index)) @@ -3983,7 +4002,7 @@ output_constructor (tree exp, unsigned HOST_WIDE_INT size, unsigned int align) { tree type = TREE_TYPE (exp); - tree link, field = 0; + tree field = 0; tree min_index = 0; /* Number of bytes output or skipped so far. In other words, current position within the constructor. */ @@ -3991,6 +4010,8 @@ output_constructor (tree exp, unsigned HOST_WIDE_INT size, /* Nonzero means BYTE contains part of a byte, to be output. */ int byte_buffer_in_use = 0; int byte = 0; + unsigned HOST_WIDE_INT cnt; + constructor_elt *ce; gcc_assert (HOST_BITS_PER_WIDE_INT >= BITS_PER_UNIT); @@ -4010,23 +4031,22 @@ output_constructor (tree exp, unsigned HOST_WIDE_INT size, There is always a maximum of one element in the chain LINK for unions (even if the initializer in a source program incorrectly contains more one). */ - for (link = CONSTRUCTOR_ELTS (exp); - link; - link = TREE_CHAIN (link), - field = field ? TREE_CHAIN (field) : 0) + for (cnt = 0; + VEC_iterate (constructor_elt, CONSTRUCTOR_ELTS (exp), cnt, ce); + cnt++, field = field ? TREE_CHAIN (field) : 0) { - tree val = TREE_VALUE (link); + tree val = ce->value; tree index = 0; /* The element in a union constructor specifies the proper field or index. */ if ((TREE_CODE (type) == RECORD_TYPE || TREE_CODE (type) == UNION_TYPE || TREE_CODE (type) == QUAL_UNION_TYPE) - && TREE_PURPOSE (link) != 0) - field = TREE_PURPOSE (link); + && ce->index != 0) + field = ce->index; else if (TREE_CODE (type) == ARRAY_TYPE) - index = TREE_PURPOSE (link); + index = ce->index; #ifdef ASM_COMMENT_START if (field && flag_verbose_asm) @@ -4089,6 +4109,7 @@ output_constructor (tree exp, unsigned HOST_WIDE_INT size, if each element has the proper size. */ if ((field != 0 || index != 0) && pos != total_bytes) { + gcc_assert (pos >= total_bytes); assemble_zeros (pos - total_bytes); total_bytes = pos; } @@ -4164,6 +4185,7 @@ output_constructor (tree exp, unsigned HOST_WIDE_INT size, /* If still not at proper byte, advance to there. */ if (next_offset / BITS_PER_UNIT != total_bytes) { + gcc_assert (next_offset / BITS_PER_UNIT >= total_bytes); assemble_zeros (next_offset / BITS_PER_UNIT - total_bytes); total_bytes = next_offset / BITS_PER_UNIT; } |