Thread: [Fb-contrib-commit] SF.net SVN: fb-contrib: [416] trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/det
Brought to you by:
dbrosius
From: <dbr...@us...> - 2006-04-08 14:25:09
|
Revision: 416 Author: dbrosius Date: 2006-04-08 07:24:57 -0700 (Sat, 08 Apr 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=416&view=rev Log Message: ----------- only check methods that actually return a value Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UnnecessaryStoreBeforeReturn.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UnnecessaryStoreBeforeReturn.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UnnecessaryStoreBeforeReturn.java 2006-04-08 14:19:15 UTC (rev 415) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UnnecessaryStoreBeforeReturn.java 2006-04-08 14:24:57 UTC (rev 416) @@ -21,7 +21,9 @@ import java.util.HashSet; import java.util.Set; +import org.apache.bcel.classfile.Code; import org.apache.bcel.classfile.Method; +import org.apache.bcel.generic.Type; import edu.umd.cs.findbugs.BugInstance; import edu.umd.cs.findbugs.BugReporter; @@ -82,12 +84,29 @@ return super.clone(); } + /** + * implements the visitor to make sure method returns a value, and then clears the targets + * + * @param obj the context object of the currently parsed code block + */ @Override - public void visitMethod(Method obj) { - state = SEEN_NOTHING; - branchTargets.clear(); + public void visitCode(Code obj) { + Method m = getMethod(); + String sig = m.getSignature(); + Type t = Type.getReturnType(sig); + if (!t.equals(Type.VOID)) { + state = SEEN_NOTHING; + branchTargets.clear(); + super.visitCode(obj); + } } + /** + * implements the visitor to look for store of registers immediately before returns + * of that register + * + * @param seen the opcode of the currently parsed instruction + */ @Override public void sawOpcode(int seen) { int loadReg; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-04-11 14:28:48
|
Revision: 439 Author: dbrosius Date: 2006-04-11 07:28:33 -0700 (Tue, 11 Apr 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=439&view=rev Log Message: ----------- reduce cyclomatic complexity Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UnnecessaryStoreBeforeReturn.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UnnecessaryStoreBeforeReturn.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UnnecessaryStoreBeforeReturn.java 2006-04-11 14:15:45 UTC (rev 438) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UnnecessaryStoreBeforeReturn.java 2006-04-11 14:28:33 UTC (rev 439) @@ -112,25 +112,8 @@ int loadReg; switch (state) { case SEEN_NOTHING: - if ((seen >= ISTORE) && (seen <= ASTORE)) { - storeReg = getRegisterOperand(); + if (lookForStore(seen)) state = SEEN_STORE; - } else if ((seen >= ISTORE_0) && (seen <= ISTORE_3)) { - storeReg = seen - ISTORE_0; - state = SEEN_STORE; - } else if ((seen >= LSTORE_0) && (seen <= LSTORE_3)) { - storeReg = seen - LSTORE_0; - state = SEEN_STORE; - } else if ((seen >= FSTORE_0) && (seen <= FSTORE_3)) { - storeReg = seen - FSTORE_0; - state = SEEN_STORE; - } else if ((seen >= DSTORE_0) && (seen <= DSTORE_3)) { - storeReg = seen - DSTORE_0; - state = SEEN_STORE; - } else if ((seen >= ASTORE_0) && (seen <= ASTORE_3)) { - storeReg = seen - ASTORE_0; - state = SEEN_STORE; - } break; case SEEN_STORE: @@ -139,26 +122,7 @@ return; } - if ((seen >= ILOAD) && (seen <= ALOAD)) { - loadReg = getRegisterOperand(); - state = (storeReg == loadReg) ? SEEN_LOAD : SEEN_NOTHING; - } else if ((seen >= ILOAD_0) && (seen <= ILOAD_3)) { - loadReg = seen - ILOAD_0; - state = (storeReg == loadReg) ? SEEN_LOAD : SEEN_NOTHING; - } else if ((seen >= LLOAD_0) && (seen <= LLOAD_3)) { - loadReg = seen - LLOAD_0; - state = (storeReg == loadReg) ? SEEN_LOAD : SEEN_NOTHING; - } else if ((seen >= FLOAD_0) && (seen <= FLOAD_3)) { - loadReg = seen - FLOAD_0; - state = (storeReg == loadReg) ? SEEN_LOAD : SEEN_NOTHING; - } else if ((seen >= DLOAD_0) && (seen <= DLOAD_3)) { - loadReg = seen - DLOAD_0; - state = (storeReg == loadReg) ? SEEN_LOAD : SEEN_NOTHING; - } else if ((seen >= ALOAD_0) && (seen <= ALOAD_3)) { - loadReg = seen - ALOAD_0; - state = (storeReg == loadReg) ? SEEN_LOAD : SEEN_NOTHING; - } else - state = SEEN_NOTHING; + state = lookForLoad(seen) ? SEEN_LOAD : SEEN_NOTHING; break; case SEEN_LOAD: @@ -177,5 +141,54 @@ } } - + + /** + * checks if the curent opcode is a store, if so saves the register + * + * @param seen the opcode of the currently parsed instruction + * @return if a store was seen + */ + private boolean lookForStore(int seen) { + if ((seen >= ISTORE) && (seen <= ASTORE)) + storeReg = getRegisterOperand(); + else if ((seen >= ISTORE_0) && (seen <= ISTORE_3)) + storeReg = seen - ISTORE_0; + else if ((seen >= LSTORE_0) && (seen <= LSTORE_3)) + storeReg = seen - LSTORE_0; + else if ((seen >= FSTORE_0) && (seen <= FSTORE_3)) + storeReg = seen - FSTORE_0; + else if ((seen >= DSTORE_0) && (seen <= DSTORE_3)) + storeReg = seen - DSTORE_0; + else if ((seen >= ASTORE_0) && (seen <= ASTORE_3)) + storeReg = seen - ASTORE_0; + else + return false; + return true; + } + + /** + * looks for a load of the register that was just stored + * + * @param seen the opcode of the currently parsed instruction + * @return if the load was seen + */ + private boolean lookForLoad(int seen) { + int loadReg; + if ((seen >= ILOAD) && (seen <= ALOAD)) + loadReg = getRegisterOperand(); + else if ((seen >= ILOAD_0) && (seen <= ILOAD_3)) + loadReg = seen - ILOAD_0; + else if ((seen >= LLOAD_0) && (seen <= LLOAD_3)) + loadReg = seen - LLOAD_0; + else if ((seen >= FLOAD_0) && (seen <= FLOAD_3)) + loadReg = seen - FLOAD_0; + else if ((seen >= DLOAD_0) && (seen <= DLOAD_3)) + loadReg = seen - DLOAD_0; + else if ((seen >= ALOAD_0) && (seen <= ALOAD_3)) + loadReg = seen - ALOAD_0; + else + return false; + + return (storeReg == loadReg); + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-04-19 00:39:46
|
Revision: 480 Author: dbrosius Date: 2006-04-18 17:39:41 -0700 (Tue, 18 Apr 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=480&view=rev Log Message: ----------- Manually cleanup memory now that StatelessDetector is removed. Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UnnecessaryStoreBeforeReturn.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UnnecessaryStoreBeforeReturn.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UnnecessaryStoreBeforeReturn.java 2006-04-18 22:29:55 UTC (rev 479) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UnnecessaryStoreBeforeReturn.java 2006-04-19 00:39:41 UTC (rev 480) @@ -28,13 +28,13 @@ import edu.umd.cs.findbugs.BugInstance; import edu.umd.cs.findbugs.BugReporter; import edu.umd.cs.findbugs.BytecodeScanningDetector; -import edu.umd.cs.findbugs.StatelessDetector; +import edu.umd.cs.findbugs.ba.ClassContext; /** * Looks for methods that store the return result in a local variable, and * then immediately returns that local variable. */ -public class UnnecessaryStoreBeforeReturn extends BytecodeScanningDetector implements StatelessDetector +public class UnnecessaryStoreBeforeReturn extends BytecodeScanningDetector { private static final int SEEN_NOTHING = 0; private static final int SEEN_STORE = 1; @@ -62,7 +62,7 @@ } private BugReporter bugReporter; - private Set<Integer> branchTargets = new HashSet<Integer>(); + private Set<Integer> branchTargets; private int state; private int storeReg; @@ -75,15 +75,19 @@ } /** - * clone this detector so that it can be a StatelessDetector + * implements the visitor to create and clear the branchTargets * - * @return a clone of this object + * @param classContext the context object for the currently parsed class */ @Override - public Object clone() throws CloneNotSupportedException { - return super.clone(); + public void visitClassContext(ClassContext classContext) { + try { + branchTargets = new HashSet<Integer>(); + super.visitClassContext(classContext); + } finally { + branchTargets = null; + } } - /** * implements the visitor to make sure method returns a value, and then clears the targets * This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-06-04 03:43:57
|
Revision: 547 Author: dbrosius Date: 2006-06-03 20:43:32 -0700 (Sat, 03 Jun 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=547&view=rev Log Message: ----------- remove some false positives Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UnnecessaryStoreBeforeReturn.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UnnecessaryStoreBeforeReturn.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UnnecessaryStoreBeforeReturn.java 2006-06-03 05:19:26 UTC (rev 546) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UnnecessaryStoreBeforeReturn.java 2006-06-04 03:43:32 UTC (rev 547) @@ -124,7 +124,7 @@ case SEEN_STORE: if (branchTargets.contains(Integer14.valueOf(getPC()))) { state = SEEN_NOTHING; - return; + break; } state = lookForLoad(seen) ? SEEN_LOAD : SEEN_NOTHING; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |