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


C# Compiler.AddFrame方法代码示例

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


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

示例1: CompileDereference

        protected virtual Expression CompileDereference(Compiler compiler, Frame frame, Expression left, Parse.BinaryExpression expression, System.Type typeHint)
        {
            left = compiler.MaterializeReference(left);

            var local = compiler.AddFrame(frame, expression);
            var memberType = left.Type.GenericTypeArguments[0];
            var parameters = new List<ParameterExpression>();

            var valueParam = compiler.CreateValueParam(expression, local, left, memberType);
            parameters.Add(valueParam);

            var indexParam = compiler.CreateIndexParam(expression, local);
            parameters.Add(indexParam);

            var right =
                compiler.MaterializeReference
                (
                    compiler.CompileExpression(local, expression.Right, typeHint)
                );

            var selection = Expression.Lambda(right, parameters);
            var select =
                typeof(Enumerable).GetMethodExt
                (
                    "Select",
                    new System.Type[] { typeof(IEnumerable<ReflectionUtility.T>), typeof(Func<ReflectionUtility.T, int, ReflectionUtility.T>) }
                );
            select = select.MakeGenericMethod(memberType, selection.ReturnType);
            return Expression.Call(select, left, selection);
        }
开发者ID:jgabb8989,项目名称:DotQL,代码行数:30,代码来源:NaryTypeHandler.cs

示例2: CompileDereference

        private Expression CompileDereference(Compiler compiler, Frame frame, Expression left, Parse.BinaryExpression expression, System.Type typeHint)
        {
            left = compiler.MaterializeReference(left);

            var local = compiler.AddFrame(frame, expression);
            foreach (var field in left.Type.GetFields(BindingFlags.Public | BindingFlags.Instance))
            {
                local.Add(expression, Name.FromNative(field.Name), field);
                var fieldExpression = Expression.Field(left, field);
                compiler.ExpressionsBySymbol.Add(field, fieldExpression);
            }
            return compiler.CompileExpression(local, expression.Right, typeHint);
        }
开发者ID:jgabb8989,项目名称:DotQL,代码行数:13,代码来源:TupleTypeHandler.cs

示例3: CompileExtractExpression

        // Restriction
        public override ExpressionContext CompileExtractExpression(Compiler compiler, Frame frame, ExpressionContext left, Parse.ExtractExpression expression, BaseType typeHint)
        {
            var local = compiler.AddFrame(frame, expression);
            var alreadyOptional = left.Type is OptionalType;
            var memberNative = left.Type.GetNative(compiler.Emitter);
            var resultType = alreadyOptional ? left.Type : new OptionalType(left.Type);
            var resultNative = resultType.GetNative(compiler.Emitter);

            // Register value symbol
            LocalBuilder valueLocal = null;
            var localSymbol = new Object();
            local.Add(expression.Condition, Name.FromComponents(Parse.ReservedWords.Value), localSymbol);
            compiler.ContextsBySymbol.Add
            (
                localSymbol,
                new ExpressionContext
                (
                    null,
                    left.Type,
                    left.Characteristics,
                    m => { m.IL.Emit(OpCodes.Ldloc, valueLocal); }
                )
            );

            var condition = compiler.CompileExpression(local, expression.Condition, SystemTypes.Boolean);
            if (!(condition.Type is BooleanType))
                throw new CompilerException(expression.Condition, CompilerException.Codes.IncorrectType, condition.Type, "Boolean");

            return
                new ExpressionContext
                (
                    expression,
                    resultType,
                    Compiler.MergeCharacteristics(left.Characteristics, condition.Characteristics),
                    m =>
                    {
                        var nullLabel = m.IL.DefineLabel();
                        var endLabel = m.IL.DefineLabel();

                        // Register value argument
                        valueLocal = m.DeclareLocal(expression, memberNative, Parse.ReservedWords.Value);
                        left.EmitGet(m);
                        m.IL.Emit(OpCodes.Stloc, valueLocal);

                        condition.EmitGet(m);
                        m.IL.Emit(OpCodes.Brfalse, nullLabel);

                        // Passed condition
                        if (!alreadyOptional && memberNative.IsValueType)
                        {
                            var optionalLocal = m.DeclareLocal(expression, resultNative, Parse.ReservedWords.Value);
                            m.IL.Emit(OpCodes.Ldloca, optionalLocal);
                            m.IL.Emit(OpCodes.Ldloc, valueLocal);
                            m.IL.Emit(OpCodes.Call, resultNative.GetConstructor(new System.Type[] { left.Type.GetNative(compiler.Emitter) }));
                            m.IL.Emit(OpCodes.Ldloc, optionalLocal);
                        }
                        else
                            m.IL.Emit(OpCodes.Ldloc, valueLocal);
                        m.IL.Emit(OpCodes.Br, endLabel);

                        // Failed condition
                        m.IL.MarkLabel(nullLabel);
                        if (!alreadyOptional && memberNative.IsValueType)
                        {
                            var optionalLocal = m.DeclareLocal(expression, resultNative, Parse.ReservedWords.Value);
                            m.IL.Emit(OpCodes.Ldloca, optionalLocal);
                            m.IL.Emit(OpCodes.Initobj, resultNative);
                            m.IL.Emit(OpCodes.Ldloc, optionalLocal);
                        }
                        else if (alreadyOptional && memberNative.IsValueType)
                        {
                            m.IL.Emit(OpCodes.Ldloca, valueLocal);
                            m.IL.Emit(OpCodes.Initobj, resultNative);
                            m.IL.Emit(OpCodes.Ldloc, valueLocal);
                        }
                        else
                            m.IL.Emit(OpCodes.Ldnull);

                        m.IL.MarkLabel(endLabel);
                    }
                );
        }
开发者ID:Ancestry,项目名称:DotQL,代码行数:83,代码来源:ScalarType.cs

示例4: CompileDereference

        private ExpressionContext CompileDereference(Compiler compiler, Frame frame, ExpressionContext left, Parse.BinaryExpression expression, Type.BaseType typeHint)
        {
            var local = compiler.AddFrame(frame, expression);
            var native = left.ActualNative(compiler.Emitter);

            LocalBuilder valueVariable = null;

            // Create symbol for each tuple member
            foreach (var a in ((TupleType)left.Type).Attributes)
            {
                var field = native.GetField(a.Key.ToString(), BindingFlags.Public | BindingFlags.Instance);
                local.Add(expression, a.Key, field);
                compiler.ContextsBySymbol.Add
                (
                    field,
                    new ExpressionContext
                    (
                        null,
                        a.Value,
                        Characteristic.Default,
                        m =>
                        {
                            m.IL.Emit(OpCodes.Ldloc, valueVariable);
                            m.IL.Emit(OpCodes.Ldfld, field);
                        }
                    )
                );
            }

            var right = compiler.CompileExpression(local, expression.Right, typeHint);

            return
                new ExpressionContext
                (
                    expression,
                    right.Type,
                    Compiler.MergeCharacteristics(left.Characteristics, right.Characteristics),
                    m =>
                    {
                        m.IL.BeginScope();

                        left.EmitGet(m);
                        valueVariable = m.DeclareLocal(expression.Right, native, "value");
                        m.IL.Emit(OpCodes.Stloc, valueVariable);

                        right.EmitGet(m);

                        m.IL.EndScope();
                    }
                );
        }
开发者ID:Ancestry,项目名称:DotQL,代码行数:51,代码来源:TupleType.cs

示例5: CompileExtractExpression

        // Restriction
        public override ExpressionContext CompileExtractExpression(Compiler compiler, Frame frame, ExpressionContext left, Parse.ExtractExpression expression, BaseType typeHint)
        {
            var memberType = ((NaryType)left.Type).Of;
            var memberNative = left.NativeType ?? memberType.GetNative(compiler.Emitter);

            var local = compiler.AddFrame(frame, expression);

            // Prepare index and value symbols
            var indexSymbol = PrepareValueIndexContext(compiler, left, expression.Condition, memberType, memberNative, local);

            // Compile condition
            var condition = compiler.CompileExpression(local, expression.Condition, SystemTypes.Boolean);
            if (!(condition.Type is BooleanType))
                throw new CompilerException(expression.Condition, CompilerException.Codes.IncorrectType, condition.Type, "Boolean");

            var indexReferenced = compiler.References.ContainsKey(indexSymbol);

            return
                new ExpressionContext
                (
                    expression,
                    left.Type,
                    Compiler.MergeCharacteristics(left.Characteristics, condition.Characteristics),
                    m =>
                    {
                        // Create a new private method for the condition
                        var typeBuilder = (TypeBuilder)m.Builder.DeclaringType;
                        var innerMethod =
                            new MethodContext
                            (
                                typeBuilder.DefineMethod
                                (
                                    "Where" + expression.GetHashCode(),
                                    MethodAttributes.Private | MethodAttributes.Static,
                                    typeof(bool),	// return type
                                    indexReferenced ? new System.Type[] { memberNative, typeof(int) } : new System.Type[] { memberNative }	// param types
                                )
                            );
                        condition.EmitGet(innerMethod);
                        innerMethod.IL.Emit(OpCodes.Ret);

                        left.EmitGet(m);

                        // TODO: Force ordering to left if Set and index is referenced

                        // Instantiate a delegate pointing to the new method
                        m.IL.Emit(OpCodes.Ldnull);				// instance
                        m.IL.Emit(OpCodes.Ldftn, innerMethod.Builder);	// method
                        var funcType =
                            indexReferenced
                                ? System.Linq.Expressions.Expression.GetFuncType(memberNative, typeof(int), typeof(bool))
                                : System.Linq.Expressions.Expression.GetFuncType(memberNative, typeof(bool));
                        m.IL.Emit
                        (
                            OpCodes.Newobj,
                            funcType.GetConstructor(new[] { typeof(object), typeof(IntPtr) })
                        );

                        funcType = indexReferenced ? typeof(Func<ReflectionUtility.T, int, bool>) : typeof(Func<ReflectionUtility.T, bool>);
                        var where = typeof(System.Linq.Enumerable).GetMethodExt("Where", new System.Type[] { typeof(IEnumerable<ReflectionUtility.T>), funcType });
                        where = where.MakeGenericMethod(memberNative);

                        m.IL.EmitCall(OpCodes.Call, where, null);
                    }
                );
        }
开发者ID:Ancestry,项目名称:DotQL,代码行数:67,代码来源:NaryType.cs

示例6: CompileDereference

        protected virtual ExpressionContext CompileDereference(Compiler compiler, Frame frame, ExpressionContext left, Parse.BinaryExpression expression, Type.BaseType typeHint)
        {
            var memberType = ((NaryType)left.Type).Of;
            var memberNative = left.NativeType ?? memberType.GetNative(compiler.Emitter);

            var local = compiler.AddFrame(frame, expression);

            // Prepare index and value symbols
            var indexSymbol = PrepareValueIndexContext(compiler, left, expression.Right, memberType, memberNative, local);

            // Compile selection
            var selection = compiler.CompileExpression(local, expression.Right);

            var indexReferenced = compiler.References.ContainsKey(indexSymbol);

            return
                new ExpressionContext
                (
                    expression,
                    new ListType(selection.Type),
                    Compiler.MergeCharacteristics(left.Characteristics, selection.Characteristics),
                    m =>
                    {
                        // Create a new private method for the condition
                        var typeBuilder = (TypeBuilder)m.Builder.DeclaringType;
                        var innerMethod =
                            new MethodContext
                            (
                                typeBuilder.DefineMethod
                                (
                                    "Select" + expression.GetHashCode(),
                                    MethodAttributes.Private | MethodAttributes.Static,
                                    selection.ActualNative(compiler.Emitter),	// temporary return type
                                    indexReferenced ? new System.Type[] { memberNative, typeof(int) } : new System.Type[] { memberNative }	// param types
                                )
                            );
                        selection.EmitGet(innerMethod);
                        innerMethod.IL.Emit(OpCodes.Ret);

                        left.EmitGet(m);

                        // TODO: Force ordering of Left if a set and index is referenced

                        // Instantiate a delegate pointing to the new method
                        m.IL.Emit(OpCodes.Ldnull);				// instance
                        m.IL.Emit(OpCodes.Ldftn, innerMethod.Builder);	// method
                        var funcType =
                            indexReferenced
                                ? System.Linq.Expressions.Expression.GetFuncType(memberNative, typeof(int), innerMethod.Builder.ReturnType)
                                : System.Linq.Expressions.Expression.GetFuncType(memberNative, innerMethod.Builder.ReturnType);
                        m.IL.Emit
                        (
                            OpCodes.Newobj,
                            funcType.GetConstructor(new[] { typeof(object), typeof(IntPtr) })
                        );

                        funcType = indexReferenced ? typeof(Func<ReflectionUtility.T, int, ReflectionUtility.T>) : typeof(Func<ReflectionUtility.T, ReflectionUtility.T>);
                        var select =
                            typeof(Enumerable).GetMethodExt
                            (
                                "Select",
                                new System.Type[] { typeof(IEnumerable<ReflectionUtility.T>), funcType }
                            );
                        select = select.MakeGenericMethod(memberNative, innerMethod.Builder.ReturnType);

                        m.IL.EmitCall(OpCodes.Call, select, null);
                    }
                );
        }
开发者ID:Ancestry,项目名称:DotQL,代码行数:69,代码来源:NaryType.cs


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