Class BloatedAssignmentScope.ScopeBlock

java.lang.Object
com.mebigfatguy.fbcontrib.detect.BloatedAssignmentScope.ScopeBlock
Enclosing class:
BloatedAssignmentScope

private class BloatedAssignmentScope.ScopeBlock extends Object
holds the description of a scope { } block, be it a for, if, while block
  • Field Details

  • Constructor Details

    • ScopeBlock

      public ScopeBlock(int start, int finish)
      constructs a new scope block
      Parameters:
      start - the beginning of the block
      finish - the end of the block
  • Method Details

    • toString

      public String toString()
      returns a string representation of the scope block
      Overrides:
      toString in class Object
      Returns:
      a string representation
    • getParent

      returns the scope blocks parent
      Returns:
      the parent of this scope block
    • getChildren

      public 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 stored
      pc - the instruction that did the store
      assocObject - the the object that is associated with this store, usually the field from which this came
    • removeByAssoc

      public void removeByAssoc(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 loaded
      pc - 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(Set<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(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