001/** 002 * 003 * Copyright (c) 2014, the Railo Company Ltd. All rights reserved. 004 * 005 * This library is free software; you can redistribute it and/or 006 * modify it under the terms of the GNU Lesser General Public 007 * License as published by the Free Software Foundation; either 008 * version 2.1 of the License, or (at your option) any later version. 009 * 010 * This library is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 013 * Lesser General Public License for more details. 014 * 015 * You should have received a copy of the GNU Lesser General Public 016 * License along with this library. If not, see <http://www.gnu.org/licenses/>. 017 * 018 **/ 019package lucee.transformer.bytecode.literal; 020 021import lucee.runtime.op.Caster; 022import lucee.transformer.bytecode.BytecodeContext; 023import lucee.transformer.bytecode.Literal; 024import lucee.transformer.bytecode.Position; 025import lucee.transformer.bytecode.expression.ExprFloat; 026import lucee.transformer.bytecode.expression.ExpressionBase; 027import lucee.transformer.bytecode.util.Methods; 028import lucee.transformer.bytecode.util.Types; 029 030import org.objectweb.asm.Type; 031import org.objectweb.asm.commons.GeneratorAdapter; 032 033/** 034 * Literal Double Value 035 */ 036public final class LitFloat extends ExpressionBase implements Literal,ExprFloat { 037 038 private float f; 039 040 public static ExprFloat toExprFloat(float f, Position start,Position end) { 041 return new LitFloat(f,start,end); 042 } 043 044 /** 045 * constructor of the class 046 * @param d 047 * @param line 048 */ 049 public LitFloat(float f, Position start,Position end) { 050 super(start,end); 051 this.f=f; 052 } 053 054 /** 055 * @return return value as double value 056 */ 057 public float getFloatValue() { 058 return f; 059 } 060 061 public Float getFloat() { 062 return new Float(f); 063 } 064 065 /** 066 * @see lucee.transformer.bytecode.Literal#getString() 067 */ 068 public String getString() { 069 return Caster.toString(f); 070 } 071 072 /** 073 * @return return value as a Boolean Object 074 */ 075 public Boolean getBoolean() { 076 return Caster.toBoolean(f); 077 } 078 079 /** 080 * @return return value as a boolean value 081 */ 082 public boolean getBooleanValue() { 083 return Caster.toBooleanValue(f); 084 } 085 086 /** 087 * @see lucee.transformer.bytecode.expression.Expression#_writeOut(org.objectweb.asm.commons.GeneratorAdapter, int) 088 */ 089 public Type _writeOut(BytecodeContext bc, int mode) { 090 GeneratorAdapter adapter = bc.getAdapter(); 091 adapter.push(f); 092 if(mode==MODE_REF) { 093 adapter.invokeStatic(Types.CASTER,Methods.METHOD_TO_FLOAT_FROM_FLOAT); 094 return Types.FLOAT; 095 } 096 return Types.FLOAT_VALUE; 097 } 098 099 /** 100 * @see lucee.transformer.bytecode.Literal#getDouble(java.lang.Double) 101 */ 102 public Double getDouble(Double defaultValue) { 103 return new Double(getFloatValue()); 104 } 105 106 /** 107 * @see lucee.transformer.bytecode.Literal#getBoolean(java.lang.Boolean) 108 */ 109 public Boolean getBoolean(Boolean defaultValue) { 110 return getBoolean(); 111 } 112}