public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [C++ PATCH[ move METHOD_VEC handling
@ 2017-09-01 19:02 Nathan Sidwell
  0 siblings, 0 replies; only message in thread
From: Nathan Sidwell @ 2017-09-01 19:02 UTC (permalink / raw)
  To: GCC Patches

[-- Attachment #1: Type: text/plain, Size: 289 bytes --]

This patch moves the CLASSTYPE_METHOD_VEC sorting functions from class.c 
to name-lookup.c.  It also merges the intial sort call into 
set_class_bindings, leaving that function in control of arranging the 
post-definition lookup data objects.

Applied to trunk.

nathan
-- 
Nathan Sidwell

[-- Attachment #2: mvec-move.diff --]
[-- Type: text/x-patch, Size: 7765 bytes --]

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.

Index: class.c
===================================================================
--- class.c	(revision 251608)
+++ class.c	(working copy)
@@ -129,10 +129,7 @@ static void handle_using_decl (tree, tre
 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 (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: cp-tree.h
===================================================================
--- cp-tree.h	(revision 251592)
+++ cp-tree.h	(working copy)
@@ -5952,8 +5952,6 @@ extern tree convert_to_base_statically
 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: name-lookup.c
===================================================================
--- name-lookup.c	(revision 251592)
+++ name-lookup.c	(working copy)
@@ -1312,6 +1312,59 @@ lookup_fnfields_slot (tree type, tree na
   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 enu
 }
 
 /* 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: name-lookup.h
===================================================================
--- name-lookup.h	(revision 251592)
+++ name-lookup.h	(working copy)
@@ -322,7 +322,9 @@ extern tree lookup_arg_dependent (tree,
 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);

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2017-09-01 19:02 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-01 19:02 [C++ PATCH[ move METHOD_VEC handling Nathan Sidwell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).