Ejemplo n.º 1
0
        protected override bool HandleItem(INode n)
        {
            if ((nameFilterHash != 0 && n.NameHash != nameFilterHash) || !(n.Parent is DModule))
            {
                return(false);
            }

            DVariable dv;
            var       dc = n as DClassLike;

            if (dc != null && dc.ClassType == DTokens.Template)
            {
                if (sr is TemplateInstanceExpression || nameFilterHash == 0)
                {
                    var templ = TypeDeclarationResolver.HandleNodeMatch(dc, ctxt, null, sr);
                    templ.Tag = new UfcsTag {
                        firstArgument = firstArgument
                    };
                    matches.Add(templ);
                }
            }
            else if (n is DMethod)
            {
                HandleMethod(n as DMethod);
            }
            else if ((dv = n as DVariable) != null && dv.IsAlias)
            {
                var t = TypeDeclarationResolver.HandleNodeMatch(n, ctxt, null, sr);

                var t_ = DResolver.StripAliasSymbol(t) as DSymbol;
                if (t_ != null)
                {
                    if (t_ is MemberSymbol && t_.Definition is DMethod)
                    {
                        HandleMethod(t_.Definition as DMethod, t_ as MemberSymbol);
                    }
                    else if (t_.Definition is DClassLike)
                    {
                        t_.Tag = new UfcsTag {
                            firstArgument = firstArgument
                        };
                        matches.Add(t_);
                    }
                    // Perhaps other types may occur here as well - but which remain then to be added?
                }
            }

            return(false);
        }
Ejemplo n.º 2
0
        public static AbstractType ResolveKey(ArrayDecl ad, out int fixedArrayLength, out ISymbolValue keyVal, ResolutionContext ctxt)
        {
            keyVal           = null;
            fixedArrayLength = -1;
            AbstractType keyType = null;

            if (ad.KeyExpression != null)
            {
                //TODO: Template instance expressions?
                var id_x = ad.KeyExpression as IdentifierExpression;
                if (id_x != null && id_x.IsIdentifier)
                {
                    var id = new IdentifierDeclaration((string)id_x.Value)
                    {
                        Location    = id_x.Location,
                        EndLocation = id_x.EndLocation
                    };

                    keyType = TypeDeclarationResolver.ResolveSingle(id, ctxt);

                    if (keyType != null)
                    {
                        var tt = DResolver.StripAliasSymbol(keyType) as MemberSymbol;

                        if (tt == null ||
                            !(tt.Definition is DVariable) ||
                            ((DVariable)tt.Definition).Initializer == null)
                        {
                            return(keyType);
                        }
                    }
                }

                try
                {
                    keyVal = Evaluation.EvaluateValue(ad.KeyExpression, ctxt);

                    if (keyVal != null)
                    {
                        // Take the value's type as array key type
                        keyType = keyVal.RepresentedType;

                        // It should be mostly a number only that points out how large the final array should be
                        var pv = Evaluation.GetVariableContents(keyVal, new StandardValueProvider(ctxt)) as PrimitiveValue;
                        if (pv != null)
                        {
                            fixedArrayLength = System.Convert.ToInt32(pv.Value);

                            if (fixedArrayLength < 0)
                            {
                                ctxt.LogError(ad, "Invalid array size: Length value must be greater than 0");
                            }
                        }
                        //TODO Is there any other type of value allowed?
                    }
                }
                catch { }
            }
            else
            {
                var t = Resolve(ad.KeyType, ctxt);
                ctxt.CheckForSingleResult(t, ad.KeyType);

                if (t != null && t.Length != 0)
                {
                    return(t[0]);
                }
            }

            return(keyType);
        }