Class HeapEnvironment<T extends NonRelationalHeapDomain<T>>
- java.lang.Object
-
- it.unive.lisa.analysis.BaseLattice<F>
-
- it.unive.lisa.analysis.lattices.FunctionalLattice<M,Identifier,T>
-
- it.unive.lisa.analysis.nonrelational.Environment<HeapEnvironment<T>,SymbolicExpression,T,T>
-
- it.unive.lisa.analysis.nonrelational.heap.HeapEnvironment<T>
-
- Type Parameters:
T
- the concrete instance of theNonRelationalHeapDomain
whose instances are mapped in this environment
- All Implemented Interfaces:
HeapDomain<HeapEnvironment<T>>
,HeapSemanticOperation
,Lattice<HeapEnvironment<T>>
,SemanticDomain<HeapEnvironment<T>,SymbolicExpression,Identifier>
,java.lang.Iterable<java.util.Map.Entry<Identifier,T>>
public class HeapEnvironment<T extends NonRelationalHeapDomain<T>> extends Environment<HeapEnvironment<T>,SymbolicExpression,T,T> implements HeapDomain<HeapEnvironment<T>>
An environment for aNonRelationalHeapDomain
, 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.heap.HeapSemanticOperation
HeapSemanticOperation.HeapReplacement
-
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 HeapEnvironment(T domain)
Builds an empty environment.HeapEnvironment(T domain, java.util.Map<Identifier,T> function)
Builds an empty environment from a given mapping.HeapEnvironment(T domain, java.util.Map<Identifier,T> function, java.util.List<HeapSemanticOperation.HeapReplacement> substitution)
Builds an environment containing the given mapping.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description HeapEnvironment<T>
assignAux(Identifier id, SymbolicExpression expression, java.util.Map<Identifier,T> function, T value, T eval, ProgramPoint pp)
Auxiliary function ofEnvironment.assign(Identifier, SymbolicExpression, ProgramPoint)
that is invoked after the evaluation of the expression.HeapEnvironment<T>
assumeSatisfied(T eval)
Assumes that an expression, that evaluated toeval
, is always satisfied by this environment.HeapEnvironment<T>
bottom()
Yields the bottom element of this lattice.HeapEnvironment<T>
copy()
Copies this environment.boolean
equals(java.lang.Object obj)
org.apache.commons.lang3.tuple.Pair<T,T>
eval(SymbolicExpression expression, ProgramPoint pp)
Yields the evaluation of the given expression, happening at the given program point.java.util.List<HeapSemanticOperation.HeapReplacement>
getSubstitution()
Yields the substitution, in the form of a list ofHeapSemanticOperation.HeapReplacement
s that must be processed in their order of appearance, that the creation of this heap domain caused.HeapEnvironment<T>
glbAux(T lattice, java.util.Map<Identifier,T> function, HeapEnvironment<T> other)
Auxiliary glb operation, invoked after the result has been computed to create the concrete instance of environment.int
hashCode()
boolean
lessOrEqualAux(HeapEnvironment<T> 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.HeapEnvironment<T>
lubAux(HeapEnvironment<T> other)
Performs the least upper bound operation between this lattice element and the given one, assuming that base cases have already been handled.HeapEnvironment<T>
mk(T lattice, java.util.Map<Identifier,T> function)
Builds a instance of this class from the given lattice instance and the given mapping.ExpressionSet<ValueExpression>
rewrite(SymbolicExpression expression, ProgramPoint pp)
Rewrites aSymbolicExpression
, getting rid of the parts that access heap structures, substituting them with syntheticHeapLocation
s representing the accessed locations.HeapEnvironment<T>
smallStepSemantics(SymbolicExpression expression, ProgramPoint pp)
Yields a copy of this domain, that has been modified accordingly to the semantics of the givenexpression
.HeapEnvironment<T>
top()
Yields the top element of this lattice.HeapEnvironment<T>
wideningAux(HeapEnvironment<T> 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 it.unive.lisa.analysis.nonrelational.Environment
assign, assume, forgetIdentifier, forgetIdentifiersIf, glb, lubKeys, popScope, pushScope, representation, satisfies
-
Methods inherited from class it.unive.lisa.analysis.lattices.FunctionalLattice
functionalLift, getKeys, getMap, getState, getValues, glbKeys, isBottom, isTop, iterator, mkNewFunction, putState, toString
-
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.heap.HeapDomain
rewriteAll
-
Methods inherited from interface it.unive.lisa.analysis.Lattice
isBottom, isTop, lessOrEqual, lub, widening
-
Methods inherited from interface it.unive.lisa.analysis.SemanticDomain
assign, assume, forgetIdentifier, forgetIdentifiers, forgetIdentifiersIf, getDomainInstance, popScope, pushScope, representation, satisfies
-
-
-
-
Constructor Detail
-
HeapEnvironment
public HeapEnvironment(T domain)
Builds an empty environment.- Parameters:
domain
- a singleton instance to be used during semantic operations to retrieve top and bottom values
-
HeapEnvironment
public HeapEnvironment(T domain, java.util.Map<Identifier,T> function)
Builds an empty environment from a given mapping.- Parameters:
domain
- singleton instance to be used during semantic operations to retrieve top and bottom valuesfunction
- the initial mapping of this heap environment
-
HeapEnvironment
public HeapEnvironment(T domain, java.util.Map<Identifier,T> function, java.util.List<HeapSemanticOperation.HeapReplacement> substitution)
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
substitution
- the list of substitutions that has been generated together with the fresh instance being built
-
-
Method Detail
-
mk
public HeapEnvironment<T> mk(T lattice, java.util.Map<Identifier,T> function)
Description copied from class:FunctionalLattice
Builds a instance of this class from the given lattice instance and the given mapping.- Specified by:
mk
in classFunctionalLattice<HeapEnvironment<T extends NonRelationalHeapDomain<T>>,Identifier,T extends NonRelationalHeapDomain<T>>
- 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
-
rewrite
public ExpressionSet<ValueExpression> rewrite(SymbolicExpression expression, ProgramPoint pp) throws SemanticException
Description copied from interface:HeapDomain
Rewrites aSymbolicExpression
, getting rid of the parts that access heap structures, substituting them with syntheticHeapLocation
s representing the accessed locations. The expression returned by this method should not containHeapExpression
s.
If no rewriting is necessary, the input expression can be returned instead.- Specified by:
rewrite
in interfaceHeapDomain<T extends NonRelationalHeapDomain<T>>
- Parameters:
expression
- the expression to rewritepp
- the program point that where this expression is being rewritten- Returns:
- the rewritten expression, or the original one
- Throws:
SemanticException
- if something goes wrong during the rewriting
-
getSubstitution
public java.util.List<HeapSemanticOperation.HeapReplacement> getSubstitution()
Description copied from interface:HeapSemanticOperation
Yields the substitution, in the form of a list ofHeapSemanticOperation.HeapReplacement
s that must be processed in their order of appearance, that the creation of this heap domain caused. This substitution mapsIdentifier
s in the pre-state toIdentifier
s in the post state. If no substitution needs to be applied, this method should return an empty list.- Specified by:
getSubstitution
in interfaceHeapSemanticOperation
- Returns:
- the list of replacements
-
copy
public HeapEnvironment<T> copy()
Description copied from class:Environment
Copies this environment. The function of the returned environment must be a (shallow) copy of the one of the given environment.- Specified by:
copy
in classEnvironment<HeapEnvironment<T extends NonRelationalHeapDomain<T>>,SymbolicExpression,T extends NonRelationalHeapDomain<T>,T extends NonRelationalHeapDomain<T>>
- Returns:
- a copy of the given environment
-
eval
public org.apache.commons.lang3.tuple.Pair<T,T> eval(SymbolicExpression expression, ProgramPoint pp) throws SemanticException
Description copied from class:Environment
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.- Specified by:
eval
in classEnvironment<HeapEnvironment<T extends NonRelationalHeapDomain<T>>,SymbolicExpression,T extends NonRelationalHeapDomain<T>,T extends NonRelationalHeapDomain<T>>
- 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 HeapEnvironment<T> assignAux(Identifier id, SymbolicExpression expression, java.util.Map<Identifier,T> function, T value, T eval, ProgramPoint pp)
Description copied from class:Environment
Auxiliary function ofEnvironment.assign(Identifier, SymbolicExpression, ProgramPoint)
that is invoked after the evaluation of the expression.- Specified by:
assignAux
in classEnvironment<HeapEnvironment<T extends NonRelationalHeapDomain<T>>,SymbolicExpression,T extends NonRelationalHeapDomain<T>,T extends NonRelationalHeapDomain<T>>
- 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
-
assumeSatisfied
public HeapEnvironment<T> assumeSatisfied(T eval)
Description copied from class:Environment
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.- Specified by:
assumeSatisfied
in classEnvironment<HeapEnvironment<T extends NonRelationalHeapDomain<T>>,SymbolicExpression,T extends NonRelationalHeapDomain<T>,T extends NonRelationalHeapDomain<T>>
- Parameters:
eval
- the result of the evaluation of the expression that is always satisfied- Returns:
- the (possibly) updated environment
-
glbAux
public HeapEnvironment<T> glbAux(T lattice, java.util.Map<Identifier,T> function, HeapEnvironment<T> other)
Description copied from class:Environment
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.- Specified by:
glbAux
in classEnvironment<HeapEnvironment<T extends NonRelationalHeapDomain<T>>,SymbolicExpression,T extends NonRelationalHeapDomain<T>,T extends NonRelationalHeapDomain<T>>
- 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
-
smallStepSemantics
public HeapEnvironment<T> smallStepSemantics(SymbolicExpression expression, ProgramPoint pp) throws SemanticException
Description copied from interface:SemanticDomain
Yields a copy of this domain, that has been modified accordingly to the semantics of the givenexpression
.- Specified by:
smallStepSemantics
in interfaceSemanticDomain<HeapEnvironment<T extends NonRelationalHeapDomain<T>>,SymbolicExpression,Identifier>
- Parameters:
expression
- the expression whose semantics need to be computedpp
- the program point that where this operation is being evaluated- Returns:
- a copy of this domain, modified accordingly to the semantics of
expression
- Throws:
SemanticException
- if an error occurs during the computation
-
top
public HeapEnvironment<T> top()
Description copied from interface:Lattice
Yields the top element of this lattice. The returned element should be unique across different calls to this method, sinceLattice.isTop()
uses reference equality by default. If the value returned by this method is not a singleton, overrideLattice.isTop()
accordingly to provide a coherent test.- Specified by:
top
in interfaceLattice<T extends NonRelationalHeapDomain<T>>
- Returns:
- the top element
-
bottom
public HeapEnvironment<T> bottom()
Description copied from interface:Lattice
Yields the bottom element of this lattice. The returned element should be unique across different calls to this method, sinceLattice.isBottom()
uses reference equality by default. If the value returned by this method is not a singleton, overrideLattice.isBottom()
accordingly to provide a coherent test.- Specified by:
bottom
in interfaceLattice<T extends NonRelationalHeapDomain<T>>
- Returns:
- the bottom element
-
lubAux
public HeapEnvironment<T> lubAux(HeapEnvironment<T> 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)
)
- Overrides:
lubAux
in classFunctionalLattice<HeapEnvironment<T extends NonRelationalHeapDomain<T>>,Identifier,T extends NonRelationalHeapDomain<T>>
- Parameters:
other
- the other lattice element- Returns:
- the least upper bound between this and other
- Throws:
SemanticException
- if an error occurs during the computation
-
wideningAux
public HeapEnvironment<T> wideningAux(HeapEnvironment<T> other) throws SemanticException
Description copied from class: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.- Overrides:
wideningAux
in classFunctionalLattice<HeapEnvironment<T extends NonRelationalHeapDomain<T>>,Identifier,T extends NonRelationalHeapDomain<T>>
- Parameters:
other
- the other lattice element- Returns:
- the widening between this and other
- Throws:
SemanticException
- if an error occurs during the computation
-
lessOrEqualAux
public boolean lessOrEqualAux(HeapEnvironment<T> 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)
)
- Overrides:
lessOrEqualAux
in classFunctionalLattice<HeapEnvironment<T extends NonRelationalHeapDomain<T>>,Identifier,T extends NonRelationalHeapDomain<T>>
- Parameters:
other
- the other lattice element- Returns:
true
if and only if that condition holds- Throws:
SemanticException
- if an error occurs during the computation
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classFunctionalLattice<HeapEnvironment<T extends NonRelationalHeapDomain<T>>,Identifier,T extends NonRelationalHeapDomain<T>>
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classFunctionalLattice<HeapEnvironment<T extends NonRelationalHeapDomain<T>>,Identifier,T extends NonRelationalHeapDomain<T>>
-
-