Beispiel #1
0
        public bool FreeContent(IILGen ilGenerator, Action <IILGen> pushReaderOrCtx)
        {
            var localCount       = ilGenerator.DeclareLocal(typeof(uint));
            var finish           = ilGenerator.DefineLabel();
            var next             = ilGenerator.DefineLabel();
            var needsFreeContent = false;

            ilGenerator
            .Do(pushReaderOrCtx)
            .Callvirt(() => default(IReaderCtx).SkipObject())
            .Brfalse(finish)
            .Do(Extensions.PushReaderFromCtx(pushReaderOrCtx))
            .Callvirt(() => default(AbstractBufferedReader).ReadVUInt32())
            .Stloc(localCount)
            .Mark(next)
            .Ldloc(localCount)
            .Brfalse(finish)
            .Ldloc(localCount)
            .LdcI4(1)
            .Sub()
            .ConvU4()
            .Stloc(localCount)
            .GenerateFreeContent(_itemsHandler, pushReaderOrCtx, ref needsFreeContent)
            .Br(next)
            .Mark(finish);
            return(needsFreeContent);
        }
Beispiel #2
0
        public void Skip(IILGen ilGenerator, Action <IILGen> pushReaderOrCtx)
        {
            var localCount = ilGenerator.DeclareLocal(typeof(uint));
            var finish     = ilGenerator.DefineLabel();
            var next       = ilGenerator.DefineLabel();

            ilGenerator
            .Do(pushReaderOrCtx)
            .Callvirt(() => ((IReaderCtx)null).SkipObject())
            .Brfalse(finish)
            .Do(Extensions.PushReaderFromCtx(pushReaderOrCtx))
            .Callvirt(() => ((AbstractBufferedReader)null).ReadVUInt32())
            .Stloc(localCount)
            .Mark(next)
            .Ldloc(localCount)
            .Brfalse(finish)
            .Ldloc(localCount)
            .LdcI4(1)
            .Sub()
            .ConvU4()
            .Stloc(localCount)
            .GenerateSkip(_keysHandler, pushReaderOrCtx)
            .GenerateSkip(_valuesHandler, pushReaderOrCtx)
            .Br(next)
            .Mark(finish);
        }
Beispiel #3
0
        public void Load(IILGen ilGenerator, Action <IILGen> pushReaderOrCtx)
        {
            var    localCount          = ilGenerator.DeclareLocal(typeof(uint));
            var    localResultOfObject = ilGenerator.DeclareLocal(typeof(object));
            var    localResult         = ilGenerator.DeclareLocal(HandledType());
            var    loadSkipped         = ilGenerator.DefineLabel();
            var    finish           = ilGenerator.DefineLabel();
            var    readFinish       = ilGenerator.DefineLabel();
            var    next             = ilGenerator.DefineLabel();
            var    genericArguments = _type !.GetGenericArguments();
            object fake;

            ilGenerator
            .Do(pushReaderOrCtx)
            .Ldloca(localResultOfObject)
            .Callvirt(() => default(IReaderCtx).ReadObject(out fake))
            .Brfalse(loadSkipped)
            .Do(Extensions.PushReaderFromCtx(pushReaderOrCtx))
            .Callvirt(() => default(AbstractBufferedReader).ReadVUInt32())
            .Stloc(localCount)
            .Ldloc(localCount)
            .Newobj(typeof(Dictionary <,>).MakeGenericType(genericArguments).GetConstructor(new[] { typeof(int) }) !)
            .Stloc(localResult)
            .Do(pushReaderOrCtx)
            .Ldloc(localResult)
            .Castclass(typeof(object))
            .Callvirt(() => default(IReaderCtx).RegisterObject(null))
            .Mark(next)
            .Ldloc(localCount)
            .Brfalse(readFinish)
            .Ldloc(localCount)
            .LdcI4(1)
            .Sub()
            .ConvU4()
            .Stloc(localCount)
            .Ldloc(localResult)
            .GenerateLoad(_keysHandler, genericArguments[0], pushReaderOrCtx, _typeConvertGenerator)
            .GenerateLoad(_valuesHandler, genericArguments[1], pushReaderOrCtx, _typeConvertGenerator)
            .Callvirt(_type.GetMethod("Add") !)
            .Br(next)
            .Mark(readFinish)
            .Do(pushReaderOrCtx)
            .Callvirt(() => default(IReaderCtx).ReadObjectDone())
            .Br(finish)
            .Mark(loadSkipped)
            .Ldloc(localResultOfObject)
            .Isinst(_type)
            .Stloc(localResult)
            .Mark(finish)
            .Ldloc(localResult);
        }
Beispiel #4
0
        public void Load(IILGen ilGenerator, Action <IILGen> pushReaderOrCtx)
        {
            var    localCount          = ilGenerator.DeclareLocal(typeof(uint));
            var    localResultOfObject = ilGenerator.DeclareLocal(typeof(object));
            var    localResult         = ilGenerator.DeclareLocal(HandledType());
            var    loadSkipped         = ilGenerator.DefineLabel();
            var    loadFinished        = ilGenerator.DefineLabel();
            var    finish = ilGenerator.DefineLabel();
            var    next   = ilGenerator.DefineLabel();
            var    collectionInterface = _type !.SpecializationOf(typeof(ICollection <>));
            var    itemType            = collectionInterface !.GetGenericArguments()[0];
            object fake;

            ilGenerator
            .Do(pushReaderOrCtx)
            .Ldloca(localResultOfObject)
            .Callvirt(() => default(IReaderCtx).ReadObject(out fake))
            .Brfalse(loadSkipped)
            .Do(Extensions.PushReaderFromCtx(pushReaderOrCtx))
            .Callvirt(() => default(AbstractBufferedReader).ReadVUInt32())
            .Stloc(localCount)
            .Ldloc(localCount)
            .Newobj((_isSet?typeof(HashSet <>):typeof(List <>)).MakeGenericType(itemType).GetConstructor(new[] { typeof(int) }) !)
            .Stloc(localResult)
            .Do(pushReaderOrCtx)
            .Ldloc(localResult)
            .Castclass(typeof(object))
            .Callvirt(() => default(IReaderCtx).RegisterObject(null))
            .Mark(next)
            .Ldloc(localCount)
            .Brfalse(loadFinished)
            .Ldloc(localCount)
            .LdcI4(1)
            .Sub()
            .ConvU4()
            .Stloc(localCount)
            .Ldloc(localResult)
            .GenerateLoad(_itemsHandler, itemType, pushReaderOrCtx, _typeConvertGenerator)
            .Callvirt(collectionInterface !.GetMethod("Add") !)
            .Br(next)
            .Mark(loadFinished)
            .Do(pushReaderOrCtx)
            .Callvirt(() => default(IReaderCtx).ReadObjectDone())
            .Br(finish)
            .Mark(loadSkipped)
            .Ldloc(localResultOfObject)
            .Isinst(_type)
            .Stloc(localResult)
            .Mark(finish)
            .Ldloc(localResult);
        }