Example #1
0
File: DDG.cs Project: xNUTs/PTVS
        public override bool Walk(AssignmentStatement node)
        {
            var valueType = _eval.Evaluate(node.Right);

            // For self assignments (e.g. "fob = fob"), include values from
            // outer scopes, otherwise such assignments will always be unknown
            // because we use the unassigned variable for the RHS.
            var ne = node.Right as NameExpression;
            InterpreterScope oldScope;

            if (ne != null &&
                (oldScope = _eval.Scope).OuterScope != null &&
                node.Left.OfType <NameExpression>().Any(n => n.Name == ne.Name))
            {
                try {
                    _eval.Scope = _eval.Scope.OuterScope;
                    valueType   = valueType.Union(_eval.Evaluate(node.Right));
                } finally {
                    _eval.Scope = oldScope;
                }
            }

            foreach (var left in node.Left)
            {
                _eval.AssignTo(node, left, valueType);
            }
            return(false);
        }
        internal static void WalkComprehension(ExpressionEvaluator ee, Comprehension comp, int start = 1)
        {
            foreach (var compFor in comp.Iterators.Skip(start).OfType <ComprehensionFor>())
            {
                var listTypes = ee.Evaluate(compFor.List);
                ee.AssignTo(comp, compFor.Left, listTypes.GetEnumeratorTypes(comp, ee._unit));
            }

            foreach (var compIf in comp.Iterators.OfType <ComprehensionIf>())
            {
                ee.EvaluateMaybeNull(compIf.Test);
            }
        }
Example #3
0
        public override bool Walk(AssignmentStatement node)
        {
            var valueType = _eval.Evaluate(node.Right);

            // For self assignments (e.g. "fob = fob"), include values from
            // outer scopes, otherwise such assignments will always be unknown
            // because we use the unassigned variable for the RHS.
            var ne = node.Right as NameExpression;
            InterpreterScope oldScope;

            if (ne != null &&
                (oldScope = _eval.Scope).OuterScope != null &&
                (node.Left.OfType <NameExpression>().Any(n => n.Name == ne.Name) ||
                 node.Left.OfType <ExpressionWithAnnotation>().Select(e => e.Expression).OfType <NameExpression>().Any(n => n.Name == ne.Name)))
            {
                try {
                    _eval.Scope = _eval.Scope.OuterScope;
                    valueType   = valueType.Union(_eval.Evaluate(node.Right));
                } finally {
                    _eval.Scope = oldScope;
                }
            }

            foreach (var left in node.Left)
            {
                if (left is ExpressionWithAnnotation annoExpr && annoExpr.Annotation != null)
                {
                    var annoType = _eval.EvaluateAnnotation(annoExpr.Annotation);
                    var annoInst = annoType?.GetInstanceType();
                    if (annoInst?.Any() == true)
                    {
                        _eval.AssignTo(node, annoExpr.Expression, annoInst);
                    }
                }

                _eval.AssignTo(node, left, valueType);
            }
            return(false);
        }