As mentioned yesterday, there's now no need for set_global_binding to
have separate name & decl parms. This patch makes that change and kills
IDENTIFIER_GLOBAL_VALUE and SET_IDENTIFIER_GLOBAL_VALUE, which are have
been forwarding macros for a long time now.
Because get_namespace_binding has the namespace arg first, we can't
simply use a default arg there -- and swapping them round is
incompatible with the rest of the name-lookup argument conventions. So
get_global_binding is simple inline wrapper to that. (I decided to keep
the NULL == global_namespace idiom to avoid each call instance having to
go get the global_node.)
I discovered we had an identifier_global_value function already, used
directly by c-common.c. I moved it to cp-objcp-common.c. I declined
the opportunity to hookize it :)
Applying to trunk.
nathan
--
Nathan Sidwell
2017-10-05 Nathan Sidwell <nat...@acm.org>
Kill IDENTIFIER_GLOBAL_VALUE, SET_IDENTIFIER_GLOBAL_VALUE
* cp-tree.h (IDENTIFIER_GLOBAL_VALUE,
SET_IDENTIFIER_GLOBAL_VALUE): Delete.
* name-lookup.h (set_global_binding): Remove NAME parm.
(get_global_binding): New inline fn.
* name-lookup.c (set_global_binding): Remove NAME parm. Adjust.
(identifier_global_value): Move to ...
* cp-objcp-common.c (identifier_global_value): ... here.
* class.c (build_ctor_vtbl_group, build_vtbl_initializer): Adjust.
* decl.c (record_builtin_type, expand_static_init,
grokdeclarator): Adjust.
* decl2.c (get_guard, get_local_tls_init_fn, get_tls_init_fn,
get_tls_wrapper_fn, maybe_warn_sized_delete): Adjust.
* except.c (declare_library_fn, build_throw): Adjust.
* init.c (throw_bad_array_length): Adjust.
* rtti.c (throw_bad_cast, throw_bad_typeid, get_tinfo_decl): Adjust.
Index: class.c
===================================================================
--- class.c (revision 253413)
+++ class.c (working copy)
@@ -8912,7 +8912,7 @@ build_ctor_vtbl_group (tree binfo, tree
/* See if we've already created this construction vtable group. */
id = mangle_ctor_vtbl_for_type (t, binfo);
- if (IDENTIFIER_GLOBAL_VALUE (id))
+ if (get_global_binding (id))
return;
gcc_assert (!SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), t));
@@ -9294,7 +9294,7 @@ build_vtbl_initializer (tree binfo,
if (!dvirt_fn)
{
tree name = get_identifier ("__cxa_deleted_virtual");
- dvirt_fn = IDENTIFIER_GLOBAL_VALUE (name);
+ dvirt_fn = get_global_binding (name);
if (!dvirt_fn)
dvirt_fn = push_library_fn
(name,
Index: cp-objcp-common.c
===================================================================
--- cp-objcp-common.c (revision 253413)
+++ cp-objcp-common.c (working copy)
@@ -400,6 +400,15 @@ cp_pushdecl (tree decl)
return pushdecl (decl);
}
+/* Get the global value binding of NAME. Called directly from
+ c-common.c, not via a hook. */
+
+tree
+identifier_global_value (tree name)
+{
+ return get_global_binding (name);
+}
+
/* Register c++-specific dumps. */
void
Index: cp-tree.h
===================================================================
--- cp-tree.h (revision 253421)
+++ cp-tree.h (working copy)
@@ -613,11 +613,6 @@ struct GTY(()) ptrmem_cst {
};
typedef struct ptrmem_cst * ptrmem_cst_t;
-#define IDENTIFIER_GLOBAL_VALUE(NODE) \
- get_namespace_binding (NULL_TREE, (NODE))
-#define SET_IDENTIFIER_GLOBAL_VALUE(NODE, VAL) \
- set_global_binding ((NODE), (VAL))
-
#define CLEANUP_P(NODE) TREE_LANG_FLAG_0 (TRY_BLOCK_CHECK (NODE))
#define BIND_EXPR_TRY_BLOCK(NODE) \
Index: decl.c
===================================================================
--- decl.c (revision 253426)
+++ decl.c (working copy)
@@ -3897,7 +3897,7 @@ make_unbound_class_template (tree contex
RID_POINTERS. NAME is the name used when looking up the builtin
type. TYPE is the _TYPE node for the builtin type.
- The calls to SET_IDENTIFIER_GLOBAL_VALUE below should be
+ The calls to set_global_binding below should be
eliminated. Built-in types should not be looked up name; their
names are keywords that the parser can recognize. However, there
is code in c-common.c that uses identifier_global_value to look up
@@ -3915,7 +3915,7 @@ record_builtin_type (enum rid rid_index,
tree tname = get_identifier (name);
tree tdecl = build_decl (BUILTINS_LOCATION, TYPE_DECL, tname, type);
DECL_ARTIFICIAL (tdecl) = 1;
- SET_IDENTIFIER_GLOBAL_VALUE (tname, tdecl);
+ set_global_binding (tdecl);
decl = tdecl;
}
@@ -3925,7 +3925,7 @@ record_builtin_type (enum rid rid_index,
{
tree rdecl = build_decl (BUILTINS_LOCATION, TYPE_DECL, rname, type);
DECL_ARTIFICIAL (rdecl) = 1;
- SET_IDENTIFIER_GLOBAL_VALUE (rname, rdecl);
+ set_global_binding (rdecl);
if (!decl)
decl = rdecl;
}
@@ -4509,7 +4509,7 @@ build_cp_library_fn_ptr (const char* nam
}
/* Like build_library_fn, but also pushes the function so that we will
- be able to find it via IDENTIFIER_GLOBAL_VALUE. Also, the function
+ be able to find it via get_global_binding. Also, the function
may throw exceptions listed in RAISES. */
tree
@@ -8055,9 +8055,9 @@ expand_static_init (tree decl, tree init
acquire_name = get_identifier ("__cxa_guard_acquire");
release_name = get_identifier ("__cxa_guard_release");
abort_name = get_identifier ("__cxa_guard_abort");
- acquire_fn = identifier_global_value (acquire_name);
- release_fn = identifier_global_value (release_name);
- abort_fn = identifier_global_value (abort_name);
+ acquire_fn = get_global_binding (acquire_name);
+ release_fn = get_global_binding (release_name);
+ abort_fn = get_global_binding (abort_name);
if (!acquire_fn)
acquire_fn = push_library_fn
(acquire_name, build_function_type_list (integer_type_node,
@@ -10126,7 +10126,7 @@ grokdeclarator (const cp_declarator *dec
gcc_assert (flags == NO_SPECIAL);
flags = TYPENAME_FLAG;
sfk = sfk_conversion;
- tree glob = IDENTIFIER_GLOBAL_VALUE (dname);
+ tree glob = get_global_binding (dname);
if (glob && TREE_CODE (glob) == TYPE_DECL)
name = identifier_to_locale (IDENTIFIER_POINTER (dname));
else
Index: decl2.c
===================================================================
--- decl2.c (revision 253440)
+++ decl2.c (working copy)
@@ -2985,7 +2985,7 @@ get_guard (tree decl)
tree guard;
sname = mangle_guard_variable (decl);
- guard = IDENTIFIER_GLOBAL_VALUE (sname);
+ guard = get_global_binding (sname);
if (! guard)
{
tree guard_type;
@@ -3153,7 +3153,7 @@ static tree
get_local_tls_init_fn (void)
{
tree sname = get_identifier ("__tls_init");
- tree fn = IDENTIFIER_GLOBAL_VALUE (sname);
+ tree fn = get_global_binding (sname);
if (!fn)
{
fn = build_lang_decl (FUNCTION_DECL, sname,
@@ -3163,7 +3163,7 @@ get_local_tls_init_fn (void)
TREE_PUBLIC (fn) = false;
DECL_ARTIFICIAL (fn) = true;
mark_used (fn);
- SET_IDENTIFIER_GLOBAL_VALUE (sname, fn);
+ set_global_binding (fn);
}
return fn;
}
@@ -3191,7 +3191,7 @@ get_tls_init_fn (tree var)
return get_local_tls_init_fn ();
tree sname = mangle_tls_init_fn (var);
- tree fn = IDENTIFIER_GLOBAL_VALUE (sname);
+ tree fn = get_global_binding (sname);
if (!fn)
{
fn = build_lang_decl (FUNCTION_DECL, sname,
@@ -3225,7 +3225,7 @@ get_tls_init_fn (tree var)
DECL_BEFRIENDING_CLASSES (fn) = var;
- SET_IDENTIFIER_GLOBAL_VALUE (sname, fn);
+ set_global_binding (fn);
}
return fn;
}
@@ -3243,7 +3243,7 @@ get_tls_wrapper_fn (tree var)
return NULL_TREE;
tree sname = mangle_tls_wrapper_fn (var);
- tree fn = IDENTIFIER_GLOBAL_VALUE (sname);
+ tree fn = get_global_binding (sname);
if (!fn)
{
/* A named rvalue reference is an lvalue, so the wrapper should
@@ -3282,7 +3282,7 @@ get_tls_wrapper_fn (tree var)
DECL_BEFRIENDING_CLASSES (fn) = var;
- SET_IDENTIFIER_GLOBAL_VALUE (sname, fn);
+ set_global_binding (fn);
}
return fn;
}
@@ -4427,7 +4427,7 @@ maybe_warn_sized_delete (enum tree_code
tree sized = NULL_TREE;
tree unsized = NULL_TREE;
- for (ovl_iterator iter (IDENTIFIER_GLOBAL_VALUE (cp_operator_id (code)));
+ for (ovl_iterator iter (get_global_binding (cp_operator_id (code)));
iter; ++iter)
{
tree fn = *iter;
Index: except.c
===================================================================
--- except.c (revision 253413)
+++ except.c (working copy)
@@ -147,7 +147,7 @@ declare_library_fn (const char *name, tr
int ecf, int tm_ecf)
{
tree ident = get_identifier (name);
- tree res = IDENTIFIER_GLOBAL_VALUE (ident);
+ tree res = get_global_binding (ident);
if (!res)
{
tree type = build_function_type_list (rtype, ptype, NULL_TREE);
@@ -158,7 +158,7 @@ declare_library_fn (const char *name, tr
char *tm_name = concat ("_ITM_", name + 2, NULL_TREE);
tree tm_ident = get_identifier (tm_name);
free (tm_name);
- tree tm_fn = IDENTIFIER_GLOBAL_VALUE (tm_ident);
+ tree tm_fn = get_global_binding (tm_ident);
if (!tm_fn)
tm_fn = push_library_fn (tm_ident, type, except, ecf | tm_ecf);
record_tm_replacement (res, tm_fn);
@@ -609,7 +609,7 @@ build_throw (tree exp)
if (!throw_fn)
{
tree name = get_identifier ("__cxa_throw");
- throw_fn = IDENTIFIER_GLOBAL_VALUE (name);
+ throw_fn = get_global_binding (name);
if (!throw_fn)
{
/* Declare void __cxa_throw (void*, void*, void (*)(void*)). */
@@ -622,7 +622,7 @@ build_throw (tree exp)
if (flag_tm)
{
tree itm_name = get_identifier ("_ITM_cxa_throw");
- tree itm_fn = IDENTIFIER_GLOBAL_VALUE (itm_name);
+ tree itm_fn = get_global_binding (itm_name);
if (!itm_fn)
itm_fn = push_throw_library_fn (itm_name, tmp);
apply_tm_attr (itm_fn, get_identifier ("transaction_pure"));
@@ -764,7 +764,7 @@ build_throw (tree exp)
if (!rethrow_fn)
{
tree name = get_identifier ("__cxa_rethrow");
- rethrow_fn = IDENTIFIER_GLOBAL_VALUE (name);
+ rethrow_fn = get_global_binding (name);
if (!rethrow_fn)
/* Declare void __cxa_rethrow (void). */
rethrow_fn = push_throw_library_fn
Index: init.c
===================================================================
--- init.c (revision 253413)
+++ init.c (working copy)
@@ -2446,7 +2446,7 @@ throw_bad_array_new_length (void)
{
tree name = get_identifier ("__cxa_throw_bad_array_new_length");
- fn = IDENTIFIER_GLOBAL_VALUE (name);
+ fn = get_global_binding (name);
if (!fn)
fn = push_throw_library_fn
(name, build_function_type_list (sizetype, NULL_TREE));
Index: name-lookup.c
===================================================================
--- name-lookup.c (revision 253426)
+++ name-lookup.c (working copy)
@@ -3774,16 +3774,6 @@ identifier_type_value (tree id)
return ret;
}
-
-/* Return the IDENTIFIER_GLOBAL_VALUE of T, for use in common code, since
- the definition of IDENTIFIER_GLOBAL_VALUE is different for C and C++. */
-
-tree
-identifier_global_value (tree t)
-{
- return IDENTIFIER_GLOBAL_VALUE (t);
-}
-
/* Push a definition of struct, union or enum tag named ID. into
binding_level B. DECL is a TYPE_DECL for the type. We assume that
the tag ID is not already defined. */
@@ -4839,32 +4829,32 @@ get_namespace_binding (tree ns, tree nam
return ret;
}
-/* Set value binding of NAME in the global namespace to VAL. Does not
- add it to the list of things in the namespace. */
+/* Push internal DECL into the global namespace. Does not do the
+ full overload fn handling and does not add it to the list of things
+ in the namespace. */
void
-set_global_binding (tree name, tree val)
+set_global_binding (tree decl)
{
bool subtime = timevar_cond_start (TV_NAME_LOOKUP);
- gcc_checking_assert (name == DECL_NAME (val));
- tree *slot = find_namespace_slot (global_namespace, name, true);
+ tree *slot = find_namespace_slot (global_namespace, DECL_NAME (decl), true);
tree old = MAYBE_STAT_DECL (*slot);
if (!old)
- *slot = val;
- else if (old == val)
+ *slot = decl;
+ else if (old == decl)
;
else if (!STAT_HACK_P (*slot)
- && TREE_CODE (val) == TYPE_DECL && DECL_ARTIFICIAL (val))
- *slot = stat_hack (old, val);
+ && TREE_CODE (decl) == TYPE_DECL && DECL_ARTIFICIAL (decl))
+ *slot = stat_hack (old, decl);
else if (!STAT_HACK_P (*slot)
&& TREE_CODE (old) == TYPE_DECL && DECL_ARTIFICIAL (old))
- *slot = stat_hack (val, old);
+ *slot = stat_hack (decl, old);
else
/* The user's placed something in the implementor's
namespace. */
- diagnose_name_conflict (val, old);
+ diagnose_name_conflict (decl, old);
timevar_cond_stop (TV_NAME_LOOKUP, subtime);
}
Index: name-lookup.h
===================================================================
--- name-lookup.h (revision 253413)
+++ name-lookup.h (working copy)
@@ -178,9 +178,6 @@ struct GTY(()) cp_label_binding {
CURRENT_BINDING_LEVEL. You should use lookup_name_current_level
instead. */
-/* Note that the information in the `names' component of the global contour
- is duplicated in the IDENTIFIER_GLOBAL_VALUEs of all identifiers. */
-
struct GTY(()) cp_binding_level {
/* A chain of _DECL nodes for all variables, constants, functions,
and typedef types. These are in the reverse of the order
@@ -303,7 +300,11 @@ extern tree lookup_name_prefer_type (tre
extern tree lookup_name_real (tree, int, int, bool, int, int);
extern tree lookup_type_scope (tree, tag_scope);
extern tree get_namespace_binding (tree ns, tree id);
-extern void set_global_binding (tree id, tree val);
+extern void set_global_binding (tree decl);
+inline tree get_global_binding (tree id)
+{
+ return get_namespace_binding (NULL_TREE, id);
+}
extern tree lookup_qualified_name (tree, tree, int, bool, /*hidden*/bool = false);
extern tree lookup_name_nonclass (tree);
extern bool is_local_extern (tree);
Index: rtti.c
===================================================================
--- rtti.c (revision 253413)
+++ rtti.c (working copy)
@@ -52,7 +52,7 @@ along with GCC; see the file COPYING3.
type_info objects for static initialization.
The type information VAR_DECL of a type is held on the
- IDENTIFIER_GLOBAL_VALUE of the type's mangled name. That VAR_DECL
+ get_global_binding of the type's mangled name. That VAR_DECL
will be the internal type. It will usually have the correct
internal type reflecting the kind of type it represents (pointer,
array, function, class, inherited class, etc). When the type it
@@ -226,7 +226,7 @@ throw_bad_cast (void)
if (!fn)
{
tree name = get_identifier ("__cxa_bad_cast");
- fn = IDENTIFIER_GLOBAL_VALUE (name);
+ fn = get_global_binding (name);
if (!fn)
fn = push_throw_library_fn
(name, build_function_type_list (ptr_type_node, NULL_TREE));
@@ -245,7 +245,7 @@ throw_bad_typeid (void)
if (!fn)
{
tree name = get_identifier ("__cxa_bad_typeid");
- fn = IDENTIFIER_GLOBAL_VALUE (name);
+ fn = get_global_binding (name);
if (!fn)
{
tree t = build_reference_type (const_type_info_type_node);
@@ -446,7 +446,7 @@ get_tinfo_decl (tree type)
name = mangle_typeinfo_for_type (type);
- d = IDENTIFIER_GLOBAL_VALUE (name);
+ d = get_global_binding (name);
if (!d)
{
int ix = get_pseudo_ti_index (type);