Commit af6fd53f by Gabriel Dos Reis Committed by Gabriel Dos Reis

Compile-time improvement: 2/n.

	* cp-tree.h (struct cxx_binding): New datatype;
	(struct lang_identifier): Use it.
	(LOCAL_BINDING_P): Adjust definition.
	(INHERITED_VALUE_BINDING_P): Likewise.
	(BINDING_SCOPE): Likewise.
	(BINDING_HAS_LEVEL_P): Likewise.
	(BINDING_VALUE): Likewise.
	(BINDING_TYPE): Likewise.
	(IDENTIFIER_VALUE): Likewise.
	(struct tree_binding): Remove.
	(TS_CP_BINDING): Likewise.
	((union lang_tree_node): Remove field "binding".
	(cxx_binding_clear): New macro.
	(binding_for_name): Adjust return type.
	(qualified_lookup_using_namespace): Adjust prototype.
	(lookup_using_namespace): Adjust prototype.
	(cxx_scope_find_binding_for_name): Declare.
	* cp-tree.def: Remove CPLUS_BINDING definition.
	* parse.y (parse_scoped_id): Don't type-abuse of 'id'.  Allocate
	temporary cxx_binding on stack.  Simplify.
	* decl.c (push_binding): Adjust local variable type.
	(add_binding): Likewise.
	(push_class_binding): Likewise.
	(pop_binding): Likewise.
	(poplevel): Likewise.
	(poplevel_class): Likewise.
	(free_bindings):  Adjust type.
	(find_binding): Adjust return type, add a third parameter. Remove
	non-useful assertion now that we use static typing.
	(cxx_scope_find_binding_for_name): New function.
	(binding_for_name): Use it.  Adjust local variable type. Simplify.
	(namespace_binding):  Simplify.
	(set_namespace_binding): Likewise.
	(set_identifier_type_value_with_scope): Adjust local variable type.
	(lookup_tag): Don't type-abuse of local variable 'old'.
	(lookup_namespace_name): Likewise.  Allocate binding on stack.
	(select_decl): Adjust prototype.
	(unqualified_namespace_lookup):  Allocate binding on stack.
	Don't type-abuse of local variable 'val'.
	(lookup_name_real): Likewise.
	(maybe_inject_for_scope_var): Adjust local variable type.
	(cp_tree_node_structure): Remove CPLUS_BINDING case label.
	(namespace_binding): Adjust logic, simplify.
	(BINDING_LEVEL): Adjust definition.
	(push_class_level_binding): Adjust local variable type.
	(struct cxx_saved_binding): Adjust field 'binding' type.
	* decl2.c (ambiguous_decl): Adjust prototype.
	(lookup_using_namespace): Adjust local variable type.
	(qualified_lookup_using_namespace): Catch type error and correct
	ensueing logic error.
	(do_nonmember_using_decl): Adjust local variable type.  Allocate
	temporary cxx_binding on stack.
	(do_toplevel_using_decl): Adjust local variable type.
	* ptree.c (cxx_print_cxx_binding): New function.
	(cxx_print_identifier): Use it.
	(cxx_print_xnode): Delete CPLUS_BINDING case label.

From-SVN: r64405
parent 151c68c3
2003-03-15 <gcc@integrable-solutions.net>
Compile-time improvement: 2/n.
* cp-tree.h (struct cxx_binding): New datatype;
(struct lang_identifier): Use it.
(LOCAL_BINDING_P): Adjust definition.
(INHERITED_VALUE_BINDING_P): Likewise.
(BINDING_SCOPE): Likewise.
(BINDING_HAS_LEVEL_P): Likewise.
(BINDING_VALUE): Likewise.
(BINDING_TYPE): Likewise.
(IDENTIFIER_VALUE): Likewise.
(struct tree_binding): Remove.
(TS_CP_BINDING): Likewise.
((union lang_tree_node): Remove field "binding".
(cxx_binding_clear): New macro.
(binding_for_name): Adjust return type.
(qualified_lookup_using_namespace): Adjust prototype.
(lookup_using_namespace): Adjust prototype.
(cxx_scope_find_binding_for_name): Declare.
* cp-tree.def: Remove CPLUS_BINDING definition.
* decl.c (push_binding): Adjust local variable type.
(add_binding): Likewise.
(push_class_binding): Likewise.
(pop_binding): Likewise.
(poplevel): Likewise.
(poplevel_class): Likewise.
(free_bindings): Adjust type.
(find_binding): Adjust return type, add a third parameter. Remove
non-useful assertion now that we use static typing.
(cxx_scope_find_binding_for_name): New function.
(binding_for_name): Use it. Adjust local variable type. Simplify.
(namespace_binding): Simplify.
(set_namespace_binding): Likewise.
(set_identifier_type_value_with_scope): Adjust local variable type.
(lookup_tag): Don't type-abuse of local variable 'old'.
(lookup_namespace_name): Likewise. Allocate binding on stack.
(select_decl): Adjust prototype.
(unqualified_namespace_lookup): Allocate binding on stack.
Don't type-abuse of local variable 'val'.
(lookup_name_real): Likewise.
(maybe_inject_for_scope_var): Adjust local variable type.
(cp_tree_node_structure): Remove CPLUS_BINDING case label.
(namespace_binding): Adjust logic, simplify.
(BINDING_LEVEL): Adjust definition.
(push_class_level_binding): Adjust local variable type.
(struct cxx_saved_binding): Adjust field 'binding' type.
* decl2.c (ambiguous_decl): Adjust prototype.
(lookup_using_namespace): Adjust local variable type.
(qualified_lookup_using_namespace): Catch type error and correct
ensueing logic error.
(do_nonmember_using_decl): Adjust local variable type. Allocate
temporary cxx_binding on stack.
(do_toplevel_using_decl): Adjust local variable type.
* ptree.c (cxx_print_cxx_binding): New function.
(cxx_print_identifier): Use it.
(cxx_print_xnode): Delete CPLUS_BINDING case label.
2003-03-15 Roger Sayle <roger@eyesopen.com> 2003-03-15 Roger Sayle <roger@eyesopen.com>
* tree.c (count_functions): Fix whitespace. * tree.c (count_functions): Fix whitespace.
......
...@@ -222,11 +222,6 @@ DEFTREECODE (DEFAULT_ARG, "default_arg", 'x', 2) ...@@ -222,11 +222,6 @@ DEFTREECODE (DEFAULT_ARG, "default_arg", 'x', 2)
the template may be a LOOKUP_EXPR. */ the template may be a LOOKUP_EXPR. */
DEFTREECODE (TEMPLATE_ID_EXPR, "template_id_expr", 'e', 2) DEFTREECODE (TEMPLATE_ID_EXPR, "template_id_expr", 'e', 2)
/* An association between name and entity. Parameters are the scope
and the (non-type) value. TREE_TYPE indicates the type bound to
the name. */
DEFTREECODE (CPLUS_BINDING, "binding", 'x', 2)
/* A list-like node for chaining overloading candidates. TREE_TYPE is /* A list-like node for chaining overloading candidates. TREE_TYPE is
the original name, and the parameter is the FUNCTION_DECL. */ the original name, and the parameter is the FUNCTION_DECL. */
DEFTREECODE (OVERLOAD, "overload", 'x', 1) DEFTREECODE (OVERLOAD, "overload", 'x', 1)
......
...@@ -44,7 +44,6 @@ struct diagnostic_context; ...@@ -44,7 +44,6 @@ struct diagnostic_context;
DELETE_EXPR_USE_GLOBAL (in DELETE_EXPR). DELETE_EXPR_USE_GLOBAL (in DELETE_EXPR).
LOOKUP_EXPR_GLOBAL (in LOOKUP_EXPR). LOOKUP_EXPR_GLOBAL (in LOOKUP_EXPR).
TREE_INDIRECT_USING (in NAMESPACE_DECL). TREE_INDIRECT_USING (in NAMESPACE_DECL).
LOCAL_BINDING_P (in CPLUS_BINDING)
ICS_USER_FLAG (in _CONV) ICS_USER_FLAG (in _CONV)
CLEANUP_P (in TRY_BLOCK) CLEANUP_P (in TRY_BLOCK)
AGGR_INIT_VIA_CTOR_P (in AGGR_INIT_EXPR) AGGR_INIT_VIA_CTOR_P (in AGGR_INIT_EXPR)
...@@ -56,14 +55,12 @@ struct diagnostic_context; ...@@ -56,14 +55,12 @@ struct diagnostic_context;
DELETE_EXPR_USE_VEC (in DELETE_EXPR). DELETE_EXPR_USE_VEC (in DELETE_EXPR).
(TREE_CALLS_NEW) (in _EXPR or _REF) (commented-out). (TREE_CALLS_NEW) (in _EXPR or _REF) (commented-out).
TYPE_BASE_CONVS_MAY_REQUIRE_CODE_P (in _TYPE). TYPE_BASE_CONVS_MAY_REQUIRE_CODE_P (in _TYPE).
INHERITED_VALUE_BINDING_P (in CPLUS_BINDING)
ICS_ELLIPSIS_FLAG (in _CONV) ICS_ELLIPSIS_FLAG (in _CONV)
BINFO_DEPENDENT_BASE_P (in BINFO) BINFO_DEPENDENT_BASE_P (in BINFO)
DECL_INITIALIZED_P (in VAR_DECL) DECL_INITIALIZED_P (in VAR_DECL)
2: IDENTIFIER_OPNAME_P. 2: IDENTIFIER_OPNAME_P.
TYPE_POLYMORPHIC_P (in _TYPE) TYPE_POLYMORPHIC_P (in _TYPE)
ICS_THIS_FLAG (in _CONV) ICS_THIS_FLAG (in _CONV)
BINDING_HAS_LEVEL_P (in CPLUS_BINDING)
BINFO_LOST_PRIMARY_P (in BINFO) BINFO_LOST_PRIMARY_P (in BINFO)
TREE_PARMLIST (in TREE_LIST) TREE_PARMLIST (in TREE_LIST)
3: TYPE_USES_VIRTUAL_BASECLASSES (in a class TYPE). 3: TYPE_USES_VIRTUAL_BASECLASSES (in a class TYPE).
...@@ -225,14 +222,41 @@ struct diagnostic_context; ...@@ -225,14 +222,41 @@ struct diagnostic_context;
/* Datatype used to temporarily save C++ bindings (for implicit /* Datatype used to temporarily save C++ bindings (for implicit
instantiations purposes and like). Implemented in decl.c. */ instantiations purposes and like). Implemented in decl.c. */
typedef struct cxx_saved_binding cxx_saved_binding; typedef struct cxx_saved_binding cxx_saved_binding;
/* Datatype that represents binding established by a declaration between
a name and a C++ entity. */
typedef struct cxx_binding cxx_binding;
/* (GC-)allocate a cxx_binding object. */
#define cxx_binding_make() (ggc_alloc (sizeof (cxx_binding)))
/* Zero out a cxx_binding pointed to by B. */
#define cxx_binding_clear(B) memset ((B), 0, sizeof (cxx_binding))
struct cxx_binding GTY(())
{
/* Link to chain together various bindings for this name. */
cxx_binding *previous;
/* The non-type entity this name is bound to. */
tree value;
/* The type entity this name is bound to. */
tree type;
union tree_binding_u {
tree GTY ((tag ("0"))) scope;
struct cp_binding_level * GTY ((tag ("1"))) level;
} GTY ((desc ("%0.has_level"))) scope;
unsigned has_level : 1;
unsigned value_is_inherited : 1;
unsigned is_local : 1;
};
/* Language-dependent contents of an identifier. */ /* Language-dependent contents of an identifier. */
struct lang_identifier GTY(()) struct lang_identifier GTY(())
{ {
struct c_common_identifier c_common; struct c_common_identifier c_common;
tree namespace_bindings; cxx_binding *namespace_bindings;
tree bindings; cxx_binding *bindings;
tree class_value; tree class_value;
tree class_template_info; tree class_template_info;
struct lang_id2 *x; struct lang_id2 *x;
...@@ -275,30 +299,28 @@ typedef struct ptrmem_cst * ptrmem_cst_t; ...@@ -275,30 +299,28 @@ typedef struct ptrmem_cst * ptrmem_cst_t;
/* Nonzero if this binding is for a local scope, as opposed to a class /* Nonzero if this binding is for a local scope, as opposed to a class
or namespace scope. */ or namespace scope. */
#define LOCAL_BINDING_P(NODE) TREE_LANG_FLAG_0 (NODE) #define LOCAL_BINDING_P(NODE) ((NODE)->is_local)
/* Nonzero if BINDING_VALUE is from a base class of the class which is /* Nonzero if BINDING_VALUE is from a base class of the class which is
currently being defined. */ currently being defined. */
#define INHERITED_VALUE_BINDING_P(NODE) TREE_LANG_FLAG_1 (NODE) #define INHERITED_VALUE_BINDING_P(NODE) ((NODE)->value_is_inherited)
/* For a binding between a name and an entity at a non-local scope, /* For a binding between a name and an entity at a non-local scope,
defines the scope where the binding is declared. (Either a class defines the scope where the binding is declared. (Either a class
_TYPE node, or a NAMESPACE_DECL.) This macro should be used only _TYPE node, or a NAMESPACE_DECL.) This macro should be used only
for namespace-level bindings; on the IDENTIFIER_BINDING list for namespace-level bindings; on the IDENTIFIER_BINDING list
BINDING_LEVEL is used instead. */ BINDING_LEVEL is used instead. */
#define BINDING_SCOPE(NODE) \ #define BINDING_SCOPE(NODE) ((NODE)->scope.scope)
(((struct tree_binding*)CPLUS_BINDING_CHECK (NODE))->scope.scope)
/* Nonzero if NODE has BINDING_LEVEL, rather than BINDING_SCOPE. */ /* Nonzero if NODE has BINDING_LEVEL, rather than BINDING_SCOPE. */
#define BINDING_HAS_LEVEL_P(NODE) TREE_LANG_FLAG_2 (NODE) #define BINDING_HAS_LEVEL_P(NODE) ((NODE)->has_level)
/* This is the declaration bound to the name. Possible values: /* This is the declaration bound to the name. Possible values:
variable, overloaded function, namespace, template, enumerator. */ variable, overloaded function, namespace, template, enumerator. */
#define BINDING_VALUE(NODE) \ #define BINDING_VALUE(NODE) ((NODE)->value)
(((struct tree_binding*)CPLUS_BINDING_CHECK (NODE))->value)
/* If name is bound to a type, this is the type (struct, union, enum). */ /* If name is bound to a type, this is the type (struct, union, enum). */
#define BINDING_TYPE(NODE) TREE_TYPE (NODE) #define BINDING_TYPE(NODE) ((NODE)->type)
#define IDENTIFIER_GLOBAL_VALUE(NODE) \ #define IDENTIFIER_GLOBAL_VALUE(NODE) \
namespace_binding ((NODE), global_namespace) namespace_binding ((NODE), global_namespace)
...@@ -332,17 +354,6 @@ typedef struct ptrmem_cst * ptrmem_cst_t; ...@@ -332,17 +354,6 @@ typedef struct ptrmem_cst * ptrmem_cst_t;
&& DECL_NAME (NODE) != NULL_TREE \ && DECL_NAME (NODE) != NULL_TREE \
&& MAIN_NAME_P (DECL_NAME (NODE))) && MAIN_NAME_P (DECL_NAME (NODE)))
struct tree_binding GTY(())
{
struct tree_common common;
union tree_binding_u {
tree GTY ((tag ("0"))) scope;
struct cp_binding_level * GTY ((tag ("1"))) level;
} GTY ((desc ("BINDING_HAS_LEVEL_P ((tree)&%0)"))) scope;
tree value;
};
/* The overloaded FUNCTION_DECL. */ /* The overloaded FUNCTION_DECL. */
#define OVL_FUNCTION(NODE) \ #define OVL_FUNCTION(NODE) \
(((struct tree_overload*)OVERLOAD_CHECK (NODE))->function) (((struct tree_overload*)OVERLOAD_CHECK (NODE))->function)
...@@ -420,8 +431,8 @@ struct tree_srcloc GTY(()) ...@@ -420,8 +431,8 @@ struct tree_srcloc GTY(())
#define IDENTIFIER_TEMPLATE(NODE) \ #define IDENTIFIER_TEMPLATE(NODE) \
(LANG_IDENTIFIER_CAST (NODE)->class_template_info) (LANG_IDENTIFIER_CAST (NODE)->class_template_info)
/* The IDENTIFIER_BINDING is the innermost CPLUS_BINDING for the /* The IDENTIFIER_BINDING is the innermost cxx_binding for the
identifier. It's TREE_CHAIN is the next outermost binding. Each identifier. It's PREVIOUS is the next outermost binding. Each
BINDING_VALUE is a DECL for the associated declaration. Thus, BINDING_VALUE is a DECL for the associated declaration. Thus,
name lookup consists simply of pulling off the node at the front name lookup consists simply of pulling off the node at the front
of the list (modulo oddities for looking up the names of types, of the list (modulo oddities for looking up the names of types,
...@@ -433,9 +444,7 @@ struct tree_srcloc GTY(()) ...@@ -433,9 +444,7 @@ struct tree_srcloc GTY(())
/* The IDENTIFIER_VALUE is the value of the IDENTIFIER_BINDING, or /* The IDENTIFIER_VALUE is the value of the IDENTIFIER_BINDING, or
NULL_TREE if there is no binding. */ NULL_TREE if there is no binding. */
#define IDENTIFIER_VALUE(NODE) \ #define IDENTIFIER_VALUE(NODE) \
(IDENTIFIER_BINDING (NODE) \ (IDENTIFIER_BINDING (NODE) ? IDENTIFIER_BINDING (NODE)->value : NULL)
? BINDING_VALUE (IDENTIFIER_BINDING (NODE)) \
: NULL_TREE)
/* If IDENTIFIER_CLASS_VALUE is set, then NODE is bound in the current /* If IDENTIFIER_CLASS_VALUE is set, then NODE is bound in the current
class, and IDENTIFIER_CLASS_VALUE is the value binding. This is class, and IDENTIFIER_CLASS_VALUE is the value binding. This is
...@@ -540,7 +549,6 @@ union lang_tree_node GTY((desc ("cp_tree_node_structure (&%h)"), ...@@ -540,7 +549,6 @@ union lang_tree_node GTY((desc ("cp_tree_node_structure (&%h)"),
desc ("tree_node_structure (&%h)"))) generic; desc ("tree_node_structure (&%h)"))) generic;
struct template_parm_index_s GTY ((tag ("TS_CP_TPI"))) tpi; struct template_parm_index_s GTY ((tag ("TS_CP_TPI"))) tpi;
struct ptrmem_cst GTY ((tag ("TS_CP_PTRMEM"))) ptrmem; struct ptrmem_cst GTY ((tag ("TS_CP_PTRMEM"))) ptrmem;
struct tree_binding GTY ((tag ("TS_CP_BINDING"))) binding;
struct tree_overload GTY ((tag ("TS_CP_OVERLOAD"))) overload; struct tree_overload GTY ((tag ("TS_CP_OVERLOAD"))) overload;
struct tree_baselink GTY ((tag ("TS_CP_BASELINK"))) baselink; struct tree_baselink GTY ((tag ("TS_CP_BASELINK"))) baselink;
struct tree_wrapper GTY ((tag ("TS_CP_WRAPPER"))) wrapper; struct tree_wrapper GTY ((tag ("TS_CP_WRAPPER"))) wrapper;
...@@ -3705,7 +3713,7 @@ extern tree declare_local_label (tree); ...@@ -3705,7 +3713,7 @@ extern tree declare_local_label (tree);
extern tree define_label (const char *, int, tree); extern tree define_label (const char *, int, tree);
extern void check_goto (tree); extern void check_goto (tree);
extern void define_case_label (void); extern void define_case_label (void);
extern tree binding_for_name (tree, tree); extern cxx_binding *binding_for_name (tree, tree);
extern tree namespace_binding (tree, tree); extern tree namespace_binding (tree, tree);
extern void set_namespace_binding (tree, tree, tree); extern void set_namespace_binding (tree, tree, tree);
extern tree lookup_namespace_name (tree, tree); extern tree lookup_namespace_name (tree, tree);
...@@ -3722,8 +3730,8 @@ extern tree namespace_ancestor (tree, tree); ...@@ -3722,8 +3730,8 @@ extern tree namespace_ancestor (tree, tree);
extern bool is_ancestor (tree, tree); extern bool is_ancestor (tree, tree);
extern tree unqualified_namespace_lookup (tree, int, tree *); extern tree unqualified_namespace_lookup (tree, int, tree *);
extern tree check_for_out_of_scope_variable (tree); extern tree check_for_out_of_scope_variable (tree);
extern bool lookup_using_namespace (tree, tree, tree, tree, int, tree *); extern bool lookup_using_namespace (tree, cxx_binding *, tree, tree, int, tree *);
extern bool qualified_lookup_using_namespace (tree, tree, tree, int); extern bool qualified_lookup_using_namespace (tree, tree, cxx_binding *, int);
extern tree build_library_fn (tree, tree); extern tree build_library_fn (tree, tree);
extern tree build_library_fn_ptr (const char *, tree); extern tree build_library_fn_ptr (const char *, tree);
extern tree build_cp_library_fn_ptr (const char *, tree); extern tree build_cp_library_fn_ptr (const char *, tree);
...@@ -3795,6 +3803,7 @@ extern int nonstatic_local_decl_p (tree); ...@@ -3795,6 +3803,7 @@ extern int nonstatic_local_decl_p (tree);
extern tree declare_global_var (tree, tree); extern tree declare_global_var (tree, tree);
extern void register_dtor_fn (tree); extern void register_dtor_fn (tree);
extern tmpl_spec_kind current_tmpl_spec_kind (int); extern tmpl_spec_kind current_tmpl_spec_kind (int);
extern cxx_binding *cxx_scope_find_binding_for_name (tree, tree);
extern tree cp_fname_init (const char *); extern tree cp_fname_init (const char *);
extern bool have_extern_spec; extern bool have_extern_spec;
......
...@@ -63,7 +63,7 @@ static void mark_vtable_entries (tree); ...@@ -63,7 +63,7 @@ static void mark_vtable_entries (tree);
static void grok_function_init (tree, tree); static void grok_function_init (tree, tree);
static bool maybe_emit_vtables (tree); static bool maybe_emit_vtables (tree);
static void add_using_namespace (tree, tree, bool); static void add_using_namespace (tree, tree, bool);
static tree ambiguous_decl (tree, tree, tree,int); static cxx_binding *ambiguous_decl (tree, cxx_binding *, cxx_binding *, int);
static tree build_anon_union_vars (tree); static tree build_anon_union_vars (tree);
static bool acceptable_java_type (tree); static bool acceptable_java_type (tree);
static void output_vtable_inherit (tree); static void output_vtable_inherit (tree);
...@@ -3497,11 +3497,11 @@ merge_functions (tree s1, tree s2) ...@@ -3497,11 +3497,11 @@ merge_functions (tree s1, tree s2)
XXX In what way should I treat extern declarations? XXX In what way should I treat extern declarations?
XXX I don't want to repeat the entire duplicate_decls here */ XXX I don't want to repeat the entire duplicate_decls here */
static tree static cxx_binding *
ambiguous_decl (tree name, tree old, tree new, int flags) ambiguous_decl (tree name, cxx_binding *old, cxx_binding *new, int flags)
{ {
tree val, type; tree val, type;
my_friendly_assert (old != NULL_TREE, 393); my_friendly_assert (old != NULL, 393);
/* Copy the value. */ /* Copy the value. */
val = BINDING_VALUE (new); val = BINDING_VALUE (new);
if (val) if (val)
...@@ -3536,12 +3536,8 @@ ambiguous_decl (tree name, tree old, tree new, int flags) ...@@ -3536,12 +3536,8 @@ ambiguous_decl (tree name, tree old, tree new, int flags)
BINDING_VALUE (old) = val; BINDING_VALUE (old) = val;
else if (val && val != BINDING_VALUE (old)) else if (val && val != BINDING_VALUE (old))
{ {
if (is_overloaded_fn (BINDING_VALUE (old)) if (is_overloaded_fn (BINDING_VALUE (old)) && is_overloaded_fn (val))
&& is_overloaded_fn (val)) BINDING_VALUE (old) = merge_functions (BINDING_VALUE (old), val);
{
BINDING_VALUE (old) = merge_functions (BINDING_VALUE (old),
val);
}
else else
{ {
/* Some declarations are functions, some are not. */ /* Some declarations are functions, some are not. */
...@@ -3587,23 +3583,23 @@ ambiguous_decl (tree name, tree old, tree new, int flags) ...@@ -3587,23 +3583,23 @@ ambiguous_decl (tree name, tree old, tree new, int flags)
Returns false on errors. */ Returns false on errors. */
bool bool
lookup_using_namespace (tree name, tree val, tree usings, tree scope, lookup_using_namespace (tree name, cxx_binding *val, tree usings, tree scope,
int flags, tree *spacesp) int flags, tree *spacesp)
{ {
tree iter; tree iter;
tree val1;
timevar_push (TV_NAME_LOOKUP); timevar_push (TV_NAME_LOOKUP);
/* Iterate over all used namespaces in current, searching for using /* Iterate over all used namespaces in current, searching for using
directives of scope. */ directives of scope. */
for (iter = usings; iter; iter = TREE_CHAIN (iter)) for (iter = usings; iter; iter = TREE_CHAIN (iter))
if (TREE_VALUE (iter) == scope) if (TREE_VALUE (iter) == scope)
{ {
if (spacesp) cxx_binding *val1 =
*spacesp = tree_cons (TREE_PURPOSE (iter), NULL_TREE, cxx_scope_find_binding_for_name (TREE_PURPOSE (iter), name);
*spacesp); if (spacesp)
val1 = binding_for_name (name, TREE_PURPOSE (iter)); *spacesp = tree_cons (TREE_PURPOSE (iter), NULL_TREE, *spacesp);
/* Resolve ambiguities. */ /* Resolve ambiguities. */
val = ambiguous_decl (name, val, val1, flags); if (val1)
val = ambiguous_decl (name, val, val1, flags);
} }
POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP,
BINDING_VALUE (val) != error_mark_node); BINDING_VALUE (val) != error_mark_node);
...@@ -3611,11 +3607,11 @@ lookup_using_namespace (tree name, tree val, tree usings, tree scope, ...@@ -3611,11 +3607,11 @@ lookup_using_namespace (tree name, tree val, tree usings, tree scope,
/* [namespace.qual] /* [namespace.qual]
Accepts the NAME to lookup and its qualifying SCOPE. Accepts the NAME to lookup and its qualifying SCOPE.
Returns the name/type pair found into the CPLUS_BINDING RESULT, Returns the name/type pair found into the cxx_binding *RESULT,
or false on error. */ or false on error. */
bool bool
qualified_lookup_using_namespace (tree name, tree scope, tree result, qualified_lookup_using_namespace (tree name, tree scope, cxx_binding *result,
int flags) int flags)
{ {
/* Maintain a list of namespaces visited... */ /* Maintain a list of namespaces visited... */
...@@ -3626,11 +3622,12 @@ qualified_lookup_using_namespace (tree name, tree scope, tree result, ...@@ -3626,11 +3622,12 @@ qualified_lookup_using_namespace (tree name, tree scope, tree result,
timevar_push (TV_NAME_LOOKUP); timevar_push (TV_NAME_LOOKUP);
/* Look through namespace aliases. */ /* Look through namespace aliases. */
scope = ORIGINAL_NAMESPACE (scope); scope = ORIGINAL_NAMESPACE (scope);
while (scope && (result != error_mark_node)) while (scope && result->value != error_mark_node)
{ {
cxx_binding *binding = cxx_scope_find_binding_for_name (scope, name);
seen = tree_cons (scope, NULL_TREE, seen); seen = tree_cons (scope, NULL_TREE, seen);
result = ambiguous_decl (name, result, if (binding)
binding_for_name (name, scope), flags); result = ambiguous_decl (name, result, binding, flags);
if (!BINDING_VALUE (result) && !BINDING_TYPE (result)) if (!BINDING_VALUE (result) && !BINDING_TYPE (result))
/* Consider using directives. */ /* Consider using directives. */
for (usings = DECL_NAMESPACE_USING (scope); usings; for (usings = DECL_NAMESPACE_USING (scope); usings;
...@@ -3647,7 +3644,7 @@ qualified_lookup_using_namespace (tree name, tree scope, tree result, ...@@ -3647,7 +3644,7 @@ qualified_lookup_using_namespace (tree name, tree scope, tree result,
else else
scope = NULL_TREE; /* If there never was a todo list. */ scope = NULL_TREE; /* If there never was a todo list. */
} }
POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, result != error_mark_node); POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, result->value != error_mark_node);
} }
/* [namespace.memdef]/2 */ /* [namespace.memdef]/2 */
...@@ -4203,22 +4200,22 @@ static void ...@@ -4203,22 +4200,22 @@ static void
do_nonmember_using_decl (tree scope, tree name, tree oldval, tree oldtype, do_nonmember_using_decl (tree scope, tree name, tree oldval, tree oldtype,
tree *newval, tree *newtype) tree *newval, tree *newtype)
{ {
tree decls; cxx_binding decls;
*newval = *newtype = NULL_TREE; *newval = *newtype = NULL_TREE;
decls = make_node (CPLUS_BINDING); cxx_binding_clear (&decls);
if (!qualified_lookup_using_namespace (name, scope, decls, 0)) if (!qualified_lookup_using_namespace (name, scope, &decls, 0))
/* Lookup error */ /* Lookup error */
return; return;
if (!BINDING_VALUE (decls) && !BINDING_TYPE (decls)) if (!decls.value && !decls.type)
{ {
error ("`%D' not declared", name); error ("`%D' not declared", name);
return; return;
} }
/* Check for using functions. */ /* Check for using functions. */
if (BINDING_VALUE (decls) && is_overloaded_fn (BINDING_VALUE (decls))) if (decls.value && is_overloaded_fn (decls.value))
{ {
tree tmp, tmp1; tree tmp, tmp1;
...@@ -4230,7 +4227,7 @@ do_nonmember_using_decl (tree scope, tree name, tree oldval, tree oldtype, ...@@ -4230,7 +4227,7 @@ do_nonmember_using_decl (tree scope, tree name, tree oldval, tree oldtype,
} }
*newval = oldval; *newval = oldval;
for (tmp = BINDING_VALUE (decls); tmp; tmp = OVL_NEXT (tmp)) for (tmp = decls.value; tmp; tmp = OVL_NEXT (tmp))
{ {
tree new_fn = OVL_CURRENT (tmp); tree new_fn = OVL_CURRENT (tmp);
...@@ -4290,12 +4287,12 @@ do_nonmember_using_decl (tree scope, tree name, tree oldval, tree oldtype, ...@@ -4290,12 +4287,12 @@ do_nonmember_using_decl (tree scope, tree name, tree oldval, tree oldtype,
} }
else else
{ {
*newval = BINDING_VALUE (decls); *newval = decls.value;
if (oldval && !decls_match (*newval, oldval)) if (oldval && !decls_match (*newval, oldval))
error ("`%D' is already declared in this scope", name); error ("`%D' is already declared in this scope", name);
} }
*newtype = BINDING_TYPE (decls); *newtype = decls.type;
if (oldtype && *newtype && !same_type_p (oldtype, *newtype)) if (oldtype && *newtype && !same_type_p (oldtype, *newtype))
{ {
error ("using declaration `%D' introduced ambiguous type `%T'", error ("using declaration `%D' introduced ambiguous type `%T'",
...@@ -4309,8 +4306,9 @@ do_nonmember_using_decl (tree scope, tree name, tree oldval, tree oldtype, ...@@ -4309,8 +4306,9 @@ do_nonmember_using_decl (tree scope, tree name, tree oldval, tree oldtype,
void void
do_toplevel_using_decl (tree decl) do_toplevel_using_decl (tree decl)
{ {
tree scope, name, binding; tree scope, name;
tree oldval, oldtype, newval, newtype; tree oldval, oldtype, newval, newtype;
cxx_binding *binding;
decl = validate_nonmember_using_decl (decl, &scope, &name); decl = validate_nonmember_using_decl (decl, &scope, &name);
if (decl == NULL_TREE) if (decl == NULL_TREE)
......
...@@ -153,12 +153,21 @@ cxx_print_type (FILE *file, tree node, int indent) ...@@ -153,12 +153,21 @@ cxx_print_type (FILE *file, tree node, int indent)
} }
} }
static void
cxx_print_binding (FILE *stream, cxx_binding *binding, const char *prefix)
{
fprintf (stream, "%s <", prefix);
fprintf (stream, HOST_PTR_PRINTF, (char *) binding);
fprintf (stream, ">");
}
void void
cxx_print_identifier (FILE *file, tree node, int indent) cxx_print_identifier (FILE *file, tree node, int indent)
{ {
print_node (file, "bindings", IDENTIFIER_NAMESPACE_BINDINGS (node), indent + 4); cxx_print_binding (file, IDENTIFIER_NAMESPACE_BINDINGS (node), "bindings");
print_node (file, "class", IDENTIFIER_CLASS_VALUE (node), indent + 4); print_node (file, "class", IDENTIFIER_CLASS_VALUE (node), indent + 4);
print_node (file, "local bindings", IDENTIFIER_BINDING (node), indent + 4); cxx_print_binding (file, IDENTIFIER_BINDING (node), "local bindings");
print_node (file, "label", IDENTIFIER_LABEL_VALUE (node), indent + 4); print_node (file, "label", IDENTIFIER_LABEL_VALUE (node), indent + 4);
print_node (file, "template", IDENTIFIER_TEMPLATE (node), indent + 4); print_node (file, "template", IDENTIFIER_TEMPLATE (node), indent + 4);
print_node (file, "implicit", IDENTIFIER_IMPLICIT_DECL (node), indent + 4); print_node (file, "implicit", IDENTIFIER_IMPLICIT_DECL (node), indent + 4);
...@@ -170,12 +179,6 @@ cxx_print_xnode (FILE *file, tree node, int indent) ...@@ -170,12 +179,6 @@ cxx_print_xnode (FILE *file, tree node, int indent)
{ {
switch (TREE_CODE (node)) switch (TREE_CODE (node))
{ {
case CPLUS_BINDING:
fprintf (file, " scope ");
fprintf (file, HOST_PTR_PRINTF, BINDING_SCOPE (node));
print_node (file, "value", BINDING_VALUE (node), indent+4);
print_node (file, "chain", TREE_CHAIN (node), indent+4);
break;
case OVERLOAD: case OVERLOAD:
print_node (file, "function", OVL_FUNCTION (node), indent+4); print_node (file, "function", OVL_FUNCTION (node), indent+4);
print_node (file, "chain", TREE_CHAIN (node), indent+4); print_node (file, "chain", TREE_CHAIN (node), indent+4);
......
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