Package org.htmlunit.corejs.javascript
Class IRFactory
- java.lang.Object
-
- org.htmlunit.corejs.javascript.IRFactory
-
public final class IRFactory extends java.lang.ObjectThis class rewrites the parse tree into an IR suitable for codegen.- See Also:
Node
-
-
Field Summary
Fields Modifier and Type Field Description private static intALWAYS_FALSE_BOOLEANprivate static intALWAYS_TRUE_BOOLEANprivate static intLOOP_DO_WHILEprivate static intLOOP_FORprivate static intLOOP_WHILEprivate Parserparser
-
Constructor Summary
Constructors Constructor Description IRFactory(CompilerEnvirons env)IRFactory(CompilerEnvirons env, ErrorReporter errorReporter)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static voidaddSwitchCase(Node switchBlock, Node caseExpression, Node statements)If caseExpression argument is null it indicates a default label.private NodearrayCompTransformHelper(ArrayComprehension node, java.lang.String arrayName)private static voidcloseSwitch(Node switchBlock)private NodecreateAssignment(int assignType, Node left, Node right)private static NodecreateBinary(int nodeType, Node left, Node right)private NodecreateCallOrNew(int nodeType, Node child)private NodecreateCatch(Node varName, Node catchCond, Node stmts, int lineno)Catch clause of try/catch/finallyprivate static NodecreateCondExpr(Node cond, Node ifTrue, Node ifFalse)private NodecreateElementGet(Node target, java.lang.String namespace, Node elem, int memberTypeFlags)private static NodecreateExprStatementNoReturn(Node expr, int lineno)private static NodecreateFor(Scope loop, Node init, Node test, Node incr, Node body)private NodecreateForIn(int declType, Node loop, Node lhs, Node obj, Node body, boolean isForEach, boolean isForOf)Generate IR for a for..in loop.private static NodecreateIf(Node cond, Node ifTrue, Node ifFalse, int lineno)private static NodecreateIncDec(int nodeType, boolean post, Node child)private static NodecreateLoop(Jump loop, int loopType, Node body, Node cond, Node init, Node incr)private ScopecreateLoopNode(Node loopLabel, int lineno)Create loop node.private NodecreateMemberRefGet(Node target, java.lang.String namespace, Node elem, int memberTypeFlags)private NodecreatePropertyGet(Node target, java.lang.String namespace, java.lang.String name, int memberTypeFlags)private static NodecreateString(java.lang.String string)private NodecreateTryCatchFinally(Node tryBlock, Node catchBlocks, Node finallyBlock, int lineno)Try/Catch/Finallyprivate static NodecreateUnary(int nodeType, Node child)private static NodecreateUseLocal(Node localBlock)private NodecreateWith(Node obj, Node body, int lineno)(package private) voiddecompile(AstNode node)(package private) voiddecompileArrayLiteral(ArrayLiteral node)(package private) voiddecompileElementGet(ElementGet node)(package private) NodedecompileFunctionHeader(FunctionNode fn)(package private) voiddecompileObjectLiteral(ObjectLiteral node)(package private) voiddecompilePropertyGet(PropertyGet node)private NodegenExprTransformHelper(GeneratorExpression node)private java.lang.ObjectgetPropKey(Node id)private static NodeinitFunction(FunctionNode fnNode, int functionIndex, Node statements, int functionType)private static intisAlwaysDefinedBoolean(Node node)(package private) booleanisDestructuring(Node n)private static JumpmakeJump(int type, Node target)private static NodemakeReference(Node node)Nodetransform(AstNode node)private NodetransformArrayComp(ArrayComprehension node)private NodetransformArrayLiteral(ArrayLiteral node)private NodetransformAssignment(Assignment node)private AstNodetransformAssignmentLeft(Assignment node, AstNode left, AstNode right)private NodetransformBigInt(BigIntLiteral node)private NodetransformBlock(AstNode node)private NodetransformBreak(BreakStatement node)private NodetransformCondExpr(ConditionalExpression node)private NodetransformContinue(ContinueStatement node)private NodetransformDefaultXmlNamepace(UnaryExpression node)private NodetransformDoLoop(DoLoop loop)private NodetransformElementGet(ElementGet node)private NodetransformExprStmt(ExpressionStatement node)private NodetransformForInLoop(ForInLoop loop)private NodetransformForLoop(ForLoop loop)private NodetransformFunction(FunctionNode fn)private NodetransformFunctionCall(FunctionCall node)private NodetransformGenExpr(GeneratorExpression node)private NodetransformIf(IfStatement n)private NodetransformInfix(InfixExpression node)private NodetransformLabeledStatement(LabeledStatement ls)private NodetransformLetNode(LetNode node)private NodetransformLiteral(AstNode node)private NodetransformName(Name node)private NodetransformNewExpr(NewExpression node)private NodetransformNumber(NumberLiteral node)private NodetransformObjectLiteral(ObjectLiteral node)private NodetransformParenExpr(ParenthesizedExpression node)private NodetransformPropertyGet(PropertyGet node)private NodetransformRegExp(RegExpLiteral node)private NodetransformReturn(ReturnStatement node)private NodetransformScript(ScriptNode node)private NodetransformString(StringLiteral node)private NodetransformSwitch(SwitchStatement node)private NodetransformTemplateLiteral(TemplateLiteral node)private NodetransformTemplateLiteralCall(TaggedTemplateLiteral node)private NodetransformThrow(ThrowStatement node)ScriptNodetransformTree(AstRoot root, java.lang.String sourceString)Transforms the tree into a lower-level IR suitable for codegen.private NodetransformTry(TryStatement node)private NodetransformUnary(UnaryExpression node)private NodetransformUpdate(UpdateExpression node)private NodetransformVariableInitializers(VariableDeclaration node)private NodetransformVariables(VariableDeclaration node)private NodetransformWhileLoop(WhileLoop loop)private NodetransformWith(WithStatement node)private NodetransformXmlLiteral(XmlLiteral node)private NodetransformXmlMemberGet(XmlMemberGet node)private NodetransformXmlRef(XmlRef node)private NodetransformXmlRef(Node pn, XmlRef node, int memberTypeFlags)private NodetransformYield(Yield node)
-
-
-
Field Detail
-
LOOP_DO_WHILE
private static final int LOOP_DO_WHILE
- See Also:
- Constant Field Values
-
LOOP_WHILE
private static final int LOOP_WHILE
- See Also:
- Constant Field Values
-
LOOP_FOR
private static final int LOOP_FOR
- See Also:
- Constant Field Values
-
ALWAYS_TRUE_BOOLEAN
private static final int ALWAYS_TRUE_BOOLEAN
- See Also:
- Constant Field Values
-
ALWAYS_FALSE_BOOLEAN
private static final int ALWAYS_FALSE_BOOLEAN
- See Also:
- Constant Field Values
-
parser
private Parser parser
-
-
Constructor Detail
-
IRFactory
public IRFactory(CompilerEnvirons env)
-
IRFactory
public IRFactory(CompilerEnvirons env, ErrorReporter errorReporter)
-
-
Method Detail
-
transformTree
public ScriptNode transformTree(AstRoot root, java.lang.String sourceString)
Transforms the tree into a lower-level IR suitable for codegen. Optionally generates the encoded source.
-
transformArrayComp
private Node transformArrayComp(ArrayComprehension node)
-
arrayCompTransformHelper
private Node arrayCompTransformHelper(ArrayComprehension node, java.lang.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)
-
transformBreak
private Node transformBreak(BreakStatement node)
-
transformCondExpr
private Node transformCondExpr(ConditionalExpression node)
-
transformContinue
private Node transformContinue(ContinueStatement node)
-
transformElementGet
private Node transformElementGet(ElementGet node)
-
transformExprStmt
private Node transformExprStmt(ExpressionStatement node)
-
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)
-
transformNewExpr
private Node transformNewExpr(NewExpression node)
-
transformNumber
private Node transformNumber(NumberLiteral node)
-
transformObjectLiteral
private Node transformObjectLiteral(ObjectLiteral node)
-
getPropKey
private java.lang.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)
-
transformWith
private Node transformWith(WithStatement node)
-
transformXmlLiteral
private Node transformXmlLiteral(XmlLiteral node)
-
transformXmlMemberGet
private Node transformXmlMemberGet(XmlMemberGet node)
-
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)
-
createString
private static Node createString(java.lang.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 exceptioncatchCond- the condition under which to catch the exception. May be null if no condition is given.stmts- the statements in the catch clauselineno- 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.
-
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/FinallyThe 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.
-
createPropertyGet
private Node createPropertyGet(Node target, java.lang.String namespace, java.lang.String name, int memberTypeFlags)
-
createElementGet
private Node createElementGet(Node target, java.lang.String namespace, Node elem, int memberTypeFlags)
- Parameters:
target- the node before the LBnamespace- optional namespaceelem- the node in the bracketsmemberTypeFlags- E4X flags
-
createMemberRefGet
private Node createMemberRefGet(Node target, java.lang.String namespace, Node elem, int memberTypeFlags)
-
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)
-
-