예제 #1
0
        // GlobalStatement
        public override bool Walk(GlobalStatement node)
        {
            foreach (NameExpression nameNode in node.Names)
            {
                string n = nameNode.Name;
                if (n == null)
                {
                    continue;
                }

                PythonVariable conflict;
                // Check current scope for conflicting variable
                bool assignedGlobal = false;
                if (_currentScope.TryGetVariable(n, out conflict))
                {
                    // conflict?
                    switch (conflict.Kind)
                    {
                    case VariableKind.Global:
                    case VariableKind.Local:
                        assignedGlobal = true;
                        ReportSyntaxWarning(
                            "name '{0}' is assigned to before global declaration".FormatUI(n),
                            node
                            );
                        break;

                    case VariableKind.Parameter:
                        ReportSyntaxError(
                            "Name '{0}' is a function parameter and declared global".FormatUI(n),
                            node);
                        break;
                    }
                }

                // Check for the name being referenced previously. If it has been, issue warning.
                if (_currentScope.IsReferenced(n) && !assignedGlobal)
                {
                    ReportSyntaxWarning(
                        "name '{0}' is used prior to global declaration".FormatUI(n),
                        node);
                }


                // Create the variable in the global context and mark it as global
                PythonVariable variable = GlobalScope.EnsureGlobalVariable(n);
                variable.Kind = VariableKind.Global;

                if (conflict == null)
                {
                    // no previously definied variables, add it to the current scope
                    _currentScope.AddVariable(variable);
                }

                nameNode.AddVariableReference(GlobalScope, BindReferences, Reference(n));
            }
            return(true);
        }
예제 #2
0
 public override bool Walk(GlobalStatement node) {
     CanComplete = IsActualExpression(node.Names);
     CommitByDefault = true;
     return base.Walk(node);
 }
예제 #3
0
파일: Parser.cs 프로젝트: omnimark/PTVS
 //global_stmt: 'global' NAME (',' NAME)*
 private GlobalStatement ParseGlobalStmt() {
     Eat(TokenKind.KeywordGlobal);
     var start = GetStart();
     string globalWhiteSpace = _tokenWhiteSpace;
     List<string> commaWhiteSpace;
     List<string> namesWhiteSpace;
     
     var l = ReadNameList(out commaWhiteSpace, out namesWhiteSpace);
     var names = l.ToArray();
     GlobalStatement ret = new GlobalStatement(names);
     ret.SetLoc(start, GetEnd());
     if (_verbatim) {
         AddPreceedingWhiteSpace(ret, globalWhiteSpace);
         AddListWhiteSpace(ret, commaWhiteSpace.ToArray());
         AddNamesWhiteSpace(ret, namesWhiteSpace.ToArray());
     }
     return ret;
 }
예제 #4
0
        // GlobalStatement
        public override bool Walk(GlobalStatement node)
        {
            node.Parent = _currentScope;

            foreach (string n in node.Names)
            {
                PythonVariable conflict;
                // Check current scope for conflicting variable
                bool assignedGlobal = false;
                if (_currentScope.TryGetVariable(n, out conflict))
                {
                    // conflict?
                    switch (conflict.Kind)
                    {
                    case VariableKind.Global:
                    case VariableKind.Local:
                        assignedGlobal = true;
                        ReportSyntaxWarning(
                            String.Format(
                                System.Globalization.CultureInfo.InvariantCulture,
                                "name '{0}' is assigned to before global declaration",
                                n
                                ),
                            node
                            );
                        break;

                    case VariableKind.Parameter:
                        ReportSyntaxError(
                            String.Format(
                                System.Globalization.CultureInfo.InvariantCulture,
                                "Name '{0}' is a function parameter and declared global",
                                n),
                            node);
                        break;
                    }
                }

                // Check for the name being referenced previously. If it has been, issue warning.
                if (_currentScope.IsReferenced(n) && !assignedGlobal)
                {
                    ReportSyntaxWarning(
                        String.Format(
                            System.Globalization.CultureInfo.InvariantCulture,
                            "name '{0}' is used prior to global declaration",
                            n),
                        node);
                }


                // Create the variable in the global context and mark it as global
                PythonVariable variable = _globalScope.EnsureGlobalVariable(n);
                variable.Kind = VariableKind.Global;

                if (conflict == null)
                {
                    // no previously definied variables, add it to the current scope
                    _currentScope.AddVariable(variable);
                }
            }
            return(true);
        }
예제 #5
0
        // GlobalStatement
        public override bool Walk(GlobalStatement node) {
            foreach (NameExpression nameNode in node.Names) {
                string n = nameNode.Name;
                if (n == null) {
                    continue;
                }

                PythonVariable conflict;
                // Check current scope for conflicting variable
                bool assignedGlobal = false;
                if (_currentScope.TryGetVariable(n, out conflict)) {
                    // conflict?
                    switch (conflict.Kind) {
                        case VariableKind.Global:
                        case VariableKind.Local:
                            assignedGlobal = true;
                            ReportSyntaxWarning(
                                String.Format(
                                    System.Globalization.CultureInfo.InvariantCulture,
                                    "name '{0}' is assigned to before global declaration",
                                    n
                                ),
                                node
                            );
                            break;
                        
                        case VariableKind.Parameter:
                            ReportSyntaxError(
                                String.Format(
                                    System.Globalization.CultureInfo.InvariantCulture,
                                    "Name '{0}' is a function parameter and declared global",
                                    n),
                                node);
                            break;
                    }
                }

                // Check for the name being referenced previously. If it has been, issue warning.
                if (_currentScope.IsReferenced(n) && !assignedGlobal) {
                    ReportSyntaxWarning(
                        String.Format(
                        System.Globalization.CultureInfo.InvariantCulture,
                        "name '{0}' is used prior to global declaration",
                        n),
                    node);
                }


                // Create the variable in the global context and mark it as global
                PythonVariable variable = _globalScope.EnsureGlobalVariable(n);
                variable.Kind = VariableKind.Global;

                if (conflict == null) {
                    // no previously definied variables, add it to the current scope
                    _currentScope.AddVariable(variable);
                }
                
                nameNode.AddVariableReference(_globalScope, _bindRefs, Reference(n));
            }
            return true;
        }
예제 #6
0
        public override bool Walk(GlobalStatement node) {
            UpdateLineInfo(node, true);

            return base.Walk(node);
        }
예제 #7
0
 public override bool Walk(GlobalStatement node) {
     foreach (var name in node.Names) {
         if (name.Name != null) {
             // set the variable in the local scope to be the real variable in the global scope
             _scope.AddVariable(name.Name, _scope.GlobalScope.CreateVariable(node, _curUnit, name.Name, false));
         }
     }
     return false;
 }
예제 #8
0
 public override void PostWalk(GlobalStatement node) { PostWalkWorker(node); }
예제 #9
0
 // GlobalStatement
 public override bool Walk(GlobalStatement node) { return ShouldWalkWorker(node); }