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;
}
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;
}
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);
}
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);
}
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);
}
}
Aggregations