Search in sources :

Example 1 with RegularTransferResult

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

the class ValueTransfer method createNewResultBoolean.

/**
 * Create a boolean transfer result.
 */
private TransferResult<CFValue, CFStore> createNewResultBoolean(CFStore thenStore, CFStore elseStore, List<Boolean> resultValues, TypeMirror underlyingType) {
    AnnotationMirror boolVal = atypeFactory.createBooleanAnnotation(resultValues);
    CFValue newResultValue = analysis.createSingleAnnotationValue(boolVal, underlyingType);
    if (elseStore != null) {
        return new ConditionalTransferResult<>(newResultValue, thenStore, elseStore);
    } else {
        return new RegularTransferResult<>(newResultValue, thenStore);
    }
}
Also used : CFValue(org.checkerframework.framework.flow.CFValue) AnnotationMirror(javax.lang.model.element.AnnotationMirror) ConditionalTransferResult(org.checkerframework.dataflow.analysis.ConditionalTransferResult) RegularTransferResult(org.checkerframework.dataflow.analysis.RegularTransferResult)

Example 2 with RegularTransferResult

use of org.checkerframework.dataflow.analysis.RegularTransferResult 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 {
            JavaExpression firstParam = JavaExpression.fromNode(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);
        JavaExpression firstParam = JavaExpression.fromNode(node.getArgument(0));
        AnnotationBuilder builder = new AnnotationBuilder(tu.processingEnv, I18nInvalidFormat.class);
        // 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 : CFValue(org.checkerframework.framework.flow.CFValue) AnnotationMirror(javax.lang.model.element.AnnotationMirror) CFStore(org.checkerframework.framework.flow.CFStore) JavaExpression(org.checkerframework.dataflow.expression.JavaExpression) ConditionalTransferResult(org.checkerframework.dataflow.analysis.ConditionalTransferResult) AnnotationBuilder(org.checkerframework.javacutil.AnnotationBuilder) RegularTransferResult(org.checkerframework.dataflow.analysis.RegularTransferResult)

Example 3 with RegularTransferResult

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

the class LiveVarTransfer method visitReturn.

@Override
public RegularTransferResult<LiveVarValue, LiveVarStore> visitReturn(ReturnNode n, TransferInput<LiveVarValue, LiveVarStore> p) {
    RegularTransferResult<LiveVarValue, LiveVarStore> transferResult = (RegularTransferResult<LiveVarValue, LiveVarStore>) super.visitReturn(n, p);
    Node result = n.getResult();
    if (result != null) {
        LiveVarStore store = transferResult.getRegularStore();
        store.addUseInExpression(result);
    }
    return transferResult;
}
Also used : ObjectCreationNode(org.checkerframework.dataflow.cfg.node.ObjectCreationNode) ReturnNode(org.checkerframework.dataflow.cfg.node.ReturnNode) MethodInvocationNode(org.checkerframework.dataflow.cfg.node.MethodInvocationNode) AssignmentNode(org.checkerframework.dataflow.cfg.node.AssignmentNode) StringConcatenateAssignmentNode(org.checkerframework.dataflow.cfg.node.StringConcatenateAssignmentNode) Node(org.checkerframework.dataflow.cfg.node.Node) RegularTransferResult(org.checkerframework.dataflow.analysis.RegularTransferResult)

Example 4 with RegularTransferResult

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

the class LiveVarTransfer method visitMethodInvocation.

@Override
public RegularTransferResult<LiveVarValue, LiveVarStore> visitMethodInvocation(MethodInvocationNode n, TransferInput<LiveVarValue, LiveVarStore> p) {
    RegularTransferResult<LiveVarValue, LiveVarStore> transferResult = (RegularTransferResult<LiveVarValue, LiveVarStore>) super.visitMethodInvocation(n, p);
    LiveVarStore store = transferResult.getRegularStore();
    for (Node arg : n.getArguments()) {
        store.addUseInExpression(arg);
    }
    return transferResult;
}
Also used : ObjectCreationNode(org.checkerframework.dataflow.cfg.node.ObjectCreationNode) ReturnNode(org.checkerframework.dataflow.cfg.node.ReturnNode) MethodInvocationNode(org.checkerframework.dataflow.cfg.node.MethodInvocationNode) AssignmentNode(org.checkerframework.dataflow.cfg.node.AssignmentNode) StringConcatenateAssignmentNode(org.checkerframework.dataflow.cfg.node.StringConcatenateAssignmentNode) Node(org.checkerframework.dataflow.cfg.node.Node) RegularTransferResult(org.checkerframework.dataflow.analysis.RegularTransferResult)

Example 5 with RegularTransferResult

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

the class CFAbstractTransfer method visitThis.

@Override
public TransferResult<V, S> visitThis(ThisNode 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) Tree(com.sun.source.tree.Tree) ClassTree(com.sun.source.tree.ClassTree) ExpressionTree(com.sun.source.tree.ExpressionTree) 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