diff options
author | chiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3> | 2003-05-16 17:07:03 +0000 |
---|---|---|
committer | chiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3> | 2003-05-16 17:07:03 +0000 |
commit | 5fc3a4c6aa6cd5378d417f98b66f76529c4341e4 (patch) | |
tree | d86a6647b4af2691d80ed2334737ab2a88c6f781 /src | |
parent | 51df92b44b8e1dcbcdb75e1390a81c0aa2f9ae78 (diff) | |
download | javassist-5fc3a4c6aa6cd5378d417f98b66f76529c4341e4.tar.gz javassist-5fc3a4c6aa6cd5378d417f98b66f76529c4341e4.zip |
modified the semantics of ($r).
git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@16 30ef5769-5b8d-40dd-aea6-55b5d6557bb3
Diffstat (limited to 'src')
-rw-r--r-- | src/main/javassist/compiler/CodeGen.java | 24 | ||||
-rw-r--r-- | src/main/javassist/compiler/JvstCodeGen.java | 37 |
2 files changed, 50 insertions, 11 deletions
diff --git a/src/main/javassist/compiler/CodeGen.java b/src/main/javassist/compiler/CodeGen.java index 60170dbb..e0b2dfa4 100644 --- a/src/main/javassist/compiler/CodeGen.java +++ b/src/main/javassist/compiler/CodeGen.java @@ -192,6 +192,30 @@ public abstract class CodeGen extends Visitor implements Opcode, TokenId { return sbuf.toString(); } + protected static int jvmTypeNameToExprType(char type) { + switch(type) { + case 'Z' : + return BOOLEAN; + case 'B' : + return BYTE; + case 'C' : + return CHAR; + case 'S' : + return SHORT; + case 'I' : + return INT; + case 'J' : + return LONG; + case 'F' : + return FLOAT; + case 'D' : + return DOUBLE; + case 'V' : + return VOID; + default : + return CLASS; + } + } public void atASTList(ASTList n) throws CompileError { fatal(); } diff --git a/src/main/javassist/compiler/JvstCodeGen.java b/src/main/javassist/compiler/JvstCodeGen.java index 0090f851..40d39a11 100644 --- a/src/main/javassist/compiler/JvstCodeGen.java +++ b/src/main/javassist/compiler/JvstCodeGen.java @@ -184,10 +184,18 @@ public class JvstCodeGen extends MemberCodeGen { */ protected void atCastToRtype(CastExpr expr) throws CompileError { expr.getOprand().accept(this); - if (!isRefType(exprType) || arrayDim > 0) - throw new CompileError("invalid type for " + returnCastName); - - compileUnwrapValue(returnType, bytecode); + if (exprType == VOID || isRefType(exprType) || arrayDim > 0) + compileUnwrapValue(returnType, bytecode); + else if (returnType instanceof CtPrimitiveType) { + CtPrimitiveType pt = (CtPrimitiveType)returnType; + int destType = jvmTypeNameToExprType(pt.getDescriptor()); + atNumCastExpr(exprType, destType); + exprType = destType; + arrayDim = 0; + className = null; + } + else + throw new CompileError("invalid cast"); } protected void atCastToWrapper(CastExpr expr) throws CompileError { @@ -583,15 +591,22 @@ public class JvstCodeGen extends MemberCodeGen { protected void compileUnwrapValue(CtClass type, Bytecode code) throws CompileError { + if (type == CtClass.voidType) { + addNullIfVoid(); + return; + } + + if (exprType == VOID) + throw new CompileError("invalid type for " + returnCastName); + if (type instanceof CtPrimitiveType) { CtPrimitiveType pt = (CtPrimitiveType)type; - if (pt != CtClass.voidType) { - String wrapper = pt.getWrapperName(); - code.addCheckcast(wrapper); - code.addInvokevirtual(wrapper, pt.getGetMethodName(), - pt.getGetMethodDescriptor()); - setType(type); - } + // pt is not voidType. + String wrapper = pt.getWrapperName(); + code.addCheckcast(wrapper); + code.addInvokevirtual(wrapper, pt.getGetMethodName(), + pt.getGetMethodDescriptor()); + setType(type); } else { code.addCheckcast(type); |