[Fb-contrib-commit] SF.net SVN: fb-contrib: [725] trunk/fb-contrib/src/com/mebigfatguy/ fbcontrib/
Brought to you by:
dbrosius
From: <dbr...@us...> - 2006-12-13 04:40:05
|
Revision: 725 http://svn.sourceforge.net/fb-contrib/?rev=725&view=rev Author: dbrosius Date: 2006-12-12 20:40:01 -0800 (Tue, 12 Dec 2006) Log Message: ----------- add switch blocks as scope blocks, don't add the goto's at the end of the case blocks. 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-12 15:17:26 UTC (rev 724) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java 2006-12-13 04:40:01 UTC (rev 725) @@ -19,6 +19,7 @@ package com.mebigfatguy.fbcontrib.detect; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -47,6 +48,7 @@ private Set<Integer> ignoreRegs; private ScopeBlock rootScopeBlock; private Set<Integer> catchHandlers; + private Set<Integer> switchTargets; private boolean dontReport; private boolean sawDup; @@ -69,10 +71,12 @@ try { ignoreRegs = new HashSet<Integer>(); catchHandlers = new HashSet<Integer>(); + switchTargets = new HashSet<Integer>(); super.visitClassContext(classContext); } finally { ignoreRegs = null; catchHandlers = null; + switchTargets = null; } } @@ -104,7 +108,7 @@ } } - + switchTargets.clear(); dontReport = false; sawDup = false; super.visitCode(obj); @@ -172,17 +176,20 @@ int target = getBranchTarget(); if (target > getPC()) { if ((seen == GOTO) || (seen == GOTO_W)) { - ScopeBlock sb = findScopeBlockWithTarget(rootScopeBlock, getPC(), getNextPC()); - if (sb == null) { - sb = new ScopeBlock(getPC(), target); - sb.setLoop(); - sb.setGoto(); - rootScopeBlock.addChild(sb); - } else { - sb = new ScopeBlock(getPC(), target); - sb.setGoto(); - rootScopeBlock.addChild(sb); - } + Integer nextPC = Integer.valueOf(getNextPC()); + if (!switchTargets.contains(nextPC)) { + ScopeBlock sb = findScopeBlockWithTarget(rootScopeBlock, getPC(), getNextPC()); + if (sb == null) { + sb = new ScopeBlock(getPC(), target); + sb.setLoop(); + sb.setGoto(); + rootScopeBlock.addChild(sb); + } else { + sb = new ScopeBlock(getPC(), target); + sb.setGoto(); + rootScopeBlock.addChild(sb); + } + } } else { ScopeBlock sb = findScopeBlockWithTarget(rootScopeBlock, getPC(), target); if ((sb != null) && (!sb.isLoop) && !sb.hasChildren()) { @@ -207,6 +214,25 @@ if (sb != null) sb.setLoop(); } + } else if ((seen == TABLESWITCH) || (seen == LOOKUPSWITCH)) { + int pc = getPC(); + int[] offsets = getSwitchOffsets(); + List<Integer> targets = new ArrayList<Integer>(); + for (int i = 0; i < offsets.length; i++) + targets.add(Integer.valueOf(offsets[i] + 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()); + rootScopeBlock.addChild(sb); + lastTarget = nextTarget; + } + switchTargets.addAll(targets); } else if ((seen == INVOKEVIRTUAL) || (seen == INVOKEVIRTUAL)) { if ("wasNull".equals(getNameConstantOperand()) && "()Z".equals(getSigConstantOperand())) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |