Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions lib/objc/DNObjectiveCContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ class DNArgumentContext extends DNContext {
this.type = type
this.anonDef = null //user for block arguement
this.isNullable = false
this.isOutParam = false
}
}

Expand Down Expand Up @@ -236,13 +237,14 @@ class DNMethodContext extends DNContext {
}

var newImpl = 'Pointer<Void> result = ' + impl.replace(');\n','') + ' ,decodeRetVal: false);\n'

if(this.retValIsObj){
var supportType = DNObjectiveCTypeConverter.DNDartToOCMap[rawRetType]
if(supportType) {
newImpl += ' return ' + supportType + '.fromPointer(result).raw;\n'
} else if (isMutableRetType) {
newImpl += ' return ' + rawRetType + '.fromPointer(result).raw;\n'
} else {
newImpl += ' return ' + rawRetType + '.fromPointer(result);\n'
}
}
return newImpl
Expand Down Expand Up @@ -276,15 +278,17 @@ class DNMethodContext extends DNContext {
if(element.isNullable){
nullableArgs.push(element)
}else{
var arg = element.anonDef ? element.anonDef : this.convertMutableTypeIfNeed(element.type) + ' ' + element.name
var argType = element.isOutParam ? 'NSObjectRef<' + element.type + '>' : element.type
var arg = element.anonDef ? element.anonDef : this.convertMutableTypeIfNeed(argType) + ' ' + element.name
argList += arg + (index == this.args.length - 1 && nullableArgs.length == 0 ? '' : ', ')
}
})

if(nullableArgs.length > 0){
argList += '{'
nullableArgs.forEach((element, index) => {
var arg = element.anonDef ? element.anonDef : this.convertMutableTypeIfNeed(element.type) + ' ' + element.name
var argType = element.isOutParam ? 'NSObjectRef<' + element.type + '>' : element.type
var arg = element.anonDef ? element.anonDef : this.convertMutableTypeIfNeed(argType) + ' ' + element.name
argList += arg + (index == nullableArgs.length - 1 ? '' : ', ')
})
argList += '}'
Expand Down
26 changes: 26 additions & 0 deletions lib/objc/DNObjectiveCParserListener.js
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,32 @@ class DNObjectiveCParserListener extends ObjectiveCParserListener {
this.currentContext.retValIsObj = ctx.stop.text == '*'
} else if (this.currentContext instanceof DNArgumentContext) {
this.currentContext.type = TC.convert(ctx.start.text,true)

// check if it's a out parameter
if(ctx.start.text == 'out'){
//case:(out NsError **) error
this.currentContext.isOutParam = true
this.currentContext.type = TC.convert(ctx.children[0].stop.text,true) //correct arg type
} else if(ctx.children.length > 1){
var childOne = ctx.children[1]
//case:(NsError ** )error
var isP2P = childOne.start.text == '*' && childOne.stop.text == '*' && childOne.start.stop != childOne.stop.stop
if(!isP2P){
//case:(NsError ** _Nullable) error
var subChild = childOne.children[0]
if(subChild instanceof ObjectiveCParser.PointerContext){
for(var i = 0 ; i < subChild.children.length; i++){
if(subChild.children[i] instanceof ObjectiveCParser.PointerContext){
isP2P = true
break
}
}
}
}
this.currentContext.isOutParam = isP2P
}

// check if it's a nullable parameter
if(ctx.start.text == 'nullable'){
this.currentContext.isNullable = true
this.currentContext.type = TC.convert(ctx.children[0].stop.text,true) //correct arg type
Expand Down
1 change: 1 addition & 0 deletions test/objc/RuntimeStub.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ typedef NS_OPTIONS(NSUInteger, UIViewAutoresizing) {
- (NSMutableSet<NSString *> *)fooMutable:(BOOL)a bar:(NSMutableArray<NSMutableArray *> *)b c:(NSMutableArray *)c;
- (void)fooEnum:(RuntimeStubEnum)aEnum;
- (void)foolNullable:(nullable NSString *)a b:(int _Nullable)b c:(NSString * __nullable)c d:(int)d;
- (void)fooWithError:(out NSError **)error;
@end

@interface RuntimeStub(Foo)
Expand Down