1use crate::syntax::Type; 2 3pub trait Visit<'a> { 4 fn visit_type(&mut self, ty: &'a Type) { 5 visit_type(self, ty); 6 } 7} 8 9pub fn visit_type<'a, V>(visitor: &mut V, ty: &'a Type) 10where 11 V: Visit<'a> + ?Sized, 12{ 13 match ty { 14 Type::Ident(_) | Type::Str(_) | Type::Void(_) => {} 15 Type::RustBox(ty) 16 | Type::UniquePtr(ty) 17 | Type::SharedPtr(ty) 18 | Type::WeakPtr(ty) 19 | Type::CxxVector(ty) 20 | Type::RustVec(ty) => visitor.visit_type(&ty.inner), 21 Type::Ref(r) => visitor.visit_type(&r.inner), 22 Type::Ptr(p) => visitor.visit_type(&p.inner), 23 Type::Array(a) => visitor.visit_type(&a.inner), 24 Type::SliceRef(s) => visitor.visit_type(&s.inner), 25 Type::Fn(fun) => { 26 if let Some(ret) = &fun.ret { 27 visitor.visit_type(ret); 28 } 29 for arg in &fun.args { 30 visitor.visit_type(&arg.ty); 31 } 32 } 33 } 34} 35