public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] ast: Add Tokenstream visitors for loop expressions
@ 2023-04-06 21:34 Thomas Schwinge
0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2023-04-06 21:34 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:bea0c13139d48294d26f0a72401d6e3fb6a48d77
commit bea0c13139d48294d26f0a72401d6e3fb6a48d77
Author: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Date: Wed Mar 22 16:17:42 2023 +0100
ast: Add Tokenstream visitors for loop expressions
Add the implementation of tokenstream dump for multiple loop
expressions.
gcc/rust/ChangeLog:
* ast/rust-ast-tokenstream.cc (TokenStream::visit): Add
visitors.
(TokenStream::visit_loop_common): Merge common loop code.
* ast/rust-ast-tokenstream.h: Add function prototypes.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Diff:
---
gcc/rust/ast/rust-ast-tokenstream.cc | 73 ++++++++++++++++++++++++++++++------
gcc/rust/ast/rust-ast-tokenstream.h | 3 ++
2 files changed, 64 insertions(+), 12 deletions(-)
diff --git a/gcc/rust/ast/rust-ast-tokenstream.cc b/gcc/rust/ast/rust-ast-tokenstream.cc
index 18337ac076c..c93c24c3fa8 100644
--- a/gcc/rust/ast/rust-ast-tokenstream.cc
+++ b/gcc/rust/ast/rust-ast-tokenstream.cc
@@ -1179,28 +1179,77 @@ TokenStream::visit (RangeToInclExpr &expr)
}
void
-TokenStream::visit (ReturnExpr &)
-{}
+TokenStream::visit (ReturnExpr &expr)
+{
+ tokens.push_back (Rust::Token::make (RETURN_TOK, expr.get_locus ()));
+ if (expr.has_returned_expr ())
+ visit (expr.get_returned_expr ());
+}
void
-TokenStream::visit (UnsafeBlockExpr &)
-{}
+TokenStream::visit (UnsafeBlockExpr &expr)
+{
+ tokens.push_back (Rust::Token::make (UNSAFE, expr.get_locus ()));
+ visit (expr.get_block_expr ());
+}
void
-TokenStream::visit (LoopExpr &)
-{}
+TokenStream::visit (LoopLabel &label)
+{
+ visit (label.get_lifetime ());
+ tokens.push_back (Rust::Token::make (COLON, label.get_locus ()));
+}
void
-TokenStream::visit (WhileLoopExpr &)
-{}
+TokenStream::visit_loop_common (BaseLoopExpr &expr)
+{
+ if (expr.has_loop_label ())
+ visit (expr.get_loop_label ());
+}
void
-TokenStream::visit (WhileLetLoopExpr &)
-{}
+TokenStream::visit (LoopExpr &expr)
+{
+ visit_loop_common (expr);
+ tokens.push_back (Rust::Token::make (LOOP, expr.get_locus ()));
+ visit (expr.get_loop_block ());
+}
void
-TokenStream::visit (ForLoopExpr &)
-{}
+TokenStream::visit (WhileLoopExpr &expr)
+{
+ visit_loop_common (expr);
+ tokens.push_back (Rust::Token::make (WHILE, expr.get_locus ()));
+ visit (expr.get_predicate_expr ());
+ visit (expr.get_loop_block ());
+}
+
+void
+TokenStream::visit (WhileLetLoopExpr &expr)
+{
+ visit_loop_common (expr);
+ tokens.push_back (Rust::Token::make (WHILE, expr.get_locus ()));
+ tokens.push_back (Rust::Token::make (LET, Location ()));
+ // TODO: The reference mention only one Pattern
+ for (auto &item : expr.get_patterns ())
+ {
+ visit (item);
+ }
+ tokens.push_back (Rust::Token::make (EQUAL, Location ()));
+ visit (expr.get_scrutinee_expr ());
+ visit (expr.get_loop_block ());
+}
+
+void
+TokenStream::visit (ForLoopExpr &expr)
+{
+ visit_loop_common (expr);
+ tokens.push_back (Rust::Token::make (FOR, expr.get_locus ()));
+ visit (expr.get_pattern ());
+ tokens.push_back (Rust::Token::make (IN, Location ()));
+ visit (expr.get_iterator_expr ());
+ visit (expr.get_loop_block ());
+}
void
TokenStream::visit (IfExpr &expr)
diff --git a/gcc/rust/ast/rust-ast-tokenstream.h b/gcc/rust/ast/rust-ast-tokenstream.h
index 58b90fba010..c8a69829d90 100644
--- a/gcc/rust/ast/rust-ast-tokenstream.h
+++ b/gcc/rust/ast/rust-ast-tokenstream.h
@@ -94,6 +94,9 @@ private:
void visit_function_common (std::unique_ptr<Type> &return_type,
std::unique_ptr<BlockExpr> &block);
+ void visit_loop_common (BaseLoopExpr &expr);
+ void visit (LoopLabel &label);
+
void visit (Literal &lit, Location locus = {});
void visit (FunctionParam ¶m);
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-04-06 21:34 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-06 21:34 [gcc/devel/rust/master] ast: Add Tokenstream visitors for loop expressions Thomas Schwinge
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).