コード例 #1
0
        protected override void VisitMemberAccessSyntax(MemberAccessSyntax pNode)
        {
            Visit(pNode.Identifier);

            //Save current local definitions
            //Mark the current type we are on so error messages can be more descriptive
            var l = _locals;

            using (var t = Store.AddValue("__Type", pNode.Identifier.Type))
            {
                //If field doesn't exist or something went wrong, stop checking things to reduce redundant errors
                if (CurrentType != SmallTypeCache.Undefined)
                {
                    //For methods and arrays we need to allow existing variables, but member access should only allow the struct's fields
                    if (NeedToCopyLocals(pNode.Value))
                    {
                        _locals = _locals.Copy();
                    }
                    else
                    {
                        _locals = new ScopeCache <LocalDefinition>();
                    }

                    //Namespaces return a null type
                    if (CurrentType != null)
                    {
                        _locals.AddScope();
                        foreach (var f in CurrentType.GetFields())
                        {
                            if (!_locals.IsVariableDefinedInScope(f.Name))
                            {
                                _locals.DefineVariableInScope(f.Name, LocalDefinition.Create(false, f.Type));
                            }
                        }
                    }

                    Visit(pNode.Value);
                }
            }

            //Restore local definitions
            Namespace = null;
            _locals   = l;
        }