]> gcc.gnu.org Git - gcc.git/commitdiff
decl.c (pop_binding_level, [...]): Merge into leave_scope.
authorGabriel Dos Reis <gdr@integrable-solutions.net>
Fri, 26 Sep 2003 15:21:30 +0000 (15:21 +0000)
committerGabriel Dos Reis <gdr@gcc.gnu.org>
Fri, 26 Sep 2003 15:21:30 +0000 (15:21 +0000)
        * 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.

From-SVN: r71821

gcc/cp/ChangeLog
gcc/cp/decl.c

index dcf2f665b63a00f6366ed26097564cea5de05c16..ff621d2e10dc2e4fd46d2b239e8af45a6aa7e173 100644 (file)
@@ -1,3 +1,12 @@
+2003-09-26  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-25  Kriang Lerdsuwanakij  <lerdsuwa@users.sourceforge.net>
 
        PR c++/5655
index 9538a1e9e22fce7e27ed51e12e61e0ecb9719f29..52b3b60054910d431d2ce1603bd2caf9d2d1829d 100644 (file)
@@ -55,8 +55,6 @@ Boston, MA 02111-1307, USA.  */
 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);
@@ -98,7 +96,6 @@ static int lookup_flags (int, int);
 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*);
@@ -566,81 +563,62 @@ begin_scope (scope_kind kind, tree entity)
   return scope;
 }
 
-/* Find the innermost enclosing class scope, and reset
-   CLASS_BINDING_LEVEL appropriately.  */
+/* We're about to leave current scope.  Pop the top of the stack of
+   currently active scopes.  Return the enclosing scope, now active.  */
 
-static void
-find_class_binding_level (void)
+static cxx_scope *
+leave_scope (void)
 {
-  struct cp_binding_level *level = current_binding_level;
+  cxx_scope *scope = 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;
-}
+  if (scope->kind == sk_namespace && class_binding_level)
+    current_binding_level = class_binding_level;
 
-static void
-pop_binding_level (void)
-{
+  /* We cannot leave a scope, if there are none left.  */
   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.  */
+    my_friendly_assert (!global_scope_p (scope), 20030527);
+  
   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))
+      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_binding_level "
-                    "== class_binding_level)\n");
+          verbatim ("XXX is_class_level != (current_scope == class_scope)\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;
+  /* Move one nesting level up.  */
+  current_binding_level = scope->level_chain;
 
-  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)
+  /* 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)
     {
-      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 ();
+      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
@@ -1387,7 +1365,7 @@ poplevel (int keep, int reverse, int functionbody)
 
   kind = current_binding_level->kind;
 
-  pop_binding_level ();
+  leave_scope ();
   if (functionbody)
     DECL_INITIAL (current_function_decl) = block;
   else if (block)
@@ -1555,7 +1533,7 @@ poplevel_class (void)
   if (ENABLE_SCOPE_CHECKING)
     is_class_level = 1;
 
-  pop_binding_level ();
+  leave_scope ();
   timevar_pop (TV_NAME_LOOKUP);
 }
 
@@ -1967,7 +1945,7 @@ pop_namespace (void)
   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 ();
+  leave_scope ();
 }
 
 /* Push into the scope of the namespace NS, even if it is deeply
This page took 0.098291 seconds and 5 git commands to generate.