cxx_gen/syntax/improper.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 35 36 37 38 39
use self::ImproperCtype::*;
use crate::syntax::atom::Atom::{self, *};
use crate::syntax::{Type, Types};
use proc_macro2::Ident;
pub(crate) enum ImproperCtype<'a> {
Definite(bool),
Depends(&'a Ident),
}
impl<'a> Types<'a> {
// yes, no, maybe
pub(crate) fn determine_improper_ctype(&self, ty: &Type) -> ImproperCtype<'a> {
match ty {
Type::Ident(ident) => {
let ident = &ident.rust;
if let Some(atom) = Atom::from(ident) {
Definite(atom == RustString)
} else if let Some(strct) = self.structs.get(ident) {
Depends(&strct.name.rust) // iterate to fixed-point
} else {
Definite(self.rust.contains(ident) || self.aliases.contains_key(ident))
}
}
Type::RustBox(_)
| Type::RustVec(_)
| Type::Str(_)
| Type::Fn(_)
| Type::Void(_)
| Type::SliceRef(_) => Definite(true),
Type::UniquePtr(_) | Type::SharedPtr(_) | Type::WeakPtr(_) | Type::CxxVector(_) => {
Definite(false)
}
Type::Ref(ty) => self.determine_improper_ctype(&ty.inner),
Type::Ptr(ty) => self.determine_improper_ctype(&ty.inner),
Type::Array(ty) => self.determine_improper_ctype(&ty.inner),
}
}
}