mirror of
https://github.com/LegacyModdingMC/UniMix.git
synced 2026-11-19 17:39:46 +00:00
Make ModifyVariable print option work more intuitively, closes #209
This commit is contained in:
1 parent
67a764c0ef
commit
164e471dcd
7 files changed
+40
-22
No files matched your search
@@ -208,7 +208,7 @@ public abstract class Injector {
|
||||
* Use the supplied InjectionPoints to find target insns in the target
|
||||
* method
|
||||
*
|
||||
* @param target.method Target method
|
||||
* @param injectorTarget Target method
|
||||
* @param injectionPoints List of injection points parsed from At
|
||||
* annotations on the callback method
|
||||
* @return Target insn nodes in the target method
|
||||
|
||||
@@ -51,7 +51,7 @@ public final class MethodSlice {
|
||||
|
||||
/**
|
||||
* A read-only wrapper for an {@link InsnList} which only allows the segment
|
||||
* identified by {@link #start} and {@link end} to be accessed. In essence
|
||||
* identified by {@link #start} and {@link #end} to be accessed. In essence
|
||||
* this class provides a <em>view</em> of the underlying InsnList.
|
||||
*/
|
||||
static final class InsnListSlice extends ReadOnlyInsnList {
|
||||
|
||||
@@ -80,6 +80,11 @@ public class BeforeLoadLocal extends ContextualInjectionPoint {
|
||||
*/
|
||||
static class SearchState {
|
||||
|
||||
/**
|
||||
* Print LVT search, be permissive
|
||||
*/
|
||||
private final boolean print;
|
||||
|
||||
/**
|
||||
* The target ordinal from the injection point
|
||||
*/
|
||||
@@ -106,8 +111,9 @@ public class BeforeLoadLocal extends ContextualInjectionPoint {
|
||||
*/
|
||||
private VarInsnNode varNode;
|
||||
|
||||
SearchState(int targetOrdinal) {
|
||||
SearchState(int targetOrdinal, boolean print) {
|
||||
this.targetOrdinal = targetOrdinal;
|
||||
this.print = print;
|
||||
}
|
||||
|
||||
boolean success() {
|
||||
@@ -128,7 +134,7 @@ public class BeforeLoadLocal extends ContextualInjectionPoint {
|
||||
|
||||
void check(Collection<AbstractInsnNode> nodes, AbstractInsnNode insn, int local) {
|
||||
this.pendingCheck = false;
|
||||
if (local != this.varNode.var) {
|
||||
if (local != this.varNode.var && (local > -2 || !this.print)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -186,7 +192,7 @@ public class BeforeLoadLocal extends ContextualInjectionPoint {
|
||||
|
||||
@Override
|
||||
boolean find(Target target, Collection<AbstractInsnNode> nodes) {
|
||||
SearchState state = new SearchState(this.ordinal);
|
||||
SearchState state = new SearchState(this.ordinal, this.discriminator.printLVT());
|
||||
|
||||
ListIterator<AbstractInsnNode> iter = target.method.instructions.iterator();
|
||||
while (iter.hasNext()) {
|
||||
|
||||
+19
-4
@@ -209,18 +209,25 @@ public class LocalVariableDiscriminator {
|
||||
* single local by type
|
||||
*/
|
||||
private final Set<String> names;
|
||||
|
||||
/**
|
||||
* True to request print of the LVT
|
||||
*/
|
||||
private final boolean print;
|
||||
|
||||
/**
|
||||
* @param argsOnly true to only search within the method arguments
|
||||
* @param ordinal target variable ordinal
|
||||
* @param index target variable index
|
||||
* @param names target variable names
|
||||
* @param print true to print lvt
|
||||
*/
|
||||
public LocalVariableDiscriminator(boolean argsOnly, int ordinal, int index, Set<String> names) {
|
||||
public LocalVariableDiscriminator(boolean argsOnly, int ordinal, int index, Set<String> names, boolean print) {
|
||||
this.argsOnly = argsOnly;
|
||||
this.ordinal = ordinal;
|
||||
this.index = index;
|
||||
this.names = Collections.<String>unmodifiableSet(names);
|
||||
this.print = print;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -258,7 +265,14 @@ public class LocalVariableDiscriminator {
|
||||
public boolean hasNames() {
|
||||
return !this.names.isEmpty();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* True if the injector should print the LVT
|
||||
*/
|
||||
public boolean printLVT() {
|
||||
return this.print;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the user specifies no values for <tt>ordinal</tt>, <tt>index</tt> or
|
||||
* <tt>names</tt> then we are considered to be operating in "implicit mode"
|
||||
@@ -285,7 +299,7 @@ public class LocalVariableDiscriminator {
|
||||
try {
|
||||
return this.findLocal(new Context(returnType, argsOnly, target, node));
|
||||
} catch (InvalidImplicitDiscriminatorException ex) {
|
||||
return -1;
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -372,6 +386,7 @@ public class LocalVariableDiscriminator {
|
||||
boolean argsOnly = Annotations.<Boolean>getValue(annotation, "argsOnly", Boolean.FALSE).booleanValue();
|
||||
int ordinal = Annotations.<Integer>getValue(annotation, "ordinal", -1);
|
||||
int index = Annotations.<Integer>getValue(annotation, "index", -1);
|
||||
boolean print = Annotations.<Boolean>getValue(annotation, "print", Boolean.FALSE).booleanValue();
|
||||
|
||||
Set<String> names = new HashSet<String>();
|
||||
List<String> namesList = Annotations.<List<String>>getValue(annotation, "name", (List<String>)null);
|
||||
@@ -379,7 +394,7 @@ public class LocalVariableDiscriminator {
|
||||
names.addAll(namesList);
|
||||
}
|
||||
|
||||
return new LocalVariableDiscriminator(argsOnly, ordinal, index, names);
|
||||
return new LocalVariableDiscriminator(argsOnly, ordinal, index, names, print);
|
||||
}
|
||||
|
||||
}
|
||||
+6
-9
@@ -88,11 +88,6 @@ public class ModifyVariableInjector extends Injector {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Print LVT
|
||||
*/
|
||||
private final boolean print;
|
||||
|
||||
/**
|
||||
* True to consider only method args
|
||||
*/
|
||||
@@ -100,12 +95,10 @@ public class ModifyVariableInjector extends Injector {
|
||||
|
||||
/**
|
||||
* @param info Injection info
|
||||
* @param print True to print this injector's discovered LVT
|
||||
* @param discriminator discriminator
|
||||
*/
|
||||
public ModifyVariableInjector(InjectionInfo info, boolean print, LocalVariableDiscriminator discriminator) {
|
||||
public ModifyVariableInjector(InjectionInfo info, LocalVariableDiscriminator discriminator) {
|
||||
super(info);
|
||||
this.print = print;
|
||||
this.discriminator = discriminator;
|
||||
}
|
||||
|
||||
@@ -152,7 +145,7 @@ public class ModifyVariableInjector extends Injector {
|
||||
|
||||
Context context = new Context(this.returnType, this.discriminator.isArgsOnly(), target, node.getCurrentTarget());
|
||||
|
||||
if (this.print) {
|
||||
if (this.discriminator.printLVT()) {
|
||||
this.printLocals(context);
|
||||
}
|
||||
|
||||
@@ -162,6 +155,10 @@ public class ModifyVariableInjector extends Injector {
|
||||
this.inject(context, local);
|
||||
}
|
||||
} catch (InvalidImplicitDiscriminatorException ex) {
|
||||
if (this.discriminator.printLVT()) {
|
||||
this.info.addCallbackInvocation(this.methodNode);
|
||||
return;
|
||||
}
|
||||
throw new InvalidInjectionException(this.info, "Implicit variable modifier injection failed in " + this, ex);
|
||||
}
|
||||
|
||||
|
||||
+1
-3
@@ -31,7 +31,6 @@ import org.spongepowered.asm.mixin.injection.code.Injector;
|
||||
import org.spongepowered.asm.mixin.injection.modify.LocalVariableDiscriminator;
|
||||
import org.spongepowered.asm.mixin.injection.modify.ModifyVariableInjector;
|
||||
import org.spongepowered.asm.mixin.transformer.MixinTargetContext;
|
||||
import org.spongepowered.asm.util.Annotations;
|
||||
|
||||
/**
|
||||
* Information about a {@link ModifyVariable} injector
|
||||
@@ -44,8 +43,7 @@ public class ModifyVariableInjectionInfo extends InjectionInfo {
|
||||
|
||||
@Override
|
||||
protected Injector parseInjector(AnnotationNode injectAnnotation) {
|
||||
boolean print = Annotations.<Boolean>getValue(injectAnnotation, "print", Boolean.FALSE).booleanValue();
|
||||
return new ModifyVariableInjector(this, print, LocalVariableDiscriminator.parse(injectAnnotation));
|
||||
return new ModifyVariableInjector(this, LocalVariableDiscriminator.parse(injectAnnotation));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -206,7 +206,9 @@ public final class Locals {
|
||||
} else if (insn instanceof VarInsnNode) {
|
||||
VarInsnNode varNode = (VarInsnNode) insn;
|
||||
frame[varNode.var] = Locals.getLocalVariableAt(classNode, method, node, varNode.var);
|
||||
} else if (insn == node) {
|
||||
}
|
||||
|
||||
if (insn == node) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user