From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 113586 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 113496 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:20 +0000 X-ASG-Debug-ID: 1480001298-0c856e65d5b89eb0001-fS2M51 Received: from smtp.electronicbox.net (smtp.electronicbox.net [96.127.255.82]) by barracuda.ebox.ca with ESMTP id n3j0Im1YwWbRYBKM (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 24 Nov 2016 10:28:18 -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 11222440E7C; Thu, 24 Nov 2016 10:28:18 -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 18/22] ui_out_table: Replace boolean flag with enum Date: Thu, 24 Nov 2016 15:28:00 -0000 X-ASG-Orig-Subj: [PATCH 18/22] ui_out_table: Replace boolean flag with enum Message-Id: <20161124152710.25007-18-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: 1480001298 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: 5718 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/msg00758.txt.bz2 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) : Remove field. : 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