cp-tree.h (IDENTIFIER_GLOBAL_VALUE): Use get_namespace_value.
authorNathan Sidwell <nathan@acm.org>
Fri, 5 May 2017 20:04:45 +0000 (20:04 +0000)
committerNathan Sidwell <nathan@gcc.gnu.org>
Fri, 5 May 2017 20:04:45 +0000 (20:04 +0000)
* cp-tree.h (IDENTIFIER_GLOBAL_VALUE): Use get_namespace_value.
(SET_IDENTIFIER_GLOBAL_VALUE): Use set_global_value.
(IDENTIFIER_NAMESPACE_VALUE): Delete.
* name-lookup.h (namespace_binding, set_namespace_binding):
Replace
with ...
(get_namespace_value, set_global_value): ... these.
(get_global_value_if_present, is_typename_at_global_scope):
Delete.
* decl.c (poplevel): Use get_namespace_value.
(grokdeclarator): Use IDENTIFIER_GLOBAL_VALUE.
* class.c (build_vtbl_initializer): Stash library decl in
static var. Use IDENTIFIER_GLOBAL_VALUE.
* except.c (do_get_exception_ptr, do_begin_catch, do_end_catch)
do_allocate_exception, do_free_exception, build_throw): Likewise.
* init.c (throw_bad_array_new_length): Likewise.
* rtti.c (throw_bad_cast, throw_bad_typeid): Likewise.
* name-lookup.c (arg_assoc_namespace, pushdecl_maybe_friend_1)
check_for_our_of_scope_variable, push_overloaded_decl_1): Use
get_namespace_value.
(set_namespace_binding_1): Rename to
(set_namespace_binding): ... here.
(set_global_value): New.
(lookup_name_innermost_nonclass_level_1, push_namespace): Use
get_namespace_value.
* pt.c (listify): Use get_namespace_value.
((--This line, and those below, will be ignored--

M    cp/name-lookup.c
M    cp/name-lookup.h
M    cp/ChangeLog
M    cp/except.c
M    cp/class.c
M    cp/pt.c
M    cp/init.c
M    cp/cp-tree.h
M    cp/decl.c
M    cp/rtti.c

From-SVN: r247654

gcc/cp/ChangeLog
gcc/cp/class.c
gcc/cp/cp-tree.h
gcc/cp/decl.c
gcc/cp/except.c
gcc/cp/init.c
gcc/cp/name-lookup.c
gcc/cp/name-lookup.h
gcc/cp/pt.c
gcc/cp/rtti.c

index eaeddb2f66e82d361154057296885d84552f36c9..f81b6863d0322e45a32b7a00831377aaf4d752bc 100644 (file)
@@ -1,5 +1,30 @@
 2017-05-05  Nathan Sidwell  <nathan@acm.org>
 
+       * cp-tree.h (IDENTIFIER_GLOBAL_VALUE): Use get_namespace_value.
+       (SET_IDENTIFIER_GLOBAL_VALUE): Use set_global_value.
+       (IDENTIFIER_NAMESPACE_VALUE): Delete.
+       * name-lookup.h (namespace_binding, set_namespace_binding): Replace
+       with ...
+       (get_namespace_value, set_global_value): ... these.
+       (get_global_value_if_present, is_typename_at_global_scope): Delete.
+       * decl.c (poplevel): Use get_namespace_value.
+       (grokdeclarator): Use IDENTIFIER_GLOBAL_VALUE.
+       * class.c (build_vtbl_initializer): Stash library decl in
+       static var. Use IDENTIFIER_GLOBAL_VALUE.
+       * except.c (do_get_exception_ptr, do_begin_catch, do_end_catch,
+       do_allocate_exception, do_free_exception, build_throw): Likewise.
+       * init.c (throw_bad_array_new_length): Likewise.
+       * rtti.c (throw_bad_cast, throw_bad_typeid): Likewise.
+       * name-lookup.c (arg_assoc_namespace, pushdecl_maybe_friend_1,
+       check_for_our_of_scope_variable, push_overloaded_decl_1): Use
+       get_namespace_value.
+       (set_namespace_binding_1): Rename to
+       (set_namespace_binding): ... here.
+       (set_global_value): New.
+       (lookup_name_innermost_nonclass_level_1, push_namespace): Use
+       get_namespace_value.
+       * pt.c (listify): Use get_namespace_value.
+
        * call.c (make_temporary_var_for_ref_to_temp): Push decl into
        current scope.
        * lex.c (unqualified_name_lookup_error): Likewise.
index f610c7700412d6e351552d708dc4060334ae4d95..945406e8bdbca53755208943311597abd1d87f07 100644 (file)
@@ -9769,11 +9769,18 @@ build_vtbl_initializer (tree binfo,
          /* Likewise for deleted virtuals.  */
          else if (DECL_DELETED_FN (fn_original))
            {
-             fn = get_identifier ("__cxa_deleted_virtual");
-             if (!get_global_value_if_present (fn, &fn))
-               fn = push_library_fn (fn, (build_function_type_list
-                                          (void_type_node, NULL_TREE)),
-                                     NULL_TREE, ECF_NORETURN);
+             static tree fn;
+
+             if (!fn)
+               {
+                 tree name = get_identifier ("__cxa_deleted_virtual");
+                 fn = IDENTIFIER_GLOBAL_VALUE (name);
+                 if (!fn)
+                   fn = push_library_fn
+                     (name,
+                      build_function_type_list (void_type_node, NULL_TREE),
+                      NULL_TREE, ECF_NORETURN);
+               }
              if (!TARGET_VTABLE_USES_DESCRIPTORS)
                init = fold_convert (vfunc_ptr_type_node,
                                     build_fold_addr_expr (fn));
index 8120b9332becb687027900bf3f2b04ca08b864b0..f8f9060efd68588ee00491f3b93a7b9431dffc45 100644 (file)
@@ -554,13 +554,9 @@ struct GTY(()) ptrmem_cst {
 typedef struct ptrmem_cst * ptrmem_cst_t;
 
 #define IDENTIFIER_GLOBAL_VALUE(NODE) \
-  namespace_binding ((NODE), global_namespace)
+  get_namespace_value (NULL_TREE, (NODE))
 #define SET_IDENTIFIER_GLOBAL_VALUE(NODE, VAL) \
-  set_namespace_binding ((NODE), global_namespace, (VAL))
-#define IDENTIFIER_NAMESPACE_VALUE(NODE) \
-  namespace_binding ((NODE), current_namespace)
-#define SET_IDENTIFIER_NAMESPACE_VALUE(NODE, VAL) \
-  set_namespace_binding ((NODE), current_namespace, (VAL))
+  set_global_value ((NODE), (VAL))
 
 #define CLEANUP_P(NODE)                TREE_LANG_FLAG_0 (TRY_BLOCK_CHECK (NODE))
 
index e182e4f43cf05bc39f7e29e9bc68f6069648a7e3..bbdbda753bef82977bf17d453b1e00d0bc33e15c 100644 (file)
@@ -687,16 +687,13 @@ poplevel (int keep, int reverse, int functionbody)
          && DECL_NAME (link))
        {
          tree name = DECL_NAME (link);
-         cxx_binding *ob;
-         tree ns_binding;
 
-         ob = outer_binding (name,
-                             IDENTIFIER_BINDING (name),
-                             /*class_p=*/true);
+         cxx_binding *ob = outer_binding (name,
+                                          IDENTIFIER_BINDING (name),
+                                          /*class_p=*/true);
+         tree ns_binding = NULL_TREE;
          if (!ob)
-           ns_binding = IDENTIFIER_NAMESPACE_VALUE (name);
-         else
-           ns_binding = NULL_TREE;
+           ns_binding = get_namespace_value (current_namespace, name);
 
          if (ob && ob->scope == current_binding_level->level_chain)
            /* We have something like:
@@ -10148,7 +10145,8 @@ grokdeclarator (const cp_declarator *declarator,
                    gcc_assert (flags == NO_SPECIAL);
                    flags = TYPENAME_FLAG;
                    sfk = sfk_conversion;
-                   if (is_typename_at_global_scope (dname))
+                   tree glob = IDENTIFIER_GLOBAL_VALUE (dname);
+                   if (glob && TREE_CODE (glob) == TYPE_DECL)
                      name = identifier_to_locale (IDENTIFIER_POINTER (dname));
                    else
                      name = "<invalid operator>";
index f65b717c32b567dc365bbeb68e1d275fe3725a83..b4fe07af4d0e6f1cf3e408568d6bb25b01359289 100644 (file)
@@ -154,14 +154,17 @@ declare_library_fn (tree name, tree return_type, tree parm_type, int ecf_flags)
 static tree
 do_get_exception_ptr (void)
 {
-  tree fn;
+  static tree fn;
 
-  fn = get_identifier ("__cxa_get_exception_ptr");
-  if (!get_global_value_if_present (fn, &fn))
+  if (!fn)
     {
-      /* Declare void* __cxa_get_exception_ptr (void *) throw().  */
-      fn = declare_library_fn (fn, ptr_type_node, ptr_type_node,
-                              ECF_NOTHROW | ECF_PURE | ECF_LEAF | ECF_TM_PURE);
+      tree name = get_identifier ("__cxa_get_exception_ptr");
+      fn = IDENTIFIER_GLOBAL_VALUE (name);
+      if (!fn)
+       /* Declare void* __cxa_get_exception_ptr (void *) throw().  */
+       fn = declare_library_fn
+         (name, ptr_type_node, ptr_type_node,
+          ECF_NOTHROW | ECF_PURE | ECF_LEAF | ECF_TM_PURE);
     }
 
   return cp_build_function_call_nary (fn, tf_warning_or_error,
@@ -174,22 +177,29 @@ do_get_exception_ptr (void)
 static tree
 do_begin_catch (void)
 {
-  tree fn;
+  static tree fn;
 
-  fn = get_identifier ("__cxa_begin_catch");
-  if (!get_global_value_if_present (fn, &fn))
+  if (!fn)
     {
-      /* Declare void* __cxa_begin_catch (void *) throw().  */
-      fn = declare_library_fn (fn, ptr_type_node, ptr_type_node, ECF_NOTHROW);
-
-      /* Create its transactional-memory equivalent.  */
-      if (flag_tm)
+      tree name = fn = get_identifier ("__cxa_begin_catch");
+      fn = IDENTIFIER_GLOBAL_VALUE (name);
+      if (!fn)
        {
-         tree fn2 = get_identifier ("_ITM_cxa_begin_catch");
-         if (!get_global_value_if_present (fn2, &fn2))
-           fn2 = declare_library_fn (fn2, ptr_type_node,
-                                     ptr_type_node, ECF_NOTHROW | ECF_TM_PURE);
-         record_tm_replacement (fn, fn2);
+         /* Declare void* __cxa_begin_catch (void *) throw().  */
+         fn = declare_library_fn
+           (name, ptr_type_node, ptr_type_node, ECF_NOTHROW);
+
+         /* Create its transactional-memory equivalent.  */
+         if (flag_tm)
+           {
+             tree itm_name = get_identifier ("_ITM_cxa_begin_catch");
+             tree itm_fn = IDENTIFIER_GLOBAL_VALUE (itm_name);
+             if (!itm_fn)
+               itm_fn = declare_library_fn
+                 (itm_name, ptr_type_node, ptr_type_node,
+                  ECF_NOTHROW | ECF_TM_PURE);
+             record_tm_replacement (fn, itm_fn);
+           }
        }
     }
 
@@ -221,26 +231,32 @@ dtor_nothrow (tree type)
 static tree
 do_end_catch (tree type)
 {
-  tree fn, cleanup;
+  static tree fn;
 
-  fn = get_identifier ("__cxa_end_catch");
-  if (!get_global_value_if_present (fn, &fn))
+  if (!fn)
     {
-      /* Declare void __cxa_end_catch ().
-         This can throw if the destructor for the exception throws.  */
-      fn = push_void_library_fn (fn, void_list_node, 0);
-
-      /* Create its transactional-memory equivalent.  */
-      if (flag_tm)
+      tree name = get_identifier ("__cxa_end_catch");
+      fn = IDENTIFIER_GLOBAL_VALUE (name);
+      if (!fn)
        {
-         tree fn2 = get_identifier ("_ITM_cxa_end_catch");
-         if (!get_global_value_if_present (fn2, &fn2))
-           fn2 = push_void_library_fn (fn2, void_list_node, ECF_TM_PURE);
-         record_tm_replacement (fn, fn2);
+         /* Declare void __cxa_end_catch ().
+            This can throw if the destructor for the exception throws.  */
+         fn = push_void_library_fn (name, void_list_node, 0);
+
+         /* Create its transactional-memory equivalent.  */
+         if (flag_tm)
+           {
+             tree itm_name = get_identifier ("_ITM_cxa_end_catch");
+             tree itm_fn = IDENTIFIER_GLOBAL_VALUE (itm_name);
+             if (!itm_fn)
+               itm_fn = push_void_library_fn
+                 (itm_name, void_list_node, ECF_TM_PURE);
+             record_tm_replacement (fn, itm_fn);
+           }
        }
     }
 
-  cleanup = cp_build_function_call_vec (fn, NULL, tf_warning_or_error);
+  tree cleanup = cp_build_function_call_vec (fn, NULL, tf_warning_or_error);
   TREE_NOTHROW (cleanup) = dtor_nothrow (type);
 
   return cleanup;
@@ -500,23 +516,28 @@ finish_eh_spec_block (tree raw_raises, tree eh_spec_block)
 static tree
 do_allocate_exception (tree type)
 {
-  tree fn;
+  static tree fn;
 
-  fn = get_identifier ("__cxa_allocate_exception");
-  if (!get_global_value_if_present (fn, &fn))
+  if (!fn)
     {
-      /* Declare void *__cxa_allocate_exception(size_t) throw().  */
-      fn = declare_library_fn (fn, ptr_type_node, size_type_node,
-                               ECF_NOTHROW | ECF_MALLOC);
-
-      if (flag_tm)
+      tree name = get_identifier ("__cxa_allocate_exception");
+      fn = IDENTIFIER_GLOBAL_VALUE (name);
+      if (!fn)
        {
-         tree fn2 = get_identifier ("_ITM_cxa_allocate_exception");
-         if (!get_global_value_if_present (fn2, &fn2))
-           fn2 = declare_library_fn (fn2, ptr_type_node,
-                                     size_type_node, 
-                                     ECF_NOTHROW | ECF_MALLOC | ECF_TM_PURE);
-         record_tm_replacement (fn, fn2);
+         /* Declare void *__cxa_allocate_exception(size_t) throw().  */
+         fn = declare_library_fn (name, ptr_type_node, size_type_node,
+                                  ECF_NOTHROW | ECF_MALLOC);
+
+         if (flag_tm)
+           {
+             tree itm_name = get_identifier ("_ITM_cxa_allocate_exception");
+             tree itm_fn = IDENTIFIER_GLOBAL_VALUE (itm_name);
+             if (!itm_fn)
+               itm_fn = declare_library_fn
+                 (itm_name, ptr_type_node, size_type_node, 
+                  ECF_NOTHROW | ECF_MALLOC | ECF_TM_PURE);
+             record_tm_replacement (fn, itm_fn);
+           }
        }
     }
 
@@ -530,23 +551,28 @@ do_allocate_exception (tree type)
 static tree
 do_free_exception (tree ptr)
 {
-  tree fn;
+  static tree fn;
 
-  fn = get_identifier ("__cxa_free_exception");
-  if (!get_global_value_if_present (fn, &fn))
+  if (!fn)
     {
-      /* Declare void __cxa_free_exception (void *) throw().  */
-      fn = declare_library_fn (fn, void_type_node, ptr_type_node,
-                              ECF_NOTHROW | ECF_LEAF);
-
-      if (flag_tm)
+      tree name = get_identifier ("__cxa_free_exception");
+      fn = IDENTIFIER_GLOBAL_VALUE (name);
+      if (!fn)
        {
-         tree fn2 = get_identifier ("_ITM_cxa_free_exception");
-         if (!get_global_value_if_present (fn2, &fn2))
-           fn2 = declare_library_fn (fn2, void_type_node,
-                                     ptr_type_node,
-                                     ECF_NOTHROW | ECF_LEAF | ECF_TM_PURE);
-         record_tm_replacement (fn, fn2);
+         /* Declare void __cxa_free_exception (void *) throw().  */
+         fn = declare_library_fn (name, void_type_node, ptr_type_node,
+                                  ECF_NOTHROW | ECF_LEAF);
+
+         if (flag_tm)
+           {
+             tree itm_name = get_identifier ("_ITM_cxa_free_exception");
+             tree itm_fn = IDENTIFIER_GLOBAL_VALUE (itm_name);
+             if (!itm_fn)
+               itm_fn = declare_library_fn
+                 (itm_name, void_type_node, ptr_type_node,
+                  ECF_NOTHROW | ECF_LEAF | ECF_TM_PURE);
+             record_tm_replacement (fn, itm_fn);
+           }
        }
     }
 
@@ -588,8 +614,6 @@ wrap_cleanups_r (tree *tp, int *walk_subtrees, void * /*data*/)
 tree
 build_throw (tree exp)
 {
-  tree fn;
-
   if (exp == error_mark_node)
     return exp;
 
@@ -616,6 +640,7 @@ build_throw (tree exp)
 
   if (exp)
     {
+      static tree throw_fn;
       tree throw_type;
       tree temp_type;
       tree cleanup;
@@ -631,23 +656,28 @@ build_throw (tree exp)
          cleanup_type = build_pointer_type (tmp);
        }
 
-      fn = get_identifier ("__cxa_throw");
-      if (!get_global_value_if_present (fn, &fn))
+      if (!throw_fn)
        {
-         /* Declare void __cxa_throw (void*, void*, void (*)(void*)).  */
-         /* ??? Second argument is supposed to be "std::type_info*".  */
-         tmp = build_function_type_list (void_type_node,
-                                         ptr_type_node, ptr_type_node,
-                                         cleanup_type, NULL_TREE);
-         fn = push_throw_library_fn (fn, tmp);
-
-         if (flag_tm)
+         tree name = get_identifier ("__cxa_throw");
+         throw_fn = IDENTIFIER_GLOBAL_VALUE (name);
+         if (!throw_fn)
            {
-             tree fn2 = get_identifier ("_ITM_cxa_throw");
-             if (!get_global_value_if_present (fn2, &fn2))
-               fn2 = push_throw_library_fn (fn2, tmp);
-             apply_tm_attr (fn2, get_identifier ("transaction_pure"));
-             record_tm_replacement (fn, fn2);
+             /* Declare void __cxa_throw (void*, void*, void (*)(void*)).  */
+             /* ??? Second argument is supposed to be "std::type_info*".  */
+             tmp = build_function_type_list (void_type_node,
+                                             ptr_type_node, ptr_type_node,
+                                             cleanup_type, NULL_TREE);
+             throw_fn = push_throw_library_fn (name, tmp);
+
+             if (flag_tm)
+               {
+                 tree itm_name = get_identifier ("_ITM_cxa_throw");
+                 tree itm_fn = IDENTIFIER_GLOBAL_VALUE (itm_name);
+                 if (!itm_fn)
+                   itm_fn = push_throw_library_fn (itm_name, tmp);
+                 apply_tm_attr (itm_fn, get_identifier ("transaction_pure"));
+                 record_tm_replacement (throw_fn, itm_fn);
+               }
            }
        }
 
@@ -739,22 +769,22 @@ build_throw (tree exp)
       cleanup = NULL_TREE;
       if (type_build_dtor_call (TREE_TYPE (object)))
        {
-         tree fn = lookup_fnfields (TYPE_BINFO (TREE_TYPE (object)),
-                                    complete_dtor_identifier, 0);
-         fn = BASELINK_FUNCTIONS (fn);
-         mark_used (fn);
+         tree dtor_fn = lookup_fnfields (TYPE_BINFO (TREE_TYPE (object)),
+                                         complete_dtor_identifier, 0);
+         dtor_fn = BASELINK_FUNCTIONS (dtor_fn);
+         mark_used (dtor_fn);
          if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TREE_TYPE (object)))
            {
-             cxx_mark_addressable (fn);
+             cxx_mark_addressable (dtor_fn);
              /* Pretend it's a normal function.  */
-             cleanup = build1 (ADDR_EXPR, cleanup_type, fn);
+             cleanup = build1 (ADDR_EXPR, cleanup_type, dtor_fn);
            }
        }
       if (cleanup == NULL_TREE)
        cleanup = build_int_cst (cleanup_type, 0);
 
       /* ??? Indicate that this function call throws throw_type.  */
-      tmp = cp_build_function_call_nary (fn, tf_warning_or_error,
+      tmp = cp_build_function_call_nary (throw_fn, tf_warning_or_error,
                                         ptr, throw_type, cleanup, NULL_TREE);
 
       /* Tack on the initialization stuff.  */
@@ -763,21 +793,24 @@ build_throw (tree exp)
   else
     {
       /* Rethrow current exception.  */
+      static tree rethrow_fn;
 
-      tree fn = get_identifier ("__cxa_rethrow");
-      if (!get_global_value_if_present (fn, &fn))
+      if (!rethrow_fn)
        {
-         /* Declare void __cxa_rethrow (void).  */
-         fn = push_throw_library_fn
-           (fn, build_function_type_list (void_type_node, NULL_TREE));
-       }
+         tree name = get_identifier ("__cxa_rethrow");
+         rethrow_fn = IDENTIFIER_GLOBAL_VALUE (name);
+         if (!rethrow_fn)
+           /* Declare void __cxa_rethrow (void).  */
+           rethrow_fn = push_throw_library_fn
+             (name, build_function_type_list (void_type_node, NULL_TREE));
 
-      if (flag_tm)
-       apply_tm_attr (fn, get_identifier ("transaction_pure"));
+         if (flag_tm)
+           apply_tm_attr (rethrow_fn, get_identifier ("transaction_pure"));
+       }
 
       /* ??? Indicate that this function call allows exceptions of the type
         of the enclosing catch block (if known).  */
-      exp = cp_build_function_call_vec (fn, NULL, tf_warning_or_error);
+      exp = cp_build_function_call_vec (rethrow_fn, NULL, tf_warning_or_error);
     }
 
   exp = build1 (THROW_EXPR, void_type_node, exp);
index e9c39ff25e6df09d8bedb454e6949a323ba2e7ed..00916d73a9103f3cb3c5d64047d383426dd0fd60 100644 (file)
@@ -2402,10 +2402,16 @@ diagnose_uninitialized_cst_or_ref_member (tree type, bool using_new, bool compla
 tree
 throw_bad_array_new_length (void)
 {
-  tree fn = get_identifier ("__cxa_throw_bad_array_new_length");
-  if (!get_global_value_if_present (fn, &fn))
-    fn = push_throw_library_fn (fn, build_function_type_list (sizetype,
-                                                             NULL_TREE));
+  static tree fn;
+  if (!fn)
+    {
+      tree name = get_identifier ("__cxa_throw_bad_array_new_length");
+
+      fn = IDENTIFIER_GLOBAL_VALUE (name);
+      if (!fn)
+       fn = push_throw_library_fn
+         (name, build_function_type_list (sizetype, NULL_TREE));
+    }
 
   return build_cxx_call (fn, 0, NULL, tf_warning_or_error);
 }
index b88fdeb5fbe6d8c7eafc21730a034128ec16be9a..f820c88cdd54eefce4b06b2a2f25197e91c1ce31 100644 (file)
@@ -37,6 +37,8 @@ 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);
+
 /* The bindings for a particular name in a particular scope.  */
 
 struct scope_binding {
@@ -213,7 +215,7 @@ arg_assoc_namespace (struct arg_lookup *k, tree scope)
       if (arg_assoc_namespace (k, TREE_PURPOSE (value)))
        return true;
 
-  value = namespace_binding (k->name, scope);
+  value = get_namespace_value (scope, k->name);
   if (!value)
     return false;
 
@@ -1248,7 +1250,7 @@ pushdecl_maybe_friend_1 (tree x, bool is_friend)
       /* In case this decl was explicitly namespace-qualified, look it
         up in its namespace context.  */
       if (DECL_NAMESPACE_SCOPE_P (x) && namespace_bindings_p ())
-       t = namespace_binding (name, DECL_CONTEXT (x));
+       t = get_namespace_value (DECL_CONTEXT (x), name);
       else
        t = lookup_name_innermost_nonclass_level (name);
 
@@ -1265,7 +1267,7 @@ pushdecl_maybe_friend_1 (tree x, bool is_friend)
          t = innermost_non_namespace_value (name);
          /* Or in the innermost namespace.  */
          if (! t)
-           t = namespace_binding (name, DECL_CONTEXT (x));
+           t = get_namespace_value (DECL_CONTEXT (x), name);
          /* Does it have linkage?  Note that if this isn't a DECL, it's an
             OVERLOAD, which is OK.  */
          if (t && DECL_P (t) && ! (TREE_STATIC (t) || DECL_EXTERNAL (t)))
@@ -1519,7 +1521,7 @@ pushdecl_maybe_friend_1 (tree x, bool is_friend)
        {
          tree decl;
 
-         decl = IDENTIFIER_NAMESPACE_VALUE (name);
+         decl = get_namespace_value (current_namespace, name);
          if (decl && TREE_CODE (decl) == OVERLOAD)
            decl = OVL_FUNCTION (decl);
 
@@ -1556,7 +1558,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_IDENTIFIER_NAMESPACE_VALUE (name, x);
+           set_namespace_binding (name, current_namespace, x);
 
          /* If new decl is `static' and an `extern' was seen previously,
             warn about it.  */
@@ -1566,7 +1568,7 @@ pushdecl_maybe_friend_1 (tree x, bool is_friend)
       else
        {
          /* Here to install a non-global value.  */
-         tree oldglobal = IDENTIFIER_NAMESPACE_VALUE (name);
+         tree oldglobal = get_namespace_value (current_namespace, name);
          tree oldlocal = NULL_TREE;
          cp_binding_level *oldscope = NULL;
          cxx_binding *oldbinding = outer_binding (name, NULL, true);
@@ -1605,7 +1607,8 @@ pushdecl_maybe_friend_1 (tree x, bool is_friend)
                oldlocal = DECL_SHADOWED_FOR_VAR (oldlocal);
 
              if (oldlocal == NULL_TREE)
-               oldlocal = IDENTIFIER_NAMESPACE_VALUE (DECL_NAME (d));
+               oldlocal
+                 = get_namespace_value (current_namespace, DECL_NAME (d));
            }
 
          /* If this is an extern function declaration, see if we
@@ -1969,7 +1972,7 @@ check_for_out_of_scope_variable (tree decl)
     shadowed = DECL_HAS_SHADOWED_FOR_VAR_P (shadowed)
       ? DECL_SHADOWED_FOR_VAR (shadowed) : NULL_TREE;
   if (!shadowed)
-    shadowed = IDENTIFIER_NAMESPACE_VALUE (DECL_NAME (decl));
+    shadowed = get_namespace_value (current_namespace, DECL_NAME (decl));
   if (shadowed)
     {
       if (!DECL_ERROR_REPORTED (decl))
@@ -2931,7 +2934,7 @@ push_overloaded_decl_1 (tree decl, int flags, bool is_friend)
   int doing_global = (namespace_bindings_p () || !(flags & PUSH_LOCAL));
 
   if (doing_global)
-    old = namespace_binding (name, DECL_CONTEXT (decl));
+    old = get_namespace_value (DECL_CONTEXT (decl), name);
   else
     old = lookup_name_innermost_nonclass_level (name);
 
@@ -4016,20 +4019,22 @@ namespace_binding_1 (tree name, tree scope)
   return binding ? binding->value : NULL_TREE;
 }
 
+/* Return the binding for NAME in NS.  If NS is NULL, look in
+   global_namespace.  */
+
 tree
-namespace_binding (tree name, tree scope)
+get_namespace_value (tree ns, tree name)
 {
-  tree ret;
   bool subtime = timevar_cond_start (TV_NAME_LOOKUP);
-  ret = namespace_binding_1 (name, scope);
+  if (!ns)
+    ns = global_namespace;
+  tree ret = namespace_binding_1 (name, ns);
   timevar_cond_stop (TV_NAME_LOOKUP, subtime);
   return ret;
 }
 
-/* Set the binding value for name in scope.  */
-
 static void
-set_namespace_binding_1 (tree name, tree scope, tree val)
+set_namespace_binding (tree name, tree scope, tree val)
 {
   cxx_binding *b;
 
@@ -4047,13 +4052,16 @@ set_namespace_binding_1 (tree name, tree scope, tree val)
     supplement_binding (b, val);
 }
 
-/* Wrapper for set_namespace_binding_1.  */
+/* Set NAME in the global namespace to VAL.  Does not add it to the
+   list of things in the namespace.  */
 
 void
-set_namespace_binding (tree name, tree scope, tree val)
+set_global_value (tree name, tree val)
 {
   bool subtime = timevar_cond_start (TV_NAME_LOOKUP);
-  set_namespace_binding_1 (name, scope, val);
+
+  set_namespace_binding (name, global_namespace, val);
+
   timevar_cond_stop (TV_NAME_LOOKUP, subtime);
 }
 
@@ -5815,7 +5823,7 @@ lookup_name_innermost_nonclass_level_1 (tree name)
 
   if (b->kind == sk_namespace)
     {
-      t = IDENTIFIER_NAMESPACE_VALUE (name);
+      t = get_namespace_value (current_namespace, name);
 
       /* extern "C" function() */
       if (t != NULL_TREE && TREE_CODE (t) == TREE_LIST)
@@ -6467,7 +6475,7 @@ push_namespace (tree name)
   if (anon)
     {
       name = anon_identifier;
-      d = IDENTIFIER_NAMESPACE_VALUE (name);
+      d = get_namespace_value (current_namespace, name);
       if (d)
        /* Reopening anonymous namespace.  */
        need_new = false;
@@ -6476,7 +6484,7 @@ push_namespace (tree name)
   else
     {
       /* Check whether this is an extended namespace definition.  */
-      d = IDENTIFIER_NAMESPACE_VALUE (name);
+      d = get_namespace_value (current_namespace, name);
       if (d != NULL_TREE && TREE_CODE (d) == NAMESPACE_DECL)
        {
          tree dna = DECL_NAMESPACE_ALIAS (d);
index a0b61d398089328b7308e690ddb6d105c62ec3ad..20845d314a62eef67dd51f5543c6a1af914f0817 100644 (file)
@@ -311,8 +311,8 @@ extern tree pushdecl_with_scope (tree, cp_binding_level *, bool);
 extern tree lookup_name_prefer_type (tree, int);
 extern tree lookup_name_real (tree, int, int, bool, int, int);
 extern tree lookup_type_scope (tree, tag_scope);
-extern tree namespace_binding (tree, tree);
-extern void set_namespace_binding (tree, tree, tree);
+extern tree get_namespace_value (tree ns, tree id);
+extern void set_global_value (tree id, tree val);
 extern bool hidden_name_p (tree);
 extern tree remove_hidden_names (tree);
 extern tree lookup_qualified_name (tree, tree, int, bool, /*hidden*/bool = false);
@@ -342,26 +342,4 @@ extern tree innermost_non_namespace_value (tree);
 extern cxx_binding *outer_binding (tree, cxx_binding *, bool);
 extern void cp_emit_debug_info_for_using (tree, tree);
 
-/* Set *DECL to the (non-hidden) declaration for ID at global scope,
-   if present and return true; otherwise return false.  */
-
-inline bool
-get_global_value_if_present (tree id, tree *decl)
-{
-  tree global_value = namespace_binding (id, global_namespace);
-  if (global_value)
-    *decl = global_value;
-  return global_value != NULL;
-}
-
-/* True is the binding of IDENTIFIER at global scope names a type.  */
-
-inline bool
-is_typename_at_global_scope (tree id)
-{
-  tree global_value = namespace_binding (id, global_namespace);
-
-  return global_value && TREE_CODE (global_value) == TYPE_DECL;
-}
-
 #endif /* GCC_CP_NAME_LOOKUP_H */
index c4d402efd0a7684b0029346c2b5772593a04b84b..61c3ac0c540bb445b13e6b946ff7b6e5922d957e 100644 (file)
@@ -24731,7 +24731,7 @@ make_constrained_auto (tree con, tree args)
 static tree
 listify (tree arg)
 {
-  tree std_init_list = namespace_binding (init_list_identifier, std_node);
+  tree std_init_list = get_namespace_value (std_node, init_list_identifier);
   tree argvec;
   if (!std_init_list || !DECL_CLASS_TEMPLATE_P (std_init_list))
     {    
index 94b8fe754835e6818bbb7d310980a2a8e46acb10..89d18914adfe6d87d80225ce250fab3aec483b70 100644 (file)
@@ -202,10 +202,15 @@ build_headof (tree exp)
 static tree
 throw_bad_cast (void)
 {
-  tree fn = get_identifier ("__cxa_bad_cast");
-  if (!get_global_value_if_present (fn, &fn))
-    fn = push_throw_library_fn (fn, build_function_type_list (ptr_type_node,
-                                                             NULL_TREE));
+  static tree fn;
+  if (!fn)
+    {
+      tree name = get_identifier ("__cxa_bad_cast");
+      fn = IDENTIFIER_GLOBAL_VALUE (name);
+      if (!fn)
+       fn = push_throw_library_fn
+         (name, build_function_type_list (ptr_type_node, NULL_TREE));
+    }
 
   return build_cxx_call (fn, 0, NULL, tf_warning_or_error);
 }
@@ -216,14 +221,17 @@ throw_bad_cast (void)
 static tree
 throw_bad_typeid (void)
 {
-  tree fn = get_identifier ("__cxa_bad_typeid");
-  if (!get_global_value_if_present (fn, &fn))
+  static tree fn;
+  if (!fn)
     {
-      tree t;
-
-      t = build_reference_type (const_type_info_type_node);
-      t = build_function_type_list (t, NULL_TREE);
-      fn = push_throw_library_fn (fn, t);
+      tree name = get_identifier ("__cxa_bad_typeid");
+      fn = IDENTIFIER_GLOBAL_VALUE (name);
+      if (!fn)
+       {
+         tree t = build_reference_type (const_type_info_type_node);
+         t = build_function_type_list (t, NULL_TREE);
+         fn = push_throw_library_fn (name, t);
+       }
     }
 
   return build_cxx_call (fn, 0, NULL, tf_warning_or_error);