Class ConstraintState
java.lang.Object
org.ek9lang.compiler.phase5.flow.ConstraintState
Immutable constraint state mapping variables to their abstract values.
At each program point, a ConstraintState maps each tracked variable to its
abstract value. Untracked variables are implicitly TopValue.INSTANCE.
Supports copy-on-write semantics for branch splitting — creating a new state from an existing one is cheap (shallow copy of the internal map).
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionevaluateCondition(AbstractValue left, String operator, AbstractValue right) Evaluate a condition given the current state of two symbols/values.Get the abstract value for a symbol.booleanCheck if this state represents an unreachable program point.static ConstraintStatejoin(ConstraintState first, ConstraintState second) Join this state with another at a branch convergence point.voidMark this state as unreachable (BOTTOM).voidset(ISymbol symbol, AbstractValue abstractValue) Set the abstract value for a symbol (mutates this state).snapshot()Create a snapshot (copy) of this state for branch splitting.toString()
-
Constructor Details
-
ConstraintState
public ConstraintState()Create an empty constraint state.
-
-
Method Details
-
snapshot
Create a snapshot (copy) of this state for branch splitting. -
get
Get the abstract value for a symbol. Returns TOP if not tracked. -
set
Set the abstract value for a symbol (mutates this state). -
markUnreachable
public void markUnreachable()Mark this state as unreachable (BOTTOM). Used after throw statements or contradictory conditions. -
isUnreachable
public boolean isUnreachable()Check if this state represents an unreachable program point. -
join
Join this state with another at a branch convergence point.If either state is unreachable (BOTTOM), the other state is used. Otherwise, for each variable, the joined value is the lattice join of both branch values.
- Parameters:
first- the state from the first branchsecond- the state from the second branch- Returns:
- a new joined state
-
evaluateCondition
Evaluate a condition given the current state of two symbols/values.- Parameters:
left- the abstract value of the left operandoperator- the comparison operatorright- the abstract value of the right operand- Returns:
- the condition evaluation result
-
toString
-