private bool _readBeforeInitialized; // the variable is read before it's initialized and therefore needs an init check #endregion Fields #region Constructors public TotemVariable(string name, VariableKind kind, ScopeStatement/*!*/ scope) { Assert.NotNull(scope); _name = name; _kind = kind; _scope = scope; }
public void SetLoc(TotemAst globalParent, IndexSpan span) { _span = span; _parent = globalParent; }
public void SetLoc(TotemAst globalParent, int start, int end) { _span = new IndexSpan(start, end > start ? end - start : start); _parent = globalParent; }
private void PushScope(ScopeStatement node) { node.Parent = _currentScope; _currentScope = node; _finallyCount.Add(0); }
private void PopScope() { _scopes.Add(_currentScope); _currentScope = _currentScope.Parent; _finallyCount.RemoveAt(_finallyCount.Count - 1); }
private void Bind(TotemAst unboundAst) { Assert.NotNull(unboundAst); _currentScope = _globalScope = unboundAst; _finallyCount.Add(0); // Find all scopes and variables unboundAst.Walk(this); // Bind foreach (ScopeStatement scope in _scopes) { scope.Bind(this); } // Finish the globals unboundAst.Bind(this); // Finish Binding w/ outer most scopes first. for (int i = _scopes.Count - 1; i >= 0; i--) { _scopes[i].FinishBind(this); } // Finish the globals unboundAst.FinishBind(this); // Run flow checker foreach (ScopeStatement scope in _scopes) { FlowChecker.Check(scope); } }
public override void PostWalk(TotemAst node) { // Do not add the global suite to the list of processed nodes, // the publishing must be done after the class local binding. Debug.Assert(_currentScope == node); _currentScope = _currentScope.Parent; _finallyCount.RemoveAt(_finallyCount.Count - 1); }
public DelayedProfiling(ScopeStatement ast, MSAst.Expression body, MSAst.ParameterExpression tick) { _ast = ast; _body = body; _tick = tick; }
internal virtual bool TryBindOuter(ScopeStatement from, string name, out TotemVariable variable) { // Hide scope contents by default (only functions expose their locals) variable = null; return false; }
private ScopeStatement VisitScope(ScopeStatement scope) { var newScope = scope.CopyForRewrite(); ScopeStatement prevScope = _curScope; try { // rewrite the method body _curScope = newScope; newScope.Parent = prevScope; newScope.RewriteBody(this); } finally { _curScope = prevScope; } return newScope; }
public LookupVisitor(TotemAst ast, MSAst.Expression globalContext) { _globalContext = globalContext; _curScope = ast; }
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; } }