aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>2023-02-15 17:57:09 +0100
committerPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>2023-03-30 13:52:30 +0200
commit905cf7298dea48f6b354ec98810b91f9b16c0541 (patch)
tree6044c6f67151c02fe6dc57e60853a085b6fe6359
parent95016480c62e0c26d0456282344f48a55ce74f3c (diff)
downloadgcc-905cf7298dea48f6b354ec98810b91f9b16c0541.zip
gcc-905cf7298dea48f6b354ec98810b91f9b16c0541.tar.gz
gcc-905cf7298dea48f6b354ec98810b91f9b16c0541.tar.bz2
libproc_macro: Add Punct rust type implementation
Add the implementation for the Punct rust type in libproc_macro. ChangeLog: * librust/proc_macro/rust/bridge.rs: Add punct module. * librust/proc_macro/rust/punct.rs: Add Punct bridge. * librust/proc_macro/rust/bridge/punct.rs: Add Punct internals. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
-rw-r--r--librust/proc_macro/rust/bridge.rs1
-rw-r--r--librust/proc_macro/rust/bridge/punct.rs23
-rw-r--r--librust/proc_macro/rust/punct.rs32
3 files changed, 40 insertions, 16 deletions
diff --git a/librust/proc_macro/rust/bridge.rs b/librust/proc_macro/rust/bridge.rs
index 33d0914..b3b28c0 100644
--- a/librust/proc_macro/rust/bridge.rs
+++ b/librust/proc_macro/rust/bridge.rs
@@ -1,2 +1,3 @@
pub mod ident;
+pub mod punct;
pub mod span;
diff --git a/librust/proc_macro/rust/bridge/punct.rs b/librust/proc_macro/rust/bridge/punct.rs
new file mode 100644
index 0000000..57487ea
--- /dev/null
+++ b/librust/proc_macro/rust/bridge/punct.rs
@@ -0,0 +1,23 @@
+use bridge::span::Span;
+use Spacing;
+
+#[repr(C)]
+#[derive(Clone, Debug)]
+pub struct Punct {
+ pub(crate) ch: char,
+ pub(crate) spacing: Spacing,
+}
+
+impl Punct {
+ pub fn new(ch: char, spacing: Spacing) -> Self {
+ Punct { ch, spacing }
+ }
+
+ pub fn span(&self) -> Span {
+ Span {}
+ }
+
+ pub fn set_span(&mut self, span: Span) {
+ let _ = span;
+ }
+}
diff --git a/librust/proc_macro/rust/punct.rs b/librust/proc_macro/rust/punct.rs
index 24d6acb..cbd64fc 100644
--- a/librust/proc_macro/rust/punct.rs
+++ b/librust/proc_macro/rust/punct.rs
@@ -1,7 +1,9 @@
+use bridge;
use std::fmt;
use Span;
/// Describes the context of a [`Punct`] relatively to the next token.
+#[repr(C)]
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum Spacing {
/// A [`Punct`] is not immediately followed by another `Punct`.
@@ -16,9 +18,7 @@ pub enum Spacing {
/// Multi-character operators like `+=` are represented as two instances of
/// `Punct` with different forms of `Spacing` returned.
#[derive(Clone)]
-pub struct Punct {
- // Internal implementation details.
-}
+pub struct Punct(pub(crate) bridge::punct::Punct);
impl Punct {
/// Creates a new `Punct` from a given character and spacing.
@@ -32,25 +32,25 @@ impl Punct {
///
/// This function will panic if the `ch` argument is not a valid
/// punctuation character allowed by the language.
- pub fn new(_ch: char, _spacing: Spacing) -> Self {
- todo!("Implement this function")
+ pub fn new(ch: char, spacing: Spacing) -> Self {
+ Punct(bridge::punct::Punct::new(ch, spacing))
}
/// Get the value for this punctuation character as `char`.
pub fn as_char(&self) -> char {
- todo!("Implement this function")
+ self.0.ch
}
/// Get the [`Spacing`] of this punctuation character, indicating whether
/// the following character can be combined into a multi-character operator
/// or not.
pub fn spacing(&self) -> Spacing {
- todo!("Implement this function")
+ self.0.spacing
}
/// Get the [`Span`] for this punctuation character.
pub fn span(&self) -> Span {
- todo!("Implement this function")
+ Span(self.0.span())
}
/// Set the span for this punctuation character.
@@ -58,8 +58,8 @@ impl Punct {
/// # Arguments
///
/// * `span` - The new span value.
- 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);
}
}
@@ -70,19 +70,19 @@ impl fmt::Display for Punct {
}
impl fmt::Debug for Punct {
- fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result {
- todo!("Implement this function")
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ self.0.fmt(f)
}
}
impl PartialEq<char> for Punct {
- fn eq(&self, _rhs: &char) -> bool {
- todo!("Implement this function")
+ fn eq(&self, rhs: &char) -> bool {
+ self.0.ch == *rhs
}
}
impl PartialEq<Punct> for char {
- fn eq(&self, _rhs: &Punct) -> bool {
- todo!("Implement this function")
+ fn eq(&self, rhs: &Punct) -> bool {
+ *self == rhs.0.ch
}
}