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

Function gateTypeParameter

src/resolution/type-parameters.ts:50–97  ·  view source on GitHub ↗
(resolved: ResolvedRef | null, ref: UnresolvedRef, context: ResolutionContext)

Source from the content-addressed store, hash-verified

48 * argument; cats bound 846 such calls to a case class's `f` field).
49 */
50export function gateTypeParameter(resolved: ResolvedRef | null, ref: UnresolvedRef, context: ResolutionContext): ResolvedRef | null {
51 if (!resolved) return resolved;
52 let result = resolved;
53 if (ref.language === 'scala' && (ref.referenceKind === 'calls' || ref.referenceKind === 'references') &&
54 /^[A-Za-z_]\w*$/.test(ref.referenceName)) {
55 for (const declaration of enclosingDeclarations(ref, context)) {
56 if ((declaration.kind === 'function' || declaration.kind === 'method') &&
57 declaredValueParameters(declaration, context).has(ref.referenceName)) return null;
58 }
59 }
60 if (ref.language === 'scala' && !scalaMemberInScope(result, ref, context)) {
61 // Out of scope: the type of that name that IS in scope — cats' own
62 // `trait FlatMap`, not `Eval`'s nested `FlatMap` case class — when one fits.
63 const target = context.getNodeById?.(result.targetNodeId);
64 if (!target || !SCALA_TYPE_KINDS.has(target.kind)) return null;
65 const inScope = context
66 .getNodesByName(ref.referenceName)
67 .filter((n) => n.id !== target.id && n.language === 'scala' && SCALA_TYPE_KINDS.has(n.kind))
68 .filter((n) => scalaMemberInScope({ ...result, targetNodeId: n.id }, ref, context));
69 const chosen = inScope.length === 1 ? inScope[0]! : inScope.find((n) => n.filePath === ref.filePath);
70 if (!chosen) return null;
71 result = { ...result, targetNodeId: chosen.id };
72 }
73 // A C++ name qualified by a template parameter is a member of whatever type
74 // the template is instantiated with: rocksdb's `CacheShard::ComputeHash(…)`
75 // in `template <class CacheShard> class ShardedCache` is not the
76 // `ClockCacheShard::ComputeHash` a guess by name reaches. Only the
77 // parameter's default is known: protobuf's `Parser::ParseLoop(…)` under
78 // `template <typename Parser = TcParser>` is TcParser's for every caller
79 // that passes no parser.
80 if (ref.language === 'cpp') {
81 const qualifier = /^([A-Za-z_]\w*)::/.exec(ref.referenceName)?.[1];
82 if (qualifier) {
83 for (const declaration of enclosingDeclarations(ref, context)) {
84 const parameters = declaredTypeParameters(declaration, context);
85 if (!parameters.has(qualifier)) continue;
86 return isMemberOfDefault(result, parameters.get(qualifier), context) ? result : null;
87 }
88 }
89 }
90 if (!GENERIC_LANGUAGES.has(ref.language) || !TYPE_REF_KINDS.has(ref.referenceKind)) return result;
91 const name = ref.referenceName;
92 if (!/^[A-Z][A-Za-z0-9_]*$/.test(name)) return result;
93 for (const declaration of enclosingDeclarations(ref, context)) {
94 if (declaredTypeParameters(declaration, context).has(name)) return null;
95 }
96 return result;
97}
98
99/** Whether the resolved target is a member of the class a C++ template parameter defaults to (`= TcParser`, `= std::allocator<T>`). */
100function isMemberOfDefault(result: ResolvedRef, fallback: string | undefined, context: ResolutionContext): boolean {

Callers 1

resolveOneInMethod · 0.90

Calls 10

enclosingDeclarationsFunction · 0.85
declaredValueParametersFunction · 0.85
scalaMemberInScopeFunction · 0.85
declaredTypeParametersFunction · 0.85
isMemberOfDefaultFunction · 0.85
hasMethod · 0.80
getNodeByIdMethod · 0.65
getNodesByNameMethod · 0.65
execMethod · 0.65
getMethod · 0.65

Tested by

no test coverage detected