Skip to content

Commit 71680f5

Browse files
committedFeb 13, 2024
rust-fmt: Store parsed string in Pieces struct
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.
1 parent b3abebe commit 71680f5

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed
 

‎gcc/rust/ast/rust-fmt.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ namespace Rust {
2323
namespace Fmt {
2424

2525
Pieces
26-
Pieces::collect (const std::string &to_parse)
26+
Pieces::collect (std::string &&to_parse)
2727
{
2828
auto piece_slice = collect_pieces (to_parse.c_str ());
2929

@@ -34,7 +34,7 @@ Pieces::collect (const std::string &to_parse)
3434
auto pieces = std::vector (piece_slice.base_ptr,
3535
piece_slice.base_ptr + piece_slice.len);
3636

37-
return Pieces (piece_slice);
37+
return Pieces (piece_slice, std::move (to_parse));
3838
}
3939

4040
Pieces::~Pieces () { destroy_pieces (slice); }

‎gcc/rust/ast/rust-fmt.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -251,13 +251,16 @@ void destroy_pieces (PieceSlice);
251251

252252
struct Pieces
253253
{
254-
static Pieces collect (const std::string &to_parse);
254+
static Pieces collect (std::string &&to_parse);
255255
~Pieces ();
256256

257257
private:
258-
Pieces (PieceSlice slice) : slice (slice) {}
258+
Pieces (PieceSlice slice, std::string &&to_parse)
259+
: slice (slice), to_parse (std::move (to_parse))
260+
{}
259261

260262
PieceSlice slice;
263+
std::string to_parse;
261264
};
262265

263266
} // namespace Fmt

‎libgrust/libformat_parser/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,7 @@ pub struct PieceSlice {
340340
pub extern "C" fn collect_pieces(input: *const libc::c_char) -> PieceSlice {
341341
// FIXME: Add comment
342342
let str = unsafe { CStr::from_ptr(input) };
343+
dbg!(str);
343344

344345
// FIXME: No unwrap
345346
let pieces: Vec<ffi::Piece<'_>> = rust::collect_pieces(str.to_str().unwrap())

0 commit comments

Comments
 (0)
Failed to load comments.