Record Class CollectionStateValue
java.lang.Object
java.lang.Record
org.ek9lang.compiler.phase5.flow.CollectionStateValue
- All Implemented Interfaces:
AbstractValue
public record CollectionStateValue(boolean isSet, boolean isEmpty)
extends Record
implements AbstractValue
Represents a variable known to be a collection or container type with both SET/UNSET
and EMPTY/NON-EMPTY state tracked.
Extends the lattice for built-in collection and container types (List, Dict, Optional, Result) whose construction semantics provide compile-time knowledge of both their isSet state and their emptiness state.
Examples:
List() of String→ SET and EMPTY (created but no elements)[1, 2, 3]→ SET and NON-EMPTY (literal list with elements)Dict() of (String, Integer)→ SET and EMPTY{"key": 1}→ SET and NON-EMPTY (literal dict with entries)Optional("hello")→ SET and NON-EMPTY (has a value)Optional() of String→ UNSET and EMPTY (no value)
Lattice join rules:
- Same state join same state = same state
- Different states = TOP (disagreement)
- CollectionStateValue(SET, _) join SetStateValue(SET) = this (more precise)
- CollectionStateValue(SET, _) join ConstantValue = ConstantValue (more precise)
- CollectionStateValue(UNSET, _) join SetStateValue(SET) = TOP (disagreement)
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final CollectionStateValueCollection/container that is SET and EMPTY (e.g.,List() of String).static final CollectionStateValueCollection/container that is SET and NON-EMPTY (e.g.,[1, 2, 3]).static final CollectionStateValueCollection/container that is UNSET and EMPTY (e.g.,Optional() of String). -
Constructor Summary
ConstructorsConstructorDescriptionCollectionStateValue(boolean isSet, boolean isEmpty) Creates an instance of aCollectionStateValuerecord 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.booleanisEmpty()Returns the value of theisEmptyrecord component.booleanisKnown()Check if this value represents a known state (not TOP and not BOTTOM).booleanisSet()Returns the value of theisSetrecord component.join(AbstractValue other) Join this value with another at a branch convergence point.toString()Returns a string representation of this record class.Methods inherited from interface AbstractValue
isKnownSet
-
Field Details
-
SET_AND_EMPTY
Collection/container that is SET and EMPTY (e.g.,List() of String). -
SET_AND_NON_EMPTY
Collection/container that is SET and NON-EMPTY (e.g.,[1, 2, 3]). -
UNSET_AND_EMPTY
Collection/container that is UNSET and EMPTY (e.g.,Optional() of String).
-
-
Constructor Details
-
CollectionStateValue
public CollectionStateValue(boolean isSet, boolean isEmpty) Creates an instance of aCollectionStateValuerecord class.- Parameters:
isSet- the value for theisSetrecord componentisEmpty- the value for theisEmptyrecord component
-
-
Method Details
-
join
Description copied from interface:AbstractValueJoin 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:
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. -
isSet
public boolean isSet()Returns the value of theisSetrecord component.- Returns:
- the value of the
isSetrecord component
-
isEmpty
public boolean isEmpty()Returns the value of theisEmptyrecord component.- Returns:
- the value of the
isEmptyrecord component
-