Search in sources :

Example 1 with ObjectCreationNode

use of org.checkerframework.dataflow.cfg.node.ObjectCreationNode in project checker-framework by typetools.

the class WholeProgramInferenceScenes method updateInferredConstructorParameterTypes.

/**
 * Updates the parameter types of the constructor created by objectCreationNode based on
 * arguments to the constructor.
 *
 * <p>For each parameter in constructorElt:
 *
 * <ul>
 *   <li>If the Scene does not contain an annotated type for that parameter, then the type of
 *       the respective value passed as argument in the object creation call objectCreationNode
 *       will be added to the parameter in the Scene.
 *   <li>If the Scene previously contained an annotated type for that parameter, then its new
 *       type will be the LUB between the previous type and the type of the respective value
 *       passed as argument in the object creation call.
 * </ul>
 *
 * <p>
 *
 * @param objectCreationNode the new Object() node
 * @param atf the annotated type factory of a given type system, whose type hierarchy will be
 *     used to update the constructor's parameters' types
 */
@Override
public void updateInferredConstructorParameterTypes(ObjectCreationNode objectCreationNode, ExecutableElement constructorElt, AnnotatedTypeFactory atf) {
    ClassSymbol classSymbol = getEnclosingClassSymbol(objectCreationNode.getTree());
    if (classSymbol == null) {
        // https://github.com/typetools/checker-framework/issues/682
        return;
    }
    String className = classSymbol.flatname.toString();
    String jaifPath = helper.getJaifPath(className);
    AClass clazz = helper.getAClass(className, jaifPath);
    String methodName = JVMNames.getJVMMethodName(constructorElt);
    AMethod method = clazz.methods.vivify(methodName);
    List<Node> arguments = objectCreationNode.getArguments();
    updateInferredExecutableParameterTypes(constructorElt, atf, jaifPath, method, arguments);
}
Also used : ClassSymbol(com.sun.tools.javac.code.Symbol.ClassSymbol) FieldAccessNode(org.checkerframework.dataflow.cfg.node.FieldAccessNode) ObjectCreationNode(org.checkerframework.dataflow.cfg.node.ObjectCreationNode) ReturnNode(org.checkerframework.dataflow.cfg.node.ReturnNode) MethodInvocationNode(org.checkerframework.dataflow.cfg.node.MethodInvocationNode) ImplicitThisLiteralNode(org.checkerframework.dataflow.cfg.node.ImplicitThisLiteralNode) LocalVariableNode(org.checkerframework.dataflow.cfg.node.LocalVariableNode) Node(org.checkerframework.dataflow.cfg.node.Node) AClass(scenelib.annotations.el.AClass) AMethod(scenelib.annotations.el.AMethod)

Example 2 with ObjectCreationNode

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

Aggregations

MethodInvocationNode (org.checkerframework.dataflow.cfg.node.MethodInvocationNode)2 Node (org.checkerframework.dataflow.cfg.node.Node)2 ObjectCreationNode (org.checkerframework.dataflow.cfg.node.ObjectCreationNode)2 Tree (com.sun.source.tree.Tree)1 ClassSymbol (com.sun.tools.javac.code.Symbol.ClassSymbol)1 Unique (org.checkerframework.common.aliasing.qual.Unique)1 Receiver (org.checkerframework.dataflow.analysis.FlowExpressions.Receiver)1 RegularTransferResult (org.checkerframework.dataflow.analysis.RegularTransferResult)1 AssignmentNode (org.checkerframework.dataflow.cfg.node.AssignmentNode)1 FieldAccessNode (org.checkerframework.dataflow.cfg.node.FieldAccessNode)1 ImplicitThisLiteralNode (org.checkerframework.dataflow.cfg.node.ImplicitThisLiteralNode)1 LocalVariableNode (org.checkerframework.dataflow.cfg.node.LocalVariableNode)1 ReturnNode (org.checkerframework.dataflow.cfg.node.ReturnNode)1 AnnotatedTypeMirror (org.checkerframework.framework.type.AnnotatedTypeMirror)1 AClass (scenelib.annotations.el.AClass)1 AMethod (scenelib.annotations.el.AMethod)1