001 package railo.transformer.bytecode.literal; 002 003 import org.objectweb.asm.Type; 004 import org.objectweb.asm.commons.GeneratorAdapter; 005 006 import railo.commons.color.ConstantsDouble; 007 import railo.runtime.op.Caster; 008 import railo.transformer.bytecode.BytecodeContext; 009 import railo.transformer.bytecode.Literal; 010 import railo.transformer.bytecode.Position; 011 import railo.transformer.bytecode.expression.ExprDouble; 012 import railo.transformer.bytecode.expression.ExpressionBase; 013 import railo.transformer.bytecode.util.Methods; 014 import railo.transformer.bytecode.util.Types; 015 016 /** 017 * Literal Double Value 018 */ 019 public final class LitDouble extends ExpressionBase implements Literal,ExprDouble { 020 021 private static final Type CONSTANTS_DOUBLE = Type.getType(ConstantsDouble.class); 022 public static final LitDouble ZERO=new LitDouble(0,null,null); 023 024 private double d; 025 026 public static LitDouble toExprDouble(double d) { 027 return new LitDouble(d,null,null); 028 } 029 public static LitDouble toExprDouble(double d, Position start,Position end) { 030 return new LitDouble(d,start,end); 031 } 032 033 /** 034 * constructor of the class 035 * @param d 036 * @param line 037 */ 038 private LitDouble(double d, Position start,Position end) { 039 super(start,end); 040 041 this.d=d; 042 } 043 044 /** 045 * @return return value as double value 046 */ 047 public double getDoubleValue() { 048 return d; 049 } 050 051 /** 052 * @return return value as Double Object 053 */ 054 public Double getDouble() { 055 return new Double(d); 056 } 057 058 /** 059 * @see railo.transformer.bytecode.Literal#getString() 060 */ 061 public String getString() { 062 return Caster.toString(d); 063 } 064 065 /** 066 * @return return value as a Boolean Object 067 */ 068 public Boolean getBoolean() { 069 return Caster.toBoolean(d); 070 } 071 072 /** 073 * @return return value as a boolean value 074 */ 075 public boolean getBooleanValue() { 076 return Caster.toBooleanValue(d); 077 } 078 079 /** 080 * @see railo.transformer.bytecode.expression.Expression#_writeOut(org.objectweb.asm.commons.GeneratorAdapter, int) 081 */ 082 public Type _writeOut(BytecodeContext bc, int mode) { 083 GeneratorAdapter adapter = bc.getAdapter(); 084 if(mode==MODE_REF) { 085 String str=ConstantsDouble.getFieldName(d); 086 if(str!=null) { 087 bc.getAdapter().getStatic(CONSTANTS_DOUBLE, str, Types.DOUBLE); 088 } 089 else { 090 adapter.push(d); 091 adapter.invokeStatic(Types.CASTER,Methods.METHOD_TO_DOUBLE_FROM_DOUBLE); 092 } 093 return Types.DOUBLE; 094 } 095 adapter.push(d); 096 097 return Types.DOUBLE_VALUE; 098 } 099 100 /** 101 * @see railo.transformer.bytecode.Literal#getDouble(java.lang.Double) 102 */ 103 public Double getDouble(Double defaultValue) { 104 return getDouble(); 105 } 106 107 /** 108 * @see railo.transformer.bytecode.Literal#getBoolean(java.lang.Boolean) 109 */ 110 public Boolean getBoolean(Boolean defaultValue) { 111 return getBoolean(); 112 } 113 }