Re: [RFC 1/8] Use std::map for MI commands in mi-cmds.c

Simon Marchi
2019-05-03T22:40:26Z

On 2019-04-18 11:23 a.m., Jan Vrany wrote:
> @@ -82,7 +82,7 @@ mi_cmd_info_gdb_mi_command (const char *command, char **argv, int argc)
> if (cmd_name[0] == '-')
> cmd_name++;
>
> - cmd = mi_lookup (cmd_name);
> + cmd = mi_cmd_lookup (cmd_name);
>
> ui_out_emit_tuple tuple_emitter (uiout, "command");
> uiout->field_string ("exists", cmd != NULL ? "true" : "false");
> diff --git a/gdb/mi/mi-cmds.c b/gdb/mi/mi-cmds.c
> index fe30ac2e82..2b3cf297cf 100644
> --- a/gdb/mi/mi-cmds.c
> +++ b/gdb/mi/mi-cmds.c
> @@ -22,267 +22,243 @@
> #include "top.h"
> #include "mi-cmds.h"
> #include "mi-main.h"
> +#include
> +#include <string>
> +#include <memory>

Is there something that uses <memory>?

> +/* Create an mi_cmd structure with name NAME. */
> +
> +static mi_cmd_up
> +create_mi_cmd (const char *name)
> {
> - return *lookup_table (command);
> + mi_cmd_up cmd (new mi_cmd ());
> +
> + cmd->name = name;
> +
> + return cmd;
> }

create_mi_cmd could be a constructor to mi_cmd instead. In fact, there could be
two constructors of mi_cmd for each version (the mi-based MI commands and the
cli-based MI commands), each taking the appropriate parameters.

Simon