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

java.lang.Object
  extended by edu.uci.eecs.doc.cascade.controlflow.Node
      extended by edu.uci.eecs.doc.cascade.controlflow.Loop
All Implemented Interfaces:
Iterable<Node>
Direct Known Subclasses:
DoWhileLoop, ForLoop, WhileLoop

public class Loop
extends Node

A base class to represent loop constructs in control flow graphs and trees.

Author:
Trevor Harmon

Field Summary
protected  Node body
           
protected  List<InstructionHandle> instructions
           
 
Fields inherited from class edu.uci.eecs.doc.cascade.controlflow.Node
block, nextNode, parent, scope, tree
 
Constructor Summary
protected Loop(Tree tree, int scope, Node parent, LoopBlock loopBlock, List<InstructionHandle> instructions)
          Creates a new Loop object.
 
Method Summary
 Node getBody()
          Returns the control flow of the loop body, or null if the loop body is empty.
protected  Expression getCondition()
          Returns the conditional expression of the loop (e.g., i<10)
 List<MethodInvocation> getMethodInvocations()
          Returns the methods invoked by the loop's conditional expression in the order in which they are invoked.
 boolean hasBody()
          Returns true if the loop has a body.
 void setBody(Node body)
          Sets the body of the loop.
 
Methods inherited from class edu.uci.eecs.doc.cascade.controlflow.Node
getBlock, getEnclosingLoop, getFirstInstruction, getInstructions, getLastInstruction, getMethodInvocations, getNext, getOutermostLoop, getParent, getScope, getSourceCodeLineNumber, getStartAddress, getTree, iterator, lastNode, setNext
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

body

protected Node body

instructions

protected List<InstructionHandle> instructions
Constructor Detail

Loop

protected Loop(Tree tree,
               int scope,
               Node parent,
               LoopBlock loopBlock,
               List<InstructionHandle> instructions)
Creates a new Loop object.

Parameters:
tree - the control flow tree to which this node belongs
scope - the lexical scope of the node (0 = top-level scope)
parent - the node's parent (null if the node has no parent)
loopBlock - a JODE object representing the for loop
instructions - the list of instructions in the loop's method (the whole method, not just the loop)
Method Detail

getMethodInvocations

public List<MethodInvocation> getMethodInvocations()
Returns the methods invoked by the loop's conditional expression in the order in which they are invoked. (Methods invoked by the loop body are not included.) If the same method is invoked more than once, it will appear in the list more than once.

Overrides:
getMethodInvocations in class Node
Returns:
a list of Java method handles, or an empty list if this expression does not invoke any methods

getBody

public Node getBody()
Returns the control flow of the loop body, or null if the loop body is empty.

Returns:
a control flow node representing the loop's body, or null if the loop has no body (in the case of a "for" loop, the body is null only if the increment statement is also null)

setBody

public void setBody(Node body)
Sets the body of the loop. This may be necessary if, for example, the loop body is determined to be empty and needs to be "fixed up" accordingly.

Parameters:
body - a control flow node representing the loop's body

hasBody

public boolean hasBody()
Returns true if the loop has a body. Note that goto nodes and increment statements (in for loops) are not considered part of the "body". Therefore, calling getBody() may return a valid node (e.g., a goto node) even if this method return false.

Returns:
true if the node has a body; false otherwise

getCondition

protected Expression getCondition()
Returns the conditional expression of the loop (e.g., i<10)

Returns:
a JODE object representing an expression