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

Lookup() public method

Look up a name in the current symbol table. If not found, recurse on the parent table.
public Lookup ( string name ) : ISet
name string
return ISet
        public ISet<Binding> Lookup(string name)
        {
            ISet<Binding> b = getModuleBindingIfGlobal(name);
            if (b != null)
            {
                return b;
            }
            ISet<Binding> ent = LookupLocal(name);
            if (ent != null)
            {
                return ent;
            }
            else if (Parent != null)
            {
                return Parent.Lookup(name);
            }
            else
            {
                return null;
            }
        }

Usage Example

Beispiel #1
0
        public DataType VisitSuite(SuiteStatement b)
        {
            // first pass: mark global names
            var globalNames = b.stmts
                              .OfType <GlobalStatement>()
                              .SelectMany(g => g.names)
                              .Concat(b.stmts
                                      .OfType <NonlocalStatement>()
                                      .SelectMany(g => g.names));

            foreach (var id in globalNames)
            {
                scope.AddGlobalName(id.Name);
                ISet <Binding> nb = scope.Lookup(id.Name);
                if (nb != null)
                {
                    analyzer.putRef(id, nb);
                }
            }

            bool     returned = false;
            DataType retType  = DataType.Unknown;

            foreach (var n in b.stmts)
            {
                DataType t = n.Accept(this);
                if (!returned)
                {
                    retType = UnionType.Union(retType, t);
                    if (!UnionType.Contains(t, DataType.Cont))
                    {
                        returned = true;
                        retType  = UnionType.remove(retType, DataType.Cont);
                    }
                }
            }
            return(retType);
        }