Package com.mebigfatguy.fbcontrib.detect
Class BloatedAssignmentScope.ScopeBlock
java.lang.Object
com.mebigfatguy.fbcontrib.detect.BloatedAssignmentScope.ScopeBlock
- Enclosing class:
BloatedAssignmentScope
holds the description of a scope { } block, be it a for, if, while block
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Map<BloatedAssignmentScope.UserObject, Integer> private List<BloatedAssignmentScope.ScopeBlock> private intprivate booleanprivate booleanprivate booleanprivate booleanprivate booleanprivate int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddChild(BloatedAssignmentScope.ScopeBlock newChild) adds a scope block to this subtree by finding the correct place in the hierarchy to store itvoidaddLoad(int reg, int pc) adds the register as a load in this scope blockvoidaddStore(int reg, int pc, BloatedAssignmentScope.UserObject assocObject) adds the register as a store in this scope blockprivate booleanappearsToBeUserRegister(int reg) in some cases the java compiler synthesizes variable for its own purposes.voidreport stores that occur at scopes higher than associated loads that are not involved with loopsreturns the children of this scope blockintreturns the end of the blockreturns the scope blocks parentintgetStart()returns the start of the blockbooleanbooleanisCase()returns whether this block was caused from a case blockbooleanisGoto()returns whether this block was caused from a gotobooleanisLoop()returns whether this scope block is a loopbooleanisSync()returns whether this block was caused from a synchronized blockbooleanisTry()returns whether this block was caused from a try blockvoidmarkFieldAssociatedWrites(int sourceReg) voidpush all loads and stores to this block up to the parentvoidremoveByAssoc(Object assocObject) removes stores to registers that where retrieved from method calls on assocObjectvoidremoves a child from this nodevoidsetCase()sets that this block was caused from a case blockvoidsetFinish(int finish) sets the finish pc of the blockvoidsetGoto()sets that this block was caused from a goto, (an if block exit)voidsetLoop()sets that this block is a loopvoidsetStart(int start) sets the start pc of the blockvoidsetSync()sets that this block was caused from a synchronized blockvoidsetTry()sets that this block was caused from a try blocktoString()returns a string representation of the scope blockbooleanreturns whether this block either loads or stores into the register in question
-
Field Details
-
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
-
stores
-
assocs
-
children
-
-
Constructor Details
-
ScopeBlock
public ScopeBlock(int start, int finish) constructs a new scope block- Parameters:
start- the beginning of the blockfinish- the end of the block
-
-
Method Details
-
toString
returns a string representation of the scope block -
getParent
returns the scope blocks parent- Returns:
- the parent of this scope block
-
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
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
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
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
removes a child from this node- Parameters:
child- the child to remove
-
markFieldAssociatedWrites
public void markFieldAssociatedWrites(int sourceReg) -
findBugs
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
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
-