c++: More simplification of name_lookup api

Nathan Sidwell nathan@acm.org
Fri Aug 14 14:48:01 GMT 2020


Continuing fixing name lookup's API we have two parameters saying what 
we'd like to find 'prefer_type', which is a tri-valued boolan with 
meaning 'don't care', 'type or namespace', 'type or death'.  And we have 
a second parameter 'namespaces_only', which means 'namespace or death'. 
There are only 4 states, because the latter one has priority. Firstly 
'prefer_type' isn't really the right name -- it's not a preference, it's 
a requirement.  Name lookup maps those two parameters into 2 LOOKUP_ 
bits.  We can simply have callers express that desire directly.

So this adds another enum class, LOOK_want, which expresses all those 
options in 2 bits.  Most of this patch is then the expected fallout from 
such a change.  The parser was mapping its internal state into a 
prefer_type value, which was then mapped into the LOOKUP_ bits. So this 
saves a conversion there.  Also the parser's conversion routine had an 
'is_template' flag, which was only ever true in one place, where the 
parser also had to deal with other nuances of the flags to pass.  So 
just drop that parm and deal with it at the call site too.

I've left LOOKUP_HIDDEN alone for the moment.  That'll be next.

pushed

	gcc/cp/
	* cp-tree.h (LOOKUP_PREFER_TYPES, LOOKUP_PREFER_NAMESPACES)
	(LOOKUP_NAMESPACES_ONLY, LOOKUP_TYPES_ONLY)
	(LOOKUP_QUALIFIERS_ONL): Delete.
	(LOOKUP_HIDDEN): Adjust.
	* name-lookup.h (enum class LOOK_want): New.
	(operator|, operator&): Overloads for it.
	(lookup_name_real): Replace prefer_type & namespaces_only with
	LOOK_want parm.
	(lookup_qualified_name): Replace prefer_type with LOOK_want.
	(lookup_name_prefer_type): Replace with ...
	(lookup_name): ... this.  New overload with LOOK_want parm.
	* name-lookup.c (struct name_lookup): Replace flags with want and
	hidden fields.  Adjust constructors.
	(name_lookyp::add_overload): Correct hidden stripping test.  Update
	for new LOOK_want type.
	(name_lookup::process_binding): Likewise.
	(name_lookup::search_unqualified): Use hidden flag.
	(identifier_type_value_1): Adjust lookup_name_real call.
	(set_decl_namespace): Adjust name_lookup ctor.
	(lookup_flags): Delete.
	(qualify_lookup): Add LOOK_want parm, adjust.
	(lookup_qualified_name): Replace prefer_type parm with LOOK_want.
	(lookup_name_real_1): Replace prefer_type and namespaces_only with
	LOOK_want parm.
	(lookup_name_real): Likewise.
	(lookup_name_nonclass, lookup_name): Adjust lookup_name_real call.
	(lookup_name_prefer_type): Rename to ...
	(lookup_name): ... here.  New overload with LOOK_want parm.
	(lookup_type_scope_1): Adjust qualify_lookup calls.
	* call.c (build_operator_new_call)
	(add_operator_candidates): Adjust lookup_name_real calls.
	* coroutines.cc (find_coro_traits_template_decl)
	(find_coro_handle_template_decl, morph_fn_to_coro): Adjust
	lookup_qualified_name calls.
	* cp-objcp-common.c (identifier_global_tag): Likewise.
	* decl.c (get_tuple_size, get_tuple_decomp_init): Likewise.
	(lookup_and_check_tag): Use lookup_name overload.
	* parser.c (cp_parser_userdef_numeric_literal): Adjust
	lookup_qualified_name call.
	(prefer_arg_type): Drop template_mem_access parm, return LOOK_want
	value.
	(cp_parser_lookup_name): Adjust lookup_member, lookup_name_real
	calls.
	* pt.c (check_explicit_specialization): Adjust lookup_qualified_name
	call.
	(tsubst_copy_and_build, tsubst_qualified_name): Likewise
	(deduction_guides_for): Likewise.
	(tsubst_friend_class): Adjust lookup_name_real call.
	(lookup_init_capture, tsubst_expr): Likewise.
	* rtti.c (emit_support_tinfos): Adjust lookup_qualified_name call.
	* semantics.c (omp_reduction_lookup): Likewise.
	(capture_decltype): Adjust lookup_name_real call.
	libcc1/
	* libcp1plugin.cc (plugin_build_dependent_expr): Adjust
	lookup_name_real & lookup_qualified_name calls.
-- 
Nathan Sidwell
-------------- next part --------------
A non-text attachment was scrubbed...
Name: name-lookup-api-2.diff
Type: text/x-patch
Size: 33595 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc-patches/attachments/20200814/ad4a48db/attachment-0001.bin>


More information about the Gcc-patches mailing list