Package it.unive.lisa.analysis
Class AnalysisState<A extends AbstractState<A>>
- java.lang.Object
-
- it.unive.lisa.analysis.AnalysisState<A>
-
- Type Parameters:
A
- the type ofAbstractState
embedded in this state
- All Implemented Interfaces:
BaseLattice<AnalysisState<A>>
,Lattice<AnalysisState<A>>
,ScopedObject<AnalysisState<A>>
,StructuredObject
public class AnalysisState<A extends AbstractState<A>> extends java.lang.Object implements BaseLattice<AnalysisState<A>>, StructuredObject, ScopedObject<AnalysisState<A>>
The abstract analysis state at a given program point. An analysis state is composed by anAbstractState
modeling the abstract values of program variables and heap locations, and a collection ofSymbolicExpression
s keeping trace of what has been evaluated and is available for later computations, but is not stored in memory (i.e. the stack).
-
-
Field Summary
-
Fields inherited from interface it.unive.lisa.analysis.Lattice
BOTTOM_STRING, TOP_STRING
-
-
Constructor Summary
Constructors Constructor Description AnalysisState(A state, ExpressionSet computedExpressions)
Builds a new state.AnalysisState(A state, ExpressionSet computedExpressions, FixpointInfo info)
Builds a new state.AnalysisState(A state, SymbolicExpression computedExpression)
Builds a new state.AnalysisState(A state, SymbolicExpression computedExpression, FixpointInfo info)
Builds a new state.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description AnalysisState<A>
assign(SymbolicExpression id, SymbolicExpression expression, ProgramPoint pp)
Yields a copy of this analysis state, where the symbolic expressionid
has been assigned tovalue
: ifid
is not anIdentifier
, then it is rewritten before performing the assignment.AnalysisState<A>
assign(Identifier id, SymbolicExpression value, ProgramPoint pp)
Yields a copy of this state, whereid
has been assigned tovalue
.AnalysisState<A>
assume(SymbolicExpression expression, ProgramPoint src, ProgramPoint dest)
Yields a copy of this state, modified by assuming that the given expression holds.AnalysisState<A>
bottom()
Yields the bottom element of this lattice.boolean
equals(java.lang.Object obj)
AnalysisState<A>
forgetIdentifier(Identifier id)
Forgets anIdentifier
.AnalysisState<A>
forgetIdentifiers(java.lang.Iterable<Identifier> ids)
Forgets all the givenIdentifier
s by invokingforgetIdentifier(Identifier)
on each given identifier.AnalysisState<A>
forgetIdentifiersIf(java.util.function.Predicate<Identifier> test)
Forgets allIdentifier
s that match the given predicate.ExpressionSet
getComputedExpressions()
Yields the last computed expression.FixpointInfo
getFixpointInformation()
Yields the additional information that must be computed during fixpoint computations.Lattice<?>
getInfo(java.lang.String key)
Yields the Additional information associated to the given key, as defined in this instance'sgetFixpointInformation()
.<T> T
getInfo(java.lang.String key, java.lang.Class<T> type)
Yields the additional information associated to the given key, casted to the given type, as defined in this instance'sgetFixpointInformation()
.A
getState()
Yields theAbstractState
embedded into this analysis state, containing abstract values for program variables and memory locations.AnalysisState<A>
glbAux(AnalysisState<A> other)
Performs the greatest lower bound operation between this lattice element and the given one, assuming that base cases have already been handled.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.boolean
lessOrEqualAux(AnalysisState<A> 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.AnalysisState<A>
lubAux(AnalysisState<A> other)
Performs the least upper bound operation between this lattice element and the given one, assuming that base cases have already been handled.AnalysisState<A>
narrowingAux(AnalysisState<A> other)
Performs the narrowing operation between this lattice element and the given one, assuming that base cases have already been handled.AnalysisState<A>
popScope(ScopeToken scope)
Pops the scope identified by the given token from this object.AnalysisState<A>
pushScope(ScopeToken scope)
Pushes a new scope, identified by the give token, in this object.StructuredRepresentation
representation()
Yields aStructuredRepresentation
of the information contained in this object's instance.StructuredRepresentation
representationWithInfo()
Variant ofrepresentation()
that also includesgetFixpointInformation()
.Satisfiability
satisfies(SymbolicExpression expression, ProgramPoint pp)
Checks if the given expression is satisfied by the abstract values of this state, returning an instance ofSatisfiability
.AnalysisState<A>
smallStepSemantics(SymbolicExpression expression, ProgramPoint pp)
Yields a copy of this state, that has been modified accordingly to the semantics of the givenexpression
.AnalysisState<A>
storeInfo(java.lang.String key, Lattice<?> info)
Yields a copy of this state where the additional fixpoint information (getFixpointInformation()
) has been updated by mapping the given key toinfo
.AnalysisState<A>
top()
Yields the top element of this lattice.java.lang.String
toString()
AnalysisState<A>
weakStoreInfo(java.lang.String key, Lattice<?> info)
Yields a copy of this state where the additional fixpoint information (getFixpointInformation()
) has been updated by mapping the given key toinfo
.AnalysisState<A>
wideningAux(AnalysisState<A> other)
Performs the widening operation between this lattice element and the given one, assuming that base cases have already been handled.AnalysisState<A>
withTopMemory()
Yields a copy of this state, but with theAbstractState
's inner memory abstraction set to top.AnalysisState<A>
withTopTypes()
Yields a copy of this state, but with theAbstractState
's inner type abstraction set to top.AnalysisState<A>
withTopValues()
Yields a copy of this state, but with theAbstractState
's inner value abstraction set to top.-
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
-
AnalysisState
public AnalysisState(A state, SymbolicExpression computedExpression)
Builds a new state.- Parameters:
state
- theAbstractState
to embed in this analysis statecomputedExpression
- the expression that has been computed
-
AnalysisState
public AnalysisState(A state, ExpressionSet computedExpressions)
Builds a new state.- Parameters:
state
- theAbstractState
to embed in this analysis statecomputedExpressions
- the expressions that have been computed
-
AnalysisState
public AnalysisState(A state, SymbolicExpression computedExpression, FixpointInfo info)
Builds a new state.- Parameters:
state
- theAbstractState
to embed in this analysis statecomputedExpression
- the expression that has been computedinfo
- the additional information to be computed during fixpoint computations
-
AnalysisState
public AnalysisState(A state, ExpressionSet computedExpressions, FixpointInfo info)
Builds a new state.- Parameters:
state
- theAbstractState
to embed in this analysis statecomputedExpressions
- the expressions that have been computedinfo
- the additional information to be computed during fixpoint computations
-
-
Method Detail
-
getState
public A getState()
Yields theAbstractState
embedded into this analysis state, containing abstract values for program variables and memory locations.- Returns:
- the abstract state
-
getFixpointInformation
public FixpointInfo getFixpointInformation()
Yields the additional information that must be computed during fixpoint computations. This is a generic key-value mapping that users of the library can use for ad-hoc purposes.- Returns:
- the additional information (can be
null
)
-
getInfo
public Lattice<?> getInfo(java.lang.String key)
Yields the Additional information associated to the given key, as defined in this instance'sgetFixpointInformation()
.- Parameters:
key
- the key- Returns:
- the mapped information
-
getInfo
public <T> T getInfo(java.lang.String key, java.lang.Class<T> type)
Yields the additional information associated to the given key, casted to the given type, as defined in this instance'sgetFixpointInformation()
.- Type Parameters:
T
- the type to cast the return value of this method to- Parameters:
key
- the keytype
- the type to cast the retrieved information to- Returns:
- the mapped information
-
storeInfo
public AnalysisState<A> storeInfo(java.lang.String key, Lattice<?> info)
Yields a copy of this state where the additional fixpoint information (getFixpointInformation()
) has been updated by mapping the given key toinfo
. This is a strong update, meaning that the information previously mapped to the same key, if any, is lost. For a weak update, useweakStoreInfo(String, Lattice)
.- Parameters:
key
- the keyinfo
- the information to store- Returns:
- a new instance with the updated mapping
-
weakStoreInfo
public AnalysisState<A> weakStoreInfo(java.lang.String key, Lattice<?> info) throws SemanticException
Yields a copy of this state where the additional fixpoint information (getFixpointInformation()
) has been updated by mapping the given key toinfo
. This is a weak update, meaning that the information previously mapped to the same key, if any, is lubbed together with the given one, and the result is stored inside the mapping instead. For a strong update, usestoreInfo(String, Lattice)
.- Parameters:
key
- the keyinfo
- the information to store- Returns:
- a new instance with the updated mapping
- Throws:
SemanticException
- if something goes wrong during the lub
-
getComputedExpressions
public ExpressionSet getComputedExpressions()
Yields the last computed expression. This is an instance ofSymbolicExpression
that will contain markers for all abstract values that would be present on the stack, as well as variable identifiers for values that should be read from the state. These are tied together in a form of expression that abstract domains are able to interpret. The collection returned by this method usually contains one expression, but instances created through lattice operations (e.g., lub) might contain more.- Returns:
- the last computed expression
-
assign
public AnalysisState<A> assign(Identifier id, SymbolicExpression value, ProgramPoint pp) throws SemanticException
Yields a copy of this state, whereid
has been assigned tovalue
.- Parameters:
id
- the identifier to assign the value tovalue
- 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
-
assign
public AnalysisState<A> assign(SymbolicExpression id, SymbolicExpression expression, ProgramPoint pp) throws SemanticException
Yields a copy of this analysis state, where the symbolic expressionid
has been assigned tovalue
: ifid
is not anIdentifier
, then it is rewritten before performing the assignment.- Parameters:
id
- the symbolic expression to be assignedexpression
- the expression to assignpp
- the program point that where this operation is being evaluated- Returns:
- a copy of this analysis state, modified by the assignment
- Throws:
SemanticException
- if an error occurs during the computation
-
smallStepSemantics
public AnalysisState<A> smallStepSemantics(SymbolicExpression expression, ProgramPoint pp) throws SemanticException
Yields a copy of this state, that has been modified accordingly to the semantics of the givenexpression
.- 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
-
assume
public AnalysisState<A> assume(SymbolicExpression expression, ProgramPoint src, ProgramPoint dest) throws SemanticException
Yields a copy of this state, 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
.- Parameters:
expression
- the expression to assume to hold.src
- the program point that where this operation is being evaluated, corresponding to the one that generated the given expressiondest
- the program point where the execution will move after the expression has been assumed- Returns:
- the (optionally) modified copy of this domain
- Throws:
SemanticException
- if an error occurs during the computation
-
satisfies
public Satisfiability satisfies(SymbolicExpression expression, ProgramPoint pp) throws SemanticException
Checks if the given expression is satisfied by the abstract values of this state, returning an instance ofSatisfiability
.- Parameters:
expression
- the expression whose satisfiability is to be evaluatedpp
- the program point that where this operation is being evaluated- Returns:
Satisfiability.SATISFIED
is the expression is satisfied by the values of this domain,Satisfiability.NOT_SATISFIED
if it is not satisfied, orSatisfiability.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 AnalysisState<A> pushScope(ScopeToken scope) throws SemanticException
Description copied from interface:ScopedObject
Pushes a new scope, identified by the give token, in this object. This causes 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 withScopedObject.popScope(ScopeToken)
.- Specified by:
pushScope
in interfaceScopedObject<A extends AbstractState<A>>
- Parameters:
scope
- the token identifying the scope to push- Returns:
- a copy of this object where the local unscoped variables have been hidden
- Throws:
SemanticException
- if an error occurs during the computation
-
popScope
public AnalysisState<A> popScope(ScopeToken scope) throws SemanticException
Description copied from interface:ScopedObject
Pops the scope identified by the given token from this object. This causes all the visible variables (i.e. that are not mapped to a scope) to be removed, while the local variables that were associated to the given scope token (and thus hidden) will become visible again.- Specified by:
popScope
in interfaceScopedObject<A extends AbstractState<A>>
- Parameters:
scope
- the token of the scope to be restored- Returns:
- a copy of this object 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
-
lubAux
public AnalysisState<A> lubAux(AnalysisState<A> 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<A extends AbstractState<A>>
- 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 AnalysisState<A> glbAux(AnalysisState<A> 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<A extends AbstractState<A>>
- 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 AnalysisState<A> wideningAux(AnalysisState<A> 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<A extends AbstractState<A>>
- Parameters:
other
- the other lattice element- Returns:
- the widening between this and other
- Throws:
SemanticException
- if an error occurs during the computation
-
narrowingAux
public AnalysisState<A> narrowingAux(AnalysisState<A> 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<A extends AbstractState<A>>
- Parameters:
other
- the other lattice element- Returns:
- the narrowing between this and other
- Throws:
SemanticException
- if an error occurs during the computation
-
lessOrEqualAux
public boolean lessOrEqualAux(AnalysisState<A> 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<A extends AbstractState<A>>
- Parameters:
other
- the other lattice element- Returns:
true
if and only if that condition holds- Throws:
SemanticException
- if an error occurs during the computation
-
top
public AnalysisState<A> 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<A extends AbstractState<A>>
- Returns:
- the top element
-
bottom
public AnalysisState<A> 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<A extends AbstractState<A>>
- Returns:
- the bottom element
-
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.- Specified by:
isTop
in interfaceLattice<A extends AbstractState<A>>
- Returns:
true
if this is the top of the lattice
-
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.- Specified by:
isBottom
in interfaceLattice<A extends AbstractState<A>>
- Returns:
true
if this is the bottom of the lattice
-
forgetIdentifier
public AnalysisState<A> forgetIdentifier(Identifier id) throws SemanticException
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.- Parameters:
id
- the identifier to forget- Returns:
- the analysis state without information about the given id
- Throws:
SemanticException
- if an error occurs during the computation
-
forgetIdentifiersIf
public AnalysisState<A> forgetIdentifiersIf(java.util.function.Predicate<Identifier> test) throws SemanticException
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.- Parameters:
test
- the test to identify the targets of the removal- Returns:
- the analysis state in without information about the ids
- Throws:
SemanticException
- if an error occurs during the computation
-
forgetIdentifiers
public AnalysisState<A> forgetIdentifiers(java.lang.Iterable<Identifier> ids) throws SemanticException
Forgets all the givenIdentifier
s by invokingforgetIdentifier(Identifier)
on each given identifier.- Parameters:
ids
- the collection of identifiers to forget- Returns:
- the analysis state without information about the given ids
- Throws:
SemanticException
- if an error occurs during the computation
-
hashCode
public int hashCode()
- Specified by:
hashCode
in interfaceBaseLattice<A extends AbstractState<A>>
- Overrides:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Specified by:
equals
in interfaceBaseLattice<A extends AbstractState<A>>
- Overrides:
equals
in classjava.lang.Object
-
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
-
representationWithInfo
public StructuredRepresentation representationWithInfo()
Variant ofrepresentation()
that also includesgetFixpointInformation()
.- Returns:
- the enriched representation
-
toString
public java.lang.String toString()
- Specified by:
toString
in interfaceBaseLattice<A extends AbstractState<A>>
- Overrides:
toString
in classjava.lang.Object
-
withTopMemory
public AnalysisState<A> withTopMemory()
Yields a copy of this state, but with theAbstractState
's inner memory abstraction set to top. This is useful to represent effects of unknown calls that arbitrarily manipulate the memory.- Returns:
- the copy with top memory
-
withTopValues
public AnalysisState<A> withTopValues()
Yields a copy of this state, but with theAbstractState
's inner value abstraction set to top. This is useful to represent effects of unknown calls that arbitrarily manipulate the values of variables.- Returns:
- the copy with top value
-
withTopTypes
public AnalysisState<A> withTopTypes()
Yields a copy of this state, but with theAbstractState
's inner type abstraction set to top. This is useful to represent effects of unknown calls that arbitrarily manipulate the values of variables (and their type accordingly).- Returns:
- the copy with top type
-
-