public static IEnumerable <IOperation> DescendantOperations(this ControlFlowGraph cfg) => cfg.Blocks.SelectMany(b => b.DescendantOperations());
public static IEnumerable <T> DescendantOperations <T>(this ControlFlowGraph cfg, OperationKind operationKind) where T : IOperation => cfg.DescendantOperations().Where(d => d?.Kind == operationKind).Cast <T>();
public static ImmutableDictionary <CaptureId, FlowCaptureKind> CreateLValueFlowCaptures(ControlFlowGraph cfg) { // This method identifies flow capture reference operations that are target of an assignment // and marks them as lvalue flow captures. // Note that currently the control flow graph does not contain flow captures // that are r-value captures at some point and l-values captures at other point in // the flow graph. The debug only asserts in this method ensure this invariant. // If these asserts fire, we should adjust this algorithm. ImmutableDictionary <CaptureId, FlowCaptureKind> .Builder lvalueFlowCaptureIdBuilder = null; #if DEBUG var rvalueFlowCaptureIds = new HashSet <CaptureId>(); #endif foreach (var flowCaptureReference in cfg.DescendantOperations <IFlowCaptureReferenceOperation>(OperationKind.FlowCaptureReference)) { if (flowCaptureReference.Parent is IAssignmentOperation assignment && assignment.Target == flowCaptureReference || flowCaptureReference.IsInLeftOfDeconstructionAssignment(out _)) { lvalueFlowCaptureIdBuilder = lvalueFlowCaptureIdBuilder ?? ImmutableDictionary.CreateBuilder <CaptureId, FlowCaptureKind>(); var captureKind = flowCaptureReference.Parent is ICompoundAssignmentOperation ? FlowCaptureKind.LValueAndRValueCapture : FlowCaptureKind.LValueCapture; lvalueFlowCaptureIdBuilder.Add(flowCaptureReference.Id, captureKind); }