1 use self::ImproperCtype::*; 2 use crate::syntax::atom::Atom::{self, *}; 3 use crate::syntax::{Type, Types}; 4 use proc_macro2::Ident; 5 6 pub enum ImproperCtype<'a> { 7 Definite(bool), 8 Depends(&'a Ident), 9 } 10 11 impl<'a> Types<'a> { 12 // yes, no, maybe determine_improper_ctype(&self, ty: &Type) -> ImproperCtype<'a>13 pub fn determine_improper_ctype(&self, ty: &Type) -> ImproperCtype<'a> { 14 match ty { 15 Type::Ident(ident) => { 16 let ident = &ident.rust; 17 if let Some(atom) = Atom::from(ident) { 18 Definite(atom == RustString) 19 } else if let Some(strct) = self.structs.get(ident) { 20 Depends(&strct.name.rust) // iterate to fixed-point 21 } else { 22 Definite(self.rust.contains(ident) || self.aliases.contains_key(ident)) 23 } 24 } 25 Type::RustBox(_) 26 | Type::RustVec(_) 27 | Type::Str(_) 28 | Type::Fn(_) 29 | Type::Void(_) 30 | Type::SliceRef(_) => Definite(true), 31 Type::UniquePtr(_) | Type::SharedPtr(_) | Type::WeakPtr(_) | Type::CxxVector(_) => { 32 Definite(false) 33 } 34 Type::Ref(ty) => self.determine_improper_ctype(&ty.inner), 35 Type::Ptr(ty) => self.determine_improper_ctype(&ty.inner), 36 Type::Array(ty) => self.determine_improper_ctype(&ty.inner), 37 } 38 } 39 } 40