com.singularsys.aa.manipulation
Class ConstantFolder

java.lang.Object
  extended by com.singularsys.aa.manipulation.ConstantFolder
All Implemented Interfaces:
org.nfunk.jep.ParserVisitor

public class ConstantFolder
extends java.lang.Object
implements org.nfunk.jep.ParserVisitor

Combines constants.

 Folding Constants
   fun(C1, C2, ...) ->  C3
 


Constructor Summary
ConstantFolder()
          Creates new ConstantFolder
 
Method Summary
 org.nfunk.jep.Node foldCommutative(org.nfunk.jep.ASTFunNode node)
          Combines all constant children of a function node into constant child.
 org.nfunk.jep.Node foldConstants(org.nfunk.jep.Node topNode)
          Combine the constants in the expression (only one iteration).
 java.lang.Object visit(org.nfunk.jep.ASTConstant node, java.lang.Object data)
           
 java.lang.Object visit(org.nfunk.jep.ASTFunNode node, java.lang.Object data)
           
 java.lang.Object visit(org.nfunk.jep.ASTStart node, java.lang.Object data)
           
 java.lang.Object visit(org.nfunk.jep.ASTVarNode node, java.lang.Object data)
           
 java.lang.Object visit(org.nfunk.jep.SimpleNode node, java.lang.Object data)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConstantFolder

public ConstantFolder()
Creates new ConstantFolder

Method Detail

foldConstants

public org.nfunk.jep.Node foldConstants(org.nfunk.jep.Node topNode)
Combine the constants in the expression (only one iteration). The expression will not be completely reduced with only one call to this function. It should be called repeatedly until no changes are found.


visit

public java.lang.Object visit(org.nfunk.jep.ASTFunNode node,
                              java.lang.Object data)
Specified by:
visit in interface org.nfunk.jep.ParserVisitor

visit

public java.lang.Object visit(org.nfunk.jep.ASTConstant node,
                              java.lang.Object data)
Specified by:
visit in interface org.nfunk.jep.ParserVisitor

visit

public java.lang.Object visit(org.nfunk.jep.ASTVarNode node,
                              java.lang.Object data)
Specified by:
visit in interface org.nfunk.jep.ParserVisitor

visit

public java.lang.Object visit(org.nfunk.jep.ASTStart node,
                              java.lang.Object data)
Specified by:
visit in interface org.nfunk.jep.ParserVisitor

visit

public java.lang.Object visit(org.nfunk.jep.SimpleNode node,
                              java.lang.Object data)
Specified by:
visit in interface org.nfunk.jep.ParserVisitor

foldCommutative

public org.nfunk.jep.Node foldCommutative(org.nfunk.jep.ASTFunNode node)
Combines all constant children of a function node into constant child. If all children are constant, the function node is replaced by a single constant.
        (?)            (?)
      / / \ \    ->   / | \
     a 1   b 2       3  a  b