Inheritance: IEntity
Beispiel #1
0
        private IEntity[] FindExtension(IType fromType, string name)
        {
            IEntity extension = _context.NameResolutionService.ResolveExtension(fromType, name);

            if (null == extension)
            {
                return(Ambiguous.NoEntities);
            }

            Ambiguous a = extension as Ambiguous;

            if (null != a)
            {
                return(a.Entities);
            }
            return(new IEntity[] { extension });
        }
Beispiel #2
0
        /// <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));
        }
Beispiel #3
0
        public static IEntity GetEntityFromList(IList list)
        {
            IEntity element = null;

            if (list.Count > 0)
            {
                if (list.Count > 1)
                {
                    element = new Ambiguous(list);
                }
                else
                {
                    element = (IEntity)list[0];
                }
                list.Clear();
            }
            return(element);
        }
Beispiel #4
0
        private IEntity ResolveAmbiguousLValue(Expression sourceNode, Ambiguous candidates, Expression rvalue)
        {
            if (!candidates.AllEntitiesAre(EntityType.Property)) return null;

            IEntity[] entities = candidates.Entities;
            IEntity[] getters = GetSetMethods(entities);
            ExpressionCollection args = new ExpressionCollection();
            args.Add(rvalue);
            IEntity found = GetCorrectCallableReference(sourceNode, args, getters);
            if (null != found && EntityType.Method == found.EntityType)
            {
                IProperty property = (IProperty)entities[GetIndex(getters, found)];
                BindProperty(sourceNode, property);
                return property;
            }
            return null;
        }
Beispiel #5
0
        private IEntity ResolveCallableReference(MethodInvocationExpression node, Ambiguous entity)
        {
            IEntity resolved = CallableResolutionService.ResolveCallableReference(node.Arguments, entity.Entities);
            if (null == resolved)
                return null;

            IMember member = (IMember)resolved;
            if (NodeType.ReferenceExpression == node.Target.NodeType)
            {
                ResolveMemberInfo((ReferenceExpression)node.Target, member);
            }
            else
            {
                Bind(node.Target, member);
                BindExpressionType(node.Target, member.Type);
            }
            return resolved;
        }
Beispiel #6
0
 private List<IEntity> GetMatchesByGenericity(ReferenceExpression node, Ambiguous candidates)
 {
     bool isGenericReference = (node.ParentNode is GenericReferenceExpression);
     List<IEntity> matches = new List<IEntity>();
     foreach (IEntity candidate in candidates.Entities)
     {
         IType type = candidate as IType;
         bool isGenericType = (type != null && type.GenericInfo != null);
         if (isGenericType == isGenericReference)
         {
             matches.Add(candidate);
         }
     }
     return matches;
 }
Beispiel #7
0
 IEntity ResolveMacroExtensionType(MacroStatement node, Ambiguous extensions)
 {
     if (null == extensions)
         return null;
     foreach (var entity in extensions.Entities)
     {
         var extensionType = ResolveMacroExtensionType(node, entity as IMethod);
         if (null != extensionType)
             return extensionType;
     }
     return null;
 }
Beispiel #8
0
        /// <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);
        }
Beispiel #9
0
        private IEntity ResolveAmbiguousTypeReference(ReferenceExpression node, Ambiguous candidates)
        {
            List<IEntity> matches = GetMatchesByGenericity(node, candidates);
            if (matches.Count > 1)
            {
                PreferInternalEntitiesOverNonInternal(matches);
            }

            if (matches.Count == 1)
            {
                Bind(node, matches[0]);
            }
            else
            {
                Bind(node, new Ambiguous(matches));
            }

            return node.Entity;
        }
 public static IEntity GetEntityFromList(IList list)
 {
     IEntity element = null;
     if (list.Count > 0)
     {
         if (list.Count > 1)
         {
             element = new Ambiguous(list);
         }
         else
         {
             element = (IEntity)list[0];
         }
         list.Clear();
     }
     return element;
 }
Beispiel #11
0
 private IEntity ResolveAmbiguousMethodReference(ReferenceExpression node, Ambiguous candidates, ExpressionCollection args)
 {
     //BOO-656
     if (!AstUtil.IsTargetOfMethodInvocation(node)
         && !AstUtil.IsTargetOfSlicing(node)
         && !node.IsTargetOfAssignment())
     {
         return candidates.Entities[0];
     }
     return candidates;
 }
Beispiel #12
0
        private IEntity ResolveAmbiguousReference(ReferenceExpression node, Ambiguous candidates)
        {
            var resolved = ResolveAmbiguousReferenceByAccessibility(candidates);
            var accessibleCandidates = resolved as Ambiguous;

            if (accessibleCandidates == null || AstUtil.IsTargetOfSlicing(node) || node.IsTargetOfAssignment())
                return resolved;

            if (accessibleCandidates.AllEntitiesAre(EntityType.Property))
                return ResolveAmbiguousPropertyReference(node, accessibleCandidates, EmptyExpressionCollection);

            if (accessibleCandidates.AllEntitiesAre(EntityType.Method))
                return ResolveAmbiguousMethodReference(node, accessibleCandidates, EmptyExpressionCollection);

            if (accessibleCandidates.AllEntitiesAre(EntityType.Type))
                return ResolveAmbiguousTypeReference(node, accessibleCandidates);

            return resolved;
        }
        private IEntity ResolveAmbiguousTypeReference(ReferenceExpression node, Ambiguous candidates)
        {
            bool isGenericReference = (node.ParentNode is GenericReferenceExpression);

            List matches = new List();

            foreach (IEntity candidate in candidates.Entities)
            {
                IType type = candidate as IType;
                bool isGenericType = (type != null && type.GenericInfo != null);
                if (isGenericType == isGenericReference)
                {
                    matches.Add(candidate);
                }
            }

            if (matches.Count == 1)
            {
                Bind(node, (IEntity)matches[0]);
            }
            else
            {
                Bind(node, new Ambiguous(matches));
            }

            return node.Entity;
        }
        private IEntity ResolveAmbiguousReferenceByAccessibility(Ambiguous candidates)
        {
            List newEntities = new List();
            foreach (IEntity entity in candidates.Entities)
            {
                if (!IsInaccessible(entity))
                { newEntities.Add(entity); }
            }

            if (newEntities.Count == 1)
            { return (IEntity)newEntities[0]; }

            return new Ambiguous(newEntities);
        }
        private IEntity ResolveAmbiguousReference(ReferenceExpression node, Ambiguous candidates)
        {
            if (!AstUtil.IsTargetOfSlicing(node)
                && !AstUtil.IsLhsOfAssignment(node))
            {
                if (candidates.AllEntitiesAre(EntityType.Property))
                {
                    return ResolveAmbiguousPropertyReference(node, candidates, EmptyExpressionCollection);
                }
                else if (candidates.AllEntitiesAre(EntityType.Method))
                {
                    return ResolveAmbiguousMethodReference(node, candidates, EmptyExpressionCollection);
                    }
                else if (candidates.AllEntitiesAre(EntityType.Type))
                {
                    return ResolveAmbiguousTypeReference(node, candidates);
                }
            }

            return ResolveAmbiguousReferenceByAccessibility(candidates);
        }
        private IEntity ResolveAmbiguousExtension(MethodInvocationExpression node, Ambiguous ambiguous)
        {
            IEntity resolved = ResolveCallableReference(node, ambiguous);
            if (null != resolved) return resolved;

            return CantResolveAmbiguousMethodInvocation(node, ambiguous.Entities);
        }
        protected virtual IEntity ResolveAmbiguousMethodInvocation(MethodInvocationExpression node, Ambiguous entity)
        {
            _context.TraceVerbose("{0}: resolving ambigous method invocation: {1}", node.LexicalInfo, entity);

            IEntity resolved = ResolveCallableReference(node, entity);
            if (null != resolved) return resolved;

            if (TryToProcessAsExtensionInvocation(node)) return null;

            return CantResolveAmbiguousMethodInvocation(node, entity.Entities);
        }
Beispiel #18
0
        private IEntity ResolveAmbiguousPropertyReference(ReferenceExpression node, Ambiguous candidates, ExpressionCollection args)
        {
            IEntity[] entities = candidates.Entities;
            IEntity[] getters = GetGetMethods(entities);
            IEntity found = GetCorrectCallableReference(node, args, getters);
            if (null != found && EntityType.Method == found.EntityType)
            {
                IProperty property = (IProperty)entities[GetIndex(getters, found)];
                BindProperty(node, property);
                return property;
            }

            return candidates;
        }
Beispiel #19
0
 private IEntity AmbiguousReference(SimpleTypeReference node, Ambiguous entity)
 {
     _context.Errors.Add(CompilerErrorFactory.AmbiguousReference(node, node.Name, entity.Entities));
     return(TypeSystemServices.ErrorEntity);
 }
Beispiel #20
0
 private IEntity ResolveAmbiguousReferenceByAccessibility(Ambiguous candidates)
 {
     var newEntities = new List<IEntity>();
     foreach (IEntity entity in candidates.Entities)
         if (!IsInaccessible(entity))
             newEntities.Add(entity);
     return Entities.EntityFromList(newEntities);
 }
Beispiel #21
0
 private IEntity MapAmbiguousEntity(Ambiguous source)
 {
     // Map each individual entity in the ambiguous list
     return new Ambiguous(Array.ConvertAll<IEntity, IEntity>(source.Entities, Map));
 }
Beispiel #22
0
        private IEntity ResolveCallableReference(MethodInvocationExpression node, Ambiguous entity)
        {
            var genericService = My<GenericsServices>.Instance;
            var methods = entity.Entities
                .OfType<IMethod>()
                .Select(m => {
                    if (m.GenericInfo == null)
                        return m;

                    var inferrer = new GenericParameterInferrer(Context, m, node.Arguments);
                    inferrer.ResolveClosure += ProcessClosureInMethodInvocation;
                    if (!inferrer.Run())
                        return null;
                    var arguments = inferrer.GetInferredTypes();
                    if (arguments == null || !genericService.CheckGenericConstruction(m, arguments))
                        return null;
                    return m.GenericInfo.ConstructMethod(arguments);
                }).Where(m => m != null).ToArray();

            var resolved = CallableResolutionService.ResolveCallableReference(node.Arguments, methods);
            if (null == resolved)
                return null;

            IMember member = (IMember)resolved;
            if (NodeType.ReferenceExpression == node.Target.NodeType)
            {
                ResolveMemberInfo((ReferenceExpression)node.Target, member);
            }
            else
            {
                Bind(node.Target, member);
                BindExpressionType(node.Target, member.Type);
            }
            return resolved;
        }
 private IEntity AmbiguousReference(SimpleTypeReference node, Ambiguous entity)
 {
     _context.Errors.Add(CompilerErrorFactory.AmbiguousReference(node, node.Name, entity.Entities));
     return TypeSystemServices.ErrorEntity;
 }