diff --git a/crates/header-translator/src/method.rs b/crates/header-translator/src/method.rs index 29ec44239..7a8ee56a6 100644 --- a/crates/header-translator/src/method.rs +++ b/crates/header-translator/src/method.rs @@ -195,7 +195,7 @@ impl Method { }); let ty = entity.get_type().expect("argument type"); - let ty = RustType::parse(ty, false, is_consumed); + let ty = RustType::parse_argument(ty, is_consumed); (name, qualifier, ty) }) @@ -210,7 +210,7 @@ impl Method { ); } let result_type = if result_type.get_kind() != TypeKind::Void { - Some(RustType::parse(result_type, true, false)) + Some(RustType::parse_return(result_type)) } else { None }; diff --git a/crates/header-translator/src/rust_type.rs b/crates/header-translator/src/rust_type.rs index 9dc7235ae..1149bb3db 100644 --- a/crates/header-translator/src/rust_type.rs +++ b/crates/header-translator/src/rust_type.rs @@ -301,7 +301,7 @@ impl RustType { matches!(self, Self::Id { .. }) } - pub fn parse(ty: Type<'_>, is_return: bool, is_consumed: bool) -> Self { + fn parse(ty: Type<'_>, is_return: bool, is_consumed: bool) -> Self { use TypeKind::*; // println!("{:?}, {:?}", ty, ty.get_class_type()); @@ -450,6 +450,60 @@ impl RustType { } } +impl RustType { + fn visit_lifetime(&self, mut f: impl FnMut(Lifetime)) { + match self { + Self::Id { lifetime, .. } => f(*lifetime), + Self::Pointer { pointee, .. } => pointee.visit_lifetime(f), + Self::Array { element_type, .. } => element_type.visit_lifetime(f), + _ => {} + } + } + + pub fn parse_return(ty: Type<'_>) -> Self { + let this = Self::parse(ty, true, false); + + this.visit_lifetime(|lifetime| { + if lifetime != Lifetime::Unspecified { + panic!("unexpected lifetime in return {this:?}"); + } + }); + + this + } + + pub fn parse_argument(ty: Type<'_>, is_consumed: bool) -> Self { + let this = Self::parse(ty, false, is_consumed); + + match &this { + Self::Pointer { pointee, .. } => pointee.visit_lifetime(|lifetime| { + if lifetime != Lifetime::Autoreleasing && lifetime != Lifetime::Unspecified { + panic!("unexpected lifetime {lifetime:?} in pointer argument {ty:?}"); + } + }), + _ => this.visit_lifetime(|lifetime| { + if lifetime != Lifetime::Strong && lifetime != Lifetime::Unspecified { + panic!("unexpected lifetime {lifetime:?} in argument {ty:?}"); + } + }), + } + + this + } + + pub fn parse_typedef(ty: Type<'_>) -> Self { + let this = Self::parse(ty, false, false); + + this.visit_lifetime(|lifetime| { + if lifetime != Lifetime::Unspecified { + panic!("unexpected lifetime in typedef {this:?}"); + } + }); + + this + } +} + impl ToTokens for RustType { fn to_tokens(&self, tokens: &mut TokenStream) { use RustType::*; diff --git a/crates/header-translator/src/stmt.rs b/crates/header-translator/src/stmt.rs index 038648621..b2fbac0aa 100644 --- a/crates/header-translator/src/stmt.rs +++ b/crates/header-translator/src/stmt.rs @@ -299,7 +299,7 @@ impl Stmt { }) } TypeKind::Typedef => { - let type_ = RustType::parse(ty, false, false); + let type_ = RustType::parse_typedef(ty); Some(Self::AliasDecl { name, type_ }) } _ => { diff --git a/crates/icrate/src/Foundation.toml b/crates/icrate/src/Foundation.toml index 418379d44..9b7162c2d 100644 --- a/crates/icrate/src/Foundation.toml +++ b/crates/icrate/src/Foundation.toml @@ -26,3 +26,16 @@ initWithString = { unsafe = false } [class.NSBlockOperation.methods] # Uses `NSArray`, which is difficult to handle executionBlocks = { skipped = true } + +# These use `Class`, which is unsupported +[class.NSItemProvider.methods] +registerObjectOfClass_visibility_loadHandler = { skipped = true } +canLoadObjectOfClass = { skipped = true } +loadObjectOfClass_completionHandler = { skipped = true } + +# These use `SomeObject * __strong *`, which is unsupported +[class.NSNetService.methods] +getInputStream_outputStream = { skipped = true } +[class.NSPropertyListSerialization.methods] +dataFromPropertyList_format_errorDescription = { skipped = true } +propertyListFromData_mutabilityOption_format_errorDescription = { skipped = true } diff --git a/crates/icrate/src/generated/Foundation/NSItemProvider.rs b/crates/icrate/src/generated/Foundation/NSItemProvider.rs index b3e806e09..ac08b003f 100644 --- a/crates/icrate/src/generated/Foundation/NSItemProvider.rs +++ b/crates/icrate/src/generated/Foundation/NSItemProvider.rs @@ -108,33 +108,6 @@ impl NSItemProvider { ) { msg_send![self, registerObject: object, visibility: visibility] } - pub unsafe fn registerObjectOfClass_visibility_loadHandler( - &self, - aClass: &TodoProtocols, - visibility: NSItemProviderRepresentationVisibility, - loadHandler: TodoBlock, - ) { - msg_send![ - self, - registerObjectOfClass: aClass, - visibility: visibility, - loadHandler: loadHandler - ] - } - pub unsafe fn canLoadObjectOfClass(&self, aClass: &TodoProtocols) -> bool { - msg_send![self, canLoadObjectOfClass: aClass] - } - pub unsafe fn loadObjectOfClass_completionHandler( - &self, - aClass: &TodoProtocols, - completionHandler: TodoBlock, - ) -> Id { - msg_send_id![ - self, - loadObjectOfClass: aClass, - completionHandler: completionHandler - ] - } pub unsafe fn initWithItem_typeIdentifier( &self, item: Option<&NSSecureCoding>, diff --git a/crates/icrate/src/generated/Foundation/NSNetServices.rs b/crates/icrate/src/generated/Foundation/NSNetServices.rs index 67b19933c..f958b2990 100644 --- a/crates/icrate/src/generated/Foundation/NSNetServices.rs +++ b/crates/icrate/src/generated/Foundation/NSNetServices.rs @@ -70,17 +70,6 @@ impl NSNetService { pub unsafe fn resolveWithTimeout(&self, timeout: NSTimeInterval) { msg_send![self, resolveWithTimeout: timeout] } - pub unsafe fn getInputStream_outputStream( - &self, - inputStream: *mut *mut NSInputStream, - outputStream: *mut *mut NSOutputStream, - ) -> bool { - msg_send![ - self, - getInputStream: inputStream, - outputStream: outputStream - ] - } pub unsafe fn setTXTRecordData(&self, recordData: Option<&NSData>) -> bool { msg_send![self, setTXTRecordData: recordData] } diff --git a/crates/icrate/src/generated/Foundation/NSPropertyList.rs b/crates/icrate/src/generated/Foundation/NSPropertyList.rs index 49b47c75f..9afbb9d78 100644 --- a/crates/icrate/src/generated/Foundation/NSPropertyList.rs +++ b/crates/icrate/src/generated/Foundation/NSPropertyList.rs @@ -83,30 +83,4 @@ impl NSPropertyListSerialization { error: error ] } - pub unsafe fn dataFromPropertyList_format_errorDescription( - plist: &Object, - format: NSPropertyListFormat, - errorString: *mut *mut NSString, - ) -> Option> { - msg_send_id![ - Self::class(), - dataFromPropertyList: plist, - format: format, - errorDescription: errorString - ] - } - pub unsafe fn propertyListFromData_mutabilityOption_format_errorDescription( - data: &NSData, - opt: NSPropertyListMutabilityOptions, - format: *mut NSPropertyListFormat, - errorString: *mut *mut NSString, - ) -> Option> { - msg_send_id![ - Self::class(), - propertyListFromData: data, - mutabilityOption: opt, - format: format, - errorDescription: errorString - ] - } }