예제 #1
0
  public void convertToBaf(JimpleToBafContext context, List out) {
    Unit u = Baf.v().newStaticGetInst(fieldRef);
    out.add(u);

    Iterator it = context.getCurrentUnit().getTags().iterator();
    while (it.hasNext()) {
      u.addTag((Tag) it.next());
    }
  }
예제 #2
0
  /**
   * Produces a string representation of the puzzle, this shall be a 9 columns and 9 rows in size,
   * separated by new line characters.
   *
   * @return A string representation of this puzzle.
   */
  public String toString() {

    String out = new String();

    for (Unit x : rows) {
      out += x.toString() + "\n";
    }

    return out;
  }
예제 #3
0
  private int addJimpleLnTags(int lnNum, Unit stmt, int endLn) {

    if (endLn - lnNum <= 1) {
      stmt.addTag(new JimpleLineNumberTag(lnNum));
      // G.v().out.println(stmt.getClass().toString());
      lnNum++;
      return lnNum;
    } else {
      stmt.addTag(new JimpleLineNumberTag(lnNum, endLn));
      // G.v().out.println("multi-line: "+stmt.getClass().toString());
      endLn++;
      return endLn;
    }
  }
예제 #4
0
  /**
   * This method return the the sum of duplicate values in each unit.
   *
   * <p>Each unit may contain each number 1 to 9 once. The conflict count is incremented by 1 each
   * time a number occurs more than once in a unit. So if a unit contains [1,3,4,1,1], its conflict
   * count is 2.
   *
   * @return The the sum of duplicate values in each unit.
   */
  public Integer conflictCount() {

    if (modified) {
      conflicts = 0;

      for (Unit x : rows) {
        conflicts += x.conflictCount();
      }

      for (Unit x : cols) {
        conflicts += x.conflictCount();
      }

      for (Unit x : boxes) {
        conflicts += x.conflictCount();
      }
    }

    return conflicts;
  }
예제 #5
0
  /** Prints the given <code>JimpleBody</code> to the specified <code>PrintWriter</code>. */
  private void printStatementsInBody(
      Body body, java.io.PrintWriter out, LabeledUnitPrinter up, UnitGraph unitGraph) {
    Chain units = body.getUnits();
    Iterator unitIt = units.iterator();
    Unit currentStmt = null, previousStmt;

    while (unitIt.hasNext()) {

      previousStmt = currentStmt;
      currentStmt = (Unit) unitIt.next();

      // Print appropriate header.
      {
        // Put an empty line if the previous node was a branch node, the current node is a join node
        //   or the previous statement does not have body statement as a successor, or if
        //   body statement has a label on it

        if (currentStmt != units.getFirst()) {
          if (unitGraph.getSuccsOf(previousStmt).size() != 1
              || unitGraph.getPredsOf(currentStmt).size() != 1
              || up.labels().containsKey(currentStmt)) {
            up.newline();
          } else {
            // Or if the previous node does not have body statement as a successor.

            List succs = unitGraph.getSuccsOf(previousStmt);

            if (succs.get(0) != currentStmt) {
              up.newline();
            }
          }
        }

        if (up.labels().containsKey(currentStmt)) {
          up.unitRef(currentStmt, true);
          up.literal(":");
          up.newline();
        }

        if (up.references().containsKey(currentStmt)) {
          up.unitRef(currentStmt, false);
        }
      }

      up.startUnit(currentStmt);
      currentStmt.toString(up);
      up.endUnit(currentStmt);

      up.literal(";");
      up.newline();

      // only print them if not generating attributes files
      // because they mess up line number
      // if (!addJimpleLn()) {
      if (Options.v().print_tags_in_output()) {
        Iterator tagIterator = currentStmt.getTags().iterator();
        while (tagIterator.hasNext()) {
          Tag t = (Tag) tagIterator.next();
          up.noIndent();
          up.literal("/*");
          up.literal(t.toString());
          up.literal("*/");
          up.newline();
        }
        /*Iterator udIt = currentStmt.getUseAndDefBoxes().iterator();
        while (udIt.hasNext()) {
            ValueBox temp = (ValueBox)udIt.next();
            Iterator vbtags = temp.getTags().iterator();
            while (vbtags.hasNext()) {
                Tag t = (Tag) vbtags.next();
                up.noIndent();
                up.literal("VB Tag: "+t.toString());
                up.newline();
            }
        }*/
      }
    }

    out.print(up.toString());
    if (addJimpleLn()) {
      setJimpleLnNum(up.getPositionTagger().getEndLn());
    }

    // Print out exceptions
    {
      Iterator trapIt = body.getTraps().iterator();

      if (trapIt.hasNext()) {
        out.println();
        incJimpleLnNum();
      }

      while (trapIt.hasNext()) {
        Trap trap = (Trap) trapIt.next();

        out.println(
            "        catch "
                + Scene.v().quotedNameOf(trap.getException().getName())
                + " from "
                + up.labels().get(trap.getBeginUnit())
                + " to "
                + up.labels().get(trap.getEndUnit())
                + " with "
                + up.labels().get(trap.getHandlerUnit())
                + ";");

        incJimpleLnNum();
      }
    }
  }