rootScopeBlock = new ScopeBlock(0, obj.getLength()); tryBlocks.clear(); catchHandlers.clear(); rootScopeBlock.findBugs(new HashSet<Integer>());
newChild.finishLocation = child.finishLocation; child.addChild(newChild); return;
ScopeBlock sb = findScopeBlockWithTarget(rootScopeBlock, pc, nextPC); if (sb == null) { sb = new ScopeBlock(pc, target); sb.setLoop(); sb.setGoto(); rootScopeBlock.addChild(sb); } else { sb = new ScopeBlock(nextPC, target); sb.setGoto(); rootScopeBlock.addChild(sb); if ((sb != null) && !sb.isLoop() && !sb.isCase() && !sb.hasChildren()) { if (sb.isGoto()) { ScopeBlock parent = sb.getParent(); sb.pushUpLoadStores(); if (parent != null) { parent.removeChild(sb); sb = new ScopeBlock(pc, target); rootScopeBlock.addChild(sb); } else { sb.pushUpLoadStores(); sb.setStart(pc); sb = new ScopeBlock(pc, target); rootScopeBlock.addChild(sb); ScopeBlock sb = findScopeBlock(rootScopeBlock, pc); if (sb != null) {
ScopeBlock sb = findScopeBlockWithTarget(rootScopeBlock, pc, nextPC); if (sb == null) { sb = new ScopeBlock(pc, target); sb.setLoop(); sb.setGoto(); rootScopeBlock.addChild(sb); } else { sb = new ScopeBlock(nextPC, target); sb.setGoto(); rootScopeBlock.addChild(sb); if ((sb != null) && !sb.isLoop() && !sb.isCase() && !sb.hasChildren()) { if (sb.isGoto()) { ScopeBlock parent = sb.getParent(); sb.pushUpLoadStores(); if (parent != null) { parent.removeChild(sb); sb = new ScopeBlock(pc, target); rootScopeBlock.addChild(sb); } else { sb.pushUpLoadStores(); sb.setStart(pc); sb = new ScopeBlock(pc, target); rootScopeBlock.addChild(sb); ScopeBlock sb = findScopeBlock(rootScopeBlock, pc); if (sb != null) {
Integer reg = entry.getKey(); for (ScopeBlock child : children) { if (child.usesReg(reg)) { if (child.isLoop || child.isSync() || child.isTry()) { inIgnoreSB = true; break; if (appearsToBeUserRegister(reg)) { bugReporter.reportBug(new BugInstance(BloatedAssignmentScope.this, BugType.BAS_BLOATED_ASSIGNMENT_SCOPE.name(), NORMAL_PRIORITY) .addClass(BloatedAssignmentScope.this).addMethod(BloatedAssignmentScope.this) child.findBugs(usedRegs);
ScopeBlock sb = new ScopeBlock(pc, findCatchHandlerFor(pc)); sb.setTry(); rootScopeBlock.addChild(sb);
ScopeBlock sb = new ScopeBlock(pc, findCatchHandlerFor(pc)); sb.setTry(); rootScopeBlock.addChild(sb);
ignoreRegs.set(reg); ScopeBlock catchSB = findScopeBlock(rootScopeBlock, pc + 1); if ((catchSB != null) && (catchSB.getStart() < pc)) { ScopeBlock sb = new ScopeBlock(pc, catchSB.getFinish()); catchSB.setFinish(getPC() - 1); rootScopeBlock.addChild(sb); ignoreRegs.set(reg); } else { sb.addStore(reg, pc, assoc); if (sawDup) { sb.addLoad(reg, pc); sb.markFieldAssociatedWrites(reg);
ignoreRegs.set(reg); ScopeBlock catchSB = findScopeBlock(rootScopeBlock, pc + 1); if ((catchSB != null) && (catchSB.getStart() < pc)) { ScopeBlock sb = new ScopeBlock(pc, catchSB.getFinish()); catchSB.setFinish(getPC() - 1); rootScopeBlock.addChild(sb); ignoreRegs.set(reg); } else { sb.addStore(reg, pc, assoc); if (sawDup) { sb.addLoad(reg, pc); sb.markFieldAssociatedWrites(reg);
Integer reg = entry.getKey(); for (ScopeBlock child : children) { if (child.usesReg(reg)) { if (child.isLoop || child.isSync() || child.isTry()) { inIgnoreSB = true; break; if (appearsToBeUserRegister(reg)) { bugReporter.reportBug(new BugInstance(BloatedAssignmentScope.this, BugType.BAS_BLOATED_ASSIGNMENT_SCOPE.name(), NORMAL_PRIORITY) .addClass(BloatedAssignmentScope.this).addMethod(BloatedAssignmentScope.this) child.findBugs(usedRegs);
rootScopeBlock = new ScopeBlock(0, obj.getLength()); tryBlocks.clear(); catchHandlers.clear(); rootScopeBlock.findBugs(new HashSet<Integer>());
newChild.finishLocation = child.finishLocation; child.addChild(newChild); return;
/** * creates a new scope block for each case statement * * @param pc * the current program counter */ private void sawSwitch(int pc) { int[] offsets = getSwitchOffsets(); List<Integer> targets = new ArrayList<>(offsets.length); for (int offset : offsets) { targets.add(Integer.valueOf(offset + pc)); } Integer defOffset = Integer.valueOf(getDefaultSwitchOffset() + pc); if (!targets.contains(defOffset)) { targets.add(defOffset); } Collections.sort(targets); Integer lastTarget = targets.get(0); for (int i = 1; i < targets.size(); i++) { Integer nextTarget = targets.get(i); ScopeBlock sb = new ScopeBlock(lastTarget.intValue(), nextTarget.intValue()); sb.setCase(); rootScopeBlock.addChild(sb); lastTarget = nextTarget; } for (Integer target : targets) { switchTargets.set(target.intValue()); } }
/** * creates a new scope block for each case statement * * @param pc * the current program counter */ private void sawSwitch(int pc) { int[] offsets = getSwitchOffsets(); List<Integer> targets = new ArrayList<>(offsets.length); for (int offset : offsets) { targets.add(Integer.valueOf(offset + pc)); } Integer defOffset = Integer.valueOf(getDefaultSwitchOffset() + pc); if (!targets.contains(defOffset)) { targets.add(defOffset); } Collections.sort(targets); Integer lastTarget = targets.get(0); for (int i = 1; i < targets.size(); i++) { Integer nextTarget = targets.get(i); ScopeBlock sb = new ScopeBlock(lastTarget.intValue(), nextTarget.intValue()); sb.setCase(); rootScopeBlock.addChild(sb); lastTarget = nextTarget; } for (Integer target : targets) { switchTargets.set(target.intValue()); } }
/** * looks for the ScopeBlock has the same parent as this given one, but precedes it in the list. * * @param sb * the scope block to look for the previous scope block * @return the previous sibling scope block, or null if doesn't exist */ @Nullable private ScopeBlock findPreviousSiblingScopeBlock(ScopeBlock sb) { ScopeBlock parent = sb.getParent(); if (parent == null) { return null; } List<ScopeBlock> children = parent.getChildren(); if (children == null) { return null; } ScopeBlock lastSibling = null; for (ScopeBlock sibling : children) { if (sibling.equals(sb)) { return lastSibling; } lastSibling = sibling; } return null; }
/** * returns the scope block in which this register was assigned, by traversing the scope block tree * * @param sb * the scope block to start searching in * @param pc * the current program counter * @return the scope block or null if not found */ @Nullable private ScopeBlock findScopeBlock(ScopeBlock sb, int pc) { if ((pc <= sb.getStart()) || (pc >= sb.getFinish())) { return null; } List<ScopeBlock> children = sb.getChildren(); if (children != null) { for (ScopeBlock child : children) { ScopeBlock foundSb = findScopeBlock(child, pc); if (foundSb != null) { return foundSb; } } } return sb; }
/** * returns the scope block in which this register was assigned, by traversing the scope block tree * * @param sb * the scope block to start searching in * @param pc * the current program counter * @return the scope block or null if not found */ @Nullable private ScopeBlock findScopeBlock(ScopeBlock sb, int pc) { if ((pc <= sb.getStart()) || (pc >= sb.getFinish())) { return null; } if (sb.children != null) { for (ScopeBlock child : sb.children) { ScopeBlock foundSb = findScopeBlock(child, pc); if (foundSb != null) { return foundSb; } } } return sb; }
/** * looks for the ScopeBlock has the same parent as this given one, but precedes it in the list. * * @param sb * the scope block to look for the previous scope block * @return the previous sibling scope block, or null if doesn't exist */ @Nullable private ScopeBlock findPreviousSiblingScopeBlock(ScopeBlock sb) { ScopeBlock parent = sb.getParent(); if (parent == null) { return null; } List<ScopeBlock> children = parent.getChildren(); if (children == null) { return null; } ScopeBlock lastSibling = null; for (ScopeBlock sibling : children) { if (sibling.equals(sb)) { return lastSibling; } lastSibling = sibling; } return null; }