Skip to content

Commit

Permalink
add visitor for Region
Browse files Browse the repository at this point in the history
  • Loading branch information
ouz-a committed Sep 28, 2023
1 parent bb17fe8 commit fed72e0
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions compiler/stable_mir/src/visitor.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use std::ops::ControlFlow;

use crate::Opaque;
use crate::{
ty::{BoundRegion, BoundRegionKind},
Opaque,
};

use super::ty::{
Allocation, Binder, Const, ConstDef, ExistentialPredicate, FnSig, GenericArgKind, GenericArgs,
Expand All @@ -15,6 +18,9 @@ pub trait Visitor: Sized {
fn visit_const(&mut self, c: &Const) -> ControlFlow<Self::Break> {
c.super_visit(self)
}
fn visit_reg(&mut self, reg: &Region) -> ControlFlow<Self::Break> {
reg.super_visit(self)
}
}

pub trait Visitable {
Expand Down Expand Up @@ -102,11 +108,38 @@ impl Visitable for GenericArgs {
}

impl Visitable for Region {
fn super_visit<V: Visitor>(&self, _visitor: &mut V) -> ControlFlow<V::Break> {
fn visit<V: Visitor>(&self, visitor: &mut V) -> ControlFlow<V::Break> {
visitor.visit_reg(self)
}

fn super_visit<V: Visitor>(&self, visitor: &mut V) -> ControlFlow<V::Break> {
match self.kind.clone() {
crate::ty::RegionKind::ReEarlyBound(_) => {}
crate::ty::RegionKind::ReLateBound(_, bound_reg) => bound_reg.visit(visitor)?,
crate::ty::RegionKind::ReStatic => {}
crate::ty::RegionKind::RePlaceholder(bound_reg) => bound_reg.bound.visit(visitor)?,
crate::ty::RegionKind::ReErased => {}
}
ControlFlow::Continue(())
}
}

impl Visitable for BoundRegion {
fn super_visit<V: Visitor>(&self, visitor: &mut V) -> ControlFlow<V::Break> {
self.kind.visit(visitor)
}
}

impl Visitable for BoundRegionKind {
fn super_visit<V: Visitor>(&self, _visitor: &mut V) -> ControlFlow<V::Break> {
match self {
BoundRegionKind::BrAnon => ControlFlow::Continue(()),
BoundRegionKind::BrNamed(_, _) => ControlFlow::Continue(()),
BoundRegionKind::BrEnv => ControlFlow::Continue(()),
}
}
}

impl Visitable for GenericArgKind {
fn super_visit<V: Visitor>(&self, visitor: &mut V) -> ControlFlow<V::Break> {
match self {
Expand Down

0 comments on commit fed72e0

Please sign in to comment.