Package it.unive.lisa.analysis.lattices
Class FunctionalLattice<F extends FunctionalLattice<F,K,V>,K,V extends Lattice<V>>
- java.lang.Object
-
- it.unive.lisa.analysis.lattices.FunctionalLattice<F,K,V>
-
- Type Parameters:
F
- the concreteFunctionalLattice
typeK
- the concrete type of the keys of this functionV
- the concreteLattice
type of the values of this function
- All Implemented Interfaces:
BaseLattice<F>
,Lattice<F>
,StructuredObject
,java.lang.Iterable<java.util.Map.Entry<K,V>>
- Direct Known Subclasses:
CFGResults
,FixpointResults
,GenericMapLattice
,StatementStore
,SymbolAliasing
,VariableLift
public abstract class FunctionalLattice<F extends FunctionalLattice<F,K,V>,K,V extends Lattice<V>> extends java.lang.Object implements BaseLattice<F>, java.lang.Iterable<java.util.Map.Entry<K,V>>
A generic functional abstract domain that performs the functional lifting of the lattice on the elements of the co-domain.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
FunctionalLattice.FunctionalLift<V extends Lattice<V>>
Interface for the lift of lattice elements.static interface
FunctionalLattice.KeyFunctionalLift<K>
Interface for the left of key sets.
-
Field Summary
Fields Modifier and Type Field Description java.util.Map<K,V>
function
The function implemented by this lattice.V
lattice
The underlying lattice.-
Fields inherited from interface it.unive.lisa.analysis.Lattice
BOTTOM_STRING, TOP_STRING
-
-
Constructor Summary
Constructors Constructor Description FunctionalLattice(V lattice)
Builds the lattice.FunctionalLattice(V lattice, java.util.Map<K,V> function)
Builds the lattice by cloning the given function.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description boolean
equals(java.lang.Object obj)
F
functionalLift(F other, V missing, FunctionalLattice.KeyFunctionalLift<K> keyLifter, FunctionalLattice.FunctionalLift<V> valueLifter)
Yields the functional lift betweenthis
andother
.java.util.Set<K>
getKeys()
Yields the set of keys currently in this lattice.java.util.Map<K,V>
getMap()
Yields the map associated with this functional lattice element.V
getOtDefault(K key, V def)
Similar togetState(Object)
, but yields a custom default value for keys that are not part of the mapping (instead of usingstateOfUnknown(Object)
).V
getState(K key)
Yields the state associated to the given key.java.util.Collection<V>
getValues()
Yields the values of this functional lattice.F
glbAux(F other)
Performs the greatest lower bound operation between this lattice element and the given one, assuming that base cases have already been handled.java.util.Set<K>
glbKeys(java.util.Set<K> k1, java.util.Set<K> k2)
Yields the intersection of the keys betweenk1
andk2
.int
hashCode()
boolean
isBottom()
Yieldstrue
if and only if this object represents the bottom of the lattice.boolean
isTop()
Yieldstrue
if and only if this object represents the top of the lattice.java.util.Iterator<java.util.Map.Entry<K,V>>
iterator()
boolean
lessOrEqualAux(F 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.F
lubAux(F other)
Performs the least upper bound operation between this lattice element and the given one, assuming that base cases have already been handled.java.util.Set<K>
lubKeys(java.util.Set<K> k1, java.util.Set<K> k2)
Yields the union of the keys betweenk1
andk2
.abstract F
mk(V lattice, java.util.Map<K,V> function)
Builds a instance of this class from the given lattice instance and the given mapping.java.util.Map<K,V>
mkNewFunction(java.util.Map<K,V> other, boolean preserveNull)
Creates a new instance of the underlying function.F
narrowingAux(F other)
Performs the narrowing operation between this lattice element and the given one, assuming that base cases have already been handled.F
putState(K key, V state)
Yields an instance of this class equal to the receiver of the call, but withkey
mapped tostate
.StructuredRepresentation
representation()
Yields aStructuredRepresentation
of the information contained in this object's instance.abstract V
stateOfUnknown(K key)
Yields the value that should be returned bygetState(Object)
whenever the given key is not present in this map.java.lang.String
toString()
F
wideningAux(F other)
Performs the widening operation between this lattice element and the given one, assuming that base cases have already been handled.-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface it.unive.lisa.analysis.BaseLattice
glb, lessOrEqual, lub, narrowing, widening
-
-
-
-
Constructor Detail
-
FunctionalLattice
public FunctionalLattice(V lattice)
Builds the lattice.- Parameters:
lattice
- the underlying lattice
-
-
Method Detail
-
mkNewFunction
public java.util.Map<K,V> mkNewFunction(java.util.Map<K,V> other, boolean preserveNull)
Creates a new instance of the underlying function. The purpose of this method is to provide a common function implementation to every subclass that does not have implementation-specific requirements.- Parameters:
other
- an optional function to copy, can benull
preserveNull
- whether a nullother
should cause anull
return value or an empty function- Returns:
- a new function
-
getKeys
public java.util.Set<K> getKeys()
Yields the set of keys currently in this lattice.- Returns:
- the set of keys
-
getState
public V getState(K key)
Yields the state associated to the given key. This operation is defined in term of lattices: it always returns bottom ofisBottom()
holds, top ifisTop()
holds, the stored value when key is part of the mapping, orstateOfUnknown(Object)
otherwise. This method is the primary way in which information mapped to a key should be extracted from this function.- Parameters:
key
- the key- Returns:
- the state
-
getOtDefault
public V getOtDefault(K key, V def)
Similar togetState(Object)
, but yields a custom default value for keys that are not part of the mapping (instead of usingstateOfUnknown(Object)
). This is useful for implementing specific operation that need to use an operation-neutral element as fallback.- Parameters:
key
- the keydef
- the default value to return when there is no mapping forkey
- Returns:
- the state
-
stateOfUnknown
public abstract V stateOfUnknown(K key)
Yields the value that should be returned bygetState(Object)
whenever the given key is not present in this map.- Parameters:
key
- the key that is missing- Returns:
- the lattice element for keys not in the mapping
-
putState
public F putState(K key, V state)
Yields an instance of this class equal to the receiver of the call, but withkey
mapped tostate
.- Parameters:
key
- the keystate
- the state- Returns:
- the new instance of this class with the updated mapping
-
mk
public abstract F mk(V lattice, java.util.Map<K,V> function)
Builds a instance of this class from the given lattice instance and the given mapping.- Parameters:
lattice
- an instance of lattice to be used during semantic operations to retrieve top and bottom valuesfunction
- the function representing the mapping contained in the new environment; can benull
- Returns:
- a new instance of this class
-
lubAux
public F lubAux(F other) throws SemanticException
Description copied from interface: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 interfaceBaseLattice<F extends FunctionalLattice<F,K,V>>
- Parameters:
other
- the other lattice element- Returns:
- the least upper bound between this and other
- Throws:
SemanticException
- if an error occurs during the computation
-
glbAux
public F glbAux(F other) throws SemanticException
Description copied from interface:BaseLattice
Performs the greatest lower 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:
glbAux
in interfaceBaseLattice<F extends FunctionalLattice<F,K,V>>
- Parameters:
other
- the other lattice element- Returns:
- the greatest lower bound between this and other
- Throws:
SemanticException
- if an error occurs during the computation
-
wideningAux
public F wideningAux(F other) throws SemanticException
Description copied from interface:BaseLattice
Performs the widening 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)
)
BaseLattice.lubAux(BaseLattice)
, and is thus safe for finite lattices and ACC ones.- Specified by:
wideningAux
in interfaceBaseLattice<F extends FunctionalLattice<F,K,V>>
- Parameters:
other
- the other lattice element- Returns:
- the widening between this and other
- Throws:
SemanticException
- if an error occurs during the computation
-
narrowingAux
public F narrowingAux(F other) throws SemanticException
Description copied from interface:BaseLattice
Performs the narrowing 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)
)
BaseLattice.glbAux(BaseLattice)
, and is thus safe for finite lattices and DCC ones.- Specified by:
narrowingAux
in interfaceBaseLattice<F extends FunctionalLattice<F,K,V>>
- Parameters:
other
- the other lattice element- Returns:
- the narrowing between this and other
- Throws:
SemanticException
- if an error occurs during the computation
-
functionalLift
public F functionalLift(F other, V missing, FunctionalLattice.KeyFunctionalLift<K> keyLifter, FunctionalLattice.FunctionalLift<V> valueLifter) throws SemanticException
Yields the functional lift betweenthis
andother
.- Parameters:
other
- the other functional latticemissing
- the lattice element to use for the lift when a key has no mapping in one of the two functions (e.g., for lub, missing should be bottom, while for glb it should be top)keyLifter
- the key liftervalueLifter
- the value lifter- Returns:
- the intersection between
k1
andk2
- Throws:
SemanticException
- if something goes wrong while lifting the lattice elements
-
lubKeys
public java.util.Set<K> lubKeys(java.util.Set<K> k1, java.util.Set<K> k2) throws SemanticException
Yields the union of the keys betweenk1
andk2
.- Parameters:
k1
- the first key setk2
- the second key set- Returns:
- the union between
k1
andk2
- Throws:
SemanticException
- if something goes wrong while lifting the keys
-
glbKeys
public java.util.Set<K> glbKeys(java.util.Set<K> k1, java.util.Set<K> k2) throws SemanticException
Yields the intersection of the keys betweenk1
andk2
.- Parameters:
k1
- the first key setk2
- the second key set- Returns:
- the intersection between
k1
andk2
- Throws:
SemanticException
- if something goes wrong while lifting the key sets
-
lessOrEqualAux
public boolean lessOrEqualAux(F other) throws SemanticException
Description copied from interface: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 interfaceBaseLattice<F extends FunctionalLattice<F,K,V>>
- 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()
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.
By default, a functional lattice is the top lattice if the underlying lattice'sisTop()
holds and its function isnull
.
-
isBottom
public boolean isBottom()
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.
By default, a functional lattice is the top lattice if the underlying lattice'sisBottom()
holds and its function isnull
.
-
hashCode
public int hashCode()
- Specified by:
hashCode
in interfaceBaseLattice<F extends FunctionalLattice<F,K,V>>
- Overrides:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Specified by:
equals
in interfaceBaseLattice<F extends FunctionalLattice<F,K,V>>
- Overrides:
equals
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Specified by:
toString
in interfaceBaseLattice<F extends FunctionalLattice<F,K,V>>
- Overrides:
toString
in classjava.lang.Object
-
iterator
public java.util.Iterator<java.util.Map.Entry<K,V>> iterator()
- Specified by:
iterator
in interfacejava.lang.Iterable<F extends FunctionalLattice<F,K,V>>
-
getValues
public java.util.Collection<V> getValues()
Yields the values of this functional lattice.- Returns:
- the values of this functional lattice
-
getMap
public java.util.Map<K,V> getMap()
Yields the map associated with this functional lattice element.- Returns:
- the map associated with this functional lattice element.
-
representation
public StructuredRepresentation representation()
Description copied from interface:StructuredObject
Yields aStructuredRepresentation
of the information contained in this object's instance.- Specified by:
representation
in interfaceStructuredObject
- Returns:
- the representation
-
-