mirror of
https://github.com/openharmony/third_party_rust_bindgen.git
synced 2026-08-26 12:24:45 -04:00
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:
@@ -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 \
|
||||
|
||||
@@ -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) }
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// bindgen-flags: --objc-extern-crate -- -x objective-c
|
||||
// bindgen-osx-only
|
||||
|
||||
@interface Foo<__covariant ObjectType>
|
||||
- (ObjectType)get;
|
||||
@end
|
||||
Reference in New Issue
Block a user