};
#define EMPTY_SCOPE_BINDING { NULL_TREE, NULL_TREE }
-static cxx_binding *binding_for_name (cp_binding_level *, tree);
static tree push_overloaded_decl (tree, int, bool);
static bool lookup_using_namespace (tree, struct scope_binding *, tree,
tree, int);
static tree push_using_directive (tree);
static void diagnose_name_conflict (tree, tree);
+/* Find the binding for NAME in namespace NS. If CREATE_P is true,
+ make an empty binding if there wasn't one. */
+
+static cxx_binding *
+find_namespace_binding (tree ns, tree name, bool create_p = false)
+{
+ cp_binding_level *level = NAMESPACE_LEVEL (ns);
+ cxx_binding *binding = IDENTIFIER_NAMESPACE_BINDINGS (name);
+
+ for (;binding; binding = binding->previous)
+ if (binding->scope == level)
+ return binding;
+
+ if (create_p)
+ {
+ binding = cxx_binding_make (NULL, NULL);
+ binding->previous = IDENTIFIER_NAMESPACE_BINDINGS (name);
+ binding->scope = level;
+ binding->is_local = false;
+ binding->value_is_inherited = false;
+ IDENTIFIER_NAMESPACE_BINDINGS (name) = binding;
+ }
+
+ return binding;
+}
+
/* Add DECL to the list of things declared in B. */
static void
/* In case this decl was explicitly namespace-qualified, look it
up in its namespace context. */
if (DECL_NAMESPACE_SCOPE_P (x) && namespace_bindings_p ())
- t = get_namespace_binding (DECL_CONTEXT (x), name);
+ t = get_namespace_binding (CP_DECL_CONTEXT (x), name);
else
t = lookup_name_innermost_nonclass_level (name);
}
else
{
- cxx_binding *binding =
- binding_for_name (NAMESPACE_LEVEL (current_namespace), id);
- gcc_assert (decl);
+ cxx_binding *binding
+ = find_namespace_binding (current_namespace, id, true);
+
if (binding->value)
supplement_binding (binding, decl);
else
return get_identifier (buf);
}
-/* Return (from the stack of) the BINDING, if any, established at SCOPE. */
-
-static inline cxx_binding *
-find_binding (cp_binding_level *scope, cxx_binding *binding)
-{
- for (; binding != NULL; binding = binding->previous)
- if (binding->scope == scope)
- return binding;
-
- return (cxx_binding *)0;
-}
-
-/* Return the binding for NAME in SCOPE, if any. Otherwise, return NULL. */
-
-static inline cxx_binding *
-cp_binding_level_find_binding_for_name (cp_binding_level *scope, tree name)
-{
- cxx_binding *b = IDENTIFIER_NAMESPACE_BINDINGS (name);
- if (b)
- {
- /* Fold-in case where NAME is used only once. */
- if (scope == b->scope && b->previous == NULL)
- return b;
- return find_binding (scope, b);
- }
- return NULL;
-}
-
-/* Always returns a binding for name in scope. If no binding is
- found, make a new one. */
-
-static cxx_binding *
-binding_for_name (cp_binding_level *scope, tree name)
-{
- cxx_binding *result;
-
- result = cp_binding_level_find_binding_for_name (scope, name);
- if (result)
- return result;
- /* Not found, make a new one. */
- result = cxx_binding_make (NULL, NULL);
- result->previous = IDENTIFIER_NAMESPACE_BINDINGS (name);
- result->scope = scope;
- result->is_local = false;
- result->value_is_inherited = false;
- IDENTIFIER_NAMESPACE_BINDINGS (name) = result;
- return result;
-}
-
/* Insert another USING_DECL into the current binding level, returning
this declaration. If this is a redeclaration, do nothing, and
return NULL_TREE if this not in namespace scope (in namespace
int doing_global = (namespace_bindings_p () || !(flags & PUSH_LOCAL));
if (doing_global)
- old = get_namespace_binding (DECL_CONTEXT (decl), name);
+ old = get_namespace_binding (CP_DECL_CONTEXT (decl), name);
else
old = lookup_name_innermost_nonclass_level (name);
}
\f
-/* Return the binding value for name in scope. */
-
-
-static tree
-namespace_binding_1 (tree scope, tree name)
-{
- cxx_binding *binding;
-
- if (SCOPE_FILE_SCOPE_P (scope))
- scope = global_namespace;
- else
- /* Unnecessary for the global namespace because it can't be an alias. */
- scope = ORIGINAL_NAMESPACE (scope);
-
- binding = cp_binding_level_find_binding_for_name (NAMESPACE_LEVEL (scope), name);
-
- return binding ? binding->value : NULL_TREE;
-}
-
/* Return the binding for NAME in NS. If NS is NULL, look in
global_namespace. */
bool subtime = timevar_cond_start (TV_NAME_LOOKUP);
if (!ns)
ns = global_namespace;
- tree ret = namespace_binding_1 (ns, name);
+ cxx_binding *binding = find_namespace_binding (ns, name);
timevar_cond_stop (TV_NAME_LOOKUP, subtime);
- return ret;
+ return binding ? binding->value : NULL_TREE;
}
static void
set_namespace_binding (tree scope, tree name, tree val)
{
- cxx_binding *b;
-
if (scope == NULL_TREE)
scope = global_namespace;
- b = binding_for_name (NAMESPACE_LEVEL (scope), name);
- if (!b->value
+ cxx_binding *binding = find_namespace_binding (scope, name, true);
+ if (!binding->value
/* For templates and using we create a single element OVERLOAD.
Look for the chain to know whether this is really augmenting
an existing overload. */
|| (TREE_CODE (val) == OVERLOAD && OVL_CHAIN (val))
|| val == error_mark_node)
- b->value = val;
+ binding->value = val;
else
- supplement_binding (b, val);
+ supplement_binding (binding, val);
}
/* Set value binding og NAME in the global namespace to VAL. Does not
return;
cxx_binding *binding
- = binding_for_name (NAMESPACE_LEVEL (current_namespace), name);
+ = find_namespace_binding (current_namespace, name, true);
tree value = binding->value;
tree type = binding->type;
for (; !val; scope = CP_DECL_CONTEXT (scope))
{
struct scope_binding binding = EMPTY_SCOPE_BINDING;
- cxx_binding *b =
- cp_binding_level_find_binding_for_name (NAMESPACE_LEVEL (scope), name);
+ cxx_binding *b = find_namespace_binding (scope, name);
if (b)
ambiguous_decl (&binding, b, flags);
if (TREE_VALUE (iter) == scope)
{
tree used = ORIGINAL_NAMESPACE (TREE_PURPOSE (iter));
- cxx_binding *val1 =
- cp_binding_level_find_binding_for_name (NAMESPACE_LEVEL (used), name);
+ cxx_binding *val1 = find_namespace_binding (used, name);
/* Resolve ambiguities. */
if (val1)
ambiguous_decl (val, val1, flags);
continue;
vec_safe_push (seen_inline, scope);
- binding =
- cp_binding_level_find_binding_for_name (NAMESPACE_LEVEL (scope), name);
+ binding = find_namespace_binding (scope, name);
if (binding)
{
ambiguous_decl (result, binding, flags);
/* Look in namespace scope. */
if (!val)
{
- iter = cp_binding_level_find_binding_for_name
- (NAMESPACE_LEVEL (current_decl_namespace ()), name);
+ iter = find_namespace_binding (current_decl_namespace (), name);
if (iter)
{
lookup_name_innermost_nonclass_level_1 (tree name)
{
cp_binding_level *b = innermost_nonclass_level ();
+ cxx_binding *binding = NULL;
if (b->kind == sk_namespace)
- return namespace_binding_1 (current_namespace, name);
- else if (cxx_binding *binding = find_local_binding (b, name))
- return binding->value;
+ binding = find_namespace_binding (current_namespace, name);
else
- return NULL_TREE;
+ binding = find_local_binding (b, name);
+
+ return binding ? binding->value : NULL_TREE;
}
/* Wrapper for lookup_name_innermost_nonclass_level_1. */