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