use of org.checkerframework.dataflow.analysis.FlowExpressions.Receiver in project checker-framework by typetools.
the class SameLenAnnotatedTypeFactory method getAnnotatedTypeLhs.
/**
* Handles case 2.
*/
@Override
public AnnotatedTypeMirror getAnnotatedTypeLhs(Tree tree) {
AnnotatedTypeMirror atm = super.getAnnotatedTypeLhs(tree);
if (tree.getKind() == Tree.Kind.VARIABLE) {
Receiver r;
try {
r = FlowExpressionParseUtil.internalReprOfVariable(this, (VariableTree) tree);
} catch (FlowExpressionParseException ex) {
r = null;
}
if (r != null) {
String varName = r.toString();
AnnotationMirror anm = atm.getAnnotation(SameLen.class);
if (anm != null) {
List<String> slArrays = IndexUtil.getValueOfAnnotationWithStringArgument(anm);
if (slArrays.contains(varName)) {
slArrays.remove(varName);
}
if (slArrays.size() == 0) {
atm.replaceAnnotation(UNKNOWN);
} else {
atm.replaceAnnotation(createSameLen(slArrays.toArray(new String[0])));
}
}
}
}
return atm;
}
use of org.checkerframework.dataflow.analysis.FlowExpressions.Receiver in project checker-framework by typetools.
the class SameLenTransfer method propagateCombinedSameLen.
/**
* Insert combinedSameLen into the store as the SameLen type of each array listed in
* combinedSameLen.
*
* @param combinedSameLen a Samelen annotation. Not just an annotation in the SameLen hierarchy;
* this annotation MUST be @SameLen().
* @param node the node in the tree where the combination is happening. Used for context.
* @param store the store to modify
*/
private void propagateCombinedSameLen(AnnotationMirror combinedSameLen, Node node, CFStore store) {
TreePath currentPath = aTypeFactory.getPath(node.getTree());
if (currentPath == null) {
return;
}
for (String s : IndexUtil.getValueOfAnnotationWithStringArgument(combinedSameLen)) {
Receiver recS;
try {
recS = aTypeFactory.getReceiverFromJavaExpressionString(s, currentPath);
} catch (FlowExpressionParseUtil.FlowExpressionParseException e) {
continue;
}
store.clearValue(recS);
store.insertValue(recS, combinedSameLen);
}
}
use of org.checkerframework.dataflow.analysis.FlowExpressions.Receiver in project checker-framework by typetools.
the class AliasingTransfer method visitAssignment.
/**
* Case 1: For every assignment, the LHS is refined if the RHS has type {@literal @}Unique and
* is a method invocation or a new class instance.
*/
@Override
public TransferResult<CFValue, CFStore> visitAssignment(AssignmentNode n, TransferInput<CFValue, CFStore> in) {
Node rhs = n.getExpression();
Tree treeRhs = rhs.getTree();
AnnotatedTypeMirror rhsType = factory.getAnnotatedType(treeRhs);
if (rhsType.hasAnnotation(Unique.class) && (rhs instanceof MethodInvocationNode || rhs instanceof ObjectCreationNode)) {
// Do normal refinement.
return super.visitAssignment(n, in);
}
// Widen the type of the rhs if the RHS's declared type wasn't @Unique.
Receiver r = FlowExpressions.internalReprOf(factory, rhs);
in.getRegularStore().clearValue(r);
return new RegularTransferResult<>(null, in.getRegularStore());
}
use of org.checkerframework.dataflow.analysis.FlowExpressions.Receiver in project checker-framework by typetools.
the class DependentTypesHelper method standardizeExpression.
public void standardizeExpression(ExpressionTree tree, AnnotatedTypeMirror annotatedType) {
if (!hasDependentType(annotatedType)) {
return;
}
TreePath path = factory.getPath(tree);
if (path == null) {
return;
}
Tree enclosingClass = TreeUtils.enclosingClass(path);
if (enclosingClass == null) {
return;
}
TypeMirror enclosingType = TreeUtils.typeOf(enclosingClass);
FlowExpressions.Receiver receiver = FlowExpressions.internalReprOfPseudoReceiver(path, enclosingType);
FlowExpressionContext localContext = new FlowExpressionContext(receiver, FlowExpressions.getParametersOfEnclosingMethod(factory, path), factory.getContext());
standardizeUseLocals(localContext, path, annotatedType);
}
use of org.checkerframework.dataflow.analysis.FlowExpressions.Receiver in project checker-framework by typetools.
the class DependentTypesHelper method standardizeFieldAccess.
public void standardizeFieldAccess(MemberSelectTree node, AnnotatedTypeMirror type) {
if (!hasDependentType(type)) {
return;
}
if (TreeUtils.isClassLiteral(node)) {
return;
}
Element ele = TreeUtils.elementFromUse(node);
if (ele.getKind() != ElementKind.FIELD) {
return;
}
FlowExpressions.Receiver receiver = FlowExpressions.internalReprOf(factory, node.getExpression());
FlowExpressionContext context = new FlowExpressionContext(receiver, null, factory.getContext());
standardizeDoNotUseLocals(context, factory.getPath(node), type);
}
Aggregations