diff options
author | Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com> | 2023-05-03 15:18:51 +0200 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2023-05-11 09:38:22 +0200 |
commit | b61549737c59f283852e8338b098cb78b1713be8 (patch) | |
tree | 6e66f9c5a270276734af89747a27d5bfc4e74092 | |
parent | f616a5db5cce0dc48bef0200952ae4c034cd107d (diff) | |
download | gcc-b61549737c59f283852e8338b098cb78b1713be8.zip gcc-b61549737c59f283852e8338b098cb78b1713be8.tar.gz gcc-b61549737c59f283852e8338b098cb78b1713be8.tar.bz2 |
converter: Add Ident conversions
Add the implementation to convert an Ident structure back to a token.
gcc/rust/ChangeLog:
* util/rust-token-converter.cc (from_tokenstream): Add
conversion of Ident structures.
(from_ident): Likewise.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
-rw-r--r-- | gcc/rust/util/rust-token-converter.cc | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/gcc/rust/util/rust-token-converter.cc b/gcc/rust/util/rust-token-converter.cc index 1a44de2..5cc2fbc 100644 --- a/gcc/rust/util/rust-token-converter.cc +++ b/gcc/rust/util/rust-token-converter.cc @@ -302,9 +302,26 @@ static void from_tokenstream (const ProcMacro::TokenStream &ts, std::vector<const_TokenPtr> &result); +/** + * Append the token corresponding to a given Ident to a vector. + * + * @param literal Reference to the Ident to convert. + * @param result Reference to the output vector. + */ static void -from_ident (ProcMacro::Ident ident, std::vector<const_TokenPtr> &result) -{} +from_ident (const ProcMacro::Ident &ident, std::vector<const_TokenPtr> &result) +{ + std::string value (reinterpret_cast<const char *> (ident.val), ident.len); + if (ident.is_raw) + { + value = "r#" + value; + } + + // TODO: Inject span -> for now spans are not stored in Ident, once changed + // the span should be injected in the built token below. + Lexer lexer (value); + result.push_back (lexer.peek_token ()); +} static void string_literal (const ProcMacro::StringPayload &payload, |