use of org.checkerframework.dataflow.analysis.FlowExpressions.Receiver in project checker-framework by typetools.
the class NullnessTransfer method strengthenAnnotationOfEqualTo.
/**
* {@inheritDoc}
*
* <p>Furthermore, this method refines the type to {@code NonNull} for the appropriate branch if
* an expression is compared to the {@code null} literal (listed as case 1 in the class
* description).
*/
@Override
protected TransferResult<NullnessValue, NullnessStore> strengthenAnnotationOfEqualTo(TransferResult<NullnessValue, NullnessStore> res, Node firstNode, Node secondNode, NullnessValue firstValue, NullnessValue secondValue, boolean notEqualTo) {
res = super.strengthenAnnotationOfEqualTo(res, firstNode, secondNode, firstValue, secondValue, notEqualTo);
if (firstNode instanceof NullLiteralNode) {
NullnessStore thenStore = res.getThenStore();
NullnessStore elseStore = res.getElseStore();
List<Node> secondParts = splitAssignments(secondNode);
for (Node secondPart : secondParts) {
Receiver secondInternal = FlowExpressions.internalReprOf(analysis.getTypeFactory(), secondPart);
if (CFAbstractStore.canInsertReceiver(secondInternal)) {
thenStore = thenStore == null ? res.getThenStore() : thenStore;
elseStore = elseStore == null ? res.getElseStore() : elseStore;
if (notEqualTo) {
thenStore.insertValue(secondInternal, NONNULL);
} else {
elseStore.insertValue(secondInternal, NONNULL);
}
}
}
Set<AnnotationMirror> secondAnnos = secondValue != null ? secondValue.getAnnotations() : AnnotationUtils.createAnnotationSet();
if (AnnotationUtils.containsSameByClass(secondAnnos, PolyNull.class) || AnnotationUtils.containsSameByClass(secondAnnos, PolyAll.class)) {
thenStore = thenStore == null ? res.getThenStore() : thenStore;
elseStore = elseStore == null ? res.getElseStore() : elseStore;
thenStore.setPolyNullNull(true);
}
if (thenStore != null) {
return new ConditionalTransferResult<>(res.getResultValue(), thenStore, elseStore);
}
}
return res;
}
use of org.checkerframework.dataflow.analysis.FlowExpressions.Receiver in project checker-framework by typetools.
the class RegexTransfer method handleMatcherGroupCount.
/**
* See whether possibleMatcher is a call of groupCount on a Matcher and possibleConstant is a
* constant. If so, annotate the matcher as constant + 1 if !isAlsoEqual constant if isAlsoEqual
*
* @param possibleMatcher the Node that might be a call of Matcher.groupCount()
* @param possibleConstant the Node that might be a constant
* @param isAlsoEqual whether the comparison operation is strict or reflexive
* @param in the TransferInput
* @param resultIn TransferResult
* @return the possibly refined output TransferResult
*/
private TransferResult<CFValue, CFStore> handleMatcherGroupCount(Node possibleMatcher, Node possibleConstant, boolean isAlsoEqual, TransferInput<CFValue, CFStore> in, TransferResult<CFValue, CFStore> resultIn) {
if (!(possibleMatcher instanceof MethodInvocationNode)) {
return resultIn;
}
if (!(possibleConstant instanceof IntegerLiteralNode)) {
return resultIn;
}
MethodAccessNode methodAccessNode = ((MethodInvocationNode) possibleMatcher).getTarget();
ExecutableElement method = methodAccessNode.getMethod();
Node receiver = methodAccessNode.getReceiver();
if (!isMatcherGroupCountMethod(method, receiver)) {
return resultIn;
}
Receiver matcherReceiver = FlowExpressions.internalReprOf(analysis.getTypeFactory(), receiver);
IntegerLiteralNode iln = (IntegerLiteralNode) possibleConstant;
int groupCount;
if (isAlsoEqual) {
groupCount = iln.getValue();
} else {
groupCount = iln.getValue() + 1;
}
CFStore thenStore = resultIn.getRegularStore();
CFStore elseStore = thenStore.copy();
ConditionalTransferResult<CFValue, CFStore> newResult = new ConditionalTransferResult<>(resultIn.getResultValue(), thenStore, elseStore);
RegexAnnotatedTypeFactory factory = (RegexAnnotatedTypeFactory) analysis.getTypeFactory();
AnnotationMirror regexAnnotation = factory.createRegexAnnotation(groupCount);
thenStore.insertValue(matcherReceiver, regexAnnotation);
return newResult;
}
use of org.checkerframework.dataflow.analysis.FlowExpressions.Receiver in project checker-framework by typetools.
the class LessThanTransfer method refineGTE.
/**
* Case 2.
*/
@Override
protected void refineGTE(Node left, AnnotationMirror leftAnno, Node right, AnnotationMirror rightAnno, CFStore store, TransferInput<CFValue, CFStore> in) {
// left >= right so right is less than left
// Refine right to @LessThan("left + 1")
LessThanAnnotatedTypeFactory factory = (LessThanAnnotatedTypeFactory) analysis.getTypeFactory();
// left > right so right is less than left
// Refine right to @LessThan("left")
Receiver leftRec = FlowExpressions.internalReprOf(factory, left);
if (leftRec != null && leftRec.isUnmodifiableByOtherCode()) {
List<String> lessThanExpressions = LessThanAnnotatedTypeFactory.getLessThanExpressions(rightAnno);
if (lessThanExpressions == null) {
// right is already bottom, nothing to refine.
return;
}
lessThanExpressions.add(leftRec.toString() + " + 1");
Receiver rightRec = FlowExpressions.internalReprOf(analysis.getTypeFactory(), right);
store.insertValue(rightRec, factory.createLessThanQualifier(lessThanExpressions));
}
}
use of org.checkerframework.dataflow.analysis.FlowExpressions.Receiver in project checker-framework by typetools.
the class LowerBoundTransfer method notEqualToValue.
/**
* Refines GTEN1 to NN if it is not equal to -1, and NN to Pos if it is not equal to 0.
* Implements case 7.
*
* @param mLiteral a potential literal
* @param otherNode the node on the other side of the ==/!=
* @param otherAnno the annotation of the other side of the ==/!=
*/
private void notEqualToValue(Node mLiteral, Node otherNode, AnnotationMirror otherAnno, CFStore store) {
Long integerLiteral = getExactValue(mLiteral.getTree(), aTypeFactory.getValueAnnotatedTypeFactory());
if (integerLiteral == null) {
return;
}
long intLiteral = integerLiteral.longValue();
if (intLiteral == 0) {
if (AnnotationUtils.areSameByClass(otherAnno, NonNegative.class)) {
List<Node> internals = splitAssignments(otherNode);
for (Node internal : internals) {
Receiver rec = FlowExpressions.internalReprOf(aTypeFactory, internal);
store.insertValue(rec, POS);
}
}
} else if (intLiteral == -1) {
if (AnnotationUtils.areSameByClass(otherAnno, GTENegativeOne.class)) {
List<Node> internals = splitAssignments(otherNode);
for (Node internal : internals) {
Receiver rec = FlowExpressions.internalReprOf(aTypeFactory, internal);
store.insertValue(rec, NN);
}
}
}
}
use of org.checkerframework.dataflow.analysis.FlowExpressions.Receiver in project checker-framework by typetools.
the class SameLenAnnotatedTypeFactory method createCombinedSameLen.
/**
* For the use of the transfer function; generates a SameLen that includes a and b, as well as
* everything in sl1 and sl2, if they are SameLen annotations.
*
* @param receivers a list of receivers representing arrays to be included in the combined
* annotation
* @param annos a list of the current annotations of the receivers. Must be the same length as
* receivers.
* @return a combined SameLen annotation
*/
public AnnotationMirror createCombinedSameLen(List<FlowExpressions.Receiver> receivers, List<AnnotationMirror> annos) {
assert receivers.size() == annos.size();
List<String> values = new ArrayList<>();
for (int i = 0; i < receivers.size(); i++) {
Receiver rec = receivers.get(i);
AnnotationMirror anno = annos.get(i);
if (shouldUseInAnnotation(rec)) {
values.add(rec.toString());
}
if (AnnotationUtils.areSameByClass(anno, SameLen.class)) {
values.addAll(getValueOfAnnotationWithStringArgument(anno));
}
}
AnnotationMirror res = getCombinedSameLen(values, new ArrayList<>());
return res;
}
Aggregations