001 package railo.transformer.bytecode.literal; 002 003 import org.objectweb.asm.Type; 004 import org.objectweb.asm.commons.GeneratorAdapter; 005 006 import railo.runtime.op.Caster; 007 import railo.transformer.bytecode.BytecodeContext; 008 import railo.transformer.bytecode.Literal; 009 import railo.transformer.bytecode.expression.ExprFloat; 010 import railo.transformer.bytecode.expression.ExpressionBase; 011 import railo.transformer.bytecode.util.Methods; 012 import railo.transformer.bytecode.util.Types; 013 014 /** 015 * Literal Double Value 016 */ 017 public final class LitFloat extends ExpressionBase implements Literal,ExprFloat { 018 019 private float f; 020 021 public static ExprFloat toExprFloat(float f, int line) { 022 return new LitFloat(f,line); 023 } 024 025 /** 026 * constructor of the class 027 * @param d 028 * @param line 029 */ 030 public LitFloat(float f, int line) { 031 super(line); 032 this.f=f; 033 } 034 035 /** 036 * @return return value as double value 037 */ 038 public float getFloatValue() { 039 return f; 040 } 041 042 public Float getFloat() { 043 return new Float(f); 044 } 045 046 /** 047 * @see railo.transformer.bytecode.Literal#getString() 048 */ 049 public String getString() { 050 return Caster.toString(f); 051 } 052 053 /** 054 * @return return value as a Boolean Object 055 */ 056 public Boolean getBoolean() { 057 return Caster.toBoolean(f); 058 } 059 060 /** 061 * @return return value as a boolean value 062 */ 063 public boolean getBooleanValue() { 064 return Caster.toBooleanValue(f); 065 } 066 067 /** 068 * @see railo.transformer.bytecode.expression.Expression#_writeOut(org.objectweb.asm.commons.GeneratorAdapter, int) 069 */ 070 public Type _writeOut(BytecodeContext bc, int mode) { 071 GeneratorAdapter adapter = bc.getAdapter(); 072 adapter.push(f); 073 if(mode==MODE_REF) { 074 adapter.invokeStatic(Types.CASTER,Methods.METHOD_TO_FLOAT_FROM_FLOAT); 075 return Types.FLOAT; 076 } 077 return Types.FLOAT_VALUE; 078 } 079 080 /** 081 * @see railo.transformer.bytecode.Literal#getDouble(java.lang.Double) 082 */ 083 public Double getDouble(Double defaultValue) { 084 return new Double(getFloatValue()); 085 } 086 087 /** 088 * @see railo.transformer.bytecode.Literal#getBoolean(java.lang.Boolean) 089 */ 090 public Boolean getBoolean(Boolean defaultValue) { 091 return getBoolean(); 092 } 093 }