This patch replaces the final few uses of ovl_cons and build_overload
with the new lookup_add and ovl_insert interfaces. Not all the use
locations are in their final form, but this does allow me to build out
the feature set. Soon changes will be confined to name-lookup.
While there I noticed another awkward argument ordering, and swapped
lookup_add to be consistent with ovl_insert and friends. I also noticed
do_class_deduction had two mutually exclusive if bodies, performing
very nearly the same work.
Applied to trunk.
nathan
--
Nathan Sidwell
2017-05-18 Nathan Sidwell <nat...@acm.org>
* 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.
Index: cp-tree.h
===================================================================
--- cp-tree.h (revision 248166)
+++ cp-tree.h (working copy)
@@ -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);
Index: name-lookup.c
===================================================================
--- name-lookup.c (revision 248191)
+++ name-lookup.c (working copy)
@@ -160,7 +160,7 @@ add_function (struct arg_lookup *k, tree
;
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 f
}
}
- 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, tre
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;
}
}
Index: pt.c
===================================================================
--- pt.c (revision 248166)
+++ pt.c (working copy)
@@ -2931,7 +2931,7 @@ check_explicit_specialization (tree decl
/* 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 tmp
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 tmp
&& 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)
Index: tree.c
===================================================================
--- tree.c (revision 248166)
+++ tree.c (working copy)
@@ -2183,18 +2183,18 @@ ovl_iterator::remove_node (tree overload
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