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

org.checkerframework.dataflow.reachingdef.ReachingDefinitionTransfer 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.reachingdef;

import java.util.List;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.dataflow.analysis.ForwardTransferFunction;
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.LocalVariableNode;
import org.checkerframework.dataflow.cfg.node.Node;

/**
 * The reaching definition transfer function. The transfer function processes the
 * ReachingDefinitionNode in ReachingDefinitionStore, killing the node with same LHS and putting new
 * generated node into the store. See dataflow manual for more details.
 */
public class ReachingDefinitionTransfer
    extends AbstractNodeVisitor<
        TransferResult,
        TransferInput>
    implements ForwardTransferFunction {

  /** Create a new ReachingDefinitionTransfer. */
  public ReachingDefinitionTransfer() {}

  @Override
  public ReachingDefinitionStore initialStore(
      UnderlyingAST underlyingAST, @Nullable List parameters) {
    return new ReachingDefinitionStore();
  }

  @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);
    processDefinition(n, transferResult.getRegularStore());
    return transferResult;
  }

  /**
   * Update a reaching definition node in the store from an assignment statement.
   *
   * @param def the definition that should be put into the store
   * @param store the reaching definition store
   */
  private void processDefinition(AssignmentNode def, ReachingDefinitionStore store) {
    store.killDef(def.getTarget());
    store.putDef(new ReachingDefinitionNode(def));
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy