All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.checkerframework.dataflow.busyexpr.BusyExprTransfer Maven / Gradle / Ivy

Go to download

The Checker Framework enhances Java's type system to make it more powerful and useful. This lets software developers detect and prevent errors in their Java programs. The Checker Framework includes compiler plug-ins ("checkers") that find bugs or verify their absence. It also permits you to write your own compiler plug-ins.

There is a newer version: 3.48.2
Show newest version
package org.checkerframework.dataflow.busyexpr;

import java.util.List;
import org.checkerframework.dataflow.analysis.BackwardTransferFunction;
import org.checkerframework.dataflow.analysis.RegularTransferResult;
import org.checkerframework.dataflow.analysis.TransferInput;
import org.checkerframework.dataflow.analysis.TransferResult;
import org.checkerframework.dataflow.analysis.UnusedAbstractValue;
import org.checkerframework.dataflow.cfg.UnderlyingAST;
import org.checkerframework.dataflow.cfg.node.AbstractNodeVisitor;
import org.checkerframework.dataflow.cfg.node.AssignmentNode;
import org.checkerframework.dataflow.cfg.node.MethodInvocationNode;
import org.checkerframework.dataflow.cfg.node.Node;
import org.checkerframework.dataflow.cfg.node.ObjectCreationNode;
import org.checkerframework.dataflow.cfg.node.ReturnNode;

/** A busy expression transfer function */
public class BusyExprTransfer
    extends AbstractNodeVisitor<
        TransferResult,
        TransferInput>
    implements BackwardTransferFunction {

  @Override
  public BusyExprStore initialNormalExitStore(
      UnderlyingAST underlyingAST, List returnNodes) {
    return new BusyExprStore();
  }

  @Override
  public BusyExprStore initialExceptionalExitStore(UnderlyingAST underlyingAST) {
    return new BusyExprStore();
  }

  @Override
  public RegularTransferResult visitNode(
      Node n, TransferInput p) {
    return new RegularTransferResult<>(null, p.getRegularStore());
  }

  @Override
  public RegularTransferResult visitAssignment(
      AssignmentNode n, TransferInput p) {
    RegularTransferResult transferResult =
        (RegularTransferResult) super.visitAssignment(n, p);
    BusyExprStore store = transferResult.getRegularStore();
    store.killBusyExpr(n.getTarget());
    store.addUseInExpression(n.getExpression());
    return transferResult;
  }

  @Override
  public RegularTransferResult visitMethodInvocation(
      MethodInvocationNode n, TransferInput p) {
    RegularTransferResult transferResult =
        (RegularTransferResult)
            super.visitMethodInvocation(n, p);
    BusyExprStore store = transferResult.getRegularStore();
    for (Node arg : n.getArguments()) {
      store.addUseInExpression(arg);
    }
    return transferResult;
  }

  @Override
  public RegularTransferResult visitObjectCreation(
      ObjectCreationNode n, TransferInput p) {
    RegularTransferResult transferResult =
        (RegularTransferResult) super.visitObjectCreation(n, p);
    BusyExprStore store = transferResult.getRegularStore();
    for (Node arg : n.getArguments()) {
      store.addUseInExpression(arg);
    }
    return transferResult;
  }

  @Override
  public RegularTransferResult visitReturn(
      ReturnNode n, TransferInput p) {
    RegularTransferResult transferResult =
        (RegularTransferResult) super.visitReturn(n, p);
    Node result = n.getResult();
    if (result != null) {
      BusyExprStore store = transferResult.getRegularStore();
      store.addUseInExpression(result);
    }
    return transferResult;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy