1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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) {}
}