private void Verify(PythonNameBinder binder)
 {
     if (ContainsImportStar && IsClosure)
     {
         binder.ReportSyntaxError(
             "import * is not allowed in function '{0}' because it is a nested function".FormatUI(Name),
             this);
     }
     if (ContainsImportStar && Parent is FunctionDefinition)
     {
         binder.ReportSyntaxError(
             "import * is not allowed in function '{0}' because it is a nested function".FormatUI(Name),
             this);
     }
     if (ContainsImportStar && ContainsNestedFreeVariables)
     {
         binder.ReportSyntaxError(
             "import * is not allowed in function '{0}' because it contains a nested function with free variables".FormatUI(Name),
             this);
     }
     if (ContainsUnqualifiedExec && ContainsNestedFreeVariables)
     {
         binder.ReportSyntaxError(
             "unqualified exec is not allowed in function '{0}' because it contains a nested function with free variables".FormatUI(Name),
             this);
     }
     if (ContainsUnqualifiedExec && IsClosure)
     {
         binder.ReportSyntaxError(
             "unqualified exec is not allowed in function '{0}' because it is a nested function".FormatUI(Name),
             this);
     }
 }
Beispiel #2
0
 private void Verify(PythonNameBinder binder)
 {
     if (ContainsImportStar && IsClosure)
     {
         binder.ReportSyntaxError(
             String.Format(
                 System.Globalization.CultureInfo.InvariantCulture,
                 "import * is not allowed in function '{0}' because it is a nested function",
                 Name),
             this);
     }
     if (ContainsImportStar && Parent is FunctionDefinition)
     {
         binder.ReportSyntaxError(
             String.Format(
                 System.Globalization.CultureInfo.InvariantCulture,
                 "import * is not allowed in function '{0}' because it is a nested function",
                 Name),
             this);
     }
     if (ContainsImportStar && ContainsNestedFreeVariables)
     {
         binder.ReportSyntaxError(
             String.Format(
                 System.Globalization.CultureInfo.InvariantCulture,
                 "import * is not allowed in function '{0}' because it contains a nested function with free variables",
                 Name),
             this);
     }
     if (ContainsUnqualifiedExec && ContainsNestedFreeVariables)
     {
         binder.ReportSyntaxError(
             String.Format(
                 System.Globalization.CultureInfo.InvariantCulture,
                 "unqualified exec is not allowed in function '{0}' because it contains a nested function with free variables",
                 Name),
             this);
     }
     if (ContainsUnqualifiedExec && IsClosure)
     {
         binder.ReportSyntaxError(
             String.Format(
                 System.Globalization.CultureInfo.InvariantCulture,
                 "unqualified exec is not allowed in function '{0}' because it is a nested function",
                 Name),
             this);
     }
 }
Beispiel #3
0
        internal virtual void Bind(PythonNameBinder binder)
        {
            if (_references != null)
            {
                foreach (var refList in _references.Values)
                {
                    foreach (var reference in refList)
                    {
                        PythonVariable variable;
                        reference.Variable = variable = BindReference(binder, reference.Name);

                        // Accessing outer scope variable which is being deleted?
                        if (variable != null)
                        {
                            if (variable.Deleted && variable.Scope != this && !variable.Scope.IsGlobal && binder.LanguageVersion < PythonLanguageVersion.V32)
                            {
                                // report syntax error
                                binder.ReportSyntaxError(
                                    String.Format(
                                        System.Globalization.CultureInfo.InvariantCulture,
                                        "can not delete variable '{0}' referenced in nested scope",
                                        reference.Name
                                        ),
                                    this);
                            }
                        }
                    }
                }
            }
        }
Beispiel #4
0
 private void Verify(PythonNameBinder binder) {
     if (ContainsImportStar && IsClosure) {
         binder.ReportSyntaxError(
             String.Format(
                 System.Globalization.CultureInfo.InvariantCulture,
                 "import * is not allowed in function '{0}' because it is a nested function",
                 Name),
             this);
     }
     if (ContainsImportStar && Parent is FunctionDefinition) {
         binder.ReportSyntaxError(
             String.Format(
                 System.Globalization.CultureInfo.InvariantCulture,
                 "import * is not allowed in function '{0}' because it is a nested function",
                 Name),
             this);
     }
     if (ContainsImportStar && ContainsNestedFreeVariables) {
         binder.ReportSyntaxError(
             String.Format(
                 System.Globalization.CultureInfo.InvariantCulture,
                 "import * is not allowed in function '{0}' because it contains a nested function with free variables",
                 Name),
             this);
     }
     if (ContainsUnqualifiedExec && ContainsNestedFreeVariables) {
         binder.ReportSyntaxError(
             String.Format(
                 System.Globalization.CultureInfo.InvariantCulture,
                 "unqualified exec is not allowed in function '{0}' because it contains a nested function with free variables",
                 Name),
             this);
     }
     if (ContainsUnqualifiedExec && IsClosure) {
         binder.ReportSyntaxError(
             String.Format(
                 System.Globalization.CultureInfo.InvariantCulture,
                 "unqualified exec is not allowed in function '{0}' because it is a nested function",
                 Name),
             this);
     }
 }
Beispiel #5
0
        internal virtual void FinishBind(PythonNameBinder binder)
        {
            List <ClosureInfo> closureVariables = null;

            if (_nonLocalVars != null)
            {
                foreach (var variableName in _nonLocalVars)
                {
                    bool bound = false;
                    for (ScopeStatement parent = Parent; parent != null; parent = parent.Parent)
                    {
                        PythonVariable variable;

                        if (parent.TryBindOuter(this, variableName.Name, false, out variable))
                        {
                            bound = !variable.IsGlobal;
                            break;
                        }
                    }

                    if (!bound)
                    {
                        binder.ReportSyntaxError(String.Format("no binding for nonlocal '{0}' found", 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 (PythonVariable 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;
        }
Beispiel #6
0
        internal virtual void FinishBind(PythonNameBinder binder) {
            List<ClosureInfo> closureVariables = null;

            if (_nonLocalVars != null) {
                foreach (var variableName in _nonLocalVars) {
                    bool bound = false;
                    for (ScopeStatement parent = Parent; parent != null; parent = parent.Parent) {
                        PythonVariable variable;

                        if (parent.TryBindOuter(this, variableName.Name, false, out variable)) {
                            bound = !variable.IsGlobal;
                            break;
                        }
                    }

                    if (!bound) {
                        binder.ReportSyntaxError(String.Format("no binding for nonlocal '{0}' found", 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 (PythonVariable 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;
        }
Beispiel #7
0
        internal virtual void Bind(PythonNameBinder binder) {
            if (_references != null) {
                foreach (var refList in _references.Values) {
                    foreach (var reference in refList) {
                        PythonVariable variable;
                        reference.Variable = variable = BindReference(binder, reference.Name);

                        // Accessing outer scope variable which is being deleted?
                        if (variable != null) {
                            if (variable.Deleted && variable.Scope != this && !variable.Scope.IsGlobal && binder.LanguageVersion < PythonLanguageVersion.V32) {

                                // report syntax error
                                binder.ReportSyntaxError(
                                    String.Format(
                                        System.Globalization.CultureInfo.InvariantCulture,
                                        "can not delete variable '{0}' referenced in nested scope",
                                        reference.Name
                                        ),
                                    this);
                            }
                        }
                    }
                }
            }
        }