private static object doTrap(object self, string name, List args, Type type) { Slot slot = type.slot(name, true); if (slot is Method) { Method m = (Method)slot; return(m.m_func.callOn(self, args)); } else { Field f = (Field)slot; int argSize = (args == null) ? 0 : args.sz(); if (argSize == 0) { return(FanUtil.box(f.get(self))); } if (argSize == 1) { object val = args.get(0); f.set(self, val); return(FanUtil.box(val)); } throw ArgErr.make("Invalid number of args to get or set field '" + name + "'").val; } }
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; }
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; }
public static Slot find(string qname, bool check) { string typeName, slotName; try { int dot = qname.IndexOf('.'); typeName = qname.Substring(0, dot); slotName = qname.Substring(dot + 1); } catch (Exception) { throw Err.make("Invalid slot qname \"" + qname + "\", use <pod>::<type>.<slot>").val; } Type type = Type.find(typeName, check); if (type == null) { return(null); } return(type.slot(slotName, check)); }
/// <summary> /// typeLiteral := type "#" /// slotLiteral := type "#" id /// </summary> private object readTypeOrSlotLiteral(int line, Type t) { consume(Token.POUND, "Expected '#' for type literal"); if (curt == Token.ID && !isEndOfStmt(line)) { string slotName = consumeId("slot literal name"); return t.slot(slotName); } else { return t; } }
private static object doTrap(object self, string name, List args, Type type) { Slot slot = type.slot(name, true); if (slot is Method) { Method m = (Method)slot; return m.m_func.callOn(self, args); } else { Field f = (Field)slot; int argSize = (args == null) ? 0 : args.sz(); if (argSize == 0) { return FanUtil.box(f.get(self)); } if (argSize == 1) { object val = args.get(0); f.set(self, val); return FanUtil.box(val); } throw ArgErr.make("Invalid number of args to get or set field '" + name + "'").val; } }