From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1643) id 2E1CD385841A; Sat, 11 Feb 2023 15:30:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2E1CD385841A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1676129422; bh=9OnQhEPsFdECzXRb33WONskiW7xFNKh5TWsy8lkUGc0=; h=From:To:Subject:Date:From; b=fDX4GMnT1XJpHYJYbZywzD4xdR0UqWBx/kmDukQ6jdoyFywfVTrl4vYnttBugPD8I kd2zO+zkWrgFMSWqRNazDEufJur9GJqVgNe7lKwq42XEkhiS96g2pPmUwQNJI10aPc RnYwDZxuG/1tsAHLYghfappZQKCEg2mPacnCvq80= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Thomas Schwinge To: gcc-cvs@gcc.gnu.org Subject: [gcc/devel/rust/master] Moving Functions from rust-gcc-diagnostics to rust-diagnostics.cc X-Act-Checkin: gcc X-Git-Author: Parthib <94271200+Parthib314@users.noreply.github.com> X-Git-Refname: refs/heads/devel/rust/master X-Git-Oldrev: 21ec24265b2fb5ee76f806680d30ea90b4903ec8 X-Git-Newrev: 0d6b11551b810426119827d40461964f8804b016 Message-Id: <20230211153022.2E1CD385841A@sourceware.org> Date: Sat, 11 Feb 2023 15:30:22 +0000 (GMT) List-Id: https://gcc.gnu.org/g:0d6b11551b810426119827d40461964f8804b016 commit 0d6b11551b810426119827d40461964f8804b016 Author: Parthib <94271200+Parthib314@users.noreply.github.com> Date: Tue Jan 31 18:45:01 2023 +0530 Moving Functions from rust-gcc-diagnostics to rust-diagnostics.cc gcc/rust/ChangeLog: * Make-lang.in: Modified * rust-diagnostics.cc (rust_be_get_quotechars): Added (rust_be_internal_error_at): Added (rust_be_error_at): Added (class rust_error_code_rule): Added (rust_be_warning_at): Added (rust_be_fatal_error): Added (rust_be_inform): Added (rust_be_debug_p): Added * rust-gcc-diagnostics.cc: Removed Diff: --- 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(-) diff --git a/gcc/rust/Make-lang.in b/gcc/rust/Make-lang.in index 90da858433d..a005e05d551 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 79daf6b163c..894772dd5a5 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 98e2af7308d..00000000000 --- a/gcc/rust/rust-gcc-diagnostics.cc +++ /dev/null @@ -1,117 +0,0 @@ -// Copyright (C) 2020-2022 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; -}