Class CodeGen
- java.lang.Object
-
- org.hotswap.agent.javassist.compiler.ast.Visitor
-
- org.hotswap.agent.javassist.compiler.CodeGen
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classCodeGen.ReturnHookdoit() in ReturnHook is called from atReturn().
-
Field Summary
Fields Modifier and Type Field Description protected intarrayDimprotected List<Integer>breakListprotected Bytecodebytecodeprotected StringclassNameprotected List<Integer>continueListprotected intexprTypeprotected booleanhasReturnedtrue if the last visited node is a return statement.booleaninStaticMethodMust be true if compilation is for a static method.protected CodeGen.ReturnHookreturnHooks-
Fields inherited from interface org.hotswap.agent.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, 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, CHECKCAST, 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_DOUBLE, T_FLOAT, T_CHAR, T_INT, T_LONG, T_SHORT, TABLESWITCH, WIDE
-
Fields inherited from interface org.hotswap.agent.javassist.compiler.TokenId
ABSTRACT, AND_E, ANDAND, ARRAY, ARSHIFT, ARSHIFT_E, assignOps, BadToken, BLOCK, BOOLEAN, BREAK, BYTE, CALL, CASE, CATCH, CLASS, CONST, CONTINUE, DECL, DEFAULT, DIV_E, DO, DOUBLE, DoubleConstant, ELSE, EQ, EXOR_E, EXPR, EXTENDS, FALSE, FINAL, FINALLY, FLOAT, FloatConstant, FOR, GE, GOTO, CHAR, CharConstant, 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
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected voidarrayAccess(ASTree array, ASTree index)abstract voidatArrayInit(ArrayInit init)voidatArrayPlusPlus(int token, boolean isPost, Expr expr, boolean doDup)voidatArrayRead(ASTree array, ASTree index)protected abstract voidatArrayVariableAssign(ArrayInit init, int varType, int varArray, String varClass)protected voidatAssignCore(Expr expr, int op, ASTree right, int type, int dim, String cname)voidatAssignExpr(AssignExpr expr)protected voidatAssignExpr(AssignExpr expr, boolean doDup)voidatASTList(ASTList n)voidatBinExpr(BinExpr expr)abstract voidatCallExpr(CallExpr expr)voidatCastExpr(CastExpr expr)voidatClassObject(Expr expr)protected voidatClassObject2(String cname)voidatCondExpr(CondExpr expr)voidatDeclarator(Declarator d)voidatDoubleConst(DoubleConst d)voidatExpr(Expr expr)protected abstract voidatFieldAssign(Expr expr, int op, ASTree left, ASTree right, boolean doDup)voidatFieldDecl(FieldDecl field)protected abstract voidatFieldPlusPlus(int token, boolean isPost, ASTree oprand, Expr expr, boolean doDup)protected abstract voidatFieldRead(ASTree expr)voidatInstanceOfExpr(InstanceOfExpr expr)voidatIntConst(IntConst i)voidatKeyword(Keyword k)abstract voidatMember(Member n)voidatMethodBody(Stmnt s, boolean isCons, boolean isVoid)voidatMethodDecl(MethodDecl method)abstract voidatNewExpr(NewExpr n)voidatPair(Pair n)protected voidatPlusPlusCore(int dup_code, boolean doDup, int token, boolean isPost, Expr expr)protected voidatReturnStmnt(Stmnt st)protected voidatReturnStmnt2(ASTree result)voidatStmnt(Stmnt st)voidatStringL(StringL s)voidatSymbol(Symbol n)protected voidatTryStmnt(Stmnt st)voidatVariable(Variable v)protected static voidbadAssign(Expr expr)protected static voidbadType(Expr expr)protected static voidbadTypes(Expr expr)booleancompileBooleanExpr(boolean branchIf, ASTree expr)voidcompileExpr(ASTree expr)voiddoTypeCheck(ASTree expr)protected static voidfatal()protected static intgetArrayReadOp(int type, int dim)protected static intgetArrayWriteOp(int type, int dim)protected intgetLocalVar(Declarator d)intgetMaxLocals()protected abstract StringgetSuperName()Returns the JVM-internal representation of this super class name.protected intgetTempVar()Returns a local variable that single or double words can be stored in.protected abstract StringgetThisName()Returns the JVM-internal representation of this class name.protected voidincMaxLocals(int size)protected abstract voidinsertDefaultSuperCall()static booleanis2word(int type, int dim)protected static booleanisRefType(int type)protected voidpatchGoto(List<Integer> list, int targetPc)protected abstract StringresolveClassName(String jvmClassName)protected abstract StringresolveClassName(ASTList name)voidsetMaxLocals(int n)voidsetTypeChecker(TypeChecker checker)protected static StringtoJvmArrayName(String name, int dim)protected static StringtoJvmTypeName(int type, int dim)
-
-
-
Field Detail
-
bytecode
protected Bytecode bytecode
-
hasReturned
protected boolean hasReturned
true if the last visited node is a return statement.
-
inStaticMethod
public boolean inStaticMethod
Must be true if compilation is for a static method.
-
returnHooks
protected CodeGen.ReturnHook returnHooks
-
exprType
protected int exprType
-
arrayDim
protected int arrayDim
-
className
protected String className
-
-
Constructor Detail
-
CodeGen
public CodeGen(Bytecode b)
-
-
Method Detail
-
setTypeChecker
public void setTypeChecker(TypeChecker checker)
-
fatal
protected static void fatal() throws CompileError- 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
protected int getLocalVar(Declarator d)
-
getThisName
protected abstract String getThisName()
Returns the JVM-internal representation of this class name.
-
getSuperName
protected abstract String getSuperName() throws CompileError
Returns the JVM-internal representation of this super class name.- Throws:
CompileError
-
resolveClassName
protected abstract String resolveClassName(ASTList name) throws CompileError
- Throws:
CompileError
-
resolveClassName
protected abstract String resolveClassName(String jvmClassName) throws CompileError
- Throws:
CompileError
-
toJvmArrayName
protected static String toJvmArrayName(String name, int dim)
- Parameters:
name- the JVM-internal representation. name is not exapnded to java.lang.*.
-
toJvmTypeName
protected static String toJvmTypeName(int type, int dim)
-
compileExpr
public void compileExpr(ASTree expr) throws CompileError
- Throws:
CompileError
-
compileBooleanExpr
public boolean compileBooleanExpr(boolean branchIf, ASTree expr) throws CompileError- Throws:
CompileError
-
doTypeCheck
public void doTypeCheck(ASTree expr) throws CompileError
- Throws:
CompileError
-
atASTList
public void atASTList(ASTList n) throws CompileError
- Overrides:
atASTListin classVisitor- Throws:
CompileError
-
atPair
public void atPair(Pair n) throws CompileError
- Overrides:
atPairin classVisitor- Throws:
CompileError
-
atSymbol
public void atSymbol(Symbol n) throws CompileError
- Overrides:
atSymbolin classVisitor- Throws:
CompileError
-
atFieldDecl
public void atFieldDecl(FieldDecl field) throws CompileError
- Overrides:
atFieldDeclin classVisitor- Throws:
CompileError
-
atMethodDecl
public void atMethodDecl(MethodDecl method) throws CompileError
- Overrides:
atMethodDeclin classVisitor- Throws:
CompileError
-
atMethodBody
public void atMethodBody(Stmnt s, boolean isCons, boolean isVoid) throws CompileError
- Parameters:
isCons- true if super() must be called. false if the method is a class initializer.- Throws:
CompileError
-
insertDefaultSuperCall
protected abstract void insertDefaultSuperCall() throws CompileError- Throws:
CompileError
-
atStmnt
public void atStmnt(Stmnt st) throws CompileError
- Overrides:
atStmntin classVisitor- Throws:
CompileError
-
atReturnStmnt
protected void atReturnStmnt(Stmnt st) throws CompileError
- Throws:
CompileError
-
atReturnStmnt2
protected final void atReturnStmnt2(ASTree result) throws CompileError
- Throws:
CompileError
-
atTryStmnt
protected void atTryStmnt(Stmnt st) throws CompileError
- Throws:
CompileError
-
atDeclarator
public void atDeclarator(Declarator d) throws CompileError
- Overrides:
atDeclaratorin classVisitor- Throws:
CompileError
-
atNewExpr
public abstract void atNewExpr(NewExpr n) throws CompileError
- Overrides:
atNewExprin classVisitor- Throws:
CompileError
-
atArrayInit
public abstract void atArrayInit(ArrayInit init) throws CompileError
- Overrides:
atArrayInitin classVisitor- Throws:
CompileError
-
atAssignExpr
public void atAssignExpr(AssignExpr expr) throws CompileError
- Overrides:
atAssignExprin classVisitor- Throws:
CompileError
-
atAssignExpr
protected void atAssignExpr(AssignExpr expr, boolean doDup) throws CompileError
- Throws:
CompileError
-
badAssign
protected static void badAssign(Expr expr) throws CompileError
- Throws:
CompileError
-
atArrayVariableAssign
protected abstract void atArrayVariableAssign(ArrayInit init, int varType, int varArray, String varClass) 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
-
atCondExpr
public void atCondExpr(CondExpr expr) throws CompileError
- Overrides:
atCondExprin classVisitor- Throws:
CompileError
-
atBinExpr
public void atBinExpr(BinExpr expr) throws CompileError
- Overrides:
atBinExprin classVisitor- Throws:
CompileError
-
badTypes
protected static void badTypes(Expr expr) throws CompileError
- Throws:
CompileError
-
isRefType
protected static boolean isRefType(int type)
-
atCastExpr
public void atCastExpr(CastExpr expr) throws CompileError
- Overrides:
atCastExprin classVisitor- Throws:
CompileError
-
atInstanceOfExpr
public void atInstanceOfExpr(InstanceOfExpr expr) throws CompileError
- Overrides:
atInstanceOfExprin classVisitor- Throws:
CompileError
-
atExpr
public void atExpr(Expr expr) throws CompileError
- Overrides:
atExprin classVisitor- Throws:
CompileError
-
badType
protected static void badType(Expr expr) throws CompileError
- Throws:
CompileError
-
atCallExpr
public abstract void atCallExpr(CallExpr expr) throws CompileError
- Overrides:
atCallExprin classVisitor- Throws:
CompileError
-
atFieldRead
protected abstract void atFieldRead(ASTree expr) throws CompileError
- Throws:
CompileError
-
atClassObject
public void atClassObject(Expr expr) throws CompileError
- Throws:
CompileError
-
atClassObject2
protected void atClassObject2(String cname) throws CompileError
- Throws:
CompileError
-
atArrayRead
public void atArrayRead(ASTree array, ASTree index) throws CompileError
- Throws:
CompileError
-
arrayAccess
protected void arrayAccess(ASTree array, ASTree index) throws CompileError
- Throws:
CompileError
-
getArrayReadOp
protected static int getArrayReadOp(int type, int dim)
-
getArrayWriteOp
protected static int getArrayWriteOp(int type, int dim)
-
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
public abstract void atMember(Member n) throws CompileError
- Overrides:
atMemberin classVisitor- Throws:
CompileError
-
atVariable
public void atVariable(Variable v) throws CompileError
- Overrides:
atVariablein classVisitor- Throws:
CompileError
-
atKeyword
public void atKeyword(Keyword k) throws CompileError
- Overrides:
atKeywordin classVisitor- Throws:
CompileError
-
atStringL
public void atStringL(StringL s) throws CompileError
- Overrides:
atStringLin classVisitor- Throws:
CompileError
-
atIntConst
public void atIntConst(IntConst i) throws CompileError
- Overrides:
atIntConstin classVisitor- Throws:
CompileError
-
atDoubleConst
public void atDoubleConst(DoubleConst d) throws CompileError
- Overrides:
atDoubleConstin classVisitor- Throws:
CompileError
-
-