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

Function declaredInRoutine

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

* 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)

Source from the content-addressed store, hash-verified

700 * down to the call.
701 */
702function 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. */
718function routineHeaderAt(filePath: string, line: number, context: ResolutionContext): number {

Callers 1

gatePascalDataCallFunction · 0.85

Calls 3

fileLinesFunction · 0.85
routineHeaderAtFunction · 0.85
escapeRegExpFunction · 0.70

Tested by

no test coverage detected