Example #1
0
 public virtual void VisitSetVariable(BoundSetVariable node)
 {
     DefaultVisit(node);
 }
            public override void VisitSetVariable(BoundSetVariable node)
            {
                base.VisitSetVariable(node);

                MarkWrite(node.Variable);
                _branch.MarkExpression(node.Value);
            }
Example #3
0
            public override BoundNode VisitSetVariable(BoundSetVariable node)
            {
                var variable = node.Variable;

                var temporary = variable as BoundTemporary;
                if (temporary != null)
                {
                    var statistic = _statistics[temporary];
                    if (statistic.WriteState == WriteType.Local)
                        variable = (IBoundWritable)((BoundGetVariable)statistic.Value.Expression).Variable;
                }

                return node.Update(
                    variable,
                    (BoundExpression)Visit(node.Value),
                    node.Location
                );
            }
Example #4
0
            public override void VisitSetVariable(BoundSetVariable node)
            {
                base.VisitSetVariable(node);

                // Bump the write count of the target.

                int writeCount;
                _variableWriteCount.TryGetValue(node.Variable, out writeCount);
                writeCount++;
                _variableWriteCount[node.Variable] = writeCount;

                // Update the statistic if the target is a temporary.

                var temporary = node.Variable as BoundTemporary;
                if (temporary != null)
                {
                    var statistic = GetStatistic(temporary);

                    if (statistic.WriteState == WriteType.Not)
                    {
                        // If we're reading from a local, we need to get the
                        // current write count for the local to check whether
                        // the value the temporary is receiving is going to be
                        // killed.
                        int localWriteCount = -1;
                        var getVariable = node.Value as BoundGetVariable;
                        BoundLocal local = null;
                        if (getVariable != null)
                        {
                            local = getVariable.Variable as BoundLocal;
                            if (local != null)
                                _variableWriteCount.TryGetValue(local, out localWriteCount);
                        }

                        statistic.Value = new ReadState(node.Value, localWriteCount);

                        statistic.WriteState = local != null
                            ? WriteType.Local
                            : WriteType.Expression;
                    }
                    else if (statistic.WriteState != WriteType.Local)
                    {
                        statistic.WriteState = WriteType.DoNotRemove;
                    }
                }
            }
Example #5
0
            public override void VisitSetVariable(BoundSetVariable node)
            {
                base.VisitSetVariable(node);

                _scope.MarkWrite(node.Variable, node.Value.ValueType);

                switch (node.Value.Kind)
                {
                    case BoundKind.NewBuiltIn:
                        _scope.SpeculateType(
                            node.Variable,
                            ((BoundNewBuiltIn)node.Value).NewBuiltInType == BoundNewBuiltInType.Array
                                ? SpeculatedType.Array
                                : SpeculatedType.Object,
                            true
                        );
                        break;

                    case BoundKind.New:
                        var getVariable = ((BoundNew)node.Value).Expression as BoundGetVariable;
                        var type = SpeculatedType.Object;

                        if (getVariable != null)
                        {
                            var @global = getVariable.Variable as BoundGlobal;
                            if (@global != null && @global.Name == "Array")
                                type = SpeculatedType.Array;
                        }

                        _scope.SpeculateType(
                            node.Variable,
                            type,
                            true
                        );
                        break;

                    case BoundKind.RegEx:
                        _scope.SpeculateType(node.Variable, SpeculatedType.Object, true);
                        break;

                    case BoundKind.Call:
                        var call = (BoundCall)node.Value;
                        getVariable = call.Method as BoundGetVariable;
                        if (getVariable != null)
                        {
                            var @global = getVariable.Variable as BoundGlobal;
                            if (@global != null && @global.Name == "Array")
                                _scope.SpeculateType(node.Variable, SpeculatedType.Array, true);
                        }
                        break;

                    case BoundKind.GetVariable:
                        getVariable = (BoundGetVariable)node.Value;
                        _scope.SpeculateType(node.Variable, getVariable.Variable);
                        break;

                    case BoundKind.ExpressionBlock:
                        var expressionBlock = (BoundExpressionBlock)node.Value;
                        _scope.SpeculateType(node.Variable, expressionBlock.Result);
                        break;

                    case BoundKind.CreateFunction:
                        _scope.SpeculateType(node.Variable, SpeculatedType.Object, true);
                        break;
                }
            }
Example #6
0
 private void EmitSetVariable(BoundSetVariable node)
 {
     EmitSetVariable(node.Variable, node.Value);
 }