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

AddGlobalName() public method

public AddGlobalName ( string name ) : void
name string
return void
        public void AddGlobalName(string name)
        {
            if (globalNames == null)
            {
                globalNames = new HashSet<string>();
            }
            globalNames.Add(name);
        }

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);
        }