本文整理汇总了C#中Compiler.EmitBasicRead方法的典型用法代码示例。如果您正苦于以下问题:C# Compiler.EmitBasicRead方法的具体用法?C# Compiler.EmitBasicRead怎么用?C# Compiler.EmitBasicRead使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Compiler
的用法示例。
在下文中一共展示了Compiler.EmitBasicRead方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EmitRead
protected override void EmitRead(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
{
using (Compiler.Local oldValue = ctx.GetLocalWithValue(expectedType, valueFrom))
using (Compiler.Local token = new Compiler.Local(ctx, ctx.MapType(typeof(SubItemToken))))
using (Compiler.Local field = new Compiler.Local(ctx, ctx.MapType(typeof(int))))
{
ctx.LoadReaderWriter();
ctx.EmitCall(ctx.MapType(typeof(ProtoReader)).GetMethod("StartSubItem"));
ctx.StoreValue(token);
Compiler.CodeLabel next = ctx.DefineLabel(), processField = ctx.DefineLabel(), end = ctx.DefineLabel();
ctx.MarkLabel(next);
ctx.EmitBasicRead("ReadFieldHeader", ctx.MapType(typeof(int)));
ctx.CopyValue();
ctx.StoreValue(field);
ctx.LoadValue(Tag); // = 1 - process
ctx.BranchIfEqual(processField, true);
ctx.LoadValue(field);
ctx.LoadValue(1); // < 1 - exit
ctx.BranchIfLess(end, false);
// default: skip
ctx.LoadReaderWriter();
ctx.EmitCall(ctx.MapType(typeof(ProtoReader)).GetMethod("SkipField"));
ctx.Branch(next, true);
// process
ctx.MarkLabel(processField);
if (Tail.RequiresOldValue)
{
if (Helpers.IsValueType(expectedType))
{
ctx.LoadAddress(oldValue, expectedType);
ctx.EmitCall(expectedType.GetMethod("GetValueOrDefault", Helpers.EmptyTypes));
}
else
{
ctx.LoadValue(oldValue);
}
}
Tail.EmitRead(ctx, null);
// note we demanded always returns a value
if (Helpers.IsValueType(expectedType))
{
ctx.EmitCtor(expectedType, Tail.ExpectedType); // re-nullable<T> it
}
ctx.StoreValue(oldValue);
ctx.Branch(next, false);
// outro
ctx.MarkLabel(end);
ctx.LoadValue(token);
ctx.LoadReaderWriter();
ctx.EmitCall(ctx.MapType(typeof(ProtoReader)).GetMethod("EndSubItem"));
ctx.LoadValue(oldValue); // load the old value
}
}
示例2:
void IProtoSerializer.EmitRead(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
{
ctx.EmitBasicRead(typeof(BclHelpers), "ReadDecimal", ExpectedType);
}
示例3: GetTypeCode
void IProtoSerializer.EmitRead(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
{
TypeCode typeCode = GetTypeCode();
if (map == null)
{
ctx.EmitBasicRead("ReadInt32", typeof(int));
ctx.ConvertFromInt32(typeCode);
}
else
{
int[] wireValues = new int[map.Length];
object[] values = new object[map.Length];
for (int i = 0; i < map.Length; i++)
{
wireValues[i] = map[i].WireValue;
values[i] = map[i].Value;
}
using (Compiler.Local result = new Compiler.Local(ctx, ExpectedType))
using (Compiler.Local wireValue = new Compiler.Local(ctx, typeof(int)))
{
ctx.EmitBasicRead("ReadInt32", typeof(int));
ctx.StoreValue(wireValue);
Compiler.CodeLabel @continue = ctx.DefineLabel();
foreach (BasicList.Group group in BasicList.GetContiguousGroups(wireValues, values))
{
Compiler.CodeLabel tryNextGroup = ctx.DefineLabel();
int groupItemCount = group.Items.Count;
if (groupItemCount == 1)
{
// discreet group; use an equality test
ctx.LoadValue(wireValue);
ctx.LoadValue(group.First);
Compiler.CodeLabel processThisValue = ctx.DefineLabel();
ctx.BranchIfEqual(processThisValue, true);
ctx.Branch(tryNextGroup, false);
WriteEnumValue(ctx, typeCode, processThisValue, @continue, group.Items[0], @result);
}
else
{
// implement as a jump-table-based switch
ctx.LoadValue(wireValue);
ctx.LoadValue(group.First);
ctx.Subtract(); // jump-tables are zero-based
Compiler.CodeLabel[] jmp = new Compiler.CodeLabel[groupItemCount];
for (int i = 0; i < groupItemCount; i++) {
jmp[i] = ctx.DefineLabel();
}
ctx.Switch(jmp);
// write the default...
ctx.Branch(tryNextGroup, false);
for (int i = 0; i < groupItemCount; i++)
{
WriteEnumValue(ctx, typeCode, jmp[i], @continue, group.Items[i], @result);
}
}
ctx.MarkLabel(tryNextGroup);
}
// throw source.CreateEnumException(ExpectedType, wireValue);
ctx.LoadReaderWriter();
ctx.LoadValue(ExpectedType);
ctx.LoadValue(wireValue);
ctx.EmitCall(typeof(ProtoReader).GetMethod("ThrowEnumException"));
ctx.MarkLabel(@continue);
ctx.LoadValue(result);
}
}
}
示例4: EmitRead
//.........这里部分代码省略.........
{
ctx.LoadAddress(objValue, ExpectedType);
ctx.BranchIfFalse(skipOld, false);
}
for (int i = 0; i < members.Length; i++)
{
ctx.LoadAddress(objValue, ExpectedType);
if (members[i] is FieldInfo)
{
ctx.LoadValue((FieldInfo)members[i]);
}
else if (members[i] is PropertyInfo)
{
ctx.LoadValue((PropertyInfo)members[i]);
}
ctx.StoreValue(locals[i]);
}
if (!Helpers.IsValueType(ExpectedType)) ctx.MarkLabel(skipOld);
using (Compiler.Local fieldNumber = new Compiler.Local(ctx, ctx.MapType(typeof(int))))
{
Compiler.CodeLabel @continue = ctx.DefineLabel(),
processField = ctx.DefineLabel(),
notRecognised = ctx.DefineLabel();
ctx.Branch(@continue, false);
Compiler.CodeLabel[] handlers = new Compiler.CodeLabel[members.Length];
for (int i = 0; i < members.Length; i++)
{
handlers[i] = ctx.DefineLabel();
}
ctx.MarkLabel(processField);
ctx.LoadValue(fieldNumber);
ctx.LoadValue(1);
ctx.Subtract(); // jump-table is zero-based
ctx.Switch(handlers);
// and the default:
ctx.Branch(notRecognised, false);
for (int i = 0; i < handlers.Length; i++)
{
ctx.MarkLabel(handlers[i]);
IProtoSerializer tail = tails[i];
Compiler.Local oldValIfNeeded = tail.RequiresOldValue ? locals[i] : null;
ctx.ReadNullCheckedTail(locals[i].Type, tail, oldValIfNeeded);
if (tail.ReturnsValue)
{
if (Helpers.IsValueType(locals[i].Type))
{
ctx.StoreValue(locals[i]);
}
else
{
Compiler.CodeLabel hasValue = ctx.DefineLabel(), allDone = ctx.DefineLabel();
ctx.CopyValue();
ctx.BranchIfTrue(hasValue, true); // interpret null as "don't assign"
ctx.DiscardValue();
ctx.Branch(allDone, true);
ctx.MarkLabel(hasValue);
ctx.StoreValue(locals[i]);
ctx.MarkLabel(allDone);
}
}
ctx.Branch(@continue, false);
}
ctx.MarkLabel(notRecognised);
ctx.LoadReaderWriter();
ctx.EmitCall(ctx.MapType(typeof(ProtoReader)).GetMethod("SkipField"));
ctx.MarkLabel(@continue);
ctx.EmitBasicRead("ReadFieldHeader", ctx.MapType(typeof(int)));
ctx.CopyValue();
ctx.StoreValue(fieldNumber);
ctx.LoadValue(0);
ctx.BranchIfGreater(processField, false);
}
for (int i = 0; i < locals.Length; i++)
{
ctx.LoadValue(locals[i]);
}
ctx.EmitCtor(ctor);
ctx.StoreValue(objValue);
}
finally
{
for (int i = 0; i < locals.Length; i++)
{
if (locals[i] != null)
locals[i].Dispose(); // release for re-use
}
}
}
}
示例5:
void IProtoSerializer.EmitRead(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
{
ctx.EmitBasicRead("ReadBoolean", ExpectedType);
}
示例6: typeof
void IProtoSerializer.EmitRead(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
{
ctx.EmitBasicRead("ReadString", typeof(string));
ctx.EmitCall(parse);
}
示例7: using
void IProtoSerializer.EmitRead(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
{
Type expected = ExpectedType;
Helpers.DebugAssert(valueFrom != null);
using (Compiler.Local loc = ctx.GetLocalWithValue(expected, valueFrom))
using (Compiler.Local fieldNumber = new Compiler.Local(ctx, typeof(int)))
{
// pre-callbacks
if (HasCallbacks(TypeModel.CallbackType.BeforeDeserialize))
{
Compiler.CodeLabel callbacksDone = ctx.DefineLabel();
ctx.LoadValue(loc);
ctx.BranchIfFalse(callbacksDone, false);
EmitCallbackIfNeeded(ctx, loc, TypeModel.CallbackType.BeforeDeserialize);
ctx.MarkLabel(callbacksDone);
}
Compiler.CodeLabel @continue = ctx.DefineLabel(), processField = ctx.DefineLabel();
ctx.Branch(@continue, false);
ctx.MarkLabel(processField);
foreach (BasicList.Group group in BasicList.GetContiguousGroups(fieldNumbers, serializers))
{
Compiler.CodeLabel tryNextField = ctx.DefineLabel();
int groupItemCount = group.Items.Count;
if (groupItemCount == 1)
{
// discreet group; use an equality test
ctx.LoadValue(fieldNumber);
ctx.LoadValue(group.First);
Compiler.CodeLabel processThisField = ctx.DefineLabel();
ctx.BranchIfEqual(processThisField, true);
ctx.Branch(tryNextField, false);
WriteFieldHandler(ctx, expected, loc, processThisField, @continue, (IProtoSerializer)group.Items[0]);
}
else
{ // implement as a jump-table-based switch
ctx.LoadValue(fieldNumber);
ctx.LoadValue(group.First);
ctx.Subtract(); // jump-tables are zero-based
Compiler.CodeLabel[] jmp = new Compiler.CodeLabel[groupItemCount];
for (int i = 0; i < groupItemCount; i++) {
jmp[i] = ctx.DefineLabel();
}
ctx.Switch(jmp);
// write the default...
ctx.Branch(tryNextField, false);
for (int i = 0; i < groupItemCount; i++)
{
WriteFieldHandler(ctx, expected, loc, jmp[i], @continue, (IProtoSerializer)group.Items[i]);
}
}
ctx.MarkLabel(tryNextField);
}
EmitCreateIfNull(ctx, expected, loc);
ctx.LoadReaderWriter();
if (isExtensible)
{
ctx.LoadValue(loc);
ctx.EmitCall(typeof(ProtoReader).GetMethod("AppendExtensionData"));
}
else
{
ctx.EmitCall(typeof(ProtoReader).GetMethod("SkipField"));
}
ctx.MarkLabel(@continue);
ctx.EmitBasicRead("ReadFieldHeader", typeof(int));
ctx.CopyValue();
ctx.StoreValue(fieldNumber);
ctx.LoadValue(0);
ctx.BranchIfGreater(processField, false);
EmitCreateIfNull(ctx, expected, loc);
// post-callbacks
EmitCallbackIfNeeded(ctx, loc, TypeModel.CallbackType.AfterDeserialize);
}
}
示例8: typeof
void IProtoSerializer.EmitRead(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
{
ctx.EmitBasicRead("ReadUInt16", typeof(ushort));
}