Class ConstraintState

java.lang.Object
org.ek9lang.compiler.phase5.flow.ConstraintState

public final class ConstraintState extends Object
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 Details

    • ConstraintState

      public ConstraintState()
      Create an empty constraint state.
  • Method Details

    • snapshot

      public ConstraintState snapshot()
      Create a snapshot (copy) of this state for branch splitting.
    • get

      public AbstractValue get(ISymbol symbol)
      Get the abstract value for a symbol. Returns TOP if not tracked.
    • set

      public void set(ISymbol symbol, AbstractValue abstractValue)
      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

      public static ConstraintState join(ConstraintState first, ConstraintState second)
      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 branch
      second - the state from the second branch
      Returns:
      a new joined state
    • evaluateCondition

      public ConditionResult evaluateCondition(AbstractValue left, String operator, AbstractValue right)
      Evaluate a condition given the current state of two symbols/values.
      Parameters:
      left - the abstract value of the left operand
      operator - the comparison operator
      right - the abstract value of the right operand
      Returns:
      the condition evaluation result
    • toString

      public String toString()
      Overrides:
      toString in class Object