예제 #1
0
  public class LoopWhereIfIsExitNode extends AdHocUnitGraph {
    /*
     *     +------+----+
     *     v      |    |
     *  -> if -> n2    |
     *     +---------> n1
     * */

    public final Unit n1 = j.newGotoStmt((Unit) null);
    public final Unit n2 = j.newGotoStmt((Unit) null);
    public final Unit nIf = j.newIfStmt(j.newEqExpr(IntConstant.v(0), IntConstant.v(0)), n1);

    public LoopWhereIfIsExitNode() {
      ((GotoStmt) n1).setTarget(nIf);
      ((GotoStmt) n2).setTarget(nIf);
    }

    @Override
    protected List<Unit> getUnits() {
      return Arrays.asList(nIf, n1, n2);
    }

    @Override
    public List<Unit> getHeads() {
      return Collections.singletonList(nIf);
    }

    @Override
    public List<Unit> getTails() {
      return Collections.singletonList(nIf);
    }

    @Override
    public List<Unit> getPredsOf(Unit unit) {
      if (unit.equals(nIf)) {
        return Collections.emptyList();
      } else if (unit.equals(n1)) {
        return Collections.singletonList(nIf);
      } else if (unit.equals(n2)) {
        return Collections.singletonList(nIf);
      } else {
        throw new RuntimeException("UNEXPECTED CASE");
      }
    }

    @Override
    public List<Unit> getSuccsOf(Unit unit) {

      if (unit.equals(nIf)) {
        return asList(n1, n2);
      } else if (unit.equals(n1)) {
        return Collections.singletonList(nIf);
      } else if (unit.equals(n2)) {
        return Collections.singletonList(nIf);
      } else {
        throw new RuntimeException("UNEXPECTED CASE");
      }
    }
  }
예제 #2
0
  public class LoopWithReflexivePostdom extends AdHocUnitGraph {
    /*
     *     +-----------+
     *     v           |
     *  -> if -> exit  |
     *     +---------> n
     * */

    public final Unit nExit = j.newReturnStmt(IntConstant.v(42));
    public final Unit nIf = j.newIfStmt(j.newEqExpr(IntConstant.v(0), IntConstant.v(0)), nExit);
    public final Unit n = j.newGotoStmt(nIf);

    @Override
    protected List<Unit> getUnits() {
      return Arrays.asList(nIf, n, nExit);
    }

    @Override
    public List<Unit> getHeads() {
      return Collections.singletonList(nIf);
    }

    @Override
    public List<Unit> getTails() {
      return Collections.singletonList(nExit);
    }

    @Override
    public List<Unit> getPredsOf(Unit unit) {
      if (unit.equals(nIf)) {
        return Collections.emptyList();
      } else if (unit.equals(nExit)) {
        return Collections.singletonList(nIf);
      } else if (unit.equals(n)) {
        return Collections.singletonList(nIf);
      } else {
        throw new RuntimeException("UNEXPECTED CASE");
      }
    }

    @Override
    public List<Unit> getSuccsOf(Unit unit) {

      if (unit.equals(nIf)) {
        return asList(nExit, n);
      } else if (unit.equals(nExit)) {
        return Collections.emptyList();
      } else if (unit.equals(n)) {
        return Collections.singletonList(nIf);
      } else {
        throw new RuntimeException("UNEXPECTED CASE");
      }
    }
  }
예제 #3
0
  public class MultipleReturns extends AdHocForwardUnitGraph {
    public final Unit returnX = j.newReturnStmt(localX);
    public final Unit returnZ = j.newReturnStmt(localZ);
    public final Unit ifY = j.newIfStmt(j.newEqExpr(localY, localY), returnX);
    public final Unit ifO = j.newIfStmt(j.newEqExpr(localO, localO), ifY);
    public final Unit returnZero = j.newReturnStmt(IntConstant.v(0));

    public MultipleReturns() {
      setForwardEdges(makeEdges(makeEdge(ifO, ifY, returnZ), makeEdge(ifY, returnX, returnZero)));
    }
  }