Package it.unive.lisa.analysis.lattices
Class SetLattice<S extends SetLattice<S,E>,E>
- java.lang.Object
-
- it.unive.lisa.analysis.BaseLattice<S>
-
- it.unive.lisa.analysis.lattices.SetLattice<S,E>
-
- Type Parameters:
S
- the concrete instance ofSetLattice
E
- the type of elements of the domain of this lattice
- All Implemented Interfaces:
Lattice<S>
,java.lang.Iterable<E>
- Direct Known Subclasses:
Aliases
,ExpressionSet
public abstract class SetLattice<S extends SetLattice<S,E>,E> extends BaseLattice<S> implements java.lang.Iterable<E>
A generic set lattice containing a set of elements. Lattice operations correspond to standard set operations:- the lub is the set union
- the ≤ is the set inclusion
- ...
-
-
Field Summary
Fields Modifier and Type Field Description java.util.Set<E>
elements
The set of elements contained in the lattice.boolean
isTop
Whether or not this is the top or bottom element of the lattice, valid only if the set of elements is empty.-
Fields inherited from interface it.unive.lisa.analysis.Lattice
BOTTOM_STRING, TOP_STRING
-
-
Constructor Summary
Constructors Constructor Description SetLattice(java.util.Set<E> elements, boolean isTop)
Builds the lattice.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description boolean
contains(E elem)
Checks whether an element is contained in this set.java.util.Set<E>
elements()
Yields the set of elements contained in this lattice element.boolean
equals(java.lang.Object obj)
S
glb(S other)
Performs the greatest lower bound between this set lattice element and the given one.int
hashCode()
boolean
isBottom()
Yieldstrue
if and only if this object represents the bottom of the lattice.boolean
isEmpty()
Returnstrue
if this set contains no elements.boolean
isTop()
Yieldstrue
if and only if this object represents the top of the lattice.java.util.Iterator<E>
iterator()
boolean
lessOrEqualAux(S other)
Yieldstrue
if and only if this lattice element is in relation with (usually represented through ≤) the given one, assuming that base cases have already been handled.S
lubAux(S other)
Performs the least upper bound operation between this lattice element and the given one, assuming that base cases have already been handled.abstract S
mk(java.util.Set<E> set)
Utility for creating a concrete instance ofSetLattice
given a set.int
size()
Returns the number of elements in this lattice (its cardinality).java.lang.String
toString()
-
Methods inherited from class it.unive.lisa.analysis.BaseLattice
lessOrEqual, lub, widening, wideningAux
-
-
-
-
Field Detail
-
elements
public final java.util.Set<E> elements
The set of elements contained in the lattice.
-
isTop
public final boolean isTop
Whether or not this is the top or bottom element of the lattice, valid only if the set of elements is empty.
-
-
Constructor Detail
-
SetLattice
public SetLattice(java.util.Set<E> elements, boolean isTop)
Builds the lattice.- Parameters:
elements
- the elements that are contained in the latticeisTop
- whether or not this is the top or bottom element of the lattice, valid only if the set of elements is empty
-
-
Method Detail
-
mk
public abstract S mk(java.util.Set<E> set)
Utility for creating a concrete instance ofSetLattice
given a set. This decouples the instance of set used during computation of the elements to put in the lattice from the actual type of set underlying the lattice.- Parameters:
set
- the set containing the elements that must be included in the lattice instance- Returns:
- a new concrete instance of
SetLattice
containing the elements of the given set
-
lubAux
public S lubAux(S other) throws SemanticException
Description copied from class:BaseLattice
Performs the least upper bound operation between this lattice element and the given one, assuming that base cases have already been handled. In particular, it is guaranteed that:other
is notnull
other
is neither top nor bottomthis
is neither top nor bottomthis
andother
are not the same object (according both to==
and toObject.equals(Object)
)
- Specified by:
lubAux
in classBaseLattice<S extends SetLattice<S,E>>
- Parameters:
other
- the other lattice element- Returns:
- the least upper bound between this and other
- Throws:
SemanticException
- if an error occurs during the computation
-
glb
public S glb(S other) throws SemanticException
Performs the greatest lower bound between this set lattice element and the given one.- Parameters:
other
- the other set lattice element- Returns:
- the greatest lower bound between this and other
- Throws:
SemanticException
- if an error occurs during the computation
-
lessOrEqualAux
public boolean lessOrEqualAux(S other) throws SemanticException
Description copied from class:BaseLattice
Yieldstrue
if and only if this lattice element is in relation with (usually represented through ≤) the given one, assuming that base cases have already been handled. In particular, it is guaranteed that:other
is notnull
other
is neither top nor bottomthis
is neither top nor bottomthis
andother
are not the same object (according both to==
and toObject.equals(Object)
)
- Specified by:
lessOrEqualAux
in classBaseLattice<S extends SetLattice<S,E>>
- Parameters:
other
- the other lattice element- Returns:
true
if and only if that condition holds- Throws:
SemanticException
- if an error occurs during the computation
-
isTop
public boolean isTop()
Description copied from interface:Lattice
Yieldstrue
if and only if this object represents the top of the lattice. The default implementation of this method uses reference equality betweenthis
and the value returned byLattice.top()
, thus assuming that the top element is a singleton. If this is not the case, override this method accordingly to provide a coherent test.
-
isBottom
public boolean isBottom()
Description copied from interface:Lattice
Yieldstrue
if and only if this object represents the bottom of the lattice. The default implementation of this method uses reference equality betweenthis
and the value returned byLattice.bottom()
, thus assuming that the bottom element is a singleton. If this is not the case, override this method accordingly to provide a coherent test.
-
contains
public boolean contains(E elem)
Checks whether an element is contained in this set.- Parameters:
elem
- the element- Returns:
true
if the element is contained in this set,false
otherwise.
-
elements
public java.util.Set<E> elements()
Yields the set of elements contained in this lattice element.- Returns:
- the set of elements contained in this lattice element.
-
iterator
public java.util.Iterator<E> iterator()
- Specified by:
iterator
in interfacejava.lang.Iterable<S extends SetLattice<S,E>>
-
hashCode
public int hashCode()
- Specified by:
hashCode
in classBaseLattice<S extends SetLattice<S,E>>
-
equals
public boolean equals(java.lang.Object obj)
- Specified by:
equals
in classBaseLattice<S extends SetLattice<S,E>>
-
toString
public final java.lang.String toString()
- Specified by:
toString
in classBaseLattice<S extends SetLattice<S,E>>
-
size
public int size()
Returns the number of elements in this lattice (its cardinality). If this lattice contains more thanInteger.MAX_VALUE
elements, returnsInteger.MAX_VALUE
.- Returns:
- the number of elements in this lattice (its cardinality)
-
isEmpty
public boolean isEmpty()
Returnstrue
if this set contains no elements.- Returns:
true
if this set contains no elements
-
-