Skip to content

Commit cde58b9

Browse files
committed
fix: "+ (void)test:(int (^)(NSString *a))t;"
1 parent f42008e commit cde58b9

File tree

2 files changed

+24
-19
lines changed

2 files changed

+24
-19
lines changed

lib/objc/DNObjectiveCContext.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ class DNArgumentContext extends DNContext {
157157
if (internal.name && internal.types) {
158158
this.name = internal.name.start.text
159159
}
160-
this.type = null
160+
this.type = ''
161161
this.isBlock = false //user for block arguement
162162
this.isNullable = false
163163
this.isOutParam = false

lib/objc/DNObjectiveCParserListener.js

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -327,10 +327,26 @@ class DNObjectiveCParserListener extends ObjectiveCParserListener {
327327
enterBlockType(ctx) {
328328
if (this.currentContext instanceof DNMethodContext) {
329329
this.currentContext.returnType = 'Block'
330+
} else if (this.currentContext instanceof DNArgumentContext) {
331+
this.currentContext.isBlock = true
332+
this.currentContext.blockRetType = null
333+
this.currentContext.blockArgTypes = []
334+
this.currentContext.blockArgNames = []
330335
}
331336
}
332337
// Exit a parse tree produced by ObjectiveCParser#blockType.
333338
exitBlockType(ctx) {
339+
if (this.currentContext instanceof DNArgumentContext) {
340+
var blockArgs = ''
341+
this.currentContext.blockArgTypes.forEach((argType, index) => {
342+
var argName = this.currentContext.blockArgNames[index]
343+
if (argName && argType) {
344+
blockArgs += argType + ' ' + argName + ', '
345+
}
346+
})
347+
blockArgs = '(' + blockArgs.substring(0, blockArgs.length - 2) + ')' // remove ', ' symbol
348+
this.currentContext.type += this.currentContext.blockRetType + ' ' + this.currentContext.name + blockArgs
349+
}
334350
}
335351
// Enter a parse tree produced by ObjectiveCParser#genericsSpecifier.
336352
enterGenericsSpecifier(ctx) {
@@ -377,25 +393,9 @@ class DNObjectiveCParserListener extends ObjectiveCParserListener {
377393
}
378394
// Enter a parse tree produced by ObjectiveCParser#blockParameters.
379395
enterBlockParameters(ctx) {
380-
if (this.currentContext instanceof DNArgumentContext) {
381-
this.currentContext.isBlock = true
382-
this.currentContext.blockArgTypes = []
383-
this.currentContext.blockArgNames = []
384-
}
385396
}
386397
// Exit a parse tree produced by ObjectiveCParser#blockParameters.
387398
exitBlockParameters(ctx) {
388-
if (this.currentContext instanceof DNArgumentContext) {
389-
var blockArgs = ''
390-
this.currentContext.blockArgTypes.forEach((argType, index) => {
391-
var argName = this.currentContext.blockArgNames[index]
392-
if (argName && argType) {
393-
blockArgs += argType + ' ' + argName + ', '
394-
}
395-
})
396-
blockArgs = '(' + blockArgs.substring(0, blockArgs.length - 2) + ')' // remove ', ' symbol
397-
this.currentContext.type += ' ' + this.currentContext.name + blockArgs
398-
}
399399
}
400400
// Enter a parse tree produced by ObjectiveCParser#typeVariableDeclaratorOrName.
401401
enterTypeVariableDeclaratorOrName(ctx) {
@@ -754,8 +754,13 @@ class DNObjectiveCParserListener extends ObjectiveCParserListener {
754754
if (!this.currentContext.isBlock) {
755755
let isArgInBlock = this.currentContext.parent instanceof DNBlockDefContext
756756
this.currentContext.type = TC.convert(type, isArgInBlock)
757-
}else {
758-
this.currentContext.blockArgTypes.push(type)
757+
} else {
758+
let convertedType = TC.convert(type, true)
759+
if (!this.currentContext.blockRetType) {
760+
this.currentContext.blockRetType = convertedType
761+
} else {
762+
this.currentContext.blockArgTypes.push(convertedType)
763+
}
759764
}
760765
// case:(NSError ** )error
761766
this.currentContext.isOutParam = isPointer2Pointer

0 commit comments

Comments
 (0)