Class Environment<M extends Environment<M,E,T,V>,E extends SymbolicExpression,T extends NonRelationalElement<T,E,M>,V extends Lattice<V>>
- java.lang.Object
-
- it.unive.lisa.analysis.BaseLattice<F>
-
- it.unive.lisa.analysis.lattices.FunctionalLattice<M,Identifier,T>
-
- it.unive.lisa.analysis.nonrelational.Environment<M,E,T,V>
-
- Type Parameters:
M- the concrete type of environmentE- the type of expressions that this domain can evaluateT- the concrete instance of theNonRelationalElementwhose instances are mapped in this environmentV- the type of value returned by the eval function of objects of typeT
- All Implemented Interfaces:
Lattice<M>,SemanticDomain<M,E,Identifier>,java.lang.Iterable<java.util.Map.Entry<Identifier,T>>
- Direct Known Subclasses:
HeapEnvironment,InferenceSystem,ValueEnvironment
public abstract class Environment<M extends Environment<M,E,T,V>,E extends SymbolicExpression,T extends NonRelationalElement<T,E,M>,V extends Lattice<V>> extends FunctionalLattice<M,Identifier,T> implements SemanticDomain<M,E,Identifier>
An environment for aNonRelationalDomain, that mapsIdentifiers to instances of such domain. This is aFunctionalLattice, that is, it implements a function mapping keys (identifiers) to values (instances of the domain), and lattice operations are automatically lifted for individual elements of the environment if they are mapped to the same key.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class it.unive.lisa.analysis.lattices.FunctionalLattice
FunctionalLattice.FunctionalLift<V extends Lattice<V>>, FunctionalLattice.KeyFunctionalLift<K>
-
Nested classes/interfaces inherited from interface it.unive.lisa.analysis.SemanticDomain
SemanticDomain.Satisfiability
-
-
Field Summary
-
Fields inherited from class it.unive.lisa.analysis.lattices.FunctionalLattice
function, lattice
-
Fields inherited from interface it.unive.lisa.analysis.Lattice
BOTTOM_REPR, BOTTOM_STRING, TOP_REPR, TOP_STRING
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedEnvironment(T domain)Builds an empty environment.protectedEnvironment(T domain, java.util.Map<Identifier,T> function)Builds an environment containing the given mapping.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description Massign(Identifier id, E expression, ProgramPoint pp)Yields a copy of this domain, whereidhas been assigned tovalue.protected abstract MassignAux(Identifier id, E expression, java.util.Map<Identifier,T> function, T value, V eval, ProgramPoint pp)Auxiliary function ofassign(Identifier, SymbolicExpression, ProgramPoint)that is invoked after the evaluation of the expression.Massume(E expression, ProgramPoint pp)Yields a copy of this domain, modified by assuming that the given expression holds.protected abstract MassumeSatisfied(V eval)Assumes that an expression, that evaluated toeval, is always satisfied by this environment.protected abstract Mcopy()Copies this environment.protected abstract org.apache.commons.lang3.tuple.Pair<T,V>eval(E expression, ProgramPoint pp)Yields the evaluation of the given expression, happening at the given program point.MforgetIdentifier(Identifier id)Forgets anIdentifier.Mglb(M other)Performs the greatest lower bound between this environment andother.protected abstract MglbAux(T lattice, java.util.Map<Identifier,T> function, M other)Auxiliary glb operation, invoked after the result has been computed to create the concrete instance of environment.booleanisBottom()Yieldstrueif and only if this object represents the bottom of the lattice.booleanisTop()Yieldstrueif and only if this object represents the top of the lattice.protected java.util.Set<Identifier>lubKeys(java.util.Set<Identifier> k1, java.util.Set<Identifier> k2)Yields the union of the keys betweenk1andk2.MpopScope(ScopeToken scope)Pops the scope identified by the given token from the domain.MpushScope(ScopeToken scope)Pushes a new scope, identified by the give token, in the domain.DomainRepresentationrepresentation()Yields aDomainRepresentationof the information contained in this domain's instance.SemanticDomain.Satisfiabilitysatisfies(E expression, ProgramPoint pp)Checks if the given expression is satisfied by the abstract values of this domain, returning an instance ofSemanticDomain.Satisfiability.-
Methods inherited from class it.unive.lisa.analysis.lattices.FunctionalLattice
equals, functionalLift, getKeys, getMap, getState, getValues, glbKeys, hashCode, iterator, lessOrEqualAux, lubAux, mk, mkNewFunction, putState, toString, wideningAux
-
Methods inherited from class it.unive.lisa.analysis.BaseLattice
lessOrEqual, lub, widening
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface it.unive.lisa.analysis.SemanticDomain
forgetIdentifiers, smallStepSemantics
-
-
-
-
Constructor Detail
-
Environment
protected Environment(T domain)
Builds an empty environment.- Parameters:
domain- a singleton instance to be used during semantic operations to retrieve top and bottom values
-
Environment
protected Environment(T domain, java.util.Map<Identifier,T> function)
Builds an environment containing the given mapping. If function isnull, the new environment is the top environment iflattice.isTop()holds, and it is the bottom environment iflattice.isBottom()holds.- Parameters:
domain- a singleton instance to be used during semantic operations to retrieve top and bottom valuesfunction- the function representing the mapping contained in the new environment; can benull
-
-
Method Detail
-
copy
protected abstract M copy()
Copies this environment. The function of the returned environment must be a (shallow) copy of the one of the given environment.- Returns:
- a copy of the given environment
-
assign
public final M assign(Identifier id, E expression, ProgramPoint pp) throws SemanticException
Description copied from interface:SemanticDomainYields a copy of this domain, whereidhas been assigned tovalue.- Specified by:
assignin interfaceSemanticDomain<M extends Environment<M,E,T,V>,E extends SymbolicExpression,T extends NonRelationalElement<T,E,M>>- Parameters:
id- the identifier to assign the value toexpression- the expression to assignpp- the program point that where this operation is being evaluated- Returns:
- a copy of this domain, modified by the assignment
- Throws:
SemanticException- if an error occurs during the computation
-
eval
protected abstract org.apache.commons.lang3.tuple.Pair<T,V> eval(E expression, ProgramPoint pp) throws SemanticException
Yields the evaluation of the given expression, happening at the given program point. The result of the evaluation is in the form of<abstract element, evaluation result>, whereevaluation resultis the true result of the evaluation, whileabstract elementis the element derived by the result that is to be stored inside the environment mapped to an identifier.- Parameters:
expression- the expression to evaluatepp- the program point where the evaluation happens- Returns:
- the result of the evaluation
- Throws:
SemanticException- if something goes wrong during the evaluation
-
assignAux
protected abstract M assignAux(Identifier id, E expression, java.util.Map<Identifier,T> function, T value, V eval, ProgramPoint pp)
Auxiliary function ofassign(Identifier, SymbolicExpression, ProgramPoint)that is invoked after the evaluation of the expression.- Parameters:
id- the identifier that has been assignedexpression- the expression that has been evaluated and assignedfunction- a copy of the current function, where theidhas been assigned toevalvalue- the final value stored forid, after considering applyingNonRelationalElement.variable(Identifier, ProgramPoint)andIdentifier.isWeak()eval- the abstract value that is the result of the evaluation ofvaluepp- the program point that where this operation is being evaluated- Returns:
- a new instance of this environment containing the given function,
obtained by assigning
idtoeval
-
assume
public final M assume(E expression, ProgramPoint pp) throws SemanticException
Description copied from interface:SemanticDomainYields a copy of this domain, modified by assuming that the given expression holds. It is required that the returned domain is in relation with this one. A safe (but imprecise) implementation of this method can always returnthis.- Specified by:
assumein interfaceSemanticDomain<M extends Environment<M,E,T,V>,E extends SymbolicExpression,T extends NonRelationalElement<T,E,M>>- Parameters:
expression- the expression to assume to hold.pp- the program point that where this operation is being evaluated- Returns:
- the (optionally) modified copy of this domain
- Throws:
SemanticException- if an error occurs during the computation
-
assumeSatisfied
protected abstract M assumeSatisfied(V eval)
Assumes that an expression, that evaluated toeval, is always satisfied by this environment. This auxiliary method serves as a constructor for the final concrete instance of environment.- Parameters:
eval- the result of the evaluation of the expression that is always satisfied- Returns:
- the (possibly) updated environment
-
glb
public final M glb(M other) throws SemanticException
Performs the greatest lower bound between this environment andother.- Parameters:
other- the other environment- Returns:
- the greatest lower bound between this environment and
other - Throws:
SemanticException- if something goes wrong during the computation
-
glbAux
protected abstract M glbAux(T lattice, java.util.Map<Identifier,T> function, M other)
Auxiliary glb operation, invoked after the result has been computed to create the concrete instance of environment. Note that any additional information that is instance-specific (i.e. anything but function and lattice singleton) has to be computed by this method.- Parameters:
lattice- the lattice that is the result of the glbfunction- the function that is the result of the glb (might benullother- the other environment- Returns:
- the final instance of the glb
-
satisfies
public final SemanticDomain.Satisfiability satisfies(E expression, ProgramPoint pp) throws SemanticException
Description copied from interface:SemanticDomainChecks if the given expression is satisfied by the abstract values of this domain, returning an instance ofSemanticDomain.Satisfiability.- Specified by:
satisfiesin interfaceSemanticDomain<M extends Environment<M,E,T,V>,E extends SymbolicExpression,T extends NonRelationalElement<T,E,M>>- Parameters:
expression- the expression whose satisfiability is to be evaluatedpp- the program point that where this operation is being evaluated- Returns:
SemanticDomain.Satisfiability.SATISFIEDis the expression is satisfied by the values of this domain,SemanticDomain.Satisfiability.NOT_SATISFIEDif it is not satisfied, orSemanticDomain.Satisfiability.UNKNOWNif it is either impossible to determine if it satisfied, or if it is satisfied by some values and not by some others (this is equivalent to a TOP boolean value)- Throws:
SemanticException- if an error occurs during the computation
-
isTop
public final boolean isTop()
Yieldstrueif and only if this object represents the top of the lattice. The default implementation of this method uses reference equality betweenthisand 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.
An environment is the top environment if the underlying lattice'sisTop()holds and its function isnull.
-
isBottom
public final boolean isBottom()
Yieldstrueif and only if this object represents the bottom of the lattice. The default implementation of this method uses reference equality betweenthisand 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.
An environment is the bottom environment if the underlying lattice'sisBottom()holds and its function isnull.
-
pushScope
public M pushScope(ScopeToken scope) throws SemanticException
Description copied from interface:SemanticDomainPushes a new scope, identified by the give token, in the domain. This causes information about all variables not associated with a scope (and thus visible) to be mapped to the given scope and hidden away, until the scope is popped withSemanticDomain.popScope(ScopeToken).- Specified by:
pushScopein interfaceSemanticDomain<M extends Environment<M,E,T,V>,E extends SymbolicExpression,T extends NonRelationalElement<T,E,M>>- Parameters:
scope- the token identifying the scope to push- Returns:
- a copy of this domain where the local variables have been hidden
- Throws:
SemanticException- if an error occurs during the computation
-
popScope
public M popScope(ScopeToken scope) throws SemanticException
Description copied from interface:SemanticDomainPops the scope identified by the given token from the domain. This causes all the visible variables (i.e. that are not mapped to a scope) to be removed from the domain, while the local variables that were associated to the given scope token (and thus hidden) will become visible again.- Specified by:
popScopein interfaceSemanticDomain<M extends Environment<M,E,T,V>,E extends SymbolicExpression,T extends NonRelationalElement<T,E,M>>- Parameters:
scope- the token of the scope to be restored- Returns:
- a copy of this domain where the local variables have been removed, while the variables mapped to the given scope are visible again
- Throws:
SemanticException- if an error occurs during the computation
-
forgetIdentifier
public final M forgetIdentifier(Identifier id) throws SemanticException
Description copied from interface:SemanticDomainForgets anIdentifier. This means that all information regarding the givenidwill be lost. This method should be invoked whenever an identifier gets out of scope.- Specified by:
forgetIdentifierin interfaceSemanticDomain<M extends Environment<M,E,T,V>,E extends SymbolicExpression,T extends NonRelationalElement<T,E,M>>- Parameters:
id- the identifier to forget- Returns:
- the semantic domain without information about the given id
- Throws:
SemanticException- if an error occurs during the computation
-
representation
public DomainRepresentation representation()
Description copied from interface:SemanticDomainYields aDomainRepresentationof the information contained in this domain's instance.- Specified by:
representationin interfaceSemanticDomain<M extends Environment<M,E,T,V>,E extends SymbolicExpression,T extends NonRelationalElement<T,E,M>>- Returns:
- the representation
-
lubKeys
protected java.util.Set<Identifier> lubKeys(java.util.Set<Identifier> k1, java.util.Set<Identifier> k2) throws SemanticException
Description copied from class:FunctionalLatticeYields the union of the keys betweenk1andk2.- Overrides:
lubKeysin classFunctionalLattice<M extends Environment<M,E,T,V>,Identifier,T extends NonRelationalElement<T,E,M>>- Parameters:
k1- the first key setk2- the second key set- Returns:
- the union between
k1andk2 - Throws:
SemanticException- if something goes wrong while lifting the keys
-
-