コード例 #1
0
        public override IType check(Context context)
        {
            CategoryDeclaration cd = context.getRegisteredDeclaration <CategoryDeclaration>(this.type.GetTypeName());

            if (cd == null)
            {
                throw new SyntaxError("Unknown category " + this.type.GetTypeName());
            }
            checkFirstHomonym(context, cd);
            cd.checkConstructorContext(context);
            if (copyFrom != null)
            {
                IType cft = copyFrom.check(context);
                if (!(cft is CategoryType) && (cft != DocumentType.Instance))
                {
                    throw new SyntaxError("Cannot copy from " + cft.GetTypeName());
                }
            }
            if (arguments != null)
            {
                foreach (Argument argument in arguments)
                {
                    if (!cd.hasAttribute(context, argument.GetName()))
                    {
                        throw new SyntaxError("\"" + argument.GetName() +
                                              "\" is not an attribute of " + type.GetTypeName());
                    }
                    argument.check(context);
                }
            }
            return(((CategoryType)cd.GetIType(context)).AsMutable(context, type.Mutable));
        }
コード例 #2
0
        public override IType check(Context context)
        {
            if (!(predicate is IPredicateExpression))
            {
                throw new SyntaxError("Filtering expression must be a predicate !");
            }
            if (type != null)
            {
                CategoryDeclaration decl = context.getRegisteredDeclaration <CategoryDeclaration>(type.GetTypeName());
                if (decl == null)
                {
                    throw new SyntaxError("Unknown category: " + type.GetTypeName().ToString());
                }
                context = context.newInstanceContext((CategoryType)decl.GetIType(context), true);
            }
            IType filterType = predicate.check(context);

            if (filterType != BooleanType.Instance)
            {
                throw new SyntaxError("Filtering expression must return a boolean !");
            }
            if (include != null)
            {
                foreach (string name in include)
                {
                    if (context.getRegisteredDeclaration <AttributeDeclaration>(name) == null)
                    {
                        throw new SyntaxError("Unknown attribute: " + name);
                    }
                }
            }
            if (type != null)
            {
                return(type);
            }
            else
            {
                return(AnyType.Instance);
            }
        }