Record Class ConstantValue

java.lang.Object
java.lang.Record
org.ek9lang.compiler.phase5.flow.ConstantValue
Record Components:
value - the constant
mayBeUnset - the variable is this constant only when it is set
All Implemented Interfaces:
AbstractValue

public record ConstantValue(Object value, boolean mayBeUnset) extends Record implements AbstractValue
Represents a variable known to hold a specific constant value.

Supported constant types:

The value is stored as an Object to support all types uniformly. Type-specific comparison is handled by evaluateCondition(String, AbstractValue) using Comparable.compareTo(T).

mayBeUnset (D66, the tri-state rule): the variable holds this value ONLY when it is set. The false branch of a Boolean condition (if flag ... else) is reached when flag is false OR unset, so what the else knows is "false, if set" - a verdict that the condition is always TRUE is not sound there, a verdict that it is always FALSE still is, and the value is not known to be set. Every constant a literal or a true branch gives is set.

  • Constructor Details

    • ConstantValue

      public ConstantValue(Object value, boolean mayBeUnset)
      Creates an instance of a ConstantValue record class.
      Parameters:
      value - the value for the value record component
      mayBeUnset - the value for the mayBeUnset record component
    • ConstantValue

      public ConstantValue(Object value)
      A constant that is known to be set.
  • Method Details

    • withMayBeUnset

      public ConstantValue withMayBeUnset(boolean flag)
      The same constant, flagged as one the variable holds only when it is set (or not).
    • of

      public static ConstantValue of(int intValue)
      Factory for integer constants.
    • of

      public static ConstantValue of(boolean boolValue)
      Factory for boolean constants.
    • of

      public static ConstantValue of(String strValue)
      Factory for string constants.
    • of

      public static ConstantValue of(double floatValue)
      Factory for float constants.
    • of

      public static ConstantValue of(CharacterConstant character)
      Factory for character constants.
    • of

      public static ConstantValue of(LocalDate dateValue)
      Factory for date constants.
    • of

      public static ConstantValue of(LocalTime timeValue)
      Factory for time constants.
    • of

      public static ConstantValue of(OffsetDateTime dateTimeValue)
      Factory for datetime constants.
    • ofMillisecond

      public static ConstantValue ofMillisecond(long msValue)
      Factory for millisecond constants. Uses a distinct name to avoid overload ambiguity with of(int).
    • 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. Every implementation delegates to LatticeJoin, THE join, so the result never depends on which of the two values is the receiver.

      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. Reference components are compared with Objects::equals(Object,Object); primitive components 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.
    • value

      public Object value()
      Returns the value of the value record component.
      Returns:
      the value of the value record component
    • mayBeUnset

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