[Fb-contrib-commit] SF.net SVN: fb-contrib: [731] trunk/fb-contrib/src/com/mebigfatguy/ fbcontrib/
Brought to you by:
dbrosius
From: <dbr...@us...> - 2006-12-16 09:06:20
|
Revision: 731 http://svn.sourceforge.net/fb-contrib/?rev=731&view=rev Author: dbrosius Date: 2006-12-16 01:06:19 -0800 (Sat, 16 Dec 2006) Log Message: ----------- if a variable is used in a parent scope, don't report on it at a child scope. Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java 2006-12-16 07:34:52 UTC (rev 730) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java 2006-12-16 09:06:19 UTC (rev 731) @@ -114,7 +114,7 @@ super.visitCode(obj); if (!dontReport) - rootScopeBlock.findBugs(); + rootScopeBlock.findBugs(new HashSet<Integer>()); } finally { rootScopeBlock = null; @@ -473,40 +473,50 @@ /** * report stores that occur at scopes higher than associated loads that are not involved with loops */ - public void findBugs() { + public void findBugs(Set<Integer> parentUsedRegs) { if (isLoop) return; + Set<Integer> usedRegs = new HashSet<Integer>(parentUsedRegs); + if (stores != null) + usedRegs.addAll(stores.keySet()); + if (loads != null) + usedRegs.addAll(loads.keySet()); + if (stores != null) { if (loads != null) stores.keySet().removeAll(loads.keySet()); + stores.keySet().removeAll(parentUsedRegs); - if (children != null) { - for (Map.Entry<Integer, Integer> entry : stores.entrySet()) { - int childUseCount = 0; - boolean inLoop = false; - for (ScopeBlock child : children) { - if (child.usesReg(entry.getKey())) { - if (child.isLoop) { - inLoop = true; - break; - } - childUseCount++; - } - } - if ((!inLoop) && (childUseCount == 1)) { - bugReporter.reportBug(new BugInstance(BloatedAssignmentScope.this, "BAS_BLOATED_ASSIGNMENT_SCOPE", NORMAL_PRIORITY) - .addClass(BloatedAssignmentScope.this) - .addMethod(BloatedAssignmentScope.this) - .addSourceLine(BloatedAssignmentScope.this, entry.getValue())); - } - } - } + if (stores.size() > 0) { + if (children != null) { + for (Map.Entry<Integer, Integer> entry : stores.entrySet()) { + int childUseCount = 0; + boolean inLoop = false; + Integer reg = entry.getKey(); + for (ScopeBlock child : children) { + if (child.usesReg(reg)) { + if (child.isLoop) { + inLoop = true; + break; + } + childUseCount++; + } + } + if ((!inLoop) && (childUseCount == 1)) { + bugReporter.reportBug(new BugInstance(BloatedAssignmentScope.this, "BAS_BLOATED_ASSIGNMENT_SCOPE", NORMAL_PRIORITY) + .addClass(BloatedAssignmentScope.this) + .addMethod(BloatedAssignmentScope.this) + .addSourceLine(BloatedAssignmentScope.this, entry.getValue())); + } + } + } + } } if (children != null) { for (ScopeBlock child : children) { - child.findBugs(); + child.findBugs(usedRegs); } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |