aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>2023-02-15 15:45:17 +0100
committerPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>2023-03-30 13:52:29 +0200
commitddd0c450bc64e8d44a4c481f3cea0e238d95e08c (patch)
treec807b77002e33a15d322ddb80754eabd98d5fc3b
parent2e39012125d65cf22f53215c1aab70bbf8e3fd44 (diff)
downloadgcc-ddd0c450bc64e8d44a4c481f3cea0e238d95e08c.zip
gcc-ddd0c450bc64e8d44a4c481f3cea0e238d95e08c.tar.gz
gcc-ddd0c450bc64e8d44a4c481f3cea0e238d95e08c.tar.bz2
libproc_macro: Add Span rust implementation
Add a rust implementation for the Span rust type. Since this type is a compiler internal and unstable even in the reference compiler, the bridge internal structure is left empty. ChangeLog: * librust/proc_macro/rust/lib.rs: Add bridge module. * librust/proc_macro/rust/span.rs: Add reference to internal Span module. * librust/proc_macro/rust/bridge.rs: Add internal bridge module. * librust/proc_macro/rust/bridge/span.rs: Add internal Span module. 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/span.rs32
-rw-r--r--librust/proc_macro/rust/lib.rs1
-rw-r--r--librust/proc_macro/rust/span.rs23
4 files changed, 45 insertions, 12 deletions
diff --git a/librust/proc_macro/rust/bridge.rs b/librust/proc_macro/rust/bridge.rs
new file mode 100644
index 0000000..e066cd4
--- /dev/null
+++ b/librust/proc_macro/rust/bridge.rs
@@ -0,0 +1 @@
+pub mod span;
diff --git a/librust/proc_macro/rust/bridge/span.rs b/librust/proc_macro/rust/bridge/span.rs
new file mode 100644
index 0000000..5bbdd5a
--- /dev/null
+++ b/librust/proc_macro/rust/bridge/span.rs
@@ -0,0 +1,32 @@
+//! Bridge internal span representation and functions
+//!
+//! # Note
+//!
+//! All methods accessing source location in rust are unstable, hence this
+//! implementation with an empty structure.
+
+#[derive(Copy, Clone, Debug)]
+#[repr(C)]
+pub struct Span {}
+
+impl Span {
+ pub fn call_site() -> Self {
+ Span {}
+ }
+
+ pub fn mixed_site() -> Self {
+ Span {}
+ }
+
+ pub fn resolved_at(&self, _other: Span) -> Self {
+ Span {}
+ }
+
+ pub fn located_at(&self, _other: Span) -> Self {
+ Span {}
+ }
+
+ pub fn source_text(&self) -> Option<String> {
+ None
+ }
+}
diff --git a/librust/proc_macro/rust/lib.rs b/librust/proc_macro/rust/lib.rs
index de2ad9d..f749530 100644
--- a/librust/proc_macro/rust/lib.rs
+++ b/librust/proc_macro/rust/lib.rs
@@ -6,6 +6,7 @@ pub use span::Span;
use std::error;
use std::{fmt, iter, str::FromStr};
+mod bridge;
mod group;
mod ident;
mod literal;
diff --git a/librust/proc_macro/rust/span.rs b/librust/proc_macro/rust/span.rs
index b1c51d2..0ea60eca 100644
--- a/librust/proc_macro/rust/span.rs
+++ b/librust/proc_macro/rust/span.rs
@@ -1,23 +1,22 @@
+use bridge;
use std::fmt;
/// A region of source code along with macro expansion information.
#[derive(Copy, Clone)]
-pub struct Span {
- // Internal implementation details
-}
+pub struct Span(bridge::span::Span);
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")
+ Span(bridge::span::Span::call_site())
}
/// 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")
+ Span(bridge::span::Span::mixed_site())
}
/// Creates a new span with the same line/column informations but that
@@ -26,8 +25,8 @@ impl Span {
/// # Arguments
///
/// * `other` - Other span to resolve at.
- pub fn resolved_at(&self, _other: Span) -> Self {
- todo!("Implement this function")
+ pub fn resolved_at(&self, other: Span) -> Self {
+ Span(self.0.resolved_at(other.0))
}
/// Creates a new span with the same name resolution behavior as self, but
@@ -36,18 +35,18 @@ impl Span {
/// # Arguments
///
/// * `other` - Other span containing the line/column informations to use.
- pub fn located_at(&self, _other: Span) -> Self {
- todo!("Implement this function")
+ pub fn located_at(&self, other: Span) -> Self {
+ Span(self.0.located_at(other.0))
}
/// Return the source text behind a span.
pub fn source_text(&self) -> Option<String> {
- todo!("Implement this function")
+ self.0.source_text()
}
}
impl fmt::Debug for Span {
- 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)
}
}