From dffb1adabd3853a8d1100e53d5fa351f8b5f180c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Poulhi=C3=A8s?= Date: Sat, 15 Jan 2022 22:43:08 +0100 Subject: HIR Visitor refactoring MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This change split the single HIR visitor in smaller abstract ones: - Stmt - VisItem - Pattern - ExternalItem - Impl - Type - Expression Instead of providing a Base class with empty visit() methods, they are kept abstract to avoid the case where a missing visit() is silently ignored: implementors must explicitely override all visit. There is also a FullVisitor that covers all HIR nodes and also provides a Base class with empty behavior. fixes #825 Signed-off-by: Marc Poulhiès --- gcc/rust/backend/rust-compile-expr.h | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) (limited to 'gcc/rust/backend/rust-compile-expr.h') diff --git a/gcc/rust/backend/rust-compile-expr.h b/gcc/rust/backend/rust-compile-expr.h index f2b4df8..3cc51d4 100644 --- a/gcc/rust/backend/rust-compile-expr.h +++ b/gcc/rust/backend/rust-compile-expr.h @@ -29,10 +29,8 @@ namespace Rust { namespace Compile { -class CompileExpr : public HIRCompileBase +class CompileExpr : public HIRCompileBase, public HIR::HIRExpressionVisitor { - using Rust::Compile::HIRCompileBase::visit; - public: static tree Compile (HIR::Expr *expr, Context *ctx) { @@ -769,9 +767,7 @@ public: } void visit (HIR::BorrowExpr &expr) override; - void visit (HIR::DereferenceExpr &expr) override; - void visit (HIR::MatchExpr &expr) override; void visit (HIR::RangeFromToExpr &expr) override; @@ -784,6 +780,24 @@ public: void visit (HIR::RangeFromToInclExpr &expr) override; + // Empty visit for unused Expression HIR nodes. + void visit (HIR::ClosureExprInner &) override {} + void visit (HIR::ClosureExprInnerTyped &) override {} + void visit (HIR::StructExprFieldIdentifier &) override {} + void visit (HIR::StructExprFieldIdentifierValue &) override {} + void visit (HIR::StructExprFieldIndexValue &) override {} + void visit (HIR::ErrorPropagationExpr &) override {} + void visit (HIR::RangeToInclExpr &) override {} + void visit (HIR::WhileLetLoopExpr &) override {} + void visit (HIR::ForLoopExpr &) override {} + void visit (HIR::IfExprConseqIfLet &) override {} + void visit (HIR::IfLetExpr &) override {} + void visit (HIR::IfLetExprConseqElse &) override {} + void visit (HIR::IfLetExprConseqIf &) override {} + void visit (HIR::IfLetExprConseqIfLet &) override {} + void visit (HIR::AwaitExpr &) override {} + void visit (HIR::AsyncBlockExpr &) override {} + protected: tree compile_dyn_dispatch_call (const TyTy::DynamicObjectType *dyn, TyTy::BaseType *receiver, -- cgit v1.1