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]

Re: C++ PATCH to decl.c: Factor debug code


Jason Merrill <jason@redhat.com> writes:

| On Fri, 30 May 2003 12:28:12 -0500, Benjamin Kosnik <bkoz@redhat.com> wrote:
| 
| >> These two names sound odd to me; I'd say cxx_make_scope or make_cxx_scope,
| >> and initial_push_namespace_scope.  Also, the latter needs a comment.
| >
| > Huh. I'd thought the same thing when I read this patch.
| >
| > ... or maybe push_initial_namespace_scope and make_cxx_scope? Most
| > functions seem to be named with the active verb as the first bit, at
| > least that is the active convention that I'm pushing in the runtime.
| 
| In the case of "cxx_make_scope", the "cxx" modifies the whole rest of the
| function name (though I also like "make_cxx_scope"), and for
| "initial_push_namespace_scope", the "initial" modifies "push"; subsequent
| pushes reuse the binding level created in the initial push.

This is the final form it got.

Thanks,

-- Gaby
Index: ChangeLog
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/ChangeLog,v
retrieving revision 1.3397
diff -p -r1.3397 ChangeLog
*** ChangeLog	31 May 2003 12:13:29 -0000	1.3397
--- ChangeLog	31 May 2003 12:51:18 -0000
***************
*** 1,3 ****
--- 1,28 ----
+ 2003-05-31  Gabriel Dos Reis <gdr@integrable-solutions.net>
+ 
+ 	* decl.c (cp_binding_level::this_entity): Rename from this_class.
+ 	(cxx_scope_descriptor): New function.
+ 	(cxx_scope_debug): Likewise.
+ 	(push_binding_level): Use it.
+ 	(pop_binding_level): Likewise.
+ 	(suspend_binding_level): Likewise.
+ 	(resume_binding_level): Likewise.
+ 	(pushlevel_class): Adjust use of this_class.
+ 	(pushtag): Likewise.
+ 	(lookup_name_real): Likewise.
+ 	(global_scope_name): New variable.
+ 	(initialize_predefined_identifiers): Initialize it.
+ 	(push_namespace): Use it.
+ 	(make_cxx_scope): New function.
+ 	(pushlevel): Use it.
+ 	(pushlevel_class): Likewise.
+ 	(push_binding_level): Simplify.  Loose the last two arguments.
+ 	(make_binding_level): Remove.
+ 	(initial_push_namespace_scope): New function.
+ 	(push_namespace): Use it.  Simplify.
+ 	(cxx_init_decl_processing): Likewise. 
+ 	(declare_namespace_level): Remove.
+ 
  2003-05-31  Kriang Lerdsuwanakij  <lerdsuwa@users.sourceforge.net>
  
  	PR c++/10956
Index: decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/decl.c,v
retrieving revision 1.1058
diff -p -r1.1058 decl.c
*** decl.c	29 May 2003 17:25:04 -0000	1.1058
--- decl.c	31 May 2003 12:51:25 -0000
*************** Boston, MA 02111-1307, USA.  */
*** 55,67 ****
  static tree grokparms (tree);
  static const char *redeclaration_error_message (tree, tree);
  
! static void push_binding_level (struct cp_binding_level *, int,
! 				int);
  static void pop_binding_level (void);
  static void suspend_binding_level (void);
  static void resume_binding_level (struct cp_binding_level *);
- static struct cp_binding_level *make_binding_level (void);
- static void declare_namespace_level (void);
  static int decl_jump_unsafe (tree);
  static void storedecls (tree);
  static void require_complete_types_for_parms (tree);
--- 55,64 ----
  static tree grokparms (tree);
  static const char *redeclaration_error_message (tree, tree);
  
! static void push_binding_level (cxx_scope *);
  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);
  static void require_complete_types_for_parms (tree);
*************** tree cp_global_trees[CPTI_MAX];
*** 203,208 ****
--- 200,208 ----
  
  static GTY(()) tree global_type_node;
  
+ /* The node that holds the "name" of the global scope.  */
+ static GTY(()) tree global_scope_name;
+ 
  /* Used only for jumps to as-yet undefined labels, since jumps to
     defined labels can have their validity checked immediately.  */
  
*************** struct cp_binding_level GTY(())
*** 358,365 ****
         that were entered and exited one level down.  */
      tree blocks;
  
!     /* The _TYPE node for this level, if parm_flag == 2.  */
!     tree this_class;
  
      /* The binding level which this one is contained in (inherits from).  */
      struct cp_binding_level *level_chain;
--- 358,366 ----
         that were entered and exited one level down.  */
      tree blocks;
  
!     /* The entity (namespace, class, function) the scope of which this
!        binding contour corresponds to.  Otherwise NULL.  */
!     tree this_entity;
  
      /* The binding level which this one is contained in (inherits from).  */
      struct cp_binding_level *level_chain;
*************** indent (int depth)
*** 464,490 ****
  
  static tree pushdecl_with_scope	(tree, struct cp_binding_level *);
  
  static void
! push_binding_level (struct cp_binding_level *newlevel, 
!                     int tag_transparent, 
!                     int keep)
  {
    /* Add this level to the front of the chain (stack) of levels that
       are active.  */
-   memset ((char*) newlevel, 0, sizeof (struct cp_binding_level));
    newlevel->level_chain = current_binding_level;
    current_binding_level = newlevel;
-   newlevel->tag_transparent = tag_transparent;
-   newlevel->more_cleanups_ok = 1;
  
-   newlevel->keep = keep;
    if (ENABLE_SCOPE_CHECKING)
      {
        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++;
      }
--- 465,548 ----
  
  static tree pushdecl_with_scope	(tree, struct cp_binding_level *);
  
+ /* Return a string describing the kind of SCOPE we have.  */
+ static const char *
+ cxx_scope_descriptor (cxx_scope *scope)
+ {
+   const char *desc;
+ 
+   if (scope->namespace_p)
+     desc = "namespace-scope";
+   else if (scope->parm_flag == 1)
+     desc = "function-prototype-scope";
+   else if (scope->parm_flag == 2)
+     desc = "class-scope";
+   else if (scope->is_for_scope)
+     desc = "for-scope";
+   else if (scope->is_try_scope)
+     desc = "try-scope";
+   else if (scope->is_catch_scope)
+     desc = "catch-scope";
+   else if (scope->template_spec_p)
+     desc = "template-explicit-spec-scope";
+   else if (scope->template_parms_p)
+     desc = "template-prototype-scope";
+   else
+     desc = "block-scope";
+ 
+   return desc;
+ }
+ 
+ /* Output a debugging information about SCOPE when performning
+    ACTION at LINE.  */
+ static void
+ cxx_scope_debug (cxx_scope *scope, int line, const char *action)
+ {
+   const char *desc = cxx_scope_descriptor (scope);
+   if (scope->this_entity)
+     verbatim ("%s %s(%E) %p %d\n", action, desc,
+               scope->this_entity, (void *) scope, line);
+   else
+     verbatim ("%s %s %p %d\n", action, desc, (void *) scope, line);
+ }
+ 
+ /* Construct a scope that may be TAG-TRANSPARENT, the sub-blocks of
+    which may be KEPT.  */
+ static inline cxx_scope *
+ make_cxx_scope (bool tag_transparent, int keep)
+ {
+   cxx_scope *scope;
+   
+   /* Reuse or create a struct for this binding level.  */
+   if (!ENABLE_SCOPE_CHECKING && free_binding_level)
+     {
+       scope = free_binding_level;
+       free_binding_level = scope->level_chain;
+     }
+   else
+     scope = ggc_alloc (sizeof (cxx_scope));
+ 
+   memset (scope, 0, sizeof (cxx_scope));
+   scope->tag_transparent = tag_transparent;
+   scope->keep = keep;
+   scope->more_cleanups_ok = true;
+ 
+   return scope;
+ }
+ 
  static void
! push_binding_level (cxx_scope *newlevel)
  {
    /* Add this level to the front of the chain (stack) of levels that
       are active.  */
    newlevel->level_chain = current_binding_level;
    current_binding_level = newlevel;
  
    if (ENABLE_SCOPE_CHECKING)
      {
        newlevel->binding_depth = binding_depth;
        indent (binding_depth);
!       cxx_scope_debug (newlevel, input_location.line, "push");
        is_class_level = 0;
        binding_depth++;
      }
*************** pop_binding_level (void)
*** 516,524 ****
    if (ENABLE_SCOPE_CHECKING)
      {
        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);
--- 574,580 ----
    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);
*************** suspend_binding_level (void)
*** 556,564 ****
    if (ENABLE_SCOPE_CHECKING)
      {
        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);
--- 612,618 ----
    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);
*************** resume_binding_level (struct cp_binding_
*** 584,606 ****
      {
        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'.  */
- 
- static
- struct cp_binding_level *
- make_binding_level (void)
- {
-   /* NOSTRICT */
-   return (struct cp_binding_level *) ggc_alloc (sizeof (struct cp_binding_level));
- }
- 
  /* Nonzero if we are currently in the global binding level.  */
  
  int
--- 638,649 ----
      {
        b->binding_depth = binding_depth;
        indent (binding_depth);
!       cxx_scope_debug (b, input_location.line, "resume");
        is_class_level = 0;
        binding_depth++;
      }
  }
  
  /* Nonzero if we are currently in the global binding level.  */
  
  int
*************** kept_level_p (void)
*** 671,682 ****
  	      && !current_binding_level->tag_transparent));
  }
  
- static void
- declare_namespace_level (void)
- {
-   current_binding_level->namespace_p = 1;
- }
- 
  /* Returns nonzero if this scope was created to store template
     parameters.  */
  
--- 714,719 ----
*************** set_class_shadows (tree shadows)
*** 787,807 ****
  void
  pushlevel (int tag_transparent)
  {
-   struct cp_binding_level *newlevel;
- 
    if (cfun && !doing_semantic_analysis_p ())
      return;
  
!   /* Reuse or create a struct for this binding level.  */
!   if (!ENABLE_SCOPE_CHECKING && free_binding_level)
!     {
!       newlevel = free_binding_level;
!       free_binding_level = free_binding_level->level_chain;
!     }
!   else
!     newlevel = make_binding_level ();
! 
!   push_binding_level (newlevel, tag_transparent, keep_next_level_flag);
    keep_next_level_flag = 0;
  }
  
--- 824,833 ----
  void
  pushlevel (int tag_transparent)
  {
    if (cfun && !doing_semantic_analysis_p ())
      return;
  
!   push_binding_level (make_cxx_scope (tag_transparent, keep_next_level_flag));
    keep_next_level_flag = 0;
  }
  
*************** set_block (tree block ATTRIBUTE_UNUSED )
*** 1550,1574 ****
  void
  pushlevel_class (void)
  {
-   register struct cp_binding_level *newlevel;
- 
-   /* Reuse or create a struct for this binding level.  */
-   if (!ENABLE_SCOPE_CHECKING && free_binding_level)
-     {
-       newlevel = free_binding_level;
-       free_binding_level = free_binding_level->level_chain;
-     }
-   else
-     newlevel = make_binding_level ();
- 
    if (ENABLE_SCOPE_CHECKING)
      is_class_level = 1;
  
!   push_binding_level (newlevel, 0, 0);
  
    class_binding_level = current_binding_level;
    class_binding_level->parm_flag = 2;
!   class_binding_level->this_class = current_class_type;
  }
  
  /* ...and a poplevel for class declarations.  */
--- 1576,1589 ----
  void
  pushlevel_class (void)
  {
    if (ENABLE_SCOPE_CHECKING)
      is_class_level = 1;
  
!   push_binding_level (make_cxx_scope (false, 0));
  
    class_binding_level = current_binding_level;
    class_binding_level->parm_flag = 2;
!   class_binding_level->this_entity = current_class_type;
  }
  
  /* ...and a poplevel for class declarations.  */
*************** print_binding_stack (void)
*** 1988,1993 ****
--- 2003,2033 ----
     the identifier is polymorphic, with three possible values:
     NULL_TREE, a list of "cxx_binding"s.  */
  
+ 
+ /* Push the initial binding contour of NAMESPACE-scope.  Any subsequent
+    push of NS is actually a resume.  */
+ static void
+ initial_push_namespace_scope (tree ns)
+ {
+   tree name = DECL_NAME (ns);
+   cxx_scope *scope;
+ 
+   pushlevel (0);
+   scope = current_binding_level;
+   scope->namespace_p = true;
+   scope->type_decls = binding_table_new (name == std_identifier
+                                          ? NAMESPACE_STD_HT_SIZE
+                                          : (name == global_scope_name
+                                             ? GLOBAL_SCOPE_HT_SIZE
+                                             : NAMESPACE_ORDINARY_HT_SIZE));
+   VARRAY_TREE_INIT (scope->static_decls,
+                     name == std_identifier || name == global_scope_name
+                     ? 200 : 10,
+                     "Static declarations");
+   scope->this_entity = ns;
+   NAMESPACE_LEVEL (ns) = scope;
+ }
+ 
  /* Push into the scope of the NAME namespace.  If NAME is NULL_TREE, then we
     select a name that is unique to this compilation unit.  */
  
*************** push_namespace (tree name)
*** 1997,2013 ****
    tree d = NULL_TREE;
    int need_new = 1;
    int implicit_use = 0;
-   int global = 0;
  
    timevar_push (TV_NAME_LOOKUP);
    
!   if (!global_namespace)
!     {
!       /* This must be ::.  */
!       my_friendly_assert (name == get_identifier ("::"), 377);
!       global = 1;
!     }
!   else if (!name)
      {
        /* The name of anonymous namespace is unique for the translation
           unit.  */
--- 2037,2052 ----
    tree d = NULL_TREE;
    int need_new = 1;
    int implicit_use = 0;
  
    timevar_push (TV_NAME_LOOKUP);
    
!   /* 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.  */
!   my_friendly_assert (global_namespace != NULL && name != global_scope_name,
!                       20030531);
! 
!   if (!name)
      {
        /* The name of anonymous namespace is unique for the translation
           unit.  */
*************** push_namespace (tree name)
*** 2040,2062 ****
      {
        /* Make a new namespace, binding the name to it.  */
        d = build_lang_decl (NAMESPACE_DECL, name, void_type_node);
!       /* The global namespace is not pushed, and the global binding
! 	 level is set elsewhere.  */
!       if (!global)
! 	{
! 	  DECL_CONTEXT (d) = FROB_CONTEXT (current_namespace);
! 	  d = pushdecl (d);
! 	  pushlevel (0);
! 	  declare_namespace_level ();
! 	  NAMESPACE_LEVEL (d) = current_binding_level;
!           current_binding_level->type_decls =
!             binding_table_new (name == std_identifier
!                                ? NAMESPACE_STD_HT_SIZE
!                                : NAMESPACE_ORDINARY_HT_SIZE);
! 	  VARRAY_TREE_INIT (current_binding_level->static_decls,
! 			    name != std_identifier ? 10 : 200,
! 			    "Static declarations");
! 	}
      }
    else
      resume_binding_level (NAMESPACE_LEVEL (d));
--- 2079,2087 ----
      {
        /* Make a new namespace, binding the name to it.  */
        d = build_lang_decl (NAMESPACE_DECL, name, void_type_node);
!       DECL_CONTEXT (d) = FROB_CONTEXT (current_namespace);
!       d = pushdecl (d);
!       initial_push_namespace_scope (d);
      }
    else
      resume_binding_level (NAMESPACE_LEVEL (d));
*************** pushtag (tree name, tree type, int globa
*** 2518,2524 ****
  		    of a static member variable. We allow this when
  		    not pedantic, and it is particularly useful for
  		    type punning via an anonymous union.  */
! 		 || COMPLETE_TYPE_P (b->this_class))))
      b = b->level_chain;
  
    if (b->type_decls == NULL)
--- 2543,2549 ----
  		    of a static member variable. We allow this when
  		    not pedantic, and it is particularly useful for
  		    type punning via an anonymous union.  */
! 		 || COMPLETE_TYPE_P (b->this_entity))))
      b = b->level_chain;
  
    if (b->type_decls == NULL)
*************** lookup_name_real (tree name, int prefer_
*** 5829,5835 ****
  	    continue;
  	  
  	  /* Lookup the conversion operator in the class.  */
! 	  class_type = level->this_class;
  	  operators = lookup_fnfields (class_type, name, /*protect=*/0);
  	  if (operators)
  	    POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, operators);
--- 5854,5860 ----
  	    continue;
  	  
  	  /* Lookup the conversion operator in the class.  */
! 	  class_type = level->this_entity;
  	  operators = lookup_fnfields (class_type, name, /*protect=*/0);
  	  if (operators)
  	    POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, operators);
*************** initialize_predefined_identifiers (void)
*** 6104,6109 ****
--- 6129,6135 ----
      { VTABLE_PFN_NAME, &pfn_identifier, 0 },
      { "_vptr", &vptr_identifier, 0 },
      { "__vtt_parm", &vtt_parm_identifier, 0 },
+     { "::", &global_scope_name, 0 },
      { "std", &std_identifier, 0 },
      { NULL, NULL, 0 }
    };
*************** cxx_init_decl_processing (void)
*** 6136,6145 ****
    /* Create the global variables.  */
    push_to_top_level ();
  
    /* Enter the global namespace.  */
    my_friendly_assert (global_namespace == NULL_TREE, 375);
!   push_namespace (get_identifier ("::"));
!   global_namespace = current_namespace;
    current_lang_name = NULL_TREE;
  
    /* Adjust various flags based on command-line settings.  */
--- 6162,6176 ----
    /* Create the global variables.  */
    push_to_top_level ();
  
+   current_function_decl = NULL_TREE;
+   current_binding_level = NULL_BINDING_LEVEL;
+   free_binding_level = NULL_BINDING_LEVEL;
    /* Enter the global namespace.  */
    my_friendly_assert (global_namespace == NULL_TREE, 375);
!   global_namespace = build_lang_decl (NAMESPACE_DECL, global_scope_name,
!                                       void_type_node);
!   initial_push_namespace_scope (global_namespace);
! 
    current_lang_name = NULL_TREE;
  
    /* Adjust various flags based on command-line settings.  */
*************** cxx_init_decl_processing (void)
*** 6165,6189 ****
    /* Initially, C.  */
    current_lang_name = lang_name_c;
  
-   current_function_decl = NULL_TREE;
-   current_binding_level = NULL_BINDING_LEVEL;
-   free_binding_level = NULL_BINDING_LEVEL;
- 
    build_common_tree_nodes (flag_signed_char);
  
    error_mark_list = build_tree_list (error_mark_node, error_mark_node);
    TREE_TYPE (error_mark_list) = error_mark_node;
- 
-   /* Make the binding_level structure for global names.  */
-   pushlevel (0);
-   current_binding_level->type_decls = binding_table_new (GLOBAL_SCOPE_HT_SIZE);
-   /* The global level is the namespace level of ::.  */
-   NAMESPACE_LEVEL (global_namespace) = current_binding_level;
-   declare_namespace_level ();
- 
-   VARRAY_TREE_INIT (current_binding_level->static_decls,
- 		    200,
- 		    "Static declarations");
  
    /* Create the `std' namespace.  */
    push_namespace (std_identifier);
--- 6196,6205 ----


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