Class Statement
- java.lang.Object
-
- it.unive.lisa.program.cfg.statement.Statement
-
- All Implemented Interfaces:
ProgramPoint
,CodeElement
,CodeNode<CFG,Statement,Edge>
,Node<CFG,Statement,Edge>
,java.lang.Comparable<Statement>
- Direct Known Subclasses:
Expression
,NaryStatement
,NoOp
,Ret
public abstract class Statement extends java.lang.Object implements CodeNode<CFG,Statement,Edge>, ProgramPoint, java.lang.Comparable<Statement>
A statement of the program to analyze.
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
Statement(CFG cfg, CodeLocation location)
Builds a statement happening at the given source location.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description <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.protected abstract int
compareSameClass(Statement o)
Auxiliary method forcompareTo(Statement)
that can safely assume that the two statements happen at the sameCodeLocation
and are instances of the same class.int
compareTo(Statement o)
boolean
equals(java.lang.Object obj)
abstract <A extends AbstractState<A>>
AnalysisState<A>forwardSemantics(AnalysisState<A> entryState, InterproceduralAnalysis<A> interprocedural, StatementStore<A> expressions)
Computes the forward semantics of the statement, expressing how semantic information is transformed by the execution of this statement.CFG
getCFG()
Yields theCFG
that this program point belongs to.Statement
getEvaluationPredecessor()
Yields theStatement
that is evaluated right before this one, such that querying for the entry state ofthis
statement is equivalent to querying the exit state of the returned one.Statement
getEvaluationSuccessor()
Yields theStatement
that is evaluated right after this one, such that querying for the exit state ofthis
statement is equivalent to querying the entry state of the returned one.CodeLocation
getLocation()
Yields the location where this code element appears in the program.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.int
hashCode()
boolean
stopsExecution()
Whether or not this statement stops the execution of the containing cfg, either by throwing an error or returning a value.boolean
throwsError()
Whether or not this statement throws an error, halting the normal execution of the containing cfg.abstract java.lang.String
toString()
-
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
-
Statement
protected Statement(CFG cfg, CodeLocation location)
Builds a statement happening at the given source location.- Parameters:
cfg
- the cfg that this statement belongs tolocation
- the location where this statement is defined within the program
-
-
Method Detail
-
getCFG
public final CFG getCFG()
Description copied from interface:ProgramPoint
Yields theCFG
that this program point belongs to.- Specified by:
getCFG
in interfaceProgramPoint
- Returns:
- the containing cfg
-
stopsExecution
public boolean stopsExecution()
Whether or not this statement stops the execution of the containing cfg, either by throwing an error or returning a value. To distinguish error-raising halting statements and normal ones, usethrowsError()
.- Returns:
true
only if that condition holds
-
throwsError
public boolean throwsError()
Whether or not this statement throws an error, halting the normal execution of the containing cfg.- Returns:
true
only if that condition holds
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
toString
public abstract java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
forwardSemantics
public abstract <A extends AbstractState<A>> AnalysisState<A> forwardSemantics(AnalysisState<A> entryState, InterproceduralAnalysis<A> interprocedural, StatementStore<A> expressions) throws SemanticException
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 theforwardSemantics(AnalysisState, InterproceduralAnalysis, StatementStore)
of each nestedExpression
, saving the result of each call inexpressions
.- 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
-
backwardSemantics
public <A extends AbstractState<A>> AnalysisState<A> backwardSemantics(AnalysisState<A> exitState, InterproceduralAnalysis<A> interprocedural, StatementStore<A> expressions) throws SemanticException
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 theforwardSemantics(AnalysisState, InterproceduralAnalysis, StatementStore)
of each nestedExpression
, saving the result of each call inexpressions
. By default, this method delegates toforwardSemantics(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.- 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
-
getLocation
public CodeLocation getLocation()
Description copied from interface:CodeElement
Yields the location where this code element appears in the program.- Specified by:
getLocation
in interfaceCodeElement
- Returns:
- the location where this code element appears in the program
-
compareTo
public final int compareTo(Statement o)
- Specified by:
compareTo
in interfacejava.lang.Comparable<Statement>
-
compareSameClass
protected abstract int compareSameClass(Statement o)
Auxiliary method forcompareTo(Statement)
that can safely assume that the two statements happen at the sameCodeLocation
and are instances of the same class.- 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
-
getEvaluationPredecessor
public final Statement getEvaluationPredecessor()
Yields theStatement
that is evaluated right before this one, such that querying for the entry state ofthis
statement is equivalent to querying the exit state of the returned one. If this method returnsnull
, then this is the first expression evaluated when an entire statement is evaluated.- Returns:
- the previous statement, or
null
-
getStatementEvaluatedBefore
public Statement getStatementEvaluatedBefore(Statement other)
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.- Parameters:
other
- the other statement- Returns:
- the previous statement, or
null
-
getEvaluationSuccessor
public final Statement getEvaluationSuccessor()
Yields theStatement
that is evaluated right after this one, such that querying for the exit state ofthis
statement is equivalent to querying the entry state of the returned one. If this method returnsnull
, then this is either a statement or the last expression evaluated when an entire statement is evaluated.- Returns:
- the next statement, or
null
-
getStatementEvaluatedAfter
public Statement getStatementEvaluatedAfter(Statement other)
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.- Parameters:
other
- the other statement- Returns:
- the next statement, or
null
-
-