aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>2023-02-10 15:44:47 +0100
committerPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>2023-03-30 13:52:28 +0200
commit570094e524d9b9205eefc42ab3cbffa52b9653c7 (patch)
tree9680c8528e70dc0a8524b1234affd763c20e9047
parentb42b30da3e3c40542a5991fe5123bb3b50b73255 (diff)
downloadgcc-570094e524d9b9205eefc42ab3cbffa52b9653c7.zip
gcc-570094e524d9b9205eefc42ab3cbffa52b9653c7.tar.gz
gcc-570094e524d9b9205eefc42ab3cbffa52b9653c7.tar.bz2
libproc_macro: Move some types to their own module
The file for the rust interfaces became quite long and we could therefore split it in multiple module and reexport their symbol at the root level. This way the code is shorter and well separated whilst keeping the exact same interface as the libproc_macro from rustc. ChangeLog: * librust/proc_macro/rust/lib.rs: Remove somes types. * librust/proc_macro/rust/ident.rs: Add Ident type to it's own module. * librust/proc_macro/rust/literal.rs: Add Literal type to it's own module. * librust/proc_macro/rust/span.rs: Add Span type to it's own module. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
-rw-r--r--librust/proc_macro/rust/ident.rs43
-rw-r--r--librust/proc_macro/rust/lib.rs257
-rw-r--r--librust/proc_macro/rust/literal.rs167
-rw-r--r--librust/proc_macro/rust/span.rs44
4 files changed, 262 insertions, 249 deletions
diff --git a/librust/proc_macro/rust/ident.rs b/librust/proc_macro/rust/ident.rs
new file mode 100644
index 0000000..f9bf814
--- /dev/null
+++ b/librust/proc_macro/rust/ident.rs
@@ -0,0 +1,43 @@
+use std::fmt;
+use Span;
+
+#[derive(Clone)]
+pub struct Ident {
+ // Internal implementation details
+}
+
+impl Ident {
+ /// Creates a new identifier from a string and a span
+ pub fn new(_string: &str, _span: Span) -> Self {
+ todo!("Implement this function")
+ }
+
+ /// Creates a raw new identifier from a string and a span
+ pub fn new_raw(_string: &str, _span: Span) -> Self {
+ todo!("Implement this function")
+ }
+
+ /// Return the span of the identifier
+ pub fn span(&self) -> Span {
+ todo!("Implement this function")
+ }
+
+ /// change the span of the identifier
+ pub fn set_span(&mut self, _span: Span) {
+ todo!("Implement this function")
+ }
+}
+
+impl fmt::Display for Ident {
+ /// Display as lossless converted string
+ fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ todo!("Implement this function")
+ }
+}
+
+impl fmt::Debug for Ident {
+ /// display debug friendly version of the Identifier
+ fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ todo!("Implement this function")
+ }
+}
diff --git a/librust/proc_macro/rust/lib.rs b/librust/proc_macro/rust/lib.rs
index cd53d39..8e7e077 100644
--- a/librust/proc_macro/rust/lib.rs
+++ b/librust/proc_macro/rust/lib.rs
@@ -1,6 +1,12 @@
+pub use ident::Ident;
+pub use literal::Literal;
+pub use span::Span;
use std::error;
use std::fmt;
-use std::str::FromStr;
+
+mod ident;
+mod literal;
+mod span;
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum Delimiter {
@@ -11,264 +17,17 @@ pub enum Delimiter {
None,
}
-#[derive(Copy, Clone)]
-pub struct Span {
- // Internal implementation details
-}
-
-impl Span {
- // TODO: Add experimental API functions for this type
-
- /// Creates a new span that resolves at the macro call location
- pub fn call_site() -> Self {
- todo!("Implement this function")
- }
-
- /// Creates a new span that resolved sometimes at macro call site, and
- /// sometimes at macro definition site
- pub fn mixed_site() -> Self {
- todo!("Implement this function")
- }
-
- /// Creates a new span with the same line/column informations but that
- /// resolve symbols as though it were at `other`
- pub fn resolved_at(&self, other: Span) -> Self {
- todo!("Implement this function")
- }
-
- /// Creates a new span with the same name resolution behavior as self, but
- /// with the line/column information of `other`.
- pub fn located_at(&self, other: Span) -> Self {
- todo!("Implement this function")
- }
-
- /// Return the source text behind a span.
- pub fn source_text(&self) -> Option<String> {
- todo!("Implement this function")
- }
-}
-
-impl fmt::Debug for Span {
- fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- todo!("Implement this function")
- }
-}
-
-#[derive(Clone)]
-pub struct Ident {
- // Internal implementation details
-}
-
-impl Ident {
- /// Creates a new identifier from a string and a span
- pub fn new(string: &str, span: Span) -> Self {
- todo!("Implement this function")
- }
-
- /// Creates a raw new identifier from a string and a span
- pub fn new_raw(string: &str, span: Span) -> Self {
- todo!("Implement this function")
- }
-
- /// Return the span of the identifier
- pub fn span(&self) -> Span {
- todo!("Implement this function")
- }
-
- /// change the span of the identifier
- pub fn set_span(&mut self, span: Span) {
- todo!("Implement this function")
- }
-}
-
-impl fmt::Display for Ident {
- /// Display as lossless converted string
- fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- todo!("Implement this function")
- }
-}
-
-impl fmt::Debug for Ident {
- /// display debug friendly version of the Identifier
- fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- todo!("Implement this function")
- }
-}
-
#[derive(Debug)]
pub struct LexError;
impl fmt::Display for LexError {
- fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result {
todo!("Implement this function")
}
}
impl error::Error for LexError {}
-#[derive(Clone)]
-pub struct Literal {
- // Internal implementation details
-}
-
-impl Literal {
- // TODO: Add experimental API functions for this type
-
- pub fn u8_suffixed(n: u8) -> Self {
- todo!("Implement this function")
- }
-
- pub fn u16_suffixed(n: u16) -> Self {
- todo!("Implement this function")
- }
-
- pub fn u32_suffixed(n: u32) -> Self {
- todo!("Implement this function")
- }
-
- pub fn u64_suffixed(n: u64) -> Self {
- todo!("Implement this function")
- }
-
- pub fn u128_suffixed(n: u128) -> Self {
- todo!("Implement this function")
- }
-
- pub fn usize_suffixed(n: usize) -> Self {
- todo!("Implement this function")
- }
-
- pub fn i8_suffixed(n: i8) -> Self {
- todo!("Implement this function")
- }
-
- pub fn i16_suffixed(n: i16) -> Self {
- todo!("Implement this function")
- }
-
- pub fn i32_suffixed(n: i32) -> Self {
- todo!("Implement this function")
- }
-
- pub fn i64_suffixed(n: i64) -> Self {
- todo!("Implement this function")
- }
-
- pub fn i128_suffixed(n: i128) -> Self {
- todo!("Implement this function")
- }
-
- pub fn isize_suffixed(n: isize) -> Self {
- todo!("Implement this function")
- }
-
- // Unsuffixed
-
- pub fn u8_unsuffixed(n: u8) -> Self {
- todo!("Implement this function")
- }
-
- pub fn u16_unsuffixed(n: u16) -> Self {
- todo!("Implement this function")
- }
-
- pub fn u32_unsuffixed(n: u32) -> Self {
- todo!("Implement this function")
- }
-
- pub fn u64_unsuffixed(n: u64) -> Self {
- todo!("Implement this function")
- }
-
- pub fn u128_unsuffixed(n: u128) -> Self {
- todo!("Implement this function")
- }
-
- pub fn usize_unsuffixed(n: usize) -> Self {
- todo!("Implement this function")
- }
-
- pub fn i8_unsuffixed(n: i8) -> Self {
- todo!("Implement this function")
- }
-
- pub fn i16_unsuffixed(n: i16) -> Self {
- todo!("Implement this function")
- }
-
- pub fn i32_unsuffixed(n: i32) -> Self {
- todo!("Implement this function")
- }
-
- pub fn i64_unsuffixed(n: i64) -> Self {
- todo!("Implement this function")
- }
-
- pub fn i128_unsuffixed(n: i128) -> Self {
- todo!("Implement this function")
- }
-
- pub fn isize_unsuffixed(n: isize) -> Self {
- todo!("Implement this function")
- }
-
- pub fn f32_unsuffixed(n: f32) -> Self {
- todo!("Implement this function")
- }
-
- pub fn f32_suffixed(n: f32) -> Self {
- todo!("Implement this function")
- }
-
- pub fn f64_unsuffixed(n: f64) -> Self {
- todo!("Implement this function")
- }
-
- pub fn f64_suffixed(n: f64) -> Self {
- todo!("Implement this function")
- }
-
- pub fn string(string: &str) -> Self {
- todo!("Implement this function")
- }
-
- pub fn character(c: char) -> Self {
- todo!("Implement this function")
- }
-
- pub fn byte_string(bytes: &[u8]) -> Self {
- todo!("Implement this function")
- }
-
- pub fn span(&self) -> Span {
- todo!("Get the span of a literal")
- }
-
- pub fn set_span(&mut self, span: Span) {
- todo!("Set the span of a literal")
- }
-}
-
-impl fmt::Debug for Literal {
- fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- todo!("Implement this function")
- }
-}
-
-impl fmt::Display for Literal {
- fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- todo!("Implement this function")
- }
-}
-
-impl FromStr for Literal {
- type Err = LexError;
-
- fn from_str(src: &str) -> Result<Self, LexError> {
- todo!("Implement this function")
- }
-}
-
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum Spacing {
Alone,
diff --git a/librust/proc_macro/rust/literal.rs b/librust/proc_macro/rust/literal.rs
new file mode 100644
index 0000000..515c7d2
--- /dev/null
+++ b/librust/proc_macro/rust/literal.rs
@@ -0,0 +1,167 @@
+use std::fmt;
+use std::str::FromStr;
+use LexError;
+use Span;
+
+#[derive(Clone)]
+pub struct Literal {
+ // Internal implementation details
+}
+
+impl Literal {
+ // TODO: Add experimental API functions for this type
+
+ pub fn u8_suffixed(_n: u8) -> Self {
+ todo!("Implement this function")
+ }
+
+ pub fn u16_suffixed(_n: u16) -> Self {
+ todo!("Implement this function")
+ }
+
+ pub fn u32_suffixed(_n: u32) -> Self {
+ todo!("Implement this function")
+ }
+
+ pub fn u64_suffixed(_n: u64) -> Self {
+ todo!("Implement this function")
+ }
+
+ pub fn u128_suffixed(_n: u128) -> Self {
+ todo!("Implement this function")
+ }
+
+ pub fn usize_suffixed(_n: usize) -> Self {
+ todo!("Implement this function")
+ }
+
+ pub fn i8_suffixed(_n: i8) -> Self {
+ todo!("Implement this function")
+ }
+
+ pub fn i16_suffixed(_n: i16) -> Self {
+ todo!("Implement this function")
+ }
+
+ pub fn i32_suffixed(_n: i32) -> Self {
+ todo!("Implement this function")
+ }
+
+ pub fn i64_suffixed(_n: i64) -> Self {
+ todo!("Implement this function")
+ }
+
+ pub fn i128_suffixed(_n: i128) -> Self {
+ todo!("Implement this function")
+ }
+
+ pub fn isize_suffixed(_n: isize) -> Self {
+ todo!("Implement this function")
+ }
+
+ // Unsuffixed
+
+ pub fn u8_unsuffixed(_n: u8) -> Self {
+ todo!("Implement this function")
+ }
+
+ pub fn u16_unsuffixed(_n: u16) -> Self {
+ todo!("Implement this function")
+ }
+
+ pub fn u32_unsuffixed(_n: u32) -> Self {
+ todo!("Implement this function")
+ }
+
+ pub fn u64_unsuffixed(_n: u64) -> Self {
+ todo!("Implement this function")
+ }
+
+ pub fn u128_unsuffixed(_n: u128) -> Self {
+ todo!("Implement this function")
+ }
+
+ pub fn usize_unsuffixed(_n: usize) -> Self {
+ todo!("Implement this function")
+ }
+
+ pub fn i8_unsuffixed(_n: i8) -> Self {
+ todo!("Implement this function")
+ }
+
+ pub fn i16_unsuffixed(_n: i16) -> Self {
+ todo!("Implement this function")
+ }
+
+ pub fn i32_unsuffixed(_n: i32) -> Self {
+ todo!("Implement this function")
+ }
+
+ pub fn i64_unsuffixed(_n: i64) -> Self {
+ todo!("Implement this function")
+ }
+
+ pub fn i128_unsuffixed(_n: i128) -> Self {
+ todo!("Implement this function")
+ }
+
+ pub fn isize_unsuffixed(_n: isize) -> Self {
+ todo!("Implement this function")
+ }
+
+ pub fn f32_unsuffixed(_n: f32) -> Self {
+ todo!("Implement this function")
+ }
+
+ pub fn f32_suffixed(_n: f32) -> Self {
+ todo!("Implement this function")
+ }
+
+ pub fn f64_unsuffixed(_n: f64) -> Self {
+ todo!("Implement this function")
+ }
+
+ pub fn f64_suffixed(_n: f64) -> Self {
+ todo!("Implement this function")
+ }
+
+ pub fn string(_string: &str) -> Self {
+ todo!("Implement this function")
+ }
+
+ pub fn character(_c: char) -> Self {
+ todo!("Implement this function")
+ }
+
+ pub fn byte_string(_bytes: &[u8]) -> Self {
+ todo!("Implement this function")
+ }
+
+ pub fn span(&self) -> Span {
+ todo!("Get the span of a literal")
+ }
+
+ pub fn set_span(&mut self, _span: Span) {
+ todo!("Set the span of a literal")
+ }
+}
+
+impl fmt::Debug for Literal {
+ fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ todo!("Implement this function")
+ }
+}
+
+impl fmt::Display for Literal {
+ fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ todo!("Implement this function")
+ }
+}
+
+impl FromStr for Literal {
+ type Err = LexError;
+
+ fn from_str(_src: &str) -> Result<Self, LexError> {
+ todo!("Implement this function")
+ }
+}
diff --git a/librust/proc_macro/rust/span.rs b/librust/proc_macro/rust/span.rs
new file mode 100644
index 0000000..646e35c
--- /dev/null
+++ b/librust/proc_macro/rust/span.rs
@@ -0,0 +1,44 @@
+use std::fmt;
+
+#[derive(Copy, Clone)]
+pub struct Span {
+ // Internal implementation details
+}
+
+impl Span {
+ // TODO: Add experimental API functions for this type
+
+ /// Creates a new span that resolves at the macro call location
+ pub fn call_site() -> Self {
+ todo!("Implement this function")
+ }
+
+ /// Creates a new span that resolved sometimes at macro call site, and
+ /// sometimes at macro definition site
+ pub fn mixed_site() -> Self {
+ todo!("Implement this function")
+ }
+
+ /// Creates a new span with the same line/column informations but that
+ /// resolve symbols as though it were at `other`
+ pub fn resolved_at(&self, _other: Span) -> Self {
+ todo!("Implement this function")
+ }
+
+ /// Creates a new span with the same name resolution behavior as self, but
+ /// with the line/column information of `other`.
+ pub fn located_at(&self, _other: Span) -> Self {
+ todo!("Implement this function")
+ }
+
+ /// Return the source text behind a span.
+ pub fn source_text(&self) -> Option<String> {
+ todo!("Implement this function")
+ }
+}
+
+impl fmt::Debug for Span {
+ fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ todo!("Implement this function")
+ }
+}