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

Function matchPascalParenlessRef

src/resolution/pascal-scope.ts:82–135  ·  view source on GitHub ↗
(ref: UnresolvedRef, context: ResolutionContext)

Source from the content-addressed store, hash-verified

80
81/** The routine a paren-less Pascal name reaches in its scope, or null (see the file comment). */
82export function matchPascalParenlessRef(ref: UnresolvedRef, context: ResolutionContext): ResolvedRef | null {
83 const m = PARENLESS.exec(ref.referenceName);
84 if (!m) return null;
85 let mode = m[1] as Mode;
86 const target = m[2];
87 const path = m[4]!.split('.');
88 // Most such names read data, often the framework's: a name no Pascal
89 // routine has is settled here, before any lookup in scope. Called with its
90 // arguments, a chain may end at data that holds a routine.
91 if (mode !== 'args' && routineNames(context)?.has(path[path.length - 1]!.toLowerCase()) === false) return null;
92 let cls: Node | null = null;
93 if (m[3]) {
94 cls = classByQualifiedName(m[3], ref.filePath!, context);
95 } else {
96 const routine = context.getNodeById?.(ref.fromNodeId);
97 if (routine) cls = classOfRoutine(routine, context);
98 }
99 const found = path.length === 1
100 ? nameInScope(path[0]!, cls, ref, context)
101 : memberThroughPath(path, cls, ref, context, mode === 'args');
102 if (!found) return null;
103 let edgeKind: 'calls' | 'references' = 'calls';
104 // Written with its arguments, the routine runs, or the routine the data holds.
105 if (mode !== 'args') {
106 if (target !== undefined) {
107 // Given to a target, a method is a method pointer when the target's
108 // declared type is a routine type, and a value otherwise. A function
109 // whose result is a routine type is called for it.
110 const routineTyped = assignedRoutineType(target, cls, ref, context);
111 if (routineTyped !== undefined) mode = routineTyped ? 'ref' : 'read';
112 if (mode === 'ref' && returnsRoutineType(found.node, context)) mode = 'read';
113 }
114 // Written without arguments, a routine that needs some can only be a
115 // method pointer — save a constructor, whose name then means an inherited
116 // one outside the project (`TObject.Create`) — and so is a procedure read
117 // for a value, and an event's method; any other runs.
118 const needsArgs = needsArguments(found.node);
119 if (needsArgs && routineKeyword(found.node, context) === 'constructor') return null;
120 const pointer = mode === 'ref' || needsArgs || (mode !== 'call' && !yieldsValue(found.node, context));
121 // A statement runs its routine, and a receiver is a routine's value.
122 if (pointer && (mode === 'call' || mode === 'recv')) return null;
123 edgeKind = pointer ? 'references' : 'calls';
124 }
125 context.rememberNode?.(found.node);
126 return {
127 original: ref,
128 targetNodeId: found.node.id,
129 confidence: found.confidence,
130 resolvedBy: found.resolvedBy,
131 edgeKind,
132 // A method pointer is a function used as a value, as `@Handler` is (#756).
133 ...(edgeKind === 'references' ? { metadata: { fnRef: true } } : {}),
134 };
135}
136
137/** Whether `ref` is a bare Pascal call to one of the System unit's names (see PASCAL_SYSTEM_NAMES). */
138export function isPascalSystemCall(ref: UnresolvedRef, context: ResolutionContext): boolean {

Callers 1

resolveOneInnerMethod · 0.90

Calls 14

routineNamesFunction · 0.85
classByQualifiedNameFunction · 0.85
classOfRoutineFunction · 0.85
nameInScopeFunction · 0.85
memberThroughPathFunction · 0.85
assignedRoutineTypeFunction · 0.85
returnsRoutineTypeFunction · 0.85
needsArgumentsFunction · 0.85
routineKeywordFunction · 0.85
yieldsValueFunction · 0.85
hasMethod · 0.80
rememberNodeMethod · 0.80

Tested by

no test coverage detected