public readonly ILInstruction CallArgument; // argument of call that needs to be promoted to a named argument private FindResult(FindResultType type, ILInstruction loadInst, ILInstruction callArg) { this.Type = type; this.LoadInst = loadInst; this.CallArgument = callArg; }
// Find the child that intersects the given point (or child gap, if no nodes intersect). // When left is true, finds the left-most child intersecting the point. Otherwise, finds the right-most child intersecting the point. static FindResult FindChild(SnapshotPoint point, List <TrackingSpanNode <T> > nodes, bool left, int lo = -1, int hi = -1) { if (nodes.Count == 0) { return new FindResult() { Index = 0, Intersects = false, Type = FindResultType.Outer } } ; ITextSnapshot snapshot = point.Snapshot; int position = point.Position; FindResultType type = FindResultType.Outer; bool intersects = false; // Binary search for the node containing the position if (lo == -1) { lo = 0; } if (hi == -1) { hi = nodes.Count - 1; } int mid = lo; SnapshotSpan midSpan = new SnapshotSpan(); while (lo <= hi) { mid = (lo + hi) / 2; midSpan = nodes[mid].TrackingSpan.GetSpan(snapshot); if (position < midSpan.Start) { hi = mid - 1; } else if (position > midSpan.End) { lo = mid + 1; } else { // midSpan contains or abuts the position if (position > midSpan.Start && position < midSpan.End) { type = FindResultType.Inner; } intersects = true; break; } } int index = mid; midSpan = nodes[index].TrackingSpan.GetSpan(snapshot); // If this is an intersection, make sure we walk to the left or right as requested. if (intersects) { if (left) { while (index >= lo) { midSpan = nodes[index].TrackingSpan.GetSpan(snapshot); if (position > midSpan.End) { index++; break; } index--; } // If we fell off the end, just return lo if (index < lo) { index = lo; } } else { while (index <= hi) { midSpan = nodes[index].TrackingSpan.GetSpan(snapshot); if (position < midSpan.Start) { index--; break; } index++; } // If we fell off the end, just return hi if (index > hi) { index = hi; } } } return(new FindResult() { Type = type, Index = index, Intersects = intersects }); }