Search in sources :

Example 11 with Expression

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

the class MethodIntermediateVisitor method processInvoke.

public void processInvoke(InvokeInstruction instruction, int nparams) {
    //collect all parameters from the stack.
    final List<Expression> parameters = new ArrayList<Expression>(nparams);
    for (int i = 0; i < nparams; i++) {
        Expression param = context.getExpressions().pop();
        LOG.debug("Parameter: " + param);
        parameters.add(param);
    }
    //now, get the target that we are calling the method on.
    Expression target = context.getExpressions().pop();
    //collect the method name we are calling.
    String methodName = instruction.getMethodName(context.getMethodGen().getConstantPool());
    //create the expression..
    MethodInvocation methodInvocation = new MethodInvocation(context.getCurrentInstruction(), target, methodName, parameters);
    Type returned = instruction.getReturnType(context.getMethodGen().getConstantPool());
    if (returned == BasicType.VOID) {
        StatementIntermediate completeLine = new StatementIntermediate(context.getCurrentInstruction(), methodInvocation);
        context.pushIntermediateToInstruction(completeLine);
        LOG.debug("Pushed complete line: " + completeLine.toString());
    } else {
        context.getExpressions().push(methodInvocation);
        LOG.debug("Pushed expression: " + methodInvocation);
    }
}
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) StatementIntermediate(org.candle.decompiler.intermediate.code.StatementIntermediate) ArrayList(java.util.ArrayList) MethodInvocation(org.candle.decompiler.intermediate.expression.MethodInvocation)

Example 12 with Expression

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

the class MethodIntermediateVisitor method visitDUP2_X1.

public void visitDUP2_X1(DUP2_X1 instruction) {
    Expression one = context.getExpressions().pop();
    Expression two = context.getExpressions().pop();
    Expression three = context.getExpressions().pop();
    //push on 1, 2
    context.getExpressions().push(two);
    context.getExpressions().push(one);
    //push on 1, 2, 3
    context.getExpressions().push(three);
    context.getExpressions().push(two);
    context.getExpressions().push(one);
}
Also used : TypedExpression(org.candle.decompiler.intermediate.expression.TypedExpression) Expression(org.candle.decompiler.intermediate.expression.Expression)

Example 13 with Expression

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

the class MethodIntermediateVisitor method visitLCMP.

public void visitLCMP(LCMP instruction) {
    Expression left = context.getExpressions().pop();
    Expression right = context.getExpressions().pop();
    MultiConditional eq = new MultiConditional(context.getCurrentInstruction(), left, right, OperationType.EQ);
    MultiConditional logic = new MultiConditional(context.getCurrentInstruction(), left, right, OperationType.GREATER);
    Resolved r0 = new Resolved(context.getCurrentInstruction(), Type.INT, "0");
    Resolved rN = new Resolved(context.getCurrentInstruction(), Type.INT, "-1");
    Resolved rP = new Resolved(context.getCurrentInstruction(), Type.INT, "1");
    Ternary tern2 = new Ternary(context.getCurrentInstruction(), ObjectType.INT, logic, rP, rN);
    Ternary tern1 = new Ternary(context.getCurrentInstruction(), Type.INT, eq, r0, tern2);
    context.getExpressions().push(tern1);
}
Also used : TypedExpression(org.candle.decompiler.intermediate.expression.TypedExpression) Expression(org.candle.decompiler.intermediate.expression.Expression) Ternary(org.candle.decompiler.intermediate.expression.Ternary) Resolved(org.candle.decompiler.intermediate.expression.Resolved) MultiConditional(org.candle.decompiler.intermediate.expression.MultiConditional)

Example 14 with Expression

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

the class MethodIntermediateVisitor method visitConversionInstruction.

public void visitConversionInstruction(ConversionInstruction instruction) {
    ConstantPoolGen cpg = context.getMethodGen().getConstantPool();
    Expression right = context.getExpressions().pop();
    Type type = instruction.getType(cpg);
    //now see what type it is.
    LOG.debug("To Type: " + type);
    Resolved resolve = new Resolved(context.getCurrentInstruction(), type, type.toString());
    Cast cast = new Cast(context.getCurrentInstruction(), resolve, right);
    context.getExpressions().push(cast);
}
Also used : Cast(org.candle.decompiler.intermediate.expression.Cast) 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) Resolved(org.candle.decompiler.intermediate.expression.Resolved)

Example 15 with Expression

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

the class MethodIntermediateVisitor method visitDUP.

//Now provide the suplication visitors
public void visitDUP(DUP instruction) {
    Expression exp = context.getExpressions().pop();
    try {
        Expression dup = (Expression) exp.clone();
        dup.setInstructionHandle(context.getCurrentInstruction());
        context.getExpressions().push(dup);
        context.getExpressions().push(exp);
    } catch (CloneNotSupportedException e) {
        LOG.error("Exception duplicating expression: " + exp.toString(), e);
    }
}
Also used : TypedExpression(org.candle.decompiler.intermediate.expression.TypedExpression) Expression(org.candle.decompiler.intermediate.expression.Expression)

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