aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>2023-02-21 09:48:16 +0100
committerPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>2023-03-30 13:52:32 +0200
commit252f019e6c046e97e11b0906d78e9b7ace115c51 (patch)
tree49a96fdf4310e3fcfa1ba04b028b3e631a40969d
parent834f9425327768a02383109ce9aa3b1c8a67a822 (diff)
downloadgcc-252f019e6c046e97e11b0906d78e9b7ace115c51.zip
gcc-252f019e6c046e97e11b0906d78e9b7ace115c51.tar.gz
gcc-252f019e6c046e97e11b0906d78e9b7ace115c51.tar.bz2
libproc_macro: Implement FromStr on bridge Literal
Implement the trait FromStr on the internal rust Literal type. ChangeLog: * librust/proc_macro/rust/bridge/literal.rs: Implement FromStr. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
-rw-r--r--librust/proc_macro/rust/bridge/literal.rs18
1 files changed, 18 insertions, 0 deletions
diff --git a/librust/proc_macro/rust/bridge/literal.rs b/librust/proc_macro/rust/bridge/literal.rs
index b5be799..27aa2ef 100644
--- a/librust/proc_macro/rust/bridge/literal.rs
+++ b/librust/proc_macro/rust/bridge/literal.rs
@@ -2,11 +2,14 @@ use bridge::span::Span;
use std::convert::{TryFrom, TryInto};
use std::ffi::c_uchar;
use std::fmt;
+use std::str::FromStr;
+use LexError;
extern "C" {
fn Literal__drop(literal: *const Literal);
fn Literal__string(str: *const c_uchar) -> Literal;
fn Literal__byte_string(bytes: *const u8) -> Literal;
+ fn Literal__from_string(str: *const c_uchar, lit: *mut Literal) -> bool;
}
#[repr(C)]
@@ -359,3 +362,18 @@ impl fmt::Display for Literal {
Ok(())
}
}
+
+impl FromStr for Literal {
+ type Err = LexError;
+
+ fn from_str(string: &str) -> Result<Self, LexError> {
+ let mut lit = Literal::Char(0);
+ // TODO: We might want to pass a LexError by reference to retrieve
+ // error information
+ if unsafe { Literal__from_string(string.as_ptr(), &mut lit as *mut Literal) } {
+ Err(LexError)
+ } else {
+ Ok(lit)
+ }
+ }
+}