[Fb-contrib-commit] SF.net SVN: fb-contrib: [700] trunk/fb-contrib/src/com/mebigfatguy/ fbcontrib/
Brought to you by:
dbrosius
From: <dbr...@us...> - 2006-12-03 10:21:19
|
Revision: 700 http://svn.sourceforge.net/fb-contrib/?rev=700&view=rev Author: dbrosius Date: 2006-12-03 02:21:09 -0800 (Sun, 03 Dec 2006) Log Message: ----------- if a scope block target is the same as another block it must be a compound conditional, so merge the blocks, and move already recorded load stores to the parent 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-03 09:52:26 UTC (rev 699) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java 2006-12-03 10:21:09 UTC (rev 700) @@ -133,8 +133,13 @@ } else if (((seen >= IFEQ) && (seen <= GOTO)) || (seen == GOTO_W)) { int target = getBranchTarget(); if (target > getPC()) { - ScopeBlock sb = new ScopeBlock(getPC(), target); - rootScopeBlock.addChild(sb); + ScopeBlock sb = findScopeBlockWithTarget(rootScopeBlock, target); + if (sb != null) { + sb.pushUpLoadStores(); + } else { + sb = new ScopeBlock(getPC(), target); + rootScopeBlock.addChild(sb); + } } else { ScopeBlock sb = findScopeBlock(rootScopeBlock, getPC()); if (sb != null) @@ -164,11 +169,36 @@ } return null; } + + /** + * returns an existing scope block that has the same target as the one looked for + * + * @param sb the scope block to start with + * @param target the target to look for + * + * @return the scope block found or null + */ + private ScopeBlock findScopeBlockWithTarget(ScopeBlock sb, int target) { + if (sb.finishLocation == target) + return sb; + if (sb.children != null) + { + for (ScopeBlock child : sb.children) { + ScopeBlock targetBlock = findScopeBlockWithTarget(child, target); + if (targetBlock != null) + return targetBlock; + } + } + + return null; + } + /** holds the description of a scope { } block, be it a for, if, while block */ private class ScopeBlock { + private ScopeBlock parent; private int startLocation; private int finishLocation; private boolean isLoop; @@ -182,6 +212,7 @@ * @param finish the end of the block */ public ScopeBlock(int start, int finish) { + parent = null; startLocation = start; finishLocation = finish; isLoop = false; @@ -254,6 +285,8 @@ * @param child the scope block to add to the tree */ public void addChild(ScopeBlock newChild) { + newChild.parent = this; + if (children != null) { for (ScopeBlock child : children) { if ((newChild.startLocation > child.startLocation) && (newChild.finishLocation < child.finishLocation)) { @@ -339,5 +372,27 @@ return false; } + + /** + * push all loads and stores to this block up to the parent + */ + public void pushUpLoadStores() { + if (parent != null) { + if (loads != null) { + if (parent.loads != null) + parent.loads.putAll(loads); + else + parent.loads = loads; + } + if (stores != null) { + if (parent.stores != null) + parent.stores.putAll(stores); + else + parent.stores = stores; + } + loads = null; + stores = null; + } + } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |