当前位置: 首页>>代码示例>>C#>>正文


C# Compiler.Local类代码示例

本文整理汇总了C#中System.Compiler.Local的典型用法代码示例。如果您正苦于以下问题:C# Local类的具体用法?C# Local怎么用?C# Local使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Local类属于System.Compiler命名空间,在下文中一共展示了Local类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: VisitReturnValue

        public override Expression VisitReturnValue(ReturnValue returnValue)
        {
            // return a default value of the same type as the return value
            TypeNode returnType = returnValue.Type;
            ITypeParameter itp = returnType as ITypeParameter;
            if (itp != null)
            {
                Local loc = new Local(returnType);

                UnaryExpression loca = new UnaryExpression(loc, NodeType.AddressOf, loc.Type.GetReferenceType());
                StatementList statements = new StatementList(2);

                statements.Add(new AssignmentStatement(new AddressDereference(loca, returnType, false, 0),
                    new Literal(null, SystemTypes.Object)));

                statements.Add(new ExpressionStatement(loc));

                return new BlockExpression(new Block(statements), returnType);
            }

            if (returnType.IsValueType)
                return new Literal(0, returnType);
            
            return new Literal(null, returnType);
        }
开发者ID:asvishnyakov,项目名称:CodeContracts,代码行数:25,代码来源:CleanUpOldAndResult.cs

示例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
            }
        }
开发者ID:gezidan,项目名称:ZYSOCKET,代码行数:60,代码来源:NullDecorator.cs

示例3: VisitAssignmentStatement

        public override void VisitAssignmentStatement(AssignmentStatement assignment)
        {
            if (assignment.Target is Local && IsResultExpression(assignment.Source))
            {
                exemptResultLocal = (Local) assignment.Target;
            }

            base.VisitAssignmentStatement(assignment);
        }
开发者ID:Yatajga,项目名称:CodeContracts,代码行数:9,代码来源:GatherLocals.cs

示例4: VisitLocal

        public override Expression VisitLocal(Local local)
        {
            if (HelperMethods.IsClosureType(this.parentType, local.Type))
            {
                // don't copy local as we need to share this closure local
                return local;
            }

            return base.VisitLocal(local);
        }
开发者ID:asvishnyakov,项目名称:CodeContracts,代码行数:10,代码来源:AsyncContractDuplicator.cs

示例5: EmitReadList

        internal static void EmitReadList(ProtoBuf.Compiler.CompilerContext ctx, Compiler.Local list, IProtoSerializer tail, MethodInfo add, WireType packedWireType)
        {
            using (Compiler.Local fieldNumber = new Compiler.Local(ctx, typeof(int)))
            {
                Compiler.CodeLabel readPacked = packedWireType == WireType.None ? new Compiler.CodeLabel() : ctx.DefineLabel();                                   
                if (packedWireType != WireType.None)
                {
                    ctx.LoadReaderWriter();
                    ctx.LoadValue(typeof(ProtoReader).GetProperty("WireType"));
                    ctx.LoadValue((int)WireType.String);
                    ctx.BranchIfEqual(readPacked, false);
                }
                ctx.LoadReaderWriter();
                ctx.LoadValue(typeof(ProtoReader).GetProperty("FieldNumber"));
                ctx.StoreValue(fieldNumber);

                Compiler.CodeLabel @continue = ctx.DefineLabel();
                ctx.MarkLabel(@continue);

                EmitReadAndAddItem(ctx, list, tail, add);

                ctx.LoadReaderWriter();
                ctx.LoadValue(fieldNumber);
                ctx.EmitCall(typeof(ProtoReader).GetMethod("TryReadFieldHeader"));
                ctx.BranchIfTrue(@continue, false);

                if (packedWireType != WireType.None)
                {
                    Compiler.CodeLabel allDone = ctx.DefineLabel();
                    ctx.Branch(allDone, false);
                    ctx.MarkLabel(readPacked);

                    ctx.LoadReaderWriter();
                    ctx.EmitCall(typeof(ProtoReader).GetMethod("StartSubItem"));

                    Compiler.CodeLabel testForData = ctx.DefineLabel(), noMoreData = ctx.DefineLabel();
                    ctx.MarkLabel(testForData);
                    ctx.LoadValue((int)packedWireType);
                    ctx.LoadReaderWriter();
                    ctx.EmitCall(typeof(ProtoReader).GetMethod("HasSubValue"));
                    ctx.BranchIfFalse(noMoreData, false);

                    EmitReadAndAddItem(ctx, list, tail, add);
                    ctx.Branch(testForData, false);

                    ctx.MarkLabel(noMoreData);
                    ctx.LoadReaderWriter();
                    ctx.EmitCall(typeof(ProtoReader).GetMethod("EndSubItem"));
                    ctx.MarkLabel(allDone);
                }


                
            }
        }
开发者ID:AugustoAngeletti,项目名称:blockspaces,代码行数:55,代码来源:ListDecorator.cs

示例6: VisitLocal

        public override void VisitLocal(Local local)
        {
            // if the local is a reference to a closure class, then
            // don't mark it because it is sure to be used in both
            // the contracts and the method body
            if (!IsLocalExempt(local) && Locals[local.UniqueKey] == null)
            {
                //Console.Write("{0} ", local.Name.Name);
                Locals[local.UniqueKey] = local;
            }

            base.VisitLocal(local);
        }
开发者ID:Yatajga,项目名称:CodeContracts,代码行数:13,代码来源:GatherLocals.cs

示例7: VisitLocal

        /// <summary>
        /// check for reused local.
        /// HACK: ignore VB cached boolean locals used in tests. VB does this seemingly for debuggability.
        /// These are always assigned before use in the same scope, so we ignore them.
        /// </summary>
        /// <param name="local"></param>
        /// <returns></returns>
        public override void VisitLocal(Local local)
        {
            if (gatherLocals.Locals[local.UniqueKey] != null)
            {
                if (local.Name != null && local.Name.Name.StartsWith("VB$CG$"))
                {
                    // ignore VB compiler generated locals.
                }
                else
                {
                    reUseOfExistingLocal = local;
                }
            }

            base.VisitLocal(local);
        }
开发者ID:asvishnyakov,项目名称:CodeContracts,代码行数:23,代码来源:CheckLocals.cs

示例8: using

        void IProtoSerializer.EmitRead(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
        {
            Helpers.DebugAssert(valueFrom != null); // don't support stack-head for this
            using (Compiler.Local converted = new Compiler.Local(ctx, tail.ExpectedType)) // declare/re-use local
            {
                ctx.LoadValue(valueFrom); // load primary onto stack
                ctx.EmitCall(toTail); // static convert op, primary-to-surrogate
                ctx.StoreValue(converted); // store into surrogate local

                tail.EmitRead(ctx, converted); // downstream processing against surrogate local

                ctx.LoadValue(converted); // load from surrogate local
                ctx.EmitCall(fromTail);  // static convert op, surrogate-to-primary
                ctx.StoreValue(valueFrom); // store back into primary
            }
        }
开发者ID:AugustoAngeletti,项目名称:blockspaces,代码行数:16,代码来源:SurrogateSerializer.cs

示例9: VisitLocal

        public override void VisitLocal(Local local)
        {
            // if the local is a reference to a closure class, then
            // don't mark it because it is sure to be used in both
            // the contracts and the method body.
            
            // Another exception for this rule is an expression initialization 
            // that also introduces local variable that could be used in Contract.Requires
            if (!IsLocalExempt(local) && Locals[local.UniqueKey] == null)
            {
                //Console.Write("{0} ", local.Name.Name);
                Locals[local.UniqueKey] = local;
            }

            base.VisitLocal(local);
        }
开发者ID:asvishnyakov,项目名称:CodeContracts,代码行数:16,代码来源:GatherLocals.cs

示例10: EmitWrite

        protected override void EmitWrite(ProtoBuf.Compiler.CompilerContext ctx, ProtoBuf.Compiler.Local valueFrom)
        {
            // int i and T[] arr
            using (Compiler.Local arr = ctx.GetLocalWithValue(arrayType, valueFrom))
            using (Compiler.Local i = new ProtoBuf.Compiler.Local(ctx, typeof(int)))
            {
                if (packedFieldNumber > 0)
                {
                    Compiler.CodeLabel allDone = ctx.DefineLabel();
                    ctx.LoadLength(arr, false);
                    ctx.BranchIfFalse(allDone, false);

                    ctx.LoadValue(packedFieldNumber);
                    ctx.LoadValue((int)WireType.String);
                    ctx.LoadReaderWriter();
                    ctx.EmitCall(typeof(ProtoWriter).GetMethod("WriteFieldHeader"));

                    ctx.LoadValue(arr);
                    ctx.LoadReaderWriter();
                    ctx.EmitCall(typeof(ProtoWriter).GetMethod("StartSubItem"));
                    using (Compiler.Local token = new Compiler.Local(ctx, typeof(SubItemToken))) { 
                        ctx.StoreValue(token);

                        ctx.LoadValue(packedFieldNumber);
                        ctx.LoadReaderWriter();
                        ctx.EmitCall(typeof(ProtoWriter).GetMethod("SetPackedField"));

                        EmitWriteArrayLoop(ctx, i, arr);

                        ctx.LoadValue(token);
                        ctx.LoadReaderWriter();
                        ctx.EmitCall(typeof(ProtoWriter).GetMethod("EndSubItem"));
                    }
                    ctx.MarkLabel(allDone);
                }
                else
                {
                    EmitWriteArrayLoop(ctx, i, arr);    
                }
            }
        }
开发者ID:martindevans,项目名称:DistributedServiceProvider,代码行数:41,代码来源:ArrayDecorator.cs

示例11: 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);
                        }
                    }
                }
            }
        }
开发者ID:d3x0r,项目名称:Voxelarium,代码行数:39,代码来源:FieldDecorator.cs

示例12: IsLocalExempt

        /// <summary>
        /// Use stricter checking if local has a real name (other than "localXXX")
        /// </summary>
        private bool IsLocalExempt(Local local)
        {
            if (local == exemptResultLocal) return true;

            bool strict = false;

            if (local.Name != null && local.Name.Name != null && !local.Name.Name.StartsWith("local"))
            {
                strict = true;
            }

            var localType = local.Type;
            if (localType == null) return true;

            return HelperMethods.IsCompilerGenerated(localType)
                   || local.Name.Name == "_preConditionHolds"
                // introduced by extractor itself for legacy pre-conditions
                   || (strict
                       ? (LocalNameIsExempt(local.Name.Name))
                       : (HelperMethods.IsDelegateType(localType)
                          || HelperMethods.IsTypeParameterType(localType)
                          || localType.IsValueType));
        }
开发者ID:Yatajga,项目名称:CodeContracts,代码行数:26,代码来源:GatherLocals.cs

示例13: Dispose

            public void Dispose()
            {
                if (local == null || ctx == null) return;

                ctx.EndTry(label, false);
                ctx.BeginFinally();
                Type disposableType = ctx.MapType(typeof (IDisposable));
                MethodInfo dispose = disposableType.GetMethod("Dispose");
                Type type = local.Type;
                // remember that we've already (in the .ctor) excluded the case
                // where it *cannot* be disposable
                if (type.IsValueType)
                {
                    ctx.LoadAddress(local, type);
                    switch (ctx.MetadataVersion)
                    {
                        case ILVersion.Net1:
                            ctx.LoadValue(local);
                            ctx.CastToObject(type);
                            break;

                        default:
                #if FX11
                            throw new NotSupportedException();
                #else
                            ctx.Constrain(type);
                            break;
                #endif
                    }
                    ctx.EmitCall(dispose);
                }
                else
                {
                    Compiler.CodeLabel @null = ctx.DefineLabel();
                    if (disposableType.IsAssignableFrom(type))
                    {   // *known* to be IDisposable; just needs a null-check
                        ctx.LoadValue(local);
                        ctx.BranchIfFalse(@null, true);
                        ctx.LoadAddress(local, type);
                    }
                    else
                    {   // *could* be IDisposable; test via "as"
                        using (Compiler.Local disp = new Compiler.Local(ctx, disposableType))
                        {
                            ctx.LoadValue(local);
                            ctx.TryCast(disposableType);
                            ctx.CopyValue();
                            ctx.StoreValue(disp);
                            ctx.BranchIfFalse(@null, true);
                            ctx.LoadAddress(disp, disposableType);
                        }
                    }
                    ctx.EmitCall(dispose);
                    ctx.MarkLabel(@null);
                }
                ctx.EndFinally();
                this.local = null;
                this.ctx = null;
                label = new CodeLabel(); // default
            }
开发者ID:banksyhf,项目名称:Auxilium-2,代码行数:60,代码来源:CompilerContext.cs

示例14: 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);
//.........这里部分代码省略.........
开发者ID:GeorchW,项目名称:protobuf-net,代码行数:101,代码来源:TupleSerializer.cs

示例15: EmitBoxedSerializer

        private static MethodBuilder EmitBoxedSerializer(TypeBuilder type, int i, Type valueType, SerializerPair[] methodPairs, TypeModel model, Compiler.CompilerContext.ILVersion ilVersion, string assemblyName)
        {
            MethodInfo dedicated = methodPairs[i].Deserialize;
            MethodBuilder boxedSerializer = type.DefineMethod("_" + i.ToString(), MethodAttributes.Static, CallingConventions.Standard,
                model.MapType(typeof(object)), new Type[] { model.MapType(typeof(object)), model.MapType(typeof(ProtoReader)) });
            Compiler.CompilerContext ctx = new Compiler.CompilerContext(boxedSerializer.GetILGenerator(), true, false, methodPairs, model, ilVersion, assemblyName, model.MapType(typeof(object)));
            ctx.LoadValue(ctx.InputValue);
            Compiler.CodeLabel @null = ctx.DefineLabel();
            ctx.BranchIfFalse(@null, true);

            Type mappedValueType = valueType;
            ctx.LoadValue(ctx.InputValue);
            ctx.CastFromObject(mappedValueType);
            ctx.LoadReaderWriter();
            ctx.EmitCall(dedicated);
            ctx.CastToObject(mappedValueType);
            ctx.Return();

            ctx.MarkLabel(@null);
            using (Compiler.Local typedVal = new Compiler.Local(ctx, mappedValueType))
            {
                // create a new valueType
                ctx.LoadAddress(typedVal, mappedValueType);
                ctx.EmitCtor(mappedValueType);
                ctx.LoadValue(typedVal);
                ctx.LoadReaderWriter();
                ctx.EmitCall(dedicated);
                ctx.CastToObject(mappedValueType);
                ctx.Return();
            }
            return boxedSerializer;
        }
开发者ID:SimonPStevens,项目名称:protobuf-net,代码行数:32,代码来源:RuntimeTypeModel.cs


注:本文中的System.Compiler.Local类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。