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

soot.toolkits.scalar.BranchedFlowAnalysis Maven / Gradle / Ivy

package soot.toolkits.scalar;

/*-
 * #%L
 * Soot - a J*va Optimization Framework
 * %%
 * Copyright (C) 1997 - 2000 Patrick Lam
 * %%
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation, either version 2.1 of the
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Lesser Public License for more details.
 * 
 * You should have received a copy of the GNU General Lesser Public
 * License along with this program.  If not, see
 * .
 * #L%
 */

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import soot.Unit;
import soot.toolkits.graph.DirectedGraph;

/**
 * Abstract class providing functionality for branched flow analysis.
 *
 * A branched flow analysis is one which can propagate different information to the successors of a node. This is useful for
 * propagating information past a statement like if(x >
 * 0): one successor has x > 0 while the other successor has x ≤ 0.
 */
public abstract class BranchedFlowAnalysis extends AbstractFlowAnalysis {
  /** Maps graph nodes to OUT sets. */
  protected Map> unitToAfterFallFlow;
  protected Map> unitToAfterBranchFlow;

  public BranchedFlowAnalysis(DirectedGraph graph) {
    super(graph);

    unitToAfterFallFlow = new HashMap>(graph.size() * 2 + 1, 0.7f);
    unitToAfterBranchFlow = new HashMap>(graph.size() * 2 + 1, 0.7f);
  }

  /**
   * Given the merge of the in sets, compute the fallOut and branchOuts set for
   * s.
   */
  protected abstract void flowThrough(A in, Unit s, List fallOut, List branchOuts);

  public A getFallFlowAfter(Unit s) {
    List fl = unitToAfterFallFlow.get(s);

    if (fl.isEmpty()) {
      return newInitialFlow();
    } else {
      return fl.get(0);
    }
  }

  public List getBranchFlowAfter(Unit s) {
    return (unitToAfterBranchFlow.get(s));
  }

} // end class BranchedFlowAnalysis




© 2015 - 2024 Weber Informatics LLC | Privacy Policy