From patchwork Fri Apr 5 18:54:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 88117 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9B4C7384646C for ; Fri, 5 Apr 2024 18:54:47 +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 F381C385840C for ; Fri, 5 Apr 2024 18:54:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F381C385840C 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 F381C385840C 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=1712343259; cv=none; b=ROiShCrsXtHy8z4YLvgI1/IT12fQeTbCs19j02FQLH6uWmYSkE6MTNqsd67M4QnFE0PKQGsvkRT6xzzO50CWfwv+6w8ILIkioUBdVWpSYMdZ51VGnyIMzkyWFsjfvdmbRA/fuaIO+q02b9HXacf4j0GpGjCqIdD2Zc5TSHTMIZg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712343259; c=relaxed/simple; bh=KE6MirW6KFXjcrAkpA4itxmcZmTDMxnGkooagIwilDY=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=hsgMu9YiblZUcMz53OBZ1xUe/xEHV6V8VE0T/drYTXx/gqOISpl7wzxdKpp7Gfnbh3pIigCQADGNjTzeJQ+a9MPJQZuz3xU9b+znHBeziGkjdsP2C44vvbQtVSBSuyCRIbGEmTx6pZ3ypMnHqF+JK/22pD4r+QRtdCPtcn7JwoE= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1712343257; 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=gImny5BYFtnga283mqP5h5qD4psigv/taFMFFWDquC4=; b=LeEs3cd9oG6PcBxyfOJooD1mxUTzHJksaAoIPDND4uagOJPmM5NjuWimu5fFgFu5/7UQ59 wLxh0ihoVG9xe2ezsb2Z67H9NtBg6C0jyILrqfbotO35HmFR4KIWYGSW0KqkMX1vyx1lMP li/GPfhoHiBa2pPa4x5sCYv9qxVGO24= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-347-HGth5r72NmG79QdKwn97gQ-1; Fri, 05 Apr 2024 14:54:16 -0400 X-MC-Unique: HGth5r72NmG79QdKwn97gQ-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (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 2E1071C38267 for ; Fri, 5 Apr 2024 18:54:16 +0000 (UTC) Received: from t14s.localdomain.com (unknown [10.22.16.86]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0194A1C060A4; Fri, 5 Apr 2024 18:54:15 +0000 (UTC) From: David Malcolm To: gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [pushed] analyzer: respect GCC_COLORS in out-of-bounds diagrams [PR114588] Date: Fri, 5 Apr 2024 14:54:14 -0400 Message-Id: <20240405185414.2521002-1-dmalcolm@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.6 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 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+patchwork=sourceware.org@gcc.gnu.org Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu. Pushed to trunk as r14-9817-g4b02dd48f531ea. gcc/analyzer/ChangeLog: PR analyzer/114588 * access-diagram.cc (access_diagram_impl::access_diagram_impl): Replace hardcoded colors for valid_style and invalid_style with calls to text_art::get_style_from_color_cap_name. gcc/ChangeLog: PR analyzer/114588 * diagnostic-color.cc (color_dict): Add "valid" and "invalid" as color capability names. * doc/invoke.texi: Document them in description of GCC_COLORS. * text-art/style.cc: Include "diagnostic-color.h". (text_art::get_style_from_color_cap_name): New. * text-art/types.h (get_style_from_color_cap_name): New decl. Signed-off-by: David Malcolm --- gcc/analyzer/access-diagram.cc | 8 ++------ gcc/diagnostic-color.cc | 2 ++ gcc/doc/invoke.texi | 10 +++++++++- gcc/text-art/style.cc | 18 ++++++++++++++++++ gcc/text-art/types.h | 2 ++ 5 files changed, 33 insertions(+), 7 deletions(-) diff --git a/gcc/analyzer/access-diagram.cc b/gcc/analyzer/access-diagram.cc index 4cb6570e90b9..85e1049bb898 100644 --- a/gcc/analyzer/access-diagram.cc +++ b/gcc/analyzer/access-diagram.cc @@ -2059,14 +2059,10 @@ public: /* Register painting styles. */ { - style valid_style; - valid_style.m_fg_color = style::named_color::GREEN; - valid_style.m_bold = true; + style valid_style (get_style_from_color_cap_name ("valid")); m_valid_style_id = m_sm.get_or_create_id (valid_style); - style invalid_style; - invalid_style.m_fg_color = style::named_color::RED; - invalid_style.m_bold = true; + style invalid_style (get_style_from_color_cap_name ("invalid")); m_invalid_style_id = m_sm.get_or_create_id (invalid_style); } diff --git a/gcc/diagnostic-color.cc b/gcc/diagnostic-color.cc index 4859f36da6a9..f01a0fc2e377 100644 --- a/gcc/diagnostic-color.cc +++ b/gcc/diagnostic-color.cc @@ -101,6 +101,8 @@ static struct color_cap color_dict[] = { "diff-delete", SGR_SEQ (COLOR_FG_RED), 11, false }, { "diff-insert", SGR_SEQ (COLOR_FG_GREEN), 11, false }, { "type-diff", SGR_SEQ (COLOR_BOLD COLOR_SEPARATOR COLOR_FG_GREEN), 9, false }, + { "valid", SGR_SEQ (COLOR_BOLD COLOR_SEPARATOR COLOR_FG_GREEN), 5, false }, + { "invalid", SGR_SEQ (COLOR_BOLD COLOR_SEPARATOR COLOR_FG_RED), 7, false }, { NULL, NULL, 0, false } }; diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index c584664e1688..73bb2aec7c31 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -5241,7 +5241,7 @@ The default @env{GCC_COLORS} is error=01;31:warning=01;35:note=01;36:range1=32:range2=34:locus=01:\ quote=01:path=01;36:fixit-insert=32:fixit-delete=31:\ diff-filename=01:diff-hunk=32:diff-delete=31:diff-insert=32:\ -type-diff=01;32:fnname=01;32:targs=35 +type-diff=01;32:fnname=01;32:targs=35:valid=01;31:invalid=01;32 @end smallexample @noindent where @samp{01;31} is bold red, @samp{01;35} is bold magenta, @@ -5324,6 +5324,14 @@ SGR substring for inserted lines within generated patches. @item type-diff= SGR substring for highlighting mismatching types within template arguments in the C++ frontend. + +@vindex valid GCC_COLORS @r{capability} +@item valid= +SGR substring for highlighting valid elements within text art diagrams. + +@vindex invalid GCC_COLORS @r{capability} +@item invalid= +SGR substring for highlighting invalid elements within text art diagrams. @end table @opindex fdiagnostics-urls diff --git a/gcc/text-art/style.cc b/gcc/text-art/style.cc index e74efe23014c..5c58d432cf48 100644 --- a/gcc/text-art/style.cc +++ b/gcc/text-art/style.cc @@ -31,6 +31,7 @@ along with GCC; see the file COPYING3. If not see #include "text-art/selftests.h" #include "text-art/types.h" #include "color-macros.h" +#include "diagnostic-color.h" using namespace text_art; @@ -256,6 +257,23 @@ style::print_changes (pretty_printer *pp, } } +/* Look up the current SGR codes for a color capability NAME + (from GCC_COLORS or the defaults), and convert them to + a text_art::style. */ + +style +text_art::get_style_from_color_cap_name (const char *name) +{ + const char *sgr_codes = colorize_start (true, name); + gcc_assert (sgr_codes); + + /* Parse the sgr codes. We expect the resulting styled_string to be + empty; we're interested in the final style created during parsing. */ + style_manager sm; + styled_string styled_str (sm, sgr_codes); + return sm.get_style (sm.get_num_styles () - 1); +} + /* class text_art::style_manager. */ style_manager::style_manager () diff --git a/gcc/text-art/types.h b/gcc/text-art/types.h index 02de2e86122e..2b9f8b387c71 100644 --- a/gcc/text-art/types.h +++ b/gcc/text-art/types.h @@ -332,6 +332,8 @@ struct style std::vector m_url; // empty = no URL }; +extern style get_style_from_color_cap_name (const char *name); + /* A class to keep track of all the styles in use in a drawing, so that we can refer to them via the compact style::id_t type, rather than via e.g. pointers. */