aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>2023-02-16 18:33:07 +0100
committerPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>2023-03-30 13:52:30 +0200
commitdc4f537942ee67079526e06528a9f0823ee81bf1 (patch)
tree7b4bf3f8ec18b289ab205d1aff83c3d88a0ea4d6
parent896533bfff4b29042000d7b4813e6fa3cf30a1c6 (diff)
downloadgcc-dc4f537942ee67079526e06528a9f0823ee81bf1.zip
gcc-dc4f537942ee67079526e06528a9f0823ee81bf1.tar.gz
gcc-dc4f537942ee67079526e06528a9f0823ee81bf1.tar.bz2
libproc_macro: Add TokenTree implementation
Add most parts of TokenTree type implementation. ChangeLog: * librust/proc_macro/rust/lib.rs: Add TokenTree implementation. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
-rw-r--r--librust/proc_macro/rust/lib.rs50
1 files changed, 35 insertions, 15 deletions
diff --git a/librust/proc_macro/rust/lib.rs b/librust/proc_macro/rust/lib.rs
index f749530..48e1bcd 100644
--- a/librust/proc_macro/rust/lib.rs
+++ b/librust/proc_macro/rust/lib.rs
@@ -37,7 +37,12 @@ pub enum TokenTree {
impl TokenTree {
/// Get the [`Span`] for this TokenTree.
pub fn span(&self) -> Span {
- todo!("Implement this function")
+ match self {
+ TokenTree::Group(group) => group.span(),
+ TokenTree::Ident(ident) => ident.span(),
+ TokenTree::Punct(punct) => punct.span(),
+ TokenTree::Literal(literal) => literal.span(),
+ }
}
/// Set the span for this TokenTree.
@@ -45,44 +50,59 @@ impl TokenTree {
/// # 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) {
+ match self {
+ TokenTree::Group(group) => group.set_span(span),
+ TokenTree::Ident(ident) => ident.set_span(span),
+ TokenTree::Punct(punct) => punct.set_span(span),
+ TokenTree::Literal(literal) => literal.set_span(span),
+ }
}
}
impl fmt::Debug for TokenTree {
- fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result {
- todo!("Implement this function")
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ match self {
+ TokenTree::Group(group) => group.fmt(f),
+ TokenTree::Ident(ident) => ident.fmt(f),
+ TokenTree::Punct(punct) => punct.fmt(f),
+ TokenTree::Literal(literal) => literal.fmt(f),
+ }
}
}
impl fmt::Display for TokenTree {
- fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result {
- todo!("Implement this function")
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ match self {
+ TokenTree::Group(group) => group.fmt(f),
+ TokenTree::Ident(ident) => ident.fmt(f),
+ TokenTree::Punct(punct) => punct.fmt(f),
+ TokenTree::Literal(literal) => literal.fmt(f),
+ }
}
}
impl From<Group> for TokenTree {
- fn from(_g: Group) -> Self {
- todo!("Implement this function")
+ fn from(g: Group) -> Self {
+ TokenTree::Group(g)
}
}
impl From<Ident> for TokenTree {
- fn from(_i: Ident) -> Self {
- todo!("Implement this function")
+ fn from(i: Ident) -> Self {
+ TokenTree::Ident(i)
}
}
impl From<Punct> for TokenTree {
- fn from(_p: Punct) -> Self {
- todo!("Implement this function")
+ fn from(p: Punct) -> Self {
+ TokenTree::Punct(p)
}
}
impl From<Literal> for TokenTree {
- fn from(_l: Literal) -> Self {
- todo!("Implement this function")
+ fn from(l: Literal) -> Self {
+ TokenTree::Literal(l)
}
}