* 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)
| 9857 | * set literal, a type). |
| 9858 | */ |
| 9859 | private pascalNameMode(name: SyntaxNode, parent: SyntaxNode): PascalNameMode | null { |
| 9860 | const is = (field: string): boolean => parent.childForFieldName(field)?.id === name.id; |
| 9861 | switch (parent.type) { |
| 9862 | case 'statement': |
| 9863 | return parent.namedChildCount === 1 && name.type === 'identifier' ? 'call' : null; |
| 9864 | case 'exprSubscript': |
| 9865 | return parent.namedChild(0)?.id === name.id ? 'recv' : null; |
| 9866 | case 'assignment': { |
| 9867 | const target = parent.namedChild(0); |
| 9868 | if (!target || target.id === name.id) return null; |
| 9869 | const last = target.type === 'exprDot' |
| 9870 | ? target.namedChildren.filter((c: SyntaxNode) => c.type === 'identifier').pop() |
| 9871 | : target; |
| 9872 | return last && /^F?On[A-Z]/.test(getNodeText(last, this.source)) ? 'ref' : 'read'; |
| 9873 | } |
| 9874 | case 'exprArgs': |
| 9875 | return parent.parent?.type === 'exprCall' || parent.parent?.type === 'exprSubscript' || parent.parent?.type === 'inherited' ? 'read' : null; |
| 9876 | case 'exprBinary': { |
| 9877 | const op = parent.namedChildren.find((c: SyntaxNode) => c.id !== name.id && /^k[A-Z]/.test(c.type)); |
| 9878 | return op && (op.type === 'kIs' || op.type === 'kAs') && parent.namedChild(0)?.id !== name.id ? null : 'read'; |
| 9879 | } |
| 9880 | case 'exprUnary': |
| 9881 | // `@Obj.Method` takes a method's address, a method pointer whatever it |
| 9882 | // is given to (#2550); `@Handler` is a function value (#756). |
| 9883 | if (parent.child(0)?.type === 'kAt') return name.type === 'exprDot' ? 'ref' : null; |
| 9884 | return 'read'; |
| 9885 | case 'if': |
| 9886 | case 'ifElse': |
| 9887 | case 'while': |
| 9888 | case 'repeat': |
| 9889 | return is('condition') ? 'read' : null; |
| 9890 | case 'case': |
| 9891 | return 'read'; |
| 9892 | case 'foreach': |
| 9893 | return is('iterable') ? 'read' : null; |
| 9894 | case 'for': |
| 9895 | return is('end') ? 'read' : null; |
| 9896 | case 'exprParens': |
| 9897 | return 'read'; |
| 9898 | default: |
| 9899 | return null; |
| 9900 | } |
| 9901 | } |
| 9902 | |
| 9903 | /** |
| 9904 | * An assignment's target, for what a method given to it is (#2550): its |
no test coverage detected