Search in sources :

Example 11 with RegularTransferResult

use of org.checkerframework.dataflow.analysis.RegularTransferResult in project bazel by bazelbuild.

the class ConstantPropagationTransfer method visitAssignment.

@Override
public TransferResult<Constant, ConstantPropagationStore> visitAssignment(AssignmentNode n, TransferInput<Constant, ConstantPropagationStore> pi) {
    ConstantPropagationStore p = pi.getRegularStore();
    Node target = n.getTarget();
    Constant info = null;
    if (target instanceof LocalVariableNode) {
        LocalVariableNode t = (LocalVariableNode) target;
        info = p.getInformation(n.getExpression());
        p.setInformation(t, info);
    }
    return new RegularTransferResult<>(info, p);
}
Also used : IntegerLiteralNode(org.checkerframework.dataflow.cfg.node.IntegerLiteralNode) AssignmentNode(org.checkerframework.dataflow.cfg.node.AssignmentNode) LocalVariableNode(org.checkerframework.dataflow.cfg.node.LocalVariableNode) EqualToNode(org.checkerframework.dataflow.cfg.node.EqualToNode) Node(org.checkerframework.dataflow.cfg.node.Node) LocalVariableNode(org.checkerframework.dataflow.cfg.node.LocalVariableNode) RegularTransferResult(org.checkerframework.dataflow.analysis.RegularTransferResult)

Example 12 with RegularTransferResult

use of org.checkerframework.dataflow.analysis.RegularTransferResult in project checker-framework by typetools.

the class CFAbstractTransfer method visitThisLiteral.

@Override
public TransferResult<V, S> visitThisLiteral(ThisLiteralNode n, TransferInput<V, S> in) {
    S store = in.getRegularStore();
    V valueFromStore = store.getValue(n);
    V valueFromFactory = null;
    V value = null;
    Tree tree = n.getTree();
    if (tree != null && TreeUtils.canHaveTypeAnnotation(tree)) {
        valueFromFactory = getValueFromFactory(tree, n);
    }
    if (valueFromFactory == null) {
        value = valueFromStore;
    } else {
        value = moreSpecificValue(valueFromFactory, valueFromStore);
    }
    return new RegularTransferResult<>(finishValue(value, store), store);
}
Also used : MethodTree(com.sun.source.tree.MethodTree) VariableTree(com.sun.source.tree.VariableTree) Tree(com.sun.source.tree.Tree) ClassTree(com.sun.source.tree.ClassTree) RegularTransferResult(org.checkerframework.dataflow.analysis.RegularTransferResult)

Example 13 with RegularTransferResult

use of org.checkerframework.dataflow.analysis.RegularTransferResult 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;
}
Also used : CFValue(org.checkerframework.framework.flow.CFValue) AnnotationMirror(javax.lang.model.element.AnnotationMirror) CFStore(org.checkerframework.framework.flow.CFStore) RegularTransferResult(org.checkerframework.dataflow.analysis.RegularTransferResult)

Example 14 with RegularTransferResult

use of org.checkerframework.dataflow.analysis.RegularTransferResult 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.
    JavaExpression rhsExpr = JavaExpression.fromNode(rhs);
    in.getRegularStore().clearValue(rhsExpr);
    return new RegularTransferResult<>(null, in.getRegularStore());
}
Also used : JavaExpression(org.checkerframework.dataflow.expression.JavaExpression) MethodInvocationNode(org.checkerframework.dataflow.cfg.node.MethodInvocationNode) ObjectCreationNode(org.checkerframework.dataflow.cfg.node.ObjectCreationNode) MethodInvocationNode(org.checkerframework.dataflow.cfg.node.MethodInvocationNode) AssignmentNode(org.checkerframework.dataflow.cfg.node.AssignmentNode) Node(org.checkerframework.dataflow.cfg.node.Node) ObjectCreationNode(org.checkerframework.dataflow.cfg.node.ObjectCreationNode) Tree(com.sun.source.tree.Tree) Unique(org.checkerframework.common.aliasing.qual.Unique) AnnotatedTypeMirror(org.checkerframework.framework.type.AnnotatedTypeMirror) RegularTransferResult(org.checkerframework.dataflow.analysis.RegularTransferResult)

Example 15 with RegularTransferResult

use of org.checkerframework.dataflow.analysis.RegularTransferResult in project checker-framework by typetools.

the class UpperBoundTransfer method visitIntegerLiteral.

@Override
public TransferResult<CFValue, CFStore> visitIntegerLiteral(IntegerLiteralNode n, TransferInput<CFValue, CFStore> pi) {
    TransferResult<CFValue, CFStore> result = super.visitIntegerLiteral(n, pi);
    int intValue = n.getValue();
    AnnotationMirror newAnno;
    switch(intValue) {
        case 0:
            newAnno = atypeFactory.ZERO;
            break;
        case -1:
            newAnno = atypeFactory.NEGATIVEONE;
            break;
        default:
            return result;
    }
    CFValue c = new CFValue(analysis, Collections.singleton(newAnno), intTM);
    return new RegularTransferResult<>(c, result.getRegularStore());
}
Also used : CFValue(org.checkerframework.framework.flow.CFValue) AnnotationMirror(javax.lang.model.element.AnnotationMirror) CFStore(org.checkerframework.framework.flow.CFStore) RegularTransferResult(org.checkerframework.dataflow.analysis.RegularTransferResult)

Aggregations

RegularTransferResult (org.checkerframework.dataflow.analysis.RegularTransferResult)18 AssignmentNode (org.checkerframework.dataflow.cfg.node.AssignmentNode)8 Node (org.checkerframework.dataflow.cfg.node.Node)8 AnnotationMirror (javax.lang.model.element.AnnotationMirror)7 MethodInvocationNode (org.checkerframework.dataflow.cfg.node.MethodInvocationNode)6 ObjectCreationNode (org.checkerframework.dataflow.cfg.node.ObjectCreationNode)6 CFValue (org.checkerframework.framework.flow.CFValue)6 ReturnNode (org.checkerframework.dataflow.cfg.node.ReturnNode)5 StringConcatenateAssignmentNode (org.checkerframework.dataflow.cfg.node.StringConcatenateAssignmentNode)5 JavaExpression (org.checkerframework.dataflow.expression.JavaExpression)5 Tree (com.sun.source.tree.Tree)4 EqualToNode (org.checkerframework.dataflow.cfg.node.EqualToNode)4 LocalVariableNode (org.checkerframework.dataflow.cfg.node.LocalVariableNode)4 CFStore (org.checkerframework.framework.flow.CFStore)4 ClassTree (com.sun.source.tree.ClassTree)3 MethodTree (com.sun.source.tree.MethodTree)3 ExpressionTree (com.sun.source.tree.ExpressionTree)2 ConditionalTransferResult (org.checkerframework.dataflow.analysis.ConditionalTransferResult)2 ArrayAccessNode (org.checkerframework.dataflow.cfg.node.ArrayAccessNode)2 CaseNode (org.checkerframework.dataflow.cfg.node.CaseNode)2