From patchwork Mon Nov 6 19:49:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 162155 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:8f47:0:b0:403:3b70:6f57 with SMTP id j7csp2890916vqu; Mon, 6 Nov 2023 11:51:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IElDoJ8VBg4TegN0bZ75fHPdD39c61IK0bqskH18o8szYp/oFks9LPtK9oOw0RFzKkGsnLA X-Received: by 2002:a05:6902:1083:b0:da0:5370:fdce with SMTP id v3-20020a056902108300b00da05370fdcemr33921396ybu.19.1699300267679; Mon, 06 Nov 2023 11:51:07 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1699300267; cv=pass; d=google.com; s=arc-20160816; b=wH20EuxHHDWS2WYGI2uiuLgiD9iBf3C21Nt1E/aoect2EJiewEEKePPogCPliY7ovE 8L+OJHf7+yWUVSP1uccgydT+ZotHDp+OXuN/5gXPbxDakwmtjh8qmrgQxlSw9yyK3Nb7 mQWSs8k9720hOmQ0trGEdgVQgbUR3d08mMiiW/tdUaBBF5WL4iz8MEmO7r6W0T1FuFpq xb+156bDKXu3ENzuX1VxZ9j33QXDsrny2bSLKDA4oxSwvK84sLTgWMXS/rikh4x+rNPe mCBe3tiAh5/VmTXzBU1ACR6Uo2yMNwwMQYLMMZPSYkLaH2m2pXa8/9I3vHjeQKlxWpbC BNNA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=0jD7+9cphHRU6LSsQr5m3bRGGkCNogXktpe6trq0AuA=; fh=NXemEfxTRbZtBxUkxR2ehQUaYlcDfMdzPkO8MChVQE4=; b=q5vDci+Idf/4BfDNGSbW7ZLdN4fnt8Rvlbpno847zT3TnclC/7WL+dWFboWuOKMtjK P0K4mrAIB0VB3a7bq09FF0T42sfPtvil8d/jwY/J/CHUWURY/mS7cW53I76aT/bf6Qr0 6fpuHK3I7dPNL6SaHyxi2mSQC/rIuGF5uqU9Gz7qj/wvoQjgagYXmXdCyG6Zk7Za/duT 9N88cGWTn52I9lgbP7rr58r6dY6c29kP+eTFjru4YXrjUTcHF/fvdtbRr3bhLysbSCU5 oiwoCbZ8wj+vkx25jfn840oEWE9Q8gQzKVwaHGmkrFTyLZW0517deSNexRQ2GXoQq0JG NUSQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=JoC8OD2D; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id a16-20020a0ce910000000b0065b23aea95asi6177840qvo.11.2023.11.06.11.51.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 11:51:07 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=JoC8OD2D; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6EC003856943 for ; Mon, 6 Nov 2023 19:51:07 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 697FB3857713 for ; Mon, 6 Nov 2023 19:50:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 697FB3857713 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 697FB3857713 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699300218; cv=none; b=hHQfseGaWbaAEaLLlg0CaNHnNoSO15GNSNu9E5iSuCb/NqZbl3HVMqNKIwraNqJmgEhH9AqhOPOADaOqLwGO7v2iJavTWCHUZV9Z4NpkI3l05/oin4QWhRskQv59bYKgewj+RRKzbQKvDtor126qTm4fHbNhtvciA0vHXghxGxM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699300218; c=relaxed/simple; bh=LPOcase1lZlhowKcDqg8CucOMCTRXRs5bS6E95KK91E=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=wP8VqdDAbwsKnD2syAXhhCDhi39I+l4aSS60/uXo+O2ldGlTb3f8+tDIAOkMq1u8705sOT9UdxuCsGMp1MrVVSX6U1t3iOPhkWfhwaZko7FgCqckmKDyxQ69F/8/PWz5ydjlGM+PTzwatZbIZzCfS5hd/VaIjtNcjnciQ3SF8YU= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1699300215; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0jD7+9cphHRU6LSsQr5m3bRGGkCNogXktpe6trq0AuA=; b=JoC8OD2DcaQgRB0T/5d+15gc0OMqAMFSu5oIM3w+rYglwVIl77nBDcd/QgFBF7vXDlkA+G VRkSBJb+XPEC9UTuOzQDCEcCk4uUgP87NVw/Lr74vA9fsdaXZMXA4cJ+PlcGNRLm3bN63e TuF/Afw4Q9kNNK6+nhIdVaKN863diA0= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-669-HqVf0fU-Mo6jUlO7G7aitA-1; Mon, 06 Nov 2023 14:49:39 -0500 X-MC-Unique: HqVf0fU-Mo6jUlO7G7aitA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BF13381B163 for ; Mon, 6 Nov 2023 19:49:38 +0000 (UTC) Received: from t14s.localdomain.com (unknown [10.22.8.62]) by smtp.corp.redhat.com (Postfix) with ESMTP id 920E325C0; Mon, 6 Nov 2023 19:49:38 +0000 (UTC) From: David Malcolm To: gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [pushed 4/4] diagnostics: split out struct diagnostic_source_printing_options Date: Mon, 6 Nov 2023 14:49:35 -0500 Message-Id: <20231106194935.2693735-4-dmalcolm@redhat.com> In-Reply-To: <20231106194935.2693735-1-dmalcolm@redhat.com> References: <20231106194935.2693735-1-dmalcolm@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781845477714263120 X-GMAIL-MSGID: 1781845477714263120 This patch removes almost all use of diagnostic_context from the source-printing code. No functional change intended. Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu. Pushed to trunk as r14-5169-g54da47f9459890. gcc/ChangeLog: * diagnostic-show-locus.cc (class colorizer): Take just a pretty_printer rather than a diagnostic_context. (layout::layout): Make context param a const reference, and pretty_printer param non-optional. (layout::m_context): Drop field. (layout::m_options): New field. (layout::m_colorize_source_p): Drop field. (layout::m_show_labels_p): Drop field. (layout::m_show_line_numbers_p): Drop field. (layout::print_gap_in_line_numbering): Use m_options. (layout::calculate_line_spans): Likewise. (layout::calculate_linenum_width): Likewise. (layout::calculate_x_offset_display): Likewise. (layout::print_source_line): Likewise. (layout::start_annotation_line): Likewise. (layout::print_annotation_line): Likewise. (layout::print_line): Likewise. (gcc_rich_location::add_location_if_nearby): Update for changes to layout ctor. (diagnostic_show_locus): Likewise. (selftest::test_offset_impl): Likewise. (selftest::test_layout_x_offset_display_utf8): Likewise. (selftest::test_layout_x_offset_display_tab): Likewise. (selftest::test_tab_expansion): Likewise. * diagnostic.h (diagnostic_context::m_source_printing): Move declaration of struct outside diagnostic_context as... (struct diagnostic_source_printing_options)... this. --- gcc/diagnostic-show-locus.cc | 94 +++++++++++++++++------------------- gcc/diagnostic.h | 88 ++++++++++++++++----------------- 2 files changed, 88 insertions(+), 94 deletions(-) diff --git a/gcc/diagnostic-show-locus.cc b/gcc/diagnostic-show-locus.cc index d7a471426b9..43523572fe5 100644 --- a/gcc/diagnostic-show-locus.cc +++ b/gcc/diagnostic-show-locus.cc @@ -83,7 +83,7 @@ struct point_state class colorizer { public: - colorizer (diagnostic_context *context, + colorizer (pretty_printer *pp, diagnostic_t diagnostic_kind); ~colorizer (); @@ -113,7 +113,7 @@ class colorizer static const int STATE_FIXIT_INSERT = -2; static const int STATE_FIXIT_DELETE = -3; - diagnostic_context *m_context; + pretty_printer *m_pp; diagnostic_t m_diagnostic_kind; int m_current_state; const char *m_range1; @@ -365,10 +365,10 @@ struct char_display_policy : public cpp_char_column_policy class layout { public: - layout (diagnostic_context *context, + layout (const diagnostic_context &context, rich_location *richloc, diagnostic_t diagnostic_kind, - pretty_printer *pp = nullptr); + pretty_printer *pp); bool maybe_add_location_range (const location_range *loc_range, unsigned original_idx, @@ -428,15 +428,12 @@ class layout move_to_column (int *column, int dest_column, bool add_left_margin); private: - diagnostic_context *m_context; + const diagnostic_source_printing_options &m_options; pretty_printer *m_pp; char_display_policy m_policy; location_t m_primary_loc; exploc_with_display_col m_exploc; colorizer m_colorizer; - bool m_colorize_source_p; - bool m_show_labels_p; - bool m_show_line_numbers_p; bool m_diagnostic_path_p; auto_vec m_layout_ranges; auto_vec m_fixit_hints; @@ -451,9 +448,9 @@ class layout /* The constructor for "colorizer". Lookup and store color codes for the different kinds of things we might need to print. */ -colorizer::colorizer (diagnostic_context *context, +colorizer::colorizer (pretty_printer *pp, diagnostic_t diagnostic_kind) : - m_context (context), + m_pp (pp), m_diagnostic_kind (diagnostic_kind), m_current_state (STATE_NORMAL_TEXT) { @@ -461,7 +458,7 @@ colorizer::colorizer (diagnostic_context *context, m_range2 = get_color_by_name ("range2"); m_fixit_insert = get_color_by_name ("fixit-insert"); m_fixit_delete = get_color_by_name ("fixit-delete"); - m_stop_color = colorize_stop (pp_show_color (context->printer)); + m_stop_color = colorize_stop (pp_show_color (m_pp)); } /* The destructor for "colorize". If colorization is on, print a code to @@ -497,35 +494,35 @@ colorizer::begin_state (int state) break; case STATE_FIXIT_INSERT: - pp_string (m_context->printer, m_fixit_insert); + pp_string (m_pp, m_fixit_insert); break; case STATE_FIXIT_DELETE: - pp_string (m_context->printer, m_fixit_delete); + pp_string (m_pp, m_fixit_delete); break; case 0: /* Make range 0 be the same color as the "kind" text (error vs warning vs note). */ pp_string - (m_context->printer, - colorize_start (pp_show_color (m_context->printer), + (m_pp, + colorize_start (pp_show_color (m_pp), diagnostic_get_color_for_kind (m_diagnostic_kind))); break; case 1: - pp_string (m_context->printer, m_range1); + pp_string (m_pp, m_range1); break; case 2: - pp_string (m_context->printer, m_range2); + pp_string (m_pp, m_range2); break; default: /* For ranges beyond 2, alternate between color 1 and color 2. */ { gcc_assert (state > 2); - pp_string (m_context->printer, + pp_string (m_pp, state % 2 ? m_range1 : m_range2); } break; @@ -538,7 +535,7 @@ void colorizer::finish_state (int state) { if (state != STATE_NORMAL_TEXT) - pp_string (m_context->printer, m_stop_color); + pp_string (m_pp, m_stop_color); } /* Get the color code for NAME (or the empty string if @@ -547,7 +544,7 @@ colorizer::finish_state (int state) const char * colorizer::get_color_by_name (const char *name) { - return colorize_start (pp_show_color (m_context->printer), name); + return colorize_start (pp_show_color (m_pp), name); } /* Implementation of class layout_range. */ @@ -1182,20 +1179,17 @@ make_policy (const diagnostic_context &dc, Determine m_x_offset_display, to ensure that the primary caret will fit within the max_width provided by the diagnostic_context. */ -layout::layout (diagnostic_context * context, +layout::layout (const diagnostic_context &context, rich_location *richloc, diagnostic_t diagnostic_kind, pretty_printer *pp) -: m_context (context), - m_pp (pp ? pp : context->printer), - m_policy (make_policy (*context, *richloc)), +: m_options (context.m_source_printing), + m_pp (pp ? pp : context.printer), + m_policy (make_policy (context, *richloc)), m_primary_loc (richloc->get_range (0)->m_loc), m_exploc (richloc->get_expanded_location (0), m_policy, LOCATION_ASPECT_CARET), - m_colorizer (context, diagnostic_kind), - m_colorize_source_p (context->m_source_printing.colorize_source_p), - m_show_labels_p (context->m_source_printing.show_labels_p), - m_show_line_numbers_p (context->m_source_printing.show_line_numbers_p), + m_colorizer (m_pp, diagnostic_kind), m_diagnostic_path_p (diagnostic_kind == DK_DIAGNOSTIC_PATH), m_layout_ranges (richloc->get_num_locations ()), m_fixit_hints (richloc->get_num_fixit_hints ()), @@ -1229,8 +1223,8 @@ layout::layout (diagnostic_context * context, calculate_linenum_width (); calculate_x_offset_display (); - if (context->m_source_printing.show_ruler_p) - show_ruler (m_x_offset_display + m_context->m_source_printing.max_width); + if (m_options.show_ruler_p) + show_ruler (m_x_offset_display + m_options.max_width); } @@ -1363,7 +1357,7 @@ layout::will_show_line_p (linenum_type row) const void layout::print_gap_in_line_numbering () { - gcc_assert (m_show_line_numbers_p); + gcc_assert (m_options.show_line_numbers_p); pp_emit_prefix (m_pp); @@ -1546,7 +1540,7 @@ layout::calculate_line_spans () line_span *current = &m_line_spans[m_line_spans.length () - 1]; const line_span *next = &tmp_spans[i]; gcc_assert (next->m_first_line >= current->m_first_line); - const int merger_distance = m_show_line_numbers_p ? 1 : 0; + const int merger_distance = m_options.show_line_numbers_p ? 1 : 0; if ((linenum_arith_t)next->m_first_line <= (linenum_arith_t)current->m_last_line + 1 + merger_distance) { @@ -1595,8 +1589,7 @@ layout::calculate_linenum_width () m_linenum_width = MAX (m_linenum_width, 3); /* If there's a minimum margin width, apply it (subtracting 1 for the space after the line number. */ - m_linenum_width = MAX (m_linenum_width, - m_context->m_source_printing.min_margin_width - 1); + m_linenum_width = MAX (m_linenum_width, m_options.min_margin_width - 1); } /* Calculate m_x_offset_display, which improves readability in case the source @@ -1610,7 +1603,7 @@ layout::calculate_x_offset_display () { m_x_offset_display = 0; - const int max_width = m_context->m_source_printing.max_width; + const int max_width = m_options.max_width; if (!max_width) { /* Nothing to do, the width is not capped. */ @@ -1644,7 +1637,7 @@ layout::calculate_x_offset_display () with a space. */ const int source_display_cols = eol_display_column; int left_margin_size = 1; - if (m_show_line_numbers_p) + if (m_options.show_line_numbers_p) left_margin_size = m_linenum_width + 3; caret_display_column += left_margin_size; eol_display_column += left_margin_size; @@ -1691,7 +1684,7 @@ layout::print_source_line (linenum_type row, const char *line, int line_bytes) m_colorizer.set_normal_text (); pp_emit_prefix (m_pp); - if (m_show_line_numbers_p) + if (m_options.show_line_numbers_p) { int width = num_digits (row); for (int i = 0; i < m_linenum_width - width; i++) @@ -1737,7 +1730,7 @@ layout::print_source_line (linenum_type row, const char *line, int line_bytes) For frontends that only generate carets, we don't colorize the characters above them, since this would look strange (e.g. colorizing just the first character in a token). */ - if (m_colorize_source_p) + if (m_options.colorize_source_p) { bool in_range_p; point_state state; @@ -1809,7 +1802,7 @@ void layout::start_annotation_line (char margin_char) const { pp_emit_prefix (m_pp); - if (m_show_line_numbers_p) + if (m_options.show_line_numbers_p) { /* Print the margin. If MARGIN_CHAR != ' ', then print up to 3 of it, right-aligned, padded with spaces. */ @@ -1852,8 +1845,7 @@ layout::print_annotation_line (linenum_type row, const line_bounds lbounds) /* Draw the caret. */ char caret_char; if (state.range_idx < rich_location::STATICALLY_ALLOCATED_RANGES) - caret_char - = m_context->m_source_printing.caret_chars[state.range_idx]; + caret_char = m_options.caret_chars[state.range_idx]; else caret_char = '^'; pp_character (m_pp, caret_char); @@ -2796,7 +2788,7 @@ layout::print_line (linenum_type row) = print_source_line (row, line.get_buffer (), line.length ()); if (should_print_annotation_line_p (row)) print_annotation_line (row, lbounds); - if (m_show_labels_p) + if (m_options.show_labels_p) print_any_labels (row); print_trailing_fixits (row); } @@ -2816,7 +2808,7 @@ gcc_rich_location::add_location_if_nearby (location_t loc, /* Use the layout location-handling logic to sanitize LOC, filtering it to the current line spans within a temporary layout instance. */ - layout layout (global_dc, this, DK_ERROR); + layout layout (*global_dc, this, DK_ERROR, nullptr); location_range loc_range; loc_range.m_loc = loc; loc_range.m_range_display_kind = SHOW_RANGE_WITHOUT_CARET; @@ -2857,7 +2849,7 @@ diagnostic_show_locus (diagnostic_context * context, context->m_last_location = loc; - layout layout (context, richloc, diagnostic_kind, pp); + layout layout (*context, richloc, diagnostic_kind, pp); for (int line_span_idx = 0; line_span_idx < layout.get_num_line_spans (); line_span_idx++) { @@ -2969,7 +2961,7 @@ test_offset_impl (int caret_byte_col, int max_width, rich_location richloc (line_table, linemap_position_for_column (line_table, caret_byte_col)); - layout test_layout (&dc, &richloc, DK_ERROR); + layout test_layout (dc, &richloc, DK_ERROR, nullptr); ASSERT_EQ (left_margin - test_linenum_sep, test_layout.get_linenum_width ()); ASSERT_EQ (expected_x_offset_display, @@ -3084,7 +3076,7 @@ test_layout_x_offset_display_utf8 (const line_table_case &case_) rich_location richloc (line_table, linemap_position_for_column (line_table, emoji_col)); - layout test_layout (&dc, &richloc, DK_ERROR); + layout test_layout (dc, &richloc, DK_ERROR, nullptr); test_layout.print_line (1); ASSERT_STREQ (" | 1 \n" " | 1 \n" @@ -3109,7 +3101,7 @@ test_layout_x_offset_display_utf8 (const line_table_case &case_) rich_location richloc (line_table, linemap_position_for_column (line_table, emoji_col + 2)); - layout test_layout (&dc, &richloc, DK_ERROR); + layout test_layout (dc, &richloc, DK_ERROR, nullptr); test_layout.print_line (1); ASSERT_STREQ (" | 1 1 \n" " | 1 2 \n" @@ -3186,7 +3178,7 @@ test_layout_x_offset_display_tab (const line_table_case &case_) { test_diagnostic_context dc; dc.m_tabstop = tabstop; - layout test_layout (&dc, &richloc, DK_ERROR); + layout test_layout (dc, &richloc, DK_ERROR, nullptr); test_layout.print_line (1); const char *out = pp_formatted_text (dc.printer); ASSERT_EQ (NULL, strchr (out, '\t')); @@ -3209,7 +3201,7 @@ test_layout_x_offset_display_tab (const line_table_case &case_) dc.m_source_printing.min_margin_width = test_left_margin - test_linenum_sep + 1; dc.m_source_printing.show_line_numbers_p = true; - layout test_layout (&dc, &richloc, DK_ERROR); + layout test_layout (dc, &richloc, DK_ERROR, nullptr); test_layout.print_line (1); /* We have arranged things so that two columns will be printed before @@ -5521,7 +5513,7 @@ test_tab_expansion (const line_table_case &case_) rich_location richloc (line_table, linemap_position_for_column (line_table, first_non_ws_byte_col)); - layout test_layout (&dc, &richloc, DK_ERROR); + layout test_layout (dc, &richloc, DK_ERROR, nullptr); test_layout.print_line (1); ASSERT_STREQ (" This: ` ' is a tab.\n" " ^\n", @@ -5536,7 +5528,7 @@ test_tab_expansion (const line_table_case &case_) rich_location richloc (line_table, linemap_position_for_column (line_table, right_quote_byte_col)); - layout test_layout (&dc, &richloc, DK_ERROR); + layout test_layout (dc, &richloc, DK_ERROR, nullptr); test_layout.print_line (1); ASSERT_STREQ (" This: ` ' is a tab.\n" " ^\n", diff --git a/gcc/diagnostic.h b/gcc/diagnostic.h index b83cdeb35c1..58341cec308 100644 --- a/gcc/diagnostic.h +++ b/gcc/diagnostic.h @@ -303,6 +303,50 @@ private: int m_n_push; }; +/* A bundle of options relating to printing the user's source code + (potentially with a margin, underlining, labels, etc). */ + +struct diagnostic_source_printing_options +{ + /* True if we should print the source line with a caret indicating + the location. + Corresponds to -fdiagnostics-show-caret. */ + bool enabled; + + /* Maximum width of the source line printed. */ + int max_width; + + /* Character used at the caret when printing source locations. */ + char caret_chars[rich_location::STATICALLY_ALLOCATED_RANGES]; + + /* When printing source code, should the characters at carets and ranges + be colorized? (assuming colorization is on at all). + This should be true for frontends that generate range information + (so that the ranges of code are colorized), + and false for frontends that merely specify points within the + source code (to avoid e.g. colorizing just the first character in + a token, which would look strange). */ + bool colorize_source_p; + + /* When printing source code, should labelled ranges be printed? + Corresponds to -fdiagnostics-show-labels. */ + bool show_labels_p; + + /* When printing source code, should there be a left-hand margin + showing line numbers? + Corresponds to -fdiagnostics-show-line-numbers. */ + bool show_line_numbers_p; + + /* If printing source code, what should the minimum width of the margin + be? Line numbers will be right-aligned, and padded to this width. + Corresponds to -fdiagnostics-minimum-margin-width=VALUE. */ + int min_margin_width; + + /* Usable by plugins; if true, print a debugging ruler above the + source output. */ + bool show_ruler_p; +}; + /* This data structure bundles altogether any information relevant to the context of a diagnostic message. */ class diagnostic_context @@ -601,49 +645,7 @@ public: bool m_inhibit_notes_p; - /* Fields relating to printing the user's source code (potentially with - a margin, underlining, labels, etc). */ - struct { - - /* True if we should print the source line with a caret indicating - the location. - Corresponds to -fdiagnostics-show-caret. */ - bool enabled; - - /* Maximum width of the source line printed. */ - int max_width; - - /* Character used at the caret when printing source locations. */ - char caret_chars[rich_location::STATICALLY_ALLOCATED_RANGES]; - - /* When printing source code, should the characters at carets and ranges - be colorized? (assuming colorization is on at all). - This should be true for frontends that generate range information - (so that the ranges of code are colorized), - and false for frontends that merely specify points within the - source code (to avoid e.g. colorizing just the first character in - a token, which would look strange). */ - bool colorize_source_p; - - /* When printing source code, should labelled ranges be printed? - Corresponds to -fdiagnostics-show-labels. */ - bool show_labels_p; - - /* When printing source code, should there be a left-hand margin - showing line numbers? - Corresponds to -fdiagnostics-show-line-numbers. */ - bool show_line_numbers_p; - - /* If printing source code, what should the minimum width of the margin - be? Line numbers will be right-aligned, and padded to this width. - Corresponds to -fdiagnostics-minimum-margin-width=VALUE. */ - int min_margin_width; - - /* Usable by plugins; if true, print a debugging ruler above the - source output. */ - bool show_ruler_p; - - } m_source_printing; + diagnostic_source_printing_options m_source_printing; private: /* True if -freport-bug option is used. */