Skip to content

Make objc-related expectations compile #1026

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/ir/objc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,13 +236,21 @@ impl ObjCMethod {
);
}

// Get arguments without type signatures to pass to `msg_send!`
let mut args_without_types = vec![];
for arg in args.iter() {
let name_and_sig: Vec<&str> = arg.as_str().split(' ').collect();
let name = name_and_sig[0];
args_without_types.push(quote::Ident::new(name))
};

let args = split_name
.into_iter()
.zip(args.iter())
.map(|(arg, ty)| quote! { #arg : #ty });
.zip(args_without_types)
.map(|(arg, arg_val)| quote! { #arg : #arg_val });

quote! {
#( #args ),*
#( #args )*
}
}
}
Expand Down
11 changes: 3 additions & 8 deletions tests/expectations/tests/objc_class_method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ impl Foo for id {
unsafe fn methodWithInt_(foo: ::std::os::raw::c_int) {
msg_send!(
objc::runtime::Class::get("Foo").expect("Couldn't find Foo"),
methodWithInt: foo: ::std::os::raw::c_int
methodWithInt: foo
)
}
unsafe fn methodWithFoo_(foo: id) {
msg_send!(
objc::runtime::Class::get("Foo").expect("Couldn't find Foo"),
methodWithFoo: foo: id
methodWithFoo: foo
)
}
unsafe fn methodReturningInt() -> ::std::os::raw::c_int {
Expand All @@ -56,11 +56,6 @@ impl Foo for id {
ptr: *mut ::std::os::raw::c_char,
floatvalue: f32,
) {
msg_send!(
objc::runtime::Class::get("Foo").expect("Couldn't find Foo"),
methodWithArg1: intvalue: ::std::os::raw::c_int,
andArg2: ptr: *mut ::std::os::raw::c_char,
andArg3: floatvalue: f32
)
msg_send ! ( objc :: runtime :: Class :: get ( "Foo" ) . expect ( "Couldn't find Foo" ) , methodWithArg1 : intvalue andArg2 : ptr andArg3 : floatvalue )
}
}
11 changes: 3 additions & 8 deletions tests/expectations/tests/objc_method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ impl Foo for id {
msg_send!(self, method)
}
unsafe fn methodWithInt_(self, foo: ::std::os::raw::c_int) {
msg_send!(self, methodWithInt: foo: ::std::os::raw::c_int)
msg_send!(self, methodWithInt: foo)
}
unsafe fn methodWithFoo_(self, foo: id) {
msg_send!(self, methodWithFoo: foo: id)
msg_send!(self, methodWithFoo: foo)
}
unsafe fn methodReturningInt(self) -> ::std::os::raw::c_int {
msg_send!(self, methodReturningInt)
Expand All @@ -43,11 +43,6 @@ impl Foo for id {
ptr: *mut ::std::os::raw::c_char,
floatvalue: f32,
) {
msg_send!(
self,
methodWithArg1: intvalue: ::std::os::raw::c_int,
andArg2: ptr: *mut ::std::os::raw::c_char,
andArg3: floatvalue: f32
)
msg_send ! ( self , methodWithArg1 : intvalue andArg2 : ptr andArg3 : floatvalue )
}
}
5 changes: 1 addition & 4 deletions tests/expectations/tests/objc_property_fnptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ impl Foo for id {
self,
func: ::std::option::Option<unsafe extern "C" fn() -> ::std::os::raw::c_int>,
) {
msg_send!(
self,
setFunc: func: ::std::option::Option<unsafe extern "C" fn() -> ::std::os::raw::c_int>
)
msg_send!(self, setFunc: func)
}
}