From patchwork Mon Sep 11 14:42:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 137892 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ab0a:0:b0:3f2:4152:657d with SMTP id m10csp2124702vqo; Mon, 11 Sep 2023 07:44:22 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE2ke7C8JJebB0zk1DuQ0W5Y6gkbw6rL12AYr0iiq5sS7vXvc2fpI/hZG/NSo45WZSgVSMB X-Received: by 2002:a2e:9813:0:b0:2bc:c771:5498 with SMTP id a19-20020a2e9813000000b002bcc7715498mr7289982ljj.18.1694443462333; Mon, 11 Sep 2023 07:44:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694443462; cv=none; d=google.com; s=arc-20160816; b=wpAUQCEykbmbI7vVkT4VI4JJbX7D8yyoVEua18xLZp07sYtMyb0yzMIND4kFz3OaAq RValWC4T55Ndn8LAsSb5JATuBxeHBPVO/8K7f+JozNFUWuOB60bB68Gqdel5Ymjgi0w0 yj0OsTU03dDILWLt2GCK24AJIxwKMrnRJGGtSfqixqpbeXh/UL5dPSfBg2IyL1wOQdqn qSJet3hYjAiTClb3TeMp+FVSf2slX3eOym6d8HqN/53nz6dFGeO9pqNEgiCBGRITpPhP 51FUfMCAMAPS8IszURZo1t4SAHHL+z/MYrXFYFnS/j32xFyvKaAw5qqedjRrkcIX9QSk 22vA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender: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=3JEAWZLXR4iSOvqje++0h7zUUT5xOX+fSJLUi3zzCno=; fh=BGqvTlSKnKroHxSDh030YpVd3x/KMcYpGtui0vckT0o=; b=b7t4Jmf+FkkrzsW5K9mlR7xpfoetsc3mPY4obopCIpC5Hs7CiOLC/qUu0t8CUyspT8 nCmhpwOnct9dlvNBDVcGXBGBmtUdzQHxf3xTdf88mKApysWQ/VM+Cd89yVwLf+Chw5Ty GrqoqTy3cdMSI2ayLyGlosseF1QhieQ8mCOOD+AM90dkx+JD912ZTXZRSCVgCLYy87d6 5dtMAvDQyBF2Hubc1x65TNaC0ozBUt6ScV/14x/krrWaCnuENUYiq9wnOqWWF43rNECX msOLhwAFhv/CGFL/nq2l8hoKy5Im4707knQHXgFpzRSvbAf7J632wm6j4Sk/gYG15GFY hypA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=JCSZIs8s; 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" Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id c7-20020a17090603c700b0099b4948325bsi6513502eja.31.2023.09.11.07.44.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 07:44:22 -0700 (PDT) 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=@embecosm.com header.s=google header.b=JCSZIs8s; 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" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D81E63857722 for ; Mon, 11 Sep 2023 14:44:09 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by sourceware.org (Postfix) with ESMTPS id ABA7E3858C62 for ; Mon, 11 Sep 2023 14:43:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org ABA7E3858C62 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embecosm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=embecosm.com Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-401d24f1f27so51837835e9.1 for ; Mon, 11 Sep 2023 07:43:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1694443420; x=1695048220; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=3JEAWZLXR4iSOvqje++0h7zUUT5xOX+fSJLUi3zzCno=; b=JCSZIs8sux3N1iYA4xWzSiSWyzpsiqoMXM+wwJb6gran1AKPVnxkBJVndn2Y8hY3jM TJ8IzoSvVPjUSsfYCimM4zkKnpvUH5Ffx97DyluBmPzU+10z1G9mv6BI7DpxDl/G7XLa 6ELcvx03NKqwEkyUxkb/b36ZwV20nrmvzNPi6k45sL2vLVRteKBxdSU/x5W+b/u4PbzG abD47KZOETYHdhbczKfQrdhWLZl+UgSon7tDtjcZURByrfhSfPYlntPTMsYVGFP6/xyc klA8nVTMg6CRC3KULGSnkAJOYn6iCUHZ/RX634A5TRtBHitC7gbNf1YAXLcRnpi/Q2ei M0GA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694443420; x=1695048220; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=3JEAWZLXR4iSOvqje++0h7zUUT5xOX+fSJLUi3zzCno=; b=OQzuubglxFfdl/5MHL+0YcBHp7maqo0jgVNw+06PP/Lo7TzDTy6rUifVO3mlYFIxk5 Hz+3bcumTLmxEhUmW8HqVV1eV1dqfQwVvXCex5/aGk6NlfCtYyVN4JkidfopjtT40Dk1 mA5tX00JIhkTyhiujl7iGetalCrSwVF7Bw+p4dS9Re0CAy+y3l/yDe43u/2nKrvaw/ec Cd8WYSTD25UouFPAKEJQprTec9HApR5l3GSRKH6Cv4wJu3aqeDax/9jHM8ZYD774Y9se PdY4CXdb9lUs9Rl8ECC2FjLaa0hgk/IvynDEGkzO6nYfscLgJQlYftHzHrDADMhuXCCS +FZg== X-Gm-Message-State: AOJu0YwmRxkykOV52SG6mf4XqWj/0XM18mZfPm2affabTHf5bpukz29e +f7jCmUrg509pFbvMDJ2GbQWPGxhOuIEMhTApQ== X-Received: by 2002:a7b:c389:0:b0:401:d947:c8a9 with SMTP id s9-20020a7bc389000000b00401d947c8a9mr8274064wmj.19.1694443419952; Mon, 11 Sep 2023 07:43:39 -0700 (PDT) Received: from platypus.localdomain ([62.23.166.218]) by smtp.gmail.com with ESMTPSA id z6-20020a7bc7c6000000b00401e32b25adsm10262301wmk.4.2023.09.11.07.43.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 07:43:39 -0700 (PDT) From: Arthur Cohen To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Parthib <94271200+Parthib314@users.noreply.github.com>, Parthib Datta Subject: [COMMITTED] gccrs: move functions from rust-gcc-diagnostics to rust-diagnostics.cc Date: Mon, 11 Sep 2023 16:42:25 +0200 Message-ID: <20230911144243.3506767-2-arthur.cohen@embecosm.com> X-Mailer: git-send-email 2.42.0 MIME-Version: 1.0 X-Spam-Status: No, score=-14.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=unavailable 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 Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776752747779202413 X-GMAIL-MSGID: 1776752747779202413 From: Parthib <94271200+Parthib314@users.noreply.github.com> gcc/rust/ChangeLog: * Make-lang.in: Removed rust-gcc-diagnostics object file. * rust-diagnostics.cc (rust_be_get_quotechars): Added from original file. (rust_be_internal_error_at): Likewise. (rust_be_error_at): Likewise. (class rust_error_code_rule): Likewise. (rust_be_warning_at): Likewise. (rust_be_fatal_error): Likewise. (rust_be_inform): Likewise. (rust_be_debug_p): Likewise. * rust-gcc-diagnostics.cc: Removed. Signed-off-by: Parthib Datta Tested on x86-64 Linux --- gcc/rust/Make-lang.in | 1 - gcc/rust/rust-diagnostics.cc | 95 +++++++++++++++++++++++++ gcc/rust/rust-gcc-diagnostics.cc | 117 ------------------------------- 3 files changed, 95 insertions(+), 118 deletions(-) delete mode 100644 gcc/rust/rust-gcc-diagnostics.cc diff --git a/gcc/rust/Make-lang.in b/gcc/rust/Make-lang.in index 3ed0c09e0e7..6449f47564d 100644 --- a/gcc/rust/Make-lang.in +++ b/gcc/rust/Make-lang.in @@ -66,7 +66,6 @@ GRS_OBJS = \ rust/rust-lang.o \ rust/rust-object-export.o \ rust/rust-linemap.o \ - rust/rust-gcc-diagnostics.o \ rust/rust-diagnostics.o \ rust/rust-gcc.o \ rust/rust-token.o \ diff --git a/gcc/rust/rust-diagnostics.cc b/gcc/rust/rust-diagnostics.cc index f29aec67652..16665b058d1 100644 --- a/gcc/rust/rust-diagnostics.cc +++ b/gcc/rust/rust-diagnostics.cc @@ -21,6 +21,9 @@ #include "rust-system.h" #include "rust-diagnostics.h" +#include "options.h" +#include "diagnostic-metadata.h" + static std::string mformat_value () { @@ -130,6 +133,13 @@ expand_message (const char *fmt, va_list ap) static const char *cached_open_quote = NULL; static const char *cached_close_quote = NULL; +void +rust_be_get_quotechars (const char **open_qu, const char **close_qu) +{ + *open_qu = open_quote; + *close_qu = close_quote; +} + const char * rust_open_quote () { @@ -146,6 +156,16 @@ rust_close_quote () return cached_close_quote; } +void +rust_be_internal_error_at (const Location location, const std::string &errmsg) +{ + std::string loc_str = Linemap::location_to_string (location); + if (loc_str.empty ()) + internal_error ("%s", errmsg.c_str ()); + else + internal_error ("at %s, %s", loc_str.c_str (), errmsg.c_str ()); +} + void rust_internal_error_at (const Location location, const char *fmt, ...) { @@ -156,6 +176,13 @@ rust_internal_error_at (const Location location, const char *fmt, ...) va_end (ap); } +void +rust_be_error_at (const Location location, const std::string &errmsg) +{ + location_t gcc_loc = location.gcc_location (); + error_at (gcc_loc, "%s", errmsg.c_str ()); +} + void rust_error_at (const Location location, const char *fmt, ...) { @@ -166,6 +193,38 @@ rust_error_at (const Location location, const char *fmt, ...) va_end (ap); } +class rust_error_code_rule : public diagnostic_metadata::rule +{ +public: + rust_error_code_rule (const ErrorCode code) : m_code (code) {} + + char *make_description () const final override + { + return xstrdup (m_code.m_str); + } + + char *make_url () const final override + { + return concat ("https://doc.rust-lang.org/error-index.html#", m_code.m_str, + NULL); + } + +private: + const ErrorCode m_code; +}; + +void +rust_be_error_at (const RichLocation &location, const ErrorCode code, + const std::string &errmsg) +{ + /* TODO: 'error_at' would like a non-'const' 'rich_location *'. */ + rich_location &gcc_loc = const_cast (location.get ()); + diagnostic_metadata m; + rust_error_code_rule rule (code); + m.add_rule (rule); + error_meta (&gcc_loc, m, "%s", errmsg.c_str ()); +} + void rust_error_at (const RichLocation &location, const ErrorCode code, const char *fmt, ...) @@ -177,6 +236,14 @@ rust_error_at (const RichLocation &location, const ErrorCode code, va_end (ap); } +void +rust_be_warning_at (const Location location, int opt, + const std::string &warningmsg) +{ + location_t gcc_loc = location.gcc_location (); + warning_at (gcc_loc, opt, "%s", warningmsg.c_str ()); +} + void rust_warning_at (const Location location, int opt, const char *fmt, ...) { @@ -187,6 +254,13 @@ rust_warning_at (const Location location, int opt, const char *fmt, ...) va_end (ap); } +void +rust_be_fatal_error (const Location location, const std::string &fatalmsg) +{ + location_t gcc_loc = location.gcc_location (); + fatal_error (gcc_loc, "%s", fatalmsg.c_str ()); +} + void rust_fatal_error (const Location location, const char *fmt, ...) { @@ -197,6 +271,13 @@ rust_fatal_error (const Location location, const char *fmt, ...) va_end (ap); } +void +rust_be_inform (const Location location, const std::string &infomsg) +{ + location_t gcc_loc = location.gcc_location (); + inform (gcc_loc, "%s", infomsg.c_str ()); +} + void rust_inform (const Location location, const char *fmt, ...) { @@ -208,6 +289,14 @@ rust_inform (const Location location, const char *fmt, ...) } // Rich Locations +void +rust_be_error_at (const RichLocation &location, const std::string &errmsg) +{ + /* TODO: 'error_at' would like a non-'const' 'rich_location *'. */ + rich_location &gcc_loc = const_cast (location.get ()); + error_at (&gcc_loc, "%s", errmsg.c_str ()); +} + void rust_error_at (const RichLocation &location, const char *fmt, ...) { @@ -218,6 +307,12 @@ rust_error_at (const RichLocation &location, const char *fmt, ...) va_end (ap); } +bool +rust_be_debug_p (void) +{ + return !!flag_rust_debug; +} + void rust_debug_loc (const Location location, const char *fmt, ...) { diff --git a/gcc/rust/rust-gcc-diagnostics.cc b/gcc/rust/rust-gcc-diagnostics.cc deleted file mode 100644 index 58c0a5654ea..00000000000 --- a/gcc/rust/rust-gcc-diagnostics.cc +++ /dev/null @@ -1,117 +0,0 @@ -// Copyright (C) 2020-2023 Free Software Foundation, Inc. - -// This file is part of GCC. - -// GCC is free software; you can redistribute it and/or modify it under -// the terms of the GNU General Public License as published by the Free -// Software Foundation; either version 3, or (at your option) any later -// version. - -// GCC is distributed in the hope that it will be useful, but WITHOUT ANY -// WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -// for more details. - -// You should have received a copy of the GNU General Public License -// along with GCC; see the file COPYING3. If not see -// . - -// rust-gcc-diagnostics.cc -- GCC implementation of rust diagnostics interface. - -#include "rust-system.h" -#include "rust-diagnostics.h" - -#include "options.h" -#include "diagnostic-metadata.h" - -void -rust_be_internal_error_at (const Location location, const std::string &errmsg) -{ - std::string loc_str = Linemap::location_to_string (location); - if (loc_str.empty ()) - internal_error ("%s", errmsg.c_str ()); - else - internal_error ("at %s, %s", loc_str.c_str (), errmsg.c_str ()); -} - -void -rust_be_error_at (const Location location, const std::string &errmsg) -{ - location_t gcc_loc = location.gcc_location (); - error_at (gcc_loc, "%s", errmsg.c_str ()); -} - -void -rust_be_warning_at (const Location location, int opt, - const std::string &warningmsg) -{ - location_t gcc_loc = location.gcc_location (); - warning_at (gcc_loc, opt, "%s", warningmsg.c_str ()); -} - -void -rust_be_fatal_error (const Location location, const std::string &fatalmsg) -{ - location_t gcc_loc = location.gcc_location (); - fatal_error (gcc_loc, "%s", fatalmsg.c_str ()); -} - -void -rust_be_inform (const Location location, const std::string &infomsg) -{ - location_t gcc_loc = location.gcc_location (); - inform (gcc_loc, "%s", infomsg.c_str ()); -} - -void -rust_be_error_at (const RichLocation &location, const std::string &errmsg) -{ - /* TODO: 'error_at' would like a non-'const' 'rich_location *'. */ - rich_location &gcc_loc = const_cast (location.get ()); - error_at (&gcc_loc, "%s", errmsg.c_str ()); -} - -class rust_error_code_rule : public diagnostic_metadata::rule -{ -public: - rust_error_code_rule (const ErrorCode code) : m_code (code) {} - - char *make_description () const final override - { - return xstrdup (m_code.m_str); - } - - char *make_url () const final override - { - return concat ("https://doc.rust-lang.org/error-index.html#", m_code.m_str, - NULL); - } - -private: - const ErrorCode m_code; -}; - -void -rust_be_error_at (const RichLocation &location, const ErrorCode code, - const std::string &errmsg) -{ - /* TODO: 'error_at' would like a non-'const' 'rich_location *'. */ - rich_location &gcc_loc = const_cast (location.get ()); - diagnostic_metadata m; - rust_error_code_rule rule (code); - m.add_rule (rule); - error_meta (&gcc_loc, m, "%s", errmsg.c_str ()); -} - -void -rust_be_get_quotechars (const char **open_qu, const char **close_qu) -{ - *open_qu = open_quote; - *close_qu = close_quote; -} - -bool -rust_be_debug_p (void) -{ - return !!flag_rust_debug; -}