diff options
author | Arthur Cohen <arthur.cohen@embecosm.com> | 2024-02-22 14:59:17 +0100 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2024-08-01 13:12:14 +0200 |
commit | 5151b289ad4090072a12fb6ac6219c035118eb32 (patch) | |
tree | d1875583bc90444cd225bd87aa99eaf70192383b /gcc/rust/ast/rust-fmt.cc | |
parent | 68cb878c1dab0636da4f686d6c8f5d4fa3b66e3b (diff) | |
download | gcc-5151b289ad4090072a12fb6ac6219c035118eb32.zip gcc-5151b289ad4090072a12fb6ac6219c035118eb32.tar.gz gcc-5151b289ad4090072a12fb6ac6219c035118eb32.tar.bz2 |
gccrs: lower: Add base for lowering FormatArgs nodes
gcc/rust/ChangeLog:
* Make-lang.in: Compile the new source file.
* ast/rust-ast-collector.cc (TokenCollector::visit): Error out when
visiting FormatArgs nodes.
* resolve/rust-ast-resolve-base.cc (ResolverBase::visit): Likewise.
* hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): Likewise.
* ast/rust-ast.cc (FormatArgs::get_locus): New.
* ast/rust-builtin-ast-nodes.h: Improve FormatArgs API.
* ast/rust-fmt.cc (Pieces::~Pieces): Cleanup.
(Pieces::Pieces): Likewise.
* ast/rust-fmt.h (struct Pieces): Add pieces_vector member.
* hir/rust-ast-lower-format-args.cc: New file.
* hir/rust-ast-lower-format-args.h: New file.
Diffstat (limited to 'gcc/rust/ast/rust-fmt.cc')
-rw-r--r-- | gcc/rust/ast/rust-fmt.cc | 39 |
1 files changed, 15 insertions, 24 deletions
diff --git a/gcc/rust/ast/rust-fmt.cc b/gcc/rust/ast/rust-fmt.cc index c367e30..b82e089 100644 --- a/gcc/rust/ast/rust-fmt.cc +++ b/gcc/rust/ast/rust-fmt.cc @@ -27,30 +27,23 @@ Pieces::collect (std::string &&to_parse, bool append_newline) { 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); - // this performs multiple copies, can we avoid them maybe? - // auto pieces = std::vector<Piece> (piece_slice.base_ptr, - // piece_slice.base_ptr + piece_slice.len); - - return Pieces (piece_slice, std::move (to_parse)); + // TODO: Instead of just creating a vec of, basically, `ffi::Piece`s, we + // should transform them into the proper C++ type which we can work with. so + // transform all the strings into C++ strings? all the Option<T> into + // tl::optional<T>? + auto pieces = std::vector<Piece> (piece_slice.base_ptr, + piece_slice.base_ptr + piece_slice.len); + + return Pieces (std::move (pieces), piece_slice, std::move (to_parse)); } -Pieces::~Pieces () -{ - std::cerr << "Arthur: destoying pieces. this: " << (void *) this - << " slice: " << slice.base_ptr << std::endl; - destroy_pieces (slice); -} +Pieces::~Pieces () { destroy_pieces (slice); } -Pieces::Pieces (const Pieces &other) : to_parse (other.to_parse) +Pieces::Pieces (const Pieces &other) + : pieces_vector (other.pieces_vector), 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 & @@ -63,13 +56,11 @@ Pieces::operator= (const Pieces &other) } Pieces::Pieces (Pieces &&other) - : slice ( - clone_pieces (other.slice.base_ptr, other.slice.len, other.slice.cap)), + : pieces_vector (std::move (other.pieces_vector)), + 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 |