aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>2023-02-20 16:49:06 +0100
committerPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>2023-03-30 13:52:31 +0200
commit9eaf139ee7bb743422ed9c32d153185e125194f9 (patch)
tree2d3383b99b30dbac5cefce9eb1a99f7b7f3c9df4
parent1364b17a02f0353aee82e7ef37fcb48d97b5ec97 (diff)
downloadgcc-9eaf139ee7bb743422ed9c32d153185e125194f9.zip
gcc-9eaf139ee7bb743422ed9c32d153185e125194f9.tar.gz
gcc-9eaf139ee7bb743422ed9c32d153185e125194f9.tar.bz2
libproc_macro: Add Group implementation
Add Group rust structure implementation in libproc_macro. ChangeLog: * librust/proc_macro/rust/bridge/group.rs: Add internal Group implementation. * librust/proc_macro/rust/group.rs: Add Group implementation. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
-rw-r--r--librust/proc_macro/rust/bridge/group.rs28
-rw-r--r--librust/proc_macro/rust/group.rs18
2 files changed, 35 insertions, 11 deletions
diff --git a/librust/proc_macro/rust/bridge/group.rs b/librust/proc_macro/rust/bridge/group.rs
index 12c1b60..83d2e06 100644
--- a/librust/proc_macro/rust/bridge/group.rs
+++ b/librust/proc_macro/rust/bridge/group.rs
@@ -1,4 +1,5 @@
-use bridge;
+use bridge::span::Span;
+use bridge::token_stream::TokenStream;
use std::fmt;
use Delimiter;
@@ -6,8 +7,31 @@ use Delimiter;
#[derive(Debug, Clone)]
pub struct Group {
delimiter: Delimiter,
- stream: bridge::token_stream::TokenStream,
+ stream: TokenStream,
}
+
+impl Group {
+ pub fn new(delimiter: Delimiter, stream: TokenStream) -> Self {
+ Group { delimiter, stream }
+ }
+
+ pub fn delimiter(&self) -> Delimiter {
+ self.delimiter
+ }
+
+ pub fn span(&self) -> Span {
+ Span {}
+ }
+
+ pub fn set_span(&mut self, span: Span) {
+ let _ = span;
+ }
+
+ pub fn stream(&self) -> TokenStream {
+ self.stream.clone()
+ }
+}
+
impl fmt::Display for Group {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self.delimiter {
diff --git a/librust/proc_macro/rust/group.rs b/librust/proc_macro/rust/group.rs
index 224fbad..29bfb9d 100644
--- a/librust/proc_macro/rust/group.rs
+++ b/librust/proc_macro/rust/group.rs
@@ -28,13 +28,13 @@ impl Group {
///
/// * `delimiter` - The delimiter surrounding the inner [`TokenStream`].
/// * `stream` - The tokenstream for this `Group`.
- pub fn new(_delimiter: Delimiter, _stream: TokenStream) -> Self {
- todo!("Implement this function")
+ pub fn new(delimiter: Delimiter, stream: TokenStream) -> Self {
+ Group(bridge::group::Group::new(delimiter, stream.0))
}
/// Get the delimiter of the `Group`.
pub fn delimiter(&self) -> Delimiter {
- todo!("Implement this function")
+ self.0.delimiter()
}
/// Get the stream of the `Group`.
@@ -43,23 +43,23 @@ impl Group {
///
/// The returned stream does not include the delimiters of this group.
pub fn stream(&self) -> TokenStream {
- todo!("Implement this function")
+ TokenStream(self.0.stream())
}
/// Get the span for the delimiters of this token stream, spanning the
/// entire group.
pub fn span(&self) -> Span {
- todo!("Implement this function")
+ Span(self.0.span())
}
/// Get the span pointing to the opening delimiter of this `Group`.
pub fn span_open(&self) -> Span {
- todo!("Implement this function")
+ Span(self.0.span())
}
/// Get the span pointing to the closing delimiter of this `Group`.
pub fn span_close(&self) -> Span {
- todo!("Implement this function")
+ Span(self.0.span())
}
/// Change the span for this `Group`'s delimiters, but not its internal
@@ -70,8 +70,8 @@ impl Group {
/// This method will **not** set the span of all the internal tokens spanned
/// by this group, but rather it will only set the span of the delimiter
/// tokens at the level of the `Group`.
- pub fn set_span(&mut self, _span: Span) {
- todo!("Implement this function")
+ pub fn set_span(&mut self, span: Span) {
+ self.0.set_span(span.0)
}
}