use of org.objectweb.asm.tree.LocalVariableNode in project evosuite by EvoSuite.
the class ImplicitElseTransformer method isDefinedBefore.
@SuppressWarnings("unchecked")
private boolean isDefinedBefore(MethodNode mn, VarInsnNode var, AbstractInsnNode position) {
// TODO: Iterate over local variables and check if local is defined here
List<LocalVariableNode> localVar = mn.localVariables;
if (localVar.isEmpty()) {
// If we have no debug information, try to guess
AbstractInsnNode pos = position.getPrevious();
while (pos != mn.instructions.getFirst()) {
if (pos instanceof VarInsnNode) {
VarInsnNode vn = (VarInsnNode) pos;
if (var.var == vn.var) {
return true;
}
}
pos = pos.getPrevious();
}
} else {
int current = mn.instructions.indexOf(position);
for (LocalVariableNode local : localVar) {
if (local.index == var.var) {
int start = mn.instructions.indexOf(local.start);
int end = mn.instructions.indexOf(local.end);
if (current >= start && current <= end)
return true;
}
}
}
return false;
}
use of org.objectweb.asm.tree.LocalVariableNode in project evosuite by EvoSuite.
the class ReplaceVariable method getLocalReplacements.
private Map<String, InsnList> getLocalReplacements(MethodNode mn, String desc, AbstractInsnNode node, Frame frame) {
Map<String, InsnList> replacements = new HashMap<String, InsnList>();
// if (desc.equals("I"))
// return replacements;
int otherNum = -1;
if (node instanceof VarInsnNode) {
VarInsnNode vNode = (VarInsnNode) node;
otherNum = vNode.var;
}
if (otherNum == -1)
return replacements;
int currentId = mn.instructions.indexOf(node);
logger.info("Looking for replacements at position " + currentId + " of variable " + otherNum + " of type " + desc);
for (Object v : mn.localVariables) {
LocalVariableNode localVar = (LocalVariableNode) v;
int startId = mn.instructions.indexOf(localVar.start);
int endId = mn.instructions.indexOf(localVar.end);
logger.info("Checking local variable " + localVar.name + " of type " + localVar.desc + " at index " + localVar.index);
if (!localVar.desc.equals(desc))
logger.info("- Types do not match");
if (localVar.index == otherNum)
logger.info("- Replacement = original");
if (currentId < startId)
logger.info("- Out of scope (start)");
if (currentId > endId)
logger.info("- Out of scope (end)");
BasicValue newValue = (BasicValue) frame.getLocal(localVar.index);
if (newValue == BasicValue.UNINITIALIZED_VALUE)
logger.info("- Not initialized");
if (localVar.desc.equals(desc) && localVar.index != otherNum && currentId >= startId && currentId <= endId && newValue != BasicValue.UNINITIALIZED_VALUE) {
logger.info("Adding local variable " + localVar.name + " of type " + localVar.desc + " at index " + localVar.index + ", " + startId + "-" + endId + ", " + currentId);
InsnList list = new InsnList();
if (node.getOpcode() == Opcodes.GETFIELD) {
// Remove field owner from stack
list.add(new InsnNode(Opcodes.POP));
}
list.add(new VarInsnNode(getLoadOpcode(localVar), localVar.index));
replacements.put(localVar.name, list);
}
}
return replacements;
}
use of org.objectweb.asm.tree.LocalVariableNode in project evosuite by EvoSuite.
the class ReplaceVariable method getName.
private String getName(MethodNode mn, AbstractInsnNode node) throws VariableNotFoundException {
if (node instanceof VarInsnNode) {
LocalVariableNode var = getLocal(mn, node, ((VarInsnNode) node).var);
return var.name;
} else if (node instanceof FieldInsnNode) {
return ((FieldInsnNode) node).name;
} else if (node instanceof IincInsnNode) {
IincInsnNode incNode = (IincInsnNode) node;
LocalVariableNode var = getLocal(mn, node, incNode.var);
return var.name;
} else {
throw new RuntimeException("Unknown variable node: " + node);
}
}
use of org.objectweb.asm.tree.LocalVariableNode in project evosuite by EvoSuite.
the class ReplaceVariable method getLocalReplacementsInc.
private Map<String, InsnList> getLocalReplacementsInc(MethodNode mn, String desc, IincInsnNode node, Frame frame) {
Map<String, InsnList> replacements = new HashMap<String, InsnList>();
int otherNum = -1;
otherNum = node.var;
int currentId = mn.instructions.indexOf(node);
for (Object v : mn.localVariables) {
LocalVariableNode localVar = (LocalVariableNode) v;
int startId = mn.instructions.indexOf(localVar.start);
int endId = mn.instructions.indexOf(localVar.end);
logger.info("Checking local variable " + localVar.name + " of type " + localVar.desc + " at index " + localVar.index);
if (!localVar.desc.equals(desc))
logger.info("- Types do not match: " + localVar.name);
if (localVar.index == otherNum)
logger.info("- Replacement = original " + localVar.name);
if (currentId < startId)
logger.info("- Out of scope (start) " + localVar.name);
if (currentId > endId)
logger.info("- Out of scope (end) " + localVar.name);
BasicValue newValue = (BasicValue) frame.getLocal(localVar.index);
if (newValue == BasicValue.UNINITIALIZED_VALUE)
logger.info("- Not initialized");
if (localVar.desc.equals(desc) && localVar.index != otherNum && currentId >= startId && currentId <= endId && newValue != BasicValue.UNINITIALIZED_VALUE) {
logger.info("Adding local variable " + localVar.name + " of type " + localVar.desc + " at index " + localVar.index);
InsnList list = new InsnList();
list.add(new IincInsnNode(localVar.index, node.incr));
replacements.put(localVar.name, list);
}
}
return replacements;
}
use of org.objectweb.asm.tree.LocalVariableNode in project Random-Things by lumien231.
the class ClassTransformer method getNextIndex.
public int getNextIndex(MethodNode mn) {
Iterator it = mn.localVariables.iterator();
int max = 0;
int next = 0;
while (it.hasNext()) {
LocalVariableNode var = (LocalVariableNode) it.next();
int index = var.index;
if (index >= max) {
max = index;
next = max + Type.getType(var.desc).getSize();
}
}
return next;
}
Aggregations