]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: converter: Add group conversion implementation
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Wed, 3 May 2023 08:32:17 +0000 (10:32 +0200)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 16 Jan 2024 17:37:17 +0000 (18:37 +0100)
Add conversion of a given Group reference.

gcc/rust/ChangeLog:

* util/rust-token-converter.cc (from_punct): Add group
conversion.
(from_group): Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
gcc/rust/util/rust-token-converter.cc

index 25abf763e241ab5beffff32fdf5f934def7860b0..e40d2135fda255cc7fbdf04278d4572fcf6fda40 100644 (file)
@@ -312,9 +312,40 @@ static void
 from_punct (ProcMacro::Punct punct, std::vector<TokenPtr> &result)
 {}
 
+/**
+ * Iterate over a Group and append all inner tokens to a vector enclosed by it's
+ * delimiters.
+ *
+ * @param g Reference to the Group to convert.
+ * @param result Reference to the vector tokens should be appended to.
+ */
 static void
-from_group (ProcMacro::Group g, std::vector<TokenPtr> &result)
-{}
+from_group (const ProcMacro::Group &g, std::vector<TokenPtr> &result)
+{
+  switch (g.delimiter)
+    {
+    case ProcMacro::PARENTHESIS:
+      result.push_back (Token::make (LEFT_PAREN, Location ()));
+      from_tokenstream (g.stream, result);
+      result.push_back (Token::make (RIGHT_PAREN, Location ()));
+      break;
+    case ProcMacro::BRACE:
+      result.push_back (Token::make (LEFT_CURLY, Location ()));
+      from_tokenstream (g.stream, result);
+      result.push_back (Token::make (RIGHT_CURLY, Location ()));
+      break;
+    case ProcMacro::BRACKET:
+      result.push_back (Token::make (LEFT_SQUARE, Location ()));
+      from_tokenstream (g.stream, result);
+      result.push_back (Token::make (RIGHT_SQUARE, Location ()));
+      break;
+    case ProcMacro::NONE:
+      from_tokenstream (g.stream, result);
+      break;
+    default:
+      gcc_unreachable ();
+    }
+}
 
 static void
 from_tokenstream (ProcMacro::TokenStream ts, std::vector<TokenPtr> &result)