[Fb-contrib-commit] SF.net SVN: fb-contrib: [722] trunk/fb-contrib/src/com/mebigfatguy/ fbcontrib/
Brought to you by:
dbrosius
From: <dbr...@us...> - 2006-12-12 07:43:05
|
Revision: 722 http://svn.sourceforge.net/fb-contrib/?rev=722&view=rev Author: dbrosius Date: 2006-12-11 23:36:16 -0800 (Mon, 11 Dec 2006) Log Message: ----------- create a scope block for the end of if block goto temporarily, so that an unguarded else is blocked. But if a scope block is found to this goto block, then remove it, as we've found an else if 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 04:35:24 UTC (rev 721) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java 2006-12-12 07:36:16 UTC (rev 722) @@ -171,14 +171,27 @@ 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()) { - sb.pushUpLoadStores(); - sb.setStart(getPC()); - sb.setFinish(target); + if (sb.isGoto()) { + ScopeBlock parent = sb.getParent(); + if (parent != null) + parent.removeChild(sb); + sb = new ScopeBlock(getPC(), target); + rootScopeBlock.addChild(sb); + } else { + sb.pushUpLoadStores(); + sb.setStart(getPC()); + sb.setFinish(target); + } } else { sb = new ScopeBlock(getPC(), target); rootScopeBlock.addChild(sb); @@ -227,8 +240,10 @@ * @return the scope block found or null */ private ScopeBlock findScopeBlockWithTarget(ScopeBlock sb, int start, int target) { - if ((sb.startLocation < start) && (sb.finishLocation >= start) && (sb.finishLocation <= target)) - return sb; + if ((sb.startLocation < start) && (sb.finishLocation >= start)) { + if ((sb.finishLocation <= target) || (sb.isGoto() && !sb.isLoop())) + return sb; + } if (sb.children != null) { @@ -250,6 +265,7 @@ private int startLocation; private int finishLocation; private boolean isLoop; + private boolean isGoto; private Map<Integer, Integer> loads; private Map<Integer, Integer> stores; private List<ScopeBlock> children; @@ -264,6 +280,7 @@ startLocation = start; finishLocation = finish; isLoop = false; + isGoto = false; loads = null; stores = null; children = null; @@ -278,6 +295,15 @@ return "Start=" + startLocation + " Finish=" + finishLocation + " Loop=" + isLoop + " Loads=" + loads + " Stores=" + stores; } + /** + * returns the scope blocks parent + * + * @return the parent of this scope block + */ + public ScopeBlock getParent() { + return parent; + } + /** returns the start of the block * * @return the start of the block @@ -319,6 +345,31 @@ public void setLoop() { isLoop = true; } + + /** + * returns whether this scope block is a loop + * + * @returns whether this block is a loop + */ + public boolean isLoop() { + return isLoop; + } + + /** + * sets that this block was caused from a goto, (an if block exit) + */ + public void setGoto() { + isGoto = true; + } + + /** + * returns whether this block was caused from a goto + * + * @returns whether this block was caused by a goto + */ + public boolean isGoto() { + return isGoto; + } /** * adds the register as a store in this scope block @@ -376,6 +427,15 @@ children.add(newChild); } + /** + * removes a child from this node + * @param child the child to remove + */ + public void removeChild(ScopeBlock child) { + if (children != null) + children.remove(child); + } + /** * report stores that occur at scopes higher than associated loads that are not involved with loops */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |