Add getFieldInitializer to ExtendedRemapper

My rough plan for combining static scrambling and remapping is to split
Library::remap into three passes:

* Remove static methods, fields and initializers from the library,
  storing them in a temporary location.
* Pass all classes through ClassNodeRemapper, as we do now.
* Add static methods, fields and initializers to their new classes,
  remapping as we do so.

This ensures a ClassNode is never in a state where it has a mixture of
remapped and non-remapped fields, methods or instructions. This is
important to ensure no conflicts can occur when we use the refactored
names from the NameMap, rather than the auto-generated names.

It means TypedRemapper needs the ability to provide the instructions
that make up a field's initializer, such that Library::remap can move
these instructions to a different InsnList. The new getFieldInitializer
method and FieldInitializer type support this.

Signed-off-by: Graham <gpe@openrs2.dev>
Graham 5 years ago
parent 1a41982b76
commit a3ec4ec322
  1. 4
      asm/src/main/java/dev/openrs2/asm/classpath/ExtendedRemapper.kt
  2. 14
      asm/src/main/java/dev/openrs2/asm/classpath/FieldInitializer.kt

@ -3,6 +3,10 @@ package dev.openrs2.asm.classpath
import org.objectweb.asm.commons.Remapper
abstract class ExtendedRemapper : Remapper() {
open fun getFieldInitializer(owner: String, name: String, descriptor: String): FieldInitializer? {
return null
}
open fun mapFieldOwner(owner: String, name: String, descriptor: String): String {
return mapType(owner)
}

@ -0,0 +1,14 @@
package dev.openrs2.asm.classpath
import dev.openrs2.asm.MemberRef
import org.objectweb.asm.Opcodes
import org.objectweb.asm.tree.AbstractInsnNode
import org.objectweb.asm.tree.FieldInsnNode
class FieldInitializer(val instructions: List<AbstractInsnNode>, val version: Int, val maxStack: Int) {
val dependencies = instructions.asSequence()
.filterIsInstance<FieldInsnNode>()
.filter { it.opcode == Opcodes.GETSTATIC }
.map(::MemberRef)
.toSet()
}
Loading…
Cancel
Save