use of org.evosuite.symbolic.expr.ref.ReferenceExpression in project evosuite by EvoSuite.
the class SymbolicObserver method readInstanceField.
private ReferenceExpressionPair readInstanceField(VariableReference source, Field field, Scope scope) {
String owner = field.getDeclaringClass().getName().replace('.', '/');
String name = field.getName();
Class<?> fieldClazz = field.getType();
String source_name = source.getName();
ReferenceConstant symb_receiver = (ReferenceConstant) symb_references.get(source_name);
try {
Object conc_receiver = source.getObject(scope);
if (fieldClazz.equals(int.class)) {
int conc_value = field.getInt(conc_receiver);
IntegerValue expr = env.heap.getField(owner, name, conc_receiver, symb_receiver, conc_value);
ReferenceConstant newIntegerRef = newIntegerReference(conc_value, expr);
return new ReferenceExpressionPair(newIntegerRef, expr);
} else if (fieldClazz.equals(char.class)) {
char conc_value = field.getChar(conc_receiver);
IntegerValue expr = env.heap.getField(owner, name, conc_receiver, symb_receiver, conc_value);
ReferenceConstant newCharacterRef = newCharacterReference(conc_value, expr);
return new ReferenceExpressionPair(newCharacterRef, expr);
} else if (fieldClazz.equals(long.class)) {
long conc_value = field.getLong(conc_receiver);
IntegerValue expr = env.heap.getField(owner, name, conc_receiver, symb_receiver, conc_value);
ReferenceConstant newLongRef = newLongReference(conc_value, expr);
return new ReferenceExpressionPair(newLongRef, expr);
} else if (fieldClazz.equals(short.class)) {
short conc_value = field.getShort(conc_receiver);
IntegerValue expr = env.heap.getField(owner, name, conc_receiver, symb_receiver, conc_value);
ReferenceConstant newShortRef = newShortReference(conc_value, expr);
return new ReferenceExpressionPair(newShortRef, expr);
} else if (fieldClazz.equals(byte.class)) {
byte conc_value = field.getByte(conc_receiver);
IntegerValue expr = env.heap.getField(owner, name, conc_receiver, symb_receiver, conc_value);
ReferenceConstant newByteRef = newByteReference(conc_value, expr);
return new ReferenceExpressionPair(newByteRef, expr);
} else if (fieldClazz.equals(boolean.class)) {
boolean conc_value = field.getBoolean(conc_receiver);
IntegerValue expr = env.heap.getField(owner, name, conc_receiver, symb_receiver, conc_value ? 1 : 0);
ReferenceConstant newBooleanRef = newBooleanReference(conc_value, expr);
return new ReferenceExpressionPair(newBooleanRef, expr);
} else if (fieldClazz.equals(float.class)) {
float conc_value = field.getFloat(conc_receiver);
RealValue expr = env.heap.getField(owner, name, conc_receiver, symb_receiver, conc_value);
ReferenceConstant newFloatRef = newFloatReference(conc_value, expr);
return new ReferenceExpressionPair(newFloatRef, expr);
} else if (fieldClazz.equals(double.class)) {
double conc_value = field.getDouble(conc_receiver);
RealValue expr = env.heap.getField(owner, name, conc_receiver, symb_receiver, conc_value);
ReferenceConstant newDoubleRef = newDoubleReference(conc_value, expr);
return new ReferenceExpressionPair(newDoubleRef, expr);
} else {
Object conc_value = field.get(conc_receiver);
if (conc_value instanceof String) {
String string = (String) conc_value;
StringValue expr = env.heap.getField(owner, name, conc_receiver, symb_receiver, string);
ReferenceConstant newStringRef = newStringReference(string, expr);
return new ReferenceExpressionPair(newStringRef, expr);
} else {
ReferenceExpression ref = env.heap.getReference(conc_value);
if (conc_value != null && isWrapper(conc_value)) {
ReferenceConstant nonNullRef = (ReferenceConstant) ref;
Expression<?> expr = findOrCreate(conc_value, nonNullRef);
return new ReferenceExpressionPair(ref, expr);
} else {
return new ReferenceExpressionPair(ref, null);
}
}
}
} catch (IllegalArgumentException e) {
throw new RuntimeException(e);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
} catch (CodeUnderTestException e) {
throw new RuntimeException(e);
}
}
use of org.evosuite.symbolic.expr.ref.ReferenceExpression in project evosuite by EvoSuite.
the class SymbolicObserver method before.
private void before(MethodStatement statement, Scope scope) {
Method method = statement.getMethod().getMethod();
String owner = method.getDeclaringClass().getName().replace('.', '/');
String name = method.getName();
String desc = Type.getMethodDescriptor(method);
boolean needThis = statement.getCallee() != null;
if (needThis) {
VariableReference callee = statement.getCallee();
ReferenceExpressionPair refExprPair = read(callee, scope);
ReferenceExpression ref = refExprPair.getReference();
this.env.topFrame().operandStack.pushRef(ref);
}
List<VariableReference> parameters = statement.getParameterReferences();
pushParameterList(parameters, scope, desc);
if (needThis) {
VariableReference callee = statement.getCallee();
Object receiver;
try {
receiver = callee.getObject(scope);
} catch (CodeUnderTestException e) {
throw new RuntimeException(e);
}
Class<?> ownerClass = env.ensurePrepared(owner);
if (ownerClass.isInterface()) {
VM.INVOKEINTERFACE(receiver, owner, name, desc);
} else {
VM.INVOKEVIRTUAL(receiver, owner, name, desc);
}
} else {
VM.INVOKESTATIC(owner, name, desc);
}
call_vm_caller_stack_params(needThis, parameters, scope, desc);
}
use of org.evosuite.symbolic.expr.ref.ReferenceExpression in project evosuite by EvoSuite.
the class SymbolicObserver method after.
private void after(FileNamePrimitiveStatement statement, Scope scope) {
EvoSuiteFile conc_evosuite_file = statement.getValue();
VariableReference varRef = statement.getReturnValue();
String varRefName = varRef.getName();
ReferenceExpression fileRef;
if (conc_evosuite_file == null) {
fileRef = env.heap.getReference(null);
if (fileRef.getConcreteValue() != null) {
throw new IllegalStateException("Expected null concrete object");
}
} else {
fileRef = (ReferenceConstant) env.heap.getReference(conc_evosuite_file);
if (fileRef.getConcreteValue() == null) {
throw new IllegalStateException("Expected non-null concrete object");
}
}
symb_references.put(varRefName, fileRef);
}
Aggregations