Skip to content

Commit

Permalink
Expressions: Fix @Locals not properly handling compound insns.
Browse files Browse the repository at this point in the history
Also adapt to related MixinExtras changes.
  • Loading branch information
LlamaLad7 committed Jul 4, 2024
1 parent aa7241f commit f51d82f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ dependencies {
implementation(files(Jvm.current().toolsJar))

// TODO: temporary waiting for a release
fun mixinExtras(variant: String) = "com.github.LlamaLad7.MixinExtras:mixinextras-$variant:371c39e"
fun mixinExtras(variant: String) = "com.github.LlamaLad7.MixinExtras:mixinextras-$variant:2ad48e8"

implementation(mixinExtras("expressions"))
testLibs(mixinExtras("common"))
Expand Down
22 changes: 12 additions & 10 deletions src/main/kotlin/platform/mixin/expression/MEExpressionMatchUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import com.llamalad7.mixinextras.expression.impl.flow.FlowValue
import com.llamalad7.mixinextras.expression.impl.flow.expansion.InsnExpander
import com.llamalad7.mixinextras.expression.impl.point.ExpressionContext
import com.llamalad7.mixinextras.expression.impl.pool.IdentifierPool
import com.llamalad7.mixinextras.expression.impl.pool.MemberDefinition
import com.llamalad7.mixinextras.expression.impl.pool.SimpleMemberDefinition
import org.objectweb.asm.Handle
import org.objectweb.asm.Opcodes
import org.objectweb.asm.Type
Expand Down Expand Up @@ -171,17 +171,17 @@ object MEExpressionMatchUtil {
val fields = annotation.findDeclaredAttributeValue("field")?.computeStringArray() ?: emptyList()
for (field in fields) {
val fieldRef = MemberReference.parse(field) ?: continue
pool.addMember(definitionId) {
pool.addMember(definitionId, SimpleMemberDefinition {
it is FieldInsnNode && fieldRef.matchField(it.owner, it.name, it.desc)
}
})
}

val methods = annotation.findDeclaredAttributeValue("method")?.computeStringArray() ?: emptyList()
for (method in methods) {
val methodRef = MemberReference.parse(method) ?: continue
pool.addMember(
definitionId,
object : MemberDefinition {
object : SimpleMemberDefinition {
override fun matches(insn: AbstractInsnNode) =
insn is MethodInsnNode && methodRef.matchMethod(insn.owner, insn.name, insn.desc)

Expand All @@ -202,20 +202,22 @@ object MEExpressionMatchUtil {
for (localAnnotation in locals) {
val localType = localAnnotation.findDeclaredAttributeValue("type")?.resolveType()
val localInfo = LocalInfo.fromAnnotation(localType, localAnnotation)
pool.addMember(definitionId) { insn ->
if (insn !is VarInsnNode) {
pool.addMember(definitionId) { node ->
val virtualInsn = node.insn
if (virtualInsn !is VarInsnNode) {
return@addMember false
}
val actualInsn = if (insn.opcode >= Opcodes.ISTORE && insn.opcode <= Opcodes.ASTORE) {
insn.next ?: return@addMember false
val physicalInsn = InsnExpander.getRepresentative(node)
val actualInsn = if (virtualInsn.opcode >= Opcodes.ISTORE && virtualInsn.opcode <= Opcodes.ASTORE) {
physicalInsn.next ?: return@addMember false
} else {
insn
physicalInsn
}

val unfilteredLocals = localInfo.getLocals(module, targetClass, targetMethod, actualInsn)
?: return@addMember false
val filteredLocals = localInfo.matchLocals(unfilteredLocals, CollectVisitor.Mode.MATCH_ALL)
filteredLocals.any { it.index == insn.`var` }
filteredLocals.any { it.index == virtualInsn.`var` }
}
}
}
Expand Down

0 comments on commit f51d82f

Please sign in to comment.