Search in sources :

Example 1 with Range

use of org.checkerframework.common.value.util.Range in project checker-framework by typetools.

the class RangeTest method testRemainder.

@Test
public void testRemainder() {
    assert new Range(1, 2).remainder(new Range(0, 0)) == Range.NOTHING;
    for (RangeAndElement re1 : rangeAndElements()) {
        for (RangeAndElement re2 : rangeAndElements()) {
            if (re2.element == 0) {
                continue;
            }
            Range result = re1.range.remainder(re2.range);
            Long witness = re1.element % re2.element;
            assert result.contains(witness) : String.format("Range.remainder failure: %s %s => %s; witnesses %s %% %s => %s", re1.range, re2.range, result, re1.element, re2.element, witness);
        }
    }
}
Also used : Range(org.checkerframework.common.value.util.Range) Test(org.junit.Test)

Example 2 with Range

use of org.checkerframework.common.value.util.Range in project checker-framework by typetools.

the class RangeTest method testDivide.

@Test
public void testDivide() {
    assert new Range(1, 2).divide(new Range(0, 0)) == Range.NOTHING;
    for (RangeAndElement re1 : rangeAndElements()) {
        for (RangeAndElement re2 : rangeAndElements()) {
            if (re2.element == 0) {
                continue;
            }
            Range result = re1.range.divide(re2.range);
            Long witness = re1.element / re2.element;
            assert result.contains(witness) : String.format("Range.divide failure: %s %s => %s; witnesses %s / %s => %s", re1.range, re2.range, result, re1.element, re2.element, witness);
        }
    }
}
Also used : Range(org.checkerframework.common.value.util.Range) Test(org.junit.Test)

Example 3 with Range

use of org.checkerframework.common.value.util.Range in project checker-framework by typetools.

the class RangeOrListOfValues method addAll.

/**
 * If this is not a range, adds all members of newValues to the list. Otherwise, extends the
 * range as appropriate based on the max and min of newValues. If adding newValues to a
 * non-range would cause the list to become too large, converts this into a range.
 *
 * <p>If reading from an {@link org.checkerframework.common.value.qual.IntRange} annotation,
 * {@link #convertLongsToInts(List)} should be called before calling this method.
 */
public void addAll(List<Integer> newValues) {
    if (isRange) {
        Range newValueRange = new Range(Collections.min(newValues), Collections.max(newValues));
        range = range.union(newValueRange);
    } else {
        for (Integer i : newValues) {
            if (!values.contains(i)) {
                values.add(i);
            }
        }
        if (values.size() > ValueAnnotatedTypeFactory.MAX_VALUES) {
            convertToRange();
        }
    }
}
Also used : ArrayLenRange(org.checkerframework.common.value.qual.ArrayLenRange) Range(org.checkerframework.common.value.util.Range)

Example 4 with Range

use of org.checkerframework.common.value.util.Range in project checker-framework by typetools.

the class RangeOrListOfValues method convertToRange.

/**
 * Transforms this into a range. Fails if there are no values in the list. Has no effect if this
 * is already a range.
 */
public void convertToRange() {
    if (!isRange) {
        isRange = true;
        range = new Range(Collections.min(values), Collections.max(values));
        values = null;
    }
}
Also used : ArrayLenRange(org.checkerframework.common.value.qual.ArrayLenRange) Range(org.checkerframework.common.value.util.Range)

Example 5 with Range

use of org.checkerframework.common.value.util.Range in project checker-framework by typetools.

the class ValueAnnotatedTypeFactory method convertIntRangeToIntVal.

/**
 * Convert an {@code @IntRange} annotation to an {@code @IntVal} annotation, or to UNKNOWNVAL if
 * the input is too wide to be represented as an {@code @IntVal}.
 */
public AnnotationMirror convertIntRangeToIntVal(AnnotationMirror intRangeAnno) {
    Range range = getRange(intRangeAnno);
    List<Long> values = ValueCheckerUtils.getValuesFromRange(range, Long.class);
    return createIntValAnnotation(values);
}
Also used : IntRange(org.checkerframework.common.value.qual.IntRange) ArrayLenRange(org.checkerframework.common.value.qual.ArrayLenRange) Range(org.checkerframework.common.value.util.Range)

Aggregations

Range (org.checkerframework.common.value.util.Range)22 ArrayLenRange (org.checkerframework.common.value.qual.ArrayLenRange)15 IntRange (org.checkerframework.common.value.qual.IntRange)7 ArrayList (java.util.ArrayList)6 AnnotationMirror (javax.lang.model.element.AnnotationMirror)6 CFValue (org.checkerframework.framework.flow.CFValue)4 AnnotatedTypeMirror (org.checkerframework.framework.type.AnnotatedTypeMirror)4 List (java.util.List)3 StringConversionNode (org.checkerframework.dataflow.cfg.node.StringConversionNode)3 TypeKind (javax.lang.model.type.TypeKind)2 IntVal (org.checkerframework.common.value.qual.IntVal)2 Test (org.junit.Test)2 ArrayLen (org.checkerframework.common.value.qual.ArrayLen)1 BottomVal (org.checkerframework.common.value.qual.BottomVal)1 DoubleVal (org.checkerframework.common.value.qual.DoubleVal)1 StringVal (org.checkerframework.common.value.qual.StringVal)1 UnknownVal (org.checkerframework.common.value.qual.UnknownVal)1