Search in sources :

Example 1 with Assignment

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

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

the class MethodIntermediateVisitor method visitPUTFIELD.

public void visitPUTFIELD(PUTFIELD instruction) {
    ConstantPoolGen cpg = context.getMethodGen().getConstantPool();
    String fieldName = instruction.getFieldName(cpg);
    Expression right = context.getExpressions().pop();
    Expression left = context.getExpressions().pop();
    FieldAccess fieldRef = new FieldAccess(context.getCurrentInstruction(), left, fieldName);
    Assignment assignment = new Assignment(context.getCurrentInstruction(), fieldRef, right);
    StatementIntermediate complete = new StatementIntermediate(context.getCurrentInstruction(), assignment);
    context.pushIntermediateToInstruction(complete);
}
Also used : Assignment(org.candle.decompiler.intermediate.expression.Assignment) TypedExpression(org.candle.decompiler.intermediate.expression.TypedExpression) Expression(org.candle.decompiler.intermediate.expression.Expression) StatementIntermediate(org.candle.decompiler.intermediate.code.StatementIntermediate) FieldAccess(org.candle.decompiler.intermediate.expression.FieldAccess)

Example 3 with Assignment

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

the class MethodIntermediateVisitor method visitPUTSTATIC.

public void visitPUTSTATIC(PUTSTATIC instruction) {
    ConstantPoolGen cpg = context.getMethodGen().getConstantPool();
    String fieldName = instruction.getFieldName(cpg);
    Type fieldType = instruction.getFieldType(cpg);
    Expression right = context.getExpressions().pop();
    Variable variable = new Variable(context.getCurrentInstruction(), fieldType, fieldName);
    Assignment assignment = new Assignment(context.getCurrentInstruction(), variable, right);
    if (LOG.isDebugEnabled()) {
        for (Field field : context.getJavaClass().getFields()) {
            LOG.debug(field);
        }
    }
    StatementIntermediate complete = new StatementIntermediate(context.getCurrentInstruction(), assignment);
    context.pushIntermediateToInstruction(complete);
}
Also used : Assignment(org.candle.decompiler.intermediate.expression.Assignment) Field(org.apache.bcel.classfile.Field) OperationType(org.candle.decompiler.intermediate.expression.OperationType) ArithmeticType(org.candle.decompiler.intermediate.expression.ArithmeticType) GeneratedVariable(org.candle.decompiler.intermediate.expression.GeneratedVariable) Variable(org.candle.decompiler.intermediate.expression.Variable) IntermediateVariable(org.candle.decompiler.intermediate.IntermediateVariable) TypedExpression(org.candle.decompiler.intermediate.expression.TypedExpression) Expression(org.candle.decompiler.intermediate.expression.Expression) StatementIntermediate(org.candle.decompiler.intermediate.code.StatementIntermediate)

Example 4 with Assignment

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

the class MethodIntermediateVisitor method visitStoreInstruction.

public void visitStoreInstruction(StoreInstruction instruction) {
    Expression right = this.context.getExpressions().pop();
    Type type = instruction.getType(context.getMethodGen().getConstantPool());
    // first, check to see whether the variable currently has been declared.
    // this would be the case if we don't get null when looking up the local variable.
    int pc = context.getCurrentInstruction().getPosition();
    int lvtIndex = instruction.getIndex();
    IntermediateVariable iv = context.getVariableResolver().getLocalVariable(lvtIndex, pc);
    // if the variable is not null, it is declared.
    boolean declared = (iv != null);
    Variable variable = null;
    if (!declared) {
        // look it up from the next phase code.
        pc = this.context.getCurrentInstruction().getNext().getPosition();
        iv = context.getVariableResolver().getLocalVariable(lvtIndex, pc);
        if (iv == null) {
            // probably need to create a variable for enhanced loops...
            LOG.debug("Adding index: " + instruction.getIndex() + " as: " + type);
            // try and resolve the type for the variable from the right hand side.
            if (type == Type.OBJECT) {
                if (right instanceof TypedExpression) {
                    type = ((TypedExpression) right).getType();
                }
            }
            // generate variable name...
            iv = context.getVariableResolver().addLocalVariable(instruction.getIndex(), context.getCurrentInstruction(), type);
            variable = new GeneratedVariable(context.getCurrentInstruction(), iv.getType(), iv.getName());
        }
    }
    // create the variable.
    if (variable == null) {
        variable = new Variable(context.getCurrentInstruction(), iv.getType(), iv.getName());
    }
    // create the assignment.
    Assignment assignment = new Assignment(context.getCurrentInstruction(), variable, right);
    Expression left = null;
    if (declared) {
        left = assignment;
    } else {
        // if it is currently not declared... create the declaration.
        left = new Declaration(context.getCurrentInstruction(), variable, assignment);
    }
    StatementIntermediate cl = new StatementIntermediate(context.getCurrentInstruction(), left);
    context.pushIntermediateToInstruction(cl);
    LOG.debug("Stored.");
}
Also used : Assignment(org.candle.decompiler.intermediate.expression.Assignment) OperationType(org.candle.decompiler.intermediate.expression.OperationType) ArithmeticType(org.candle.decompiler.intermediate.expression.ArithmeticType) IntermediateVariable(org.candle.decompiler.intermediate.IntermediateVariable) GeneratedVariable(org.candle.decompiler.intermediate.expression.GeneratedVariable) Variable(org.candle.decompiler.intermediate.expression.Variable) IntermediateVariable(org.candle.decompiler.intermediate.IntermediateVariable) GeneratedVariable(org.candle.decompiler.intermediate.expression.GeneratedVariable) TypedExpression(org.candle.decompiler.intermediate.expression.TypedExpression) Expression(org.candle.decompiler.intermediate.expression.Expression) StatementIntermediate(org.candle.decompiler.intermediate.code.StatementIntermediate) Declaration(org.candle.decompiler.intermediate.expression.Declaration) TypedExpression(org.candle.decompiler.intermediate.expression.TypedExpression)

Example 5 with Assignment

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

the class MethodIntermediateVisitor method processArrayStore.

protected void processArrayStore() {
    Expression value = context.getExpressions().pop();
    Expression arrayPosition = context.getExpressions().pop();
    Expression arrayReference = context.getExpressions().pop();
    ArrayAccess arrayPositionReference = new ArrayAccess(context.getCurrentInstruction(), arrayReference, arrayPosition);
    Assignment assignment = new Assignment(context.getCurrentInstruction(), arrayPositionReference, value);
    StatementIntermediate si = new StatementIntermediate(context.getCurrentInstruction(), assignment);
    // add it to the intermediate lines.
    context.pushIntermediateToInstruction(si);
}
Also used : Assignment(org.candle.decompiler.intermediate.expression.Assignment) ArrayAccess(org.candle.decompiler.intermediate.expression.ArrayAccess) TypedExpression(org.candle.decompiler.intermediate.expression.TypedExpression) Expression(org.candle.decompiler.intermediate.expression.Expression) StatementIntermediate(org.candle.decompiler.intermediate.code.StatementIntermediate)

Aggregations

Assignment (org.candle.decompiler.intermediate.expression.Assignment)7 Expression (org.candle.decompiler.intermediate.expression.Expression)6 StatementIntermediate (org.candle.decompiler.intermediate.code.StatementIntermediate)5 TypedExpression (org.candle.decompiler.intermediate.expression.TypedExpression)4 ArrayAccess (org.candle.decompiler.intermediate.expression.ArrayAccess)3 IntermediateVariable (org.candle.decompiler.intermediate.IntermediateVariable)2 AbstractIntermediate (org.candle.decompiler.intermediate.code.AbstractIntermediate)2 ArithmeticType (org.candle.decompiler.intermediate.expression.ArithmeticType)2 Declaration (org.candle.decompiler.intermediate.expression.Declaration)2 GeneratedVariable (org.candle.decompiler.intermediate.expression.GeneratedVariable)2 NewConstantArrayInstance (org.candle.decompiler.intermediate.expression.NewConstantArrayInstance)2 OperationType (org.candle.decompiler.intermediate.expression.OperationType)2 Variable (org.candle.decompiler.intermediate.expression.Variable)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Field (org.apache.bcel.classfile.Field)1 ConstantArray (org.candle.decompiler.intermediate.expression.ConstantArray)1 FieldAccess (org.candle.decompiler.intermediate.expression.FieldAccess)1 Resolved (org.candle.decompiler.intermediate.expression.Resolved)1