]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
rust-fmt: Store parsed string in Pieces struct
authorArthur Cohen <arthur.cohen@embecosm.com>
Tue, 13 Feb 2024 15:31:25 +0000 (16:31 +0100)
committerCohenArthur <arthur.cohen@embecosm.com>
Mon, 26 Feb 2024 17:32:38 +0000 (17:32 +0000)
gcc/rust/ChangeLog:

* ast/rust-fmt.cc (Pieces::collect): Fix signature to take ownership
of the given string.
* ast/rust-fmt.h (struct Pieces): Store parsed string in the struct.

libgrust/ChangeLog:

* libformat_parser/src/lib.rs: Add debug prompt.

gcc/rust/ast/rust-fmt.cc
gcc/rust/ast/rust-fmt.h
libgrust/libformat_parser/src/lib.rs

index f6ee8a209137c65c690f39bb0659de62d8b1ff18..511e94740c5eb94f8b7391b43d2678ff43ab2768 100644 (file)
@@ -23,7 +23,7 @@ namespace Rust {
 namespace Fmt {
 
 Pieces
-Pieces::collect (const std::string &to_parse)
+Pieces::collect (std::string &&to_parse)
 {
   auto piece_slice = collect_pieces (to_parse.c_str ());
 
@@ -34,7 +34,7 @@ Pieces::collect (const std::string &to_parse)
   // auto pieces = std::vector<Piece> (piece_slice.base_ptr,
   //        piece_slice.base_ptr + piece_slice.len);
 
-  return Pieces (piece_slice);
+  return Pieces (piece_slice, std::move (to_parse));
 }
 
 Pieces::~Pieces () { destroy_pieces (slice); }
index 50aeff6433eeb618b6230f287e34eb7c13b7c12d..0bf9695bb6d2f64c42b65ec5839b2245b5869b08 100644 (file)
@@ -251,13 +251,16 @@ void destroy_pieces (PieceSlice);
 
 struct Pieces
 {
-  static Pieces collect (const std::string &to_parse);
+  static Pieces collect (std::string &&to_parse);
   ~Pieces ();
 
 private:
-  Pieces (PieceSlice slice) : slice (slice) {}
+  Pieces (PieceSlice slice, std::string &&to_parse)
+    : slice (slice), to_parse (std::move (to_parse))
+  {}
 
   PieceSlice slice;
+  std::string to_parse;
 };
 
 } // namespace Fmt
index 9b2bffed05d493f61856c4878257b07871efc386..eb3e1060e5d87e2fb8c8dd1098bf5e4c92c43fa9 100644 (file)
@@ -340,6 +340,7 @@ pub struct PieceSlice {
 pub extern "C" fn collect_pieces(input: *const libc::c_char) -> PieceSlice {
     // FIXME: Add comment
     let str = unsafe { CStr::from_ptr(input) };
+    dbg!(str);
 
     // FIXME: No unwrap
     let pieces: Vec<ffi::Piece<'_>> = rust::collect_pieces(str.to_str().unwrap())