return found;
}
+static void
+consider_decl (tree decl, best_match <tree, const char *> &bm,
+ bool consider_impl_names)
+{
+ /* Skip compiler-generated variables (e.g. __for_begin/__for_end
+ within range for). */
+ if (TREE_CODE (decl) == VAR_DECL && DECL_ARTIFICIAL (decl))
+ return;
+
+ tree suggestion = DECL_NAME (decl);
+ if (!suggestion)
+ return;
+
+ /* Don't suggest names that are for anonymous aggregate types, as
+ they are an implementation detail generated by the compiler. */
+ if (IDENTIFIER_ANON_P (suggestion))
+ return;
+
+ const char *suggestion_str = IDENTIFIER_POINTER (suggestion);
+
+ /* Ignore internal names with spaces in them. */
+ if (strchr (suggestion_str, ' '))
+ return;
+
+ /* Don't suggest names that are reserved for use by the
+ implementation, unless NAME began with an underscore. */
+ if (!consider_impl_names
+ && name_reserved_for_implementation_p (suggestion_str))
+ return;
+
+ bm.consider (suggestion_str);
+}
+
/* Helper function for lookup_name_fuzzy.
Traverse binding level LVL, looking for good name matches for NAME
(and BM). */
with an underscore. */
bool consider_implementation_names = (IDENTIFIER_POINTER (name)[0] == '_');
- for (tree t = lvl->names; t; t = TREE_CHAIN (t))
- {
- tree d = t;
-
- /* OVERLOADs or decls from using declaration are wrapped into
- TREE_LIST. */
- if (TREE_CODE (d) == TREE_LIST)
- d = OVL_FIRST (TREE_VALUE (d));
-
- /* Don't use bindings from implicitly declared functions,
- as they were likely misspellings themselves. */
- if (TREE_TYPE (d) == error_mark_node)
- continue;
-
- /* Skip anticipated decls of builtin functions. */
- if (TREE_CODE (d) == FUNCTION_DECL
- && fndecl_built_in_p (d)
- && DECL_ANTICIPATED (d))
- continue;
+ if (lvl->kind != sk_namespace)
+ for (tree t = lvl->names; t; t = TREE_CHAIN (t))
+ {
+ tree d = t;
- /* Skip compiler-generated variables (e.g. __for_begin/__for_end
- within range for). */
- if (TREE_CODE (d) == VAR_DECL
- && DECL_ARTIFICIAL (d))
- continue;
+ /* OVERLOADs or decls from using declaration are wrapped into
+ TREE_LIST. */
+ if (TREE_CODE (d) == TREE_LIST)
+ d = OVL_FIRST (TREE_VALUE (d));
- tree suggestion = DECL_NAME (d);
- if (!suggestion)
- continue;
-
- /* Don't suggest names that are for anonymous aggregate types, as
- they are an implementation detail generated by the compiler. */
- if (IDENTIFIER_ANON_P (suggestion))
- continue;
+ /* Don't use bindings from implicitly declared functions,
+ as they were likely misspellings themselves. */
+ if (TREE_TYPE (d) == error_mark_node)
+ continue;
- const char *suggestion_str = IDENTIFIER_POINTER (suggestion);
+ /* If we want a typename, ignore non-types. */
+ if (kind == FUZZY_LOOKUP_TYPENAME
+ && TREE_CODE (STRIP_TEMPLATE (d)) != TYPE_DECL)
+ continue;
- /* Ignore internal names with spaces in them. */
- if (strchr (suggestion_str, ' '))
- continue;
+ consider_decl (d, bm, consider_implementation_names);
+ }
+ else
+ {
+ /* Iterate over the namespace hash table, that'll have fewer
+ entries than the decl list. */
+ tree ns = lvl->this_entity;
- /* Don't suggest names that are reserved for use by the
- implementation, unless NAME began with an underscore. */
- if (name_reserved_for_implementation_p (suggestion_str)
- && !consider_implementation_names)
- continue;
+ hash_table<named_decl_hash>::iterator end
+ (DECL_NAMESPACE_BINDINGS (ns)->end ());
+ for (hash_table<named_decl_hash>::iterator iter
+ (DECL_NAMESPACE_BINDINGS (ns)->begin ()); iter != end; ++iter)
+ {
+ tree binding = *iter;
+ tree value = NULL_TREE;
- bm.consider (suggestion_str);
+ if (STAT_HACK_P (binding))
+ {
+ if (!STAT_TYPE_HIDDEN_P (binding)
+ && STAT_TYPE (binding))
+ consider_decl (STAT_TYPE (binding), bm,
+ consider_implementation_names);
+ else if (!STAT_DECL_HIDDEN_P (binding))
+ value = STAT_DECL (binding);
+ }
+ else
+ value = binding;
+
+ value = ovl_skip_hidden (value);
+ if (value)
+ {
+ value = OVL_FIRST (value);
+ if (!(kind == FUZZY_LOOKUP_TYPENAME
+ && TREE_CODE (STRIP_TEMPLATE (value)) != TYPE_DECL))
+ consider_decl (value, bm, consider_implementation_names);
+ }
+ }
}
}