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; }
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; } }
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; } }
ClassType newException(string name, State t) { return newClass(name, t, BaseException); }
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; }
ClassType newClass(string name, State table) { return newClass(name, table, null); }
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; }
public ModuleType CreateModule(string name, string file, string qName, State parent) { return Register(new ModuleType(name, file, qName, parent)); }
public void putAll(State other) { foreach (var de in other.table) { table.Add(de.Key, de.Value); } }
// 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; }
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; } } }
public void addSuper(State sup) { if (supers == null) { supers = new List<State>(); } supers.Add(sup); }
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); } }
public static DataType transformExpr(Analyzer analyzer, Exp n, State s) { return n.Accept(new TypeTransformer(s, analyzer)); }
public static State merge(State state1, State state2) { State ret = state1.Clone(); ret.Merge(state2); return ret; }