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 /src | |
parent | f39c4a95cbb92a3df2f68765b7b4648a51bb4402 (diff) |
Added non-keyword support to objective-c methods.
Diffstat (limited to 'src')
-rw-r--r-- | src/ir/objc.rs | 28 |
1 files changed, 19 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 )* |