Exemple #1
0
        public static AbstractType[] Resolve(IdentifierDeclaration id, ResolutionContext ctxt, AbstractType[] resultBases = null, bool filterForTemplateArgs = true)
        {
            AbstractType[] res;

            if (id.InnerDeclaration == null && resultBases == null)
            {
                res = ResolveIdentifier(id.IdHash, ctxt, id, id.ModuleScoped);
            }
            else
            {
                var rbases = resultBases ?? Resolve(id.InnerDeclaration, ctxt);

                if (rbases == null || rbases.Length == 0)
                {
                    return(null);
                }

                res = ResolveFurtherTypeIdentifier(id.IdHash, rbases, ctxt, id);
            }

            if (filterForTemplateArgs && (ctxt.Options & ResolutionOptions.NoTemplateParameterDeduction) == 0)
            {
                var l_ = new List <AbstractType>();

                if (res != null)
                {
                    foreach (var s in res)
                    {
                        l_.Add(s);
                    }
                }

                return(TemplateInstanceHandler.DeduceParamsAndFilterOverloads(l_, null, false, ctxt));
            }
            else
            {
                return(res);
            }
        }
Exemple #2
0
        public static MemberSymbol[] TryResolveUFCS(
            ISemantic firstArgument,
            PostfixExpression_Access acc,
            ResolutionContext ctxt)
        {
            if (ctxt == null)
            {
                return(null);
            }

            int name = 0;

            if (acc.AccessExpression is IdentifierExpression)
            {
                name = ((IdentifierExpression)acc.AccessExpression).ValueStringHash;
            }
            else if (acc.AccessExpression is TemplateInstanceExpression)
            {
                name = ((TemplateInstanceExpression)acc.AccessExpression).TemplateIdHash;
            }
            else
            {
                return(null);
            }

            var methodMatches = new List <MemberSymbol>();

            if (ctxt.ParseCache != null)
            {
                foreach (var pc in ctxt.ParseCache)
                {
                    var tempResults = pc.UfcsCache.FindFitting(ctxt, acc.Location, firstArgument, name);

                    if (tempResults != null)
                    {
                        foreach (var m in tempResults)
                        {
                            ctxt.PushNewScope(m);

                            if (m.TemplateParameters != null && m.TemplateParameters.Length != 0)
                            {
                                var ov = TemplateInstanceHandler.DeduceParamsAndFilterOverloads(
                                    new[] { new MemberSymbol(m, null, acc) },
                                    new[] { firstArgument }, true, ctxt);

                                if (ov == null || ov.Length == 0)
                                {
                                    continue;
                                }

                                var ms = (DSymbol)ov[0];
                                ctxt.CurrentContext.IntroduceTemplateParameterTypes(ms);
                            }

                            var mr = TypeDeclarationResolver.HandleNodeMatch(m, ctxt, null, acc) as MemberSymbol;
                            if (mr != null)
                            {
                                mr.FirstArgument = firstArgument;
                                mr.DeducedTypes  = ctxt.CurrentContext.DeducedTemplateParameters.ToReadonly();
                                mr.IsUFCSResult  = true;
                                methodMatches.Add(mr);
                            }
                            ctxt.Pop();
                        }
                    }
                }
            }

            return(methodMatches.Count == 0 ? null : methodMatches.ToArray());
        }