protected override IValue readValue(String name, Func <IValue> supplier) { ConcreteCategoryDeclaration decl = getDeclaration(); if (decl.hasAttribute(this, name)) { IValue value = instance.GetMemberValue(calling, name, false); return(value != null ? value : supplier.Invoke()); } else if (decl.hasMethod(this, name)) { IMethodDeclaration method = decl.getMemberMethods(this, name).GetFirst(); return(new ClosureValue(this, new MethodType(method))); } else { return(supplier.Invoke()); } }
public override IValue interpret(Context context) { CategoryDeclaration cd = context.getRegisteredDeclaration <CategoryDeclaration>(this.type.GetTypeName()); if (cd == null) { throw new SyntaxError("Unknown category " + this.type.GetTypeName()); } checkFirstHomonym(context, cd); IInstance instance = type.newInstance(context); instance.setMutable(true); try { if (copyFrom != null) { Object copyObj = copyFrom.interpret(context); if (copyObj is IInstance) { IInstance copyInstance = (IInstance)copyObj; foreach (String name in copyInstance.GetMemberNames()) { if (name == "dbId") { continue; } else if (cd.hasAttribute(context, name)) { IValue value = copyInstance.GetMemberValue(context, name, false); if (value != null && value.IsMutable() && !this.type.Mutable) { throw new NotMutableError(); } instance.SetMemberValue(context, name, value); } } } else if (copyObj is DocumentValue) { DocumentValue copyDoc = (DocumentValue)copyObj; foreach (String name in copyDoc.GetMemberNames()) { if (name == "dbId") { continue; } else if (cd.hasAttribute(context, name)) { IValue value = copyDoc.GetMemberValue(context, name, false); if (value != null && value.IsMutable() && !this.type.Mutable) { throw new NotMutableError(); } // TODO convert to attribute type, see Java version instance.SetMemberValue(context, name, value); } } } } if (arguments != null) { foreach (Argument argument in arguments) { IValue value = argument.getExpression().interpret(context); if (value != null && value.IsMutable() && !this.type.Mutable) { throw new NotMutableError(); } instance.SetMemberValue(context, argument.GetName(), value); } } } finally { instance.setMutable(this.type.Mutable); } return(instance); }
public override IValue GetMemberValue(Context context, String name, bool autoCreate) { makeInstance(context); return(instance.GetMemberValue(context, name, autoCreate)); }