Package it.unive.lisa.analysis
Class AnalysisState<A extends AbstractState<A,H,V,T>,H extends HeapDomain<H>,V extends ValueDomain<V>,T extends TypeDomain<T>>
- java.lang.Object
-
- it.unive.lisa.analysis.BaseLattice<AnalysisState<A,H,V,T>>
-
- it.unive.lisa.analysis.AnalysisState<A,H,V,T>
-
- Type Parameters:
A
- the type ofAbstractState
embedded in this stateH
- the type ofHeapDomain
embedded in the abstract stateV
- the type ofValueDomain
embedded in the abstract stateT
- the type ofTypeDomain
embedded in the abstract state
- All Implemented Interfaces:
Lattice<AnalysisState<A,H,V,T>>
,SemanticDomain<AnalysisState<A,H,V,T>,SymbolicExpression,Identifier>
public class AnalysisState<A extends AbstractState<A,H,V,T>,H extends HeapDomain<H>,V extends ValueDomain<V>,T extends TypeDomain<T>> extends BaseLattice<AnalysisState<A,H,V,T>> implements SemanticDomain<AnalysisState<A,H,V,T>,SymbolicExpression,Identifier>
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).
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface it.unive.lisa.analysis.SemanticDomain
SemanticDomain.Satisfiability
-
-
Field Summary
-
Fields inherited from interface it.unive.lisa.analysis.Lattice
BOTTOM_STRING, TOP_STRING
-
-
Constructor Summary
Constructors Constructor Description AnalysisState(A state, ExpressionSet<SymbolicExpression> computedExpressions, SymbolAliasing aliasing)
Builds a new state.AnalysisState(A state, SymbolicExpression computedExpression, SymbolAliasing aliasing)
Builds a new state.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description AnalysisState<A,H,V,T>
alias(Symbol toAlias, Symbol alias)
Registers an alias for the given symbol.AnalysisState<A,H,V,T>
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,H,V,T>
assign(Identifier id, SymbolicExpression value, ProgramPoint pp)
Yields a copy of this domain, whereid
has been assigned tovalue
.AnalysisState<A,H,V,T>
assume(SymbolicExpression expression, ProgramPoint pp)
Yields a copy of this domain, modified by assuming that the given expression holds.AnalysisState<A,H,V,T>
bottom()
Yields the bottom element of this lattice.boolean
equals(java.lang.Object obj)
AnalysisState<A,H,V,T>
forgetIdentifier(Identifier id)
Forgets anIdentifier
.AnalysisState<A,H,V,T>
forgetIdentifiersIf(java.util.function.Predicate<Identifier> test)
Forgets allIdentifier
s that match the given predicate.SymbolAliasing
getAliasing()
Yields the symbol aliasing information, that can be used to resolve targets of calls when the names used in the call are different from the ones in the target's signature.ExpressionSet<SymbolicExpression>
getComputedExpressions()
Yields the last computed expression.<D> D
getDomainInstance(java.lang.Class<D> domain)
Yields the instance of a specific domain, of classdomain
, contained inside the domain.A
getState()
Yields theAbstractState
embedded into this analysis state, containing abstract values for program variables and memory locations.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,H,V,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.AnalysisState<A,H,V,T>
lubAux(AnalysisState<A,H,V,T> 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,H,V,T>
popScope(ScopeToken scope)
Pops the scope identified by the given token from the domain.AnalysisState<A,H,V,T>
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(SymbolicExpression expression, ProgramPoint pp)
Checks if the given expression is satisfied by the abstract values of this domain, returning an instance ofSemanticDomain.Satisfiability
.AnalysisState<A,H,V,T>
smallStepSemantics(SymbolicExpression expression, ProgramPoint pp)
Yields a copy of this domain, that has been modified accordingly to the semantics of the givenexpression
.AnalysisState<A,H,V,T>
top()
Yields the top element of this lattice.java.lang.String
toString()
AnalysisState<A,H,V,T>
wideningAux(AnalysisState<A,H,V,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.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
-
-
-
-
Constructor Detail
-
AnalysisState
public AnalysisState(A state, SymbolicExpression computedExpression, SymbolAliasing aliasing)
Builds a new state.- Parameters:
state
- theAbstractState
to embed in this analysis statecomputedExpression
- the expression that has been computedaliasing
- the symbol aliasing information
-
AnalysisState
public AnalysisState(A state, ExpressionSet<SymbolicExpression> computedExpressions, SymbolAliasing aliasing)
Builds a new state.- Parameters:
state
- theAbstractState
to embed in this analysis statecomputedExpressions
- the expressions that have been computedaliasing
- the symbol aliasing information
-
-
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
-
getAliasing
public SymbolAliasing getAliasing()
Yields the symbol aliasing information, that can be used to resolve targets of calls when the names used in the call are different from the ones in the target's signature.- Returns:
- the aliasing information
-
getComputedExpressions
public ExpressionSet<SymbolicExpression> 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
-
alias
public AnalysisState<A,H,V,T> alias(Symbol toAlias, Symbol alias)
Registers an alias for the given symbol. Any previous aliases will be deleted.- Parameters:
toAlias
- the symbol being aliasedalias
- the alias fortoAlias
- Returns:
- a copy of this analysis state, with the new alias
-
assign
public AnalysisState<A,H,V,T> assign(Identifier id, SymbolicExpression value, 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<A extends AbstractState<A,H,V,T>,H extends HeapDomain<H>,V extends ValueDomain<V>>
- 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,H,V,T> 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,H,V,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<A extends AbstractState<A,H,V,T>,H extends HeapDomain<H>,V extends ValueDomain<V>>
- 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,H,V,T> assume(SymbolicExpression 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<A extends AbstractState<A,H,V,T>,H extends HeapDomain<H>,V extends ValueDomain<V>>
- 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
-
satisfies
public SemanticDomain.Satisfiability satisfies(SymbolicExpression 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<A extends AbstractState<A,H,V,T>,H extends HeapDomain<H>,V extends ValueDomain<V>>
- 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 AnalysisState<A,H,V,T> 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<A extends AbstractState<A,H,V,T>,H extends HeapDomain<H>,V extends ValueDomain<V>>
- 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 AnalysisState<A,H,V,T> 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<A extends AbstractState<A,H,V,T>,H extends HeapDomain<H>,V extends ValueDomain<V>>
- 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
-
lubAux
public AnalysisState<A,H,V,T> lubAux(AnalysisState<A,H,V,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)
)
- Specified by:
lubAux
in classBaseLattice<AnalysisState<A extends AbstractState<A,H,V,T>,H extends HeapDomain<H>,V extends ValueDomain<V>,T extends TypeDomain<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 AnalysisState<A,H,V,T> wideningAux(AnalysisState<A,H,V,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 classBaseLattice<AnalysisState<A extends AbstractState<A,H,V,T>,H extends HeapDomain<H>,V extends ValueDomain<V>,T extends TypeDomain<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(AnalysisState<A,H,V,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)
)
- Specified by:
lessOrEqualAux
in classBaseLattice<AnalysisState<A extends AbstractState<A,H,V,T>,H extends HeapDomain<H>,V extends ValueDomain<V>,T extends TypeDomain<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
-
top
public AnalysisState<A,H,V,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.
-
bottom
public AnalysisState<A,H,V,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.
-
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.
-
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.
-
forgetIdentifier
public AnalysisState<A,H,V,T> 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<A extends AbstractState<A,H,V,T>,H extends HeapDomain<H>,V extends ValueDomain<V>>
- 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 AnalysisState<A,H,V,T> 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<A extends AbstractState<A,H,V,T>,H extends HeapDomain<H>,V extends ValueDomain<V>>
- 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
-
hashCode
public int hashCode()
- Specified by:
hashCode
in classBaseLattice<AnalysisState<A extends AbstractState<A,H,V,T>,H extends HeapDomain<H>,V extends ValueDomain<V>,T extends TypeDomain<T>>>
-
equals
public boolean equals(java.lang.Object obj)
- Specified by:
equals
in classBaseLattice<AnalysisState<A extends AbstractState<A,H,V,T>,H extends HeapDomain<H>,V extends ValueDomain<V>,T extends TypeDomain<T>>>
-
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<A extends AbstractState<A,H,V,T>,H extends HeapDomain<H>,V extends ValueDomain<V>>
- Returns:
- the representation
-
toString
public java.lang.String toString()
- Specified by:
toString
in classBaseLattice<AnalysisState<A extends AbstractState<A,H,V,T>,H extends HeapDomain<H>,V extends ValueDomain<V>,T extends TypeDomain<T>>>
-
getDomainInstance
public <D> D getDomainInstance(java.lang.Class<D> domain)
Description copied from interface:SemanticDomain
Yields the instance of a specific domain, of classdomain
, contained inside the domain. If this domain is an instance of the specified class, thenthis
is returned. Otherwise, inner domains are recursively checked (enabling retrieval of semantic domains through Cartesian products or other types of combinations), returning the first that is instance ofdomain
.
The default implementation of this method returnsthis
ifdomain.isAssignableFrom(getClass()) == true
, otherwise it returnsnull
.- Specified by:
getDomainInstance
in interfaceSemanticDomain<A extends AbstractState<A,H,V,T>,H extends HeapDomain<H>,V extends ValueDomain<V>>
- Type Parameters:
D
- the type of domain to retrieve- Parameters:
domain
- the class of the domain instance to retrieve- Returns:
- the instance of that domain, or
null
-
-