Groovy AST INSTRUCTION_SELECTION фаза против SEMANTIC_ANALYSIS - PullRequest
0 голосов
/ 21 декабря 2018

Этот фрагмент кода работает у моего посетителя на этапе SEMANTIC_ANALYSIS, но не на этапе INSTRUCTION_SELECTION.Похоже, я не могу использовать вызов конструктора.Если я вместо этого изменю конструктор на Arrays.asList (), он, похоже, скомпилируется.Любая помощь приветствуется

val codeBlock = GeneralUtils.block()

// Declare the futures list
val arrayListNode = ClassHelper.make(ArrayList::class.java)
val variable = "myVariable"
val variableDeclaration = GeneralUtils.varX(variable, arrayListNode)
val asListExpression = GeneralUtils.ctorX(arrayListNode)
val variableStmt = GeneralUtils.declS(variableDeclaration, asListExpression)
codeBlock.addStatement(variableStmt)

//
// Set the codeBlock back to the closure
closure.code = codeBlock

На этапе выбора инструкций я получаю ошибку

java.lang.ArrayIndexOutOfBoundsException: size==0
at org.codehaus.groovy.classgen.asm.OperandStack.getTopOperand(OperandStack.java:672)
at org.codehaus.groovy.classgen.asm.BinaryExpressionHelper.evaluateEqual(BinaryExpressionHelper.java:318)
at org.codehaus.groovy.classgen.asm.sc.StaticTypesBinaryExpressionMultiTypeDispatcher.evaluateEqual(StaticTypesBinaryExpressionMultiTypeDispatcher.java:142)
at org.codehaus.groovy.classgen.AsmClassGenerator.visitDeclarationExpression(AsmClassGenerator.java:637)
at org.codehaus.groovy.ast.expr.DeclarationExpression.visit(DeclarationExpression.java:89)

1 Ответ

0 голосов
/ 26 декабря 2018

Казалось, этот код работает.

// Declare the futures list
val arrayListNode = ClassHelper.make(ArrayList::class.java)
val variable = "myVariable"
val variableDeclaration = GeneralUtils.varX(variable, arrayListNode)
val asListExpression = GeneralUtils.ctorX(arrayListNode)

// Look for the arraylist constructor in the node
val arrayNodeConstructorMethod = arrayListNode.getDeclaredConstructor(arrayOf())
asListExpression.setNodeMetaData(StaticTypesMarker.DIRECT_METHOD_CALL_TARGET, arrayNodeConstructorMethod)

val variableStmt = GeneralUtils.declS(variableDeclaration, asListExpression)
codeBlock.addStatement(variableStmt)

//
// Set the codeBlock back to the closure
closure.code = codeBlock
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...