Esempio n. 1
0
        private MethodCall buildMethodCall(String methodName)
        {
            IExpression  exp  = new ValueExpression(type, type.newInstance(context));
            Argument     arg  = new Argument(null, exp);
            ArgumentList args = new ArgumentList();

            args.Add(arg);
            return(new MethodCall(new MethodSelector(methodName), args));
        }
Esempio n. 2
0
 protected virtual IValue getCurrent()
 {
     try
     {
         IStored      stored = enumerator.Current;
         CategoryType type   = ReadItemType(stored);
         return(type.newInstance(context, stored));
     } catch (PromptoError e) {
         throw new Exception(e.Message);
     }
 }
Esempio n. 3
0
        public override IValue interpret(Context context)
        {
            IStore  store  = DataStore.Instance;
            IQuery  query  = buildFetchOneQuery(context, store);
            IStored stored = store.FetchOne(query);

            if (stored == null)
            {
                return(NullValue.Instance);
            }
            else
            {
                List <String> categories     = (List <String>)stored.GetData("category");
                String        actualTypeName = categories.FindLast((v) => true);
                CategoryType  type           = new CategoryType(actualTypeName);
                if (this.type != null)
                {
                    type.Mutable = this.type.Mutable;
                }
                return(type.newInstance(context, stored));
            }
        }
Esempio n. 4
0
        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);
        }