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

Function memberAtPath

src/resolution/pascal-scope.ts:1044–1080  ·  view source on GitHub ↗

* What a dotted name's last link is declared as: a member of what the links * before it are declared to be — a field's or a property's type, a * function's result — from its head (see headOf), or, with `unit`, the * routine or variable a unit's name qualifies (`Utils.Helper`). A constructor * ca

(path: string[], cls: Node | null, ref: UnresolvedRef, context: ResolutionContext)

Source from the content-addressed store, hash-verified

1042 * (`TLog.Create.Write('x')`, `Logs.TLog.Create().Write('x')`).
1043 */
1044function memberAtPath(path: string[], cls: Node | null, ref: UnresolvedRef, context: ResolutionContext): { node: Node; unit: boolean } | null {
1045 let head = headOf(path[0]!, cls, ref, context);
1046 let rest = path.slice(1);
1047 // A dotted unit name, the longest the links make (`mormot.core.os.GetTickCount64`).
1048 for (let k = path.length - 1; !head && k >= 2; k--) {
1049 const unitFile = unitFileNamed(path.slice(0, k).join('.').toLowerCase(), ref.filePath!, context);
1050 if (unitFile) {
1051 head = { type: null, unitFile };
1052 rest = path.slice(k);
1053 }
1054 }
1055 if (!head) return null;
1056 let type = head.type;
1057 let classRef = head.classRef === true;
1058 if (head.unitFile) {
1059 // `UnitName.Routine`, `UnitName.GlobalVar.Method`, `UnitName.TFoo.Create.Method`.
1060 const decl = unitDeclaration(head.unitFile, rest[0]!.toLowerCase(), context, ref.filePath!);
1061 if (!decl) return null;
1062 if (rest.length === 1) return { node: decl, unit: true };
1063 classRef = CLASS_KINDS.has(decl.kind);
1064 type = classRef ? decl : typeOfMember(decl, context);
1065 rest = rest.slice(1);
1066 }
1067 for (let i = 0; i < rest.length && type; i++) {
1068 const lower = rest[i]!.toLowerCase();
1069 const member = memberOfValue(type, lower, ref.filePath!, context);
1070 if (i === rest.length - 1) return member ? { node: member, unit: false } : null;
1071 if (classRef && (member ? routineKeyword(member, context) === 'constructor' : lower === 'create')) {
1072 classRef = false;
1073 continue;
1074 }
1075 if (!member) return null;
1076 type = typeOfMember(member, context);
1077 classRef = false;
1078 }
1079 return null;
1080}
1081
1082/**
1083 * What a dotted name's first link is: a value of a known class (a local's

Callers 2

memberThroughPathFunction · 0.85
assignedRoutineTypeFunction · 0.85

Calls 8

headOfFunction · 0.85
unitFileNamedFunction · 0.85
unitDeclarationFunction · 0.85
typeOfMemberFunction · 0.85
memberOfValueFunction · 0.85
routineKeywordFunction · 0.85
hasMethod · 0.80
joinMethod · 0.45

Tested by

no test coverage detected