]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: converter: Add Ident conversions
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Wed, 3 May 2023 13:18:51 +0000 (15:18 +0200)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 16 Jan 2024 17:37:18 +0000 (18:37 +0100)
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>
gcc/rust/util/rust-token-converter.cc

index 1a44de2ce7e038bb6aa25fdd5c19d4496dc37e22..5cc2fbc1db7e002c1cc0e958cb39bbc73afc82ef 100644 (file)
@@ -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,