/// <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); }
protected bool Equals(SetIndexNode other) { return base.Equals(other) && Equals(Value, other.Value); }
protected bool Equals(SetIndexNode other) { return(base.Equals(other) && Equals(Value, other.Value)); }
/// <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; }