use of org.checkerframework.framework.flow.CFValue in project checker-framework by typetools.
the class LockStore method updateForMethodCall.
@Override
public void updateForMethodCall(MethodInvocationNode n, AnnotatedTypeFactory atypeFactory, CFValue val) {
super.updateForMethodCall(n, atypeFactory, val);
ExecutableElement method = n.getTarget().getMethod();
if (!isSideEffectFree(atypeFactory, method)) {
// the GuardedBy hierarchy should not be changed.
for (FieldAccess field : new ArrayList<>(fieldValues.keySet())) {
fieldValues.put(field, changeLockAnnoToTop(field, fieldValues.get(field)));
}
// Local variables could also be unlocked via an alias
for (LocalVariable var : new ArrayList<>(localVariableValues.keySet())) {
CFValue newValue = changeLockAnnoToTop(var, localVariableValues.get(var));
localVariableValues.put(var, newValue);
}
if (thisValue != null) {
thisValue = changeLockAnnoToTop(null, thisValue);
}
}
}
use of org.checkerframework.framework.flow.CFValue in project checker-framework by typetools.
the class LockStore method insertLockPossiblyHeld.
/*
* Insert an annotation exactly, without regard to whether an annotation was already present.
* This is only done for @LockPossiblyHeld. This is not sound for other type qualifiers.
*/
public void insertLockPossiblyHeld(FlowExpressions.Receiver r) {
if (r.containsUnknown()) {
// Expressions containing unknown expressions are not stored.
return;
}
if (r instanceof FlowExpressions.LocalVariable) {
FlowExpressions.LocalVariable localVar = (FlowExpressions.LocalVariable) r;
CFValue current = localVariableValues.get(localVar);
CFValue value = changeLockAnnoToTop(r, current);
localVariableValues.put(localVar, value);
} else if (r instanceof FlowExpressions.FieldAccess) {
FlowExpressions.FieldAccess fieldAcc = (FlowExpressions.FieldAccess) r;
CFValue current = fieldValues.get(fieldAcc);
CFValue value = changeLockAnnoToTop(r, current);
fieldValues.put(fieldAcc, value);
} else if (r instanceof FlowExpressions.MethodCall) {
FlowExpressions.MethodCall method = (FlowExpressions.MethodCall) r;
CFValue current = methodValues.get(method);
CFValue value = changeLockAnnoToTop(r, current);
methodValues.put(method, value);
} else if (r instanceof FlowExpressions.ArrayAccess) {
FlowExpressions.ArrayAccess arrayAccess = (ArrayAccess) r;
CFValue current = arrayValues.get(arrayAccess);
CFValue value = changeLockAnnoToTop(r, current);
arrayValues.put(arrayAccess, value);
} else if (r instanceof FlowExpressions.ThisReference) {
thisValue = changeLockAnnoToTop(r, thisValue);
} else if (r instanceof FlowExpressions.ClassName) {
FlowExpressions.ClassName className = (FlowExpressions.ClassName) r;
CFValue current = classValues.get(className);
CFValue value = changeLockAnnoToTop(r, current);
classValues.put(className, value);
} else {
// No other types of expressions need to be stored.
}
}
use of org.checkerframework.framework.flow.CFValue 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.framework.flow.CFValue in project checker-framework by typetools.
the class FormatterTransfer method visitMethodInvocation.
/**
* Makes it so that the {@link FormatUtil#asFormat} method returns a correctly annotated String.
*/
@Override
public TransferResult<CFValue, CFStore> visitMethodInvocation(MethodInvocationNode node, TransferInput<CFValue, CFStore> in) {
FormatterAnnotatedTypeFactory atypeFactory = (FormatterAnnotatedTypeFactory) analysis.getTypeFactory();
TransferResult<CFValue, CFStore> result = super.visitMethodInvocation(node, in);
FormatterTreeUtil tu = atypeFactory.treeUtil;
if (tu.isAsFormatCall(node, atypeFactory)) {
Result<ConversionCategory[]> cats = tu.asFormatCallCategories(node);
if (cats.value() == null) {
tu.failure(cats, "format.asformat.indirect.arguments");
} else {
AnnotationMirror anno = atypeFactory.treeUtil.categoriesToFormatAnnotation(cats.value());
CFValue newResultValue = analysis.createSingleAnnotationValue(anno, result.getResultValue().getUnderlyingType());
return new RegularTransferResult<>(newResultValue, result.getRegularStore());
}
}
return result;
}
use of org.checkerframework.framework.flow.CFValue in project checker-framework by typetools.
the class LowerBoundTransfer method visitIntegerDivision.
@Override
public TransferResult<CFValue, CFStore> visitIntegerDivision(IntegerDivisionNode n, TransferInput<CFValue, CFStore> p) {
TransferResult<CFValue, CFStore> result = super.visitIntegerDivision(n, p);
AnnotationMirror newAnno = getAnnotationForDivide(n, p);
return createNewResult(result, newAnno);
}
Aggregations