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