mirror of
https://github.com/GTNewHorizons/ForgeMultipart.git
synced 2026-11-19 19:59:40 +00:00
refactor: port ASM super lookup to Java
This commit is contained in:
1 parent
c0df2e0229
commit
fa008b80bb
4 files changed
+80
-29
No files matched your search
@@ -435,25 +435,7 @@ object ASMMixinCompiler {
|
||||
def getSuper(
|
||||
minsn: MethodInsnNode,
|
||||
stack: StackAnalyser
|
||||
): Option[MethodInfo] = {
|
||||
import StackAnalyser._
|
||||
|
||||
if (minsn.owner == stack.owner.getInternalName)
|
||||
return None // not a super call
|
||||
|
||||
// super calls are either to methods with the same name or contain a pattern 'target$$super$name' from the scala compiler
|
||||
val methodName = stack.m.name.replaceAll(".+\\Q$$super$\\E", "")
|
||||
if (minsn.name != methodName)
|
||||
return None
|
||||
|
||||
stack.peek(Type.getType(minsn.desc).getArgumentTypes.length) match {
|
||||
case Load(This(o)) =>
|
||||
case _ => return None // have to be invoked on this
|
||||
}
|
||||
|
||||
getClassInfo(stack.owner.getInternalName).superClass
|
||||
.flatMap(_.findPublicImpl(methodName, minsn.desc))
|
||||
}
|
||||
): Option[MethodInfo] = ClassInfoLookup.getSuper(minsn, stack)
|
||||
|
||||
def getAndRegisterParentTraits(cnode: ClassNode) =
|
||||
cnode.interfaces.map(getClassInfo).collect {
|
||||
|
||||
@@ -3,13 +3,18 @@ package codechicken.multipart.asm;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.objectweb.asm.Type;
|
||||
import org.objectweb.asm.tree.AnnotationNode;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
import org.objectweb.asm.tree.MethodInsnNode;
|
||||
import org.objectweb.asm.tree.MethodNode;
|
||||
|
||||
import codechicken.multipart.asm.ASMMixinCompiler.ClassInfo;
|
||||
import codechicken.multipart.asm.ASMMixinCompiler.ClassInfo$;
|
||||
import codechicken.multipart.asm.ASMMixinCompiler.MethodInfo;
|
||||
import codechicken.multipart.asm.StackAnalyser.Load;
|
||||
import codechicken.multipart.asm.StackAnalyser.StackEntry;
|
||||
import codechicken.multipart.asm.StackAnalyser.This;
|
||||
import scala.Array$;
|
||||
import scala.Function1;
|
||||
import scala.Function3;
|
||||
@@ -173,4 +178,24 @@ final class ClassInfoLookup {
|
||||
private static <R, E extends Throwable> R throwUnchecked(Throwable throwable) throws E {
|
||||
throw (E) throwable;
|
||||
}
|
||||
|
||||
static Option<MethodInfo> getSuper(final MethodInsnNode call, StackAnalyser stack) {
|
||||
if (Objects.equals(call.owner, stack.owner().getInternalName())) return Option.empty();
|
||||
|
||||
final String methodName = stack.m().name.replaceAll(".+\\Q$$super$\\E", "");
|
||||
if (!Objects.equals(call.name, methodName)) return Option.empty();
|
||||
|
||||
// Preserve the compiler's argument-count indexing, including its behavior for wide stack values.
|
||||
StackEntry receiver = stack.peek(Type.getType(call.desc).getArgumentTypes().length);
|
||||
if (!(receiver instanceof Load) || !(((Load) receiver).e() instanceof This)) return Option.empty();
|
||||
|
||||
return ASMMixinCompiler$.MODULE$.getClassInfo(stack.owner().getInternalName()).superClass()
|
||||
.flatMap(new AbstractFunction1<ClassInfo, Option<MethodInfo>>() {
|
||||
|
||||
@Override
|
||||
public Option<MethodInfo> apply(ClassInfo parent) {
|
||||
return parent.findPublicImpl(methodName, call.desc);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user