polyglot.visit
Class LoopNormalizer

java.lang.Object
  extended by polyglot.visit.NodeVisitor
      extended by polyglot.visit.LoopNormalizer
All Implemented Interfaces:
java.lang.Cloneable, Copy

public class LoopNormalizer
extends NodeVisitor

Turns all loops into while(true) loops.


Field Summary
protected  Job job
           
protected  NodeFactory nf
           
protected  TypeSystem ts
           
 
Constructor Summary
LoopNormalizer(Job job, TypeSystem ts, NodeFactory nf)
           
 
Method Summary
protected  void addInits(java.util.List stmts, For source)
           
protected  Eval createAssign(LocalDecl var)
           
protected  Eval createAssign(LocalDecl var, Expr right)
           
protected  Block createBlock()
           
protected  Block createBlock(java.util.List stmts)
           
protected  BooleanLit createBool(boolean val)
           
protected  If createInitIf(LocalDecl var, Expr cond)
           
protected  If createIterIf(LocalDecl var, java.util.List iters)
           
protected  Local createLocal(LocalInstance li, Position pos)
           
protected  While createLoop(Loop source)
           
protected  If createLoopIf(LocalDecl var, Stmt body)
           
protected  LocalDecl createLoopVar(Loop source)
           
protected  LocalDecl createLoopVar(Loop source, Expr cond)
           
 Node leave(Node parent, Node old, Node n, NodeVisitor v)
          This method is called after all of the children of n have been visited.
protected  java.lang.String newId()
           
protected  Node postCreate(Node n)
          Whenever a new node is created, this method is called and should do additional processing of the node as needed.
protected  Stmt translateDo(Do s)
           
protected  Stmt translateFor(For s)
           
protected  Stmt translateWhile(While s)
           
 
Methods inherited from class polyglot.visit.NodeVisitor
begin, copy, enter, enter, finish, finish, leave, override, override, toString, visitEdge, visitEdgeNoOverride
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

job

protected final Job job

ts

protected final TypeSystem ts

nf

protected final NodeFactory nf
Constructor Detail

LoopNormalizer

public LoopNormalizer(Job job,
                      TypeSystem ts,
                      NodeFactory nf)
Method Detail

leave

public Node leave(Node parent,
                  Node old,
                  Node n,
                  NodeVisitor v)
Description copied from class: NodeVisitor
This method is called after all of the children of n have been visited. In this case, these children were visited by the visitor v. This is the last chance for the visitor to modify the tree rooted at n. This method will be called exactly the same number of times as entry is called. That is, for each node that is not overriden, enter and leave are each called exactly once.

Note that if old == n then the vistior should make a copy of n before modifying it. It should then return the modified copy.

The default implementation of this method is to call leave(old, n, v), as most subclasses do not need to know the parent of the node n.

Overrides:
leave in class NodeVisitor
Parameters:
parent - The parent of old, null if old has no parent.
old - The original state of root of the current subtree.
n - The current state of the root of the current subtree.
v - The NodeVisitor object used to visit the children.
Returns:
The final result of the traversal of the tree rooted at n.

postCreate

protected Node postCreate(Node n)
Whenever a new node is created, this method is called and should do additional processing of the node as needed.


newId

protected java.lang.String newId()

createBlock

protected Block createBlock(java.util.List stmts)

createBlock

protected Block createBlock()

createLoop

protected While createLoop(Loop source)

createLoopVar

protected LocalDecl createLoopVar(Loop source,
                                  Expr cond)

createLoopVar

protected LocalDecl createLoopVar(Loop source)

createLoopIf

protected If createLoopIf(LocalDecl var,
                          Stmt body)

createAssign

protected Eval createAssign(LocalDecl var,
                            Expr right)

createAssign

protected Eval createAssign(LocalDecl var)

createInitIf

protected If createInitIf(LocalDecl var,
                          Expr cond)

createIterIf

protected If createIterIf(LocalDecl var,
                          java.util.List iters)

createLocal

protected Local createLocal(LocalInstance li,
                            Position pos)

addInits

protected void addInits(java.util.List stmts,
                        For source)

createBool

protected BooleanLit createBool(boolean val)

translateWhile

protected Stmt translateWhile(While s)

translateDo

protected Stmt translateDo(Do s)

translateFor

protected Stmt translateFor(For s)