Exemplo n.º 1
0
        private void ExtendAll(Node location, IPythonCollection values)
        {
            Eval.LookupNameInScopes(AllVariableName, out var scope, LookupOptions.Global);
            if (scope == null)
            {
                return;
            }

            var all    = scope.Variables[AllVariableName]?.Value as IPythonCollection;
            var list   = PythonCollectionType.CreateConcatenatedList(Module.Interpreter, all, values);
            var source = list.IsGeneric() ? VariableSource.Generic : VariableSource.Declaration;

            Eval.DeclareVariable(AllVariableName, list, source, location);
        }
Exemplo n.º 2
0
        private void HandleAllAppendExtend(CallExpression node)
        {
            if (!(node.Target is MemberExpression me))
            {
                return;
            }

            if (!IsHandleableAll(me.Target))
            {
                return;
            }

            if (node.Args.Count == 0)
            {
                return;
            }

            var arg = node.Args[0].Expression;
            var v   = Eval.GetValueFromExpression(arg);

            if (v == null)
            {
                _allIsUsable = false;
                return;
            }

            IPythonCollection values = null;

            switch (me.Name)
            {
            case "append":
                values = PythonCollectionType.CreateList(Module.Interpreter, Eval.GetLoc(arg), new List <IMember>()
                {
                    v
                }, exact: true);
                break;

            case "extend":
                values = v as IPythonCollection;
                break;
            }

            if (values == null)
            {
                _allIsUsable = false;
                return;
            }

            ExtendAll(node, values);
        }
Exemplo n.º 3
0
 public PythonIterator(IPythonType iteratorType, IPythonCollection collection) : base(iteratorType)
 {
     Collection = collection;
 }
Exemplo n.º 4
0
 public PythonIterator(BuiltinTypeId iteratorTypeId, IPythonCollection collection)
     : base(collection.Type.DeclaringModule.Interpreter.GetBuiltinType(iteratorTypeId))
 {
     Collection = collection;
 }
 public TypingIterator(TypingIteratorType iteratorType, IPythonCollection collection)
     : base(iteratorType.TypeId, collection)
 {
     _iteratorType = iteratorType;
 }