@VisibleForTesting public ProgramState put(Symbol symbol, SymbolicValue value) { if (symbol.isUnknown() || isVolatileField(symbol)) { return this; } SymbolicValue oldValue = values.get(symbol); if (oldValue == null || oldValue != value) { PMap<SymbolicValue, Integer> newReferences = references; if (oldValue != null) { newReferences = decreaseReference(newReferences, oldValue); } newReferences = increaseReference(newReferences, value); PMap<Symbol, SymbolicValue> newValues = values.put(symbol, value); return new ProgramState(newValues, newReferences, constraints, visitedPoints, stack, exitSymbolicValue); } return this; }
@VisibleForTesting public ProgramState put(Symbol symbol, SymbolicValue value) { if (symbol.isUnknown() || isVolatileField(symbol)) { return this; } SymbolicValue oldValue = values.get(symbol); if (oldValue == null || oldValue != value) { PMap<SymbolicValue, Integer> newReferences = references; if (oldValue != null) { newReferences = decreaseReference(newReferences, oldValue); } newReferences = increaseReference(newReferences, value); PMap<Symbol, SymbolicValue> newValues = values.put(symbol, value); return new ProgramState(newValues, newReferences, constraints, visitedPoints, stack, exitSymbolicValue); } return this; }
ProgramState put(Symbol symbol, SymbolicValue value) { if (symbol.isUnknown()) { return this; } SymbolicValue oldValue = values.get(symbol); if (oldValue == null || oldValue != value) { PMap<SymbolicValue, Integer> newReferences = references; if (oldValue != null) { newReferences = decreaseReference(newReferences, oldValue); } newReferences = increaseReference(newReferences, value); PMap<Symbol, SymbolicValue> newValues = values.put(symbol, value); return new ProgramState(newValues, newReferences, constraints, visitedPoints, stack); } return this; }
public ProgramState resetFieldValues(ConstraintManager constraintManager) { final List<VariableTree> variableTrees = new ArrayList<>(); values.forEach(new PMap.Consumer<Symbol, SymbolicValue>() { @Override public void accept(Symbol symbol, SymbolicValue value) { if (isField(symbol)) { VariableTree variable = ((Symbol.VariableSymbol) symbol).declaration(); if (variable != null) { variableTrees.add(variable); } } } }); if (variableTrees.isEmpty()) { return this; } PMap<Symbol, SymbolicValue> newValues = values; PMap<SymbolicValue, Integer> newReferences = references; for (VariableTree variableTree : variableTrees) { Symbol symbol = variableTree.symbol(); SymbolicValue oldValue = newValues.get(symbol); if (oldValue != null) { newReferences = decreaseReference(newReferences, oldValue); } SymbolicValue newValue = constraintManager.createSymbolicValue(variableTree); newValues = newValues.put(symbol, newValue); newReferences = increaseReference(newReferences, newValue); } return new ProgramState(newValues, newReferences, constraints, visitedPoints, stack); }