+2016-12-01 Simon Marchi <simon.marchi@polymtl.ca>
+
+ * 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.
+
2016-12-01 Simon Marchi <simon.marchi@polymtl.ca>
* ui-out.c (struct ui_out_level): Replace with ...
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,
/* 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);
/* 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);
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 () const
+ {
+ return this->levels.size ();
+ }
+
/* A table, if any. At present only a single table is supported. */
struct ui_out_table table;
};
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
+/* Create a new level, of TYPE. */
+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
+/* Discard the current level. TYPE is the type of the level being
+ discarded. */
+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. */
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,
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;
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 \
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
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
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
- 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. */
}
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 ())
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 the ui-out level #1, the default level. */
+ push_level (uiout, ui_out_type_tuple);
uiout->table.headers_iterator = uiout->table.headers.end ();