This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

C++ PATCH: cleanup DEBUG_BINDING_LEVELS code


Hi,

  While working on the name-lookup performance issue, I came to turn
on DEBUG_BINDING_LEVELS and realize that nobody has been turning it on
for some while.  This patch (which was dormant in my local tree)
cleans up the DEBUG_BINDING_LEVELS code  so as to make it bootstrap
again with the -Werror option.  

Bootstrapped and resgtested on an i686-pc-linux-gnu.

OK for mainline?
OK for branch?

-- Gaby

2003-05-29  Gabriel Dos Reis  <gdr@integrable-solutions.net>

	* decl.c (ENABLE_CHECKING_SCOPES): New macro.
	(binding_depth): Unconditionally define.
	(is_class_level): Likewise.
	(indent): Likewise.  Take an indenting parameter.
	(push_binding_level): Remove conditional definittion. 
	(pop_binding_level): Likewise.
	(suspend_binding_level): Likewise.
	(resume_binding_level): Likewise.
	(pushlevel): Likewise.
	(pushlevel_class): Likewise.
	(poplevel_class): Likewise.
	(pop_everything): Likewise.


Index: decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/decl.c,v
retrieving revision 1.1057
diff -p -r1.1057 decl.c
*** decl.c	29 May 2003 11:04:09 -0000	1.1057
--- decl.c	29 May 2003 16:14:28 -0000
*************** static tree next_initializable_field (tr
*** 148,157 ****
  static tree reshape_init (tree, tree *);
  static tree build_typename_type (tree, tree, tree);
  
- #if defined (DEBUG_BINDING_LEVELS)
- static void indent (void);
- #endif
- 
  /* Erroneous argument lists can use this *IFF* they do not modify it.  */
  tree error_mark_list;
  
--- 148,153 ----
*************** static int keep_next_level_flag;
*** 448,466 ****
  
  static GTY(()) tree incomplete_vars;
  
! #if defined(DEBUG_BINDING_LEVELS)
  static int binding_depth = 0;
  static int is_class_level = 0;
  
  static void
! indent (void)
  {
!   register unsigned i;
  
!   for (i = 0; i < binding_depth*2; i++)
      putc (' ', stderr);
  }
- #endif /* defined(DEBUG_BINDING_LEVELS) */
  
  static tree pushdecl_with_scope	(tree, struct cp_binding_level *);
  
--- 444,466 ----
  
  static GTY(()) tree incomplete_vars;
  
! #ifndef DEBUG_BINDING_LEVELS
! #  define ENABLE_CHECKING_SCOPES 0
! #else
! #  define ENABLE_CHECKING_SCOPES 1
! #endif
! 
  static int binding_depth = 0;
  static int is_class_level = 0;
  
  static void
! indent (int depth)
  {
!   int i;
  
!   for (i = 0; i < depth * 2; i++)
      putc (' ', stderr);
  }
  
  static tree pushdecl_with_scope	(tree, struct cp_binding_level *);
  
*************** push_binding_level (struct cp_binding_le
*** 478,491 ****
    newlevel->more_cleanups_ok = 1;
  
    newlevel->keep = keep;
! #if defined(DEBUG_BINDING_LEVELS)
!   newlevel->binding_depth = binding_depth;
!   indent ();
!   fprintf (stderr, "push %s level 0x%08x line %d\n",
! 	   (is_class_level) ? "class" : "block", newlevel, input_line);
!   is_class_level = 0;
!   binding_depth++;
! #endif /* defined(DEBUG_BINDING_LEVELS) */
  }
  
  /* Find the innermost enclosing class scope, and reset
--- 478,493 ----
    newlevel->more_cleanups_ok = 1;
  
    newlevel->keep = keep;
!   if (ENABLE_CHECKING_SCOPES)
!     {
!       newlevel->binding_depth = binding_depth;
!       indent (binding_depth);
!       verbatim ("push %s level %p line %d\n",
!                 (is_class_level) ? "class" : "block",
!                 (void *) newlevel, input_line);
!       is_class_level = 0;
!       binding_depth++;
!     }
  }
  
  /* Find the innermost enclosing class scope, and reset
*************** pop_binding_level (void)
*** 511,529 ****
      /* 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 defined(DEBUG_BINDING_LEVELS)
!   binding_depth--;
!   indent ();
!   fprintf (stderr, "pop  %s level 0x%08x line %d\n",
! 	  (is_class_level) ? "class" : "block",
! 	  current_binding_level, input_line);
!   if (is_class_level != (current_binding_level == class_binding_level))
      {
!       indent ();
!       fprintf (stderr, "XXX is_class_level != (current_binding_level == class_binding_level)\n");
      }
-   is_class_level = 0;
- #endif /* defined(DEBUG_BINDING_LEVELS) */
    {
      register struct cp_binding_level *level = current_binding_level;
      current_binding_level = current_binding_level->level_chain;
--- 513,532 ----
      /* 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_CHECKING_SCOPES)
      {
!       indent (--binding_depth);
!       verbatim ("pop  %s level %p line %d\n",
!                 (is_class_level) ? "class" : "block",
!                 (void*) current_binding_level, input_line);
!       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;
*************** pop_binding_level (void)
*** 532,541 ****
        level->type_decls = NULL;
      else
        binding_table_free (level->type_decls);
! #if 0 /* defined(DEBUG_BINDING_LEVELS) */
!     if (level->binding_depth != binding_depth)
!       abort ();
! #endif /* defined(DEBUG_BINDING_LEVELS) */
      free_binding_level = level;
      find_class_binding_level ();
    }
--- 535,543 ----
        level->type_decls = NULL;
      else
        binding_table_free (level->type_decls);
!     my_friendly_assert (!ENABLE_CHECKING_SCOPES
!                         || level->binding_depth == binding_depth,
!                         20030529);
      free_binding_level = level;
      find_class_binding_level ();
    }
*************** suspend_binding_level (void)
*** 551,569 ****
      /* 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 defined(DEBUG_BINDING_LEVELS)
!   binding_depth--;
!   indent ();
!   fprintf (stderr, "suspend  %s level 0x%08x line %d\n",
! 	  (is_class_level) ? "class" : "block",
! 	  current_binding_level, input_line);
!   if (is_class_level != (current_binding_level == class_binding_level))
      {
!       indent ();
!       fprintf (stderr, "XXX is_class_level != (current_binding_level == class_binding_level)\n");
      }
-   is_class_level = 0;
- #endif /* defined(DEBUG_BINDING_LEVELS) */
    current_binding_level = current_binding_level->level_chain;
    find_class_binding_level ();
  }
--- 553,572 ----
      /* 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_CHECKING_SCOPES)
      {
!       indent (--binding_depth);
!       verbatim ("suspend  %s level %p line %d\n",
!                 (is_class_level) ? "class" : "block",
!                 (void *) current_binding_level, input_line);
!       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 ();
  }
*************** resume_binding_level (struct cp_binding_
*** 577,590 ****
    /* Also, resuming a non-directly nested namespace is a no-no.  */
    my_friendly_assert(b->level_chain == current_binding_level, 386);
    current_binding_level = b;
! #if defined(DEBUG_BINDING_LEVELS)
!   b->binding_depth = binding_depth;
!   indent ();
!   fprintf (stderr, "resume %s level 0x%08x line %d\n",
! 	   (is_class_level) ? "class" : "block", b, input_line);
!   is_class_level = 0;
!   binding_depth++;
! #endif /* defined(DEBUG_BINDING_LEVELS) */
  }
  
  /* Create a new `struct cp_binding_level'.  */
--- 580,594 ----
    /* Also, resuming a non-directly nested namespace is a no-no.  */
    my_friendly_assert(b->level_chain == current_binding_level, 386);
    current_binding_level = b;
!   if (ENABLE_CHECKING_SCOPES)
!     {
!       b->binding_depth = binding_depth;
!       indent (binding_depth);
!       verbatim ("resume %s level %p line %d\n",
!                 (is_class_level) ? "class" : "block", b, input_line);
!       is_class_level = 0;
!       binding_depth++;
!     }
  }
  
  /* Create a new `struct cp_binding_level'.  */
*************** pushlevel (int tag_transparent)
*** 789,799 ****
      return;
  
    /* Reuse or create a struct for this binding level.  */
! #if defined(DEBUG_BINDING_LEVELS)
!   if (0)
! #else /* !defined(DEBUG_BINDING_LEVELS) */
!   if (free_binding_level)
! #endif /* !defined(DEBUG_BINDING_LEVELS) */
      {
        newlevel = free_binding_level;
        free_binding_level = free_binding_level->level_chain;
--- 793,799 ----
      return;
  
    /* Reuse or create a struct for this binding level.  */
!   if (!ENABLE_CHECKING_SCOPES && free_binding_level)
      {
        newlevel = free_binding_level;
        free_binding_level = free_binding_level->level_chain;
*************** pushlevel_class (void)
*** 1553,1563 ****
    register struct cp_binding_level *newlevel;
  
    /* Reuse or create a struct for this binding level.  */
! #if defined(DEBUG_BINDING_LEVELS)
!   if (0)
! #else /* !defined(DEBUG_BINDING_LEVELS) */
!   if (free_binding_level)
! #endif /* !defined(DEBUG_BINDING_LEVELS) */
      {
        newlevel = free_binding_level;
        free_binding_level = free_binding_level->level_chain;
--- 1553,1559 ----
    register struct cp_binding_level *newlevel;
  
    /* Reuse or create a struct for this binding level.  */
!   if (!ENABLE_CHECKING_SCOPES && free_binding_level)
      {
        newlevel = free_binding_level;
        free_binding_level = free_binding_level->level_chain;
*************** pushlevel_class (void)
*** 1565,1573 ****
    else
      newlevel = make_binding_level ();
  
! #if defined(DEBUG_BINDING_LEVELS)
!   is_class_level = 1;
! #endif /* defined(DEBUG_BINDING_LEVELS) */
  
    push_binding_level (newlevel, 0, 0);
  
--- 1561,1568 ----
    else
      newlevel = make_binding_level ();
  
!   if (ENABLE_CHECKING_SCOPES)
!     is_class_level = 1;
  
    push_binding_level (newlevel, 0, 0);
  
*************** poplevel_class (void)
*** 1644,1652 ****
  
    /* Now, pop out of the binding level which we created up in the
       `pushlevel_class' routine.  */
! #if defined(DEBUG_BINDING_LEVELS)
!   is_class_level = 1;
! #endif /* defined(DEBUG_BINDING_LEVELS) */
  
    pop_binding_level ();
    timevar_pop (TV_NAME_LOOKUP);
--- 1639,1646 ----
  
    /* Now, pop out of the binding level which we created up in the
       `pushlevel_class' routine.  */
!   if (ENABLE_CHECKING_SCOPES)
!     is_class_level = 1;
  
    pop_binding_level ();
    timevar_pop (TV_NAME_LOOKUP);
*************** identifier_type_value (tree id)
*** 2361,2369 ****
  void
  pop_everything (void)
  {
! #ifdef DEBUG_BINDING_LEVELS
!   fprintf (stderr, "XXX entering pop_everything ()\n");
! #endif
    while (!toplevel_bindings_p ())
      {
        if (current_binding_level->parm_flag == 2)
--- 2355,2362 ----
  void
  pop_everything (void)
  {
!   if (ENABLE_CHECKING_SCOPES)
!     verbatim ("XXX entering pop_everything ()\n");
    while (!toplevel_bindings_p ())
      {
        if (current_binding_level->parm_flag == 2)
*************** pop_everything (void)
*** 2371,2379 ****
        else
  	poplevel (0, 0, 0);
      }
! #ifdef DEBUG_BINDING_LEVELS
!   fprintf (stderr, "XXX leaving pop_everything ()\n");
! #endif
  }
  
  /* The type TYPE is being declared.  If it is a class template, or a
--- 2364,2371 ----
        else
  	poplevel (0, 0, 0);
      }
!   if (ENABLE_CHECKING_SCOPES)
!     verbatim ("XXX leaving pop_everything ()\n");
  }
  
  /* The type TYPE is being declared.  If it is a class template, or a


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]