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

Method visitFunctionBody

src/extraction/tree-sitter.ts:5129–5286  ·  view source on GitHub ↗
(body: SyntaxNode, _functionId: string)

Source from the content-addressed store, hash-verified

5127 }
5128
5129 private visitFunctionBody(body: SyntaxNode, _functionId: string): void {
5130 if (!this.extractor) return;
5131
5132 const visitForCallsAndStructure = (node: SyntaxNode): void => {
5133 const nodeType = node.type;
5134
5135 // Function-as-value capture (#756) — function bodies are walked here,
5136 // not in visitNode, so the capture hook must fire in both walkers.
5137 this.maybeCaptureFnRefs(node, nodeType);
5138
5139 // Rocket route-registration macros (`routes![…]` / `catchers![…]`): the
5140 // handler paths live in a raw token tree the call walker can't see.
5141 if (nodeType === 'macro_invocation') this.extractRustRouteMacro(node);
5142
5143 if (this.extractor!.callTypes.includes(nodeType)) {
5144 this.extractCall(node);
5145 } else if (INSTANTIATION_KINDS.has(nodeType) || this.isVbnetConstructorShapedArrayCreation(node)) {
5146 // `new Foo()` inside a function body — emit an `instantiates`
5147 // reference. Without this branch the body walker only knew
5148 // about `call_expression`, so constructor invocations
5149 // produced no graph edges at all.
5150 this.extractInstantiation(node);
5151 // Anonymous class with body: `new T() { ... }` (Java/C#). Extract as
5152 // a class so interface-impl synthesis (Phase 5.5) can bridge T's
5153 // methods to the overrides — same rationale as in visitNode.
5154 const anonBody = this.findAnonymousClassBody(node);
5155 if (anonBody) {
5156 this.extractAnonymousClass(node, anonBody);
5157 return;
5158 }
5159 } else if (this.extractor!.extractBareCall) {
5160 const calleeName = this.extractor!.extractBareCall(node, this.source);
5161 if (calleeName && this.nodeStack.length > 0) {
5162 const callerId = this.nodeStack[this.nodeStack.length - 1];
5163 if (callerId) {
5164 this.unresolvedReferences.push({
5165 fromNodeId: callerId,
5166 referenceName: calleeName,
5167 referenceKind: 'calls',
5168 line: node.startPosition.row + 1,
5169 column: node.startPosition.column,
5170 });
5171 }
5172 }
5173 }
5174
5175 // C++ stack / direct-initialization construction — `Calculator calc(0)`
5176 // and `Widget w{1, 2}`. Unlike heap `new Calculator(0)` (a new_expression
5177 // handled above), these carry the constructor arguments directly on the
5178 // declarator with NO call/new node, so the body walker saw no constructor
5179 // invocation and recorded no `instantiates` edge (#1035). A declaration's
5180 // `type` field IS the constructed class name, so reuse extractInstantiation
5181 // (which strips template args / namespace and emits the `instantiates`
5182 // ref). Children still recurse below, so a nested ctor-arg call
5183 // (`Calculator calc(make())`) keeps its own `calls` ref.
5184 if (nodeType === 'declaration' && this.language === 'cpp' && this.isCppStackConstruction(node)) {
5185 this.extractInstantiation(node);
5186 }

Callers 6

visitNodeMethod · 0.95
extractFunctionMethod · 0.95
extractMethodMethod · 0.95
extractRtkEndpointsMethod · 0.95
extractVariableMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected