use of org.sonar.java.se.symbolicvalues.SymbolicValue 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.symbolicvalues.SymbolicValue in project sonar-java by SonarSource.
the class ProgramState method getValuesWithConstraints.
public List<SymbolicValue> getValuesWithConstraints(final Constraint constraint) {
final List<SymbolicValue> result = new ArrayList<>();
constraints.forEach((symbolicValue, constraintByDomain) -> {
Constraint find = constraintByDomain.get(constraint.getClass());
if (constraint.equals(find)) {
result.add(symbolicValue);
}
});
return result;
}
use of org.sonar.java.se.symbolicvalues.SymbolicValue in project sonar-java by SonarSource.
the class ConstraintManager method createBinarySymbolicValue.
public SymbolicValue createBinarySymbolicValue(Instruction inst, List<ProgramState.SymbolicValueSymbol> computedFrom) {
SymbolicValue result;
switch(inst.opcode) {
case IAND:
case LAND:
result = new SymbolicValue.AndSymbolicValue();
result.computedFrom(computedFrom);
break;
case IOR:
case LOR:
result = new SymbolicValue.OrSymbolicValue();
result.computedFrom(computedFrom);
break;
case IXOR:
case LXOR:
result = new SymbolicValue.XorSymbolicValue();
result.computedFrom(computedFrom);
break;
case IF_ICMPEQ:
case IF_ACMPEQ:
case IFEQ:
case IFNULL:
result = createRelationalSymbolicValue(Kind.EQUAL, computedFrom);
break;
case IFNE:
case IFNONNULL:
case IF_ICMPNE:
case IF_ACMPNE:
result = createRelationalSymbolicValue(Kind.NOT_EQUAL, computedFrom);
break;
case IF_ICMPLT:
case IFLT:
result = createRelationalSymbolicValue(Kind.LESS_THAN, computedFrom);
break;
case IF_ICMPGE:
case IFGE:
result = createRelationalSymbolicValue(Kind.GREATER_THAN_OR_EQUAL, computedFrom);
break;
case IF_ICMPGT:
case IFGT:
result = createRelationalSymbolicValue(Kind.LESS_THAN, Lists.reverse(computedFrom));
break;
case IF_ICMPLE:
case IFLE:
result = createRelationalSymbolicValue(Kind.GREATER_THAN_OR_EQUAL, Lists.reverse(computedFrom));
break;
default:
throw new IllegalStateException("Unexpected kind for binary SV");
}
return result;
}
use of org.sonar.java.se.symbolicvalues.SymbolicValue in project sonar-java by SonarSource.
the class ConstraintManager method createMethodSymbolicValue.
public SymbolicValue createMethodSymbolicValue(MethodInvocationTree syntaxNode, List<ProgramState.SymbolicValueSymbol> values) {
SymbolicValue result;
if (ExplodedGraphWalker.EQUALS_METHODS.anyMatch(syntaxNode)) {
result = new RelationalSymbolicValue(RelationalSymbolicValue.Kind.METHOD_EQUALS);
ProgramState.SymbolicValueSymbol leftOp = values.get(1);
ProgramState.SymbolicValueSymbol rightOp = values.get(0);
result.computedFrom(ImmutableList.of(rightOp, leftOp));
} else {
result = createDefaultSymbolicValue();
}
return result;
}
use of org.sonar.java.se.symbolicvalues.SymbolicValue in project sonar-java by SonarSource.
the class ConstraintManager method createDefaultSymbolicValue.
public SymbolicValue createDefaultSymbolicValue() {
SymbolicValue result;
result = symbolicValueFactory == null ? new SymbolicValue() : symbolicValueFactory.createSymbolicValue();
symbolicValueFactory = null;
return result;
}
Aggregations