Package it.unive.lisa.analysis
Class SimpleAbstractState<H extends HeapDomain<H>,V extends ValueDomain<V>,T extends TypeDomain<T>>
- java.lang.Object
-
- it.unive.lisa.analysis.BaseLattice<SimpleAbstractState<H,V,T>>
-
- it.unive.lisa.analysis.SimpleAbstractState<H,V,T>
-
- Type Parameters:
H
- the type ofHeapDomain
embedded in this stateV
- the type ofValueDomain
embedded in this stateT
- the type ofTypeDomain
embedded in this state
- All Implemented Interfaces:
AbstractState<SimpleAbstractState<H,V,T>,H,V,T>
,Lattice<SimpleAbstractState<H,V,T>>
,SemanticDomain<SimpleAbstractState<H,V,T>,SymbolicExpression,Identifier>
public class SimpleAbstractState<H extends HeapDomain<H>,V extends ValueDomain<V>,T extends TypeDomain<T>> extends BaseLattice<SimpleAbstractState<H,V,T>> implements AbstractState<SimpleAbstractState<H,V,T>,H,V,T>
An abstract state of the analysis, composed by a heap state modeling the memory layout and a value state modeling values of program variables and memory locations.
-
-
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.AbstractState
HEAP_REPRESENTATION_KEY, TYPE_REPRESENTATION_KEY, VALUE_REPRESENTATION_KEY
-
Fields inherited from interface it.unive.lisa.analysis.Lattice
BOTTOM_STRING, TOP_STRING
-
-
Constructor Summary
Constructors Constructor Description SimpleAbstractState(H heapState, V valueState, T typeState)
Builds a new abstract state.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description SimpleAbstractState<H,V,T>
assign(Identifier id, SymbolicExpression expression, ProgramPoint pp)
Yields a copy of this domain, whereid
has been assigned tovalue
.SimpleAbstractState<H,V,T>
assume(SymbolicExpression expression, ProgramPoint pp)
Yields a copy of this domain, modified by assuming that the given expression holds.SimpleAbstractState<H,V,T>
bottom()
Yields the bottom element of this lattice.boolean
equals(java.lang.Object obj)
SimpleAbstractState<H,V,T>
forgetIdentifier(Identifier id)
Forgets anIdentifier
.SimpleAbstractState<H,V,T>
forgetIdentifiersIf(java.util.function.Predicate<Identifier> test)
Forgets allIdentifier
s that match the given predicate.<D> D
getDomainInstance(java.lang.Class<D> domain)
Yields the instance of a specific domain, of classdomain
, contained inside the domain.H
getHeapState()
Yields the instance ofHeapDomain
that contains the information on heap structures contained in this abstract state.T
getTypeState()
Yields the instance ofValueDomain
andTypeDomain
that contains the information on runtime types of program variables and concretized memory locations.V
getValueState()
Yields the instance ofValueDomain
that contains the information on values of program variables and concretized 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(SimpleAbstractState<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.SimpleAbstractState<H,V,T>
lubAux(SimpleAbstractState<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.SimpleAbstractState<H,V,T>
popScope(ScopeToken scope)
Pops the scope identified by the given token from the domain.SimpleAbstractState<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
.SimpleAbstractState<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
.SimpleAbstractState<H,V,T>
top()
Yields the top element of this lattice.java.lang.String
toString()
SimpleAbstractState<H,V,T>
wideningAux(SimpleAbstractState<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.Lattice
lessOrEqual, lub, widening
-
Methods inherited from interface it.unive.lisa.analysis.SemanticDomain
forgetIdentifiers
-
-
-
-
Constructor Detail
-
SimpleAbstractState
public SimpleAbstractState(H heapState, V valueState, T typeState)
Builds a new abstract state.- Parameters:
heapState
- the domain containing information regarding heap structuresvalueState
- the domain containing information regarding values of program variables and concretized memory locationstypeState
- the domain containing information regarding runtime types of program variables and concretized memory locations
-
-
Method Detail
-
getHeapState
public H getHeapState()
Description copied from interface:AbstractState
Yields the instance ofHeapDomain
that contains the information on heap structures contained in this abstract state.- Specified by:
getHeapState
in interfaceAbstractState<SimpleAbstractState<H extends HeapDomain<H>,V extends ValueDomain<V>,T extends TypeDomain<T>>,H extends HeapDomain<H>,V extends ValueDomain<V>,T extends TypeDomain<T>>
- Returns:
- the heap domain
-
getValueState
public V getValueState()
Description copied from interface:AbstractState
Yields the instance ofValueDomain
that contains the information on values of program variables and concretized memory locations.- Specified by:
getValueState
in interfaceAbstractState<SimpleAbstractState<H extends HeapDomain<H>,V extends ValueDomain<V>,T extends TypeDomain<T>>,H extends HeapDomain<H>,V extends ValueDomain<V>,T extends TypeDomain<T>>
- Returns:
- the value domain
-
getTypeState
public T getTypeState()
Description copied from interface:AbstractState
Yields the instance ofValueDomain
andTypeDomain
that contains the information on runtime types of program variables and concretized memory locations.- Specified by:
getTypeState
in interfaceAbstractState<SimpleAbstractState<H extends HeapDomain<H>,V extends ValueDomain<V>,T extends TypeDomain<T>>,H extends HeapDomain<H>,V extends ValueDomain<V>,T extends TypeDomain<T>>
- Returns:
- the type domain
-
assign
public SimpleAbstractState<H,V,T> assign(Identifier id, SymbolicExpression 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<H extends HeapDomain<H>,V extends ValueDomain<V>,T extends TypeDomain<T>>
- 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
-
smallStepSemantics
public SimpleAbstractState<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<H extends HeapDomain<H>,V extends ValueDomain<V>,T extends TypeDomain<T>>
- 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 SimpleAbstractState<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<H extends HeapDomain<H>,V extends ValueDomain<V>,T extends TypeDomain<T>>
- 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<H extends HeapDomain<H>,V extends ValueDomain<V>,T extends TypeDomain<T>>
- 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 SimpleAbstractState<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<H extends HeapDomain<H>,V extends ValueDomain<V>,T extends TypeDomain<T>>
- 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 SimpleAbstractState<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<H extends HeapDomain<H>,V extends ValueDomain<V>,T extends TypeDomain<T>>
- 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 SimpleAbstractState<H,V,T> lubAux(SimpleAbstractState<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<SimpleAbstractState<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 SimpleAbstractState<H,V,T> wideningAux(SimpleAbstractState<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<SimpleAbstractState<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(SimpleAbstractState<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<SimpleAbstractState<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 SimpleAbstractState<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.- Specified by:
top
in interfaceLattice<H extends HeapDomain<H>>
- Returns:
- the top element
-
bottom
public SimpleAbstractState<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.- Specified by:
bottom
in interfaceLattice<H extends HeapDomain<H>>
- 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<H extends HeapDomain<H>>
- 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<H extends HeapDomain<H>>
- Returns:
true
if this is the bottom of the lattice
-
forgetIdentifier
public SimpleAbstractState<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<H extends HeapDomain<H>,V extends ValueDomain<V>,T extends TypeDomain<T>>
- 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 SimpleAbstractState<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<H extends HeapDomain<H>,V extends ValueDomain<V>,T extends TypeDomain<T>>
- 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<SimpleAbstractState<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<SimpleAbstractState<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<H extends HeapDomain<H>,V extends ValueDomain<V>,T extends TypeDomain<T>>
- Returns:
- the representation
-
toString
public java.lang.String toString()
- Specified by:
toString
in classBaseLattice<SimpleAbstractState<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<H extends HeapDomain<H>,V extends ValueDomain<V>,T extends TypeDomain<T>>
- 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
-
-