Example #1
0
        public override Expression ResolveTypes(ParserContext context, VariableScope varScope)
        {
            // This might be a long chain of Namespace references.
            // Determine if this is a class name. Otherwise recurse down until one is.
            DotField     walker = this;
            List <Token> chain  = new List <Token>()
            {
                walker.FieldName
            };

            while (walker.Root is DotField)
            {
                chain.Add(((DotField)walker.Root).FieldName);
                walker = (DotField)walker.Root;
            }
            Variable deepestVariable = walker.Root as Variable;
            bool     isChain         = false;

            if (deepestVariable != null)
            {
                char c = deepestVariable.Name.Value[0];
                isChain = c >= 'A' && c <= 'Z'; // This is a lame optimization.
                chain.Add(deepestVariable.FirstToken);
                chain.Reverse();
            }

            if (isChain)
            {
                Expression newExpr = AttemptToResolveDotFieldChainIntoDirectReference(chain, context, this);
                if (newExpr != null)
                {
                    return(newExpr);
                }
            }

            this.Root = this.Root.ResolveTypes(context, varScope);

            if (this.Root.ResolvedType == null)
            {
                // should always be resolved by now.
                throw new System.InvalidOperationException();
            }

            ResolvedType           rootType = this.Root.ResolvedType;
            VerifiedFieldReference fieldRef = new VerifiedFieldReference(this.FirstToken, this.parent, this.FieldName, this.Root, null);

            fieldRef.TryResolveFieldReference(context, null, varScope);
            return(fieldRef);
        }