edu.uci.eecs.doc.cascade.controlflow
Class Node

java.lang.Object
  extended by edu.uci.eecs.doc.cascade.controlflow.Node
All Implemented Interfaces:
Iterable<Node>
Direct Known Subclasses:
Do, Else, Goto, IfThenElse, Loop, Statement

public class Node
extends Object
implements Iterable<Node>

A base class for source code constructs in control flow graphs and trees.

Author:
Trevor Harmon

Field Summary
protected  StructuredBlock block
           
protected  Node nextNode
           
protected  Node parent
           
protected  int scope
           
protected  Tree tree
           
 
Constructor Summary
protected Node(Tree tree, int scope, Node parent)
           
 
Method Summary
 StructuredBlock getBlock()
          Returns a handle to the corresponding JODE object representing this node.
 Loop getEnclosingLoop()
          Returns a handle to the node's enclosing loop, if one exists.
protected  InstructionHandle getFirstInstruction()
           
 List<InstructionHandle> getInstructions()
          Returns the list of instructions that correspond to this control flow node.
protected  InstructionHandle getLastInstruction()
           
 List<MethodInvocation> getMethodInvocations()
          Returns the methods that this node invokes in the order in which they are invoked.
protected  List<MethodInvocation> getMethodInvocations(Operator operator)
           
 Node getNext()
          Returns the next node in this node's scope (lexical level).
 Loop getOutermostLoop()
          Returns the outermost enclosing loop of this node.
 Node getParent()
          Returns the parent of the given node.
 int getScope()
          Returns the lexical scope of this node.
 int getSourceCodeLineNumber()
          Returns the line number of the source code on which this node begins.
 int getStartAddress()
          Returns the address in the bytecode where this node begins.
 Tree getTree()
          Returns the control flow tree to which this node belongs.
 Iterator<Node> iterator()
          Returns an iterator that iterates over this node and all of its children.
 Node lastNode()
          This helper function walks this node's scope (lexical level) and returns the last one it sees.
 void setNext(Node nextNode)
          Sets the next node in this node's scope (lexical level).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

nextNode

protected Node nextNode

parent

protected Node parent

block

protected StructuredBlock block

scope

protected int scope

tree

protected Tree tree
Constructor Detail

Node

protected Node(Tree tree,
               int scope,
               Node parent)
Method Detail

getTree

public Tree getTree()
Returns the control flow tree to which this node belongs.

Returns:
a control flow tree

getScope

public int getScope()
Returns the lexical scope of this node. Nodes at the top level are at scope 0, nodes in the next level down are at scope 1, etc. For example:
 void foobar(int i) {
   if (i == 42)   // scope 0
     i++;         // scope 1
   i *= 9;        // scope 0
   ...
 

Returns:
a non-negative integer representing the node's scope (0 = top-level scope)

getParent

public Node getParent()
Returns the parent of the given node. For example:
 void foobar(int i) {
   if (i == 42)   // parent is null
     i++;         // parent is if-then-else node
   i *= 9;        // parent is null
   ...
 

Returns:
a node representing the node's parent, or null if the node has no parent

iterator

public Iterator<Node> iterator()
Returns an iterator that iterates over this node and all of its children.

Specified by:
iterator in interface Iterable<Node>
Returns:
a node iterator
See Also:
TreeIterator

getNext

public Node getNext()
Returns the next node in this node's scope (lexical level). For example, if this node is val*=10 in the following code, then getNext() would return a node representing b=true. But if this node is i--, then getNext() returns null.
 if (i > 0)
 {
     val *= 10;
     b = true;
     i--;
 }
 

Returns:
the next node, or null if there are no more nodes in this node's scope

setNext

public void setNext(Node nextNode)
Sets the next node in this node's scope (lexical level). The next node may be null if this node is the last one in its scope.

Parameters:
nextNode - the next node

getBlock

public StructuredBlock getBlock()
Returns a handle to the corresponding JODE object representing this node. Some nodes have no corresponding JODE object, in which case this method returns null.

Returns:
the JODE object corresponding to this node, or null if the node has no corresponding JODE object

getInstructions

public List<InstructionHandle> getInstructions()
Returns the list of instructions that correspond to this control flow node. Sub-classes may need to override this method, if, for example, the node has no corresponding JODE block (i.e., if getBlock() returns null), to avoid null pointer exceptions.

Returns:
a list of bytecode instructions

getMethodInvocations

public List<MethodInvocation> getMethodInvocations()
Returns the methods that this node invokes in the order in which they are invoked. If the same method is invoked more than once, it will appear in the list more than once.

Returns:
an empty list (abstract nodes do not invoke any methods)

getStartAddress

public int getStartAddress()
Returns the address in the bytecode where this node begins.

Returns:
a zero-based code offset

getSourceCodeLineNumber

public int getSourceCodeLineNumber()
                            throws UnknownLineNumberException
Returns the line number of the source code on which this node begins.

Returns:
a one-based source code line number
Throws:
UnknownLineNumberException - if the line number for the node could not be determined

lastNode

public Node lastNode()
This helper function walks this node's scope (lexical level) and returns the last one it sees.

Returns:
the last node in this node's scope

getEnclosingLoop

public Loop getEnclosingLoop()
Returns a handle to the node's enclosing loop, if one exists. Only the node's containing method is considered, not the entire call tree. For example, given a node NODE, calling NODE.getEnclosingLoop() returns a handle to the for loop:
 for (...)
 {
    NODE
 }
 
but in this example, calling NODE.getEnclosingLoop() returns null:
 for (...)
 {
    myMethod();
 }
 void myMethod()
 {
    NODE
 }
 

Returns:
a node representing the enclosing loop, or null if the node is not part of a loop body
See Also:
getOutermostLoop()

getOutermostLoop

public Loop getOutermostLoop()
Returns the outermost enclosing loop of this node. It works just like getEnclosingLoop, but it returns the outermost instead of innermost loop.

Returns:
a node representing the outermost loop, or null if the node is not part of a loop body
See Also:
getEnclosingLoop()

getFirstInstruction

protected InstructionHandle getFirstInstruction()

getLastInstruction

protected InstructionHandle getLastInstruction()

getMethodInvocations

protected List<MethodInvocation> getMethodInvocations(Operator operator)