public static List split(string self, Long separator, bool trim) { if (separator == null) { return(splitws(self)); } int sep = separator.intValue(); List toks = new List(Sys.StrType, 16); int len = self.Length; int x = 0; for (int i = 0; i < len; ++i) { if (self[i] != sep) { continue; } if (x <= i) { toks.add(splitStr(self, x, i, trim)); } x = i + 1; } if (x <= len) { toks.add(splitStr(self, x, len, trim)); } return(toks); }
public List toList() { int start = (int)m_start; int end = (int)m_end; List acc = new List(Sys.IntType); if (start < end) { if (m_exclusive) { --end; } acc.capacity(end - start + 1); for (int i = start; i <= end; ++i) { acc.add(Long.valueOf(i)); } } else { if (m_exclusive) { ++end; } acc.capacity(start - end + 1); for (int i = start; i >= end; --i) { acc.add(Long.valueOf(i)); } } return(acc); }
public override List inheritance() { if (m_inheritance == null) { Hashtable map = new Hashtable(); List acc = new List(Sys.TypeType); // handle Void as a special case if (this == Sys.VoidType) { acc.add(this); return(m_inheritance = acc.trim()); } // add myself map[m_qname] = this; acc.add(this); // add my direct inheritance inheritance addInheritance(@base(), acc, map); List m = mixins(); for (int i = 0; i < m.sz(); i++) { addInheritance((Type)m.get(i), acc, map); } m_inheritance = acc.trim().ro(); } return(m_inheritance); }
public static Version fromStr(string s, bool check) { List segments = new List(Sys.IntType, 4); int seg = -1; bool valid = true; int len = s.Length; for (int i = 0; i < len; ++i) { int c = s[i]; if (c == '.') { if (seg < 0 || i + 1 >= len) { valid = false; break; } segments.add(Long.valueOf(seg)); seg = -1; } else { if ('0' <= c && c <= '9') { if (seg < 0) { seg = c - '0'; } else { seg = seg * 10 + (c - '0'); } } else { valid = false; break; } } } if (seg >= 0) { segments.add(Long.valueOf(seg)); } if (!valid || segments.sz() == 0) { if (check) { throw ParseErr.make("Version", s).val; } else { return(null); } } return(new Version(segments)); }
protected void doReflect() { // ensure master type is reflected Type master = m_base; master.finish(); List masterSlots = master.slots(); // allocate slot data structures m_fields = new List(Sys.FieldType, master.fields().sz()); m_methods = new List(Sys.MethodType, master.methods().sz()); m_slots = new List(Sys.SlotType, masterSlots.sz()); m_slotsByName = new Hashtable(masterSlots.sz() * 3); // parameterize master's slots for (int i = 0; i < masterSlots.sz(); i++) { Slot slot = (Slot)masterSlots.get(i); if (slot is Method) { slot = parameterize((Method)slot); m_methods.add(slot); } else { slot = parameterize((Field)slot); m_fields.add(slot); } m_slots.add(slot); m_slotsByName[slot.m_name] = slot; } }
public static List list() { lock (m_podsByName) { // TODO - eventually we need a faster way to load // pod meta-data into memory without actually loading // every pod into memory if (m_allPodsList == null) { List names = Env.cur().findAllPodNames(); List pods = new List(Sys.PodType); for (int i = 0; i < names.sz(); ++i) { string name = (string)names.get(i); try { pods.add(doFind(name, true, null)); } catch (Exception e) { System.Console.WriteLine("ERROR: Invalid pod file: " + name); Err.dumpStack(e); } } m_allPodsList = pods.ro(); } return(m_allPodsList); } }
private static List loadDatabase() { InStream input = null; List quantityNames = new List(Sys.StrType); try { // parse etc/sys/units.fog as big serialized list which contains // lists for each quantity (first item being the name) String path = "etc/sys/units.txt"; input = Env.cur().findFile(path).@in(); // parse each line string curQuantityName = null; List curQuantityList = null; string line; while ((line = input.readLine()) != null) { // skip comment and blank lines line = line.Trim(); if (line.StartsWith("//") || line.Length == 0) { continue; } // quanity sections delimited as "-- name (dim)" if (line.StartsWith("--")) { if (curQuantityName != null) { m_quantities[curQuantityName] = curQuantityList.toImmutable(); } curQuantityName = line.Substring(2, line.IndexOf('(') - 2).Trim(); curQuantityList = new List(Sys.UnitType); quantityNames.add(curQuantityName); continue; } // must be a unit try { Unit unit = Unit.define(line); curQuantityList.add(unit); } catch (Exception e) { System.Console.WriteLine("WARNING: Init unit in etc/sys/units.txt: " + line); System.Console.WriteLine(" " + e); } } m_quantities[curQuantityName] = curQuantityList.toImmutable(); } catch (Exception e) { try { input.close(); } catch (Exception) {} System.Console.WriteLine("WARNING: Cannot load lib/units.txt"); Err.dumpStack(e); } return((List)quantityNames.toImmutable()); }
private Version version() { List segs = new List(Sys.IntType, 4); int seg = consumeDigit(); while (true) { if ('0' <= m_cur && m_cur <= '9') { seg = seg * 10 + consumeDigit(); } else { segs.add(Long.valueOf(seg)); seg = 0; if (m_cur != '.') { break; } else { consume(); } } } return(new Version(segs)); }
/// <summary> /// Parameterize the specified method (reuse if generic /// parameterization isn't necessary). /// </summary> internal Method parameterize(Method m) { // if not generic, short circuit and reuse original if (!m.isGenericMethod()) { return(m); } // new signature Func func = m.m_func; Type ret; List pars = new List(Sys.ParamType, m.m_params.sz()); // parameterize return type if (func.returns().isGenericParameter()) { ret = parameterize(func.returns()); } else { ret = func.returns(); } // narrow pars (or just reuse if not parameterized) for (int i = 0; i < m.m_params.sz(); i++) { Param p = (Param)m.m_params.get(i); if (p.m_type.isGenericParameter()) { pars.add(new Param(p.m_name, parameterize(p.m_type), p.m_mask)); } else { pars.add(p); } } Method pm = new Method(this, m.m_name, m.m_flags, m.m_facets, m.m_lineNum, ret, m.m_inheritedReturns, pars, m); pm.m_reflect = m.m_reflect; return(pm); }
public List union(List that) { int capacity = m_size + that.m_size; Hashtable dups = new Hashtable(capacity * 3); List acc = new List(m_of, capacity); bool hasNull = false; // first me for (int i = 0; i < m_size; i++) { object v = m_values[i]; if (v == null && !hasNull) { hasNull = true; acc.add(v); } else if (v != null && dups[v] == null) { dups[v] = this; acc.add(v); } } // then him for (int i = 0; i < that.m_size; i++) { object v = that.m_values[i]; if (v == null && !hasNull) { hasNull = true; acc.add(v); } else if (v != null && dups[v] == null) { dups[v] = this; acc.add(v); } } return(acc); }
public static Version fromStr(string s, bool check) { List segments = new List(Sys.IntType, 4); int seg = -1; bool valid = true; int len = s.Length; for (int i=0; i<len; ++i) { int c = s[i]; if (c == '.') { if (seg < 0 || i+1>=len) { valid = false; break; } segments.add(Long.valueOf(seg)); seg = -1; } else { if ('0' <= c && c <= '9') { if (seg < 0) seg = c-'0'; else seg = seg*10 + (c-'0'); } else { valid = false; break; } } } if (seg >= 0) segments.add(Long.valueOf(seg)); if (!valid || segments.sz() == 0) { if (check) throw ParseErr.make("Version", s).val; else return null; } return new Version(segments); }
public List exclude(Func f) { List acc = new List(m_of, m_size); for (int i = 0; i < m_size; i++) { if (f.call(m_values[i], i) == Boolean.False) { acc.add(m_values[i]); } } return(acc); }
public List intersection(List that) { // put other list into map Hashtable dups = new Hashtable(that.m_size * 3); bool hasNull = false; for (int i = 0; i < that.m_size; ++i) { object v = that.m_values[i]; if (v == null) { hasNull = true; } else { dups[v] = this; } } // now walk this list and accumulate // everything found in the dups map List acc = new List(m_of, m_size); for (int i = 0; i < m_size; i++) { object v = m_values[i]; if (v == null && hasNull) { acc.add(v); hasNull = false; } else if (v != null && dups[v] != null) { acc.add(v); dups.Remove(v); } } return(acc); }
public List unique() { Hashtable dups = new Hashtable(m_size * 3); List acc = new List(m_of, m_size); bool hasNull = false; for (int i = 0; i < m_size; i++) { object v = m_values[i]; if (v == null && !hasNull) { hasNull = true; acc.add(v); } else if (v != null && dups[v] == null) { dups[v] = this; acc.add(v); } } return(acc); }
public static List splitws(String val) { List toks = new List(Sys.StrType, 16); int len = val.Length; while (len > 0 && val[len - 1] <= ' ') { --len; } int x = 0; while (x < len && val[x] <= ' ') { ++x; } for (int i = x; i < len; ++i) { if (val[i] > ' ') { continue; } toks.add(val.Substring(x, i - x)); x = i + 1; while (x < len && val[x] <= ' ') { ++x; } i = x; } if (x <= len) { toks.add(val.Substring(x, len - x)); } if (toks.sz() == 0) { toks.add(""); } return(toks); }
public static List splitLines(string self) { List lines = new List(Sys.StrType, 16); int len = self.Length; int s = 0; for (int i = 0; i < len; ++i) { int c = self[i]; if (c == '\n' || c == '\r') { lines.add(self.Substring(s, i - s)); s = i + 1; if (c == '\r' && s < len && self[s] == '\n') { i++; s++; } } } lines.add(self.Substring(s, len - s)); return(lines); }
public List findType(Type t) { List acc = new List(t, m_size); for (int i = 0; i < m_size; i++) { object item = m_values[i]; if (item != null && @typeof(item).@is(t)) { acc.add(item); } } return(acc); }
////////////////////////////////////////////////////////////////////////// // Load ////////////////////////////////////////////////////////////////////////// internal void load(FPod fpod) { this.fpod = fpod; this.typesByName = new Hashtable(); // create a hollow Type for each FType (this requires two steps, // because we don't necessary have all the Types created for // superclasses until this loop completes) m_types = new ClassType[fpod.m_types.Length]; for (int i = 0; i < fpod.m_types.Length; i++) { // create type instance ClassType type = new ClassType(this, fpod.m_types[i]); // add to my data structures m_types[i] = type; if (typesByName[type.m_name] != null) { throw Err.make("Invalid pod: " + m_name + " type already defined: " + type.m_name).val; } typesByName[type.m_name] = type; } // get TypeType to use for mixin List (we need to handle case // when loading sys itself - and lookup within my own pod) Type typeType = Sys.TypeType; if (typeType == null) { typeType = (Type)typesByName["Type"]; } // now that everthing is mapped, we can fill in the super // class fields (unless something is wacked, this will only // use Types in my pod or in pods already loaded) for (int i = 0; i < fpod.m_types.Length; i++) { FType ftype = fpod.m_types[i]; ClassType type = m_types[i]; type.m_base = findType(ftype.m_base); List mixins = new List(typeType, ftype.m_mixins.Length); for (int j = 0; j < ftype.m_mixins.Length; j++) { mixins.add(findType(ftype.m_mixins[j])); } type.m_mixins = mixins.ro(); } }
public static List findAll(Type t) { string qname = t.qname(); List list = new List(Sys.ServiceType); lock (m_lock) { Node node = (Node)byType[qname]; while (node != null) { list.add(node.service); node = node.next; } } return list.ro(); }
public List list() { if (m_list == null) { m_list = new List(Sys.FacetType, m_map.Count); IDictionaryEnumerator en = ((Hashtable)m_map.Clone()).GetEnumerator(); while (en.MoveNext()) { Type type = (Type)en.Key; m_list.add(get(type, true)); } m_list = (List)m_list.toImmutable(); } return(m_list); }
public List map(Func f) { long start = m_start; long end = m_end; Type r = f.returns(); if (r == Sys.VoidType) { r = Sys.ObjType.toNullable(); } List acc = new List(r); if (start < end) { if (m_exclusive) { --end; } for (long i = start; i <= end; ++i) { acc.add(f.call(i)); } } else { if (m_exclusive) { ++end; } for (long i = start; i >= end; --i) { acc.add(f.call(i)); } } return(acc); }
private void doFlatten(List acc) { for (int i = 0; i < m_size; ++i) { object item = m_values[i]; if (item is List) { ((List)item).doFlatten(acc); } else { acc.add(item); } } }
public List map(Func f) { Type r = f.returns(); if (r == Sys.VoidType) { r = Sys.ObjType.toNullable(); } List acc = new List(r, (int)size()); for (int i = 0; i < m_size; i++) { acc.add(f.call(m_values[i], i)); } return(acc); }
public static List listFullNames() { List list = new List(Sys.StrType); for (int i = 0; i < indexNames.Length; ++i) { string prefix = prefixes[indexPrefixes[i] & 0xff]; string name = indexNames[i]; if (prefix.Length != 0) { name = prefix + "/" + name; } list.add(name); } return(list.ro()); }
public virtual List findAllPodNames() { List acc = new List(Sys.StrType); List files = findFile(Uri.fromStr("lib/fan/")).list(); for (int i = 0; i < files.sz(); ++i) { File f = (File)files.get(i); if (f.isDir() || "pod" != f.ext()) { continue; } acc.add(f.basename()); } return(acc); }
public static List findAll(Type t) { string qname = t.qname(); List list = new List(Sys.ServiceType); lock (m_lock) { Node node = (Node)byType[qname]; while (node != null) { list.add(node.service); node = node.next; } } return(list.ro()); }
/// <summary> /// Map fcode method to a sys::Method. /// </summary> private Method map(FPod fpod, FMethod m) { string name = String.Intern(m.m_name); Type returnType = m_pod.findType(m.m_ret); Type inheritedReturnType = m_pod.findType(m.m_inheritedRet); List pars = new List(Sys.ParamType, m.m_paramCount); for (int j = 0; j < m.m_paramCount; j++) { FMethodVar p = m.m_vars[j]; int pflags = (p.def == null) ? 0 : Param.HAS_DEFAULT; pars.add(new Param(String.Intern(p.name), m_pod.findType(p.type), pflags)); } Facets facets = Facets.mapFacets(m_pod, m.m_attrs.m_facets); return(new Method(this, name, m.m_flags, facets, m.m_attrs.m_lineNum, returnType, inheritedReturnType, pars)); }
public virtual List readAllLines() { try { List list = new List(Sys.StrType); string line; while ((line = readLine()) != null) { list.add(line); } return(list); } finally { try { close(); } catch (System.Exception e) { Err.dumpStack(e); } } }
private void addInheritance(Type t, List acc, Hashtable map) { if (t == null) { return; } List ti = t.inheritance(); for (int i = 0; i < ti.sz(); i++) { Type x = (Type)ti.get(i); if (map[x.qname()] == null) { map[x.qname()] = x; acc.add(x); } } }
public override List list(Regex pattern) { int len = 0; FileSystemInfo[] list = null; if (m_file is DirectoryInfo) { list = (m_file as DirectoryInfo).GetFileSystemInfos(); len = list.Length; } List acc = new List(Sys.FileType, len); for (int i = 0; i < len; i++) { FileSystemInfo f = list[i]; if (pattern != null && !pattern.matches(f.Name)) { continue; } string name = fileNameToUriName(f.Name); acc.add(new LocalFile(m_uri.plusName(name, f is DirectoryInfo), f)); } return(acc); }
public static List splitLines(string self) { List lines = new List(Sys.StrType, 16); int len = self.Length; int s = 0; for (int i=0; i<len; ++i) { int c = self[i]; if (c == '\n' || c == '\r') { lines.add(self.Substring(s, i-s)); s = i+1; if (c == '\r' && s < len && self[s] == '\n') { i++; s++; } } } lines.add(self.Substring(s, len-s)); return lines; }
private void doReflect() { // if the ftype is non-null, that means it was passed in non-hollow // ftype (in-memory compile), otherwise we need to read it from the pod if (m_ftype.m_hollow) { try { m_ftype.read(); } catch (IOException e) { Err.dumpStack(e); throw IOErr.make("Cannot read " + m_qname + " from pod", e).val; } } // these are working accumulators used to build the // data structures of my defined and inherited slots List slots = new List(Sys.SlotType, 64); Hashtable nameToSlot = new Hashtable(); // String -> Slot Hashtable nameToIndex = new Hashtable(); // String -> Long // merge in base class and mixin classes for (int i = 0; i < m_mixins.sz(); i++) { merge((Type)m_mixins.get(i), slots, nameToSlot, nameToIndex); } merge(m_base, slots, nameToSlot, nameToIndex); // merge in all my slots FPod fpod = this.m_pod.fpod; FType ftype = this.m_ftype; for (int i = 0; i < ftype.m_fields.Length; i++) { Field f = map(fpod, ftype.m_fields[i]); merge(f, slots, nameToSlot, nameToIndex); } for (int i = 0; i < ftype.m_methods.Length; i++) { Method m = map(fpod, ftype.m_methods[i]); merge(m, slots, nameToSlot, nameToIndex); } // break out into fields and methods List fields = new List(Sys.FieldType, slots.sz()); List methods = new List(Sys.MethodType, slots.sz()); for (int i = 0; i < slots.sz(); i++) { Slot slot = (Slot)slots.get(i); if (slot is Field) { fields.add(slot); } else { methods.add(slot); } } this.m_slots = slots.trim(); this.m_fields = fields.trim(); this.m_methods = methods.trim(); this.m_slotsByName = nameToSlot; this.m_facets = Facets.mapFacets(m_pod, ftype.m_attrs.m_facets); // facets this.m_lineNum = m_ftype.m_attrs.m_lineNum; this.m_sourceFile = m_ftype.m_attrs.m_sourceFile; }
public override List list() { int len = 0; FileSystemInfo[] list = null; if (m_file is DirectoryInfo) { list = (m_file as DirectoryInfo).GetFileSystemInfos(); len = list.Length; } List acc = new List(Sys.FileType, len); for (int i=0; i<len; i++) { FileSystemInfo f = list[i]; string name = fileNameToUriName(f.Name); acc.add(new LocalFile(m_uri.plusName(name, f is DirectoryInfo), f)); } return acc; }
public List intersection(List that) { // put other list into map Hashtable dups = new Hashtable(that.m_size*3); bool hasNull = false; for (int i=0; i<that.m_size; ++i) { object v = that.m_values[i]; if (v == null) hasNull = true; else dups[v] = this; } // now walk this list and accumulate // everything found in the dups map List acc = new List(m_of, m_size); for (int i=0; i<m_size; i++) { object v = m_values[i]; if (v == null && hasNull) { acc.add(v); hasNull = false; } else if (v != null && dups[v] != null) { acc.add(v); dups.Remove(v); } } return acc; }
public List findAll(Func f) { List acc = new List(m_of, m_size); for (int i=0; i<m_size; i++) if (f.call(m_values[i], i) == Boolean.True) acc.add(m_values[i]); return acc; }
public List unique() { Hashtable dups = new Hashtable(m_size*3); List acc = new List(m_of, m_size); bool hasNull = false; for (int i=0; i<m_size; i++) { object v = m_values[i]; if (v == null && !hasNull) { hasNull = true; acc.add(v); } else if (v != null && dups[v] == null) { dups[v] = this; acc.add(v); } } return acc; }
protected void doReflect() { // ensure master type is reflected Type master = m_base; master.finish(); List masterSlots = master.slots(); // allocate slot data structures m_fields = new List(Sys.FieldType, master.fields().sz()); m_methods = new List(Sys.MethodType, master.methods().sz()); m_slots = new List(Sys.SlotType, masterSlots.sz()); m_slotsByName = new Hashtable(masterSlots.sz()*3); // parameterize master's slots for (int i=0; i<masterSlots.sz(); i++) { Slot slot = (Slot)masterSlots.get(i); if (slot is Method) { slot = parameterize((Method)slot); m_methods.add(slot); } else { slot = parameterize((Field)slot); m_fields.add(slot); } m_slots.add(slot); m_slotsByName[slot.m_name] = slot; } }
/// <summary> /// Merge the inherited slot into my slot maps. Assume this slot /// trumps any previous definition (because we process inheritance /// and my slots in the right order) /// slots: Slot[] by order /// nameToSlot: String name -> Slot /// nameToIndex: String name -> Long index of slots /// </summary> private void merge(Slot slot, List slots, Hashtable nameToSlot, Hashtable nameToIndex) { // skip constructors which aren't mine if (slot.isCtor() && slot.m_parent != this) return; string name = slot.m_name; if (nameToIndex[name] != null) { int dup = (int)nameToIndex[name]; // if the slot is inherited from Obj, then we can // safely ignore it as an override - the dup is most // likely already the same Obj method inherited from // a mixin; but the dup might actually be a more specific // override in which case we definitely don't want to // override with the sys::Obj version if (slot.parent() == Sys.ObjType) return; // if given the choice between two *inherited* slots where // one is concrete and abstract, then choose the concrete one Slot dupSlot = (Slot)slots.get(dup); if (slot.parent() != this && slot.isAbstract() && !dupSlot.isAbstract()) return; // check if this is a Getter or Setter, in which case the Field // trumps and we need to cache the method on the Field // Note: this works because we assume the compiler always generates // the field before the getter and setter in fcode if ((slot.m_flags & (FConst.Getter|FConst.Setter)) != 0) { Field field = (Field)slots.get(dup); if ((slot.m_flags & FConst.Getter) != 0) field.m_getter = (Method)slot; else field.m_setter = (Method)slot; return; } nameToSlot[name] = slot; slots.set(dup, slot); } else { nameToSlot[name] = slot; slots.add(slot); nameToIndex[name] = slots.sz()-1; } }
/// <summary> /// Map fcode method to a sys::Method. /// </summary> private Method map(FPod fpod, FMethod m) { string name = String.Intern(m.m_name); Type returnType = m_pod.findType(m.m_ret); Type inheritedReturnType = m_pod.findType(m.m_inheritedRet); List pars = new List(Sys.ParamType, m.m_paramCount); for (int j=0; j<m.m_paramCount; j++) { FMethodVar p = m.m_vars[j]; int pflags = (p.def == null) ? 0 : Param.HAS_DEFAULT; pars.add(new Param(String.Intern(p.name), m_pod.findType(p.type), pflags)); } Facets facets = Facets.mapFacets(m_pod, m.m_attrs.m_facets); return new Method(this, name, m.m_flags, facets, m.m_attrs.m_lineNum, returnType, inheritedReturnType, pars); }
private void doReflect() { // if the ftype is non-null, that means it was passed in non-hollow // ftype (in-memory compile), otherwise we need to read it from the pod if (m_ftype.m_hollow) { try { m_ftype.read(); } catch (IOException e) { Err.dumpStack(e); throw IOErr.make("Cannot read " + m_qname + " from pod", e).val; } } // these are working accumulators used to build the // data structures of my defined and inherited slots List slots = new List(Sys.SlotType, 64); Hashtable nameToSlot = new Hashtable(); // String -> Slot Hashtable nameToIndex = new Hashtable(); // String -> Long // merge in base class and mixin classes for (int i=0; i<m_mixins.sz(); i++) merge((Type)m_mixins.get(i), slots, nameToSlot, nameToIndex); merge(m_base, slots, nameToSlot, nameToIndex); // merge in all my slots FPod fpod = this.m_pod.fpod; FType ftype = this.m_ftype; for (int i=0; i<ftype.m_fields.Length; i++) { Field f = map(fpod, ftype.m_fields[i]); merge(f, slots, nameToSlot, nameToIndex); } for (int i=0; i<ftype.m_methods.Length; i++) { Method m = map(fpod, ftype.m_methods[i]); merge(m, slots, nameToSlot, nameToIndex); } // break out into fields and methods List fields = new List(Sys.FieldType, slots.sz()); List methods = new List(Sys.MethodType, slots.sz()); for (int i=0; i<slots.sz(); i++) { Slot slot = (Slot)slots.get(i); if (slot is Field) fields.add(slot); else methods.add(slot); } this.m_slots = slots.trim(); this.m_fields = fields.trim(); this.m_methods = methods.trim(); this.m_slotsByName = nameToSlot; this.m_facets = Facets.mapFacets(m_pod, ftype.m_attrs.m_facets); // facets this.m_lineNum = m_ftype.m_attrs.m_lineNum; this.m_sourceFile = m_ftype.m_attrs.m_sourceFile; }
private void addInheritance(Type t, List acc, Hashtable map) { if (t == null) return; List ti = t.inheritance(); for (int i=0; i<ti.sz(); i++) { Type x = (Type)ti.get(i); if (map[x.qname()] == null) { map[x.qname()] = x; acc.add(x); } } }
public override List inheritance() { if (m_inheritance == null) { Hashtable map = new Hashtable(); List acc = new List(Sys.TypeType); // handle Void as a special case if (this == Sys.VoidType) { acc.add(this); return m_inheritance = acc.trim(); } // add myself map[m_qname] = this; acc.add(this); // add my direct inheritance inheritance addInheritance(@base(), acc, map); List m = mixins(); for (int i=0; i<m.sz(); i++) addInheritance((Type)m.get(i), acc, map); m_inheritance = acc.trim().ro(); } return m_inheritance; }
public static List makeAll(string str) { try { IPAddress[] addr = Dns.GetHostAddresses(str); List list = new List(Fan.Sys.Sys.ObjType, addr.Length); //IpAddr.$Type, addr.length); for (int i=0; i<addr.Length; i++) list.add(make(str, addr[i])); return list; } catch (SocketException e) { throw UnknownHostErr.make(e.Message).val; } }
public static List splitws(String val) { List toks = new List(Sys.StrType, 16); int len = val.Length; while (len > 0 && val[len-1] <= ' ') --len; int x = 0; while (x < len && val[x] <= ' ') ++x; for (int i=x; i<len; ++i) { if (val[i] > ' ') continue; toks.add(val.Substring(x, i-x)); x = i + 1; while (x < len && val[x] <= ' ') ++x; i = x; } if (x <= len) toks.add(val.Substring(x, len-x)); if (toks.sz() == 0) toks.add(""); return toks; }
/// <summary> /// Parameterize the specified method (reuse if generic /// parameterization isn't necessary). /// </summary> internal Method parameterize(Method m) { // if not generic, short circuit and reuse original if (!m.isGenericMethod()) return m; // new signature Func func = m.m_func; Type ret; List pars = new List(Sys.ParamType, m.m_params.sz()); // parameterize return type if (func.returns().isGenericParameter()) ret = parameterize(func.returns()); else ret = func.returns(); // narrow pars (or just reuse if not parameterized) for (int i=0; i<m.m_params.sz(); i++) { Param p = (Param)m.m_params.get(i); if (p.m_type.isGenericParameter()) { pars.add(new Param(p.m_name, parameterize(p.m_type), p.m_mask)); } else { pars.add(p); } } Method pm = new Method(this, m.m_name, m.m_flags, m.m_facets, m.m_lineNum, ret, m.m_inheritedReturns, pars, m); pm.m_reflect = m.m_reflect; return pm; }
private Version version() { List segs = new List(Sys.IntType, 4); int seg = consumeDigit(); while (true) { if ('0' <= m_cur && m_cur <= '9') { seg = seg*10 + consumeDigit(); } else { segs.add(Long.valueOf(seg)); seg = 0; if (m_cur != '.') break; else consume(); } } return new Version(segs); }
public List union(List that) { int capacity = m_size + that.m_size; Hashtable dups = new Hashtable(capacity*3); List acc = new List(m_of, capacity); bool hasNull = false; // first me for (int i=0; i<m_size; i++) { object v = m_values[i]; if (v == null && !hasNull) { hasNull = true; acc.add(v); } else if (v != null && dups[v] == null) { dups[v] = this; acc.add(v); } } // then him for (int i=0; i<that.m_size; i++) { object v = that.m_values[i]; if (v == null && !hasNull) { hasNull = true; acc.add(v); } else if (v != null && dups[v] == null) { dups[v] = this; acc.add(v); } } return acc; }
void readComplexAdd(Type t, int line, List toAdd) { object val = readObj(null, null, false); // add to list toAdd.add(val); }
private void doFlatten(List acc) { for (int i=0; i<m_size; ++i) { object item = m_values[i]; if (item is List) ((List)item).doFlatten(acc); else acc.add(item); } }
public static List list() { lock (m_podsByName) { // TODO - eventually we need a faster way to load // pod meta-data into memory without actually loading // every pod into memory if (m_allPodsList == null) { List names = Env.cur().findAllPodNames(); List pods = new List(Sys.PodType); for (int i=0; i<names.sz(); ++i) { string name = (string)names.get(i); try { pods.add(doFind(name, true, null)); } catch (Exception e) { System.Console.WriteLine("ERROR: Invalid pod file: " + name); Err.dumpStack(e); } } m_allPodsList = pods.ro(); } return m_allPodsList; } }
public List findType(Type t) { List acc = new List(t, m_size); for (int i=0; i<m_size; i++) { object item = m_values[i]; if (item != null && @typeof(item).@is(t)) acc.add(item); } return acc; }
private static List loadDatabase() { InStream input = null; List quantityNames = new List(Sys.StrType); try { // parse etc/sys/units.fog as big serialized list which contains // lists for each quantity (first item being the name) String path = "etc/sys/units.txt"; input = Env.cur().findFile(path).@in(); // parse each line string curQuantityName = null; List curQuantityList = null; string line; while ((line = input.readLine()) != null) { // skip comment and blank lines line = line.Trim(); if (line.StartsWith("//") || line.Length == 0) continue; // quanity sections delimited as "-- name (dim)" if (line.StartsWith("--")) { if (curQuantityName != null) m_quantities[curQuantityName] = curQuantityList.toImmutable(); curQuantityName = line.Substring(2, line.IndexOf('(')-2).Trim(); curQuantityList = new List(Sys.UnitType); quantityNames.add(curQuantityName); continue; } // must be a unit try { Unit unit = Unit.define(line); curQuantityList.add(unit); } catch (Exception e) { System.Console.WriteLine("WARNING: Init unit in etc/sys/units.txt: " + line); System.Console.WriteLine(" " + e); } } m_quantities[curQuantityName] = curQuantityList.toImmutable(); } catch (Exception e) { try { input.close(); } catch (Exception) {} System.Console.WriteLine("WARNING: Cannot load lib/units.txt"); Err.dumpStack(e); } return (List)quantityNames.toImmutable(); }
public List map(Func f) { Type r = f.returns(); if (r == Sys.VoidType) r = Sys.ObjType.toNullable(); List acc = new List(r, (int)size()); for (int i=0; i<m_size; i++) acc.add(f.call(m_values[i], i)); return acc; }
public static List listFullNames() { List list = new List(Sys.StrType); for (int i=0; i<indexNames.Length; ++i) { string prefix = prefixes[indexPrefixes[i] & 0xff]; string name = indexNames[i]; if (prefix.Length != 0) name = prefix + "/" + name; list.add(name); } return list.ro(); }
////////////////////////////////////////////////////////////////////////// // Load ////////////////////////////////////////////////////////////////////////// internal void load(FPod fpod) { this.fpod = fpod; this.typesByName = new Hashtable(); // create a hollow Type for each FType (this requires two steps, // because we don't necessary have all the Types created for // superclasses until this loop completes) m_types = new ClassType[fpod.m_types.Length]; for (int i=0; i<fpod.m_types.Length; i++) { // create type instance ClassType type = new ClassType(this, fpod.m_types[i]); // add to my data structures m_types[i] = type; if (typesByName[type.m_name] != null) throw Err.make("Invalid pod: " + m_name + " type already defined: " + type.m_name).val; typesByName[type.m_name] = type; } // get TypeType to use for mixin List (we need to handle case // when loading sys itself - and lookup within my own pod) Type typeType = Sys.TypeType; if (typeType == null) typeType = (Type)typesByName["Type"]; // now that everthing is mapped, we can fill in the super // class fields (unless something is wacked, this will only // use Types in my pod or in pods already loaded) for (int i=0; i<fpod.m_types.Length; i++) { FType ftype = fpod.m_types[i]; ClassType type = m_types[i]; type.m_base = findType(ftype.m_base); List mixins = new List(typeType, ftype.m_mixins.Length); for (int j=0; j<ftype.m_mixins.Length; j++) mixins.add(findType(ftype.m_mixins[j])); type.m_mixins = mixins.ro(); } }
/// <summary> /// Merge the inherited slot into my slot maps. Assume this slot /// trumps any previous definition (because we process inheritance /// and my slots in the right order) /// slots: Slot[] by order /// nameToSlot: String name -> Slot /// nameToIndex: String name -> Long index of slots /// </summary> private void merge(Slot slot, List slots, Hashtable nameToSlot, Hashtable nameToIndex) { // skip constructors which aren't mine if (slot.isCtor() && slot.m_parent != this) { return; } string name = slot.m_name; if (nameToIndex[name] != null) { int dup = (int)nameToIndex[name]; // if the slot is inherited from Obj, then we can // safely ignore it as an override - the dup is most // likely already the same Obj method inherited from // a mixin; but the dup might actually be a more specific // override in which case we definitely don't want to // override with the sys::Obj version if (slot.parent() == Sys.ObjType) { return; } // if given the choice between two *inherited* slots where // one is concrete and abstract, then choose the concrete one Slot dupSlot = (Slot)slots.get(dup); if (slot.parent() != this && slot.isAbstract() && !dupSlot.isAbstract()) { return; } // check if this is a Getter or Setter, in which case the Field // trumps and we need to cache the method on the Field // Note: this works because we assume the compiler always generates // the field before the getter and setter in fcode if ((slot.m_flags & (FConst.Getter | FConst.Setter)) != 0) { Field field = (Field)slots.get(dup); if ((slot.m_flags & FConst.Getter) != 0) { field.m_getter = (Method)slot; } else { field.m_setter = (Method)slot; } return; } nameToSlot[name] = slot; slots.set(dup, slot); } else { nameToSlot[name] = slot; slots.add(slot); nameToIndex[name] = slots.sz() - 1; } }
/// <summary> /// Return a map to use for Pod.files() /// </summary> public List podFiles(Fan.Sys.Uri podUri) { List list = new List(Sys.FileType); IEnumerator en = zipFile.GetEnumerator(); while (en.MoveNext()) { ZipEntry entry = (ZipEntry)en.Current; string name = entry.Name; if (name.EndsWith(".fcode")) continue; if (name.EndsWith(".class")) continue; if (name.EndsWith(".def") && !name.Contains("/")) continue; Fan.Sys.Uri uri = Fan.Sys.Uri.fromStr(podUri + "/" + LocalFile.fileNameToUriName(entry.Name)); Fan.Sys.ZipEntryFile file = new Fan.Sys.ZipEntryFile(zipFile, entry, uri); list.add(file); } return list; }
public static List split(string self, Long separator, bool trim) { if (separator == null) return splitws(self); int sep = separator.intValue(); List toks = new List(Sys.StrType, 16); int len = self.Length; int x = 0; for (int i=0; i<len; ++i) { if (self[i] != sep) continue; if (x <= i) toks.add(splitStr(self, x, i, trim)); x = i+1; } if (x <= len) toks.add(splitStr(self, x, len, trim)); return toks; }
public List list() { if (m_list == null) { m_list = new List(Sys.FacetType, m_map.Count); IDictionaryEnumerator en = ((Hashtable)m_map.Clone()).GetEnumerator(); while (en.MoveNext()) { Type type = (Type)en.Key; m_list.add(get(type, true)); } m_list = (List)m_list.toImmutable(); } return m_list; }
public List toList() { int start = (int)m_start; int end = (int)m_end; List acc = new List(Sys.IntType); if (start < end) { if (m_exclusive) --end; acc.capacity(end-start+1); for (int i=start; i<=end; ++i) acc.add(Long.valueOf(i)); } else { if (m_exclusive) ++end; acc.capacity(start-end+1); for (int i=start; i>=end; --i) acc.add(Long.valueOf(i)); } return acc; }