aboutsummaryrefslogtreecommitdiff
path: root/libgrust
diff options
context:
space:
mode:
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>2023-05-11 12:35:18 +0200
committerArthur Cohen <arthur.cohen@embecosm.com>2024-01-16 18:37:20 +0100
commit4689998556b6190ab9333580725f796704e104f1 (patch)
tree011f465bfdfed8a349262d18a3cc0cad0b65290e /libgrust
parentf730dff1738a93b0bd6f4f82cca04689e7f52187 (diff)
downloadgcc-4689998556b6190ab9333580725f796704e104f1.zip
gcc-4689998556b6190ab9333580725f796704e104f1.tar.gz
gcc-4689998556b6190ab9333580725f796704e104f1.tar.bz2
gccrs: libproc_macro: Remove has_suffix attribute
This variable was redundant with the empty string representation and may have lead to desync between both. libgrust/ChangeLog: * libproc_macro/literal.h: Remove has_suffix member attribute from Literal. * libproc_macro/literal.cc: Update constructors. * libproc_macro/rust/bridge/literal.rs: Remove has_suffix attribute from Literal. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Diffstat (limited to 'libgrust')
-rw-r--r--libgrust/libproc_macro/literal.cc35
-rw-r--r--libgrust/libproc_macro/literal.h2
-rw-r--r--libgrust/libproc_macro/rust/bridge/literal.rs15
3 files changed, 19 insertions, 33 deletions
diff --git a/libgrust/libproc_macro/literal.cc b/libgrust/libproc_macro/literal.cc
index e3d171f..af1632b 100644
--- a/libgrust/libproc_macro/literal.cc
+++ b/libgrust/libproc_macro/literal.cc
@@ -46,8 +46,7 @@ Literal::drop (Literal *lit)
Literal
Literal::clone () const
{
- return {this->kind, this->text.clone (), this->has_suffix,
- this->suffix.clone ()};
+ return {this->kind, this->text.clone (), this->suffix.clone ()};
}
Literal
@@ -56,7 +55,7 @@ Literal::make_literal (LitKind kind, const std::string &text,
{
auto ffi_text = FFIString::make_ffistring (text);
auto ffi_suffix = FFIString::make_ffistring (suffix);
- return {kind, ffi_text, suffix != "", ffi_suffix};
+ return {kind, ffi_text, ffi_suffix};
}
Literal
@@ -64,7 +63,7 @@ Literal::make_u8 (std::uint8_t value, bool suffixed)
{
auto text = FFIString::make_ffistring (std::to_string (value));
auto suffix = FFIString::make_ffistring (suffixed ? "u8" : "");
- return {LitKind::make_integer (), text, suffixed, suffix};
+ return {LitKind::make_integer (), text, suffix};
}
Literal
@@ -72,7 +71,7 @@ Literal::make_u16 (std::uint16_t value, bool suffixed)
{
auto text = FFIString::make_ffistring (std::to_string (value));
auto suffix = FFIString::make_ffistring (suffixed ? "u16" : "");
- return {LitKind::make_integer (), text, suffixed, suffix};
+ return {LitKind::make_integer (), text, suffix};
}
Literal
@@ -80,7 +79,7 @@ Literal::make_u32 (std::uint32_t value, bool suffixed)
{
auto text = FFIString::make_ffistring (std::to_string (value));
auto suffix = FFIString::make_ffistring (suffixed ? "u32" : "");
- return {LitKind::make_integer (), text, suffixed, suffix};
+ return {LitKind::make_integer (), text, suffix};
}
Literal
@@ -88,7 +87,7 @@ Literal::make_u64 (std::uint64_t value, bool suffixed)
{
auto text = FFIString::make_ffistring (std::to_string (value));
auto suffix = FFIString::make_ffistring (suffixed ? "u64" : "");
- return {LitKind::make_integer (), text, suffixed, suffix};
+ return {LitKind::make_integer (), text, suffix};
}
Literal
@@ -96,7 +95,7 @@ Literal::make_i8 (std::int8_t value, bool suffixed)
{
auto text = FFIString::make_ffistring (std::to_string (value));
auto suffix = FFIString::make_ffistring (suffixed ? "i8" : "");
- return {LitKind::make_integer (), text, suffixed, suffix};
+ return {LitKind::make_integer (), text, suffix};
}
Literal
@@ -104,7 +103,7 @@ Literal::make_i16 (std::int16_t value, bool suffixed)
{
auto text = FFIString::make_ffistring (std::to_string (value));
auto suffix = FFIString::make_ffistring (suffixed ? "i16" : "");
- return {LitKind::make_integer (), text, suffixed, suffix};
+ return {LitKind::make_integer (), text, suffix};
}
Literal
@@ -112,7 +111,7 @@ Literal::make_i32 (std::int32_t value, bool suffixed)
{
auto text = FFIString::make_ffistring (std::to_string (value));
auto suffix = FFIString::make_ffistring (suffixed ? "i32" : "");
- return {LitKind::make_integer (), text, suffixed, suffix};
+ return {LitKind::make_integer (), text, suffix};
}
Literal
@@ -120,7 +119,7 @@ Literal::make_i64 (std::int64_t value, bool suffixed)
{
auto text = FFIString::make_ffistring (std::to_string (value));
auto suffix = FFIString::make_ffistring (suffixed ? "i64" : "");
- return {LitKind::make_integer (), text, suffixed, suffix};
+ return {LitKind::make_integer (), text, suffix};
}
Literal
@@ -128,7 +127,7 @@ Literal::make_string (const std::string &str)
{
auto text = FFIString::make_ffistring (str);
auto suffix = FFIString::make_ffistring ("");
- return {LitKind::make_str (), text, false, suffix};
+ return {LitKind::make_str (), text, suffix};
}
Literal
@@ -137,7 +136,7 @@ Literal::make_byte_string (const std::vector<std::uint8_t> &vec)
auto text
= FFIString::make_ffistring (std::string (vec.cbegin (), vec.cend ()));
auto suffix = FFIString::make_ffistring ("");
- return {LitKind::make_byte_str (), text, false, suffix};
+ return {LitKind::make_byte_str (), text, suffix};
}
Literal
@@ -145,7 +144,7 @@ Literal::make_f32 (float value, bool suffixed)
{
auto text = FFIString::make_ffistring (std::to_string (value));
auto suffix = FFIString::make_ffistring (suffixed ? "f32" : "");
- return {LitKind::make_float (), text, suffixed, suffix};
+ return {LitKind::make_float (), text, suffix};
}
Literal
@@ -153,7 +152,7 @@ Literal::make_f64 (double value, bool suffixed)
{
auto text = FFIString::make_ffistring (std::to_string (value));
auto suffix = FFIString::make_ffistring (suffixed ? "f64" : "");
- return {LitKind::make_float (), text, suffixed, suffix};
+ return {LitKind::make_float (), text, suffix};
}
Literal
@@ -161,7 +160,7 @@ Literal::make_char (std::uint32_t ch)
{
auto text = FFIString::make_ffistring (std::to_string ((char) ch));
auto suffix = FFIString::make_ffistring ("");
- return {LitKind::make_char (), text, false, suffix};
+ return {LitKind::make_char (), text, suffix};
}
Literal
@@ -169,7 +168,7 @@ Literal::make_usize (std::uint64_t value, bool suffixed)
{
auto text = FFIString::make_ffistring (std::to_string (value));
auto suffix = FFIString::make_ffistring (suffixed ? "usize" : "");
- return {LitKind::make_integer (), text, suffixed, suffix};
+ return {LitKind::make_integer (), text, suffix};
}
Literal
@@ -177,7 +176,7 @@ Literal::make_isize (std::int64_t value, bool suffixed)
{
auto text = FFIString::make_ffistring (std::to_string (value));
auto suffix = FFIString::make_ffistring (suffixed ? "isize" : "");
- return {LitKind::make_integer (), text, suffixed, suffix};
+ return {LitKind::make_integer (), text, suffix};
}
LitKind
diff --git a/libgrust/libproc_macro/literal.h b/libgrust/libproc_macro/literal.h
index fa2df3f..86b1a17 100644
--- a/libgrust/libproc_macro/literal.h
+++ b/libgrust/libproc_macro/literal.h
@@ -69,12 +69,12 @@ struct Literal
{
LitKind kind;
FFIString text;
- bool has_suffix;
FFIString suffix;
// TODO: Add span once done in rust interface
public:
Literal clone () const;
+ bool has_suffix () const { return suffix.len != 0; };
static Literal make_literal (const LitKind kind, const std::string &text,
const std::string &suffix = "");
diff --git a/libgrust/libproc_macro/rust/bridge/literal.rs b/libgrust/libproc_macro/rust/bridge/literal.rs
index 945311a..1e15012 100644
--- a/libgrust/libproc_macro/rust/bridge/literal.rs
+++ b/libgrust/libproc_macro/rust/bridge/literal.rs
@@ -28,7 +28,6 @@ pub enum LitKind {
pub struct Literal {
kind: LitKind,
text: FFIString,
- has_suffix: bool,
suffix: FFIString,
// FIXME: Add span, cannot add whilst Span remain an empty type
}
@@ -39,7 +38,6 @@ macro_rules! suffixed_int_literals {
Literal {
kind : LitKind::Integer,
text: FFIString::new(&n.to_string()),
- has_suffix : true,
suffix: FFIString::new(stringify!($kind))
}
}
@@ -52,7 +50,6 @@ macro_rules! unsuffixed_int_literals {
Literal {
kind : LitKind::Integer,
text: FFIString::new(&n.to_string()),
- has_suffix : false,
suffix: FFIString::new("")
}
}
@@ -99,7 +96,6 @@ impl Literal {
Literal {
kind: LitKind::Float,
text: FFIString::new(&repr),
- has_suffix: false,
suffix: FFIString::new(""),
}
}
@@ -108,7 +104,6 @@ impl Literal {
Literal {
kind: LitKind::Float,
text: FFIString::new(&n.to_string()),
- has_suffix: true,
suffix: FFIString::new("f32"),
}
}
@@ -122,7 +117,6 @@ impl Literal {
Literal {
kind: LitKind::Float,
text: FFIString::new(&repr),
- has_suffix: false,
suffix: FFIString::new(""),
}
}
@@ -131,7 +125,6 @@ impl Literal {
Literal {
kind: LitKind::Float,
text: FFIString::new(&n.to_string()),
- has_suffix: true,
suffix: FFIString::new("f64"),
}
}
@@ -140,7 +133,6 @@ impl Literal {
Literal {
kind: LitKind::Str,
text: FFIString::new(string),
- has_suffix: false,
suffix: FFIString::new(""),
}
}
@@ -149,7 +141,6 @@ impl Literal {
Literal {
kind: LitKind::Char,
text: FFIString::new(&c.to_string()),
- has_suffix: false,
suffix: FFIString::new(""),
}
}
@@ -158,7 +149,6 @@ impl Literal {
Literal {
kind: LitKind::ByteStr,
text: FFIString::new(&bytes.escape_ascii().to_string()),
- has_suffix: false,
suffix: FFIString::new(""),
}
}
@@ -217,9 +207,7 @@ impl fmt::Display for Literal {
_ => f.write_str(text)?,
}
- if self.has_suffix {
- f.write_str(&self.suffix.to_string())?;
- }
+ f.write_str(&self.suffix.to_string())?;
Ok(())
}
}
@@ -232,7 +220,6 @@ impl FromStr for Literal {
let mut lit = Literal {
kind: LitKind::Err,
text: FFIString::new(""),
- has_suffix: false,
suffix: FFIString::new(""),
};
// TODO: We might want to pass a LexError by reference to retrieve