From: Simon Marchi <simon.marchi@polymtl.ca>
To: gdb-patches@sourceware.org
Cc: Simon Marchi <simon.marchi@polymtl.ca>
Subject: [PATCH 17/22] Simplify ui-out level code
Date: Thu, 24 Nov 2016 15:28:00 -0000 [thread overview]
Message-ID: <20161124152710.25007-17-simon.marchi@polymtl.ca> (raw)
In-Reply-To: <20161124152428.24725-1-simon.marchi@polymtl.ca>
Now that we use a vector to store the levels, we don't have to keep a
separate level field in ui_out to keep track of the current level. We
can efficiently derive it from the vector size. That causes a little
change in the meaning of the level, as in they are now 1-based instead
of 0-based (the initial level has the "id" 1 now), but it shouldn't
change anything in the behavior.
Additionally, push_level and pop_level don't really need to return the
new level, making them return void simplifies the code a bit.
Finally, the ui_out_begin/ui_out_end callbacks in the ui_out_impl
interface don't need to be passed the level, it's never actually used.
gdb/ChangeLog:
* ui-out.h (ui_out_begin_ftype): Remove level parameter.
(ui_out_end_ftype): Likewise.
* ui-out.c (struct ui_out) <level>: Replace field with a method
that dynamically computes the result.
(current_level): Get vector's back item instead of using
uiout->level.
(push_level): Make return type void.
(pop_level): Make return type void and update access to
ui_out::level.
(uo_begin): Remove level parameter.
(uo_end): Likewise.
(ui_out_table_begin): Update access to uiout::level.
(ui_out_begin): Don't read return value from push_level, call
uiout->level() instead, update call to uo_begin.
(ui_out_end): Don't read return value from pop_level, update
call to uo_end.
(verify_field): Update access to uiout->level.
(ui_out_new): Don't initialize ui_out::level, call push_level
to push the initial level instead of doing it by hand.
* cli-out.c (cli_begin): Remove level parameter.
(cli_end): Likewise.
* mi/mi-out.c (mi_begin): Likewise.
(mi_end): Likewise.
---
gdb/cli-out.c | 4 +---
gdb/mi/mi-out.c | 9 ++++-----
gdb/ui-out.c | 59 +++++++++++++++++++++++----------------------------------
gdb/ui-out.h | 8 +++-----
4 files changed, 32 insertions(+), 48 deletions(-)
diff --git a/gdb/cli-out.c b/gdb/cli-out.c
index 9ba1d17..e042926 100644
--- a/gdb/cli-out.c
+++ b/gdb/cli-out.c
@@ -112,7 +112,6 @@ cli_table_header (struct ui_out *uiout, int width, enum ui_align alignment,
static void
cli_begin (struct ui_out *uiout,
enum ui_out_type type,
- int level,
const char *id)
{
cli_out_data *data = (cli_out_data *) ui_out_data (uiout);
@@ -125,8 +124,7 @@ cli_begin (struct ui_out *uiout,
static void
cli_end (struct ui_out *uiout,
- enum ui_out_type type,
- int level)
+ enum ui_out_type type)
{
cli_out_data *data = (cli_out_data *) ui_out_data (uiout);
diff --git a/gdb/mi/mi-out.c b/gdb/mi/mi-out.c
index 72e84b2..b7cd433 100644
--- a/gdb/mi/mi-out.c
+++ b/gdb/mi/mi-out.c
@@ -46,8 +46,8 @@ static void mi_table_header (struct ui_out *uiout, int width,
const std::string &col_name,
const std::string &col_hdr);
static void mi_begin (struct ui_out *uiout, enum ui_out_type type,
- int level, const char *id);
-static void mi_end (struct ui_out *uiout, enum ui_out_type type, int level);
+ const char *id);
+static void mi_end (struct ui_out *uiout, enum ui_out_type type);
static void mi_field_int (struct ui_out *uiout, int fldno, int width,
enum ui_align alig, const char *fldname, int value);
static void mi_field_skip (struct ui_out *uiout, int fldno, int width,
@@ -160,8 +160,7 @@ mi_table_header (struct ui_out *uiout, int width, enum ui_align alignment,
/* Mark beginning of a list. */
void
-mi_begin (struct ui_out *uiout, enum ui_out_type type, int level,
- const char *id)
+mi_begin (struct ui_out *uiout, enum ui_out_type type, const char *id)
{
mi_out_data *data = (mi_out_data *) ui_out_data (uiout);
@@ -174,7 +173,7 @@ mi_begin (struct ui_out *uiout, enum ui_out_type type, int level,
/* Mark end of a list. */
void
-mi_end (struct ui_out *uiout, enum ui_out_type type, int level)
+mi_end (struct ui_out *uiout, enum ui_out_type type)
{
mi_out_data *data = (mi_out_data *) ui_out_data (uiout);
diff --git a/gdb/ui-out.c b/gdb/ui-out.c
index 594338a..25a14f7 100644
--- a/gdb/ui-out.c
+++ b/gdb/ui-out.c
@@ -170,12 +170,14 @@ struct ui_out
const struct ui_out_impl *impl;
void *data;
- /* Current level. */
- int level;
-
/* Vector to store and track the ui-out levels. */
std::vector<std::unique_ptr<ui_out_level>> levels;
+ int level (void) const
+ {
+ return this->levels.size ();
+ }
+
/* A table, if any. At present only a single table is supported. */
struct ui_out_table table;
};
@@ -184,36 +186,30 @@ struct ui_out
static ui_out_level *
current_level (struct ui_out *uiout)
{
- return uiout->levels[uiout->level].get ();
+ return uiout->levels.back ().get ();
}
/* Create a new level, of TYPE. Return the new level's index. */
-static int
+static void
push_level (struct ui_out *uiout,
enum ui_out_type type)
{
std::unique_ptr<ui_out_level> level (new ui_out_level (type));
uiout->levels.push_back (std::move (level));
- uiout->level++;
-
- return uiout->level;
}
/* Discard the current level, return the discarded level's index.
TYPE is the type of the level being discarded. */
-static int
+static void
pop_level (struct ui_out *uiout,
enum ui_out_type type)
{
/* We had better not underflow the buffer. */
- gdb_assert (uiout->level > 0);
+ gdb_assert (uiout->level () > 0);
gdb_assert (current_level (uiout)->type () == type);
uiout->levels.pop_back ();
- uiout->level--;
-
- return uiout->level + 1;
}
/* These are the interfaces to implementation functions. */
@@ -228,10 +224,9 @@ static void uo_table_header (struct ui_out *uiout, int width,
const std::string &col_hdr);
static void uo_begin (struct ui_out *uiout,
enum ui_out_type type,
- int level, const char *id);
+ const char *id);
static void uo_end (struct ui_out *uiout,
- enum ui_out_type type,
- int level);
+ enum ui_out_type type);
static void uo_field_int (struct ui_out *uiout, int fldno, int width,
enum ui_align align, const char *fldname, int value);
static void uo_field_skip (struct ui_out *uiout, int fldno, int width,
@@ -277,7 +272,7 @@ previous table_end."));
uiout->table.flag = 1;
uiout->table.body_flag = 0;
- uiout->table.entry_level = uiout->level + 1;
+ uiout->table.entry_level = uiout->level () + 1;
uiout->table.columns = nbrofcols;
uiout->table.id = tblid;
@@ -357,8 +352,6 @@ ui_out_begin (struct ui_out *uiout,
enum ui_out_type type,
const char *id)
{
- int new_level;
-
if (uiout->table.flag && !uiout->table.body_flag)
internal_error (__FILE__, __LINE__,
_("table header or table_body expected; lists must be \
@@ -379,24 +372,24 @@ specified after table_body."));
verify_field (uiout, &fldno, &width, &align);
}
- new_level = push_level (uiout, type);
+ push_level (uiout, type);
/* 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
- && uiout->table.entry_level == new_level)
+ && uiout->table.entry_level == uiout->level ())
uiout->table.headers_iterator = uiout->table.headers.begin ();
- uo_begin (uiout, type, new_level, id);
+ uo_begin (uiout, type, id);
}
void
ui_out_end (struct ui_out *uiout,
enum ui_out_type type)
{
- int old_level = pop_level (uiout, type);
+ pop_level (uiout, type);
- uo_end (uiout, type, old_level);
+ uo_end (uiout, type);
}
struct ui_out_end_cleanup_data
@@ -652,22 +645,20 @@ clear_table (struct ui_out *uiout)
void
uo_begin (struct ui_out *uiout,
enum ui_out_type type,
- int level,
const char *id)
{
if (uiout->impl->begin == NULL)
return;
- uiout->impl->begin (uiout, type, level, id);
+ uiout->impl->begin (uiout, type, id);
}
void
uo_end (struct ui_out *uiout,
- enum ui_out_type type,
- int level)
+ enum ui_out_type type)
{
if (uiout->impl->end == NULL)
return;
- uiout->impl->end (uiout, type, level);
+ uiout->impl->end (uiout, type);
}
void
@@ -833,7 +824,7 @@ verify_field (struct ui_out *uiout, int *fldno, int *width,
_("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
+ that this code was only executed when uiout->level () was
greater than zero. That no longer applies - this code is run
before each table row tuple is started and at that point the
level is zero. */
@@ -842,7 +833,7 @@ specified after table_body and inside a list."));
current->inc_field_count ();
if (uiout->table.body_flag
- && uiout->table.entry_level == uiout->level
+ && uiout->table.entry_level == uiout->level ()
&& get_next_header (uiout, fldno, width, align, &text))
{
if (*fldno != current->field_count ())
@@ -906,11 +897,9 @@ ui_out_new (const struct ui_out_impl *impl, void *data,
uiout->flags = flags;
uiout->table.flag = 0;
uiout->table.body_flag = 0;
- uiout->level = 0;
- /* Create uiout->level 0, the default level. */
- std::unique_ptr<ui_out_level> level (new ui_out_level (ui_out_type_tuple));
- uiout->levels.push_back (std::move (level));
+ /* Create uiout->level () 0, the default level. */
+ push_level (uiout, ui_out_type_tuple);
uiout->table.headers_iterator = uiout->table.headers.end ();
diff --git a/gdb/ui-out.h b/gdb/ui-out.h
index ed2911d..06c05e2 100644
--- a/gdb/ui-out.h
+++ b/gdb/ui-out.h
@@ -157,14 +157,12 @@ typedef void (table_header_ftype) (struct ui_out * uiout, int width,
enum ui_align align,
const std::string &col_name,
const std::string &col_hdr);
-/* Note: level 0 is the top-level so LEVEL is always greater than
- zero. */
+
typedef void (ui_out_begin_ftype) (struct ui_out *uiout,
enum ui_out_type type,
- int level, const char *id);
+ const char *id);
typedef void (ui_out_end_ftype) (struct ui_out *uiout,
- enum ui_out_type type,
- int level);
+ enum ui_out_type type);
typedef void (field_int_ftype) (struct ui_out * uiout, int fldno, int width,
enum ui_align align,
const char *fldname, int value);
--
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 01/22] Remove unused functions and declarations 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 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 03/22] Remove ui_out_destroy 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 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 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 ` Simon Marchi [this message]
2016-11-24 18:42 ` [PATCH 17/22] Simplify ui-out level code 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 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:28 ` [PATCH 14/22] Use std::string for ui_out_hdr's text fields 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-17-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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).