Skip to content

Commit

Permalink
Add annotation export in methodNodebuilder #185 (#191)
Browse files Browse the repository at this point in the history
* Add annotation export in methodNodebuilder #185

* fix tests
  • Loading branch information
lehvolk authored Oct 18, 2023
1 parent 7bfd3c4 commit a3767c8
Showing 1 changed file with 31 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,20 @@ class MethodNodeBuilder(
mn.maxLocals = localIndex
mn.maxStack = maxStack + 1
//At this moment, we're just copying annotations from original method without any modifications
// with(method.asmNode()) {
// mn.visibleAnnotations = visibleAnnotations
// mn.visibleTypeAnnotations = visibleTypeAnnotations
// mn.visibleLocalVariableAnnotations = visibleLocalVariableAnnotations
// mn.visibleParameterAnnotations = visibleParameterAnnotations
// mn.invisibleAnnotations = invisibleAnnotations
// mn.invisibleTypeAnnotations = invisibleTypeAnnotations
// mn.invisibleLocalVariableAnnotations = invisibleLocalVariableAnnotations
// mn.invisibleParameterAnnotations = invisibleParameterAnnotations
// }
with(method.asmNode()) {
mn.visibleAnnotations = visibleAnnotations
mn.visibleTypeAnnotations = visibleTypeAnnotations
mn.visibleParameterAnnotations = visibleParameterAnnotations
mn.invisibleAnnotations = invisibleAnnotations
mn.invisibleTypeAnnotations = invisibleTypeAnnotations
mn.invisibleParameterAnnotations = invisibleParameterAnnotations

// this two line of code relies on labels in method body properly organized.

// mn.visibleLocalVariableAnnotations = visibleLocalVariableAnnotations
// mn.invisibleLocalVariableAnnotations = invisibleLocalVariableAnnotations

}
return mn
}

Expand Down Expand Up @@ -265,16 +269,27 @@ class MethodNodeBuilder(
var shouldReverse = false
val (zeroValue, zeroCmpOpcode, defaultOpcode) = when (cond) {
is JcRawEqExpr -> when {
cond.lhv.typeName == PredefinedPrimitives.Null.typeName() -> Triple(JcRawNull(), Opcodes.IFNULL, Opcodes.IF_ACMPEQ)
cond.lhv.typeName == PredefinedPrimitives.Null.typeName() -> Triple(
JcRawNull(),
Opcodes.IFNULL,
Opcodes.IF_ACMPEQ
)

cond.lhv.typeName.isPrimitive -> Triple(JcRawInt(0), Opcodes.IFEQ, Opcodes.IF_ICMPEQ)
else -> Triple(JcRawNull(), Opcodes.IFNULL, Opcodes.IF_ACMPEQ)
}

is JcRawNeqExpr -> when {
cond.lhv.typeName == PredefinedPrimitives.Null.typeName() -> Triple(JcRawNull(), Opcodes.IFNONNULL, Opcodes.IF_ACMPNE)
cond.lhv.typeName == PredefinedPrimitives.Null.typeName() -> Triple(
JcRawNull(),
Opcodes.IFNONNULL,
Opcodes.IF_ACMPNE
)

cond.lhv.typeName.isPrimitive -> Triple(JcRawInt(0), Opcodes.IFNE, Opcodes.IF_ICMPNE)
else -> Triple(JcRawNull(), Opcodes.IFNONNULL, Opcodes.IF_ACMPNE)
}

is JcRawGeExpr -> Triple(JcRawInt(0), Opcodes.IFGE, Opcodes.IF_ICMPGE)
is JcRawGtExpr -> Triple(JcRawInt(0), Opcodes.IFGT, Opcodes.IF_ICMPGT)
is JcRawLeExpr -> Triple(JcRawInt(0), Opcodes.IFLE, Opcodes.IF_ICMPLE)
Expand All @@ -295,10 +310,12 @@ class MethodNodeBuilder(
}
JumpInsnNode(invertedZeroCmpOpcode, trueTarget)
}

cond.rhv == zeroValue -> {
cond.lhv.accept(this)
JumpInsnNode(zeroCmpOpcode, trueTarget)
}

else -> {
cond.lhv.accept(this)
cond.rhv.accept(this)
Expand Down Expand Up @@ -571,7 +588,7 @@ class MethodNodeBuilder(
declaringClass.jvmClassName,
name,
if (argTypes.isEmpty() && tag <= H_GETSTATIC) {
returnType.jvmTypeName
returnType.jvmTypeName
} else {
"(${argTypes.joinToString("") { it.jvmTypeName }})${returnType.jvmTypeName}"
},
Expand Down Expand Up @@ -819,6 +836,7 @@ class MethodNodeBuilder(
}
nodesBetweenLabels.clear()
}

else -> nodesBetweenLabels.add(curInst)
}
++i
Expand Down

0 comments on commit a3767c8

Please sign in to comment.