invoke_xmethod & array_view
This replaces more pointer+length with gdb::array_view. This time, around invoke_xmethod, and then propagating the fallout around, which inevitably leaks to the overload resolution code. There are several places in the code that want to grab a slice of an array, by advancing the array pointer, and decreasing the length pointer. This patch introduces a pair of new gdb::array_view::slice(...) methods to make that convenient and clear. Unit test included. gdb/ChangeLog: 2018-11-21 Pedro Alves <palves@redhat.com> * common/array-view.h (array_view::splice(size_type, size_t)): New. (array_view::splice(size_type)): New. * eval.c (eval_call, evaluate_funcall): Adjust to use array_view. * extension.c (xmethod_worker::get_arg_types): Adjust to return an std::vector. (xmethod_worker::get_result_type): Adjust to use gdb::array_view. * extension.h: Include "common/array-view.h". (xmethod_worker::invoke): Adjust to use gdb::array_view. (xmethod_worker::get_arg_types): Adjust to return an std::vector. (xmethod_worker::get_result_type): Adjust to use gdb::array_view. (xmethod_worker::do_get_arg_types): Adjust to use std::vector. (xmethod_worker::do_get_result_type): Adjust to use gdb::array_view. * gdbtypes.c (rank_function): Adjust to use gdb::array_view. * gdbtypes.h: Include "common/array-view.h". (rank_function): Adjust to use gdb::array_view. * python/py-xmethods.c (python_xmethod_worker::invoke) (python_xmethod_worker::do_get_arg_types) (python_xmethod_worker::do_get_result_type) (python_xmethod_worker::invoke): Adjust to new interfaces. * valarith.c (value_user_defined_cpp_op, value_user_defined_op) (value_x_binop, value_x_unop): Adjust to use gdb::array_view. * valops.c (find_overload_match, find_oload_champ_namespace) (find_oload_champ_namespace_loop, find_oload_champ): Adjust to use gdb:array_view and the new xmethod_worker interfaces. * value.c (result_type_of_xmethod, call_xmethod): Adjust to use gdb::array_view. * value.h (find_overload_match, result_type_of_xmethod) (call_xmethod): Adjust to use gdb::array_view. * unittests/array-view-selftests.c: Add slicing tests.
This commit is contained in:
parent
e71585ffe2
commit
6b1747cd13
13 changed files with 212 additions and 151 deletions
|
@ -3464,21 +3464,20 @@ compare_badness (struct badness_vector *a, struct badness_vector *b)
|
|||
}
|
||||
}
|
||||
|
||||
/* Rank a function by comparing its parameter types (PARMS, length
|
||||
NPARMS), to the types of an argument list (ARGS, length NARGS).
|
||||
Return a pointer to a badness vector. This has NARGS + 1
|
||||
entries. */
|
||||
/* Rank a function by comparing its parameter types (PARMS), to the
|
||||
types of an argument list (ARGS). Return a pointer to a badness
|
||||
vector. This has ARGS.size() + 1 entries. */
|
||||
|
||||
struct badness_vector *
|
||||
rank_function (struct type **parms, int nparms,
|
||||
struct value **args, int nargs)
|
||||
rank_function (gdb::array_view<type *> parms,
|
||||
gdb::array_view<value *> args)
|
||||
{
|
||||
int i;
|
||||
struct badness_vector *bv = XNEW (struct badness_vector);
|
||||
int min_len = nparms < nargs ? nparms : nargs;
|
||||
size_t min_len = std::min (parms.size (), args.size ());
|
||||
|
||||
bv->length = nargs + 1; /* add 1 for the length-match rank. */
|
||||
bv->rank = XNEWVEC (struct rank, nargs + 1);
|
||||
bv->length = args.size () + 1; /* add 1 for the length-match rank. */
|
||||
bv->rank = XNEWVEC (struct rank, args.size () + 1);
|
||||
|
||||
/* First compare the lengths of the supplied lists.
|
||||
If there is a mismatch, set it to a high value. */
|
||||
|
@ -3487,7 +3486,7 @@ rank_function (struct type **parms, int nparms,
|
|||
arguments and ellipsis parameter lists, we should consider those
|
||||
and rank the length-match more finely. */
|
||||
|
||||
LENGTH_MATCH (bv) = (nargs != nparms)
|
||||
LENGTH_MATCH (bv) = (args.size () != parms.size ())
|
||||
? LENGTH_MISMATCH_BADNESS
|
||||
: EXACT_MATCH_BADNESS;
|
||||
|
||||
|
@ -3497,7 +3496,7 @@ rank_function (struct type **parms, int nparms,
|
|||
args[i - 1]);
|
||||
|
||||
/* If more arguments than parameters, add dummy entries. */
|
||||
for (i = min_len + 1; i <= nargs; i++)
|
||||
for (i = min_len + 1; i <= args.size (); i++)
|
||||
bv->rank[i] = TOO_FEW_PARAMS_BADNESS;
|
||||
|
||||
return bv;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue