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