public static void leadFlow(BytecodeContext bc, Statement stat, int flowType, String label) throws BytecodeException { List<FlowControlFinal> finallyLabels = new ArrayList<FlowControlFinal>(); FlowControl fc; String name; if (FlowControl.BREAK == flowType) { fc = ASMUtil.getAncestorBreakFCStatement(stat, finallyLabels, label); name = "break"; } else if (FlowControl.CONTINUE == flowType) { fc = ASMUtil.getAncestorContinueFCStatement(stat, finallyLabels, label); name = "continue"; } else { fc = ASMUtil.getAncestorRetryFCStatement(stat, finallyLabels, label); name = "retry"; } if (fc == null) throw new BytecodeException( name + " must be inside a loop (for,while,do-while,<cfloop>,<cfwhile> ...)", stat.getStart()); GeneratorAdapter adapter = bc.getAdapter(); Label end; if (FlowControl.BREAK == flowType) end = ((FlowControlBreak) fc).getBreakLabel(); else if (FlowControl.CONTINUE == flowType) end = ((FlowControlContinue) fc).getContinueLabel(); else end = ((FlowControlRetry) fc).getRetryLabel(); // first jump to all final labels FlowControlFinal[] arr = finallyLabels.toArray(new FlowControlFinal[finallyLabels.size()]); if (arr.length > 0) { FlowControlFinal fcf; for (int i = 0; i < arr.length; i++) { fcf = arr[i]; // first if (i == 0) { adapter.visitJumpInsn(Opcodes.GOTO, fcf.getFinalEntryLabel()); } // last if (arr.length == i + 1) fcf.setAfterFinalGOTOLabel(end); else fcf.setAfterFinalGOTOLabel(arr[i + 1].getFinalEntryLabel()); } } else bc.getAdapter().visitJumpInsn(Opcodes.GOTO, end); }
/** * @see * lucee.transformer.bytecode.expression.ExpressionBase#_writeOut(org.objectweb.asm.commons.GeneratorAdapter, * int) */ @Override public Type _writeOut(BytecodeContext bc, int mode) throws TransformerException { GeneratorAdapter adapter = bc.getAdapter(); if (mode == MODE_REF) { _writeOut(bc, MODE_VALUE); adapter.invokeStatic(Types.CASTER, Methods.METHOD_TO_BOOLEAN_FROM_BOOLEAN); return Types.BOOLEAN; } Label l1 = new Label(); Label l2 = new Label(); expr.writeOut(bc, MODE_VALUE); adapter.ifZCmp(Opcodes.IFEQ, l1); adapter.visitInsn(Opcodes.ICONST_0); adapter.visitJumpInsn(Opcodes.GOTO, l2); adapter.visitLabel(l1); adapter.visitInsn(Opcodes.ICONST_1); adapter.visitLabel(l2); return Types.BOOLEAN_VALUE; }
private void _writeOutCatch(BytecodeContext bc, int lRef, int lThrow) throws BytecodeException { GeneratorAdapter adapter = bc.getAdapter(); int pe = adapter.newLocal(Types.PAGE_EXCEPTION); // instance of Abort Label abortEnd = new Label(); adapter.loadLocal(lThrow); adapter.invokeStatic(Types.ABORT, TryCatchFinally.IS_ABORT); // adapter.instanceOf(Types.ABORT); adapter.ifZCmp(Opcodes.IFEQ, abortEnd); adapter.loadLocal(lThrow); adapter.throwException(); adapter.visitLabel(abortEnd); // PageExceptionImpl old=pc.getCatch(); int old = adapter.newLocal(Types.PAGE_EXCEPTION); adapter.loadArg(0); adapter.invokeVirtual(Types.PAGE_CONTEXT, TagTry.GET_CATCH); adapter.storeLocal(old); // cast to PageException Caster.toPagException(t); adapter.loadLocal(lThrow); adapter.invokeStatic(Types.CASTER, TO_PAGE_EXCEPTION); // PageException pe=... adapter.storeLocal(pe); // catch loop Label endAllIf = new Label(); Iterator<Catch> it = catches.iterator(); Catch ctElse = null; while (it.hasNext()) { Catch ct = it.next(); // store any for else if (ct.type != null && ct.type instanceof LitString && ((LitString) ct.type).getString().equalsIgnoreCase("any")) { ctElse = ct; continue; } ExpressionUtil.visitLine(bc, ct.line); // pe.typeEqual(type) if (ct.type == null) { LitBoolean.TRUE.writeOut(bc, Expression.MODE_VALUE); } else { adapter.loadLocal(pe); ct.type.writeOut(bc, Expression.MODE_REF); adapter.invokeVirtual(Types.PAGE_EXCEPTION, TYPE_EQUAL); } Label endIf = new Label(); adapter.ifZCmp(Opcodes.IFEQ, endIf); catchBody(bc, adapter, ct, pe, lRef, true, true); adapter.visitJumpInsn(Opcodes.GOTO, endAllIf); adapter.visitLabel(endIf); } if (ctElse != null) { catchBody(bc, adapter, ctElse, pe, lRef, true, true); } else { // pc.setCatch(pe,true); adapter.loadArg(0); adapter.loadLocal(pe); adapter.push(false); adapter.push(false); adapter.invokeVirtual(Types.PAGE_CONTEXT, TagTry.SET_CATCH3); adapter.loadLocal(pe); adapter.throwException(); } adapter.visitLabel(endAllIf); // PageExceptionImpl old=pc.setCatch(old); adapter.loadArg(0); adapter.loadLocal(old); adapter.invokeVirtual(Types.PAGE_CONTEXT, TagTry.SET_CATCH_PE); }