// 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($"name '{n}' is assigned to before global declaration", node); break; case VariableKind.Parameter: ReportSyntaxError($"name '{n}' is local and global", 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.AddGlobalVariable(variable); } } return(true); }
// 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: break; case VariableKind.Local: assignedGlobal = true; ReportSyntaxError($"name '{n}' is assigned to before global declaration", node); break; case VariableKind.Parameter: ReportSyntaxError($"name '{n}' is parameter and global", node); break; case VariableKind.Nonlocal: ReportSyntaxError($"name '{n}' is nonlocal and global", node); break; } } // Check for the name being referenced previously if (_currentScope.IsReferenced(n) && !assignedGlobal) { ReportSyntaxError($"name '{n}' is used prior to global declaration", node); } // Create the variable in the global context or mark it as global PythonVariable variable = _globalScope.EnsureGlobalVariable(n); if (conflict == null) { // no previously defined variables, add it to the current scope _currentScope.AddGlobalVariable(variable); } } return(true); }
// 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.AddGlobalVariable(variable); } } return true; }
public override void PostWalk(GlobalStatement node) { Content(""); }
public override bool Walk(GlobalStatement node) { foreach (var name in node.Names) { if (IsDefined(name)) { sink.Add(src, String.Format("Variable \"{0}\" is already declared before or some value already is assigned to it.", name), node.Span, PARAM_AS_GLOBBAL_VARAIBLE, Severity.Warning); } sink.Add(src, String.Format("Variable \"{0}\" will point to GLOBAL variable. Incorrect usage of global variables my lead to hardly detectable bugs.", name), node.Span, GLOBBAL_VARAIBLE, Severity.Warning); Define(name); } return false; }
//global_stmt: 'global' NAME (',' NAME)* private GlobalStatement ParseGlobalStmt() { Eat(TokenKind.KeywordGlobal); SourceLocation start = GetStart(); List<SymbolId> l = new List<SymbolId>(); l.Add(ReadName()); while (MaybeEat(TokenKind.Comma)) { l.Add(ReadName()); } SymbolId[] names = l.ToArray(); GlobalStatement ret = new GlobalStatement(names); ret.SetLoc(start, GetEnd()); return ret; }
// GlobalStatement public override bool Walk(GlobalStatement node) { foreach (SymbolId n in node.Names) { Global(n); } return true; }
// GlobalStatement public bool Walk(GlobalStatement node) { return Process(node); }
public void Visit(PyAst.GlobalStatement node) => throw CreateNotImplementedEx();
public override bool Walk(GlobalStatement node) { Emit(node); return false; }
public virtual void PostWalk(GlobalStatement node) { }
// GlobalStatement public virtual bool Walk(GlobalStatement node) { return true; }
// GlobalStmt public override bool Walk(GlobalStatement node) { foreach (SymbolId n in node.Names) { if (current != null) { Binding binding; if (current.Bindings.TryGetValue(n, out binding)) { if (binding.IsParameter) { ReportSyntaxError(String.Format("name '{0}' is a function parameter and declared global", n.GetString()), node); } else if (binding.IsAssigned) { ReportSyntaxWarning(String.Format("Variable {0} assigned before global declaration", n.GetString()), node); } else if (binding.IsFree) { ReportSyntaxWarning(String.Format("Variable {0} used before global declaration", n.GetString()), node); } } current.BindGlobal(n); } } return true; }
internal Global(GlobalStatement stmt) : this() { _names = new PythonList(stmt.Names); }
public void PostWalk(GlobalStatement node) { PostProcess(node); }
//global_stmt: 'global' NAME (',' NAME)* private GlobalStatement ParseGlobalStmt() { Eat(TokenKind.KeywordGlobal); var start = GetStart(); List<string> l = new List<string>(); l.Add(ReadName()); while (MaybeEat(TokenKind.Comma)) { l.Add(ReadName()); } string[] names = l.ToArray(); GlobalStatement ret = new GlobalStatement(names); ret.SetLoc(_globalParent, start, GetEnd()); return ret; }
public override bool Walk(GlobalStatement node) { writer.WriteLine("Global"); return base.Walk(node); }