public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] libproc_macro: Add Span rust implementation
@ 2023-04-06 21:30 Thomas Schwinge
  0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2023-04-06 21:30 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:ddd0c450bc64e8d44a4c481f3cea0e238d95e08c

commit ddd0c450bc64e8d44a4c481f3cea0e238d95e08c
Author: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Date:   Wed Feb 15 15:45:17 2023 +0100

    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>

Diff:
---
 librust/proc_macro/rust/bridge.rs      |  1 +
 librust/proc_macro/rust/bridge/span.rs | 32 ++++++++++++++++++++++++++++++++
 librust/proc_macro/rust/lib.rs         |  1 +
 librust/proc_macro/rust/span.rs        | 23 +++++++++++------------
 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 00000000000..e066cd483cd
--- /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 00000000000..5bbdd5a34ea
--- /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 de2ad9ddb0d..f74953024b4 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 b1c51d2c07e..0ea60eca0ca 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)
     }
 }

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-04-06 21:30 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:30 [gcc/devel/rust/master] libproc_macro: Add Span rust 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).