cxx_build/syntax/
visit.rs

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
use crate::syntax::Type;

pub(crate) trait Visit<'a> {
    fn visit_type(&mut self, ty: &'a Type) {
        visit_type(self, ty);
    }
}

pub(crate) fn visit_type<'a, V>(visitor: &mut V, ty: &'a Type)
where
    V: Visit<'a> + ?Sized,
{
    match ty {
        Type::Ident(_) | Type::Str(_) | Type::Void(_) => {}
        Type::RustBox(ty)
        | Type::UniquePtr(ty)
        | Type::SharedPtr(ty)
        | Type::WeakPtr(ty)
        | Type::CxxVector(ty)
        | Type::RustVec(ty) => visitor.visit_type(&ty.inner),
        Type::Ref(r) => visitor.visit_type(&r.inner),
        Type::Ptr(p) => visitor.visit_type(&p.inner),
        Type::Array(a) => visitor.visit_type(&a.inner),
        Type::SliceRef(s) => visitor.visit_type(&s.inner),
        Type::Fn(fun) => {
            if let Some(ret) = &fun.ret {
                visitor.visit_type(ret);
            }
            for arg in &fun.args {
                visitor.visit_type(&arg.ty);
            }
        }
    }
}