Search in sources :

Example 26 with Label

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

the class ASMDeserializerFactory method _setContext.

private void _setContext(Context context, MethodVisitor mw) {
    // parser
    mw.visitVarInsn(ALOAD, 1);
    mw.visitVarInsn(ALOAD, context.var("context"));
    mw.visitMethodInsn(INVOKEVIRTUAL, DefaultJSONParser, "setContext", "(" + desc(ParseContext.class) + ")V");
    Label endIf_ = new Label();
    mw.visitVarInsn(ALOAD, context.var("childContext"));
    mw.visitJumpInsn(IFNULL, endIf_);
    mw.visitVarInsn(ALOAD, context.var("childContext"));
    mw.visitVarInsn(ALOAD, context.var("instance"));
    mw.visitFieldInsn(PUTFIELD, type(ParseContext.class), "object", "Ljava/lang/Object;");
    mw.visitLabel(endIf_);
}
Also used : ParseContext(com.alibaba.fastjson.parser.ParseContext) Label(com.alibaba.fastjson.asm.Label)

Example 27 with Label

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

the class ASMSerializerFactory method _float.

private void _float(Class<?> clazz, MethodVisitor mw, FieldInfo property, Context context) {
    Label end_ = new Label();
    _nameApply(mw, property, context, end_);
    _get(mw, context, property);
    mw.visitVarInsn(FSTORE, context.var("float"));
    _filters(mw, property, context, end_);
    mw.visitVarInsn(ALOAD, context.var("out"));
    mw.visitVarInsn(ILOAD, context.var("seperator"));
    mw.visitVarInsn(ALOAD, Context.fieldName);
    mw.visitVarInsn(FLOAD, context.var("float"));
    mw.visitMethodInsn(INVOKEVIRTUAL, SerializeWriter, "writeFieldValue", "(CLjava/lang/String;F)V");
    _seperator(mw, context);
    mw.visitLabel(end_);
}
Also used : Label(com.alibaba.fastjson.asm.Label)

Example 28 with Label

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

the class ASMSerializerFactory method _getListFieldItemSer.

private void _getListFieldItemSer(Context context, MethodVisitor mw, FieldInfo fieldInfo, Class<?> itemType) {
    Label notNull_ = new Label();
    mw.visitVarInsn(ALOAD, 0);
    mw.visitFieldInsn(GETFIELD, context.className, fieldInfo.name + "_asm_list_item_ser_", ObjectSerializer_desc);
    mw.visitJumpInsn(IFNONNULL, notNull_);
    // this
    mw.visitVarInsn(ALOAD, 0);
    mw.visitVarInsn(ALOAD, Context.serializer);
    mw.visitLdcInsn(com.alibaba.fastjson.asm.Type.getType(desc(itemType)));
    mw.visitMethodInsn(INVOKEVIRTUAL, JSONSerializer, "getObjectWriter", "(Ljava/lang/Class;)" + ObjectSerializer_desc);
    mw.visitFieldInsn(PUTFIELD, context.className, fieldInfo.name + "_asm_list_item_ser_", ObjectSerializer_desc);
    mw.visitLabel(notNull_);
    mw.visitVarInsn(ALOAD, 0);
    mw.visitFieldInsn(GETFIELD, context.className, fieldInfo.name + "_asm_list_item_ser_", ObjectSerializer_desc);
}
Also used : Label(com.alibaba.fastjson.asm.Label)

Example 29 with Label

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

the class ASMSerializerFactory method _object.

private void _object(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("object"));
    _filters(mw, property, context, _end);
    _writeObject(mw, property, context, _end);
    mw.visitLabel(_end);
}
Also used : Label(com.alibaba.fastjson.asm.Label)

Example 30 with Label

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

the class ASMSerializerFactory method _processValue.

private void _processValue(MethodVisitor mw, FieldInfo fieldInfo, Context context, Label _end) {
    Label processKeyElse_ = new Label();
    Class<?> fieldClass = fieldInfo.fieldClass;
    if (fieldClass.isPrimitive()) {
        Label checkValueEnd_ = new Label();
        mw.visitVarInsn(ILOAD, context.var("checkValue"));
        mw.visitJumpInsn(IFNE, checkValueEnd_);
        mw.visitInsn(ACONST_NULL);
        mw.visitInsn(DUP);
        mw.visitVarInsn(ASTORE, Context.original);
        mw.visitVarInsn(ASTORE, Context.processValue);
        mw.visitJumpInsn(GOTO, processKeyElse_);
        mw.visitLabel(checkValueEnd_);
    }
    mw.visitVarInsn(ALOAD, 0);
    mw.visitVarInsn(ALOAD, Context.serializer);
    mw.visitVarInsn(ALOAD, 0);
    mw.visitLdcInsn(context.getFieldOrinal(fieldInfo.name));
    mw.visitMethodInsn(INVOKEVIRTUAL, JavaBeanSerializer, "getBeanContext", "(I)" + desc(BeanContext.class));
    mw.visitVarInsn(ALOAD, Context.obj);
    mw.visitVarInsn(ALOAD, Context.fieldName);
    String valueDesc = "Ljava/lang/Object;";
    if (fieldClass == byte.class) {
        mw.visitVarInsn(ILOAD, context.var("byte"));
        mw.visitMethodInsn(INVOKESTATIC, "java/lang/Byte", "valueOf", "(B)Ljava/lang/Byte;");
        mw.visitInsn(DUP);
        mw.visitVarInsn(ASTORE, Context.original);
    } else if (fieldClass == short.class) {
        mw.visitVarInsn(ILOAD, context.var("short"));
        mw.visitMethodInsn(INVOKESTATIC, "java/lang/Short", "valueOf", "(S)Ljava/lang/Short;");
        mw.visitInsn(DUP);
        mw.visitVarInsn(ASTORE, Context.original);
    } else if (fieldClass == int.class) {
        mw.visitVarInsn(ILOAD, context.var("int"));
        mw.visitMethodInsn(INVOKESTATIC, "java/lang/Integer", "valueOf", "(I)Ljava/lang/Integer;");
        mw.visitInsn(DUP);
        mw.visitVarInsn(ASTORE, Context.original);
    } else if (fieldClass == char.class) {
        mw.visitVarInsn(ILOAD, context.var("char"));
        mw.visitMethodInsn(INVOKESTATIC, "java/lang/Character", "valueOf", "(C)Ljava/lang/Character;");
        mw.visitInsn(DUP);
        mw.visitVarInsn(ASTORE, Context.original);
    } else if (fieldClass == long.class) {
        mw.visitVarInsn(LLOAD, context.var("long", 2));
        mw.visitMethodInsn(INVOKESTATIC, "java/lang/Long", "valueOf", "(J)Ljava/lang/Long;");
        mw.visitInsn(DUP);
        mw.visitVarInsn(ASTORE, Context.original);
    } else if (fieldClass == float.class) {
        mw.visitVarInsn(FLOAD, context.var("float"));
        mw.visitMethodInsn(INVOKESTATIC, "java/lang/Float", "valueOf", "(F)Ljava/lang/Float;");
        mw.visitInsn(DUP);
        mw.visitVarInsn(ASTORE, Context.original);
    } else if (fieldClass == double.class) {
        mw.visitVarInsn(DLOAD, context.var("double", 2));
        mw.visitMethodInsn(INVOKESTATIC, "java/lang/Double", "valueOf", "(D)Ljava/lang/Double;");
        mw.visitInsn(DUP);
        mw.visitVarInsn(ASTORE, Context.original);
    } else if (fieldClass == boolean.class) {
        mw.visitVarInsn(ILOAD, context.var("boolean"));
        mw.visitMethodInsn(INVOKESTATIC, "java/lang/Boolean", "valueOf", "(Z)Ljava/lang/Boolean;");
        mw.visitInsn(DUP);
        mw.visitVarInsn(ASTORE, Context.original);
    } else if (fieldClass == BigDecimal.class) {
        mw.visitVarInsn(ALOAD, context.var("decimal"));
        mw.visitVarInsn(ASTORE, Context.original);
        mw.visitVarInsn(ALOAD, Context.original);
    } else if (fieldClass == String.class) {
        mw.visitVarInsn(ALOAD, context.var("string"));
        mw.visitVarInsn(ASTORE, Context.original);
        mw.visitVarInsn(ALOAD, Context.original);
    } else if (fieldClass.isEnum()) {
        mw.visitVarInsn(ALOAD, context.var("enum"));
        mw.visitVarInsn(ASTORE, Context.original);
        mw.visitVarInsn(ALOAD, Context.original);
    } else if (List.class.isAssignableFrom(fieldClass)) {
        mw.visitVarInsn(ALOAD, context.var("list"));
        mw.visitVarInsn(ASTORE, Context.original);
        mw.visitVarInsn(ALOAD, Context.original);
    } else {
        mw.visitVarInsn(ALOAD, context.var("object"));
        mw.visitVarInsn(ASTORE, Context.original);
        mw.visitVarInsn(ALOAD, Context.original);
    }
    mw.visitMethodInsn(INVOKEVIRTUAL, JavaBeanSerializer, "processValue", //
    "(L" + JSONSerializer + ";" + //
    desc(BeanContext.class) + //
    "Ljava/lang/Object;Ljava/lang/String;" + valueDesc + ")Ljava/lang/Object;");
    mw.visitVarInsn(ASTORE, Context.processValue);
    mw.visitVarInsn(ALOAD, Context.original);
    mw.visitVarInsn(ALOAD, Context.processValue);
    mw.visitJumpInsn(IF_ACMPEQ, processKeyElse_);
    _writeObject(mw, fieldInfo, context, _end);
    mw.visitJumpInsn(GOTO, _end);
    mw.visitLabel(processKeyElse_);
}
Also used : Label(com.alibaba.fastjson.asm.Label) List(java.util.List)

Aggregations

Label (com.alibaba.fastjson.asm.Label)30 FieldInfo (com.alibaba.fastjson.util.FieldInfo)6 ParseContext (com.alibaba.fastjson.parser.ParseContext)4 JSONType (com.alibaba.fastjson.annotation.JSONType)3 MethodVisitor (com.alibaba.fastjson.asm.MethodVisitor)3 MethodWriter (com.alibaba.fastjson.asm.MethodWriter)3 ParserConfig (com.alibaba.fastjson.parser.ParserConfig)2 ParameterizedType (java.lang.reflect.ParameterizedType)2 Type (java.lang.reflect.Type)2 List (java.util.List)2 JSONException (com.alibaba.fastjson.JSONException)1 JSONField (com.alibaba.fastjson.annotation.JSONField)1 ClassWriter (com.alibaba.fastjson.asm.ClassWriter)1 FieldWriter (com.alibaba.fastjson.asm.FieldWriter)1 ResolveTask (com.alibaba.fastjson.parser.DefaultJSONParser.ResolveTask)1 SymbolTable (com.alibaba.fastjson.parser.SymbolTable)1 ASMUtils (com.alibaba.fastjson.util.ASMUtils)1 JavaBeanInfo (com.alibaba.fastjson.util.JavaBeanInfo)1 TypeUtils (com.alibaba.fastjson.util.TypeUtils)1 Serializable (java.io.Serializable)1