Class BaseInferredValue<T extends BaseInferredValue<T>>
- java.lang.Object
-
- it.unive.lisa.analysis.BaseLattice<T>
-
- it.unive.lisa.analysis.nonrelational.inference.BaseInferredValue<T>
-
- Type Parameters:
T
- the concrete type of this domain
- All Implemented Interfaces:
Lattice<T>
,InferredValue<T>
,NonRelationalElement<T,ValueExpression,InferenceSystem<T>>
,SemanticEvaluator
public abstract class BaseInferredValue<T extends BaseInferredValue<T>> extends BaseLattice<T> implements InferredValue<T>
Base implementation forInferredValue
s. This class extendsBaseLattice
and implementsInferredValue.eval(ValueExpression, InferenceSystem, ProgramPoint)
by taking care of the recursive computation of inner expressions evaluation.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
BaseInferredValue.EvaluationVisitor
AExpressionVisitor
forBaseInferredValue
instances.-
Nested classes/interfaces inherited from interface it.unive.lisa.analysis.nonrelational.inference.InferredValue
InferredValue.InferredPair<T extends InferredValue<T>>
-
-
Field Summary
-
Fields inherited from interface it.unive.lisa.analysis.Lattice
BOTTOM_STRING, TOP_STRING
-
-
Constructor Summary
Constructors Constructor Description BaseInferredValue()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description InferenceSystem<T>
assume(InferenceSystem<T> environment, ValueExpression expression, ProgramPoint pp)
Yields the environmentenvironment
on which the expressionexpression
is assumed to hold by this domain.boolean
canProcess(SymbolicExpression expression)
Yieldstrue
if the domain can processexpression
,false
otherwise.InferredValue.InferredPair<T>
eval(ValueExpression expression, InferenceSystem<T> environment, ProgramPoint pp)
Evaluates aValueExpression
, assuming that the values of program variables are the ones stored inenvironment
.InferredValue.InferredPair<T>
evalBinaryExpression(BinaryOperator operator, T left, T right, T state, ProgramPoint pp)
Yields the evaluation of aBinaryExpression
applyingoperator
to two expressions whose abstract value areleft
andright
, respectively.InferredValue.InferredPair<T>
evalIdentifier(Identifier id, InferenceSystem<T> environment, ProgramPoint pp)
Yields the evaluation of an identifier in a given environment.InferredValue.InferredPair<T>
evalNonNullConstant(Constant constant, T state, ProgramPoint pp)
Yields the evaluation of the given non-null constant.InferredValue.InferredPair<T>
evalNullConstant(T state, ProgramPoint pp)
Yields the evaluation of the null constantNullConstant
.InferredValue.InferredPair<T>
evalPushAny(PushAny pushAny, T state, ProgramPoint pp)
Yields the evaluation of a push-any expression.InferredValue.InferredPair<T>
evalTernaryExpression(TernaryOperator operator, T left, T middle, T right, T state, ProgramPoint pp)
Yields the evaluation of aTernaryExpression
applyingoperator
to two expressions whose abstract value areleft
,middle
andright
, respectively.InferredValue.InferredPair<T>
evalTypeCast(BinaryExpression cast, T left, T right, T state, ProgramPoint pp)
Yields the evaluation of a type cast expression.InferredValue.InferredPair<T>
evalTypeConv(BinaryExpression conv, T left, T right, T state, ProgramPoint pp)
Yields the evaluation of a type conversion expression.InferredValue.InferredPair<T>
evalUnaryExpression(UnaryOperator operator, T arg, T state, ProgramPoint pp)
Yields the evaluation of aUnaryExpression
applyingoperator
to an expression whose abstract value isarg
.T
glb(T other)
Performs the greatest lower bound operation between this domain element andother
.T
glbAux(T other)
Performs the greatest lower bound operation between this inferred value andother
, assuming that base cases have already been handled.SemanticDomain.Satisfiability
satisfies(ValueExpression expression, InferenceSystem<T> environment, ProgramPoint pp)
Checks whetherexpression
is satisfied inenvironment
, assuming that the values of program variables are the ones stored inenvironment
and returning an instance ofSemanticDomain.Satisfiability
.SemanticDomain.Satisfiability
satisfiesAbstractValue(T value, T state, ProgramPoint pp)
Yields the satisfiability of an abstract value of type<T>
.SemanticDomain.Satisfiability
satisfiesBinaryExpression(BinaryOperator operator, T left, T right, T state, ProgramPoint pp)
Yields the satisfiability of aBinaryExpression
applyingoperator
to two expressions whose abstract values areleft
, andright
.SemanticDomain.Satisfiability
satisfiesNonNullConstant(Constant constant, T state, ProgramPoint pp)
Yields the satisfiability of the given non-null constant on this abstract domain.SemanticDomain.Satisfiability
satisfiesNullConstant(T state, ProgramPoint pp)
Yields the satisfiability of the null constantNullConstant
on this abstract domain.SemanticDomain.Satisfiability
satisfiesPushAny(PushAny pushAny, T state)
Yields the satisfiability of the push any expression.SemanticDomain.Satisfiability
satisfiesTernaryExpression(TernaryOperator operator, T left, T middle, T right, T state, ProgramPoint pp)
Yields the satisfiability of aTernaryExpression
applyingoperator
to three expressions whose abstract values areleft
,middle
andright
.SemanticDomain.Satisfiability
satisfiesUnaryExpression(UnaryOperator operator, T arg, T state, ProgramPoint pp)
Yields the satisfiability of aUnaryExpression
applyingoperator
to an expression whose abstract value isarg
, returning an instance ofSemanticDomain.Satisfiability
.java.lang.String
toString()
boolean
tracksIdentifiers(Identifier id)
Yieldstrue
if the domain tracks information on the identifierid
,false
otherwise.-
Methods inherited from class it.unive.lisa.analysis.BaseLattice
equals, hashCode, lessOrEqual, lessOrEqualAux, lub, lubAux, widening, wideningAux
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface it.unive.lisa.analysis.Lattice
bottom, isBottom, isTop, lessOrEqual, lub, top, widening
-
Methods inherited from interface it.unive.lisa.analysis.nonrelational.NonRelationalElement
representation, variable
-
-
-
-
Method Detail
-
satisfies
public SemanticDomain.Satisfiability satisfies(ValueExpression expression, InferenceSystem<T> environment, ProgramPoint pp) throws SemanticException
Description copied from interface:NonRelationalElement
Checks whetherexpression
is satisfied inenvironment
, assuming that the values of program variables are the ones stored inenvironment
and returning an instance ofSemanticDomain.Satisfiability
.- Specified by:
satisfies
in interfaceNonRelationalElement<T extends BaseInferredValue<T>,ValueExpression,InferenceSystem<T extends BaseInferredValue<T>>>
- Parameters:
expression
- the expression whose satisfiability is to be evaluatedenvironment
- the environment containing the values of program variables for the satisfiabilitypp
- the program point that where this operation is being evaluated- Returns:
SemanticDomain.Satisfiability.SATISFIED
if the expression is satisfied by the environment,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 something goes wrong during the computation
-
eval
public InferredValue.InferredPair<T> eval(ValueExpression expression, InferenceSystem<T> environment, ProgramPoint pp) throws SemanticException
Description copied from interface:InferredValue
Evaluates aValueExpression
, assuming that the values of program variables are the ones stored inenvironment
.- Specified by:
eval
in interfaceInferredValue<T extends BaseInferredValue<T>>
- Parameters:
expression
- the expression to evaluateenvironment
- the environment containing the values of program variables for the evaluationpp
- the program point that where this operation is being evaluated- Returns:
- an new instance of this domain, representing the abstract result
of
expression
when evaluated onenvironment
. The returned value is a pair that express both the result of the evaluation and the updated execution state - Throws:
SemanticException
- if something goes wrong during the computation
-
evalIdentifier
public InferredValue.InferredPair<T> evalIdentifier(Identifier id, InferenceSystem<T> environment, ProgramPoint pp) throws SemanticException
Yields the evaluation of an identifier in a given environment.- Parameters:
id
- the identifier to be evaluatedenvironment
- the environment where the identifier must be evaluatedpp
- the program point that where this operation is being evaluated- Returns:
- the evaluation of the identifier
- Throws:
SemanticException
- if an error occurs during the computation
-
evalPushAny
public InferredValue.InferredPair<T> evalPushAny(PushAny pushAny, T state, ProgramPoint pp) throws SemanticException
Yields the evaluation of a push-any expression.- Parameters:
pushAny
- the push-any expression to be evaluatedstate
- the current execution statepp
- the program point that where this operation is being evaluated- Returns:
- the evaluation of the push-any expression
- Throws:
SemanticException
- if an error occurs during the computation
-
evalNullConstant
public InferredValue.InferredPair<T> evalNullConstant(T state, ProgramPoint pp) throws SemanticException
Yields the evaluation of the null constantNullConstant
.- Parameters:
state
- the current execution statepp
- the program point that where this operation is being evaluated- Returns:
- the evaluation of the constant
- Throws:
SemanticException
- if an error occurs during the computation
-
evalNonNullConstant
public InferredValue.InferredPair<T> evalNonNullConstant(Constant constant, T state, ProgramPoint pp) throws SemanticException
Yields the evaluation of the given non-null constant.- Parameters:
constant
- the constant to evaluatestate
- the current execution statepp
- the program point that where this operation is being evaluated- Returns:
- the evaluation of the constant
- Throws:
SemanticException
- if an error occurs during the computation
-
evalUnaryExpression
public InferredValue.InferredPair<T> evalUnaryExpression(UnaryOperator operator, T arg, T state, ProgramPoint pp) throws SemanticException
Yields the evaluation of aUnaryExpression
applyingoperator
to an expression whose abstract value isarg
. It is guaranteed thatarg
is notLattice.bottom()
.- Parameters:
operator
- the operator applied by the expressionarg
- the instance of this domain representing the abstract value of the expresion's argumentstate
- the current execution statepp
- the program point that where this operation is being evaluated- Returns:
- the evaluation of the expression
- Throws:
SemanticException
- if an error occurs during the computation
-
evalBinaryExpression
public InferredValue.InferredPair<T> evalBinaryExpression(BinaryOperator operator, T left, T right, T state, ProgramPoint pp) throws SemanticException
Yields the evaluation of aBinaryExpression
applyingoperator
to two expressions whose abstract value areleft
andright
, respectively. It is guaranteed that bothleft
andright
are notLattice.bottom()
and thatoperator
is neitherTypeCast
norTypeConv
.- Parameters:
operator
- the operator applied by the expressionleft
- the instance of this domain representing the abstract value of the left-hand side argumentright
- the instance of this domain representing the abstract value of the right-hand side argumentstate
- the current execution statepp
- the program point that where this operation is being evaluated- Returns:
- the evaluation of the expression
- Throws:
SemanticException
- if an error occurs during the computation
-
evalTypeConv
public InferredValue.InferredPair<T> evalTypeConv(BinaryExpression conv, T left, T right, T state, ProgramPoint pp) throws SemanticException
Yields the evaluation of a type conversion expression.- Parameters:
conv
- the type conversion expressionleft
- the left expression, namely the expression to be convertedright
- the right expression, namely the types to which left should be convertedstate
- the current execution statepp
- the program point that where this operation is being evaluated- Returns:
- the evaluation of the type conversion expression
- Throws:
SemanticException
- if an error occurs during the computation
-
evalTypeCast
public InferredValue.InferredPair<T> evalTypeCast(BinaryExpression cast, T left, T right, T state, ProgramPoint pp) throws SemanticException
Yields the evaluation of a type cast expression.- Parameters:
cast
- the type casted expressionleft
- the left expression, namely the expression to be castedright
- the right expression, namely the types to which left should be castedstate
- the current execution statepp
- the program point that where this operation is being evaluated- Returns:
- the evaluation of the type cast expression
- Throws:
SemanticException
- if an error occurs during the computation
-
evalTernaryExpression
public InferredValue.InferredPair<T> evalTernaryExpression(TernaryOperator operator, T left, T middle, T right, T state, ProgramPoint pp) throws SemanticException
Yields the evaluation of aTernaryExpression
applyingoperator
to two expressions whose abstract value areleft
,middle
andright
, respectively. It is guaranteed that bothleft
andright
are notLattice.bottom()
.- Parameters:
operator
- the operator applied by the expressionleft
- the instance of this domain representing the abstract value of the left-hand side argumentmiddle
- the instance of this domain representing the abstract value of the middle argumentright
- the instance of this domain representing the abstract value of the right-hand side argumentstate
- the current execution statepp
- the program point that where this operation is being evaluated- Returns:
- the evaluation of the expression
- Throws:
SemanticException
- if an error occurs during the computation
-
satisfiesAbstractValue
public SemanticDomain.Satisfiability satisfiesAbstractValue(T value, T state, ProgramPoint pp) throws SemanticException
Yields the satisfiability of an abstract value of type<T>
.- Parameters:
value
- the abstract value whose satisfiability is to be evaluatedstate
- the current execution statepp
- the program point that where this operation is being evaluated- Returns:
SemanticDomain.Satisfiability.SATISFIED
if the expression is satisfied by 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
-
satisfiesPushAny
public SemanticDomain.Satisfiability satisfiesPushAny(PushAny pushAny, T state) throws SemanticException
Yields the satisfiability of the push any expression.- Parameters:
pushAny
- the push any expression to satisfystate
- the current execution state- Returns:
SemanticDomain.Satisfiability.SATISFIED
if the expression is satisfied by 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
-
satisfiesNullConstant
public SemanticDomain.Satisfiability satisfiesNullConstant(T state, ProgramPoint pp) throws SemanticException
Yields the satisfiability of the null constantNullConstant
on this abstract domain.- Parameters:
state
- the current execution statepp
- the program point that where this operation is being evaluated- Returns:
SemanticDomain.Satisfiability.SATISFIED
if the expression is satisfied by 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
-
satisfiesNonNullConstant
public SemanticDomain.Satisfiability satisfiesNonNullConstant(Constant constant, T state, ProgramPoint pp) throws SemanticException
Yields the satisfiability of the given non-null constant on this abstract domain.- Parameters:
constant
- the constant to satisfiedstate
- the current execution statepp
- the program point that where this operation is being evaluated- Returns:
SemanticDomain.Satisfiability.SATISFIED
is the constant is satisfied by 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
-
satisfiesUnaryExpression
public SemanticDomain.Satisfiability satisfiesUnaryExpression(UnaryOperator operator, T arg, T state, ProgramPoint pp) throws SemanticException
Yields the satisfiability of aUnaryExpression
applyingoperator
to an expression whose abstract value isarg
, returning an instance ofSemanticDomain.Satisfiability
. It is guaranteed thatoperator
is notLogicalNegation
andarg
is notLattice.bottom()
.- Parameters:
operator
- the unary operator applied by the expressionarg
- an instance of this abstract domain representing the argument of the unary expressionstate
- the current execution statepp
- the program point that where this operation is being evaluated- Returns:
SemanticDomain.Satisfiability.SATISFIED
if the expression is satisfied by 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
-
satisfiesBinaryExpression
public SemanticDomain.Satisfiability satisfiesBinaryExpression(BinaryOperator operator, T left, T right, T state, ProgramPoint pp) throws SemanticException
Yields the satisfiability of aBinaryExpression
applyingoperator
to two expressions whose abstract values areleft
, andright
. This method returns an instance ofSemanticDomain.Satisfiability
. It is guaranteed thatoperator
is neitherLogicalAnd
norLogicalOr
, and that bothleft
andright
are notLattice.bottom()
.- Parameters:
operator
- the binary operator applied by the expressionleft
- an instance of this abstract domain representing the argument of the left-hand side of the binary expressionright
- an instance of this abstract domain representing the argument of the right-hand side of the binary expressionstate
- the current execution statepp
- the program point that where this operation is being evaluated- Returns:
SemanticDomain.Satisfiability.SATISFIED
if the expression is satisfied by 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
-
satisfiesTernaryExpression
public SemanticDomain.Satisfiability satisfiesTernaryExpression(TernaryOperator operator, T left, T middle, T right, T state, ProgramPoint pp) throws SemanticException
Yields the satisfiability of aTernaryExpression
applyingoperator
to three expressions whose abstract values areleft
,middle
andright
. This method returns an instance ofSemanticDomain.Satisfiability
. It is guaranteed thatleft
,middle
andright
are notLattice.bottom()
.- Parameters:
operator
- the ternary operator applied by the expressionleft
- an instance of this abstract domain representing the argument of the left-most side of the ternary expressionmiddle
- an instance of this abstract domain representing the argument in the middle of the ternary expressionright
- an instance of this abstract domain representing the argument of the right-most side of the ternary expressionstate
- the current execution statepp
- the program point that where this operation is being evaluated- Returns:
SemanticDomain.Satisfiability.SATISFIED
if the expression is satisfied by 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
-
toString
public final java.lang.String toString()
- Specified by:
toString
in classBaseLattice<T extends BaseInferredValue<T>>
-
tracksIdentifiers
public boolean tracksIdentifiers(Identifier id)
Description copied from interface:SemanticEvaluator
Yieldstrue
if the domain tracks information on the identifierid
,false
otherwise.- Specified by:
tracksIdentifiers
in interfaceSemanticEvaluator
- Parameters:
id
- the identifier- Returns:
true
if the domain tracks information on the identifierid
,false
otherwise
-
canProcess
public boolean canProcess(SymbolicExpression expression)
Description copied from interface:SemanticEvaluator
Yieldstrue
if the domain can processexpression
,false
otherwise.- Specified by:
canProcess
in interfaceSemanticEvaluator
- Parameters:
expression
- the expression- Returns:
true
if the domain can processexpression
,false
otherwise.
-
assume
public InferenceSystem<T> assume(InferenceSystem<T> environment, ValueExpression expression, ProgramPoint pp) throws SemanticException
Description copied from interface:NonRelationalElement
Yields the environmentenvironment
on which the expressionexpression
is assumed to hold by this domain.- Specified by:
assume
in interfaceNonRelationalElement<T extends BaseInferredValue<T>,ValueExpression,InferenceSystem<T extends BaseInferredValue<T>>>
- Parameters:
environment
- the environmentexpression
- the expression to be assumedpp
- the program point whereexpression
occurs.- Returns:
- the environment
environment
whereexpression
is assumed to hold - Throws:
SemanticException
- if an error occurs during the computation
-
glb
public T glb(T other) throws SemanticException
Description copied from interface:NonRelationalElement
Performs the greatest lower bound operation between this domain element andother
.- Specified by:
glb
in interfaceNonRelationalElement<T extends BaseInferredValue<T>,ValueExpression,InferenceSystem<T extends BaseInferredValue<T>>>
- Parameters:
other
- the other domain element- Returns:
- the greatest lowe bound between
this
andother
- Throws:
SemanticException
- if an error occurs during the computation
-
glbAux
public T glbAux(T other) throws SemanticException
Performs the greatest lower bound operation between this inferred value andother
, 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)
)this
andother
are not comparable (according toBaseLattice.lessOrEqual(BaseLattice)
)
Lattice.bottom()
- Parameters:
other
- the other inferred value- Returns:
- the greatest lower bound between this and other
- Throws:
SemanticException
- if an error occurs during the computation
-
-