use of org.sonar.java.se.constraint.ConstraintsByDomain in project sonar-java by SonarSource.
the class ProgramState method cleanupConstraints.
public ProgramState cleanupConstraints(Collection<SymbolicValue> protectedSymbolicValues) {
class CleanAction implements BiConsumer<SymbolicValue, ConstraintsByDomain> {
boolean newProgramState = false;
PMap<SymbolicValue, ConstraintsByDomain> newConstraints = constraints;
PMap<SymbolicValue, Integer> newReferences = references;
@Override
public void accept(SymbolicValue symbolicValue, ConstraintsByDomain constraintPMap) {
constraintPMap.forEach((domain, constraint) -> {
if (!protectedSymbolicValues.contains(symbolicValue) && !isReachable(symbolicValue, newReferences) && isDisposable(symbolicValue, constraint) && !inStack(stack, symbolicValue)) {
newProgramState = true;
ConstraintsByDomain removed = newConstraints.get(symbolicValue).remove(domain);
if (removed.isEmpty()) {
newConstraints = newConstraints.remove(symbolicValue);
} else {
newConstraints = newConstraints.put(symbolicValue, removed);
}
newReferences = newReferences.remove(symbolicValue);
}
});
}
}
CleanAction cleanAction = new CleanAction();
constraints.forEach(cleanAction);
return cleanAction.newProgramState ? new ProgramState(values, cleanAction.newReferences, cleanAction.newConstraints, visitedPoints, stack, exitSymbolicValue) : this;
}
use of org.sonar.java.se.constraint.ConstraintsByDomain in project sonar-java by SonarSource.
the class ProgramState method removeConstraintsOnDomain.
public ProgramState removeConstraintsOnDomain(SymbolicValue sv, Class<? extends Constraint> domain) {
ConstraintsByDomain svConstraint = constraints.get(sv);
if (svConstraint == null) {
return this;
}
ConstraintsByDomain newConstraintForSv = svConstraint.remove(domain);
if (newConstraintForSv.isEmpty()) {
return new ProgramState(this, constraints.remove(sv));
}
return addConstraints(sv, newConstraintForSv);
}
use of org.sonar.java.se.constraint.ConstraintsByDomain in project sonar-java by SonarSource.
the class ExceptionalYieldChecker method hasConstraintOtherThanNonNull.
private static boolean hasConstraintOtherThanNonNull(ProgramState.SymbolicValueSymbol svs, ProgramState ps) {
SymbolicValue sv = svs.symbolicValue();
ConstraintsByDomain constraints = ps.getConstraints(sv);
return constraints != null && !hasOnlyNonNullConstraint(constraints);
}
use of org.sonar.java.se.constraint.ConstraintsByDomain in project sonar-java by SonarSource.
the class MethodBehavior method addParameterConstraints.
private void addParameterConstraints(ExplodedGraph.Node node, MethodYield yield) {
// add the constraints on all the parameters
int index = 0;
for (SymbolicValue parameter : parameters) {
ConstraintsByDomain constraints = node.programState.getConstraints(parameter);
if (constraints == null) {
constraints = ConstraintsByDomain.empty();
} else {
// cleanup based on signature
org.objectweb.asm.Type[] argumentTypes = org.objectweb.asm.Type.getArgumentTypes(signature.substring(signature.indexOf('(')));
constraints = cleanup(constraints, argumentTypes[index]);
}
yield.parametersConstraints.add(constraints);
index++;
}
}
use of org.sonar.java.se.constraint.ConstraintsByDomain in project sonar-java by SonarSource.
the class MethodBehavior method getOnlyConstraintDifferenceIndex.
private static Optional<Integer> getOnlyConstraintDifferenceIndex(HappyPathYield yield1, HappyPathYield yield2) {
List<ConstraintsByDomain> constraints1 = new ArrayList<>(yield1.parametersConstraints);
constraints1.add(yield1.resultConstraint());
List<ConstraintsByDomain> constraints2 = new ArrayList<>(yield2.parametersConstraints);
constraints2.add(yield2.resultConstraint());
List<Integer> diff = new ArrayList<>();
for (int i = 0; i < constraints1.size(); i++) {
if (!Objects.equals(constraints1.get(i), constraints2.get(i))) {
diff.add(i);
}
}
if (diff.size() != 1) {
return Optional.empty();
}
return Optional.of(diff.get(0));
}
Aggregations