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: [mainline] C++ PATCH: Remove global_binding_level


OK, thanks.

----- Original Message ----- 
From: "Gabriel Dos Reis" <gdr@integrable-solutions.net>
To: <gcc-patches@gcc.gnu.org>
Cc: <jason@redhat.com>; <mark@codesourcery.com>
Sent: Monday, May 26, 2003 6:20 PM
Subject: [mainline] C++ PATCH: Remove global_binding_level


>
> In the pre-namespace era it made sense to manipulate directly the
> global scope through global_binding_level.  However, with the
> implementation of namespace in cc1plus, we've got two ways to
> manipulate the global scope: Either through global_namespace or the
> old fashioned global_binding_level.  We're just asking for troubles.
>
> Since the object pointed to by global_binding_level is also pointed to
> by NAMESPACE_LEVEL (global_namespace), it makes sense to have just
> one, true, canonical way to access that data.  This patch implements
> that idea.
>
> Booststrapped and tested on an i686-pc-linux. No regression.
> OK for mainline?
> OK for branch?
>
> -- Gaby
>
> 2003-05-27  Gabriel Dos Reis <gdr@integrable-solutions.net>
>
> * name-lookup.h (global_scope_p): New macro.
> * decl.c (pop_binding_level): Use it.  Don't refer directly to
> global_binding_level.
> (suspend_binding_level): Likewise.
> (global_bindings_p): Likewise.
> (print_other_binding_stack): Likewise.
> (print_binding_stack): Likewise.
> (maybe_push_to_top_level): Likewise.
> (pushdecl_namespace_level): Likewise.
> (cxx_init_decl_processing): Likewise.
> (start_decl): Likewise.
> (cp_finish_decl): Likewise.
> (start_function): Likewise.
> (global_binding_level): Remove.
>
> Index: name-lookup.h
> ===================================================================
> RCS file: /cvs/gcc/gcc/gcc/cp/name-lookup.h,v
> retrieving revision 1.3
> diff -p -r1.3 name-lookup.h
> *** name-lookup.h 18 May 2003 13:40:54 -0000 1.3
> --- name-lookup.h 26 May 2003 22:17:32 -0000
> *************** struct cxx_binding GTY(())
> *** 108,113 ****
> --- 108,116 ----
>   extern cxx_binding *cxx_binding_make (tree, tree);
>   extern void cxx_binding_free (cxx_binding *);
>
> + /* True if SCOPE designates the global scope binding contour.  */
> + #define global_scope_p(SCOPE) \
> +   ((SCOPE) == NAMESPACE_LEVEL (global_namespace))
>
>   extern cxx_binding *cxx_scope_find_binding_for_name (cxx_scope *, tree);
>   extern cxx_binding *binding_for_name (cxx_scope *, tree);
> Index: decl.c
> ===================================================================
> RCS file: /cvs/gcc/gcc/gcc/cp/decl.c,v
> retrieving revision 1.1056
> diff -p -r1.1056 decl.c
> *** decl.c 21 May 2003 00:33:25 -0000 1.1056
> --- decl.c 26 May 2003 22:17:40 -0000
> *************** struct cp_binding_level GTY(())
> *** 438,449 ****
>
>   static GTY((deletable (""))) struct cp_binding_level
*free_binding_level;
>
> - /* The outermost binding level, for names of file scope.
> -    This is created when the compiler is started and exists
> -    through the entire run.  */
> -
> - static GTY(()) struct cp_binding_level *global_binding_level;
> -
>   /* Nonzero means unconditionally make a BLOCK for the next level pushed.
*/
>
>   static int keep_next_level_flag;
> --- 438,443 ----
> *************** find_class_binding_level (void)
> *** 513,524 ****
>   static void
>   pop_binding_level (void)
>   {
> !   if (global_binding_level)
> !     {
> !       /* Cannot pop a level, if there are none left to pop.  */
> !       if (current_binding_level == global_binding_level)
> ! abort ();
> !     }
>     /* Pop the current level, and free the structure for reuse.  */
>   #if defined(DEBUG_BINDING_LEVELS)
>     binding_depth--;
> --- 507,515 ----
>   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 defined(DEBUG_BINDING_LEVELS)
>     binding_depth--;
> *************** suspend_binding_level (void)
> *** 556,567 ****
>     if (class_binding_level)
>       current_binding_level = class_binding_level;
>
> !   if (global_binding_level)
> !     {
> !       /* Cannot suspend a level, if there are none left to suspend.  */
> !       if (current_binding_level == global_binding_level)
> ! abort ();
> !     }
>     /* Suspend the current level.  */
>   #if defined(DEBUG_BINDING_LEVELS)
>     binding_depth--;
> --- 547,555 ----
>     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 defined(DEBUG_BINDING_LEVELS)
>     binding_depth--;
> *************** make_binding_level (void)
> *** 614,620 ****
>   int
>   global_bindings_p (void)
>   {
> !   return current_binding_level == global_binding_level;
>   }
>
>   /* Return the innermost binding level that is not for a class scope.  */
> --- 602,608 ----
>   int
>   global_bindings_p (void)
>   {
> !   return global_scope_p (current_binding_level);
>   }
>
>   /* Return the innermost binding level that is not for a class scope.  */
> *************** void
> *** 1964,1970 ****
>   print_other_binding_stack (struct cp_binding_level *stack)
>   {
>     struct cp_binding_level *level;
> !   for (level = stack; level != global_binding_level; level =
level->level_chain)
>       {
>         fprintf (stderr, "binding level ");
>         fprintf (stderr, HOST_PTR_PRINTF, (void *) level);
> --- 1952,1958 ----
>   print_other_binding_stack (struct cp_binding_level *stack)
>   {
>     struct cp_binding_level *level;
> !   for (level = stack; !global_scope_p (level); level =
level->level_chain)
>       {
>         fprintf (stderr, "binding level ");
>         fprintf (stderr, HOST_PTR_PRINTF, (void *) level);
> *************** print_binding_stack (void)
> *** 1981,1988 ****
>     fprintf (stderr, HOST_PTR_PRINTF, (void *) current_binding_level);
>     fprintf (stderr, "\nclass_binding_level=");
>     fprintf (stderr, HOST_PTR_PRINTF, (void *) class_binding_level);
> !   fprintf (stderr, "\nglobal_binding_level=");
> !   fprintf (stderr, HOST_PTR_PRINTF, (void *) global_binding_level);
>     fprintf (stderr, "\n");
>     if (class_binding_level)
>       {
> --- 1969,1977 ----
>     fprintf (stderr, HOST_PTR_PRINTF, (void *) current_binding_level);
>     fprintf (stderr, "\nclass_binding_level=");
>     fprintf (stderr, HOST_PTR_PRINTF, (void *) class_binding_level);
> !   fprintf (stderr, "\nNAMESPACE_LEVEL (global_namespace)=");
> !   fprintf (stderr, HOST_PTR_PRINTF,
> !            (void *) NAMESPACE_LEVEL (global_namespace));
>     fprintf (stderr, "\n");
>     if (class_binding_level)
>       {
> *************** print_binding_stack (void)
> *** 1998,2004 ****
>       b = current_binding_level;
>     print_other_binding_stack (b);
>     fprintf (stderr, "global:\n");
> !   print_binding_level (global_binding_level);
>   }
>
>   /* Namespace binding access routines: The namespace_bindings field of
> --- 1987,1993 ----
>       b = current_binding_level;
>     print_other_binding_stack (b);
>     fprintf (stderr, "global:\n");
> !   print_binding_level (NAMESPACE_LEVEL (global_namespace));
>   }
>
>   /* Namespace binding access routines: The namespace_bindings field of
> *************** maybe_push_to_top_level (int pseudo)
> *** 2224,2230 ****
>     if (scope_chain && previous_class_type)
>       old_bindings = store_bindings (previous_class_values, old_bindings);
>
> !   /* Have to include global_binding_level, because class-level decls
>        aren't listed anywhere useful.  */
>     for (; b; b = b->level_chain)
>       {
> --- 2213,2219 ----
>     if (scope_chain && previous_class_type)
>       old_bindings = store_bindings (previous_class_values, old_bindings);
>
> !   /* Have to include the global scope, because class-scope decls
>        aren't listed anywhere useful.  */
>     for (; b; b = b->level_chain)
>       {
> *************** maybe_push_to_top_level (int pseudo)
> *** 2234,2240 ****
>   inserted into namespace level, finish_file wouldn't find them
>   when doing pending instantiations. Therefore, don't stop at
>   namespace level, but continue until :: .  */
> !       if (b == global_binding_level || (pseudo && b->template_parms_p))
>   break;
>
>         old_bindings = store_bindings (b->names, old_bindings);
> --- 2223,2229 ----
>   inserted into namespace level, finish_file wouldn't find them
>   when doing pending instantiations. Therefore, don't stop at
>   namespace level, but continue until :: .  */
> !       if (global_scope_p (b) || (pseudo && b->template_parms_p))
>   break;
>
>         old_bindings = store_bindings (b->names, old_bindings);
> *************** pushdecl_namespace_level (tree x)
> *** 4110,4116 ****
>         tree name = DECL_NAME (x);
>         tree newval;
>         tree *ptr = (tree *)0;
> !       for (; b != global_binding_level; b = b->level_chain)
>           {
>             tree shadowed = b->type_shadowed;
>             for (; shadowed; shadowed = TREE_CHAIN (shadowed))
> --- 4099,4105 ----
>         tree name = DECL_NAME (x);
>         tree newval;
>         tree *ptr = (tree *)0;
> !       for (; !global_scope_p (b); b = b->level_chain)
>           {
>             tree shadowed = b->type_shadowed;
>             for (; shadowed; shadowed = TREE_CHAIN (shadowed))
> *************** pushdecl_namespace_level (tree x)
> *** 4137,4144 ****
>     POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, t);
>   }
>
> ! /* Like pushdecl, only it places X in GLOBAL_BINDING_LEVEL,
> !    if appropriate.  */
>
>   tree
>   pushdecl_top_level (tree x)
> --- 4126,4132 ----
>     POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, t);
>   }
>
> ! /* Like pushdecl, only it places X in the global scope if appropriate.
*/
>
>   tree
>   pushdecl_top_level (tree x)
> *************** cxx_init_decl_processing (void)
> *** 6196,6208 ****
>
>     /* Make the binding_level structure for global names.  */
>     pushlevel (0);
> !   global_binding_level = current_binding_level;
> !   global_binding_level->type_decls = binding_table_new
(GLOBAL_SCOPE_HT_SIZE);
>     /* The global level is the namespace level of ::.  */
> !   NAMESPACE_LEVEL (global_namespace) = global_binding_level;
>     declare_namespace_level ();
>
> !   VARRAY_TREE_INIT (global_binding_level->static_decls,
>       200,
>       "Static declarations");
>
> --- 6184,6195 ----
>
>     /* 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");
>
> *************** start_decl (tree declarator,
> *** 6984,6990 ****
>     cplus_decl_attributes (&decl, attributes, 0);
>
>     /* If #pragma weak was used, mark the decl weak now.  */
> !   if (current_binding_level == global_binding_level)
>       maybe_apply_pragma_weak (decl);
>
>     if (TREE_CODE (decl) == FUNCTION_DECL
> --- 6971,6977 ----
>     cplus_decl_attributes (&decl, attributes, 0);
>
>     /* If #pragma weak was used, mark the decl weak now.  */
> !   if (global_scope_p (current_binding_level))
>       maybe_apply_pragma_weak (decl);
>
>     if (TREE_CODE (decl) == FUNCTION_DECL
> *************** cp_finish_decl (tree decl, tree init, tr
> *** 7997,8003 ****
>       }
>
>     /* If a name was specified, get the string.  */
> !   if (current_binding_level == global_binding_level)
>       asmspec_tree = maybe_apply_renaming_pragma (decl, asmspec_tree);
>     if (asmspec_tree)
>       asmspec = TREE_STRING_POINTER (asmspec_tree);
> --- 7984,7990 ----
>       }
>
>     /* If a name was specified, get the string.  */
> !   if (global_scope_p (current_binding_level))
>       asmspec_tree = maybe_apply_renaming_pragma (decl, asmspec_tree);
>     if (asmspec_tree)
>       asmspec = TREE_STRING_POINTER (asmspec_tree);
> *************** start_function (tree declspecs, tree dec
> *** 13345,13351 ****
>         cplus_decl_attributes (&decl1, attrs, 0);
>
>         /* If #pragma weak was used, mark the decl weak now.  */
> !       if (current_binding_level == global_binding_level)
>   maybe_apply_pragma_weak (decl1);
>
>         fntype = TREE_TYPE (decl1);
> --- 13332,13338 ----
>         cplus_decl_attributes (&decl1, attrs, 0);
>
>         /* If #pragma weak was used, mark the decl weak now.  */
> !       if (global_scope_p (current_binding_level))
>   maybe_apply_pragma_weak (decl1);
>
>         fntype = TREE_TYPE (decl1);
>


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