Class InferenceSystem<T extends InferredValue<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<InferenceSystem<T>,ValueExpression,T,InferredValue.InferredPair<T>>
-
- it.unive.lisa.analysis.nonrelational.inference.InferenceSystem<T>
-
- Type Parameters:
T
- the type ofInferredValue
in this inference system
- All Implemented Interfaces:
Lattice<InferenceSystem<T>>
,SemanticDomain<InferenceSystem<T>,ValueExpression,Identifier>
,ValueDomain<InferenceSystem<T>>
,java.lang.Iterable<java.util.Map.Entry<Identifier,T>>
public class InferenceSystem<T extends InferredValue<T>> extends Environment<InferenceSystem<T>,ValueExpression,T,InferredValue.InferredPair<T>> implements ValueDomain<InferenceSystem<T>>
An inference system that model standard derivation systems (e.g., types systems, small step semantics, big step semantics, ...). An inference system is anEnvironment
that work onInferredValue
s, and that exposes the last inferred value (getInferredValue()
) and the execution state (getExecutionState()
).
-
-
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 InferenceSystem(InferenceSystem<T> other, T state)
Builds an inference system identical to the given one, except for the execution state that will be set to the given one.InferenceSystem(T domain)
Builds an empty inference system.InferenceSystem(T domain, java.util.Map<Identifier,T> function, InferredValue.InferredPair<T> inferred)
Builds an environment containing the given mapping.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description InferenceSystem<T>
assignAux(Identifier id, ValueExpression expression, java.util.Map<Identifier,T> function, T value, InferredValue.InferredPair<T> eval, ProgramPoint pp)
Auxiliary function ofEnvironment.assign(Identifier, SymbolicExpression, ProgramPoint)
that is invoked after the evaluation of the expression.InferenceSystem<T>
assumeSatisfied(InferredValue.InferredPair<T> eval)
Assumes that an expression, that evaluated toeval
, is always satisfied by this environment.InferenceSystem<T>
bottom()
Yields the bottom element of this lattice.InferenceSystem<T>
copy()
Copies this environment.boolean
equals(java.lang.Object obj)
org.apache.commons.lang3.tuple.Pair<T,InferredValue.InferredPair<T>>
eval(ValueExpression expression, ProgramPoint pp)
Yields the evaluation of the given expression, happening at the given program point.T
getExecutionState()
Yields the execution state (also called program counter), that might change when evaluating an expression.T
getInferredValue()
Yields the inferred value of the lastSymbolicExpression
handled by this domain, either throughEnvironment.assign(Identifier, SymbolicExpression, ProgramPoint)
orsmallStepSemantics(ValueExpression, ProgramPoint)
.InferenceSystem<T>
glbAux(T lattice, java.util.Map<Identifier,T> function, InferenceSystem<T> other)
Auxiliary glb operation, invoked after the result has been computed to create the concrete instance of environment.int
hashCode()
boolean
lessOrEqualAux(InferenceSystem<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.InferenceSystem<T>
lubAux(InferenceSystem<T> other)
Performs the least upper bound operation between this lattice element and the given one, assuming that base cases have already been handled.InferenceSystem<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.DomainRepresentation
representation()
Yields aDomainRepresentation
of the information contained in this domain's instance.InferenceSystem<T>
smallStepSemantics(ValueExpression expression, ProgramPoint pp)
Yields a copy of this domain, that has been modified accordingly to the semantics of the givenexpression
.InferenceSystem<T>
top()
Yields the top element of this lattice.InferenceSystem<T>
wideningAux(InferenceSystem<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, 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.Lattice
isBottom, isTop, lessOrEqual, lub, widening
-
Methods inherited from interface it.unive.lisa.analysis.SemanticDomain
assign, assume, forgetIdentifier, forgetIdentifiers, forgetIdentifiersIf, getDomainInstance, popScope, pushScope, satisfies
-
Methods inherited from interface it.unive.lisa.analysis.value.ValueDomain
applySubstitution
-
-
-
-
Constructor Detail
-
InferenceSystem
public InferenceSystem(T domain)
Builds an empty inference system.- Parameters:
domain
- a singleton instance to be used during semantic operations to retrieve top and bottom values
-
InferenceSystem
public InferenceSystem(InferenceSystem<T> other, T state)
Builds an inference system identical to the given one, except for the execution state that will be set to the given one.- Parameters:
other
- the inference system to copystate
- the new execution state
-
InferenceSystem
public InferenceSystem(T domain, java.util.Map<Identifier,T> function, InferredValue.InferredPair<T> inferred)
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
inferred
- the inferred pair for the last computed expression, that is left on the top of the stack
-
-
Method Detail
-
mk
public InferenceSystem<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<InferenceSystem<T extends InferredValue<T>>,Identifier,T extends InferredValue<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
-
getExecutionState
public T getExecutionState()
Yields the execution state (also called program counter), that might change when evaluating an expression.- Returns:
- the execution state
-
getInferredValue
public T getInferredValue()
Yields the inferred value of the lastSymbolicExpression
handled by this domain, either throughEnvironment.assign(Identifier, SymbolicExpression, ProgramPoint)
orsmallStepSemantics(ValueExpression, ProgramPoint)
.- Returns:
- the value inferred for the last expression
-
copy
public InferenceSystem<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<InferenceSystem<T extends InferredValue<T>>,ValueExpression,T extends InferredValue<T>,InferredValue.InferredPair<T extends InferredValue<T>>>
- Returns:
- a copy of the given environment
-
eval
public org.apache.commons.lang3.tuple.Pair<T,InferredValue.InferredPair<T>> eval(ValueExpression 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<InferenceSystem<T extends InferredValue<T>>,ValueExpression,T extends InferredValue<T>,InferredValue.InferredPair<T extends InferredValue<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 InferenceSystem<T> assignAux(Identifier id, ValueExpression expression, java.util.Map<Identifier,T> function, T value, InferredValue.InferredPair<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<InferenceSystem<T extends InferredValue<T>>,ValueExpression,T extends InferredValue<T>,InferredValue.InferredPair<T extends InferredValue<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
-
smallStepSemantics
public InferenceSystem<T> smallStepSemantics(ValueExpression 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<InferenceSystem<T extends InferredValue<T>>,ValueExpression,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 InferenceSystem<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 InferredValue<T>>
- Returns:
- the top element
-
bottom
public InferenceSystem<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 InferredValue<T>>
- Returns:
- the bottom element
-
lubAux
public InferenceSystem<T> lubAux(InferenceSystem<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<InferenceSystem<T extends InferredValue<T>>,Identifier,T extends InferredValue<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 InferenceSystem<T> wideningAux(InferenceSystem<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<InferenceSystem<T extends InferredValue<T>>,Identifier,T extends InferredValue<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(InferenceSystem<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<InferenceSystem<T extends InferredValue<T>>,Identifier,T extends InferredValue<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
-
assumeSatisfied
public InferenceSystem<T> assumeSatisfied(InferredValue.InferredPair<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<InferenceSystem<T extends InferredValue<T>>,ValueExpression,T extends InferredValue<T>,InferredValue.InferredPair<T extends InferredValue<T>>>
- Parameters:
eval
- the result of the evaluation of the expression that is always satisfied- Returns:
- the (possibly) updated environment
-
glbAux
public InferenceSystem<T> glbAux(T lattice, java.util.Map<Identifier,T> function, InferenceSystem<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<InferenceSystem<T extends InferredValue<T>>,ValueExpression,T extends InferredValue<T>,InferredValue.InferredPair<T extends InferredValue<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
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classFunctionalLattice<InferenceSystem<T extends InferredValue<T>>,Identifier,T extends InferredValue<T>>
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classFunctionalLattice<InferenceSystem<T extends InferredValue<T>>,Identifier,T extends InferredValue<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<InferenceSystem<T extends InferredValue<T>>,ValueExpression,Identifier>
- Overrides:
representation
in classEnvironment<InferenceSystem<T extends InferredValue<T>>,ValueExpression,T extends InferredValue<T>,InferredValue.InferredPair<T extends InferredValue<T>>>
- Returns:
- the representation
-
-