From f9b0ca04c88bcea93d9e80f2c98089da7484f0d7 Mon Sep 17 00:00:00 2001 From: Owen Avery Date: Sun, 9 Jul 2023 23:23:14 -0400 Subject: [PATCH] gccrs: Add rust_error_at accepting location_t and ErrorCode gcc/rust/ChangeLog: * rust-diagnostics.cc (rust_be_error_at): Add function accepting location_t and ErrorCode. (rust_error_at): Likewise. * rust-diagnostics.h (rust_error_at): Likewise. (rust_be_error_at): Likewise. Signed-off-by: Owen Avery --- gcc/rust/rust-diagnostics.cc | 22 ++++++++++++++++++++++ gcc/rust/rust-diagnostics.h | 6 ++++++ 2 files changed, 28 insertions(+) diff --git a/gcc/rust/rust-diagnostics.cc b/gcc/rust/rust-diagnostics.cc index 6c745460e161..113a128a3866 100644 --- a/gcc/rust/rust-diagnostics.cc +++ b/gcc/rust/rust-diagnostics.cc @@ -212,6 +212,28 @@ private: const ErrorCode m_code; }; +void +rust_be_error_at (const Location location, const ErrorCode code, + const std::string &errmsg) +{ + rich_location gcc_loc (line_table, location); + 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 Location location, const ErrorCode code, const char *fmt, + ...) +{ + va_list ap; + + va_start (ap, fmt); + rust_be_error_at (location, code, expand_message (fmt, ap)); + va_end (ap); +} + void rust_be_error_at (const RichLocation &location, const ErrorCode code, const std::string &errmsg) diff --git a/gcc/rust/rust-diagnostics.h b/gcc/rust/rust-diagnostics.h index 58b13616480d..50097ef4ef89 100644 --- a/gcc/rust/rust-diagnostics.h +++ b/gcc/rust/rust-diagnostics.h @@ -70,6 +70,9 @@ extern void rust_error_at (const Location, const char *fmt, ...) RUST_ATTRIBUTE_GCC_DIAG (2, 3); extern void +rust_error_at (const Location, const ErrorCode, const char *fmt, ...) + RUST_ATTRIBUTE_GCC_DIAG (3, 4); +extern void rust_warning_at (const Location, int opt, const char *fmt, ...) RUST_ATTRIBUTE_GCC_DIAG (3, 4); extern void @@ -110,6 +113,9 @@ rust_be_internal_error_at (const Location, const std::string &errmsg) extern void rust_be_error_at (const Location, const std::string &errmsg); extern void +rust_be_error_at (const Location, const ErrorCode, + const std::string &errmsg); +extern void rust_be_error_at (const RichLocation &, const std::string &errmsg); extern void rust_be_error_at (const RichLocation &, const ErrorCode, -- 2.47.2