001 package railo.transformer.bytecode.literal; 002 003 import org.objectweb.asm.Opcodes; 004 import org.objectweb.asm.Type; 005 import org.objectweb.asm.commons.GeneratorAdapter; 006 007 import railo.runtime.op.Caster; 008 import railo.transformer.bytecode.BytecodeContext; 009 import railo.transformer.bytecode.Literal; 010 import railo.transformer.bytecode.expression.ExprBoolean; 011 import railo.transformer.bytecode.expression.ExpressionBase; 012 import railo.transformer.bytecode.util.Types; 013 014 /** 015 * Literal Boolean 016 */ 017 public final class LitBoolean extends ExpressionBase implements Literal,ExprBoolean { 018 019 /** 020 * @see java.lang.Object#toString() 021 */ 022 @Override 023 public String toString() { 024 return b+""; 025 } 026 027 private boolean b; 028 029 public static final LitBoolean TRUE=new LitBoolean(true,-1); 030 public static final LitBoolean FALSE=new LitBoolean(false,-1); 031 032 public static ExprBoolean toExprBoolean(boolean b, int line) { 033 return new LitBoolean(b,line); 034 } 035 036 public static ExprBoolean toExprBoolean(boolean b) { 037 return new LitBoolean(b,-1); 038 } 039 040 /** 041 * constructor of the class 042 * @param b 043 * @param line 044 */ 045 public LitBoolean(boolean b, int line) { 046 super(line); 047 this.b=b; 048 } 049 050 /** 051 * @return return value as double value 052 */ 053 public double getDoubleValue() { 054 return Caster.toDoubleValue(b); 055 } 056 057 /** 058 * @return return value as Double Object 059 */ 060 public Double getDouble() { 061 return Caster.toDouble(b); 062 } 063 064 /** 065 * @see railo.transformer.bytecode.Literal#getString() 066 */ 067 public String getString() { 068 return Caster.toString(b); 069 } 070 071 /** 072 * @return return value as a Boolean Object 073 */ 074 public Boolean getBoolean() { 075 return Caster.toBoolean(b); 076 } 077 078 /** 079 * @return return value as a boolean value 080 */ 081 public boolean getBooleanValue() { 082 return b; 083 } 084 085 /** 086 * 087 * @see railo.transformer.bytecode.expression.ExpressionBase#_writeOut(org.objectweb.asm.commons.GeneratorAdapter, int) 088 */ 089 public Type _writeOut(BytecodeContext bc, int mode) { 090 GeneratorAdapter adapter = bc.getAdapter(); 091 092 if(mode==MODE_REF) { 093 adapter.getStatic(Types.BOOLEAN, b?"TRUE":"FALSE", Types.BOOLEAN); 094 return Types.BOOLEAN; 095 } 096 else { 097 adapter.visitInsn(b?Opcodes.ICONST_1:Opcodes.ICONST_0); 098 return Types.BOOLEAN_VALUE; 099 } 100 } 101 102 /** 103 * @see railo.transformer.bytecode.Literal#getDouble(java.lang.Double) 104 */ 105 public Double getDouble(Double defaultValue) { 106 return getDouble(); 107 } 108 109 /** 110 * @see railo.transformer.bytecode.Literal#getBoolean(java.lang.Boolean) 111 */ 112 public Boolean getBoolean(Boolean defaultValue) { 113 return getBoolean(); 114 } 115 116 /* * 117 * @see railo.transformer.bytecode.expression.Expression#getType() 118 * / 119 public int getType() { 120 return Types._BOOLEAN; 121 }*/ 122 }