From: Nathan Sidwell Date: Fri, 14 Aug 2020 23:53:43 +0000 (-0700) Subject: c++: Final bit of name-lookup api simplification X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=f00008b45ade9e63edf785838b34f5e55909af5e;p=gcc.git c++: Final bit of name-lookup api simplification We no longer need to give name_lookup_real not name_lookup_nonclass different names to the name_lookup functions. This renames the lookup functions thusly. gcc/cp/ * name-lookup.h (lookup_name_real, lookup_name_nonclass): Rename to ... (lookup_name): ... these new overloads. * name-lookup.c (identifier_type_value_1): Rename lookup_name_real call. (lookup_name_real_1): Rename to ... (lookup_name_1): ... here. (lookup_name_real): Rename to ... (lookup_name): ... here. Rename lookup_name_real_1 call. (lookup_name_nonclass): Delete. * call.c (build_operator_new_call): Rename lookup_name_real call. (add_operator_candidates): Likewise. (build_op_delete_call): Rename lookup_name_nonclass call. * parser.c (cp_parser_lookup_name): Likewise. * pt.c (tsubst_friend_class, lookup_init_capture_pack): Likewise. (tsubst_expr): Likewise. * semantics.c (capture_decltype): Likewise. libcc1/ * libcp1plugin.cc (plugin_build_dependent_expr): Rename lookup_name_real call. --- diff --git a/gcc/cp/call.c b/gcc/cp/call.c index 8c03fcaf74b..c62d9e227d3 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -4704,7 +4704,7 @@ build_operator_new_call (tree fnname, vec **args, up in the global scope. we disregard block-scope declarations of "operator new". */ - fns = lookup_name_real (fnname, LOOK_where::NAMESPACE, LOOK_want::NORMAL); + fns = lookup_name (fnname, LOOK_where::NAMESPACE); fns = lookup_arg_dependent (fnname, fns, *args); if (align_arg) @@ -5982,8 +5982,7 @@ add_operator_candidates (z_candidate **candidates, consider. */ if (!memonly) { - tree fns = lookup_name_real (fnname, LOOK_where::BLOCK_NAMESPACE, - LOOK_want::NORMAL); + tree fns = lookup_name (fnname, LOOK_where::BLOCK_NAMESPACE); fns = lookup_arg_dependent (fnname, fns, arglist); add_candidates (fns, NULL_TREE, arglist, NULL_TREE, NULL_TREE, false, NULL_TREE, NULL_TREE, @@ -6812,7 +6811,7 @@ build_op_delete_call (enum tree_code code, tree addr, tree size, fns = NULL_TREE; if (fns == NULL_TREE) - fns = lookup_name_nonclass (fnname); + fns = lookup_name (fnname, LOOK_where::BLOCK_NAMESPACE); /* Strip const and volatile from addr. */ tree oaddr = addr; diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c index 4753dc529e6..ad9c92da254 100644 --- a/gcc/cp/name-lookup.c +++ b/gcc/cp/name-lookup.c @@ -3743,7 +3743,7 @@ identifier_type_value_1 (tree id) return REAL_IDENTIFIER_TYPE_VALUE (id); /* Have to search for it. It must be on the global level, now. Ask lookup_name not to return non-types. */ - id = lookup_name_real (id, LOOK_where::BLOCK_NAMESPACE, LOOK_want::TYPE); + id = lookup_name (id, LOOK_where::BLOCK_NAMESPACE, LOOK_want::TYPE); if (id) return TREE_TYPE (id); return NULL_TREE; @@ -5213,8 +5213,7 @@ cp_namespace_decls (tree ns) } /* Given a lookup that returned VAL, use FLAGS to decide if we want to - ignore it or not. Subroutine of lookup_name_real and - lookup_type_scope. */ + ignore it or not. Subroutine of lookup_name_1 and lookup_type_scope. */ static bool qualify_lookup (tree val, LOOK_want want) @@ -5987,7 +5986,7 @@ suggest_alternative_in_scoped_enum (tree name, tree scoped_enum) /* Look up NAME (an IDENTIFIER_NODE) in SCOPE (either a NAMESPACE_DECL or a class TYPE). - WANT as for lookup_name_real_1. + WANT as for lookup_name_1. Returns a DECL (or OVERLOAD, or BASELINK) representing the declaration found. If no suitable declaration can be found, @@ -6420,10 +6419,13 @@ innermost_non_namespace_value (tree name) LOOK_want::NORMAL for normal lookup (implicit typedefs can be hidden). LOOK_want::TYPE for only TYPE_DECLS, LOOK_want::NAMESPACE for only NAMESPACE_DECLS. These two can be bit-ored to find - namespace or type. */ + namespace or type. + + WANT can also have LOOK_want::HIDDEN_FRIEND or + LOOK_want::HIDDEN_LAMBDa added to it. */ static tree -lookup_name_real_1 (tree name, LOOK_where where, LOOK_want want) +lookup_name_1 (tree name, LOOK_where where, LOOK_want want) { tree val = NULL_TREE; @@ -6560,33 +6562,21 @@ lookup_name_real_1 (tree name, LOOK_where where, LOOK_want want) return val; } -/* Wrapper for lookup_name_real_1. */ +/* Wrapper for lookup_name_1. */ tree -lookup_name_real (tree name, LOOK_where where, LOOK_want want) +lookup_name (tree name, LOOK_where where, LOOK_want want) { bool subtime = timevar_cond_start (TV_NAME_LOOKUP); - tree ret = lookup_name_real_1 (name, where, want); + tree ret = lookup_name_1 (name, where, want); timevar_cond_stop (TV_NAME_LOOKUP, subtime); return ret; } -tree -lookup_name_nonclass (tree name) -{ - return lookup_name_real (name, LOOK_where::BLOCK_NAMESPACE, LOOK_want::NORMAL); -} - tree lookup_name (tree name) { - return lookup_name_real (name, LOOK_where::ALL, LOOK_want::NORMAL); -} - -tree -lookup_name (tree name, LOOK_want want) -{ - return lookup_name_real (name, LOOK_where::ALL, want); + return lookup_name (name, LOOK_where::ALL, LOOK_want::NORMAL); } /* Look up NAME for type used in elaborated name specifier in @@ -6595,7 +6585,7 @@ lookup_name (tree name, LOOK_want want) name, more scopes are checked if cleanup or template parameter scope is encountered. - Unlike lookup_name_real, we make sure that NAME is actually + Unlike lookup_name_1, we make sure that NAME is actually declared in the desired scope, not from inheritance, nor using directive. For using declaration, there is DR138 still waiting to be resolved. Hidden name coming from an earlier friend diff --git a/gcc/cp/name-lookup.h b/gcc/cp/name-lookup.h index e43a04c1d6e..723fbb0008c 100644 --- a/gcc/cp/name-lookup.h +++ b/gcc/cp/name-lookup.h @@ -320,7 +320,14 @@ constexpr LOOK_want operator& (LOOK_want a, LOOK_want b) return LOOK_want (unsigned (a) & unsigned (b)); } -extern tree lookup_name_real (tree, LOOK_where, LOOK_want); +extern tree lookup_name (tree, LOOK_where, LOOK_want = LOOK_want::NORMAL); +/* Also declared in c-family/c-common.h. */ +extern tree lookup_name (tree name); +inline tree lookup_name (tree name, LOOK_want want) +{ + return lookup_name (name, LOOK_where::ALL, want); +} + extern tree lookup_type_scope (tree, tag_scope); extern tree get_namespace_binding (tree ns, tree id); extern void set_global_binding (tree decl); @@ -328,16 +335,12 @@ inline tree get_global_binding (tree id) { return get_namespace_binding (NULL_TREE, id); } -/* Also declared in c-family/c-common.h. */ -extern tree lookup_name (tree name); -extern tree lookup_name (tree name, LOOK_want); extern tree lookup_qualified_name (tree scope, tree name, LOOK_want = LOOK_want::NORMAL, bool = true); extern tree lookup_qualified_name (tree scope, const char *name, LOOK_want = LOOK_want::NORMAL, bool = true); -extern tree lookup_name_nonclass (tree); extern bool is_local_extern (tree); extern bool pushdecl_class_level (tree); extern tree pushdecl_namespace_level (tree, bool); diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 641cedbe3f8..7cc2dbed5fe 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -28213,7 +28213,7 @@ cp_parser_nested_requirement (cp_parser *parser) /* Support Functions */ -/* Return the appropriate prefer_type argument for lookup_name_real based on +/* Return the appropriate prefer_type argument for lookup_name based on tag_type. */ static inline LOOK_want @@ -28455,22 +28455,20 @@ cp_parser_lookup_name (cp_parser *parser, tree name, if (!decl) /* Look it up in the enclosing context. DR 141: When looking for a template-name after -> or ., only consider class templates. */ - decl = lookup_name_real (name, LOOK_where::ALL, - is_namespace ? LOOK_want::NAMESPACE - /* DR 141: When looking in the - current enclosing context for a - template-name after -> or ., only - consider class templates. */ - : is_template ? LOOK_want::TYPE - : prefer_type_arg (tag_type)); + decl = lookup_name (name, is_namespace ? LOOK_want::NAMESPACE + /* DR 141: When looking in the + current enclosing context for a + template-name after -> or ., only + consider class templates. */ + : is_template ? LOOK_want::TYPE + : prefer_type_arg (tag_type)); parser->object_scope = object_type; parser->qualifying_scope = NULL_TREE; } else { - decl = lookup_name_real (name, LOOK_where::ALL, - is_namespace ? LOOK_want::NAMESPACE - : prefer_type_arg (tag_type)); + decl = lookup_name (name, is_namespace ? LOOK_want::NAMESPACE + : prefer_type_arg (tag_type)); parser->qualifying_scope = NULL_TREE; parser->object_scope = NULL_TREE; } diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 74c745a2c5d..b80fe0a5cc5 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -11184,8 +11184,8 @@ tsubst_friend_class (tree friend_tmpl, tree args) push_nested_class (context); } - tmpl = lookup_name_real (DECL_NAME (friend_tmpl), LOOK_where::CLASS_NAMESPACE, - LOOK_want::NORMAL | LOOK_want::HIDDEN_FRIEND); + tmpl = lookup_name (DECL_NAME (friend_tmpl), LOOK_where::CLASS_NAMESPACE, + LOOK_want::NORMAL | LOOK_want::HIDDEN_FRIEND); if (tmpl && DECL_CLASS_TEMPLATE_P (tmpl)) { @@ -17835,7 +17835,7 @@ lookup_init_capture_pack (tree decl) for (int i = 0; i < len; ++i) { tree ename = vec ? make_ith_pack_parameter_name (cname, i) : cname; - tree elt = lookup_name_real (ename, LOOK_where::ALL, LOOK_want::NORMAL); + tree elt = lookup_name (ename); if (vec) TREE_VEC_ELT (vec, i) = elt; else @@ -17940,9 +17940,8 @@ tsubst_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl, tree inst; if (!DECL_PACK_P (decl)) { - inst = (lookup_name_real - (DECL_NAME (decl), LOOK_where::BLOCK, - LOOK_want::NORMAL | LOOK_want::HIDDEN_LAMBDA)); + inst = lookup_name (DECL_NAME (decl), LOOK_where::BLOCK, + LOOK_want::HIDDEN_LAMBDA); gcc_assert (inst != decl && is_capture_proxy (inst)); } else if (is_normal_capture_proxy (decl)) diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index da452c58daa..b71ca0729a8 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -10322,8 +10322,8 @@ static tree capture_decltype (tree decl) { tree lam = CLASSTYPE_LAMBDA_EXPR (DECL_CONTEXT (current_function_decl)); - tree cap = lookup_name_real (DECL_NAME (decl), LOOK_where::BLOCK, - LOOK_want::NORMAL | LOOK_want::HIDDEN_LAMBDA); + tree cap = lookup_name (DECL_NAME (decl), LOOK_where::BLOCK, + LOOK_want::HIDDEN_LAMBDA); tree type; if (cap && is_capture_proxy (cap)) diff --git a/libcc1/libcp1plugin.cc b/libcc1/libcp1plugin.cc index e30cb8c024b..a83bfeb0a16 100644 --- a/libcc1/libcp1plugin.cc +++ b/libcc1/libcp1plugin.cc @@ -2652,8 +2652,7 @@ plugin_build_dependent_expr (cc1_plugin::connection *self, } tree res = identifier; if (!scope) - res = lookup_name_real (res, LOOK_where::BLOCK_NAMESPACE, - LOOK_want::NORMAL); + res = lookup_name (res, LOOK_where::BLOCK_NAMESPACE); else if (!TYPE_P (scope) || !dependent_scope_p (scope)) { res = lookup_qualified_name (scope, res, LOOK_want::NORMAL, true);