internal static IVariable[] GetCapturedLoopVariables(IEmitter emitter, AstNode context, IEnumerable <ParameterDeclaration> parameters, bool excludeReadOnly = false) { var loop = LambdaBlock.GetOuterLoop(context); if (loop == null) { return(null); } var loopVariablesAnalyzer = new LoopVariablesAnalyzer(emitter, excludeReadOnly); loopVariablesAnalyzer.Analyze(loop); var captureAnalyzer = new CaptureAnalyzer(emitter); captureAnalyzer.Analyze(context, parameters.Select(p => p.Name)); return(captureAnalyzer.UsedVariables.Where(v => loopVariablesAnalyzer.Variables.Contains(v)).ToArray()); }
private string[] GetCapturedLoopVariables() { var loop = this.GetOuterLoop(); if (loop == null) { return(null); } var loopVariablesAnalyzer = new LoopVariablesAnalyzer(this.Emitter); loopVariablesAnalyzer.Analyze(loop); var captureAnalyzer = new CaptureAnalyzer(this.Emitter); captureAnalyzer.Analyze(this.Context, this.Parameters.Select(p => p.Name)); var capturedVariables = captureAnalyzer.UsedVariables.Where(v => loopVariablesAnalyzer.Variables.Contains(v)).ToArray(); List <string> names = new List <string>(); foreach (var capturedVariable in capturedVariables) { if (this.Emitter.LocalsMap != null && this.Emitter.LocalsMap.ContainsKey(capturedVariable)) { names.Add(this.Emitter.LocalsMap[capturedVariable]); } else if (this.Emitter.LocalsNamesMap != null && this.Emitter.LocalsNamesMap.ContainsKey(capturedVariable.Name)) { names.Add(this.Emitter.LocalsNamesMap[capturedVariable.Name]); } else { names.Add(capturedVariable.Name); } } return(names.ToArray()); }