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

Function extractCppReceiverType

src/extraction/languages/c-cpp.ts:431–457  ·  view source on GitHub ↗
(node: SyntaxNode, source: string)

Source from the content-addressed store, hash-verified

429}
430
431function extractCppReceiverType(node: SyntaxNode, source: string): string | undefined {
432 const declarator = getChildByField(node, 'declarator');
433 if (!declarator) return undefined;
434 const qid = findDeclaratorQualifiedId(declarator);
435 if (!qid) return undefined;
436 // The scopes are what the qualified id writes before its name: a
437 // specialization's arguments (`ReadPrimitive<int32_t,
438 // WireFormatLite::TYPE_INT32>`) are no scope, though they may write `::`.
439 const name = cppQualifiedIdName(qid);
440 let scopes = getNodeText(qid, source).trim().split('::').filter(Boolean).slice(0, -1).join('::');
441 if (name) {
442 scopes = source.slice(qid.startIndex, name.startIndex).trimEnd();
443 // A `::` the parser supplied in recovery writes nothing: Metal's `vertex
444 // VertexOut vertexShader(…)` reads as `VertexOut::vertexShader`.
445 if (!scopes.endsWith('::')) return undefined;
446 }
447 const parts = scopes.split('::').filter(Boolean);
448 if (parts.length === 0) return undefined;
449 // An out-of-line template method definition carries the class's template
450 // parameter list in the qualifier (`template<typename T> T Box<T>::get()`),
451 // but the class node is indexed as bare `Box` — strip `<…>` so the receiver
452 // matches it, the same normalization #1043 applies to base-class refs.
453 // Multi-line parameter lists otherwise leak whole `<…>` blocks (newlines
454 // included) into qualified_name, which can exceed NAME_MAX (#1286).
455 const receiver = stripCppTemplateArgs(parts.join('::'));
456 return receiver || undefined;
457}
458
459/**
460 * Built-in / non-class return types that can never be a method receiver. We

Callers

nothing calls this directly

Calls 6

getChildByFieldFunction · 0.90
getNodeTextFunction · 0.90
cppQualifiedIdNameFunction · 0.85
stripCppTemplateArgsFunction · 0.85
joinMethod · 0.45

Tested by

no test coverage detected