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.statement;
020
021import lucee.transformer.bytecode.BytecodeContext;
022import lucee.transformer.bytecode.BytecodeException;
023import lucee.transformer.bytecode.Position;
024import lucee.transformer.bytecode.cast.CastString;
025import lucee.transformer.bytecode.expression.ExprString;
026import lucee.transformer.bytecode.expression.Expression;
027import lucee.transformer.bytecode.util.Types;
028
029import org.objectweb.asm.Type;
030import org.objectweb.asm.commons.GeneratorAdapter;
031import org.objectweb.asm.commons.Method;
032
033public final class PrintOut extends StatementBaseNoFinal {
034
035        // void write (String)
036    private final static Method METHOD_WRITE =  new Method("write",
037                        Types.VOID,
038                        new Type[]{Types.STRING});
039    // void writePSQ (Object) TODO muss param 1 wirklich objekt sein
040    private final static Method METHOD_WRITE_PSQ = new Method("writePSQ",
041                        Types.VOID,
042                        new Type[]{Types.OBJECT}); 
043    
044    Expression expr;
045
046        private boolean checkPSQ;
047
048  
049    
050    /**
051     * constructor of the class
052     * @param expr
053     * @param line 
054     */
055    public PrintOut(Expression expr, Position start,Position end) {
056        super(start,end);
057        this.expr=CastString.toExprString(expr);
058    }
059
060
061    /**
062     * @see lucee.transformer.bytecode.Statement#_writeOut(org.objectweb.asm.commons.GeneratorAdapter)
063     */
064    public void _writeOut(BytecodeContext bc) throws BytecodeException {
065        GeneratorAdapter adapter = bc.getAdapter();
066        adapter.loadArg(0);
067        ExprString es=CastString.toExprString(expr);
068        boolean usedExternalizer=false;
069        
070        /*if(es instanceof LitString) {
071                LitString ls = ((LitString)es);
072                ls.setExternalize(true);
073        }*/
074        
075        if(!usedExternalizer)es.writeOut(bc,Expression.MODE_REF);
076        adapter.invokeVirtual(Types.PAGE_CONTEXT,checkPSQ?METHOD_WRITE_PSQ:METHOD_WRITE);
077    }
078
079
080        /**
081         * @return the expr
082         */
083        public Expression getExpr() {
084                return expr;
085        }
086
087        /**
088         * @param expr the expr to set
089         */
090        public void setExpr(Expression expr) {
091                this.expr = expr;
092        }
093
094
095        /**
096         * @param preserveSingleQuote the preserveSingleQuote to set
097         */
098        public void setCheckPSQ(boolean checkPSQ) {
099                this.checkPSQ = checkPSQ;
100        }
101}