Node root = (new Compiler()).parseTestCode(";" + code);
for (Node n = root; n != null; n = n.getFirstChild()) {
ancestors.add(0, n);
}
FunctionlessLocalScope searchIt = new FunctionlessLocalScope(
ancestors.toArray(new Node[ancestors.size()]));
boolean found = false;
while (searchIt.hasNext()) {
Node n = searchIt.next();
if (n.getType() == Token.NAME &&
searchIt.currentParent().getType() == Token.VAR &&
n.getString().equals("X")) {
found = true;
break;
}
}
assertTrue("Variable X not found! " + root.toStringTree(), found);
List<Node> currentAncestors = searchIt.currentAncestors();
assert(currentAncestors.size() >= 3);
Iterator<Node> moveIt = LocalVarMotion.forVar(
currentAncestors.get(0),
currentAncestors.get(1),
currentAncestors.get(2));