Re: [PATCH 16/22] Class-ify ui_out_level

Pedro Alves
2016-11-24T18:41:49Z

On 11/24/2016 03:27 PM, Simon Marchi wrote:
> This patch changes struct ui_out_level to be a real C++ class. No
> behavioral changes.
>
> gdb/ChangeLog:
>
> * ui-out.c (struct ui_out_level): Replace with ...
> (class ui_out_level): ... this.
> (current_level): Update.
> (push_level): Update.
> (pop_level): Update.
> (verify_field): Update.
> (ui_out_new): Update.
> ---
> gdb/ui-out.c | 65 ++++++++++++++++++++++++++++++++++++++++--------------------
> 1 file changed, 44 insertions(+), 21 deletions(-)
>
> diff --git a/gdb/ui-out.c b/gdb/ui-out.c
> index 410f40c..594338a 100644
> --- a/gdb/ui-out.c
> +++ b/gdb/ui-out.c
> @@ -90,13 +90,41 @@ class ui_out_hdr
> std::string m_header;
> };
>
> -struct ui_out_level
> +/* A level of nesting (either a list or a tuple) in a ui_out output. */
> +
> +class ui_out_level
> +{
> + public:
> +
> + ui_out_level (ui_out_type type)

explicit ?

> + : m_type (type),
> + m_field_count (0)
> {
> - /* Count each field; the first element is for non-list fields. */
> - int field_count;
> - /* The type of this level. */
> - enum ui_out_type type;
> - };
> + }
> +
> + ui_out_type type (void) const

"(void)" is not necessary in C++ (and not very idiomatic).

I saw this in several places in the series.

> + {
> + return m_type;
> + }
> +
> + int field_count (void) const
> + {
> + return m_field_count;
> + }
> +
> + void inc_field_count (void)
> + {
> + m_field_count++;
> + }

Thanks,
Pedro Alves