use crate::ir::{Implementation, Function, Parameter, Type};
use crate::generator::{Context, FileSet};
#[derive(Debug, Clone)]
pub struct Visitor<Parent, Current> {
pub parent: Parent,
pub current: Current
}
impl<Parent, Current> Visitor<Parent, Current> {
pub fn new(parent: Parent, current: Current) -> Self {
Self { parent, current }
}
pub fn child<Child>(&self, current: Child) -> Visitor<Visitor<Parent, Current>, Child>
where Parent: Clone,
Current: Clone
{
let parent = self.clone();
Visitor { parent, current }
}
}
pub type ImplementationVisitor = Visitor<(), Implementation>;
pub type FunctionVisitor = Visitor<ImplementationVisitor, Function>;
pub type ParameterVisitor = Visitor<FunctionVisitor, Parameter>;
impl FunctionVisitor {
pub fn is_method(&self) -> bool {
if let Some(input) = self.current.inputs.get(0) {
input.type_.path() == self.parent.current.self_.path() || input.type_ == Type::self_type()
} else {
false
}
}
}
pub trait FileProcessorVisitor: Default {
type Visitor;
fn process(&self, _context: &Context, _file_set: &mut FileSet, _visitor: &Self::Visitor) {}
fn post_process(&self, _context: &Context, _file_set: &mut FileSet, _visitor: &Self::Visitor) {}
}