use of org.objectweb.asm.tree.AbstractInsnNode in project evosuite by EvoSuite.
the class InsertUnaryOperator method isApplicable.
/* (non-Javadoc)
* @see org.evosuite.cfg.instrumentation.mutation.MutationOperator#isApplicable(org.evosuite.cfg.BytecodeInstruction)
*/
/**
* {@inheritDoc}
*/
@Override
public boolean isApplicable(BytecodeInstruction instruction) {
AbstractInsnNode node = instruction.getASMNode();
switch(node.getOpcode()) {
case Opcodes.ILOAD:
case Opcodes.LLOAD:
case Opcodes.FLOAD:
case Opcodes.DLOAD:
return true;
case Opcodes.GETFIELD:
case Opcodes.GETSTATIC:
FieldInsnNode fieldNode = (FieldInsnNode) instruction.getASMNode();
Type type = Type.getType(fieldNode.desc);
if (type == Type.BYTE_TYPE || type == Type.SHORT_TYPE || type == Type.LONG_TYPE || type == Type.FLOAT_TYPE || type == Type.DOUBLE_TYPE || type == Type.BOOLEAN_TYPE || type == Type.INT_TYPE) {
return true;
}
default:
return false;
}
}
use of org.objectweb.asm.tree.AbstractInsnNode in project evosuite by EvoSuite.
the class BytecodeInstructionPool method createFakeInstruction.
/**
* <p>
* createFakeInstruction
* </p>
*
* @param className
* a {@link java.lang.String} object.
* @param methodName
* a {@link java.lang.String} object.
* @return a {@link org.evosuite.graphs.cfg.BytecodeInstruction} object.
*/
public BytecodeInstruction createFakeInstruction(String className, String methodName) {
AbstractInsnNode fakeNode = new InsnNode(Opcodes.NOP);
int instructionId = getInstructionsIn(className, methodName).size();
BytecodeInstruction instruction = new BytecodeInstruction(classLoader, className, methodName, instructionId, -1, fakeNode);
registerInstruction(instruction);
return instruction;
}
use of org.objectweb.asm.tree.AbstractInsnNode in project evosuite by EvoSuite.
the class BytecodeInstructionPool method registerMethodNode.
// fill the pool
/**
* Called by each CFGGenerator for it's corresponding method.
*
* The MethodNode contains all instructions within a method. A call to
* registerMethodNode() fills the instructionMap of the
* BytecodeInstructionPool with the instructions in that method and returns
* a List containing the BytecodeInstructions within that method.
*
* While registering all instructions the lineNumber of each
* BytecodeInstruction is set.
*
* @param node
* a {@link org.objectweb.asm.tree.MethodNode} object.
* @param className
* a {@link java.lang.String} object.
* @param methodName
* a {@link java.lang.String} object.
* @return a {@link java.util.List} object.
*/
public List<BytecodeInstruction> registerMethodNode(MethodNode node, String className, String methodName) {
registerMethodNode(node);
int lastLineNumber = -1;
int bytecodeOffset = 0;
for (int instructionId = 0; instructionId < node.instructions.size(); instructionId++) {
AbstractInsnNode instructionNode = node.instructions.get(instructionId);
BytecodeInstruction instruction = BytecodeInstructionFactory.createBytecodeInstruction(classLoader, className, methodName, instructionId, bytecodeOffset, instructionNode);
if (instruction.isLineNumber())
lastLineNumber = instruction.getLineNumber();
else if (lastLineNumber != -1)
instruction.setLineNumber(lastLineNumber);
bytecodeOffset += getBytecodeIncrement(instructionNode);
if (!instruction.isLabel() && !instruction.isLineNumber() && !instruction.isFrame()) {
bytecodeOffset++;
}
registerInstruction(instruction);
}
List<BytecodeInstruction> r = getInstructionsIn(className, methodName);
if (r == null || r.size() == 0)
throw new IllegalStateException("expect instruction pool to return non-null non-empty list of instructions for a previously registered method " + methodName);
return r;
}
use of org.objectweb.asm.tree.AbstractInsnNode in project evosuite by EvoSuite.
the class NodeRegularExpression method matches.
/**
* <p>matches</p>
*
* @param instructions a {@link org.objectweb.asm.tree.InsnList} object.
* @return a boolean.
*/
public boolean matches(InsnList instructions) {
int match = 0;
AbstractInsnNode node = instructions.getFirst();
while (node != instructions.getLast()) {
if (node.getType() == AbstractInsnNode.FRAME || node.getType() == AbstractInsnNode.LABEL || node.getType() == AbstractInsnNode.LINE) {
node = node.getNext();
continue;
} else {
boolean found = false;
for (int opcode : pattern[match]) {
if (node.getOpcode() == opcode) {
match++;
found = true;
break;
}
}
if (!found)
match = 0;
}
if (match == pattern.length)
return true;
node = node.getNext();
}
return false;
}
use of org.objectweb.asm.tree.AbstractInsnNode in project evosuite by EvoSuite.
the class NodeRegularExpression method getNextMatch.
/**
* <p>getNextMatch</p>
*
* @param start a {@link org.objectweb.asm.tree.AbstractInsnNode} object.
* @param instructions a {@link org.objectweb.asm.tree.InsnList} object.
* @return a {@link org.objectweb.asm.tree.AbstractInsnNode} object.
*/
public AbstractInsnNode getNextMatch(AbstractInsnNode start, InsnList instructions) {
int match = 0;
AbstractInsnNode node = start;
AbstractInsnNode startNode = start;
while (node != instructions.getLast()) {
if (node.getType() == AbstractInsnNode.FRAME || node.getType() == AbstractInsnNode.LABEL || node.getType() == AbstractInsnNode.LINE) {
node = node.getNext();
continue;
} else {
boolean found = false;
for (int opcode : pattern[match]) {
if (node.getOpcode() == opcode) {
if (match == 0)
startNode = node;
match++;
found = true;
break;
}
}
if (!found)
match = 0;
}
if (match == pattern.length) {
return startNode;
}
node = node.getNext();
}
return null;
}
Aggregations