Skip to content

Commit

Permalink
Make default resolver inherit from default visitor
Browse files Browse the repository at this point in the history
The default resolver put some scope in place but mostly has traversal
functions similar to the default ast visitor, making it inherit from the
default visitor allows us to avoid code duplication.

gcc/rust/ChangeLog:

	* resolve/rust-default-resolver.cc (DefaultResolver::visit): Remove
	duplicated functions.
	* resolve/rust-default-resolver.h (class DefaultResolver): Make the
	default resolver inherit from the default visitor.

Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
  • Loading branch information
P-E-P committed Dec 11, 2023
1 parent 1b6adb1 commit 1748242
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 279 deletions.
240 changes: 2 additions & 238 deletions gcc/rust/resolve/rust-default-resolver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include "rust-default-resolver.h"
#include "rust-ast-full.h"
#include "rust-ast-visitor.h"
#include "rust-item.h"

namespace Rust {
Expand Down Expand Up @@ -148,26 +149,11 @@ DefaultResolver::visit (AST::StructStruct &type)
// we also can't visit `StructField`s by default, so there's nothing to do -
// correct? or should we do something like

for (auto &field : type.get_fields ())
field.get_field_type ()->accept_vis (*this);
AST::DefaultASTVisitor::visit (type);

// FIXME: ???
}

void
DefaultResolver::visit (AST::TupleStruct &type)
{
for (auto &field : type.get_fields ())
field.get_field_type ()->accept_vis (*this);
}

void
DefaultResolver::visit (AST::Union &type)
{
for (auto &field : type.get_variants ())
field.get_field_type ()->accept_vis (*this);
}

void
DefaultResolver::visit (AST::Enum &type)
{
Expand All @@ -182,118 +168,6 @@ DefaultResolver::visit (AST::Enum &type)
variant_fn, type.get_identifier ());
}

void
DefaultResolver::visit (AST::BorrowExpr &expr)
{
expr.get_borrowed_expr ()->accept_vis (*this);
}

void
DefaultResolver::visit (AST::DereferenceExpr &expr)
{
expr.get_dereferenced_expr ()->accept_vis (*this);
}

void
DefaultResolver::visit (AST::ErrorPropagationExpr &expr)
{
expr.get_propagating_expr ()->accept_vis (*this);
}

void
DefaultResolver::visit (AST::NegationExpr &expr)
{
expr.get_negated_expr ()->accept_vis (*this);
}

void
DefaultResolver::visit (AST::ArithmeticOrLogicalExpr &expr)
{
expr.get_left_expr ()->accept_vis (*this);
expr.get_right_expr ()->accept_vis (*this);
}

void
DefaultResolver::visit (AST::ComparisonExpr &expr)
{
expr.get_left_expr ()->accept_vis (*this);
expr.get_right_expr ()->accept_vis (*this);
}

void
DefaultResolver::visit (AST::LazyBooleanExpr &expr)
{
expr.get_left_expr ()->accept_vis (*this);
expr.get_right_expr ()->accept_vis (*this);
}

void
DefaultResolver::visit (AST::TypeCastExpr &expr)
{
expr.get_type_to_cast_to ()->accept_vis (*this);
expr.get_casted_expr ()->accept_vis (*this);
}

void
DefaultResolver::visit (AST::AssignmentExpr &expr)
{
expr.get_left_expr ()->accept_vis (*this);
expr.get_right_expr ()->accept_vis (*this);
}

void
DefaultResolver::visit (AST::CompoundAssignmentExpr &expr)
{
expr.get_left_expr ()->accept_vis (*this);
expr.get_right_expr ()->accept_vis (*this);
}

void
DefaultResolver::visit (AST::GroupedExpr &expr)
{
expr.get_expr_in_parens ()->accept_vis (*this);
}

void
DefaultResolver::visit (AST::ArrayElemsValues &array)
{
for (auto &value : array.get_values ())
value->accept_vis (*this);
}

void
DefaultResolver::visit (AST::ArrayElemsCopied &array)
{
array.get_elem_to_copy ()->accept_vis (*this);
array.get_num_copies ()->accept_vis (*this);
}

void
DefaultResolver::visit (AST::ArrayExpr &expr)
{
expr.get_array_elems ()->accept_vis (*this);
}

void
DefaultResolver::visit (AST::ArrayIndexExpr &expr)
{
expr.get_array_expr ()->accept_vis (*this);
expr.get_index_expr ()->accept_vis (*this);
}

void
DefaultResolver::visit (AST::TupleExpr &expr)
{
for (auto &element : expr.get_tuple_elems ())
element->accept_vis (*this);
}

void
DefaultResolver::visit (AST::TupleIndexExpr &expr)
{
expr.get_tuple_expr ()->accept_vis (*this);
}

void
DefaultResolver::visit (AST::StructExprFieldIdentifierValue &)
{}
Expand All @@ -302,28 +176,6 @@ void
DefaultResolver::visit (AST::StructExprFieldIndexValue &)
{}

void
DefaultResolver::visit (AST::CallExpr &expr)
{
expr.get_function_expr ()->accept_vis (*this);
for (auto &param : expr.get_params ())
param->accept_vis (*this);
}

void
DefaultResolver::visit (AST::MethodCallExpr &expr)
{
expr.get_receiver_expr ()->accept_vis (*this);
for (auto &param : expr.get_params ())
param->accept_vis (*this);
}

void
DefaultResolver::visit (AST::FieldAccessExpr &expr)
{
expr.get_receiver_expr ()->accept_vis (*this);
}

void
DefaultResolver::visit (AST::ClosureExprInner &)
{}
Expand All @@ -336,13 +188,6 @@ void
DefaultResolver::visit (AST::ContinueExpr &expr)
{}

void
DefaultResolver::visit (AST::BreakExpr &expr)
{
if (expr.has_break_expr ())
expr.get_break_expr ()->accept_vis (*this);
}

void
DefaultResolver::visit (AST::RangeFromToExpr &expr)
{}
Expand All @@ -355,10 +200,6 @@ void
DefaultResolver::visit (AST::RangeToExpr &expr)
{}

void
DefaultResolver::visit (AST::RangeFullExpr &expr)
{}

void
DefaultResolver::visit (AST::RangeFromToInclExpr &expr)
{}
Expand Down Expand Up @@ -415,28 +256,6 @@ void
DefaultResolver::visit (AST::AsyncBlockExpr &expr)
{}

void
DefaultResolver::visit (AST::LetStmt &let_stmt)
{
let_stmt.get_pattern ()->accept_vis (*this);

if (let_stmt.has_type ())
let_stmt.get_type ()->accept_vis (*this);

if (let_stmt.has_init_expr ())
let_stmt.get_init_expr ()->accept_vis (*this);
}

void
DefaultResolver::visit (AST::ExprStmt &stmt)
{
stmt.get_expr ()->accept_vis (*this);
}

void
DefaultResolver::visit (AST::Token &)
{}

void
DefaultResolver::visit (AST::DelimTokenTree &)
{}
Expand All @@ -449,10 +268,6 @@ void
DefaultResolver::visit (AST::IdentifierExpr &expr)
{}

void
DefaultResolver::visit (AST::Lifetime &)
{}

void
DefaultResolver::visit (AST::LifetimeParam &)
{}
Expand All @@ -465,10 +280,6 @@ void
DefaultResolver::visit (AST::PathInExpression &)
{}

void
DefaultResolver::visit (AST::TypePathSegment &)
{}

void
DefaultResolver::visit (AST::TypePathSegmentGeneric &)
{}
Expand Down Expand Up @@ -513,10 +324,6 @@ void
DefaultResolver::visit (AST::StructExprStruct &)
{}

void
DefaultResolver::visit (AST::StructExprFieldIdentifier &)
{}

void
DefaultResolver::visit (AST::StructExprStructFields &)
{}
Expand Down Expand Up @@ -623,10 +430,6 @@ void
DefaultResolver::visit (AST::ExternalFunctionItem &)
{}

void
DefaultResolver::visit (AST::MacroMatchFragment &)
{}

void
DefaultResolver::visit (AST::MacroMatchRepetition &)
{}
Expand All @@ -651,14 +454,6 @@ void
DefaultResolver::visit (AST::MetaItemSeq &)
{}

void
DefaultResolver::visit (AST::MetaWord &)
{}

void
DefaultResolver::visit (AST::MetaNameValueStr &)
{}

void
DefaultResolver::visit (AST::MetaListPaths &)
{}
Expand All @@ -667,29 +462,6 @@ void
DefaultResolver::visit (AST::MetaListNameValueStr &)
{}

void
DefaultResolver::visit (AST::LiteralPattern &)
{}

void
DefaultResolver::visit (AST::IdentifierPattern &pattern)
{
if (pattern.has_pattern_to_bind ())
pattern.get_pattern_to_bind ()->accept_vis (*this);
}

void
DefaultResolver::visit (AST::WildcardPattern &)
{}

void
DefaultResolver::visit (AST::RestPattern &)
{}

void
DefaultResolver::visit (AST::RangePatternBoundLiteral &)
{}

void
DefaultResolver::visit (AST::RangePatternBoundPath &)
{}
Expand Down Expand Up @@ -790,10 +562,6 @@ void
DefaultResolver::visit (AST::TupleType &)
{}

void
DefaultResolver::visit (AST::NeverType &)
{}

void
DefaultResolver::visit (AST::RawPointerType &)
{}
Expand All @@ -810,10 +578,6 @@ void
DefaultResolver::visit (AST::SliceType &)
{}

void
DefaultResolver::visit (AST::InferredType &)
{}

void
DefaultResolver::visit (AST::BareFunctionType &)
{}
Expand Down
Loading

0 comments on commit 1748242

Please sign in to comment.