diff options
author | Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com> | 2023-07-19 11:50:23 +0200 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2024-01-16 18:55:56 +0100 |
commit | f7af0b90ef489eb90bcab2dd47a171dc550fb303 (patch) | |
tree | 48396bf81ea49cc605bc6954ffba97eca99c2afd /libgrust/libproc_macro | |
parent | bee12555414e19c9cbeaf3b7550f9f93e939e392 (diff) | |
download | gcc-f7af0b90ef489eb90bcab2dd47a171dc550fb303.zip gcc-f7af0b90ef489eb90bcab2dd47a171dc550fb303.tar.gz gcc-f7af0b90ef489eb90bcab2dd47a171dc550fb303.tar.bz2 |
gccrs: libproc_macro: Change Ident structure
Use FFIString in Ident structure rather that a raw pointer and a
length, this will reduce the size of the code dealing with raw
pointers. Which should prevent some error.
gcc/rust/ChangeLog:
* util/rust-token-converter.cc (from_ident): Adapt code to new
constructor.
libgrust/ChangeLog:
* libproc_macro/ident.cc (Ident__new): Constructor
accepts an FFIString now.
(Ident__new_raw): Likewise.
(Ident::clone): Internal members change means clone also change.
(Ident::make_ident): Change constructor call.
(Ident::drop): Add call to FFIString::clone.
* libproc_macro/ident.h (struct Ident): Remove raw
pointer and length, add an FFIString inside instead.
(Ident__new): Change constructor.
(Ident__new_raw): Change constructor.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Diffstat (limited to 'libgrust/libproc_macro')
-rw-r--r-- | libgrust/libproc_macro/ident.cc | 28 | ||||
-rw-r--r-- | libgrust/libproc_macro/ident.h | 13 |
2 files changed, 14 insertions, 27 deletions
diff --git a/libgrust/libproc_macro/ident.cc b/libgrust/libproc_macro/ident.cc index 6c8472d..221d38e 100644 --- a/libgrust/libproc_macro/ident.cc +++ b/libgrust/libproc_macro/ident.cc @@ -28,15 +28,15 @@ namespace ProcMacro { extern "C" { Ident -Ident__new (unsigned char *str, std::uint64_t len, Span span) +Ident__new (FFIString str, Span span) { - return Ident::make_ident (str, len, span); + return Ident::make_ident (str, span); } Ident -Ident__new_raw (unsigned char *str, std::uint64_t len, Span span) +Ident__new_raw (FFIString str, Span span) { - return Ident::make_ident (str, len, span, true); + return Ident::make_ident (str, span, true); } void @@ -55,35 +55,25 @@ Ident__clone (const Ident *ident) Ident Ident::clone () const { - unsigned char *val = new unsigned char[this->len]; - // FIXME: UTF-8 Update this with sizeof codepoint instead - std::memcpy (val, this->val, this->len * sizeof (char)); - return {this->is_raw, val, this->len}; + return {this->is_raw, value.clone (), this->span}; } Ident Ident::make_ident (std::string str, Span span, bool raw) { - return Ident::make_ident (reinterpret_cast<const unsigned char *> ( - str.c_str ()), - str.length (), span, raw); + return Ident::make_ident (FFIString::make_ffistring (str), span, raw); } Ident -Ident::make_ident (const unsigned char *str, std::uint64_t len, Span span, - bool raw) +Ident::make_ident (FFIString str, Span span, bool raw) { - unsigned char *val = new unsigned char[len]; - // FIXME: UTF-8 Update this with sizeof codepoint instead - std::memcpy (val, str, len * sizeof (char)); - return {raw, val, len}; + return {raw, str, span}; } void Ident::drop (Ident *ident) { - delete[] ident->val; - ident->len = 0; + FFIString::drop (&ident->value); } } // namespace ProcMacro diff --git a/libgrust/libproc_macro/ident.h b/libgrust/libproc_macro/ident.h index 28d6ebe..66547d9 100644 --- a/libgrust/libproc_macro/ident.h +++ b/libgrust/libproc_macro/ident.h @@ -27,23 +27,20 @@ #include <string> #include "span.h" +#include "ffistring.h" namespace ProcMacro { struct Ident { bool is_raw; - // TODO: Adapt this to UTF-8 - unsigned char *val; - // Length in bytes - std::uint64_t len; + FFIString value; Span span; public: Ident clone () const; static Ident make_ident (std::string str, Span span, bool raw = false); - static Ident make_ident (const unsigned char *str, std::uint64_t len, - Span span, bool raw = false); + static Ident make_ident (FFIString str, Span span, bool raw = false); static void drop (Ident *ident); }; @@ -51,10 +48,10 @@ public: extern "C" { Ident -Ident__new (unsigned char *str, std::uint64_t len, Span span); +Ident__new (FFIString str, Span span); Ident -Ident__new_raw (unsigned char *str, std::uint64_t len, Span span); +Ident__new_raw (FFIString str, Span span); void Ident__drop (Ident *ident); |