// GlobalStatement public override bool Walk(GlobalStatement node) { foreach (var nameNode in node.Names) { var n = nameNode.Name; if (n == null) { continue; } // Check current scope for conflicting variable var assignedGlobal = false; if (_currentScope.TryGetVariable(n, out var conflict)) { // conflict? switch (conflict.Kind) { case VariableKind.Global: // OK to reassign, as long as kind is the same. // Consider (from Python test grammar) // global a // global a, b assignedGlobal = true; break; 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 var 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); }
public virtual void PostWalk(GlobalStatement node) { }
// GlobalStatement public virtual bool Walk(GlobalStatement node) { return(true); }
// GlobalStatement public override bool Walk(GlobalStatement node) { return(Contains(node)); }
public override void PostWalk(GlobalStatement node) { }
// GlobalStatement public override bool Walk(GlobalStatement node) { return(false); }