name-lookup.c (find_local_binding): New, broken out of ...
authorNathan Sidwell <nathan@acm.org>
Thu, 18 May 2017 10:49:48 +0000 (10:49 +0000)
committerNathan Sidwell <nathan@gcc.gnu.org>
Thu, 18 May 2017 10:49:48 +0000 (10:49 +0000)
* name-lookup.c (find_local_binding): New, broken out of ...
(lookup_name_innermost_nonclass_level_1): ... here.  Call it.
(set_namespace_binding): Swap scope & name args.
(namespace_binding_1): Likewise.
(pushdecl_maybe_friend_1): Adjust set_namespace_binding call.
(push_overloaded_decl_1): Likewise.
(set_global_binding): Likewise.
(get_namespace_binding): Adjust namespace_binding_1 call.

From-SVN: r248191

gcc/cp/ChangeLog
gcc/cp/name-lookup.c

index c404cedc7833e80ab3ab1ff7a889aef3fea457cd..3936877a09049c8199687a9bc77e5c10adb5494a 100644 (file)
@@ -1,3 +1,14 @@
+2017-05-18  Nathan Sidwell  <nathan@acm.org>
+
+       * name-lookup.c (find_local_binding): New, broken out of ...
+       (lookup_name_innermost_nonclass_level_1): ... here.  Call it.
+       (set_namespace_binding): Swap scope & name args.
+       (namespace_binding_1): Likewise.
+       (pushdecl_maybe_friend_1): Adjust set_namespace_binding call.
+       (push_overloaded_decl_1): Likewise.
+       (set_global_binding): Likewise.
+       (get_namespace_binding): Adjust namespace_binding_1 call.
+
 2017-05-17  Nathan Sidwell  <nathan@acm.org>
 
        * cp-tree.h (default_hash_traits <lang_identifier *>): New
index 83ef7c7423013d3588b781b57f9ebaf57af974ac..c94aeb56183f189c41d0e9c3fcbf26929447dc61 100644 (file)
@@ -37,7 +37,7 @@ static cxx_binding *cxx_binding_make (tree value, tree type);
 static cp_binding_level *innermost_nonclass_level (void);
 static void set_identifier_type_value_with_scope (tree id, tree decl,
                                                  cp_binding_level *b);
-static void set_namespace_binding (tree name, tree scope, tree val);
+static void set_namespace_binding (tree scope, tree name, tree val);
 
 /* The bindings for a particular name in a particular scope.  */
 
@@ -99,6 +99,26 @@ add_decl_to_level (tree decl, cp_binding_level *b)
     }
 }
 
+/* Find the binding for NAME in the local binding level B.  */
+
+static cxx_binding *
+find_local_binding (cp_binding_level *b, tree name)
+{
+  if (cxx_binding *binding = IDENTIFIER_BINDING (name))
+    for (;; b = b->level_chain)
+      {
+       if (binding->scope == b
+           && !(VAR_P (binding->value)
+                && DECL_DEAD_FOR_LOCAL (binding->value)))
+         return binding;
+
+       /* Cleanup contours are transparent to the language.  */
+       if (b->kind != sk_cleanup)
+         break;
+      }
+  return NULL;
+}
+
 /* [basic.lookup.koenig] */
 /* A nonzero return value in the functions below indicates an error.  */
 
@@ -1778,7 +1798,7 @@ pushdecl_maybe_friend_1 (tree x, bool is_friend)
                  || TREE_CODE (x) == NAMESPACE_DECL
                  || TREE_CODE (x) == CONST_DECL
                  || TREE_CODE (x) == TEMPLATE_DECL))
-           set_namespace_binding (name, current_namespace, x);
+           set_namespace_binding (current_namespace, name, x);
 
          /* If new decl is `static' and an `extern' was seen previously,
             warn about it.  */
@@ -2952,7 +2972,7 @@ push_overloaded_decl_1 (tree decl, int flags, bool is_friend)
     new_binding = decl;
 
   if (doing_global)
-    set_namespace_binding (name, current_namespace, new_binding);
+    set_namespace_binding (current_namespace, name, new_binding);
   else
     {
       /* We only create an OVERLOAD if there was a previous binding at
@@ -3964,7 +3984,7 @@ do_class_using_decl (tree scope, tree name)
 
 
 static tree
-namespace_binding_1 (tree name, tree scope)
+namespace_binding_1 (tree scope, tree name)
 {
   cxx_binding *binding;
 
@@ -3988,13 +4008,13 @@ get_namespace_binding (tree ns, tree name)
   bool subtime = timevar_cond_start (TV_NAME_LOOKUP);
   if (!ns)
     ns = global_namespace;
-  tree ret = namespace_binding_1 (name, ns);
+  tree ret = namespace_binding_1 (ns, name);
   timevar_cond_stop (TV_NAME_LOOKUP, subtime);
   return ret;
 }
 
 static void
-set_namespace_binding (tree name, tree scope, tree val)
+set_namespace_binding (tree scope, tree name, tree val)
 {
   cxx_binding *b;
 
@@ -4020,7 +4040,7 @@ set_global_binding (tree name, tree val)
 {
   bool subtime = timevar_cond_start (TV_NAME_LOOKUP);
 
-  set_namespace_binding (name, global_namespace, val);
+  set_namespace_binding (global_namespace, name, val);
 
   timevar_cond_stop (TV_NAME_LOOKUP, subtime);
 }
@@ -5760,39 +5780,14 @@ lookup_type_scope (tree name, tag_scope scope)
 static tree
 lookup_name_innermost_nonclass_level_1 (tree name)
 {
-  cp_binding_level *b;
-  tree t = NULL_TREE;
-
-  b = innermost_nonclass_level ();
+  cp_binding_level *b = innermost_nonclass_level ();
 
   if (b->kind == sk_namespace)
-    {
-      t = get_namespace_binding (current_namespace, name);
-
-      /* extern "C" function() */
-      if (t != NULL_TREE && TREE_CODE (t) == TREE_LIST)
-       t = TREE_VALUE (t);
-    }
-  else if (IDENTIFIER_BINDING (name)
-          && LOCAL_BINDING_P (IDENTIFIER_BINDING (name)))
-    {
-      cxx_binding *binding;
-      binding = IDENTIFIER_BINDING (name);
-      while (1)
-       {
-         if (binding->scope == b
-             && !(VAR_P (binding->value)
-                  && DECL_DEAD_FOR_LOCAL (binding->value)))
-           return binding->value;
-
-         if (b->kind == sk_cleanup)
-           b = b->level_chain;
-         else
-           break;
-       }
-    }
-
-  return t;
+    return namespace_binding_1 (current_namespace, name);
+  else if (cxx_binding *binding = find_local_binding (b, name))
+    return binding->value;
+  else
+    return NULL_TREE;
 }
 
 /* Wrapper for lookup_name_innermost_nonclass_level_1.  */