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 ofInferredValuein 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 anEnvironmentthat work onInferredValues, 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.booleanequals(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.TgetExecutionState()Yields the execution state (also called program counter), that might change when evaluating an expression.TgetInferredValue()Yields the inferred value of the lastSymbolicExpressionhandled 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.inthashCode()booleanisBottom()Yieldstrueif and only if this object represents the bottom of the lattice.booleanisTop()Yieldstrueif and only if this object represents the top of the lattice.booleanlessOrEqualAux(InferenceSystem<T> other)Yieldstrueif 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.DomainRepresentationrepresentation()Yields aDomainRepresentationof 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, 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
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 benullinferred- 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:FunctionalLatticeBuilds a instance of this class from the given lattice instance and the given mapping.- Specified by:
mkin 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 lastSymbolicExpressionhandled by this domain, either throughEnvironment.assign(Identifier, SymbolicExpression, ProgramPoint)orsmallStepSemantics(ValueExpression, ProgramPoint).- Returns:
- the value inferred for the last expression
-
eval
public org.apache.commons.lang3.tuple.Pair<T,InferredValue.InferredPair<T>> eval(ValueExpression expression, ProgramPoint pp) throws SemanticException
Description copied from class:EnvironmentYields 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 resultis the true result of the evaluation, whileabstract elementis the element derived by the result that is to be stored inside the environment mapped to an identifier.- Specified by:
evalin 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:EnvironmentAuxiliary function ofEnvironment.assign(Identifier, SymbolicExpression, ProgramPoint)that is invoked after the evaluation of the expression.- Specified by:
assignAuxin 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 theidhas been assigned toevalvalue- the final value stored forid, after considering applyingNonRelationalElement.variable(Identifier, ProgramPoint)andIdentifier.isWeak()eval- the abstract value that is the result of the evaluation ofvaluepp- the program point that where this operation is being evaluated- Returns:
- a new instance of this environment containing the given function,
obtained by assigning
idtoeval
-
smallStepSemantics
public InferenceSystem<T> smallStepSemantics(ValueExpression expression, ProgramPoint pp) throws SemanticException
Description copied from interface:SemanticDomainYields a copy of this domain, that has been modified accordingly to the semantics of the givenexpression.- Specified by:
smallStepSemanticsin 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:LatticeYields 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:
topin interfaceLattice<T extends InferredValue<T>>- Returns:
- the top element
-
bottom
public InferenceSystem<T> bottom()
Description copied from interface:LatticeYields 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:
bottomin interfaceLattice<T extends InferredValue<T>>- Returns:
- the bottom element
-
isTop
public boolean isTop()
Description copied from class:FunctionalLatticeYieldstrueif and only if this object represents the top of the lattice. The default implementation of this method uses reference equality betweenthisand 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.
By default, a functional lattice is the top lattice if the underlying lattice'sisTop()holds and its function isnull.- Specified by:
isTopin interfaceLattice<T extends InferredValue<T>>- Overrides:
isTopin classFunctionalLattice<InferenceSystem<T extends InferredValue<T>>,Identifier,T extends InferredValue<T>>- Returns:
trueif this is the top of the lattice
-
isBottom
public boolean isBottom()
Description copied from class:FunctionalLatticeYieldstrueif and only if this object represents the bottom of the lattice. The default implementation of this method uses reference equality betweenthisand 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.
By default, a functional lattice is the top lattice if the underlying lattice'sisBottom()holds and its function isnull.- Specified by:
isBottomin interfaceLattice<T extends InferredValue<T>>- Overrides:
isBottomin classFunctionalLattice<InferenceSystem<T extends InferredValue<T>>,Identifier,T extends InferredValue<T>>- Returns:
trueif this is the bottom of the lattice
-
lubAux
public InferenceSystem<T> lubAux(InferenceSystem<T> other) throws SemanticException
Description copied from class:BaseLatticePerforms 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:otheris notnullotheris neither top nor bottomthisis neither top nor bottomthisandotherare not the same object (according both to==and toObject.equals(Object))
- Overrides:
lubAuxin 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:BaseLatticePerforms 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:otheris notnullotheris neither top nor bottomthisis neither top nor bottomthisandotherare 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:
wideningAuxin 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:BaseLatticeYieldstrueif 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:otheris notnullotheris neither top nor bottomthisis neither top nor bottomthisandotherare not the same object (according both to==and toObject.equals(Object))
- Overrides:
lessOrEqualAuxin classFunctionalLattice<InferenceSystem<T extends InferredValue<T>>,Identifier,T extends InferredValue<T>>- Parameters:
other- the other lattice element- Returns:
trueif 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:EnvironmentAssumes 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:
assumeSatisfiedin 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:EnvironmentAuxiliary 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:
glbAuxin 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 benullother- the other environment- Returns:
- the final instance of the glb
-
hashCode
public int hashCode()
- Overrides:
hashCodein classFunctionalLattice<InferenceSystem<T extends InferredValue<T>>,Identifier,T extends InferredValue<T>>
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classFunctionalLattice<InferenceSystem<T extends InferredValue<T>>,Identifier,T extends InferredValue<T>>
-
representation
public DomainRepresentation representation()
Description copied from interface:SemanticDomainYields aDomainRepresentationof the information contained in this domain's instance.- Specified by:
representationin interfaceSemanticDomain<InferenceSystem<T extends InferredValue<T>>,ValueExpression,Identifier>- Overrides:
representationin classEnvironment<InferenceSystem<T extends InferredValue<T>>,ValueExpression,T extends InferredValue<T>,InferredValue.InferredPair<T extends InferredValue<T>>>- Returns:
- the representation
-
-