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

java.lang.Object
  extended by edu.uci.eecs.doc.cascade.controlflow.Node
      extended by edu.uci.eecs.doc.cascade.controlflow.Loop
          extended by edu.uci.eecs.doc.cascade.controlflow.WhileLoop
All Implemented Interfaces:
Iterable<Node>

public class WhileLoop
extends Loop

Represents while loops in control flow graphs and trees.

Author:
Trevor Harmon

Field Summary
protected  Goto gotoNode
           
 
Fields inherited from class edu.uci.eecs.doc.cascade.controlflow.Loop
body, instructions
 
Fields inherited from class edu.uci.eecs.doc.cascade.controlflow.Node
block, nextNode, parent, scope, tree
 
Constructor Summary
WhileLoop(Tree tree, int scope, Node parent, LoopBlock loopBlock, List<InstructionHandle> instructions)
          Creates a new WhileLoop object.
 
Method Summary
 Goto getGoto()
          Returns a handle to the goto instruction that is executed at the end of the loop body in order to return control to the top of the loop.
protected  InstructionHandle getLastInstruction()
           
 void setBody(Node body)
          Sets the body of the loop.
 String toString()
          Converts the while loop to a string.
 
Methods inherited from class edu.uci.eecs.doc.cascade.controlflow.Loop
getBody, getCondition, getMethodInvocations, hasBody
 
Methods inherited from class edu.uci.eecs.doc.cascade.controlflow.Node
getBlock, getEnclosingLoop, getFirstInstruction, getInstructions, 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, wait, wait, wait
 

Field Detail

gotoNode

protected Goto gotoNode
Constructor Detail

WhileLoop

public WhileLoop(Tree tree,
                 int scope,
                 Node parent,
                 LoopBlock loopBlock,
                 List<InstructionHandle> instructions)
Creates a new WhileLoop 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 while loop
instructions - the list of instructions in the loop's method (the whole method, not just the loop)
Method Detail

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.

Overrides:
setBody in class Loop
Parameters:
body - a control flow node representing the loop's body

getGoto

public Goto getGoto()
Returns a handle to the goto instruction that is executed at the end of the loop body in order to return control to the top of the loop. Note that some while loop constructs will not have a goto instruction as the last instruction in the body, or they may have no goto instruction at all. In these cases, this method returns null. For example, this while loop has no goto instruction whatsoever:
 while (val > 3)
 {
     if (b) return;
 }
 

Returns:
a handle to the goto instruction of the for loop, or null if the last instruction in the loop body is not a goto instruction

getLastInstruction

protected InstructionHandle getLastInstruction()
Overrides:
getLastInstruction in class Node

toString

public String toString()
Converts the while loop to a string.

Overrides:
toString in class Object
Returns:
a source-code-like string representing the while loop