summaryrefslogtreecommitdiff
path: root/src/codegen/mod.rs
diff options
context:
space:
mode:
authorSebastian Imlay <sebastian.imlay@gmail.com>2020-07-27 13:00:51 -0700
committerEmilio Cobos Álvarez <emilio@crisal.io>2020-08-15 13:56:25 +0200
commit4299255c8a327ad3619ed9921823e85cbf880a95 (patch)
tree8e075ae6c003e62f86a3624d0c6bc6e6a3a65cc2 /src/codegen/mod.rs
parent802561e1779b188594527d400d44b37a79faadbe (diff)
Added Bindgen names to objective-c pointer return types
* Took advantage of the repr transparent to use Bindgen return type names. * Updated unit tests and book
Diffstat (limited to 'src/codegen/mod.rs')
-rw-r--r--src/codegen/mod.rs25
1 files changed, 19 insertions, 6 deletions
diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs
index de46bb22..ccfa622c 100644
--- a/src/codegen/mod.rs
+++ b/src/codegen/mod.rs
@@ -3512,6 +3512,14 @@ impl TryToRustTy for Type {
inner.into_resolver().through_type_refs().resolve(ctx);
let inner_ty = inner.expect_type();
+ let is_objc_pointer =
+ inner.kind().as_type().map_or(false, |ty| {
+ match ty.kind() {
+ TypeKind::ObjCInterface(..) => true,
+ _ => false,
+ }
+ });
+
// Regardless if we can properly represent the inner type, we
// should always generate a proper pointer here, so use
// infallible conversion of the inner type.
@@ -3520,7 +3528,8 @@ impl TryToRustTy for Type {
// Avoid the first function pointer level, since it's already
// represented in Rust.
- if inner_ty.canonical_type(ctx).is_function() {
+ if inner_ty.canonical_type(ctx).is_function() || is_objc_pointer
+ {
Ok(ty)
} else {
Ok(ty.to_ptr(is_const))
@@ -3539,9 +3548,12 @@ impl TryToRustTy for Type {
TypeKind::ObjCId => Ok(quote! {
id
}),
- TypeKind::ObjCInterface(..) => Ok(quote! {
- objc::runtime::Object
- }),
+ TypeKind::ObjCInterface(ref interface) => {
+ let name = ctx.rust_ident(interface.name());
+ Ok(quote! {
+ #name
+ })
+ }
ref u @ TypeKind::UnresolvedTypeRef(..) => {
unreachable!("Should have been resolved after parsing {:?}!", u)
}
@@ -4395,11 +4407,12 @@ mod utils {
TypeKind::Pointer(inner) => {
let inner = ctx.resolve_item(inner);
let inner_ty = inner.expect_type();
- if let TypeKind::ObjCInterface(_) =
+ if let TypeKind::ObjCInterface(ref interface) =
*inner_ty.canonical_type(ctx).kind()
{
+ let name = ctx.rust_ident(interface.name());
quote! {
- id
+ #name
}
} else {
arg_item.to_rust_ty_or_opaque(ctx, &())