Search in sources :

Example 31 with Label

use of com.alibaba.fastjson.asm.Label in project uavstack by uavorg.

the class ASMSerializerFactory method _filters.

private void _filters(MethodVisitor mw, FieldInfo property, Context context, Label _end) {
    if (property.getField() != null) {
        if (Modifier.isTransient(property.getField().getModifiers())) {
            mw.visitVarInsn(ALOAD, context.var("out"));
            mw.visitFieldInsn(GETSTATIC, "com/alibaba/fastjson/serializer/SerializerFeature", "SkipTransientField", "Lcom/alibaba/fastjson/serializer/SerializerFeature;");
            mw.visitMethodInsn(INVOKEVIRTUAL, "com/alibaba/fastjson/serializer/SerializeWriter", "isEnabled", "(Lcom/alibaba/fastjson/serializer/SerializerFeature;)Z");
            // if true
            mw.visitJumpInsn(IFNE, _end);
        }
    }
    _notWriteDefault(mw, property, context, _end);
    _apply(mw, property, context);
    mw.visitJumpInsn(IFEQ, _end);
    _processKey(mw, property, context);
    Label _else_processKey = new Label();
    _processValue(mw, property, context);
    mw.visitVarInsn(ALOAD, context.original());
    mw.visitVarInsn(ALOAD, context.processValue());
    mw.visitJumpInsn(IF_ACMPEQ, _else_processKey);
    _writeObject(mw, property, context, _end);
    mw.visitJumpInsn(GOTO, _end);
    mw.visitLabel(_else_processKey);
}
Also used : Label(com.alibaba.fastjson.asm.Label)

Example 32 with Label

use of com.alibaba.fastjson.asm.Label in project uavstack by uavorg.

the class ASMSerializerFactory method _writeObject.

private void _writeObject(MethodVisitor mw, FieldInfo fieldInfo, Context context, Label _end) {
    String format = fieldInfo.getFormat();
    Label _not_null = new Label();
    mw.visitVarInsn(ALOAD, context.processValue());
    // if (obj == null)
    mw.visitJumpInsn(IFNONNULL, _not_null);
    _if_write_null(mw, fieldInfo, context);
    mw.visitJumpInsn(GOTO, _end);
    mw.visitLabel(_not_null);
    // writeFieldNullNumber
    mw.visitVarInsn(ALOAD, context.var("out"));
    mw.visitVarInsn(ILOAD, context.var("seperator"));
    mw.visitMethodInsn(INVOKEVIRTUAL, "com/alibaba/fastjson/serializer/SerializeWriter", "write", "(C)V");
    // out.writeFieldName("fieldName")
    mw.visitVarInsn(ALOAD, context.var("out"));
    mw.visitVarInsn(ALOAD, context.fieldName());
    mw.visitMethodInsn(INVOKEVIRTUAL, "com/alibaba/fastjson/serializer/SerializeWriter", "writeFieldName", "(Ljava/lang/String;)V");
    // serializer.write(obj)
    mw.visitVarInsn(ALOAD, context.serializer());
    mw.visitVarInsn(ALOAD, context.processValue());
    if (format != null) {
        mw.visitLdcInsn(format);
        mw.visitMethodInsn(INVOKEVIRTUAL, "com/alibaba/fastjson/serializer/JSONSerializer", "writeWithFormat", "(Ljava/lang/Object;Ljava/lang/String;)V");
    } else {
        mw.visitVarInsn(ALOAD, context.fieldName());
        if (// 
        fieldInfo.getFieldType() instanceof Class<?> && ((Class<?>) fieldInfo.getFieldType()).isPrimitive()) {
            mw.visitMethodInsn(INVOKEVIRTUAL, "com/alibaba/fastjson/serializer/JSONSerializer", "writeWithFieldName", "(Ljava/lang/Object;Ljava/lang/Object;)V");
        } else {
            mw.visitVarInsn(ALOAD, 0);
            mw.visitFieldInsn(GETFIELD, context.getClassName(), fieldInfo.getName() + "_asm_fieldType", "Ljava/lang/reflect/Type;");
            mw.visitLdcInsn(fieldInfo.getSerialzeFeatures());
            mw.visitMethodInsn(INVOKEVIRTUAL, "com/alibaba/fastjson/serializer/JSONSerializer", "writeWithFieldName", "(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/reflect/Type;I)V");
        }
    }
    _seperator(mw, context);
}
Also used : Label(com.alibaba.fastjson.asm.Label)

Example 33 with Label

use of com.alibaba.fastjson.asm.Label in project uavstack by uavorg.

the class ASMSerializerFactory method _string.

private void _string(Class<?> clazz, MethodVisitor mw, FieldInfo property, Context context) {
    Label _end = new Label();
    _nameApply(mw, property, context, _end);
    _get(mw, context, property);
    mw.visitVarInsn(ASTORE, context.var("string"));
    _filters(mw, property, context, _end);
    Label _else = new Label();
    Label _end_if = new Label();
    // if (value == null) {
    mw.visitVarInsn(ALOAD, context.var("string"));
    mw.visitJumpInsn(IFNONNULL, _else);
    _if_write_null(mw, property, context);
    mw.visitJumpInsn(GOTO, _end_if);
    // else { out.writeFieldValue(seperator, fieldName, fieldValue)
    mw.visitLabel(_else);
    mw.visitVarInsn(ALOAD, context.var("out"));
    mw.visitVarInsn(ILOAD, context.var("seperator"));
    mw.visitVarInsn(ALOAD, context.fieldName());
    mw.visitVarInsn(ALOAD, context.var("string"));
    mw.visitMethodInsn(INVOKEVIRTUAL, "com/alibaba/fastjson/serializer/SerializeWriter", "writeFieldValue", "(CLjava/lang/String;Ljava/lang/String;)V");
    _seperator(mw, context);
    mw.visitLabel(_end_if);
    mw.visitLabel(_end);
}
Also used : Label(com.alibaba.fastjson.asm.Label)

Example 34 with Label

use of com.alibaba.fastjson.asm.Label in project uavstack by uavorg.

the class ASMSerializerFactory method _notWriteDefault.

private void _notWriteDefault(MethodVisitor mw, FieldInfo property, Context context, Label _end) {
    Label elseLabel = new Label();
    mw.visitVarInsn(ALOAD, context.var("out"));
    mw.visitFieldInsn(GETSTATIC, "com/alibaba/fastjson/serializer/SerializerFeature", "NotWriteDefaultValue", "Lcom/alibaba/fastjson/serializer/SerializerFeature;");
    mw.visitMethodInsn(INVOKEVIRTUAL, "com/alibaba/fastjson/serializer/SerializeWriter", "isEnabled", "(Lcom/alibaba/fastjson/serializer/SerializerFeature;)Z");
    mw.visitJumpInsn(IFEQ, elseLabel);
    Class<?> propertyClass = property.getFieldClass();
    if (propertyClass == boolean.class) {
        mw.visitVarInsn(ILOAD, context.var("boolean"));
        mw.visitJumpInsn(IFEQ, _end);
    } else if (propertyClass == byte.class) {
        mw.visitVarInsn(ILOAD, context.var("byte"));
        mw.visitJumpInsn(IFEQ, _end);
    } else if (propertyClass == short.class) {
        mw.visitVarInsn(ILOAD, context.var("short"));
        mw.visitJumpInsn(IFEQ, _end);
    } else if (propertyClass == int.class) {
        mw.visitVarInsn(ILOAD, context.var("int"));
        mw.visitJumpInsn(IFEQ, _end);
    } else if (propertyClass == long.class) {
        mw.visitVarInsn(LLOAD, context.var("long"));
        mw.visitInsn(LCONST_0);
        mw.visitInsn(LCMP);
        mw.visitJumpInsn(IFEQ, _end);
    } else if (propertyClass == float.class) {
        mw.visitVarInsn(FLOAD, context.var("float"));
        mw.visitInsn(FCONST_0);
        mw.visitInsn(FCMPL);
        mw.visitJumpInsn(IFEQ, _end);
    } else if (propertyClass == double.class) {
        mw.visitVarInsn(DLOAD, context.var("double"));
        mw.visitInsn(DCONST_0);
        mw.visitInsn(DCMPL);
        mw.visitJumpInsn(IFEQ, _end);
    }
    mw.visitLabel(elseLabel);
}
Also used : Label(com.alibaba.fastjson.asm.Label)

Example 35 with Label

use of com.alibaba.fastjson.asm.Label in project uavstack by uavorg.

the class ASMSerializerFactory method _double.

private void _double(Class<?> clazz, MethodVisitor mw, FieldInfo property, Context context) {
    Label _end = new Label();
    _nameApply(mw, property, context, _end);
    _get(mw, context, property);
    mw.visitVarInsn(DSTORE, context.var("double", 2));
    _filters(mw, property, context, _end);
    mw.visitVarInsn(ALOAD, context.var("out"));
    mw.visitVarInsn(ILOAD, context.var("seperator"));
    mw.visitVarInsn(ALOAD, context.fieldName());
    mw.visitVarInsn(DLOAD, context.var("double", 2));
    mw.visitMethodInsn(INVOKEVIRTUAL, "com/alibaba/fastjson/serializer/SerializeWriter", "writeFieldValue", "(CLjava/lang/String;D)V");
    _seperator(mw, context);
    mw.visitLabel(_end);
}
Also used : Label(com.alibaba.fastjson.asm.Label)

Aggregations

Label (com.alibaba.fastjson.asm.Label)53 ParseContext (com.alibaba.fastjson.parser.ParseContext)8 MethodVisitor (com.alibaba.fastjson.asm.MethodVisitor)5 ParserConfig (com.alibaba.fastjson.parser.ParserConfig)5 FieldInfo (com.alibaba.fastjson.util.FieldInfo)5 MethodWriter (com.alibaba.fastjson.asm.MethodWriter)4 ParameterizedType (java.lang.reflect.ParameterizedType)4 Type (java.lang.reflect.Type)4 BigInteger (java.math.BigInteger)4 List (java.util.List)4 BigDecimal (java.math.BigDecimal)3 ResolveTask (com.alibaba.fastjson.parser.DefaultJSONParser.ResolveTask)2 JSONLexer (com.alibaba.fastjson.parser.JSONLexer)2 SymbolTable (com.alibaba.fastjson.parser.SymbolTable)2 com.alibaba.fastjson.util (com.alibaba.fastjson.util)2 Method (java.lang.reflect.Method)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 LinkedList (java.util.LinkedList)2