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

Function extractCppReceiverType

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

Source from the content-addressed store, hash-verified

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