public void add(IfBlock block) { if (blocks.isEmpty()) { blocks.addLast(block); return; } IfBlock lastBlock = blocks.getLast(); if (block.getStart() > lastBlock.getEnd()) { blocks.addLast(block); } else { lastBlock.getSubIfBlocks().add(block); } }
public void add(IfBlock block) { if (blocks.isEmpty()) { blocks.addLast(block); return; } IfBlock lastBlock = blocks.getLast(); if (block.getStart() > lastBlock.getEnd()) { blocks.addLast(block); } else { lastBlock.getSubIfBlocks().add(block); } }
@Nullable public IfBlock getBlockAt(int pc) { if (blocks.isEmpty()) { return null; } Iterator<IfBlock> it = blocks.iterator(); while (it.hasNext()) { IfBlock block = it.next(); if ((pc >= block.getStart()) && (pc <= block.getEnd())) { if (block.hasSubBlocks()) { IfBlock foundBlock = block.getSubIfBlocks().getBlockAt(pc); if (foundBlock != null) { return foundBlock; } } return block; } } return null; }
/** * counts all blocks including nested block that are closed off at the current pc * * @param pc * the current pc * @return how many blocks have ended at the pc */ public int countBlockEndsAtPC(int pc) { if (blocks.isEmpty()) { return 0; } int count = 0; Iterator<IfBlock> it = blocks.iterator(); while (it.hasNext()) { IfBlock block = it.next(); if (pc >= block.getStart()) { if (block.hasSubBlocks()) { count += block.getSubIfBlocks().countBlockEndsAtPC(pc); } } if (pc == block.getEnd()) { count++; } } return count; }
/** * counts all blocks including nested block that are closed off at the current pc * * @param pc * the current pc * @return how many blocks have ended at the pc */ public int countBlockEndsAtPC(int pc) { if (blocks.isEmpty()) { return 0; } int count = 0; Iterator<IfBlock> it = blocks.iterator(); while (it.hasNext()) { IfBlock block = it.next(); if (pc >= block.getStart()) { if (block.hasSubBlocks()) { count += block.getSubIfBlocks().countBlockEndsAtPC(pc); } } if (pc == block.getEnd()) { count++; } } return count; }
@Nullable public IfBlock getBlockAt(int pc) { if (blocks.isEmpty()) { return null; } Iterator<IfBlock> it = blocks.iterator(); while (it.hasNext()) { IfBlock block = it.next(); if ((pc >= block.getStart()) && (pc <= block.getEnd())) { if (block.hasSubBlocks()) { IfBlock foundBlock = block.getSubIfBlocks().getBlockAt(pc); if (foundBlock != null) { return foundBlock; } } return block; } } return null; }