Skip to content

Commit 57ec0d8

Browse files
committed
updates from comments
1 parent 4c1fb08 commit 57ec0d8

File tree

10 files changed

+91
-95
lines changed

10 files changed

+91
-95
lines changed

src/codegen/mod.rs

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3674,19 +3674,19 @@ fn objc_method_codegen(
36743674
.to_owned(),
36753675
);
36763676
quote! {
3677-
unsafe { msg_send!(class!(#class_name), #methods_and_args) }
3677+
msg_send!(class!(#class_name), #methods_and_args)
36783678
}
36793679
} else {
36803680
quote! {
3681-
unsafe { msg_send!(self, #methods_and_args) }
3681+
msg_send!(self, #methods_and_args)
36823682
}
36833683
};
36843684

36853685
let method_name =
36863686
ctx.rust_ident(format!("{}{}", prefix, method.rust_name()));
36873687

36883688
quote! {
3689-
fn #method_name #sig where <Self as std::ops::Deref>::Target: objc::Message + Sized {
3689+
unsafe fn #method_name #sig where <Self as std::ops::Deref>::Target: objc::Message + Sized {
36903690
#body
36913691
}
36923692
}
@@ -3786,27 +3786,25 @@ impl CodeGenerator for ObjCInterface {
37863786
result.push(impl_trait);
37873787
}
37883788
for parent_id in self.parent_classes.iter() {
3789-
match ctx.resolve_type(parent_id.expect_type_id(ctx)).kind() {
3790-
TypeKind::ObjCInterface(ref parent) => {
3791-
let parent_name = ctx.rust_ident(parent.rust_name());
3792-
let impl_trait = if parent.is_template() {
3793-
let template_names: Vec<Ident> = parent
3794-
.template_names
3795-
.iter()
3796-
.map(|g| ctx.rust_ident(g))
3797-
.collect();
3798-
quote! {
3799-
impl <#(#template_names :'static),*> #parent_name <#(#template_names),*> for #class_name {
3800-
}
3801-
}
3802-
} else {
3803-
quote! {
3804-
impl #parent_name for #class_name { }
3789+
let parent = ctx.resolve_type(parent_id.expect_type_id(ctx));
3790+
if let TypeKind::ObjCInterface(ref parent) = parent.kind() {
3791+
let parent_name = ctx.rust_ident(parent.rust_name());
3792+
let impl_trait = if parent.is_template() {
3793+
let template_names: Vec<Ident> = parent
3794+
.template_names
3795+
.iter()
3796+
.map(|g| ctx.rust_ident(g))
3797+
.collect();
3798+
quote! {
3799+
impl <#(#template_names :'static),*> #parent_name <#(#template_names),*> for #class_name {
38053800
}
3806-
};
3807-
result.push(impl_trait);
3808-
}
3809-
_ => {}
3801+
}
3802+
} else {
3803+
quote! {
3804+
impl #parent_name for #class_name { }
3805+
}
3806+
};
3807+
result.push(impl_trait);
38103808
}
38113809

38123810
}

src/ir/objc.rs

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ impl ObjCInterface {
150150

151151
for (id, item) in items_map
152152
{
153-
if let Some(ty) = item.as_type() {
153+
if let Some(ty) = item.as_type() {
154154
match *ty.kind() {
155155
TypeKind::ObjCInterface(ref protocol) => {
156156
if protocol.is_protocol
@@ -191,24 +191,28 @@ impl ObjCInterface {
191191

192192
for (id, item) in items_map
193193
{
194-
if let Some(ty) = item.as_type() {
195-
match *ty.kind() {
196-
TypeKind::ObjCInterface(ref class) => {
197-
if !class.is_protocol
198-
{
199-
debug!("Checking class {}, ty.name {:?}", class.name, ty.name());
200-
if Some(needle.as_ref()) == ty.name() {
201-
debug!("Found parent class {:?}", item);
202-
interface.parent_classes.push(id);
203-
for i in class.parent_classes.clone() {
204-
interface.parent_classes.push(i);
205-
}
206-
break;
207-
}
208-
}
209-
}
210-
_=> {}
194+
let ty = match item.as_type() {
195+
Some(ty) => ty,
196+
None => continue,
197+
};
198+
199+
let class = match *ty.kind() {
200+
TypeKind::ObjCInterface(ref class) => class,
201+
_ => continue,
202+
};
203+
204+
if class.is_protocol {
205+
continue;
206+
}
207+
208+
debug!("Checking class {}, ty.name {:?}", class.name, ty.name());
209+
if Some(needle.as_ref()) == ty.name() {
210+
debug!("Found parent class {:?}", item);
211+
interface.parent_classes.push(id);
212+
for i in class.parent_classes.clone() {
213+
interface.parent_classes.push(i);
211214
}
215+
break;
212216
}
213217
}
214218
},

tests/expectations/tests/libclang-9/objc_inheritance.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ impl Baz {
2929
}
3030
impl IBaz for Baz {}
3131
pub trait IBaz: Sized + std::ops::Deref {
32-
fn initWithFirstNumber_(
32+
unsafe fn initWithFirstNumber_(
3333
self,
3434
firstNumber: ::std::os::raw::c_int,
3535
) -> instancetype
3636
where
3737
<Self as std::ops::Deref>::Target: objc::Message + Sized,
3838
{
39-
unsafe { msg_send!(self, initWithFirstNumber: firstNumber) }
39+
msg_send!(self, initWithFirstNumber: firstNumber)
4040
}
4141
}
4242
#[repr(transparent)]
@@ -57,14 +57,14 @@ impl Foo {
5757
impl IBaz for Foo {}
5858
impl IFoo for Foo {}
5959
pub trait IFoo: Sized + std::ops::Deref {
60-
fn initWithFirstNumber_(
60+
unsafe fn initWithFirstNumber_(
6161
self,
6262
firstNumber: ::std::os::raw::c_int,
6363
) -> instancetype
6464
where
6565
<Self as std::ops::Deref>::Target: objc::Message + Sized,
6666
{
67-
unsafe { msg_send!(self, initWithFirstNumber: firstNumber) }
67+
msg_send!(self, initWithFirstNumber: firstNumber)
6868
}
6969
}
7070
pub type instancetype = id;

tests/expectations/tests/libclang-9/objc_template.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ impl Foo {
2929
}
3030
impl<ObjectType: 'static> IFoo<ObjectType> for Foo {}
3131
pub trait IFoo<ObjectType>: Sized + std::ops::Deref {
32-
fn get(self) -> u64
32+
unsafe fn get(self) -> u64
3333
where
3434
<Self as std::ops::Deref>::Target: objc::Message + Sized,
3535
{
36-
unsafe { msg_send!(self, get) }
36+
msg_send!(self, get)
3737
}
3838
}
3939
#[repr(transparent)]
@@ -58,10 +58,10 @@ impl<KeyType: 'static, ObjectType: 'static>
5858
pub trait IFooMultiGeneric<KeyType, ObjectType>:
5959
Sized + std::ops::Deref
6060
{
61-
fn objectForKey_(self, key: u64) -> u64
61+
unsafe fn objectForKey_(self, key: u64) -> u64
6262
where
6363
<Self as std::ops::Deref>::Target: objc::Message + Sized,
6464
{
65-
unsafe { msg_send!(self, objectForKey: key) }
65+
msg_send!(self, objectForKey: key)
6666
}
6767
}

tests/expectations/tests/objc_category.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,19 @@ impl Foo {
2929
}
3030
impl IFoo for Foo {}
3131
pub trait IFoo: Sized + std::ops::Deref {
32-
fn method(self)
32+
unsafe fn method(self)
3333
where
3434
<Self as std::ops::Deref>::Target: objc::Message + Sized,
3535
{
36-
unsafe { msg_send!(self, method) }
36+
msg_send!(self, method)
3737
}
3838
}
3939
impl Foo_BarCategory for Foo {}
4040
pub trait Foo_BarCategory: Sized + std::ops::Deref {
41-
fn categoryMethod(self)
41+
unsafe fn categoryMethod(self)
4242
where
4343
<Self as std::ops::Deref>::Target: objc::Message + Sized,
4444
{
45-
unsafe { msg_send!(self, categoryMethod) }
45+
msg_send!(self, categoryMethod)
4646
}
4747
}

tests/expectations/tests/objc_class.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ impl Foo {
3232
}
3333
impl IFoo for Foo {}
3434
pub trait IFoo: Sized + std::ops::Deref {
35-
fn method(self)
35+
unsafe fn method(self)
3636
where
3737
<Self as std::ops::Deref>::Target: objc::Message + Sized,
3838
{
39-
unsafe { msg_send!(self, method) }
39+
msg_send!(self, method)
4040
}
4141
}

tests/expectations/tests/objc_class_method.rs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,45 +29,43 @@ impl Foo {
2929
}
3030
impl IFoo for Foo {}
3131
pub trait IFoo: Sized + std::ops::Deref {
32-
fn method()
32+
unsafe fn method()
3333
where
3434
<Self as std::ops::Deref>::Target: objc::Message + Sized,
3535
{
36-
unsafe { msg_send!(class!(Foo), method) }
36+
msg_send!(class!(Foo), method)
3737
}
38-
fn methodWithInt_(foo: ::std::os::raw::c_int)
38+
unsafe fn methodWithInt_(foo: ::std::os::raw::c_int)
3939
where
4040
<Self as std::ops::Deref>::Target: objc::Message + Sized,
4141
{
42-
unsafe { msg_send!(class!(Foo), methodWithInt: foo) }
42+
msg_send!(class!(Foo), methodWithInt: foo)
4343
}
44-
fn methodWithFoo_(foo: id)
44+
unsafe fn methodWithFoo_(foo: id)
4545
where
4646
<Self as std::ops::Deref>::Target: objc::Message + Sized,
4747
{
48-
unsafe { msg_send!(class!(Foo), methodWithFoo: foo) }
48+
msg_send!(class!(Foo), methodWithFoo: foo)
4949
}
50-
fn methodReturningInt() -> ::std::os::raw::c_int
50+
unsafe fn methodReturningInt() -> ::std::os::raw::c_int
5151
where
5252
<Self as std::ops::Deref>::Target: objc::Message + Sized,
5353
{
54-
unsafe { msg_send!(class!(Foo), methodReturningInt) }
54+
msg_send!(class!(Foo), methodReturningInt)
5555
}
56-
fn methodReturningFoo() -> *mut objc::runtime::Object
56+
unsafe fn methodReturningFoo() -> *mut objc::runtime::Object
5757
where
5858
<Self as std::ops::Deref>::Target: objc::Message + Sized,
5959
{
60-
unsafe { msg_send!(class!(Foo), methodReturningFoo) }
60+
msg_send!(class!(Foo), methodReturningFoo)
6161
}
62-
fn methodWithArg1_andArg2_andArg3_(
62+
unsafe fn methodWithArg1_andArg2_andArg3_(
6363
intvalue: ::std::os::raw::c_int,
6464
ptr: *mut ::std::os::raw::c_char,
6565
floatvalue: f32,
6666
) where
6767
<Self as std::ops::Deref>::Target: objc::Message + Sized,
6868
{
69-
unsafe {
70-
msg_send ! ( class ! ( Foo ) , methodWithArg1 : intvalue andArg2 : ptr andArg3 : floatvalue )
71-
}
69+
msg_send ! ( class ! ( Foo ) , methodWithArg1 : intvalue andArg2 : ptr andArg3 : floatvalue )
7270
}
7371
}

tests/expectations/tests/objc_method.rs

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,49 +29,47 @@ impl Foo {
2929
}
3030
impl IFoo for Foo {}
3131
pub trait IFoo: Sized + std::ops::Deref {
32-
fn method(self)
32+
unsafe fn method(self)
3333
where
3434
<Self as std::ops::Deref>::Target: objc::Message + Sized,
3535
{
36-
unsafe { msg_send!(self, method) }
36+
msg_send!(self, method)
3737
}
38-
fn methodWithInt_(self, foo: ::std::os::raw::c_int)
38+
unsafe fn methodWithInt_(self, foo: ::std::os::raw::c_int)
3939
where
4040
<Self as std::ops::Deref>::Target: objc::Message + Sized,
4141
{
42-
unsafe { msg_send!(self, methodWithInt: foo) }
42+
msg_send!(self, methodWithInt: foo)
4343
}
44-
fn methodWithFoo_(self, foo: id)
44+
unsafe fn methodWithFoo_(self, foo: id)
4545
where
4646
<Self as std::ops::Deref>::Target: objc::Message + Sized,
4747
{
48-
unsafe { msg_send!(self, methodWithFoo: foo) }
48+
msg_send!(self, methodWithFoo: foo)
4949
}
50-
fn methodReturningInt(self) -> ::std::os::raw::c_int
50+
unsafe fn methodReturningInt(self) -> ::std::os::raw::c_int
5151
where
5252
<Self as std::ops::Deref>::Target: objc::Message + Sized,
5353
{
54-
unsafe { msg_send!(self, methodReturningInt) }
54+
msg_send!(self, methodReturningInt)
5555
}
56-
fn methodReturningFoo(self) -> *mut objc::runtime::Object
56+
unsafe fn methodReturningFoo(self) -> *mut objc::runtime::Object
5757
where
5858
<Self as std::ops::Deref>::Target: objc::Message + Sized,
5959
{
60-
unsafe { msg_send!(self, methodReturningFoo) }
60+
msg_send!(self, methodReturningFoo)
6161
}
62-
fn methodWithArg1_andArg2_andArg3_(
62+
unsafe fn methodWithArg1_andArg2_andArg3_(
6363
self,
6464
intvalue: ::std::os::raw::c_int,
6565
ptr: *mut ::std::os::raw::c_char,
6666
floatvalue: f32,
6767
) where
6868
<Self as std::ops::Deref>::Target: objc::Message + Sized,
6969
{
70-
unsafe {
71-
msg_send ! ( self , methodWithArg1 : intvalue andArg2 : ptr andArg3 : floatvalue )
72-
}
70+
msg_send ! ( self , methodWithArg1 : intvalue andArg2 : ptr andArg3 : floatvalue )
7371
}
74-
fn methodWithAndWithoutKeywords_arg2Name__arg4Name_(
72+
unsafe fn methodWithAndWithoutKeywords_arg2Name__arg4Name_(
7573
self,
7674
arg1: ::std::os::raw::c_int,
7775
arg2: f32,
@@ -81,9 +79,7 @@ pub trait IFoo: Sized + std::ops::Deref {
8179
where
8280
<Self as std::ops::Deref>::Target: objc::Message + Sized,
8381
{
84-
unsafe {
85-
msg_send ! ( self , methodWithAndWithoutKeywords : arg1 arg2Name : arg2 arg3 : arg3 arg4Name : arg4 )
86-
}
82+
msg_send ! ( self , methodWithAndWithoutKeywords : arg1 arg2Name : arg2 arg3 : arg3 arg4Name : arg4 )
8783
}
8884
}
8985
pub type instancetype = id;

tests/expectations/tests/objc_method_clash.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,16 @@ impl Foo {
2929
}
3030
impl IFoo for Foo {}
3131
pub trait IFoo: Sized + std::ops::Deref {
32-
fn foo(self)
32+
unsafe fn foo(self)
3333
where
3434
<Self as std::ops::Deref>::Target: objc::Message + Sized,
3535
{
36-
unsafe { msg_send!(self, foo) }
36+
msg_send!(self, foo)
3737
}
38-
fn class_foo()
38+
unsafe fn class_foo()
3939
where
4040
<Self as std::ops::Deref>::Target: objc::Message + Sized,
4141
{
42-
unsafe { msg_send!(class!(Foo), foo) }
42+
msg_send!(class!(Foo), foo)
4343
}
4444
}

0 commit comments

Comments
 (0)