Commit 3082cf7e authored by Eric Bruneton's avatar Eric Bruneton
Browse files

Merge branch 'rename-var-to-varindex' into 'master'

Rename 'var' to 'varIndex' where possible. See...

See merge request !340
parents 99c8d491 ddd8bb14
......@@ -252,17 +252,17 @@ public class Analyzer<V extends Value> implements Opcodes {
} else if (insnOpcode != ATHROW && (insnOpcode < IRETURN || insnOpcode > RETURN)) {
if (subroutine != null) {
if (insnNode instanceof VarInsnNode) {
int var = ((VarInsnNode) insnNode).var;
subroutine.localsUsed[var] = true;
int varIndex = ((VarInsnNode) insnNode).var;
subroutine.localsUsed[varIndex] = true;
if (insnOpcode == LLOAD
|| insnOpcode == DLOAD
|| insnOpcode == LSTORE
|| insnOpcode == DSTORE) {
subroutine.localsUsed[var + 1] = true;
subroutine.localsUsed[varIndex + 1] = true;
}
} else if (insnNode instanceof IincInsnNode) {
int var = ((IincInsnNode) insnNode).var;
subroutine.localsUsed[var] = true;
int varIndex = ((IincInsnNode) insnNode).var;
subroutine.localsUsed[varIndex] = true;
}
}
merge(insnIndex + 1, currentFrame, subroutine);
......
......@@ -293,7 +293,7 @@ public class Frame<V extends Value> {
V value2;
V value3;
V value4;
int var;
int varIndex;
switch (insn.getOpcode()) {
case Opcodes.NOP:
......@@ -331,15 +331,15 @@ public class Frame<V extends Value> {
case Opcodes.DSTORE:
case Opcodes.ASTORE:
value1 = interpreter.copyOperation(insn, pop());
var = ((VarInsnNode) insn).var;
setLocal(var, value1);
varIndex = ((VarInsnNode) insn).var;
setLocal(varIndex, value1);
if (value1.getSize() == 2) {
setLocal(var + 1, interpreter.newEmptyValue(var + 1));
setLocal(varIndex + 1, interpreter.newEmptyValue(varIndex + 1));
}
if (var > 0) {
Value local = getLocal(var - 1);
if (varIndex > 0) {
Value local = getLocal(varIndex - 1);
if (local != null && local.getSize() == 2) {
setLocal(var - 1, interpreter.newEmptyValue(var - 1));
setLocal(varIndex - 1, interpreter.newEmptyValue(varIndex - 1));
}
}
break;
......@@ -527,8 +527,8 @@ public class Frame<V extends Value> {
push(interpreter.unaryOperation(insn, pop()));
break;
case Opcodes.IINC:
var = ((IincInsnNode) insn).var;
setLocal(var, interpreter.unaryOperation(insn, getLocal(var)));
varIndex = ((IincInsnNode) insn).var;
setLocal(varIndex, interpreter.unaryOperation(insn, getLocal(varIndex)));
break;
case Opcodes.I2L:
case Opcodes.I2F:
......
......@@ -108,28 +108,28 @@ final class MethodNodeBuilder {
return this;
}
MethodNodeBuilder istore(final int var) {
methodNode.visitVarInsn(Opcodes.ISTORE, var);
MethodNodeBuilder istore(final int varIndex) {
methodNode.visitVarInsn(Opcodes.ISTORE, varIndex);
return this;
}
MethodNodeBuilder aload(final int var) {
methodNode.visitVarInsn(Opcodes.ALOAD, var);
MethodNodeBuilder aload(final int varIndex) {
methodNode.visitVarInsn(Opcodes.ALOAD, varIndex);
return this;
}
MethodNodeBuilder iload(final int var) {
methodNode.visitVarInsn(Opcodes.ILOAD, var);
MethodNodeBuilder iload(final int varIndex) {
methodNode.visitVarInsn(Opcodes.ILOAD, varIndex);
return this;
}
MethodNodeBuilder astore(final int var) {
methodNode.visitVarInsn(Opcodes.ASTORE, var);
MethodNodeBuilder astore(final int varIndex) {
methodNode.visitVarInsn(Opcodes.ASTORE, varIndex);
return this;
}
MethodNodeBuilder ret(final int var) {
methodNode.visitVarInsn(Opcodes.RET, var);
MethodNodeBuilder ret(final int varIndex) {
methodNode.visitVarInsn(Opcodes.RET, varIndex);
return this;
}
......@@ -158,8 +158,8 @@ final class MethodNodeBuilder {
return this;
}
MethodNodeBuilder iinc(final int var, final int increment) {
methodNode.visitIincInsn(var, increment);
MethodNodeBuilder iinc(final int varIndex, final int increment) {
methodNode.visitIincInsn(varIndex, increment);
return this;
}
......
......@@ -327,8 +327,8 @@ public abstract class AdviceAdapter extends GeneratorAdapter implements Opcodes
}
@Override
public void visitVarInsn(final int opcode, final int var) {
super.visitVarInsn(opcode, var);
public void visitVarInsn(final int opcode, final int varIndex) {
super.visitVarInsn(opcode, varIndex);
if (isConstructor && !superClassConstructorCalled) {
switch (opcode) {
case ILOAD:
......@@ -341,7 +341,7 @@ public abstract class AdviceAdapter extends GeneratorAdapter implements Opcodes
pushValue(OTHER);
break;
case ALOAD:
pushValue(var == 0 ? UNINITIALIZED_THIS : OTHER);
pushValue(varIndex == 0 ? UNINITIALIZED_THIS : OTHER);
break;
case ASTORE:
case ISTORE:
......
......@@ -242,15 +242,15 @@ public class AnalyzerAdapter extends MethodVisitor {
}
@Override
public void visitVarInsn(final int opcode, final int var) {
super.visitVarInsn(opcode, var);
public void visitVarInsn(final int opcode, final int varIndex) {
super.visitVarInsn(opcode, varIndex);
boolean isLongOrDouble =
opcode == Opcodes.LLOAD
|| opcode == Opcodes.DLOAD
|| opcode == Opcodes.LSTORE
|| opcode == Opcodes.DSTORE;
maxLocals = Math.max(maxLocals, var + (isLongOrDouble ? 2 : 1));
execute(opcode, var, null);
maxLocals = Math.max(maxLocals, varIndex + (isLongOrDouble ? 2 : 1));
execute(opcode, varIndex, null);
}
@Override
......@@ -398,10 +398,10 @@ public class AnalyzerAdapter extends MethodVisitor {
}
@Override
public void visitIincInsn(final int var, final int increment) {
super.visitIincInsn(var, increment);
maxLocals = Math.max(maxLocals, var + 1);
execute(Opcodes.IINC, var, null);
public void visitIincInsn(final int varIndex, final int increment) {
super.visitIincInsn(varIndex, increment);
maxLocals = Math.max(maxLocals, varIndex + 1);
execute(Opcodes.IINC, varIndex, null);
}
@Override
......
......@@ -82,18 +82,18 @@ public class CodeSizeEvaluator extends MethodVisitor implements Opcodes {
}
@Override
public void visitVarInsn(final int opcode, final int var) {
if (var < 4 && opcode != RET) {
public void visitVarInsn(final int opcode, final int varIndex) {
if (varIndex < 4 && opcode != RET) {
minSize += 1;
maxSize += 1;
} else if (var >= 256) {
} else if (varIndex >= 256) {
minSize += 4;
maxSize += 4;
} else {
minSize += 2;
maxSize += 2;
}
super.visitVarInsn(opcode, var);
super.visitVarInsn(opcode, varIndex);
}
@Override
......@@ -172,15 +172,15 @@ public class CodeSizeEvaluator extends MethodVisitor implements Opcodes {
}
@Override
public void visitIincInsn(final int var, final int increment) {
if (var > 255 || increment > 127 || increment < -128) {
public void visitIincInsn(final int varIndex, final int increment) {
if (varIndex > 255 || increment > 127 || increment < -128) {
minSize += 6;
maxSize += 6;
} else {
minSize += 3;
maxSize += 3;
}
super.visitIincInsn(var, increment);
super.visitIincInsn(varIndex, increment);
}
@Override
......
......@@ -424,40 +424,40 @@ public class InstructionAdapter extends MethodVisitor {
}
@Override
public void visitVarInsn(final int opcode, final int var) {
public void visitVarInsn(final int opcode, final int varIndex) {
switch (opcode) {
case Opcodes.ILOAD:
load(var, Type.INT_TYPE);
load(varIndex, Type.INT_TYPE);
break;
case Opcodes.LLOAD:
load(var, Type.LONG_TYPE);
load(varIndex, Type.LONG_TYPE);
break;
case Opcodes.FLOAD:
load(var, Type.FLOAT_TYPE);
load(varIndex, Type.FLOAT_TYPE);
break;
case Opcodes.DLOAD:
load(var, Type.DOUBLE_TYPE);
load(varIndex, Type.DOUBLE_TYPE);
break;
case Opcodes.ALOAD:
load(var, OBJECT_TYPE);
load(varIndex, OBJECT_TYPE);
break;
case Opcodes.ISTORE:
store(var, Type.INT_TYPE);
store(varIndex, Type.INT_TYPE);
break;
case Opcodes.LSTORE:
store(var, Type.LONG_TYPE);
store(varIndex, Type.LONG_TYPE);
break;
case Opcodes.FSTORE:
store(var, Type.FLOAT_TYPE);
store(varIndex, Type.FLOAT_TYPE);
break;
case Opcodes.DSTORE:
store(var, Type.DOUBLE_TYPE);
store(varIndex, Type.DOUBLE_TYPE);
break;
case Opcodes.ASTORE:
store(var, OBJECT_TYPE);
store(varIndex, OBJECT_TYPE);
break;
case Opcodes.RET:
ret(var);
ret(varIndex);
break;
default:
throw new IllegalArgumentException();
......@@ -654,8 +654,8 @@ public class InstructionAdapter extends MethodVisitor {
}
@Override
public void visitIincInsn(final int var, final int increment) {
iinc(var, increment);
public void visitIincInsn(final int varIndex, final int increment) {
iinc(varIndex, increment);
}
@Override
......@@ -784,16 +784,16 @@ public class InstructionAdapter extends MethodVisitor {
mv.visitLdcInsn(constantDynamic);
}
public void load(final int var, final Type type) {
mv.visitVarInsn(type.getOpcode(Opcodes.ILOAD), var);
public void load(final int varIndex, final Type type) {
mv.visitVarInsn(type.getOpcode(Opcodes.ILOAD), varIndex);
}
public void aload(final Type type) {
mv.visitInsn(type.getOpcode(Opcodes.IALOAD));
}
public void store(final int var, final Type type) {
mv.visitVarInsn(type.getOpcode(Opcodes.ISTORE), var);
public void store(final int varIndex, final Type type) {
mv.visitVarInsn(type.getOpcode(Opcodes.ISTORE), varIndex);
}
public void astore(final Type type) {
......@@ -884,8 +884,8 @@ public class InstructionAdapter extends MethodVisitor {
mv.visitInsn(type.getOpcode(Opcodes.IXOR));
}
public void iinc(final int var, final int increment) {
mv.visitIincInsn(var, increment);
public void iinc(final int varIndex, final int increment) {
mv.visitIincInsn(varIndex, increment);
}
/**
......@@ -1028,8 +1028,8 @@ public class InstructionAdapter extends MethodVisitor {
mv.visitJumpInsn(Opcodes.JSR, label);
}
public void ret(final int var) {
mv.visitVarInsn(Opcodes.RET, var);
public void ret(final int varIndex) {
mv.visitVarInsn(Opcodes.RET, varIndex);
}
public void tableswitch(final int min, final int max, final Label dflt, final Label... labels) {
......
......@@ -107,7 +107,7 @@ public class LocalVariablesSorter extends MethodVisitor {
}
@Override
public void visitVarInsn(final int opcode, final int var) {
public void visitVarInsn(final int opcode, final int varIndex) {
Type varType;
switch (opcode) {
case Opcodes.LLOAD:
......@@ -134,12 +134,12 @@ public class LocalVariablesSorter extends MethodVisitor {
default:
throw new IllegalArgumentException("Invalid opcode " + opcode);
}
super.visitVarInsn(opcode, remap(var, varType));
super.visitVarInsn(opcode, remap(varIndex, varType));
}
@Override
public void visitIincInsn(final int var, final int increment) {
super.visitIincInsn(remap(var, Type.INT_TYPE), increment);
public void visitIincInsn(final int varIndex, final int increment) {
super.visitIincInsn(remap(varIndex, Type.INT_TYPE), increment);
}
@Override
......@@ -321,11 +321,11 @@ public class LocalVariablesSorter extends MethodVisitor {
remappedLocalTypes[local] = type;
}
private int remap(final int var, final Type type) {
if (var + type.getSize() <= firstLocal) {
return var;
private int remap(final int varIndex, final Type type) {
if (varIndex + type.getSize() <= firstLocal) {
return varIndex;
}
int key = 2 * var + type.getSize() - 1;
int key = 2 * varIndex + type.getSize() - 1;
int size = remappedVariableIndices.length;
if (key >= size) {
int[] newRemappedVariableIndices = new int[Math.max(2 * size, key + 1)];
......
......@@ -243,9 +243,9 @@ class AnalyzerAdapterTest extends AsmTest {
}
@Override
public void visitVarInsn(final int opcode, final int var) {
public void visitVarInsn(final int opcode, final int varIndex) {
maybeInsertFrame();
super.visitVarInsn(opcode, var);
super.visitVarInsn(opcode, varIndex);
}
@Override
......@@ -296,9 +296,9 @@ class AnalyzerAdapterTest extends AsmTest {
}
@Override
public void visitIincInsn(final int var, final int increment) {
public void visitIincInsn(final int varIndex, final int increment) {
maybeInsertFrame();
super.visitIincInsn(var, increment);
super.visitIincInsn(varIndex, increment);
}
@Override
......
......@@ -113,28 +113,28 @@ final class MethodNodeBuilder {
return this;
}
MethodNodeBuilder istore(final int var) {
methodNode.visitVarInsn(Opcodes.ISTORE, var);
MethodNodeBuilder istore(final int varIndex) {
methodNode.visitVarInsn(Opcodes.ISTORE, varIndex);
return this;
}
MethodNodeBuilder aload(final int var) {
methodNode.visitVarInsn(Opcodes.ALOAD, var);
MethodNodeBuilder aload(final int varIndex) {
methodNode.visitVarInsn(Opcodes.ALOAD, varIndex);
return this;
}
MethodNodeBuilder iload(final int var) {
methodNode.visitVarInsn(Opcodes.ILOAD, var);
MethodNodeBuilder iload(final int varIndex) {
methodNode.visitVarInsn(Opcodes.ILOAD, varIndex);
return this;
}
MethodNodeBuilder astore(final int var) {
methodNode.visitVarInsn(Opcodes.ASTORE, var);
MethodNodeBuilder astore(final int varIndex) {
methodNode.visitVarInsn(Opcodes.ASTORE, varIndex);
return this;
}
MethodNodeBuilder ret(final int var) {
methodNode.visitVarInsn(Opcodes.RET, var);
MethodNodeBuilder ret(final int varIndex) {
methodNode.visitVarInsn(Opcodes.RET, varIndex);
return this;
}
......@@ -163,8 +163,8 @@ final class MethodNodeBuilder {
return this;
}
MethodNodeBuilder iinc(final int var, final int increment) {
methodNode.visitIincInsn(var, increment);
MethodNodeBuilder iinc(final int varIndex, final int increment) {
methodNode.visitIincInsn(varIndex, increment);
return this;
}
......
......@@ -47,12 +47,12 @@ public class IincInsnNode extends AbstractInsnNode {
/**
* Constructs a new {@link IincInsnNode}.
*
* @param var index of the local variable to be incremented.
* @param varIndex index of the local variable to be incremented.
* @param incr increment amount to increment the local variable by.
*/
public IincInsnNode(final int var, final int incr) {
public IincInsnNode(final int varIndex, final int incr) {
super(Opcodes.IINC);
this.var = var;
this.var = varIndex;
this.incr = incr;
}
......
......@@ -347,8 +347,8 @@ public class MethodNode extends MethodVisitor {
}
@Override
public void visitVarInsn(final int opcode, final int var) {
instructions.add(new VarInsnNode(opcode, var));
public void visitVarInsn(final int opcode, final int varIndex) {
instructions.add(new VarInsnNode(opcode, varIndex));
}
@Override
......@@ -406,8 +406,8 @@ public class MethodNode extends MethodVisitor {
}
@Override
public void visitIincInsn(final int var, final int increment) {
instructions.add(new IincInsnNode(var, increment));
public void visitIincInsn(final int varIndex, final int increment) {
instructions.add(new IincInsnNode(varIndex, increment));
}
@Override
......
......@@ -46,12 +46,12 @@ public class VarInsnNode extends AbstractInsnNode {
*
* @param opcode the opcode of the local variable instruction to be constructed. This opcode must
* be ILOAD, LLOAD, FLOAD, DLOAD, ALOAD, ISTORE, LSTORE, FSTORE, DSTORE, ASTORE or RET.
* @param var the operand of the instruction to be constructed. This operand is the index of a
* local variable.
* @param varIndex the operand of the instruction to be constructed. This operand is the index of
* a local variable.
*/
public VarInsnNode(final int opcode, final int var) {
public VarInsnNode(final int opcode, final int varIndex) {
super(opcode);
this.var = var;
this.var = varIndex;
}
/**
......
......@@ -823,14 +823,14 @@ public class ASMifier extends Printer {
}
@Override
public void visitVarInsn(final int opcode, final int var) {
public void visitVarInsn(final int opcode, final int varIndex) {
stringBuilder.setLength(0);
stringBuilder
.append(name)
.append(".visitVarInsn(")
.append(OPCODES[opcode])
.append(", ")
.append(var)
.append(varIndex)
.append(");\n");
text.add(stringBuilder.toString());
}
......@@ -936,12 +936,12 @@ public class ASMifier extends Printer {
}
@Override
public void visitIincInsn(final int var, final int increment) {
public void visitIincInsn(final int varIndex, final int increment) {
stringBuilder.setLength(0);
stringBuilder
.append(name)
.append(".visitIincInsn(")
.append(var)
.append(varIndex)
.append(", ")
.append(increment)
.append(");\n");
......
......@@ -679,12 +679,12 @@ public class CheckMethodAdapter extends MethodVisitor {
}
@Override
public void visitVarInsn(final int opcode, final int var) {
public void visitVarInsn(final int opcode, final int varIndex) {
checkVisitCodeCalled();
checkVisitMaxsNotCalled();
checkOpcodeMethod(opcode, Method.VISIT_VAR_INSN);
checkUnsignedShort(var, INVALID_LOCAL_VARIABLE_INDEX);
super.visitVarInsn(opcode, var);
checkUnsignedShort(varIndex, INVALID_LOCAL_VARIABLE_INDEX);
super.visitVarInsn(opcode, varIndex);
++insnCount;
}
......@@ -804,12 +804,12 @@ public class CheckMethodAdapter extends MethodVisitor {
}
@Override
public void visitIincInsn(final int var, final int increment) {
public void visitIincInsn(final int varIndex, final int increment) {
checkVisitCodeCalled();
checkVisitMaxsNotCalled();
checkUnsignedShort(var, INVALID_LOCAL_VARIABLE_INDEX);
checkUnsignedShort(varIndex, INVALID_LOCAL_VARIABLE_INDEX);
checkSignedShort(increment, "Invalid increment");
super.visitIincInsn(var, increment);
super.visitIincInsn(varIndex, increment);
++insnCount;
}
......
......@@ -917,10 +917,10 @@ public abstract class Printer {
*
* @param opcode the opcode of the local variable instruction to be visited. This opcode is either
* ILOAD, LLOAD, FLOAD, DLOAD, ALOAD, ISTORE, LSTORE, FSTORE, DSTORE, ASTORE or RET.
* @param var the operand of the instruction to be visited. This operand is the index of a local
* variable.
* @param varIndex the operand of the instruction to be visited. This operand is the index of a
* local variable.