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

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.ForLoop
All Implemented Interfaces:
Iterable<Node>

public class ForLoop
extends Loop

Represents for 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
ForLoop(Tree tree, int scope, Node parent, LoopBlock loopBlock, List<InstructionHandle> instructions)
          Creates a new ForLoop object.
 
Method Summary
protected  InstructionHandle getFirstInstruction()
           
 Goto getGoto()
          Returns a handle to the goto instruction that is executed immediately after the for loop's increment expression.
 Statement getIncrStatement()
          Returns the increment statement of the for loop.
 Statement getInitStatement()
          Returns the intialization statement of the for loop.
protected  InstructionHandle getLastInstruction()
           
 int getStartAddress()
          Returns the starting address, relative to the method, of this loop.
 String toString()
          Converts the for loop to a string.
 
Methods inherited from class edu.uci.eecs.doc.cascade.controlflow.Loop
getBody, getCondition, getMethodInvocations, hasBody, setBody
 
Methods inherited from class edu.uci.eecs.doc.cascade.controlflow.Node
getBlock, getEnclosingLoop, getInstructions, getMethodInvocations, getNext, getOutermostLoop, getParent, getScope, getSourceCodeLineNumber, 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

ForLoop

public ForLoop(Tree tree,
               int scope,
               Node parent,
               LoopBlock loopBlock,
               List<InstructionHandle> instructions)
Creates a new ForLoop 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

getStartAddress

public int getStartAddress()
Returns the starting address, relative to the method, of this loop. The starting address of for loops is considered to be the conditional expression, not the initialization expression.

Overrides:
getStartAddress in class Node
Returns:
the zero-based address of the first bytecode instruction in this loop

getInitStatement

public Statement getInitStatement()
Returns the intialization statement of the for loop. For example, if the loop is for(i=0;i<10;i++), the initialization statement is i=0. Note that for loops might not have an initialization statement, and in such cases, this method returns null. Example: for ( ; val < 10; val++) ...

Returns:
a handle to the for loop's initialization statement, or null if the loop has no initialization statement

getIncrStatement

public Statement getIncrStatement()
Returns the increment statement of the for loop. For example, if the loop is for(i=0;i<10;i++), the initialization statement is i++.

Returns:
a handle to the for loop's increment statement

getGoto

public Goto getGoto()
Returns a handle to the goto instruction that is executed immediately after the for loop's increment expression. Unlike while loops, all for loops have a goto instruction, so this method should never return null.

Returns:
a handle to the goto instruction of the for loop

getFirstInstruction

protected InstructionHandle getFirstInstruction()
Overrides:
getFirstInstruction in class Node

getLastInstruction

protected InstructionHandle getLastInstruction()
Overrides:
getLastInstruction in class Node

toString

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

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