cranelift_isle::sema

Trait RuleVisitor

source
pub trait RuleVisitor {
    type PatternVisitor: PatternVisitor;
    type ExprVisitor: ExprVisitor;
    type Expr;

    // Required methods
    fn add_arg(
        &mut self,
        index: usize,
        ty: TypeId,
    ) -> <Self::PatternVisitor as PatternVisitor>::PatternId;
    fn add_pattern<F>(&mut self, visitor: F)
       where F: FnOnce(&mut Self::PatternVisitor);
    fn add_expr<F>(&mut self, visitor: F) -> Self::Expr
       where F: FnOnce(&mut Self::ExprVisitor) -> VisitedExpr<Self::ExprVisitor>;
    fn expr_as_pattern(
        &mut self,
        expr: Self::Expr,
    ) -> <Self::PatternVisitor as PatternVisitor>::PatternId;
    fn pattern_as_expr(
        &mut self,
        pattern: <Self::PatternVisitor as PatternVisitor>::PatternId,
    ) -> <Self::ExprVisitor as ExprVisitor>::ExprId;
}
Expand description

Visitor interface for Rules. Visitors must be able to visit patterns by implementing PatternVisitor, and to visit expressions by providing a type that implements ExprVisitor.

Required Associated Types§

source

type PatternVisitor: PatternVisitor

The type of pattern visitors constructed by RuleVisitor::add_pattern.

source

type ExprVisitor: ExprVisitor

The type of expression visitors constructed by RuleVisitor::add_expr.

source

type Expr

The type returned from RuleVisitor::add_expr, which may be exchanged for a subpattern identifier using RuleVisitor::expr_as_pattern.

Required Methods§

source

fn add_arg( &mut self, index: usize, ty: TypeId, ) -> <Self::PatternVisitor as PatternVisitor>::PatternId

Visit one of the arguments to the top-level pattern.

source

fn add_pattern<F>(&mut self, visitor: F)
where F: FnOnce(&mut Self::PatternVisitor),

Visit a pattern, used once for the rule’s left-hand side and once for each if-let. You can determine which part of the rule the pattern comes from based on whether the PatternId passed to the first call to this visitor came from add_arg or expr_as_pattern.

source

fn add_expr<F>(&mut self, visitor: F) -> Self::Expr
where F: FnOnce(&mut Self::ExprVisitor) -> VisitedExpr<Self::ExprVisitor>,

Visit an expression, used once for each if-let and once for the rule’s right-hand side.

source

fn expr_as_pattern( &mut self, expr: Self::Expr, ) -> <Self::PatternVisitor as PatternVisitor>::PatternId

Given an expression from RuleVisitor::add_expr, return an identifier that can be used with a pattern visitor in RuleVisitor::add_pattern.

source

fn pattern_as_expr( &mut self, pattern: <Self::PatternVisitor as PatternVisitor>::PatternId, ) -> <Self::ExprVisitor as ExprVisitor>::ExprId

Given an identifier from the pattern visitor, return an identifier that can be used with the expression visitor.

Object Safety§

This trait is not object safe.

Implementors§