private static IAnalysisSet EvaluateListComprehension(ExpressionEvaluator ee, Node node)
        {
            if (ee._unit.State.LanguageVersion.Is2x())
            {
                // list comprehension is in enclosing scope in 2.x
                ListComprehension listComp = (ListComprehension)node;

                WalkComprehension(ee, listComp, start: 0);

                var listInfo = (ListInfo)ee.Scope.GetOrMakeNodeValue(
                    node,
                    NodeValueKind.ListComprehension,
                    (x) => new ListInfo(
                        VariableDef.EmptyArray,
                        ee._unit.State.ClassInfos[BuiltinTypeId.List],
                        node,
                        ee._unit.ProjectEntry
                        ).SelfSet);

                listInfo.AddTypes(ee._unit, new[] { ee.Evaluate(listComp.Item) });

                return(listInfo.SelfSet);
            }
            else
            {
                // list comprehension has its own scope in 3.x
                return(EvaluateComprehension(ee, node));
            }
        }
예제 #2
0
 public override void PostWalk(ListComprehension node)
 {
     if (_curUnit.State.LanguageVersion.Is3x())
     {
         Debug.Assert(_scope is ComprehensionScope);
         _scope = _scope.OuterScope;
     }
     base.PostWalk(node);
 }
        public override bool Walk(ListComprehension node)
        {
            if (_libraryMode)
            {
                return(false);
            }

            _stack.Enter(SymbolKind.None);
            return(base.Walk(node));
        }
예제 #4
0
        private static PythonNode Wrap(ListComprehension exp, PythonNode parent)
        {
            var result = new ListComprehensionNode(exp)
            {
                Parent = parent
            };

            result.AddChild(Wrap(exp.Item, result));
            exp.Iterators.ForEach(e => result.AddChild(Wrap(e, result)));
            return(result);
        }
예제 #5
0
        public CodeExpression VisitListComprehension(ListComprehension lc)
        {
            m.EnsureImport("System.Linq");
            var compFor = (CompFor)lc.Collection;
            var v       = lc.Projection.Accept(this);
            var c       = TranslateToLinq(v, compFor);

            return(m.Appl(
                       m.MethodRef(
                           c,
                           "ToList")));
        }
예제 #6
0
        public override bool Walk(ListComprehension node)
        {
            // List comprehension runs in a new scope in 3.x, runs in the same
            // scope in 2.x.  But these don't get their own analysis units
            // because they are still just expressions.
            if (_curUnit.State.LanguageVersion.Is3x())
            {
                EnsureComprehensionScope(node, MakeListComprehensionScope);
            }

            return(base.Walk(node));
        }
예제 #7
0
        public CodeExpression VisitListComprehension(ListComprehension lc)
        {
            var compFor = (CompFor)lc.Collection;
            var v       = compFor.variable.Accept(this);
            var c       = Translate(v, compFor);
            var mr      = new CodeMethodReferenceExpression(c, "Select");
            var s       = m.Appl(mr, new CodeExpression[] {
                m.Lambda(
                    new CodeExpression[] { v },
                    lc.Projection.Accept(this))
            });

            return(s);
        }
예제 #8
0
        // ListComp
        public override bool Walk(ListComprehension node)
        {
            BitArray save = _bits;

            _bits = new BitArray(_bits);

            foreach (ComprehensionIterator iter in node.Iterators)
            {
                iter.Walk(this);
            }
            node.Item.Walk(this);

            _bits = save;
            return(false);
        }
예제 #9
0
        private static ISet <Namespace> EvaluateListComprehension(ExpressionEvaluator ee, Node node)
        {
            ListComprehension listComp = (ListComprehension)node;

            for (int i = 0; i < listComp.Iterators.Count; i++)
            {
                ComprehensionFor compFor = listComp.Iterators[i] as ComprehensionFor;
                if (compFor != null)
                {
                    foreach (var listType in ee.Evaluate(compFor.List))
                    {
                        ee.AssignTo(node, compFor.Left, listType.GetEnumeratorTypes(node, ee._unit));
                    }
                }
            }

            return(ee.GlobalScope.GetOrMakeNodeVariable(
                       node,
                       (x) => new ListInfo(new [] { ee.Evaluate(listComp.Item) }, ee._unit.ProjectState._listType).SelfSet));
        }
예제 #10
0
 public void VisitListComprehension(ListComprehension lc)
 {
     throw new NotImplementedException();
 }
예제 #11
0
 private Unit MapUnitToExtGaps(Unit unit)
 {
     return(MapList(unit, (Seq seq) => ListComprehension(Gaps(ListExt(seq)), (int e) => (seq[0].Item1, seq[0].Item2, e))));
 }
예제 #12
0
 public override bool Walk(ListComprehension node)
 {
     ProcessComprehension(node, node.Item, node.Iterators);
     return(false);
 }
예제 #13
0
 // ListComprehension
 public override bool Walk(ListComprehension node)
 {
     return(false);
 }
예제 #14
0
 // ListComprehension
 public override bool Walk(ListComprehension node) { return false; }
예제 #15
0
 // ListComprehension
 public virtual bool Walk(ListComprehension node) { return true; }
예제 #16
0
 // ListComprehension
 public virtual bool Walk(ListComprehension node)
 {
     return(true);
 }
예제 #17
0
 public override void PostWalk(ListComprehension node) => ExitComprehension(node);
 public override bool Walk(ListComprehension node)
 {
     node.Walk(new ComprehensionWalker(_walker, _localNames, _localNameExpressions));
     return(false);
 }
예제 #19
0
 public override bool Walk(ListComprehension node)
 {
     _stack.Enter(SymbolKind.None);
     return(base.Walk(node));
 }
 public override void PostWalk(ListComprehension node)
 {
     PostWalkWorker(node);
 }
예제 #21
0
 public void VisitListComprehension(ListComprehension lc)
 {
     throw new NotImplementedException();
 }
예제 #22
0
 // ListComprehension
 public override bool Walk(ListComprehension node) { return Location >= node.StartIndex && Location <= node.EndIndex; }
예제 #23
0
 public override bool Walk(ListComprehension node)
 {
     BeginScope();
     return(base.Walk(node));
 }
예제 #24
0
 // ListComprehension
 public override bool Walk(ListComprehension node)
 {
     return(Location >= node.StartIndex && Location <= node.EndIndex);
 }
예제 #25
0
 private List <Inferred> InferListComp(ListComprehension node, Scope scope)
 {
     return(MakeList(module.InferType(typeof(IronPython.Runtime.List))));
 }
예제 #26
0
 public virtual void PostWalk(ListComprehension node)
 {
 }
예제 #27
0
 public void PostWalk(ListComprehension node)
 {
     PostProcess(node);
 }
예제 #28
0
 public override void PostWalk(ListComprehension node)
 {
 }
 // ListComprehension
 public override bool Walk(ListComprehension node)
 {
     return(ShouldWalkWorker(node));
 }
예제 #30
0
 public override void PostWalk(ListComprehension node) { }
예제 #31
0
 /// <remarks>
 /// Python's list comprehension will bind the variables used in generators.
 /// This will erase the original values of the variables even after the
 /// comprehension.
 /// </remarks>
 public DataType VisitListComprehension(ListComprehension l)
 {
     l.Collection.Accept(this);
     return(analyzer.TypeFactory.CreateList(l.Projection.Accept(this)));
 }
예제 #32
0
 public virtual void PostWalk(ListComprehension node) { }
예제 #33
0
 public override bool Walk(ListComprehension node)
 {
     return(UpdateLineInfo(node, true));
 }
예제 #34
0
 public override void PostWalk(ListComprehension node)
 {
     EndScope(false);
     Debug.Assert(_head != null);
     base.PostWalk(node);
 }
예제 #35
0
 // ListComprehension
 public bool Walk(ListComprehension node)
 {
     return(Process(node));
 }