示例#1
0
文件: EventNode.cs 项目: menozz/lens
 public EventNode(EventWrapper evt, SetMemberNode node, bool isSubscription)
 {
     _Event = evt;
     _IsSubscription = isSubscription;
     _Node = node;
     _Callback = Expr.CastTransparent(node.Value, _Event.EventHandlerType);
 }
示例#2
0
        /// <summary>
        /// Expands short assignment to an expression member:
        /// (expr).x += 1
        /// or type::x += 1
        /// </summary>
        private NodeBase ExpandMember(Context ctx, SetMemberNode node)
        {
            // type::name += value
            if (node.StaticType != null)
            {
                return(Expr.SetMember(
                           node.StaticType,
                           node.MemberName,
                           _assignmentOperator(
                               Expr.GetMember(
                                   node.StaticType,
                                   node.MemberName
                                   ),
                               node.Value
                               )
                           ));
            }

            // simple case: no need to cache expression
            if (node.Expression is SetIdentifierNode)
            {
                return(Expr.SetMember(
                           node.Expression,
                           node.MemberName,
                           _assignmentOperator(
                               Expr.GetMember(
                                   node.Expression,
                                   node.MemberName
                                   ),
                               node.Value
                               )
                           ));
            }

            // (x + y).name += value
            // must cache (x + y) to a local variable to prevent double execution
            var tmpVar = ctx.Scope.DeclareImplicit(ctx, node.Expression.Resolve(ctx), false);

            return(Expr.Block(
                       Expr.Set(tmpVar, node.Expression),
                       Expr.SetMember(
                           Expr.Get(tmpVar),
                           node.MemberName,
                           _assignmentOperator(
                               Expr.GetMember(
                                   Expr.Get(tmpVar),
                                   node.MemberName
                                   ),
                               node.Value
                               )
                           )
                       ));
        }
示例#3
0
        /// <summary>
        /// Attempts to expand the expression to an event (un)subscription.
        /// </summary>
        private NodeBase ExpandEvent(Context ctx, SetMemberNode node)
        {
            // incorrect operator
            if (!_operatorType.IsAnyOf(LexemType.Plus, LexemType.Minus))
            {
                return(null);
            }

            var type = node.StaticType != null
                ? ctx.ResolveType(node.StaticType)
                : node.Expression.Resolve(ctx);

            try
            {
                var evt = ctx.ResolveEvent(type, node.MemberName);
//				node.Value = Expr.CastTransparent(node.Value, evt.EventHandlerType);
                return(new EventNode(evt, node, _operatorType == LexemType.Plus));
            }
            catch (KeyNotFoundException)
            {
                return(null);
            }
        }
示例#4
0
 protected bool Equals(SetMemberNode other)
 {
     return(base.Equals(other) && Equals(Value, other.Value));
 }
示例#5
0
 protected bool Equals(SetMemberNode other)
 {
     return base.Equals(other) && Equals(Value, other.Value);
 }
示例#6
0
        /// <summary>
        /// Attempts to expand the expression to an event (un)subscription.
        /// </summary>
        private NodeBase expandEvent(Context ctx, SetMemberNode node)
        {
            // incorrect operator
            if (!_OperatorType.IsAnyOf(LexemType.Plus, LexemType.Minus))
                return null;

            var type = node.StaticType != null
                ? ctx.ResolveType(node.StaticType)
                : node.Expression.Resolve(ctx);

            try
            {
                var evt = ctx.ResolveEvent(type, node.MemberName);
            //				node.Value = Expr.CastTransparent(node.Value, evt.EventHandlerType);
                return new EventNode(evt, node, _OperatorType == LexemType.Plus);
            }
            catch (KeyNotFoundException)
            {
                return null;
            }
        }
示例#7
0
        /// <summary>
        /// Expands short assignment to an expression member:
        /// (expr).x += 1
        /// or type::x += 1
        /// </summary>
        private NodeBase expandMember(Context ctx, SetMemberNode node)
        {
            // type::name += value
            if (node.StaticType != null)
            {
                return Expr.SetMember(
                    node.StaticType,
                    node.MemberName,
                    _AssignmentOperator(
                        Expr.GetMember(
                            node.StaticType,
                            node.MemberName
                        ),
                        node.Value
                    )
                );
            }

            // simple case: no need to cache expression
            if (node.Expression is SetIdentifierNode)
            {
                return Expr.SetMember(
                    node.Expression,
                    node.MemberName,
                    _AssignmentOperator(
                        Expr.GetMember(
                            node.Expression,
                            node.MemberName
                        ),
                        node.Value
                    )
                );
            }

            // (x + y).name += value
            // must cache (x + y) to a local variable to prevent double execution
            var tmpVar = ctx.Scope.DeclareImplicit(ctx, node.Expression.Resolve(ctx), false);
            return Expr.Block(
                Expr.Set(tmpVar, node.Expression),
                Expr.SetMember(
                    Expr.Get(tmpVar),
                    node.MemberName,
                    _AssignmentOperator(
                        Expr.GetMember(
                            Expr.Get(tmpVar),
                            node.MemberName
                        ),
                        node.Value
                    )
                )
            );
        }