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

Method extractPascalCall

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

9266 * chain like `Client.New.BaseURL(…)` would leave, which matches namesakes.
9267 */
9268 private extractPascalCall(node: SyntaxNode, receiverLink = false): void {
9269 if (this.nodeStack.length === 0) return;
9270 const callerId = this.nodeStack[this.nodeStack.length - 1];
9271 if (!callerId) return;
9272
9273 // Get the callee name — first child is typically the identifier or exprDot
9274 const firstChild = node.namedChild(0);
9275 if (!firstChild) return;
9276
9277 let calleeName = '';
9278 if (firstChild.type === 'exprDot') {
9279 // Chained static-factory call: `TFoo.GetInstance().DoIt()` — the exprDot's
9280 // receiver is itself an `exprCall`, so the bare identifier list would
9281 // collapse to just `DoIt` and mis-resolve to a same-named method on an
9282 // unrelated class. Encode `TFoo.GetInstance().DoIt` so resolution infers
9283 // DoIt's class from what `TFoo.GetInstance` RETURNS (#645/#608). Only a
9284 // capitalized class-factory chain; a unary outer method.
9285 const innerCall = firstChild.namedChildren.find((c: SyntaxNode) => c.type === 'exprCall');
9286 const outerId = firstChild.namedChildren.filter((c: SyntaxNode) => c.type === 'identifier').pop();
9287 const method = outerId ? getNodeText(outerId, this.source) : '';
9288 if (innerCall && method && /^\w+$/.test(method)) {
9289 const innerFirst = innerCall.namedChild(0);
9290 let innerCallee = '';
9291 if (innerFirst?.type === 'exprDot') {
9292 innerCallee = innerFirst.namedChildren
9293 .filter((c: SyntaxNode) => c.type === 'identifier')
9294 .map((id: SyntaxNode) => getNodeText(id, this.source))
9295 .join('.');
9296 } else if (innerFirst?.type === 'identifier') {
9297 innerCallee = getNodeText(innerFirst, this.source);
9298 }
9299 // Gate on the Delphi type-naming convention — `TFoo` classes / `IFoo`
9300 // interfaces — so a class-factory chain re-encodes. Any other chain
9301 // (`FPanel.Series().Clear(1)`, `Self.X().Y()`) is typed link by link
9302 // (#2550), never left to the outer method's bare name.
9303 if (innerCallee && /^[TI][A-Z]/.test(innerCallee)) calleeName = `${innerCallee}().${method}`;
9304 else this.pushPascalChainCall(firstChild, 'args', node);
9305 } else if (firstChild.namedChild(0)?.type === 'exprDot') {
9306 // `FPanel.Series.Clear(1)`, `TLog.Create.Write('x')` (#2550).
9307 this.pushPascalChainCall(firstChild, 'args', node);
9308 } else {
9309 // Qualified call: Obj.Method(...)
9310 const identifiers = firstChild.namedChildren.filter(
9311 (c: SyntaxNode) => c.type === 'identifier'
9312 );
9313 if (identifiers.length > 0) {
9314 calleeName = identifiers.map((id: SyntaxNode) => getNodeText(id, this.source)).join('.');
9315 }
9316 }
9317 } else if (firstChild.type === 'identifier') {
9318 calleeName = getNodeText(firstChild, this.source);
9319 }
9320
9321 const vagueLink = receiverLink && firstChild.type === 'exprDot' && !calleeName.includes('.');
9322 // In a `with` body a bare `Delete(I)` or `Assign(X)` may be the `with`
9323 // object's member rather than the System unit's or the class's: which one
9324 // the object's type would have to say (see resolution/pascal-scope).
9325 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