MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / declaredForward

Function declaredForward

src/resolution/pascal-scope.ts:394–410  ·  view source on GitHub ↗

* Whether a routine nested in another is declared `forward` above a line * (`procedure Late; forward;`), which puts it in scope there ahead of its * body (#2550): a header of its name, as indented as its own, that ends in * `forward;`, between the line and the header indented less above it, the

(routine: Node, line: number, context: ResolutionContext)

Source from the content-addressed store, hash-verified

392 * routine both are nested in.
393 */
394function declaredForward(routine: Node, line: number, context: ResolutionContext): boolean {
395 const lines = fileLines(routine.filePath, context);
396 const name = routine.name.toLowerCase();
397 for (let i = Math.min(line, lines.length) - 1; i >= 0; i--) {
398 const m = /^(\s*)(?:class\s+)?(?:procedure|function|constructor|destructor)\s+([A-Za-z_]\w*)/i.exec(lines[i]!);
399 if (!m) continue;
400 if (m[1]!.length < routine.startColumn) return false;
401 if (m[1]!.length !== routine.startColumn || m[2]!.toLowerCase() !== name) continue;
402 // Its parameters may go on over a few lines.
403 let text = lines[i]!.replace(/\/\/.*$|\{[^}]*\}|\(\*.*?\*\)/g, ' ');
404 for (let j = i + 1; j < lines.length && j <= i + 4 && (text.split('(').length > text.split(')').length); j++) {
405 text += ' ' + lines[j]!.replace(/\/\/.*$|\{[^}]*\}|\(\*.*?\*\)/g, ' ');
406 }
407 if (/\bforward\s*;/i.test(text)) return true;
408 }
409 return false;
410}
411
412/**
413 * Whether a node is a routine nested in another (see nestedRoutineInScope):

Callers 1

nestedRoutineInScopeFunction · 0.85

Calls 2

fileLinesFunction · 0.85
execMethod · 0.65

Tested by

no test coverage detected