[PR testsuite/116860] Testsuite adjustment for recently added tests
[official-gcc.git] / gcc / rust / ast / rust-fmt.cc
blobcc48c2e35769cae036627a364bc9e8a62f34e80b
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
8 // version.
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.
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/>.
19 #include "rust-fmt.h"
20 #include "rust-diagnostics.h"
22 namespace Rust {
23 namespace Fmt {
25 std::string
26 ffi::RustHamster::to_string () const
28 return std::string (ptr, len);
31 Pieces
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
40 // tl::optional<T>?
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);
55 Pieces &
56 Pieces::operator= (const Pieces &other)
58 handle = ffi::clone_pieces (other.handle);
59 pieces_vector = other.pieces_vector;
61 return *this;
64 Pieces::Pieces (Pieces &&other)
65 : pieces_vector (std::move (other.pieces_vector)),
66 handle (clone_pieces (other.handle))
69 } // namespace Fmt
70 } // namespace Rust