示例#1
0
 public IType checkAttribute(Context context, CategoryDeclaration decl, String name)
 {
     if (decl.Storable && "dbId" == name)
     {
         return(AnyType.Instance);
     }
     else if (decl.hasAttribute(context, name))
     {
         AttributeDeclaration ad = context.getRegisteredDeclaration <AttributeDeclaration>(name);
         if (ad == null)
         {
             throw new SyntaxError("Unknown atttribute:" + name);
         }
         else
         {
             return(ad.GetIType(context));
         }
     }
     else if ("text" == name)
     {
         return(TextType.Instance);
     }
     else if (decl.hasMethod(context, name))
     {
         IMethodDeclaration method = decl.getMemberMethods(context, name).GetFirst();
         return(new MethodType(method));
     }
     else
     {
         throw new SyntaxError("No attribute:" + name + " in category:" + GetTypeName());
     }
 }
示例#2
0
        public override IValue interpretReference(Context context)
        {
            // resolve parent to keep clarity
            IExpression parent   = resolveParent(context);
            IValue      instance = parent.interpret(context);

            if (instance == null || instance == NullValue.Instance)
            {
                throw new NullReferenceError();
            }
            else if (instance is IInstance)
            {
                CategoryDeclaration  category = ((IInstance)instance).getDeclaration();
                MethodDeclarationMap methods  = category.getMemberMethods(context, name);
                IMethodDeclaration   method   = methods.GetFirst();             // TODO check prototype
                return(new ClosureValue(context.newInstanceContext((IInstance)instance, true), new MethodType(method)));
            }
            else
            {
                throw new SyntaxError("Should never get here!");
            }
        }