Implements a scope, which maps names to sets of bindings.
Esempio n. 1
0
 public State(State s)
 {
     this.table = new Dictionary<string, ISet<Binding>>(s.table);
     this.Parent = s.Parent;
     this.stateType = s.stateType;
     this.Forwarding = s.Forwarding;
     this.supers = s.supers;
     this.globalNames = s.globalNames;
     this.Type = s.Type;
     this.Path = s.Path;
 }
Esempio n. 2
0
        private static ISet<State> looked = new HashSet<State>(); // circularity prevention

        #endregion Fields

        #region Constructors

        public State(State parent, StateType type)
        {
            this.Parent = parent;
            this.stateType = type;
            this.Path = "";

            if (type == StateType.CLASS)
            {
                this.Forwarding = parent == null ? null : parent.getForwarding();
            }
            else
            {
                this.Forwarding = this;
            }
        }
Esempio n. 3
0
 protected void createModuleType()
 {
     if (module == null)
     {
         module = outer.newModule(name);
         table = module.Table;
         outer.analyzer.ModuleTable.Insert(outer.analyzer, name, liburl(), module, BindingKind.MODULE).IsBuiltin = true;
     }
 }
Esempio n. 4
0
 ClassType newException(string name, State t)
 {
     return newClass(name, t, BaseException);
 }
Esempio n. 5
0
 ClassType newClass(string name, State table,
                    ClassType superClass, params ClassType[] moreSupers)
 {
     var path = table.extendPath(analyzer, name);
     ClassType t = new ClassType(name, table, path, superClass);
     foreach (ClassType c in moreSupers)
     {
         t.addSuper(c);
     }
     return t;
 }
Esempio n. 6
0
 ClassType newClass(string name, State table)
 {
     return newClass(name, table, null);
 }
Esempio n. 7
0
        public DataType LoadModule(List<Name> name, State state)
        {
            if (name.Count == 0)
            {
                return null;
            }

            string qname = MakeQname(name);
            DataType mt = getBuiltinModule(qname);
            if (mt != null)
            {
                state.Insert(
                        this,
                        name[0].Name,
                        new Url(Builtins.LIBRARY_URL + mt.Table.Path + ".html"),
                        mt, BindingKind.SCOPE);
                return mt;
            }

            // If there are more than one segment
            // load the packages first
            DataType prev = null;
            string startPath = locateModule(name[0].Name);

            if (startPath == null)
            {
                return null;
            }

            string path = startPath;
            for (int i = 0; i < name.Count; i++)
            {
                path = FileSystem.CombinePath(path, name[i].Name);
                string initFile = FileSystem.CombinePath(path, "__init__.py");
                if (FileSystem.FileExists(initFile))
                {
                    DataType mod = LoadFile(initFile);
                    if (mod == null)
                    {
                        return null;
                    }

                    if (prev != null)
                    {
                        prev.Table.Insert(this, name[i].Name, name[i], mod, BindingKind.VARIABLE);
                    }
                    else
                    {
                        state.Insert(this, name[i].Name, name[i], mod, BindingKind.VARIABLE);
                    }

                    prev = mod;

                }
                else if (i == name.Count - 1)
                {
                    string startFile = path + suffix;
                    if (FileSystem.FileExists( startFile))
                    {
                        DataType mod = LoadFile(startFile);
                        if (mod == null)
                        {
                            return null;
                        }
                        if (prev != null)
                        {
                            prev.Table.Insert(this, name[i].Name, name[i], mod, BindingKind.VARIABLE);
                        }
                        else
                        {
                            state.Insert(this, name[i].Name, name[i], mod, BindingKind.VARIABLE);
                        }
                        prev = mod;
                    }
                    else
                    {
                        return null;
                    }
                }
            }
            return prev;
        }
Esempio n. 8
0
 public ModuleType CreateModule(string name, string file, string qName, State parent)
 {
     return Register(new ModuleType(name, file, qName, parent));
 }
Esempio n. 9
0
 public void putAll(State other)
 {
     foreach (var de in other.table)
     {
         table.Add(de.Key, de.Value);
     }
 }
Esempio n. 10
0
 // erase and overwrite this to s's contents
 public void Overwrite(State s)
 {
     this.table = s.table;
     this.Parent = s.Parent;
     this.stateType = s.stateType;
     this.Forwarding = s.Forwarding;
     this.supers = s.supers;
     this.globalNames = s.globalNames;
     this.Type = s.Type;
     this.Path = s.Path;
 }
Esempio n. 11
0
        public void Merge(State other)
        {
            foreach (var e2 in other.table)
            {
                ISet<Binding> b1 = table[e2.Key];
                ISet<Binding> b2 = e2.Value;

                if (b1 != null && b2 != null)
                {
                    b1.UnionWith(b2);
                }
                else if (b1 == null && b2 != null)
                {
                    table[e2.Key] = b2;
                }
            }
        }
Esempio n. 12
0
 public void addSuper(State sup)
 {
     if (supers == null)
     {
         supers = new List<State>();
     }
     supers.Add(sup);
 }
Esempio n. 13
0
 public static void transformExprs(Analyzer analyzer, List<Slice> exprs, State s)
 {
     var x = new TypeTransformer(s, analyzer);
     foreach (var e in exprs)
     {
         e.Accept(x);
     }
 }
Esempio n. 14
0
 public static DataType transformExpr(Analyzer analyzer, Exp n, State s)
 {
     return n.Accept(new TypeTransformer(s, analyzer));
 }
Esempio n. 15
0
 public static State merge(State state1, State state2)
 {
     State ret = state1.Clone();
     ret.Merge(state2);
     return ret;
 }