aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>2023-05-03 10:32:17 +0200
committerArthur Cohen <arthur.cohen@embecosm.com>2023-05-11 09:38:21 +0200
commit87dfca85c99477d442d62373bd477b87f95857fe (patch)
tree806d86bfce602170dcf0f25cab67856c13ba37d7
parent15225362fe308ee1cf71018ac84203574feaa99d (diff)
downloadgcc-87dfca85c99477d442d62373bd477b87f95857fe.zip
gcc-87dfca85c99477d442d62373bd477b87f95857fe.tar.gz
gcc-87dfca85c99477d442d62373bd477b87f95857fe.tar.bz2
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>
-rw-r--r--gcc/rust/util/rust-token-converter.cc35
1 files changed, 33 insertions, 2 deletions
diff --git a/gcc/rust/util/rust-token-converter.cc b/gcc/rust/util/rust-token-converter.cc
index 25abf76..e40d213 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)