polyglot.visit
Class NodeScrambler

java.lang.Object
  extended bypolyglot.visit.NodeVisitor
      extended bypolyglot.visit.NodeScrambler

public class NodeScrambler
extends NodeVisitor

The NodeScrambler is test case generator of sorts. Since it is ofter useful to introduce ``random'' errors into source code, this class provides a way of doing so in a semi-structed manner. The process takes place in two phases. First, a "FirstPass" is made to collect a list of nodes and their parents. Then a second pass is made to randomly replace a branch of the tree with another suitable branch.


Nested Class Summary
 class NodeScrambler.FirstPass
          Scans throught the AST, create a list of all nodes present, along with the set of parents for each node in the tree.
 
Field Summary
protected  java.util.LinkedList currentParents
           
protected  CodeWriter cw
           
 NodeScrambler.FirstPass fp
           
protected  java.util.LinkedList nodes
           
protected  java.util.HashMap pairs
           
protected  java.util.Random ran
           
protected  boolean scrambled
           
protected  long seed
           
 
Constructor Summary
NodeScrambler()
           
NodeScrambler(long seed)
          Create a new NodeScrambler with the given random number generator seed.
 
Method Summary
protected  boolean coinFlip()
           
 long getSeed()
           
 Node override(Node n)
           
protected  Node potentialScramble(Node n)
           
 
Methods inherited from class polyglot.visit.NodeVisitor
begin, enter, enter, finish, finish, leave, leave, override, toString, visitEdge
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

fp

public NodeScrambler.FirstPass fp

pairs

protected java.util.HashMap pairs

nodes

protected java.util.LinkedList nodes

currentParents

protected java.util.LinkedList currentParents

seed

protected long seed

ran

protected java.util.Random ran

scrambled

protected boolean scrambled

cw

protected CodeWriter cw
Constructor Detail

NodeScrambler

public NodeScrambler()

NodeScrambler

public NodeScrambler(long seed)
Create a new NodeScrambler with the given random number generator seed.

Method Detail

getSeed

public long getSeed()

override

public Node override(Node n)
Overrides:
override in class NodeVisitor

coinFlip

protected boolean coinFlip()

potentialScramble

protected Node potentialScramble(Node n)