use of org.evosuite.symbolic.expr.ref.ReferenceConstant in project evosuite by EvoSuite.
the class HeapVM method MULTIANEWARRAY.
/**
* MULTIANEWARRAY
*
* <pre>
* boolean[] b1 = new boolean[1]; // NEWARRAY T_BOOLEAN
* Boolean[] B1 = new Boolean[1]; // ANEWARRAY java/lang/Boolean
* boolean[][] b2 = new boolean[1][2]; // MULTIANEWARRAY [[Z 2
* Boolean[][] B2 = new Boolean[1][2]; // MULTIANEWARRAY [[Ljava/lang/Boolean; 2
* </pre>
*/
@Override
public void MULTIANEWARRAY(String arrayTypeDesc, int nrDimensions) {
// push negartive length constraints
for (int i = 0; i < nrDimensions; i++) {
IntegerValue symb_length = env.topFrame().operandStack.popBv32();
int conc_length = ((Long) symb_length.getConcreteValue()).intValue();
if (negativeArrayLengthViolation(conc_length, symb_length)) {
return;
}
}
Type multiArrayType = Type.getType(arrayTypeDesc);
// push delayed object
ReferenceConstant newMultiArray = this.env.heap.buildNewReferenceConstant(// @FIXME
multiArrayType);
env.topFrame().operandStack.pushRef(newMultiArray);
}
use of org.evosuite.symbolic.expr.ref.ReferenceConstant in project evosuite by EvoSuite.
the class HeapVM method NEWARRAY.
/* Arrays */
/**
* Create a (one-dimensional) array of primitive componenet type, e.g., new
* int[3]
*
* Allocate space on the heap and push a reference ref to it onto the stack.
*
* http://java.sun.com/docs/books/jvms/second_edition/html/Instructions2.
* doc10.html#newarray
*/
@Override
public void NEWARRAY(int conc_array_length, Class<?> componentType) {
/**
* Since this callback is invoked before the actual array creation, we
* can only add negative index constraints.
*
* PRE: int (length)
*
* POST: arrayref (delayed)
*/
// discard symbolic arguments
IntegerValue symb_array_length = env.topFrame().operandStack.popBv32();
/* negative index */
if (negativeArrayLengthViolation(conc_array_length, symb_array_length))
return;
// create array class
int[] lenghts = new int[] { 0 };
Class<?> array_class = Array.newInstance(componentType, lenghts).getClass();
Type arrayType = Type.getType(array_class);
ReferenceConstant symb_array_ref = this.env.heap.buildNewReferenceConstant(arrayType);
env.heap.putField("", ARRAY_LENGTH, null, symb_array_ref, symb_array_length);
env.topFrame().operandStack.pushRef(symb_array_ref);
}
use of org.evosuite.symbolic.expr.ref.ReferenceConstant in project evosuite by EvoSuite.
the class HeapVM method ANEWARRAY.
/**
* http://java.sun.com/docs/books/jvms/second_edition/html/Instructions2.doc
* .html#anewarray
*/
@Override
public void ANEWARRAY(int conc_array_length, String componentTypeName) {
/**
* Since this callback is invoked before the actual array creation, we
* can only add negative index constraints.
*
* PRE: int (length)
*
* POST: arrayref (delayed)
*/
// discard symbolic arguments
IntegerValue symb_array_length = env.topFrame().operandStack.popBv32();
/* negative index */
if (negativeArrayLengthViolation(conc_array_length, symb_array_length))
return;
// create array class
Type componentType = Type.getType(componentTypeName.replace('/', '.'));
Class<?> componentClass = classLoader.getClassForType(componentType);
int[] lenghts = new int[] { 0 };
Class<?> array_class = Array.newInstance(componentClass, lenghts).getClass();
Type arrayType = Type.getType(array_class);
ReferenceConstant symb_array_ref = env.heap.buildNewReferenceConstant(arrayType);
env.heap.putField("", ARRAY_LENGTH, null, symb_array_ref, symb_array_length);
env.topFrame().operandStack.pushRef(symb_array_ref);
}
use of org.evosuite.symbolic.expr.ref.ReferenceConstant in project evosuite by EvoSuite.
the class SymbolicHeap method getReference.
/**
* Returns a <code>ReferenceConstant</code> if the concrete reference is
* null. Otherwise, it looks in the list of non-null symbolic references for
* a symbolic reference with the concrete value. If it is found, that
* symbolic reference is returned, otherwise a new reference constant is
* created (and added ot the list of non-null symbolic references)
*
* @param conc_ref
* @return
*/
public ReferenceExpression getReference(Object conc_ref) {
if (conc_ref == null) {
// null reference
ReferenceConstant nullConstant = ExpressionFactory.buildNewNullExpression();
return nullConstant;
} else {
int identityHashCode = System.identityHashCode(conc_ref);
if (nonNullRefs.containsKey(identityHashCode)) {
// already known object
ReferenceExpression symb_ref = nonNullRefs.get(identityHashCode);
return symb_ref;
} else {
// unknown object
final Type type = Type.getType(conc_ref.getClass());
ReferenceConstant ref_constant = new ReferenceConstant(type, newInstanceCount++);
ref_constant.initializeReference(conc_ref);
nonNullRefs.put(identityHashCode, ref_constant);
return ref_constant;
}
}
}
use of org.evosuite.symbolic.expr.ref.ReferenceConstant in project evosuite by EvoSuite.
the class Perl5Matcher_Matches method executeFunction.
@Override
public Object executeFunction() {
// Perl5Matcher conc_matcher = (Perl5Matcher) this.getConcReceiver();
// NonNullReference symb_matcher = (NonNullReference) this
// .getSymbReceiver();
boolean res = this.getConcBooleanRetVal();
ReferenceConstant symb_string_ref = (ReferenceConstant) this.getSymbArgument(0);
// Reference symb_pattern_ref = this.getSymbArgument(1);
String conc_string = (String) this.getConcArgument(0);
Pattern conc_pattern = (Pattern) this.getConcArgument(1);
StringValue symb_string_value = env.heap.getField(org.evosuite.symbolic.vm.regex.Types.JAVA_LANG_STRING, SymbolicHeap.$STRING_VALUE, conc_string, symb_string_ref, conc_string);
if (symb_string_value != null && symb_string_value.containsSymbolicVariable()) {
int concrete_value = res ? 1 : 0;
String pattern_str = conc_pattern.getPattern();
StringConstant symb_pattern_value = ExpressionFactory.buildNewStringConstant(pattern_str);
StringBinaryComparison strComp = new StringBinaryComparison(symb_pattern_value, Operator.APACHE_ORO_PATTERN_MATCHES, symb_string_value, (long) concrete_value);
return strComp;
} else {
return this.getSymbIntegerRetVal();
}
}
Aggregations