Record Class ConstantValue
java.lang.Object
java.lang.Record
org.ek9lang.compiler.phase5.flow.ConstantValue
- Record Components:
value- the constantmayBeUnset- 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:
Integer— integer literals like5,-1Boolean— boolean literalstrue,falseString— string literals like"hello"Double— float literals like3.14,-2.5CharacterConstant— character literals like'A'(a code point)LocalDate— date literals like2024-01-15LocalTime— time literals like07:30OffsetDateTime— datetime literals like2024-01-15T10:30:00ZLong— millisecond literals like500ms(viaofMillisecond(long))
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 Summary
ConstructorsConstructorDescriptionConstantValue(Object value) A constant that is known to be set.ConstantValue(Object value, boolean mayBeUnset) Creates an instance of aConstantValuerecord class. -
Method Summary
Modifier and TypeMethodDescriptionfinal 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.booleanisBottom()Check if this value represents an unreachable program point.booleanisKnown()Check if this value represents a known state (not TOP and not BOTTOM).join(AbstractValue other) Join this value with another at a branch convergence point.booleanReturns the value of themayBeUnsetrecord component.static ConstantValueof(boolean boolValue) Factory for boolean constants.static ConstantValueof(double floatValue) Factory for float constants.static ConstantValueof(int intValue) Factory for integer constants.static ConstantValueFactory for string constants.static ConstantValueFactory for date constants.static ConstantValueFactory for time constants.static ConstantValueof(OffsetDateTime dateTimeValue) Factory for datetime constants.static ConstantValueof(CharacterConstant character) Factory for character constants.static ConstantValueofMillisecond(long msValue) Factory for millisecond constants.toString()Returns a string representation of this record class.value()Returns the value of thevaluerecord component.withMayBeUnset(boolean flag) The same constant, flagged as one the variable holds only when it is set (or not).Methods inherited from interface AbstractValue
isKnownSet
-
Constructor Details
-
ConstantValue
Creates an instance of aConstantValuerecord class.- Parameters:
value- the value for thevaluerecord componentmayBeUnset- the value for themayBeUnsetrecord component
-
ConstantValue
A constant that is known to be set.
-
-
Method Details
-
withMayBeUnset
The same constant, flagged as one the variable holds only when it is set (or not). -
of
Factory for integer constants. -
of
Factory for boolean constants. -
of
Factory for string constants. -
of
Factory for float constants. -
of
Factory for character constants. -
of
Factory for date constants. -
of
Factory for time constants. -
of
Factory for datetime constants. -
ofMillisecond
Factory for millisecond constants. Uses a distinct name to avoid overload ambiguity withof(int). -
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. Reference components are compared withObjects::equals(Object,Object); primitive components are compared with thecomparemethod from their corresponding wrapper classes. -
value
-
mayBeUnset
public boolean mayBeUnset()Returns the value of themayBeUnsetrecord component.- Returns:
- the value of the
mayBeUnsetrecord component
-