use of org.candle.decompiler.intermediate.expression.TypedExpression 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.");
}
Aggregations