diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2023-02-10 09:47:36 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-10 09:47:36 +0000 |
commit | bceb118bc2f542382591803d9727b8c199a44ddd (patch) | |
tree | 85f24c7145ccb5d8dcf0daf546600bc23ca79b4e | |
parent | d4cce9835097f31d0e32fe47a2644dca4af9c1a3 (diff) | |
parent | 0d6b11551b810426119827d40461964f8804b016 (diff) | |
download | gcc-bceb118bc2f542382591803d9727b8c199a44ddd.zip gcc-bceb118bc2f542382591803d9727b8c199a44ddd.tar.gz gcc-bceb118bc2f542382591803d9727b8c199a44ddd.tar.bz2 |
Merge #1789
1789: Run workflow r=CohenArthur a=Parthib314
Fixes #1767
Co-authored-by: Parthib <94271200+Parthib314@users.noreply.github.com>
-rw-r--r-- | gcc/rust/Make-lang.in | 1 | ||||
-rw-r--r-- | gcc/rust/rust-diagnostics.cc | 95 | ||||
-rw-r--r-- | 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 6038c84..bb554f0 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 79daf6b..894772d 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 () { @@ -147,6 +157,16 @@ rust_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, ...) { va_list ap; @@ -157,6 +177,13 @@ rust_internal_error_at (const Location location, const char *fmt, ...) } 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, ...) { va_list ap; @@ -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<rich_location &> (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, ...) @@ -178,6 +237,14 @@ rust_error_at (const RichLocation &location, const ErrorCode code, } 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, ...) { va_list ap; @@ -188,6 +255,13 @@ rust_warning_at (const Location location, int opt, const char *fmt, ...) } 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, ...) { va_list ap; @@ -198,6 +272,13 @@ rust_fatal_error (const Location location, const char *fmt, ...) } 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, ...) { va_list ap; @@ -209,6 +290,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<rich_location &> (location.get ()); + error_at (&gcc_loc, "%s", errmsg.c_str ()); +} + +void rust_error_at (const RichLocation &location, const char *fmt, ...) { va_list ap; @@ -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 98e2af7..0000000 --- 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 -// <http://www.gnu.org/licenses/>. - -// 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<rich_location &> (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<rich_location &> (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; -} |