summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexey Zabelin <hello@alexeyzabelin.com>2017-09-23 13:01:13 -0400
committerAlexey Zabelin <hello@alexeyzabelin.com>2017-09-23 13:01:13 -0400
commitca0aa04995d557bc1e432e7422e8a75ba365afb7 (patch)
treeb0284b9e7ae13ecb4428f2775bdf6cc641e74723
parent30d6e0417a691da4f4959c8083328241fc02d1fd (diff)
Make objc-related expectations compile
WIP, fixes #1004. After looking at how `msg_send!` is supposed to be used, I realized that we were erroneously passing type signatures to it. The expectations compile now, but some of them are not formatted properly. My guess is that `rustfmt` does not know how to format the following: ``` msg_send!(obj, arg1:1 arg2:2 arg3:3) ``` Notice the lack of separatros between `arg`s.
-rw-r--r--src/ir/objc.rs14
-rw-r--r--tests/expectations/tests/objc_class_method.rs11
-rw-r--r--tests/expectations/tests/objc_method.rs11
-rw-r--r--tests/expectations/tests/objc_property_fnptr.rs5
4 files changed, 18 insertions, 23 deletions
diff --git a/src/ir/objc.rs b/src/ir/objc.rs
index cabbd389..0f72c399 100644
--- a/src/ir/objc.rs
+++ b/src/ir/objc.rs
@@ -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 )*
}
}
}
diff --git a/tests/expectations/tests/objc_class_method.rs b/tests/expectations/tests/objc_class_method.rs
index 3803f1f8..a10a1fca 100644
--- a/tests/expectations/tests/objc_class_method.rs
+++ b/tests/expectations/tests/objc_class_method.rs
@@ -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 {
@@ -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 )
}
}
diff --git a/tests/expectations/tests/objc_method.rs b/tests/expectations/tests/objc_method.rs
index abf55849..bd6e748a 100644
--- a/tests/expectations/tests/objc_method.rs
+++ b/tests/expectations/tests/objc_method.rs
@@ -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)
@@ -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 )
}
}
diff --git a/tests/expectations/tests/objc_property_fnptr.rs b/tests/expectations/tests/objc_property_fnptr.rs
index 16e0b4ba..4f98f9fb 100644
--- a/tests/expectations/tests/objc_property_fnptr.rs
+++ b/tests/expectations/tests/objc_property_fnptr.rs
@@ -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)
}
}