public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-7634] gccrs: libproc_macro: Add cpp Span representation
@ 2024-01-16 17:49 Arthur Cohen
  0 siblings, 0 replies; only message in thread
From: Arthur Cohen @ 2024-01-16 17:49 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:4d950fa5dfca0aa526a5d5e72f353b4a46cfb1e4

commit r14-7634-g4d950fa5dfca0aa526a5d5e72f353b4a46cfb1e4
Author: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Date:   Tue May 30 10:57:01 2023 +0200

    gccrs: libproc_macro: Add cpp Span representation
    
    Add Span representation in libproc_macro cpp part of the library.
    Integrate spans to existing types.
    
    gcc/rust/ChangeLog:
    
            * util/rust-token-converter.cc (convert): Update call to
            constructors with location information.
            (handle_suffix): Convert token locus to a Span and use it in the
            literal.
    
    libgrust/ChangeLog:
    
            * libproc_macro/Makefile.am: Add span.cc
            * libproc_macro/Makefile.in: Regenerate.
            * libproc_macro/span.cc: New file.
            * libproc_macro/span.h: New file.
            * libproc_macro/group.cc (Group::make_group): Add span
            argument.
            * libproc_macro/group.h (GROUP_H): Add include
            directive for spans.
            * libproc_macro/ident.cc (Ident__new): Add span
            argument.
            (Ident__new_raw): Likewise.
            (Ident::make_ident): Likewise.
            * libproc_macro/ident.h (Ident__new): Likewise.
            (Ident__new_raw): Likewise.
            * libproc_macro/literal.cc (Literal::clone): Clone the
            span.
            (Literal::make_literal): Add span argument.
            (Literal::make_u8): Likewise.
            (Literal::make_u16): Likewise.
            (Literal::make_u32): Likewise.
            (Literal::make_u64): Likewise.
            (Literal::make_i8): Likewise.
            (Literal::make_i16): Likewise.
            (Literal::make_i32): Likewise.
            (Literal::make_i64): Likewise.
            (Literal::make_string): Likewise.
            (Literal::make_byte_string): Likewise.
            (Literal::make_f32): Likewise.
            (Literal::make_f64): Likewise.
            (Literal::make_char): Likewise.
            (Literal::make_usize): Likewise.
            (Literal::make_isize): Likewise.
            * libproc_macro/literal.h (struct Literal): Add span to
            Literal structure.
            * libproc_macro/punct.cc (Punct::make_punct): Add span
            argument to punct constructor.
            * libproc_macro/punct.h (struct Punct): Add span to
            Punct structure.
    
    Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>

Diff:
---
 gcc/rust/util/rust-token-converter.cc | 26 +++++++++++++++++-----
 libgrust/libproc_macro/Makefile.am    |  1 +
 libgrust/libproc_macro/Makefile.in    |  1 +
 libgrust/libproc_macro/group.cc       |  4 ++--
 libgrust/libproc_macro/group.h        |  5 ++++-
 libgrust/libproc_macro/ident.cc       | 19 ++++++++--------
 libgrust/libproc_macro/ident.h        | 11 ++++++----
 libgrust/libproc_macro/literal.cc     | 36 +++++++++++++++---------------
 libgrust/libproc_macro/literal.h      |  6 +++--
 libgrust/libproc_macro/punct.cc       |  4 ++--
 libgrust/libproc_macro/punct.h        |  5 ++++-
 libgrust/libproc_macro/span.cc        | 40 ++++++++++++++++++++++++++++++++++
 libgrust/libproc_macro/span.h         | 41 +++++++++++++++++++++++++++++++++++
 13 files changed, 155 insertions(+), 44 deletions(-)

diff --git a/gcc/rust/util/rust-token-converter.cc b/gcc/rust/util/rust-token-converter.cc
index 871c8e092c1..a50d7218113 100644
--- a/gcc/rust/util/rust-token-converter.cc
+++ b/gcc/rust/util/rust-token-converter.cc
@@ -50,6 +50,12 @@ pop_group (std::vector<ProcMacro::TokenStream> &streams,
   streams.back ().push (tt);
 }
 
+static ProcMacro::Span
+convert (Location location)
+{
+  return ProcMacro::Span::make_unknown ();
+}
+
 static void
 handle_suffix (ProcMacro::TokenStream &ts, const const_TokenPtr &token,
 	       ProcMacro::LitKind kind)
@@ -58,7 +64,8 @@ handle_suffix (ProcMacro::TokenStream &ts, const const_TokenPtr &token,
   auto lookup = suffixes.lookup (token->get_type_hint ());
   auto suffix = suffixes.is_iter_ok (lookup) ? lookup->second : "";
   ts.push (ProcMacro::TokenTree::make_tokentree (
-    ProcMacro::Literal::make_literal (kind, str, suffix)));
+    ProcMacro::Literal::make_literal (kind, convert (token->get_locus ()), str,
+				      suffix)));
 }
 
 ProcMacro::TokenStream
@@ -82,22 +89,26 @@ convert (const std::vector<const_TokenPtr> &tokens)
 	case CHAR_LITERAL:
 	  trees.back ().push (ProcMacro::TokenTree::make_tokentree (
 	    ProcMacro::Literal::make_literal (ProcMacro::LitKind::make_char (),
+					      convert (token->get_locus ()),
 					      token->as_string ())));
 	  break;
 	case STRING_LITERAL:
 	  trees.back ().push (ProcMacro::TokenTree::make_tokentree (
 	    ProcMacro::Literal::make_literal (ProcMacro::LitKind::make_str (),
+					      convert (token->get_locus ()),
 					      token->as_string ())));
 	  break;
 	case BYTE_CHAR_LITERAL:
 	  trees.back ().push (ProcMacro::TokenTree::make_tokentree (
 	    ProcMacro::Literal::make_literal (ProcMacro::LitKind::make_byte (),
+					      convert (token->get_locus ()),
 					      token->as_string ())));
 	  break;
 	case BYTE_STRING_LITERAL:
 	  trees.back ().push (ProcMacro::TokenTree::make_tokentree (
 	    ProcMacro::Literal::make_literal (
-	      ProcMacro::LitKind::make_byte_str (), token->as_string ())));
+	      ProcMacro::LitKind::make_byte_str (),
+	      convert (token->get_locus ()), token->as_string ())));
 	  break;
 	// Ident
 	case IDENTIFIER:
@@ -157,7 +168,8 @@ convert (const std::vector<const_TokenPtr> &tokens)
 	case FALSE_LITERAL:
 	case TRUE_LITERAL:
 	  trees.back ().push (ProcMacro::TokenTree::make_tokentree (
-	    ProcMacro::Ident::make_ident (token->as_string ())));
+	    ProcMacro::Ident::make_ident (token->as_string (),
+					  convert (token->get_locus ()))));
 	  break;
 	// Joint punct
 	case OR:
@@ -188,9 +200,12 @@ convert (const std::vector<const_TokenPtr> &tokens)
 	    auto it = str.cbegin ();
 	    for (; it != str.cend () - 1; it++)
 	      trees.back ().push (ProcMacro::TokenTree::make_tokentree (
-		ProcMacro::Punct::make_punct (*it, ProcMacro::JOINT)));
+		ProcMacro::Punct::make_punct (*it,
+					      convert (token->get_locus ()),
+					      ProcMacro::JOINT)));
 	    trees.back ().push (ProcMacro::TokenTree::make_tokentree (
-	      ProcMacro::Punct::make_punct (*it, ProcMacro::ALONE)));
+	      ProcMacro::Punct::make_punct (*it, convert (token->get_locus ()),
+					    ProcMacro::ALONE)));
 	  }
 	  break;
 	// Alone punct tokens
@@ -218,6 +233,7 @@ convert (const std::vector<const_TokenPtr> &tokens)
 	case SINGLE_QUOTE:
 	  trees.back ().push (ProcMacro::TokenTree::make_tokentree (
 	    ProcMacro::Punct::make_punct (token->as_string ()[0],
+					  convert (token->get_locus ()),
 					  ProcMacro::ALONE)));
 	  break;
 	case RIGHT_PAREN:
diff --git a/libgrust/libproc_macro/Makefile.am b/libgrust/libproc_macro/Makefile.am
index 493508cd9ee..24945a40fa8 100644
--- a/libgrust/libproc_macro/Makefile.am
+++ b/libgrust/libproc_macro/Makefile.am
@@ -53,6 +53,7 @@ objext = @OBJEXT@
 
 REQUIRED_OFILES =							\
 	./proc_macro.$(objext) \
+	./span.$(objext) \
 	./literal.$(objext) \
 	./group.$(objext) \
 	./ident.$(objext) \
diff --git a/libgrust/libproc_macro/Makefile.in b/libgrust/libproc_macro/Makefile.in
index 36031effcab..db5f2d4f62f 100644
--- a/libgrust/libproc_macro/Makefile.in
+++ b/libgrust/libproc_macro/Makefile.in
@@ -312,6 +312,7 @@ TARGETLIB = ./libproc_macro.a
 objext = @OBJEXT@
 REQUIRED_OFILES = \
 	./proc_macro.$(objext) \
+	./span.$(objext) \
 	./literal.$(objext) \
 	./group.$(objext) \
 	./ident.$(objext) \
diff --git a/libgrust/libproc_macro/group.cc b/libgrust/libproc_macro/group.cc
index 74c1959800e..38730d8afd9 100644
--- a/libgrust/libproc_macro/group.cc
+++ b/libgrust/libproc_macro/group.cc
@@ -25,9 +25,9 @@
 namespace ProcMacro {
 
 Group
-Group::make_group (TokenStream stream, Delimiter delim)
+Group::make_group (TokenStream stream, Delimiter delim, Span span)
 {
-  return {delim, stream};
+  return {delim, stream, span};
 }
 
 void
diff --git a/libgrust/libproc_macro/group.h b/libgrust/libproc_macro/group.h
index 26680b07848..fa76d4b15a5 100644
--- a/libgrust/libproc_macro/group.h
+++ b/libgrust/libproc_macro/group.h
@@ -23,6 +23,7 @@
 #ifndef GROUP_H
 #define GROUP_H
 
+#include "span.h"
 #include "tokenstream.h"
 
 namespace ProcMacro {
@@ -39,9 +40,11 @@ struct Group
 {
   Delimiter delimiter;
   TokenStream stream;
+  Span span;
 
 public:
-  static Group make_group (TokenStream stream, Delimiter delim);
+  static Group make_group (TokenStream stream, Delimiter delim,
+			   Span span = Span::make_unknown ());
 
   static void drop (Group *g);
 };
diff --git a/libgrust/libproc_macro/ident.cc b/libgrust/libproc_macro/ident.cc
index c21483605ff..236970519da 100644
--- a/libgrust/libproc_macro/ident.cc
+++ b/libgrust/libproc_macro/ident.cc
@@ -28,15 +28,15 @@ namespace ProcMacro {
 extern "C" {
 
 Ident
-Ident__new (unsigned char *str, std::uint64_t len)
+Ident__new (unsigned char *str, std::uint64_t len, Span span)
 {
-  return Ident::make_ident (str, len);
+  return Ident::make_ident (str, len, span);
 }
 
 Ident
-Ident__new_raw (unsigned char *str, std::uint64_t len)
+Ident__new_raw (unsigned char *str, std::uint64_t len, Span span)
 {
-  return Ident::make_ident (str, len, true);
+  return Ident::make_ident (str, len, span, true);
 }
 
 void
@@ -57,23 +57,24 @@ Ident::clone () const
 {
   unsigned char *val = new unsigned char[this->len];
   std::memcpy (val, this->val, this->len);
-  return {this->is_raw, val, this->len};
+  return {this->is_raw, val, this->len, this->span};
 }
 
 Ident
-Ident::make_ident (std::string str, bool raw)
+Ident::make_ident (std::string str, Span span, bool raw)
 {
   return Ident::make_ident (reinterpret_cast<const unsigned char *> (
 			      str.c_str ()),
-			    str.length (), raw);
+			    str.length (), span, raw);
 }
 
 Ident
-Ident::make_ident (const unsigned char *str, std::uint64_t len, bool raw)
+Ident::make_ident (const unsigned char *str, std::uint64_t len, Span span,
+		   bool raw)
 {
   unsigned char *val = new unsigned char[len];
   std::memcpy (val, str, len);
-  return {raw, val, len};
+  return {raw, val, len, span};
 }
 
 void
diff --git a/libgrust/libproc_macro/ident.h b/libgrust/libproc_macro/ident.h
index 82a154c20cc..28d6ebe825f 100644
--- a/libgrust/libproc_macro/ident.h
+++ b/libgrust/libproc_macro/ident.h
@@ -26,6 +26,8 @@
 #include <cstdint>
 #include <string>
 
+#include "span.h"
+
 namespace ProcMacro {
 
 struct Ident
@@ -35,12 +37,13 @@ struct Ident
   unsigned char *val;
   // Length in bytes
   std::uint64_t len;
+  Span span;
 
 public:
   Ident clone () const;
-  static Ident make_ident (std::string str, bool raw = false);
+  static Ident make_ident (std::string str, Span span, bool raw = false);
   static Ident make_ident (const unsigned char *str, std::uint64_t len,
-			   bool raw = false);
+			   Span span, bool raw = false);
 
   static void drop (Ident *ident);
 };
@@ -48,10 +51,10 @@ public:
 extern "C" {
 
 Ident
-Ident__new (unsigned char *str, std::uint64_t len);
+Ident__new (unsigned char *str, std::uint64_t len, Span span);
 
 Ident
-Ident__new_raw (unsigned char *str, std::uint64_t len);
+Ident__new_raw (unsigned char *str, std::uint64_t len, Span span);
 
 void
 Ident__drop (Ident *ident);
diff --git a/libgrust/libproc_macro/literal.cc b/libgrust/libproc_macro/literal.cc
index af1632b7290..4ad45c90331 100644
--- a/libgrust/libproc_macro/literal.cc
+++ b/libgrust/libproc_macro/literal.cc
@@ -46,16 +46,16 @@ Literal::drop (Literal *lit)
 Literal
 Literal::clone () const
 {
-  return {this->kind, this->text.clone (), this->suffix.clone ()};
+  return {this->kind, this->text.clone (), this->suffix.clone (), this->span};
 }
 
 Literal
-Literal::make_literal (LitKind kind, const std::string &text,
+Literal::make_literal (LitKind kind, Span span, const std::string &text,
 		       const std::string &suffix)
 {
   auto ffi_text = FFIString::make_ffistring (text);
   auto ffi_suffix = FFIString::make_ffistring (suffix);
-  return {kind, ffi_text, ffi_suffix};
+  return {kind, ffi_text, ffi_suffix, span};
 }
 
 Literal
@@ -63,7 +63,7 @@ Literal::make_u8 (std::uint8_t value, bool suffixed)
 {
   auto text = FFIString::make_ffistring (std::to_string (value));
   auto suffix = FFIString::make_ffistring (suffixed ? "u8" : "");
-  return {LitKind::make_integer (), text, suffix};
+  return {LitKind::make_integer (), text, suffix, Span::make_unknown ()};
 }
 
 Literal
@@ -71,7 +71,7 @@ Literal::make_u16 (std::uint16_t value, bool suffixed)
 {
   auto text = FFIString::make_ffistring (std::to_string (value));
   auto suffix = FFIString::make_ffistring (suffixed ? "u16" : "");
-  return {LitKind::make_integer (), text, suffix};
+  return {LitKind::make_integer (), text, suffix, Span::make_unknown ()};
 }
 
 Literal
@@ -79,7 +79,7 @@ Literal::make_u32 (std::uint32_t value, bool suffixed)
 {
   auto text = FFIString::make_ffistring (std::to_string (value));
   auto suffix = FFIString::make_ffistring (suffixed ? "u32" : "");
-  return {LitKind::make_integer (), text, suffix};
+  return {LitKind::make_integer (), text, suffix, Span::make_unknown ()};
 }
 
 Literal
@@ -87,7 +87,7 @@ Literal::make_u64 (std::uint64_t value, bool suffixed)
 {
   auto text = FFIString::make_ffistring (std::to_string (value));
   auto suffix = FFIString::make_ffistring (suffixed ? "u64" : "");
-  return {LitKind::make_integer (), text, suffix};
+  return {LitKind::make_integer (), text, suffix, Span::make_unknown ()};
 }
 
 Literal
@@ -95,7 +95,7 @@ Literal::make_i8 (std::int8_t value, bool suffixed)
 {
   auto text = FFIString::make_ffistring (std::to_string (value));
   auto suffix = FFIString::make_ffistring (suffixed ? "i8" : "");
-  return {LitKind::make_integer (), text, suffix};
+  return {LitKind::make_integer (), text, suffix, Span::make_unknown ()};
 }
 
 Literal
@@ -103,7 +103,7 @@ Literal::make_i16 (std::int16_t value, bool suffixed)
 {
   auto text = FFIString::make_ffistring (std::to_string (value));
   auto suffix = FFIString::make_ffistring (suffixed ? "i16" : "");
-  return {LitKind::make_integer (), text, suffix};
+  return {LitKind::make_integer (), text, suffix, Span::make_unknown ()};
 }
 
 Literal
@@ -111,7 +111,7 @@ Literal::make_i32 (std::int32_t value, bool suffixed)
 {
   auto text = FFIString::make_ffistring (std::to_string (value));
   auto suffix = FFIString::make_ffistring (suffixed ? "i32" : "");
-  return {LitKind::make_integer (), text, suffix};
+  return {LitKind::make_integer (), text, suffix, Span::make_unknown ()};
 }
 
 Literal
@@ -119,7 +119,7 @@ Literal::make_i64 (std::int64_t value, bool suffixed)
 {
   auto text = FFIString::make_ffistring (std::to_string (value));
   auto suffix = FFIString::make_ffistring (suffixed ? "i64" : "");
-  return {LitKind::make_integer (), text, suffix};
+  return {LitKind::make_integer (), text, suffix, Span::make_unknown ()};
 }
 
 Literal
@@ -127,7 +127,7 @@ Literal::make_string (const std::string &str)
 {
   auto text = FFIString::make_ffistring (str);
   auto suffix = FFIString::make_ffistring ("");
-  return {LitKind::make_str (), text, suffix};
+  return {LitKind::make_str (), text, suffix, Span::make_unknown ()};
 }
 
 Literal
@@ -136,7 +136,7 @@ Literal::make_byte_string (const std::vector<std::uint8_t> &vec)
   auto text
     = FFIString::make_ffistring (std::string (vec.cbegin (), vec.cend ()));
   auto suffix = FFIString::make_ffistring ("");
-  return {LitKind::make_byte_str (), text, suffix};
+  return {LitKind::make_byte_str (), text, suffix, Span::make_unknown ()};
 }
 
 Literal
@@ -144,7 +144,7 @@ Literal::make_f32 (float value, bool suffixed)
 {
   auto text = FFIString::make_ffistring (std::to_string (value));
   auto suffix = FFIString::make_ffistring (suffixed ? "f32" : "");
-  return {LitKind::make_float (), text, suffix};
+  return {LitKind::make_float (), text, suffix, Span::make_unknown ()};
 }
 
 Literal
@@ -152,7 +152,7 @@ Literal::make_f64 (double value, bool suffixed)
 {
   auto text = FFIString::make_ffistring (std::to_string (value));
   auto suffix = FFIString::make_ffistring (suffixed ? "f64" : "");
-  return {LitKind::make_float (), text, suffix};
+  return {LitKind::make_float (), text, suffix, Span::make_unknown ()};
 }
 
 Literal
@@ -160,7 +160,7 @@ Literal::make_char (std::uint32_t ch)
 {
   auto text = FFIString::make_ffistring (std::to_string ((char) ch));
   auto suffix = FFIString::make_ffistring ("");
-  return {LitKind::make_char (), text, suffix};
+  return {LitKind::make_char (), text, suffix, Span::make_unknown ()};
 }
 
 Literal
@@ -168,7 +168,7 @@ Literal::make_usize (std::uint64_t value, bool suffixed)
 {
   auto text = FFIString::make_ffistring (std::to_string (value));
   auto suffix = FFIString::make_ffistring (suffixed ? "usize" : "");
-  return {LitKind::make_integer (), text, suffix};
+  return {LitKind::make_integer (), text, suffix, Span::make_unknown ()};
 }
 
 Literal
@@ -176,7 +176,7 @@ Literal::make_isize (std::int64_t value, bool suffixed)
 {
   auto text = FFIString::make_ffistring (std::to_string (value));
   auto suffix = FFIString::make_ffistring (suffixed ? "isize" : "");
-  return {LitKind::make_integer (), text, suffix};
+  return {LitKind::make_integer (), text, suffix, Span::make_unknown ()};
 }
 
 LitKind
diff --git a/libgrust/libproc_macro/literal.h b/libgrust/libproc_macro/literal.h
index 86b1a175487..e1b7079451a 100644
--- a/libgrust/libproc_macro/literal.h
+++ b/libgrust/libproc_macro/literal.h
@@ -26,6 +26,7 @@
 #include <cstdint>
 #include <string>
 #include <vector>
+#include "span.h"
 #include "ffistring.h"
 
 namespace ProcMacro {
@@ -70,13 +71,14 @@ struct Literal
   LitKind kind;
   FFIString text;
   FFIString suffix;
-  // TODO: Add span once done in rust interface
+  Span span;
 
 public:
   Literal clone () const;
   bool has_suffix () const { return suffix.len != 0; };
 
-  static Literal make_literal (const LitKind kind, const std::string &text,
+  static Literal make_literal (const LitKind kind, Span span,
+			       const std::string &text,
 			       const std::string &suffix = "");
   static Literal make_u8 (std::uint8_t value, bool suffixed = true);
   static Literal make_u16 (std::uint16_t value, bool suffixed = true);
diff --git a/libgrust/libproc_macro/punct.cc b/libgrust/libproc_macro/punct.cc
index 78d25f9ebdb..32450cc8ea6 100644
--- a/libgrust/libproc_macro/punct.cc
+++ b/libgrust/libproc_macro/punct.cc
@@ -26,9 +26,9 @@
 namespace ProcMacro {
 
 Punct
-Punct::make_punct (std::uint32_t ch, Spacing spacing)
+Punct::make_punct (std::uint32_t ch, Span span, Spacing spacing)
 {
-  return {ch, spacing};
+  return {ch, spacing, span};
 }
 
 } // namespace ProcMacro
diff --git a/libgrust/libproc_macro/punct.h b/libgrust/libproc_macro/punct.h
index f3a1c1bd1ec..6d0146083bf 100644
--- a/libgrust/libproc_macro/punct.h
+++ b/libgrust/libproc_macro/punct.h
@@ -24,6 +24,7 @@
 #define PUNCT_H
 
 #include <cstdint>
+#include "span.h"
 
 namespace ProcMacro {
 
@@ -37,9 +38,11 @@ struct Punct
 {
   std::uint32_t ch;
   Spacing spacing;
+  Span span;
 
 public:
-  static Punct make_punct (std::uint32_t ch, Spacing spacing = Spacing::ALONE);
+  static Punct make_punct (std::uint32_t ch, Span span,
+			   Spacing spacing = Spacing::ALONE);
 };
 
 } // namespace ProcMacro
diff --git a/libgrust/libproc_macro/span.cc b/libgrust/libproc_macro/span.cc
new file mode 100644
index 00000000000..62c8c57f688
--- /dev/null
+++ b/libgrust/libproc_macro/span.cc
@@ -0,0 +1,40 @@
+// Copyright (C) 2023 Free Software Foundation, Inc.
+//
+// This file is part of the GNU Proc Macro Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// Under Section 7 of GPL version 3, you are granted additional
+// permissions described in the GCC Runtime Library Exception, version
+// 3.1, as published by the Free Software Foundation.
+
+// You should have received a copy of the GNU General Public License and
+// a copy of the GCC Runtime Library Exception along with this program;
+// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+// <http://www.gnu.org/licenses/>.
+
+#include "span.h"
+
+namespace ProcMacro {
+
+Span
+Span::make_span (std::uint32_t start, std::uint32_t end)
+{
+  return {start, end};
+}
+
+Span
+Span::make_unknown ()
+{
+  // TODO: Change this value to UNKNOWN_LOCATION from gcc/input.h
+  return {0, 0};
+}
+
+} // namespace ProcMacro
diff --git a/libgrust/libproc_macro/span.h b/libgrust/libproc_macro/span.h
new file mode 100644
index 00000000000..70ea9e7ea3d
--- /dev/null
+++ b/libgrust/libproc_macro/span.h
@@ -0,0 +1,41 @@
+// Copyright (C) 2023 Free Software Foundation, Inc.
+//
+// This file is part of the GNU Proc Macro Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// Under Section 7 of GPL version 3, you are granted additional
+// permissions described in the GCC Runtime Library Exception, version
+// 3.1, as published by the Free Software Foundation.
+
+// You should have received a copy of the GNU General Public License and
+// a copy of the GCC Runtime Library Exception along with this program;
+// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+// <http://www.gnu.org/licenses/>.
+
+#ifndef SPAN_H
+#define SPAN_H
+
+#include <cstdint>
+
+namespace ProcMacro {
+struct Span
+{
+  std::uint32_t start;
+  std::uint32_t end;
+
+public:
+  static Span make_span (std::uint32_t start, std::uint32_t end);
+
+  static Span make_unknown ();
+};
+} // namespace ProcMacro
+
+#endif /* SPAN_H */

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

only message in thread, other threads:[~2024-01-16 17:49 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-16 17:49 [gcc r14-7634] gccrs: libproc_macro: Add cpp Span representation Arthur Cohen

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).