* How a name in `parent` may run a parameterless routine: `call` as a * statement of its own, `read` for its value in an expression or an * argument, `ref` as the method an event is given, `recv` as what is * indexed; null where it can't (an assignment's target, a case label, a * set lit
(name: SyntaxNode, parent: SyntaxNode)
| 10163 | * set literal, a type). |
| 10164 | */ |
| 10165 | private pascalNameMode(name: SyntaxNode, parent: SyntaxNode): PascalNameMode | null { |
| 10166 | const is = (field: string): boolean => parent.childForFieldName(field)?.id === name.id; |
| 10167 | switch (parent.type) { |
| 10168 | case 'statement': |
| 10169 | return parent.namedChildCount === 1 && name.type === 'identifier' ? 'call' : null; |
| 10170 | case 'exprSubscript': |
| 10171 | return parent.namedChild(0)?.id === name.id ? 'recv' : null; |
| 10172 | case 'assignment': { |
| 10173 | const target = parent.namedChild(0); |
| 10174 | if (!target || target.id === name.id) return null; |
| 10175 | const last = target.type === 'exprDot' |
| 10176 | ? target.namedChildren.filter((c: SyntaxNode) => c.type === 'identifier').pop() |
| 10177 | : target; |
| 10178 | return last && /^F?On[A-Z]/.test(getNodeText(last, this.source)) ? 'ref' : 'read'; |
| 10179 | } |
| 10180 | case 'exprArgs': |
| 10181 | return parent.parent?.type === 'exprCall' || parent.parent?.type === 'exprSubscript' || parent.parent?.type === 'inherited' ? 'read' : null; |
| 10182 | case 'exprBinary': { |
| 10183 | const op = parent.namedChildren.find((c: SyntaxNode) => c.id !== name.id && /^k[A-Z]/.test(c.type)); |
| 10184 | return op && (op.type === 'kIs' || op.type === 'kAs') && parent.namedChild(0)?.id !== name.id ? null : 'read'; |
| 10185 | } |
| 10186 | case 'exprUnary': |
| 10187 | // `@Obj.Method` takes a method's address, a method pointer whatever it |
| 10188 | // is given to (#2550); `@Handler` is a function value (#756). |
| 10189 | if (parent.child(0)?.type === 'kAt') return name.type === 'exprDot' ? 'ref' : null; |
| 10190 | return 'read'; |
| 10191 | case 'if': |
| 10192 | case 'ifElse': |
| 10193 | case 'while': |
| 10194 | case 'repeat': |
| 10195 | return is('condition') ? 'read' : null; |
| 10196 | case 'case': |
| 10197 | return 'read'; |
| 10198 | case 'foreach': |
| 10199 | return is('iterable') ? 'read' : null; |
| 10200 | case 'for': |
| 10201 | return is('end') ? 'read' : null; |
| 10202 | case 'exprParens': |
| 10203 | return 'read'; |
| 10204 | default: |
| 10205 | return null; |
| 10206 | } |
| 10207 | } |
| 10208 | |
| 10209 | /** |
| 10210 | * An assignment's target, for what a method given to it is (#2550): its |
no test coverage detected