Class IRFactory

java.lang.Object
org.htmlunit.corejs.javascript.IRFactory

public final class IRFactory extends Object
This class rewrites the parse tree into an IR suitable for codegen.
See Also:
  • Field Details

  • Constructor Details

  • Method Details

    • transformTree

      public ScriptNode transformTree(AstRoot root, String sourceString)
      Transforms the tree into a lower-level IR suitable for codegen. Optionally generates the encoded source.
    • transform

      public Node transform(AstNode node)
    • transformArrayComp

      private Node transformArrayComp(ArrayComprehension node)
    • arrayCompTransformHelper

      private Node arrayCompTransformHelper(ArrayComprehension node, String arrayName)
    • transformArrayLiteral

      private Node transformArrayLiteral(ArrayLiteral node)
    • transformAssignment

      private Node transformAssignment(Assignment node)
    • transformAssignmentLeft

      private AstNode transformAssignmentLeft(Assignment node, AstNode left, AstNode right)
    • transformBigInt

      private Node transformBigInt(BigIntLiteral node)
    • transformBlock

      private Node transformBlock(AstNode node)
    • transformBreak

      private Node transformBreak(BreakStatement node)
    • transformCondExpr

      private Node transformCondExpr(ConditionalExpression node)
    • transformContinue

      private Node transformContinue(ContinueStatement node)
    • transformDoLoop

      private Node transformDoLoop(DoLoop loop)
    • transformElementGet

      private Node transformElementGet(ElementGet node)
    • transformExprStmt

      private Node transformExprStmt(ExpressionStatement node)
    • transformForInLoop

      private Node transformForInLoop(ForInLoop loop)
    • transformForLoop

      private Node transformForLoop(ForLoop loop)
    • transformFunction

      private Node transformFunction(FunctionNode fn)
    • transformFunctionCall

      private Node transformFunctionCall(FunctionCall node)
    • transformGenExpr

      private Node transformGenExpr(GeneratorExpression node)
    • genExprTransformHelper

      private Node genExprTransformHelper(GeneratorExpression node)
    • transformIf

      private Node transformIf(IfStatement n)
    • transformInfix

      private Node transformInfix(InfixExpression node)
    • transformLabeledStatement

      private Node transformLabeledStatement(LabeledStatement ls)
    • transformLetNode

      private Node transformLetNode(LetNode node)
    • transformLiteral

      private Node transformLiteral(AstNode node)
    • transformName

      private Node transformName(Name node)
    • transformNewExpr

      private Node transformNewExpr(NewExpression node)
    • transformNumber

      private Node transformNumber(NumberLiteral node)
    • transformObjectLiteral

      private Node transformObjectLiteral(ObjectLiteral node)
    • getPropKey

      private Object getPropKey(Node id)
    • transformParenExpr

      private Node transformParenExpr(ParenthesizedExpression node)
    • transformPropertyGet

      private Node transformPropertyGet(PropertyGet node)
    • transformTemplateLiteral

      private Node transformTemplateLiteral(TemplateLiteral node)
    • transformTemplateLiteralCall

      private Node transformTemplateLiteralCall(TaggedTemplateLiteral node)
    • transformRegExp

      private Node transformRegExp(RegExpLiteral node)
    • transformReturn

      private Node transformReturn(ReturnStatement node)
    • transformScript

      private Node transformScript(ScriptNode node)
    • transformString

      private Node transformString(StringLiteral node)
    • transformSwitch

      private Node transformSwitch(SwitchStatement node)
    • transformThrow

      private Node transformThrow(ThrowStatement node)
    • transformTry

      private Node transformTry(TryStatement node)
    • transformUnary

      private Node transformUnary(UnaryExpression node)
    • transformUpdate

      private Node transformUpdate(UpdateExpression node)
    • transformVariables

      private Node transformVariables(VariableDeclaration node)
    • transformVariableInitializers

      private Node transformVariableInitializers(VariableDeclaration node)
    • transformWhileLoop

      private Node transformWhileLoop(WhileLoop loop)
    • transformWith

      private Node transformWith(WithStatement node)
    • transformYield

      private Node transformYield(Yield node)
    • transformXmlLiteral

      private Node transformXmlLiteral(XmlLiteral node)
    • transformXmlMemberGet

      private Node transformXmlMemberGet(XmlMemberGet node)
    • transformXmlRef

      private Node transformXmlRef(XmlRef node)
    • transformXmlRef

      private Node transformXmlRef(Node pn, XmlRef node, int memberTypeFlags)
    • transformDefaultXmlNamepace

      private Node transformDefaultXmlNamepace(UnaryExpression node)
    • addSwitchCase

      private static void addSwitchCase(Node switchBlock, Node caseExpression, Node statements)
      If caseExpression argument is null it indicates a default label.
    • closeSwitch

      private static void closeSwitch(Node switchBlock)
    • createExprStatementNoReturn

      private static Node createExprStatementNoReturn(Node expr, int lineno)
    • createString

      private static Node createString(String string)
    • createCatch

      private Node createCatch(Node varName, Node catchCond, Node 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
    • initFunction

      private static Node initFunction(FunctionNode fnNode, int functionIndex, Node statements, int functionType)
    • createLoopNode

      private Scope createLoopNode(Node loopLabel, int lineno)
      Create loop node. The code generator will later call createWhile|createDoWhile|createFor|createForIn to finish loop generation.
    • createFor

      private static Node createFor(Scope loop, Node init, Node test, Node incr, Node body)
    • createLoop

      private static Node createLoop(Jump loop, int loopType, Node body, Node cond, Node init, Node incr)
    • createForIn

      private Node createForIn(int declType, Node loop, Node lhs, Node obj, Node body, boolean isForEach, boolean isForOf)
      Generate IR for a for..in loop.
    • createTryCatchFinally

      private Node createTryCatchFinally(Node tryBlock, Node catchBlocks, Node 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

      - a finally handler

      ... and a goto to GOTO around these handlers.

    • createWith

      private Node createWith(Node obj, Node body, int lineno)
    • createIf

      private static Node createIf(Node cond, Node ifTrue, Node ifFalse, int lineno)
    • createCondExpr

      private static Node createCondExpr(Node cond, Node ifTrue, Node ifFalse)
    • createUnary

      private static Node createUnary(int nodeType, Node child)
    • createCallOrNew

      private Node createCallOrNew(int nodeType, Node child)
    • createIncDec

      private static Node createIncDec(int nodeType, boolean post, Node child)
    • createPropertyGet

      private Node createPropertyGet(Node target, String namespace, String name, int memberTypeFlags)
    • createElementGet

      private Node createElementGet(Node target, String namespace, Node elem, int memberTypeFlags)
      Parameters:
      target - the node before the LB
      namespace - optional namespace
      elem - the node in the brackets
      memberTypeFlags - E4X flags
    • createMemberRefGet

      private Node createMemberRefGet(Node target, String namespace, Node elem, int memberTypeFlags)
    • createBinary

      private static Node createBinary(int nodeType, Node left, Node right)
    • createAssignment

      private Node createAssignment(int assignType, Node left, Node right)
    • createUseLocal

      private static Node createUseLocal(Node localBlock)
    • makeJump

      private static Jump makeJump(int type, Node target)
    • makeReference

      private static Node makeReference(Node node)
    • isAlwaysDefinedBoolean

      private static int isAlwaysDefinedBoolean(Node node)
    • isDestructuring

      boolean isDestructuring(Node n)
    • decompileFunctionHeader

      Node decompileFunctionHeader(FunctionNode fn)
    • decompile

      void decompile(AstNode node)
    • decompileArrayLiteral

      void decompileArrayLiteral(ArrayLiteral node)
    • decompileObjectLiteral

      void decompileObjectLiteral(ObjectLiteral node)
    • decompilePropertyGet

      void decompilePropertyGet(PropertyGet node)
    • decompileElementGet

      void decompileElementGet(ElementGet node)