Skip to content

Commit c883208

Browse files
committed
desugar: Use PointerVisitor for ExpressionYeast
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.
1 parent dc11f1b commit c883208

File tree

2 files changed

+9
-53
lines changed

2 files changed

+9
-53
lines changed

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

Lines changed: 3 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,16 @@
2121
#include "rust-desugar-question-mark.h"
2222
#include "rust-desugar-try-block.h"
2323
#include "rust-desugar-for-loops.h"
24-
#include "rust-ast-full.h"
2524
#include "rust-desugar-while-let.h"
2625
#include "rust-expr.h"
27-
#include "rust-stmt.h"
2826

2927
namespace Rust {
3028
namespace AST {
3129

3230
void
3331
ExpressionYeast::go (AST::Crate &crate)
3432
{
35-
DefaultASTVisitor::visit (crate);
33+
PointerVisitor::visit (crate);
3634
}
3735

3836
void
@@ -54,7 +52,7 @@ ExpressionYeast::dispatch_loops (std::unique_ptr<Expr> &loop_expr)
5452
}
5553

5654
void
57-
ExpressionYeast::dispatch (std::unique_ptr<Expr> &expr)
55+
ExpressionYeast::reseat (std::unique_ptr<Expr> &expr)
5856
{
5957
switch (expr->get_expr_kind ())
6058
{
@@ -71,47 +69,8 @@ ExpressionYeast::dispatch (std::unique_ptr<Expr> &expr)
7169
default:
7270
break;
7371
}
74-
}
75-
76-
void
77-
ExpressionYeast::visit (ExprStmt &stmt)
78-
{
79-
dispatch (stmt.get_expr_ptr ());
80-
81-
DefaultASTVisitor::visit (stmt);
82-
}
83-
84-
void
85-
ExpressionYeast::visit (CallExpr &call)
86-
{
87-
dispatch (call.get_function_expr_ptr ());
88-
89-
for (auto &arg : call.get_params ())
90-
dispatch (arg);
91-
92-
DefaultASTVisitor::visit (call);
93-
}
94-
95-
void
96-
ExpressionYeast::visit (BlockExpr &block)
97-
{
98-
for (auto &stmt : block.get_statements ())
99-
if (stmt->get_stmt_kind () == Stmt::Kind::Expr)
100-
dispatch (static_cast<ExprStmt &> (*stmt).get_expr_ptr ());
101-
102-
if (block.has_tail_expr ())
103-
dispatch (block.get_tail_expr_ptr ());
104-
105-
DefaultASTVisitor::visit (block);
106-
}
107-
108-
void
109-
ExpressionYeast::visit (LetStmt &stmt)
110-
{
111-
if (stmt.has_init_expr ())
112-
dispatch (stmt.get_init_expr_ptr ());
11372

114-
DefaultASTVisitor::visit (stmt);
73+
visit (expr);
11574
}
11675

11776
} // namespace AST

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

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#ifndef RUST_EXPRESSION_YEAST
2020
#define RUST_EXPRESSION_YEAST
2121

22-
#include "rust-ast-visitor.h"
22+
#include "rust-ast-pointer-visitor.h"
2323
#include "rust-ast.h"
2424
#include "rust-desugar-question-mark.h"
2525

@@ -28,22 +28,19 @@ namespace AST {
2828

2929
// This visitor takes care of all the expression desugars: try-blocks,
3030
// error-propagation, etc.
31-
class ExpressionYeast : public AST::DefaultASTVisitor
31+
class ExpressionYeast : public AST::PointerVisitor
3232
{
33-
using AST::DefaultASTVisitor::visit;
33+
using AST::PointerVisitor::reseat;
34+
using AST::PointerVisitor::visit;
3435

3536
public:
3637
void go (AST::Crate &);
3738

3839
private:
3940
// Dispatch to the proper desugar
40-
void dispatch (std::unique_ptr<Expr> &expr);
41-
void dispatch_loops (std::unique_ptr<Expr> &loop_expr);
41+
void reseat (std::unique_ptr<Expr> &expr) override;
4242

43-
void visit (AST::ExprStmt &) override;
44-
void visit (AST::CallExpr &) override;
45-
void visit (AST::LetStmt &) override;
46-
void visit (AST::BlockExpr &) override;
43+
void dispatch_loops (std::unique_ptr<Expr> &loop_expr);
4744
};
4845

4946
} // namespace AST

0 commit comments

Comments
 (0)