本文整理汇总了C#中Compiler.BranchIfFalse方法的典型用法代码示例。如果您正苦于以下问题:C# Compiler.BranchIfFalse方法的具体用法?C# Compiler.BranchIfFalse怎么用?C# Compiler.BranchIfFalse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Compiler
的用法示例。
在下文中一共展示了Compiler.BranchIfFalse方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EmitWrite
protected override void EmitWrite(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
{
if (getSpecified == null)
{
Tail.EmitWrite(ctx, valueFrom);
return;
}
using (Compiler.Local loc = ctx.GetLocalWithValue(ExpectedType, valueFrom))
{
ctx.LoadAddress(loc, ExpectedType);
ctx.EmitCall(getSpecified);
Compiler.CodeLabel done = ctx.DefineLabel();
ctx.BranchIfFalse(done, false);
Tail.EmitWrite(ctx, loc);
ctx.MarkLabel(done);
}
}
示例2: EmitRead
protected override void EmitRead(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
{
using (Compiler.Local loc = ctx.GetLocalWithValue(ExpectedType, valueFrom))
{
if (Tail.RequiresOldValue)
{
ctx.LoadAddress(loc, ExpectedType);
ctx.LoadValue(field);
}
// value is either now on the stack or not needed
ctx.ReadNullCheckedTail(field.FieldType, Tail, null);
if (Tail.ReturnsValue)
{
using (Compiler.Local newVal = new Compiler.Local(ctx, field.FieldType))
{
ctx.StoreValue(newVal);
if (Helpers.IsValueType(field.FieldType))
{
ctx.LoadAddress(loc, ExpectedType);
ctx.LoadValue(newVal);
ctx.StoreValue(field);
}
else
{
Compiler.CodeLabel allDone = ctx.DefineLabel();
ctx.LoadValue(newVal);
ctx.BranchIfFalse(allDone, true); // interpret null as "don't assign"
ctx.LoadAddress(loc, ExpectedType);
ctx.LoadValue(newVal);
ctx.StoreValue(field);
ctx.MarkLabel(allDone);
}
}
}
}
}
示例3: EmitRead
protected override void EmitRead(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
{
using (Compiler.Local oldList = AppendToCollection ? ctx.GetLocalWithValue(ExpectedType, valueFrom) : null)
using(Compiler.Local builder = new Compiler.Local(ctx, builderFactory.ReturnType))
{
ctx.EmitCall(builderFactory);
ctx.StoreValue(builder);
if(AppendToCollection)
{
Compiler.CodeLabel done = ctx.DefineLabel();
if(!ExpectedType.IsValueType)
{
ctx.LoadValue(oldList);
ctx.BranchIfFalse(done, false); // old value null; nothing to add
}
PropertyInfo prop = Helpers.GetProperty(ExpectedType, "Length", false);
if(prop == null) prop = Helpers.GetProperty(ExpectedType, "Count", false);
#if !NO_GENERICS
if (prop == null) prop = Helpers.GetProperty(ResolveIReadOnlyCollection(ExpectedType, Tail.ExpectedType), "Count", false);
#endif
ctx.LoadAddress(oldList, oldList.Type);
ctx.EmitCall(Helpers.GetGetMethod(prop, false, false));
ctx.BranchIfFalse(done, false); // old list is empty; nothing to add
Type voidType = ctx.MapType(typeof(void));
if(addRange != null)
{
ctx.LoadValue(builder);
ctx.LoadValue(oldList);
ctx.EmitCall(addRange);
if (addRange.ReturnType != null && add.ReturnType != voidType) ctx.DiscardValue();
}
else
{
// loop and call Add repeatedly
MethodInfo moveNext, current, getEnumerator = GetEnumeratorInfo(ctx.Model, out moveNext, out current);
Helpers.DebugAssert(moveNext != null);
Helpers.DebugAssert(current != null);
Helpers.DebugAssert(getEnumerator != null);
Type enumeratorType = getEnumerator.ReturnType;
using (Compiler.Local iter = new Compiler.Local(ctx, enumeratorType))
{
ctx.LoadAddress(oldList, ExpectedType);
ctx.EmitCall(getEnumerator);
ctx.StoreValue(iter);
using (ctx.Using(iter))
{
Compiler.CodeLabel body = ctx.DefineLabel(), next = ctx.DefineLabel();
ctx.Branch(next, false);
ctx.MarkLabel(body);
ctx.LoadAddress(builder, builder.Type);
ctx.LoadAddress(iter, enumeratorType);
ctx.EmitCall(current);
ctx.EmitCall(add);
if (add.ReturnType != null && add.ReturnType != voidType) ctx.DiscardValue();
ctx.MarkLabel(@next);
ctx.LoadAddress(iter, enumeratorType);
ctx.EmitCall(moveNext);
ctx.BranchIfTrue(body, false);
}
}
}
ctx.MarkLabel(done);
}
EmitReadList(ctx, builder, Tail, add, packedWireType, false);
ctx.LoadAddress(builder, builder.Type);
ctx.EmitCall(finish);
if(ExpectedType != finish.ReturnType)
{
ctx.Cast(ExpectedType);
}
}
}
示例4: EmitBranchIfDefaultValue
private void EmitBranchIfDefaultValue(Compiler.CompilerContext ctx, Compiler.CodeLabel label)
{
switch (Helpers.GetTypeCode(ExpectedType))
{
case ProtoTypeCode.Boolean:
if ((bool)defaultValue)
{
ctx.BranchIfTrue(label, false);
}
else
{
ctx.BranchIfFalse(label, false);
}
break;
case ProtoTypeCode.Byte:
if ((byte)defaultValue == (byte)0)
{
ctx.BranchIfFalse(label, false);
}
else
{
ctx.LoadValue((int)(byte)defaultValue);
EmitBeq(ctx, label, ExpectedType);
}
break;
case ProtoTypeCode.SByte:
if ((sbyte)defaultValue == (sbyte)0)
{
ctx.BranchIfFalse(label, false);
}
else
{
ctx.LoadValue((int)(sbyte)defaultValue);
EmitBeq(ctx, label, ExpectedType);
}
break;
case ProtoTypeCode.Int16:
if ((short)defaultValue == (short)0)
{
ctx.BranchIfFalse(label, false);
}
else
{
ctx.LoadValue((int)(short)defaultValue);
EmitBeq(ctx, label, ExpectedType);
}
break;
case ProtoTypeCode.UInt16:
if ((ushort)defaultValue == (ushort)0)
{
ctx.BranchIfFalse(label, false);
}
else
{
ctx.LoadValue((int)(ushort)defaultValue);
EmitBeq(ctx, label, ExpectedType);
}
break;
case ProtoTypeCode.Int32:
if ((int)defaultValue == (int)0)
{
ctx.BranchIfFalse(label, false);
}
else
{
ctx.LoadValue((int)defaultValue);
EmitBeq(ctx, label, ExpectedType);
}
break;
case ProtoTypeCode.UInt32:
if ((uint)defaultValue == (uint)0)
{
ctx.BranchIfFalse(label, false);
}
else
{
ctx.LoadValue((int)(uint)defaultValue);
EmitBeq(ctx, label, ExpectedType);
}
break;
case ProtoTypeCode.Char:
if ((char)defaultValue == (char)0)
{
ctx.BranchIfFalse(label, false);
}
else
{
ctx.LoadValue((int)(char)defaultValue);
EmitBeq(ctx, label, ExpectedType);
}
break;
case ProtoTypeCode.Int64:
ctx.LoadValue((long)defaultValue);
EmitBeq(ctx, label, ExpectedType);
break;
case ProtoTypeCode.UInt64:
ctx.LoadValue((long)(ulong)defaultValue);
EmitBeq(ctx, label, ExpectedType);
break;
case ProtoTypeCode.Double:
//.........这里部分代码省略.........
示例5: EmitRead
protected override void EmitRead(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
{
bool writeValue;
SanityCheck(ctx.Model, property, Tail, out writeValue, ctx.NonPublic, ctx.AllowInternal(property));
if (ExpectedType.IsValueType && valueFrom == null)
{
throw new InvalidOperationException("Attempt to mutate struct on the head of the stack; changes would be lost");
}
using (Compiler.Local loc = ctx.GetLocalWithValue(ExpectedType, valueFrom))
{
if (Tail.RequiresOldValue)
{
ctx.LoadAddress(loc, ExpectedType); // stack is: old-addr
ctx.LoadValue(property); // stack is: old-value
}
Type propertyType = property.PropertyType;
ctx.ReadNullCheckedTail(propertyType, Tail, null); // stack is [new-value]
if (writeValue)
{
using (Compiler.Local newVal = new Compiler.Local(ctx, property.PropertyType))
{
ctx.StoreValue(newVal); // stack is empty
Compiler.CodeLabel allDone = new Compiler.CodeLabel(); // <=== default structs
if (!propertyType.IsValueType)
{ // if the tail returns a null, intepret that as *no assign*
allDone = ctx.DefineLabel();
ctx.LoadValue(newVal); // stack is: new-value
ctx.BranchIfFalse(@allDone, true); // stack is empty
}
// assign the value
ctx.LoadAddress(loc, ExpectedType); // parent-addr
ctx.LoadValue(newVal); // parent-obj|new-value
if (shadowSetter == null)
{
ctx.StoreValue(property); // empty
}
else
{
ctx.EmitCall(shadowSetter); // empty
}
if (!propertyType.IsValueType)
{
ctx.MarkLabel(allDone);
}
}
}
else
{ // don't want return value; drop it if anything there
// stack is [new-value]
if (Tail.ReturnsValue) { ctx.DiscardValue(); }
}
}
}
示例6: EmitRead
public void EmitRead(Compiler.CompilerContext ctx, Compiler.Local incoming)
{
using (Compiler.Local objValue = ctx.GetLocalWithValue(ExpectedType, incoming))
{
Compiler.Local[] locals = new Compiler.Local[members.Length];
try
{
for (int i = 0; i < locals.Length; i++)
{
Type type = GetMemberType(i);
bool store = true;
locals[i] = new Compiler.Local(ctx, type);
if (!Helpers.IsValueType(ExpectedType))
{
// value-types always read the old value
if (Helpers.IsValueType(type))
{
switch (Helpers.GetTypeCode(type))
{
case ProtoTypeCode.Boolean:
case ProtoTypeCode.Byte:
case ProtoTypeCode.Int16:
case ProtoTypeCode.Int32:
case ProtoTypeCode.SByte:
case ProtoTypeCode.UInt16:
case ProtoTypeCode.UInt32:
ctx.LoadValue(0);
break;
case ProtoTypeCode.Int64:
case ProtoTypeCode.UInt64:
ctx.LoadValue(0L);
break;
case ProtoTypeCode.Single:
ctx.LoadValue(0.0F);
break;
case ProtoTypeCode.Double:
ctx.LoadValue(0.0D);
break;
case ProtoTypeCode.Decimal:
ctx.LoadValue(0M);
break;
case ProtoTypeCode.Guid:
ctx.LoadValue(Guid.Empty);
break;
default:
ctx.LoadAddress(locals[i], type);
ctx.EmitCtor(type);
store = false;
break;
}
}
else
{
ctx.LoadNullRef();
}
if (store)
{
ctx.StoreValue(locals[i]);
}
}
}
Compiler.CodeLabel skipOld = Helpers.IsValueType(ExpectedType)
? new Compiler.CodeLabel()
: ctx.DefineLabel();
if (!Helpers.IsValueType(ExpectedType))
{
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);
//.........这里部分代码省略.........
示例7: EmitWrite
protected override void EmitWrite(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
{
using(Compiler.Local valOrNull = ctx.GetLocalWithValue(expectedType, valueFrom))
using(Compiler.Local token = new Compiler.Local(ctx, ctx.MapType(typeof(SubItemToken))))
{
ctx.LoadNullRef();
ctx.LoadReaderWriter();
ctx.EmitCall(ctx.MapType(typeof(ProtoWriter)).GetMethod("StartSubItem"));
ctx.StoreValue(token);
if (Helpers.IsValueType(expectedType))
{
ctx.LoadAddress(valOrNull, expectedType);
ctx.LoadValue(expectedType.GetProperty("HasValue"));
}
else
{
ctx.LoadValue(valOrNull);
}
Compiler.CodeLabel @end = ctx.DefineLabel();
ctx.BranchIfFalse(@end, false);
if (Helpers.IsValueType(expectedType))
{
ctx.LoadAddress(valOrNull, expectedType);
ctx.EmitCall(expectedType.GetMethod("GetValueOrDefault", Helpers.EmptyTypes));
}
else
{
ctx.LoadValue(valOrNull);
}
Tail.EmitWrite(ctx, null);
ctx.MarkLabel(@end);
ctx.LoadValue(token);
ctx.LoadReaderWriter();
ctx.EmitCall(ctx.MapType(typeof(ProtoWriter)).GetMethod("EndSubItem"));
}
}
示例8: EmitRead
protected override void EmitRead(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
{
bool writeValue;
SanityCheck(ctx.Model, property, Tail, out writeValue, ctx.NonPublic, ctx.AllowInternal(property));
if (ExpectedType.IsValueType && valueFrom == null)
{
throw new InvalidOperationException("Attempt to mutate struct on the head of the stack; changes would be lost");
}
ctx.LoadAddress(valueFrom, ExpectedType); // stack is: old-addr
if (writeValue && Tail.RequiresOldValue)
{ // need to read and write
ctx.CopyValue();
}
// stack is: [old-addr]|old-addr
if (Tail.RequiresOldValue)
{
ctx.LoadValue(property); // stack is: [old-addr]|old-value
}
Type propertyType = property.PropertyType;
ctx.ReadNullCheckedTail(propertyType, Tail, null); // stack is [old-addr]|[new-value]
if (writeValue)
{
// stack is old-addr|new-value
Compiler.CodeLabel @skip = new Compiler.CodeLabel(), allDone = new Compiler.CodeLabel(); // <=== default structs
if (!propertyType.IsValueType)
{ // if the tail returns a null, intepret that as *no assign*
ctx.CopyValue(); // old-addr|new-value|new-value
@skip = ctx.DefineLabel();
allDone = ctx.DefineLabel();
ctx.BranchIfFalse(@skip, true); // old-addr|new-value
}
if (shadowSetter == null)
{
ctx.StoreValue(property);
}
else
{
ctx.EmitCall(shadowSetter);
}
if (!propertyType.IsValueType)
{
ctx.Branch(allDone, true);
ctx.MarkLabel(@skip); // old-addr|new-value
ctx.DiscardValue();
ctx.DiscardValue();
ctx.MarkLabel(allDone);
}
}
else
{ // don't want return value; drop it if anything there
// stack is [new-value]
if (Tail.ReturnsValue) { ctx.DiscardValue(); }
}
}
示例9: EmitReadArray
private void EmitReadArray(Compiler.CompilerContext ctx, Compiler.Local list, Compiler.Local oldArr,
Compiler.Local newArr, IProtoSerializer tail, MethodInfo add, Type listType)
{
Compiler.CodeLabel readPacked = packedWireType == WireType.None ? new Compiler.CodeLabel() : ctx.DefineLabel();
Compiler.CodeLabel @end = ctx.DefineLabel();
if (packedWireType != WireType.None)
{
ctx.LoadReaderWriter();
ctx.LoadValue(typeof(ProtoReader).GetProperty("WireType"));
ctx.LoadValue((int)WireType.String);
ctx.BranchIfEqual(readPacked, false);
}
using (Compiler.Local fieldNumber = new Compiler.Local(ctx, typeof(int)))
{
// int fieldNumber = source.FieldNumber;
ctx.LoadReaderWriter();
ctx.LoadValue(typeof (ProtoReader).GetProperty("FieldNumber"));
ctx.StoreValue(fieldNumber);
using (Compiler.Local readObject = new Compiler.Local(ctx, typeof (bool)))
using (Compiler.Local arrayKey = new Compiler.Local(ctx, typeof (int)))
{
// bool readObject = true;
ctx.LoadValue(true);
ctx.StoreValue(readObject);
// value = value ?? Array.CreateInstance(itemType, 0);
Compiler.CodeLabel @endCreateInstance = ctx.DefineLabel();
ctx.LoadValue(oldArr);
ctx.LoadNullRef();
ctx.TestEqual();
ctx.BranchIfFalse(@endCreateInstance, true);
ctx.LoadValue(itemType);
ctx.LoadValue(0);
ctx.EmitCall(typeof(Array).GetMethod("CreateInstance", new Type[] { typeof(Type), typeof(int) }));
ctx.StoreValue(oldArr);
ctx.MarkLabel(@endCreateInstance);
if (AsReference)
{
using (Compiler.Local objectKey = new Compiler.Local(ctx, typeof(int)))
{
//int objectKey = source.ReadInt32();
ctx.LoadReaderWriter();
ctx.EmitCall(typeof(ProtoReader).GetMethod("ReadInt32"));
ctx.StoreValue(objectKey);
Compiler.CodeLabel @ifNotThere = ctx.DefineLabel();
Compiler.CodeLabel @endIf = ctx.DefineLabel();
//if (objectKey > 0)
ctx.LoadValue(objectKey);
ctx.LoadValue(0);
ctx.BranchIfLessOrEqual(@ifNotThere, true);
// value = source.NetCache.GetKeyedObject(objectKey);
ctx.LoadReaderWriter();
ctx.LoadValue(typeof(ProtoReader).GetProperty("NetCache"));
ctx.LoadValue(objectKey);
ctx.EmitCall(typeof(NetObjectCache).GetMethod("GetKeyedObject"));
ctx.StoreValue(oldArr);
//readObject = false;
ctx.LoadValue(false);
ctx.StoreValue(readObject);
//}
ctx.Branch(@endIf, true);
//else
ctx.MarkLabel(@ifNotThere);
//bool dummy;
//arrayKey = source.NetCache.AddObjectKey(value, out dummy);
using (Compiler.Local dummy = new Compiler.Local(ctx, typeof(bool)))
{
ctx.LoadReaderWriter();
ctx.LoadValue(typeof(ProtoReader).GetProperty("NetCache"));
ctx.LoadValue(oldArr);
ctx.LoadAddress(dummy, typeof(bool));
ctx.EmitCall(typeof(NetObjectCache).GetMethod("AddObjectKey", new Type[] { typeof(object), typeof(bool).MakeByRefType() }));
ctx.StoreValue(arrayKey);
}
ctx.MarkLabel(@endIf);
}
}
else
{
using (Compiler.Local readValue = new Compiler.Local(ctx, typeof(int)))
{
ctx.LoadReaderWriter();
ctx.EmitCall(typeof(ProtoReader).GetMethod("ReadInt32"));
ctx.StoreValue(readValue);
//.........这里部分代码省略.........
示例10: EmitReadEndPacked
private void EmitReadEndPacked(Compiler.CompilerContext ctx, Compiler.Local list, Compiler.Local oldArr,
Compiler.Local newArr, Type listType)
{
// leave this "using" here, as it can share the "FieldNumber" local with EmitReadList
using(Compiler.Local oldLen = AppendToCollection ? new ProtoBuf.Compiler.Local(ctx, typeof(int)) : null) {
Type[] copyToArrayInt32Args = new Type[] { typeof(Array), typeof(int) };
if (AppendToCollection)
{
ctx.LoadLength(oldArr, true);
ctx.CopyValue();
ctx.StoreValue(oldLen);
ctx.LoadAddress(list, listType);
ctx.LoadValue(listType.GetProperty("Count"));
ctx.Add();
ctx.CreateArray(itemType, null); // length is on the stack
ctx.StoreValue(newArr);
ctx.LoadValue(oldLen);
Compiler.CodeLabel nothingToCopy = ctx.DefineLabel();
ctx.BranchIfFalse(nothingToCopy, true);
ctx.LoadValue(oldArr);
ctx.LoadValue(newArr);
ctx.LoadValue(0); // index in target
ctx.EmitCall(ExpectedType.GetMethod("CopyTo", copyToArrayInt32Args));
ctx.MarkLabel(nothingToCopy);
ctx.LoadValue(list);
ctx.LoadValue(newArr);
ctx.LoadValue(oldLen);
}
else
{
ctx.LoadAddress(list, listType);
ctx.LoadValue(listType.GetProperty("Count"));
ctx.CreateArray(itemType, null);
ctx.StoreValue(newArr);
ctx.LoadAddress(list, listType);
ctx.LoadValue(newArr);
ctx.LoadValue(0);
}
copyToArrayInt32Args[0] = ExpectedType; // // prefer: CopyTo(T[], int)
MethodInfo copyTo = listType.GetMethod("CopyTo", copyToArrayInt32Args);
if (copyTo == null)
{ // fallback: CopyTo(Array, int)
copyToArrayInt32Args[1] = typeof(Array);
copyTo = listType.GetMethod("CopyTo", copyToArrayInt32Args);
}
ctx.EmitCall(copyTo);
}
ctx.LoadValue(newArr);
}
示例11: 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);
}
}
示例12: EmitRead
//.........这里部分代码省略.........
case ProtoTypeCode.Double:
ctx.LoadValue(0.0D);
break;
case ProtoTypeCode.Decimal:
ctx.LoadValue(0M);
break;
case ProtoTypeCode.Guid:
ctx.LoadValue(Guid.Empty);
break;
default:
ctx.LoadAddress(locals[i], type);
ctx.EmitCtor(type);
store = false;
break;
}
}
else
{
ctx.LoadNullRef();
}
if (store)
{
ctx.StoreValue(locals[i]);
}
}
}
Compiler.CodeLabel skipOld = ExpectedType.IsValueType
? new Compiler.CodeLabel()
: ctx.DefineLabel();
if (!ExpectedType.IsValueType)
{
ctx.LoadAddress(objValue, ExpectedType);
ctx.BranchIfFalse(skipOld, false);
}
for (int i = 0; i < members.Length; i++)
{
ctx.LoadAddress(objValue, ExpectedType);
switch (members[i].MemberType)
{
case MemberTypes.Field:
ctx.LoadValue((FieldInfo) members[i]);
break;
case MemberTypes.Property:
ctx.LoadValue((PropertyInfo) members[i]);
break;
}
ctx.StoreValue(locals[i]);
}
if (!ExpectedType.IsValueType) ctx.MarkLabel(skipOld);
using (Compiler.Local fieldNumber = new Compiler.Local(ctx, typeof (int)))
using (Compiler.Local j = new Compiler.Local(ctx, typeof (int)))
{
// j = 0
ctx.LoadValue(0);
ctx.StoreValue(j);
Compiler.CodeLabel @continue = ctx.DefineLabel(),
processField = ctx.DefineLabel(),
notRecognised = ctx.DefineLabel(),
@endWhileLoop = ctx.DefineLabel();
ctx.Branch(@continue, false);
示例13: EmitWrite
public void EmitWrite(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
{
Compiler.CodeLabel @end = ctx.DefineLabel();
using (Compiler.Local value = ctx.GetLocalWithValue(ctor.DeclaringType, valueFrom))
{
if (!baseTupleAsReference && asReference)
{
using (Compiler.Local existing = new Compiler.Local(ctx, typeof(bool)))
using (Compiler.Local tupleKey = new Compiler.Local(ctx, typeof(int)))
{
//int tupleKey = dest.NetCache.AddObjectKey(value, out existing);
ctx.LoadReaderWriter();
ctx.LoadValue(typeof(ProtoWriter).GetProperty("NetCache"));
ctx.LoadValue(value);
ctx.CastToObject(ctor.DeclaringType); // HACK : doesn't seem to get boxed from ctx.GetLocalWithValue
ctx.LoadAddress(existing, typeof(bool));
ctx.EmitCall(typeof(NetObjectCache).GetMethod("AddObjectKey", new Type[] { typeof(object), typeof(bool).MakeByRefType() }));
ctx.StoreValue(tupleKey);
//ProtoWriter.WriteUInt32(existing ? (uint) tupleKey : 0, dest);
Compiler.CodeLabel @continueBranch = ctx.DefineLabel();
ctx.LoadValue(0);
ctx.LoadValue(existing);
ctx.BranchIfFalse(@continueBranch, true);
ctx.DiscardValue();
ctx.LoadValue(tupleKey);
//ctx.CastToObject(typeof(uint));
ctx.MarkLabel(@continueBranch);
ctx.LoadReaderWriter();
ctx.EmitCall(typeof(ProtoWriter).GetMethod("WriteUInt32"));
//if (existing) { return; }
ctx.LoadValue(existing);
ctx.BranchIfTrue(@end, false);
}
}
for (int i = 0; i < tails.Length; i++)
{
Type type = GetMemberType(i);
ctx.LoadAddress(value, ExpectedType);
switch(members[i].MemberType)
{
case MemberTypes.Field:
ctx.LoadValue((FieldInfo)members[i]);
break;
case MemberTypes.Property:
ctx.LoadValue((PropertyInfo)members[i]);
break;
}
ctx.WriteNullCheckedTail(type, tails[i], null);
}
}
if (forceIssueFakeHeader)
{
ctx.LoadReaderWriter();
ctx.EmitCall(typeof(ProtoWriter).GetMethod("WriteEndGroupFieldHeaderHack"));
}
ctx.MarkLabel(@end);
}