use of org.objectweb.asm.tree.LdcInsnNode in project enumerable by hraberg.
the class ExpressionInterpreter method newOperation.
public Value newOperation(final AbstractInsnNode insn) throws AnalyzerException {
switch(insn.getOpcode()) {
case ACONST_NULL:
return new ExpressionValue(createClassOrInterfaceType(Object.class.getName()), new NullLiteralExpr());
case ICONST_M1:
return new ExpressionValue(PRIMITIVE_INT, new UnaryExpr(new IntegerLiteralExpr("1"), UnaryExpr.Operator.negative));
case ICONST_0:
return new ExpressionValue(PRIMITIVE_INT, new IntegerLiteralExpr("0"));
case ICONST_1:
return new ExpressionValue(PRIMITIVE_INT, new IntegerLiteralExpr("1"));
case ICONST_2:
return new ExpressionValue(PRIMITIVE_INT, new IntegerLiteralExpr("2"));
case ICONST_3:
return new ExpressionValue(PRIMITIVE_INT, new IntegerLiteralExpr("3"));
case ICONST_4:
return new ExpressionValue(PRIMITIVE_INT, new IntegerLiteralExpr("4"));
case ICONST_5:
return new ExpressionValue(PRIMITIVE_INT, new IntegerLiteralExpr("5"));
case LCONST_0:
return new ExpressionValue(PRIMITIVE_LONG, new LongLiteralExpr("0L"));
case LCONST_1:
return new ExpressionValue(PRIMITIVE_LONG, new LongLiteralExpr("1L"));
case FCONST_0:
return new ExpressionValue(PRIMITIVE_FLOAT, new DoubleLiteralExpr("0.0f"));
case FCONST_1:
return new ExpressionValue(PRIMITIVE_FLOAT, new DoubleLiteralExpr("1.0f"));
case FCONST_2:
return new ExpressionValue(PRIMITIVE_FLOAT, new DoubleLiteralExpr("2.0f"));
case DCONST_0:
return new ExpressionValue(PRIMITIVE_DOUBLE, new DoubleLiteralExpr("0.0"));
case DCONST_1:
return new ExpressionValue(PRIMITIVE_DOUBLE, new DoubleLiteralExpr("1.0"));
case BIPUSH:
case SIPUSH:
int operand = ((IntInsnNode) insn).operand;
if (operand < 0)
return new ExpressionValue(PRIMITIVE_INT, new UnaryExpr(new IntegerLiteralExpr("" + Math.abs(operand)), UnaryExpr.Operator.negative));
return new ExpressionValue(PRIMITIVE_INT, new IntegerLiteralExpr("" + operand));
case LDC:
Object cst = ((LdcInsnNode) insn).cst;
if (cst instanceof Number) {
ExpressionValue value = null;
if (cst instanceof Integer) {
value = new ExpressionValue(PRIMITIVE_INT, new IntegerLiteralExpr(cst.toString()));
} else if (cst instanceof Float) {
value = new ExpressionValue(PRIMITIVE_FLOAT, new DoubleLiteralExpr(cst.toString() + "f"));
} else if (cst instanceof Long) {
value = new ExpressionValue(PRIMITIVE_LONG, new LongLiteralExpr(cst.toString() + "L"));
} else if (cst instanceof Double) {
value = new ExpressionValue(PRIMITIVE_DOUBLE, new DoubleLiteralExpr(cst.toString()));
}
if (((Number) cst).intValue() < 0) {
StringLiteralExpr expr = (StringLiteralExpr) value.expression;
expr.setValue(expr.getValue().substring("-".length()));
value.expression = new UnaryExpr(expr, UnaryExpr.Operator.negative);
}
return value;
} else if (cst instanceof Type) {
ClassExpr classExpr = new ClassExpr(new ReferenceType(createClassOrInterfaceType(((Type) cst).getClassName())));
return new ExpressionValue(createClassOrInterfaceType(Class.class.getName()), classExpr);
} else {
return new ExpressionValue(createClassOrInterfaceType(String.class.getName()), new StringLiteralExpr(cst.toString()));
}
case JSR:
throw new UnsupportedOperationException(AbstractVisitor.OPCODES[insn.getOpcode()]);
case GETSTATIC:
FieldInsnNode fieldNode = (FieldInsnNode) insn;
ExpressionValue getField = (ExpressionValue) newValue(getType(fieldNode.desc));
getField.expression = new FieldAccessExpr(new NameExpr(removeJavaLang(getObjectType(fieldNode.owner).getClassName())), fieldNode.name);
return getField;
case NEW:
return newValue(Type.getObjectType(((TypeInsnNode) insn).desc));
default:
throw new Error("Internal error.");
}
}
use of org.objectweb.asm.tree.LdcInsnNode in project bytecode-viewer by Konloch.
the class NumberNode method setNumber.
public void setNumber(int number) {
AbstractInsnNode ain = insn();
if (ain instanceof IntInsnNode) {
((IntInsnNode) insn()).operand = number;
((IntInsnNode) ain).operand = number;
} else if (ain instanceof LdcInsnNode) {
((LdcInsnNode) insn()).cst = number;
((LdcInsnNode) ain).cst = number;
}
}
use of org.objectweb.asm.tree.LdcInsnNode in project evosuite by EvoSuite.
the class Mutation method getDefaultInfectionDistance.
/**
* <p>
* getDefaultInfectionDistance
* </p>
*
* @return a {@link org.objectweb.asm.tree.InsnList} object.
*/
public static InsnList getDefaultInfectionDistance() {
InsnList defaultDistance = new InsnList();
defaultDistance.add(new LdcInsnNode(0.0));
return defaultDistance;
}
use of org.objectweb.asm.tree.LdcInsnNode in project evosuite by EvoSuite.
the class BooleanTestabilityTransformation method insertPushNull.
/**
* Insert a call to the isNull helper function
*
* @param opcode
* @param position
* @param list
*/
public void insertPushNull(int opcode, JumpInsnNode position, InsnList list) {
int branchId = getBranchID(currentMethodNode, position);
logger.info("Inserting instrumentation for NULL check at branch " + branchId + " in method " + currentMethodNode.name);
MethodInsnNode nullCheck = new MethodInsnNode(Opcodes.INVOKESTATIC, Type.getInternalName(BooleanHelper.class), "isNull", Type.getMethodDescriptor(Type.INT_TYPE, new Type[] { Type.getType(Object.class), Type.INT_TYPE }), false);
list.insertBefore(position, new InsnNode(Opcodes.DUP));
list.insertBefore(position, new LdcInsnNode(opcode));
list.insertBefore(position, nullCheck);
// list.insertBefore(position,
// new LdcInsnNode(getBranchID(currentMethodNode, position)));
insertBranchIdPlaceholder(currentMethodNode, position, branchId);
MethodInsnNode push = new MethodInsnNode(Opcodes.INVOKESTATIC, Type.getInternalName(BooleanHelper.class), "pushPredicate", Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] { Type.INT_TYPE, Type.INT_TYPE }), false);
list.insertBefore(position, push);
}
use of org.objectweb.asm.tree.LdcInsnNode in project evosuite by EvoSuite.
the class BooleanTestabilityTransformation method insertControlDependencyPlaceholder.
private void insertControlDependencyPlaceholder(MethodNode mn, AbstractInsnNode insnNode) {
Label label = new Label();
LabelNode labelNode = new LabelNode(label);
// BooleanTestabilityPlaceholderTransformer.addControlDependencyPlaceholder(label,
// insnNode);
mn.instructions.insertBefore(insnNode, labelNode);
// instructions.insertBefore(insnNode, new LdcInsnNode(0));
// mn.instructions.insertBefore(insnNode, new LdcInsnNode(0));
mn.instructions.insertBefore(insnNode, new LdcInsnNode(getControlDependentBranchID(mn, insnNode)));
mn.instructions.insertBefore(insnNode, new LdcInsnNode(getApproximationLevel(mn, insnNode)));
logger.info("Control dependent branch id: " + getControlDependentBranchID(mn, insnNode));
logger.info("Approximation level: " + getApproximationLevel(mn, insnNode));
}
Aggregations