isNull.gotoLabel(label);
.ifTrueGoto(leftIsTrue) .push(false) .gotoLabel(end) .comment("left was true; push left null flag on the stack (false)") .visitLabel(leftIsTrue) .pop(boolean.class) .push(false) .gotoLabel(end) .comment("right was true; store left null flag (on stack) in wasNull variable, and push true") .visitLabel(rightIsTrue)
.ifFalseGoto(leftIsFalse) .push(true) .gotoLabel(end) .comment("left was false; push left null flag on the stack (false)") .visitLabel(leftIsFalse) .pop(boolean.class) .push(true) .gotoLabel(end) .comment("right was false; store left null flag (on stack) in wasNull variable, and push false") .visitLabel(rightIsTrue)
.condition(invokeStatic(InCodeGenerator.class, "isInteger", boolean.class, value)) .ifFalse(new BytecodeBlock() .gotoLabel(defaultLabel))) .append(expression.set(value.cast(int.class))) .append(switchBuilder.build()); .append(generatorContext.wasNull().set(constantFalse())) .push(true) .gotoLabel(end); block.append(matchBlock); .visitLabel(noMatch) .push(false) .gotoLabel(end); block.append(noMatchBlock);
.putVariable(wasNull, true) .pushJavaDefault(javaType) .gotoLabel(end);
public static BytecodeBlock unboxPrimitiveIfNecessary(Scope scope, Class<?> boxedType) { BytecodeBlock block = new BytecodeBlock(); LabelNode end = new LabelNode("end"); Class<?> unboxedType = Primitives.unwrap(boxedType); Variable wasNull = scope.getVariable("wasNull"); if (unboxedType.isPrimitive()) { LabelNode notNull = new LabelNode("notNull"); block.dup(boxedType) .ifNotNullGoto(notNull) .append(wasNull.set(constantTrue())) .comment("swap boxed null with unboxed default") .pop(boxedType) .pushJavaDefault(unboxedType) .gotoLabel(end) .visitLabel(notNull) .append(unboxPrimitive(unboxedType)); } else { block.dup(boxedType) .ifNotNullGoto(end) .append(wasNull.set(constantTrue())); } block.visitLabel(end); return block; }
.ifFalse(new BytecodeBlock() .putVariable(finishedVariable, true) .gotoLabel(done))) .comment("do the projection") .append(createProjectIfStatement(classDefinition, method, session, cursor, pageBuilder, projections))
@Override public void accept(MethodVisitor visitor, MethodGenerationContext generationContext) { checkState(!condition.isEmpty(), "WhileLoop does not have a condition set"); BytecodeBlock block = new BytecodeBlock() .visitLabel(continueLabel) .append(condition) .ifZeroGoto(endLabel) .append(body) .gotoLabel(continueLabel) .visitLabel(endLabel); block.accept(visitor, generationContext); }
@Override public BytecodeNode getBytecode(MethodGenerationContext generationContext) { LabelNode trueLabel = new LabelNode("true"); LabelNode endLabel = new LabelNode("end"); return new BytecodeBlock() .append(value) .ifTrueGoto(trueLabel) .push(true) .gotoLabel(endLabel) .visitLabel(trueLabel) .push(false) .visitLabel(endLabel); }
@Override public BytecodeNode getBytecode(MethodGenerationContext generationContext) { LabelNode falseLabel = new LabelNode("false"); LabelNode endLabel = new LabelNode("end"); return new BytecodeBlock() .append(condition) .ifFalseGoto(falseLabel) .append(ifTrue) .gotoLabel(endLabel) .visitLabel(falseLabel) .append(ifFalse) .visitLabel(endLabel); }
@Override public void accept(MethodVisitor visitor, MethodGenerationContext generationContext) { // build switch table int[] keys = new int[cases.size()]; Label[] labels = new Label[cases.size()]; int index = 0; for (CaseStatement caseStatement : cases) { keys[index] = caseStatement.getKey(); labels[index] = caseStatement.getLabel().getLabel(); index++; } // build case blocks BytecodeBlock block = new BytecodeBlock(); for (CaseStatement caseStatement : cases) { block.visitLabel(caseStatement.getLabel()) .append(caseStatement.getBody()) .gotoLabel(endLabel); } // build default block block.visitLabel(defaultLabel); if (defaultBody != null) { block.append(defaultBody); } block.visitLabel(endLabel); // emit code expression.accept(visitor, generationContext); visitor.visitLookupSwitchInsn(defaultLabel.getLabel(), keys, labels); block.accept(visitor, generationContext); }
@Override public void accept(MethodVisitor visitor, MethodGenerationContext generationContext) { checkState(!condition.isEmpty(), "DoWhileLoop does not have a condition set"); BytecodeBlock block = new BytecodeBlock() .visitLabel(beginLabel) .append(new BytecodeBlock() .setDescription("body") .append(body)) .visitLabel(continueLabel) .append(new BytecodeBlock() .setDescription("condition") .append(condition)) .ifFalseGoto(endLabel) .gotoLabel(beginLabel) .visitLabel(endLabel); block.accept(visitor, generationContext); }
@Override public BytecodeNode getBytecode(MethodGenerationContext generationContext) { LabelNode trueLabel = new LabelNode("true"); LabelNode endLabel = new LabelNode("end"); return new BytecodeBlock() .append(left) .ifTrueGoto(trueLabel) .append(right) .ifTrueGoto(trueLabel) .push(false) .gotoLabel(endLabel) .visitLabel(trueLabel) .push(true) .visitLabel(endLabel); }
@Override public BytecodeNode getBytecode(MethodGenerationContext generationContext) { LabelNode falseLabel = new LabelNode("false"); LabelNode endLabel = new LabelNode("end"); return new BytecodeBlock() .append(left) .ifFalseGoto(falseLabel) .append(right) .ifFalseGoto(falseLabel) .push(true) .gotoLabel(endLabel) .visitLabel(falseLabel) .push(false) .visitLabel(endLabel); }
@Override public BytecodeNode getBytecode(MethodGenerationContext generationContext) { BytecodeBlock block = new BytecodeBlock() .append(left) .append(right); if (comparisonInstruction != null) { block.append(comparisonInstruction); } LabelNode noMatch = new LabelNode("no_match"); LabelNode end = new LabelNode("end"); return block .append(new JumpInstruction(noMatchJumpInstruction, noMatch)) .push(true) .gotoLabel(end) .append(noMatch) .push(false) .append(end); }
@Override public void accept(MethodVisitor visitor, MethodGenerationContext generationContext) { LabelNode tryStart = new LabelNode("tryStart"); LabelNode tryEnd = new LabelNode("tryEnd"); LabelNode handler = new LabelNode("handler"); LabelNode done = new LabelNode("done"); BytecodeBlock block = new BytecodeBlock(); // try block block.visitLabel(tryStart) .append(tryNode) .visitLabel(tryEnd) .gotoLabel(done); // handler block block.visitLabel(handler) .append(catchNode); // all done block.visitLabel(done); block.accept(visitor, generationContext); visitor.visitTryCatchBlock(tryStart.getLabel(), tryEnd.getLabel(), handler.getLabel(), exceptionName); }
public static BytecodeBlock unboxPrimitiveIfNecessary(Scope scope, Class<?> boxedType) { BytecodeBlock block = new BytecodeBlock(); LabelNode end = new LabelNode("end"); Class<?> unboxedType = Primitives.unwrap(boxedType); Variable wasNull = scope.getVariable("wasNull"); if (unboxedType.isPrimitive()) { LabelNode notNull = new LabelNode("notNull"); block.dup(boxedType) .ifNotNullGoto(notNull) .append(wasNull.set(constantTrue())) .comment("swap boxed null with unboxed default") .pop(boxedType) .pushJavaDefault(unboxedType) .gotoLabel(end) .visitLabel(notNull) .append(unboxPrimitive(unboxedType)); } else { block.dup(boxedType) .ifNotNullGoto(end) .append(wasNull.set(constantTrue())); } block.visitLabel(end); return block; }
@Override public void accept(MethodVisitor visitor, MethodGenerationContext generationContext) { checkState(!condition.isEmpty(), "ForLoop does not have a condition set"); BytecodeBlock block = new BytecodeBlock(); block.append(new BytecodeBlock() .setDescription("initialize") .append(initialize)); block.visitLabel(beginLabel) .append(new BytecodeBlock() .setDescription("condition") .append(condition)) .ifFalseGoto(endLabel); block.append(new BytecodeBlock() .setDescription("body") .append(body)); block.visitLabel(continueLabel) .append(new BytecodeBlock() .setDescription("update") .append(update)) .gotoLabel(beginLabel) .visitLabel(endLabel); block.accept(visitor, generationContext); }