Package org.mozilla.javascript
Class IRFactory
- java.lang.Object
-
- org.mozilla.javascript.Parser
-
- org.mozilla.javascript.IRFactory
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.mozilla.javascript.Parser
Parser.PerFunctionVariables
-
-
Field Summary
Fields Modifier and Type Field Description private static int
ALWAYS_FALSE_BOOLEAN
private static int
ALWAYS_TRUE_BOOLEAN
private Decompiler
decompiler
private static int
LOOP_DO_WHILE
private static int
LOOP_FOR
private static int
LOOP_WHILE
-
Fields inherited from class org.mozilla.javascript.Parser
ARGC_LIMIT, calledByCompileFunction, CLEAR_TI_MASK, compilerEnv, currentScope, currentScriptOrFn, inUseStrictDirective, nestingOfFunction, TI_AFTER_EOL, TI_CHECK_LABEL
-
-
Constructor Summary
Constructors Constructor Description IRFactory()
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 void
addSwitchCase(Node switchBlock, Node caseExpression, Node statements)
If caseExpression argument is null it indicates a default label.private Node
arrayCompTransformHelper(ArrayComprehension node, java.lang.String arrayName)
private static void
closeSwitch(Node switchBlock)
private Node
createAssignment(int assignType, Node left, Node right)
private static Node
createBinary(int nodeType, Node left, Node right)
private Node
createCallOrNew(int nodeType, Node child)
private Node
createCatch(java.lang.String varName, Node catchCond, Node stmts, int lineno)
Catch clause of try/catch/finallyprivate static Node
createCondExpr(Node cond, Node ifTrue, Node ifFalse)
private Node
createElementGet(Node target, java.lang.String namespace, Node elem, int memberTypeFlags)
private static Node
createExprStatementNoReturn(Node expr, int lineno)
private static Node
createFor(Scope loop, Node init, Node test, Node incr, Node body)
private Node
createForIn(int declType, Node loop, Node lhs, Node obj, Node body, boolean isForEach, boolean isForOf)
Generate IR for a for..in loop.private static Node
createIf(Node cond, Node ifTrue, Node ifFalse, int lineno)
private static Node
createIncDec(int nodeType, boolean post, Node child)
private static Node
createLoop(Jump loop, int loopType, Node body, Node cond, Node init, Node incr)
private Scope
createLoopNode(Node loopLabel, int lineno)
Create loop node.private Node
createMemberRefGet(Node target, java.lang.String namespace, Node elem, int memberTypeFlags)
private Node
createPropertyGet(Node target, java.lang.String namespace, java.lang.String name, int memberTypeFlags)
private static Node
createString(java.lang.String string)
private Node
createTryCatchFinally(Node tryBlock, Node catchBlocks, Node finallyBlock, int lineno)
Try/Catch/Finallyprivate static Node
createUnary(int nodeType, Node child)
private static Node
createUseLocal(Node localBlock)
private Node
createWith(Node obj, Node body, int lineno)
(package private) void
decompile(AstNode node)
(package private) void
decompileArrayLiteral(ArrayLiteral node)
(package private) void
decompileElementGet(ElementGet node)
(package private) Node
decompileFunctionHeader(FunctionNode fn)
(package private) void
decompileObjectLiteral(ObjectLiteral node)
(package private) void
decompilePropertyGet(PropertyGet node)
private Node
genExprTransformHelper(GeneratorExpression node)
private java.lang.Object
getPropKey(Node id)
private static Node
initFunction(FunctionNode fnNode, int functionIndex, Node statements, int functionType)
private static int
isAlwaysDefinedBoolean(Node node)
(package private) boolean
isDestructuring(Node n)
private static Jump
makeJump(int type, Node target)
private static Node
makeReference(Node node)
Node
transform(AstNode node)
private Node
transformArrayComp(ArrayComprehension node)
private Node
transformArrayLiteral(ArrayLiteral node)
private Node
transformAssignment(Assignment node)
private AstNode
transformAssignmentLeft(Assignment node, AstNode left, AstNode right)
private Node
transformBigInt(BigIntLiteral node)
private Node
transformBlock(AstNode node)
private Node
transformBreak(BreakStatement node)
private Node
transformCondExpr(ConditionalExpression node)
private Node
transformContinue(ContinueStatement node)
private Node
transformDefaultXmlNamepace(UnaryExpression node)
private Node
transformDoLoop(DoLoop loop)
private Node
transformElementGet(ElementGet node)
private Node
transformExprStmt(ExpressionStatement node)
private Node
transformForInLoop(ForInLoop loop)
private Node
transformForLoop(ForLoop loop)
private Node
transformFunction(FunctionNode fn)
private Node
transformFunctionCall(FunctionCall node)
private Node
transformGenExpr(GeneratorExpression node)
private Node
transformIf(IfStatement n)
private Node
transformInfix(InfixExpression node)
private Node
transformLabeledStatement(LabeledStatement ls)
private Node
transformLetNode(LetNode node)
private Node
transformLiteral(AstNode node)
private Node
transformName(Name node)
private Node
transformNewExpr(NewExpression node)
private Node
transformNumber(NumberLiteral node)
private Node
transformObjectLiteral(ObjectLiteral node)
private Node
transformParenExpr(ParenthesizedExpression node)
private Node
transformPropertyGet(PropertyGet node)
private Node
transformRegExp(RegExpLiteral node)
private Node
transformReturn(ReturnStatement node)
private Node
transformScript(ScriptNode node)
private Node
transformString(StringLiteral node)
private Node
transformSwitch(SwitchStatement node)
private Node
transformTemplateLiteral(TemplateLiteral node)
private Node
transformTemplateLiteralCall(TaggedTemplateLiteral node)
private Node
transformThrow(ThrowStatement node)
ScriptNode
transformTree(AstRoot root)
Transforms the tree into a lower-level IR suitable for codegen.private Node
transformTry(TryStatement node)
private Node
transformUnary(UnaryExpression node)
private Node
transformUpdate(UpdateExpression node)
private Node
transformVariableInitializers(VariableDeclaration node)
private Node
transformVariables(VariableDeclaration node)
private Node
transformWhileLoop(WhileLoop loop)
private Node
transformWith(WithStatement node)
private Node
transformXmlLiteral(XmlLiteral node)
private Node
transformXmlMemberGet(XmlMemberGet node)
private Node
transformXmlRef(XmlRef node)
private Node
transformXmlRef(Node pn, XmlRef node, int memberTypeFlags)
private Node
transformYield(Yield node)
-
Methods inherited from class org.mozilla.javascript.Parser
addError, addError, addError, addError, addError, addStrictWarning, addStrictWarning, addWarning, addWarning, addWarning, checkActivationName, checkMutableReference, createDestructuringAssignment, createName, createName, createNumber, createScopeNode, defineSymbol, defineSymbol, destructuringArray, destructuringAssignmentHelper, destructuringObject, eof, insideFunction, inUseStrictDirective, lookupMessage, lookupMessage, markDestructuring, parse, parse, popScope, pushScope, removeParens, reportError, reportError, reportError, reportError, setDefaultUseStrictDirective, setIsGenerator, setRequiresActivation, simpleAssignment
-
-
-
-
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
-
decompiler
private Decompiler decompiler
-
-
Constructor Detail
-
IRFactory
public IRFactory()
-
IRFactory
public IRFactory(CompilerEnvirons env)
-
IRFactory
public IRFactory(CompilerEnvirons env, ErrorReporter errorReporter)
-
-
Method Detail
-
transformTree
public ScriptNode transformTree(AstRoot root)
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(java.lang.String 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)
-
-