sofya.graphs.cfg
Class CFEdge

java.lang.Object
  extended by sofya.graphs.Edge
      extended by sofya.graphs.cfg.CFEdge
All Implemented Interfaces:
SConstants

public class CFEdge
extends Edge
implements SConstants

A control flow edge is an edge in a Sofya control flow graph. It records additional information required for handling exceptional constructs and tracking branch flow in the CFG.

Version:
11/16/2004
Author:
Alex Kinneer
See Also:
Graph, Node

Nested Class Summary
static class CFEdge.BranchID
          A branch ID associated with an edge in a CFG.
 
Nested classes/interfaces inherited from interface sofya.base.SConstants
SConstants.BlockLabel, SConstants.BlockObjectType, SConstants.BlockSubType, SConstants.BlockType, SConstants.BranchObjectType, SConstants.BranchType, SConstants.EDObjectType, SConstants.TraceObjectType
 
Field Summary
protected  java.lang.String auxLabel
          Secondary label information (used with JSR and RET edges).
protected  java.util.SortedSet branchIDs
          Control flow branch IDs assigned to the edge.
protected  org.apache.bcel.generic.Type labelType
          Type associated with the label, if appropriate.
protected  int specialNodeID
          ID of a node which has some special relationship to this edge.
protected  java.util.Map typeIDMap
          Maps edge branch types to their associated branch IDs.
static CFEdge[] ZL_ARRAY
          Zero-length control flow edge array useful for specifying array cast types to methods such Graph.getEdges(Node,Node,Edge[]).
 
Fields inherited from class sofya.graphs.Edge
edgeID, label, predNodeID, succNodeID
 
Fields inherited from interface sofya.base.SConstants
DEFAULT_PORT, INST_COMPATIBLE, INST_OLD_UNSUPPORTED, INST_OPT_NORMAL, INST_OPT_SEQUENCE, SIG_CHKALIVE, SIG_ECHO
 
Constructor Summary
CFEdge()
          Creates an edge with ID zero, an empty label, and the successor and predecessor nodes set to zero.
CFEdge(int id, int s, int p, org.apache.bcel.generic.ObjectType type)
          Creates an edge with the given label, ID, successor and predecessor nodes, and associated label type.
CFEdge(int id, int s, int p, java.lang.String str)
          Creates an edge with the given label, ID, successor, and predecessor nodes.
CFEdge(int id, int s, int p, java.lang.String label, java.lang.String auxLabel, int spNode)
          Creates an edge with the given label, ID, successor and predecessor nodes, secondary label, and special relationship node.
 
Method Summary
 java.lang.String getAuxLabel()
          Gets the secondary label for this edge.
 CFEdge.BranchID getBranchID(int index)
          Gets a branch ID from this edge's branch ID set by index.
 CFEdge.BranchID getBranchID(SConstants.BranchType type)
          Gets the branch ID associated with the given branch type.
 CFEdge.BranchID[] getBranchIDArray()
          Gets the branch IDs associated with this edge as an array.
 java.util.SortedSet getBranchIDSet()
          Gets the branch IDs associated with this edge as an unmodifiable sorted set.
 org.apache.bcel.generic.Type getLabelType()
          Gets the type associated with this edge's label.
 int getSpecialNodeID()
          Gets the ID of a node which has a special relationship to this edge.
static void main(java.lang.String[] args)
          Test driver for the Edge class.
 void setAuxLabel(java.lang.String s)
          Sets the secondary label for this edge.
 void setSpecialNodeID(int n)
          Sets the ID of a node which has a special relationship to this edge.
 java.lang.String toString()
          Returns a string representation of this edge in the form:
label: sourceNodeID -> sinkNodeID.
 
Methods inherited from class sofya.graphs.Edge
getID, getLabel, getPredNodeID, getSuccNodeID, setID, setLabel, setPredNodeID, setSuccNodeID
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

branchIDs

protected java.util.SortedSet branchIDs
Control flow branch IDs assigned to the edge. Note that the branch types associated with IDs are only guaranteed to be valid on edges whose predecessor has multiple successors.


typeIDMap

protected java.util.Map typeIDMap
Maps edge branch types to their associated branch IDs. Note that if an edge is entirely encapsulated by another "logical" edge or edges of the same type, only the mapping to the most specific ("nearest", or this edge's) branch ID is retained, since that is what we want to observe. We will already know about the enclosing edge(s).


auxLabel

protected java.lang.String auxLabel
Secondary label information (used with JSR and RET edges).


specialNodeID

protected int specialNodeID
ID of a node which has some special relationship to this edge. Edges from JSR instructions will set this to the ID of the node for the corresponding RET.


labelType

protected org.apache.bcel.generic.Type labelType
Type associated with the label, if appropriate.


ZL_ARRAY

public static final CFEdge[] ZL_ARRAY
Zero-length control flow edge array useful for specifying array cast types to methods such Graph.getEdges(Node,Node,Edge[]).

Constructor Detail

CFEdge

public CFEdge()
Creates an edge with ID zero, an empty label, and the successor and predecessor nodes set to zero.


CFEdge

public CFEdge(int id,
              int s,
              int p,
              java.lang.String str)
Creates an edge with the given label, ID, successor, and predecessor nodes.

Parameters:
id - ID of the new edge.
s - ID of the new edge's successor node.
p - ID of the new edge's predecessor node.
str - Label to be assigned to the new edge.

CFEdge

public CFEdge(int id,
              int s,
              int p,
              java.lang.String label,
              java.lang.String auxLabel,
              int spNode)
Creates an edge with the given label, ID, successor and predecessor nodes, secondary label, and special relationship node.

Parameters:
id - ID of the new edge.
s - ID of the new edge's successor node.
p - ID of the new edge's predecessor node.
label - Label to be assigned to the new edge.
auxLabel - Secondary label to be assigned to the new edge.
spNode - ID of node to be marked as having a special relationship to this edge.

CFEdge

public CFEdge(int id,
              int s,
              int p,
              org.apache.bcel.generic.ObjectType type)
Creates an edge with the given label, ID, successor and predecessor nodes, and associated label type.

Parameters:
id - ID of the new edge.
s - ID of the new edge's successor node.
p - ID of the new edge's predecessor node.
type - Type which is associated with this edge.
Method Detail

getBranchID

public CFEdge.BranchID getBranchID(int index)
Gets a branch ID from this edge's branch ID set by index.

Branch IDs are stored in numerical order. This method iterates over the ID set and returns the ID produced by the iterator after index iterations.

Parameters:
index - Index of the branch ID to be retrieved from the ID set.
Returns:
The branch ID at the given index in this edge's branch ID set.

getBranchID

public CFEdge.BranchID getBranchID(SConstants.BranchType type)
Gets the branch ID associated with the given branch type.

If there is more than one branch ID with the same associated type, only the most specific branch ID is returned. In other words, the branch ID associated with this particular branch decision is returned rather than the ID of any logical branch edge encapsulating the current edge. This allows proper instrumentation and observation of decisions made inside of 'side loops'.

Parameters:
type - Type of the branch for which the associated branch ID is to be retrieved.
Returns:
The branch ID on this edge which is associated with the specified branch type.

getBranchIDArray

public CFEdge.BranchID[] getBranchIDArray()
Gets the branch IDs associated with this edge as an array.

The branch IDs stored in the array will be sorted numerically.

Returns:
A sorted array of the branch IDs associated with this edge.

getBranchIDSet

public java.util.SortedSet getBranchIDSet()
Gets the branch IDs associated with this edge as an unmodifiable sorted set.

Returns:
A sorted set containing the branch IDs associated with this edge.

setAuxLabel

public void setAuxLabel(java.lang.String s)
Sets the secondary label for this edge.

This field is used to record additional unique identifying information related to JSR and RET edges. It may be specific to the particular version of a class from which a CFG is built.

Parameters:
s - New secondary label to be assigned to this edge.

getAuxLabel

public java.lang.String getAuxLabel()
Gets the secondary label for this edge.

Returns:
The secondary label assigned to this edge. There is no general contract which requires that this label be version-independent.

setSpecialNodeID

public void setSpecialNodeID(int n)
Sets the ID of a node which has a special relationship to this edge.

This field is used in CFGs to store a reference in JSR edges to the block that contains the matching RET instruction.

Parameters:
n - ID of the node to be marked as having a special association with this edge.

getSpecialNodeID

public int getSpecialNodeID()
Gets the ID of a node which has a special relationship to this edge.

For JSR edges, this is expected to be the ID of the node containing the corresponding RET instruction.

Returns:
The ID of a node that has been marked as having a special relationship to this edge.

getLabelType

public org.apache.bcel.generic.Type getLabelType()
Gets the type associated with this edge's label.

Returns:
The type of the object that would cause this edge to be taken.

toString

public java.lang.String toString()
Returns a string representation of this edge in the form:
label: sourceNodeID -> sinkNodeID.

If the edge is unlabeled, the special token "(nl)" is used for the label.

Overrides:
toString in class Edge
Returns:
This edge represented as a string.

main

public static void main(java.lang.String[] args)
Test driver for the Edge class.