ligen_core/generator/
visitor.rs1use crate::ir::{Implementation, Function, Parameter, Type};
4use crate::generator::{Context, FileSet};
5
6#[derive(Debug, Clone)]
8pub struct Visitor<Parent, Current> {
9 pub parent: Parent,
11 pub current: Current
13}
14
15impl<Parent, Current> Visitor<Parent, Current> {
16 pub fn new(parent: Parent, current: Current) -> Self {
18 Self { parent, current }
19 }
20
21 pub fn child<Child>(&self, current: Child) -> Visitor<Visitor<Parent, Current>, Child>
23 where Parent: Clone,
24 Current: Clone
25 {
26 let parent = self.clone();
27 Visitor { parent, current }
28 }
29}
30
31pub type ImplementationVisitor = Visitor<(), Implementation>;
33
34pub type FunctionVisitor = Visitor<ImplementationVisitor, Function>;
36
37pub type ParameterVisitor = Visitor<FunctionVisitor, Parameter>;
39
40impl FunctionVisitor {
41 pub fn is_method(&self) -> bool {
44 if let Some(input) = self.current.inputs.get(0) {
45 input.type_.path() == self.parent.current.self_.path() || input.type_ == Type::self_type()
46 } else {
47 false
48 }
49 }
50}
51
52pub trait FileProcessorVisitor: Default {
54 type Visitor;
56
57 fn process(&self, _context: &Context, _file_set: &mut FileSet, _visitor: &Self::Visitor) {}
59
60 fn post_process(&self, _context: &Context, _file_set: &mut FileSet, _visitor: &Self::Visitor) {}
64}