* Whether the routine making a call declares the called name as a parameter * or a local of its own, or one of the routines it is nested in does, above * the call (`procedure Show(Log: TProc )`): not a routine's header * (`function Max: Integer`), nor what a routine nested beside it declar
(lower: string, ref: UnresolvedRef, context: ResolutionContext)
| 374 | * (`function Max: Integer`), nor what a routine nested beside it declares. |
| 375 | */ |
| 376 | function declaredAsLocal(lower: string, ref: UnresolvedRef, context: ResolutionContext): boolean { |
| 377 | const lines = fileLines(ref.filePath!, context); |
| 378 | const from = routineHeaderAt(ref.filePath!, ref.line, context); |
| 379 | const name = escapeRegExp(lower); |
| 380 | const mentions = new RegExp(`\\b${name}\\b`, 'i'); |
| 381 | const declares = new RegExp( |
| 382 | `(?<![.\\w])(?<!\\b(?:procedure|function|constructor|destructor|operator)\\s+(?:[\\w<>]+\\s*\\.\\s*)*)${name}(?:\\s*,\\s*&?[A-Za-z_]\\w*)*\\s*:(?!=)`, 'i'); |
| 383 | const elsewhere = nestedRoutineSpans(ref.filePath!, context).filter(([start, end]) => ref.line < start || ref.line > end); |
| 384 | for (let i = Math.max(1, from); i <= ref.line && i <= lines.length; i++) { |
| 385 | const raw = lines[i - 1]!; |
| 386 | if (!mentions.test(raw) || elsewhere.some(([start, end]) => i >= start && i <= end)) continue; |
| 387 | if (declares.test(raw.replace(/\/\/.*$|\{[^}]*\}|\(\*.*?\*\)|'(?:[^']|'')*'/g, ' '))) return true; |
| 388 | } |
| 389 | return false; |
| 390 | } |
| 391 | |
| 392 | /** Whether a unit's routine is one a file sees: its own unit's, or one a unit it uses declares in its interface. */ |
| 393 | function unitRoutineInScope(routine: Node, fromFile: string, context: ResolutionContext): boolean { |
no test coverage detected