本文整理汇总了C#中Compiler.BranchIfEqual方法的典型用法代码示例。如果您正苦于以下问题:C# Compiler.BranchIfEqual方法的具体用法?C# Compiler.BranchIfEqual怎么用?C# Compiler.BranchIfEqual使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Compiler
的用法示例。
在下文中一共展示了Compiler.BranchIfEqual方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EmitBeq
private void EmitBeq(Compiler.CompilerContext ctx, Compiler.CodeLabel label, Type type)
{
switch (Helpers.GetTypeCode(type))
{
case ProtoTypeCode.Boolean:
case ProtoTypeCode.Byte:
case ProtoTypeCode.Char:
case ProtoTypeCode.Double:
case ProtoTypeCode.Int16:
case ProtoTypeCode.Int32:
case ProtoTypeCode.Int64:
case ProtoTypeCode.SByte:
case ProtoTypeCode.Single:
case ProtoTypeCode.UInt16:
case ProtoTypeCode.UInt32:
case ProtoTypeCode.UInt64:
ctx.BranchIfEqual(label, false);
break;
default:
MethodInfo method = type.GetMethod("op_Equality", BindingFlags.Public | BindingFlags.Static,
null, new Type[] { type, type }, null);
if (method == null || method.ReturnType != typeof(bool))
{
throw new InvalidOperationException("No suitable equality operator found for default-values of type: " + type.FullName);
}
ctx.EmitCall(method);
ctx.BranchIfTrue(label, false);
break;
}
}
示例2: 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
}
}
示例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: 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);
//.........这里部分代码省略.........
示例5: using
void IProtoSerializer.EmitWrite(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
{
Type expected = ExpectedType;
using (Compiler.Local loc = ctx.GetLocalWithValue(expected, valueFrom))
{
// pre-callbacks
EmitCallbackIfNeeded(ctx, loc, TypeModel.CallbackType.BeforeSerialize);
Compiler.CodeLabel startFields = ctx.DefineLabel();
// inheritance
if (CanHaveInheritance)
{
for (int i = 0; i < serializers.Length; i++)
{
IProtoSerializer ser = serializers[i];
if (ser.ExpectedType != forType)
{
Compiler.CodeLabel ifMatch = ctx.DefineLabel(), nextTest = ctx.DefineLabel();
ctx.LoadValue(loc);
ctx.TryCast(ser.ExpectedType);
ctx.CopyValue();
ctx.BranchIfTrue(ifMatch, true);
ctx.DiscardValue();
ctx.Branch(nextTest, true);
ctx.MarkLabel(ifMatch);
ser.EmitWrite(ctx, null);
ctx.Branch(startFields, false);
ctx.MarkLabel(nextTest);
}
}
if (constructType != null && constructType != forType)
{
using(Compiler.Local actualType = new Compiler.Local(ctx, typeof(Type)))
{
// would have jumped to "fields" if an expected sub-type, so two options:
// a: *exactly* that type, b: an *unexpected* type
ctx.LoadValue(loc);
ctx.EmitCall(typeof(object).GetMethod("GetType"));
ctx.CopyValue();
ctx.StoreValue(actualType);
ctx.LoadValue(forType);
ctx.BranchIfEqual(startFields, true);
ctx.LoadValue(actualType);
ctx.LoadValue(constructType);
ctx.BranchIfEqual(startFields, true);
}
}
else
{
// would have jumped to "fields" if an expected sub-type, so two options:
// a: *exactly* that type, b: an *unexpected* type
ctx.LoadValue(loc);
ctx.EmitCall(typeof(object).GetMethod("GetType"));
ctx.LoadValue(forType);
ctx.BranchIfEqual(startFields, true);
}
// unexpected, then... note that this *might* be a proxy, which
// is handled by ThrowUnexpectedSubtype
ctx.LoadValue(forType);
ctx.LoadValue(loc);
ctx.EmitCall(typeof(object).GetMethod("GetType"));
ctx.EmitCall(typeof(TypeModel).GetMethod("ThrowUnexpectedSubtype",
BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static));
}
// fields
ctx.MarkLabel(startFields);
for (int i = 0; i < serializers.Length; i++)
{
IProtoSerializer ser = serializers[i];
if (ser.ExpectedType == forType) ser.EmitWrite(ctx, loc);
}
// extension data
if (isExtensible)
{
ctx.LoadValue(loc);
ctx.LoadReaderWriter();
ctx.EmitCall(typeof(ProtoWriter).GetMethod("AppendExtensionData"));
}
// post-callbacks
EmitCallbackIfNeeded(ctx, loc, TypeModel.CallbackType.AfterSerialize);
}
}
示例6: EmitRead
public void EmitRead(Compiler.CompilerContext ctx, Compiler.Local incoming)
{
bool issueReferenceDirectives = !baseTupleAsReference && asReference;
Compiler.CodeLabel @end = ctx.DefineLabel();
using (Compiler.Local tupleKey = new Compiler.Local(ctx, typeof(int)))
using (Compiler.Local oldTuple = new Compiler.Local(ctx, typeof(object)))
using (Compiler.Local objValue = ctx.GetLocalWithValue(ExpectedType, incoming))
{
Compiler.Local[] locals = new Compiler.Local[members.Length];
try
{
if (issueReferenceDirectives)
{
//int tupleKey = 0;
ctx.LoadValue(0);
ctx.StoreValue(tupleKey);
//object oldTuple = null;
ctx.LoadNullRef();
ctx.StoreValue(oldTuple);
//tupleKey = (int)source.ReadUInt32();
ctx.LoadReaderWriter();
ctx.EmitCall(typeof (ProtoReader).GetMethod("ReadUInt32"));
//ctx.CastToObject(typeof (int));
ctx.StoreValue(tupleKey);
Compiler.CodeLabel @objectNotFound = ctx.DefineLabel();
ctx.LoadValue(tupleKey);
ctx.LoadValue(0);
ctx.BranchIfEqual(@objectNotFound, true);
//// return source.NetCache.GetKeyedObject(tupleKey);
ctx.LoadReaderWriter();
ctx.LoadValue(typeof (ProtoReader).GetProperty("NetCache"));
ctx.LoadValue(tupleKey);
ctx.EmitCall(typeof (NetObjectCache).GetMethod("GetKeyedObject"));
ctx.CastFromObject(ExpectedType);
ctx.StoreValue(objValue);
ctx.Branch(@end, false);
ctx.MarkLabel(@objectNotFound);
ctx.EmitCtor(typeof (object));
ctx.StoreValue(oldTuple);
// tupleKey = source.NetCache.AddObjectKey(oldTuple, out dummy);
using (Compiler.Local dummy = new Compiler.Local(ctx, typeof (bool)))
{
ctx.LoadReaderWriter();
ctx.LoadValue(typeof (ProtoReader).GetProperty("NetCache"));
ctx.LoadValue(oldTuple);
ctx.LoadAddress(dummy, typeof (bool));
ctx.EmitCall(typeof (NetObjectCache).GetMethod("AddObjectKey", new Type[] { typeof(object), typeof(bool).MakeByRefType() }));
ctx.StoreValue(tupleKey);
}
}
for (int i = 0; i < locals.Length; i++)
{
Type type = GetMemberType(i);
bool store = true;
locals[i] = new Compiler.Local(ctx, type);
if (!ExpectedType.IsValueType)
{
// value-types always read the old value
if (type.IsValueType)
{
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);
//.........这里部分代码省略.........