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>
This commit is contained in:
Parthib 2023-01-31 18:45:01 +05:30 committed by Arthur Cohen
parent b59e9de990
commit af91934c2f
3 changed files with 95 additions and 118 deletions

View file

@ -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 \

View file

@ -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, ...)
{

View file

@ -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;
}