diff options
author | Sebastian Imlay <sebastian.imlay@gmail.com> | 2020-01-04 14:45:59 -0800 |
---|---|---|
committer | Emilio Cobos Álvarez <emilio@crisal.io> | 2020-01-05 14:05:35 +0100 |
commit | ba409edf5d3a1acc6ac4dcb32d1e168cc3a2a41b (patch) | |
tree | 0ff53a9ce5518692e0de639ad4dbf02b226a99b3 | |
parent | f39c4a95cbb92a3df2f68765b7b4648a51bb4402 (diff) |
Added non-keyword support to objective-c methods.
-rw-r--r-- | src/ir/objc.rs | 28 | ||||
-rw-r--r-- | tests/expectations/tests/objc_method.rs | 17 | ||||
-rw-r--r-- | tests/headers/objc_method.h | 4 |
3 files changed, 40 insertions, 9 deletions
diff --git a/src/ir/objc.rs b/src/ir/objc.rs index 1b2bd5de..cfbf3dd0 100644 --- a/src/ir/objc.rs +++ b/src/ir/objc.rs @@ -226,11 +226,16 @@ impl ObjCMethod { /// Formats the method call pub fn format_method_call(&self, args: &[TokenStream]) -> TokenStream { - let split_name: Vec<_> = self + let split_name: Vec<Option<Ident>> = self .name .split(':') - .filter(|p| !p.is_empty()) - .map(|name| Ident::new(name, Span::call_site())) + .map(|name| { + if name.is_empty() { + None + } else { + Some(Ident::new(name, Span::call_site())) + } + }) .collect(); // No arguments @@ -242,11 +247,11 @@ impl ObjCMethod { } // Check right amount of arguments - if args.len() != split_name.len() { + if args.len() != split_name.len() - 1 { panic!( "Incorrect method name or arguments for objc method, {:?} vs {:?}", args, - split_name + split_name, ); } @@ -259,10 +264,15 @@ impl ObjCMethod { args_without_types.push(Ident::new(name, Span::call_site())) } - let args = split_name - .into_iter() - .zip(args_without_types) - .map(|(arg, arg_val)| quote! { #arg : #arg_val }); + let args = split_name.into_iter().zip(args_without_types).map( + |(arg, arg_val)| { + if let Some(arg) = arg { + quote! { #arg: #arg_val } + } else { + quote! { #arg_val: #arg_val } + } + }, + ); quote! { #( #args )* diff --git a/tests/expectations/tests/objc_method.rs b/tests/expectations/tests/objc_method.rs index 2c61aa23..255d8510 100644 --- a/tests/expectations/tests/objc_method.rs +++ b/tests/expectations/tests/objc_method.rs @@ -24,6 +24,13 @@ pub trait Foo { ptr: *mut ::std::os::raw::c_char, floatvalue: f32, ); + unsafe fn methodWithAndWithoutKeywords_arg2Name__arg4Name_( + self, + arg1: ::std::os::raw::c_int, + arg2: f32, + arg3: f32, + arg4: ::std::os::raw::c_int, + ) -> instancetype; } impl Foo for id { unsafe fn method(self) { @@ -49,4 +56,14 @@ impl Foo for id { ) { msg_send ! ( self , methodWithArg1 : intvalue andArg2 : ptr andArg3 : floatvalue ) } + unsafe fn methodWithAndWithoutKeywords_arg2Name__arg4Name_( + self, + arg1: ::std::os::raw::c_int, + arg2: f32, + arg3: f32, + arg4: ::std::os::raw::c_int, + ) -> instancetype { + msg_send ! ( self , methodWithAndWithoutKeywords : arg1 arg2Name : arg2 arg3 : arg3 arg4Name : arg4 ) + } } +pub type instancetype = id; diff --git a/tests/headers/objc_method.h b/tests/headers/objc_method.h index 7a22e8e4..c4d375ba 100644 --- a/tests/headers/objc_method.h +++ b/tests/headers/objc_method.h @@ -8,4 +8,8 @@ - (int)methodReturningInt; - (Foo*)methodReturningFoo; - (void)methodWithArg1:(int)intvalue andArg2:(char*)ptr andArg3:(float)floatvalue; +- (instancetype)methodWithAndWithoutKeywords:(int)arg1 + arg2Name:(float)arg2 + :(float)arg3 + arg4Name:(int)arg4; @end |