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.Expression; 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 LitLong extends ExpressionBase implements Literal { 037 038 private long l; 039 040 public static Expression toExpr(long l, Position start,Position end) { 041 return new LitLong(l,start,end); 042 } 043 044 /** 045 * constructor of the class 046 * @param d 047 * @param line 048 */ 049 public LitLong(long l, Position start,Position end) { 050 super(start,end); 051 this.l=l; 052 } 053 054 /** 055 * @return return value as int 056 */ 057 public long getLongValue() { 058 return l; 059 } 060 061 /** 062 * @return return value as Double Object 063 */ 064 public Long getLong() { 065 return new Long(l); 066 } 067 068 /** 069 * @see lucee.transformer.bytecode.Literal#getString() 070 */ 071 public String getString() { 072 return Caster.toString(l); 073 } 074 075 /** 076 * @return return value as a Boolean Object 077 */ 078 public Boolean getBoolean() { 079 return Caster.toBoolean(l); 080 } 081 082 /** 083 * @return return value as a boolean value 084 */ 085 public boolean getBooleanValue() { 086 return Caster.toBooleanValue(l); 087 } 088 089 /** 090 * @see lucee.transformer.bytecode.expression.Expression#_writeOut(org.objectweb.asm.commons.GeneratorAdapter, int) 091 */ 092 public Type _writeOut(BytecodeContext bc, int mode) { 093 GeneratorAdapter adapter = bc.getAdapter(); 094 adapter.push(l); 095 if(mode==MODE_REF) { 096 adapter.invokeStatic(Types.CASTER,Methods.METHOD_TO_LONG_FROM_LONG_VALUE); 097 return Types.LONG; 098 } 099 return Types.LONG_VALUE; 100 } 101 102 /** 103 * @see lucee.transformer.bytecode.Literal#getDouble(java.lang.Double) 104 */ 105 public Double getDouble(Double defaultValue) { 106 return getDouble(); 107 } 108 109 private Double getDouble() { 110 return new Double(l); 111 } 112 113 /** 114 * @see lucee.transformer.bytecode.Literal#getBoolean(java.lang.Boolean) 115 */ 116 public Boolean getBoolean(Boolean defaultValue) { 117 return getBoolean(); 118 } 119}