diff options
Diffstat (limited to 'src/ir/objc.rs')
-rw-r--r-- | src/ir/objc.rs | 69 |
1 files changed, 37 insertions, 32 deletions
diff --git a/src/ir/objc.rs b/src/ir/objc.rs index 91855c6..0845ad0 100644 --- a/src/ir/objc.rs +++ b/src/ir/objc.rs @@ -89,12 +89,10 @@ impl ObjCInterface { pub fn rust_name(&self) -> String { if let Some(ref cat) = self.category { format!("{}_{}", self.name(), cat) + } else if self.is_protocol { + format!("P{}", self.name()) } else { - if self.is_protocol { - format!("P{}", self.name()) - } else { - format!("I{}", self.name().to_owned()) - } + format!("I{}", self.name().to_owned()) } } @@ -149,28 +147,34 @@ impl ObjCInterface { // Gather protocols this interface conforms to let needle = format!("P{}", c.spelling()); let items_map = ctx.items(); - debug!("Interface {} conforms to {}, find the item", interface.name, needle); + debug!( + "Interface {} conforms to {}, find the item", + interface.name, needle + ); - for (id, item) in items_map - { + for (id, item) in items_map { if let Some(ty) = item.as_type() { - match *ty.kind() { - TypeKind::ObjCInterface(ref protocol) => { - if protocol.is_protocol - { - debug!("Checking protocol {}, ty.name {:?}", protocol.name, ty.name()); - if Some(needle.as_ref()) == ty.name() { - debug!("Found conforming protocol {:?}", item); - interface.conforms_to.push(id); - break; - } + if let TypeKind::ObjCInterface(ref protocol) = + *ty.kind() + { + if protocol.is_protocol { + debug!( + "Checking protocol {}, ty.name {:?}", + protocol.name, + ty.name() + ); + if Some(needle.as_ref()) == ty.name() { + debug!( + "Found conforming protocol {:?}", + item + ); + interface.conforms_to.push(id); + break; } } - _ => {} } } } - } CXCursor_ObjCInstanceMethodDecl | CXCursor_ObjCClassMethodDecl => { @@ -178,8 +182,10 @@ impl ObjCInterface { let signature = FunctionSig::from_ty(&c.cur_type(), &c, ctx) .expect("Invalid function sig"); - let is_class_method = c.kind() == CXCursor_ObjCClassMethodDecl; - let method = ObjCMethod::new(&name, signature, is_class_method); + let is_class_method = + c.kind() == CXCursor_ObjCClassMethodDecl; + let method = + ObjCMethod::new(&name, signature, is_class_method); interface.add_method(method); } CXCursor_TemplateTypeParameter => { @@ -189,7 +195,7 @@ impl ObjCInterface { CXCursor_ObjCSuperClassRef => { let item = Item::from_ty_or_ref(c.cur_type(), c, None, ctx); interface.parent_class = Some(item.into()); - }, + } _ => {} } CXChildVisit_Continue @@ -218,7 +224,7 @@ impl ObjCMethod { ObjCMethod { name: name.to_owned(), - rust_name: rust_name.to_owned(), + rust_name, signature, is_class_method, } @@ -261,7 +267,7 @@ impl ObjCMethod { .collect(); // No arguments - if args.len() == 0 && split_name.len() == 1 { + if args.is_empty() && split_name.len() == 1 { let name = &split_name[0]; return quote! { #name @@ -269,13 +275,12 @@ impl ObjCMethod { } // Check right amount of arguments - if args.len() != split_name.len() - 1 { - panic!( - "Incorrect method name or arguments for objc method, {:?} vs {:?}", - args, - split_name, - ); - } + assert!( + args.len() == split_name.len() - 1, + "Incorrect method name or arguments for objc method, {:?} vs {:?}", + args, + split_name + ); // Get arguments without type signatures to pass to `msg_send!` let mut args_without_types = vec![]; |