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.visitor; 020 021import lucee.transformer.bytecode.BytecodeContext; 022import lucee.transformer.bytecode.Position; 023import lucee.transformer.bytecode.util.ExpressionUtil; 024 025import org.objectweb.asm.Label; 026import org.objectweb.asm.Opcodes; 027 028public final class WhileVisitor implements LoopVisitor { 029 030 private Label begin; 031 private Label end; 032 033 public void visitBeforeExpression(BytecodeContext bc) { 034 begin = new Label(); 035 end = new Label(); 036 bc.getAdapter().visitLabel(begin); 037 } 038 039 public void visitAfterExpressionBeforeBody(BytecodeContext bc) { 040 bc.getAdapter().ifZCmp(Opcodes.IFEQ, end); 041 } 042 043 public void visitAfterBody(BytecodeContext bc,Position endline) { 044 bc.getAdapter().visitJumpInsn(Opcodes.GOTO, begin); 045 bc.getAdapter().visitLabel(end); 046 ExpressionUtil.visitLine(bc, endline); 047 } 048 049 /** 050 * 051 * @see lucee.transformer.bytecode.visitor.LoopVisitor#visitContinue(org.objectweb.asm.commons.GeneratorAdapter) 052 */ 053 public void visitContinue(BytecodeContext bc) { 054 bc.getAdapter().visitJumpInsn(Opcodes.GOTO, begin); 055 } 056 057 /** 058 * 059 * @see lucee.transformer.bytecode.visitor.LoopVisitor#visitBreak(org.objectweb.asm.commons.GeneratorAdapter) 060 */ 061 public void visitBreak(BytecodeContext bc) { 062 bc.getAdapter().visitJumpInsn(Opcodes.GOTO, end); 063 } 064 065 /** 066 * 067 * @see lucee.transformer.bytecode.visitor.LoopVisitor#getContinueLabel() 068 */ 069 public Label getContinueLabel() { 070 return begin; 071 } 072 073 /** 074 * 075 * @see lucee.transformer.bytecode.visitor.LoopVisitor#getBreakLabel() 076 */ 077 public Label getBreakLabel() { 078 return end; 079 } 080 081}