| 1 |
// Copyright (C) 2020-2025 Free Software Foundation, Inc. |
| 2 |
|
| 3 |
// This file is part of GCC. |
| 4 |
|
| 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 |
| 8 |
// version. |
| 9 |
|
| 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 |
| 13 |
// for more details. |
| 14 |
|
| 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/>. |
| 18 |
|
| 19 |
#include "rust-fmt.h" |
| 20 |
#include "rust-diagnostics.h" |
| 21 |
|
| 22 |
namespace Rust { |
| 23 |
namespace Fmt { |
| 24 |
|
| 25 |
std::string |
| 26 |
ffi::RustHamster::to_string () const |
| 27 |
{ |
| 28 |
return std::string (ptr, len); |
| 29 |
} |
| 30 |
|
| 31 |
Pieces |
| 32 |
Pieces::collect (const std::string &to_parse, bool append_newline, |
| 33 |
ffi::ParseMode parse_mode) |
| 34 |
{ |
| 35 |
auto handle |
| 36 |
= ffi::collect_pieces (to_parse.c_str (), append_newline, parse_mode); |
| 37 |
|
| 38 |
// this performs multiple copies, can we avoid them maybe? |
| 39 |
// TODO: Instead of just creating a vec of, basically, `ffi::Piece`s, we |
| 40 |
// should transform them into the proper C++ type which we can work with. so |
| 41 |
// transform all the strings into C++ strings? all the Option<T> into |
| 42 |
// tl::optional<T>? |
| 43 |
auto pieces_vector = std::vector<ffi::Piece> (handle.piece_slice.base_ptr, |
| 44 |
handle.piece_slice.base_ptr |
| 45 |
+ handle.piece_slice.len); |
| 46 |
|
| 47 |
return Pieces (handle, std::move (pieces_vector)); |
| 48 |
} |
| 49 |
|
| 50 |
Pieces::~Pieces () { ffi::destroy_pieces (handle); } |
| 51 |
|
| 52 |
Pieces::Pieces (const Pieces &other) : pieces_vector (other.pieces_vector) |
| 53 |
{ |
| 54 |
handle = ffi::clone_pieces (other.handle); |
| 55 |
} |
| 56 |
|
| 57 |
Pieces & |
| 58 |
Pieces::operator= (const Pieces &other) |
| 59 |
{ |
| 60 |
handle = ffi::clone_pieces (other.handle); |
| 61 |
pieces_vector = other.pieces_vector; |
| 62 |
|
| 63 |
return *this; |
| 64 |
} |
| 65 |
|
| 66 |
Pieces::Pieces (Pieces &&other) |
| 67 |
: pieces_vector (std::move (other.pieces_vector)), |
| 68 |
handle (clone_pieces (other.handle)) |
| 69 |
{} |
| 70 |
|
| 71 |
} // namespace Fmt |
| 72 |
} // namespace Rust |