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 theNonRelationalElement
whose 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
,TypeEnvironment
,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 mapsIdentifier
s 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_STRING, TOP_STRING
-
-
Constructor Summary
Constructors Constructor Description Environment(T domain)
Builds an empty environment.Environment(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 M
assign(Identifier id, E expression, ProgramPoint pp)
Yields a copy of this domain, whereid
has been assigned tovalue
.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.M
assume(E expression, ProgramPoint pp)
Yields a copy of this domain, modified by assuming that the given expression holds.abstract M
assumeSatisfied(V eval)
Assumes that an expression, that evaluated toeval
, is always satisfied by this environment.abstract M
copy()
Copies this environment.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.M
forgetIdentifier(Identifier id)
Forgets anIdentifier
.M
forgetIdentifiersIf(java.util.function.Predicate<Identifier> test)
Forgets allIdentifier
s that match the given predicate.M
glb(M other)
Performs the greatest lower bound between this environment andother
.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.java.util.Set<Identifier>
lubKeys(java.util.Set<Identifier> k1, java.util.Set<Identifier> k2)
Yields the union of the keys betweenk1
andk2
.M
popScope(ScopeToken scope)
Pops the scope identified by the given token from the domain.M
pushScope(ScopeToken scope)
Pushes a new scope, identified by the give token, in the domain.DomainRepresentation
representation()
Yields aDomainRepresentation
of the information contained in this domain's instance.SemanticDomain.Satisfiability
satisfies(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, isBottom, isTop, 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, getDomainInstance, smallStepSemantics
-
-
-
-
Constructor Detail
-
Environment
public 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
public 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
public 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 M assign(Identifier id, E expression, ProgramPoint pp) throws SemanticException
Description copied from interface:SemanticDomain
Yields a copy of this domain, whereid
has been assigned tovalue
.- Specified by:
assign
in 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
public 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 result
is the true result of the evaluation, whileabstract element
is 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
public abstract M assignAux(Identifier id, E expression, java.util.Map<Identifier,T> function, T value, V eval, ProgramPoint pp) throws SemanticException
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 theid
has been assigned toeval
value
- the final value stored forid
, after considering applyingNonRelationalElement.variable(Identifier, ProgramPoint)
andIdentifier.isWeak()
eval
- the abstract value that is the result of the evaluation ofvalue
pp
- the program point that where this operation is being evaluated- Returns:
- a new instance of this environment containing the given function,
obtained by assigning
id
toeval
- Throws:
SemanticException
- if an error occurs during the computation
-
assume
public M assume(E expression, ProgramPoint pp) throws SemanticException
Description copied from interface:SemanticDomain
Yields 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:
assume
in 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
public abstract M assumeSatisfied(V eval) throws SemanticException
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
- Throws:
SemanticException
- if an error occurs during the computation
-
glb
public 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
public abstract M glbAux(T lattice, java.util.Map<Identifier,T> function, M other) throws SemanticException
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 benull
other
- the other environment- Returns:
- the final instance of the glb
- Throws:
SemanticException
- if an error occurs during the computation
-
satisfies
public SemanticDomain.Satisfiability satisfies(E expression, ProgramPoint pp) throws SemanticException
Description copied from interface:SemanticDomain
Checks if the given expression is satisfied by the abstract values of this domain, returning an instance ofSemanticDomain.Satisfiability
.- Specified by:
satisfies
in 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.SATISFIED
is the expression is satisfied by the values of this domain,SemanticDomain.Satisfiability.NOT_SATISFIED
if it is not satisfied, orSemanticDomain.Satisfiability.UNKNOWN
if 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
-
pushScope
public M pushScope(ScopeToken scope) throws SemanticException
Description copied from interface:SemanticDomain
Pushes 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:
pushScope
in 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:SemanticDomain
Pops 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:
popScope
in 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 M forgetIdentifier(Identifier id) throws SemanticException
Description copied from interface:SemanticDomain
Forgets anIdentifier
. This means that all information regarding the givenid
will be lost. This method should be invoked whenever an identifier gets out of scope.- Specified by:
forgetIdentifier
in 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
-
forgetIdentifiersIf
public M forgetIdentifiersIf(java.util.function.Predicate<Identifier> test) throws SemanticException
Description copied from interface:SemanticDomain
Forgets allIdentifier
s that match the given predicate. This means that all information regarding the those identifiers will be lost. This method should be invoked whenever an identifier gets out of scope.- Specified by:
forgetIdentifiersIf
in interfaceSemanticDomain<M extends Environment<M,E,T,V>,E extends SymbolicExpression,T extends NonRelationalElement<T,E,M>>
- Parameters:
test
- the test to identify the targets of the removal- Returns:
- the semantic domain without information about the ids
- Throws:
SemanticException
- if an error occurs during the computation
-
representation
public DomainRepresentation representation()
Description copied from interface:SemanticDomain
Yields aDomainRepresentation
of the information contained in this domain's instance.- Specified by:
representation
in interfaceSemanticDomain<M extends Environment<M,E,T,V>,E extends SymbolicExpression,T extends NonRelationalElement<T,E,M>>
- Returns:
- the representation
-
lubKeys
public java.util.Set<Identifier> lubKeys(java.util.Set<Identifier> k1, java.util.Set<Identifier> k2) throws SemanticException
Description copied from class:FunctionalLattice
Yields the union of the keys betweenk1
andk2
.- Overrides:
lubKeys
in 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
k1
andk2
- Throws:
SemanticException
- if something goes wrong while lifting the keys
-
-