| 274 | } |
| 275 | |
| 276 | private static <T extends Item> void replaceAll(Item item, T from, T to, BitSet visited) { |
| 277 | int index = item.getIndex(); |
| 278 | // Check whether already visited this item |
| 279 | if (item != from && !visited.get(index)) { |
| 280 | // Record that have now visited |
| 281 | visited.set(index); |
| 282 | // Attempt the replacement |
| 283 | Item[] children = item.getAll(); |
| 284 | if(children != null) { |
| 285 | for (int i = 0; i != children.length; ++i) { |
| 286 | // Apply the replacement. |
| 287 | if (children[i] == from) { |
| 288 | // Time for replacement! |
| 289 | item.setOperand(i, to); |
| 290 | } else { |
| 291 | // Recursively traverse children. |
| 292 | replaceAll(children[i],from,to,visited); |
| 293 | } |
| 294 | } |
| 295 | } |
| 296 | } |
| 297 | } |
| 298 | |
| 299 | /** |
| 300 | * Mark all reachable items from a given item, whilst ignoring references. That |