Class LocalState
- java.lang.Object
-
- com.tonic.analysis.simulation.state.LocalState
-
public final class LocalState extends Object
Immutable representation of local variable slots during simulation.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description LocalStateclear()Discards every recorded slot.static LocalStateempty()Creates a state with no slots written.booleanequals(Object o)static LocalStateforParameters(List<SimValue> paramValues)Lays parameter values out from slot 0, giving each wide value two slots.SimValueget(int index)Reads a slot.Map<Integer,SimValue>getAll()Set<Integer>getDefinedIndices()SimValuegetValue(int index)Reads a slot that must not be the upper half of a wide value.inthashCode()booleanisDefined(int index)Tests whether a slot holds a value.intmaxLocal()LocalStatemerge(LocalState other)Merges another state in at a control flow join, keeping this state's value wherever both define a slot.static LocalStateof(Map<Integer,SimValue> values)Creates a state from an explicit slot map, taking the highest key as the maximum slot.LocalStateset(int index, SimValue value)Writes a single slot.LocalStatesetWide(int index, SimValue value)Writes a long or double, marking the following slot as its upper half.intsize()StringtoString()
-
-
-
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 writevalue- 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 writevalue- 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
-
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
-
-