internal override PythonVariable BindReference(PythonNameBinder binder, string name)
        {
            // First try variables local to this scope
            if (TryGetVariable(name, out var variable) && variable.Kind != VariableKind.Nonlocal)
            {
                if (variable.Kind == VariableKind.Global)
                {
                    AddReferencedGlobal(name);
                }
                return(variable);
            }

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

            return(null);
        }
Exemplo n.º 2
0
 internal override PythonVariable BindReference(PythonNameBinder binder, string name) => EnsureVariable(name);
Exemplo n.º 3
0
 internal override void FinishBind(PythonNameBinder binder)
 {
 }
 internal override void Bind(PythonNameBinder binder)
 {
     base.Bind(binder);
     Verify(binder);
 }
Exemplo n.º 5
0
        internal virtual void FinishBind(PythonNameBinder binder)
        {
            List <ClosureInfo> closureVariables = null;

            if (_nonLocalVars != null)
            {
                foreach (var variableName in _nonLocalVars)
                {
                    var bound = false;
                    for (var parent = Parent; parent != null; parent = parent.Parent)
                    {
                        if (parent.TryBindOuter(this, variableName.Name, false, out var variable))
                        {
                            bound = !variable.IsGlobal;
                            break;
                        }
                    }

                    if (!bound)
                    {
                        binder.ReportSyntaxError("no binding for nonlocal '{0}' found".FormatUI(variableName.Name), variableName);
                    }
                }
            }

            if (FreeVariables != null && FreeVariables.Count > 0)
            {
                closureVariables = new List <ClosureInfo>();

                foreach (var variable in FreeVariables)
                {
                    closureVariables.Add(new ClosureInfo(variable, !(this is ClassDefinition)));
                }
            }

            if (Variables != null && Variables.Count > 0)
            {
                if (closureVariables == null)
                {
                    closureVariables = new List <ClosureInfo>();
                }

                foreach (var variable in Variables.Values)
                {
                    if (!HasClosureVariable(closureVariables, variable) &&
                        !variable.IsGlobal && (variable.AccessedInNestedScope || ExposesLocalVariable(variable)))
                    {
                        closureVariables.Add(new ClosureInfo(variable, true));
                    }

                    if (variable.Kind == VariableKind.Local)
                    {
                        Debug.Assert(variable.Scope == this);
                    }
                }
            }

            if (closureVariables != null)
            {
                _closureVariables = closureVariables.ToArray();
            }

            // no longer needed
            _references = null;
        }
Exemplo n.º 6
0
 internal abstract PythonVariable BindReference(PythonNameBinder binder, string name);
Exemplo n.º 7
0
 public ParameterBinder(PythonNameBinder binder)
 {
     _binder = binder;
 }
Exemplo n.º 8
0
 public DefineBinder(PythonNameBinder binder)
 {
     _binder = binder;
 }
Exemplo n.º 9
0
        internal static void BindAst(PythonLanguageVersion langVersion, PythonAst ast, ErrorSink context, bool bindReferences)
        {
            var binder = new PythonNameBinder(langVersion, ast, context, bindReferences);

            binder.Bind(ast);
        }
Exemplo n.º 10
0
 public DeleteBinder(PythonNameBinder binder)
 {
     _binder = binder;
 }