Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Pedro Alves <palves@redhat.com>
To: simon.marchi@polymtl.ca, gdb-patches@sourceware.org
Subject: Re: [PATCH 19/22] Class-ify ui_out_impl
Date: Wed, 30 Nov 2016 13:09:00 -0000	[thread overview]
Message-ID: <b3ea837a-e685-952a-3bbe-9b3b2b508e69@redhat.com> (raw)
In-Reply-To: <1480173587-7053-19-git-send-email-simon.marchi@polymtl.ca>

On 11/26/2016 03:19 PM, simon.marchi@polymtl.ca wrote:
> From: Simon Marchi <simon.marchi@polymtl.ca>
> 
> This patch makes the ui_out_impl implementations an actual class
> hierarchy, instead of an array of function pointers.

LGTM with nits below.

> +ui_file *
> +cli_out_set_stream (struct ui_out *uiout, ui_file *stream)
> +{
> +  cli_ui_out_impl *impl = dynamic_cast<cli_ui_out_impl *> (ui_out_impl (uiout));

"dynamic_cast" is a code smell.  In this case, I think it
stems from the fact that we have separate ui_out and ui_out_impl
hierarchies.  If we had a simple hierarchy, then this function would
take a  cli_ui_out pointer as argument, or even be a
method of cli_ui_out.

Anyway, just a comment for another day.

Given the current design, this is OK.

> +
> +  gdb_assert (impl != NULL);
> +
> +  return impl->set_stream (stream);
> +}
> +
>  /* CLI interface to display tab-completion matches.  */
>  
>  /* CLI version of displayer.crlf.  */
> diff --git a/gdb/cli-out.h b/gdb/cli-out.h
> index 296b8c0..aacb8c5 100644
> --- a/gdb/cli-out.h
> +++ b/gdb/cli-out.h
> @@ -23,22 +23,58 @@
>  #include "ui-out.h"
>  #include <vector>
>  
> -/* These are exported so that they can be extended by other `ui_out'
> -   implementations, like TUI's.  */
> +class cli_ui_out_impl : public ui_out_impl_base
> +{
> +public:
>  
> -struct cli_ui_out_data
> -  {
> -    std::vector<ui_file *> streams;
> -    int suppress_output;
> -  };
> +  cli_ui_out_impl (ui_file *stream);

explicit.

> +  virtual ~cli_ui_out_impl ();
>  
> -extern const struct ui_out_impl cli_ui_out_impl;
> +  virtual void table_begin (int nbrofcols, int nr_rows,
> +				  const char *tblid) override;
> +  virtual void table_body () override;
> +  virtual void table_end () override;
> +  virtual void table_header (int width, ui_align align,
> +			     const std::string &col_name,
> +			     const std::string &col_hdr) override;
> +  /* Note: level 0 is the top-level so LEVEL is always greater than
> +     zero.  */
> +  virtual void begin (ui_out_type type, const char *id) override;
> +  virtual void end (ui_out_type type) override;
> +  virtual void field_int (int fldno, int width, ui_align align,
> +			  const char *fldname, int value) override;
> +  virtual void field_skip (int fldno, int width, ui_align align,
> +			   const char *fldname) override;
> +  virtual void field_string (int fldno, int width, ui_align align,
> +			     const char *fldname, const char *string) override;
> +  virtual void ATTRIBUTE_PRINTF(6,0) field_fmt (int fldno, int width,
> +						ui_align align,
> +						const char *fldname,
> +						const char *format,
> +						va_list args) override;
> +  virtual void spaces (int numspaces) override;
> +  virtual void text (const char *string) override;
> +  virtual void ATTRIBUTE_PRINTF(2,0)
> +    message (const char *format, va_list args) override;
> +  virtual void wrap_hint (const char *identstring) override;
> +  virtual void flush () override;
> +  virtual int redirect (struct ui_file * outstream) override;
>  
> +  ui_file *set_stream (ui_file *stream);
>  
> -extern struct ui_out *cli_out_new (struct ui_file *stream);
> +protected:
> +
> +  std::vector<ui_file *> m_streams;
> +  int m_suppress_output;
> +
> +private:
> +  void field_separator (void);

"(void)".  Probably easier to grep the whole patch set to
find such cases and handle all of them.


> +mi_ui_out_impl::table_begin (int nr_cols, int nr_rows,
> +			     const char *tblid)
>  {
> -  mi_open (uiout, tblid, ui_out_type_tuple);
> -  mi_field_int (uiout, -1, -1, ui_left, "nr_rows", nr_rows);
> -  mi_field_int (uiout, -1, -1, ui_left, "nr_cols", nr_cols);
> -  mi_open (uiout, "hdr", ui_out_type_list);
> +  open (tblid, ui_out_type_tuple);

FYI, it's due to names like "open" potentially conflicting
with gnulib replacing global namespace C functions with
#define open rpl_open
that I'm looking at switching to use gnulib's C++ namespace
support.  Luckily, looks like gnulib doesn't replace 
"open" currently, so you don't need to wait for that:

 $ grep -rn open | grep rpl_
 stdio.in.h:191:#   define fdopen rpl_fdopen
 stdio.in.h:264:#   define fopen rpl_fopen
 stdio.in.h:388:#   define freopen rpl_freopen
 stdio.in.h:820:#   define popen rpl_popen
 dirent.in.h:79:#   define opendir rpl_opendir
 dirent.in.h:198:#   define fdopendir rpl_fdopendir

>  void
> -mi_table_end (struct ui_out *uiout)
> +mi_ui_out_impl::table_end ()
>  {
> -  mi_out_data *data = (mi_out_data *) ui_out_data (uiout);
> -
> -  data->suppress_output = 0;
> -  mi_close (uiout, ui_out_type_list); /* body */
> -  mi_close (uiout, ui_out_type_tuple);
> +  m_suppress_output = 0;
> +  close (ui_out_type_list); /* body */
> +  close (ui_out_type_tuple);

However:

 $ grep -rn close | grep rpl_
 stdio.in.h:172:#   define fclose rpl_fclose
 dirent.in.h:131:#   define closedir rpl_closedir
 unistd.in.h:303:#   define close rpl_close


:-/

I'd like to post the gnulib namespace patch this week,
but I'm not sure I'll be able to.

> +  virtual void field_string (int fldno, int width, ui_align align,
> +			     const char *fldname, const char *string) override;
> +  virtual void ATTRIBUTE_PRINTF(6,0)
> +    field_fmt (int fldno, int width, ui_align align, const char *fldname,
> +	       const char *format, va_list args) override;

It's more usual to put the ATTRIBUTE_PRINTFs at the end of the
declaration.  Also, missing space before parens.  Something like:

  virtual void field_fmt (int fldno, int width, ui_align align, 
                          const char *fldname,
                          const char *format, va_list args) override
    ATTRIBUTE_PRINTF (6,0);

?

> +  virtual void spaces (int numspaces) override;
> +  virtual void text (const char *string) override;
> +  virtual void ATTRIBUTE_PRINTF(2,0) message (const char *format, va_list args)
> +    override;

Ditto.  There are other instances in the patch.  I won't point them all.

> +private:
> +
> +  void field_separator ();
> +  void open (const char *name, ui_out_type type);
> +  void close (ui_out_type type);
> +
> +  int m_suppress_field_separator;
> +  int m_suppress_output;

bool ?

> +  int m_mi_version;
> +  std::vector<ui_file *> m_streams;
> +};



> -typedef struct tui_ui_out_data tui_out_data;
> +class tui_ui_out_impl : public cli_ui_out_impl
> +{
> +public:
> +
> +  tui_ui_out_impl (ui_file *stream);

explicit.

> +
> +  void field_int (int fldno, int width, ui_align align, const char *fldname,
> +		  int value) override;
> +  void field_string (int fldno, int width, ui_align align, const char *fldname,
> +		     const char *string) override;
> +  void ATTRIBUTE_PRINTF(6,0)
> +    field_fmt (int fldno, int width, ui_align align, const char *fldname,
> +	       const char *format, va_list args) override;

attribute placement, space before parens.  

> +  void text (const char *string) override;
>  


> +  virtual int redirect (struct ui_file * outstream) = 0;
> +
> +  /* Set as not MI-like by default.  It is overridden in subclasses if
> +     necessary.  */
> +
> +  virtual int is_mi_like_p ()
> +  { return 0; }

bool ?

> +};
> +

Thanks,
Pedro Alves


  reply	other threads:[~2016-11-30 13:09 UTC|newest]

Thread overview: 71+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-24 15:24 [PATCH 00/22] Convert ui-out subsystem to C++ Simon Marchi
2016-11-24 15:24 ` [PATCH 02/22] Rename ui_out_data to mi_ui_out_data Simon Marchi
2016-11-24 15:24 ` [PATCH 08/22] Use new/delete instead of malloc/free-based functions Simon Marchi
2016-11-24 15:24 ` [PATCH 01/22] Remove unused functions and declarations Simon Marchi
2016-11-24 15:24 ` [PATCH 03/22] Remove ui_out_destroy Simon Marchi
2016-11-24 15:24 ` [PATCH 06/22] Remove verbosity from ui_out_message and friends Simon Marchi
2016-11-24 15:24 ` [PATCH 09/22] Use std::vector for ui_out::levels Simon Marchi
2016-11-24 15:24 ` [PATCH 07/22] Remove stale comments Simon Marchi
2016-11-24 18:38   ` Pedro Alves
2016-11-26 15:29     ` Simon Marchi
2016-11-24 15:27 ` [PATCH 10/22] Use std::vector for mi_ui_out_data::streams Simon Marchi
2016-11-24 18:38   ` Pedro Alves
2016-11-26 15:48     ` Simon Marchi
2016-11-24 15:28 ` [PATCH 16/22] Class-ify ui_out_level Simon Marchi
2016-11-24 18:41   ` Pedro Alves
2016-11-26 16:22     ` Simon Marchi
2016-11-30 12:07       ` Pedro Alves
2016-11-30 12:41         ` Antoine Tremblay
2016-11-30 13:27           ` Pedro Alves
2016-11-30 13:47             ` Antoine Tremblay
2016-11-30 14:17               ` Pedro Alves
2016-11-30 14:21                 ` Antoine Tremblay
2016-11-30 20:40         ` Simon Marchi
2016-11-24 15:28 ` [PATCH 15/22] Class-ify ui_out_hdr Simon Marchi
2016-11-24 15:28 ` [PATCH 12/22] Use std::string in ui_out_table Simon Marchi
2016-11-24 15:28 ` [PATCH 13/22] Replace hand-made linked list of ui_out_hdr by vector and iterator Simon Marchi
2016-11-24 18:41   ` Pedro Alves
2016-11-26 16:13     ` Simon Marchi
2016-12-01 20:22       ` Simon Marchi
2016-12-01 20:23         ` Pedro Alves
2016-11-24 15:28 ` [PATCH 17/22] Simplify ui-out level code Simon Marchi
2016-11-24 18:42   ` Pedro Alves
2016-11-26 16:39     ` Simon Marchi
2016-11-30 12:08       ` Pedro Alves
2016-11-24 15:28 ` [PATCH 11/22] Use std::vector for cli_ui_out_data::streams Simon Marchi
2016-11-24 18:41   ` Pedro Alves
2016-11-26 15:51     ` Simon Marchi
2016-11-24 15:28 ` [PATCH 14/22] Use std::string for ui_out_hdr's text fields Simon Marchi
2016-11-24 15:28 ` [PATCH 18/22] ui_out_table: Replace boolean flag with enum Simon Marchi
2016-11-24 18:42   ` Pedro Alves
2016-11-26 16:47     ` Simon Marchi
2016-11-30 12:10       ` Pedro Alves
2016-11-24 15:32 ` [PATCH 22/22] Introduce enum_flag type for ui_out flags Simon Marchi
2016-11-30 13:34   ` Pedro Alves
2016-11-30 21:32     ` Simon Marchi
2016-12-02 22:22     ` [pushed] " Simon Marchi
2016-11-24 15:36 ` [PATCH 04/22] Fix return value of uo_redirect Simon Marchi
2016-11-24 15:36 ` [PATCH 05/22] Constify wrap_here/wrap_hint code path Simon Marchi
2016-11-24 16:08 ` [PATCH 00/22] Convert ui-out subsystem to C++ Simon Marchi
2016-11-24 18:46   ` Pedro Alves
2016-11-24 19:15     ` Simon Marchi
2016-11-24 20:33       ` Simon Marchi
2016-11-24 18:47   ` Pedro Alves
2016-11-27  3:14     ` Simon Marchi
2016-12-01  2:51     ` Simon Marchi
2016-12-01 21:24       ` Simon Marchi
2016-11-24 19:11 ` [PATCH 20/22] Class-ify ui_out_table Simon Marchi
2016-11-30 12:29   ` Pedro Alves
2016-11-24 19:19 ` [PATCH 21/22] Class-ify ui_out Simon Marchi
2016-11-30 12:46   ` Pedro Alves
2016-11-30 21:47     ` Simon Marchi
2016-11-26 15:20 ` [PATCH 19/22] Class-ify ui_out_impl simon.marchi
2016-11-30 13:09   ` Pedro Alves [this message]
2016-11-30 22:38     ` Simon Marchi
2016-11-30 22:58       ` Pedro Alves
2016-12-01 19:04         ` Simon Marchi
2016-12-01 19:30           ` Pedro Alves
     [not found] ` <20161124153228.25177-20-simon.marchi@polymtl.ca>
2016-11-26 17:18   ` [PATCH 20/22] Class-ify ui_out_table Simon Marchi
2016-11-30 12:30     ` Pedro Alves
2016-11-30 21:48       ` [PATCH v2] " Simon Marchi
2016-11-30 23:01         ` Pedro Alves

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b3ea837a-e685-952a-3bbe-9b3b2b508e69@redhat.com \
    --to=palves@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=simon.marchi@polymtl.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox