Pytocs.TypeInference.State.BindIterator C# (CSharp) Method

BindIterator() public method

public BindIterator ( Analyzer analyzer, Exp target, Exp iter, DataType iterType, BindingKind kind ) : void
analyzer Analyzer
target Exp
iter Exp
iterType DataType
kind BindingKind
return void
        public void BindIterator(Analyzer analyzer, Exp target, Exp iter, DataType iterType, BindingKind kind)
        {
            if (iterType is ListType)
            {
                this.Bind(analyzer, target, ((ListType) iterType).eltType, kind);
            }
            else if (iterType is TupleType)
            {
                this.Bind(analyzer, target, ((TupleType) iterType).toListType().eltType, kind);
            }
            else
            {
                ISet<Binding> ents = iterType.Table.LookupAttribute("__iter__");
                if (ents != null)
                {
                    foreach (Binding ent in ents)
                    {
                        if (ent == null || !(ent.type is FunType))
                        {
                            if (!iterType.isUnknownType())
                            {
                                analyzer.putProblem(iter, "not an iterable type: " + iterType);
                            }
                            this.Bind(analyzer, target, DataType.Unknown, kind);
                        }
                        else
                        {
                            this.Bind(analyzer, target, ((FunType) ent.type).getReturnType(), kind);
                        }
                    }
                }
                else
                {
                    this.Bind(analyzer, target, DataType.Unknown, kind);
                }
            }
        }

Usage Example

Beispiel #1
0
        public DataType VisitCompFor(CompFor f)
        {
            var it = f.variable.Accept(this);

            scope.BindIterator(analyzer, f.variable, f.collection, it, BindingKind.SCOPE);
            //f.visit(node.ifs, s);
            return(f.variable.Accept(this));
        }