* Whether the routine making a call declares the called name itself, as a * parameter, a local or a nested routine (`function Hash(Item: Pointer; * Hasher: THasher)` calling `Hasher(0, Item, 4)`): from the routine's header * down to the call.
(lower: string, ref: UnresolvedRef, context: ResolutionContext)
| 700 | * down to the call. |
| 701 | */ |
| 702 | function declaredInRoutine(lower: string, ref: UnresolvedRef, context: ResolutionContext): boolean { |
| 703 | const lines = fileLines(ref.filePath!, context); |
| 704 | // The header in the text: a method's node may start at its declaration in |
| 705 | // the class, above the fields and the unit's variables. |
| 706 | const from = routineHeaderAt(ref.filePath!, ref.line, context); |
| 707 | const name = escapeRegExp(lower); |
| 708 | const mentions = new RegExp(`\\b${name}\\b`, 'i'); |
| 709 | const declares = new RegExp(`\\b(?:procedure|function)\\s+${name}\\b|\\b${name}\\s*(?:,\\s*[A-Za-z_]\\w*\\s*)*:(?!=)`, 'i'); |
| 710 | for (let i = Math.max(1, from); i <= ref.line && i <= lines.length; i++) { |
| 711 | const text = lines[i - 1]!; |
| 712 | if (mentions.test(text) && declares.test(text.replace(/\/\/.*$|\{[^}]*\}|'[^']*'/g, ' '))) return true; |
| 713 | } |
| 714 | return false; |
| 715 | } |
| 716 | |
| 717 | /** The line of the nearest routine header at column 0 at or above a line, else the line itself. */ |
| 718 | function routineHeaderAt(filePath: string, line: number, context: ResolutionContext): number { |
no test coverage detected