* The class and routine a name at `line` belongs to; null outside any code. * Where the tree has errors, a routine whose header didn't parse is a block * outside any routine, or part of the routine above it, so the source text * says: a header between the tree's routine and the name is the
(line: number)
| 9741 | * with the declarations the text gives it. |
| 9742 | */ |
| 9743 | private pascalScopeAt(line: number): { classQn: string | null; routine: string | null; locals: Map<string, string | null> | null } | null { |
| 9744 | const scope = this.pascalScopes[this.pascalScopes.length - 1]; |
| 9745 | if (!scope) return null; |
| 9746 | const own = { classQn: scope.classQn, routine: scope.routine, locals: null }; |
| 9747 | if (!this.tree?.rootNode.hasError) return own; |
| 9748 | const routines = (this.pascalTextRoutines ??= this.readPascalTextRoutines()); |
| 9749 | let lo = 0; |
| 9750 | let hi = routines.length - 1; |
| 9751 | let hit = -1; |
| 9752 | while (lo <= hi) { |
| 9753 | const mid = (lo + hi) >> 1; |
| 9754 | if (routines[mid]!.line <= line) { |
| 9755 | hit = mid; |
| 9756 | lo = mid + 1; |
| 9757 | } else { |
| 9758 | hi = mid - 1; |
| 9759 | } |
| 9760 | } |
| 9761 | const text = hit >= 0 ? routines[hit]! : null; |
| 9762 | // Inside a routine the tree parsed, only a later header overrides it. |
| 9763 | if (!text || text.line <= scope.startLine || (scope.startLine > 0 && text.routine === null)) return own; |
| 9764 | return text; |
| 9765 | } |
| 9766 | |
| 9767 | /** |
| 9768 | * Each routine header of the source text (`procedure TFoo.Bar(…)`), with |
no test coverage detected