Lines Matching full:cx

33 pub(crate) fn typecheck(cx: &mut Errors, apis: &[Api], types: &Types, generator: Generator) {  in typecheck()
37 errors: cx, in typecheck()
42 fn do_typecheck(cx: &mut Check) { in do_typecheck()
43 ident::check_all(cx, cx.apis); in do_typecheck()
45 for ty in cx.types { in do_typecheck()
47 Type::Ident(ident) => check_type_ident(cx, ident), in do_typecheck()
48 Type::RustBox(ptr) => check_type_box(cx, ptr), in do_typecheck()
49 Type::RustVec(ty) => check_type_rust_vec(cx, ty), in do_typecheck()
50 Type::UniquePtr(ptr) => check_type_unique_ptr(cx, ptr), in do_typecheck()
51 Type::SharedPtr(ptr) => check_type_shared_ptr(cx, ptr), in do_typecheck()
52 Type::WeakPtr(ptr) => check_type_weak_ptr(cx, ptr), in do_typecheck()
53 Type::CxxVector(ptr) => check_type_cxx_vector(cx, ptr), in do_typecheck()
54 Type::Ref(ty) => check_type_ref(cx, ty), in do_typecheck()
55 Type::Ptr(ty) => check_type_ptr(cx, ty), in do_typecheck()
56 Type::Array(array) => check_type_array(cx, array), in do_typecheck()
57 Type::Fn(ty) => check_type_fn(cx, ty), in do_typecheck()
58 Type::SliceRef(ty) => check_type_slice_ref(cx, ty), in do_typecheck()
63 for api in cx.apis { in do_typecheck()
66 Api::Struct(strct) => check_api_struct(cx, strct), in do_typecheck()
67 Api::Enum(enm) => check_api_enum(cx, enm), in do_typecheck()
68 Api::CxxType(ety) | Api::RustType(ety) => check_api_type(cx, ety), in do_typecheck()
69 Api::CxxFunction(efn) | Api::RustFunction(efn) => check_api_fn(cx, efn), in do_typecheck()
70 Api::TypeAlias(alias) => check_api_type_alias(cx, alias), in do_typecheck()
71 Api::Impl(imp) => check_api_impl(cx, imp), in do_typecheck()
82 fn check_type_ident(cx: &mut Check, name: &NamedType) { in check_type_ident()
85 && !cx.types.structs.contains_key(ident) in check_type_ident()
86 && !cx.types.enums.contains_key(ident) in check_type_ident()
87 && !cx.types.cxx.contains(ident) in check_type_ident()
88 && !cx.types.rust.contains(ident) in check_type_ident()
91 cx.error(ident, msg); in check_type_ident()
95 fn check_type_box(cx: &mut Check, ptr: &Ty1) { in check_type_box()
97 if cx.types.cxx.contains(&ident.rust) in check_type_box()
98 && !cx.types.aliases.contains_key(&ident.rust) in check_type_box()
99 && !cx.types.structs.contains_key(&ident.rust) in check_type_box()
100 && !cx.types.enums.contains_key(&ident.rust) in check_type_box()
102 cx.error(ptr, error::BOX_CXX_TYPE.msg); in check_type_box()
110 cx.error(ptr, "unsupported target type of Box"); in check_type_box()
113 fn check_type_rust_vec(cx: &mut Check, ty: &Ty1) { in check_type_rust_vec()
116 if cx.types.cxx.contains(&ident.rust) in check_type_rust_vec()
117 && !cx.types.aliases.contains_key(&ident.rust) in check_type_rust_vec()
118 && !cx.types.structs.contains_key(&ident.rust) in check_type_rust_vec()
119 && !cx.types.enums.contains_key(&ident.rust) in check_type_rust_vec()
121 cx.error(ty, "Rust Vec containing C++ type is not supported yet"); in check_type_rust_vec()
138 cx.error(ty, "unsupported element type of Vec"); in check_type_rust_vec()
141 fn check_type_unique_ptr(cx: &mut Check, ptr: &Ty1) { in check_type_unique_ptr()
143 if cx.types.rust.contains(&ident.rust) { in check_type_unique_ptr()
144 cx.error(ptr, "unique_ptr of a Rust type is not supported yet"); in check_type_unique_ptr()
156 cx.error(ptr, "unsupported unique_ptr target type"); in check_type_unique_ptr()
159 fn check_type_shared_ptr(cx: &mut Check, ptr: &Ty1) { in check_type_shared_ptr()
161 if cx.types.rust.contains(&ident.rust) { in check_type_shared_ptr()
162 cx.error(ptr, "shared_ptr of a Rust type is not supported yet"); in check_type_shared_ptr()
175 cx.error(ptr, "std::shared_ptr<std::vector> is not supported yet"); in check_type_shared_ptr()
179 cx.error(ptr, "unsupported shared_ptr target type"); in check_type_shared_ptr()
182 fn check_type_weak_ptr(cx: &mut Check, ptr: &Ty1) { in check_type_weak_ptr()
184 if cx.types.rust.contains(&ident.rust) { in check_type_weak_ptr()
185 cx.error(ptr, "weak_ptr of a Rust type is not supported yet"); in check_type_weak_ptr()
198 cx.error(ptr, "std::weak_ptr<std::vector> is not supported yet"); in check_type_weak_ptr()
202 cx.error(ptr, "unsupported weak_ptr target type"); in check_type_weak_ptr()
205 fn check_type_cxx_vector(cx: &mut Check, ptr: &Ty1) { in check_type_cxx_vector()
207 if cx.types.rust.contains(&ident.rust) { in check_type_cxx_vector()
208 cx.error( in check_type_cxx_vector()
225 cx.error(ptr, "unsupported vector element type"); in check_type_cxx_vector()
228 fn check_type_ref(cx: &mut Check, ty: &Ref) { in check_type_ref()
231 Type::Ident(ident) if ident.rust == CxxString || is_opaque_cxx(cx, &ident.rust) => { in check_type_ref()
237 cx.error( in check_type_ref()
250 cx.error(ty, "C++ does not allow references to references"); in check_type_ref()
256 cx.error(ty, "unsupported reference type"); in check_type_ref()
259 fn check_type_ptr(cx: &mut Check, ty: &Ptr) { in check_type_ptr()
263 cx.error(ty, "C++ does not allow pointer to reference as a type"); in check_type_ptr()
269 cx.error(ty, "unsupported pointer type"); in check_type_ptr()
272 fn check_type_slice_ref(cx: &mut Check, ty: &SliceRef) { in check_type_slice_ref()
273 let supported = !is_unsized(cx, &ty.inner) in check_type_slice_ref()
276 cx.types.rust.contains(&ident.rust) || cx.types.aliases.contains_key(&ident.rust) in check_type_slice_ref()
285 if is_opaque_cxx(cx, &ident.rust) { in check_type_slice_ref()
289 cx.error(ty, msg); in check_type_slice_ref()
293 fn check_type_array(cx: &mut Check, ty: &Array) { in check_type_array()
294 let supported = !is_unsized(cx, &ty.inner); in check_type_array()
297 cx.error(ty, "unsupported array element type"); in check_type_array()
301 fn check_type_fn(cx: &mut Check, ty: &Signature) { in check_type_fn()
303 cx.error(ty, "function pointer returning Result is not supported yet"); in check_type_fn()
309 cx.error( in check_type_fn()
318 fn check_api_struct(cx: &mut Check, strct: &Struct) { in check_api_struct()
320 check_reserved_name(cx, &name.rust); in check_api_struct()
321 check_lifetimes(cx, &strct.generics); in check_api_struct()
325 cx.error(span, "structs without any fields are not supported"); in check_api_struct()
328 if cx.types.cxx.contains(&name.rust) { in check_api_struct()
329 if let Some(ety) = cx.types.untrusted.get(&name.rust) { in check_api_struct()
331 cx.error(ety, msg); in check_api_struct()
338 cx.error(derive, msg); in check_api_struct()
344 cx.error( in check_api_struct()
348 } else if is_unsized(cx, &field.ty) { in check_api_struct()
349 let desc = describe(cx, &field.ty); in check_api_struct()
351 cx.error(field, msg); in check_api_struct()
356 fn check_api_enum(cx: &mut Check, enm: &Enum) { in check_api_enum()
357 check_reserved_name(cx, &enm.name.rust); in check_api_enum()
358 check_lifetimes(cx, &enm.generics); in check_api_enum()
362 cx.error( in check_api_enum()
371 cx.error(derive, msg); in check_api_enum()
376 fn check_api_type(cx: &mut Check, ety: &ExternType) { in check_api_type()
377 check_reserved_name(cx, &ety.name.rust); in check_api_type()
378 check_lifetimes(cx, &ety.generics); in check_api_type()
392 cx.error(derive, msg); in check_api_type()
398 cx.error(span, "extern type bounds are not implemented yet"); in check_api_type()
401 if let Some(reasons) = cx.types.required_trivial.get(&ety.name.rust) { in check_api_type()
406 cx.error(ety, msg); in check_api_type()
410 fn check_api_fn(cx: &mut Check, efn: &ExternFn) { in check_api_fn()
415cx.error(span, "extern C++ function with lifetimes must be declared in `unsafe extern \"C++\"` blo… in check_api_fn()
425 cx.error(span, message); in check_api_fn()
430 check_generics(cx, &efn.sig.generics); in check_api_fn()
444 cx.error(span, msg); in check_api_fn()
445 } else if cx.types.enums.contains_key(&receiver.ty.rust) { in check_api_fn()
446 cx.error( in check_api_fn()
450 } else if !cx.types.structs.contains_key(&receiver.ty.rust) in check_api_fn()
451 && !cx.types.cxx.contains(&receiver.ty.rust) in check_api_fn()
452 && !cx.types.rust.contains(&receiver.ty.rust) in check_api_fn()
454 cx.error(span, "unrecognized receiver type"); in check_api_fn()
455 } else if receiver.mutable && !receiver.pinned && is_opaque_cxx(cx, &receiver.ty.rust) { in check_api_fn()
456 cx.error( in check_api_fn()
469 cx.error( in check_api_fn()
476 cx.error( in check_api_fn()
481 } else if is_unsized(cx, &arg.ty) { in check_api_fn()
482 let desc = describe(cx, &arg.ty); in check_api_fn()
484 cx.error(arg, msg); in check_api_fn()
490 cx.error(ty, "returning a function pointer is not implemented yet"); in check_api_fn()
491 } else if is_unsized(cx, ty) { in check_api_fn()
492 let desc = describe(cx, ty); in check_api_fn()
494 cx.error(ty, msg); in check_api_fn()
499 check_mut_return_restriction(cx, efn); in check_api_fn()
503 fn check_api_type_alias(cx: &mut Check, alias: &TypeAlias) { in check_api_type_alias()
504 check_lifetimes(cx, &alias.generics); in check_api_type_alias()
508 cx.error(derive, msg); in check_api_type_alias()
512 fn check_api_impl(cx: &mut Check, imp: &Impl) { in check_api_impl()
515 check_lifetimes(cx, &imp.impl_generics); in check_api_impl()
519 cx.error(span, "negative impl is not supported yet"); in check_api_impl()
539 cx.error(imp, "unsupported Self type of explicit impl"); in check_api_impl()
542 fn check_mut_return_restriction(cx: &mut Check, efn: &ExternFn) { in check_mut_return_restriction()
558 let resolve = match cx.types.try_resolve(&receiver.ty) { in check_mut_return_restriction()
568 cx: &'a Check<'a>, in check_mut_return_restriction() field
578 match self.cx.types.try_resolve(ident) { in check_mut_return_restriction()
589 let mut visitor = FindLifetimeMut { cx, found: false }; in check_mut_return_restriction()
599 cx.error( in check_mut_return_restriction()
605 fn check_reserved_name(cx: &mut Check, ident: &Ident) { in check_reserved_name()
615 cx.error(ident, "reserved name"); in check_reserved_name()
619 fn check_reserved_lifetime(cx: &mut Check, lifetime: &Lifetime) { in check_reserved_lifetime()
621 match cx.generator { in check_reserved_lifetime()
624 cx.error(lifetime, error::RESERVED_LIFETIME); in check_reserved_lifetime()
630 fn check_lifetimes(cx: &mut Check, generics: &Lifetimes) { in check_lifetimes()
632 check_reserved_lifetime(cx, lifetime); in check_lifetimes()
636 fn check_generics(cx: &mut Check, generics: &Generics) { in check_generics()
639 check_reserved_lifetime(cx, &def.lifetime); in check_generics()
644 fn is_unsized(cx: &mut Check, ty: &Type) -> bool { in is_unsized()
648 ident == CxxString || is_opaque_cxx(cx, ident) || cx.types.rust.contains(ident) in is_unsized()
650 Type::Array(array) => is_unsized(cx, &array.inner), in is_unsized()
664 fn is_opaque_cxx(cx: &mut Check, ty: &Ident) -> bool { in is_opaque_cxx()
665 cx.types.cxx.contains(ty) in is_opaque_cxx()
666 && !cx.types.structs.contains_key(ty) in is_opaque_cxx()
667 && !cx.types.enums.contains_key(ty) in is_opaque_cxx()
668 && !(cx.types.aliases.contains_key(ty) && cx.types.required_trivial.contains_key(ty)) in is_opaque_cxx()
705 fn describe(cx: &mut Check, ty: &Type) -> String { in describe()
708 if cx.types.structs.contains_key(&ident.rust) { in describe()
710 } else if cx.types.enums.contains_key(&ident.rust) { in describe()
712 } else if cx.types.aliases.contains_key(&ident.rust) { in describe()
714 } else if cx.types.cxx.contains(&ident.rust) { in describe()
716 } else if cx.types.rust.contains(&ident.rust) { in describe()