Search in sources :

Example 1 with ArrayAccess

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

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

the class ArrayForToEnhancedFor method firstMatchesGeneratedVariables.

private boolean firstMatchesGeneratedVariables(StatementIntermediate first, GeneratedVariable generatedArrayRef, GeneratedVariable generatedArrayIterator) {
    Declaration childDeclaration = (Declaration) first.getExpression();
    Expression right = childDeclaration.getAssignment().getRightHandSide();
    if (right instanceof ArrayAccess) {
        ArrayAccess apr = (ArrayAccess) right;
        if (!(apr.getIndex() instanceof Variable)) {
            return false;
        }
        if (!(apr.getArray() instanceof Variable)) {
            return false;
        }
        // cast both to variable. check the variables match the name and type of the ones found above.
        Variable arrayPosition = (Variable) apr.getArray();
        Variable arrayRef = (Variable) apr.getArray();
        if (!StringUtils.equals(arrayPosition.getName(), generatedArrayIterator.getName())) {
            return false;
        }
        if (!StringUtils.equals(arrayRef.getName(), generatedArrayRef.getName())) {
            return false;
        }
        return true;
    }
    return true;
}
Also used : ArrayAccess(org.candle.decompiler.intermediate.expression.ArrayAccess) GeneratedVariable(org.candle.decompiler.intermediate.expression.GeneratedVariable) Variable(org.candle.decompiler.intermediate.expression.Variable) Expression(org.candle.decompiler.intermediate.expression.Expression) Declaration(org.candle.decompiler.intermediate.expression.Declaration)

Example 3 with ArrayAccess

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

the class MethodIntermediateVisitor method processArrayLoad.

// array load operations
protected void processArrayLoad() {
    Expression arrayPosition = context.getExpressions().pop();
    Expression arrayObject = context.getExpressions().pop();
    // now, we just need to create the array reference.
    ArrayAccess apr = new ArrayAccess(context.getCurrentInstruction(), arrayObject, arrayPosition);
    context.getExpressions().push(apr);
}
Also used : ArrayAccess(org.candle.decompiler.intermediate.expression.ArrayAccess) TypedExpression(org.candle.decompiler.intermediate.expression.TypedExpression) Expression(org.candle.decompiler.intermediate.expression.Expression)

Example 4 with ArrayAccess

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

Example 5 with ArrayAccess

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

ArrayAccess (org.candle.decompiler.intermediate.expression.ArrayAccess)5 Expression (org.candle.decompiler.intermediate.expression.Expression)4 Assignment (org.candle.decompiler.intermediate.expression.Assignment)3 StatementIntermediate (org.candle.decompiler.intermediate.code.StatementIntermediate)2 TypedExpression (org.candle.decompiler.intermediate.expression.TypedExpression)2 AbstractIntermediate (org.candle.decompiler.intermediate.code.AbstractIntermediate)1 Declaration (org.candle.decompiler.intermediate.expression.Declaration)1 GeneratedVariable (org.candle.decompiler.intermediate.expression.GeneratedVariable)1 NewConstantArrayInstance (org.candle.decompiler.intermediate.expression.NewConstantArrayInstance)1 Variable (org.candle.decompiler.intermediate.expression.Variable)1