Commit 15f8ac7f by Geoffrey Keating Committed by Geoffrey Keating

name-lookup.c (struct scope_binding): New.

	* name-lookup.c (struct scope_binding): New.
	(EMPTY_SCOPE_BINDING): New.
	(lookup_using_namespace): Take a scope_binding instead of a
	cxx_binding.
	(qualified_lookup_using_namespace): Likewise.
	(cxx_binding_clear): Delete.
	(do_nonmember_using_decl): Use a scope_binding instead of a
	cxx_binding.
	(lookup_tag): Don't call select_decl.
	(ambiguous_decl): Don't return anything (and change callers to match).
	Take a scope_binding as the second parameter.
	(lookup_namespace_name): Use a scope_binding instead of a
	cxx_binding.
	(unqualified_namespace_lookup): Likewise.
	(lookup_qualified_name): Likewise.
	(select_decl): Take a scope_binding instead of a cxx_binding.
	Use macros rather than hand-coding tests for type-ness.

From-SVN: r81864
parent ae0d0d59
2004-05-14 Geoffrey Keating <geoffk@apple.com>
* name-lookup.c (struct scope_binding): New.
(EMPTY_SCOPE_BINDING): New.
(lookup_using_namespace): Take a scope_binding instead of a
cxx_binding.
(qualified_lookup_using_namespace): Likewise.
(cxx_binding_clear): Delete.
(do_nonmember_using_decl): Use a scope_binding instead of a
cxx_binding.
(lookup_tag): Don't call select_decl.
(ambiguous_decl): Don't return anything (and change callers to match).
Take a scope_binding as the second parameter.
(lookup_namespace_name): Use a scope_binding instead of a
cxx_binding.
(unqualified_namespace_lookup): Likewise.
(lookup_qualified_name): Likewise.
(select_decl): Take a scope_binding instead of a cxx_binding.
Use macros rather than hand-coding tests for type-ness.
2004-05-13 Diego Novillo <dnovillo@redhat.com> 2004-05-13 Diego Novillo <dnovillo@redhat.com>
* cp-gimplify.c: Rename from cp-simplify.c. * cp-gimplify.c: Rename from cp-simplify.c.
......
...@@ -32,14 +32,23 @@ Boston, MA 02111-1307, USA. */ ...@@ -32,14 +32,23 @@ Boston, MA 02111-1307, USA. */
#include "diagnostic.h" #include "diagnostic.h"
#include "debug.h" #include "debug.h"
/* The bindings for a particular name in a particular scope. */
struct scope_binding {
tree value;
tree type;
};
#define EMPTY_SCOPE_BINDING { NULL_TREE, NULL_TREE }
static cxx_scope *innermost_nonclass_level (void); static cxx_scope *innermost_nonclass_level (void);
static tree select_decl (cxx_binding *, int); static tree select_decl (const struct scope_binding *, int);
static cxx_binding *binding_for_name (cxx_scope *, tree); static cxx_binding *binding_for_name (cxx_scope *, tree);
static tree lookup_name_current_level (tree); static tree lookup_name_current_level (tree);
static tree push_overloaded_decl (tree, int); static tree push_overloaded_decl (tree, int);
static bool lookup_using_namespace (tree, cxx_binding *, tree, static bool lookup_using_namespace (tree, struct scope_binding *, tree,
tree, int); tree, int);
static bool qualified_lookup_using_namespace (tree, tree, cxx_binding *, int); static bool qualified_lookup_using_namespace (tree, tree,
struct scope_binding *, int);
static tree lookup_type_current_level (tree); static tree lookup_type_current_level (tree);
static tree push_using_directive (tree); static tree push_using_directive (tree);
static void cp_emit_debug_info_for_using (tree, tree); static void cp_emit_debug_info_for_using (tree, tree);
...@@ -319,9 +328,6 @@ binding_table_foreach (binding_table table, bt_foreach_proc proc, void *data) ...@@ -319,9 +328,6 @@ binding_table_foreach (binding_table table, bt_foreach_proc proc, void *data)
static GTY((deletable)) cxx_binding *free_bindings; static GTY((deletable)) cxx_binding *free_bindings;
/* Zero out a cxx_binding pointed to by B. */
#define cxx_binding_clear(B) memset ((B), 0, sizeof (cxx_binding))
/* (GC)-allocate a binding object with VALUE and TYPE member initialized. */ /* (GC)-allocate a binding object with VALUE and TYPE member initialized. */
static cxx_binding * static cxx_binding *
...@@ -2116,10 +2122,9 @@ static void ...@@ -2116,10 +2122,9 @@ 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)
{ {
cxx_binding decls; struct scope_binding decls = EMPTY_SCOPE_BINDING;
*newval = *newtype = NULL_TREE; *newval = *newtype = NULL_TREE;
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;
...@@ -2362,6 +2367,11 @@ lookup_tag (enum tree_code form, tree name, ...@@ -2362,6 +2367,11 @@ lookup_tag (enum tree_code form, tree name,
{ {
cxx_binding *binding = cxx_binding *binding =
cxx_scope_find_binding_for_name (NAMESPACE_LEVEL (tail), name); cxx_scope_find_binding_for_name (NAMESPACE_LEVEL (tail), name);
if (binding && (binding->type
|| (binding->value
&& DECL_DECLARES_TYPE_P (binding->value))))
{
tree old; tree old;
/* If we just skipped past a template parameter level, /* If we just skipped past a template parameter level,
...@@ -2369,16 +2379,12 @@ lookup_tag (enum tree_code form, tree name, ...@@ -2369,16 +2379,12 @@ lookup_tag (enum tree_code form, tree name,
class declaration, then we use the _TYPE node for the class declaration, then we use the _TYPE node for the
template. See the example below. */ template. See the example below. */
if (thislevel_only && !allow_template_parms_p if (thislevel_only && !allow_template_parms_p
&& binding && binding->value && binding->value
&& DECL_CLASS_TEMPLATE_P (binding->value)) && DECL_CLASS_TEMPLATE_P (binding->value))
old = binding->value; old = binding->value;
else if (binding)
old = select_decl (binding, LOOKUP_PREFER_TYPES);
else else
old = NULL_TREE; old = binding->type ? binding->type : binding->value;
if (old)
{
/* We've found something at this binding level. If it is /* We've found something at this binding level. If it is
a typedef, extract the tag it refers to. Lookup fails a typedef, extract the tag it refers to. Lookup fails
if the typedef doesn't refer to a taggable type. */ if the typedef doesn't refer to a taggable type. */
...@@ -3493,8 +3499,9 @@ merge_functions (tree s1, tree s2) ...@@ -3493,8 +3499,9 @@ 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 cxx_binding * static void
ambiguous_decl (tree name, cxx_binding *old, cxx_binding *new, int flags) ambiguous_decl (tree name, struct scope_binding *old, cxx_binding *new,
int flags)
{ {
tree val, type; tree val, type;
my_friendly_assert (old != NULL, 393); my_friendly_assert (old != NULL, 393);
...@@ -3568,7 +3575,6 @@ ambiguous_decl (tree name, cxx_binding *old, cxx_binding *new, int flags) ...@@ -3568,7 +3575,6 @@ ambiguous_decl (tree name, cxx_binding *old, cxx_binding *new, int flags)
error ("%J other type here", TYPE_MAIN_DECL (type)); error ("%J other type here", TYPE_MAIN_DECL (type));
} }
} }
return old;
} }
/* Return the declarations that are members of the namespace NS. */ /* Return the declarations that are members of the namespace NS. */
...@@ -3618,7 +3624,7 @@ lookup_namespace_name (tree namespace, tree name) ...@@ -3618,7 +3624,7 @@ lookup_namespace_name (tree namespace, tree name)
{ {
tree val; tree val;
tree template_id = NULL_TREE; tree template_id = NULL_TREE;
cxx_binding binding; struct scope_binding binding = EMPTY_SCOPE_BINDING;
timevar_push (TV_NAME_LOOKUP); timevar_push (TV_NAME_LOOKUP);
my_friendly_assert (TREE_CODE (namespace) == NAMESPACE_DECL, 370); my_friendly_assert (TREE_CODE (namespace) == NAMESPACE_DECL, 370);
...@@ -3648,7 +3654,6 @@ lookup_namespace_name (tree namespace, tree name) ...@@ -3648,7 +3654,6 @@ lookup_namespace_name (tree namespace, tree name)
my_friendly_assert (TREE_CODE (name) == IDENTIFIER_NODE, 373); my_friendly_assert (TREE_CODE (name) == IDENTIFIER_NODE, 373);
cxx_binding_clear (&binding);
if (!qualified_lookup_using_namespace (name, namespace, &binding, 0)) if (!qualified_lookup_using_namespace (name, namespace, &binding, 0))
POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, error_mark_node); POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, error_mark_node);
...@@ -3695,7 +3700,7 @@ lookup_namespace_name (tree namespace, tree name) ...@@ -3695,7 +3700,7 @@ lookup_namespace_name (tree namespace, tree name)
/* Select the right _DECL from multiple choices. */ /* Select the right _DECL from multiple choices. */
static tree static tree
select_decl (cxx_binding *binding, int flags) select_decl (const struct scope_binding *binding, int flags)
{ {
tree val; tree val;
val = binding->value; val = binding->value;
...@@ -3714,9 +3719,8 @@ select_decl (cxx_binding *binding, int flags) ...@@ -3714,9 +3719,8 @@ select_decl (cxx_binding *binding, int flags)
if (binding->type && (!val || (flags & LOOKUP_PREFER_TYPES))) if (binding->type && (!val || (flags & LOOKUP_PREFER_TYPES)))
val = binding->type; val = binding->type;
/* Don't return non-types if we really prefer types. */ /* Don't return non-types if we really prefer types. */
else if (val && LOOKUP_TYPES_ONLY (flags) && TREE_CODE (val) != TYPE_DECL else if (val && LOOKUP_TYPES_ONLY (flags)
&& (TREE_CODE (val) != TEMPLATE_DECL && ! DECL_DECLARES_TYPE_P (val))
|| !DECL_CLASS_TEMPLATE_P (val)))
val = NULL_TREE; val = NULL_TREE;
POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, val); POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, val);
...@@ -3733,10 +3737,9 @@ unqualified_namespace_lookup (tree name, int flags) ...@@ -3733,10 +3737,9 @@ unqualified_namespace_lookup (tree name, int flags)
tree siter; tree siter;
struct cp_binding_level *level; struct cp_binding_level *level;
tree val = NULL_TREE; tree val = NULL_TREE;
cxx_binding binding; struct scope_binding binding = EMPTY_SCOPE_BINDING;
timevar_push (TV_NAME_LOOKUP); timevar_push (TV_NAME_LOOKUP);
cxx_binding_clear (&binding);
for (; !val; scope = CP_DECL_CONTEXT (scope)) for (; !val; scope = CP_DECL_CONTEXT (scope))
{ {
...@@ -3800,9 +3803,8 @@ lookup_qualified_name (tree scope, tree name, bool is_type_p, bool complain) ...@@ -3800,9 +3803,8 @@ lookup_qualified_name (tree scope, tree name, bool is_type_p, bool complain)
if (TREE_CODE (scope) == NAMESPACE_DECL) if (TREE_CODE (scope) == NAMESPACE_DECL)
{ {
cxx_binding binding; struct scope_binding binding = EMPTY_SCOPE_BINDING;
cxx_binding_clear (&binding);
flags |= LOOKUP_COMPLAIN; flags |= LOOKUP_COMPLAIN;
if (is_type_p) if (is_type_p)
flags |= LOOKUP_PREFER_TYPES; flags |= LOOKUP_PREFER_TYPES;
...@@ -3828,8 +3830,8 @@ lookup_qualified_name (tree scope, tree name, bool is_type_p, bool complain) ...@@ -3828,8 +3830,8 @@ lookup_qualified_name (tree scope, tree name, bool is_type_p, bool complain)
Returns false on errors. */ Returns false on errors. */
static bool static bool
lookup_using_namespace (tree name, cxx_binding *val, tree usings, tree scope, lookup_using_namespace (tree name, struct scope_binding *val,
int flags) tree usings, tree scope, int flags)
{ {
tree iter; tree iter;
timevar_push (TV_NAME_LOOKUP); timevar_push (TV_NAME_LOOKUP);
...@@ -3843,7 +3845,7 @@ lookup_using_namespace (tree name, cxx_binding *val, tree usings, tree scope, ...@@ -3843,7 +3845,7 @@ lookup_using_namespace (tree name, cxx_binding *val, tree usings, tree scope,
cxx_scope_find_binding_for_name (NAMESPACE_LEVEL (used), name); cxx_scope_find_binding_for_name (NAMESPACE_LEVEL (used), name);
/* Resolve ambiguities. */ /* Resolve ambiguities. */
if (val1) if (val1)
val = ambiguous_decl (name, val, val1, flags); ambiguous_decl (name, val, val1, flags);
} }
POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, val->value != error_mark_node); POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, val->value != error_mark_node);
} }
...@@ -3854,8 +3856,8 @@ lookup_using_namespace (tree name, cxx_binding *val, tree usings, tree scope, ...@@ -3854,8 +3856,8 @@ lookup_using_namespace (tree name, cxx_binding *val, tree usings, tree scope,
or false on error. */ or false on error. */
static bool static bool
qualified_lookup_using_namespace (tree name, tree scope, cxx_binding *result, qualified_lookup_using_namespace (tree name, tree scope,
int flags) struct scope_binding *result, int flags)
{ {
/* Maintain a list of namespaces visited... */ /* Maintain a list of namespaces visited... */
tree seen = NULL_TREE; tree seen = NULL_TREE;
...@@ -3872,7 +3874,7 @@ qualified_lookup_using_namespace (tree name, tree scope, cxx_binding *result, ...@@ -3872,7 +3874,7 @@ qualified_lookup_using_namespace (tree name, tree scope, cxx_binding *result,
cxx_scope_find_binding_for_name (NAMESPACE_LEVEL (scope), name); cxx_scope_find_binding_for_name (NAMESPACE_LEVEL (scope), name);
seen = tree_cons (scope, NULL_TREE, seen); seen = tree_cons (scope, NULL_TREE, seen);
if (binding) if (binding)
result = ambiguous_decl (name, result, binding, flags); ambiguous_decl (name, result, binding, flags);
/* Consider strong using directives always, and non-strong ones /* Consider strong using directives always, and non-strong ones
if we haven't found a binding yet. ??? Shouldn't we consider if we haven't found a binding yet. ??? Shouldn't we consider
......
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