aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/ast
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/rust/ast')
-rw-r--r--gcc/rust/ast/rust-ast-collector.cc3
-rw-r--r--gcc/rust/ast/rust-ast.cc2
-rw-r--r--gcc/rust/ast/rust-builtin-ast-nodes.h32
-rw-r--r--gcc/rust/ast/rust-fmt.cc39
-rw-r--r--gcc/rust/ast/rust-fmt.h13
5 files changed, 37 insertions, 52 deletions
diff --git a/gcc/rust/ast/rust-ast-collector.cc b/gcc/rust/ast/rust-ast-collector.cc
index b8ec623..c0e8e77 100644
--- a/gcc/rust/ast/rust-ast-collector.cc
+++ b/gcc/rust/ast/rust-ast-collector.cc
@@ -2810,7 +2810,8 @@ TokenCollector::visit (BareFunctionType &type)
void
TokenCollector::visit (AST::FormatArgs &fmt)
{
- rust_sorry_at (0, "unimplemented format_args!() visitor");
+ rust_sorry_at (fmt.get_locus (), "%s:%u: unimplemented FormatArgs visitor",
+ __FILE__, __LINE__);
}
} // namespace AST
diff --git a/gcc/rust/ast/rust-ast.cc b/gcc/rust/ast/rust-ast.cc
index f3dabc6..fbd795f 100644
--- a/gcc/rust/ast/rust-ast.cc
+++ b/gcc/rust/ast/rust-ast.cc
@@ -5065,7 +5065,7 @@ FormatArgs::as_string () const
location_t
FormatArgs::get_locus () const
{
- rust_unreachable ();
+ return loc;
}
bool
diff --git a/gcc/rust/ast/rust-builtin-ast-nodes.h b/gcc/rust/ast/rust-builtin-ast-nodes.h
index 6e26717..780d1a9 100644
--- a/gcc/rust/ast/rust-builtin-ast-nodes.h
+++ b/gcc/rust/ast/rust-builtin-ast-nodes.h
@@ -184,48 +184,32 @@ public:
FormatArgs (location_t loc, Fmt::Pieces &&template_str,
FormatArguments &&arguments)
- : loc (loc), template_str (std::move (template_str)),
+ : loc (loc), template_pieces (std::move (template_str)),
arguments (std::move (arguments))
{}
- FormatArgs (FormatArgs &&other)
- : loc (std::move (other.loc)),
- template_str (std::move (other.template_str)),
- arguments (std::move (other.arguments))
- {
- std::cerr << "[ARTHUR] moving FormatArgs" << std::endl;
- }
-
- // FIXME: This might be invalid - we are reusing the same memory allocated
- // on the Rust side for `other`. This is probably valid as long as we only
- // ever read that memory and never write to it.
- FormatArgs (const FormatArgs &other)
- : loc (other.loc), template_str (other.template_str),
- arguments (other.arguments)
- {
- std::cerr << "[ARTHUR] copying FormatArgs" << std::endl;
- }
-
- // FormatArgs &operator= (const FormatArgs &other) = default;
- // : template_str (other.template_str), arguments (other.arguments)
- // {}
+ FormatArgs (FormatArgs &&other) = default;
+ FormatArgs (const FormatArgs &other) = default;
+ FormatArgs &operator= (const FormatArgs &other) = default;
void accept_vis (AST::ASTVisitor &vis) override;
+ const Fmt::Pieces &get_template () const { return template_pieces; }
+ virtual location_t get_locus () const override;
+
private:
location_t loc;
// FIXME: This probably needs to be a separate type - it is one in rustc's
// expansion of format_args!(). There is extra handling associated with it.
// we can maybe do that in rust-fmt.cc? in collect_pieces()? like do the
// transformation into something we can handle better
- Fmt::Pieces template_str;
+ Fmt::Pieces template_pieces;
FormatArguments arguments;
bool marked_for_strip = false;
protected:
virtual std::string as_string () const override;
- virtual location_t get_locus () const override;
virtual bool is_expr_without_block () const override;
virtual void mark_for_strip () override;
virtual bool is_marked_for_strip () const override;
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
diff --git a/gcc/rust/ast/rust-fmt.h b/gcc/rust/ast/rust-fmt.h
index 22447c4..ba412f9 100644
--- a/gcc/rust/ast/rust-fmt.h
+++ b/gcc/rust/ast/rust-fmt.h
@@ -262,6 +262,8 @@ struct Pieces
Pieces (Pieces &&other);
+ const std::vector<Piece> &get_pieces () const { return pieces_vector; }
+
// {
// slice = clone_pieces (&other.slice);
// to_parse = other.to_parse;
@@ -270,10 +272,17 @@ struct Pieces
// }
private:
- Pieces (PieceSlice slice, std::string &&to_parse)
- : slice (slice), to_parse (std::move (to_parse))
+ Pieces (std::vector<Piece> &&pieces_vector, PieceSlice slice,
+ std::string &&to_parse)
+ : pieces_vector (std::move (pieces_vector)), slice (slice),
+ to_parse (std::move (to_parse))
{}
+ std::vector<Piece> pieces_vector;
+
+ // this memory is held for FFI reasons - it needs to be released and cloned
+ // precisely, so try to not access it/modify it if possible. you should
+ // instead work with `pieces_vector`
PieceSlice slice;
std::string to_parse;
};