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.Body; 022import lucee.transformer.bytecode.BytecodeContext; 023import lucee.transformer.bytecode.BytecodeException; 024import lucee.transformer.bytecode.Position; 025import lucee.transformer.bytecode.cast.CastBoolean; 026import lucee.transformer.bytecode.expression.ExprBoolean; 027import lucee.transformer.bytecode.expression.Expression; 028 029import org.objectweb.asm.Label; 030import org.objectweb.asm.Opcodes; 031import org.objectweb.asm.commons.GeneratorAdapter; 032 033public final class DoWhile extends StatementBaseNoFinal implements FlowControlBreak,FlowControlContinue,HasBody { 034 035 private ExprBoolean expr; 036 private Body body; 037 038 private Label begin = new Label(); 039 private Label beforeEnd = new Label(); 040 private Label end = new Label(); 041 private String label; 042 043 044 /** 045 * Constructor of the class 046 * @param expr 047 * @param body 048 * @param line 049 */ 050 public DoWhile(Expression expr,Body body,Position start, Position end, String label) { 051 super(start,end); 052 this.expr=CastBoolean.toExprBoolean(expr); 053 this.body=body; 054 body.setParent(this); 055 this.label=label; 056 } 057 058 @Override 059 public void _writeOut(BytecodeContext bc) throws BytecodeException { 060 GeneratorAdapter adapter = bc.getAdapter(); 061 adapter.visitLabel(begin); 062 body.writeOut(bc); 063 064 adapter.visitLabel(beforeEnd); 065 066 067 expr.writeOut(bc, Expression.MODE_VALUE); 068 adapter.ifZCmp(Opcodes.IFNE, begin); 069 070 adapter.visitLabel(end); 071 072 } 073 074 @Override 075 public Label getBreakLabel() { 076 return end; 077 } 078 079 @Override 080 public Label getContinueLabel() { 081 return beforeEnd; 082 } 083 084 @Override 085 public Body getBody() { 086 return body; 087 } 088 089 @Override 090 public String getLabel() { 091 return label; 092 } 093 094}