private static int typePrecedence(int type) { if (type == DOUBLE) return P_DOUBLE; else if (type == FLOAT) return P_FLOAT; else if (type == LONG) return P_LONG; else if (isRefType(type)) return P_OTHER; else if (type == VOID) return P_OTHER; // this is wrong, but ... else return P_INT; // BOOLEAN, BYTE, CHAR, SHORT, INT }
private static int typePrecedence(int type) { if (type == DOUBLE) return P_DOUBLE; else if (type == FLOAT) return P_FLOAT; else if (type == LONG) return P_LONG; else if (isRefType(type)) return P_OTHER; else if (type == VOID) return P_OTHER; // this is wrong, but ... else return P_INT; // BOOLEAN, BYTE, CHAR, SHORT, INT }
protected void atCastToWrapper(CastExpr expr) throws CompileError { expr.getOprand().accept(this); if (CodeGen.isRefType(exprType) || arrayDim > 0) return; // Object type. do nothing. CtClass clazz = resolver.lookupClass(exprType, arrayDim, className); if (clazz instanceof CtPrimitiveType) { exprType = CLASS; arrayDim = 0; className = jvmJavaLangObject; } }
protected void atCastToWrapper(CastExpr expr) throws CompileError { expr.getOprand().accept(this); if (CodeGen.isRefType(exprType) || arrayDim > 0) return; // Object type. do nothing. CtClass clazz = resolver.lookupClass(exprType, arrayDim, className); if (clazz instanceof CtPrimitiveType) { exprType = CLASS; arrayDim = 0; className = jvmJavaLangObject; } }
protected final void atReturnStmnt2(ASTree result) throws CompileError { int op; if (result == null) op = Opcode.RETURN; else { compileExpr(result); if (arrayDim > 0) op = ARETURN; else { int type = exprType; if (type == DOUBLE) op = DRETURN; else if (type == FLOAT) op = FRETURN; else if (type == LONG) op = LRETURN; else if (isRefType(type)) op = ARETURN; else op = IRETURN; } } for (ReturnHook har = returnHooks; har != null; har = har.next) if (har.doit(bytecode, op)) { hasReturned = true; return; } bytecode.addOpcode(op); hasReturned = true; }
/** * Inserts a cast operator to the return type. * If the return type is void, this does nothing. */ protected void atCastToRtype(CastExpr expr) throws CompileError { CtClass returnType = codeGen.returnType; expr.getOprand().accept(this); if (exprType == VOID || CodeGen.isRefType(exprType) || arrayDim > 0) compileUnwrapValue(returnType); else if (returnType instanceof CtPrimitiveType) { CtPrimitiveType pt = (CtPrimitiveType)returnType; int destType = MemberResolver.descToType(pt.getDescriptor()); exprType = destType; arrayDim = 0; className = null; } }
protected final void atReturnStmnt2(ASTree result) throws CompileError { int op; if (result == null) op = Opcode.RETURN; else { compileExpr(result); if (arrayDim > 0) op = ARETURN; else { int type = exprType; if (type == DOUBLE) op = DRETURN; else if (type == FLOAT) op = FRETURN; else if (type == LONG) op = LRETURN; else if (isRefType(type)) op = ARETURN; else op = IRETURN; } } for (ReturnHook har = returnHooks; har != null; har = har.next) if (har.doit(bytecode, op)) { hasReturned = true; return; } bytecode.addOpcode(op); hasReturned = true; }
/** * Inserts a cast operator to the return type. * If the return type is void, this does nothing. */ protected void atCastToRtype(CastExpr expr) throws CompileError { CtClass returnType = codeGen.returnType; expr.getOprand().accept(this); if (exprType == VOID || CodeGen.isRefType(exprType) || arrayDim > 0) compileUnwrapValue(returnType); else if (returnType instanceof CtPrimitiveType) { CtPrimitiveType pt = (CtPrimitiveType)returnType; int destType = MemberResolver.descToType(pt.getDescriptor()); exprType = destType; arrayDim = 0; className = null; } }
protected void atAssignCore(Expr expr, int op, ASTree right, int type, int dim, String cname) throws CompileError { if (op == PLUS_E && dim == 0 && type == CLASS) atStringPlusEq(expr, type, dim, cname, right); else { right.accept(this); if (invalidDim(exprType, arrayDim, className, type, dim, cname, false) || (op != '=' && dim > 0)) badAssign(expr); if (op != '=') { int token = assignOps[op - MOD_E]; int k = lookupBinOp(token); if (k < 0) fatal(); atArithBinExpr(expr, token, k, type); } } if (op != '=' || (dim == 0 && !isRefType(type))) atNumCastExpr(exprType, type); // type check should be done here. }
private void convToString(int type, int dim) throws CompileError { final String method = "valueOf"; if (isRefType(type) || dim > 0) bytecode.addInvokestatic(javaLangString, method, "(Ljava/lang/Object;)Ljava/lang/String;"); else if (type == DOUBLE) bytecode.addInvokestatic(javaLangString, method, "(D)Ljava/lang/String;"); else if (type == FLOAT) bytecode.addInvokestatic(javaLangString, method, "(F)Ljava/lang/String;"); else if (type == LONG) bytecode.addInvokestatic(javaLangString, method, "(J)Ljava/lang/String;"); else if (type == BOOLEAN) bytecode.addInvokestatic(javaLangString, method, "(Z)Ljava/lang/String;"); else if (type == CHAR) bytecode.addInvokestatic(javaLangString, method, "(C)Ljava/lang/String;"); else if (type == VOID) throw new CompileError("void type expression"); else /* INT, BYTE, SHORT */ bytecode.addInvokestatic(javaLangString, method, "(I)Ljava/lang/String;"); }
private String checkCastExpr(CastExpr expr, String name) throws CompileError { final String msg = "invalid cast"; ASTree oprand = expr.getOprand(); int dim = expr.getArrayDim(); int type = expr.getType(); oprand.accept(this); int srcType = exprType; int srcDim = arrayDim; if (invalidDim(srcType, arrayDim, className, type, dim, name, true) || srcType == VOID || type == VOID) throw new CompileError(msg); if (type == CLASS) { if (!isRefType(srcType) && srcDim == 0) throw new CompileError(msg); return toJvmArrayName(name, dim); } else if (dim > 0) return toJvmTypeName(type, dim); else return null; // built-in type }
protected void atAssignCore(Expr expr, int op, ASTree right, int type, int dim, String cname) throws CompileError { if (op == PLUS_E && dim == 0 && type == CLASS) atStringPlusEq(expr, type, dim, cname, right); else { right.accept(this); if (invalidDim(exprType, arrayDim, className, type, dim, cname, false) || (op != '=' && dim > 0)) badAssign(expr); if (op != '=') { int token = assignOps[op - MOD_E]; int k = lookupBinOp(token); if (k < 0) fatal(); atArithBinExpr(expr, token, k, type); } } if (op != '=' || (dim == 0 && !isRefType(type))) atNumCastExpr(exprType, type); // type check should be done here. }
private void convToString(int type, int dim) throws CompileError { final String method = "valueOf"; if (isRefType(type) || dim > 0) bytecode.addInvokestatic(javaLangString, method, "(Ljava/lang/Object;)Ljava/lang/String;"); else if (type == DOUBLE) bytecode.addInvokestatic(javaLangString, method, "(D)Ljava/lang/String;"); else if (type == FLOAT) bytecode.addInvokestatic(javaLangString, method, "(F)Ljava/lang/String;"); else if (type == LONG) bytecode.addInvokestatic(javaLangString, method, "(J)Ljava/lang/String;"); else if (type == BOOLEAN) bytecode.addInvokestatic(javaLangString, method, "(Z)Ljava/lang/String;"); else if (type == CHAR) bytecode.addInvokestatic(javaLangString, method, "(C)Ljava/lang/String;"); else if (type == VOID) throw new CompileError("void type expression"); else /* INT, BYTE, SHORT */ bytecode.addInvokestatic(javaLangString, method, "(I)Ljava/lang/String;"); }
private String checkCastExpr(CastExpr expr, String name) throws CompileError { final String msg = "invalid cast"; ASTree oprand = expr.getOprand(); int dim = expr.getArrayDim(); int type = expr.getType(); oprand.accept(this); int srcType = exprType; int srcDim = arrayDim; if (invalidDim(srcType, arrayDim, className, type, dim, name, true) || srcType == VOID || type == VOID) throw new CompileError(msg); if (type == CLASS) { if (!isRefType(srcType) && srcDim == 0) throw new CompileError(msg); return toJvmArrayName(name, dim); } else if (dim > 0) return toJvmTypeName(type, dim); else return null; // built-in type }
else if (varType == LONG) bytecode.addLstore(varNo); else if (isRefType(varType)) bytecode.addAstore(varNo); else
else if (varType == LONG) bytecode.addLstore(varNo); else if (isRefType(varType)) bytecode.addAstore(varNo); else
protected void atCastToWrapper(CastExpr expr) throws CompileError { expr.getOprand().accept(this); if (CodeGen.isRefType(exprType) || arrayDim > 0) return; // Object type. do nothing. CtClass clazz = resolver.lookupClass(exprType, arrayDim, className); if (clazz instanceof CtPrimitiveType) { exprType = CLASS; arrayDim = 0; className = jvmJavaLangObject; } }
protected void atCastToWrapper(CastExpr expr) throws CompileError { expr.getOprand().accept(this); if (CodeGen.isRefType(exprType) || arrayDim > 0) return; // Object type. do nothing. CtClass clazz = resolver.lookupClass(exprType, arrayDim, className); if (clazz instanceof CtPrimitiveType) { exprType = CLASS; arrayDim = 0; className = jvmJavaLangObject; } }
protected void atCastToWrapper(CastExpr expr) throws CompileError { expr.getOprand().accept(this); if (CodeGen.isRefType(exprType) || arrayDim > 0) return; // Object type. do nothing. CtClass clazz = resolver.lookupClass(exprType, arrayDim, className); if (clazz instanceof CtPrimitiveType) { exprType = CLASS; arrayDim = 0; className = jvmJavaLangObject; } }
protected void atCastToWrapper(CastExpr expr) throws CompileError { expr.getOprand().accept(this); if (CodeGen.isRefType(exprType) || arrayDim > 0) return; // Object type. do nothing. CtClass clazz = resolver.lookupClass(exprType, arrayDim, className); if (clazz instanceof CtPrimitiveType) { exprType = CLASS; arrayDim = 0; className = jvmJavaLangObject; } }