private void insertCast(BinExpr expr, int type1, int type2) throws CompileError { if (CodeGen.rightIsStrong(type1, type2)) expr.setLeft(new CastExpr(type2, 0, expr.oprand1())); else exprType = type1; }
public void atCastExpr(CastExpr expr) throws CompileError { String cname = resolveClassName(expr.getClassName()); expr.getOprand().accept(this); exprType = expr.getType(); arrayDim = expr.getArrayDim(); className = cname; }
public ASTList getClassName() { return (ASTList)getLeft(); }
public void atCastExpr(CastExpr expr) throws CompileError { String cname = resolveClassName(expr.getClassName()); String toClass = checkCastExpr(expr, cname); int srcType = exprType; exprType = expr.getType(); arrayDim = expr.getArrayDim(); className = cname; if (toClass == null) atNumCastExpr(srcType, exprType); // built-in type else bytecode.addCheckcast(toClass); }
public void atCastExpr(CastExpr expr) throws CompileError { ASTList classname = expr.getClassName(); if (classname != null && expr.getArrayDim() == 0) { ASTree p = classname.head(); if (p instanceof Symbol && classname.tail() == null) { String typename = ((Symbol)p).get(); if (typename.equals(codeGen.returnCastName)) { atCastToRtype(expr); return; } else if (typename.equals(JvstCodeGen.wrapperCastName)) { atCastToWrapper(expr); return; } } } super.atCastExpr(expr); }
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 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; } }
public ASTree getOprand() { return getRight().getLeft(); }
@Override public void atCastExpr(CastExpr expr) throws CompileError { String cname = resolveClassName(expr.getClassName()); String toClass = checkCastExpr(expr, cname); int srcType = exprType; exprType = expr.getType(); arrayDim = expr.getArrayDim(); className = cname; if (toClass == null) atNumCastExpr(srcType, exprType); // built-in type else bytecode.addCheckcast(toClass); }
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 }
public void atCastExpr(CastExpr expr) throws CompileError { ASTList classname = expr.getClassName(); if (classname != null && expr.getArrayDim() == 0) { ASTree p = classname.head(); if (p instanceof Symbol && classname.tail() == null) { String typename = ((Symbol)p).get(); if (typename.equals(returnCastName)) { atCastToRtype(expr); return; } else if (typename.equals(wrapperCastName)) { atCastToWrapper(expr); return; } } } super.atCastExpr(expr); }
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; } }
public void setOprand(ASTree t) { getRight().setLeft(t); }
@Override public void atCastExpr(CastExpr expr) throws CompileError { String cname = resolveClassName(expr.getClassName()); expr.getOprand().accept(this); exprType = expr.getType(); arrayDim = expr.getArrayDim(); className = cname; }
public void atCastExpr(CastExpr expr) throws CompileError { String cname = resolveClassName(expr.getClassName()); String toClass = checkCastExpr(expr, cname); int srcType = exprType; exprType = expr.getType(); arrayDim = expr.getArrayDim(); className = cname; if (toClass == null) atNumCastExpr(srcType, exprType); // built-in type else bytecode.addCheckcast(toClass); }
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; if (invalidDim(srcType, arrayDim, className, type, dim, name, true) || srcType == VOID || type == VOID) throw new CompileError(msg); if (type == CLASS) { if (!isRefType(srcType)) throw new CompileError(msg); return toJvmArrayName(name, dim); } else if (dim > 0) return toJvmTypeName(type, dim); else return null; // built-in type }
@Override public void atCastExpr(CastExpr expr) throws CompileError { ASTList classname = expr.getClassName(); if (classname != null && expr.getArrayDim() == 0) { ASTree p = classname.head(); if (p instanceof Symbol && classname.tail() == null) { String typename = ((Symbol)p).get(); if (typename.equals(returnCastName)) { atCastToRtype(expr); return; } else if (typename.equals(wrapperCastName)) { atCastToWrapper(expr); return; } } } super.atCastExpr(expr); }
/** * 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; } }
private void insertCast(BinExpr expr, int type1, int type2) throws CompileError { if (CodeGen.rightIsStrong(type1, type2)) expr.setLeft(new CastExpr(type2, 0, expr.oprand1())); else exprType = type1; }
public void setOprand(ASTree t) { getRight().setLeft(t); }