1 // Copyright (C) 2020-2025 Free Software Foundation, Inc.
3 // This file is part of GCC.
5 // GCC is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU General Public License as published by the Free
7 // Software Foundation; either version 3, or (at your option) any later
10 // GCC is distributed in the hope that it will be useful, but WITHOUT ANY
11 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 // You should have received a copy of the GNU General Public License
16 // along with GCC; see the file COPYING3. If not see
17 // <http://www.gnu.org/licenses/>.
20 #include "rust-diagnostics.h"
26 ffi::RustHamster::to_string () const
28 return std::string (ptr
, len
);
32 Pieces::collect (const std::string
&to_parse
, bool append_newline
)
34 auto handle
= ffi::collect_pieces (to_parse
.c_str (), append_newline
);
36 // this performs multiple copies, can we avoid them maybe?
37 // TODO: Instead of just creating a vec of, basically, `ffi::Piece`s, we
38 // should transform them into the proper C++ type which we can work with. so
39 // transform all the strings into C++ strings? all the Option<T> into
41 auto pieces_vector
= std::vector
<ffi::Piece
> (handle
.piece_slice
.base_ptr
,
42 handle
.piece_slice
.base_ptr
43 + handle
.piece_slice
.len
);
45 return Pieces (handle
, std::move (pieces_vector
));
48 Pieces::~Pieces () { ffi::destroy_pieces (handle
); }
50 Pieces::Pieces (const Pieces
&other
) : pieces_vector (other
.pieces_vector
)
52 handle
= ffi::clone_pieces (other
.handle
);
56 Pieces::operator= (const Pieces
&other
)
58 handle
= ffi::clone_pieces (other
.handle
);
59 pieces_vector
= other
.pieces_vector
;
64 Pieces::Pieces (Pieces
&&other
)
65 : pieces_vector (std::move (other
.pieces_vector
)),
66 handle (clone_pieces (other
.handle
))