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

Function declaredInRoutine

src/resolution/pascal-scope.ts:220–233  ·  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

218 * down to the call.
219 */
220function 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. */
236function 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