aboutsummaryrefslogtreecommitdiff
path: root/libgrust
diff options
context:
space:
mode:
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>2023-05-26 18:03:28 +0200
committerArthur Cohen <arthur.cohen@embecosm.com>2024-01-16 18:37:23 +0100
commite4b769cb0a196b3410b4da5e4415b634b4429399 (patch)
tree93013ba6daad2198ba86b1af600638f552cf91b4 /libgrust
parent007248a2c48ef3c349204899b325bab574019734 (diff)
downloadgcc-e4b769cb0a196b3410b4da5e4415b634b4429399.zip
gcc-e4b769cb0a196b3410b4da5e4415b634b4429399.tar.gz
gcc-e4b769cb0a196b3410b4da5e4415b634b4429399.tar.bz2
gccrs: libproc_macro: Add Span definition
Add Span type definition in the rust interface. libgrust/ChangeLog: * libproc_macro/rust/bridge/group.rs: Add span member to the Group structure. * libproc_macro/rust/bridge/ident.rs: Likewise with the Ident structure. * libproc_macro/rust/bridge/literal.rs: Likewise with the Literal structure. * libproc_macro/rust/bridge/punct.rs: Likewise with the Punct structure. * libproc_macro/rust/bridge/span.rs: Add span internals. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Diffstat (limited to 'libgrust')
-rw-r--r--libgrust/libproc_macro/rust/bridge/group.rs9
-rw-r--r--libgrust/libproc_macro/rust/bridge/ident.rs17
-rw-r--r--libgrust/libproc_macro/rust/bridge/literal.rs20
-rw-r--r--libgrust/libproc_macro/rust/bridge/punct.rs4
-rw-r--r--libgrust/libproc_macro/rust/bridge/span.rs20
5 files changed, 48 insertions, 22 deletions
diff --git a/libgrust/libproc_macro/rust/bridge/group.rs b/libgrust/libproc_macro/rust/bridge/group.rs
index 83d2e06..254a3db 100644
--- a/libgrust/libproc_macro/rust/bridge/group.rs
+++ b/libgrust/libproc_macro/rust/bridge/group.rs
@@ -8,11 +8,16 @@ use Delimiter;
pub struct Group {
delimiter: Delimiter,
stream: TokenStream,
+ span: Span,
}
impl Group {
pub fn new(delimiter: Delimiter, stream: TokenStream) -> Self {
- Group { delimiter, stream }
+ Group {
+ delimiter,
+ stream,
+ span: Span::default(),
+ }
}
pub fn delimiter(&self) -> Delimiter {
@@ -20,7 +25,7 @@ impl Group {
}
pub fn span(&self) -> Span {
- Span {}
+ self.span
}
pub fn set_span(&mut self, span: Span) {
diff --git a/libgrust/libproc_macro/rust/bridge/ident.rs b/libgrust/libproc_macro/rust/bridge/ident.rs
index 04169a4..4218921 100644
--- a/libgrust/libproc_macro/rust/bridge/ident.rs
+++ b/libgrust/libproc_macro/rust/bridge/ident.rs
@@ -4,8 +4,8 @@ use std::ffi::c_uchar;
use std::fmt;
extern "C" {
- fn Ident__new(string: *const c_uchar, len: u64) -> Ident;
- fn Ident__new_raw(string: *const c_uchar, len: u64) -> Ident;
+ fn Ident__new(string: *const c_uchar, len: u64, span: Span) -> Ident;
+ fn Ident__new_raw(string: *const c_uchar, len: u64, span: Span) -> Ident;
fn Ident__drop(ident: *mut Ident);
fn Ident__clone(ident: *const Ident) -> Ident;
}
@@ -16,23 +16,24 @@ pub struct Ident {
pub(crate) is_raw: bool,
pub(crate) val: *const c_uchar,
len: u64,
+ span: Span,
}
impl Ident {
- pub fn new(string: &str, _span: Span) -> Self {
- unsafe { Ident__new(string.as_ptr(), string.len().try_into().unwrap()) }
+ pub fn new(string: &str, span: Span) -> Self {
+ unsafe { Ident__new(string.as_ptr(), string.len().try_into().unwrap(), span) }
}
- pub fn new_raw(string: &str, _span: Span) -> Self {
- unsafe { Ident__new_raw(string.as_ptr(), string.len().try_into().unwrap()) }
+ pub fn new_raw(string: &str, span: Span) -> Self {
+ unsafe { Ident__new_raw(string.as_ptr(), string.len().try_into().unwrap(), span) }
}
pub fn span(&self) -> Span {
- Span {}
+ self.span
}
pub fn set_span(&mut self, span: Span) {
- let _ = span;
+ self.span = span;
}
}
diff --git a/libgrust/libproc_macro/rust/bridge/literal.rs b/libgrust/libproc_macro/rust/bridge/literal.rs
index f54bfe2..b03e363 100644
--- a/libgrust/libproc_macro/rust/bridge/literal.rs
+++ b/libgrust/libproc_macro/rust/bridge/literal.rs
@@ -29,7 +29,7 @@ pub struct Literal {
kind: LitKind,
text: FFIString,
suffix: FFIString,
- // FIXME: Add span, cannot add whilst Span remain an empty type
+ span: Span,
}
macro_rules! suffixed_int_literals {
@@ -38,7 +38,8 @@ macro_rules! suffixed_int_literals {
Literal {
kind : LitKind::Integer,
text: FFIString::from(&n.to_string()),
- suffix: FFIString::from(stringify!($kind))
+ suffix: FFIString::from(stringify!($kind)),
+ span: Span::default(),
}
}
)*)
@@ -50,7 +51,8 @@ macro_rules! unsuffixed_int_literals {
Literal {
kind : LitKind::Integer,
text: FFIString::from(&n.to_string()),
- suffix: FFIString::from("")
+ suffix: FFIString::from(""),
+ span: Span::default(),
}
}
)*)
@@ -97,6 +99,7 @@ impl Literal {
kind: LitKind::Float,
text: FFIString::from(&repr),
suffix: FFIString::from(""),
+ span: Span::default(),
}
}
@@ -105,6 +108,7 @@ impl Literal {
kind: LitKind::Float,
text: FFIString::from(&n.to_string()),
suffix: FFIString::from("f32"),
+ span: Span::default(),
}
}
@@ -118,6 +122,7 @@ impl Literal {
kind: LitKind::Float,
text: FFIString::from(&repr),
suffix: FFIString::from(""),
+ span: Span::default(),
}
}
@@ -126,6 +131,7 @@ impl Literal {
kind: LitKind::Float,
text: FFIString::from(&n.to_string()),
suffix: FFIString::from("f64"),
+ span: Span::default(),
}
}
@@ -134,6 +140,7 @@ impl Literal {
kind: LitKind::Str,
text: FFIString::from(string),
suffix: FFIString::from(""),
+ span: Span::default(),
}
}
@@ -142,6 +149,7 @@ impl Literal {
kind: LitKind::Char,
text: FFIString::from(&c.to_string()),
suffix: FFIString::from(""),
+ span: Span::default(),
}
}
@@ -150,15 +158,16 @@ impl Literal {
kind: LitKind::ByteStr,
text: FFIString::from(&bytes.escape_ascii().to_string()),
suffix: FFIString::from(""),
+ span: Span::default(),
}
}
pub fn span(&self) -> Span {
- Span {}
+ self.span
}
pub fn set_span(&mut self, span: Span) {
- let _ = span;
+ self.span = span;
}
}
@@ -221,6 +230,7 @@ impl FromStr for Literal {
kind: LitKind::Err,
text: FFIString::from(""),
suffix: FFIString::from(""),
+ span: Span::default(),
};
// TODO: We might want to pass a LexError by reference to retrieve
// error information
diff --git a/libgrust/libproc_macro/rust/bridge/punct.rs b/libgrust/libproc_macro/rust/bridge/punct.rs
index f5f76b1..e835472 100644
--- a/libgrust/libproc_macro/rust/bridge/punct.rs
+++ b/libgrust/libproc_macro/rust/bridge/punct.rs
@@ -8,6 +8,7 @@ use Spacing;
pub struct Punct {
pub(crate) ch: u32,
pub(crate) spacing: Spacing,
+ span: Span,
}
impl Punct {
@@ -15,11 +16,12 @@ impl Punct {
Punct {
ch: ch.into(),
spacing,
+ span: Span::default(),
}
}
pub fn span(&self) -> Span {
- Span {}
+ self.span
}
pub fn set_span(&mut self, span: Span) {
diff --git a/libgrust/libproc_macro/rust/bridge/span.rs b/libgrust/libproc_macro/rust/bridge/span.rs
index 5bbdd5a..06537c9 100644
--- a/libgrust/libproc_macro/rust/bridge/span.rs
+++ b/libgrust/libproc_macro/rust/bridge/span.rs
@@ -5,28 +5,36 @@
//! All methods accessing source location in rust are unstable, hence this
//! implementation with an empty structure.
-#[derive(Copy, Clone, Debug)]
+/// # Note: Gcc does not have a span interner, a span will not contain an index
+#[derive(Copy, Clone, Debug, Default)]
#[repr(C)]
-pub struct Span {}
+pub struct Span {
+ location: u32,
+}
impl Span {
pub fn call_site() -> Self {
- Span {}
+ // FIXME: implement this function properly
+ Span::default()
}
pub fn mixed_site() -> Self {
- Span {}
+ // FIXME: implement this function properly
+ Span::default()
}
pub fn resolved_at(&self, _other: Span) -> Self {
- Span {}
+ // FIXME: implement this function properly
+ Span::default()
}
pub fn located_at(&self, _other: Span) -> Self {
- Span {}
+ // FIXME: implement this function properly
+ Span::default()
}
pub fn source_text(&self) -> Option<String> {
+ // FIXME: implement this function properly
None
}
}