private MSAst.Expression VisitComprehension(Comprehension comprehension) { var newScope = (ComprehensionScope)comprehension.Scope.CopyForRewrite(); newScope.Parent = _curScope; var newComprehension = comprehension.CopyForRewrite(newScope); ScopeStatement prevScope = _curScope; try { // rewrite the comprehension in a new scope _curScope = newScope; return(base.VisitExtension(newComprehension)); } finally { _curScope = prevScope; } }
// Comprehensions private void WalkComprehensionIterators(Comprehension node) { node.Parent = _currentScope; // Special walk case: first (outermost) "for" iterator // See also: PythonAst.LookupVisitor.VisitComprehension(...) var outermostFor = (ComprehensionFor)node.Iterators[0]; outermostFor.List.Walk(this); PushScope(node.Scope); Walk(outermostFor); outermostFor.Left.Walk(this); PostWalk(outermostFor); // Regular walk cases: remaining iterators/conditionals for (int i = 1; i < node.Iterators.Count; i++) { node.Iterators[i].Walk(this); } }
private MSAst.Expression VisitComprehension(Comprehension comprehension) { var newScope = (ComprehensionScope)comprehension.Scope.CopyForRewrite(); newScope.Parent = _curScope; var newComprehension = comprehension.CopyForRewrite(newScope); ScopeStatement prevScope = _curScope; try { // mark the first (outermost) "for" iterator for rewrite in the current scope _outerComprehensionScopes[((ComprehensionFor)comprehension.Iterators[0]).List] = _curScope; // rewrite the rest of comprehension in the new scope _curScope = newScope; return(base.VisitExtension(newComprehension)); } finally { _curScope = prevScope; } }
public ComprehensionScope(Comprehension comprehension) { _comprehension = comprehension; }