Search in sources :

Example 16 with CFStore

use of org.checkerframework.framework.flow.CFStore 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 17 with CFStore

use of org.checkerframework.framework.flow.CFStore 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 18 with CFStore

use of org.checkerframework.framework.flow.CFStore in project checker-framework by typetools.

the class LowerBoundTransfer method visitUnsignedRightShift.

@Override
public TransferResult<CFValue, CFStore> visitUnsignedRightShift(UnsignedRightShiftNode n, TransferInput<CFValue, CFStore> p) {
    TransferResult<CFValue, CFStore> transferResult = super.visitUnsignedRightShift(n, p);
    AnnotationMirror resultAnno = getAnnotationForRightShift(n, p);
    return createNewResult(transferResult, resultAnno);
}
Also used : CFValue(org.checkerframework.framework.flow.CFValue) AnnotationMirror(javax.lang.model.element.AnnotationMirror) CFStore(org.checkerframework.framework.flow.CFStore)

Example 19 with CFStore

use of org.checkerframework.framework.flow.CFStore in project checker-framework by typetools.

the class LowerBoundTransfer method visitNumericalMultiplication.

@Override
public TransferResult<CFValue, CFStore> visitNumericalMultiplication(NumericalMultiplicationNode n, TransferInput<CFValue, CFStore> p) {
    TransferResult<CFValue, CFStore> result = super.visitNumericalMultiplication(n, p);
    AnnotationMirror newAnno = getAnnotationForMultiply(n, p);
    return createNewResult(result, newAnno);
}
Also used : CFValue(org.checkerframework.framework.flow.CFValue) AnnotationMirror(javax.lang.model.element.AnnotationMirror) CFStore(org.checkerframework.framework.flow.CFStore)

Example 20 with CFStore

use of org.checkerframework.framework.flow.CFStore in project checker-framework by typetools.

the class LowerBoundTransfer method visitNumericalSubtraction.

@Override
public TransferResult<CFValue, CFStore> visitNumericalSubtraction(NumericalSubtractionNode n, TransferInput<CFValue, CFStore> p) {
    TransferResult<CFValue, CFStore> result = super.visitNumericalSubtraction(n, p);
    AnnotationMirror newAnno = getAnnotationForMinus(n, p);
    return createNewResult(result, newAnno);
}
Also used : CFValue(org.checkerframework.framework.flow.CFValue) AnnotationMirror(javax.lang.model.element.AnnotationMirror) CFStore(org.checkerframework.framework.flow.CFStore)

Aggregations

CFStore (org.checkerframework.framework.flow.CFStore)45 CFValue (org.checkerframework.framework.flow.CFValue)41 AnnotationMirror (javax.lang.model.element.AnnotationMirror)31 MethodInvocationNode (org.checkerframework.dataflow.cfg.node.MethodInvocationNode)8 Node (org.checkerframework.dataflow.cfg.node.Node)8 Receiver (org.checkerframework.dataflow.analysis.FlowExpressions.Receiver)7 TypeMirror (javax.lang.model.type.TypeMirror)5 ConditionalTransferResult (org.checkerframework.dataflow.analysis.ConditionalTransferResult)5 AssignmentNode (org.checkerframework.dataflow.cfg.node.AssignmentNode)5 ArrayCreationNode (org.checkerframework.dataflow.cfg.node.ArrayCreationNode)4 FieldAccessNode (org.checkerframework.dataflow.cfg.node.FieldAccessNode)4 Tree (com.sun.source.tree.Tree)3 ExecutableElement (javax.lang.model.element.ExecutableElement)3 RegularTransferResult (org.checkerframework.dataflow.analysis.RegularTransferResult)3 ClassNameNode (org.checkerframework.dataflow.cfg.node.ClassNameNode)3 GreaterThanNode (org.checkerframework.dataflow.cfg.node.GreaterThanNode)3 GreaterThanOrEqualNode (org.checkerframework.dataflow.cfg.node.GreaterThanOrEqualNode)3 IntegerLiteralNode (org.checkerframework.dataflow.cfg.node.IntegerLiteralNode)3 LessThanNode (org.checkerframework.dataflow.cfg.node.LessThanNode)3 LessThanOrEqualNode (org.checkerframework.dataflow.cfg.node.LessThanOrEqualNode)3