1
Fork 0

Move MirVisitable to visit.rs

This commit is contained in:
Santiago Pastorino 2017-12-12 11:59:09 -03:00 committed by Niko Matsakis
parent 93afb1affc
commit 58b0506d65
3 changed files with 27 additions and 24 deletions

View file

@ -46,6 +46,7 @@
#![feature(const_fn)]
#![feature(core_intrinsics)]
#![feature(drain_filter)]
#![feature(dyn_trait)]
#![feature(from_ref)]
#![feature(i128)]
#![feature(i128_type)]

View file

@ -811,6 +811,31 @@ macro_rules! make_mir_visitor {
make_mir_visitor!(Visitor,);
make_mir_visitor!(MutVisitor,mut);
pub trait MirVisitable<'tcx> {
fn apply(&self, location: Location, visitor: &mut dyn Visitor<'tcx>);
}
impl<'tcx> MirVisitable<'tcx> for Statement<'tcx> {
fn apply(&self, location: Location, visitor: &mut dyn Visitor<'tcx>)
{
visitor.visit_statement(location.block, self, location)
}
}
impl<'tcx> MirVisitable<'tcx> for Terminator<'tcx> {
fn apply(&self, location: Location, visitor: &mut dyn Visitor<'tcx>)
{
visitor.visit_terminator(location.block, self, location)
}
}
impl<'tcx> MirVisitable<'tcx> for Option<Terminator<'tcx>> {
fn apply(&self, location: Location, visitor: &mut dyn Visitor<'tcx>)
{
visitor.visit_terminator(location.block, self.as_ref().unwrap(), location)
}
}
/// Extra information passed to `visit_ty` and friends to give context
/// about where the type etc appears.
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]

View file

@ -39,6 +39,7 @@ use rustc_data_structures::indexed_vec::{Idx, IndexVec};
use rustc_data_structures::indexed_set::IdxSetBuf;
use util::pretty::{dump_enabled, write_basic_block, write_mir_intro};
use rustc::ty::item_path;
use rustc::mir::visit::MirVisitable;
use std::path::{Path, PathBuf};
use std::fs;
use rustc::ty::TyCtxt;
@ -358,30 +359,6 @@ fn block<'tcx>(mode: LivenessMode, b: &BasicBlockData<'tcx>, locals: usize) -> D
visitor.defs_uses
}
trait MirVisitable<'tcx> {
fn apply<V>(&self, location: Location, visitor: &mut V)
where
V: Visitor<'tcx>;
}
impl<'tcx> MirVisitable<'tcx> for Statement<'tcx> {
fn apply<V>(&self, location: Location, visitor: &mut V)
where
V: Visitor<'tcx>,
{
visitor.visit_statement(location.block, self, location)
}
}
impl<'tcx> MirVisitable<'tcx> for Option<Terminator<'tcx>> {
fn apply<V>(&self, location: Location, visitor: &mut V)
where
V: Visitor<'tcx>,
{
visitor.visit_terminator(location.block, self.as_ref().unwrap(), location)
}
}
pub fn dump_mir<'a, 'tcx>(
tcx: TyCtxt<'a, 'tcx, 'tcx>,
pass_name: &str,