Record Class SetStateValue

java.lang.Object
java.lang.Record
org.ek9lang.compiler.phase5.flow.SetStateValue
All Implemented Interfaces:
AbstractValue

public record SetStateValue(boolean isSet) extends Record implements AbstractValue
Represents a variable known to be either SET (has a meaningful value) or UNSET (declared but no value).

Phase 3 of the value-tracking lattice. Tracks the isSet state of variables through assignments, guard expressions, and literal initializations. Used to detect redundant ? (isSet) checks and impossible isSet checks.

SetStateValue is less precise than ConstantValue and RangeValue: if a variable is known to hold a constant or be in a range, it is implicitly SET. SetStateValue is used when we know the set/unset state but not the specific value.

Lattice join rules:

  • SET join SET = SET
  • UNSET join UNSET = UNSET
  • SET join UNSET = TOP (disagreement)
  • SET join ConstantValue = ConstantValue (more precise, both agree SET)
  • UNSET join ConstantValue = TOP (disagreement)
  • SET join RangeValue = RangeValue (more precise, both agree SET)
  • UNSET join RangeValue = TOP (disagreement)
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final SetStateValue
    Singleton for a variable known to be SET.
    static final SetStateValue
    Singleton for a variable known to be UNSET.
  • Constructor Summary

    Constructors
    Constructor
    Description
    SetStateValue(boolean isSet)
    Creates an instance of a SetStateValue record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    final boolean
    Indicates whether some other object is "equal to" this one.
    Evaluate whether this abstract value satisfies a comparison condition.
    final int
    Returns a hash code value for this object.
    boolean
    Check if this value represents an unreachable program point.
    boolean
    Check if this value represents a known state (not TOP and not BOTTOM).
    boolean
    Returns the value of the isSet record component.
    Join this value with another at a branch convergence point.
    Returns a string representation of this record class.

    Methods inherited from class Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface AbstractValue

    isKnownSet
  • Field Details

    • SET

      public static final SetStateValue SET
      Singleton for a variable known to be SET.
    • UNSET

      public static final SetStateValue UNSET
      Singleton for a variable known to be UNSET.
  • Constructor Details

    • SetStateValue

      public SetStateValue(boolean isSet)
      Creates an instance of a SetStateValue record class.
      Parameters:
      isSet - the value for the isSet record component
  • Method Details

    • join

      public AbstractValue join(AbstractValue other)
      Description copied from interface: AbstractValue
      Join this value with another at a branch convergence point. Returns the least upper bound of the two values.

      Key rules:

      • BOTTOM join X = X (unreachable path is ignored)
      • X join BOTTOM = X
      • TOP join X = TOP
      • Constant(a) join Constant(a) = Constant(a) (both agree)
      • Constant(a) join Constant(b) = TOP (disagreement)
      Specified by:
      join in interface AbstractValue
    • evaluateCondition

      public ConditionResult evaluateCondition(String operator, AbstractValue operand)
      Description copied from interface: AbstractValue
      Evaluate whether this abstract value satisfies a comparison condition.
      Specified by:
      evaluateCondition in interface AbstractValue
      Parameters:
      operator - the comparison operator (==, <>, <, >, etc.)
      operand - the right-hand side value to compare against
      Returns:
      TRUE if condition is always satisfied, FALSE if never satisfied, UNKNOWN if indeterminate
    • isKnown

      public boolean isKnown()
      Description copied from interface: AbstractValue
      Check if this value represents a known state (not TOP and not BOTTOM).
      Specified by:
      isKnown in interface AbstractValue
    • isBottom

      public boolean isBottom()
      Description copied from interface: AbstractValue
      Check if this value represents an unreachable program point.
      Specified by:
      isBottom in interface AbstractValue
    • toString

      public String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with the compare method from their corresponding wrapper classes.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • isSet

      public boolean isSet()
      Returns the value of the isSet record component.
      Returns:
      the value of the isSet record component