From patchwork Mon Oct 2 16:33:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 147372 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2a8e:b0:403:3b70:6f57 with SMTP id in14csp1546950vqb; Mon, 2 Oct 2023 09:35:55 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGih6tzXOuX8qzxtbWno/4X4wOwDO/cqKi1ZFNQCVElYzx99GrZ4d1rb59FMuiiVVCf7OzU X-Received: by 2002:a17:906:51d8:b0:99b:627b:e96d with SMTP id v24-20020a17090651d800b0099b627be96dmr10573505ejk.44.1696264555245; Mon, 02 Oct 2023 09:35:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696264555; cv=none; d=google.com; s=arc-20160816; b=o8iDArgUgKXStYV6UjJinh7K6il/LMI/m/unZ1KwIBnuNUblzdlea/twLCYB+gMnNX +GdzOSCGSbgJPBLuOirhF5xwza4yaxOoxNsmz5fM56LWzjUOBO5E4idPZa2+AjLrNJ07 T34lZ8P/yxHExhRtX4cpxB4MWJnYmm8Rad0wrzeCQtl1PWu54SUCk/AZKxrxPGazt2Ld 94Dvyqp0uyaS5U6EMh6zWrTlrZg78Pydgb9BwVnJM8hmTJYdhlZozRj4mbEJHLD0Xsvh kkpw/SBHClkOF6KZO+vTrdiCqq3lpBy1vIf8ZwD04SCscoTfznl5JVl6SZKU+mB0pVb/ Wd5g== ARC-Message-Signature: i=1; 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:message-id:date:subject:cc:to:from:dkim-signature :dmarc-filter:delivered-to; bh=AGUJ/Es3C/sUVR03znxYpxKnbCm/bh2DqpIFpRHwdrA=; fh=NXemEfxTRbZtBxUkxR2ehQUaYlcDfMdzPkO8MChVQE4=; b=kY6B5oDOTUts+Ulj7YFl/qjAlKSsgXYx1CJCr2dPBrRkpOhZ2vcTfoGybbovMI1TGs ySIB5e/u0nLQt8xc0Vl6t0Crzgyun/Ifza0zD7k+E1jlrSY/cHNTfZhJrdG+zApRX5M7 i2v+KZu0NtNsih1UuomgMGnqzu2XFXY8KaQGWxd7+GKVMCcsuZfAJvl9f48yR4GVn/7a 6PWVadbuIijiXxTNLXoEmj10kFlqIeCupnAoE7Zr7wk+u9hyH17Wgty6b+K4uduE5392 Te5Bygi/u56xG36HZxGL4uz6oXbzE4U2MQeaSgzY+/G8QDNWoOC99BN2CXyclsyhHMgp jwDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=IdSCKi1a; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id lz1-20020a170906fb0100b009ae5a1d536fsi19379272ejb.132.2023.10.02.09.35.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 09:35:55 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=IdSCKi1a; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 A24EB385CC9C for ; Mon, 2 Oct 2023 16:34:43 +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 5498D3858409 for ; Mon, 2 Oct 2023 16:33:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5498D3858409 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1696264417; 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; bh=AGUJ/Es3C/sUVR03znxYpxKnbCm/bh2DqpIFpRHwdrA=; b=IdSCKi1aFCG563lld0RMA9sEtFBJJLUShPSxMwwHJ+rcA0RNeyi6IN0phCJXNOUkqLVXdl zRttjs/yrCMSEGAVlRAoqAYmxJR06KWqLHD9l9sUL6YWmc1/RH8ABVG1PTMu5Y8HLBWQy0 SC2yDu6ZRjsQztU4U+zGcscPwvJXcPg= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-261-Hrqc0PMUNiGsxt2PQ-NQTw-1; Mon, 02 Oct 2023 12:33:16 -0400 X-MC-Unique: Hrqc0PMUNiGsxt2PQ-NQTw-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 30FF11C2B665 for ; Mon, 2 Oct 2023 16:33:16 +0000 (UTC) Received: from t14s.localdomain.com (unknown [10.22.18.119]) by smtp.corp.redhat.com (Postfix) with ESMTP id E3C8E1005B90; Mon, 2 Oct 2023 16:33:15 +0000 (UTC) From: David Malcolm To: gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [pushed] diagnostics: group together source printing fields of diagnostic_context Date: Mon, 2 Oct 2023 12:33:15 -0400 Message-Id: <20231002163315.4034790-1-dmalcolm@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-10.1 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, RCVD_IN_SBL_CSS, SPF_HELO_NONE, SPF_NONE, TXREP 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: 1778662302143086154 X-GMAIL-MSGID: 1778662302143086154 struct diagnostic_context has > 60 fields. Try to tame some of the complexity by grouping together the 8 source-printing fields into a struct, the "m_source_printing" field. No functional change intended. Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu. Pushed to trunk as r14-4367-gc5c565eff6277a. gcc/ada/ChangeLog: * gcc-interface/misc.cc (gnat_post_options): Update for renaming of diagnostic_context's show_caret to m_source_printing.enabled. gcc/analyzer/ChangeLog: * program-point.cc: Update for grouping of source printing fields within diagnostic_context. gcc/c-family/ChangeLog: * c-common.cc (maybe_add_include_fixit): Update for renaming of diagnostic_context's show_caret to m_source_printing.enabled. * c-opts.cc (c_common_init_options): Update for renaming of diagnostic_context's colorize_source_p to m_source_printing.colorize_source_p. gcc/ChangeLog: * diagnostic-show-locus.cc: Update for reorganization of source-printing fields of diagnostic_context. * diagnostic.cc (diagnostic_set_caret_max_width): Likewise. (diagnostic_initialize): Likewise. * diagnostic.h (diagnostic_context::show_caret): Move to... (diagnostic_context::m_source_printing::enabled): ...here. (diagnostic_context::caret_max_width): Move to... (diagnostic_context::m_source_printing::max_width): ...here. (diagnostic_context::caret_chars): Move to... (diagnostic_context::m_source_printing::caret_chars): ...here. (diagnostic_context::colorize_source_p): Move to... (diagnostic_context::m_source_printing::colorize_source_p): ...here. (diagnostic_context::show_labels_p): Move to... (diagnostic_context::m_source_printing::show_labels_p): ...here. (diagnostic_context::show_line_numbers_p): Move to... (diagnostic_context::m_source_printing::show_line_numbers_p): ...here. (diagnostic_context::min_margin_width): Move to... (diagnostic_context::m_source_printing::min_margin_width): ...here. (diagnostic_context::show_ruler_p): Move to... (diagnostic_context::m_source_printing::show_ruler_p): ...here. (diagnostic_same_line): Update for above changes. * opts.cc (common_handle_option): Update for reorganization of source-printing fields of diagnostic_context. * selftest-diagnostic.cc (test_diagnostic_context::test_diagnostic_context): Likewise. * toplev.cc (general_init): Likewise. * tree-diagnostic-path.cc (struct event_range): Likewise. gcc/fortran/ChangeLog: * error.cc (gfc_diagnostic_starter): Update for reorganization of source-printing fields of diagnostic_context. (gfc_diagnostics_init): Likewise. (gfc_diagnostics_finish): Likewise. gcc/testsuite/ChangeLog: * gcc.dg/plugin/diagnostic_plugin_show_trees.c: Update for reorganization of source-printing fields of diagnostic_context. * gcc.dg/plugin/diagnostic_plugin_test_inlining.c: Likewise. * gcc.dg/plugin/diagnostic_plugin_test_paths.c: Likewise. * gcc.dg/plugin/diagnostic_plugin_test_show_locus.c: Likewise. * gcc.dg/plugin/diagnostic_plugin_test_string_literals.c: Likewise. * gcc.dg/plugin/diagnostic_plugin_test_tree_expression_range.c: Likewise. --- gcc/ada/gcc-interface/misc.cc | 2 +- gcc/analyzer/program-point.cc | 4 +- gcc/c-family/c-common.cc | 2 +- gcc/c-family/c-opts.cc | 2 +- gcc/diagnostic-show-locus.cc | 93 ++++++++++--------- gcc/diagnostic.cc | 16 ++-- gcc/diagnostic.h | 73 ++++++++------- gcc/fortran/error.cc | 10 +- gcc/opts.cc | 8 +- gcc/selftest-diagnostic.cc | 8 +- .../plugin/diagnostic_plugin_show_trees.c | 2 +- .../plugin/diagnostic_plugin_test_inlining.c | 2 +- .../plugin/diagnostic_plugin_test_paths.c | 2 +- .../diagnostic_plugin_test_show_locus.c | 26 +++--- .../diagnostic_plugin_test_string_literals.c | 2 +- ...nostic_plugin_test_tree_expression_range.c | 2 +- gcc/toplev.cc | 8 +- gcc/tree-diagnostic-path.cc | 2 +- 18 files changed, 140 insertions(+), 124 deletions(-) diff --git a/gcc/ada/gcc-interface/misc.cc b/gcc/ada/gcc-interface/misc.cc index 3b21bf5b43a..269c15e4b0d 100644 --- a/gcc/ada/gcc-interface/misc.cc +++ b/gcc/ada/gcc-interface/misc.cc @@ -269,7 +269,7 @@ gnat_post_options (const char **pfilename ATTRIBUTE_UNUSED) /* No caret by default for Ada. */ if (!OPTION_SET_P (flag_diagnostics_show_caret)) - global_dc->show_caret = false; + global_dc->m_source_printing.enabled = false; /* Copy global settings to local versions. */ gnat_encodings = global_options.x_gnat_encodings; diff --git a/gcc/analyzer/program-point.cc b/gcc/analyzer/program-point.cc index d7db2f52239..914d49f0314 100644 --- a/gcc/analyzer/program-point.cc +++ b/gcc/analyzer/program-point.cc @@ -256,8 +256,8 @@ public: debug_diagnostic_context () { diagnostic_initialize (this, 0); - show_line_numbers_p = true; - show_caret = true; + m_source_printing.show_line_numbers_p = true; + m_source_printing.enabled = true; } ~debug_diagnostic_context () { diff --git a/gcc/c-family/c-common.cc b/gcc/c-family/c-common.cc index aae57260097..f044db5b797 100644 --- a/gcc/c-family/c-common.cc +++ b/gcc/c-family/c-common.cc @@ -9569,7 +9569,7 @@ maybe_add_include_fixit (rich_location *richloc, const char *header, richloc->add_fixit_insert_before (include_insert_loc, text); free (text); - if (override_location && global_dc->show_caret) + if (override_location && global_dc->m_source_printing.enabled) { /* Replace the primary location with that of the insertion point for the fix-it hint. diff --git a/gcc/c-family/c-opts.cc b/gcc/c-family/c-opts.cc index fe2d14307f4..ce2e021e69d 100644 --- a/gcc/c-family/c-opts.cc +++ b/gcc/c-family/c-opts.cc @@ -272,7 +272,7 @@ c_common_init_options (unsigned int decoded_options_count, if (c_dialect_cxx ()) set_std_cxx17 (/*ISO*/false); - global_dc->colorize_source_p = true; + global_dc->m_source_printing.colorize_source_p = true; } /* Handle switch SCODE with argument ARG. VALUE is true, unless no- diff --git a/gcc/diagnostic-show-locus.cc b/gcc/diagnostic-show-locus.cc index 31ef85151fd..0778223ccb5 100644 --- a/gcc/diagnostic-show-locus.cc +++ b/gcc/diagnostic-show-locus.cc @@ -1193,9 +1193,9 @@ layout::layout (diagnostic_context * context, m_exploc (richloc->get_expanded_location (0), m_policy, LOCATION_ASPECT_CARET), m_colorizer (context, diagnostic_kind), - m_colorize_source_p (context->colorize_source_p), - m_show_labels_p (context->show_labels_p), - m_show_line_numbers_p (context->show_line_numbers_p), + 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_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 +1229,8 @@ layout::layout (diagnostic_context * context, calculate_linenum_width (); calculate_x_offset_display (); - if (context->show_ruler_p) - show_ruler (m_x_offset_display + m_context->caret_max_width); + if (context->m_source_printing.show_ruler_p) + show_ruler (m_x_offset_display + m_context->m_source_printing.max_width); } @@ -1595,7 +1595,8 @@ 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->min_margin_width - 1); + m_linenum_width = MAX (m_linenum_width, + m_context->m_source_printing.min_margin_width - 1); } /* Calculate m_x_offset_display, which improves readability in case the source @@ -1609,7 +1610,7 @@ layout::calculate_x_offset_display () { m_x_offset_display = 0; - const int max_width = m_context->caret_max_width; + const int max_width = m_context->m_source_printing.max_width; if (!max_width) { /* Nothing to do, the width is not capped. */ @@ -1851,7 +1852,8 @@ 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->caret_chars[state.range_idx]; + caret_char + = m_context->m_source_printing.caret_chars[state.range_idx]; else caret_char = '^'; pp_character (m_pp, caret_char); @@ -2838,7 +2840,7 @@ diagnostic_show_locus (diagnostic_context * context, { location_t loc = richloc->get_loc (); /* Do nothing if source-printing has been disabled. */ - if (!context->show_caret) + if (!context->m_source_printing.enabled) return; /* Don't attempt to print source for UNKNOWN_LOCATION and for builtins. */ @@ -2860,7 +2862,7 @@ diagnostic_show_locus (diagnostic_context * context, line_span_idx++) { const line_span *line_span = layout.get_line_span (line_span_idx); - if (context->show_line_numbers_p) + if (context->m_source_printing.show_line_numbers_p) { /* With line numbers, we should show whenever the line-numbering "jumps". */ @@ -2959,11 +2961,11 @@ test_offset_impl (int caret_byte_col, int max_width, int left_margin = test_left_margin) { test_diagnostic_context dc; - dc.caret_max_width = max_width; + dc.m_source_printing.max_width = max_width; /* diagnostic_context::min_margin_width sets the minimum space reserved for the line number plus one space after. */ - dc.min_margin_width = left_margin - test_linenum_sep + 1; - dc.show_line_numbers_p = true; + dc.m_source_printing.min_margin_width = left_margin - test_linenum_sep + 1; + dc.m_source_printing.show_line_numbers_p = true; rich_location richloc (line_table, linemap_position_for_column (line_table, caret_byte_col)); @@ -3074,10 +3076,11 @@ test_layout_x_offset_display_utf8 (const line_table_case &case_) /* Test that the source line is offset as expected when printed. */ { test_diagnostic_context dc; - dc.caret_max_width = small_width - 6; - dc.min_margin_width = test_left_margin - test_linenum_sep + 1; - dc.show_line_numbers_p = true; - dc.show_ruler_p = true; + dc.m_source_printing.max_width = small_width - 6; + dc.m_source_printing.min_margin_width + = test_left_margin - test_linenum_sep + 1; + dc.m_source_printing.show_line_numbers_p = true; + dc.m_source_printing.show_ruler_p = true; rich_location richloc (line_table, linemap_position_for_column (line_table, emoji_col)); @@ -3098,10 +3101,11 @@ test_layout_x_offset_display_utf8 (const line_table_case &case_) it with a padding space in this case. */ { test_diagnostic_context dc; - dc.caret_max_width = small_width - 5; - dc.min_margin_width = test_left_margin - test_linenum_sep + 1; - dc.show_line_numbers_p = true; - dc.show_ruler_p = true; + dc.m_source_printing.max_width = small_width - 5; + dc.m_source_printing.min_margin_width + = test_left_margin - test_linenum_sep + 1; + dc.m_source_printing.show_line_numbers_p = true; + dc.m_source_printing.show_ruler_p = true; rich_location richloc (line_table, linemap_position_for_column (line_table, emoji_col + 2)); @@ -3201,9 +3205,10 @@ test_layout_x_offset_display_tab (const line_table_case &case_) test_diagnostic_context dc; dc.tabstop = tabstop; static const int small_width = 24; - dc.caret_max_width = small_width - 4; - dc.min_margin_width = test_left_margin - test_linenum_sep + 1; - dc.show_line_numbers_p = true; + dc.m_source_printing.max_width = small_width - 4; + 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); test_layout.print_line (1); @@ -3287,19 +3292,19 @@ test_one_liner_multiple_carets_and_ranges () = make_location (linemap_position_for_column (line_table, 2), linemap_position_for_column (line_table, 1), linemap_position_for_column (line_table, 3)); - dc.caret_chars[0] = 'A'; + dc.m_source_printing.caret_chars[0] = 'A'; location_t bar = make_location (linemap_position_for_column (line_table, 8), linemap_position_for_column (line_table, 7), linemap_position_for_column (line_table, 9)); - dc.caret_chars[1] = 'B'; + dc.m_source_printing.caret_chars[1] = 'B'; location_t field = make_location (linemap_position_for_column (line_table, 13), linemap_position_for_column (line_table, 11), linemap_position_for_column (line_table, 15)); - dc.caret_chars[2] = 'C'; + dc.m_source_printing.caret_chars[2] = 'C'; rich_location richloc (line_table, foo); richloc.add_range (bar, SHOW_RANGE_WITH_CARET); @@ -3382,8 +3387,8 @@ test_one_liner_fixit_remove () /* Normal, with ruler. */ { test_diagnostic_context dc; - dc.show_ruler_p = true; - dc.caret_max_width = 104; + dc.m_source_printing.show_ruler_p = true; + dc.m_source_printing.max_width = 104; diagnostic_show_locus (&dc, &richloc, DK_ERROR); ASSERT_STREQ (" 0 0 0 0 0 0 0 0 0 1 \n" " 1 2 3 4 5 6 7 8 9 0 \n" @@ -3397,8 +3402,8 @@ test_one_liner_fixit_remove () /* Test of adding a prefix, with ruler. */ { test_diagnostic_context dc; - dc.show_ruler_p = true; - dc.caret_max_width = 50; + dc.m_source_printing.show_ruler_p = true; + dc.m_source_printing.max_width = 50; pp_prefixing_rule (dc.printer) = DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE; pp_set_prefix (dc.printer, xstrdup ("TEST PREFIX:")); diagnostic_show_locus (&dc, &richloc, DK_ERROR); @@ -3413,9 +3418,9 @@ test_one_liner_fixit_remove () /* Test of adding a prefix, with ruler and line numbers. */ { test_diagnostic_context dc; - dc.show_ruler_p = true; - dc.caret_max_width = 50; - dc.show_line_numbers_p = true; + dc.m_source_printing.show_ruler_p = true; + dc.m_source_printing.max_width = 50; + dc.m_source_printing.show_line_numbers_p = true; pp_prefixing_rule (dc.printer) = DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE; pp_set_prefix (dc.printer, xstrdup ("TEST PREFIX:")); diagnostic_show_locus (&dc, &richloc, DK_ERROR); @@ -3641,7 +3646,7 @@ test_one_liner_labels () /* Verify that we can disable label-printing. */ { test_diagnostic_context dc; - dc.show_labels_p = false; + dc.m_source_printing.show_labels_p = false; diagnostic_show_locus (&dc, &richloc, DK_ERROR); ASSERT_STREQ (" foo = bar.field;\n" " ^~~ ~~~ ~~~~~\n", @@ -3895,19 +3900,19 @@ test_one_liner_multiple_carets_and_ranges_utf8 () = make_location (linemap_position_for_column (line_table, 7), linemap_position_for_column (line_table, 1), linemap_position_for_column (line_table, 8)); - dc.caret_chars[0] = 'A'; + dc.m_source_printing.caret_chars[0] = 'A'; location_t bar = make_location (linemap_position_for_column (line_table, 16), linemap_position_for_column (line_table, 12), linemap_position_for_column (line_table, 17)); - dc.caret_chars[1] = 'B'; + dc.m_source_printing.caret_chars[1] = 'B'; location_t field = make_location (linemap_position_for_column (line_table, 26), linemap_position_for_column (line_table, 19), linemap_position_for_column (line_table, 30)); - dc.caret_chars[2] = 'C'; + dc.m_source_printing.caret_chars[2] = 'C'; rich_location richloc (line_table, foo); richloc.add_range (bar, SHOW_RANGE_WITH_CARET); richloc.add_range (field, SHOW_RANGE_WITH_CARET); @@ -4348,7 +4353,7 @@ static void test_one_liner_colorized_utf8 () { test_diagnostic_context dc; - dc.colorize_source_p = true; + dc.m_source_printing.colorize_source_p = true; diagnostic_color_init (&dc, DIAGNOSTICS_COLOR_YES); const location_t pi = linemap_position_for_column (line_table, 12); rich_location richloc (line_table, pi); @@ -4563,7 +4568,7 @@ test_diagnostic_show_locus_fixit_lines (const line_table_case &case_) richloc.add_fixit_insert_before (y, "."); richloc.add_fixit_replace (colon, "="); test_diagnostic_context dc; - dc.show_line_numbers_p = true; + dc.m_source_printing.show_line_numbers_p = true; diagnostic_show_locus (&dc, &richloc, DK_ERROR); ASSERT_STREQ (" 3 | y\n" " | .\n" @@ -5304,7 +5309,7 @@ test_fixit_insert_containing_newline (const line_table_case &case_) /* With line numbers. */ { test_diagnostic_context dc; - dc.show_line_numbers_p = true; + dc.m_source_printing.show_line_numbers_p = true; diagnostic_show_locus (&dc, &richloc, DK_ERROR); ASSERT_STREQ (" 2 | x = a;\n" " +++ |+ break;\n" @@ -5383,7 +5388,7 @@ test_fixit_insert_containing_newline_2 (const line_table_case &case_) consolidated, since it makes little sense to skip line 2. */ { test_diagnostic_context dc; - dc.show_line_numbers_p = true; + dc.m_source_printing.show_line_numbers_p = true; diagnostic_show_locus (&dc, &richloc, DK_ERROR); ASSERT_STREQ (" +++ |+#include \n" " 1 | test (int ch)\n" @@ -5679,8 +5684,8 @@ test_line_numbers_multiline_range () location_t loc = make_location (caret, start, finish); test_diagnostic_context dc; - dc.show_line_numbers_p = true; - dc.min_margin_width = 0; + dc.m_source_printing.show_line_numbers_p = true; + dc.m_source_printing.min_margin_width = 0; gcc_rich_location richloc (loc); diagnostic_show_locus (&dc, &richloc, DK_ERROR); ASSERT_STREQ (" 9 | this is line 9\n" diff --git a/gcc/diagnostic.cc b/gcc/diagnostic.cc index 28ab74ff23e..b4bbd60590b 100644 --- a/gcc/diagnostic.cc +++ b/gcc/diagnostic.cc @@ -147,7 +147,7 @@ diagnostic_set_caret_max_width (diagnostic_context *context, int value) if (value <= 0) value = INT_MAX; - context->caret_max_width = value; + context->m_source_printing.max_width = value; } /* Default implementation of final_cb. */ @@ -189,10 +189,10 @@ diagnostic_initialize (diagnostic_context *context, int n_opts) context->classify_diagnostic = XNEWVEC (diagnostic_t, n_opts); for (i = 0; i < n_opts; i++) context->classify_diagnostic[i] = DK_UNSPECIFIED; - context->show_caret = false; + context->m_source_printing.enabled = false; diagnostic_set_caret_max_width (context, pp_line_cutoff (context->printer)); for (i = 0; i < rich_location::STATICALLY_ALLOCATED_RANGES; i++) - context->caret_chars[i] = '^'; + context->m_source_printing.caret_chars[i] = '^'; context->show_cwe = false; context->show_rules = false; context->path_format = DPF_NONE; @@ -220,11 +220,11 @@ diagnostic_initialize (diagnostic_context *context, int n_opts) context->x_data = NULL; context->lock = 0; context->inhibit_notes_p = false; - context->colorize_source_p = false; - context->show_labels_p = false; - context->show_line_numbers_p = false; - context->min_margin_width = 0; - context->show_ruler_p = false; + context->m_source_printing.colorize_source_p = false; + context->m_source_printing.show_labels_p = false; + context->m_source_printing.show_line_numbers_p = false; + context->m_source_printing.min_margin_width = 0; + context->m_source_printing.show_ruler_p = false; context->report_bug = false; if (const char *var = getenv ("GCC_EXTRA_DIAGNOSTIC_OUTPUT")) diff --git a/gcc/diagnostic.h b/gcc/diagnostic.h index 4ec83a988d5..1f2d93c3d00 100644 --- a/gcc/diagnostic.h +++ b/gcc/diagnostic.h @@ -219,16 +219,6 @@ struct diagnostic_context int *push_list; int n_push; - /* True if we should print the source line with a caret indicating - the location. */ - bool show_caret; - - /* Maximum width of the source line printed. */ - int caret_max_width; - - /* Character used for caret diagnostics. */ - char caret_chars[rich_location::STATICALLY_ALLOCATED_RANGES]; - /* True if we should print any CWE identifiers associated with diagnostics. */ bool show_cwe; @@ -336,29 +326,49 @@ struct diagnostic_context bool inhibit_notes_p; - /* 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; + /* 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 labelled ranges be printed? */ - 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; - /* When printing source code, should there be a left-hand margin - showing 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; - /* If printing source code, what should the minimum width of the margin - be? Line numbers will be right-aligned, and padded to this width. */ - int min_margin_width; + /* Usable by plugins; if true, print a debugging ruler above the + source output. */ + bool show_ruler_p; - /* Usable by plugins; if true, print a debugging ruler above the - source output. */ - bool show_ruler_p; + } m_source_printing; /* True if -freport-bug option is used. */ bool report_bug; @@ -605,8 +615,9 @@ inline bool diagnostic_same_line (const diagnostic_context *context, expanded_location s1, expanded_location s2) { - return s2.column && s1.line == s2.line - && context->caret_max_width - CARET_LINE_MARGIN > abs (s1.column - s2.column); + return (s2.column && s1.line == s2.line + && (context->m_source_printing.max_width - CARET_LINE_MARGIN + > abs (s1.column - s2.column))); } extern const char *diagnostic_get_color_for_kind (diagnostic_t kind); diff --git a/gcc/fortran/error.cc b/gcc/fortran/error.cc index 6cae6726f91..378f7393133 100644 --- a/gcc/fortran/error.cc +++ b/gcc/fortran/error.cc @@ -1222,7 +1222,7 @@ gfc_diagnostic_starter (diagnostic_context *context, ? gfc_diagnostic_build_locus_prefix (context, s1) : gfc_diagnostic_build_locus_prefix (context, s1, s2); - if (!context->show_caret + if (!context->m_source_printing.enabled || diagnostic_location (diagnostic, 0) <= BUILTINS_LOCATION || diagnostic_location (diagnostic, 0) == context->last_location) { @@ -1640,8 +1640,8 @@ gfc_diagnostics_init (void) global_dc->start_span = gfc_diagnostic_start_span; diagnostic_finalizer (global_dc) = gfc_diagnostic_finalizer; diagnostic_format_decoder (global_dc) = gfc_format_decoder; - global_dc->caret_chars[0] = '1'; - global_dc->caret_chars[1] = '2'; + global_dc->m_source_printing.caret_chars[0] = '1'; + global_dc->m_source_printing.caret_chars[1] = '2'; pp_warning_buffer = new (XNEW (output_buffer)) output_buffer (); pp_warning_buffer->flush_p = false; /* pp_error_buffer is statically allocated. This simplifies memory @@ -1658,6 +1658,6 @@ gfc_diagnostics_finish (void) defaults. */ diagnostic_starter (global_dc) = gfc_diagnostic_starter; diagnostic_finalizer (global_dc) = gfc_diagnostic_finalizer; - global_dc->caret_chars[0] = '^'; - global_dc->caret_chars[1] = '^'; + global_dc->m_source_printing.caret_chars[0] = '^'; + global_dc->m_source_printing.caret_chars[1] = '^'; } diff --git a/gcc/opts.cc b/gcc/opts.cc index ac81d4e4294..573dcf8e497 100644 --- a/gcc/opts.cc +++ b/gcc/opts.cc @@ -2864,15 +2864,15 @@ common_handle_option (struct gcc_options *opts, break; case OPT_fdiagnostics_show_caret: - dc->show_caret = value; + dc->m_source_printing.enabled = value; break; case OPT_fdiagnostics_show_labels: - dc->show_labels_p = value; + dc->m_source_printing.show_labels_p = value; break; case OPT_fdiagnostics_show_line_numbers: - dc->show_line_numbers_p = value; + dc->m_source_printing.show_line_numbers_p = value; break; case OPT_fdiagnostics_color_: @@ -2936,7 +2936,7 @@ common_handle_option (struct gcc_options *opts, break; case OPT_fdiagnostics_minimum_margin_width_: - dc->min_margin_width = value; + dc->m_source_printing.min_margin_width = value; break; case OPT_fdump_: diff --git a/gcc/selftest-diagnostic.cc b/gcc/selftest-diagnostic.cc index 6d1bd1bd792..5469e555fc0 100644 --- a/gcc/selftest-diagnostic.cc +++ b/gcc/selftest-diagnostic.cc @@ -36,12 +36,12 @@ namespace selftest { test_diagnostic_context::test_diagnostic_context () { diagnostic_initialize (this, 0); - show_caret = true; - show_labels_p = true; + m_source_printing.enabled = true; + m_source_printing.show_labels_p = true; show_column = true; start_span = start_span_cb; - min_margin_width = 6; - caret_max_width = 80; + m_source_printing.min_margin_width = 6; + m_source_printing.max_width = 80; } test_diagnostic_context::~test_diagnostic_context () diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_show_trees.c b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_show_trees.c index d81fa571c97..f5c6fc5202f 100644 --- a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_show_trees.c +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_show_trees.c @@ -115,7 +115,7 @@ plugin_init (struct plugin_name_args *plugin_info, if (!plugin_default_version_check (version, &gcc_version)) return 1; - global_dc->caret_max_width = 80; + global_dc->m_source_printing.max_width = 80; register_callback (plugin_name, PLUGIN_PRE_GENERICIZE, diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_inlining.c b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_inlining.c index 3627f7a2b7f..7edce1fe2d4 100644 --- a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_inlining.c +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_inlining.c @@ -169,7 +169,7 @@ plugin_init (struct plugin_name_args *plugin_info, if (!plugin_default_version_check (version, &gcc_version)) return 1; - global_dc->caret_max_width = 80; + global_dc->m_source_printing.max_width = 80; pass_info.pass = new pass_test_inlining (g); pass_info.reference_pass_name = "*warn_function_noreturn"; diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_paths.c b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_paths.c index 62558bede95..bf665005c8b 100644 --- a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_paths.c +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_paths.c @@ -534,7 +534,7 @@ plugin_init (struct plugin_name_args *plugin_info, if (!plugin_default_version_check (version, &gcc_version)) return 1; - global_dc->caret_max_width = 80; + global_dc->m_source_printing.max_width = 80; pass_info.pass = make_pass_test_show_path (g); pass_info.reference_pass_name = "whole-program"; diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_show_locus.c b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_show_locus.c index baa6b629b83..2b8cbc952eb 100644 --- a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_show_locus.c +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_show_locus.c @@ -175,7 +175,7 @@ test_show_locus (function *fun) /* Hardcode the "terminal width", to verify the behavior of very wide lines. */ - global_dc->caret_max_width = 71; + global_dc->m_source_printing.max_width = 71; if (0 == strcmp (fnname, "test_simple")) { @@ -246,7 +246,7 @@ test_show_locus (function *fun) if (0 == strcmp (fnname, "test_very_wide_line")) { const int line = fnstart_line + 2; - global_dc->show_ruler_p = true; + global_dc->m_source_printing.show_ruler_p = true; text_range_label label0 ("label 0"); text_range_label label1 ("label 1"); rich_location richloc (line_table, @@ -258,7 +258,7 @@ test_show_locus (function *fun) &label1); richloc.add_fixit_replace ("bar * foo"); warning_at (&richloc, 0, "test"); - global_dc->show_ruler_p = false; + global_dc->m_source_printing.show_ruler_p = false; } /* Likewise, but with a secondary location that's immediately before @@ -266,7 +266,7 @@ test_show_locus (function *fun) if (0 == strcmp (fnname, "test_very_wide_line_2")) { const int line = fnstart_line + 2; - global_dc->show_ruler_p = true; + global_dc->m_source_printing.show_ruler_p = true; text_range_label label0 ("label 0"); text_range_label label1 ("label 1"); rich_location richloc (line_table, @@ -278,7 +278,7 @@ test_show_locus (function *fun) richloc.add_range (get_loc (line, 34), SHOW_RANGE_WITHOUT_CARET, &label1); warning_at (&richloc, 0, "test"); - global_dc->show_ruler_p = false; + global_dc->m_source_printing.show_ruler_p = false; } /* Example of multiple carets. */ @@ -289,11 +289,11 @@ test_show_locus (function *fun) location_t caret_b = get_loc (line, 11); rich_location richloc (line_table, caret_a); add_range (&richloc, caret_b, caret_b, SHOW_RANGE_WITH_CARET); - global_dc->caret_chars[0] = 'A'; - global_dc->caret_chars[1] = 'B'; + global_dc->m_source_printing.caret_chars[0] = 'A'; + global_dc->m_source_printing.caret_chars[1] = 'B'; warning_at (&richloc, 0, "test"); - global_dc->caret_chars[0] = '^'; - global_dc->caret_chars[1] = '^'; + global_dc->m_source_printing.caret_chars[0] = '^'; + global_dc->m_source_printing.caret_chars[1] = '^'; } /* Tests of rendering fixit hints. */ @@ -407,11 +407,11 @@ test_show_locus (function *fun) location_t caret_b = get_loc (line - 1, 19); rich_location richloc (line_table, caret_a); richloc.add_range (caret_b, SHOW_RANGE_WITH_CARET); - global_dc->caret_chars[0] = '1'; - global_dc->caret_chars[1] = '2'; + global_dc->m_source_printing.caret_chars[0] = '1'; + global_dc->m_source_printing.caret_chars[1] = '2'; warning_at (&richloc, 0, "test"); - global_dc->caret_chars[0] = '^'; - global_dc->caret_chars[1] = '^'; + global_dc->m_source_printing.caret_chars[0] = '^'; + global_dc->m_source_printing.caret_chars[1] = '^'; } /* Example of using the "%q+D" format code, which as well as printing diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_string_literals.c b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_string_literals.c index 0269f728a93..1b5fad2bc66 100644 --- a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_string_literals.c +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_string_literals.c @@ -208,7 +208,7 @@ plugin_init (struct plugin_name_args *plugin_info, if (!plugin_default_version_check (version, &gcc_version)) return 1; - global_dc->caret_max_width = 80; + global_dc->m_source_printing.max_width = 80; pass_info.pass = new pass_test_string_literals (g); pass_info.reference_pass_name = "ssa"; diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_tree_expression_range.c b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_tree_expression_range.c index f5468636e06..fbdb2f899d6 100644 --- a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_tree_expression_range.c +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_tree_expression_range.c @@ -89,7 +89,7 @@ plugin_init (struct plugin_name_args *plugin_info, if (!plugin_default_version_check (version, &gcc_version)) return 1; - global_dc->caret_max_width = 130; + global_dc->m_source_printing.max_width = 130; register_callback (plugin_name, PLUGIN_PRE_GENERICIZE, diff --git a/gcc/toplev.cc b/gcc/toplev.cc index db62e3e995e..626cc435c8b 100644 --- a/gcc/toplev.cc +++ b/gcc/toplev.cc @@ -1023,11 +1023,11 @@ general_init (const char *argv0, bool init_signals) override it later. */ tree_diagnostics_defaults (global_dc); - global_dc->show_caret + global_dc->m_source_printing.enabled = global_options_init.x_flag_diagnostics_show_caret; - global_dc->show_labels_p + global_dc->m_source_printing.show_labels_p = global_options_init.x_flag_diagnostics_show_labels; - global_dc->show_line_numbers_p + global_dc->m_source_printing.show_line_numbers_p = global_options_init.x_flag_diagnostics_show_line_numbers; global_dc->show_cwe = global_options_init.x_flag_diagnostics_show_cwe; @@ -1039,7 +1039,7 @@ general_init (const char *argv0, bool init_signals) = global_options_init.x_flag_diagnostics_show_path_depths; global_dc->show_option_requested = global_options_init.x_flag_diagnostics_show_option; - global_dc->min_margin_width + global_dc->m_source_printing.min_margin_width = global_options_init.x_diagnostics_minimum_margin_width; global_dc->show_column = global_options_init.x_flag_show_column; diff --git a/gcc/tree-diagnostic-path.cc b/gcc/tree-diagnostic-path.cc index 84148da53af..b1b483a27aa 100644 --- a/gcc/tree-diagnostic-path.cc +++ b/gcc/tree-diagnostic-path.cc @@ -200,7 +200,7 @@ struct event_range /* Emit a span indicating the filename (and line/column) if the line has changed relative to the last call to diagnostic_show_locus. */ - if (dc->show_caret) + if (dc->m_source_printing.enabled) { expanded_location exploc = linemap_client_expand_location_to_spelling_point