Lines Matching refs:cx

33 pub(crate) fn typecheck(cx: &mut Errors, apis: &[Api], types: &Types, generator: Generator) {
37 errors: cx,
42 fn do_typecheck(cx: &mut Check) {
43 ident::check_all(cx, cx.apis);
45 for ty in cx.types {
47 Type::Ident(ident) => check_type_ident(cx, ident),
48 Type::RustBox(ptr) => check_type_box(cx, ptr),
49 Type::RustVec(ty) => check_type_rust_vec(cx, ty),
50 Type::UniquePtr(ptr) => check_type_unique_ptr(cx, ptr),
51 Type::SharedPtr(ptr) => check_type_shared_ptr(cx, ptr),
52 Type::WeakPtr(ptr) => check_type_weak_ptr(cx, ptr),
53 Type::CxxVector(ptr) => check_type_cxx_vector(cx, ptr),
54 Type::Ref(ty) => check_type_ref(cx, ty),
55 Type::Ptr(ty) => check_type_ptr(cx, ty),
56 Type::Array(array) => check_type_array(cx, array),
57 Type::Fn(ty) => check_type_fn(cx, ty),
58 Type::SliceRef(ty) => check_type_slice_ref(cx, ty),
63 for api in cx.apis {
66 Api::Struct(strct) => check_api_struct(cx, strct),
67 Api::Enum(enm) => check_api_enum(cx, enm),
68 Api::CxxType(ety) | Api::RustType(ety) => check_api_type(cx, ety),
69 Api::CxxFunction(efn) | Api::RustFunction(efn) => check_api_fn(cx, efn),
70 Api::TypeAlias(alias) => check_api_type_alias(cx, alias),
71 Api::Impl(imp) => check_api_impl(cx, imp),
82 fn check_type_ident(cx: &mut Check, name: &NamedType) {
85 && !cx.types.structs.contains_key(ident)
86 && !cx.types.enums.contains_key(ident)
87 && !cx.types.cxx.contains(ident)
88 && !cx.types.rust.contains(ident)
91 cx.error(ident, msg);
95 fn check_type_box(cx: &mut Check, ptr: &Ty1) {
97 if cx.types.cxx.contains(&ident.rust)
98 && !cx.types.aliases.contains_key(&ident.rust)
99 && !cx.types.structs.contains_key(&ident.rust)
100 && !cx.types.enums.contains_key(&ident.rust)
102 cx.error(ptr, error::BOX_CXX_TYPE.msg);
110 cx.error(ptr, "unsupported target type of Box");
113 fn check_type_rust_vec(cx: &mut Check, ty: &Ty1) {
116 if cx.types.cxx.contains(&ident.rust)
117 && !cx.types.aliases.contains_key(&ident.rust)
118 && !cx.types.structs.contains_key(&ident.rust)
119 && !cx.types.enums.contains_key(&ident.rust)
121 cx.error(ty, "Rust Vec containing C++ type is not supported yet");
136 cx.error(ty, "unsupported element type of Vec");
139 fn check_type_unique_ptr(cx: &mut Check, ptr: &Ty1) {
141 if cx.types.rust.contains(&ident.rust) {
142 cx.error(ptr, "unique_ptr of a Rust type is not supported yet");
154 cx.error(ptr, "unsupported unique_ptr target type");
157 fn check_type_shared_ptr(cx: &mut Check, ptr: &Ty1) {
159 if cx.types.rust.contains(&ident.rust) {
160 cx.error(ptr, "shared_ptr of a Rust type is not supported yet");
171 cx.error(ptr, "std::shared_ptr<std::vector> is not supported yet");
175 cx.error(ptr, "unsupported shared_ptr target type");
178 fn check_type_weak_ptr(cx: &mut Check, ptr: &Ty1) {
180 if cx.types.rust.contains(&ident.rust) {
181 cx.error(ptr, "weak_ptr of a Rust type is not supported yet");
192 cx.error(ptr, "std::weak_ptr<std::vector> is not supported yet");
196 cx.error(ptr, "unsupported weak_ptr target type");
199 fn check_type_cxx_vector(cx: &mut Check, ptr: &Ty1) {
201 if cx.types.rust.contains(&ident.rust) {
202 cx.error(
218 cx.error(ptr, "unsupported vector element type");
221 fn check_type_ref(cx: &mut Check, ty: &Ref) {
224 Type::Ident(ident) if ident.rust == CxxString || is_opaque_cxx(cx, &ident.rust) => {
230 cx.error(
243 cx.error(ty, "C++ does not allow references to references");
249 cx.error(ty, "unsupported reference type");
252 fn check_type_ptr(cx: &mut Check, ty: &Ptr) {
256 cx.error(ty, "C++ does not allow pointer to reference as a type");
262 cx.error(ty, "unsupported pointer type");
265 fn check_type_slice_ref(cx: &mut Check, ty: &SliceRef) {
266 let supported = !is_unsized(cx, &ty.inner)
269 cx.types.rust.contains(&ident.rust) || cx.types.aliases.contains_key(&ident.rust)
278 if is_opaque_cxx(cx, &ident.rust) {
282 cx.error(ty, msg);
286 fn check_type_array(cx: &mut Check, ty: &Array) {
287 let supported = !is_unsized(cx, &ty.inner);
290 cx.error(ty, "unsupported array element type");
294 fn check_type_fn(cx: &mut Check, ty: &Signature) {
296 cx.error(ty, "function pointer returning Result is not supported yet");
302 cx.error(
311 fn check_api_struct(cx: &mut Check, strct: &Struct) {
313 check_reserved_name(cx, &name.rust);
314 check_lifetimes(cx, &strct.generics);
318 cx.error(span, "structs without any fields are not supported");
321 if cx.types.cxx.contains(&name.rust) {
322 if let Some(ety) = cx.types.untrusted.get(&name.rust) {
324 cx.error(ety, msg);
331 cx.error(derive, msg);
337 cx.error(
341 } else if is_unsized(cx, &field.ty) {
342 let desc = describe(cx, &field.ty);
344 cx.error(field, msg);
349 fn check_api_enum(cx: &mut Check, enm: &Enum) {
350 check_reserved_name(cx, &enm.name.rust);
351 check_lifetimes(cx, &enm.generics);
355 cx.error(
364 cx.error(derive, msg);
369 fn check_api_type(cx: &mut Check, ety: &ExternType) {
370 check_reserved_name(cx, &ety.name.rust);
371 check_lifetimes(cx, &ety.generics);
385 cx.error(derive, msg);
391 cx.error(span, "extern type bounds are not implemented yet");
394 if let Some(reasons) = cx.types.required_trivial.get(&ety.name.rust) {
399 cx.error(ety, msg);
403 fn check_api_fn(cx: &mut Check, efn: &ExternFn) {
408 cx.error(span, "extern C++ function with lifetimes must be declared in `unsafe extern \"C++\"` block");
418 cx.error(span, message);
423 check_generics(cx, &efn.sig.generics);
437 cx.error(span, msg);
438 } else if cx.types.enums.contains_key(&receiver.ty.rust) {
439 cx.error(
443 } else if !cx.types.structs.contains_key(&receiver.ty.rust)
444 && !cx.types.cxx.contains(&receiver.ty.rust)
445 && !cx.types.rust.contains(&receiver.ty.rust)
447 cx.error(span, "unrecognized receiver type");
448 } else if receiver.mutable && !receiver.pinned && is_opaque_cxx(cx, &receiver.ty.rust) {
449 cx.error(
462 cx.error(
469 cx.error(
474 } else if is_unsized(cx, &arg.ty) {
475 let desc = describe(cx, &arg.ty);
477 cx.error(arg, msg);
483 cx.error(ty, "returning a function pointer is not implemented yet");
484 } else if is_unsized(cx, ty) {
485 let desc = describe(cx, ty);
487 cx.error(ty, msg);
492 check_mut_return_restriction(cx, efn);
496 fn check_api_type_alias(cx: &mut Check, alias: &TypeAlias) {
497 check_lifetimes(cx, &alias.generics);
501 cx.error(derive, msg);
505 fn check_api_impl(cx: &mut Check, imp: &Impl) {
508 check_lifetimes(cx, &imp.impl_generics);
512 cx.error(span, "negative impl is not supported yet");
532 cx.error(imp, "unsupported Self type of explicit impl");
535 fn check_mut_return_restriction(cx: &mut Check, efn: &ExternFn) {
551 let resolve = match cx.types.try_resolve(&receiver.ty) {
561 cx: &'a Check<'a>,
571 match self.cx.types.try_resolve(ident) {
582 let mut visitor = FindLifetimeMut { cx, found: false };
592 cx.error(
598 fn check_reserved_name(cx: &mut Check, ident: &Ident) {
608 cx.error(ident, "reserved name");
612 fn check_reserved_lifetime(cx: &mut Check, lifetime: &Lifetime) {
614 match cx.generator {
617 cx.error(lifetime, error::RESERVED_LIFETIME);
623 fn check_lifetimes(cx: &mut Check, generics: &Lifetimes) {
625 check_reserved_lifetime(cx, lifetime);
629 fn check_generics(cx: &mut Check, generics: &Generics) {
632 check_reserved_lifetime(cx, &def.lifetime);
637 fn is_unsized(cx: &mut Check, ty: &Type) -> bool {
641 ident == CxxString || is_opaque_cxx(cx, ident) || cx.types.rust.contains(ident)
643 Type::Array(array) => is_unsized(cx, &array.inner),
657 fn is_opaque_cxx(cx: &mut Check, ty: &Ident) -> bool {
658 cx.types.cxx.contains(ty)
659 && !cx.types.structs.contains_key(ty)
660 && !cx.types.enums.contains_key(ty)
661 && !(cx.types.aliases.contains_key(ty) && cx.types.required_trivial.contains_key(ty))
698 fn describe(cx: &mut Check, ty: &Type) -> String {
701 if cx.types.structs.contains_key(&ident.rust) {
703 } else if cx.types.enums.contains_key(&ident.rust) {
705 } else if cx.types.aliases.contains_key(&ident.rust) {
707 } else if cx.types.cxx.contains(&ident.rust) {
709 } else if cx.types.rust.contains(&ident.rust) {