Class NaryExpression
- java.lang.Object
-
- it.unive.lisa.program.cfg.statement.Statement
-
- it.unive.lisa.program.cfg.statement.Expression
-
- it.unive.lisa.program.cfg.statement.NaryExpression
-
- All Implemented Interfaces:
ProgramPoint
,CodeElement
,CodeNode<CFG,Statement,Edge>
,Node<CFG,Statement,Edge>
,java.lang.Comparable<Statement>
- Direct Known Subclasses:
BinaryExpression
,Call
,TernaryExpression
,UnaryExpression
public abstract class NaryExpression extends Expression
A generic expression withn
sub-expressions.
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
NaryExpression(CFG cfg, CodeLocation location, java.lang.String constructName, EvaluationOrder order, Expression... subExpressions)
Builds the expression, happening at the given location in the program.protected
NaryExpression(CFG cfg, CodeLocation location, java.lang.String constructName, EvaluationOrder order, Type staticType, Expression... subExpressions)
Builds the expression, happening at the given location in the program.protected
NaryExpression(CFG cfg, CodeLocation location, java.lang.String constructName, Expression... subExpressions)
Builds the expression, happening at the given location in the program.protected
NaryExpression(CFG cfg, CodeLocation location, java.lang.String constructName, Type staticType, Expression... subExpressions)
Builds the expression, happening at the given location in the program.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description <V> boolean
accept(GraphVisitor<CFG,Statement,Edge,V> visitor, V tool)
Accepts the givenGraphVisitor
.<A extends AbstractState<A>>
AnalysisState<A>backwardSemantics(AnalysisState<A> exitState, InterproceduralAnalysis<A> interprocedural, StatementStore<A> expressions)
Computes the backward semantics of the statement, expressing how semantic information is transformed by the execution of this statement.<A extends AbstractState<A>>
AnalysisState<A>backwardSemanticsAux(InterproceduralAnalysis<A> interprocedural, AnalysisState<A> state, ExpressionSet[] params, StatementStore<A> expressions)
Computes the backward semantics of the expression, after the semantics of all sub-expressions have been computed.protected int
compareSameClass(Statement o)
Auxiliary method forStatement.compareTo(Statement)
that can safely assume that the two statements happen at the sameCodeLocation
and are instances of the same class.protected abstract int
compareSameClassAndParams(Statement o)
Auxiliary method forStatement.compareTo(Statement)
that can safely assume that the two expressions happen at the sameCodeLocation
, are instances of the same class, and have the same parameters according to their implementation ofStatement.compareTo(Statement)
.boolean
equals(java.lang.Object obj)
<A extends AbstractState<A>>
AnalysisState<A>forwardSemantics(AnalysisState<A> entryState, InterproceduralAnalysis<A> interprocedural, StatementStore<A> expressions)
Semantics of an n-ary expression is evaluated by computing the semantics of its sub-expressions, in the specified order, using the analysis state from each sub-expression's computation as entry state for the next one.abstract <A extends AbstractState<A>>
AnalysisState<A>forwardSemanticsAux(InterproceduralAnalysis<A> interprocedural, AnalysisState<A> state, ExpressionSet[] params, StatementStore<A> expressions)
Computes the forward semantics of the expression, after the semantics of all sub-expressions have been computed.java.lang.String
getConstructName()
Yields the name of the native construct represented by this expression.EvaluationOrder
getOrder()
Yields theEvaluationOrder
of the sub-expressions.Statement
getStatementEvaluatedAfter(Statement other)
Yields theStatement
that follows the given one, assuming thatother
is contained into this statement.Statement
getStatementEvaluatedBefore(Statement other)
Yields theStatement
that precedes the given one, assuming thatother
is contained into this statement.Expression[]
getSubExpressions()
Yields the sub-expressions of this expression.int
hashCode()
java.lang.String
toString()
-
Methods inherited from class it.unive.lisa.program.cfg.statement.Expression
getMetaVariables, getParentStatement, getRootStatement, getStaticType, setParentStatement
-
Methods inherited from class it.unive.lisa.program.cfg.statement.Statement
compareTo, getCFG, getEvaluationPredecessor, getEvaluationSuccessor, getLocation, stopsExecution, throwsError
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface it.unive.lisa.program.cfg.ProgramPoint
getProgram
-
-
-
-
Constructor Detail
-
NaryExpression
protected NaryExpression(CFG cfg, CodeLocation location, java.lang.String constructName, Expression... subExpressions)
Builds the expression, happening at the given location in the program. The static type of this expression isUntyped
. TheEvaluationOrder
isLeftToRightEvaluation
.- Parameters:
cfg
- the cfg that this expression belongs tolocation
- the location where the expression is defined within the programconstructName
- the name of the construct represented by this expressionsubExpressions
- the sub-expressions to be evaluated left-to-right
-
NaryExpression
protected NaryExpression(CFG cfg, CodeLocation location, java.lang.String constructName, EvaluationOrder order, Expression... subExpressions)
Builds the expression, happening at the given location in the program. The static type of this expression isUntyped
.- Parameters:
cfg
- the cfg that this expression belongs tolocation
- the location where the expression is defined within the programconstructName
- the name of the construct represented by this expressionorder
- the evaluation order of the sub-expressionssubExpressions
- the sub-expressions
-
NaryExpression
protected NaryExpression(CFG cfg, CodeLocation location, java.lang.String constructName, Type staticType, Expression... subExpressions)
Builds the expression, happening at the given location in the program. TheEvaluationOrder
isLeftToRightEvaluation
.- Parameters:
cfg
- the cfg that this expression belongs tolocation
- the location where the expression is defined within the programconstructName
- the name of the construct represented by this expressionstaticType
- the static type of this expressionsubExpressions
- the sub-expressions to be evaluated left-to-right
-
NaryExpression
protected NaryExpression(CFG cfg, CodeLocation location, java.lang.String constructName, EvaluationOrder order, Type staticType, Expression... subExpressions)
Builds the expression, happening at the given location in the program.- Parameters:
cfg
- the cfg that this expression belongs tolocation
- the location where the expression is defined within the programconstructName
- the name of the construct represented by this expressionorder
- the evaluation order of the sub-expressionsstaticType
- the static type of this expressionsubExpressions
- the sub-expressions
-
-
Method Detail
-
getConstructName
public final java.lang.String getConstructName()
Yields the name of the native construct represented by this expression.- Returns:
- the name of the construct
-
getSubExpressions
public final Expression[] getSubExpressions()
Yields the sub-expressions of this expression.- Returns:
- the sub-expressions
-
getOrder
public EvaluationOrder getOrder()
Yields theEvaluationOrder
of the sub-expressions.- Returns:
- the evaluation order
-
getStatementEvaluatedBefore
public Statement getStatementEvaluatedBefore(Statement other)
Description copied from class:Statement
Yields theStatement
that precedes the given one, assuming thatother
is contained into this statement. If this method returnsnull
, thenother
is the first expression evaluated when this statement is evaluated.- Overrides:
getStatementEvaluatedBefore
in classExpression
- Parameters:
other
- the other statement- Returns:
- the previous statement, or
null
-
getStatementEvaluatedAfter
public Statement getStatementEvaluatedAfter(Statement other)
Description copied from class:Statement
Yields theStatement
that follows the given one, assuming thatother
is contained into this statement. If this method returnsnull
, thenother
is the last expression evaluated when this statement is evaluated.- Overrides:
getStatementEvaluatedAfter
in classExpression
- Parameters:
other
- the other statement- Returns:
- the next statement, or
null
-
accept
public final <V> boolean accept(GraphVisitor<CFG,Statement,Edge,V> visitor, V tool)
Description copied from interface:Node
Accepts the givenGraphVisitor
. Implementors of this method are responsible for invokingGraphVisitor.visit(Object, Graph, Node)
on this node afterNode.accept(GraphVisitor, Object)
has been invoked on all nested nodes, if any. The visiting should stop at the first of such calls that returnfalse
.- Type Parameters:
V
- the type of auxiliary tool thatvisitor
can use- Parameters:
visitor
- the visitor that is visiting theGraph
containing this nodetool
- the auxiliary tool thatvisitor
can use- Returns:
- whether or not the visiting should stop when this call returns, as decided by the visitor itself
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classExpression
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classExpression
-
compareSameClass
protected int compareSameClass(Statement o)
Description copied from class:Statement
Auxiliary method forStatement.compareTo(Statement)
that can safely assume that the two statements happen at the sameCodeLocation
and are instances of the same class.- Specified by:
compareSameClass
in classStatement
- Parameters:
o
- the other statement- Returns:
- a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object
-
compareSameClassAndParams
protected abstract int compareSameClassAndParams(Statement o)
Auxiliary method forStatement.compareTo(Statement)
that can safely assume that the two expressions happen at the sameCodeLocation
, are instances of the same class, and have the same parameters according to their implementation ofStatement.compareTo(Statement)
.- Parameters:
o
- the other expression- Returns:
- a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object
-
forwardSemantics
public <A extends AbstractState<A>> AnalysisState<A> forwardSemantics(AnalysisState<A> entryState, InterproceduralAnalysis<A> interprocedural, StatementStore<A> expressions) throws SemanticException
Semantics of an n-ary expression is evaluated by computing the semantics of its sub-expressions, in the specified order, using the analysis state from each sub-expression's computation as entry state for the next one. Then, the semantics of the expression itself is evaluated.
Computes the forward semantics of the statement, expressing how semantic information is transformed by the execution of this statement. This method is also responsible for recursively invoking theStatement.forwardSemantics(AnalysisState, InterproceduralAnalysis, StatementStore)
of each nestedExpression
, saving the result of each call inexpressions
.- Specified by:
forwardSemantics
in classStatement
- Type Parameters:
A
- the type ofAbstractState
- Parameters:
entryState
- the entry state that represents the abstract values of each program variable and memory location when the execution reaches this statementinterprocedural
- the interprocedural analysis of the program to analyzeexpressions
- the cache where analysis states of intermediate expressions must be stored- Returns:
- the
AnalysisState
representing the abstract result of the execution of this statement - Throws:
SemanticException
- if something goes wrong during the computation
-
forwardSemanticsAux
public abstract <A extends AbstractState<A>> AnalysisState<A> forwardSemanticsAux(InterproceduralAnalysis<A> interprocedural, AnalysisState<A> state, ExpressionSet[] params, StatementStore<A> expressions) throws SemanticException
Computes the forward semantics of the expression, after the semantics of all sub-expressions have been computed. Meta variables from the sub-expressions will be forgotten after this call returns.- Type Parameters:
A
- the type ofAbstractState
- Parameters:
interprocedural
- the interprocedural analysis of the program to analyzestate
- the state where the expression is to be evaluatedparams
- the symbolic expressions representing the computed values of the sub-expressions of this expressionexpressions
- the cache where analysis states of intermediate expressions are stored and that can be accessed to query for post-states of parameters expressions- Returns:
- the
AnalysisState
representing the abstract result of the execution of this expression - Throws:
SemanticException
- if something goes wrong during the computation
-
backwardSemantics
public <A extends AbstractState<A>> AnalysisState<A> backwardSemantics(AnalysisState<A> exitState, InterproceduralAnalysis<A> interprocedural, StatementStore<A> expressions) throws SemanticException
Description copied from class:Statement
Computes the backward semantics of the statement, expressing how semantic information is transformed by the execution of this statement. This method is also responsible for recursively invoking theStatement.forwardSemantics(AnalysisState, InterproceduralAnalysis, StatementStore)
of each nestedExpression
, saving the result of each call inexpressions
. By default, this method delegates toStatement.forwardSemantics(AnalysisState, InterproceduralAnalysis, StatementStore)
, as it is fine for most atomic statements. One should redefine this method if a statement's semantics is composed of a series of smaller operations.- Overrides:
backwardSemantics
in classStatement
- Type Parameters:
A
- the type ofAbstractState
- Parameters:
exitState
- the exit state that represents the abstract values of each program variable and memory location when the execution reaches this statementinterprocedural
- the interprocedural analysis of the program to analyzeexpressions
- the cache where analysis states of intermediate expressions must be stored- Returns:
- the
AnalysisState
representing the abstract result of the execution of this statement - Throws:
SemanticException
- if something goes wrong during the computation
-
backwardSemanticsAux
public <A extends AbstractState<A>> AnalysisState<A> backwardSemanticsAux(InterproceduralAnalysis<A> interprocedural, AnalysisState<A> state, ExpressionSet[] params, StatementStore<A> expressions) throws SemanticException
Computes the backward semantics of the expression, after the semantics of all sub-expressions have been computed. Meta variables from the sub-expressions will be forgotten after this call returns. By default, this method delegates toforwardSemanticsAux(InterproceduralAnalysis, AnalysisState, ExpressionSet[], StatementStore)
, as it is fine for most atomic statements. One should redefine this method if a statement's semantics is composed of a series of smaller operations.- Type Parameters:
A
- the type ofAbstractState
- Parameters:
interprocedural
- the interprocedural analysis of the program to analyzestate
- the state where the expression is to be evaluatedparams
- the symbolic expressions representing the computed values of the sub-expressions of this expressionexpressions
- the cache where analysis states of intermediate expressions are stored and that can be accessed to query for post-states of parameters expressions- Returns:
- the
AnalysisState
representing the abstract result of the execution of this expression - Throws:
SemanticException
- if something goes wrong during the computation
-
-