From: Pierre-Emmanuel Patry <[email protected]>
This commit introduce a new public function to visit function parameters
in the default visitor. It allows visitors derived from DefaultVisitor
to override only a small part of the default visitor.
gcc/rust/ChangeLog:
* ast/rust-ast-visitor.cc (DefaultASTVisitor::visit_function_params):
Add specialized function to visit function parameters.
(DefaultASTVisitor::visit): Remove parameter visit and call specialized
function instead.
* ast/rust-ast-visitor.h: Add function prototye.
* resolve/rust-late-name-resolver-2.0.cc (Late::visit): Remove
function.
(Late::visit_function_params): Override specialized visit function.
* resolve/rust-late-name-resolver-2.0.h: Add overriden function
prototype.
Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
---
gcc/rust/ast/rust-ast-visitor.cc | 12 ++++++--
gcc/rust/ast/rust-ast-visitor.h | 2 ++
.../resolve/rust-late-name-resolver-2.0.cc | 30 ++++---------------
.../resolve/rust-late-name-resolver-2.0.h | 4 ++-
4 files changed, 20 insertions(+), 28 deletions(-)
diff --git a/gcc/rust/ast/rust-ast-visitor.cc b/gcc/rust/ast/rust-ast-visitor.cc
index 6862024354f..87e7b86573b 100644
--- a/gcc/rust/ast/rust-ast-visitor.cc
+++ b/gcc/rust/ast/rust-ast-visitor.cc
@@ -831,6 +831,13 @@ DefaultASTVisitor::visit (AST::UseDeclaration &use_decl)
visit (use_decl.get_tree ());
}
+void
+DefaultASTVisitor::visit_function_params (AST::Function &function)
+{
+ for (auto ¶m : function.get_function_params ())
+ visit (param);
+}
+
void
DefaultASTVisitor::visit (AST::Function &function)
{
@@ -839,8 +846,9 @@ DefaultASTVisitor::visit (AST::Function &function)
visit (function.get_qualifiers ());
for (auto &generic : function.get_generic_params ())
visit (generic);
- for (auto ¶m : function.get_function_params ())
- visit (param);
+
+ visit_function_params (function);
+
if (function.has_return_type ())
visit (function.get_return_type ());
if (function.has_where_clause ())
diff --git a/gcc/rust/ast/rust-ast-visitor.h b/gcc/rust/ast/rust-ast-visitor.h
index 6d243e7b063..b1fc50465a1 100644
--- a/gcc/rust/ast/rust-ast-visitor.h
+++ b/gcc/rust/ast/rust-ast-visitor.h
@@ -242,6 +242,8 @@ public:
class DefaultASTVisitor : public ASTVisitor
{
public:
+ virtual void visit_function_params (AST::Function &function);
+
virtual void visit (AST::Crate &crate);
virtual void visit (AST::Token &tok) override;
diff --git a/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
b/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
index e26e4187b28..6ec04229c8e 100644
--- a/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
@@ -266,34 +266,14 @@ Late::visit (AST::AltPattern &pattern)
}
void
-Late::visit (AST::Function &function)
+Late::visit_function_params (AST::Function &function)
{
- auto def_fn = [this, &function] () {
- visit_outer_attrs (function);
- visit (function.get_visibility ());
- visit (function.get_qualifiers ());
- for (auto &generic : function.get_generic_params ())
- visit (generic);
-
- // We only care about params
- ctx.bindings.enter (BindingSource::Param);
-
- for (auto ¶m : function.get_function_params ())
- visit (param);
-
- ctx.bindings.exit ();
-
- // Back to regular visit
+ ctx.bindings.enter (BindingSource::Param);
- if (function.has_return_type ())
- visit (function.get_return_type ());
- if (function.has_where_clause ())
- visit (function.get_where_clause ());
- if (function.has_body ())
- visit (*function.get_definition ());
- };
+ for (auto ¶m : function.get_function_params ())
+ visit (param);
- ctx.scoped (Rib::Kind::Function, function.get_node_id (), def_fn);
+ ctx.bindings.exit ();
}
void
diff --git a/gcc/rust/resolve/rust-late-name-resolver-2.0.h
b/gcc/rust/resolve/rust-late-name-resolver-2.0.h
index 9e2bfdefaad..171d9bfe0f6 100644
--- a/gcc/rust/resolve/rust-late-name-resolver-2.0.h
+++ b/gcc/rust/resolve/rust-late-name-resolver-2.0.h
@@ -37,6 +37,9 @@ public:
void new_label (Identifier name, NodeId id);
+ // Specialized visit bits
+ void visit_function_params (AST::Function &function) override;
+
// some more label declarations
void visit (AST::LetStmt &) override;
// TODO: Do we need this?
@@ -44,7 +47,6 @@ public:
void visit (AST::IdentifierPattern &) override;
void visit (AST::StructPatternFieldIdent &) override;
void visit (AST::AltPattern &) override;
- void visit (AST::Function &) override;
void visit (AST::SelfParam &) override;
void visit (AST::MatchArm &) override;
void visit (AST::ForLoopExpr &) override;
--
2.49.0