package node.exprNode; import env.*; import type.*; import type.basicType.*; import runEnv.*; public class CastNode extends ExprNode { private ExprNode expr; private Type type; public CastNode( ExprNode expr, Type type ) { this.expr = expr; this.type = type; precedence = PREC_PREFIX; } public Type checkType( Env env ) { error( "Should never invoke checkType() for a CastNode()" ); return null; } public String toString() { return "( " + type + " ) " + expr.toString( precedence ); } public RunValue eval( RunEnv runEnv ) { RunValue exprValue = expr.eval( runEnv ); Type exprType = expr.type(); if ( type instanceof RealType ) return new RunValue( ( double ) exprValue.intValue() ); else if ( type instanceof StringType ) return new RunValue( exprValue.stringValue() ); else if ( type instanceof VoidType ) { return null; } else { return exprValue; } } }