From fe920c2d9f479c2b17d6963973cf11efe0169293 Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Fri, 1 Sep 2017 19:00:42 +0000 Subject: [PATCH] cp-tree.h (resort_type_method_vec): Move declaration to ... * cp-tree.h (resort_type_method_vec): Move declaration to ... * name-lookup.h (resort_type_method_vec): ... here. (set_class_bindings): Lose 2nd arg. * class.c (finish_struct_1, finish_struct): Adjust set_class_bindings call. Don't call finish_struct_methods. (resort_data, method_name_cmp, resort_method_name_cmp, resort_type_method_vec, finish_struct_methods): Move to ... * name-lookup.c (resort_data, method_name_cmp, resort_method_name_cmp, resort_type_method_vec): ... here. (set_class_bindings): Lose fields arg. Swallow finish_struct_methods. From-SVN: r251609 --- gcc/cp/ChangeLog | 11 ++++++++ gcc/cp/class.c | 79 ++-------------------------------------------------- gcc/cp/cp-tree.h | 2 -- gcc/cp/name-lookup.c | 62 +++++++++++++++++++++++++++++++++++++++-- gcc/cp/name-lookup.h | 4 ++- 5 files changed, 76 insertions(+), 82 deletions(-) diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 650e766..55cf4a0 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,16 @@ 2017-09-01 Nathan Sidwell + * cp-tree.h (resort_type_method_vec): Move declaration to ... + * name-lookup.h (resort_type_method_vec): ... here. + (set_class_bindings): Lose 2nd arg. + * class.c (finish_struct_1, finish_struct): Adjust + set_class_bindings call. Don't call finish_struct_methods. + (resort_data, method_name_cmp, resort_method_name_cmp, + resort_type_method_vec, finish_struct_methods): Move to ... + * name-lookup.c (resort_data, method_name_cmp, + resort_method_name_cmp, resort_type_method_vec): ... here. + (set_class_bindings): Lose fields arg. Swallow finish_struct_methods. + * class.c (finish_struct): Call set_class_bindings for the template case too. diff --git a/gcc/cp/class.c b/gcc/cp/class.c index 0476ae8..e5f237c 100644 --- a/gcc/cp/class.c +++ b/gcc/cp/class.c @@ -129,10 +129,7 @@ static void handle_using_decl (tree, tree); static tree dfs_modify_vtables (tree, void *); static tree modify_all_vtables (tree, tree); static void determine_primary_bases (tree); -static void finish_struct_methods (tree); static void maybe_warn_about_overly_private_class (tree); -static int method_name_cmp (const void *, const void *); -static int resort_method_name_cmp (const void *, const void *); static void add_implicitly_declared_members (tree, tree*, int, int); static tree fixed_type_or_null (tree, int *, int *); static tree build_simple_base_path (tree expr, tree binfo); @@ -2247,76 +2244,6 @@ maybe_warn_about_overly_private_class (tree t) } } -static struct { - gt_pointer_operator new_value; - void *cookie; -} resort_data; - -/* Comparison function to compare two TYPE_METHOD_VEC entries by name. */ - -static int -method_name_cmp (const void* m1_p, const void* m2_p) -{ - const tree *const m1 = (const tree *) m1_p; - const tree *const m2 = (const tree *) m2_p; - - if (OVL_NAME (*m1) < OVL_NAME (*m2)) - return -1; - return 1; -} - -/* This routine compares two fields like method_name_cmp but using the - pointer operator in resort_field_decl_data. */ - -static int -resort_method_name_cmp (const void* m1_p, const void* m2_p) -{ - const tree *const m1 = (const tree *) m1_p; - const tree *const m2 = (const tree *) m2_p; - - tree n1 = OVL_NAME (*m1); - tree n2 = OVL_NAME (*m2); - resort_data.new_value (&n1, resort_data.cookie); - resort_data.new_value (&n2, resort_data.cookie); - if (n1 < n2) - return -1; - return 1; -} - -/* Resort TYPE_METHOD_VEC because pointers have been reordered. */ - -void -resort_type_method_vec (void* obj, - void* /*orig_obj*/, - gt_pointer_operator new_value, - void* cookie) -{ - if (vec *method_vec = (vec *) obj) - { - resort_data.new_value = new_value; - resort_data.cookie = cookie; - qsort (method_vec->address (), method_vec->length (), sizeof (tree), - resort_method_name_cmp); - } -} - -/* Warn about duplicate methods in fn_fields. - - Sort methods that are not special (i.e., constructors, destructors, - and type conversion operators) so that we can find them faster in - search. */ - -static void -finish_struct_methods (tree t) -{ - vec *method_vec = CLASSTYPE_METHOD_VEC (t); - if (!method_vec) - return; - - qsort (method_vec->address (), method_vec->length (), - sizeof (tree), method_name_cmp); -} - /* Make BINFO's vtable have N entries, including RTTI entries, vbase and vcall offsets, etc. Set its type and call the back end to lay it out. */ @@ -6966,8 +6893,7 @@ finish_struct_1 (tree t) layout_class_type (t, &virtuals); /* COMPLETE_TYPE_P is now true. */ - finish_struct_methods (t); - set_class_bindings (t, TYPE_FIELDS (t)); + set_class_bindings (t); if (CLASSTYPE_AS_BASE (t) != t) /* We use the base type for trivial assignments, and hence it @@ -7187,8 +7113,7 @@ finish_struct (tree t, tree attributes) TYPE_SIZE_UNIT (t) = size_zero_node; /* COMPLETE_TYPE_P is now true. */ - finish_struct_methods (t); - set_class_bindings (t, TYPE_FIELDS (t)); + set_class_bindings (t); /* We need to emit an error message if this type was used as a parameter and it is an abstract type, even if it is a template. We construct diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index d8fe953..432faa9 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -5952,8 +5952,6 @@ extern tree convert_to_base_statically (tree, tree); extern tree build_vtbl_ref (tree, tree); extern tree build_vfn_ref (tree, tree); extern tree get_vtable_decl (tree, int); -extern void resort_type_method_vec (void *, void *, - gt_pointer_operator, void *); extern bool add_method (tree, tree, bool); extern tree declared_access (tree); extern tree currently_open_class (tree); diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c index 7cd8f4a..f4b9ff1 100644 --- a/gcc/cp/name-lookup.c +++ b/gcc/cp/name-lookup.c @@ -1312,6 +1312,59 @@ lookup_fnfields_slot (tree type, tree name) return lookup_fnfields_slot_nolazy (type, name); } +static struct { + gt_pointer_operator new_value; + void *cookie; +} resort_data; + +/* Comparison function to compare two TYPE_METHOD_VEC entries by name. */ + +static int +method_name_cmp (const void* m1_p, const void* m2_p) +{ + const tree *const m1 = (const tree *) m1_p; + const tree *const m2 = (const tree *) m2_p; + + if (OVL_NAME (*m1) < OVL_NAME (*m2)) + return -1; + return 1; +} + +/* This routine compares two fields like method_name_cmp but using the + pointer operator in resort_field_decl_data. */ + +static int +resort_method_name_cmp (const void* m1_p, const void* m2_p) +{ + const tree *const m1 = (const tree *) m1_p; + const tree *const m2 = (const tree *) m2_p; + + tree n1 = OVL_NAME (*m1); + tree n2 = OVL_NAME (*m2); + resort_data.new_value (&n1, resort_data.cookie); + resort_data.new_value (&n2, resort_data.cookie); + if (n1 < n2) + return -1; + return 1; +} + +/* Resort TYPE_METHOD_VEC because pointers have been reordered. */ + +void +resort_type_method_vec (void* obj, + void* /*orig_obj*/, + gt_pointer_operator new_value, + void* cookie) +{ + if (vec *method_vec = (vec *) obj) + { + resort_data.new_value = new_value; + resort_data.cookie = cookie; + qsort (method_vec->address (), method_vec->length (), sizeof (tree), + resort_method_name_cmp); + } +} + /* Allocate and return an instance of struct sorted_fields_type with N fields. */ @@ -1383,11 +1436,16 @@ add_enum_fields_to_record_type (tree enumtype, } /* Insert FIELDS into KLASS for the sorted case if the FIELDS count is - big enough. */ + big enough. Sort the METHOD_VEC too. */ void -set_class_bindings (tree klass, tree fields) +set_class_bindings (tree klass) { + if (vec *method_vec = CLASSTYPE_METHOD_VEC (klass)) + qsort (method_vec->address (), method_vec->length (), + sizeof (tree), method_name_cmp); + + tree fields = TYPE_FIELDS (klass); int n_fields = count_fields (fields); if (n_fields >= 8) { diff --git a/gcc/cp/name-lookup.h b/gcc/cp/name-lookup.h index a6bbd4a..94d2aaa 100644 --- a/gcc/cp/name-lookup.h +++ b/gcc/cp/name-lookup.h @@ -322,7 +322,9 @@ extern tree lookup_arg_dependent (tree, tree, vec *); extern tree lookup_field_1 (tree, tree, bool); extern tree lookup_fnfields_slot (tree, tree); extern tree lookup_fnfields_slot_nolazy (tree, tree); -extern void set_class_bindings (tree, tree); +extern void resort_type_method_vec (void *, void *, + gt_pointer_operator, void *); +extern void set_class_bindings (tree); extern void insert_late_enum_def_bindings (tree, tree); extern tree innermost_non_namespace_value (tree); extern cxx_binding *outer_binding (tree, cxx_binding *, bool); -- 2.7.4