Ejemplo n.º 1
0
        internal override bool TryBindOuter(ScopeStatement from, string name, out TotemVariable 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
                {
                    from.AddReferencedGlobal(name);
                }
                return true;
            }
            return false;
        }
Ejemplo n.º 2
0
        internal override bool TryBindOuter(ScopeStatement from, string name, out TotemVariable variable)
        {
            // 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;
            }
        }