From 1ec57cf03b8ba96e9e98553cabf16b2f70d062a6 Mon Sep 17 00:00:00 2001 From: Gabriel Dos Reis <gdr@integrable-solutions.net> Date: Fri, 3 Oct 2003 20:27:05 +0000 Subject: [PATCH] decl.c (struct cp_binding_level): Move to name-lookup.h * decl.c (struct cp_binding_level): Move to name-lookup.h (current_binding_level): Likewise. (class_binding_level): Likewise. * cp-tree.h (enum scope_kind): Likewise. From-SVN: r72076 --- gcc/cp/ChangeLog | 7 +++ gcc/cp/cp-tree.h | 25 -------- gcc/cp/decl.c | 127 +------------------------------------ gcc/cp/name-lookup.h | 147 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 155 insertions(+), 151 deletions(-) diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 50df2b92f1d1..3cc736991c4c 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +2003-10-03 Gabriel Dos Reis <gdr@integrable-solutions.net> + + * decl.c (struct cp_binding_level): Move to name-lookup.h + (current_binding_level): Likewise. + (class_binding_level): Likewise. + * cp-tree.h (enum scope_kind): Likewise. + 2003-10-03 Gabriel Dos Reis <gdr@integrable-solutions.net> * name-lookup.c (binding_entry_free): Nullify name and type diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 0786bc558fb1..eb6b6c2f81e6 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -2926,31 +2926,6 @@ typedef enum cp_lvalue_kind { clk_packed = 8 /* An lvalue for a packed field. */ } cp_lvalue_kind; -/* The kinds of scopes we recognize. */ -typedef enum scope_kind { - sk_block = 0, /* An ordinary block scope. This enumerator must - have the value zero because "cp_binding_level" - is initialized by using "memset" to set the - contents to zero, and the default scope kind - is "sk_block". */ - sk_cleanup, /* A scope for (pseudo-)scope for cleanup. It is - peusdo in that it is transparent to name lookup - activities. */ - sk_try, /* A try-block. */ - sk_catch, /* A catch-block. */ - sk_for, /* The scope of the variable declared in a - for-init-statement. */ - sk_function_parms, /* The scope containing function parameters. */ - sk_class, /* The scope containing the members of a class. */ - sk_namespace, /* The scope containing the members of a - namespace, including the global scope. */ - sk_template_parms, /* A scope for template parameters. */ - sk_template_spec /* Like sk_template_parms, but for an explicit - specialization. Since, by definition, an - explicit specialization is introduced by - "template <>", this scope is always empty. */ -} scope_kind; - /* Various kinds of template specialization, instantiation, etc. */ typedef enum tmpl_spec_kind { tsk_none, /* Not a template at all. */ diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 64d8e5252b1d..729e54990a96 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -278,130 +278,6 @@ int adding_implicit_members = 0; bool have_extern_spec; -/* For each binding contour we allocate a binding_level structure - which records the names defined in that contour. - Contours include: - 0) the global one - 1) one for each function definition, - where internal declarations of the parameters appear. - 2) one for each compound statement, - to record its declarations. - - The current meaning of a name can be found by searching the levels - from the current one out to the global one. - - Off to the side, may be the class_binding_level. This exists only - to catch class-local declarations. It is otherwise nonexistent. - - Also there may be binding levels that catch cleanups that must be - run when exceptions occur. Thus, to see whether a name is bound in - the current scope, it is not enough to look in the - CURRENT_BINDING_LEVEL. You should use lookup_name_current_level - instead. */ - -/* Note that the information in the `names' component of the global contour - is duplicated in the IDENTIFIER_GLOBAL_VALUEs of all identifiers. */ - -struct cp_binding_level GTY(()) - { - /* A chain of _DECL nodes for all variables, constants, functions, - and typedef types. These are in the reverse of the order - supplied. There may be OVERLOADs on this list, too, but they - are wrapped in TREE_LISTs; the TREE_VALUE is the OVERLOAD. */ - tree names; - - /* Count of elements in names chain. */ - size_t names_size; - - /* A chain of NAMESPACE_DECL nodes. */ - tree namespaces; - - /* An array of static functions and variables (for namespaces only) */ - varray_type static_decls; - - /* A chain of VTABLE_DECL nodes. */ - tree vtables; - - /* A dictionary for looking up user-defined-types. */ - binding_table type_decls; - - /* A list of USING_DECL nodes. */ - tree usings; - - /* A list of used namespaces. PURPOSE is the namespace, - VALUE the common ancestor with this binding_level's namespace. */ - tree using_directives; - - /* If this binding level is the binding level for a class, then - class_shadowed is a TREE_LIST. The TREE_PURPOSE of each node - is the name of an entity bound in the class. The TREE_TYPE is - the DECL bound by this name in the class. */ - tree class_shadowed; - - /* Similar to class_shadowed, but for IDENTIFIER_TYPE_VALUE, and - is used for all binding levels. In addition the TREE_VALUE is the - IDENTIFIER_TYPE_VALUE before we entered the class. */ - tree type_shadowed; - - /* A TREE_LIST. Each TREE_VALUE is the LABEL_DECL for a local - label in this scope. The TREE_PURPOSE is the previous value of - the IDENTIFIER_LABEL VALUE. */ - tree shadowed_labels; - - /* For each level (except not the global one), - a chain of BLOCK nodes for all the levels - 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; - - /* List of VAR_DECLS saved from a previous for statement. - These would be dead in ISO-conforming code, but might - be referenced in ARM-era code. These are stored in a - TREE_LIST; the TREE_VALUE is the actual declaration. */ - tree dead_vars_from_for; - - /* Binding depth at which this level began. */ - int binding_depth; - - /* The kind of scope that this object represents. However, a - SK_TEMPLATE_SPEC scope is represented with KIND set to - SK_TEMPALTE_PARMS and EXPLICIT_SPEC_P set to true. */ - enum scope_kind kind : 4; - - /* True if this scope is an SK_TEMPLATE_SPEC scope. This field is - only valid if KIND == SK_TEMPLATE_PARMS. */ - bool explicit_spec_p : 1; - - /* true means make a BLOCK for this level regardless of all else. */ - unsigned keep : 1; - - /* Nonzero if this level can safely have additional - cleanup-needing variables added to it. */ - unsigned more_cleanups_ok : 1; - unsigned have_cleanups : 1; - - /* 22 bits left to fill a 32-bit word. */ - }; - -#define NULL_BINDING_LEVEL ((struct cp_binding_level *) NULL) - -/* The binding level currently in effect. */ - -#define current_binding_level \ - (*(cfun && cp_function_chain->bindings \ - ? &cp_function_chain->bindings \ - : &scope_chain->bindings)) - -/* The binding level of the current class, if any. */ - -#define class_binding_level scope_chain->class_bindings - /* A chain of binding_level structures awaiting reuse. */ static GTY((deletable (""))) struct cp_binding_level *free_binding_level; @@ -6055,8 +5931,7 @@ cxx_init_decl_processing (void) push_to_top_level (); current_function_decl = NULL_TREE; - current_binding_level = NULL_BINDING_LEVEL; - free_binding_level = NULL_BINDING_LEVEL; + current_binding_level = NULL; /* Enter the global namespace. */ my_friendly_assert (global_namespace == NULL_TREE, 375); global_namespace = build_lang_decl (NAMESPACE_DECL, global_scope_name, diff --git a/gcc/cp/name-lookup.h b/gcc/cp/name-lookup.h index 04c6161dbc44..15f1936ebf27 100644 --- a/gcc/cp/name-lookup.h +++ b/gcc/cp/name-lookup.h @@ -97,6 +97,153 @@ extern cxx_binding *cxx_binding_make (tree, tree); extern void cxx_binding_free (cxx_binding *); extern bool supplement_binding (cxx_binding *, tree); +/* The kinds of scopes we recognize. */ +typedef enum scope_kind { + sk_block = 0, /* An ordinary block scope. This enumerator must + have the value zero because "cp_binding_level" + is initialized by using "memset" to set the + contents to zero, and the default scope kind + is "sk_block". */ + sk_cleanup, /* A scope for (pseudo-)scope for cleanup. It is + peusdo in that it is transparent to name lookup + activities. */ + sk_try, /* A try-block. */ + sk_catch, /* A catch-block. */ + sk_for, /* The scope of the variable declared in a + for-init-statement. */ + sk_function_parms, /* The scope containing function parameters. */ + sk_class, /* The scope containing the members of a class. */ + sk_namespace, /* The scope containing the members of a + namespace, including the global scope. */ + sk_template_parms, /* A scope for template parameters. */ + sk_template_spec /* Like sk_template_parms, but for an explicit + specialization. Since, by definition, an + explicit specialization is introduced by + "template <>", this scope is always empty. */ +} scope_kind; + +/* For each binding contour we allocate a binding_level structure + which records the names defined in that contour. + Contours include: + 0) the global one + 1) one for each function definition, + where internal declarations of the parameters appear. + 2) one for each compound statement, + to record its declarations. + + The current meaning of a name can be found by searching the levels + from the current one out to the global one. + + Off to the side, may be the class_binding_level. This exists only + to catch class-local declarations. It is otherwise nonexistent. + + Also there may be binding levels that catch cleanups that must be + run when exceptions occur. Thus, to see whether a name is bound in + the current scope, it is not enough to look in the + CURRENT_BINDING_LEVEL. You should use lookup_name_current_level + instead. */ + +/* Note that the information in the `names' component of the global contour + is duplicated in the IDENTIFIER_GLOBAL_VALUEs of all identifiers. */ + +struct cp_binding_level GTY(()) + { + /* A chain of _DECL nodes for all variables, constants, functions, + and typedef types. These are in the reverse of the order + supplied. There may be OVERLOADs on this list, too, but they + are wrapped in TREE_LISTs; the TREE_VALUE is the OVERLOAD. */ + tree names; + + /* Count of elements in names chain. */ + size_t names_size; + + /* A chain of NAMESPACE_DECL nodes. */ + tree namespaces; + + /* An array of static functions and variables (for namespaces only) */ + varray_type static_decls; + + /* A chain of VTABLE_DECL nodes. */ + tree vtables; + + /* A dictionary for looking up user-defined-types. */ + binding_table type_decls; + + /* A list of USING_DECL nodes. */ + tree usings; + + /* A list of used namespaces. PURPOSE is the namespace, + VALUE the common ancestor with this binding_level's namespace. */ + tree using_directives; + + /* If this binding level is the binding level for a class, then + class_shadowed is a TREE_LIST. The TREE_PURPOSE of each node + is the name of an entity bound in the class. The TREE_TYPE is + the DECL bound by this name in the class. */ + tree class_shadowed; + + /* Similar to class_shadowed, but for IDENTIFIER_TYPE_VALUE, and + is used for all binding levels. In addition the TREE_VALUE is the + IDENTIFIER_TYPE_VALUE before we entered the class. */ + tree type_shadowed; + + /* A TREE_LIST. Each TREE_VALUE is the LABEL_DECL for a local + label in this scope. The TREE_PURPOSE is the previous value of + the IDENTIFIER_LABEL VALUE. */ + tree shadowed_labels; + + /* For each level (except not the global one), + a chain of BLOCK nodes for all the levels + 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; + + /* List of VAR_DECLS saved from a previous for statement. + These would be dead in ISO-conforming code, but might + be referenced in ARM-era code. These are stored in a + TREE_LIST; the TREE_VALUE is the actual declaration. */ + tree dead_vars_from_for; + + /* Binding depth at which this level began. */ + int binding_depth; + + /* The kind of scope that this object represents. However, a + SK_TEMPLATE_SPEC scope is represented with KIND set to + SK_TEMPALTE_PARMS and EXPLICIT_SPEC_P set to true. */ + enum scope_kind kind : 4; + + /* True if this scope is an SK_TEMPLATE_SPEC scope. This field is + only valid if KIND == SK_TEMPLATE_PARMS. */ + bool explicit_spec_p : 1; + + /* true means make a BLOCK for this level regardless of all else. */ + unsigned keep : 1; + + /* Nonzero if this level can safely have additional + cleanup-needing variables added to it. */ + unsigned more_cleanups_ok : 1; + unsigned have_cleanups : 1; + + /* 22 bits left to fill a 32-bit word. */ + }; + +/* The binding level currently in effect. */ + +#define current_binding_level \ + (*(cfun && cp_function_chain->bindings \ + ? &cp_function_chain->bindings \ + : &scope_chain->bindings)) + +/* The binding level of the current class, if any. */ + +#define class_binding_level scope_chain->class_bindings + /* The tree node representing the global scope. */ extern GTY(()) tree global_namespace; -- GitLab