From 3480ea7a05313f30e827f47180549267389387ec Mon Sep 17 00:00:00 2001 From: Pierre-Emmanuel Patry Date: Wed, 3 May 2023 15:18:51 +0200 Subject: [PATCH] gccrs: 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 --- gcc/rust/util/rust-token-converter.cc | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/gcc/rust/util/rust-token-converter.cc b/gcc/rust/util/rust-token-converter.cc index 1a44de2ce7e0..5cc2fbc1db7e 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 &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 &result) -{} +from_ident (const ProcMacro::Ident &ident, std::vector &result) +{ + std::string value (reinterpret_cast (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, -- 2.47.2