From 000d38ea95cb73068021fabf8d3325e3a00aec8d Mon Sep 17 00:00:00 2001 From: Gabriel Dos Reis Date: Tue, 4 Mar 2003 23:23:16 +0000 Subject: [PATCH] cp-tree.h (cxx_saved_binding): Declare. * cp-tree.h (cxx_saved_binding): Declare. (struct saved_scope): Adjust type of field 'old_binding'. * decl.c (cxx_saved_binding_make): New macro. (struct cxx_saved_binding): Define. (store_bindings): Adjust prototype. Use cxx_saved_binding to save C++ bindings. (maybe_push_to_top_level): Adjust local variable type. (pop_from_top_level): Likewise. From-SVN: r63810 --- gcc/cp/ChangeLog | 11 +++++++++ gcc/cp/cp-tree.h | 6 ++++- gcc/cp/decl.c | 62 +++++++++++++++++++++++++++++++----------------- 3 files changed, 56 insertions(+), 23 deletions(-) diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index bd058bf0fa4e..232cf24a3ad9 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,14 @@ +2003-03-04 Gabriel Dos Reis + + * cp-tree.h (cxx_saved_binding): Declare. + (struct saved_scope): Adjust type of field 'old_binding'. + * decl.c (cxx_saved_binding_make): New macro. + (struct cxx_saved_binding): Define. + (store_bindings): Adjust prototype. Use cxx_saved_binding to save + C++ bindings. + (maybe_push_to_top_level): Adjust local variable type. + (pop_from_top_level): Likewise. + 2003-03-04 Tom Tromey * Make-lang.in (c++.tags): New target. diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index cf84fcb46e7f..447fd57530b2 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -221,6 +221,10 @@ struct diagnostic_context; #define abi_version_at_least(N) \ (flag_abi_version == 0 || flag_abi_version >= (N)) + +/* Datatype used to temporarily save C++ bindings (for implicit + instantiations purposes and like). Implemented in decl.c. */ +typedef struct cxx_saved_binding cxx_saved_binding; /* Language-dependent contents of an identifier. */ @@ -755,7 +759,7 @@ extern GTY(()) tree cp_global_trees[CPTI_MAX]; struct saved_scope GTY(()) { - tree old_bindings; + cxx_saved_binding *old_bindings; tree old_namespace; tree decl_ns_list; tree class_name; diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 0bed8e993254..90058e7aa37b 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -67,7 +67,7 @@ static void storedecls (tree); static void require_complete_types_for_parms (tree); static int ambi_op_p (enum tree_code); static int unary_op_p (enum tree_code); -static tree store_bindings (tree, tree); +static cxx_saved_binding *store_bindings (tree, cxx_saved_binding *); static tree lookup_tag_reverse (tree, tree); static void push_local_name (tree); static void warn_extern_redeclared_static (tree, tree); @@ -2252,6 +2252,22 @@ pop_nested_namespace (tree ns) } +/* Allocate storage for saving a C++ binding. */ +#define cxx_saved_binding_make() \ + (ggc_alloc (sizeof (cxx_saved_binding))) + +struct cxx_saved_binding GTY(()) +{ + /* Link that chains saved C++ bindings for a given name into a stack. */ + cxx_saved_binding *previous; + /* The name of the current binding. */ + tree identifier; + /* The binding we're saving. */ + tree binding; + tree class_value; + tree real_type_value; +}; + /* Subroutines for reverting temporarily to top-level for instantiation of templates and such. We actually need to clear out the class- and local-value slots of all identifiers, so that only the global values @@ -2259,16 +2275,18 @@ pop_nested_namespace (tree ns) scope isn't enough, because more binding levels may be pushed. */ struct saved_scope *scope_chain; -static tree -store_bindings (tree names, tree old_bindings) +static cxx_saved_binding * +store_bindings (tree names, cxx_saved_binding *old_bindings) { tree t; - tree search_bindings = old_bindings; + cxx_saved_binding *search_bindings = old_bindings; timevar_push (TV_NAME_LOOKUP); for (t = names; t; t = TREE_CHAIN (t)) { - tree binding, t1, id; + tree id; + cxx_saved_binding *saved; + cxx_saved_binding *t1; if (TREE_CODE (t) == TREE_LIST) id = TREE_PURPOSE (t); @@ -2282,20 +2300,20 @@ store_bindings (tree names, tree old_bindings) || !(IDENTIFIER_BINDING (id) || IDENTIFIER_CLASS_VALUE (id))) continue; - for (t1 = search_bindings; t1; t1 = TREE_CHAIN (t1)) - if (TREE_VEC_ELT (t1, 0) == id) + for (t1 = search_bindings; t1; t1 = t1->previous) + if (t1->identifier == id) goto skip_it; my_friendly_assert (TREE_CODE (id) == IDENTIFIER_NODE, 135); - binding = make_tree_vec (4); - TREE_VEC_ELT (binding, 0) = id; - TREE_VEC_ELT (binding, 1) = REAL_IDENTIFIER_TYPE_VALUE (id); - TREE_VEC_ELT (binding, 2) = IDENTIFIER_BINDING (id); - TREE_VEC_ELT (binding, 3) = IDENTIFIER_CLASS_VALUE (id); + saved = cxx_saved_binding_make (); + saved->previous = old_bindings; + saved->identifier = id; + saved->binding = IDENTIFIER_BINDING (id); + saved->class_value = IDENTIFIER_CLASS_VALUE (id);; + saved->real_type_value = REAL_IDENTIFIER_TYPE_VALUE (id); IDENTIFIER_BINDING (id) = NULL_TREE; IDENTIFIER_CLASS_VALUE (id) = NULL_TREE; - TREE_CHAIN (binding) = old_bindings; - old_bindings = binding; + old_bindings = saved; skip_it: ; } @@ -2307,7 +2325,7 @@ maybe_push_to_top_level (int pseudo) { struct saved_scope *s; struct cp_binding_level *b; - tree old_bindings; + cxx_saved_binding *old_bindings; int need_pop; timevar_push (TV_NAME_LOOKUP); @@ -2324,7 +2342,7 @@ maybe_push_to_top_level (int pseudo) else need_pop = 0; - old_bindings = NULL_TREE; + old_bindings = NULL; if (scope_chain && previous_class_type) old_bindings = store_bindings (previous_class_values, old_bindings); @@ -2377,7 +2395,7 @@ void pop_from_top_level (void) { struct saved_scope *s = scope_chain; - tree t; + cxx_saved_binding *saved; timevar_push (TV_NAME_LOOKUP); /* Clear out class-level bindings cache. */ @@ -2387,13 +2405,13 @@ pop_from_top_level (void) current_lang_base = 0; scope_chain = s->prev; - for (t = s->old_bindings; t; t = TREE_CHAIN (t)) + for (saved = s->old_bindings; saved; saved = saved->previous) { - tree id = TREE_VEC_ELT (t, 0); + tree id = saved->identifier; - SET_IDENTIFIER_TYPE_VALUE (id, TREE_VEC_ELT (t, 1)); - IDENTIFIER_BINDING (id) = TREE_VEC_ELT (t, 2); - IDENTIFIER_CLASS_VALUE (id) = TREE_VEC_ELT (t, 3); + IDENTIFIER_BINDING (id) = saved->binding; + IDENTIFIER_CLASS_VALUE (id) = saved->class_value; + SET_IDENTIFIER_TYPE_VALUE (id, saved->real_type_value); } /* If we were in the middle of compiling a function, restore our