vasco
Class Context<M,N,A>

java.lang.Object
  extended by vasco.Context<M,N,A>
Type Parameters:
M - the type of a method
N - the type of a node in the CFG
A - the type of a data flow value
All Implemented Interfaces:
Comparable<Context<M,N,A>>, Context

public class Context<M,N,A>
extends Object
implements Context, Comparable<Context<M,N,A>>

A value-based context for a context-sensitive inter-procedural data flow analysis.

A value-based context is identified as a pair of a method and the data flow value at the entry of the method, for forward flows, or the data flow value at the exit of the method, for backward flows. Thus, if two distinct calls are made to a method and each call-site has the same data flow value then it is considered that the target of that call is the same context. This concept allows termination in the presence of recursion as the number of contexts is limited by the size of the lattice (which must be finite).

Each value context has its own work-list of CFG nodes to analyse, and the results of analysis are stored in a map from nodes to the data flow values before/after the node.

Author:
Rohan Padhye

Constructor Summary
Context(M method, DirectedGraph<N> cfg, boolean reverse)
          Creates a new context for the given method.
 
Method Summary
 int compareTo(Context<M,N,A> other)
          Compares two contexts by their globally unique IDs.
 DirectedGraph<N> getControlFlowGraph()
          Returns a reference to the control flow graph of this context's method.
static int getCount()
          Returns the total number of contexts created so far.
 A getEntryValue()
          Returns a reference to the data flow value at the method entry.
 A getExitValue()
          Returns a reference to the data flow value at the method exit.
 int getId()
          Returns the globally unique identifier of this context.
 M getMethod()
          Returns a reference to this context's method.
 A getValueAfter(N node)
          Gets the data flow value at the exit of the given node.
 A getValueBefore(N node)
          Gets the data flow value at the entry of the given node.
 NavigableSet<N> getWorkList()
          Returns a reference to this context's work-list.
 boolean isAnalysed()
          Returns whether or not this context has been analysed at least once.
 void setEntryValue(A entryValue)
          Sets the entry flow of this context.
 void setExitValue(A exitValue)
          Sets the exit flow of this context.
 void setValueAfter(N node, A value)
          Sets the data flow value at the exit of the given node.
 void setValueBefore(N node, A value)
          Sets the data flow value at the entry of the given node.
 String toString()
          
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Context

public Context(M method,
               DirectedGraph<N> cfg,
               boolean reverse)
Creates a new context for the given method.

Parameters:
method - the method to which this value context belongs
cfg - the control-flow graph for the body of method
reverse - true if the analysis is in the reverse direction, and false if the analysis is in the forward direction
Method Detail

compareTo

public int compareTo(Context<M,N,A> other)
Compares two contexts by their globally unique IDs. This functionality is useful in the framework's internal methods where ordered processing of newer contexts first helps speed up certain operations.

Specified by:
compareTo in interface Comparable<Context<M,N,A>>

getControlFlowGraph

public DirectedGraph<N> getControlFlowGraph()
Returns a reference to the control flow graph of this context's method.

Returns:
a reference to the control flow graph of this context's method

getCount

public static int getCount()
Returns the total number of contexts created so far.


getEntryValue

public A getEntryValue()
Returns a reference to the data flow value at the method entry.

Returns:
a reference to the data flow value at the method entry

getExitValue

public A getExitValue()
Returns a reference to the data flow value at the method exit.

Returns:
a reference to the data flow value at the method exit

getId

public int getId()
Returns the globally unique identifier of this context.

Returns:
the globally unique identifier of this context

getMethod

public M getMethod()
Returns a reference to this context's method.

Returns:
a reference to this context's method

getValueAfter

public A getValueAfter(N node)
Gets the data flow value at the exit of the given node.

Parameters:
node - a node in the control flow graph
Returns:
the data flow value at the exit of the given node

getValueBefore

public A getValueBefore(N node)
Gets the data flow value at the entry of the given node.

Parameters:
node - a node in the control flow graph
Returns:
the data flow value at the entry of the given node

getWorkList

public NavigableSet<N> getWorkList()
Returns a reference to this context's work-list.

Returns:
a reference to this context's work-list

isAnalysed

public boolean isAnalysed()
Returns whether or not this context has been analysed at least once.

Returns:
true if the context has been analysed at least once, or false otherwise

setEntryValue

public void setEntryValue(A entryValue)
Sets the entry flow of this context.

Parameters:
entryValue - the new data flow value at the method entry

setExitValue

public void setExitValue(A exitValue)
Sets the exit flow of this context.

Parameters:
exitValue - the new data flow value at the method exit

setValueAfter

public void setValueAfter(N node,
                          A value)
Sets the data flow value at the exit of the given node.

Parameters:
node - a node in the control flow graph
value - the new data flow at the node exit

setValueBefore

public void setValueBefore(N node,
                           A value)
Sets the data flow value at the entry of the given node.

Parameters:
node - a node in the control flow graph
value - the new data flow at the node entry

toString

public String toString()

Overrides:
toString in class Object