TryBindOuter() приватный Метод

private TryBindOuter ( ScopeStatement from, PythonReference reference, PythonVariable &variable ) : bool
from ScopeStatement
reference PythonReference
variable PythonVariable
Результат bool
Пример #1
0
        internal override PythonVariable BindReference(PythonNameBinder binder, PythonReference reference)
        {
            PythonVariable variable;

            // First try variables local to this scope
            if (TryGetVariable(reference.Name, out variable))
            {
                if (variable.Kind == VariableKind.Global)
                {
                    AddReferencedGlobal(reference.Name);
                }
                return(variable);
            }

            // Try to bind in outer scopes
            for (ScopeStatement parent = Parent; parent != null; parent = parent.Parent)
            {
                if (parent.TryBindOuter(this, reference, out variable))
                {
                    return(variable);
                }
            }

            return(null);
        }
Пример #2
0
        internal override PythonVariable BindReference(PythonNameBinder binder, PythonReference reference)
        {
            PythonVariable variable;

            // Python semantics: The variables bound local in the class
            // scope are accessed by name - the dictionary behavior of classes
            if (TryGetVariable(reference.Name, out variable))
            {
                // TODO: This results in doing a dictionary lookup to get/set the local,
                // when it should probably be an uninitialized check / global lookup for gets
                // and a direct set
                if (variable.Kind == VariableKind.Global)
                {
                    AddReferencedGlobal(reference.Name);
                }
                else if (variable.Kind == VariableKind.Local)
                {
                    return(null);
                }

                return(variable);
            }

            // Try to bind in outer scopes, if we have an unqualified exec we need to leave the
            // variables as free for the same reason that locals are accessed by name.
            for (ScopeStatement parent = Parent; parent != null; parent = parent.Parent)
            {
                if (parent.TryBindOuter(this, reference, out variable))
                {
                    return(variable);
                }
            }

            return(null);
        }
Пример #3
0
        internal override PythonVariable BindReference(PythonNameBinder binder, PythonReference reference)
        {
            // First try variables local to this scope
            if (TryGetVariable(reference.Name, out PythonVariable variable))
            {
                if (variable.Kind == VariableKind.Global)
                {
                    AddReferencedGlobal(reference.Name);
                }
                Debug.Assert(variable.Kind != VariableKind.Nonlocal, "there should be no nonlocals in a comprehension");
                return(variable);
            }

            // then try to bind in outer scopes
            for (ScopeStatement parent = Parent; parent != null; parent = parent.Parent)
            {
                if (parent.TryBindOuter(this, reference, out variable))
                {
                    return(variable);
                }
            }

            return(null);
        }