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

Method extractPascalCall

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

* Extract function calls from a Pascal expression. A `receiverLink` call is * a link inside another call's receiver chain (#2547): it is recorded only * when it can be named precisely — `Obj.Method`, a bare routine, or a * `TFoo.Factory().Method` chain — never as the bare method name a long

(node: SyntaxNode, receiverLink = false)

Source from the content-addressed store, hash-verified

9572 * chain like `Client.New.BaseURL(…)` would leave, which matches namesakes.
9573 */
9574 private extractPascalCall(node: SyntaxNode, receiverLink = false): void {
9575 if (this.nodeStack.length === 0) return;
9576 const callerId = this.nodeStack[this.nodeStack.length - 1];
9577 if (!callerId) return;
9578
9579 // Get the callee name — first child is typically the identifier or exprDot
9580 const firstChild = node.namedChild(0);
9581 if (!firstChild) return;
9582
9583 let calleeName = '';
9584 if (firstChild.type === 'exprDot') {
9585 // Chained static-factory call: `TFoo.GetInstance().DoIt()` — the exprDot's
9586 // receiver is itself an `exprCall`, so the bare identifier list would
9587 // collapse to just `DoIt` and mis-resolve to a same-named method on an
9588 // unrelated class. Encode `TFoo.GetInstance().DoIt` so resolution infers
9589 // DoIt's class from what `TFoo.GetInstance` RETURNS (#645/#608). Only a
9590 // capitalized class-factory chain; a unary outer method.
9591 const innerCall = firstChild.namedChildren.find((c: SyntaxNode) => c.type === 'exprCall');
9592 const outerId = firstChild.namedChildren.filter((c: SyntaxNode) => c.type === 'identifier').pop();
9593 const method = outerId ? getNodeText(outerId, this.source) : '';
9594 if (innerCall && method && /^\w+$/.test(method)) {
9595 const innerFirst = innerCall.namedChild(0);
9596 let innerCallee = '';
9597 if (innerFirst?.type === 'exprDot') {
9598 innerCallee = innerFirst.namedChildren
9599 .filter((c: SyntaxNode) => c.type === 'identifier')
9600 .map((id: SyntaxNode) => getNodeText(id, this.source))
9601 .join('.');
9602 } else if (innerFirst?.type === 'identifier') {
9603 innerCallee = getNodeText(innerFirst, this.source);
9604 }
9605 // Gate on the Delphi type-naming convention — `TFoo` classes / `IFoo`
9606 // interfaces — so a class-factory chain re-encodes. Any other chain
9607 // (`FPanel.Series().Clear(1)`, `Self.X().Y()`) is typed link by link
9608 // (#2550), never left to the outer method's bare name.
9609 if (innerCallee && /^[TI][A-Z]/.test(innerCallee)) calleeName = `${innerCallee}().${method}`;
9610 else this.pushPascalChainCall(firstChild, 'args', node);
9611 } else if (firstChild.namedChild(0)?.type === 'exprDot') {
9612 // `FPanel.Series.Clear(1)`, `TLog.Create.Write('x')` (#2550).
9613 this.pushPascalChainCall(firstChild, 'args', node);
9614 } else {
9615 // Qualified call: Obj.Method(...)
9616 const identifiers = firstChild.namedChildren.filter(
9617 (c: SyntaxNode) => c.type === 'identifier'
9618 );
9619 if (identifiers.length > 0) {
9620 calleeName = identifiers.map((id: SyntaxNode) => getNodeText(id, this.source)).join('.');
9621 }
9622 }
9623 } else if (firstChild.type === 'identifier') {
9624 calleeName = getNodeText(firstChild, this.source);
9625 }
9626
9627 const vagueLink = receiverLink && firstChild.type === 'exprDot' && !calleeName.includes('.');
9628 // In a `with` body a bare `Delete(I)` or `Assign(X)` may be the `with`
9629 // object's member rather than the System unit's or the class's: which one
9630 // the object's type would have to say (see resolution/pascal-scope).
9631 const withMember = this.pascalWithDepth > 0 && firstChild.type === 'identifier' && PASCAL_SYSTEM_NAMES.has(calleeName.toLowerCase());

Callers 3

visitPascalNodeMethod · 0.95
visitPascalBlockMethod · 0.95

Calls 8

pushPascalChainCallMethod · 0.95
visitPascalBlockMethod · 0.95
getNodeTextFunction · 0.90
mapMethod · 0.80
hasMethod · 0.80
pushMethod · 0.80
joinMethod · 0.45

Tested by

no test coverage detected