diff options
author | Nathan Sidwell <nathan@codesourcery.com> | 2004-07-19 15:45:53 +0000 |
---|---|---|
committer | Nathan Sidwell <nathan@gcc.gnu.org> | 2004-07-19 15:45:53 +0000 |
commit | 9ba5ff0f25985468d845360aee1d11cb3a0f09c8 (patch) | |
tree | 46c29242b882c33b8a12977fcf57e4b3cd23ce78 /gcc/cp | |
parent | 6df91b0004725e310b8dc7fa463745a703c1c059 (diff) | |
download | gcc-9ba5ff0f25985468d845360aee1d11cb3a0f09c8.zip gcc-9ba5ff0f25985468d845360aee1d11cb3a0f09c8.tar.gz gcc-9ba5ff0f25985468d845360aee1d11cb3a0f09c8.tar.bz2 |
vec.h: Propagate location information properly.
.: * vec.h: Propagate location information properly.
(VEC_T_iterate): Add result pointer parameter.
(VEC_T_space): New.
(VEC_T_reserve): Use it.
cp:
* class.c (add_method): Delay adding the slot until the end.
(determine_primary_base): Adjust VEC_iterate invokation.
(resort_type_method_vec, finish_struct_methods, warn_hidden,
walk_subobject_offsets, end_of_class, warn_about_ambiguous_bases,
build_vtbl_initializer): Likewise.
* init.c (sort_mem_initializers, build_delete, push_base_cleanups,
build_vbase_delete): Likewise.
* method.c (do_build_copy_constructor): Likewise.
* name-lookup.c (new_class_binding, print_binding_level,
poplevel_class, store_class_bindings, push_to_top_level,
pop_from_top_level): Likewise.
* pt.c (check_explicit_specialization): Likewise.
* search.c (lookup_conversion_operator, lookup_fnfields_1,
get_pure_virtuals, add_conversions, dfs_check_overlap,
binfo_for_vbase): Likewise.
From-SVN: r84924
Diffstat (limited to 'gcc/cp')
-rw-r--r-- | gcc/cp/ChangeLog | 18 | ||||
-rw-r--r-- | gcc/cp/class.c | 106 | ||||
-rw-r--r-- | gcc/cp/init.c | 22 | ||||
-rw-r--r-- | gcc/cp/method.c | 6 | ||||
-rw-r--r-- | gcc/cp/name-lookup.c | 20 | ||||
-rw-r--r-- | gcc/cp/pt.c | 2 | ||||
-rw-r--r-- | gcc/cp/search.c | 24 |
7 files changed, 105 insertions, 93 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index f4db5d3..dfd8d26 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,21 @@ +2004-07-19 Nathan Sidwell <nathan@codesourcery.com> + + * class.c (add_method): Delay adding the slot until the end. + (determine_primary_base): Adjust VEC_iterate invokation. + (resort_type_method_vec, finish_struct_methods, warn_hidden, + walk_subobject_offsets, end_of_class, warn_about_ambiguous_bases, + build_vtbl_initializer): Likewise. + * init.c (sort_mem_initializers, build_delete, push_base_cleanups, + build_vbase_delete): Likewise. + * method.c (do_build_copy_constructor): Likewise. + * name-lookup.c (new_class_binding, print_binding_level, + poplevel_class, store_class_bindings, push_to_top_level, + pop_from_top_level): Likewise. + * pt.c (check_explicit_specialization): Likewise. + * search.c (lookup_conversion_operator, lookup_fnfields_1, + get_pure_virtuals, add_conversions, dfs_check_overlap, + binfo_for_vbase): Likewise. + 2004-07-19 Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net> PR c++/12170 diff --git a/gcc/cp/class.c b/gcc/cp/class.c index cc1dc76..69f6d9e 100644 --- a/gcc/cp/class.c +++ b/gcc/cp/class.c @@ -801,12 +801,13 @@ void add_method (tree type, tree method) { int using; - size_t len; - size_t slot; + unsigned slot; tree overload; int template_conv_p; VEC(tree) *method_vec; bool complete_p; + bool insert_p = false; + tree current_fns; if (method == error_mark_node) return; @@ -830,8 +831,6 @@ add_method (tree type, tree method) CLASSTYPE_METHOD_VEC (type) = method_vec; } - len = VEC_length (tree, method_vec); - /* Constructors and destructors go in special slots. */ if (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (method)) slot = CLASSTYPE_CONSTRUCTOR_SLOT; @@ -848,13 +847,13 @@ add_method (tree type, tree method) } else { - bool insert_p = true; bool conv_p = DECL_CONV_FN_P (method); tree m; + insert_p = true; /* See if we already have an entry with this name. */ for (slot = CLASSTYPE_FIRST_CONVERSION_SLOT; - (m = VEC_iterate (tree, method_vec, slot)); + VEC_iterate (tree, method_vec, slot, m); ++slot) { m = OVL_CURRENT (m); @@ -877,25 +876,9 @@ add_method (tree type, tree method) && DECL_NAME (m) > DECL_NAME (method)) break; } - - /* If we need a new slot, make room. */ - if (insert_p) - { - /* We expect to add few methods in the COMPLETE_P case, so - just make room for one more method. */ - if (complete_p) - VEC_reserve (tree, method_vec, 1); - if (slot == len) - VEC_safe_push (tree, method_vec, NULL_TREE); - else - VEC_safe_insert (tree, method_vec, slot, NULL_TREE); - len++; - /* Inserting a new slot may have caused the vector to be - reallocated. */ - CLASSTYPE_METHOD_VEC (type) = method_vec; - } } - + current_fns = insert_p ? NULL_TREE : VEC_index (tree, method_vec, slot); + if (processing_template_decl) /* TYPE is a template class. Don't issue any errors now; wait until instantiation time to complain. */ @@ -905,9 +888,7 @@ add_method (tree type, tree method) tree fns; /* Check to see if we've already got this method. */ - for (fns = VEC_index (tree, method_vec, slot); - fns; - fns = OVL_NEXT (fns)) + for (fns = current_fns; fns; fns = OVL_NEXT (fns)) { tree fn = OVL_CURRENT (fns); tree parms1; @@ -975,14 +956,25 @@ add_method (tree type, tree method) } /* Add the new binding. */ - overload = build_overload (method, VEC_index (tree, method_vec, slot)); - if (!DECL_CONSTRUCTOR_P (method) - && !DECL_DESTRUCTOR_P (method) - && !complete_p) + overload = build_overload (method, current_fns); + + if (slot >= CLASSTYPE_FIRST_CONVERSION_SLOT && !complete_p) push_class_level_binding (DECL_NAME (method), overload); - /* Actually insert the new method. */ - VEC_replace (tree, method_vec, slot, overload); + if (insert_p) + { + /* We only expect to add few methods in the COMPLETE_P case, so + just make room for one more method in that case. */ + if (VEC_reserve (tree, method_vec, complete_p ? 1 : -1)) + CLASSTYPE_METHOD_VEC (type) = method_vec; + if (slot == VEC_length (tree, method_vec)) + VEC_quick_push (tree, method_vec, overload); + else + VEC_quick_insert (tree, method_vec, slot, overload); + } + else + /* Replace the current slot. */ + VEC_replace (tree, method_vec, slot, overload); } /* Subroutines of finish_struct. */ @@ -1275,8 +1267,9 @@ static void determine_primary_base (tree t) { unsigned i, n_baseclasses = BINFO_N_BASE_BINFOS (TYPE_BINFO (t)); - tree type_binfo; + tree type_binfo = TYPE_BINFO (t); tree vbase_binfo; + VEC(tree) *vbases; /* If there are no baseclasses, there is certainly no primary base. */ if (n_baseclasses == 0) @@ -1324,8 +1317,8 @@ determine_primary_base (tree t) /* Find the indirect primary bases - those virtual bases which are primary bases of something else in this hierarchy. */ - for (i = 0; (vbase_binfo = VEC_iterate - (tree, CLASSTYPE_VBASECLASSES (t), i)); i++) + for (vbases = CLASSTYPE_VBASECLASSES (t), i = 0; + VEC_iterate (tree, vbases, i, vbase_binfo); i++) { unsigned j; @@ -1335,11 +1328,12 @@ determine_primary_base (tree t) for (j = 0; j != n_baseclasses; ++j) { unsigned k; + VEC (tree) *base_vbases; tree base_vbase_binfo; tree basetype = BINFO_TYPE (BINFO_BASE_BINFO (TYPE_BINFO (t), j)); - for (k = 0; (base_vbase_binfo = VEC_iterate - (tree, CLASSTYPE_VBASECLASSES (basetype), k)); k++) + for (base_vbases = CLASSTYPE_VBASECLASSES (basetype), k = 0; + VEC_iterate (tree, base_vbases, k, base_vbase_binfo); k++) { if (BINFO_PRIMARY_P (base_vbase_binfo) && same_type_p (BINFO_TYPE (base_vbase_binfo), @@ -1677,7 +1671,7 @@ resort_type_method_vec (void* obj, /* The type conversion ops have to live at the front of the vec, so we can't sort them. */ for (slot = CLASSTYPE_FIRST_CONVERSION_SLOT; - (fn = VEC_iterate (tree, method_vec, slot)); + VEC_iterate (tree, method_vec, slot, fn); ++slot) if (!DECL_CONV_FN_P (OVL_CURRENT (fn))) break; @@ -1738,8 +1732,8 @@ finish_struct_methods (tree t) /* The type conversion ops have to live at the front of the vec, so we can't sort them. */ - for (slot = 2; - (fn_fields = VEC_iterate (tree, method_vec, slot)); + for (slot = CLASSTYPE_FIRST_CONVERSION_SLOT; + VEC_iterate (tree, method_vec, slot, fn_fields); ++slot) if (!DECL_CONV_FN_P (OVL_CURRENT (fn_fields))) break; @@ -2369,7 +2363,7 @@ warn_hidden (tree t) /* We go through each separately named virtual function. */ for (i = CLASSTYPE_FIRST_CONVERSION_SLOT; - (fns = VEC_iterate (tree, method_vec, i)); + VEC_iterate (tree, method_vec, i, fns); ++i) { tree fn; @@ -3229,6 +3223,7 @@ walk_subobject_offsets (tree type, if (abi_version_at_least (2) && CLASSTYPE_VBASECLASSES (type)) { unsigned ix; + VEC (tree) *vbases; /* Iterate through the virtual base classes of TYPE. In G++ 3.2, we included virtual bases in the direct base class @@ -3236,8 +3231,8 @@ walk_subobject_offsets (tree type, correct offsets for virtual bases are only known when working with the most derived type. */ if (vbases_p) - for (ix = 0; (binfo = VEC_iterate - (tree, CLASSTYPE_VBASECLASSES (type), ix)); ix++) + for (vbases = CLASSTYPE_VBASECLASSES (type), ix = 0; + VEC_iterate (tree, vbases, ix, binfo); ix++) { r = walk_subobject_offsets (binfo, f, @@ -4402,7 +4397,9 @@ static tree end_of_class (tree t, int include_virtuals_p) { tree result = size_zero_node; + VEC (tree) *vbases; tree binfo; + tree base_binfo; tree offset; int i; @@ -4422,10 +4419,10 @@ end_of_class (tree t, int include_virtuals_p) /* G++ 3.2 did not check indirect virtual bases. */ if (abi_version_at_least (2) && include_virtuals_p) - for (i = 0; (binfo = VEC_iterate - (tree, CLASSTYPE_VBASECLASSES (t), i)); i++) + for (vbases = CLASSTYPE_VBASECLASSES (t), i = 0; + VEC_iterate (tree, vbases, i, base_binfo); i++) { - offset = end_of_base (binfo); + offset = end_of_base (base_binfo); if (INT_CST_LT_UNSIGNED (result, offset)) result = offset; } @@ -4447,11 +4444,13 @@ static void warn_about_ambiguous_bases (tree t) { int i; + VEC (tree) *vbases; tree basetype; tree binfo; /* Check direct bases. */ - for (i = 0; i < BINFO_N_BASE_BINFOS (TYPE_BINFO (t)); ++i) + for (i = 0; + i < BINFO_N_BASE_BINFOS (TYPE_BINFO (t)); ++i) { basetype = BINFO_TYPE (BINFO_BASE_BINFO (TYPE_BINFO (t), i)); @@ -4462,8 +4461,8 @@ warn_about_ambiguous_bases (tree t) /* Check for ambiguous virtual bases. */ if (extra_warnings) - for (i = 0; (binfo = VEC_iterate - (tree, CLASSTYPE_VBASECLASSES (t), i)); i++) + for (vbases = CLASSTYPE_VBASECLASSES (t), i = 0; + VEC_iterate (tree, vbases, i, binfo); i++) { basetype = BINFO_TYPE (binfo); @@ -7237,7 +7236,8 @@ build_vtbl_initializer (tree binfo, vtbl_init_data vid; unsigned ix; tree vbinfo; - + VEC (tree) *vbases; + /* Initialize VID. */ memset (&vid, 0, sizeof (vid)); vid.binfo = binfo; @@ -7262,8 +7262,8 @@ build_vtbl_initializer (tree binfo, /* Clear BINFO_VTABLE_PATH_MARKED; it's set by build_vbase_offset_vtbl_entries. */ - for (ix = 0; (vbinfo = VEC_iterate - (tree, CLASSTYPE_VBASECLASSES (t), ix)); ix++) + for (vbases = CLASSTYPE_VBASECLASSES (t), ix = 0; + VEC_iterate (tree, vbases, ix, vbinfo); ix++) BINFO_VTABLE_PATH_MARKED (vbinfo) = 0; /* If the target requires padding between data entries, add that now. */ diff --git a/gcc/cp/init.c b/gcc/cp/init.c index 926dfcd..988bfba 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -460,6 +460,7 @@ sort_mem_initializers (tree t, tree mem_inits) tree base; tree sorted_inits; tree next_subobject; + VEC (tree) *vbases; int i; int uses_unions_p; @@ -470,8 +471,8 @@ sort_mem_initializers (tree t, tree mem_inits) sorted_inits = NULL_TREE; /* Process the virtual bases. */ - for (i = 0; (base = VEC_iterate - (tree, CLASSTYPE_VBASECLASSES (t), i)); i++) + for (vbases = CLASSTYPE_VBASECLASSES (t), i = 0; + VEC_iterate (tree, vbases, i, base); i++) sorted_inits = tree_cons (base, NULL_TREE, sorted_inits); /* Process the direct bases. */ @@ -2857,10 +2858,11 @@ build_delete (tree type, tree addr, special_function_kind auto_delete, void push_base_cleanups (void) { - tree binfos; + tree binfos, base_binfo; int i, n_baseclasses; tree member; tree expr; + VEC (tree) *vbases; /* Run destructors for all virtual baseclasses. */ if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type)) @@ -2872,16 +2874,15 @@ push_base_cleanups (void) /* The CLASSTYPE_VBASECLASSES vector is in initialization order, which is also the right order for pushing cleanups. */ - for (i = 0; (binfos = VEC_iterate - (tree, CLASSTYPE_VBASECLASSES (current_class_type), i)); - i++) + for (vbases = CLASSTYPE_VBASECLASSES (current_class_type), i = 0; + VEC_iterate (tree, vbases, i, base_binfo); i++) { - if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (BINFO_TYPE (binfos))) + if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (BINFO_TYPE (base_binfo))) { expr = build_special_member_call (current_class_ref, base_dtor_identifier, NULL_TREE, - binfos, + base_binfo, (LOOKUP_NORMAL | LOOKUP_NONVIRTUAL)); expr = build (COND_EXPR, void_type_node, cond, @@ -2938,13 +2939,14 @@ build_vbase_delete (tree type, tree decl) unsigned ix; tree binfo; tree result; + VEC (tree) *vbases; tree addr = build_unary_op (ADDR_EXPR, decl, 0); my_friendly_assert (addr != error_mark_node, 222); result = convert_to_void (integer_zero_node, NULL); - for (ix = 0; (binfo = VEC_iterate - (tree, CLASSTYPE_VBASECLASSES (type), ix)); ix++) + for (vbases = CLASSTYPE_VBASECLASSES (type), ix = 0; + VEC_iterate (tree, vbases, ix, binfo); ix++) { tree base_addr = convert_force (build_pointer_type (BINFO_TYPE (binfo)), addr, 0); diff --git a/gcc/cp/method.c b/gcc/cp/method.c index 984e0e9..802d4c0 100644 --- a/gcc/cp/method.c +++ b/gcc/cp/method.c @@ -521,15 +521,15 @@ do_build_copy_constructor (tree fndecl) int cvquals = cp_type_quals (TREE_TYPE (parm)); int i; tree binfo; + VEC (tree) *vbases; /* Initialize all the base-classes with the parameter converted to their type so that we get their copy constructor and not another constructor that takes current_class_type. We must deal with the binfo's directly as a direct base might be inaccessible due to ambiguity. */ - for (i = 0; (binfo = VEC_iterate - (tree, CLASSTYPE_VBASECLASSES (current_class_type), i)); - i++) + for (vbases = CLASSTYPE_VBASECLASSES (current_class_type), i = 0; + VEC_iterate (tree, vbases, i, binfo); i++) { member_init_list = tree_cons (binfo, diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c index 3a2f71c..6cbebb3 100644 --- a/gcc/cp/name-lookup.c +++ b/gcc/cp/name-lookup.c @@ -387,7 +387,7 @@ new_class_binding (tree name, tree value, tree type, cxx_scope *scope) size_t i; for (i = 0; - (cb = VEC_iterate (cp_class_binding, scope->class_shadowed, i)); + VEC_iterate (cp_class_binding, scope->class_shadowed, i, cb); i++) { cxx_binding **b; @@ -1656,9 +1656,7 @@ print_binding_level (struct cp_binding_level* lvl) cp_class_binding *b; fprintf (stderr, " class-shadowed:"); for (i = 0; - (b = VEC_iterate(cp_class_binding, - lvl->class_shadowed, - i)); + VEC_iterate(cp_class_binding, lvl->class_shadowed, i, b); ++i) fprintf (stderr, " %s ", IDENTIFIER_POINTER (b->identifier)); fprintf (stderr, "\n"); @@ -2617,7 +2615,7 @@ poplevel_class (void) if (level->class_shadowed) { for (i = 0; - (cb = VEC_iterate (cp_class_binding, level->class_shadowed, i)); + VEC_iterate (cp_class_binding, level->class_shadowed, i, cb); ++i) IDENTIFIER_BINDING (cb->identifier) = cb->base.previous; ggc_free (level->class_shadowed); @@ -4924,9 +4922,7 @@ store_class_bindings (VEC(cp_class_binding) *names, cp_class_binding *cb; timevar_push (TV_NAME_LOOKUP); - for (i = 0; - (cb = VEC_iterate(cp_class_binding, names, i)); - ++i) + for (i = 0; VEC_iterate(cp_class_binding, names, i, cb); ++i) store_binding (cb->identifier, old_bindings); timevar_pop (TV_NAME_LOOKUP); } @@ -4982,9 +4978,7 @@ push_to_top_level (void) SET_IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (t), TREE_VALUE (t)); } - for (i = 0; - (sb = VEC_iterate (cxx_saved_binding, s->old_bindings, i)); - ++i) + for (i = 0; VEC_iterate (cxx_saved_binding, s->old_bindings, i, sb); ++i) IDENTIFIER_MARKED (sb->identifier) = 0; s->prev = scope_chain; @@ -5015,9 +5009,7 @@ pop_from_top_level (void) current_lang_base = 0; scope_chain = s->prev; - for (i = 0; - (saved = VEC_iterate (cxx_saved_binding, s->old_bindings, i)); - ++i) + for (i = 0; VEC_iterate (cxx_saved_binding, s->old_bindings, i, saved); ++i) { tree id = saved->identifier; diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index b1d9de0..4c059c1 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -1838,7 +1838,7 @@ check_explicit_specialization (tree declarator, methods = CLASSTYPE_METHOD_VEC (ctype); if (methods) for (idx = CLASSTYPE_FIRST_CONVERSION_SLOT; - (ovl = VEC_iterate (tree, methods, idx)); + VEC_iterate (tree, methods, idx, ovl); ++idx) { if (!DECL_CONV_FN_P (OVL_CURRENT (ovl))) diff --git a/gcc/cp/search.c b/gcc/cp/search.c index ceefa3c..e172aa3 100644 --- a/gcc/cp/search.c +++ b/gcc/cp/search.c @@ -1319,8 +1319,7 @@ lookup_conversion_operator (tree class_type, tree type) for (pass = 0; pass < 2; ++pass) for (i = CLASSTYPE_FIRST_CONVERSION_SLOT; - (fn = VEC_iterate (tree, methods, i)); - ++i) + VEC_iterate (tree, methods, i, fn); ++i) { /* All the conversion operators come near the beginning of the class. Therefore, if FN is not a conversion operator, there @@ -1410,7 +1409,7 @@ lookup_fnfields_1 (tree type, tree name) /* Skip the conversion operators. */ for (i = CLASSTYPE_FIRST_CONVERSION_SLOT; - (fn = VEC_iterate (tree, method_vec, i)); + VEC_iterate (tree, method_vec, i, fn); ++i) if (!DECL_CONV_FN_P (OVL_CURRENT (fn))) break; @@ -1442,9 +1441,7 @@ lookup_fnfields_1 (tree type, tree name) } } else - for (; - (fn = VEC_iterate (tree, method_vec, i)); - ++i) + for (; VEC_iterate (tree, method_vec, i, fn); ++i) { #ifdef GATHER_STATISTICS n_outer_fields_searched++; @@ -1887,6 +1884,7 @@ get_pure_virtuals (tree type) { unsigned ix; tree binfo; + VEC (tree) *vbases; /* Clear the CLASSTYPE_PURE_VIRTUALS list; whatever is already there is going to be overridden. */ @@ -1903,8 +1901,8 @@ get_pure_virtuals (tree type) /* Put the pure virtuals in dfs order. */ CLASSTYPE_PURE_VIRTUALS (type) = nreverse (CLASSTYPE_PURE_VIRTUALS (type)); - for (ix = 0; (binfo = VEC_iterate - (tree, CLASSTYPE_VBASECLASSES (type), ix)); ix++) + for (vbases = CLASSTYPE_VBASECLASSES (type), ix = 0; + VEC_iterate (tree, vbases, ix, binfo); ix++) { tree virtuals; @@ -2078,12 +2076,12 @@ add_conversions (tree binfo, void *data) return NULL_TREE; for (i = CLASSTYPE_FIRST_CONVERSION_SLOT; - (tmp = VEC_iterate (tree, method_vec, i)); + VEC_iterate (tree, method_vec, i, tmp); ++i) { tree name; - if (!tmp || ! DECL_CONV_FN_P (OVL_CURRENT (tmp))) + if (!DECL_CONV_FN_P (OVL_CURRENT (tmp))) break; name = DECL_NAME (OVL_CURRENT (tmp)); @@ -2153,6 +2151,7 @@ dfs_check_overlap (tree empty_binfo, void *data) { struct overlap_info *oi = (struct overlap_info *) data; tree binfo; + for (binfo = TYPE_BINFO (oi->compare_type); ; binfo = BINFO_BASE_BINFO (binfo, 0)) @@ -2308,9 +2307,10 @@ binfo_for_vbase (tree base, tree t) { unsigned ix; tree binfo; + VEC (tree) *vbases; - for (ix = 0; (binfo = VEC_iterate - (tree, CLASSTYPE_VBASECLASSES (t), ix)); ix++) + for (vbases = CLASSTYPE_VBASECLASSES (t), ix = 0; + VEC_iterate (tree, vbases, ix, binfo); ix++) if (BINFO_TYPE (binfo) == base) return binfo; return NULL; |