Пример #1
0
        private Result RewriteMemberExpression(Expression expr, Stack stack)
        {
            MemberExpression node = (MemberExpression)expr;

            ChildRewriter cr = new ChildRewriter(this, stack, 1);

            cr.Add(node.Expression);

            if (cr.Rewrite)
            {
                if (cr.Action == RewriteAction.SpillStack && node.Member is PropertyInfo)
                {
                    // Only need to validate propreties because reading a field
                    // is always side-effect free.
#if LINQ
                    RequireNotRefInstance(node.Expression);
#else
                    MarkRefInstance(cr, node.Expression);
#endif
                }

                expr = MemberExpressionStubs.Make(cr[0], node.Member);
            }

            return(cr.Finish(expr));
        }
Пример #2
0
        // member assignment
        private Result RewriteMemberAssignment(BinaryExpression node, Stack stack)
        {
            MemberExpression lvalue = (MemberExpression)node.Left;

            ChildRewriter cr = new ChildRewriter(this, stack, 2);

            // If there's an instance, it executes on the stack in current state
            // and rest is executed on non-empty stack.
            // Otherwise the stack is left unchanged.
            cr.Add(lvalue.Expression);

            cr.Add(node.Right);

            if (cr.Action == RewriteAction.SpillStack)
            {
#if LINQ
                RequireNotRefInstance(lvalue.Expression);
#else
                MarkRefInstance(cr, lvalue.Expression);
#endif
            }

            if (cr.Rewrite)
            {
                return(cr.Finish(
                           CreateAssignBinaryExpression(
                               MemberExpressionStubs.Make(cr[0], lvalue.Member),
                               cr[1]
                               )
                           ));
            }
            return(new Result(RewriteAction.None, node));
        }
Пример #3
0
        // MemberExpression
#if LINQ
        private Result RewriteMemberExpression(Expression expr, Stack stack)
        {
            MemberExpression node = (MemberExpression)expr;

            // Expression is emitted on top of the stack in current state
            Result expression = RewriteExpression(node.Expression, stack);

            if (expression.Action != RewriteAction.None)
            {
                if (expression.Action == RewriteAction.SpillStack &&
                    node.Member is PropertyInfo)
                {
                    // Only need to validate propreties because reading a field
                    // is always side-effect free.
                    RequireNotRefInstance(node.Expression);
                }
                expr = MemberExpressionStubs.Make(expression.Node, node.Member);
            }
            return(new Result(expression.Action, expr));
        }