2017-05-04 Nathan Sidwell <nathan@acm.org>
More global trees.
* cp-tree.h (enum cp_tree_index): Add CPTI_GLOBAL,
CPTI_GLOBAL_TYPE, CPTI_GLOBAL_IDENTIFIER, CPTI_ANON_IDENTIFIER,
CPTI_INIT_LIST_IDENTIFIER.
(global_namespace, global_type_node, global_identifier,
anon_identifier, init_list_identifier): New.
* decl.c (global_type_node, global_scope_name): Delete.
(initialize_predefined_identifiers): Add new identifiers.
(cxx_init_decl_processing): Adjust.
* name-lookup.h (global_namespace, global_type_node): Delete.
* name-lookup.c (global_namespace, anonymous_namespace_name,
get_anonymous_namespace_name): Delete.
(namespace_scope_ht_size, begin_scope, pushtag_1,
push_namespace): Adjust,
* call.c (type_has_extended_temps): Use init_list_identifier.
* pt.c (listify): Likewise.
===================================================================
@@ -10543,15 +10543,15 @@ type_has_extended_temps (tree type)
bool
is_std_init_list (tree type)
{
- /* Look through typedefs. */
if (!TYPE_P (type))
return false;
if (cxx_dialect == cxx98)
return false;
+ /* Look through typedefs. */
type = TYPE_MAIN_VARIANT (type);
return (CLASS_TYPE_P (type)
&& CP_TYPE_CONTEXT (type) == std_node
- && strcmp (TYPE_NAME_STRING (type), "initializer_list") == 0);
+ && init_list_identifier == DECL_NAME (TYPE_NAME (type)));
}
/* Returns true iff DECL is a list constructor: i.e. a constructor which
===================================================================
@@ -119,6 +119,8 @@ enum cp_tree_index
CPTI_VTBL_PTR_TYPE,
CPTI_STD,
CPTI_ABI,
+ CPTI_GLOBAL,
+ CPTI_GLOBAL_TYPE,
CPTI_CONST_TYPE_INFO_TYPE,
CPTI_TYPE_INFO_PTR_TYPE,
CPTI_ABORT_FNDECL,
@@ -138,9 +140,12 @@ enum cp_tree_index
CPTI_THIS_IDENTIFIER,
CPTI_PFN_IDENTIFIER,
CPTI_VPTR_IDENTIFIER,
+ CPTI_GLOBAL_IDENTIFIER,
CPTI_STD_IDENTIFIER,
+ CPTI_ANON_IDENTIFIER,
CPTI_AUTO_IDENTIFIER,
CPTI_DECLTYPE_AUTO_IDENTIFIER,
+ CPTI_INIT_LIST_IDENTIFIER,
CPTI_LANG_NAME_C,
CPTI_LANG_NAME_CPLUSPLUS,
@@ -184,6 +189,8 @@ extern GTY(()) tree cp_global_trees[CPTI
#define vtbl_ptr_type_node cp_global_trees[CPTI_VTBL_PTR_TYPE]
#define std_node cp_global_trees[CPTI_STD]
#define abi_node cp_global_trees[CPTI_ABI]
+#define global_namespace cp_global_trees[CPTI_GLOBAL]
+#define global_type_node cp_global_trees[CPTI_GLOBAL_TYPE]
#define const_type_info_type_node cp_global_trees[CPTI_CONST_TYPE_INFO_TYPE]
#define type_info_ptr_type cp_global_trees[CPTI_TYPE_INFO_PTR_TYPE]
#define abort_fndecl cp_global_trees[CPTI_ABORT_FNDECL]
@@ -224,12 +231,14 @@ extern GTY(()) tree cp_global_trees[CPTI
#define this_identifier cp_global_trees[CPTI_THIS_IDENTIFIER]
#define pfn_identifier cp_global_trees[CPTI_PFN_IDENTIFIER]
#define vptr_identifier cp_global_trees[CPTI_VPTR_IDENTIFIER]
-/* The name of the std namespace. */
+/* The name of the ::, std & anon namespaces. */
+#define global_identifier cp_global_trees[CPTI_GLOBAL_IDENTIFIER]
#define std_identifier cp_global_trees[CPTI_STD_IDENTIFIER]
+#define anon_identifier cp_global_trees[CPTI_ANON_IDENTIFIER]
/* auto and declspec(auto) identifiers. */
#define auto_identifier cp_global_trees[CPTI_AUTO_IDENTIFIER]
#define decltype_auto_identifier cp_global_trees[CPTI_DECLTYPE_AUTO_IDENTIFIER]
-/* The name of a C++17 deduction guide. */
+#define init_list_identifier cp_global_trees[CPTI_INIT_LIST_IDENTIFIER]
#define lang_name_c cp_global_trees[CPTI_LANG_NAME_C]
#define lang_name_cplusplus cp_global_trees[CPTI_LANG_NAME_CPLUSPLUS]
@@ -277,6 +286,7 @@ extern GTY(()) tree cp_global_trees[CPTI
access nodes in tree.h. */
#define access_default_node null_node
+
#include "name-lookup.h"
===================================================================
@@ -140,14 +140,6 @@ static void expand_static_init (tree, tr
tree cp_global_trees[CPTI_MAX];
-/* Indicates that there is a type value in some namespace, although
- that is not necessarily in scope at the moment. */
-
-tree global_type_node;
-
-/* The node that holds the "name" of the global scope. */
-tree global_scope_name;
-
#define local_names cp_function_chain->x_local_names
/* A list of objects which have constructors or destructors
@@ -3935,7 +3927,7 @@ make_unbound_class_template (tree contex
-/* Push the declarations of builtin types into the namespace.
+/* Push the declarations of builtin types into the global namespace.
RID_INDEX is the index of the builtin type in the array
RID_POINTERS. NAME is the name used when looking up the builtin
type. TYPE is the _TYPE node for the builtin type. */
@@ -4037,10 +4029,15 @@ initialize_predefined_identifiers (void)
{ VTABLE_PFN_NAME, &pfn_identifier, 0 },
{ "_vptr", &vptr_identifier, 0 },
{ "__vtt_parm", &vtt_parm_identifier, 0 },
- { "::", &global_scope_name, 0 },
+ { "::", &global_identifier, 0 },
{ "std", &std_identifier, 0 },
+ /* The demangler expects anonymous namespaces to be called
+ something starting with '_GLOBAL__N_'. It no longer needs
+ to be unique to the TU. */
+ { "_GLOBAL__N_1", &anon_identifier, 0 },
{ "auto", &auto_identifier, 0 },
{ "decltype(auto)", &decltype_auto_identifier, 0 },
+ { "initializer_list", &init_list_identifier, 0 },
{ NULL, NULL, 0 }
};
@@ -4073,14 +4070,15 @@ cxx_init_decl_processing (void)
current_binding_level = NULL;
/* Enter the global namespace. */
gcc_assert (global_namespace == NULL_TREE);
- global_namespace = build_lang_decl (NAMESPACE_DECL, global_scope_name,
+ global_namespace = build_lang_decl (NAMESPACE_DECL, global_identifier,
void_type_node);
+ TREE_PUBLIC (global_namespace) = 1;
DECL_CONTEXT (global_namespace)
= build_translation_unit_decl (get_identifier (main_input_filename));
debug_hooks->register_main_translation_unit
(DECL_CONTEXT (global_namespace));
- TREE_PUBLIC (global_namespace) = 1;
begin_scope (sk_namespace, global_namespace);
+ current_namespace = global_namespace;
if (flag_visibility_ms_compat)
default_visibility = VISIBILITY_HIDDEN;
===================================================================
@@ -61,14 +61,6 @@ static tree push_using_directive (tree);
static tree lookup_extern_c_fun_in_all_ns (tree);
static void diagnose_name_conflict (tree, tree);
-/* The :: namespace. */
-
-tree global_namespace;
-
-/* The name of the anonymous namespace, throughout this translation
- unit. */
-static GTY(()) tree anonymous_namespace_name;
-
/* Add DECL to the list of things declared in B. */
static void
@@ -644,23 +636,6 @@ lookup_arg_dependent (tree name, tree fn
return ret;
}
-/* Initialize anonymous_namespace_name if necessary, and return it. */
-
-static tree
-get_anonymous_namespace_name (void)
-{
- if (!anonymous_namespace_name)
- {
- /* We used to use get_file_function_name here, but that isn't
- necessary now that anonymous namespace typeinfos
- are !TREE_PUBLIC, and thus compared by address. */
- /* The demangler expects anonymous namespaces to be called
- something starting with '_GLOBAL__N_'. */
- anonymous_namespace_name = get_identifier ("_GLOBAL__N_1");
- }
- return anonymous_namespace_name;
-}
-
/* Compute the chain index of a binding_entry given the HASH value of its
name and the total COUNT of chains. COUNT is assumed to be a power
of 2. */
@@ -2111,7 +2086,7 @@ namespace_scope_ht_size (tree ns)
return name == std_identifier
? NAMESPACE_STD_HT_SIZE
- : (name == global_scope_name
+ : (name == global_identifier
? GLOBAL_SCOPE_HT_SIZE
: NAMESPACE_ORDINARY_HT_SIZE);
}
@@ -2189,7 +2164,7 @@ begin_scope (scope_kind kind, tree entit
NAMESPACE_LEVEL (entity) = scope;
vec_alloc (scope->static_decls,
(DECL_NAME (entity) == std_identifier
- || DECL_NAME (entity) == global_scope_name) ? 200 : 10);
+ || DECL_NAME (entity) == global_identifier) ? 200 : 10);
break;
default:
@@ -6167,7 +6142,7 @@ pushtag_1 (tree name, tree type, tag_sco
return decl;
if (DECL_CONTEXT (decl) == std_node
- && strcmp (TYPE_NAME_STRING (type), "initializer_list") == 0
+ && init_list_identifier == DECL_NAME (TYPE_NAME (type))
&& !CLASSTYPE_TEMPLATE_INFO (type))
{
error ("declaration of std::initializer_list does not match "
@@ -6489,11 +6464,11 @@ push_namespace (tree name)
/* We should not get here if the global_namespace is not yet constructed
nor if NAME designates the global namespace: The global scope is
constructed elsewhere. */
- gcc_assert (global_namespace != NULL && name != global_scope_name);
+ gcc_assert (global_namespace != NULL && name != global_identifier);
if (anon)
{
- name = get_anonymous_namespace_name();
+ name = anon_identifier;
d = IDENTIFIER_NAMESPACE_VALUE (name);
if (d)
/* Reopening anonymous namespace. */
===================================================================
@@ -278,15 +278,6 @@ struct GTY(()) cp_binding_level {
#define class_binding_level scope_chain->class_bindings
-/* The tree node representing the global scope. */
-extern GTY(()) tree global_namespace;
-extern GTY(()) tree global_scope_name;
-
-/* Indicates that there is a type value in some namespace, although
- that is not necessarily in scope at the moment. */
-
-extern GTY(()) tree global_type_node;
-
/* True if SCOPE designates the global scope binding contour. */
#define global_scope_p(SCOPE) \
((SCOPE) == NAMESPACE_LEVEL (global_namespace))
===================================================================
@@ -24730,8 +24730,7 @@ make_constrained_auto (tree con, tree ar
static tree
listify (tree arg)
{
- tree std_init_list = namespace_binding
- (get_identifier ("initializer_list"), std_node);
+ tree std_init_list = namespace_binding (init_list_identifier, std_node);
tree argvec;
if (!std_init_list || !DECL_CLASS_TEMPLATE_P (std_init_list))
{