From: Simon Marchi <simon.marchi@polymtl.ca>
To: gdb-patches@sourceware.org
Cc: Simon Marchi <simon.marchi@polymtl.ca>
Subject: [PATCH 18/22] ui_out_table: Replace boolean flag with enum
Date: Thu, 24 Nov 2016 15:28:00 -0000 [thread overview]
Message-ID: <20161124152710.25007-18-simon.marchi@polymtl.ca> (raw)
In-Reply-To: <20161124152428.24725-1-simon.marchi@polymtl.ca>
This patch is just a little cleanup, it replaces the body_flag field of
ui_out_table with an enum. It expresses more explicitly the
intent of the field (check that state == TABLE_STATE_HEADERS conveys
more what we want to do than checking for !body_flag).
gdb/ChangeLog:
* ui-out.c (enum ui_out_table_state): New enum.
(struct ui_out_table) <body_flag>: Remove field.
<state>: New field.
(ui_out_table_begin): Replace usages of body_flag with state.
(ui_out_table_body): Likewise.
(ui_out_table_end): Likewise.
(ui_out_table_header): Likewise.
(ui_out_begin): Likewise.
(verify_field): Likewise.
(ui_out_new): Likewise.
---
gdb/ui-out.c | 41 +++++++++++++++++++++++++----------------
1 file changed, 25 insertions(+), 16 deletions(-)
diff --git a/gdb/ui-out.c b/gdb/ui-out.c
index 25a14f7..1717491 100644
--- a/gdb/ui-out.c
+++ b/gdb/ui-out.c
@@ -126,6 +126,16 @@ class ui_out_level
int m_field_count;
};
+/* States (steps) of a table generation. */
+
+enum ui_out_table_state
+{
+ /* We are generating the table headers. */
+ TABLE_STATE_HEADERS,
+
+ /* We are generating the table body. */
+ TABLE_STATE_BODY,
+};
/* Tables are special. Maintain a separate structure that tracks
their state. At present an output can only contain a single table
@@ -136,9 +146,7 @@ struct ui_out_table
/* If on, a table is being generated. */
int flag;
- /* If on, the body of a table is being generated. If off, the table
- header is being generated. */
- int body_flag;
+ ui_out_table_state state;
/* The level at which each entry of the table is to be found. A row
(a tuple) is made up of entries. Consequently ENTRY_LEVEL is one
@@ -271,7 +279,7 @@ ui_out_table_begin (struct ui_out *uiout, int nbrofcols,
previous table_end."));
uiout->table.flag = 1;
- uiout->table.body_flag = 0;
+ uiout->table.state = ui_out_table_state::TABLE_STATE_HEADERS;
uiout->table.entry_level = uiout->level () + 1;
uiout->table.columns = nbrofcols;
uiout->table.id = tblid;
@@ -288,16 +296,18 @@ ui_out_table_body (struct ui_out *uiout)
internal_error (__FILE__, __LINE__,
_("table_body outside a table is not valid; it must be \
after a table_begin and before a table_end."));
- if (uiout->table.body_flag)
+
+ if (uiout->table.state == TABLE_STATE_BODY)
internal_error (__FILE__, __LINE__,
_("extra table_body call not allowed; there must be \
only one table_body after a table_begin and before a table_end."));
+
if (uiout->table.headers.size () != uiout->table.columns)
internal_error (__FILE__, __LINE__,
_("number of headers differ from number of table \
columns."));
- uiout->table.body_flag = 1;
+ uiout->table.state = TABLE_STATE_BODY;
uo_table_body (uiout);
}
@@ -310,7 +320,7 @@ ui_out_table_end (struct ui_out *uiout)
_("misplaced table_end or missing table_begin."));
uiout->table.entry_level = 0;
- uiout->table.body_flag = 0;
+ uiout->table.state = TABLE_STATE_HEADERS;
uiout->table.flag = 0;
uo_table_end (uiout);
@@ -321,7 +331,7 @@ void
ui_out_table_header (struct ui_out *uiout, int width, enum ui_align alignment,
const std::string &col_name, const std::string &col_hdr)
{
- if (!uiout->table.flag || uiout->table.body_flag)
+ if (!uiout->table.flag || uiout->table.state != TABLE_STATE_HEADERS)
internal_error (__FILE__, __LINE__,
_("table header must be specified after table_begin \
and before table_body."));
@@ -352,7 +362,7 @@ ui_out_begin (struct ui_out *uiout,
enum ui_out_type type,
const char *id)
{
- if (uiout->table.flag && !uiout->table.body_flag)
+ if (uiout->table.flag && uiout->table.state != TABLE_STATE_BODY)
internal_error (__FILE__, __LINE__,
_("table header or table_body expected; lists must be \
specified after table_body."));
@@ -376,7 +386,7 @@ specified after table_body."));
/* If the push puts us at the same level as a table row entry, we've
got a new table row. Put the header pointer back to the start. */
- if (uiout->table.body_flag
+ if (uiout->table.state == TABLE_STATE_BODY
&& uiout->table.entry_level == uiout->level ())
uiout->table.headers_iterator = uiout->table.headers.begin ();
@@ -817,11 +827,10 @@ verify_field (struct ui_out *uiout, int *fldno, int *width,
ui_out_level *current = current_level (uiout);
const char *text;
- if (uiout->table.flag)
+ if (uiout->table.flag && uiout->table.state != TABLE_STATE_BODY)
{
- if (!uiout->table.body_flag)
- internal_error (__FILE__, __LINE__,
- _("table_body missing; table fields must be \
+ internal_error (__FILE__, __LINE__,
+ _("table_body missing; table fields must be \
specified after table_body and inside a list."));
/* NOTE: cagney/2001-12-08: There was a check here to ensure
that this code was only executed when uiout->level () was
@@ -832,7 +841,7 @@ specified after table_body and inside a list."));
current->inc_field_count ();
- if (uiout->table.body_flag
+ if (uiout->table.state == TABLE_STATE_BODY
&& uiout->table.entry_level == uiout->level ()
&& get_next_header (uiout, fldno, width, align, &text))
{
@@ -896,7 +905,7 @@ ui_out_new (const struct ui_out_impl *impl, void *data,
uiout->impl = impl;
uiout->flags = flags;
uiout->table.flag = 0;
- uiout->table.body_flag = 0;
+ uiout->table.state = TABLE_STATE_HEADERS;
/* Create uiout->level () 0, the default level. */
push_level (uiout, ui_out_type_tuple);
--
2.10.0
next prev parent reply other threads:[~2016-11-24 15:28 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 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: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 03/22] Remove ui_out_destroy Simon Marchi
2016-11-24 15:24 ` [PATCH 01/22] Remove unused functions and declarations 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 02/22] Rename ui_out_data to mi_ui_out_data 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 ` Simon Marchi [this message]
2016-11-24 18:42 ` [PATCH 18/22] ui_out_table: Replace boolean flag with enum Pedro Alves
2016-11-26 16:47 ` Simon Marchi
2016-11-30 12:10 ` Pedro Alves
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 12/22] Use std::string in ui_out_table Simon Marchi
2016-11-24 15:28 ` [PATCH 15/22] Class-ify ui_out_hdr 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: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 05/22] Constify wrap_here/wrap_hint code path Simon Marchi
2016-11-24 15:36 ` [PATCH 04/22] Fix return value of uo_redirect 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
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=20161124152710.25007-18-simon.marchi@polymtl.ca \
--to=simon.marchi@polymtl.ca \
--cc=gdb-patches@sourceware.org \
/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