]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: desugar: Use PointerVisitor for ExpressionYeast
authorArthur Cohen <arthur.cohen@embecosm.com>
Thu, 14 Aug 2025 08:29:57 +0000 (10:29 +0200)
committerArthur Cohen <arthur.cohen@embecosm.com>
Thu, 30 Oct 2025 19:58:49 +0000 (20:58 +0100)
gcc/rust/ChangeLog:

* ast/rust-expression-yeast.cc (ExpressionYeast::dispatch): Rename to...
(ExpressionYeast::reseat): ...this.
(ExpressionYeast::visit): Remove.
* ast/rust-expression-yeast.h: Inherit from PointerVisitor, override reseat instead
of declaring dispatch.

gcc/rust/ast/rust-expression-yeast.cc
gcc/rust/ast/rust-expression-yeast.h

index 9f6a62ff37c29624a6e9df975ad582bf659fa3ca..7626abc721c9b77802cc75f885695f5fadf16d72 100644 (file)
 #include "rust-desugar-question-mark.h"
 #include "rust-desugar-try-block.h"
 #include "rust-desugar-for-loops.h"
-#include "rust-ast-full.h"
 #include "rust-desugar-while-let.h"
 #include "rust-expr.h"
-#include "rust-stmt.h"
 
 namespace Rust {
 namespace AST {
@@ -32,7 +30,7 @@ namespace AST {
 void
 ExpressionYeast::go (AST::Crate &crate)
 {
-  DefaultASTVisitor::visit (crate);
+  PointerVisitor::visit (crate);
 }
 
 void
@@ -54,7 +52,7 @@ ExpressionYeast::dispatch_loops (std::unique_ptr<Expr> &loop_expr)
 }
 
 void
-ExpressionYeast::dispatch (std::unique_ptr<Expr> &expr)
+ExpressionYeast::reseat (std::unique_ptr<Expr> &expr)
 {
   switch (expr->get_expr_kind ())
     {
@@ -71,47 +69,8 @@ ExpressionYeast::dispatch (std::unique_ptr<Expr> &expr)
     default:
       break;
     }
-}
-
-void
-ExpressionYeast::visit (ExprStmt &stmt)
-{
-  dispatch (stmt.get_expr_ptr ());
-
-  DefaultASTVisitor::visit (stmt);
-}
-
-void
-ExpressionYeast::visit (CallExpr &call)
-{
-  dispatch (call.get_function_expr_ptr ());
-
-  for (auto &arg : call.get_params ())
-    dispatch (arg);
-
-  DefaultASTVisitor::visit (call);
-}
-
-void
-ExpressionYeast::visit (BlockExpr &block)
-{
-  for (auto &stmt : block.get_statements ())
-    if (stmt->get_stmt_kind () == Stmt::Kind::Expr)
-      dispatch (static_cast<ExprStmt &> (*stmt).get_expr_ptr ());
-
-  if (block.has_tail_expr ())
-    dispatch (block.get_tail_expr_ptr ());
-
-  DefaultASTVisitor::visit (block);
-}
-
-void
-ExpressionYeast::visit (LetStmt &stmt)
-{
-  if (stmt.has_init_expr ())
-    dispatch (stmt.get_init_expr_ptr ());
 
-  DefaultASTVisitor::visit (stmt);
+  visit (expr);
 }
 
 } // namespace AST
index 855918fbc216e283746f8ca4897779a4118fb9c1..3f64b1d6fa7d5eb28382eca8e77cfe19390b2ad8 100644 (file)
@@ -19,7 +19,7 @@
 #ifndef RUST_EXPRESSION_YEAST
 #define RUST_EXPRESSION_YEAST
 
-#include "rust-ast-visitor.h"
+#include "rust-ast-pointer-visitor.h"
 #include "rust-ast.h"
 #include "rust-desugar-question-mark.h"
 
@@ -28,22 +28,19 @@ namespace AST {
 
 // This visitor takes care of all the expression desugars: try-blocks,
 // error-propagation, etc.
-class ExpressionYeast : public AST::DefaultASTVisitor
+class ExpressionYeast : public AST::PointerVisitor
 {
-  using AST::DefaultASTVisitor::visit;
+  using AST::PointerVisitor::reseat;
+  using AST::PointerVisitor::visit;
 
 public:
   void go (AST::Crate &);
 
 private:
   // Dispatch to the proper desugar
-  void dispatch (std::unique_ptr<Expr> &expr);
-  void dispatch_loops (std::unique_ptr<Expr> &loop_expr);
+  void reseat (std::unique_ptr<Expr> &expr) override;
 
-  void visit (AST::ExprStmt &) override;
-  void visit (AST::CallExpr &) override;
-  void visit (AST::LetStmt &) override;
-  void visit (AST::BlockExpr &) override;
+  void dispatch_loops (std::unique_ptr<Expr> &loop_expr);
 };
 
 } // namespace AST