Package org.mozilla.javascript
Class IRFactory
java.lang.Object
org.mozilla.javascript.Parser
org.mozilla.javascript.IRFactory
This class rewrites the parse tree into an IR suitable for codegen.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class org.mozilla.javascript.Parser
Parser.PerFunctionVariables
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final int
private static final int
private Decompiler
private static final int
private static final int
private static final int
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 -
Method Summary
Modifier and TypeMethodDescriptionprivate static void
addSwitchCase
(Node switchBlock, Node caseExpression, Node statements) If caseExpression argument is null it indicates a default label.private Node
arrayCompTransformHelper
(ArrayComprehension node, 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
(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, String namespace, Node elem, int memberTypeFlags) private static Node
createExprStatementNoReturn
(Node expr, int lineno) private static Node
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
private static Node
createIncDec
(int nodeType, boolean post, Node child) private static Node
private Scope
createLoopNode
(Node loopLabel, int lineno) Create loop node.private Node
createMemberRefGet
(Node target, String namespace, Node elem, int memberTypeFlags) private Node
createPropertyGet
(Node target, String namespace, String name, int memberTypeFlags) private static Node
createString
(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
(package private) void
(package private) void
(package private) Node
(package private) void
(package private) void
private Node
private 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
private static Jump
private static Node
makeReference
(Node node) private Node
private Node
private 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
private Node
private Node
private Node
transformDoLoop
(DoLoop loop) private Node
private Node
private Node
transformForInLoop
(ForInLoop loop) private Node
transformForLoop
(ForLoop loop) private Node
private Node
private Node
private Node
private Node
private Node
private Node
transformLetNode
(LetNode node) private Node
transformLiteral
(AstNode node) private Node
transformName
(Name node) private Node
private Node
transformNumber
(NumberLiteral node) private Node
private Node
private Node
private Node
transformRegExp
(RegExpLiteral node) private Node
private Node
transformScript
(ScriptNode node) private Node
transformString
(StringLiteral node) private Node
private Node
private Node
private Node
transformThrow
(ThrowStatement node) transformTree
(AstRoot root) Transforms the tree into a lower-level IR suitable for codegen.private Node
transformTry
(TryStatement node) private Node
private Node
private Node
private Node
private Node
transformWhileLoop
(WhileLoop loop) private Node
transformWith
(WithStatement node) private Node
private 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 Details
-
LOOP_DO_WHILE
private static final int LOOP_DO_WHILE- See Also:
-
LOOP_WHILE
private static final int LOOP_WHILE- See Also:
-
LOOP_FOR
private static final int LOOP_FOR- See Also:
-
ALWAYS_TRUE_BOOLEAN
private static final int ALWAYS_TRUE_BOOLEAN- See Also:
-
ALWAYS_FALSE_BOOLEAN
private static final int ALWAYS_FALSE_BOOLEAN- See Also:
-
decompiler
-
-
Constructor Details
-
IRFactory
public IRFactory() -
IRFactory
-
IRFactory
-
-
Method Details
-
transformTree
Transforms the tree into a lower-level IR suitable for codegen. Optionally generates the encoded source. -
transform
-
transformArrayComp
-
arrayCompTransformHelper
-
transformArrayLiteral
-
transformAssignment
-
transformAssignmentLeft
-
transformBigInt
-
transformBlock
-
transformBreak
-
transformCondExpr
-
transformContinue
-
transformDoLoop
-
transformElementGet
-
transformExprStmt
-
transformForInLoop
-
transformForLoop
-
transformFunction
-
transformFunctionCall
-
transformGenExpr
-
genExprTransformHelper
-
transformIf
-
transformInfix
-
transformLabeledStatement
-
transformLetNode
-
transformLiteral
-
transformName
-
transformNewExpr
-
transformNumber
-
transformObjectLiteral
-
getPropKey
-
transformParenExpr
-
transformPropertyGet
-
transformTemplateLiteral
-
transformTemplateLiteralCall
-
transformRegExp
-
transformReturn
-
transformScript
-
transformString
-
transformSwitch
-
transformThrow
-
transformTry
-
transformUnary
-
transformUpdate
-
transformVariables
-
transformVariableInitializers
-
transformWhileLoop
-
transformWith
-
transformYield
-
transformXmlLiteral
-
transformXmlMemberGet
-
transformXmlRef
-
transformXmlRef
-
transformDefaultXmlNamepace
-
addSwitchCase
If caseExpression argument is null it indicates a default label. -
closeSwitch
-
createExprStatementNoReturn
-
createString
-
createCatch
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
Create loop node. The code generator will later call createWhile|createDoWhile|createFor|createForIn to finish loop generation. -
createFor
-
createLoop
-
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
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.
-
createWith
-
createIf
-
createCondExpr
-
createUnary
-
createCallOrNew
-
createIncDec
-
createPropertyGet
-
createElementGet
- Parameters:
target
- the node before the LBnamespace
- optional namespaceelem
- the node in the bracketsmemberTypeFlags
- E4X flags
-
createMemberRefGet
-
createBinary
-
createAssignment
-
createUseLocal
-
makeJump
-
makeReference
-
isAlwaysDefinedBoolean
-
isDestructuring
-
decompileFunctionHeader
-
decompile
-
decompileArrayLiteral
-
decompileObjectLiteral
-
decompilePropertyGet
-
decompileElementGet
-