public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] libproc_macro: Add TokenTree implementation
@ 2023-04-06 21:31 Thomas Schwinge
0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2023-04-06 21:31 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:dc4f537942ee67079526e06528a9f0823ee81bf1
commit dc4f537942ee67079526e06528a9f0823ee81bf1
Author: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Date: Thu Feb 16 18:33:07 2023 +0100
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>
Diff:
---
librust/proc_macro/rust/lib.rs | 50 +++++++++++++++++++++++++++++-------------
1 file changed, 35 insertions(+), 15 deletions(-)
diff --git a/librust/proc_macro/rust/lib.rs b/librust/proc_macro/rust/lib.rs
index f74953024b4..48e1bcd7679 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)
}
}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-04-06 21:31 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-06 21:31 [gcc/devel/rust/master] libproc_macro: Add TokenTree implementation Thomas Schwinge
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).