From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 110202 invoked by alias); 24 Nov 2016 15:28:17 -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 110104 invoked by uid 89); 24 Nov 2016 15:28:17 -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:15 +0000 X-ASG-Debug-ID: 1480001293-0c856e65d5b89ea0001-fS2M51 Received: from smtp.electronicbox.net (smtp.electronicbox.net [96.127.255.82]) by barracuda.ebox.ca with ESMTP id HDI33ukhcV5xhuOn (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 24 Nov 2016 10:28:13 -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 BF7CA440E7C; Thu, 24 Nov 2016 10:28:13 -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 16/22] Class-ify ui_out_level Date: Thu, 24 Nov 2016 15:28:00 -0000 X-ASG-Orig-Subj: [PATCH 16/22] Class-ify ui_out_level Message-Id: <20161124152710.25007-16-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: 1480001293 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: 4289 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/msg00756.txt.bz2 This patch changes struct ui_out_level to be a real C++ class. No behavioral changes. gdb/ChangeLog: * ui-out.c (struct ui_out_level): Replace with ... (class ui_out_level): ... this. (current_level): Update. (push_level): Update. (pop_level): Update. (verify_field): Update. (ui_out_new): Update. --- gdb/ui-out.c | 65 ++++++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 44 insertions(+), 21 deletions(-) diff --git a/gdb/ui-out.c b/gdb/ui-out.c index 410f40c..594338a 100644 --- a/gdb/ui-out.c +++ b/gdb/ui-out.c @@ -90,13 +90,41 @@ class ui_out_hdr std::string m_header; }; -struct ui_out_level +/* A level of nesting (either a list or a tuple) in a ui_out output. */ + +class ui_out_level +{ + public: + + ui_out_level (ui_out_type type) + : m_type (type), + m_field_count (0) { - /* Count each field; the first element is for non-list fields. */ - int field_count; - /* The type of this level. */ - enum ui_out_type type; - }; + } + + ui_out_type type (void) const + { + return m_type; + } + + int field_count (void) const + { + return m_field_count; + } + + void inc_field_count (void) + { + m_field_count++; + } + + private: + + /* The type of this level. */ + ui_out_type m_type; + + /* Count each field; the first element is for non-list fields. */ + int m_field_count; +}; /* Tables are special. Maintain a separate structure that tracks @@ -153,7 +181,7 @@ struct ui_out }; /* The current (inner most) level. */ -static struct ui_out_level * +static ui_out_level * current_level (struct ui_out *uiout) { return uiout->levels[uiout->level].get (); @@ -164,13 +192,10 @@ static int push_level (struct ui_out *uiout, enum ui_out_type type) { - std::unique_ptr current (new ui_out_level ()); - - current->field_count = 0; - current->type = type; + std::unique_ptr level (new ui_out_level (type)); + uiout->levels.push_back (std::move (level)); uiout->level++; - uiout->levels.push_back (std::move (current)); return uiout->level; } @@ -183,7 +208,7 @@ pop_level (struct ui_out *uiout, { /* We had better not underflow the buffer. */ gdb_assert (uiout->level > 0); - gdb_assert (current_level (uiout)->type == type); + gdb_assert (current_level (uiout)->type () == type); uiout->levels.pop_back (); uiout->level--; @@ -798,7 +823,7 @@ static void verify_field (struct ui_out *uiout, int *fldno, int *width, enum ui_align *align) { - struct ui_out_level *current = current_level (uiout); + ui_out_level *current = current_level (uiout); const char *text; if (uiout->table.flag) @@ -814,13 +839,13 @@ specified after table_body and inside a list.")); level is zero. */ } - current->field_count += 1; + current->inc_field_count (); if (uiout->table.body_flag && uiout->table.entry_level == uiout->level && get_next_header (uiout, fldno, width, align, &text)) { - if (*fldno != current->field_count) + if (*fldno != current->field_count ()) internal_error (__FILE__, __LINE__, _("ui-out internal error in handling headers.")); } @@ -828,7 +853,7 @@ specified after table_body and inside a list.")); { *width = 0; *align = ui_noalign; - *fldno = current->field_count; + *fldno = current->field_count (); } } @@ -875,7 +900,6 @@ ui_out_new (const struct ui_out_impl *impl, void *data, int flags) { struct ui_out *uiout = new ui_out (); - std::unique_ptr current (new ui_out_level ()); uiout->data = data; uiout->impl = impl; @@ -885,9 +909,8 @@ ui_out_new (const struct ui_out_impl *impl, void *data, uiout->level = 0; /* Create uiout->level 0, the default level. */ - current->type = ui_out_type_tuple; - current->field_count = 0; - uiout->levels.push_back (std::move (current)); + std::unique_ptr level (new ui_out_level (ui_out_type_tuple)); + uiout->levels.push_back (std::move (level)); uiout->table.headers_iterator = uiout->table.headers.end (); -- 2.10.0