public void GetWriteILCode(PropertyData prop, BinaryStruct currentStruct, GroboIL il, GroboIL.Local binaryStruct, GroboIL.Local value, GroboIL.Local typeSize, GroboIL.Local buffer, GroboIL.Local offset, bool listValue) { var arr = il.DeclareLocal(prop.PropertyInfo.PropertyType); var len = il.DeclareLocal(typeof(int)); if (prop.PropertyInfo != null) { il.Ldloc(value); il.Call(prop.ArraySizeProperty.Getter); il.Stloc(len); } else { il.Ldc_I4(prop.ArraySize); il.Stloc(len); } il.Ldloc(value); il.Call(prop.Getter); il.Stloc(arr); var typeKey = prop.PropertyInfo.PropertyType.GetGenericArguments()[0]; var typeValue = prop.PropertyInfo.PropertyType.GetGenericArguments()[1]; var ivar = il.DeclareLocal(typeof(int)); var currentItemKey = il.DeclareLocal(typeKey); var currentItemValue = il.DeclareLocal(typeValue); var point = il.DefineLabel("for_label"); il.Ldc_I4(0); il.Stloc(ivar); var enumeratorMethod = prop.PropertyInfo.PropertyType.GetMethod("GetEnumerator"); var enumerator = il.DeclareLocal(enumeratorMethod.ReturnType); var moveNext = enumerator.Type.GetMethod("MoveNext"); var getCurrent = enumerator.Type.GetMethod("get_Current"); var temp = il.DeclareLocal(getCurrent.ReturnType); var exist = il.DeclareLocal(typeof(bool)); il.Ldloc(arr); il.Call(enumeratorMethod, isVirtual: true); il.Stloc(enumerator); var keyGetter = getCurrent.ReturnType.GetMethod("get_Key"); var valueGetter = getCurrent.ReturnType.GetMethod("get_Value"); il.MarkLabel(point); //body il.Ldloca(enumerator); il.Call(moveNext, enumerator.Type); il.Stloc(exist); il.Ldloca(enumerator); //il.Calli(CallingConventions.Any, typeof(KeyValuePair<int, int>),new Type[] { typeof(int),typeof(int) }); il.Call(getCurrent, enumerator.Type); il.Stloc(temp); il.Ldloca(temp); il.Call(keyGetter, typeof(int)); il.Stloc(currentItemKey); if (typeof(IBasicType).IsAssignableFrom(prop.BinaryAttr.Type.GetGenericArguments()[0])) { IBasicType t = (IBasicType)Activator.CreateInstance(prop.BinaryAttr.Type.GetGenericArguments()[0]); t.GetWriteILCode(prop, currentStruct, il, binaryStruct, currentItemKey, typeSize, buffer, offset, true); } else { BinaryStruct.CompileWriter(currentStruct.CurrentStorage.GetTypeInfo(typeKey, currentStruct.Scheme), il, binaryStruct, currentItemKey, buffer, offset, typeSize); } il.Ldloca(temp); il.Call(valueGetter); il.Stloc(currentItemValue); if (typeof(IBasicType).IsAssignableFrom(prop.BinaryAttr.Type.GetGenericArguments()[1])) { IBasicType t = (IBasicType)Activator.CreateInstance(prop.BinaryAttr.Type.GetGenericArguments()[1]); t.GetWriteILCode(prop, currentStruct, il, binaryStruct, currentItemValue, typeSize, buffer, offset, true); } else { BinaryStruct.CompileWriter(currentStruct.CurrentStorage.GetTypeInfo(typeValue, currentStruct.Scheme), il, binaryStruct, currentItemValue, buffer, offset, typeSize); } //end body il.Ldc_I4(1); il.Ldloc(ivar); il.Add(); il.Stloc(ivar); il.Ldloc(ivar); il.Ldloc(len); il.Clt(false); il.Brtrue(point); }
public void GetReadILCode(PropertyData prop, BinaryStruct currentStruct, GroboIL il, GroboIL.Local binaryStruct, GroboIL.Local buffer, GroboIL.Local result, GroboIL.Local typeSize, GroboIL.Local offset, bool listValue) { var exitLabel = il.DefineLabel("exit"); BinaryStruct.ReadObjectNull(il, exitLabel, buffer, offset, typeSize); var len = il.DeclareLocal(typeof(int)); var list = il.DeclareLocal(prop.PropertyInfo.PropertyType); il.Ldloc(buffer); il.Ldloc(offset); il.Call(readBitConverterMethodInfo); il.Stloc(len); BinaryStruct.WriteOffsetAppend(il, offset, 4); il.Newobj(BinaryStruct.GetConstructor(prop.PropertyInfo.PropertyType, null)); il.Stloc(list); il.Ldloc(result); il.Ldloc(list); il.Call(prop.Setter, isVirtual: true); il.Ldloc(len); il.Ldc_I4(0); il.Ceq(); il.Brtrue(exitLabel); var typeKey = prop.PropertyInfo.PropertyType.GetGenericArguments()[0]; var typeValue = prop.PropertyInfo.PropertyType.GetGenericArguments()[1]; var ivar = il.DeclareLocal(typeof(int)); var currentItemKey = il.DeclareLocal(typeKey); var currentItemValue = il.DeclareLocal(typeValue); var point = il.DefineLabel("for_label"); il.Ldc_I4(0); il.Stloc(ivar); il.MarkLabel(point); //body //key if (typeof(IBasicType).IsAssignableFrom(prop.BinaryAttr.Type.GetGenericArguments()[0])) { IBasicType t = (IBasicType)Activator.CreateInstance(prop.BinaryAttr.Type.GetGenericArguments()[0]); t.GetReadILCode(prop, currentStruct, il, binaryStruct, buffer, currentItemKey, typeSize, offset, true); } else { var constr = BinaryStruct.GetConstructor(typeKey, null); if (constr == null) { throw new Exception($"Type {typeKey} not have constructor with not parameters"); } il.Newobj(constr); il.Stloc(currentItemKey); BinaryStruct.CompileReader(currentStruct.CurrentStorage.GetTypeInfo(typeKey, currentStruct.Scheme), il, binaryStruct, buffer, offset, currentItemKey, typeSize); } //value if (typeof(IBasicType).IsAssignableFrom(prop.BinaryAttr.Type.GetGenericArguments()[1])) { IBasicType t = (IBasicType)Activator.CreateInstance(prop.BinaryAttr.Type.GetGenericArguments()[1]); t.GetReadILCode(prop, currentStruct, il, binaryStruct, buffer, currentItemValue, typeSize, offset, true); } else { var constr = BinaryStruct.GetConstructor(typeValue, null); if (constr == null) { throw new Exception($"Type {typeValue} not have constructor with not parameters"); } il.Newobj(constr); il.Stloc(currentItemValue); BinaryStruct.CompileReader(currentStruct.CurrentStorage.GetTypeInfo(typeValue, currentStruct.Scheme), il, binaryStruct, buffer, offset, currentItemValue, typeSize); } il.Ldloc(list); il.Ldloc(currentItemKey); il.Ldloc(currentItemValue); il.Call(prop.PropertyInfo.PropertyType.GetMethod("Add"), isVirtual: true); //end body il.Ldc_I4(1); il.Ldloc(ivar); il.Add(); il.Stloc(ivar); il.Ldloc(ivar); il.Ldloc(len); il.Clt(false); il.Brtrue(point); il.MarkLabel(exitLabel); }
public void GetWriteILCode(PropertyData prop, BinaryStruct currentStruct, GroboIL il, GroboIL.Local binaryStruct, GroboIL.Local value, GroboIL.Local typeSize, GroboIL.Local buffer, GroboIL.Local offset, bool listValue) { var arr = il.DeclareLocal(prop.PropertyInfo.PropertyType); var len = il.DeclareLocal(typeof(int)); if (prop.PropertyInfo != null) { il.Ldloc(value); il.Call(prop.ArraySizeProperty.Getter); il.Stloc(len); } else { il.Ldc_I4(prop.ArraySize); il.Stloc(len); } il.Ldloc(value); il.Call(prop.Getter); il.Stloc(arr); var type = prop.PropertyInfo.PropertyType.GetGenericArguments()[0]; var ivar = il.DeclareLocal(typeof(int)); var currentValue = il.DeclareLocal(type); var point = il.DefineLabel("for_label"); il.Ldc_I4(0); il.Stloc(ivar); il.MarkLabel(point); //body il.Ldloc(arr); il.Ldloc(ivar); il.Call(prop.PropertyInfo.PropertyType.GetMethod("get_Item"), isVirtual: true); il.Stloc(currentValue); if (typeof(IBasicType).IsAssignableFrom(prop.BinaryAttr.Type.GetGenericArguments()[0])) { IBasicType t = (IBasicType)Activator.CreateInstance(prop.BinaryAttr.Type.GetGenericArguments()[0]); t.GetWriteILCode(prop, currentStruct, il, binaryStruct, currentValue, typeSize, buffer, offset, true); } else { BinaryStruct.CompileWriter(currentStruct.CurrentStorage.GetTypeInfo(type, currentStruct.Scheme), il, binaryStruct, currentValue, buffer, offset, typeSize); } //end body il.Ldc_I4(1); il.Ldloc(ivar); il.Add(); il.Stloc(ivar); il.Ldloc(ivar); il.Ldloc(len); il.Clt(false); il.Brtrue(point); }
public void GetWriteILCode(PropertyData prop, BinaryStruct currentStruct, GroboIL il, GroboIL.Local binaryStruct, GroboIL.Local value, GroboIL.Local typeSize, GroboIL.Local buffer, GroboIL.Local offset, bool listValue) { var arr = il.DeclareLocal(prop.PropertyInfo.PropertyType); il.Ldloc(value); il.Call(prop.Getter); il.Stloc(arr); var exitLabel = il.DefineLabel("exit"); BinaryStruct.WriteSizeChecker(il, buffer, offset, 5); BinaryStruct.WriteObjectNull(il, exitLabel, arr, buffer, offset, typeSize); var arrSize = il.DeclareLocal(typeof(byte[])); var len = il.DeclareLocal(typeof(int)); il.Ldloc(value); il.Call(prop.Getter); il.Call(typeof(ICollection).GetProperty("Count").GetMethod); il.Stloc(len); il.Ldloc(len); il.Call(writeBitConverterMethodInfo); il.Stloc(arrSize); il.Ldloc(buffer); il.Ldloc(offset); il.Ldloc(arrSize); il.Ldc_I4(0); il.Ldelem(typeof(byte)); il.Stelem(typeof(byte)); for (int i = 1; i < 4; i++) { il.Ldloc(buffer); il.Ldloc(offset); il.Ldc_I4(i); il.Add(); il.Ldloc(arrSize); il.Ldc_I4(i); il.Ldelem(typeof(byte)); il.Stelem(typeof(byte)); } BinaryStruct.WriteOffsetAppend(il, offset, 4); il.Ldloc(len); il.Ldc_I4(0); il.Ceq(); il.Brtrue(exitLabel); var type = prop.PropertyInfo.PropertyType.GetElementType(); var ivar = il.DeclareLocal(typeof(int)); var currentValue = il.DeclareLocal(type); var point = il.DefineLabel("for_label"); il.Ldc_I4(0); il.Stloc(ivar); il.MarkLabel(point); //body il.Ldloc(arr); il.Ldloc(ivar); il.Ldelem(type); //il.Call(prop.PropertyInfo.PropertyType.GetMethod("Get"), isVirtual: true); il.Stloc(currentValue); if (typeof(IBasicType).IsAssignableFrom(prop.BinaryAttr.Type.GetGenericArguments()[0])) { IBasicType t = (IBasicType)Activator.CreateInstance(prop.BinaryAttr.Type.GetGenericArguments()[0]); t.GetWriteILCode(prop, currentStruct, il, binaryStruct, currentValue, typeSize, buffer, offset, true); } else { BinaryStruct.CompileWriter(currentStruct.CurrentStorage.GetTypeInfo(type, currentStruct.Scheme), il, binaryStruct, currentValue, buffer, offset, typeSize); } //end body il.Ldc_I4(1); il.Ldloc(ivar); il.Add(); il.Stloc(ivar); il.Ldloc(ivar); il.Ldloc(len); il.Clt(false); il.Brtrue(point); il.MarkLabel(exitLabel); }
public void GetWriteILCode(PropertyData prop, BinaryStruct currentStruct, GroboIL il, GroboIL.Local binaryStruct, GroboIL.Local value, GroboIL.Local typeSize, GroboIL.Local buffer, GroboIL.Local offset, bool listValue) { BinaryStruct.WriteSizeChecker(il, buffer, offset, 5); var arr = il.DeclareLocal(typeof(byte[])); var arrSize = il.DeclareLocal(typeof(byte[])); var temp = il.DeclareLocal(typeof(string)); var exitLabel = il.DefineLabel("exit"); il.Ldloc(value); if (!listValue) { il.Call(prop.Getter); } il.Stloc(temp); il.Ldloc(temp); BinaryStruct.WriteObjectNull(il, exitLabel, buffer, offset, typeSize); il.Ldloc(temp); il.Call(typeof(string).GetProperty("Length").GetMethod); il.Stloc(typeSize); il.Ldarg(1); il.Call(codingMethodInfo); il.Ldloc(temp); il.Call(currentStruct.Coding.GetType().GetMethod("GetBytes", new Type[] { typeof(string) })); il.Stloc(arr); il.Ldloc(arr); il.Call(typeof(byte[]).GetProperty("Length").GetMethod); il.Stloc(typeSize); il.Ldloc(typeSize); il.Call(writeBitConverterMethodInfo); il.Stloc(arrSize); il.Ldloc(buffer); il.Ldloc(offset); il.Ldloc(arrSize); il.Ldc_I4(0); il.Ldelem(typeof(byte)); il.Stelem(typeof(byte)); for (int i = 1; i < 4; i++) { il.Ldloc(buffer); il.Ldloc(offset); il.Ldc_I4(i); il.Add(); il.Ldloc(arrSize); il.Ldc_I4(i); il.Ldelem(typeof(byte)); il.Stelem(typeof(byte)); } BinaryStruct.WriteOffsetAppend(il, offset, 4); il.Ldloc(typeSize); il.Ldc_I4(0); il.Ceq(); il.Brtrue(exitLabel); BinaryStruct.WriteSizeChecker(il, buffer, offset, typeSize); var ivar = il.DeclareLocal(typeof(int)); var point = il.DefineLabel("for_label"); il.Ldc_I4(0); il.Stloc(ivar); il.MarkLabel(point); //body il.Ldloc(buffer); il.Ldloc(ivar); il.Ldloc(offset); il.Add(); il.Ldloc(arr); il.Ldloc(ivar); il.Ldelem(typeof(byte)); il.Stelem(typeof(byte)); //end body il.Ldc_I4(1); il.Ldloc(ivar); il.Add(); il.Stloc(ivar); il.Ldloc(ivar); il.Ldloc(typeSize); il.Clt(false); il.Brtrue(point); BinaryStruct.WriteOffsetAppend(il, offset, typeSize); il.MarkLabel(exitLabel); }
public void GetWriteILCode(PropertyData prop, BinaryStruct currentStruct, GroboIL il, GroboIL.Local binaryStruct, GroboIL.Local value, GroboIL.Local typeSize, GroboIL.Local buffer, GroboIL.Local offset, bool listValue) { var arr = il.DeclareLocal(prop.PropertyInfo.PropertyType); il.Ldloc(value); il.Call(prop.Getter); il.Stloc(arr); var exitLabel = il.DefineLabel("exit"); BinaryStruct.WriteSizeChecker(il, buffer, offset, 3); BinaryStruct.WriteObjectNull(il, exitLabel, arr, buffer, offset, typeSize); var arrSize = il.DeclareLocal(typeof(byte[])); var len = il.DeclareLocal(typeof(short)); il.Ldloc(value); il.Call(prop.Getter); il.Call(typeof(ICollection).GetProperty("Count").GetMethod); il.Stloc(len); il.Ldloc(len); il.Call(writeBitConverterMethodInfo); il.Stloc(arrSize); il.Ldloc(buffer); il.Ldloc(offset); il.Ldloc(arrSize); il.Ldc_I4(0); il.Ldelem(typeof(byte)); il.Stelem(typeof(byte)); for (int i = 1; i < 2; i++) { il.Ldloc(buffer); il.Ldloc(offset); il.Ldc_I4(i); il.Add(); il.Ldloc(arrSize); il.Ldc_I4(i); il.Ldelem(typeof(byte)); il.Stelem(typeof(byte)); } BinaryStruct.WriteOffsetAppend(il, offset, 2); il.Ldloc(len); il.Ldc_I4(0); il.Ceq(); il.Brtrue(exitLabel); var typeKey = prop.PropertyInfo.PropertyType.GetGenericArguments()[0]; var typeValue = prop.PropertyInfo.PropertyType.GetGenericArguments()[1]; var ivar = il.DeclareLocal(typeof(int)); var currentItemKey = il.DeclareLocal(typeKey); var currentItemValue = il.DeclareLocal(typeValue); var point = il.DefineLabel("for_label"); il.Ldc_I4(0); il.Stloc(ivar); var enumeratorMethod = prop.PropertyInfo.PropertyType.GetMethod("GetEnumerator"); var enumerator = il.DeclareLocal(enumeratorMethod.ReturnType); var moveNext = enumerator.Type.GetMethod("MoveNext"); var getCurrent = enumerator.Type.GetMethod("get_Current"); var temp = il.DeclareLocal(getCurrent.ReturnType); var exist = il.DeclareLocal(typeof(bool)); il.Ldloc(arr); il.Call(enumeratorMethod, isVirtual: true); il.Stloc(enumerator); var keyGetter = getCurrent.ReturnType.GetMethod("get_Key"); var valueGetter = getCurrent.ReturnType.GetMethod("get_Value"); il.MarkLabel(point); //body il.Ldloca(enumerator); il.Call(moveNext, enumerator.Type); il.Stloc(exist); il.Ldloca(enumerator); il.Call(getCurrent, enumerator.Type); il.Stloc(temp); il.Ldloca(temp); il.Call(keyGetter, typeof(int)); il.Stloc(currentItemKey); if (typeof(IBasicType).IsAssignableFrom(prop.BinaryAttr.Type.GetGenericArguments()[0])) { IBasicType t = (IBasicType)Activator.CreateInstance(prop.BinaryAttr.Type.GetGenericArguments()[0]); t.GetWriteILCode(prop, currentStruct, il, binaryStruct, currentItemKey, typeSize, buffer, offset, true); } else { BinaryStruct.CompileWriter(currentStruct.CurrentStorage.GetTypeInfo(typeKey, currentStruct.Scheme), il, binaryStruct, currentItemKey, buffer, offset, typeSize); } il.Ldloca(temp); il.Call(valueGetter); il.Stloc(currentItemValue); if (typeof(IBasicType).IsAssignableFrom(prop.BinaryAttr.Type.GetGenericArguments()[1])) { IBasicType t = (IBasicType)Activator.CreateInstance(prop.BinaryAttr.Type.GetGenericArguments()[1]); t.GetWriteILCode(prop, currentStruct, il, binaryStruct, currentItemValue, typeSize, buffer, offset, true); } else { BinaryStruct.CompileWriter(currentStruct.CurrentStorage.GetTypeInfo(typeValue, currentStruct.Scheme), il, binaryStruct, currentItemValue, buffer, offset, typeSize); } //end body il.Ldc_I4(1); il.Ldloc(ivar); il.Add(); il.Stloc(ivar); il.Ldloc(ivar); il.Ldloc(len); il.Clt(false); il.Brtrue(point); il.MarkLabel(exitLabel); }
internal static void Resize(GroboIL il, GroboIL.Local buffer, GroboIL.Local offset /*, GroboIL.Local len*/) { var totalLen = il.DeclareLocal(typeof(int)); //offset add typesize = minSize il.Ldloc(offset); il.Add(); il.Stloc(totalLen); var exit = il.DefineLabel("exit"); //Compare if minSize < buffer.len il.Ldloc(totalLen); il.Ldloc(buffer); il.Ldlen(); il.Clt(false); il.Brtrue(exit); var avar = il.DeclareLocal(typeof(byte)); il.Ldc_I4(2); il.Stloc(avar); var point = il.DefineLabel("for_label"); il.MarkLabel(point); //body il.Ldloc(avar); il.Ldc_I4(2); il.Mul(); il.Stloc(avar); //end body il.Ldloc(buffer); il.Ldlen(); il.Ldloc(avar); il.Mul(); //OutputValue(il,typeof(int)); il.Ldloc(totalLen); //OutputValue(il, typeof(int)); il.Clt(false); //OutputValue(il, typeof(bool)); il.Brtrue(point); il.Ldloca(buffer); il.Ldloc(avar); il.Ldloc(buffer); il.Ldlen(); il.Mul(); //OutputValue(il, typeof(int)); il.Call(typeof(Array).GetMethod("Resize", BindingFlags.Public | BindingFlags.Static).MakeGenericMethod(typeof(byte))); il.MarkLabel(exit); }