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, boolean mayBeUnset)
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 Summary
ConstructorsConstructorDescriptionRangeValue(long lo, long hi) A range of a value that is known set.RangeValue(long lo, long hi, boolean mayBeUnset) Creates an instance of aRangeValuerecord class. -
Method Summary
Modifier and TypeMethodDescriptionbooleancoversEntireDomain(RangeValue other) Check if the union of this range and another covers the entire domain [MIN_VALUE, MAX_VALUE].final booleanIndicates whether some other object is "equal to" this one.evaluateCondition(String operator, AbstractValue operand) Evaluate whether this abstract value satisfies a comparison condition.final inthashCode()Returns a hash code value for this object.longhi()Returns the value of thehirecord component.intersect(RangeValue other) Compute the intersection of two ranges.booleanisBottom()Check if this value represents an unreachable program point.booleanisKnown()Check if this value represents a known state (not TOP and not BOTTOM).booleanisSubsetOf(RangeValue container) Check if this range is entirely contained within the given container range.join(AbstractValue other) Join this value with another at a branch convergence point.longlo()Returns the value of thelorecord component.booleanReturns the value of themayBeUnsetrecord component.static RangeValuenarrowForFalse(String operator, long operandValue) Create a range from a comparison narrowing on the false branch.static RangeValuenarrowForTrue(String operator, long operandValue) Create a range from a comparison narrowing on the true branch.toString()Returns a string representation of this record class.withMayBeUnset(boolean flag) The same range, flagged as one the variable holds only when it is set (D50): the FALSE branch of a comparison narrows an operand that was not known set to this range, because an unset operand makes the comparison unset, which is also the false path.Methods inherited from interface AbstractValue
isKnownSet
-
Constructor Details
-
RangeValue
public RangeValue(long lo, long hi, boolean mayBeUnset) Creates an instance of aRangeValuerecord class.- Parameters:
lo- the value for thelorecord componenthi- the value for thehirecord componentmayBeUnset- the value for themayBeUnsetrecord component
-
RangeValue
public RangeValue(long lo, long hi) A range of a value that is known set.
-
-
Method Details
-
withMayBeUnset
The same range, flagged as one the variable holds only when it is set (D50): the FALSE branch of a comparison narrows an operand that was not known set to this range, because an unset operand makes the comparison unset, which is also the false path. Conditions are still decided over the range (they assume the operand is set, as every comparison here does), but the variable is not known to be set. -
narrowForTrue
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
Create a range from a comparison narrowing on the false branch.- Parameters:
operator- the comparison operatoroperandValue- the integer value being compared against- Returns:
- the narrowed range for the false branch, or null if not narrowable
-
intersect
Compute the intersection of two ranges.- Returns:
- the intersection range, or null if the ranges are disjoint
-
isSubsetOf
Check if this range is entirely contained within the given container range. -
coversEntireDomain
Check if the union of this range and another covers the entire domain [MIN_VALUE, MAX_VALUE]. -
join
Description copied from interface:AbstractValueJoin this value with another at a branch convergence point. Returns the least upper bound of the two values. Every implementation delegates toLatticeJoin, 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:
joinin interfaceAbstractValue
-
evaluateCondition
Description copied from interface:AbstractValueEvaluate whether this abstract value satisfies a comparison condition.- Specified by:
evaluateConditionin interfaceAbstractValue- 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:AbstractValueCheck if this value represents a known state (not TOP and not BOTTOM).- Specified by:
isKnownin interfaceAbstractValue
-
isBottom
public boolean isBottom()Description copied from interface:AbstractValueCheck if this value represents an unreachable program point.- Specified by:
isBottomin interfaceAbstractValue
-
toString
-
hashCode
-
equals
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 thecomparemethod from their corresponding wrapper classes. -
lo
public long lo()Returns the value of thelorecord component.- Returns:
- the value of the
lorecord component
-
hi
public long hi()Returns the value of thehirecord component.- Returns:
- the value of the
hirecord component
-
mayBeUnset
public boolean mayBeUnset()Returns the value of themayBeUnsetrecord component.- Returns:
- the value of the
mayBeUnsetrecord component
-