This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[C++ PATCH] Kill IDENTIFIER_NAMESPACE_BINDINGS


At last, here's the final (for the moment) name-lookup data structure patch. It replaces IDENTIFIER_NAMESPACE_BINDINGS -- a list of ns/value tuples chained on each identifier -- with a per-namespace hash-map.

nathan
--
Nathan Sidwell
2017-05-30  Nathan Sidwell  <nathan@acm.org>

	Kill IDENTIFIER_NAMESPACE_BINDINGS
	* cp-tree.h (lang_identifier): Delete namespace_bindings.
	(IDENTIFIER_NAMESPACE_BINDINGS): Delete.
	(lang_decl_ns): Add bindings.
	(DECL_NAMESPACE_BINDINGS): New.
	* lex.c (retrofit_lang_decl): Create namespace hash table.
	* name-lookup.c (find_namespace_slot): Change to use hash-map.
	* ptree.c (cxx_print_binding): Delete.
	(cxx_print_identifier): Remove NAMESPACE_BINDING printing.

Index: cp-tree.h
===================================================================
--- cp-tree.h	(revision 248693)
+++ cp-tree.h	(working copy)
@@ -535,7 +535,6 @@ extern GTY(()) tree cp_global_trees[CPTI
 
 struct GTY(()) lang_identifier {
   struct c_common_identifier c_common;
-  cxx_binding *namespace_bindings;
   cxx_binding *bindings;
   tree class_template_info;
   tree label_value;
@@ -965,8 +964,6 @@ enum GTY(()) abstract_class_use {
 
 /* Macros for access to language-specific slots in an identifier.  */
 
-#define IDENTIFIER_NAMESPACE_BINDINGS(NODE)	\
-  (LANG_IDENTIFIER_CAST (NODE)->namespace_bindings)
 #define IDENTIFIER_TEMPLATE(NODE)	\
   (LANG_IDENTIFIER_CAST (NODE)->class_template_info)
 
@@ -2552,6 +2549,9 @@ struct GTY(()) lang_decl_ns {
      because of PCH.  */
   vec<tree, va_gc> *usings;
   vec<tree, va_gc> *inlinees;
+
+  /* Map from IDENTIFIER nodes to DECLS.  */
+  hash_map<lang_identifier *, tree> *bindings;
 };
 
 /* DECL_LANG_SPECIFIC for parameters.  */
@@ -3146,6 +3146,10 @@ struct GTY(()) lang_decl {
 #define DECL_NAMESPACE_INLINEES(NODE) \
    (LANG_DECL_NS_CHECK (NODE)->inlinees)
 
+/* Pointer to hash_map from IDENTIFIERS to DECLS  */
+#define DECL_NAMESPACE_BINDINGS(NODE) \
+   (LANG_DECL_NS_CHECK (NODE)->bindings)
+
 /* In a NAMESPACE_DECL, points to the original namespace if this is
    a namespace alias.  */
 #define DECL_NAMESPACE_ALIAS(NODE) \
Index: lex.c
===================================================================
--- lex.c	(revision 248689)
+++ lex.c	(working copy)
@@ -566,8 +566,12 @@ retrofit_lang_decl (tree t, int sel)
     memcpy (ld, DECL_LANG_SPECIFIC (t), oldsize);
 
   ld->u.base.selector = sel;
-
   DECL_LANG_SPECIFIC (t) = ld;
+
+  if (sel == 2)
+    /* Who'd create a namespace, only to put nothing in it?  */
+    ld->u.ns.bindings = hash_map<lang_identifier *, tree>::create_ggc (499);
+
   if (current_lang_name == lang_name_cplusplus
       || decl_linkage (t) == lk_none)
     SET_DECL_LANGUAGE (t, lang_cplusplus);
Index: name-lookup.c
===================================================================
--- name-lookup.c	(revision 248693)
+++ name-lookup.c	(working copy)
@@ -86,25 +86,18 @@ create_local_binding (cp_binding_level *
 static tree *
 find_namespace_slot (tree ns, tree name, bool create_p = false)
 {
-  cp_binding_level *level = NAMESPACE_LEVEL (ns);
-  cxx_binding *binding = IDENTIFIER_NAMESPACE_BINDINGS (name);
-
-  for (;binding; binding = binding->previous)
-    if (binding->scope == level)
-      return &binding->value;
+  tree *slot;
 
   if (create_p)
     {
-      binding = cxx_binding_make (NULL, NULL);
-      binding->previous = IDENTIFIER_NAMESPACE_BINDINGS (name);
-      binding->scope = level;
-      binding->is_local = false;
-      binding->value_is_inherited = false;
-      IDENTIFIER_NAMESPACE_BINDINGS (name) = binding;
-      return &binding->value;
+      bool existed;
+      slot = &DECL_NAMESPACE_BINDINGS (ns)->get_or_insert (name, &existed);
+      if (!existed)
+	*slot = NULL_TREE;
     }
-
-  return NULL;
+  else
+    slot = DECL_NAMESPACE_BINDINGS (ns)->get (name);
+  return slot;
 }
 
 static tree
Index: ptree.c
===================================================================
--- ptree.c	(revision 248689)
+++ ptree.c	(working copy)
@@ -171,14 +171,6 @@ cxx_print_type (FILE *file, tree node, i
     }
 }
 
-
-static void
-cxx_print_binding (FILE *stream, cxx_binding *binding, const char *prefix)
-{
-  fprintf (stream, "%s <%p>",
-	   prefix, (void *) binding);
-}
-
 void
 cxx_print_identifier (FILE *file, tree node, int indent)
 {
@@ -186,12 +178,7 @@ cxx_print_identifier (FILE *file, tree n
     fprintf (file, " ");
   else
     indent_to (file, indent + 4);
-  cxx_print_binding (file, IDENTIFIER_NAMESPACE_BINDINGS (node), "bindings");
-  if (indent == 0)
-    fprintf (file, " ");
-  else
-    indent_to (file, indent + 4);
-  cxx_print_binding (file, IDENTIFIER_BINDING (node), "local bindings");
+  fprintf (file, "local bindings <%p>", (void *) IDENTIFIER_BINDING (node));
   print_node (file, "label", IDENTIFIER_LABEL_VALUE (node), indent + 4);
   print_node (file, "template", IDENTIFIER_TEMPLATE (node), indent + 4);
 }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]