objc: Handle template params

The objetive-c template type params were handled as Typedefs so every
interface generated its own, clashing in the namespace. This now maps them to id.
This commit is contained in:
Mikko Lehtonen
2017-03-14 01:43:59 +02:00
parent 3fa0d9972c
commit f8b7761ba3
3 changed files with 42 additions and 0 deletions
+18
View File
@@ -836,6 +836,24 @@ impl Type {
_ => {}
}
// Objective C template type parameter
// FIXME: This is probably wrong, we are attempting to find the
// objc template params, which seem to manifest as a typedef.
// We are rewriting them as id to suppress multiple conflicting
// typedefs at root level
if ty_kind == CXType_Typedef {
let is_template_type_param = ty.declaration().kind() == CXCursor_TemplateTypeParameter;
let is_canonical_objcpointer = canonical_ty.kind() == CXType_ObjCObjectPointer;
// We have found a template type for objc interface
if is_canonical_objcpointer && is_template_type_param {
// Objective-C generics are just ids with fancy name.
// To keep it simple, just name them ids
name = "id".to_owned();
}
}
if location.kind() == CXCursor_ClassTemplatePartialSpecialization {
// Sorry! (Not sorry)
warn!("Found a partial template specialization; bindgen does not \
+18
View File
@@ -0,0 +1,18 @@
/* automatically generated by rust-bindgen */
#![allow(non_snake_case)]
#![cfg(target_os="macos")]
#[macro_use]
extern crate objc;
#[allow(non_camel_case_types)]
pub type id = *mut objc::runtime::Object;
pub trait Foo {
unsafe fn get(self)
-> id;
}
impl Foo for id {
unsafe fn get(self) -> id { msg_send!(self , get) }
}
+6
View File
@@ -0,0 +1,6 @@
// bindgen-flags: --objc-extern-crate -- -x objective-c
// bindgen-osx-only
@interface Foo<__covariant ObjectType>
- (ObjectType)get;
@end