* 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)
| 218 | * down to the call. |
| 219 | */ |
| 220 | function declaredInRoutine(lower: string, ref: UnresolvedRef, context: ResolutionContext): boolean { |
| 221 | const lines = fileLines(ref.filePath!, context); |
| 222 | // The header in the text: a method's node may start at its declaration in |
| 223 | // the class, above the fields and the unit's variables. |
| 224 | const from = routineHeaderAt(ref.filePath!, ref.line, context); |
| 225 | const name = escapeRegExp(lower); |
| 226 | const mentions = new RegExp(`\\b${name}\\b`, 'i'); |
| 227 | const declares = new RegExp(`\\b(?:procedure|function)\\s+${name}\\b|\\b${name}\\s*(?:,\\s*[A-Za-z_]\\w*\\s*)*:(?!=)`, 'i'); |
| 228 | for (let i = Math.max(1, from); i <= ref.line && i <= lines.length; i++) { |
| 229 | const text = lines[i - 1]!; |
| 230 | if (mentions.test(text) && declares.test(text.replace(/\/\/.*$|\{[^}]*\}|'[^']*'/g, ' '))) return true; |
| 231 | } |
| 232 | return false; |
| 233 | } |
| 234 | |
| 235 | /** The line of the nearest routine header at column 0 at or above a line, else the line itself. */ |
| 236 | function routineHeaderAt(filePath: string, line: number, context: ResolutionContext): number { |
no test coverage detected