コード例 #1
0
        internal override bool TryBindOuter(ScopeStatement from, string name, bool allowGlobals, out PythonVariable variable)
        {
            // Functions expose their locals to direct access
            ContainsNestedFreeVariables = true;
            if (TryGetVariable(name, out variable))
            {
                variable.AccessedInNestedScope = true;

                if (variable.Kind == VariableKind.Local || variable.Kind == VariableKind.Parameter)
                {
                    from.AddFreeVariable(variable, true);

                    for (ScopeStatement scope = from.Parent; scope != this; scope = scope.Parent)
                    {
                        scope.AddFreeVariable(variable, false);
                    }

                    AddCellVariable(variable);
                }
                else if (allowGlobals)
                {
                    from.AddReferencedGlobal(name);
                }
                return(true);
            }
            return(false);
        }
コード例 #2
0
        internal override bool TryBindOuter(ScopeStatement from, string name, bool allowGlobals, out PythonVariable variable)
        {
            if (allowGlobals)
            {
                // Unbound variable
                from.AddReferencedGlobal(name);

                if (from.HasLateBoundVariableSets)
                {
                    // If the context contains unqualified exec, new locals can be introduced
                    // Therefore we need to turn this into a fully late-bound lookup which
                    // happens when we don't have a PythonVariable.
                    variable = null;
                    return(false);
                }
                else
                {
                    // Create a global variable to bind to.
                    variable = EnsureGlobalVariable(name);
                    return(true);
                }
            }
            variable = null;
            return(false);
        }
コード例 #3
0
ファイル: FunctionDefinition.cs プロジェクト: omnimark/PTVS
        internal override bool TryBindOuter(ScopeStatement from, string name, bool allowGlobals, out PythonVariable variable) {
            // Functions expose their locals to direct access
            ContainsNestedFreeVariables = true;
            if (TryGetVariable(name, out variable)) {
                variable.AccessedInNestedScope = true;

                if (variable.Kind == VariableKind.Local || variable.Kind == VariableKind.Parameter) {
                    from.AddFreeVariable(variable, true);

                    for (ScopeStatement scope = from.Parent; scope != this; scope = scope.Parent) {
                        scope.AddFreeVariable(variable, false);
                    }

                    AddCellVariable(variable);
                } else if(allowGlobals) {
                    from.AddReferencedGlobal(name);
                }
                return true;
            }
            return false;
        }
コード例 #4
0
        internal override bool TryBindOuter(ScopeStatement from, string name, bool allowGlobals, out PythonVariable variable)
        {
            if (allowGlobals) {
                // Unbound variable
                from.AddReferencedGlobal(name);

                if (from.HasLateBoundVariableSets) {
                    // If the context contains unqualified exec, new locals can be introduced
                    // Therefore we need to turn this into a fully late-bound lookup which
                    // happens when we don't have a PythonVariable.
                    variable = null;
                    return false;
                } else {
                    // Create a global variable to bind to.
                    variable = EnsureGlobalVariable(name);
                    return true;
                }
            }
            variable = null;
            return false;
        }