Search in sources :

Example 61 with ReferenceExpression

use of org.evosuite.symbolic.expr.ref.ReferenceExpression in project evosuite by EvoSuite.

the class HeapVM method CASTORE.

@Override
public void CASTORE(Object conc_array, int conc_index) {
    // pop arguments
    IntegerValue symb_value = env.topFrame().operandStack.popBv32();
    IntegerValue symb_index = env.topFrame().operandStack.popBv32();
    ReferenceExpression array_ref = env.topFrame().operandStack.popRef();
    /* check reference initialization */
    env.heap.initializeReference(conc_array, array_ref);
    /* null-check */
    if (nullReferenceViolation(array_ref, conc_array)) {
        return;
    }
    /* negative index */
    if (negativeIndexViolation(conc_index, symb_index)) {
        return;
    }
    /* out of bound index */
    ReferenceExpression symb_array = array_ref;
    int conc_array_length = Array.getLength(conc_array);
    IntegerValue symb_array_length = env.heap.getField("", ARRAY_LENGTH, conc_array, symb_array, conc_array_length);
    if (indexTooBigViolation(conc_index, symb_index, conc_array_length, symb_array_length))
        return;
    env.heap.array_store(conc_array, symb_array, conc_index, symb_value);
}
Also used : IntegerValue(org.evosuite.symbolic.expr.bv.IntegerValue) ReferenceExpression(org.evosuite.symbolic.expr.ref.ReferenceExpression) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint)

Example 62 with ReferenceExpression

use of org.evosuite.symbolic.expr.ref.ReferenceExpression in project evosuite by EvoSuite.

the class HeapVM method IALOAD.

/**
 * Load an int value from an array and push it on the stack
 *
 * ..., arrayref, index ==> ..., value
 *
 * http://java.sun.com/docs/books/jvms/second_edition/html/Instructions2.
 * doc6.html#iaload
 */
@Override
public void IALOAD(Object conc_array, int conc_index) {
    // pop symbolic arguments
    IntegerValue symb_index = env.topFrame().operandStack.popBv32();
    ReferenceExpression array_ref = env.topFrame().operandStack.popRef();
    /* check reference initialization */
    env.heap.initializeReference(conc_array, array_ref);
    /* null-check */
    if (nullReferenceViolation(array_ref, conc_array)) {
        return;
    }
    /* negative index */
    if (negativeIndexViolation(conc_index, symb_index)) {
        return;
    }
    /* out of bound index */
    ReferenceExpression symb_array = (ReferenceExpression) array_ref;
    int conc_array_length = Array.getLength(conc_array);
    IntegerValue symb_array_length = env.heap.getField("", ARRAY_LENGTH, conc_array, symb_array, conc_array_length);
    if (indexTooBigViolation(conc_index, symb_index, conc_array_length, symb_array_length))
        return;
    int bv32 = Array.getInt(conc_array, conc_index);
    IntegerValue c = env.heap.array_load(symb_array, conc_index, (long) bv32);
    env.topFrame().operandStack.pushBv32(c);
}
Also used : IntegerValue(org.evosuite.symbolic.expr.bv.IntegerValue) ReferenceExpression(org.evosuite.symbolic.expr.ref.ReferenceExpression) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint)

Example 63 with ReferenceExpression

use of org.evosuite.symbolic.expr.ref.ReferenceExpression in project evosuite by EvoSuite.

the class OperandStack method pushNullRef.

public void pushNullRef() {
    ReferenceExpression nullExpression = ExpressionFactory.buildNewNullExpression();
    this.stack.push(new ReferenceOperand(nullExpression));
}
Also used : ReferenceExpression(org.evosuite.symbolic.expr.ref.ReferenceExpression)

Example 64 with ReferenceExpression

use of org.evosuite.symbolic.expr.ref.ReferenceExpression in project evosuite by EvoSuite.

the class OperandStack method peekRef.

public ReferenceExpression peekRef() {
    Operand operand = this.peekOperand();
    if (!(operand instanceof ReferenceOperand)) {
        throw new ClassCastException("top of stack is not a reference but an operand of type " + operand.getClass().getCanonicalName());
    }
    ReferenceOperand refOp = (ReferenceOperand) operand;
    ReferenceExpression ref = refOp.getReference();
    return ref;
}
Also used : ReferenceExpression(org.evosuite.symbolic.expr.ref.ReferenceExpression)

Example 65 with ReferenceExpression

use of org.evosuite.symbolic.expr.ref.ReferenceExpression in project evosuite by EvoSuite.

the class StringTokenizer_Init method executeFunction.

@Override
public Object executeFunction() {
    // symbolic receiver (new object)
    ReferenceConstant symb_str_tokenizer = (ReferenceConstant) this.getSymbReceiver();
    // string argument
    String conc_str = (String) this.getConcArgument(0);
    ReferenceExpression symb_str = this.getSymbArgument(0);
    // delim argument
    String conc_delim = (String) this.getConcArgument(1);
    ReferenceExpression symb_delim = this.getSymbArgument(1);
    if (symb_str instanceof ReferenceConstant && symb_delim instanceof ReferenceConstant) {
        ReferenceConstant non_null_symb_string = (ReferenceConstant) symb_str;
        assert conc_str != null;
        StringValue strExpr = env.heap.getField(Types.JAVA_LANG_STRING, SymbolicHeap.$STRING_VALUE, conc_str, non_null_symb_string, conc_str);
        ReferenceConstant non_null_symb_delim = (ReferenceConstant) symb_delim;
        assert conc_delim != null;
        StringValue delimExpr = env.heap.getField(Types.JAVA_LANG_STRING, SymbolicHeap.$STRING_VALUE, conc_delim, non_null_symb_delim, conc_delim);
        NewTokenizerExpr newTokenizerExpr = new NewTokenizerExpr(strExpr, delimExpr);
        // update symbolic heap
        env.heap.putField(Types.JAVA_UTIL_STRING_TOKENIZER, SymbolicHeap.$STRING_TOKENIZER_VALUE, null, symb_str_tokenizer, newTokenizerExpr);
    }
    // constructor returns void
    return null;
}
Also used : ReferenceConstant(org.evosuite.symbolic.expr.ref.ReferenceConstant) NewTokenizerExpr(org.evosuite.symbolic.expr.token.NewTokenizerExpr) ReferenceExpression(org.evosuite.symbolic.expr.ref.ReferenceExpression) StringValue(org.evosuite.symbolic.expr.str.StringValue)

Aggregations

ReferenceExpression (org.evosuite.symbolic.expr.ref.ReferenceExpression)73 IntegerValue (org.evosuite.symbolic.expr.bv.IntegerValue)27 IntegerConstraint (org.evosuite.symbolic.expr.IntegerConstraint)19 ReferenceConstant (org.evosuite.symbolic.expr.ref.ReferenceConstant)18 StringValue (org.evosuite.symbolic.expr.str.StringValue)16 Expression (org.evosuite.symbolic.expr.Expression)13 RealValue (org.evosuite.symbolic.expr.fp.RealValue)13 VariableReference (org.evosuite.testcase.variable.VariableReference)11 Type (org.objectweb.asm.Type)9 CodeUnderTestException (org.evosuite.testcase.execution.CodeUnderTestException)6 PrimitiveExpression (org.evosuite.testcase.statements.PrimitiveExpression)5 Field (java.lang.reflect.Field)3 StringBinaryComparison (org.evosuite.symbolic.expr.bv.StringBinaryComparison)3 Method (java.lang.reflect.Method)2 StringMultipleExpression (org.evosuite.symbolic.expr.str.StringMultipleExpression)2 EvosuiteError (org.evosuite.testcase.execution.EvosuiteError)2 ArrayReference (org.evosuite.testcase.variable.ArrayReference)2 BigInteger (java.math.BigInteger)1 Matcher (java.util.regex.Matcher)1 EvoSuiteFile (org.evosuite.runtime.testdata.EvoSuiteFile)1