private ProgramState.Pop popStack(int nbOfValues, int opcode) { ProgramState.Pop pop = programState.unstackValue(nbOfValues); Preconditions.checkState(pop.values.size() == nbOfValues, "%s needs %s values on stack", Printer.OPCODES[opcode], nbOfValues); return pop; }
private void executeAssertStatement(Tree tree) { // After an assert statement we know that the evaluated expression is true. ProgramState.Pop pop = programState.unstackValue(1); pop.values.forEach(v -> v.setConstraint(pop.state, BooleanConstraint.TRUE) .forEach(ps -> { checkerDispatcher.syntaxNode = tree; checkerDispatcher.addTransition(ps); ps.clearStack(); })); }
private void executeNewArray(NewArrayTree newArrayTree) { int numberDimensions = (int) newArrayTree.dimensions().stream().map(ArrayDimensionTree::expression).filter(Objects::nonNull).count(); programState = programState.unstackValue(numberDimensions).state; programState = programState.unstackValue(newArrayTree.initializers().size()).state; SymbolicValue svNewArray = constraintManager.createSymbolicValue(newArrayTree); programState = programState.stackValue(svNewArray); programState = svNewArray.setSingleConstraint(programState, ObjectConstraint.NOT_NULL); }
private void executeArrayAccessExpression(ArrayAccessExpressionTree tree) { // unstack expression and dimension ProgramState.Pop unstack = programState.unstackValue(2); programState = unstack.state; programState = programState.stackValue(constraintManager.createSymbolicValue(tree)); }
private void executeArrayAccessExpression(ArrayAccessExpressionTree tree) { // unstack expression and dimension ProgramState.Pop unstack = programState.unstackValue(2); programState = unstack.state; programState = programState.stackValue(constraintManager.createSymbolicValue(tree)); }
private void executeNewArray(NewArrayTree newArrayTree) { int numberDimensions = (int) newArrayTree.dimensions().stream().map(ArrayDimensionTree::expression).filter(Objects::nonNull).count(); programState = programState.unstackValue(numberDimensions).state; programState = programState.unstackValue(newArrayTree.initializers().size()).state; SymbolicValue svNewArray = constraintManager.createSymbolicValue(newArrayTree); programState = programState.stackValue(svNewArray); programState = svNewArray.setSingleConstraint(programState, ObjectConstraint.NOT_NULL); }
private void executeArrayAccessExpression(ArrayAccessExpressionTree tree) { // unstack expression and dimension ProgramState.Pop unstack = programState.unstackValue(2); programState = unstack.state; programState = programState.stackValue(constraintManager.createSymbolicValue(tree)); }
public Pair<List<ProgramState>, List<ProgramState>> assumeDual(ProgramState programState) { ProgramState.Pop unstack = programState.unstackValue(1); SymbolicValue sv = unstack.values.get(0); List<ProgramState> falseConstraint = sv.setConstraint(unstack.state, BooleanConstraint.FALSE); List<ProgramState> trueConstraint = sv.setConstraint(unstack.state, BooleanConstraint.TRUE); return new Pair<>(falseConstraint, trueConstraint); }
public Pair<List<ProgramState>, List<ProgramState>> assumeDual(ProgramState programState) { ProgramState.Pop unstack = programState.unstackValue(1); SymbolicValue sv = unstack.values.get(0); List<ProgramState> falseConstraint = sv.setConstraint(unstack.state, BooleanConstraint.FALSE); List<ProgramState> trueConstraint = sv.setConstraint(unstack.state, BooleanConstraint.TRUE); return new Pair<>(falseConstraint, trueConstraint); }
private void executeBinaryExpression(Tree tree) { // Consume two and produce one SV. ProgramState.Pop unstackBinary = programState.unstackValue(2); programState = unstackBinary.state; SymbolicValue symbolicValue = constraintManager.createBinarySymbolicValue(tree, unstackBinary.valuesAndSymbols); programState = programState.addConstraint(symbolicValue, ObjectConstraint.NOT_NULL); programState = programState.stackValue(symbolicValue); }
private void executeBinaryExpression(Tree tree) { // Consume two and produce one SV. ProgramState.Pop unstackBinary = programState.unstackValue(2); programState = unstackBinary.state; SymbolicValue symbolicValue = constraintManager.createBinarySymbolicValue(tree, unstackBinary.valuesAndSymbols); programState = programState.addConstraint(symbolicValue, ObjectConstraint.NOT_NULL); programState = programState.stackValue(symbolicValue); }
private void executeMemberSelect(MemberSelectExpressionTree mse) { if (!"class".equals(mse.identifier().name())) { ProgramState.Pop unstackMSE = programState.unstackValue(1); programState = unstackMSE.state; } SymbolicValue mseValue = constraintManager.createSymbolicValue(mse); programState = programState.stackValue(mseValue); }
private void executeLogicalAssignement(AssignmentExpressionTree tree) { ExpressionTree variable = tree.variable(); if (variable.is(Tree.Kind.IDENTIFIER)) { ProgramState.Pop unstack = programState.unstackValue(2); SymbolicValue assignedTo = unstack.values.get(0); SymbolicValue value = unstack.values.get(1); programState = unstack.state; SymbolicValue symbolicValue = constraintManager.createSymbolicValue(tree); symbolicValue.computedFrom(ImmutableList.of(assignedTo, value)); programState = programState.put(((IdentifierTree) variable).symbol(), symbolicValue); programState = programState.stackValue(symbolicValue); } }
private static ProgramState handleShift(ProgramState previousState, ProgramState currentState) { List<SymbolicValue> operands = previousState.peekValues(2); SymbolicValue result = currentState.peekValue(); SymbolicValue op1 = operands.get(0); SymbolicValue op2 = operands.get(0); if (isZero(currentState, op1) || isZero(currentState, op2)) { // shifting by zero or shifting zero: Reuse fist operand return currentState.unstackValue(1).state.stackValue(op1); } return currentState.removeConstraintsOnDomain(result, BooleanConstraint.class).addConstraint(result, ZeroConstraint.NON_ZERO); }
private static ProgramState handleShift(ProgramState previousState, ProgramState currentState) { List<SymbolicValue> operands = previousState.peekValues(2); SymbolicValue result = currentState.peekValue(); SymbolicValue op1 = operands.get(0); SymbolicValue op2 = operands.get(0); if (isZero(currentState, op1) || isZero(currentState, op2)) { // shifting by zero or shifting zero: Reuse fist operand return currentState.unstackValue(1).state.stackValue(op1); } return currentState.removeConstraintsOnDomain(result, BooleanConstraint.class).addConstraint(result, ZeroConstraint.NON_ZERO); }
private void executeMemberSelect(MemberSelectExpressionTree mse) { if (!"class".equals(mse.identifier().name())) { ProgramState.Pop unstackMSE = programState.unstackValue(1); programState = unstackMSE.state; } if (ExpressionUtils.isSelectOnThisOrSuper(mse)) { executeIdentifier(mse.identifier()); } else { SymbolicValue mseValue = constraintManager.createSymbolicValue(mse); programState = programState.stackValue(mseValue); } }
private void executeNewArray(NewArrayTree newArrayTree) { programState = programState.unstackValue(newArrayTree.initializers().size()).state; SymbolicValue svNewArray = constraintManager.createSymbolicValue(newArrayTree); programState = programState.stackValue(svNewArray); programState = svNewArray.setSingleConstraint(programState, ObjectConstraint.NOT_NULL); }
private void executeAssignement(AssignmentExpressionTree tree) { ExpressionTree variable = tree.variable(); if (variable.is(Tree.Kind.IDENTIFIER)) { // FIXME restricted to identifiers for now. ProgramState.Pop unstack = programState.unstackValue(2); SymbolicValue value = tree.is(Tree.Kind.ASSIGNMENT) ? unstack.values.get(1) : constraintManager.createSymbolicValue(tree); programState = unstack.state; programState = programState.put(((IdentifierTree) variable).symbol(), value); programState = programState.stackValue(value); } }
private void executeTypeCast(TypeCastTree typeCast) { Type type = typeCast.type().symbolType(); if (type.isPrimitive()) { ProgramState.Pop unstack = programState.unstackValue(1); programState = unstack.state; programState = programState.stackValue(constraintManager.createSymbolicValue(typeCast.expression())); } }
private void executeNewClass(NewClassTree tree) { NewClassTree newClassTree = tree; programState = programState.unstackValue(newClassTree.arguments().size()).state; // Enqueue exceptional paths ((CFG.Block) node.programPoint.block).exceptions().forEach(b -> enqueue(new ProgramPoint(b), programState, !b.isCatchBlock())); SymbolicValue svNewClass = constraintManager.createSymbolicValue(newClassTree); programState = programState.stackValue(svNewClass); programState = svNewClass.setSingleConstraint(programState, ObjectConstraint.NOT_NULL); }