////////////////////////////////////////////////////////////////////////// // Constructor ////////////////////////////////////////////////////////////////////////// public Slot(Type parent, string name, int flags, Facets facets, int lineNum) { this.m_parent = parent; this.m_name = name; this.m_qname = parent == null ? name : parent.qname() + "." + name; this.m_flags = flags; this.m_facets = facets; this.m_lineNum = lineNum; }
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(); }
void putCache(File file, Type t) { CachedScript c = new CachedScript(); c.modified = file.modified(); c.size = file.size(); c.typeName = t.qname(); lock (m_cache) { m_cache[cacheKey(file)] = c; } }
public static Service find(Type t, bool check) { return find(t.qname(), check); }
public static Service find(Type t) { return find(t.qname(), true); }
private void findMixins(Type t, Hashtable acc) { // if mixin I haven't seen add to accumulator string qname = t.qname(); if (t.isMixin() && acc[qname] == null) acc[qname] = t; // recurse for (int i=0; i<t.mixins().sz(); ++i) findMixins((Type)t.mixins().get(i), acc); }
void complexAdd(Type t, object obj, Method addMethod, object val, int line) { try { addMethod.invoke(obj, new object[] { val }); } catch (System.Exception ex) { throw err("Cannot call " + t.qname() + ".add: " + ex, line, ex); } }
protected static Enum doFromStr(Type t, string name, bool check) { // the compiler marks the value fields with the Enum flag Slot slot = t.slot(name, false); if (slot != null && (slot.m_flags & FConst.Enum) != 0) { try { return (Enum)((Field)slot).get(null); } catch (System.Exception) { } } if (!check) return null; throw ParseErr.make(t.qname(), name).val; }
/// <summary> /// simple := type "(" str ")" /// </summary> private object readSimple(int line, Type t) { // parse: type(str) consume(Token.LPAREN, "Expected ( in simple"); string str = consumeStr("Expected string literal for simple"); consume(Token.RPAREN, "Expected ) in simple"); // lookup the fromStr method t.finish(); Method m = t.method("fromStr", false); if (m == null) throw err("Missing method: " + t.qname() + ".fromStr", line); // invoke parse method to translate into instance try { return m.invoke(null, new object[] { str }); } catch (ParseErr.Val e) { throw ParseErr.make(e.err().msg() + " [Line " + line + "]").val; } catch (System.Exception e) { throw ParseErr.make(e.ToString() + " [Line " + line + "]", e).val; } }
void readComplexSet(Type t, int line, string name, Map toSet) { // resolve field Field field = t.field(name, false); if (field == null) throw err("Field not found: " + t.qname() + "." + name, line); // parse value object val = readObj(field, null, false); try { // if const field, then make val immutable if (field.isConst()) val = OpUtil.toImmutable(val); } catch (System.Exception ex) { throw err("Cannot make object const for " + field.qname() + ": " + ex, line, ex); } // add to map toSet.set(field, val); }
////////////////////////////////////////////////////////////////////////// // Complex ////////////////////////////////////////////////////////////////////////// /// <summary> /// complex := type [fields] /// fields := "{" field (eos field)* "}" /// field := name "=" obj /// </summary> private object readComplex(int line, Type t, bool root) { Map toSet = new Map(Sys.FieldType, Sys.ObjType.toNullable()); List toAdd = new List(Sys.ObjType.toNullable()); // read fields/collection into toSet/toAdd readComplexFields(t, toSet, toAdd); // get the make constructor Method makeCtor = t.method("make", false); if (makeCtor == null || !makeCtor.isPublic()) throw err("Missing public constructor " + t.qname() + ".make", line); // get argument lists List args = null; if (root && options != null) args = (List)options.get("makeArgs"); // construct object object obj = null; bool setAfterCtor = true; try { // if first parameter is an function then pass toSet // as an it-block for setting the fields Param p = (Param)makeCtor.@params().first(); if (args == null && p != null && p.type().fits(Sys.FuncType)) { args = new List(Sys.ObjType).add(Field.makeSetFunc(toSet)); setAfterCtor = false; } // invoke make to construct object obj = makeCtor.callList(args); } catch (System.Exception e) { throw err("Cannot make " + t + ": " + e, line, e); } // set fields (if not passed to ctor as it-block) if (setAfterCtor && toSet.size() > 0) { IDictionaryEnumerator en = toSet.pairsIterator(); while (en.MoveNext()) { complexSet(obj, (Field)en.Key, en.Value, line); } } // add if (toAdd.size() > 0) { Method addMethod = t.method("add", false); if (addMethod == null) throw err("Method not found: " + t.qname() + ".add", line); for (int i=0; i<toAdd.sz(); ++i) complexAdd(t, obj, addMethod, toAdd.get(i), line); } return obj; }
public Facet get(Type type, bool check) { object val = m_map[type]; if (val is Facet) return (Facet)val; if (val is string) { Facet f = decode(type, (string)val); m_map[type] = f; return f; } if (check) throw UnknownFacetErr.make(type.qname()).val; return null; }
////////////////////////////////////////////////////////////////////////// // Collection (@collection) ////////////////////////////////////////////////////////////////////////// private bool writeCollectionItems(Type type, object obj, bool first) { // lookup each method Method m = type.method("each", false); if (m == null) throw IOErr.make("Missing " + type.qname() + ".each").val; // call each(it) EachIterator it = new EachIterator(this, first); m.invoke(obj, new object[] { it }); return it.first; }