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.op; 020 021import lucee.transformer.bytecode.BytecodeContext; 022import lucee.transformer.bytecode.BytecodeException; 023import lucee.transformer.bytecode.cast.CastBoolean; 024import lucee.transformer.bytecode.expression.ExprBoolean; 025import lucee.transformer.bytecode.expression.Expression; 026import lucee.transformer.bytecode.expression.ExpressionBase; 027import lucee.transformer.bytecode.util.ExpressionUtil; 028import lucee.transformer.bytecode.util.Types; 029 030import org.objectweb.asm.Label; 031import org.objectweb.asm.Opcodes; 032import org.objectweb.asm.Type; 033import org.objectweb.asm.commons.GeneratorAdapter; 034 035public final class OpContional extends ExpressionBase { 036 037 private ExprBoolean cont; 038 private Expression left; 039 private Expression right; 040 041 /** 042 * 043 * @see lucee.transformer.bytecode.expression.ExpressionBase#_writeOut(org.objectweb.asm.commons.GeneratorAdapter, int) 044 */ 045 public Type _writeOut(BytecodeContext bc, int mode) throws BytecodeException { 046 GeneratorAdapter adapter = bc.getAdapter(); 047 048 049 Label yes = new Label(); 050 Label end = new Label(); 051 052 // cont 053 ExpressionUtil.visitLine(bc, cont.getStart()); 054 cont.writeOut(bc, MODE_VALUE); 055 ExpressionUtil.visitLine(bc, cont.getEnd()); 056 adapter.visitJumpInsn(Opcodes.IFEQ, yes); 057 058 // left 059 ExpressionUtil.visitLine(bc, left.getStart()); 060 left.writeOut(bc, MODE_REF); 061 ExpressionUtil.visitLine(bc, left.getEnd()); 062 adapter.visitJumpInsn(Opcodes.GOTO, end); 063 064 // right 065 ExpressionUtil.visitLine(bc, right.getStart()); 066 adapter.visitLabel(yes); 067 right.writeOut(bc, MODE_REF); 068 ExpressionUtil.visitLine(bc, right.getEnd()); 069 adapter.visitLabel(end); 070 071 return Types.OBJECT; 072 073 } 074 075 076 077 078 079 080 081 private OpContional(Expression cont, Expression left, Expression right) { 082 super(left.getStart(),right.getEnd()); 083 this.cont=CastBoolean.toExprBoolean(cont); 084 this.left=left; 085 this.right=right; 086 } 087 088 089 public static Expression toExpr(Expression cont, Expression left, Expression right) { 090 return new OpContional(cont,left,right); 091 } 092 093 094 /* * 095 * @see lucee.transformer.bytecode.expression.Expression#getType() 096 * / 097 public int getType() { 098 return Types._BOOLEAN; 099 }*/ 100} 101