Package com.tonic.analysis.typeinference
Class TypeState
- java.lang.Object
-
- com.tonic.analysis.typeinference.TypeState
-
public class TypeState extends Object
A value's inferred type set paired with its nullability lattice element.
-
-
Constructor Summary
Constructors Constructor Description TypeState(IRType type)Creates a single-type state with unknown nullability.TypeState(IRType type, Nullability nullability)Creates a single-type state.TypeState(TypeSet typeSet, Nullability nullability)Creates a state from an explicit type set.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Object o)IRTypegetAnyType()NullabilitygetNullability()IRTypegetSingleType()TypeSetgetTypeSet()inthashCode()booleanisBottom()booleanisDefinitelyNotNull()booleanisDefinitelyNull()booleanisPrecise()TypeStatejoin(TypeState other)Joins two states at a control-flow merge point; bottom is absorbing.TypeStatenarrow(TypeState other)Narrows this state with additional information; bottom on either side yields bottom.static TypeStatenotNull(IRType type)Creates a type state for a definitely non-null value.static TypeStatenullable(IRType type)Creates a type state whose nullability is unknown.static TypeStatepolymorphic(TypeSet types, Nullability nullability)Creates a type state from multiple possible types.StringtoString()TypeStatewithNullability(Nullability newNullability)Copies this state with a different nullability.TypeStatewithType(IRType additionalType)Copies this state with one more possible type in the set.
-
-
-
Constructor Detail
-
TypeState
public TypeState(TypeSet typeSet, Nullability nullability)
Creates a state from an explicit type set.- Parameters:
typeSet- the set of possible typesnullability- the nullability lattice element
-
TypeState
public TypeState(IRType type, Nullability nullability)
Creates a single-type state.- Parameters:
type- the only possible typenullability- the nullability lattice element
-
TypeState
public TypeState(IRType type)
Creates a single-type state with unknown nullability.- Parameters:
type- the only possible type
-
-
Method Detail
-
notNull
public static TypeState notNull(IRType type)
Creates a type state for a definitely non-null value.- Parameters:
type- the only possible type- Returns:
- the new state
-
nullable
public static TypeState nullable(IRType type)
Creates a type state whose nullability is unknown.- Parameters:
type- the only possible type- Returns:
- the new state
-
polymorphic
public static TypeState polymorphic(TypeSet types, Nullability nullability)
Creates a type state from multiple possible types.- Parameters:
types- the set of possible typesnullability- the nullability lattice element- Returns:
- the new state
-
getTypeSet
public TypeSet getTypeSet()
- Returns:
- the type set
-
getNullability
public Nullability getNullability()
- Returns:
- the nullability
-
getSingleType
public IRType getSingleType()
- Returns:
- the sole possible type, or null if the set is not a singleton
-
getAnyType
public IRType getAnyType()
- Returns:
- an arbitrary representative type from the set
-
isDefinitelyNull
public boolean isDefinitelyNull()
- Returns:
- true if the value is known to be null
-
isDefinitelyNotNull
public boolean isDefinitelyNotNull()
- Returns:
- true if the value is known to be non-null
-
isBottom
public boolean isBottom()
- Returns:
- true if no information has been established yet
-
isPrecise
public boolean isPrecise()
- Returns:
- true if the set holds exactly one type and is complete (no subtypes)
-
join
public TypeState join(TypeState other)
Joins two states at a control-flow merge point; bottom is absorbing.- Parameters:
other- the state arriving on the other edge- Returns:
- the least upper bound of both states
-
narrow
public TypeState narrow(TypeState other)
Narrows this state with additional information; bottom on either side yields bottom.- Parameters:
other- the refining state- Returns:
- the greatest lower bound of both states
-
withNullability
public TypeState withNullability(Nullability newNullability)
Copies this state with a different nullability.- Parameters:
newNullability- the replacement lattice element- Returns:
- the new state
-
withType
public TypeState withType(IRType additionalType)
Copies this state with one more possible type in the set.- Parameters:
additionalType- the type to add- Returns:
- the new state
-
-