aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/ast/rust-fmt.cc
diff options
context:
space:
mode:
authorArthur Cohen <arthur.cohen@embecosm.com>2024-02-16 18:27:22 +0100
committerCohenArthur <arthur.cohen@embecosm.com>2024-03-01 15:42:36 +0000
commitafed72d7137afe4ab4c7db44262379ba6dda4eb9 (patch)
tree24d8b8c13d34bd86db7094b134e19e255def747e /gcc/rust/ast/rust-fmt.cc
parent38e3cffdbdee48cc4793948f1551b075672f6fdd (diff)
downloadgcc-afed72d7137afe4ab4c7db44262379ba6dda4eb9.zip
gcc-afed72d7137afe4ab4c7db44262379ba6dda4eb9.tar.gz
gcc-afed72d7137afe4ab4c7db44262379ba6dda4eb9.tar.bz2
format-args: Fix Rust interface and add input parsing.
gcc/rust/ChangeLog: * Make-lang.in: Do not build Rust library in release mode. * ast/rust-ast.cc: Make FormatArgs inherit from AST::Expr * ast/rust-builtin-ast-nodes.h: Improve FormatArg* nodes and helpers. * ast/rust-fmt.cc (Pieces::collect): Fix interface to match FFI function. * ast/rust-fmt.h (collect_pieces): Likewise. (struct Pieces): Add append_newline parameter. * expand/rust-macro-builtins.cc: Add proper parsing of format_args input. * hir/rust-ast-lower-base.cc: Include diagnostics header. libgrust/ChangeLog: * libformat_parser/src/lib.rs: Switch interface to use more parser parameters. * libformat_parser/src/bin.rs: Use new interface.
Diffstat (limited to 'gcc/rust/ast/rust-fmt.cc')
-rw-r--r--gcc/rust/ast/rust-fmt.cc38
1 files changed, 35 insertions, 3 deletions
diff --git a/gcc/rust/ast/rust-fmt.cc b/gcc/rust/ast/rust-fmt.cc
index 511e947..c367e30 100644
--- a/gcc/rust/ast/rust-fmt.cc
+++ b/gcc/rust/ast/rust-fmt.cc
@@ -23,9 +23,9 @@ namespace Rust {
namespace Fmt {
Pieces
-Pieces::collect (std::string &&to_parse)
+Pieces::collect (std::string &&to_parse, bool append_newline)
{
- auto piece_slice = collect_pieces (to_parse.c_str ());
+ auto piece_slice = collect_pieces (to_parse.c_str (), append_newline);
rust_debug ("[ARTHUR] %p, %lu", (const void *) piece_slice.base_ptr,
piece_slice.len);
@@ -37,7 +37,39 @@ Pieces::collect (std::string &&to_parse)
return Pieces (piece_slice, std::move (to_parse));
}
-Pieces::~Pieces () { destroy_pieces (slice); }
+Pieces::~Pieces ()
+{
+ std::cerr << "Arthur: destoying pieces. this: " << (void *) this
+ << " slice: " << slice.base_ptr << std::endl;
+ destroy_pieces (slice);
+}
+
+Pieces::Pieces (const Pieces &other) : to_parse (other.to_parse)
+{
+ slice = clone_pieces (other.slice.base_ptr, other.slice.len, other.slice.cap);
+ std::cerr << "Arthur: copying pieces: other.to_parse: "
+ << (void *) other.to_parse.c_str ()
+ << " ours to_parse: " << (void *) to_parse.c_str () << std::endl;
+ // auto pieces = std::vector (slice.base_ptr, slice.base_ptr + slice.len);
+}
+
+Pieces &
+Pieces::operator= (const Pieces &other)
+{
+ slice = clone_pieces (other.slice.base_ptr, other.slice.len, other.slice.cap);
+ to_parse = other.to_parse;
+
+ return *this;
+}
+
+Pieces::Pieces (Pieces &&other)
+ : slice (
+ clone_pieces (other.slice.base_ptr, other.slice.len, other.slice.cap)),
+ to_parse (std::move (other.to_parse))
+{
+ std::cerr << "Arthur: moving pieces. to_parse: " << (void *) to_parse.c_str ()
+ << " base_ptr/slice: " << (void *) slice.base_ptr << std::endl;
+}
} // namespace Fmt
} // namespace Rust