From 31ab89c14afc55c26ccaabebcff0bcfdd2c87369 Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Thu, 18 May 2017 12:55:11 +0000 Subject: [PATCH] cp-tree.h (lookup_add): Swap args. * cp-tree.h (lookup_add): Swap args. (ovl_cons, build_overload): Delete. * name-lookup.c (add_function, push_overloaded_decl_1) do_nonmember_using_decl, merge_functions, remove_hidden_names): Use lookup_add, ovl_insert. * pt.c (check_explicit_specialization): Use lookup_add. (do_class_deduction): Likewise. Refactor if. * tree.c (lookup_add): Swap args. (ovl_cons, build_overload): Delete. (--This line, and those below, will be ignored-- M cp/cp-tree.h M cp/name-lookup.c M cp/pt.c M cp/ChangeLog M cp/tree.c From-SVN: r248198 --- gcc/cp/ChangeLog | 10 ++++++++++ gcc/cp/cp-tree.h | 4 +--- gcc/cp/name-lookup.c | 37 +++++-------------------------------- gcc/cp/pt.c | 40 ++++++++++++++++++++-------------------- gcc/cp/tree.c | 34 +++++----------------------------- 5 files changed, 41 insertions(+), 84 deletions(-) diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 3936877a090..8b5f8513a5a 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,15 @@ 2017-05-18 Nathan Sidwell + * cp-tree.h (lookup_add): Swap args. + (ovl_cons, build_overload): Delete. + * name-lookup.c (add_function, push_overloaded_decl_1, + do_nonmember_using_decl, merge_functions, remove_hidden_names): + Use lookup_add, ovl_insert. + * pt.c (check_explicit_specialization): Use lookup_add. + (do_class_deduction): Likewise. Refactor if. + * tree.c (lookup_add): Swap args. + (ovl_cons, build_overload): Delete. + * name-lookup.c (find_local_binding): New, broken out of ... (lookup_name_innermost_nonclass_level_1): ... here. Call it. (set_namespace_binding): Swap scope & name args. diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 25b05ef6cd0..3e1cf306eb0 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -6809,13 +6809,11 @@ extern tree ovl_make (tree fn, tree next = NULL_TREE); extern tree ovl_insert (tree fn, tree maybe_ovl, bool using_p = false); -extern tree lookup_add (tree lookup, tree ovl); +extern tree lookup_add (tree fns, tree lookup); extern int is_overloaded_fn (tree); extern tree dependent_name (tree); extern tree get_fns (tree) ATTRIBUTE_PURE; extern tree get_first_fn (tree) ATTRIBUTE_PURE; -extern tree ovl_cons (tree, tree); -extern tree build_overload (tree, tree); extern tree ovl_scope (tree); extern const char *cxx_printable_name (tree, int); extern const char *cxx_printable_name_translate (tree, int); diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c index c94aeb56183..a4fe3d3ee2a 100644 --- a/gcc/cp/name-lookup.c +++ b/gcc/cp/name-lookup.c @@ -160,7 +160,7 @@ add_function (struct arg_lookup *k, tree fn) ; else { - k->functions = build_overload (fn, k->functions); + k->functions = lookup_add (fn, k->functions); if (TREE_CODE (k->functions) == OVERLOAD) OVL_ARG_DEPENDENT (k->functions) = true; } @@ -2952,24 +2952,7 @@ push_overloaded_decl_1 (tree decl, int flags, bool is_friend) } } - if (old || TREE_CODE (decl) == TEMPLATE_DECL - /* If it's a using declaration, we always need to build an OVERLOAD, - because it's the only way to remember that the declaration comes - from 'using', and have the lookup behave correctly. */ - || (flags & PUSH_USING)) - { - if (old && TREE_CODE (old) != OVERLOAD) - /* Wrap the existing single decl in an overload. */ - new_binding = ovl_cons (old, NULL_TREE); - else - new_binding = old; - new_binding = ovl_cons (decl, new_binding); - if (flags & PUSH_USING) - OVL_USED (new_binding) = 1; - } - else - /* NAME is not ambiguous. */ - new_binding = decl; + new_binding = ovl_insert (decl, old, flags & PUSH_USING); if (doing_global) set_namespace_binding (current_namespace, name, new_binding); @@ -3184,17 +3167,7 @@ do_nonmember_using_decl (tree scope, tree name, tree oldval, tree oldtype, if (*newval && TREE_CODE (*newval) == OVERLOAD) TREE_TYPE (*newval) = unknown_type_node; /* Add this new function to the set. */ - *newval = build_overload (OVL_CURRENT (tmp), *newval); - /* If there is only one function, then we use its type. (A - using-declaration naming a single function can be used in - contexts where overload resolution cannot be - performed.) */ - if (TREE_CODE (*newval) != OVERLOAD) - { - *newval = ovl_cons (*newval, NULL_TREE); - TREE_TYPE (*newval) = TREE_TYPE (OVL_CURRENT (tmp)); - } - OVL_USED (*newval) = 1; + *newval = ovl_insert (OVL_CURRENT (tmp), *newval, true); } } else @@ -4578,7 +4551,7 @@ merge_functions (tree s1, tree s2) /* If we exhausted all of the functions in S1, FN2 is new. */ if (!fns1) - s1 = build_overload (fn2, s1); + s1 = lookup_add (fn2, s1); } return s1; } @@ -4788,7 +4761,7 @@ remove_hidden_names (tree fns) for (o = fns; o; o = OVL_NEXT (o)) if (!hidden_name_p (OVL_CURRENT (o))) - n = build_overload (OVL_CURRENT (o), n); + n = lookup_add (OVL_CURRENT (o), n); fns = n; } } diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 45f878e26f4..ed3f45ed84e 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -2931,7 +2931,7 @@ check_explicit_specialization (tree declarator, /* Glue all these conversion functions together with those we already have. */ for (; ovl; ovl = OVL_NEXT (ovl)) - fns = ovl_cons (OVL_CURRENT (ovl), fns); + fns = lookup_add (OVL_CURRENT (ovl), fns); } } @@ -25171,7 +25171,7 @@ do_class_deduction (tree ptype, tree tmpl, tree init, int flags, tree pruned = NULL_TREE; for (lkp_iterator iter (cands); iter; ++iter) if (!DECL_NONCONVERTING_P (STRIP_TEMPLATE (*iter))) - pruned = lookup_add (pruned, *iter); + pruned = lookup_add (*iter, pruned); cands = pruned; } @@ -25196,29 +25196,29 @@ do_class_deduction (tree ptype, tree tmpl, tree init, int flags, && DECL_NONCONVERTING_P (STRIP_TEMPLATE (guide))) elided = true; else - cands = lookup_add (cands, guide); + cands = lookup_add (guide, cands); saw_ctor = true; } - if (!saw_ctor && args->length() == 0) + if (args->length () < 2) { - tree guide = build_deduction_guide (type, outer_args, complain); - if ((flags & LOOKUP_ONLYCONVERTING) - && DECL_NONCONVERTING_P (STRIP_TEMPLATE (guide))) - elided = true; - else - cands = lookup_add (cands, guide); - } - if (args->length() == 1) - { - tree guide = build_deduction_guide (build_reference_type (type), - outer_args, complain); - if ((flags & LOOKUP_ONLYCONVERTING) - && DECL_NONCONVERTING_P (STRIP_TEMPLATE (guide))) - elided = true; - else - cands = lookup_add (cands, guide); + tree gtype = NULL_TREE; + + if (args->length () == 1) + gtype = build_reference_type (type); + else if (!saw_ctor) + gtype = type; + + if (gtype) + { + tree guide = build_deduction_guide (gtype, outer_args, complain); + if ((flags & LOOKUP_ONLYCONVERTING) + && DECL_NONCONVERTING_P (STRIP_TEMPLATE (guide))) + elided = true; + else + cands = lookup_add (guide, cands); + } } if (elided && !cands) diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c index 7ea6ce2e37b..4417f079212 100644 --- a/gcc/cp/tree.c +++ b/gcc/cp/tree.c @@ -2183,18 +2183,18 @@ ovl_iterator::remove_node (tree overload, tree node) return overload; } -/* Add a potential overload into a lookup set. */ +/* Add a set of new FNS into a lookup. */ tree -lookup_add (tree lookup, tree ovl) +lookup_add (tree fns, tree lookup) { - if (lookup || TREE_CODE (ovl) == TEMPLATE_DECL) + if (lookup || TREE_CODE (fns) == TEMPLATE_DECL) { - lookup = ovl_make (ovl, lookup); + lookup = ovl_make (fns, lookup); OVL_LOOKUP_P (lookup) = true; } else - lookup = ovl; + lookup = fns; return lookup; } @@ -2277,30 +2277,6 @@ get_first_fn (tree from) return OVL_FIRST (get_fns (from)); } -/* Return a new OVL node, concatenating it with the old one. */ - -tree -ovl_cons (tree decl, tree chain) -{ - tree result = make_node (OVERLOAD); - TREE_TYPE (result) = unknown_type_node; - OVL_FUNCTION (result) = decl; - TREE_CHAIN (result) = chain; - - return result; -} - -/* Build a new overloaded function. If this is the first one, - just return it; otherwise, ovl_cons the _DECLs */ - -tree -build_overload (tree decl, tree chain) -{ - if (! chain && TREE_CODE (decl) != TEMPLATE_DECL) - return decl; - return ovl_cons (decl, chain); -} - /* Return the scope where the overloaded functions OVL were found. */ tree -- 2.30.2