Skip to content

Commit ef5dd50

Browse files
CohenArthurP-E-P
authored andcommitted
expand: Inherit from PointerVisitor
gcc/rust/ChangeLog: * expand/rust-expand-visitor.cc: Remove old visitors. * expand/rust-expand-visitor.h: Likewise, plus inherit from PointerVisitor.
1 parent 32ce955 commit ef5dd50

File tree

2 files changed

+24
-39
lines changed

2 files changed

+24
-39
lines changed

gcc/rust/expand/rust-expand-visitor.cc

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -597,12 +597,6 @@ void
597597
ExpandVisitor::visit (AST::MetaItemPathExpr &)
598598
{}
599599

600-
void
601-
ExpandVisitor::visit (AST::ErrorPropagationExpr &expr)
602-
{
603-
visit (expr.get_propagating_expr ());
604-
}
605-
606600
void
607601
ExpandVisitor::visit (AST::ArithmeticOrLogicalExpr &expr)
608602
{
@@ -664,15 +658,6 @@ ExpandVisitor::visit (AST::CallExpr &expr)
664658
maybe_expand_expr (param);
665659
}
666660

667-
void
668-
ExpandVisitor::visit (AST::MethodCallExpr &expr)
669-
{
670-
visit (expr.get_receiver_expr ());
671-
672-
for (auto &param : expr.get_params ())
673-
maybe_expand_expr (param);
674-
}
675-
676661
void
677662
ExpandVisitor::visit (AST::ClosureExprInner &expr)
678663
{
@@ -739,25 +724,6 @@ ExpandVisitor::visit (AST::IfLetExprConseqElse &expr)
739724
visit (expr.get_else_block ());
740725
}
741726

742-
void
743-
ExpandVisitor::visit (AST::MatchExpr &expr)
744-
{
745-
visit (expr.get_scrutinee_expr ());
746-
747-
for (auto &match_case : expr.get_match_cases ())
748-
{
749-
auto &arm = match_case.get_arm ();
750-
751-
for (auto &pattern : arm.get_patterns ())
752-
maybe_expand_pattern (pattern);
753-
754-
if (arm.has_match_arm_guard ())
755-
maybe_expand_expr (arm.get_guard_expr_ptr ());
756-
757-
maybe_expand_expr (match_case.get_expr_ptr ());
758-
}
759-
}
760-
761727
void
762728
ExpandVisitor::visit (AST::TupleExpr &expr)
763729
{

gcc/rust/expand/rust-expand-visitor.h

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

22+
#include "rust-ast-pointer-visitor.h"
2223
#include "rust-ast-visitor.h"
2324
#include "rust-item.h"
2425
#include "rust-macro-expand.h"
@@ -36,7 +37,7 @@ bool is_derive (AST::Attribute &attr);
3637
*/
3738
bool is_builtin (AST::Attribute &attr);
3839

39-
class ExpandVisitor : public AST::DefaultASTVisitor
40+
class ExpandVisitor : public AST::PointerVisitor
4041
{
4142
public:
4243
ExpandVisitor (MacroExpander &expander)
@@ -46,7 +47,28 @@ class ExpandVisitor : public AST::DefaultASTVisitor
4647
/* Expand all of the macro invocations currently contained in a crate */
4748
void go (AST::Crate &crate);
4849

49-
using AST::DefaultASTVisitor::visit;
50+
using AST::PointerVisitor::reseat;
51+
using AST::PointerVisitor::visit;
52+
53+
void reseat (std::unique_ptr<AST::Expr> &ptr) override
54+
{
55+
maybe_expand_expr (ptr);
56+
}
57+
58+
void reseat (std::unique_ptr<AST::Type> &ptr) override
59+
{
60+
maybe_expand_type (ptr);
61+
}
62+
63+
void reseat (std::unique_ptr<AST::TypeNoBounds> &ptr) override
64+
{
65+
maybe_expand_type (ptr);
66+
}
67+
68+
void reseat (std::unique_ptr<AST::Pattern> &ptr) override
69+
{
70+
maybe_expand_pattern (ptr);
71+
}
5072

5173
/**
5274
* Maybe expand a macro invocation in lieu of an expression, type or pattern.
@@ -214,7 +236,6 @@ class ExpandVisitor : public AST::DefaultASTVisitor
214236
void visit (AST::AttrInputMacro &) override;
215237
void visit (AST::MetaItemLitExpr &) override;
216238
void visit (AST::MetaItemPathExpr &) override;
217-
void visit (AST::ErrorPropagationExpr &expr) override;
218239
void visit (AST::ArithmeticOrLogicalExpr &expr) override;
219240
void visit (AST::ComparisonExpr &expr) override;
220241
void visit (AST::LazyBooleanExpr &expr) override;
@@ -225,7 +246,6 @@ class ExpandVisitor : public AST::DefaultASTVisitor
225246
void visit (AST::StructExprStruct &expr) override;
226247

227248
void visit (AST::CallExpr &expr) override;
228-
void visit (AST::MethodCallExpr &expr) override;
229249
void visit (AST::ClosureExprInner &expr) override;
230250

231251
void visit (AST::BlockExpr &expr) override;
@@ -236,7 +256,6 @@ class ExpandVisitor : public AST::DefaultASTVisitor
236256
void visit (AST::IfExprConseqElse &expr) override;
237257
void visit (AST::IfLetExpr &expr) override;
238258
void visit (AST::IfLetExprConseqElse &expr) override;
239-
void visit (AST::MatchExpr &expr) override;
240259
void visit (AST::TupleExpr &expr) override;
241260
void visit (AST::TypeParam &param) override;
242261
void visit (AST::LifetimeWhereClauseItem &) override;

0 commit comments

Comments
 (0)