Search in sources :

Example 46 with Expression

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

the class MethodIntermediateVisitor method visitFRETURN.

public void visitFRETURN(FRETURN instruction) {
    Expression exp = context.getExpressions().pop();
    Return ret = new Return(context.getCurrentInstruction(), exp);
    processReturn(ret);
}
Also used : Return(org.candle.decompiler.intermediate.expression.Return) TypedExpression(org.candle.decompiler.intermediate.expression.TypedExpression) Expression(org.candle.decompiler.intermediate.expression.Expression)

Example 47 with Expression

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

the class MethodIntermediateVisitor method visitIFLT.

// Process all single-value conditionals.
@Override
public void visitIFLT(IFLT instruction) {
    Expression left = context.getExpressions().pop();
    // TODO: this should probably be resolved to it's left expression value for the resovled value.
    Expression right = new Resolved(context.getCurrentInstruction(), null, "0");
    processMultiConditionalStatement(OperationType.LESS, left, right);
}
Also used : TypedExpression(org.candle.decompiler.intermediate.expression.TypedExpression) Expression(org.candle.decompiler.intermediate.expression.Expression) Resolved(org.candle.decompiler.intermediate.expression.Resolved)

Example 48 with Expression

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

the class StatementBlock method write.

@Override
public void write(Writer builder) throws IOException {
    final String indent = buildIndent();
    Expression expression = intermediate.getExpression();
    builder.write(indent);
    expression.write(builder);
    builder.write(";");
}
Also used : Expression(org.candle.decompiler.intermediate.expression.Expression)

Example 49 with Expression

use of org.candle.decompiler.intermediate.expression.Expression 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)

Example 50 with Expression

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

the class ConstantArrayCompressor method collectConstantAssignments.

public void collectConstantAssignments(AbstractIntermediate current, Map<Integer, Expression> assignments) {
    StatementIntermediate si = (StatementIntermediate) current;
    // get the assignment...
    Assignment assignment = extractConstantArrayAssignment(si.getExpression());
    if (assignment == null) {
        return;
    }
    Expression right = assignment.getRightHandSide();
    ArrayAccess apr = (ArrayAccess) assignment.getLeftHandSide();
    assignments.put(toInteger(apr.getIndex()), right);
    List<AbstractIntermediate> predecessor = Graphs.predecessorListOf(igc.getGraph(), current);
    if (predecessor.size() != 1) {
        return;
    }
    if (!(predecessor.get(0) instanceof StatementIntermediate)) {
        return;
    }
    for (AbstractIntermediate a : predecessor) {
        collectConstantAssignments(a, assignments);
    }
}
Also used : Assignment(org.candle.decompiler.intermediate.expression.Assignment) AbstractIntermediate(org.candle.decompiler.intermediate.code.AbstractIntermediate) ArrayAccess(org.candle.decompiler.intermediate.expression.ArrayAccess) Expression(org.candle.decompiler.intermediate.expression.Expression) StatementIntermediate(org.candle.decompiler.intermediate.code.StatementIntermediate)

Aggregations

Expression (org.candle.decompiler.intermediate.expression.Expression)52 TypedExpression (org.candle.decompiler.intermediate.expression.TypedExpression)46 Resolved (org.candle.decompiler.intermediate.expression.Resolved)11 StatementIntermediate (org.candle.decompiler.intermediate.code.StatementIntermediate)10 ArithmeticType (org.candle.decompiler.intermediate.expression.ArithmeticType)10 OperationType (org.candle.decompiler.intermediate.expression.OperationType)10 ArrayList (java.util.ArrayList)6 Assignment (org.candle.decompiler.intermediate.expression.Assignment)6 BooleanBranchIntermediate (org.candle.decompiler.intermediate.code.BooleanBranchIntermediate)5 Return (org.candle.decompiler.intermediate.expression.Return)5 ArrayAccess (org.candle.decompiler.intermediate.expression.ArrayAccess)4 GeneratedVariable (org.candle.decompiler.intermediate.expression.GeneratedVariable)4 MethodInvocation (org.candle.decompiler.intermediate.expression.MethodInvocation)4 MultiConditional (org.candle.decompiler.intermediate.expression.MultiConditional)4 Variable (org.candle.decompiler.intermediate.expression.Variable)4 IntermediateVariable (org.candle.decompiler.intermediate.IntermediateVariable)3 ArrayCreation (org.candle.decompiler.intermediate.expression.ArrayCreation)3 Declaration (org.candle.decompiler.intermediate.expression.Declaration)3 NewConstantArrayInstance (org.candle.decompiler.intermediate.expression.NewConstantArrayInstance)3 AbstractIntermediate (org.candle.decompiler.intermediate.code.AbstractIntermediate)2