private Expression Rewrite(CodeContextScopeExpression ccs) { Expression saved = _context; ParameterExpression nested = Expression.Variable(typeof(CodeContext), "$frame"); // rewrite body with nested context _context = nested; Expression body = Visit(ccs.Body); _context = saved; // wrap the body in a scope that initializes the nested context return(AstUtils.AddScopedVariable(body, nested, Visit(ccs.NewContext))); }
protected override Expression VisitExtension(Expression node) { if (node is YieldExpression || node is GeneratorExpression || node is FinallyFlowControlExpression) { // These should be rewritten last, when doing finaly compilation // for now, just walk them so we can find other nodes return(base.VisitExtension(node)); } GlobalVariableExpression global = node as GlobalVariableExpression; if (global != null) { return(RewriteGet(global)); } CodeContextExpression cc = node as CodeContextExpression; if (cc != null) { return(_context); } CodeContextScopeExpression ccs = node as CodeContextScopeExpression; if (ccs != null) { return(Rewrite(ccs)); } AssignmentExtensionExpression aee = node as AssignmentExtensionExpression; if (aee != null) { return(Rewrite(aee)); } // Must remove extension nodes because they could contain // one of the above node types. See, e.g. DeleteUnboundExpression return(Visit(node.ReduceExtensions())); }