示例#1
0
  void mixLists(
      LinkedList<Integer> left,
      LinkedList<Integer> right,
      ArrayList<LinkedList<Integer>> mix,
      LinkedList<Integer> before) {
    if (before.isEmpty() || right.isEmpty()) {
      LinkedList<Integer> l = new LinkedList<>();
      l = (LinkedList<Integer>) before.clone();
      l.addAll(left);
      l.addAll(right);
      mix.add(l);
      return;
    }
    int hl = left.removeFirst();
    before.addLast(hl);
    mixLists(left, right, mix, before);
    before.removeLast();
    left.addFirst(hl);

    int hr = right.removeFirst();
    before.addLast(hr);
    mixLists(left, right, mix, before);
    before.removeLast();
    right.addFirst(hr);
  }
示例#2
0
  /*
    case_label =
    {constant} case minus? integer_constant |
    {default}  default;
  */
  public void outAConstantCaseLabel(AConstantCaseLabel node) {
    String s = (String) mProductions.removeLast();
    int sign = 1;
    if (node.getMinus() != null) sign = -1;

    if (s.endsWith("L")) {
      mProductions.addLast(LongConstant.v(sign * Long.parseLong(s.substring(0, s.length() - 1))));
    } else mProductions.addLast(IntConstant.v(sign * Integer.parseInt(s)));
  }
示例#3
0
  public void outAIntegerConstant(AIntegerConstant node) {
    String s = (String) mProductions.removeLast();

    StringBuffer buf = new StringBuffer();
    if (node.getMinus() != null) buf.append('-');
    buf.append(s);

    s = buf.toString();
    if (s.endsWith("L")) {
      mProductions.addLast(LongConstant.v(Long.parseLong(s.substring(0, s.length() - 1))));
    } else mProductions.addLast(IntConstant.v(Integer.parseInt(s)));
  }
示例#4
0
 private void resolveLocalFileHeaderData(
     final Map<ZipEntry, NameAndComment> entriesWithoutUTF8Flag) throws IOException {
   for (final Entry ze : this.entries) {
     final OffsetEntry offsetEntry = ze.getOffsetEntry();
     final long offset = offsetEntry.headerOffset;
     this.archive.seek(offset + 26L);
     this.archive.readFully(this.SHORT_BUF);
     final int fileNameLen = ZipShort.getValue(this.SHORT_BUF);
     this.archive.readFully(this.SHORT_BUF);
     final int extraFieldLen = ZipShort.getValue(this.SHORT_BUF);
     int skipped;
     for (int lenToSkip = fileNameLen; lenToSkip > 0; lenToSkip -= skipped) {
       skipped = this.archive.skipBytes(lenToSkip);
       if (skipped <= 0) {
         throw new IOException("failed to skip file name in local file header");
       }
     }
     final byte[] localExtraData = new byte[extraFieldLen];
     this.archive.readFully(localExtraData);
     ze.setExtra(localExtraData);
     offsetEntry.dataOffset = offset + 26L + 2L + 2L + fileNameLen + extraFieldLen;
     if (entriesWithoutUTF8Flag.containsKey(ze)) {
       final NameAndComment nc = entriesWithoutUTF8Flag.get(ze);
       ZipUtil.setNameAndCommentFromExtraFields(ze, nc.name, nc.comment);
     }
     final String name = ze.getName();
     LinkedList<ZipEntry> entriesOfThatName = this.nameMap.get(name);
     if (entriesOfThatName == null) {
       entriesOfThatName = new LinkedList<ZipEntry>();
       this.nameMap.put(name, entriesOfThatName);
     }
     entriesOfThatName.addLast(ze);
   }
 }
示例#5
0
  public void outAInvokeStatement(AInvokeStatement node) {
    Value op = (Value) mProductions.removeLast();

    Unit u = Jimple.v().newInvokeStmt(op);

    mProductions.addLast(u);
  }
示例#6
0
  public void outALocalImmediate(ALocalImmediate node) {
    String local = (String) mProductions.removeLast();

    Local l = (Local) mLocals.get(local);
    if (l == null) throw new RuntimeException("did not find local: " + local);
    mProductions.addLast(l);
  }
  /**
   * Add a new <code>SourceJob</code> for the <code>Source source</code>, with AST <code>ast</code>.
   * A new job will be created if needed. If the <code>Source source</code> has already been
   * processed, and its job discarded to release resources, then <code>null</code> will be returned.
   */
  public SourceJob addJob(Source source, Node ast) {
    Object o = jobs.get(source);
    SourceJob job = null;
    if (o == COMPLETED_JOB) {
      // the job has already been completed.
      // We don't need to add a job
      return null;
    } else if (o == null) {
      // No appropriate job yet exists, we will create one.

      job = this.createSourceJob(source, ast);

      // record the job in the map and the worklist.
      jobs.put(source, job);
      worklist.addLast(job);

      if (Report.should_report(Report.frontend, 3)) {
        Report.report(3, "Adding job for " + source + " at the " + "request of job " + currentJob);
      }
    } else {
      job = (SourceJob) o;
    }

    // if the current source job caused this job to load, record the
    // dependency.
    if (currentJob instanceof SourceJob) {
      ((SourceJob) currentJob).addDependency(source);
    }

    return job;
  }
示例#8
0
  public void defaultCase(Node node) {
    if (node instanceof TQuotedName
        || node instanceof TFullIdentifier
        || node instanceof TIdentifier
        || node instanceof TStringConstant
        || node instanceof TIntegerConstant
        || node instanceof TFloatConstant
        || node instanceof TAtIdentifier) {

      if (debug) G.v().out.println("Default case -pushing token:" + ((Token) node).getText());
      String tokenString = ((Token) node).getText();
      if (node instanceof TStringConstant || node instanceof TQuotedName) {
        tokenString = tokenString.substring(1, tokenString.length() - 1);
      }

      if (node instanceof TIdentifier
          || node instanceof TFullIdentifier
          || node instanceof TQuotedName
          || node instanceof TStringConstant) {
        try {
          tokenString = StringTools.getUnEscapedStringOf(tokenString);

        } catch (RuntimeException e) {
          G.v().out.println(tokenString);
          throw e;
        }
      }

      mProductions.addLast(tokenString);
    }
  }
 @Override
 public synchronized void write(byte[] ba, int str, int len) {
   try {
     curLength += len;
     if (bytesEndWith(ba, str, len, LINE_SEP)) {
       lineLengths.addLast(new Integer(curLength));
       curLength = 0;
       if (lineLengths.size() > maxLines) {
         textArea.replaceRange(null, 0, lineLengths.removeFirst().intValue());
       }
     }
     for (int xa = 0; xa < 10; xa++) {
       try {
         textArea.append(new String(ba, str, len));
         break;
       } catch (
           Throwable
               thr) { // sometimes throws a java.lang.Error: Interrupted attempt to aquire write
                      // lock
         if (xa == 9) {
           thr.printStackTrace();
         }
       }
     }
     textArea.setCaretPosition(textArea.getText().length());
   } catch (Throwable thr) {
     CharArrayWriter caw = new CharArrayWriter();
     thr.printStackTrace(new PrintWriter(caw, true));
     textArea.append(System.getProperty("line.separator", "\n"));
     textArea.append(caw.toString());
   }
 }
示例#10
0
 public void outAFullIdentNonvoidType(AFullIdentNonvoidType node) {
   String typeName = (String) mProductions.removeLast();
   Type t = RefType.v(typeName);
   int dim = node.getArrayBrackets().size();
   if (dim > 0) t = ArrayType.v(t, dim);
   mProductions.addLast(t);
 }
示例#11
0
  public void outAAssignStatement(AAssignStatement node) {
    Value rvalue = (Value) mProductions.removeLast();
    Value variable = (Value) mProductions.removeLast();

    Unit u = Jimple.v().newAssignStmt(variable, rvalue);
    mProductions.addLast(u);
  }
示例#12
0
  public void outALookupswitchStatement(ALookupswitchStatement node) {
    List lookupValues = new ArrayList();
    List targets = new ArrayList();
    UnitBox defaultTarget = null;

    if (node.getCaseStmt() != null) {
      int size = node.getCaseStmt().size();

      for (int i = 0; i < size; i++) {
        Object valueTargetPair = mProductions.removeLast();
        if (valueTargetPair instanceof UnitBox) {
          if (defaultTarget != null)
            throw new RuntimeException("error: can't ;have more than 1 default stmt");

          defaultTarget = (UnitBox) valueTargetPair;
        } else {
          Object[] pair = (Object[]) valueTargetPair;

          lookupValues.add(0, pair[0]);
          targets.add(0, pair[1]);
        }
      }
    } else {
      throw new RuntimeException("error: switch stmt has no case stmts");
    }

    Value key = (Value) mProductions.removeLast();
    Unit switchStmt = Jimple.v().newLookupSwitchStmt(key, lookupValues, targets, defaultTarget);

    mProductions.addLast(switchStmt);
  }
示例#13
0
 public void totalExport() {
   File expf = new File("export");
   if (expf.exists()) rmrf(expf);
   expf.mkdirs();
   for (int sto = 0; sto < storeLocs.size(); sto++) {
     try {
       String sl =
           storeLocs.get(sto).getAbsolutePath().replaceAll("/", "-").replaceAll("\\\\", "-");
       File estore = new File(expf, sl);
       estore.mkdir();
       File log = new File(estore, LIBRARY_NAME);
       PrintWriter pw = new PrintWriter(log);
       for (int i = 0; i < store.getRowCount(); i++)
         if (store.curStore(i) == sto) {
           File enc = store.locate(i);
           File dec = sec.prepareMainFile(enc, estore, false);
           pw.println(dec.getName());
           pw.println(store.getValueAt(i, Storage.COL_DATE));
           pw.println(store.getValueAt(i, Storage.COL_TAGS));
           synchronized (jobs) {
             jobs.addLast(expJob(enc, dec));
           }
         }
       pw.close();
     } catch (IOException exc) {
       exc.printStackTrace();
       JOptionPane.showMessageDialog(frm, "Exporting Failed");
       return;
     }
   }
   JOptionPane.showMessageDialog(frm, "Exporting to:\n   " + expf.getAbsolutePath());
 }
示例#14
0
  public void outANonstaticInvokeExpr(ANonstaticInvokeExpr node) {
    List args;

    if (node.getArgList() != null) args = (List) mProductions.removeLast();
    else args = new ArrayList();

    SootMethodRef method = (SootMethodRef) mProductions.removeLast();

    String local = (String) mProductions.removeLast();

    Local l = (Local) mLocals.get(local);
    if (l == null) throw new RuntimeException("did not find local: " + local);

    Node invokeType = (Node) node.getNonstaticInvoke();
    Expr invokeExpr;

    if (invokeType instanceof ASpecialNonstaticInvoke) {
      invokeExpr = Jimple.v().newSpecialInvokeExpr(l, method, args);
    } else if (invokeType instanceof AVirtualNonstaticInvoke) {
      invokeExpr = Jimple.v().newVirtualInvokeExpr(l, method, args);
    } else {
      if (debug)
        if (!(invokeType instanceof AInterfaceNonstaticInvoke))
          throw new RuntimeException("expected interface invoke.");
      invokeExpr = Jimple.v().newInterfaceInvokeExpr(l, method, args);
    }

    mProductions.addLast(invokeExpr);
  }
示例#15
0
  public void outAIdentityNoTypeStatement(AIdentityNoTypeStatement node) {
    mProductions.removeLast(); // get rid of @caughtexception string presently on top of the stack
    Value local =
        (Value) mLocals.get(mProductions.removeLast()); // the local ref from it's identifier

    Unit u = Jimple.v().newIdentityStmt(local, Jimple.v().newCaughtExceptionRef());
    mProductions.addLast(u);
  }
示例#16
0
  public void outABinopExpr(ABinopExpr node) {
    Value right = (Value) mProductions.removeLast();
    BinopExpr expr = (BinopExpr) mProductions.removeLast();
    Value left = (Value) mProductions.removeLast();

    expr.setOp1(left);
    expr.setOp2(right);
    mProductions.addLast(expr);
  }
示例#17
0
  public void outAArrayRef(AArrayRef node) {
    Value immediate = (Value) mProductions.removeLast();
    String identifier = (String) mProductions.removeLast();

    Local l = (Local) mLocals.get(identifier);
    if (l == null) throw new RuntimeException("did not find local: " + identifier);

    mProductions.addLast(Jimple.v().newArrayRef(l, immediate));
  }
示例#18
0
  /*
    case_stmt =
    case_label colon goto_stmt;
  */
  public void outACaseStmt(ACaseStmt node) {
    String labelName = (String) mProductions.removeLast();
    UnitBox box = Jimple.v().newStmtBox(null);

    addBoxToPatch(labelName, box);

    Value labelValue = null;
    if (node.getCaseLabel() instanceof AConstantCaseLabel)
      labelValue = (Value) mProductions.removeLast();

    // if labelValue == null, this is the default label.
    if (labelValue == null) mProductions.addLast(box);
    else {
      Object[] valueTargetPair = new Object[2];
      valueTargetPair[0] = labelValue;
      valueTargetPair[1] = box;
      mProductions.addLast(valueTargetPair);
    }
  }
示例#19
0
  public void outAGotoStatement(AGotoStatement node) {
    String targetLabel = (String) mProductions.removeLast();

    UnitBox box = Jimple.v().newStmtBox(null);
    Unit branch = Jimple.v().newGotoStmt(box);

    addBoxToPatch(targetLabel, box);

    mProductions.addLast(branch);
  }
示例#20
0
  public void outALocalFieldRef(ALocalFieldRef node) {
    SootFieldRef field = (SootFieldRef) mProductions.removeLast();

    String local = (String) mProductions.removeLast();

    Local l = (Local) mLocals.get(local);
    if (l == null) throw new RuntimeException("did not find local: " + local);

    mProductions.addLast(Jimple.v().newInstanceFieldRef(l, field));
  }
示例#21
0
  public void parseInputFile(File inputFile) throws IOException {
    geneFeatures.clear();
    otherRecords.clear();

    try {
      GFFEntrySet gffEntries = GFFTools.readGFF(inputFile);

      Iterator itr = gffEntries.lineIterator();
      int count = 0;
      int intronFeatures = 0;
      LinkedList<GFFRecord> cdsRecs = new LinkedList<GFFRecord>();

      while (itr.hasNext()) {
        Object val = itr.next();
        if (val instanceof GFFRecord) {
          GFFRecord rec = (GFFRecord) val;
          count += 1;

          if (rec.getFeature().endsWith("gene")) {
            GeneFeatures gf = new GeneFeatures(rec);
            geneFeatures.put(gf.id, gf);
          } else if (rec.getFeature().equals("CDS")) {
            cdsRecs.addLast(rec);
          } else {
            otherRecords.add(rec);
          }
        }
      }

      for (GFFRecord rec : cdsRecs) {
        Map<String, List<String>> attrs = decodeAttrMap(rec);
        if (geneFeatures.containsKey(attrs.get("Parent").get(0))) {
          geneFeatures.get(attrs.get("Parent").get(0)).addCDS(rec, attrs);
        } else {
          System.err.println("Unknown CDS Parent: " + attrs.get("Parent").get(0));
        }
      }

      for (String k : geneFeatures.keySet()) {
        GeneFeatures gf = geneFeatures.get(k);
        if (gf.cds != null && gf.cds.size() > 1) {
          intronFeatures++;
        }
      }

      System.err.println("# GFF Records: " + count);
      System.err.println("# Gene Feature Sets: " + geneFeatures.size());
      System.err.println("\t# Intron-Features: " + intronFeatures);

    } catch (ParserException e) {
      e.printStackTrace();
    } catch (BioException e) {
      e.printStackTrace();
    }
  }
示例#22
0
  public void outAIfStatement(AIfStatement node) {
    String targetLabel = (String) mProductions.removeLast();
    Value condition = (Value) mProductions.removeLast();

    UnitBox box = Jimple.v().newStmtBox(null);
    Unit u = Jimple.v().newIfStmt(condition, box);

    addBoxToPatch(targetLabel, box);

    mProductions.addLast(u);
  }
示例#23
0
文件: A1.java 项目: paohui817/arena
 public static TreeNode createTree(ArrayList<String> list) {
   LinkedList<NodeWithBranch> queue = new LinkedList<>();
   TreeNode head = new TreeNode(0);
   queue.addLast(new NodeWithBranch(head, 0));
   for (String s : list) {
     NodeWithBranch node = queue.removeFirst();
     if (!s.equals(NULL)) {
       if (node.branch == 0) {
         node.tree.left = new TreeNode(Integer.parseInt(s));
         queue.addLast(new NodeWithBranch(node.tree.left, 0));
         queue.addLast(new NodeWithBranch(node.tree.left, 1));
       } else {
         node.tree.right = new TreeNode(Integer.parseInt(s));
         queue.addLast(new NodeWithBranch(node.tree.right, 0));
         queue.addLast(new NodeWithBranch(node.tree.right, 1));
       }
     }
   }
   return head.left;
 }
示例#24
0
  public void outAReturnStatement(AReturnStatement node) {
    Value v;
    Stmt s = null;
    if (node.getImmediate() != null) {
      v = (Value) mProductions.removeLast();
      s = Jimple.v().newReturnStmt(v);
    } else {
      s = Jimple.v().newReturnVoidStmt();
    }

    mProductions.addLast(s);
  }
示例#25
0
  public void outADeclaration(ADeclaration node) {
    List localNameList = (List) mProductions.removeLast();
    Type type = (Type) mProductions.removeLast();
    Iterator it = localNameList.iterator();
    List localList = new ArrayList();

    while (it.hasNext()) {
      Local l = Jimple.v().newLocal((String) it.next(), type);
      mLocals.put(l.getName(), l);
      localList.add(l);
    }
    mProductions.addLast(localList);
  }
 public void search(Vertex[] nodes, int start) {
   LinkedList<Vertex> queue = new LinkedList<>();
   nodes[start].numPaths = 1;
   nodes[start].minDistance = 0;
   queue.addLast(nodes[start]);
   while (!queue.isEmpty()) {
     Vertex curr = queue.removeFirst();
     for (Edge e : curr.edges) {
       Vertex other = e.end;
       if (!other.checked) {
         other.checked = true;
         queue.addLast(other);
       }
       if (curr.minDistance + e.weight < other.minDistance) {
         other.minDistance = curr.minDistance + e.weight;
         other.numPaths = curr.numPaths;
       } else if (curr.minDistance + e.weight == other.minDistance) {
         other.numPaths += curr.numPaths;
       }
     }
   }
 }
示例#27
0
  public void outAFieldSignature(AFieldSignature node) {
    String className, fieldName;
    Type t;

    fieldName = (String) mProductions.removeLast();
    t = (Type) mProductions.removeLast();
    className = (String) mProductions.removeLast();

    SootClass cl = mResolver.makeClassRef(className);
    SootFieldRef field = Scene.v().makeFieldRef(cl, fieldName, t, false);

    mProductions.addLast(field);
  }
示例#28
0
  public void outAStringConstant(AStringConstant node) {
    String s = (String) mProductions.removeLast();
    mProductions.addLast(StringConstant.v(s));
    /*
      try {
      String t = StringTools.getUnEscapedStringOf(s);

      mProductions.push(StringConstant.v(t));
      } catch(RuntimeException e) {
      G.v().out.println(s);
      throw e;
      }
    */
  }
示例#29
0
  /*
    throws_clause =
    throws class_name_list;
  */
  public void outAThrowsClause(AThrowsClause node) {
    List l = (List) mProductions.removeLast();

    Iterator it = l.iterator();
    List exceptionClasses = new ArrayList(l.size());

    while (it.hasNext()) {
      String className = (String) it.next();

      exceptionClasses.add(mResolver.makeClassRef(className));
    }

    mProductions.addLast(exceptionClasses);
  }
示例#30
0
 public void secureExport(int i) {
   File expf = getExportTempFile(store.plainName(i));
   // check if its already been exported
   if (expf.exists()) secureUse(expf);
   else { // otherwise add to work queue
     File cipf = store.locate(i);
     if (cipf != null) {
       synchronized (jobs) {
         if (priorityExport) jobs.addFirst(expJob(cipf, expf));
         else jobs.addLast(expJob(cipf, expf));
       }
     } else System.err.println("Cannot export, missing encrypted file");
   }
   updateStatus();
 }