Search in sources :

Example 26 with Receiver

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

the class NullnessTransfer method makeNonNull.

/**
 * Sets a given {@link Node} to non-null in the given {@code store}. Calls to this method
 * implement case 2.
 */
protected void makeNonNull(NullnessStore store, Node node) {
    Receiver internalRepr = FlowExpressions.internalReprOf(analysis.getTypeFactory(), node);
    store.insertValue(internalRepr, NONNULL);
}
Also used : Receiver(org.checkerframework.dataflow.analysis.FlowExpressions.Receiver)

Example 27 with Receiver

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

the class RegexTransfer method handleRegexUtil.

private TransferResult<CFValue, CFStore> handleRegexUtil(MethodInvocationNode n, ExecutableElement method, TransferResult<CFValue, CFStore> result) {
    RegexAnnotatedTypeFactory factory = (RegexAnnotatedTypeFactory) analysis.getTypeFactory();
    if (ElementUtils.matchesElement(method, IS_REGEX_METHOD_NAME, String.class, int.class)) {
        // RegexUtil.isRegex(s, groups) method
        // (No special case is needed for isRegex(String) because of
        // the annotation on that method's definition.)
        CFStore thenStore = result.getRegularStore();
        CFStore elseStore = thenStore.copy();
        ConditionalTransferResult<CFValue, CFStore> newResult = new ConditionalTransferResult<>(result.getResultValue(), thenStore, elseStore);
        Receiver firstParam = FlowExpressions.internalReprOf(factory.getContext().getAnnotationProvider(), n.getArgument(0));
        // add annotation with correct group count (if possible,
        // regex annotation without count otherwise)
        Node count = n.getArgument(1);
        int groupCount;
        if (count instanceof IntegerLiteralNode) {
            IntegerLiteralNode iln = (IntegerLiteralNode) count;
            groupCount = iln.getValue();
        } else {
            groupCount = 0;
        }
        AnnotationMirror regexAnnotation = factory.createRegexAnnotation(groupCount);
        thenStore.insertValue(firstParam, regexAnnotation);
        return newResult;
    } else if (ElementUtils.matchesElement(method, AS_REGEX_METHOD_NAME, String.class, int.class)) {
        // RegexUtil.asRegex(s, groups) method
        // (No special case is needed for asRegex(String) because of
        // the annotation on that method's definition.)
        // add annotation with correct group count (if possible,
        // regex annotation without count otherwise)
        AnnotationMirror regexAnnotation;
        Node count = n.getArgument(1);
        int groupCount;
        if (count instanceof IntegerLiteralNode) {
            IntegerLiteralNode iln = (IntegerLiteralNode) count;
            groupCount = iln.getValue();
        } else {
            groupCount = 0;
        }
        regexAnnotation = factory.createRegexAnnotation(groupCount);
        CFValue newResultValue = analysis.createSingleAnnotationValue(regexAnnotation, 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) ConditionalTransferResult(org.checkerframework.dataflow.analysis.ConditionalTransferResult) MethodAccessNode(org.checkerframework.dataflow.cfg.node.MethodAccessNode) ClassNameNode(org.checkerframework.dataflow.cfg.node.ClassNameNode) LessThanNode(org.checkerframework.dataflow.cfg.node.LessThanNode) MethodInvocationNode(org.checkerframework.dataflow.cfg.node.MethodInvocationNode) IntegerLiteralNode(org.checkerframework.dataflow.cfg.node.IntegerLiteralNode) GreaterThanNode(org.checkerframework.dataflow.cfg.node.GreaterThanNode) LessThanOrEqualNode(org.checkerframework.dataflow.cfg.node.LessThanOrEqualNode) GreaterThanOrEqualNode(org.checkerframework.dataflow.cfg.node.GreaterThanOrEqualNode) Node(org.checkerframework.dataflow.cfg.node.Node) Receiver(org.checkerframework.dataflow.analysis.FlowExpressions.Receiver) IntegerLiteralNode(org.checkerframework.dataflow.cfg.node.IntegerLiteralNode)

Example 28 with Receiver

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

the class I18nFormatterTransfer method visitMethodInvocation.

@Override
public TransferResult<CFValue, CFStore> visitMethodInvocation(MethodInvocationNode node, TransferInput<CFValue, CFStore> in) {
    I18nFormatterAnnotatedTypeFactory atypeFactory = (I18nFormatterAnnotatedTypeFactory) analysis.getTypeFactory();
    TransferResult<CFValue, CFStore> result = super.visitMethodInvocation(node, in);
    I18nFormatterTreeUtil tu = atypeFactory.treeUtil;
    // If hasFormat is called, make sure that the format string is annotated correctly
    if (tu.isHasFormatCall(node, atypeFactory)) {
        CFStore thenStore = result.getRegularStore();
        CFStore elseStore = thenStore.copy();
        ConditionalTransferResult<CFValue, CFStore> newResult = new ConditionalTransferResult<>(result.getResultValue(), thenStore, elseStore);
        Result<I18nConversionCategory[]> cats = tu.getHasFormatCallCategories(node);
        if (cats.value() == null) {
            tu.failure(cats, "i18nformat.indirect.arguments");
        } else {
            Receiver firstParam = FlowExpressions.internalReprOf(atypeFactory, node.getArgument(0));
            AnnotationMirror anno = atypeFactory.treeUtil.categoriesToFormatAnnotation(cats.value());
            thenStore.insertValue(firstParam, anno);
        }
        return newResult;
    }
    // If isFormat is called, annotate the format string with I18nInvalidFormat
    if (tu.isIsFormatCall(node, atypeFactory)) {
        CFStore thenStore = result.getRegularStore();
        CFStore elseStore = thenStore.copy();
        ConditionalTransferResult<CFValue, CFStore> newResult = new ConditionalTransferResult<>(result.getResultValue(), thenStore, elseStore);
        Receiver firstParam = FlowExpressions.internalReprOf(atypeFactory, node.getArgument(0));
        AnnotationBuilder builder = new AnnotationBuilder(tu.processingEnv, I18nInvalidFormat.class.getCanonicalName());
        // No need to set a value of @I18nInvalidFormat
        builder.setValue("value", "");
        elseStore.insertValue(firstParam, builder.build());
        return newResult;
    }
    // corresponding key's value
    if (tu.isMakeFormatCall(node, atypeFactory)) {
        Result<I18nConversionCategory[]> cats = tu.makeFormatCallCategories(node, atypeFactory);
        if (cats.value() == null) {
            tu.failure(cats, "i18nformat.key.not.found");
        } 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 : CFStore(org.checkerframework.framework.flow.CFStore) ConditionalTransferResult(org.checkerframework.dataflow.analysis.ConditionalTransferResult) Receiver(org.checkerframework.dataflow.analysis.FlowExpressions.Receiver) CFValue(org.checkerframework.framework.flow.CFValue) AnnotationMirror(javax.lang.model.element.AnnotationMirror) AnnotationBuilder(org.checkerframework.javacutil.AnnotationBuilder) I18nInvalidFormat(org.checkerframework.checker.i18nformatter.qual.I18nInvalidFormat) RegularTransferResult(org.checkerframework.dataflow.analysis.RegularTransferResult)

Example 29 with Receiver

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

the class LessThanTransfer method refineGT.

/**
 * Case 1.
 */
@Override
protected void refineGT(Node left, AnnotationMirror leftAnno, Node right, AnnotationMirror rightAnno, CFStore store, TransferInput<CFValue, CFStore> in) {
    LessThanAnnotatedTypeFactory factory = (LessThanAnnotatedTypeFactory) analysis.getTypeFactory();
    // left > right so right < left
    // Refine right to @LessThan("left")
    Receiver leftRec = FlowExpressions.internalReprOf(factory, left);
    if (leftRec != null && leftRec.isUnmodifiableByOtherCode()) {
        List<String> lessThanExpressions = LessThanAnnotatedTypeFactory.getLessThanExpressions(rightAnno);
        if (lessThanExpressions == null) {
            // right is already bottom, nothing to refine.
            return;
        }
        lessThanExpressions.add(leftRec.toString());
        Receiver rightRec = FlowExpressions.internalReprOf(analysis.getTypeFactory(), right);
        store.insertValue(rightRec, factory.createLessThanQualifier(lessThanExpressions));
    }
}
Also used : Receiver(org.checkerframework.dataflow.analysis.FlowExpressions.Receiver)

Example 30 with Receiver

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

the class LowerBoundTransfer method refineGTE.

/**
 * Refines left to exactly the level of right, since in the worst case they're equal. Modifies
 * an existing type in the store, but has to be careful not to overwrite a more precise existing
 * type.
 *
 * <p>This implements parts of cases 1, 2, 3, and 4 using the decomposition strategy described
 * in this class's Javadoc.
 */
@Override
protected void refineGTE(Node left, AnnotationMirror leftAnno, Node right, AnnotationMirror rightAnno, CFStore store, TransferInput<CFValue, CFStore> in) {
    if (rightAnno == null || leftAnno == null) {
        return;
    }
    Receiver leftRec = FlowExpressions.internalReprOf(aTypeFactory, left);
    AnnotationMirror newLBType = aTypeFactory.getQualifierHierarchy().greatestLowerBound(rightAnno, leftAnno);
    store.insertValue(leftRec, newLBType);
}
Also used : AnnotationMirror(javax.lang.model.element.AnnotationMirror) Receiver(org.checkerframework.dataflow.analysis.FlowExpressions.Receiver)

Aggregations

Receiver (org.checkerframework.dataflow.analysis.FlowExpressions.Receiver)55 AnnotationMirror (javax.lang.model.element.AnnotationMirror)19 Node (org.checkerframework.dataflow.cfg.node.Node)15 MethodInvocationNode (org.checkerframework.dataflow.cfg.node.MethodInvocationNode)14 FieldAccessNode (org.checkerframework.dataflow.cfg.node.FieldAccessNode)10 CFValue (org.checkerframework.framework.flow.CFValue)9 FlowExpressions (org.checkerframework.dataflow.analysis.FlowExpressions)8 FieldAccess (org.checkerframework.dataflow.analysis.FlowExpressions.FieldAccess)8 NumericalAdditionNode (org.checkerframework.dataflow.cfg.node.NumericalAdditionNode)8 NumericalSubtractionNode (org.checkerframework.dataflow.cfg.node.NumericalSubtractionNode)8 ArrayList (java.util.ArrayList)7 TypeMirror (javax.lang.model.type.TypeMirror)7 ClassName (org.checkerframework.dataflow.analysis.FlowExpressions.ClassName)7 AssignmentNode (org.checkerframework.dataflow.cfg.node.AssignmentNode)7 Tree (com.sun.source.tree.Tree)6 TreePath (com.sun.source.util.TreePath)6 ArrayCreationNode (org.checkerframework.dataflow.cfg.node.ArrayCreationNode)6 AnnotatedTypeMirror (org.checkerframework.framework.type.AnnotatedTypeMirror)6 MethodTree (com.sun.source.tree.MethodTree)5 CaseNode (org.checkerframework.dataflow.cfg.node.CaseNode)5