From 98c28dd4ba5bc2fe9141f44aeed7d59a07012018 Mon Sep 17 00:00:00 2001
From: Nathan Sidwell <nathan@acm.org>
Date: Tue, 30 May 2017 19:12:35 +0000
Subject: [PATCH] Kill IDENTIFIER_NAMESPACE_BINDINGS

	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.

From-SVN: r248694
---
 gcc/cp/ChangeLog     | 10 ++++++++++
 gcc/cp/cp-tree.h     | 10 +++++++---
 gcc/cp/lex.c         |  6 +++++-
 gcc/cp/name-lookup.c | 23 ++++++++---------------
 gcc/cp/ptree.c       | 15 +--------------
 5 files changed, 31 insertions(+), 33 deletions(-)

diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 1e4685f0756d..3da2f979e4dc 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,5 +1,15 @@
 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.
+
 	* cp-tree.def (OVERLOAD): Fix comment.
 	* cp-tree.h: Fix comments and whitespace.
 	* error.c (dump_decl): Use pp_cxx_colon_colon, ovl_scope.
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index a01e76a228d5..d6713f19e8f9 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -535,7 +535,6 @@ extern GTY(()) tree cp_global_trees[CPTI_MAX];
 
 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) \
diff --git a/gcc/cp/lex.c b/gcc/cp/lex.c
index a9c38ff24a34..1b4eb35e7657 100644
--- a/gcc/cp/lex.c
+++ b/gcc/cp/lex.c
@@ -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);
diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c
index 7f58682f594b..e4d60744f9b7 100644
--- a/gcc/cp/name-lookup.c
+++ b/gcc/cp/name-lookup.c
@@ -86,25 +86,18 @@ create_local_binding (cp_binding_level *level, tree name)
 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
diff --git a/gcc/cp/ptree.c b/gcc/cp/ptree.c
index f8e879ef6567..5775e07dbbd5 100644
--- a/gcc/cp/ptree.c
+++ b/gcc/cp/ptree.c
@@ -171,14 +171,6 @@ cxx_print_type (FILE *file, tree node, int indent)
     }
 }
 
-
-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 node, int indent)
     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);
 }
-- 
GitLab