Search in sources :

Example 1 with Unknown

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

the class LockVisitor method getLockExpressions.

private List<LockExpression> getLockExpressions(boolean implicitThis, AnnotationMirror gbAnno, Tree tree) {
    List<String> expressions = AnnotationUtils.getElementValueArray(gbAnno, "value", String.class, true);
    if (expressions.isEmpty()) {
        return Collections.emptyList();
    }
    TreePath currentPath = getCurrentPath();
    List<Receiver> params = FlowExpressions.getParametersOfEnclosingMethod(atypeFactory, currentPath);
    TypeMirror enclosingType = TreeUtils.typeOf(TreeUtils.enclosingClass(currentPath));
    Receiver pseudoReceiver = FlowExpressions.internalReprOfPseudoReceiver(currentPath, enclosingType);
    FlowExpressionContext exprContext = new FlowExpressionContext(pseudoReceiver, params, atypeFactory.getContext());
    Receiver self;
    if (implicitThis) {
        self = pseudoReceiver;
    } else if (TreeUtils.isExpressionTree(tree)) {
        self = FlowExpressions.internalReprOf(atypeFactory, (ExpressionTree) tree);
    } else {
        self = new Unknown(TreeUtils.typeOf(tree));
    }
    List<LockExpression> lockExpressions = new ArrayList<>();
    for (String expression : expressions) {
        lockExpressions.add(parseExpressionString(expression, exprContext, currentPath, self));
    }
    return lockExpressions;
}
Also used : TreePath(com.sun.source.util.TreePath) Unknown(org.checkerframework.dataflow.analysis.FlowExpressions.Unknown) GuardedByUnknown(org.checkerframework.checker.lock.qual.GuardedByUnknown) AnnotatedTypeMirror(org.checkerframework.framework.type.AnnotatedTypeMirror) TypeMirror(javax.lang.model.type.TypeMirror) FlowExpressionContext(org.checkerframework.framework.util.FlowExpressionParseUtil.FlowExpressionContext) ArrayList(java.util.ArrayList) Receiver(org.checkerframework.dataflow.analysis.FlowExpressions.Receiver)

Example 2 with Unknown

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

the class OffsetEquation method createOffsetFromNode.

private static void createOffsetFromNode(Node node, AnnotationProvider factory, OffsetEquation eq, char op) {
    Receiver r = FlowExpressions.internalReprOf(factory, node);
    if (r instanceof Unknown || r == null) {
        if (node instanceof NumericalAdditionNode) {
            createOffsetFromNode(((NumericalAdditionNode) node).getLeftOperand(), factory, eq, op);
            createOffsetFromNode(((NumericalAdditionNode) node).getRightOperand(), factory, eq, op);
        } else if (node instanceof NumericalSubtractionNode) {
            createOffsetFromNode(((NumericalSubtractionNode) node).getLeftOperand(), factory, eq, op);
            char other = op == '+' ? '-' : '+';
            createOffsetFromNode(((NumericalSubtractionNode) node).getRightOperand(), factory, eq, other);
        } else {
            eq.error = node.toString();
        }
    } else {
        eq.addTerm(op, r.toString());
    }
}
Also used : NumericalAdditionNode(org.checkerframework.dataflow.cfg.node.NumericalAdditionNode) Unknown(org.checkerframework.dataflow.analysis.FlowExpressions.Unknown) Receiver(org.checkerframework.dataflow.analysis.FlowExpressions.Receiver) NumericalSubtractionNode(org.checkerframework.dataflow.cfg.node.NumericalSubtractionNode)

Aggregations

Receiver (org.checkerframework.dataflow.analysis.FlowExpressions.Receiver)2 Unknown (org.checkerframework.dataflow.analysis.FlowExpressions.Unknown)2 TreePath (com.sun.source.util.TreePath)1 ArrayList (java.util.ArrayList)1 TypeMirror (javax.lang.model.type.TypeMirror)1 GuardedByUnknown (org.checkerframework.checker.lock.qual.GuardedByUnknown)1 NumericalAdditionNode (org.checkerframework.dataflow.cfg.node.NumericalAdditionNode)1 NumericalSubtractionNode (org.checkerframework.dataflow.cfg.node.NumericalSubtractionNode)1 AnnotatedTypeMirror (org.checkerframework.framework.type.AnnotatedTypeMirror)1 FlowExpressionContext (org.checkerframework.framework.util.FlowExpressionParseUtil.FlowExpressionContext)1