public inbox for gcc-rust@gcc.gnu.org
 help / color / mirror / Atom feed
* [COMMITTED] gccrs: move functions from rust-gcc-diagnostics to rust-diagnostics.cc
@ 2023-09-11 14:42 Arthur Cohen
  0 siblings, 0 replies; only message in thread
From: Arthur Cohen @ 2023-09-11 14:42 UTC (permalink / raw)
  To: gcc-patches; +Cc: gcc-rust, Parthib, Parthib Datta

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 <parthibdutta02@gmail.com>

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<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, ...)
@@ -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<rich_location &> (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
-// <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;
-}
-- 
2.42.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-09-11 14:43 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-11 14:42 [COMMITTED] gccrs: move functions from rust-gcc-diagnostics to rust-diagnostics.cc Arthur Cohen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).