Commit 5f52c0e0 by Gabriel Dos Reis Committed by Gabriel Dos Reis

name-lookup.h (global_scope_p): New macro.

        * 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.

From-SVN: r67221
parent c8520e56
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.
2003-05-25 Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>
* parser.c (cp_parser_explicit_instantiation): Restore old
......
......@@ -438,12 +438,6 @@ struct cp_binding_level GTY(())
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;
......@@ -513,12 +507,9 @@ find_class_binding_level (void)
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 ();
}
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--;
......@@ -556,12 +547,9 @@ suspend_binding_level (void)
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 ();
}
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--;
......@@ -614,7 +602,7 @@ make_binding_level (void)
int
global_bindings_p (void)
{
return current_binding_level == global_binding_level;
return global_scope_p (current_binding_level);
}
/* Return the innermost binding level that is not for a class scope. */
......@@ -1964,7 +1952,7 @@ void
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)
for (level = stack; !global_scope_p (level); level = level->level_chain)
{
fprintf (stderr, "binding level ");
fprintf (stderr, HOST_PTR_PRINTF, (void *) level);
......@@ -1981,8 +1969,9 @@ print_binding_stack (void)
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, "\nNAMESPACE_LEVEL (global_namespace)=");
fprintf (stderr, HOST_PTR_PRINTF,
(void *) NAMESPACE_LEVEL (global_namespace));
fprintf (stderr, "\n");
if (class_binding_level)
{
......@@ -1998,7 +1987,7 @@ print_binding_stack (void)
b = current_binding_level;
print_other_binding_stack (b);
fprintf (stderr, "global:\n");
print_binding_level (global_binding_level);
print_binding_level (NAMESPACE_LEVEL (global_namespace));
}
/* Namespace binding access routines: The namespace_bindings field of
......@@ -2224,7 +2213,7 @@ maybe_push_to_top_level (int pseudo)
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
/* Have to include the global scope, because class-scope decls
aren't listed anywhere useful. */
for (; b; b = b->level_chain)
{
......@@ -2234,7 +2223,7 @@ maybe_push_to_top_level (int pseudo)
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))
if (global_scope_p (b) || (pseudo && b->template_parms_p))
break;
old_bindings = store_bindings (b->names, old_bindings);
......@@ -4110,7 +4099,7 @@ pushdecl_namespace_level (tree x)
tree name = DECL_NAME (x);
tree newval;
tree *ptr = (tree *)0;
for (; b != global_binding_level; b = b->level_chain)
for (; !global_scope_p (b); b = b->level_chain)
{
tree shadowed = b->type_shadowed;
for (; shadowed; shadowed = TREE_CHAIN (shadowed))
......@@ -4137,8 +4126,7 @@ pushdecl_namespace_level (tree x)
POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, t);
}
/* Like pushdecl, only it places X in GLOBAL_BINDING_LEVEL,
if appropriate. */
/* Like pushdecl, only it places X in the global scope if appropriate. */
tree
pushdecl_top_level (tree x)
......@@ -6196,13 +6184,12 @@ cxx_init_decl_processing (void)
/* 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);
current_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;
NAMESPACE_LEVEL (global_namespace) = current_binding_level;
declare_namespace_level ();
VARRAY_TREE_INIT (global_binding_level->static_decls,
VARRAY_TREE_INIT (current_binding_level->static_decls,
200,
"Static declarations");
......@@ -6984,7 +6971,7 @@ start_decl (tree declarator,
cplus_decl_attributes (&decl, attributes, 0);
/* If #pragma weak was used, mark the decl weak now. */
if (current_binding_level == global_binding_level)
if (global_scope_p (current_binding_level))
maybe_apply_pragma_weak (decl);
if (TREE_CODE (decl) == FUNCTION_DECL
......@@ -7997,7 +7984,7 @@ cp_finish_decl (tree decl, tree init, tree asmspec_tree, int flags)
}
/* If a name was specified, get the string. */
if (current_binding_level == global_binding_level)
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);
......@@ -13345,7 +13332,7 @@ start_function (tree declspecs, tree declarator, tree attrs, int flags)
cplus_decl_attributes (&decl1, attrs, 0);
/* If #pragma weak was used, mark the decl weak now. */
if (current_binding_level == global_binding_level)
if (global_scope_p (current_binding_level))
maybe_apply_pragma_weak (decl1);
fntype = TREE_TYPE (decl1);
......
......@@ -108,6 +108,9 @@ struct cxx_binding GTY(())
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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment