TACInstruction decl, init;
for(int i = 0; i < 4; i++) {
VariableDeclarationStatement s = (VariableDeclarationStatement) stmts.get(i);
Assert.assertTrue("Statement: " + s, s.fragments().size() == 1);
VariableDeclaration d = (VariableDeclaration) s.fragments().get(0);
decl = tac.instruction(d);
Assert.assertNotNull("Statement: " + s, decl);
Assert.assertNotNull("Statement: " + s, d.getInitializer());
if(d.getInitializer() instanceof ParenthesizedExpression)
init = tac.instruction(((ParenthesizedExpression) d.getInitializer()).getExpression());
else
init = tac.instruction(d.getInitializer());
Assert.assertNotNull("Statement: " + s, init);
Assert.assertTrue("Statement: " + s, init instanceof AssignmentInstruction);
Variable t = ((AssignmentInstruction) init).getTarget();
Variable declared = null;
// if(decl instanceof SourceVariableDeclaration) {
// declared = ((SourceVariableDeclaration) decl).getDeclaredVariable();
// Assert.assertEquals("Statement: " + s, declared, t);
// }
// else
if(decl instanceof EclipseInstructionSequence) {
TACInstruction[] seq = ((EclipseInstructionSequence) decl).getInstructions();
Assert.assertTrue("Statement: " + s, seq.length == 2);
Assert.assertTrue("Statement: " + s, seq[0] instanceof SourceVariableDeclaration);
declared = ((SourceVariableDeclaration) seq[0]).getDeclaredVariable();
Assert.assertTrue("Statement: " + s, seq[1] instanceof CopyInstruction);
Assert.assertEquals("Statement: " + s, declared, ((CopyInstruction) seq[1]).getTarget());
Assert.assertEquals("Statement: " + s, t, ((CopyInstruction) seq[1]).getOperand());
}
else
Assert.fail("Statement has unexpected translation: " + s);
Assert.assertEquals("Statement: " + s, tac.sourceVariable(d.resolveBinding()), declared);
}
}