Search in sources :

Example 1 with NewConstantArrayInstance

use of org.candle.decompiler.intermediate.expression.NewConstantArrayInstance in project candle-decompiler by bradsdavis.

the class ConstantArrayCompressor method extractConstantArrayAssignment.

public Assignment extractConstantArrayAssignment(Expression line) {
    if (!(line instanceof Assignment)) {
        return null;
    }
    Assignment assignment = (Assignment) line;
    if (!(assignment.getLeftHandSide() instanceof ArrayAccess)) {
        return null;
    }
    ArrayAccess apr = (ArrayAccess) assignment.getLeftHandSide();
    if (!(apr.getArray() instanceof NewConstantArrayInstance)) {
        return null;
    }
    return assignment;
}
Also used : Assignment(org.candle.decompiler.intermediate.expression.Assignment) ArrayAccess(org.candle.decompiler.intermediate.expression.ArrayAccess) NewConstantArrayInstance(org.candle.decompiler.intermediate.expression.NewConstantArrayInstance)

Example 2 with NewConstantArrayInstance

use of org.candle.decompiler.intermediate.expression.NewConstantArrayInstance in project candle-decompiler by bradsdavis.

the class MethodIntermediateVisitor method visitANEWARRAY.

/**
	 * Decompiles "new object array" operations. 
	 */
public void visitANEWARRAY(ANEWARRAY instruction) {
    Type type = instruction.getType(context.getMethodGen().getConstantPool());
    Expression count = context.getExpressions().pop();
    ArrayCreation nai = null;
    if (context.getCurrentInstruction().getNext().getInstruction() instanceof DUP) {
        nai = new NewConstantArrayInstance(context.getCurrentInstruction(), type, count);
    } else {
        nai = new ArrayCreation(context.getCurrentInstruction(), type, count);
    }
    context.getExpressions().push(nai);
}
Also used : OperationType(org.candle.decompiler.intermediate.expression.OperationType) ArithmeticType(org.candle.decompiler.intermediate.expression.ArithmeticType) TypedExpression(org.candle.decompiler.intermediate.expression.TypedExpression) Expression(org.candle.decompiler.intermediate.expression.Expression) ArrayCreation(org.candle.decompiler.intermediate.expression.ArrayCreation) NewConstantArrayInstance(org.candle.decompiler.intermediate.expression.NewConstantArrayInstance)

Example 3 with NewConstantArrayInstance

use of org.candle.decompiler.intermediate.expression.NewConstantArrayInstance in project candle-decompiler by bradsdavis.

the class MethodIntermediateVisitor method visitNEWARRAY.

/**
	 * Decompiles "new primitive array" operations. 
	 */
public void visitNEWARRAY(NEWARRAY instruction) {
    //first, check to see if the next instruction is a DUP.  If so,
    //this is probably a constant array value.
    Expression count = context.getExpressions().pop();
    ArrayCreation nai = null;
    if (context.getCurrentInstruction().getNext().getInstruction() instanceof DUP) {
        nai = new NewConstantArrayInstance(context.getCurrentInstruction(), instruction.getType(), count);
    } else {
        nai = new ArrayCreation(context.getCurrentInstruction(), instruction.getType(), count);
    }
    context.getExpressions().push(nai);
}
Also used : TypedExpression(org.candle.decompiler.intermediate.expression.TypedExpression) Expression(org.candle.decompiler.intermediate.expression.Expression) ArrayCreation(org.candle.decompiler.intermediate.expression.ArrayCreation) NewConstantArrayInstance(org.candle.decompiler.intermediate.expression.NewConstantArrayInstance)

Example 4 with NewConstantArrayInstance

use of org.candle.decompiler.intermediate.expression.NewConstantArrayInstance in project candle-decompiler by bradsdavis.

the class ConstantArrayCompressor method visitStatementIntermediate.

@Override
public void visitStatementIntermediate(StatementIntermediate line) {
    //first, look for the 
    Assignment assignment = extractConstantArrayAssignment(line.getExpression());
    if (assignment == null) {
        return;
    }
    //at this point, we know both the statement is an assignment, and that the left assignment is to a constant array value.
    //find the one that is right before the array assignment.
    Declaration declaration = extractNextDeclaration(line);
    //if we didn't find the declaration, this must not be the constant array assignment proceeding the declaration.
    if (declaration == null) {
        return;
    }
    //check the right hand of the declaration...
    if (!(declaration.getAssignment().getRightHandSide() instanceof NewConstantArrayInstance)) {
        return;
    }
    NewConstantArrayInstance ncai = (NewConstantArrayInstance) declaration.getAssignment().getRightHandSide();
    Expression countExpression = ncai.getCount();
    AbstractIntermediate current = line;
    Map<Integer, Expression> values = new HashMap<Integer, Expression>();
    collectConstantAssignments(current, values);
    //create a new array...
    Integer count = toInteger(countExpression);
    List<Expression> expressions = new ArrayList<Expression>(count);
    for (int i = 0, j = count; i < j; i++) {
        Expression exp = null;
        if (values.containsKey(i)) {
            exp = values.get(i);
        } else {
            exp = new Resolved(ncai.getInstructionHandle(), Type.NULL, "null");
        }
        expressions.add(i, exp);
    }
    //ok, we have the stack... now we need to just create a new expression.
    //create the contant...
    ConstantArray constantArray = new ConstantArray(declaration.getAssignment().getRightHandSide().getInstructionHandle(), expressions);
    declaration.getAssignment().setRightHandSide(constantArray);
    //excellent.  we have reordered the statements into the appropriate ContantArray assignment.  Now, we need to remove the dead nodes and heal the graph.
    AbstractIntermediate next = Graphs.successorListOf(igc.getGraph(), line).get(0);
    //loop through the dead elements...
    //we know the number of dead items is equal to the number of values we found.
    healGraph(line, next, values.size());
}
Also used : AbstractIntermediate(org.candle.decompiler.intermediate.code.AbstractIntermediate) ConstantArray(org.candle.decompiler.intermediate.expression.ConstantArray) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) NewConstantArrayInstance(org.candle.decompiler.intermediate.expression.NewConstantArrayInstance) Assignment(org.candle.decompiler.intermediate.expression.Assignment) Expression(org.candle.decompiler.intermediate.expression.Expression) Resolved(org.candle.decompiler.intermediate.expression.Resolved) Declaration(org.candle.decompiler.intermediate.expression.Declaration)

Aggregations

NewConstantArrayInstance (org.candle.decompiler.intermediate.expression.NewConstantArrayInstance)4 Expression (org.candle.decompiler.intermediate.expression.Expression)3 ArrayCreation (org.candle.decompiler.intermediate.expression.ArrayCreation)2 Assignment (org.candle.decompiler.intermediate.expression.Assignment)2 TypedExpression (org.candle.decompiler.intermediate.expression.TypedExpression)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 AbstractIntermediate (org.candle.decompiler.intermediate.code.AbstractIntermediate)1 ArithmeticType (org.candle.decompiler.intermediate.expression.ArithmeticType)1 ArrayAccess (org.candle.decompiler.intermediate.expression.ArrayAccess)1 ConstantArray (org.candle.decompiler.intermediate.expression.ConstantArray)1 Declaration (org.candle.decompiler.intermediate.expression.Declaration)1 OperationType (org.candle.decompiler.intermediate.expression.OperationType)1 Resolved (org.candle.decompiler.intermediate.expression.Resolved)1