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

Method visitPascalBlock

src/extraction/tree-sitter.ts:9529–9589  ·  view source on GitHub ↗

* Recursively visit a Pascal block/statement tree for call expressions. * With `declarations`, a declaration in it is visited as a declaration.

(node: SyntaxNode, declarations = false)

Source from the content-addressed store, hash-verified

9527 * With `declarations`, a declaration in it is visited as a declaration.
9528 */
9529 private visitPascalBlock(node: SyntaxNode, declarations = false): void {
9530 for (let i = 0; i < node.namedChildCount; i++) {
9531 const child = node.namedChild(i);
9532 if (!child) continue;
9533 if (declarations && /^(?:decl|defProc$|interface$|implementation$)/.test(child.type)) {
9534 this.visitNode(child);
9535 continue;
9536 }
9537 // Function-as-value capture (#756): Pascal bodies are walked here, not
9538 // in visitNode/visitForCallsAndStructure, so the capture hook fires here
9539 // — assignment RHS is the Delphi event-wiring idiom (`OnFire := Handler`).
9540 this.maybeCaptureFnRefs(child, child.type);
9541 this.declarePascalInline(child);
9542 this.learnPascalVariable(child);
9543 if (child.type === 'exprCall') {
9544 this.extractPascalCall(child);
9545 // The walker doesn't descend into a call's arguments — dispatch the
9546 // argument container directly (`RegisterHandler(TargetCb)` / `(@Cb)`).
9547 const args = child.namedChildren.find((c: SyntaxNode) => c.type === 'exprArgs');
9548 if (args) this.maybeCaptureFnRefs(args, 'exprArgs');
9549 } else if (child.type === 'exprDot') {
9550 // A STATEMENT-level bare exprDot is a paren-less call (`Obj.Free;`,
9551 // `TFoo.GetInstance.DoIt;`). Anywhere else (assignment side, condition,
9552 // expression) a bare exprDot is ambiguous with a field/property access,
9553 // so there we only read the paren'd calls in its receiver chain
9554 // (`X := A(1).B.C` reads `A(1)`); a call right before the read is
9555 // named as any call is.
9556 if (node.type === 'statement') {
9557 // Where the tree has errors, `procedure TFoo.Bar;` may parse as
9558 // one: a routine's header calls nothing (#2514).
9559 if (!this.isPascalHeaderName(child)) {
9560 this.extractPascalParenlessCall(child);
9561 }
9562 } else {
9563 const receiver = child.namedChild(0);
9564 if (receiver?.type === 'exprCall') this.extractPascalReceiverCall(receiver, false);
9565 else this.extractPascalReceiverCalls(receiver);
9566 this.extractPascalParenlessName(child, node);
9567 }
9568 } else if (child.type === 'identifier') {
9569 this.extractPascalParenlessName(child, node);
9570 } else if (child.type === 'with') {
9571 this.pascalWithDepth++;
9572 this.visitPascalBlock(child, declarations);
9573 this.pascalWithDepth--;
9574 } else if (child.type === 'lambda') {
9575 const outer = this.pascalScopes[this.pascalScopes.length - 1];
9576 this.pascalScopes.push({
9577 locals: this.pascalRoutineLocals(child),
9578 classQn: outer?.classQn ?? null,
9579 routine: null,
9580 startLine: outer?.startLine ?? 0,
9581 });
9582 this.visitPascalBlock(child, declarations);
9583 this.pascalScopes.pop();
9584 } else {
9585 // A `begin … end` block in it holds statements only, as it always has.
9586 this.visitPascalBlock(child, declarations && child.type !== 'block');

Callers 4

visitPascalNodeMethod · 0.95
walkPascalRoutineMethod · 0.95
extractPascalCallMethod · 0.95

Calls 12

visitNodeMethod · 0.95
maybeCaptureFnRefsMethod · 0.95
declarePascalInlineMethod · 0.95
learnPascalVariableMethod · 0.95
extractPascalCallMethod · 0.95
isPascalHeaderNameMethod · 0.95
pascalRoutineLocalsMethod · 0.95
pushMethod · 0.80

Tested by

no test coverage detected