summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikko Lehtonen <scoopr@iki.fi>2017-03-14 01:43:59 +0200
committerMikko Lehtonen <scoopr@iki.fi>2017-05-03 00:54:14 +0300
commitc266097617f199d66b422a27ecd0bf22c6a9fdb2 (patch)
tree7c6b45f4f668ba05a02ce131aeb73ff4db10e396
parent86aabcf4479e72d63d75eeea802290802a55fb22 (diff)
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.
-rw-r--r--src/ir/ty.rs18
-rw-r--r--tests/expectations/tests/objc_template.rs18
-rw-r--r--tests/headers/objc_template.h6
3 files changed, 42 insertions, 0 deletions
diff --git a/src/ir/ty.rs b/src/ir/ty.rs
index c3f26572..a9054e98 100644
--- a/src/ir/ty.rs
+++ b/src/ir/ty.rs
@@ -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 \
diff --git a/tests/expectations/tests/objc_template.rs b/tests/expectations/tests/objc_template.rs
new file mode 100644
index 00000000..e5a874c6
--- /dev/null
+++ b/tests/expectations/tests/objc_template.rs
@@ -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) }
+}
diff --git a/tests/headers/objc_template.h b/tests/headers/objc_template.h
new file mode 100644
index 00000000..62398eb7
--- /dev/null
+++ b/tests/headers/objc_template.h
@@ -0,0 +1,6 @@
+// bindgen-flags: --objc-extern-crate -- -x objective-c
+// bindgen-osx-only
+
+@interface Foo<__covariant ObjectType>
+- (ObjectType)get;
+@end