From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 113636 invoked by alias); 24 Nov 2016 15:28:28 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 113508 invoked by uid 89); 24 Nov 2016 15:28:28 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=1.4 required=5.0 tests=AWL,BAYES_50,SPF_SOFTFAIL autolearn=no version=3.3.2 spammy=Hx-spam-relays-external:sk:cable-1, H*RU:sk:cable-1, H*r:sk:cable-1, uiout X-HELO: barracuda.ebox.ca Received: from barracuda.ebox.ca (HELO barracuda.ebox.ca) (96.127.255.19) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 24 Nov 2016 15:28:18 +0000 X-ASG-Debug-ID: 1480001296-0c856e65d4b89790001-fS2M51 Received: from smtp.electronicbox.net (smtp.electronicbox.net [96.127.255.82]) by barracuda.ebox.ca with ESMTP id DDmG1xg7AKLGk4xH (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 24 Nov 2016 10:28:16 -0500 (EST) X-Barracuda-Envelope-From: simon.marchi@polymtl.ca X-Barracuda-RBL-Trusted-Forwarder: 96.127.255.82 Received: from simark.lan (cable-11.246.173-162.electronicbox.net [173.246.11.162]) by smtp.electronicbox.net (Postfix) with ESMTP id 0FBE9440E7C; Thu, 24 Nov 2016 10:28:16 -0500 (EST) From: Simon Marchi X-Barracuda-Effective-Source-IP: cable-11.246.173-162.electronicbox.net[173.246.11.162] X-Barracuda-Apparent-Source-IP: 173.246.11.162 X-Barracuda-RBL-IP: 173.246.11.162 To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH 17/22] Simplify ui-out level code Date: Thu, 24 Nov 2016 15:28:00 -0000 X-ASG-Orig-Subj: [PATCH 17/22] Simplify ui-out level code Message-Id: <20161124152710.25007-17-simon.marchi@polymtl.ca> In-Reply-To: <20161124152428.24725-1-simon.marchi@polymtl.ca> References: <20161124152428.24725-1-simon.marchi@polymtl.ca> X-Barracuda-Connect: smtp.electronicbox.net[96.127.255.82] X-Barracuda-Start-Time: 1480001296 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://96.127.255.19:443/cgi-mod/mark.cgi X-Barracuda-Scan-Msg-Size: 10601 X-Barracuda-BRTS-Status: 1 X-Barracuda-Spam-Score: 0.00 X-Barracuda-Spam-Status: No, SCORE=0.00 using global scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=8.0 tests=BSF_SC0_MISMATCH_TO X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.34709 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- 0.00 BSF_SC0_MISMATCH_TO Envelope rcpt doesn't match header X-IsSubscribed: yes X-SW-Source: 2016-11/txt/msg00757.txt.bz2 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) : 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> 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 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 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