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<>();
}
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);
}
Aggregations