use of org.evosuite.symbolic.expr.ref.ReferenceExpression in project evosuite by EvoSuite.
the class Pattern_Matches method executeFunction.
@Override
public Object executeFunction() {
// argument 0
String regex_str = (String) this.getConcArgument(0);
ReferenceConstant regex_ref = (ReferenceConstant) this.getSymbArgument(0);
// argument 1
CharSequence input_char_seq = (CharSequence) this.getConcArgument(1);
ReferenceExpression input_ref = this.getSymbArgument(1);
// return value
boolean res = this.getConcBooleanRetVal();
// symbolic execution
StringValue symb_regex = env.heap.getField(Types.JAVA_LANG_STRING, SymbolicHeap.$STRING_VALUE, regex_str, regex_ref, regex_str);
StringValue symb_input = getSymbInput(input_char_seq, input_ref);
if (symb_input != null && symb_input.containsSymbolicVariable()) {
int concrete_value = res ? 1 : 0;
StringBinaryComparison strComp = new StringBinaryComparison(symb_regex, Operator.PATTERNMATCHES, symb_input, (long) concrete_value);
return strComp;
} else {
return this.getSymbIntegerRetVal();
}
}
use of org.evosuite.symbolic.expr.ref.ReferenceExpression in project evosuite by EvoSuite.
the class Equals method executeFunction.
@Override
public Object executeFunction() {
String conc_left = (String) this.getConcReceiver();
ReferenceConstant symb_left = this.getSymbReceiver();
Object conc_right = this.getConcArgument(0);
ReferenceExpression symb_right = this.getSymbArgument(0);
boolean res = this.getConcBooleanRetVal();
StringValue left_expr = env.heap.getField(Types.JAVA_LANG_STRING, SymbolicHeap.$STRING_VALUE, conc_left, symb_left, conc_left);
if (symb_right instanceof ReferenceConstant && conc_right instanceof String) {
ReferenceConstant non_null_symb_right = (ReferenceConstant) symb_right;
String conc_right_str = (String) conc_right;
StringValue right_expr = env.heap.getField(Types.JAVA_LANG_STRING, SymbolicHeap.$STRING_VALUE, conc_right_str, non_null_symb_right, conc_right_str);
if (left_expr.containsSymbolicVariable() || right_expr.containsSymbolicVariable()) {
int conV = res ? 1 : 0;
StringBinaryComparison strBExpr = new StringBinaryComparison(left_expr, Operator.EQUALS, right_expr, (long) conV);
return strBExpr;
}
}
return this.getSymbIntegerRetVal();
}
use of org.evosuite.symbolic.expr.ref.ReferenceExpression in project evosuite by EvoSuite.
the class ReplaceAll method executeFunction.
@Override
public Object executeFunction() {
// receiver
ReferenceConstant symb_receiver = this.getSymbReceiver();
String conc_receiver = (String) this.getConcReceiver();
// regex argument
ReferenceExpression symb_regex = this.getSymbArgument(0);
String conc_regex = (String) this.getConcArgument(0);
// replacement argument
ReferenceExpression symb_replacement = this.getSymbArgument(1);
String conc_replacement = (String) this.getConcArgument(1);
// return value
String conc_ret_val = (String) this.getConcRetVal();
ReferenceExpression symb_ret_val = this.getSymbRetVal();
StringValue stringReceiverExpr = env.heap.getField(Types.JAVA_LANG_STRING, SymbolicHeap.$STRING_VALUE, conc_receiver, symb_receiver, conc_receiver);
if (symb_regex instanceof ReferenceConstant && symb_replacement instanceof ReferenceConstant) {
ReferenceConstant non_null_symb_regex = (ReferenceConstant) symb_regex;
StringValue regexExpr = env.heap.getField(Types.JAVA_LANG_STRING, SymbolicHeap.$STRING_VALUE, conc_regex, non_null_symb_regex, conc_regex);
ReferenceConstant non_null_symb_replacement = (ReferenceConstant) symb_replacement;
StringValue replacementExpr = env.heap.getField(Types.JAVA_LANG_STRING, SymbolicHeap.$STRING_VALUE, conc_replacement, non_null_symb_replacement, conc_replacement);
if (symb_ret_val instanceof ReferenceConstant) {
ReferenceConstant non_null_symb_ret_val = (ReferenceConstant) symb_ret_val;
StringMultipleExpression symb_value = new StringMultipleExpression(stringReceiverExpr, Operator.REPLACEALL, regexExpr, new ArrayList<Expression<?>>(Collections.singletonList(replacementExpr)), conc_ret_val);
env.heap.putField(Types.JAVA_LANG_STRING, SymbolicHeap.$STRING_VALUE, conc_ret_val, non_null_symb_ret_val, symb_value);
}
}
return symb_ret_val;
}
use of org.evosuite.symbolic.expr.ref.ReferenceExpression in project evosuite by EvoSuite.
the class SymbolicObserver method after.
private void after(EnumPrimitiveStatement<?> s, Scope scope) {
VariableReference varRef = s.getReturnValue();
String varName = varRef.getName();
Object conc_value = s.getValue();
ReferenceExpression symb_value = env.heap.getReference(conc_value);
symb_references.put(varName, symb_value);
}
use of org.evosuite.symbolic.expr.ref.ReferenceExpression in project evosuite by EvoSuite.
the class SymbolicObserver method readVariable.
/**
* Reads a VariableReference from the stored symbolic references and
* symbolic expressions.
*
* @throws IllegalArgumentException
* if no value was found
*
* @param rhs
* @param scope
* @return
*/
private ReferenceExpressionPair readVariable(VariableReference rhs, Scope scope) {
String rhs_name = rhs.getName();
ReferenceExpression symb_ref = symb_references.get(rhs_name);
Expression<?> symb_expr = symb_expressions.get(rhs_name);
return new ReferenceExpressionPair(symb_ref, symb_expr);
}
Aggregations