diff options
Diffstat (limited to 'src/main/javassist')
-rw-r--r-- | src/main/javassist/CtClass.java | 2 | ||||
-rw-r--r-- | src/main/javassist/bytecode/Bytecode.java | 27 | ||||
-rw-r--r-- | src/main/javassist/bytecode/Descriptor.java | 32 | ||||
-rw-r--r-- | src/main/javassist/expr/Cast.java | 4 | ||||
-rw-r--r-- | src/main/javassist/expr/FieldAccess.java | 13 | ||||
-rw-r--r-- | src/main/javassist/expr/Instanceof.java | 4 | ||||
-rw-r--r-- | src/main/javassist/expr/MethodCall.java | 6 | ||||
-rw-r--r-- | src/main/javassist/expr/NewExpr.java | 4 |
8 files changed, 71 insertions, 21 deletions
diff --git a/src/main/javassist/CtClass.java b/src/main/javassist/CtClass.java index 001269a8..bf5a28ee 100644 --- a/src/main/javassist/CtClass.java +++ b/src/main/javassist/CtClass.java @@ -35,7 +35,7 @@ public abstract class CtClass { /** * The version number of this release. */ - public static final String version = "3.0 beta"; + public static final String version = "3.0 beta 3"; /** * Prints the version number and the copyright notice. diff --git a/src/main/javassist/bytecode/Bytecode.java b/src/main/javassist/bytecode/Bytecode.java index ae6f1691..e319eeea 100644 --- a/src/main/javassist/bytecode/Bytecode.java +++ b/src/main/javassist/bytecode/Bytecode.java @@ -442,6 +442,29 @@ public class Bytecode implements Opcode { } /** + * Appends an instruction for pushing zero or null on the stack. + * If the type is void, this method does not append any instruction. + * + * @param type the type of the zero value (or null). + */ + public void addConstZero(CtClass type) { + if (type.isPrimitive()) { + if (type == CtClass.longType) + addOpcode(LCONST_0); + else if (type == CtClass.floatType) + addOpcode(FCONST_0); + else if (type == CtClass.doubleType) + addOpcode(DCONST_0); + else if (type == CtClass.voidType) + throw new RuntimeException("void type?"); + else + addOpcode(ICONST_0); + } + else + addOpcode(ACONST_NULL); + } + + /** * Appends ILOAD or (WIDE) ILOAD_<n> * * @param n an index into the local variable array. @@ -680,9 +703,9 @@ public class Bytecode implements Opcode { addLstore(n); return 2; } - else if(type == CtClass.floatType) + else if (type == CtClass.floatType) addFstore(n); - else if(type == CtClass.doubleType) { + else if (type == CtClass.doubleType) { addDstore(n); return 2; } diff --git a/src/main/javassist/bytecode/Descriptor.java b/src/main/javassist/bytecode/Descriptor.java index b3cc5a8c..9590d632 100644 --- a/src/main/javassist/bytecode/Descriptor.java +++ b/src/main/javassist/bytecode/Descriptor.java @@ -46,22 +46,20 @@ public class Descriptor { return classname.replace('/', '.'); } - /** - * Converts to a classname from a descriptor - */ - public static String fromDescriptor(String descriptor) - { - String newname = toJavaName(descriptor).substring(1); - return newname.substring(0, newname.length() - 1); - } - - /** - * Converts to a descriptor from a classname - */ - public static String toDescriptor(String classname) - { - return "L" + toJvmName(classname) + ";"; - } + /** + * Converts to a classname from a descriptor + */ + public static String fromDescriptor(String descriptor) { + String newname = toJavaName(descriptor).substring(1); + return newname.substring(0, newname.length() - 1); + } + + /** + * Converts to a descriptor from a classname + */ + public static String toDescriptor(String classname) { + return "L" + toJvmName(classname) + ";"; + } /** * Returns the internal representation of the class name in the @@ -179,8 +177,6 @@ public class Descriptor { return sbuf.toString(); } - - private static void toDescriptor(StringBuffer desc, CtClass type) { if (type.isArray()) { desc.append('['); diff --git a/src/main/javassist/expr/Cast.java b/src/main/javassist/expr/Cast.java index 80ad4012..160698ff 100644 --- a/src/main/javassist/expr/Cast.java +++ b/src/main/javassist/expr/Cast.java @@ -113,6 +113,10 @@ public class Cast extends Expr { Bytecode bytecode = jc.getBytecode(); storeStack(params, true, paramVar, bytecode); jc.recordLocalVariables(ca, pos); + + bytecode.addConstZero(retType); + bytecode.addStore(retVar, retType); // initialize $_ + jc.compileStmnt(statement); bytecode.addLoad(retVar, retType); diff --git a/src/main/javassist/expr/FieldAccess.java b/src/main/javassist/expr/FieldAccess.java index 8598f456..954c3413 100644 --- a/src/main/javassist/expr/FieldAccess.java +++ b/src/main/javassist/expr/FieldAccess.java @@ -174,6 +174,8 @@ public class FieldAccess extends Expr { /* Is $_ included in the source code? */ boolean included = checkResultValue(retType, statement); + if (read) + included = true; int retVar = jc.recordReturnType(retType, included); if (read) @@ -189,6 +191,17 @@ public class FieldAccess extends Expr { Bytecode bytecode = jc.getBytecode(); storeStack(params, isStatic(), paramVar, bytecode); jc.recordLocalVariables(ca, pos); + + if (included) + if (retType == CtClass.voidType) { + bytecode.addOpcode(ACONST_NULL); + bytecode.addAstore(retVar); + } + else { + bytecode.addConstZero(retType); + bytecode.addStore(retVar, retType); // initialize $_ + } + jc.compileStmnt(statement); if (read) bytecode.addLoad(retVar, retType); diff --git a/src/main/javassist/expr/Instanceof.java b/src/main/javassist/expr/Instanceof.java index a0982583..2cb9790b 100644 --- a/src/main/javassist/expr/Instanceof.java +++ b/src/main/javassist/expr/Instanceof.java @@ -118,6 +118,10 @@ public class Instanceof extends Expr { Bytecode bytecode = jc.getBytecode(); storeStack(params, true, paramVar, bytecode); jc.recordLocalVariables(ca, pos); + + bytecode.addConstZero(retType); + bytecode.addStore(retVar, retType); // initialize $_ + jc.compileStmnt(statement); bytecode.addLoad(retVar, retType); diff --git a/src/main/javassist/expr/MethodCall.java b/src/main/javassist/expr/MethodCall.java index 28ed8d2d..1e0a842d 100644 --- a/src/main/javassist/expr/MethodCall.java +++ b/src/main/javassist/expr/MethodCall.java @@ -211,6 +211,12 @@ public class MethodCall extends Expr { Bytecode bytecode = jc.getBytecode(); storeStack(params, c == INVOKESTATIC, paramVar, bytecode); jc.recordLocalVariables(ca, pos); + + if (retType != CtClass.voidType) { + bytecode.addConstZero(retType); + bytecode.addStore(retVar, retType); // initialize $_ + } + jc.compileStmnt(statement); if (retType != CtClass.voidType) bytecode.addLoad(retVar, retType); diff --git a/src/main/javassist/expr/NewExpr.java b/src/main/javassist/expr/NewExpr.java index 1fa7d4e9..e4c979fe 100644 --- a/src/main/javassist/expr/NewExpr.java +++ b/src/main/javassist/expr/NewExpr.java @@ -178,6 +178,10 @@ public class NewExpr extends Expr { Bytecode bytecode = jc.getBytecode(); storeStack(params, true, paramVar, bytecode); jc.recordLocalVariables(ca, pos); + + bytecode.addConstZero(newType); + bytecode.addStore(retVar, newType); // initialize $_ + jc.compileStmnt(statement); bytecode.addAload(retVar); |