cxx_gen/syntax/pod.rs
1use crate::syntax::atom::Atom::{self, *};
2use crate::syntax::{primitive, Type, Types};
3
4impl<'a> Types<'a> {
5 pub(crate) fn is_guaranteed_pod(&self, ty: &Type) -> bool {
6 match ty {
7 Type::Ident(ident) => {
8 let ident = &ident.rust;
9 if let Some(atom) = Atom::from(ident) {
10 match atom {
11 Bool | Char | U8 | U16 | U32 | U64 | Usize | I8 | I16 | I32 | I64
12 | Isize | F32 | F64 => true,
13 CxxString | RustString => false,
14 }
15 } else if let Some(strct) = self.structs.get(ident) {
16 strct.fields.iter().all(|field| {
17 primitive::kind(&field.ty).is_none() && self.is_guaranteed_pod(&field.ty)
18 })
19 } else {
20 self.enums.contains_key(ident)
21 }
22 }
23 Type::RustBox(_)
24 | Type::RustVec(_)
25 | Type::UniquePtr(_)
26 | Type::SharedPtr(_)
27 | Type::WeakPtr(_)
28 | Type::CxxVector(_)
29 | Type::Void(_) => false,
30 Type::Ref(_) | Type::Str(_) | Type::Fn(_) | Type::SliceRef(_) | Type::Ptr(_) => true,
31 Type::Array(array) => self.is_guaranteed_pod(&array.inner),
32 }
33 }
34}