[gcc r14-7580] gccrs: converter: Add group conversion implementation

Arthur Cohen cohenarthur@gcc.gnu.org
Tue Jan 16 17:42:23 GMT 2024


https://gcc.gnu.org/g:c3462989ec4755e1a1d9aaa6364667927112c413

commit r14-7580-gc3462989ec4755e1a1d9aaa6364667927112c413
Author: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Date:   Wed May 3 10:32:17 2023 +0200

    gccrs: converter: Add group conversion implementation
    
    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>

Diff:
---
 gcc/rust/util/rust-token-converter.cc | 35 +++++++++++++++++++++++++++++++++--
 1 file changed, 33 insertions(+), 2 deletions(-)

diff --git a/gcc/rust/util/rust-token-converter.cc b/gcc/rust/util/rust-token-converter.cc
index 25abf763e24..e40d2135fda 100644
--- a/gcc/rust/util/rust-token-converter.cc
+++ b/gcc/rust/util/rust-token-converter.cc
@@ -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)


More information about the Gcc-cvs mailing list