public int length() { return collinstr.size(); }
public void setAllElements() { int[] lastindex = colValuesInternal.get(colValuesInternal.size() - 1); for (int i = lastindex[0] - 1; i >= 0; i--) { data[i] = 0xFFFFFFFF; } data[lastindex[0]] = lastindex[1] | (lastindex[1] - 1); }
private FastFixedSetIterator(FastFixedSet<E> set) { colValuesInternal = set.getFactory().getInternalValuesCollection(); data = set.getData(); size = colValuesInternal.size(); }
private FastSparseSetIterator(FastSparseSet<E> set) { colValuesInternal = set.getFactory().getInternalValuesCollection(); data = set.getData(); next = set.getNext(); size = colValuesInternal.size(); }
public Set<E> toPlainSet() { HashSet<E> set = new HashSet<>(); int[] intdata = data; int size = data.length * 32; if (size > colValuesInternal.size()) { size = colValuesInternal.size(); } for (int i = size - 1; i >= 0; i--) { int[] index = colValuesInternal.get(i); if ((intdata[index[0]] & index[1]) != 0) { set.add(colValuesInternal.getKey(i)); } } return set; }
public String toString(int indent) { String new_line_separator = DecompilerContext.getNewLineSeparator(); StringBuilder buf = new StringBuilder(); for (int i = 0; i < collinstr.size(); i++) { buf.append(TextUtil.getIndentString(indent)); buf.append(collinstr.getKey(i).intValue()); buf.append(": "); buf.append(collinstr.get(i).toString()); buf.append(new_line_separator); } return buf.toString(); }
public String toString() { StringBuilder buffer = new StringBuilder("{"); int[] intdata = data; boolean first = true; for (int i = colValuesInternal.size() - 1; i >= 0; i--) { int[] index = colValuesInternal.get(i); if ((intdata[index[0]] & index[1]) != 0) { if (first) { first = false; } else { buffer.append(","); } buffer.append(colValuesInternal.getKey(i)); } } buffer.append("}"); return buffer.toString(); }
public void removeLast() { if (!collinstr.isEmpty()) { collinstr.remove(collinstr.size() - 1); } }
@Override public IMatchable findObject(MatchNode matchNode, int index) { int node_type = matchNode.getType(); if (node_type == MatchNode.MATCHNODE_STATEMENT && !this.stats.isEmpty()) { String position = (String)matchNode.getRuleValue(MatchProperties.STATEMENT_POSITION); if (position != null) { if (position.matches("-?\\d+")) { return this.stats.get((this.stats.size() + Integer.parseInt(position)) % this.stats.size()); // care for negative positions } } else if (index < this.stats.size()) { // use 'index' parameter return this.stats.get(index); } } else if (node_type == MatchNode.MATCHNODE_EXPRENT && this.exprents != null && !this.exprents.isEmpty()) { String position = (String)matchNode.getRuleValue(MatchProperties.EXPRENT_POSITION); if (position != null) { if (position.matches("-?\\d+")) { return this.exprents.get((this.exprents.size() + Integer.parseInt(position)) % this.exprents.size()); // care for negative positions } } else if (index < this.exprents.size()) { // use 'index' parameter return this.exprents.get(index); } } return null; }
public List<Statement> getPostReversePostOrderList(List<Statement> lstexits) { List<Statement> res = new ArrayList<>(); if (lstexits == null) { StrongConnectivityHelper schelper = new StrongConnectivityHelper(this); lstexits = StrongConnectivityHelper.getExitReps(schelper.getComponents()); } HashSet<Statement> setVisited = new HashSet<>(); for (Statement exit : lstexits) { addToPostReversePostOrderList(exit, res, setVisited); } if (res.size() != stats.size()) { throw new RuntimeException("computing post reverse post order failed!"); } return res; }
@Override public void initSimpleCopy() { first = stats.get(0); List<StatEdge> lstSuccs = first.getSuccessorEdges(STATEDGE_DIRECT_ALL); ifedge = lstSuccs.get((iftype == IFTYPE_IF || negated) ? 0 : 1); if (stats.size() > 1) { ifstat = stats.get(1); } if (iftype == IFTYPE_IFELSE) { elseedge = lstSuccs.get(negated ? 1 : 0); elsestat = stats.get(2); } }
private static Statement getLastDirectData(Statement stat) { if (stat.getExprents() != null) { return stat; } if (stat.type == Statement.TYPE_SEQUENCE) { for (int i = stat.getStats().size() - 1; i >= 0; i--) { Statement tmp = getLastDirectData(stat.getStats().get(i)); if (tmp == null || !tmp.getExprents().isEmpty()) { return tmp; } } } return null; } }
private static void cleanUpUnreachableBlocks(Statement stat) { boolean found; do { found = false; for (int i = 0; i < stat.getStats().size(); i++) { Statement st = stat.getStats().get(i); cleanUpUnreachableBlocks(st); if (st.type == Statement.TYPE_SEQUENCE && st.getStats().size() > 1) { Statement last = st.getStats().getLast(); Statement secondlast = st.getStats().get(st.getStats().size() - 2); if (last.getExprents() == null || !last.getExprents().isEmpty()) { if (!secondlast.hasBasicSuccEdge()) { Set<Statement> set = last.getNeighboursSet(Statement.STATEDGE_DIRECT_ALL, Statement.DIRECTION_BACKWARD); set.remove(secondlast); if (set.isEmpty()) { last.setExprents(new ArrayList<>()); found = true; break; } } } } } } while (found); }
private static void collectCatchVars(Statement stat, FlattenStatementsHelper flatthelper, Map<String, VarExprent> map) { List<VarExprent> lst = null; if (stat.type == Statement.TYPE_CATCHALL) { CatchAllStatement catchall = (CatchAllStatement)stat; if (!catchall.isFinally()) { lst = catchall.getVars(); } } else if (stat.type == Statement.TYPE_TRYCATCH) { lst = ((CatchStatement)stat).getVars(); } if (lst != null) { for (int i = 1; i < stat.getStats().size(); i++) { map.put(flatthelper.getMapDestinationNodes().get(stat.getStats().get(i).id)[0], lst.get(i - 1)); } } for (Statement st : stat.getStats()) { collectCatchVars(st, flatthelper, map); } }
private static boolean inlineSingleBlocksRec(Statement stat) { boolean res = false; for (Statement st : stat.getStats()) { res |= inlineSingleBlocksRec(st); } if (stat.type == Statement.TYPE_SEQUENCE) { SequenceStatement seq = (SequenceStatement)stat; for (int i = 1; i < seq.getStats().size(); i++) { if (isInlineable(seq, i)) { inlineBlock(seq, i); return true; } } } return res; }
private void setCatchMaps(Statement stat, DirectGraph dgraph, FlattenStatementsHelper flatthelper) { SFormsFastMapDirect map; switch (stat.type) { case Statement.TYPE_CATCHALL: case Statement.TYPE_TRYCATCH: List<VarExprent> lstVars; if (stat.type == Statement.TYPE_CATCHALL) { lstVars = ((CatchAllStatement)stat).getVars(); } else { lstVars = ((CatchStatement)stat).getVars(); } for (int i = 1; i < stat.getStats().size(); i++) { int varindex = lstVars.get(i - 1).getIndex(); int version = getNextFreeVersion(varindex); // == 1 map = new SFormsFastMapDirect(); setCurrentVar(map, varindex, version); extraVarVersions.put(dgraph.nodes.getWithKey(flatthelper.getMapDestinationNodes().get(stat.getStats().get(i).id)[0]).id, map); } } for (Statement st : stat.getStats()) { setCatchMaps(st, dgraph, flatthelper); } }
private static boolean isInlineable(SequenceStatement seq, int index) { Statement first = seq.getStats().get(index); Statement pre = seq.getStats().get(index - 1); if (pre.hasBasicSuccEdge()) { return false; } List<StatEdge> lst = first.getPredecessorEdges(StatEdge.TYPE_BREAK); if (lst.size() == 1) { StatEdge edge = lst.get(0); if (sameCatchRanges(edge)) { if (!edge.explicit) { for (int i = index; i < seq.getStats().size(); i++) { if (!noExitLabels(seq.getStats().get(i), seq)) { return false; } } } return true; } // FIXME: count labels properly } return false; }
private void setCatchMaps(Statement stat, DirectGraph dgraph, FlattenStatementsHelper flatthelper) { SFormsFastMapDirect map; switch (stat.type) { case Statement.TYPE_CATCHALL: case Statement.TYPE_TRYCATCH: List<VarExprent> lstVars; if (stat.type == Statement.TYPE_CATCHALL) { lstVars = ((CatchAllStatement)stat).getVars(); } else { lstVars = ((CatchStatement)stat).getVars(); } for (int i = 1; i < stat.getStats().size(); i++) { int varindex = lstVars.get(i - 1).getIndex(); int version = getNextFreeVersion(varindex, stat); // == 1 map = new SFormsFastMapDirect(); setCurrentVar(map, varindex, version); extraVarVersions.put(dgraph.nodes.getWithKey(flatthelper.getMapDestinationNodes().get(stat.getStats().get(i).id)[0]).id, map); //ssuversions.createOrGetNode(new VarVersionPair(varindex, version)); ssuversions.createNode(new VarVersionPair(varindex, version)); } } for (Statement st : stat.getStats()) { setCatchMaps(st, dgraph, flatthelper); } }
private static Statement getNextStatement(Statement stat) { Statement parent = stat.getParent(); switch (parent.type) { case Statement.TYPE_ROOT: return ((RootStatement)parent).getDummyExit(); case Statement.TYPE_DO: return parent; case Statement.TYPE_SEQUENCE: SequenceStatement sequence = (SequenceStatement)parent; if (sequence.getStats().getLast() != stat) { for (int i = sequence.getStats().size() - 1; i >= 0; i--) { if (sequence.getStats().get(i) == stat) { return sequence.getStats().get(i + 1); } } } } return getNextStatement(parent); }
@Override public TextBuffer toJava(int indent, BytecodeMappingTracer tracer) { TextBuffer buf = new TextBuffer(); boolean islabeled = isLabeled(); buf.append(ExprProcessor.listToJava(varDefinitions, indent, tracer)); if (islabeled) { buf.appendIndent(indent++).append("label").append(this.id.toString()).append(": {").appendLineSeparator(); tracer.incrementCurrentSourceLine(); } boolean notempty = false; for (int i = 0; i < stats.size(); i++) { Statement st = stats.get(i); if (i > 0 && notempty) { buf.appendLineSeparator(); tracer.incrementCurrentSourceLine(); } TextBuffer str = ExprProcessor.jmpWrapper(st, indent, false, tracer); buf.append(str); notempty = !str.containsOnlyWhitespaces(); } if (islabeled) { buf.appendIndent(indent-1).append("}").appendLineSeparator(); tracer.incrementCurrentSourceLine(); } return buf; }