Package org.mozilla.javascript
Class CodeGenerator
- java.lang.Object
-
- org.mozilla.javascript.Icode
-
- org.mozilla.javascript.CodeGenerator
-
class CodeGenerator extends Icode
Generates bytecode for the Interpreter.
-
-
Field Summary
Fields Modifier and Type Field Description private CompilerEnvirons
compilerEnv
private int
doubleTableTop
private static int
ECF_TAIL
private int
exceptionTableTop
private long[]
fixupTable
private int
fixupTableTop
private int
iCodeTop
private InterpreterData
itsData
private boolean
itsInFunctionFlag
private boolean
itsInTryFlag
private int[]
labelTable
private int
labelTableTop
private int
lineNumber
private ObjArray
literalIds
private int
localTop
private static int
MIN_FIXUP_TABLE_SIZE
private static int
MIN_LABEL_TABLE_SIZE
private ScriptNode
scriptOrFn
private int
stackDepth
private ObjToIntMap
strings
-
Fields inherited from class org.mozilla.javascript.Icode
Icode_CALLSPECIAL, Icode_CLOSURE_EXPR, Icode_CLOSURE_STMT, Icode_DEBUGGER, Icode_DELNAME, Icode_DUP, Icode_DUP2, Icode_ELEM_AND_THIS, Icode_ELEM_INC_DEC, Icode_ENTERDQ, Icode_GENERATOR, Icode_GENERATOR_END, Icode_GENERATOR_RETURN, Icode_GETVAR1, Icode_GOSUB, Icode_IFEQ_POP, Icode_INTNUMBER, Icode_LEAVEDQ, Icode_LINE, Icode_LITERAL_GETTER, Icode_LITERAL_NEW, Icode_LITERAL_SET, Icode_LITERAL_SETTER, Icode_LOCAL_CLEAR, Icode_NAME_AND_THIS, Icode_NAME_INC_DEC, Icode_ONE, Icode_POP, Icode_POP_RESULT, Icode_PROP_AND_THIS, Icode_PROP_INC_DEC, Icode_REF_INC_DEC, Icode_REG_IND_C0, Icode_REG_IND_C1, Icode_REG_IND_C2, Icode_REG_IND_C3, Icode_REG_IND_C4, Icode_REG_IND_C5, Icode_REG_IND1, Icode_REG_IND2, Icode_REG_IND4, Icode_REG_STR_C0, Icode_REG_STR_C1, Icode_REG_STR_C2, Icode_REG_STR_C3, Icode_REG_STR1, Icode_REG_STR2, Icode_REG_STR4, Icode_RETSUB, Icode_RETUNDEF, Icode_SCOPE_LOAD, Icode_SCOPE_SAVE, Icode_SETCONST, Icode_SETCONSTVAR, Icode_SETCONSTVAR1, Icode_SETVAR1, Icode_SHORTNUMBER, Icode_SPARE_ARRAYLIT, Icode_STARTSUB, Icode_SWAP, Icode_TAIL_CALL, Icode_TYPEOFNAME, Icode_UNDEF, Icode_VALUE_AND_THIS, Icode_VAR_INC_DEC, Icode_YIELD_STAR, Icode_ZERO, MIN_ICODE
-
-
Constructor Summary
Constructors Constructor Description CodeGenerator()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
addBackwardGoto(int gotoOp, int jumpPC)
private void
addExceptionHandler(int icodeStart, int icodeEnd, int handlerStart, boolean isFinally, int exceptionObjectLocal, int scopeLocal)
private void
addGoto(Node target, int gotoOp)
private void
addGotoOp(int gotoOp)
private void
addIcode(int icode)
private void
addIndexOp(int op, int index)
private void
addIndexPrefix(int index)
private void
addInt(int i)
private void
addStringOp(int op, java.lang.String str)
private void
addStringPrefix(java.lang.String str)
private void
addToken(int token)
private void
addUint16(int value)
private void
addUint8(int value)
private void
addVarOp(int op, int varIndex)
private int
allocLocal()
private static java.lang.RuntimeException
badTree(Node node)
InterpreterData
compile(CompilerEnvirons compilerEnv, ScriptNode tree, java.lang.String encodedSource, boolean returnFunction)
private void
fixLabelGotos()
private void
generateCallFunAndThis(Node left)
private void
generateFunctionICode()
private void
generateICodeFromTree(Node tree)
private void
generateNestedFunctions()
private void
generateRegExpLiterals()
private int
getDoubleIndex(double num)
private static int
getLocalBlockRef(Node node)
private int
getTargetLabel(Node target)
private byte[]
increaseICodeCapacity(int extraSize)
private void
markTargetLabel(Node target)
private void
releaseLocal(int localSlot)
private void
resolveForwardGoto(int fromPC)
private void
resolveGoto(int fromPC, int jumpPC)
private void
stackChange(int change)
private void
updateLineNumber(Node node)
private void
visitArrayComprehension(Node node, Node initStmt, Node expr)
private void
visitExpression(Node node, int contextFlags)
private void
visitIncDec(Node node, Node child)
private void
visitLiteral(Node node, Node child)
private void
visitStatement(Node node, int initialStackDepth)
-
Methods inherited from class org.mozilla.javascript.Icode
bytecodeName, validBytecode, validIcode, validTokenCode
-
-
-
-
Field Detail
-
MIN_LABEL_TABLE_SIZE
private static final int MIN_LABEL_TABLE_SIZE
- See Also:
- Constant Field Values
-
MIN_FIXUP_TABLE_SIZE
private static final int MIN_FIXUP_TABLE_SIZE
- See Also:
- Constant Field Values
-
compilerEnv
private CompilerEnvirons compilerEnv
-
itsInFunctionFlag
private boolean itsInFunctionFlag
-
itsInTryFlag
private boolean itsInTryFlag
-
itsData
private InterpreterData itsData
-
scriptOrFn
private ScriptNode scriptOrFn
-
iCodeTop
private int iCodeTop
-
stackDepth
private int stackDepth
-
lineNumber
private int lineNumber
-
doubleTableTop
private int doubleTableTop
-
strings
private ObjToIntMap strings
-
localTop
private int localTop
-
labelTable
private int[] labelTable
-
labelTableTop
private int labelTableTop
-
fixupTable
private long[] fixupTable
-
fixupTableTop
private int fixupTableTop
-
literalIds
private ObjArray literalIds
-
exceptionTableTop
private int exceptionTableTop
-
ECF_TAIL
private static final int ECF_TAIL
- See Also:
- Constant Field Values
-
-
Method Detail
-
compile
public InterpreterData compile(CompilerEnvirons compilerEnv, ScriptNode tree, java.lang.String encodedSource, boolean returnFunction)
-
generateFunctionICode
private void generateFunctionICode()
-
generateICodeFromTree
private void generateICodeFromTree(Node tree)
-
generateNestedFunctions
private void generateNestedFunctions()
-
generateRegExpLiterals
private void generateRegExpLiterals()
-
updateLineNumber
private void updateLineNumber(Node node)
-
badTree
private static java.lang.RuntimeException badTree(Node node)
-
visitStatement
private void visitStatement(Node node, int initialStackDepth)
-
visitExpression
private void visitExpression(Node node, int contextFlags)
-
generateCallFunAndThis
private void generateCallFunAndThis(Node left)
-
getLocalBlockRef
private static int getLocalBlockRef(Node node)
-
getTargetLabel
private int getTargetLabel(Node target)
-
markTargetLabel
private void markTargetLabel(Node target)
-
addGoto
private void addGoto(Node target, int gotoOp)
-
fixLabelGotos
private void fixLabelGotos()
-
addBackwardGoto
private void addBackwardGoto(int gotoOp, int jumpPC)
-
resolveForwardGoto
private void resolveForwardGoto(int fromPC)
-
resolveGoto
private void resolveGoto(int fromPC, int jumpPC)
-
addToken
private void addToken(int token)
-
addIcode
private void addIcode(int icode)
-
addUint8
private void addUint8(int value)
-
addUint16
private void addUint16(int value)
-
addInt
private void addInt(int i)
-
getDoubleIndex
private int getDoubleIndex(double num)
-
addGotoOp
private void addGotoOp(int gotoOp)
-
addVarOp
private void addVarOp(int op, int varIndex)
-
addStringOp
private void addStringOp(int op, java.lang.String str)
-
addIndexOp
private void addIndexOp(int op, int index)
-
addStringPrefix
private void addStringPrefix(java.lang.String str)
-
addIndexPrefix
private void addIndexPrefix(int index)
-
addExceptionHandler
private void addExceptionHandler(int icodeStart, int icodeEnd, int handlerStart, boolean isFinally, int exceptionObjectLocal, int scopeLocal)
-
increaseICodeCapacity
private byte[] increaseICodeCapacity(int extraSize)
-
stackChange
private void stackChange(int change)
-
allocLocal
private int allocLocal()
-
releaseLocal
private void releaseLocal(int localSlot)
-
-