cp-tree.h (resort_type_method_vec): Move declaration to ...
authorNathan Sidwell <nathan@acm.org>
Fri, 1 Sep 2017 19:00:42 +0000 (19:00 +0000)
committerNathan Sidwell <nathan@gcc.gnu.org>
Fri, 1 Sep 2017 19:00:42 +0000 (19:00 +0000)
* 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
gcc/cp/class.c
gcc/cp/cp-tree.h
gcc/cp/name-lookup.c
gcc/cp/name-lookup.h

index 650e766..55cf4a0 100644 (file)
@@ -1,5 +1,16 @@
 2017-09-01  Nathan Sidwell  <nathan@acm.org>
 
+       * 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.
 
index 0476ae8..e5f237c 100644 (file)
@@ -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<tree, va_gc> *method_vec = (vec<tree, va_gc> *) 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<tree, va_gc> *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
index d8fe953..432faa9 100644 (file)
@@ -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);
index 7cd8f4a..f4b9ff1 100644 (file)
@@ -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<tree, va_gc> *method_vec = (vec<tree, va_gc> *) 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<tree, va_gc> *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)
     {
index a6bbd4a..94d2aaa 100644 (file)
@@ -322,7 +322,9 @@ extern tree lookup_arg_dependent (tree, tree, vec<tree, va_gc> *);
 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);