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; 024import lucee.transformer.bytecode.util.Types; 025 026import org.objectweb.asm.Label; 027import org.objectweb.asm.Opcodes; 028import org.objectweb.asm.commons.GeneratorAdapter; 029 030/** 031 * @deprecated replaced with ForIntVisitor 032 */ 033public final class ForConditionIntVisitor implements Opcodes, LoopVisitor { 034 035 private Label l0; 036 private Label l1; 037 private Label l2; 038 private Label l3; 039 private int i; 040 private Label lend; 041 private Label lbegin; 042 public int visitBegin(GeneratorAdapter adapter, int start, boolean isLocal) { 043 044 lend = new Label(); 045 lbegin = new Label(); 046 047 i=adapter.newLocal(Types.INT_VALUE); 048 049 l0 = new Label(); 050 adapter.visitLabel(l0); 051 if(isLocal)adapter.loadLocal(start,Types.INT_VALUE); 052 else adapter.push(start); 053 //mv.visitInsn(ICONST_1); 054 adapter.visitVarInsn(ISTORE, i); 055 l1 = new Label(); 056 adapter.visitLabel(l1); 057 l2 = new Label(); 058 adapter.visitJumpInsn(GOTO, l2); 059 l3 = new Label(); 060 adapter.visitLabel(l3); 061 062 return i; 063 } 064 public void visitEndBeforeCondition(BytecodeContext bc, int step, boolean isLocal,Position startline) { 065 GeneratorAdapter adapter = bc.getAdapter(); 066 067 068 adapter.visitLabel(lbegin); 069 if(isLocal) { 070 adapter.visitVarInsn(ILOAD, i); 071 //adapter.loadLocal(i); 072 adapter.loadLocal(step); 073 adapter.visitInsn(IADD); 074 //adapter.dup(); 075 adapter.visitVarInsn(ISTORE, i); 076 077 } 078 else adapter.visitIincInsn(i, step); 079 ExpressionUtil.visitLine(bc, startline); 080 adapter.visitLabel(l2); 081 } 082 083 public void visitEndAfterCondition(BytecodeContext bc) { 084 GeneratorAdapter adapter = bc.getAdapter(); 085 086 adapter.ifZCmp(Opcodes.IFNE, l3); 087 088 adapter.visitLabel(lend); 089 090 adapter.visitLocalVariable("i", "I", null, l1, lend, i); 091 092 } 093 094 095 /** 096 * 097 * @see lucee.transformer.bytecode.visitor.LoopVisitor#visitContinue(org.objectweb.asm.commons.GeneratorAdapter) 098 */ 099 public void visitContinue(BytecodeContext bc) { 100 bc.getAdapter().visitJumpInsn(Opcodes.GOTO, lbegin); 101 } 102 103 /** 104 * 105 * @see lucee.transformer.bytecode.visitor.LoopVisitor#visitBreak(org.objectweb.asm.commons.GeneratorAdapter) 106 */ 107 public void visitBreak(BytecodeContext bc) { 108 bc.getAdapter().visitJumpInsn(Opcodes.GOTO, lend); 109 } 110 111 /** 112 * 113 * @see lucee.transformer.bytecode.visitor.LoopVisitor#getContinueLabel() 114 */ 115 public Label getContinueLabel() { 116 return lbegin; 117 } 118 119 /** 120 * 121 * @see lucee.transformer.bytecode.visitor.LoopVisitor#getBreakLabel() 122 */ 123 public Label getBreakLabel() { 124 return lend; 125 } 126}