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

Function inferCppAutoInitializerType

src/resolution/name-matcher.ts:856–876  ·  view source on GitHub ↗

* Recover the type of an `auto`-declared local from its initializer on the * declaration line — `auto x = Foo::instance();`, `auto w = make_unique ();`, * `auto p = new W();`, `auto w = Widget();` (#645).

(
  line: string,
  receiverName: string,
  ref: UnresolvedRef,
  context: ResolutionContext,
  depth: number,
)

Source from the content-addressed store, hash-verified

854 * `auto p = new W();`, `auto w = Widget();` (#645).
855 */
856function inferCppAutoInitializerType(
857 line: string,
858 receiverName: string,
859 ref: UnresolvedRef,
860 context: ResolutionContext,
861 depth: number,
862): string | null {
863 const escaped = receiverName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
864 const m = line.match(new RegExp(`\\b${escaped}\\b\\s*=\\s*([^;]+)`));
865 if (!m || !m[1]) return null;
866 const init = m[1].trim();
867
868 const neu = init.match(/^new\s+([A-Za-z_][\w:]*)/);
869 if (neu && neu[1]) return cppLastSegment(neu[1]);
870
871 // A call or construction: `Foo(...)`, `A::b(...)`, `make_unique<T>(...)`.
872 const call = init.match(/^([A-Za-z_][\w:]*(?:\s*<[^>;]*>)?)\s*\(/);
873 if (call && call[1]) return resolveCppCallResultType(call[1].replace(/\s+/g, ''), ref, context, depth + 1);
874
875 return null;
876}
877
878/**
879 * Resolve a C++ chained call whose receiver is itself a call — encoded by the

Callers 1

inferCppReceiverTypeFunction · 0.85

Calls 2

cppLastSegmentFunction · 0.85
resolveCppCallResultTypeFunction · 0.85

Tested by

no test coverage detected