tip.cfg
Class CCFG

java.lang.Object
  extended by tip.cfg.CCFG
All Implemented Interfaces:
ICFG

public class CCFG
extends Object
implements ICFG

CCFG is the standard implementation of ICFG. It is used by CFGBuilder.

Author:
Johnni Winther, jw@brics.dk

Constructor Summary
CCFG(String name)
          Creates a new empty control flow graph with the name name.
CCFG(String name, List<IProgramPoint> pointList)
          Creates a new linear control flow graph from the list of program points.
CCFG(String name, Set<ICFG> cfgSet)
          Creates a new control flow graph from the set of control flow graphs.
 
Method Summary
 void add(IProgramPoint point)
          Adds the IProgramPoint point to the set of program points associated with this ICFG.
 void apply(Analysis analysis)
          Applies analysis to all nodes associated with program points in this control flow graph.
<Q> void
apply(Question<Q> caller, Q question)
          Applies the Question caller and question to all nodes associated with program points in this control flow graph.
 void clean()
          Cleans the control flow graph by removing all predecessors and successors of the program points in the program point set of this control flow graph which are not in the program point set of this control flow graph.
 CCFG clone()
          Returns a deep clone of the ICFG with respect to program points, i.e. program points cloned but the associated AST nodes are not.
 boolean containsProgramPoint(IProgramPoint point)
          Returns true if this ICFG contains the IProgramPoint point.
 IProgramPoint getEntry()
          Returns the entry point of the control flow graph.
 IProgramPoint getExit()
          Returns the exit point of the control flow graph.
 String getName()
          Returns the name of the control flow graph
<T extends Node>
Collection<T>
getNodeDescendants(Class<T> classType)
          Returns a collection of descendants to the nodes associated to the program points in this control flow graph.
<T extends Node>
void
getNodeDescendants(Collection<T> collection, NodeFilter<T> filter)
          Adds descendants to the nodes associated to the program points in this control flow graph to collection.
<T extends Node>
Collection<T>
getNodeDescendants(NodeFilter<T> filter)
          Returns a collection of descendants to the nodes associated to the program points in this control flow graph.
 Collection<IProgramPoint> getProgramPoints()
          Returns the collection of program points in the control flow graph.
 void insertAfter(IProgramPoint point, IProgramPoint newPoint)
          Inserts newPoint in the control flow graph after point.
 void insertBefore(IProgramPoint point, IProgramPoint newPoint)
          Inserts newPoint in the control flow graph before point.
 void prefixCFG(ICFG cfg)
          Prefixes cfg in this control flow graph.
 void remove(IProgramPoint point)
          Removes the IProgramPoint point from the set of program points associated with this ICFG.
 void removePoint(IProgramPoint point)
          Removes point from this control flow graph, updating the predecessors and successors of point to point to eachother.
 void replaceByCFG(IProgramPoint point, ICFG cfg)
          Replaces point with cfg in this control flow graph.
 void replacePoint(IProgramPoint oldPoint, IProgramPoint newPoint)
          Replaces oldPoint with newPoint in this control flow graph.
 void setEntry(IProgramPoint point)
          Sets the entry point of the control flow graph.
 void setExit(IProgramPoint point)
          Sets the exit point of the control flow graph.
 void suffixCFG(ICFG cfg)
          Suffixes cfg in this control flow graph.
 String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CCFG

public CCFG(String name)
Creates a new empty control flow graph with the name name.

Parameters:
name - the name of the control flow graph

CCFG

public CCFG(String name,
            List<IProgramPoint> pointList)
Creates a new linear control flow graph from the list of program points. The first point is set to be the entry point, the last to be the exit point, and predecessor/successors relations are set between the points to form a linear control flow graph.

Parameters:
name - the name of the control flow graph
pointList - the list of program points from which the control flow graph is constructed

CCFG

public CCFG(String name,
            Set<ICFG> cfgSet)
Creates a new control flow graph from the set of control flow graphs. A new entry and exit point (with no associated Node) are made, all successors of the entry points are set as successors to this new entry point and all predecessors of the exit points are set as predecessors of the new exit point.

Parameters:
name - the name of the control flow graph
cfgSet - the set of control flow graphs from which the control flow graph is constructed
Method Detail

getName

public String getName()
Returns the name of the control flow graph

Specified by:
getName in interface ICFG
Returns:
the name of the control flow graph

add

public void add(IProgramPoint point)
Adds the IProgramPoint point to the set of program points associated with this ICFG. Predecessors and successors are not updated.

Specified by:
add in interface ICFG
Parameters:
point - the IProgramPoint to be added to this ICFG

remove

public void remove(IProgramPoint point)
Removes the IProgramPoint point from the set of program points associated with this ICFG. Predecessors and successors are not updated.

Specified by:
remove in interface ICFG
Parameters:
point - the IProgramPoint to be removed from this ICFG

getProgramPoints

public Collection<IProgramPoint> getProgramPoints()
Returns the collection of program points in the control flow graph.

Specified by:
getProgramPoints in interface ICFG
Returns:
the collection of program points in the control flow graph

containsProgramPoint

public boolean containsProgramPoint(IProgramPoint point)
Returns true if this ICFG contains the IProgramPoint point.

Specified by:
containsProgramPoint in interface ICFG
Parameters:
point - the IProgramPoint in question
Returns:
true if this ICFG contains the IProgramPoint point

replaceByCFG

public void replaceByCFG(IProgramPoint point,
                         ICFG cfg)
Replaces point with cfg in this control flow graph. That is, point is removed from this control flow graph, all predecessors of point are set to have all successors of the entry point in cfg as their successor instead of point and all successors of point are set to have all predecessors of the exit point in cfg as their predecessor instead of point. All program point in cfg, except the entry and exit points, are added to this control flow graph.

Specified by:
replaceByCFG in interface ICFG
Parameters:
point - the replaced point
cfg - the replacing control flow graph

prefixCFG

public void prefixCFG(ICFG cfg)
Prefixes cfg in this control flow graph. That is, all successors of the entry point in cfg are set to be successors of the entry point in this control flow graph, and all successors of the entry point in this control flow graph are set as successors of the exit point in cfg. All program point in cfg, except the entry and exit points, are added to this control flow graph.

Specified by:
prefixCFG in interface ICFG
Parameters:
cfg - the prefixed cfg

suffixCFG

public void suffixCFG(ICFG cfg)
Suffixes cfg in this control flow graph. That is, all predecessors of the exit point in cfg are set to be predecessors of the exit point in this control flow graph, and all predecessors of the exit point in this control flow graph are set as predecessors of the entry point in cfg. All program point in cfg, except the entry and exit points, are added to this control flow graph.

Specified by:
suffixCFG in interface ICFG
Parameters:
cfg - the suffixed cfg

replacePoint

public void replacePoint(IProgramPoint oldPoint,
                         IProgramPoint newPoint)
Replaces oldPoint with newPoint in this control flow graph. Successors and predecessors are transferred from oldPoint to newPoint. oldPoint is removed from this control flow graph newPoint is added to this control flow graph.

Specified by:
replacePoint in interface ICFG
Parameters:
oldPoint - the replaced point
newPoint - the replacing point

removePoint

public void removePoint(IProgramPoint point)
Removes point from this control flow graph, updating the predecessors and successors of point to point to eachother.

Specified by:
removePoint in interface ICFG
Parameters:
point - the removed point

insertAfter

public void insertAfter(IProgramPoint point,
                        IProgramPoint newPoint)
Inserts newPoint in the control flow graph after point. That is, all successors of point are set as successors of newPoint and newPoint is set as the sole successor of point

Specified by:
insertAfter in interface ICFG
Parameters:
point - the point in this control flow graph after which newPoint is inserted
newPoint - the inserted point

insertBefore

public void insertBefore(IProgramPoint point,
                         IProgramPoint newPoint)
Inserts newPoint in the control flow graph before point. That is, all predecessors of point are set as predecessors of newPoint and newPoint is set as the sole predecessor of point

Specified by:
insertBefore in interface ICFG
Parameters:
point - the point in this control flow graph before which newPoint is inserted
newPoint - the inserted point

clean

public void clean()
Cleans the control flow graph by removing all predecessors and successors of the program points in the program point set of this control flow graph which are not in the program point set of this control flow graph. This may be necessary for analyses to work correctly after having added points to the control flow graph from other control flow graphs, as after replaceByCFG(IProgramPoint,ICFG), prefixCFG(ICFG), suffixCFG(ICFG), replacePoint(IProgramPoint,IProgramPoint), insertAfter(IProgramPoint,IProgramPoint), and insertBefore(IProgramPoint,IProgramPoint).

Specified by:
clean in interface ICFG

getNodeDescendants

public <T extends Node> Collection<T> getNodeDescendants(Class<T> classType)
Returns a collection of descendants to the nodes associated to the program points in this control flow graph. Only descendants that are subtypes of classType are returned.

Specified by:
getNodeDescendants in interface ICFG
Parameters:
classType - the supertype of returned descendants
Returns:
a collection of descendants to the associated nodes

getNodeDescendants

public <T extends Node> Collection<T> getNodeDescendants(NodeFilter<T> filter)
Returns a collection of descendants to the nodes associated to the program points in this control flow graph. Only descendants that are accepted by the NodeFilter filter are returned.

Specified by:
getNodeDescendants in interface ICFG
Parameters:
filter - the NodeFilter used for filtering nodes
Returns:
a collection of descendants to the associated nodes

getNodeDescendants

public <T extends Node> void getNodeDescendants(Collection<T> collection,
                                                NodeFilter<T> filter)
Adds descendants to the nodes associated to the program points in this control flow graph to collection. Only descendants that are accepted by the NodeFilter filter are returned.

Specified by:
getNodeDescendants in interface ICFG
Parameters:
collection - the collection to which the descendants are added
filter - the NodeFilter used for filtering nodes

apply

public void apply(Analysis analysis)
Applies analysis to all nodes associated with program points in this control flow graph.

Specified by:
apply in interface ICFG
Parameters:
analysis - the Analysis applied to the associated nodes

apply

public <Q> void apply(Question<Q> caller,
                      Q question)
Applies the Question caller and question to all nodes associated with program points in this control flow graph.

Specified by:
apply in interface ICFG
Parameters:
caller - the Question applied to the associated nodes
question - the provided question

getEntry

public IProgramPoint getEntry()
Returns the entry point of the control flow graph.

Specified by:
getEntry in interface ICFG
Returns:
the entry point of the control flow graph

setEntry

public void setEntry(IProgramPoint point)
Sets the entry point of the control flow graph.

Parameters:
point - the entry point of the control flow graph the graph

getExit

public IProgramPoint getExit()
Returns the exit point of the control flow graph.

Specified by:
getExit in interface ICFG
Returns:
the exit point of the control flow graph

setExit

public void setExit(IProgramPoint point)
Sets the exit point of the control flow graph.

Parameters:
point - the exit point of the control flow graph the graph

clone

public CCFG clone()
Returns a deep clone of the ICFG with respect to program points, i.e. program points cloned but the associated AST nodes are not.

Specified by:
clone in interface ICFG
Overrides:
clone in class Object
Returns:
a deep clone of the ICFG

toString

public String toString()
Overrides:
toString in class Object