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

Function declaredUnderCondition

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

* Whether a declaration is inside an `{$IFDEF}`, `{$IFNDEF}`, `{$IF}` or * `{$IFOPT}` block, or its `{$ELSE}`.

(node: Node, context: ResolutionContext)

Source from the content-addressed store, hash-verified

249 * `{$IFOPT}` block, or its `{$ELSE}`.
250 */
251function declaredUnderCondition(node: Node, context: ResolutionContext): boolean {
252 const memo = memos(context).conditionDepths;
253 let depths = memo.get(node.filePath);
254 const lines = fileLines(node.filePath, context);
255 if (!depths) {
256 depths = [];
257 let depth = 0;
258 for (const text of lines) {
259 depths.push(depth);
260 if (text.includes('{$')) depth = conditionDepthAfter(text, depth);
261 }
262 memo.set(node.filePath, depths);
263 }
264 const line = lines[node.startLine - 1] ?? '';
265 return conditionDepthAfter(line.slice(0, node.startColumn), depths[node.startLine - 1] ?? 0) > 0;
266}
267
268/** The depth of conditional blocks after a line's directives (`{$IFDEF X}` opens one, `{$ENDIF}` closes it). */
269function conditionDepthAfter(text: string, depth: number): number {

Callers 1

matchPascalSystemCallFunction · 0.85

Calls 6

memosFunction · 0.85
fileLinesFunction · 0.85
conditionDepthAfterFunction · 0.85
pushMethod · 0.80
getMethod · 0.65
setMethod · 0.45

Tested by

no test coverage detected