List of usage examples for org.objectweb.asm Label Label
public Label()
From source file:com.yahoo.yqlplus.engine.internal.plan.types.base.IterateFirstSequence.java
@Override public void generate(CodeEmitter start) { CodeEmitter code = start.createScope(); Label done = new Label(); Label isNull = new Label(); MethodVisitor mv = code.getMethodVisitor(); BytecodeExpression tgt = code.evaluateOnce(target); tgt.generate(code);/*from ww w .ja v a2 s . c om*/ code.emitInstanceCheck(tgt.getType(), Iterable.class, isNull); AssignableValue iterator = code.allocate(Iterator.class); mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, Type.getInternalName(Iterable.class), "iterator", Type.getMethodDescriptor(Type.getType(Iterator.class)), true); code.exec(iterator.write(code.adapt(Iterator.class))); code.exec(iterator.read()); mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, Type.getInternalName(Iterator.class), "hasNext", Type.getMethodDescriptor(Type.BOOLEAN_TYPE), true); mv.visitJumpInsn(Opcodes.IFEQ, isNull); code.exec(iterator.read()); mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, Type.getInternalName(Iterator.class), "next", Type.getMethodDescriptor(Type.getType(Object.class)), true); code.cast(valueType, AnyTypeWidget.getInstance(), isNull); mv.visitJumpInsn(Opcodes.GOTO, done); mv.visitLabel(isNull); mv.visitInsn(Opcodes.ACONST_NULL); mv.visitLabel(done); }
From source file:com.yahoo.yqlplus.engine.internal.plan.types.base.IterateSequence.java
@Override public void generate(CodeEmitter code) { Label done = new Label(); Label next = new Label(); MethodVisitor mv = code.getMethodVisitor(); BytecodeExpression tgt = code.evaluateOnce(target); code.exec(tgt);//from w w w . java 2s . c om code.emitInstanceCheck(tgt.getType(), Iterable.class, done); AssignableValue item = this.item == null ? code.allocate(valueType) : this.item; AssignableValue iterator = code.allocate(Iterator.class); mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, Type.getInternalName(Iterable.class), "iterator", Type.getMethodDescriptor(Type.getType(Iterator.class)), true); code.exec(iterator.write(code.adapt(Iterator.class))); mv.visitLabel(next); code.exec(iterator.read()); mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, Type.getInternalName(Iterator.class), "hasNext", Type.getMethodDescriptor(Type.BOOLEAN_TYPE), true); mv.visitJumpInsn(Opcodes.IFEQ, done); code.exec(iterator.read()); mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, Type.getInternalName(Iterator.class), "next", Type.getMethodDescriptor(Type.getType(Object.class)), true); code.cast(valueType, AnyTypeWidget.getInstance()); // , next); // don't skip nulls code.exec(item.write(item.getType())); loop.item(code, item.read(), done, next); mv.visitJumpInsn(Opcodes.GOTO, next); mv.visitLabel(done); }
From source file:com.yahoo.yqlplus.engine.internal.plan.types.base.NullTestingSerializationAdapter.java
@Override public BytecodeSequence serializeTo(final BytecodeExpression input, final BytecodeExpression generator) { return new BytecodeSequence() { @Override/*www . j a v a 2 s.c o m*/ public void generate(CodeEmitter code) { Label isNull = new Label(); Label done = new Label(); BytecodeExpression source = code.evaluateOnce(input); code.gotoIfNull(source, isNull); MethodVisitor mv = code.getMethodVisitor(); code.exec(targetAdapter.serializeTo(source, generator)); mv.visitJumpInsn(Opcodes.GOTO, done); mv.visitLabel(isNull); switch (encoding) { case TBIN: code.exec(generator); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(TBinEncoder.class), "writeNull", Type.getMethodDescriptor(Type.VOID_TYPE), false); break; case JSON: code.exec(generator); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(JsonGenerator.class), "writeNull", Type.getMethodDescriptor(Type.VOID_TYPE), false); break; default: throw new UnsupportedOperationException("unknown NativeEncoding: " + encoding); } mv.visitLabel(done); } }; }
From source file:com.yahoo.yqlplus.engine.internal.plan.types.base.StringSwitchSequence.java
@Override public void generate(CodeEmitter code) { Map<String, Label> labelMap = Maps.newHashMapWithExpectedSize(sequenceMap.size()); for (String key : sequenceMap.keySet()) { labelMap.put(key, new Label()); }//from www . ja v a 2 s . c o m Label done = new Label(); Label defaultCase = defaultSequence == BytecodeSequence.NOOP ? done : new Label(); code.exec(input); code.emitInstanceCheck(input.getType(), String.class, defaultCase); code.emitStringSwitch(labelMap, defaultCase, caseInsensitive); MethodVisitor mv = code.getMethodVisitor(); for (Map.Entry<String, BytecodeSequence> e : sequenceMap.entrySet()) { mv.visitLabel(labelMap.get(e.getKey())); code.exec(e.getValue()); mv.visitJumpInsn(Opcodes.GOTO, done); } if (defaultCase != done) { mv.visitLabel(defaultCase); code.exec(defaultSequence); } mv.visitLabel(done); }
From source file:de.chimos.property.compiler.passtwo.javafx.PassTwoJFXClassVisitor.java
License:Open Source License
protected void generatePropertyMethod(PropertyInfo property) { MethodVisitor mv = cv.visitMethod(property.writeAccessLevel + ACC_FINAL, property.propertyMethodName, "()" + property.propertyInterfaceSignature, property.propertyInterfaceSignatureGeneric != null ? "()" + property.propertyInterfaceSignatureGeneric : null,//from ww w .j av a 2s .c om null); { AnnotationVisitor av0 = mv.visitAnnotation("L" + Property.class.getName().replace('.', '/') + ";", true); av0.visit("writeable", Boolean.TRUE); av0.visit("name", property.propertyName); av0.visit("dataSignature", property.dataSignature); av0.visit("dataSignatureGeneric", property.dataSignatureGeneric != null ? property.dataSignatureGeneric : ""); av0.visit("humanReadableName", property.humanReadablePropertyName != null ? property.humanReadablePropertyName : ""); av0.visitEnd(); } mv.visitCode(); Label l0 = new Label(); mv.visitLabel(l0); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, className, property.propertyFieldName, property.propertyDataSignature); Label l1 = new Label(); mv.visitJumpInsn(IFNONNULL, l1); Label l2 = new Label(); mv.visitLabel(l2); mv.visitVarInsn(ALOAD, 0); mv.visitTypeInsn(NEW, property.propertyDataType); mv.visitInsn(DUP); mv.visitVarInsn(ALOAD, 0); mv.visitLdcInsn(property.propertyName); mv.visitMethodInsn(INVOKESPECIAL, property.propertyDataType, "<init>", "(Ljava/lang/Object;Ljava/lang/String;)V"); mv.visitFieldInsn(PUTFIELD, className, property.propertyFieldName, property.propertyDataSignature); mv.visitLabel(l1); mv.visitFrame(F_SAME, 0, null, 0, null); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, className, property.propertyFieldName, property.propertyDataSignature); mv.visitTypeInsn(CHECKCAST, property.propertyInterfaceType); mv.visitInsn(ARETURN); Label l3 = new Label(); mv.visitLabel(l3); mv.visitLocalVariable("this", "L" + className + ";", null, l0, l3, 0); mv.visitMaxs(5, 1); mv.visitEnd(); }
From source file:de.chimos.property.compiler.passtwo.javafx.PassTwoJFXClassVisitor.java
License:Open Source License
protected void generateReadOnlyPropertyMethod(PropertyInfo property) { MethodVisitor mv = cv.visitMethod(property.readAccessLevel + ACC_FINAL, property.readOnlyPropertyMethodName, "()" + property.readOnlyPropertyInterfaceSignature, property.readOnlyPropertyInterfaceSignatureGeneric != null ? "()" + property.readOnlyPropertyInterfaceSignatureGeneric : null,//w w w . jav a 2s .com null); { AnnotationVisitor av0 = mv.visitAnnotation("L" + Property.class.getName().replace('.', '/') + ";", true); av0.visit("writeable", Boolean.FALSE); av0.visit("name", property.propertyName); av0.visit("dataSignature", property.dataSignature); av0.visit("dataSignatureGeneric", property.dataSignatureGeneric != null ? property.dataSignatureGeneric : ""); av0.visit("humanReadableName", property.humanReadablePropertyName != null ? property.humanReadablePropertyName : ""); av0.visitEnd(); } mv.visitCode(); Label l0 = new Label(); mv.visitLabel(l0); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, className, property.propertyFieldName, property.propertyDataSignature); Label l1 = new Label(); mv.visitJumpInsn(IFNONNULL, l1); Label l2 = new Label(); mv.visitLabel(l2); mv.visitVarInsn(ALOAD, 0); mv.visitTypeInsn(NEW, property.propertyDataType); mv.visitInsn(DUP); mv.visitVarInsn(ALOAD, 0); mv.visitLdcInsn(property.propertyName); mv.visitMethodInsn(INVOKESPECIAL, property.propertyDataType, "<init>", "(Ljava/lang/Object;Ljava/lang/String;)V"); mv.visitFieldInsn(PUTFIELD, className, property.propertyFieldName, property.propertyDataSignature); mv.visitLabel(l1); mv.visitFrame(F_SAME, 0, null, 0, null); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, className, property.propertyFieldName, property.propertyDataSignature); mv.visitMethodInsn(INVOKEVIRTUAL, property.propertyDataType, "getReadOnlyProperty", "()" + property.readOnlyPropertyInterfaceSignature); mv.visitTypeInsn(CHECKCAST, property.readOnlyPropertyInterfaceType); mv.visitInsn(ARETURN); Label l3 = new Label(); mv.visitLabel(l3); mv.visitLocalVariable("this", "L" + className + ";", null, l0, l3, 0); mv.visitMaxs(5, 1); mv.visitEnd(); }
From source file:de.chimos.property.compiler.passtwo.javafx.PassTwoJFXClassVisitor.java
License:Open Source License
protected void generateInternalGetterMethod(PropertyInfo property) { MethodVisitor mv = cv.visitMethod(ACC_PRIVATE + ACC_FINAL, property.internalGetterMethodName, "()" + property.dataSignature, property.dataSignatureGeneric != null ? "()" + property.dataSignatureGeneric : null, null); mv.visitCode();//from w ww .j a v a2s.co m Label l0 = new Label(); mv.visitLabel(l0); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKEVIRTUAL, className, property.propertyMethodName, "()" + property.propertyInterfaceSignature); mv.visitMethodInsn(INVOKEVIRTUAL, property.propertyInterfaceType, "getValue", "()Ljava/lang/Object;"); mv.visitTypeInsn(CHECKCAST, property.dataType); mv.visitInsn(ARETURN); Label l1 = new Label(); mv.visitLabel(l1); mv.visitLocalVariable("this", "L" + className + ";", null, l0, l1, 0); mv.visitMaxs(1, 1); mv.visitEnd(); }
From source file:de.chimos.property.compiler.passtwo.javafx.PassTwoJFXClassVisitor.java
License:Open Source License
protected void generateInternalSetterMethod(PropertyInfo property) { MethodVisitor mv = cv.visitMethod(ACC_PRIVATE + ACC_FINAL, property.internalSetterMethodName, "(" + property.dataSignature + ")V", property.dataSignatureGeneric != null ? "(" + property.dataSignatureGeneric + ")V" : null, null); mv.visitCode();/*w w w . j a va2 s .co m*/ Label l0 = new Label(); mv.visitLabel(l0); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKEVIRTUAL, className, property.propertyMethodName, "()" + property.propertyInterfaceSignature); mv.visitVarInsn(ALOAD, 1); mv.visitMethodInsn(INVOKEVIRTUAL, property.propertyInterfaceType, "setValue", "(Ljava/lang/Object;)V"); Label l1 = new Label(); mv.visitLabel(l1); mv.visitInsn(RETURN); Label l2 = new Label(); mv.visitLabel(l2); mv.visitLocalVariable("this", "L" + className + ";", null, l0, l2, 0); mv.visitLocalVariable("value", property.dataSignature, null, l0, l2, 1); mv.visitMaxs(2, 2); mv.visitEnd(); }
From source file:de.chimos.property.compiler.passtwo.javafx.PassTwoJFXClassVisitor.java
License:Open Source License
protected void generateGetterMethod(PropertyInfo property) { MethodVisitor mv = cv.visitMethod(property.readAccessLevel, property.getterMethodName, "()" + property.dataSignature, property.dataSignatureGeneric != null ? "()" + property.dataSignatureGeneric : null, null); if (property.enableSerialization == true && config.serialization == Config.Serialization.JAXB) { AnnotationVisitor av0 = mv.visitAnnotation("Ljavax/xml/bind/annotation/XmlElement;", true); av0.visitEnd();/*from www.j a v a 2 s .c om*/ } mv.visitCode(); Label l0 = new Label(); mv.visitLabel(l0); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKESPECIAL, className, property.internalGetterMethodName, "()" + property.dataSignature); mv.visitInsn(ARETURN); Label l1 = new Label(); mv.visitLabel(l1); mv.visitLocalVariable("this", "L" + className + ";", null, l0, l1, 0); mv.visitMaxs(1, 1); mv.visitEnd(); }
From source file:de.chimos.property.compiler.passtwo.javafx.PassTwoJFXClassVisitor.java
License:Open Source License
protected void generateSetterMethod(PropertyInfo property) { MethodVisitor mv = cv.visitMethod(property.writeAccessLevel, property.setterMethodName, "(" + property.dataSignature + ")V", property.dataSignatureGeneric != null ? "(" + property.dataSignatureGeneric + ")V" : null, null); mv.visitCode();/*from ww w . j a va 2s . c o m*/ Label l0 = new Label(); mv.visitLabel(l0); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, 1); mv.visitMethodInsn(INVOKESPECIAL, className, property.internalSetterMethodName, "(" + property.dataSignature + ")V"); Label l1 = new Label(); mv.visitLabel(l1); mv.visitInsn(RETURN); Label l2 = new Label(); mv.visitLabel(l2); mv.visitLocalVariable("this", "L" + className + ";", null, l0, l2, 0); mv.visitLocalVariable("value", property.dataSignature, null, l0, l2, 1); mv.visitMaxs(2, 2); mv.visitEnd(); }