Package javassist.compiler
Class CodeGen
java.lang.Object
javassist.compiler.ast.Visitor
javassist.compiler.CodeGen
- Direct Known Subclasses:
MemberCodeGen
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static class
doit() in ReturnHook is called from atReturn(). -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected int
(package private) static final int[]
protected Bytecode
private static final int[]
protected String
protected int
protected boolean
true if the last visited node is a return statement.private static final int[]
private static final int[]
boolean
Must be true if compilation is for a static method.(package private) static final String
(package private) static final String
(package private) static final String
(package private) static final String
private static final int
private static final int
private static final int
private static final int
private static final int
protected CodeGen.ReturnHook
private int
(package private) TypeChecker
Fields inherited from interface javassist.bytecode.Opcode
AALOAD, AASTORE, ACONST_NULL, ALOAD, ALOAD_0, ALOAD_1, ALOAD_2, ALOAD_3, ANEWARRAY, ARETURN, ARRAYLENGTH, ASTORE, ASTORE_0, ASTORE_1, ASTORE_2, ASTORE_3, ATHROW, BALOAD, BASTORE, BIPUSH, CALOAD, CASTORE, CHECKCAST, D2F, D2I, D2L, DADD, DALOAD, DASTORE, DCMPG, DCMPL, DCONST_0, DCONST_1, DDIV, DLOAD, DLOAD_0, DLOAD_1, DLOAD_2, DLOAD_3, DMUL, DNEG, DREM, DRETURN, DSTORE, DSTORE_0, DSTORE_1, DSTORE_2, DSTORE_3, DSUB, DUP, DUP_X1, DUP_X2, DUP2, DUP2_X1, DUP2_X2, F2D, F2I, F2L, FADD, FALOAD, FASTORE, FCMPG, FCMPL, FCONST_0, FCONST_1, FCONST_2, FDIV, FLOAD, FLOAD_0, FLOAD_1, FLOAD_2, FLOAD_3, FMUL, FNEG, FREM, FRETURN, FSTORE, FSTORE_0, FSTORE_1, FSTORE_2, FSTORE_3, FSUB, GETFIELD, GETSTATIC, GOTO, GOTO_W, I2B, I2C, I2D, I2F, I2L, I2S, IADD, IALOAD, IAND, IASTORE, ICONST_0, ICONST_1, ICONST_2, ICONST_3, ICONST_4, ICONST_5, ICONST_M1, IDIV, IF_ACMPEQ, IF_ACMPNE, IF_ICMPEQ, IF_ICMPGE, IF_ICMPGT, IF_ICMPLE, IF_ICMPLT, IF_ICMPNE, IFEQ, IFGE, IFGT, IFLE, IFLT, IFNE, IFNONNULL, IFNULL, IINC, ILOAD, ILOAD_0, ILOAD_1, ILOAD_2, ILOAD_3, IMUL, INEG, INSTANCEOF, INVOKEDYNAMIC, INVOKEINTERFACE, INVOKESPECIAL, INVOKESTATIC, INVOKEVIRTUAL, IOR, IREM, IRETURN, ISHL, ISHR, ISTORE, ISTORE_0, ISTORE_1, ISTORE_2, ISTORE_3, ISUB, IUSHR, IXOR, JSR, JSR_W, L2D, L2F, L2I, LADD, LALOAD, LAND, LASTORE, LCMP, LCONST_0, LCONST_1, LDC, LDC_W, LDC2_W, LDIV, LLOAD, LLOAD_0, LLOAD_1, LLOAD_2, LLOAD_3, LMUL, LNEG, LOOKUPSWITCH, LOR, LREM, LRETURN, LSHL, LSHR, LSTORE, LSTORE_0, LSTORE_1, LSTORE_2, LSTORE_3, LSUB, LUSHR, LXOR, MONITORENTER, MONITOREXIT, MULTIANEWARRAY, NEW, NEWARRAY, NOP, POP, POP2, PUTFIELD, PUTSTATIC, RET, RETURN, SALOAD, SASTORE, SIPUSH, STACK_GROW, SWAP, T_BOOLEAN, T_BYTE, T_CHAR, T_DOUBLE, T_FLOAT, T_INT, T_LONG, T_SHORT, TABLESWITCH, WIDE
Fields inherited from interface javassist.compiler.TokenId
ABSTRACT, AND_E, ANDAND, ARRAY, ARSHIFT, ARSHIFT_E, assignOps, BadToken, BLOCK, BOOLEAN, BREAK, BYTE, CALL, CASE, CATCH, CHAR, CharConstant, CLASS, CONST, CONTINUE, DECL, DEFAULT, DIV_E, DO, DOUBLE, DoubleConstant, ELSE, EQ, EXOR_E, EXPR, EXTENDS, FALSE, FINAL, FINALLY, FLOAT, FloatConstant, FOR, GE, GOTO, Identifier, IF, IMPLEMENTS, IMPORT, INSTANCEOF, INT, IntConstant, INTERFACE, LABEL, LE, LONG, LongConstant, LSHIFT, LSHIFT_E, MEMBER, MINUS_E, MINUSMINUS, MOD_E, MUL_E, NATIVE, NEQ, NEW, NULL, opNames, OR_E, OROR, PACKAGE, PLUS_E, PLUSPLUS, PRIVATE, PROTECTED, PUBLIC, RETURN, RSHIFT, RSHIFT_E, SHORT, STATIC, STRICT, StringL, SUPER, SWITCH, SYNCHRONIZED, THIS, THROW, THROWS, TRANSIENT, TRUE, TRY, VOID, VOLATILE, WHILE
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected void
arrayAccess
(ASTree array, ASTree index) private void
atArithBinExpr
(Expr expr, int token, int index, int type1) private void
atArrayAssign
(Expr expr, int op, Expr array, ASTree right, boolean doDup) abstract void
atArrayInit
(ArrayInit init) void
atArrayPlusPlus
(int token, boolean isPost, Expr expr, boolean doDup) void
atArrayRead
(ASTree array, ASTree index) protected abstract void
atArrayVariableAssign
(ArrayInit init, int varType, int varArray, String varClass) protected void
atAssignCore
(Expr expr, int op, ASTree right, int type, int dim, String cname) void
atAssignExpr
(AssignExpr expr) protected void
atAssignExpr
(AssignExpr expr, boolean doDup) void
void
private void
atBreakStmnt
(Stmnt st, boolean notCont) abstract void
atCallExpr
(CallExpr expr) void
atCastExpr
(CastExpr expr) void
atClassObject
(Expr expr) protected void
atClassObject2
(String cname) void
atCondExpr
(CondExpr expr) void
void
void
protected abstract void
atFieldAssign
(Expr expr, int op, ASTree left, ASTree right, boolean doDup) void
atFieldDecl
(FieldDecl field) protected abstract void
atFieldPlusPlus
(int token, boolean isPost, ASTree oprand, Expr expr, boolean doDup) protected abstract void
atFieldRead
(ASTree expr) private void
atForStmnt
(Stmnt st) private void
void
void
void
abstract void
void
atMethodBody
(Stmnt s, boolean isCons, boolean isVoid) void
atMethodDecl
(MethodDecl method) abstract void
(package private) void
atNumCastExpr
(int srcType, int destType) void
private void
atPlusPlus
(int token, ASTree oprand, Expr expr, boolean doDup) protected void
atPlusPlusCore
(int dup_code, boolean doDup, int token, boolean isPost, Expr expr) protected void
atReturnStmnt
(Stmnt st) protected final void
atReturnStmnt2
(ASTree result) void
private void
atStringConcatExpr
(Expr expr, int type1, int dim1, String cname1) void
private void
atStringPlusEq
(Expr expr, int type, int dim, String cname, ASTree right) private void
atSwitchStmnt
(Stmnt st) void
private void
atSyncStmnt
(Stmnt st) private void
atThrowStmnt
(Stmnt st) protected void
atTryStmnt
(Stmnt st) void
private void
atVariableAssign
(Expr expr, int op, Variable var, Declarator d, ASTree right, boolean doDup) private void
atWhileStmnt
(Stmnt st, boolean notDo) protected static void
protected static void
protected static void
private boolean
booleanExpr
(boolean branchIf, ASTree expr) private String
checkCastExpr
(CastExpr expr, String name) private void
compareExpr
(boolean branchIf, int token, int type1, BinExpr expr) boolean
compileBooleanExpr
(boolean branchIf, ASTree expr) void
compileExpr
(ASTree expr) private int
compileOprands
(BinExpr expr) private int
computeLabel
(ASTree expr) private int
computeStringLabel
(ASTree expr, int tmpVar, List<Integer> gotoDefaults) private void
convertOprandTypes
(int type1, int type2, Expr expr) private void
convToString
(int type, int dim) void
doTypeCheck
(ASTree expr) protected static void
fatal()
protected static int
getArrayReadOp
(int type, int dim) protected static int
getArrayWriteOp
(int type, int dim) (package private) static int
getCompOperator
(ASTree expr) private static int
getListSize
(List<Integer> list) protected int
int
protected abstract String
Returns the JVM-internal representation of this super class name.protected int
Returns a local variable that single or double words can be stored in.protected abstract String
Returns the JVM-internal representation of this class name.protected void
incMaxLocals
(int size) protected abstract void
private boolean
invalidDim
(int srcType, int srcDim, String srcClass, int destType, int destDim, String destClass, boolean isCast) static boolean
is2word
(int type, int dim) private static boolean
isAlwaysBranch
(ASTree expr, boolean branchIf) (package private) static boolean
isP_INT
(int type) private static boolean
isPlusPlusExpr
(ASTree expr) protected static boolean
isRefType
(int type) (package private) static int
lookupBinOp
(int token) private boolean
needsSuperCall
(Stmnt body) protected void
protected abstract String
resolveClassName
(String jvmClassName) protected abstract String
resolveClassName
(ASTList name) (package private) static boolean
rightIsStrong
(int type1, int type2) void
setMaxLocals
(int n) void
setTypeChecker
(TypeChecker checker) protected static String
toJvmArrayName
(String name, int dim) protected static String
toJvmTypeName
(int type, int dim) private static int
typePrecedence
(int type)
-
Field Details
-
javaLangObject
- See Also:
-
jvmJavaLangObject
- See Also:
-
javaLangString
- See Also:
-
jvmJavaLangString
- See Also:
-
bytecode
-
tempVar
private int tempVar -
typeChecker
TypeChecker typeChecker -
hasReturned
protected boolean hasReturnedtrue if the last visited node is a return statement. -
inStaticMethod
public boolean inStaticMethodMust be true if compilation is for a static method. -
breakList
-
continueList
-
returnHooks
-
exprType
protected int exprType -
arrayDim
protected int arrayDim -
className
-
binOp
static final int[] binOp -
ifOp
private static final int[] ifOp -
ifOp2
private static final int[] ifOp2 -
P_DOUBLE
private static final int P_DOUBLE- See Also:
-
P_FLOAT
private static final int P_FLOAT- See Also:
-
P_LONG
private static final int P_LONG- See Also:
-
P_INT
private static final int P_INT- See Also:
-
P_OTHER
private static final int P_OTHER- See Also:
-
castOp
private static final int[] castOp
-
-
Constructor Details
-
CodeGen
-
-
Method Details
-
setTypeChecker
-
fatal
- Throws:
CompileError
-
is2word
public static boolean is2word(int type, int dim) -
getMaxLocals
public int getMaxLocals() -
setMaxLocals
public void setMaxLocals(int n) -
incMaxLocals
protected void incMaxLocals(int size) -
getTempVar
protected int getTempVar()Returns a local variable that single or double words can be stored in. -
getLocalVar
-
getThisName
Returns the JVM-internal representation of this class name. -
getSuperName
Returns the JVM-internal representation of this super class name.- Throws:
CompileError
-
resolveClassName
- Throws:
CompileError
-
resolveClassName
- Throws:
CompileError
-
toJvmArrayName
- Parameters:
name
- the JVM-internal representation. name is not exapnded to java.lang.*.
-
toJvmTypeName
-
compileExpr
- Throws:
CompileError
-
compileBooleanExpr
- Throws:
CompileError
-
doTypeCheck
- Throws:
CompileError
-
atASTList
- Overrides:
atASTList
in classVisitor
- Throws:
CompileError
-
atPair
- Overrides:
atPair
in classVisitor
- Throws:
CompileError
-
atSymbol
- Overrides:
atSymbol
in classVisitor
- Throws:
CompileError
-
atFieldDecl
- Overrides:
atFieldDecl
in classVisitor
- Throws:
CompileError
-
atMethodDecl
- Overrides:
atMethodDecl
in classVisitor
- Throws:
CompileError
-
atMethodBody
- Parameters:
isCons
- true if super() must be called. false if the method is a class initializer.- Throws:
CompileError
-
needsSuperCall
- Throws:
CompileError
-
insertDefaultSuperCall
- Throws:
CompileError
-
atStmnt
- Overrides:
atStmnt
in classVisitor
- Throws:
CompileError
-
atIfStmnt
- Throws:
CompileError
-
atWhileStmnt
- Throws:
CompileError
-
patchGoto
-
atForStmnt
- Throws:
CompileError
-
atSwitchStmnt
- Throws:
CompileError
-
computeLabel
- Throws:
CompileError
-
computeStringLabel
private int computeStringLabel(ASTree expr, int tmpVar, List<Integer> gotoDefaults) throws CompileError - Throws:
CompileError
-
atBreakStmnt
- Throws:
CompileError
-
atReturnStmnt
- Throws:
CompileError
-
atReturnStmnt2
- Throws:
CompileError
-
atThrowStmnt
- Throws:
CompileError
-
atTryStmnt
- Throws:
CompileError
-
atSyncStmnt
- Throws:
CompileError
-
getListSize
-
isPlusPlusExpr
-
atDeclarator
- Overrides:
atDeclarator
in classVisitor
- Throws:
CompileError
-
atNewExpr
- Overrides:
atNewExpr
in classVisitor
- Throws:
CompileError
-
atArrayInit
- Overrides:
atArrayInit
in classVisitor
- Throws:
CompileError
-
atAssignExpr
- Overrides:
atAssignExpr
in classVisitor
- Throws:
CompileError
-
atAssignExpr
- Throws:
CompileError
-
badAssign
- Throws:
CompileError
-
atVariableAssign
private void atVariableAssign(Expr expr, int op, Variable var, Declarator d, ASTree right, boolean doDup) throws CompileError - Throws:
CompileError
-
atArrayVariableAssign
protected abstract void atArrayVariableAssign(ArrayInit init, int varType, int varArray, String varClass) throws CompileError - Throws:
CompileError
-
atArrayAssign
private void atArrayAssign(Expr expr, int op, Expr array, ASTree right, boolean doDup) throws CompileError - Throws:
CompileError
-
atFieldAssign
protected abstract void atFieldAssign(Expr expr, int op, ASTree left, ASTree right, boolean doDup) throws CompileError - Throws:
CompileError
-
atAssignCore
protected void atAssignCore(Expr expr, int op, ASTree right, int type, int dim, String cname) throws CompileError - Throws:
CompileError
-
atStringPlusEq
private void atStringPlusEq(Expr expr, int type, int dim, String cname, ASTree right) throws CompileError - Throws:
CompileError
-
invalidDim
-
atCondExpr
- Overrides:
atCondExpr
in classVisitor
- Throws:
CompileError
-
lookupBinOp
static int lookupBinOp(int token) -
atBinExpr
- Overrides:
atBinExpr
in classVisitor
- Throws:
CompileError
-
atArithBinExpr
- Throws:
CompileError
-
atStringConcatExpr
- Throws:
CompileError
-
convToString
- Throws:
CompileError
-
booleanExpr
- Throws:
CompileError
-
isAlwaysBranch
-
getCompOperator
- Throws:
CompileError
-
compileOprands
- Throws:
CompileError
-
compareExpr
- Throws:
CompileError
-
badTypes
- Throws:
CompileError
-
isRefType
protected static boolean isRefType(int type) -
typePrecedence
private static int typePrecedence(int type) -
isP_INT
static boolean isP_INT(int type) -
rightIsStrong
static boolean rightIsStrong(int type1, int type2) -
convertOprandTypes
- Throws:
CompileError
-
atCastExpr
- Overrides:
atCastExpr
in classVisitor
- Throws:
CompileError
-
atInstanceOfExpr
- Overrides:
atInstanceOfExpr
in classVisitor
- Throws:
CompileError
-
checkCastExpr
- Throws:
CompileError
-
atNumCastExpr
- Throws:
CompileError
-
atExpr
- Overrides:
atExpr
in classVisitor
- Throws:
CompileError
-
badType
- Throws:
CompileError
-
atCallExpr
- Overrides:
atCallExpr
in classVisitor
- Throws:
CompileError
-
atFieldRead
- Throws:
CompileError
-
atClassObject
- Throws:
CompileError
-
atClassObject2
- Throws:
CompileError
-
atArrayRead
- Throws:
CompileError
-
arrayAccess
- Throws:
CompileError
-
getArrayReadOp
protected static int getArrayReadOp(int type, int dim) -
getArrayWriteOp
protected static int getArrayWriteOp(int type, int dim) -
atPlusPlus
- Throws:
CompileError
-
atArrayPlusPlus
public void atArrayPlusPlus(int token, boolean isPost, Expr expr, boolean doDup) throws CompileError - Throws:
CompileError
-
atPlusPlusCore
protected void atPlusPlusCore(int dup_code, boolean doDup, int token, boolean isPost, Expr expr) throws CompileError - Throws:
CompileError
-
atFieldPlusPlus
protected abstract void atFieldPlusPlus(int token, boolean isPost, ASTree oprand, Expr expr, boolean doDup) throws CompileError - Throws:
CompileError
-
atMember
- Overrides:
atMember
in classVisitor
- Throws:
CompileError
-
atVariable
- Overrides:
atVariable
in classVisitor
- Throws:
CompileError
-
atKeyword
- Overrides:
atKeyword
in classVisitor
- Throws:
CompileError
-
atStringL
- Overrides:
atStringL
in classVisitor
- Throws:
CompileError
-
atIntConst
- Overrides:
atIntConst
in classVisitor
- Throws:
CompileError
-
atDoubleConst
- Overrides:
atDoubleConst
in classVisitor
- Throws:
CompileError
-