diff options
author | Pedro Alves <palves@redhat.com> | 2018-11-21 11:55:12 +0000 |
---|---|---|
committer | Pedro Alves <palves@redhat.com> | 2018-11-21 12:06:20 +0000 |
commit | 6b1747cd135ff9859fceb6043179b1ef94363996 (patch) | |
tree | 9dd00eb42169b61747d43efeec410c66ba7070e3 /gdb/extension.h | |
parent | e71585ffe2e1394858f0fcf809e86f1b324fe4e6 (diff) | |
download | gdb-6b1747cd135ff9859fceb6043179b1ef94363996.zip gdb-6b1747cd135ff9859fceb6043179b1ef94363996.tar.gz gdb-6b1747cd135ff9859fceb6043179b1ef94363996.tar.bz2 |
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.
Diffstat (limited to 'gdb/extension.h')
-rw-r--r-- | gdb/extension.h | 32 |
1 files changed, 15 insertions, 17 deletions
diff --git a/gdb/extension.h b/gdb/extension.h index 0c8c4ee..b9314c0 100644 --- a/gdb/extension.h +++ b/gdb/extension.h @@ -22,6 +22,7 @@ #include "mi/mi-cmds.h" /* For PRINT_NO_VALUES, etc. */ #include "common/vec.h" +#include "common/array-view.h" struct breakpoint; struct command_line; @@ -186,38 +187,35 @@ struct xmethod_worker virtual ~xmethod_worker () = default; /* Invoke the xmethod encapsulated in this worker and return the result. - The method is invoked on OBJ with arguments in the ARGS array. NARGS is - the length of the this array. */ + The method is invoked on OBJ with arguments in the ARGS array. */ - virtual value *invoke (value *obj, value **args, int nargs) = 0; + virtual value *invoke (value *obj, gdb::array_view<value *> args) = 0; /* Return the arg types of the xmethod encapsulated in this worker. - An array of arg types is returned. The length of the array is returned in - NARGS. The type of the 'this' object is returned as the first element of - array. */ + The type of the 'this' object is returned as the first element of + the vector. */ - type **get_arg_types (int *nargs); + std::vector<type *> get_arg_types (); /* Return the type of the result of the xmethod encapsulated in this worker. - OBJECT, ARGS, NARGS are the same as for invoke. */ + OBJECT and ARGS are the same as for invoke. */ - type *get_result_type (value *object, value **args, int nargs); + type *get_result_type (value *object, gdb::array_view<value *> args); private: - /* Return the types of the arguments the method takes. The number of - arguments is returned in NARGS, and their types are returned in the array - ARGTYPES. */ + /* Return the types of the arguments the method takes. The types + are returned in TYPE_ARGS, one per argument. */ virtual enum ext_lang_rc do_get_arg_types - (int *nargs, struct type ***arg_types) = 0; + (std::vector<type *> *type_args) = 0; - /* Fetch the type of the result of the method implemented by this worker. - OBJECT, ARGS, NARGS are the same as for the invoked method. The result - type is stored in *RESULT_TYPE. */ + /* Fetch the type of the result of the method implemented by this + worker. OBJECT and ARGS are the same as for the invoked method. + The result type is stored in *RESULT_TYPE. */ virtual enum ext_lang_rc do_get_result_type - (struct value *obj, struct value **args, int nargs, + (struct value *obj, gdb::array_view<value *> args, struct type **result_type_ptr) = 0; /* The language the xmethod worker is implemented in. */ |