Ejemplo n.º 1
0
        /// <summary>
        /// Expands short assignment to an array index:
        /// a[x] += 1
        /// </summary>
        private NodeBase ExpandIndex(Context ctx, SetIndexNode node)
        {
            var body = Expr.Block();

            // must cache expression?
            if (!(node.Expression is GetIdentifierNode))
            {
                var tmpExpr = ctx.Scope.DeclareImplicit(ctx, node.Expression.Resolve(ctx), false);
                body.Add(Expr.Set(tmpExpr, node.Expression));
                node.Expression = Expr.Get(tmpExpr);
            }

            // must cache index?
            if (!(node.Index is GetIdentifierNode || node.Index is ILiteralNode || node.Index.IsConstant))
            {
                var tmpIdx = ctx.Scope.DeclareImplicit(ctx, node.Index.Resolve(ctx), false);
                body.Add(Expr.Set(tmpIdx, node.Index));
                node.Index = Expr.Get(tmpIdx);
            }

            body.Add(
                Expr.SetIdx(
                    node.Expression,
                    node.Index,
                    _assignmentOperator(
                        Expr.GetIdx(
                            node.Expression,
                            node.Index
                            ),
                        node.Value
                        )
                    )
                );

            return(body);
        }
Ejemplo n.º 2
0
 protected bool Equals(SetIndexNode other)
 {
     return base.Equals(other) && Equals(Value, other.Value);
 }
Ejemplo n.º 3
0
 protected bool Equals(SetIndexNode other)
 {
     return(base.Equals(other) && Equals(Value, other.Value));
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Expands short assignment to an array index:
        /// a[x] += 1
        /// </summary>
        private NodeBase expandIndex(Context ctx, SetIndexNode node)
        {
            var body = Expr.Block();

            // must cache expression?
            if (!(node.Expression is GetIdentifierNode))
            {
                var tmpExpr = ctx.Scope.DeclareImplicit(ctx, node.Expression.Resolve(ctx), false);
                body.Add(Expr.Set(tmpExpr, node.Expression));
                node.Expression = Expr.Get(tmpExpr);
            }

            // must cache index?
            if (!(node.Index is GetIdentifierNode || node.Index is ILiteralNode || node.Index.IsConstant))
            {
                var tmpIdx = ctx.Scope.DeclareImplicit(ctx, node.Index.Resolve(ctx), false);
                body.Add(Expr.Set(tmpIdx, node.Index));
                node.Index = Expr.Get(tmpIdx);
            }

            body.Add(
                Expr.SetIdx(
                    node.Expression,
                    node.Index,
                    _AssignmentOperator(
                        Expr.GetIdx(
                            node.Expression,
                            node.Index
                        ),
                        node.Value
                    )
                )
            );

            return body;
        }