Record Class RangeValue

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

public record RangeValue(long lo, long hi) extends Record implements AbstractValue
Represents a variable known to be within a numeric range [lo, hi].

Created by condition narrowing: when if x > 10 is entered, the true branch narrows x to Range(11, Integer.MAX_VALUE) and the false branch to Range(Integer.MIN_VALUE, 10).

Supports evaluation of comparison conditions against constants and other ranges. When the entire range satisfies the condition, the result is TRUE (always). When no part of the range can satisfy the condition, the result is FALSE (never). Otherwise, the result is UNKNOWN.

  • Constructor Details

    • RangeValue

      public RangeValue(long lo, long hi)
      Creates an instance of a RangeValue record class.
      Parameters:
      lo - the value for the lo record component
      hi - the value for the hi record component
  • Method Details

    • narrowForTrue

      public static RangeValue narrowForTrue(String operator, long operandValue)
      Create a range from a comparison narrowing on the true branch.
      Parameters:
      operator - the comparison operator (must be one of <, >, <=, >=, ==)
      operandValue - the integer value being compared against
      Returns:
      the narrowed range for the true branch, or null if not narrowable
    • narrowForFalse

      public static RangeValue narrowForFalse(String operator, long operandValue)
      Create a range from a comparison narrowing on the false branch.
      Parameters:
      operator - the comparison operator
      operandValue - the integer value being compared against
      Returns:
      the narrowed range for the false branch, or null if not narrowable
    • intersect

      public RangeValue intersect(RangeValue other)
      Compute the intersection of two ranges.
      Returns:
      the intersection range, or null if the ranges are disjoint
    • isSubsetOf

      public boolean isSubsetOf(RangeValue container)
      Check if this range is entirely contained within the given container range.
    • coversEntireDomain

      public boolean coversEntireDomain(RangeValue other)
      Check if the union of this range and another covers the entire domain [MIN_VALUE, MAX_VALUE].
    • 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.
    • lo

      public long lo()
      Returns the value of the lo record component.
      Returns:
      the value of the lo record component
    • hi

      public long hi()
      Returns the value of the hi record component.
      Returns:
      the value of the hi record component