From: Pierre-Emmanuel Patry Date: Wed, 3 May 2023 13:18:51 +0000 (+0200) Subject: gccrs: converter: Add Ident conversions X-Git-Tag: basepoints/gcc-15~2553 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3480ea7a05313f30e827f47180549267389387ec;p=thirdparty%2Fgcc.git 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 --- 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,