use of org.checkerframework.framework.flow.CFStore in project checker-framework by typetools.
the class SameLenTransfer method strengthenAnnotationOfEqualTo.
/**
* Implements the transfer rules for both equal nodes and not-equals nodes.
*/
@Override
protected TransferResult<CFValue, CFStore> strengthenAnnotationOfEqualTo(TransferResult<CFValue, CFStore> result, Node firstNode, Node secondNode, CFValue firstValue, CFValue secondValue, boolean notEqualTo) {
CFStore equalStore = notEqualTo ? result.getElseStore() : result.getThenStore();
Node firstLengthReceiver = getLengthNodeReceiver(firstNode);
Node secondLengthReceiver = getLengthNodeReceiver(secondNode);
if (firstLengthReceiver != null && secondLengthReceiver != null) {
// Refinement in the else store if this is a.length == b.length (or length() in case of
// strings).
refineEq(firstLengthReceiver, secondLengthReceiver, equalStore);
} else if (IndexUtil.isSequenceType(firstNode.getType()) || IndexUtil.isSequenceType(secondNode.getType())) {
refineEq(firstNode, secondNode, equalStore);
}
return new ConditionalTransferResult<>(result.getResultValue(), result.getThenStore(), result.getElseStore());
}
use of org.checkerframework.framework.flow.CFStore in project checker-framework by typetools.
the class AliasingTransfer method visitMethodInvocation.
/**
* Case 3: Given a method invocation expression, if the parent of the expression is not a
* statement, check if there are any arguments of the method call annotated as
* {@literal @}LeakedToResult and remove it from the store, since it might be leaked.
*/
@Override
public TransferResult<CFValue, CFStore> visitMethodInvocation(MethodInvocationNode n, TransferInput<CFValue, CFStore> in) {
Tree parent = n.getTreePath().getParentPath().getLeaf();
boolean parentIsStatement = parent.getKind() == Kind.EXPRESSION_STATEMENT;
if (!parentIsStatement) {
ExecutableElement methodElement = TreeUtils.elementFromUse(n.getTree());
List<Node> args = n.getArguments();
List<? extends VariableElement> params = methodElement.getParameters();
assert (args.size() == params.size()) : "Number of arguments in " + "the method call " + n.toString() + " is different from the" + " number of parameters for the method declaration: " + methodElement.getSimpleName().toString();
CFStore store = in.getRegularStore();
for (int i = 0; i < args.size(); i++) {
Node arg = args.get(i);
VariableElement param = params.get(i);
if (factory.getAnnotatedType(param).hasAnnotation(LeakedToResult.class)) {
// If argument can leak to result, and parent is not a
// single statement, remove that node from store.
store.clearValue(FlowExpressions.internalReprOf(factory, arg));
}
}
// Now, doing the same as above for the receiver parameter
Node receiver = n.getTarget().getReceiver();
AnnotatedExecutableType annotatedType = factory.getAnnotatedType(methodElement);
AnnotatedDeclaredType receiverType = annotatedType.getReceiverType();
if (receiverType != null && receiverType.hasAnnotation(LeakedToResult.class)) {
store.clearValue(FlowExpressions.internalReprOf(factory, receiver));
}
}
// pseudo-assignments.
return super.visitMethodInvocation(n, in);
}
use of org.checkerframework.framework.flow.CFStore in project checker-framework by typetools.
the class ValueTransfer method visitFloatingRemainder.
@Override
public TransferResult<CFValue, CFStore> visitFloatingRemainder(FloatingRemainderNode n, TransferInput<CFValue, CFStore> p) {
TransferResult<CFValue, CFStore> transferResult = super.visitFloatingRemainder(n, p);
AnnotationMirror resultAnno = calculateNumericalBinaryOp(n.getLeftOperand(), n.getRightOperand(), NumericalBinaryOps.REMAINDER, p);
return createNewResult(transferResult, resultAnno);
}
use of org.checkerframework.framework.flow.CFStore in project checker-framework by typetools.
the class ValueTransfer method visitBitwiseAnd.
@Override
public TransferResult<CFValue, CFStore> visitBitwiseAnd(BitwiseAndNode n, TransferInput<CFValue, CFStore> p) {
TransferResult<CFValue, CFStore> transferResult = super.visitBitwiseAnd(n, p);
AnnotationMirror resultAnno = calculateNumericalBinaryOp(n.getLeftOperand(), n.getRightOperand(), NumericalBinaryOps.BITWISE_AND, p);
return createNewResult(transferResult, resultAnno);
}
use of org.checkerframework.framework.flow.CFStore in project checker-framework by typetools.
the class ValueTransfer method visitFloatingDivision.
@Override
public TransferResult<CFValue, CFStore> visitFloatingDivision(FloatingDivisionNode n, TransferInput<CFValue, CFStore> p) {
TransferResult<CFValue, CFStore> transferResult = super.visitFloatingDivision(n, p);
AnnotationMirror resultAnno = calculateNumericalBinaryOp(n.getLeftOperand(), n.getRightOperand(), NumericalBinaryOps.DIVISION, p);
return createNewResult(transferResult, resultAnno);
}
Aggregations