Class LocalState


  • public final class LocalState
    extends Object
    Immutable representation of local variable slots during simulation.
    • Method Detail

      • empty

        public static LocalState empty()
        Creates a state with no slots written.
        Returns:
        the empty state
      • of

        public static LocalState of​(Map<Integer,​SimValue> values)
        Creates a state from an explicit slot map, taking the highest key as the maximum slot.
        Parameters:
        values - the initial slot values
        Returns:
        the populated state
      • forParameters

        public static LocalState forParameters​(List<SimValue> paramValues)
        Lays parameter values out from slot 0, giving each wide value two slots.
        Parameters:
        paramValues - the parameter values, including 'this' for instance methods
        Returns:
        the initialized state
      • set

        public LocalState set​(int index,
                              SimValue value)
        Writes a single slot.
        Parameters:
        index - the slot index to write
        value - the value to store
        Returns:
        a new state with that slot written
      • setWide

        public LocalState setWide​(int index,
                                  SimValue value)
        Writes a long or double, marking the following slot as its upper half.
        Parameters:
        index - the slot index to write
        value - the wide value to store
        Returns:
        a new state with both slots written
      • get

        public SimValue get​(int index)
        Reads a slot.
        Parameters:
        index - the slot index
        Returns:
        the value at that slot, or an unknown value if unset
      • getValue

        public SimValue getValue​(int index)
        Reads a slot that must not be the upper half of a wide value.
        Parameters:
        index - the slot index
        Returns:
        the value at that slot, or an unknown value if unset
        Throws:
        IllegalStateException - if the slot holds a wide second slot marker
      • isDefined

        public boolean isDefined​(int index)
        Tests whether a slot holds a value.
        Parameters:
        index - the slot index
        Returns:
        true if a value is recorded at that slot
      • maxLocal

        public int maxLocal()
        Returns:
        the highest slot index this state has ever written
      • size

        public int size()
        Returns:
        the number of slots holding a value
      • getAll

        public Map<Integer,​SimValue> getAll()
        Returns:
        an unmodifiable map of slot index to value
      • getDefinedIndices

        public Set<Integer> getDefinedIndices()
        Returns:
        the indices that hold a value
      • merge

        public LocalState merge​(LocalState other)
        Merges another state in at a control flow join, keeping this state's value wherever both define a slot.
        Parameters:
        other - the state to merge in, may be null
        Returns:
        the merged state, or this state if other is null
      • clear

        public LocalState clear()
        Discards every recorded slot.
        Returns:
        an empty state
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object