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>
This commit is contained in:
Pierre-Emmanuel Patry 2023-05-26 18:03:28 +02:00 committed by Arthur Cohen
parent 007248a2c4
commit e4b769cb0a
5 changed files with 48 additions and 22 deletions

View File

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

View File

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

View File

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

View File

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

View File

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