Checks a generic construction for several kinds of errors.
コード例 #1
0
ファイル: GenericsServices.cs プロジェクト: codehaus/boo
        /// <summary>
        /// Checks whether a given set of arguments can be used to construct a generic type or method from a specified definition.
        /// </summary>
        public bool CheckGenericConstruction(IEntity definition, Node node, TypeReferenceCollection arguments, CompilerErrorCollection errors)
        {
            GenericConstructionChecker checker = new GenericConstructionChecker(
                TypeSystemServices, node, arguments, Errors);

            return(!(
                       checker.NotGenericDefinition(definition) ||
                       checker.IncorrectGenerity(definition) ||
                       checker.ViolatesParameterConstraints(definition)));
        }
コード例 #2
0
ファイル: GenericsServices.cs プロジェクト: codehaus/boo
        /// <summary>
        /// Constructs generic entities out of an ambiguous definition.
        /// </summary>
        private IEntity ConstructAmbiguousEntity(Ambiguous ambiguousDefinition, Node constructionNode, TypeReferenceCollection argumentNodes)
        {
            GenericConstructionChecker checker = new GenericConstructionChecker(
                TypeSystemServices,
                constructionNode,
                argumentNodes,
                new CompilerErrorCollection());

            List <IEntity> matches = new List <IEntity>(ambiguousDefinition.Entities);

            // Filter matches by genericness, generity and constraints
            Predicate <IEntity>[] filters = new Predicate <IEntity>[] {
                checker.NotGenericDefinition,
                checker.IncorrectGenerity,
                checker.ViolatesParameterConstraints
            };

            foreach (Predicate <IEntity> filter in filters)
            {
                checker.Errors.Clear();
                matches.RemoveAll(filter);

                // If no matches pass the filter, record the first error only
                // (providing all the distinct errors that occured would be superfluous)
                if (matches.Count == 0)
                {
                    Errors.Add(checker.Errors[0]);
                    return(TypeSystemServices.ErrorEntity);
                }

                // If only one match passes the filter, continue construction normally
                if (matches.Count == 1)
                {
                    return(ConstructEntity(matches[0], constructionNode, argumentNodes));
                }
            }

            // Several matches have passed the filter -
            // construct all of them and return another Ambiguous entity
            IEntity[] constructed = Array.ConvertAll <IEntity, IEntity>(
                matches.ToArray(),
                delegate(IEntity def) { return(ConstructEntity(def, constructionNode, argumentNodes)); });

            return(new Ambiguous(constructed));
        }
コード例 #3
0
ファイル: GenericsServices.cs プロジェクト: boo/boo-lang
        /// <summary>
        /// Constructs generic entities out of an ambiguous definition.
        /// </summary>
        private IEntity ConstructAmbiguousEntity(Node constructionNode, Ambiguous ambiguousDefinition, IType[] typeArguments)
        {
            GenericConstructionChecker checker = new GenericConstructionChecker(
                TypeSystemServices,
                constructionNode,
                typeArguments,
                new CompilerErrorCollection());

            List<IEntity> matches = new List<IEntity>(ambiguousDefinition.Entities);

            // Filter matches by genericness, generity and constraints
            Predicate<IEntity>[] filters = new Predicate<IEntity>[] {
                checker.NotGenericDefinition,
                checker.IncorrectGenerity,
                checker.ViolatesParameterConstraints };

            foreach (Predicate<IEntity> filter in filters)
            {
                checker.Errors.Clear();
                matches.RemoveAll(filter);

                // If no matches pass the filter, record the first error only
                // (providing all the distinct errors that occured would be superfluous)
                if (matches.Count == 0)
                {
                    Errors.Add(checker.Errors[0]);
                    return TypeSystemServices.ErrorEntity;
                }

                // If only one match passes the filter, continue construction normally
                if (matches.Count == 1)
                {
                    return ConstructEntity(constructionNode, matches[0], typeArguments);
                }
            }

            // Several matches have passed the filter -
            // construct all of them and return another Ambiguous entity
            IEntity[] constructed = Array.ConvertAll<IEntity, IEntity>(
                matches.ToArray(),
                delegate(IEntity def) { return ConstructEntity(constructionNode, def, typeArguments); });

            return new Ambiguous(constructed);
        }
コード例 #4
0
ファイル: GenericsServices.cs プロジェクト: boo/boo-lang
        /// <summary>
        /// Checks whether a given set of arguments can be used to construct a generic type or method from a specified definition.
        /// </summary>
        public bool CheckGenericConstruction(Node node, IEntity definition, IType[] argumentTypes, CompilerErrorCollection errors)
        {
            GenericConstructionChecker checker = new GenericConstructionChecker(
                TypeSystemServices, node, argumentTypes, Errors);

            return !(
                checker.NotGenericDefinition(definition) ||
                checker.IncorrectGenerity(definition) ||
                checker.ViolatesParameterConstraints(definition));
        }
コード例 #5
0
ファイル: GenericsServices.cs プロジェクト: w4x/boolangstudio
        /// <summary>
        /// Checks whether a given set of arguments can be used to construct a generic type or method from a specified definition.
        /// </summary>
        public bool CheckGenericConstruction(IEntity definition, Node node, TypeReferenceCollection arguments, CompilerErrorCollection errors)
        {
            // Ensure definition is a valid entity
            if (definition == null || TypeSystemServices.IsError(definition))
            {
                return false;
            }

            // Ensure definition really is a generic definition
            GenericConstructionChecker checker = new GenericConstructionChecker(
                TypeSystemServices, node, arguments, Errors);

            return !(
                checker.NotGenericDefinition(definition) ||
                checker.IncorrectGenerity(definition) ||
                checker.ViolatesParameterConstraints(definition));
        }