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