Exemple #1
0
        public IMember LookupNameInScopes(string name, out IScope scope, LookupOptions options)
        {
            var scopes = CurrentScope.ToChainTowardsGlobal().ToList();

            if (scopes.Count == 1)
            {
                if (!options.HasFlag(LookupOptions.Local) && !options.HasFlag(LookupOptions.Global))
                {
                    scopes.Clear();
                }
            }
            else if (scopes.Count >= 2)
            {
                if (!options.HasFlag(LookupOptions.Nonlocal))
                {
                    while (scopes.Count > 2)
                    {
                        scopes.RemoveAt(1);
                    }
                }

                if (!options.HasFlag(LookupOptions.Local))
                {
                    scopes.RemoveAt(0);
                }

                if (!options.HasFlag(LookupOptions.Global))
                {
                    scopes.RemoveAt(scopes.Count - 1);
                }
            }

            scope = scopes.FirstOrDefault(s => s.Variables.Contains(name));
            var value = scope?.Variables[name].Value;

            if (value == null)
            {
                if (Module != Interpreter.ModuleResolution.BuiltinsModule && options.HasFlag(LookupOptions.Builtins))
                {
                    value = Interpreter.ModuleResolution.BuiltinsModule.GetMember(name);
                }
            }

            return(value);
        }