aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorParthib <94271200+Parthib314@users.noreply.github.com>2023-01-31 18:45:01 +0530
committerArthur Cohen <arthur.cohen@embecosm.com>2023-09-11 16:29:29 +0200
commitaf91934c2f6b8efc67d625c99068b4761ae5edd0 (patch)
treefbcbda8d5d4e00b52e461c540411bfaa11efb6e2
parentb59e9de990a17bfd5fa7252b76339c35bff7f2e8 (diff)
downloadgcc-af91934c2f6b8efc67d625c99068b4761ae5edd0.zip
gcc-af91934c2f6b8efc67d625c99068b4761ae5edd0.tar.gz
gcc-af91934c2f6b8efc67d625c99068b4761ae5edd0.tar.bz2
gccrs: move functions from rust-gcc-diagnostics to rust-diagnostics.cc
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 <parthibdutta02@gmail.com>
-rw-r--r--gcc/rust/Make-lang.in1
-rw-r--r--gcc/rust/rust-diagnostics.cc95
-rw-r--r--gcc/rust/rust-gcc-diagnostics.cc117
3 files changed, 95 insertions, 118 deletions
diff --git a/gcc/rust/Make-lang.in b/gcc/rust/Make-lang.in
index 3ed0c09..6449f47 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 f29aec6..16665b0 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 58c0a56..0000000
--- 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
-// <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;
-}