private static void introducePreIncrementOptimization(final DecompilerContext context, final Block method) { final Inlining inlining = new Inlining(context, method); inlining.analyzeMethod(); for (final Block block : method.getSelfAndChildrenRecursive(Block.class)) { final List<Node> body = block.getBody(); final MutableInteger position = new MutableInteger(); for (; position.getValue() < body.size() - 1; position.increment()) { if (!introducePreIncrementForVariables(body, position) && !introducePreIncrementForStaticFields(body, position, inlining)) { introducePreIncrementForInstanceFields(body, position, inlining); } } } }
final boolean inlineIfPossible(final List<Node> body, final MutableInteger position) { final int currentPosition = position.getValue(); if (inlineOneIfPossible(body, currentPosition, true)) { position.setValue(currentPosition - inlineInto(body, currentPosition, _aggressive)); return true; } return false; }
private static void increment(final Map<Variable, MutableInteger> map, final Variable variable) { final MutableInteger count = map.get(variable); if (count == null) { map.put(variable, new MutableInteger(1)); } else { count.increment(); } }
private static void parseTypeParameters( final String s, final MutableInteger position, final Type<?> resolvedType, final Type<?>[] typeArguments) { int i = position.getValue(); assert s.charAt(i) == '<'; position.increment(); for (int j = 0; j < typeArguments.length; j++) { typeArguments[j] = parseTypeArgument(s, position, resolvedType, j); } i = position.getValue(); if (s.charAt(i) != '>') { throw Error.invalidSignatureExpectedEndOfTypeArguments(s, i); } position.increment(); }
final int typeArgumentIndex) { int i = position.getValue(); return Type.makeWildcard(); case '+': return Type.makeExtendsWildcard(parseTypeArgument(s, position.increment(), genericType, typeArgumentIndex)); case '-': return Type.makeSuperWildcard(parseTypeArgument(s, position.increment(), genericType, typeArgumentIndex)); case '[': return parseTypeArgument(s, position.increment(), genericType, typeArgumentIndex).makeArrayType(); case 'L': return finishTopLevelType(s, position); while (++i < s.length()) { if (s.charAt(i) == ';') { position.setValue(i + 1); return genericType.getGenericTypeParameters().get(typeArgumentIndex); throw Error.invalidSignatureExpectedTypeArgument(s, position.getValue()); default: throw Error.invalidSignatureUnexpectedToken(s, i);
@Override public MutableInteger get() { return new MutableInteger(); } };
final MutableInteger position = new MutableInteger(); Expression lastParent = parentArguments.get(position.getValue()); for (final Expression e : getParents((Expression) n, parentLookup, parentArguments.get(position.getValue()))) { if (e.getCode().isWriteOperation()) { boolean lastParentFound = false; parentArguments.get(position.getValue()).getRanges() ); parentArguments.set(position.getValue(), inlinedExpression);
int tailStartIndex = startIndex; final MutableInteger tempIndex = new MutableInteger(); tempIndex.setValue(tryEndIndex); if (tempIndex.getValue() > tailStartIndex) { tailStartIndex = tempIndex.getValue(); exceptionHandlers.removeAll(nestedHandlers); tempIndex.setValue(handlersEndIndex); if (tempIndex.getValue() > tailStartIndex) { tailStartIndex = tempIndex.getValue(); if (tailStartIndex < endIndex.getValue()) { ast.addAll(convertToAst(body.subList(tailStartIndex, endIndex.getValue()))); endIndex.setValue(tailStartIndex);
private static boolean introducePreIncrementForVariables(final List<Node> body, final MutableInteger position) { final int i = position.getValue(); if (i >= body.size() - 1) { return false; } final Node node = body.get(i); final Node next = body.get(i + 1); final StrongBox<Variable> v = new StrongBox<>(); final StrongBox<Expression> t = new StrongBox<>(); final StrongBox<Integer> d = new StrongBox<>(); if (!(node instanceof Expression && next instanceof Expression)) { return false; } final Expression e = (Expression) node; final Expression n = (Expression) next; if (matchGetArgument(e, AstCode.Inc, v, t) && matchGetOperand(t.get(), AstCode.LdC, Integer.class, d) && Math.abs(d.get()) == 1 && match(n, AstCode.Store) && matchLoad(n.getArguments().get(0), v.get())) { n.getArguments().set( 0, new Expression(AstCode.PreIncrement, d.get(), n.getArguments().get(0).getOffset(), n.getArguments().get(0)) ); body.remove(i); position.decrement(); return true; } return false; }
static int count(final Map<Variable, MutableInteger> map, final Variable variable) { final MutableInteger count = map.get(variable); return count != null ? count.getValue() : 0; }
public static void inc(MutableInteger val) { System.out.println("inc called: " + val); val.increment(); }
final int typeArgumentIndex) { int i = position.getValue(); return Type.makeWildcard(); case '+': return Type.makeExtendsWildcard(parseTypeArgument(s, position.increment(), genericType, typeArgumentIndex)); case '-': return Type.makeSuperWildcard(parseTypeArgument(s, position.increment(), genericType, typeArgumentIndex)); case '[': return parseTypeArgument(s, position.increment(), genericType, typeArgumentIndex).makeArrayType(); case 'L': return finishTopLevelType(s, position); while (++i < s.length()) { if (s.charAt(i) == ';') { position.setValue(i + 1); return genericType.getGenericTypeParameters().get(typeArgumentIndex); throw Error.invalidSignatureExpectedTypeArgument(s, position.getValue()); default: throw Error.invalidSignatureUnexpectedToken(s, i);
@Override public MutableInteger get() { return new MutableInteger(); } };
private static void parseTypeParameters( final String s, final MutableInteger position, final Type<?> resolvedType, final Type<?>[] typeArguments) { int i = position.getValue(); assert s.charAt(i) == '<'; position.increment(); for (int j = 0; j < typeArguments.length; j++) { typeArguments[j] = parseTypeArgument(s, position, resolvedType, j); } i = position.getValue(); if (s.charAt(i) != '>') { throw Error.invalidSignatureExpectedEndOfTypeArguments(s, i); } position.increment(); }
final MutableInteger position = new MutableInteger(); Expression lastParent = parentArguments.get(position.getValue()); for (final Expression e : getParents((Expression) n, parentLookup, parentArguments.get(position.getValue()))) { if (e.getCode().isWriteOperation()) { boolean lastParentFound = false; parentArguments.get(position.getValue()).getRanges() ); parentArguments.set(position.getValue(), inlinedExpression);
int tailStartIndex = startIndex; final MutableInteger tempIndex = new MutableInteger(); tempIndex.setValue(tryEndIndex); if (tempIndex.getValue() > tailStartIndex) { tailStartIndex = tempIndex.getValue(); exceptionHandlers.removeAll(nestedHandlers); tempIndex.setValue(handlersEndIndex); if (tempIndex.getValue() > tailStartIndex) { tailStartIndex = tempIndex.getValue(); if (tailStartIndex < endIndex.getValue()) { ast.addAll(convertToAst(body.subList(tailStartIndex, endIndex.getValue()))); endIndex.setValue(tailStartIndex);
private static void increment(final Map<Variable, MutableInteger> map, final Variable variable) { final MutableInteger count = map.get(variable); if (count == null) { map.put(variable, new MutableInteger(1)); } else { count.increment(); } }
static int count(final Map<Variable, MutableInteger> map, final Variable variable) { final MutableInteger count = map.get(variable); return count != null ? count.getValue() : 0; }