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