Package com.mebigfatguy.fbcontrib.detect
Class BloatedAssignmentScope.ScopeBlock
- java.lang.Object
-
- com.mebigfatguy.fbcontrib.detect.BloatedAssignmentScope.ScopeBlock
-
- Enclosing class:
- BloatedAssignmentScope
private class BloatedAssignmentScope.ScopeBlock extends java.lang.Object
holds the description of a scope { } block, be it a for, if, while block
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<BloatedAssignmentScope.UserObject,java.lang.Integer>
assocs
private java.util.List<BloatedAssignmentScope.ScopeBlock>
children
private int
finishLocation
private boolean
isCase
private boolean
isGoto
private boolean
isLoop
private boolean
isSync
private boolean
isTry
private java.util.Map<java.lang.Integer,java.lang.Integer>
loads
private BloatedAssignmentScope.ScopeBlock
parent
private int
startLocation
private java.util.Map<java.lang.Integer,java.lang.Integer>
stores
-
Constructor Summary
Constructors Constructor Description ScopeBlock(int start, int finish)
constructs a new scope block
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addChild(BloatedAssignmentScope.ScopeBlock newChild)
adds a scope block to this subtree by finding the correct place in the hierarchy to store itvoid
addLoad(int reg, int pc)
adds the register as a load in this scope blockvoid
addStore(int reg, int pc, BloatedAssignmentScope.UserObject assocObject)
adds the register as a store in this scope blockprivate boolean
appearsToBeUserRegister(int reg)
in some cases the java compiler synthesizes variable for its own purposes.void
findBugs(java.util.Set<java.lang.Integer> parentUsedRegs)
report stores that occur at scopes higher than associated loads that are not involved with loopsjava.util.List<BloatedAssignmentScope.ScopeBlock>
getChildren()
returns the children of this scope blockint
getFinish()
returns the end of the blockBloatedAssignmentScope.ScopeBlock
getParent()
returns the scope blocks parentint
getStart()
returns the start of the blockboolean
hasChildren()
boolean
isCase()
returns whether this block was caused from a case blockboolean
isGoto()
returns whether this block was caused from a gotoboolean
isLoop()
returns whether this scope block is a loopboolean
isSync()
returns whether this block was caused from a synchronized blockboolean
isTry()
returns whether this block was caused from a try blockvoid
markFieldAssociatedWrites(int sourceReg)
void
pushUpLoadStores()
push all loads and stores to this block up to the parentvoid
removeByAssoc(java.lang.Object assocObject)
removes stores to registers that where retrieved from method calls on assocObjectvoid
removeChild(BloatedAssignmentScope.ScopeBlock child)
removes a child from this nodevoid
setCase()
sets that this block was caused from a case blockvoid
setFinish(int finish)
sets the finish pc of the blockvoid
setGoto()
sets that this block was caused from a goto, (an if block exit)void
setLoop()
sets that this block is a loopvoid
setStart(int start)
sets the start pc of the blockvoid
setSync()
sets that this block was caused from a synchronized blockvoid
setTry()
sets that this block was caused from a try blockjava.lang.String
toString()
returns a string representation of the scope blockboolean
usesReg(java.lang.Integer reg)
returns whether this block either loads or stores into the register in question
-
-
-
Field Detail
-
parent
private BloatedAssignmentScope.ScopeBlock parent
-
startLocation
private int startLocation
-
finishLocation
private int finishLocation
-
isLoop
private boolean isLoop
-
isGoto
private boolean isGoto
-
isSync
private boolean isSync
-
isTry
private boolean isTry
-
isCase
private boolean isCase
-
loads
private java.util.Map<java.lang.Integer,java.lang.Integer> loads
-
stores
private java.util.Map<java.lang.Integer,java.lang.Integer> stores
-
assocs
private java.util.Map<BloatedAssignmentScope.UserObject,java.lang.Integer> assocs
-
children
private java.util.List<BloatedAssignmentScope.ScopeBlock> children
-
-
Method Detail
-
toString
public java.lang.String toString()
returns a string representation of the scope block- Overrides:
toString
in classjava.lang.Object
- Returns:
- a string representation
-
getParent
public BloatedAssignmentScope.ScopeBlock getParent()
returns the scope blocks parent- Returns:
- the parent of this scope block
-
getChildren
public java.util.List<BloatedAssignmentScope.ScopeBlock> getChildren()
returns the children of this scope block- Returns:
- the scope blocks children
-
getStart
public int getStart()
returns the start of the block- Returns:
- the start of the block
-
getFinish
public int getFinish()
returns the end of the block- Returns:
- the end of the block
-
setStart
public void setStart(int start)
sets the start pc of the block- Parameters:
start
- the start pc
-
setFinish
public void setFinish(int finish)
sets the finish pc of the block- Parameters:
finish
- the finish pc
-
hasChildren
public boolean hasChildren()
-
setLoop
public void setLoop()
sets that this block is a loop
-
isLoop
public boolean isLoop()
returns whether this scope block is a loop- Returns:
- whether this block is a loop
-
setGoto
public void setGoto()
sets that this block was caused from a goto, (an if block exit)
-
isGoto
public boolean isGoto()
returns whether this block was caused from a goto- Returns:
- whether this block was caused by a goto
-
setSync
public void setSync()
sets that this block was caused from a synchronized block
-
isSync
public boolean isSync()
returns whether this block was caused from a synchronized block- Returns:
- whether this block was caused by a synchronized block
-
setTry
public void setTry()
sets that this block was caused from a try block
-
isTry
public boolean isTry()
returns whether this block was caused from a try block- Returns:
- whether this block was caused by a try block
-
setCase
public void setCase()
sets that this block was caused from a case block
-
isCase
public boolean isCase()
returns whether this block was caused from a case block- Returns:
- whether this block was caused by a case block
-
addStore
public void addStore(int reg, int pc, BloatedAssignmentScope.UserObject assocObject)
adds the register as a store in this scope block- Parameters:
reg
- the register that was storedpc
- the instruction that did the storeassocObject
- the the object that is associated with this store, usually the field from which this came
-
removeByAssoc
public void removeByAssoc(java.lang.Object assocObject)
removes stores to registers that where retrieved from method calls on assocObject- Parameters:
assocObject
- the object that a method call was just performed on
-
addLoad
public void addLoad(int reg, int pc)
adds the register as a load in this scope block- Parameters:
reg
- the register that was loadedpc
- the instruction that did the load
-
addChild
public void addChild(BloatedAssignmentScope.ScopeBlock newChild)
adds a scope block to this subtree by finding the correct place in the hierarchy to store it- Parameters:
newChild
- the scope block to add to the tree
-
removeChild
public void removeChild(BloatedAssignmentScope.ScopeBlock child)
removes a child from this node- Parameters:
child
- the child to remove
-
markFieldAssociatedWrites
public void markFieldAssociatedWrites(int sourceReg)
-
findBugs
public void findBugs(java.util.Set<java.lang.Integer> parentUsedRegs)
report stores that occur at scopes higher than associated loads that are not involved with loops- Parameters:
parentUsedRegs
- the set of registers that where used by the parent scope block
-
appearsToBeUserRegister
private boolean appearsToBeUserRegister(int reg)
in some cases the java compiler synthesizes variable for its own purposes. Hopefully when it does this these, can not be found in the localvariable table. If we find this to be the case, don't report them- Parameters:
reg
- the register to check- Returns:
- if reg variable appears in the local variable table
-
usesReg
public boolean usesReg(java.lang.Integer reg)
returns whether this block either loads or stores into the register in question- Parameters:
reg
- the register to look for loads or stores- Returns:
- whether the block uses the register
-
pushUpLoadStores
public void pushUpLoadStores()
push all loads and stores to this block up to the parent
-
-