Skip to content

Commit

Permalink
Fix out parameters (except for NSError)
Browse files Browse the repository at this point in the history
Assuming we find a good solution to #277
  • Loading branch information
madsmtm committed Oct 6, 2022
1 parent 793be25 commit ec53e8d
Show file tree
Hide file tree
Showing 20 changed files with 111 additions and 76 deletions.
85 changes: 60 additions & 25 deletions header-translator/src/rust_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -575,33 +575,68 @@ impl ToTokens for RustType {
nullability,
is_const,
pointee,
} => {
let tokens = match &**pointee {
Self::Id {
type_,
is_return: _,
is_const,
lifetime: _,
nullability,
} => {
if *nullability == Nullability::NonNull {
quote!(NonNull<#type_>)
} else if *is_const {
quote!(*const #type_)
} else {
quote!(*mut #type_)
}
} => match &**pointee {
Self::Id {
type_: tokens,
is_return: false,
is_const: false,
lifetime: Lifetime::Autoreleasing,
nullability: inner_nullability,
} => {
let tokens = quote!(Id<#tokens, Shared>);
let tokens = if *inner_nullability == Nullability::NonNull {
tokens
} else {
quote!(Option<#tokens>)
};

let tokens = if *is_const {
quote!(&#tokens)
} else {
quote!(&mut #tokens)
};
if *nullability == Nullability::NonNull {
tokens
} else {
quote!(Option<#tokens>)
}
pointee => quote!(#pointee),
};
if *nullability == Nullability::NonNull {
quote!(NonNull<#tokens>)
} else if *is_const {
quote!(*const #tokens)
} else {
quote!(*mut #tokens)
}
}
Self::Id {
type_: tokens,
is_return: false,
is_const: false,
lifetime: Lifetime::Unspecified,
nullability: inner_nullability,
} => {
if tokens.name != "NSError" {
println!("id*: {self:?}");
}
let tokens = if *inner_nullability == Nullability::NonNull {
quote!(NonNull<#tokens>)
} else {
quote!(*mut #tokens)
};
if *nullability == Nullability::NonNull {
quote!(NonNull<#tokens>)
} else if *is_const {
quote!(*const #tokens)
} else {
quote!(*mut #tokens)
}
}
Self::Id { .. } => {
unreachable!("there should be no id with other values: {self:?}")
}
pointee => {
if *nullability == Nullability::NonNull {
quote!(NonNull<#pointee>)
} else if *is_const {
quote!(*const #pointee)
} else {
quote!(*mut #pointee)
}
}
},
Array {
element_type,
num_elements,
Expand Down
8 changes: 4 additions & 4 deletions icrate/src/generated/Foundation/NSAppleScript.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ impl NSAppleScript {
pub unsafe fn initWithContentsOfURL_error(
&self,
url: &NSURL,
errorInfo: *mut *mut NSDictionary<NSString, Object>,
errorInfo: Option<&mut Option<Id<NSDictionary<NSString, Object>, Shared>>>,
) -> Option<Id<Self, Shared>> {
msg_send_id![self, initWithContentsOfURL: url, error: errorInfo]
}
Expand All @@ -27,20 +27,20 @@ impl NSAppleScript {
}
pub unsafe fn compileAndReturnError(
&self,
errorInfo: *mut *mut NSDictionary<NSString, Object>,
errorInfo: Option<&mut Option<Id<NSDictionary<NSString, Object>, Shared>>>,
) -> bool {
msg_send![self, compileAndReturnError: errorInfo]
}
pub unsafe fn executeAndReturnError(
&self,
errorInfo: *mut *mut NSDictionary<NSString, Object>,
errorInfo: Option<&mut Option<Id<NSDictionary<NSString, Object>, Shared>>>,
) -> Id<NSAppleEventDescriptor, Shared> {
msg_send_id![self, executeAndReturnError: errorInfo]
}
pub unsafe fn executeAppleEvent_error(
&self,
event: &NSAppleEventDescriptor,
errorInfo: *mut *mut NSDictionary<NSString, Object>,
errorInfo: Option<&mut Option<Id<NSDictionary<NSString, Object>, Shared>>>,
) -> Id<NSAppleEventDescriptor, Shared> {
msg_send_id![self, executeAppleEvent: event, error: errorInfo]
}
Expand Down
6 changes: 3 additions & 3 deletions icrate/src/generated/Foundation/NSCalendar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl NSCalendar {
pub unsafe fn rangeOfUnit_startDate_interval_forDate(
&self,
unit: NSCalendarUnit,
datep: *mut *mut NSDate,
datep: Option<&mut Option<Id<NSDate, Shared>>>,
tip: *mut NSTimeInterval,
date: &NSDate,
) -> bool {
Expand Down Expand Up @@ -273,7 +273,7 @@ impl NSCalendar {
}
pub unsafe fn rangeOfWeekendStartDate_interval_containingDate(
&self,
datep: *mut *mut NSDate,
datep: Option<&mut Option<Id<NSDate, Shared>>>,
tip: *mut NSTimeInterval,
date: &NSDate,
) -> bool {
Expand All @@ -286,7 +286,7 @@ impl NSCalendar {
}
pub unsafe fn nextWeekendStartDate_interval_options_afterDate(
&self,
datep: *mut *mut NSDate,
datep: Option<&mut Option<Id<NSDate, Shared>>>,
tip: *mut NSTimeInterval,
options: NSCalendarOptions,
date: &NSDate,
Expand Down
4 changes: 2 additions & 2 deletions icrate/src/generated/Foundation/NSDateComponentsFormatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ impl NSDateComponentsFormatter {
}
pub unsafe fn getObjectValue_forString_errorDescription(
&self,
obj: *mut *mut Object,
obj: Option<&mut Option<Id<Object, Shared>>>,
string: &NSString,
error: *mut *mut NSString,
error: Option<&mut Option<Id<NSString, Shared>>>,
) -> bool {
msg_send![
self,
Expand Down
2 changes: 1 addition & 1 deletion icrate/src/generated/Foundation/NSDateFormatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ extern_class!(
impl NSDateFormatter {
pub unsafe fn getObjectValue_forString_range_error(
&self,
obj: *mut *mut Object,
obj: Option<&mut Option<Id<Object, Shared>>>,
string: &NSString,
rangep: *mut NSRange,
error: *mut *mut NSError,
Expand Down
4 changes: 2 additions & 2 deletions icrate/src/generated/Foundation/NSEnergyFormatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ impl NSEnergyFormatter {
}
pub unsafe fn getObjectValue_forString_errorDescription(
&self,
obj: *mut *mut Object,
obj: Option<&mut Option<Id<Object, Shared>>>,
string: &NSString,
error: *mut *mut NSString,
error: Option<&mut Option<Id<NSString, Shared>>>,
) -> bool {
msg_send![
self,
Expand Down
6 changes: 3 additions & 3 deletions icrate/src/generated/Foundation/NSFileManager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ impl NSFileManager {
pub unsafe fn trashItemAtURL_resultingItemURL_error(
&self,
url: &NSURL,
outResultingURL: *mut *mut NSURL,
outResultingURL: Option<&mut Option<Id<NSURL, Shared>>>,
error: *mut *mut NSError,
) -> bool {
msg_send![
Expand Down Expand Up @@ -463,7 +463,7 @@ impl NSFileManager {
newItemURL: &NSURL,
backupItemName: Option<&NSString>,
options: NSFileManagerItemReplacementOptions,
resultingURL: *mut *mut NSURL,
resultingURL: Option<&mut Option<Id<NSURL, Shared>>>,
error: *mut *mut NSError,
) -> bool {
msg_send![
Expand Down Expand Up @@ -517,7 +517,7 @@ impl NSFileManager {
pub unsafe fn URLForPublishingUbiquitousItemAtURL_expirationDate_error(
&self,
url: &NSURL,
outDate: *mut *mut NSDate,
outDate: Option<&mut Option<Id<NSDate, Shared>>>,
error: *mut *mut NSError,
) -> Option<Id<NSURL, Shared>> {
msg_send_id![
Expand Down
12 changes: 6 additions & 6 deletions icrate/src/generated/Foundation/NSFormatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ impl NSFormatter {
}
pub unsafe fn getObjectValue_forString_errorDescription(
&self,
obj: *mut *mut Object,
obj: Option<&mut Option<Id<Object, Shared>>>,
string: &NSString,
error: *mut *mut NSString,
error: Option<&mut Option<Id<NSString, Shared>>>,
) -> bool {
msg_send![
self,
Expand All @@ -52,8 +52,8 @@ impl NSFormatter {
pub unsafe fn isPartialStringValid_newEditingString_errorDescription(
&self,
partialString: &NSString,
newString: *mut *mut NSString,
error: *mut *mut NSString,
newString: Option<&mut Option<Id<NSString, Shared>>>,
error: Option<&mut Option<Id<NSString, Shared>>>,
) -> bool {
msg_send![
self,
Expand All @@ -64,11 +64,11 @@ impl NSFormatter {
}
pub unsafe fn isPartialStringValid_proposedSelectedRange_originalString_originalSelectedRange_errorDescription(
&self,
partialStringPtr: NonNull<NonNull<NSString>>,
partialStringPtr: &mut Id<NSString, Shared>,
proposedSelRangePtr: NSRangePointer,
origString: &NSString,
origSelRange: NSRange,
error: *mut *mut NSString,
error: Option<&mut Option<Id<NSString, Shared>>>,
) -> bool {
msg_send![
self,
Expand Down
4 changes: 2 additions & 2 deletions icrate/src/generated/Foundation/NSKeyValueCoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl NSObject {
}
pub unsafe fn validateValue_forKey_error(
&self,
ioValue: NonNull<*mut Object>,
ioValue: &mut Option<Id<Object, Shared>>,
inKey: &NSString,
outError: *mut *mut NSError,
) -> bool {
Expand All @@ -46,7 +46,7 @@ impl NSObject {
}
pub unsafe fn validateValue_forKeyPath_error(
&self,
ioValue: NonNull<*mut Object>,
ioValue: &mut Option<Id<Object, Shared>>,
inKeyPath: &NSString,
outError: *mut *mut NSError,
) -> bool {
Expand Down
4 changes: 2 additions & 2 deletions icrate/src/generated/Foundation/NSLengthFormatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ impl NSLengthFormatter {
}
pub unsafe fn getObjectValue_forString_errorDescription(
&self,
obj: *mut *mut Object,
obj: Option<&mut Option<Id<Object, Shared>>>,
string: &NSString,
error: *mut *mut NSString,
error: Option<&mut Option<Id<NSString, Shared>>>,
) -> bool {
msg_send![
self,
Expand Down
10 changes: 5 additions & 5 deletions icrate/src/generated/Foundation/NSLinguisticTagger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl NSLinguisticTagger {
unit: NSLinguisticTaggerUnit,
scheme: &NSLinguisticTagScheme,
options: NSLinguisticTaggerOptions,
tokenRanges: *mut *mut NSArray<NSValue>,
tokenRanges: Option<&mut Option<Id<NSArray<NSValue>, Shared>>>,
) -> Id<NSArray<NSLinguisticTag>, Shared> {
msg_send_id![
self,
Expand Down Expand Up @@ -150,7 +150,7 @@ impl NSLinguisticTagger {
range: NSRange,
tagScheme: &NSString,
opts: NSLinguisticTaggerOptions,
tokenRanges: *mut *mut NSArray<NSValue>,
tokenRanges: Option<&mut Option<Id<NSArray<NSValue>, Shared>>>,
) -> Id<NSArray<NSString>, Shared> {
msg_send_id![
self,
Expand Down Expand Up @@ -188,7 +188,7 @@ impl NSLinguisticTagger {
scheme: &NSLinguisticTagScheme,
options: NSLinguisticTaggerOptions,
orthography: Option<&NSOrthography>,
tokenRanges: *mut *mut NSArray<NSValue>,
tokenRanges: Option<&mut Option<Id<NSArray<NSValue>, Shared>>>,
) -> Id<NSArray<NSLinguisticTag>, Shared> {
msg_send_id![
Self::class(),
Expand Down Expand Up @@ -227,7 +227,7 @@ impl NSLinguisticTagger {
tagScheme: &NSString,
tokenRange: NSRangePointer,
sentenceRange: NSRangePointer,
scores: *mut *mut NSArray<NSValue>,
scores: Option<&mut Option<Id<NSArray<NSValue>, Shared>>>,
) -> Option<Id<NSArray<NSString>, Shared>> {
msg_send_id![
self,
Expand Down Expand Up @@ -259,7 +259,7 @@ impl NSString {
scheme: &NSLinguisticTagScheme,
options: NSLinguisticTaggerOptions,
orthography: Option<&NSOrthography>,
tokenRanges: *mut *mut NSArray<NSValue>,
tokenRanges: Option<&mut Option<Id<NSArray<NSValue>, Shared>>>,
) -> Id<NSArray<NSLinguisticTag>, Shared> {
msg_send_id![
self,
Expand Down
4 changes: 2 additions & 2 deletions icrate/src/generated/Foundation/NSMassFormatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ impl NSMassFormatter {
}
pub unsafe fn getObjectValue_forString_errorDescription(
&self,
obj: *mut *mut Object,
obj: Option<&mut Option<Id<Object, Shared>>>,
string: &NSString,
error: *mut *mut NSString,
error: Option<&mut Option<Id<NSString, Shared>>>,
) -> bool {
msg_send![
self,
Expand Down
2 changes: 1 addition & 1 deletion icrate/src/generated/Foundation/NSNumberFormatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ extern_class!(
impl NSNumberFormatter {
pub unsafe fn getObjectValue_forString_range_error(
&self,
obj: *mut *mut Object,
obj: Option<&mut Option<Id<Object, Shared>>>,
string: &NSString,
rangep: *mut NSRange,
error: *mut *mut NSError,
Expand Down
4 changes: 2 additions & 2 deletions icrate/src/generated/Foundation/NSPathUtilities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ impl NSString {
}
pub unsafe fn completePathIntoString_caseSensitive_matchesIntoArray_filterTypes(
&self,
outputName: *mut *mut NSString,
outputName: Option<&mut Option<Id<NSString, Shared>>>,
flag: bool,
outputArray: *mut *mut NSArray<NSString>,
outputArray: Option<&mut Option<Id<NSArray<NSString>, Shared>>>,
filterTypes: Option<&NSArray<NSString>>,
) -> NSUInteger {
msg_send![
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ impl NSPersonNameComponentsFormatter {
}
pub unsafe fn getObjectValue_forString_errorDescription(
&self,
obj: *mut *mut Object,
obj: Option<&mut Option<Id<Object, Shared>>>,
string: &NSString,
error: *mut *mut NSString,
error: Option<&mut Option<Id<NSString, Shared>>>,
) -> bool {
msg_send![
self,
Expand Down
Loading

0 comments on commit ec53e8d

Please sign in to comment.