org.mozilla.javascript
Class IRFactory

java.lang.Object
  |
  +--org.mozilla.javascript.IRFactory
Direct Known Subclasses:
OptIRFactory

public class IRFactory
extends java.lang.Object

This class allows the creation of nodes, and follows the Factory pattern.

Author:
Mike McCabe, Norris Boyd
See Also:
Node

Constructor Summary
IRFactory(TokenStream ts, Scriptable scope)
           
 
Method Summary
 void addChildToBack(java.lang.Object parent, java.lang.Object child)
          Add a child to the back of the given node.
 java.lang.Object createArrayLiteral(java.lang.Object obj)
          Array Literal
createArrayLiteral rewrites its argument as array creation plus a series of array element entries, so later compiler stages don't need to know about array literals.
 java.lang.Object createAssignment(int nodeOp, Node left, Node right, java.lang.Class convert, boolean postfix)
           
 java.lang.Object createBinary(int nodeType, int nodeOp, java.lang.Object left, java.lang.Object right)
           
 java.lang.Object createBinary(int nodeType, java.lang.Object left, java.lang.Object right)
          Binary
 java.lang.Object createBlock(int lineno)
          Statement block Creates the empty statement block Must make subsequent calls to add statements to the node
 java.lang.Object createBreak(java.lang.String label, int lineno)
          Break (possibly labeled)
 java.lang.Object createCatch(java.lang.String varName, java.lang.Object catchCond, java.lang.Object stmts, int lineno)
          Catch clause of try/catch/finally
 java.lang.Object createContinue(java.lang.String label, int lineno)
          Continue (possibly labeled)
 java.lang.Object createDoWhile(java.lang.Object body, java.lang.Object cond, int lineno)
          DoWhile
 java.lang.Object createExprStatement(java.lang.Object expr, int lineno)
           
 java.lang.Object createFor(java.lang.Object init, java.lang.Object test, java.lang.Object incr, java.lang.Object body, int lineno)
          For
 java.lang.Object createForIn(java.lang.Object lhs, java.lang.Object obj, java.lang.Object body, int lineno)
          For ..
 java.lang.Object createFunction(java.lang.String name, java.lang.Object args, java.lang.Object statements, java.lang.String sourceName, int baseLineno, int endLineno, java.lang.Object source, boolean isExpr)
           
 java.lang.Object createFunctionNode(java.lang.String name, java.lang.Object args, java.lang.Object statements)
           
 java.lang.Object createIf(java.lang.Object cond, java.lang.Object ifTrue, java.lang.Object ifFalse, int lineno)
          If statement
 java.lang.Object createLabel(java.lang.String label, int lineno)
          Label
 java.lang.Object createLeaf(int nodeType)
          Leaf
 java.lang.Object createLeaf(int nodeType, int nodeOp)
           
 java.lang.Object createLeaf(int nodeType, java.lang.String id)
           
 java.lang.Object createName(java.lang.String name)
          Name
 Node createNewLocal(Node n)
           
 Node createNewTemp(Node n)
           
 java.lang.Object createNumber(double number)
          Number (for literals)
 java.lang.Object createObjectLiteral(java.lang.Object obj)
          Object Literals
createObjectLiteral rewrites its argument as object creation plus object property entries, so later compiler stages don't need to know about object literals.
 java.lang.Object createRegExp(java.lang.String string, java.lang.String flags)
          Regular expressions
 java.lang.Object createReturn(java.lang.Object expr, int lineno)
          Return
 java.lang.Object createScript(java.lang.Object body, java.lang.String sourceName, int baseLineno, int endLineno, java.lang.Object source)
          Script (for associating file/url names with toplevel scripts.)
 java.lang.Object createString(java.lang.String string)
          String (for literals)
 java.lang.Object createSwitch(int lineno)
          Statement leaf nodes.
 java.lang.Object createTernary(java.lang.Object cond, java.lang.Object ifTrue, java.lang.Object ifFalse)
           
 java.lang.Object createThrow(java.lang.Object expr, int lineno)
          Throw
 java.lang.Object createTryCatchFinally(java.lang.Object tryblock, java.lang.Object catchblocks, java.lang.Object finallyblock, int lineno)
          Try/Catch/Finally The IRFactory tries to express as much as possible in the tree; the responsibilities remaining for Codegen are to add the Java handlers: (Either (but not both) of TARGET and FINALLY might not be defined) - a catch handler for javascript exceptions that unwraps the exception onto the stack and GOTOes to the catch target - TARGET_PROP in the try node.
 java.lang.Object createUnary(int nodeType, int nodeOp, java.lang.Object child)
           
 java.lang.Object createUnary(int nodeType, java.lang.Object child)
          Unary
 Node createUseLocal(Node newLocal)
           
 Node createUseTemp(Node newTemp)
           
 java.lang.Object createVariables(int lineno)
           
 java.lang.Object createWhile(java.lang.Object cond, java.lang.Object body, int lineno)
          While
 java.lang.Object createWith(java.lang.Object obj, java.lang.Object body, int lineno)
          With
 int getLeafType(java.lang.Object leaf)
           
static boolean hasSideEffects(Node exprTree)
           
 void setFunctionExpressionStatement(java.lang.Object o)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IRFactory

public IRFactory(TokenStream ts,
                 Scriptable scope)
Method Detail

createScript

public java.lang.Object createScript(java.lang.Object body,
                                     java.lang.String sourceName,
                                     int baseLineno,
                                     int endLineno,
                                     java.lang.Object source)
Script (for associating file/url names with toplevel scripts.)

createLeaf

public java.lang.Object createLeaf(int nodeType)
Leaf

createLeaf

public java.lang.Object createLeaf(int nodeType,
                                   java.lang.String id)

createLeaf

public java.lang.Object createLeaf(int nodeType,
                                   int nodeOp)

getLeafType

public int getLeafType(java.lang.Object leaf)

createSwitch

public java.lang.Object createSwitch(int lineno)
Statement leaf nodes.

createVariables

public java.lang.Object createVariables(int lineno)

createExprStatement

public java.lang.Object createExprStatement(java.lang.Object expr,
                                            int lineno)

createName

public java.lang.Object createName(java.lang.String name)
Name

createString

public java.lang.Object createString(java.lang.String string)
String (for literals)

createNumber

public java.lang.Object createNumber(double number)
Number (for literals)

createCatch

public java.lang.Object createCatch(java.lang.String varName,
                                    java.lang.Object catchCond,
                                    java.lang.Object stmts,
                                    int lineno)
Catch clause of try/catch/finally
Parameters:
varName - the name of the variable to bind to the exception
catchCond - the condition under which to catch the exception. May be null if no condition is given.
stmts - the statements in the catch clause
lineno - the starting line number of the catch clause

createThrow

public java.lang.Object createThrow(java.lang.Object expr,
                                    int lineno)
Throw

createReturn

public java.lang.Object createReturn(java.lang.Object expr,
                                     int lineno)
Return

createLabel

public java.lang.Object createLabel(java.lang.String label,
                                    int lineno)
Label

createBreak

public java.lang.Object createBreak(java.lang.String label,
                                    int lineno)
Break (possibly labeled)

createContinue

public java.lang.Object createContinue(java.lang.String label,
                                       int lineno)
Continue (possibly labeled)

createBlock

public java.lang.Object createBlock(int lineno)
Statement block Creates the empty statement block Must make subsequent calls to add statements to the node

createFunctionNode

public java.lang.Object createFunctionNode(java.lang.String name,
                                           java.lang.Object args,
                                           java.lang.Object statements)

createFunction

public java.lang.Object createFunction(java.lang.String name,
                                       java.lang.Object args,
                                       java.lang.Object statements,
                                       java.lang.String sourceName,
                                       int baseLineno,
                                       int endLineno,
                                       java.lang.Object source,
                                       boolean isExpr)

setFunctionExpressionStatement

public void setFunctionExpressionStatement(java.lang.Object o)

addChildToBack

public void addChildToBack(java.lang.Object parent,
                           java.lang.Object child)
Add a child to the back of the given node. This function breaks the Factory abstraction, but it removes a requirement from implementors of Node.

createWhile

public java.lang.Object createWhile(java.lang.Object cond,
                                    java.lang.Object body,
                                    int lineno)
While

createDoWhile

public java.lang.Object createDoWhile(java.lang.Object body,
                                      java.lang.Object cond,
                                      int lineno)
DoWhile

createFor

public java.lang.Object createFor(java.lang.Object init,
                                  java.lang.Object test,
                                  java.lang.Object incr,
                                  java.lang.Object body,
                                  int lineno)
For

createForIn

public java.lang.Object createForIn(java.lang.Object lhs,
                                    java.lang.Object obj,
                                    java.lang.Object body,
                                    int lineno)
For .. In

createTryCatchFinally

public java.lang.Object createTryCatchFinally(java.lang.Object tryblock,
                                              java.lang.Object catchblocks,
                                              java.lang.Object finallyblock,
                                              int lineno)
Try/Catch/Finally The IRFactory tries to express as much as possible in the tree; the responsibilities remaining for Codegen are to add the Java handlers: (Either (but not both) of TARGET and FINALLY might not be defined) - a catch handler for javascript exceptions that unwraps the exception onto the stack and GOTOes to the catch target - TARGET_PROP in the try node. - a finally handler that catches any exception, stores it to a temporary, and JSRs to the finally target - FINALLY_PROP in the try node - before re-throwing the exception. ... and a goto to GOTO around these handlers.

createWith

public java.lang.Object createWith(java.lang.Object obj,
                                   java.lang.Object body,
                                   int lineno)
With

createArrayLiteral

public java.lang.Object createArrayLiteral(java.lang.Object obj)
Array Literal
createArrayLiteral rewrites its argument as array creation plus a series of array element entries, so later compiler stages don't need to know about array literals.

createObjectLiteral

public java.lang.Object createObjectLiteral(java.lang.Object obj)
Object Literals
createObjectLiteral rewrites its argument as object creation plus object property entries, so later compiler stages don't need to know about object literals.

createRegExp

public java.lang.Object createRegExp(java.lang.String string,
                                     java.lang.String flags)
Regular expressions

createIf

public java.lang.Object createIf(java.lang.Object cond,
                                 java.lang.Object ifTrue,
                                 java.lang.Object ifFalse,
                                 int lineno)
If statement

createTernary

public java.lang.Object createTernary(java.lang.Object cond,
                                      java.lang.Object ifTrue,
                                      java.lang.Object ifFalse)

createUnary

public java.lang.Object createUnary(int nodeType,
                                    java.lang.Object child)
Unary

createUnary

public java.lang.Object createUnary(int nodeType,
                                    int nodeOp,
                                    java.lang.Object child)

createBinary

public java.lang.Object createBinary(int nodeType,
                                     java.lang.Object left,
                                     java.lang.Object right)
Binary

createBinary

public java.lang.Object createBinary(int nodeType,
                                     int nodeOp,
                                     java.lang.Object left,
                                     java.lang.Object right)

createAssignment

public java.lang.Object createAssignment(int nodeOp,
                                         Node left,
                                         Node right,
                                         java.lang.Class convert,
                                         boolean postfix)

createNewTemp

public Node createNewTemp(Node n)

createUseTemp

public Node createUseTemp(Node newTemp)

createNewLocal

public Node createNewLocal(Node n)

createUseLocal

public Node createUseLocal(Node newLocal)

hasSideEffects

public static boolean hasSideEffects(Node exprTree)