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>
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 {
}
pub fn span(&self) -> Span {
- Span {}
+ self.span
}
pub fn set_span(&mut self, span: Span) {
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;
}
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;
}
}
kind: LitKind,
text: FFIString,
suffix: FFIString,
- // FIXME: Add span, cannot add whilst Span remain an empty type
+ span: Span,
}
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(),
}
}
)*)
Literal {
kind : LitKind::Integer,
text: FFIString::from(&n.to_string()),
- suffix: FFIString::from("")
+ suffix: FFIString::from(""),
+ span: Span::default(),
}
}
)*)
kind: LitKind::Float,
text: FFIString::from(&repr),
suffix: FFIString::from(""),
+ span: Span::default(),
}
}
kind: LitKind::Float,
text: FFIString::from(&n.to_string()),
suffix: FFIString::from("f32"),
+ span: Span::default(),
}
}
kind: LitKind::Float,
text: FFIString::from(&repr),
suffix: FFIString::from(""),
+ span: Span::default(),
}
}
kind: LitKind::Float,
text: FFIString::from(&n.to_string()),
suffix: FFIString::from("f64"),
+ span: Span::default(),
}
}
kind: LitKind::Str,
text: FFIString::from(string),
suffix: FFIString::from(""),
+ span: Span::default(),
}
}
kind: LitKind::Char,
text: FFIString::from(&c.to_string()),
suffix: FFIString::from(""),
+ span: Span::default(),
}
}
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;
}
}
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
pub struct Punct {
pub(crate) ch: u32,
pub(crate) spacing: Spacing,
+ span: Span,
}
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) {
//! 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
}
}