Search in sources :

Example 1 with IntVal

use of org.checkerframework.common.value.qual.IntVal in project checker-framework by typetools.

the class ValueTransfer method getCharValues.

/**
 * Get possible char values from annotation @IntRange or @IntVal.
 */
private List<Character> getCharValues(Node subNode, TransferInput<CFValue, CFStore> p) {
    CFValue value = p.getValueOfSubNode(subNode);
    AnnotationMirror intAnno;
    intAnno = AnnotationUtils.getAnnotationByClass(value.getAnnotations(), IntVal.class);
    if (intAnno != null) {
        return ValueAnnotatedTypeFactory.getCharValues(intAnno);
    }
    if (atypefactory.isIntRange(value.getAnnotations())) {
        intAnno = atypefactory.getQualifierHierarchy().findAnnotationInHierarchy(value.getAnnotations(), atypefactory.UNKNOWNVAL);
        Range range = ValueAnnotatedTypeFactory.getRange(intAnno);
        return ValueCheckerUtils.getValuesFromRange(range, Character.class);
    }
    return new ArrayList<>();
}
Also used : CFValue(org.checkerframework.framework.flow.CFValue) AnnotationMirror(javax.lang.model.element.AnnotationMirror) IntVal(org.checkerframework.common.value.qual.IntVal) ArrayList(java.util.ArrayList) ArrayLenRange(org.checkerframework.common.value.qual.ArrayLenRange) Range(org.checkerframework.common.value.util.Range)

Example 2 with IntVal

use of org.checkerframework.common.value.qual.IntVal in project checker-framework by typetools.

the class ValueTransfer method refineAtLengthAccess.

/**
 * Transform @IntVal or @IntRange annotations of a array or string length into an @ArrayLen
 * or @ArrayLenRange annotation for the array or string.
 */
private void refineAtLengthAccess(Node lengthNode, Node receiverNode, CFStore store) {
    Receiver lengthRec = FlowExpressions.internalReprOf(analysis.getTypeFactory(), lengthNode);
    // not marked @Pure, then do not refine.
    if (lengthRec instanceof FlowExpressions.Unknown) {
        return;
    }
    CFValue value = store.getValue(lengthRec);
    if (value == null) {
        return;
    }
    AnnotationMirror lengthAnno = getValueAnnotation(value);
    if (lengthAnno == null) {
        return;
    }
    if (AnnotationUtils.areSameByClass(lengthAnno, BottomVal.class)) {
        // If the length is bottom, then this is dead code, so the receiver type
        // should also be bottom.
        Receiver receiver = FlowExpressions.internalReprOf(atypefactory, receiverNode);
        store.insertValue(receiver, lengthAnno);
        return;
    }
    RangeOrListOfValues rolv;
    if (atypefactory.isIntRange(lengthAnno)) {
        rolv = new RangeOrListOfValues(ValueAnnotatedTypeFactory.getRange(lengthAnno));
    } else if (AnnotationUtils.areSameByClass(lengthAnno, IntVal.class)) {
        List<Long> lengthValues = ValueAnnotatedTypeFactory.getIntValues(lengthAnno);
        rolv = new RangeOrListOfValues(RangeOrListOfValues.convertLongsToInts(lengthValues));
    } else {
        return;
    }
    AnnotationMirror newRecAnno = rolv.createAnnotation(atypefactory);
    AnnotationMirror oldRecAnno = getArrayOrStringAnnotation(receiverNode);
    AnnotationMirror combinedRecAnno;
    // with the facts known about its length using GLB.
    if (oldRecAnno == null) {
        combinedRecAnno = newRecAnno;
    } else {
        combinedRecAnno = atypefactory.getQualifierHierarchy().greatestLowerBound(oldRecAnno, newRecAnno);
    }
    Receiver receiver = FlowExpressions.internalReprOf(analysis.getTypeFactory(), receiverNode);
    store.insertValue(receiver, combinedRecAnno);
}
Also used : CFValue(org.checkerframework.framework.flow.CFValue) AnnotationMirror(javax.lang.model.element.AnnotationMirror) IntVal(org.checkerframework.common.value.qual.IntVal) Receiver(org.checkerframework.dataflow.analysis.FlowExpressions.Receiver) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

ArrayList (java.util.ArrayList)2 AnnotationMirror (javax.lang.model.element.AnnotationMirror)2 IntVal (org.checkerframework.common.value.qual.IntVal)2 CFValue (org.checkerframework.framework.flow.CFValue)2 List (java.util.List)1 ArrayLenRange (org.checkerframework.common.value.qual.ArrayLenRange)1 Range (org.checkerframework.common.value.util.Range)1 Receiver (org.checkerframework.dataflow.analysis.FlowExpressions.Receiver)1