C++ PATCH: Unify pop_binding_level and suspend_binding_level
Gabriel Dos Reis
gdr@integrable-solutions.net
Wed Sep 24 09:09:00 GMT 2003
Hi,
The codes in pop_binding_level and suspend_binding_level are quite
similar, except that pop_binding_level definitely free scope
structures. This patch removes that code duplication and merge both
functions into leave_scope.
Bootstrapped and regtested on an i686-pc-linux-gnu.
OK to install?
-- Gaby
Index: ChangeLog
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/ChangeLog,v
retrieving revision 1.3701
diff -p -r1.3701 ChangeLog
*** ChangeLog 23 Sep 2003 15:42:19 -0000 1.3701
--- ChangeLog 24 Sep 2003 08:15:25 -0000
***************
*** 1,3 ****
--- 1,12 ----
+ 2003-09-24 Gabriel Dos Reis <gdr@integrable-solutions.net>
+
+ * decl.c (pop_binding_level, suspend_binding_level,
+ find_class_binding_level): Merge into leave_scope. Remove.
+ (leave_scope): New function.
+ (poplevel): Update.
+ (poplevel_class): Likewise.
+ (pop_namespace): Likewise.
+
2003-09-22 Gabriel Dos Reis <gcc@integrable-solutions.net>
* cp-tree.h (scope_kind): Add new enumerator.
Index: decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/decl.c,v
retrieving revision 1.1132
diff -p -r1.1132 decl.c
*** decl.c 23 Sep 2003 15:42:20 -0000 1.1132
--- decl.c 24 Sep 2003 08:15:31 -0000
*************** Boston, MA 02111-1307, USA. */
*** 55,62 ****
static tree grokparms (tree);
static const char *redeclaration_error_message (tree, tree);
- static void pop_binding_level (void);
- static void suspend_binding_level (void);
static void resume_binding_level (struct cp_binding_level *);
static int decl_jump_unsafe (tree);
static void storedecls (tree);
--- 55,60 ----
*************** static int lookup_flags (int, int);
*** 98,104 ****
static tree qualify_lookup (tree, int);
static tree record_builtin_java_type (const char *, int);
static const char *tag_name (enum tag_types code);
- static void find_class_binding_level (void);
static struct cp_binding_level *innermost_nonclass_level (void);
static int walk_namespaces_r (tree, walk_namespaces_fn, void *);
static int walk_globals_r (tree, void*);
--- 96,101 ----
*************** begin_scope (scope_kind kind, tree entit
*** 566,646 ****
return scope;
}
! /* Find the innermost enclosing class scope, and reset
! CLASS_BINDING_LEVEL appropriately. */
! static void
! find_class_binding_level (void)
{
! struct cp_binding_level *level = current_binding_level;
! while (level && level->kind != sk_class)
! level = level->level_chain;
! if (level && level->kind == sk_class)
! class_binding_level = level;
! else
! class_binding_level = 0;
! }
! static void
! pop_binding_level (void)
! {
if (NAMESPACE_LEVEL (global_namespace))
! /* Cannot pop a level, if there are none left to pop. */
! my_friendly_assert (!global_scope_p (current_binding_level), 20030527);
! /* Pop the current level, and free the structure for reuse. */
if (ENABLE_SCOPE_CHECKING)
{
indent (--binding_depth);
! cxx_scope_debug (current_binding_level, input_location.line, "pop");
! if (is_class_level != (current_binding_level == class_binding_level))
{
indent (binding_depth);
! verbatim ("XXX is_class_level != (current_binding_level "
! "== class_binding_level)\n");
}
is_class_level = 0;
}
- {
- register struct cp_binding_level *level = current_binding_level;
- current_binding_level = current_binding_level->level_chain;
- level->level_chain = free_binding_level;
- if (level->kind == sk_class)
- level->type_decls = NULL;
- else
- binding_table_free (level->type_decls);
- my_friendly_assert (!ENABLE_SCOPE_CHECKING
- || level->binding_depth == binding_depth,
- 20030529);
- free_binding_level = level;
- find_class_binding_level ();
- }
- }
! static void
! suspend_binding_level (void)
! {
! if (class_binding_level)
! current_binding_level = class_binding_level;
! if (NAMESPACE_LEVEL (global_namespace))
! /* Cannot suspend a level, if there are none left to suspend. */
! my_friendly_assert (!global_scope_p (current_binding_level), 20030527);
! /* Suspend the current level. */
! if (ENABLE_SCOPE_CHECKING)
! {
! indent (--binding_depth);
! cxx_scope_debug (current_binding_level, input_location.line, "suspend");
! if (is_class_level != (current_binding_level == class_binding_level))
! {
! indent (binding_depth);
! verbatim ("XXX is_class_level != (current_binding_level "
! "== class_binding_level)\n");
! }
! is_class_level = 0;
! }
! current_binding_level = current_binding_level->level_chain;
! find_class_binding_level ();
}
static void
--- 563,624 ----
return scope;
}
! /* We're about to leave current scope. Pop the top of the stack of
! currently active scopes. Return the enclosing scope, now active. */
! static cxx_scope *
! leave_scope (void)
{
! cxx_scope *scope = current_binding_level;
! if (scope->kind == sk_namespace && class_binding_level)
! current_binding_level = class_binding_level;
! /* We cannot leave a scope, if there are none left. */
if (NAMESPACE_LEVEL (global_namespace))
! my_friendly_assert (!global_scope_p (scope), 20030527);
!
if (ENABLE_SCOPE_CHECKING)
{
indent (--binding_depth);
! cxx_scope_debug (scope, input_location.line, "leave");
! if (is_class_level != (scope == class_binding_level))
{
indent (binding_depth);
! verbatim ("XXX is_class_level != (current_scope == class_scope)\n");
}
is_class_level = 0;
}
! /* Move one nesting level up. */
! current_binding_level = scope->level_chain;
! /* Namespace-scopes are left most probably temporarily, not completely;
! they can be reopen later, e.g. in namespace-extension or any name
! binding acttivity that requires us to resume a namespace. For other
! scopes, we just make the structure available for reuse. */
! if (scope->kind != sk_namespace)
! {
! scope->level_chain = free_binding_level;
! if (scope->kind == sk_class)
! scope->type_decls = NULL;
! else
! binding_table_free (scope->type_decls);
! my_friendly_assert (!ENABLE_SCOPE_CHECKING
! || scope->binding_depth == binding_depth,
! 20030529);
! free_binding_level = scope;
! }
!
! /* Find the innermost enclosing class scope, and reset
! CLASS_BINDING_LEVEL appropriately. */
! for (scope = current_binding_level;
! scope && scope->kind != sk_class;
! scope = scope->level_chain)
! ;
! class_binding_level = scope && scope->kind == sk_class ? scope : NULL;
!
! return current_binding_level;
}
static void
*************** poplevel (int keep, int reverse, int fun
*** 1387,1393 ****
kind = current_binding_level->kind;
! pop_binding_level ();
if (functionbody)
DECL_INITIAL (current_function_decl) = block;
else if (block)
--- 1365,1371 ----
kind = current_binding_level->kind;
! leave_scope ();
if (functionbody)
DECL_INITIAL (current_function_decl) = block;
else if (block)
*************** poplevel_class (void)
*** 1555,1561 ****
if (ENABLE_SCOPE_CHECKING)
is_class_level = 1;
! pop_binding_level ();
timevar_pop (TV_NAME_LOOKUP);
}
--- 1533,1539 ----
if (ENABLE_SCOPE_CHECKING)
is_class_level = 1;
! leave_scope ();
timevar_pop (TV_NAME_LOOKUP);
}
*************** pop_namespace (void)
*** 1967,1973 ****
my_friendly_assert (current_namespace != global_namespace, 20010801);
current_namespace = CP_DECL_CONTEXT (current_namespace);
/* The binding level is not popped, as it might be re-opened later. */
! suspend_binding_level ();
}
/* Push into the scope of the namespace NS, even if it is deeply
--- 1945,1951 ----
my_friendly_assert (current_namespace != global_namespace, 20010801);
current_namespace = CP_DECL_CONTEXT (current_namespace);
/* The binding level is not popped, as it might be re-opened later. */
! leave_scope ();
}
/* Push into the scope of the namespace NS, even if it is deeply
More information about the Gcc-patches
mailing list