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

Method visitPascalBlock

src/extraction/tree-sitter.ts:9835–9895  ·  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

9833 * With `declarations`, a declaration in it is visited as a declaration.
9834 */
9835 private visitPascalBlock(node: SyntaxNode, declarations = false): void {
9836 for (let i = 0; i < node.namedChildCount; i++) {
9837 const child = node.namedChild(i);
9838 if (!child) continue;
9839 if (declarations && /^(?:decl|defProc$|interface$|implementation$)/.test(child.type)) {
9840 this.visitNode(child);
9841 continue;
9842 }
9843 // Function-as-value capture (#756): Pascal bodies are walked here, not
9844 // in visitNode/visitForCallsAndStructure, so the capture hook fires here
9845 // — assignment RHS is the Delphi event-wiring idiom (`OnFire := Handler`).
9846 this.maybeCaptureFnRefs(child, child.type);
9847 this.declarePascalInline(child);
9848 this.learnPascalVariable(child);
9849 if (child.type === 'exprCall') {
9850 this.extractPascalCall(child);
9851 // The walker doesn't descend into a call's arguments — dispatch the
9852 // argument container directly (`RegisterHandler(TargetCb)` / `(@Cb)`).
9853 const args = child.namedChildren.find((c: SyntaxNode) => c.type === 'exprArgs');
9854 if (args) this.maybeCaptureFnRefs(args, 'exprArgs');
9855 } else if (child.type === 'exprDot') {
9856 // A STATEMENT-level bare exprDot is a paren-less call (`Obj.Free;`,
9857 // `TFoo.GetInstance.DoIt;`). Anywhere else (assignment side, condition,
9858 // expression) a bare exprDot is ambiguous with a field/property access,
9859 // so there we only read the paren'd calls in its receiver chain
9860 // (`X := A(1).B.C` reads `A(1)`); a call right before the read is
9861 // named as any call is.
9862 if (node.type === 'statement') {
9863 // Where the tree has errors, `procedure TFoo.Bar;` may parse as
9864 // one: a routine's header calls nothing (#2514).
9865 if (!this.isPascalHeaderName(child)) {
9866 this.extractPascalParenlessCall(child);
9867 }
9868 } else {
9869 const receiver = child.namedChild(0);
9870 if (receiver?.type === 'exprCall') this.extractPascalReceiverCall(receiver, false);
9871 else this.extractPascalReceiverCalls(receiver);
9872 this.extractPascalParenlessName(child, node);
9873 }
9874 } else if (child.type === 'identifier') {
9875 this.extractPascalParenlessName(child, node);
9876 } else if (child.type === 'with') {
9877 this.pascalWithDepth++;
9878 this.visitPascalBlock(child, declarations);
9879 this.pascalWithDepth--;
9880 } else if (child.type === 'lambda') {
9881 const outer = this.pascalScopes[this.pascalScopes.length - 1];
9882 this.pascalScopes.push({
9883 locals: this.pascalRoutineLocals(child),
9884 classQn: outer?.classQn ?? null,
9885 routine: null,
9886 startLine: outer?.startLine ?? 0,
9887 });
9888 this.visitPascalBlock(child, declarations);
9889 this.pascalScopes.pop();
9890 } else {
9891 // A `begin … end` block in it holds statements only, as it always has.
9892 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