use of org.sonar.java.se.symbolicvalues.SymbolicValue in project sonar-java by SonarSource.
the class ExplodedGraphWalker method executeNewArray.
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);
}
use of org.sonar.java.se.symbolicvalues.SymbolicValue in project sonar-java by SonarSource.
the class ExplodedGraphWalker method executeIdentifier.
private void executeIdentifier(IdentifierTree tree) {
Symbol symbol = tree.symbol();
SymbolicValue value = programState.getValue(symbol);
if (value == null) {
value = constraintManager.createSymbolicValue(tree);
programState = programState.stackValue(value, symbol);
learnIdentifierConstraints(tree, value);
} else {
programState = programState.stackValue(value, symbol);
}
programState = programState.put(symbol, value);
}
use of org.sonar.java.se.symbolicvalues.SymbolicValue in project sonar-java by SonarSource.
the class ProgramState method addConstraintTransitively.
public ProgramState addConstraintTransitively(SymbolicValue symbolicValue, Constraint constraint) {
List<SymbolicValue> transitiveSymbolicValues = knownRelations().stream().filter(rsv -> rsv.isEquality() && (rsv.getLeftOp() == symbolicValue || rsv.getRightOp() == symbolicValue)).map(rsv -> rsv.getLeftOp() == symbolicValue ? rsv.getRightOp() : rsv.getLeftOp()).collect(Collectors.toList());
ProgramState ps = addConstraint(symbolicValue, constraint);
for (SymbolicValue sv : transitiveSymbolicValues) {
ps = ps.addConstraint(sv, constraint);
}
return ps;
}
use of org.sonar.java.se.symbolicvalues.SymbolicValue in project sonar-java by SonarSource.
the class ProgramState method put.
@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;
}
use of org.sonar.java.se.symbolicvalues.SymbolicValue in project sonar-java by SonarSource.
the class ConstraintManager method assumeDual.
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);
}
Aggregations