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