Search in sources :

Example 11 with Resolved

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

the class MethodIntermediateVisitor method visitIFLE.

@Override
public void visitIFLE(IFLE obj) {
    Expression right = new Resolved(context.getCurrentInstruction(), null, "0");
    Expression left = context.getExpressions().pop();
    processMultiConditionalStatement(OperationType.LESS_EQUAL, 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 12 with Resolved

use of org.candle.decompiler.intermediate.expression.Resolved 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 13 with Resolved

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

the class MethodIntermediateVisitor method visitIFGT.

@Override
public void visitIFGT(IFGT instruction) {
    Expression right = new Resolved(context.getCurrentInstruction(), null, "0");
    Expression left = context.getExpressions().pop();
    processMultiConditionalStatement(OperationType.GREATER, 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 14 with Resolved

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

the class MethodIntermediateVisitor method visitINVOKESTATIC.

public void visitINVOKESTATIC(INVOKESTATIC instruction) {
    //collect all parameters from the stack.
    ConstantPoolGen cpg = context.getMethodGen().getConstantPool();
    Type[] types = instruction.getArgumentTypes(context.getMethodGen().getConstantPool());
    final List<Expression> parameters = new ArrayList<Expression>(types.length);
    for (int i = 0, j = types.length; i < j; i++) {
        Expression param = context.getExpressions().pop();
        LOG.debug("Parameter: " + param);
        parameters.add(param);
    }
    Resolved resolvedType = new Resolved(context.getCurrentInstruction(), Type.CLASS, instruction.getLoadClassType(cpg).getClassName());
    String methodName = instruction.getMethodName(cpg);
    //create the expression..
    MethodInvocation methodInvocation = new MethodInvocation(context.getCurrentInstruction(), resolvedType, methodName, parameters);
    Type returned = instruction.getReturnType(context.getMethodGen().getConstantPool());
    if (returned == BasicType.VOID) {
        LOG.debug("This is a void return type!!");
        StatementIntermediate completeLine = new StatementIntermediate(context.getCurrentInstruction(), methodInvocation);
        context.pushIntermediateToInstruction(completeLine);
    } else {
        context.getExpressions().push(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) Resolved(org.candle.decompiler.intermediate.expression.Resolved) MethodInvocation(org.candle.decompiler.intermediate.expression.MethodInvocation)

Example 15 with Resolved

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

the class MethodIntermediateVisitor method processNegation.

//negate operations
protected void processNegation(Type type) {
    //negation is the same as multiplying by negative 1; more readable.
    //push a negative 1 to the stack.
    Expression negativeOne = new Resolved(context.getCurrentInstruction(), type, "-1");
    context.getExpressions().push(negativeOne);
    processArithmeticTwoStackOperations(ArithmeticType.MULTIPLY);
}
Also used : TypedExpression(org.candle.decompiler.intermediate.expression.TypedExpression) Expression(org.candle.decompiler.intermediate.expression.Expression) Resolved(org.candle.decompiler.intermediate.expression.Resolved)

Aggregations

Resolved (org.candle.decompiler.intermediate.expression.Resolved)20 Expression (org.candle.decompiler.intermediate.expression.Expression)11 TypedExpression (org.candle.decompiler.intermediate.expression.TypedExpression)10 ArithmeticType (org.candle.decompiler.intermediate.expression.ArithmeticType)4 OperationType (org.candle.decompiler.intermediate.expression.OperationType)4 ArrayList (java.util.ArrayList)2 ConstantClass (org.apache.bcel.classfile.ConstantClass)2 InstructionHandle (org.apache.bcel.generic.InstructionHandle)2 AbstractIntermediate (org.candle.decompiler.intermediate.code.AbstractIntermediate)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 ObjectType (org.apache.bcel.generic.ObjectType)1 Select (org.apache.bcel.generic.Select)1 CaseIntermediate (org.candle.decompiler.intermediate.code.CaseIntermediate)1 StatementIntermediate (org.candle.decompiler.intermediate.code.StatementIntermediate)1 Assignment (org.candle.decompiler.intermediate.expression.Assignment)1 Case (org.candle.decompiler.intermediate.expression.Case)1 Cast (org.candle.decompiler.intermediate.expression.Cast)1 ConstantArray (org.candle.decompiler.intermediate.expression.ConstantArray)1 Declaration (org.candle.decompiler.intermediate.expression.Declaration)1